The code to print events is now part of textDump.c. If part of it is useful
[lttv.git] / ltt / branches / poly / misc / parser.h
CommitLineData
5a1bc7d3 1
2/* Extensible array container */
3
4typedef struct _sequence {
5 int size;
6 int position;
7 void **array;
8} sequence;
9
10void sequence_init(sequence *t);
11void sequence_dispose(sequence *t);
12void sequence_push(sequence *t, void *elem);
13void *sequence_pop(sequence *t);
14
15
16/* Hash table */
17
18typedef struct _table {
19 sequence keys;
20 sequence values;
21} table;
22
23void table_init(table *t);
24void table_dispose(table *t);
25void table_insert(table *t, char *key, void *value);
26void *table_find(table *t, char *key);
27
28
29/* Token types */
30
31typedef enum _token_type {
32 ENDFILE,
33 COMA,
34 LPARENTHESIS,
35 RPARENTHESIS,
36 SEMICOLON,
37 EQUAL,
38 QUOTEDSTRING,
39 NUMBER,
40 NAME
41} token_type;
42
43
44/* State associated with a file being parsed */
45typedef struct _parse_file {
46 char *name;
47 FILE * fp;
48 int lineno;
49 char *buffer;
50 token_type type;
51 int unget;
52 void (*error) (struct _parse_file *, char *);
53} parse_file;
54
55void ungetToken(parse_file * in);
56char *getToken(parse_file *in);
57char *getComa(parse_file *in);
58char *getLParenthesis(parse_file *in);
59char *getRParenthesis(parse_file *in);
60char *getSemiColon(parse_file *in);
61char *getQuotedString(parse_file *in);
62char *getName(parse_file *in);
63int getNumber(parse_file *in);
64char * getEqual(parse_file *in);
65
66void skipComment(parse_file * in);
67void skipEOL(parse_file * in);
68int isalpha(char car);
69int isalnum(char car);
70
71/* Some constants */
72
73static const int BUFFER_SIZE = 1024;
74
75
76/* Events data types */
77
78typedef enum _data_type {
79 INT,
80 UINT,
81 FLOAT,
82 STRING,
83 ENUM,
84 ARRAY,
85 SEQUENCE,
86 STRUCT,
87 NONE
88} data_type;
89
90
91/* Event type descriptors */
92
93typedef struct _type_descriptor {
94 data_type type;
95 char *fmt;
96 int size;
97 sequence labels; // for enumeration
98 sequence fields; // for structure
99 struct _type_descriptor *nested_type; // for array and sequence
100} type_descriptor;
101
102
103/* Fields within types */
104
105typedef struct _field{
106 char *name;
107 char *description;
108 type_descriptor *type;
109} field;
110
111
112/* Events definitions */
113
114typedef struct _event {
115 char *name;
116 char *description;
117 type_descriptor *type;
118 int nested;
119} event;
120
121int getSize(parse_file *in);
122unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type, int * nestedStruct);
123
124void parseEvent(parse_file *in, event *ev, sequence * unnamed_types, table * named_types);
125void parseTypeDefinition(parse_file *in, sequence * unnamed_types, table * named_types);
126type_descriptor *parseType(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
127void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
128void checkNamedTypesImplemented(table * namedTypes);
129type_descriptor * find_named_type(char *name, table * named_types);
130void generateChecksum(char * facName, unsigned long * checksum, sequence * events);
131
132
133
134static char *intOutputTypes[] = {
135 "int8_t", "int16_t", "int32_t", "int64_t", "short int", "int", "long int" };
136
137static char *uintOutputTypes[] = {
138 "uint8_t", "uint16_t", "uint32_t", "uint64_t", "unsigned short int",
139 "unsigned int", "unsigned long int" };
140
141static char *floatOutputTypes[] = {
142 "undef", "undef", "float", "double", "undef", "float", "double" };
143
144
145/* Dynamic memory allocation and freeing */
146
147void * memAlloc(int size);
148char *allocAndCopy(char * str);
149char *appendString(char *s, char *suffix);
150void freeTypes(sequence *t);
151void freeType(type_descriptor * td);
152void freeEvents(sequence *t);
153void freeNamedType(table * t);
154void error_callback(parse_file *in, char *msg);
155
156
157//checksum part
158static const unsigned int crctab32[] =
159{
160#include "crc32.tab"
161};
162
163static inline unsigned long
164partial_crc32_one(unsigned char c, unsigned long crc)
165{
166 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
167}
168
169static inline unsigned long
170partial_crc32(const char *s, unsigned long crc)
171{
172 while (*s)
173 crc = partial_crc32_one(*s++, crc);
174 return crc;
175}
176
177static inline unsigned long
178crc32(const char *s)
179{
180 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
181}
182
This page took 0.028313 seconds and 4 git commands to generate.