Check-in Lasker-2.2.3 tar ball from samba.org
[capablanca.git] / lasker-2.2.3 / src / parsers / genparser.h
1 /*
2    Copyright (C) Andrew Tridgell <genstruct@tridgell.net> 2002
3    
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8    
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13    
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 /* these macros are needed for genstruct auto-parsers */
20 #ifndef GENSTRUCT
21 #define GENSTRUCT
22 #define _LEN(x)
23 #define _NULLTERM
24 #endif
25
26 /*
27   automatic marshalling/unmarshalling system for C structures
28 */
29
30 enum parse_type {T_INT, T_UNSIGNED, T_CHAR,
31                  T_FLOAT, T_DOUBLE, T_ENUM, T_STRUCT,
32                  T_TIME_T, T_LONG, T_ULONG};
33
34 /* flag to mark a fixed size array as actually being null terminated */
35 #define FLAG_NULLTERM 1
36 #define FLAG_ALWAYS 2
37
38 struct enum_struct {
39         const char *name;
40         unsigned value;
41 };
42
43 /* intermediate dumps are stored in one of these */
44 struct parse_string {
45         unsigned allocated;
46         unsigned length;
47         char *s;
48 };
49
50 typedef int (*gen_dump_fn)(struct parse_string *, const char *ptr, unsigned indent);
51 typedef int (*gen_parse_fn)(char *ptr, const char *str);
52
53 /* genstruct.pl generates arrays of these */
54 struct parse_struct {
55         const char *name;
56         unsigned ptr_count;
57         unsigned size;
58         unsigned offset;
59         unsigned array_len;
60         const char *dynamic_len;
61         unsigned flags;
62         gen_dump_fn dump_fn;
63         gen_parse_fn parse_fn;
64 };
65
66 char *gen_dump(const struct parse_struct *pinfo, 
67                const char *data, 
68                unsigned indent);
69 int gen_parse(const struct parse_struct *pinfo, char *data, const char *str0);
70
71 int gen_addgen(struct parse_string *p, const char *fmt, ...);
72
73 int gen_dump_enum(const struct enum_struct *einfo,
74                   struct parse_string *p, 
75                   const char *ptr, 
76                   unsigned indent);
77 int gen_parse_enum(const struct enum_struct *einfo, 
78                    char *ptr, 
79                    const char *str);
80
81 int gen_dump_struct(const struct parse_struct *pinfo,
82                     struct parse_string *p, 
83                     const char *ptr, 
84                     unsigned indent);
85 int gen_parse_struct(const struct parse_struct *pinfo,
86                      char *ptr,
87                      const char *str);
88
89 #define DUMP_PARSE_DECL(type) \
90   int gen_dump_ ## type(struct parse_string *, const char *, unsigned); \
91   int gen_parse_ ## type(char *, const char *);
92
93 DUMP_PARSE_DECL(char)
94 DUMP_PARSE_DECL(int)
95 DUMP_PARSE_DECL(unsigned)
96 DUMP_PARSE_DECL(double)
97 DUMP_PARSE_DECL(float)
98
99 #define gen_dump_unsigned_char gen_dump_char
100 #define gen_parse_unsigned_char gen_parse_char