7b141a5721fb114535fa91fa44951067d5e31887
1 /******************************************************************************
4 * Event generator. XML to logging C code converter.
9 * Will generate ltt-facility-name.h, ltt-facility-id-name.h
10 * ltt-facility-loader-name.c, ltt-facility-loader-name.h
11 * in the current directory.
15 * - C types : struct, union, enum, basic types.
16 * - Architectures : LP32, ILP32, ILP64, LLP64, LP64.
18 * Additionnal structures supported :
19 * - embedded variable size strings
20 * - embedded variable size arrays
21 * - embedded variable size sequences
25 * enums are limited to integer type, as this is what is used in C. Note,
26 * however, that ISO/IEC 9899:TC2 specify that the type of enum can be char,
27 * unsigned int or int. This is implementation defined (compiler). That's why we
28 * add a check for sizeof enum.
31 * Because of archtecture defined type sizes, we need to ask for ltt_align
32 * (which gives the alignment) by passing basic types, not their actual sizes.
33 * It's up to ltt_align to determine sizes of types.
36 * http://www.usenix.org/publications/login/standards/10.data.html
37 * (Andrew Josey <a.josey@opengroup.org>) :
39 * Data Type LP32 ILP32 ILP64 LLP64 LP64
41 * short 16 16 16 16 16
45 * long long (int64) 64
46 * pointer 32 32 64 64 64
48 * With these constraints :
49 * sizeof(char) <= sizeof(short) <= sizeof(int)
50 * <= sizeof(long) = sizeof(size_t)
52 * and therefore sizeof(long) <= sizeof(pointer) <= sizeof(size_t)
54 * Which means we only have to remember which is the biggest type in a structure
55 * to know the structure's alignment.
59 #include <sys/types.h>
76 /* Type size checking */
77 int print_check(int fd
);
81 int print_types(int fd
);
85 int print_events(int fd
);
89 /* code taken from ltt_facility_open in ltt/facility.c in lttv */
91 /*****************************************************************************
93 * ltt_facility_open : open facilities
95 * pathname : the path name of the facility
97 * Open the facility corresponding to the right checksum.
99 *returns the facility on success, NULL on error.
100 ****************************************************************************/
101 facility_t
*ltt_facility_open(char * pathname
)
106 facility_t
* fac
= NULL
;
107 unsigned long checksum
;
108 char buffer
[BUFFER_SIZE
];
109 int generated
= FALSE
;
111 in
.buffer
= &(buffer
[0]);
113 in
.error
= error_callback
;
117 in
.fp
= fopen(in
.name
, "r");
124 token
= getToken(&in
);
125 if(in
.type
== ENDFILE
) break;
128 printf("More than one facility in the file. Only using the first one.\n");
132 if(strcmp(token
, "<")) in
.error(&in
,"not a facility file");
133 token
= getName(&in
);
135 if(strcmp("facility",token
) == 0) {
136 fac
= malloc(sizeof(facility_t
));
138 fac
->description
= NULL
;
139 sequence_init(&(fac
->events
));
140 table_init(&(fac
->named_types
));
141 sequence_init(&(fac
->unnamed_types
));
143 parseFacility(&in
, fac
);
145 //check if any namedType is not defined
146 checkNamedTypesImplemented(&fac
->named_types
);
148 generateChecksum(fac
->name
, &checksum
, &fac
->events
);
153 printf("facility token was expected in file %s\n", in
.name
);
164 printf("Cannot find facility %s\n", pathname
);
171 /* Close the facility */
172 void ltt_facility_close(facility_t
*fac
)
176 free(fac
->description
);
177 freeEvents(&fac
->events
);
178 sequence_dispose(&fac
->events
);
179 freeNamedType(&fac
->named_types
);
180 table_dispose(&fac
->named_types
);
181 freeTypes(&fac
->unnamed_types
);
182 sequence_dispose(&fac
->unnamed_types
);
188 void show_help(int argc
, char ** argv
)
190 printf("Genevent help : \n");
192 printf("Use %s name.xml\n", argv
[0]);
193 printf("to create :\n");
194 printf("ltt-facility-name.h\n");
195 printf("ltt-facility-id-name.h\n");
196 printf("ltt-facility-loader-name.h\n");
197 printf("ltt-facility-loader-name.c\n");
198 printf("In the current directory.\n");
202 /* Parse program arguments */
204 * 0 : continue program
205 * -1 : stop program, return 0
206 * > 0 : stop program, return value as exit.
208 int check_args(int argc
, char **argv
)
211 printf("Not enough arguments\n");
212 show_help(argc
, argv
);
216 if(strcmp(argv
[1], "-h") == 0) {
217 show_help(argc
, argv
);
224 int main(int argc
, char **argv
)
229 err
= check_args(argc
, argv
);
230 if(err
> 0) return err
;
231 else if(err
< 0) return 0;
233 /* open the facility */
234 fac
= ltt_facility_open(argv
[1]);
236 printf("Error opening file %s for reading : %s\n",
237 argv
[1], strerror(errno
));
241 /* generate the output C files */
244 /* ltt-facility-name.h : main logging header */
247 /* ltt-facility-id-name.h : facility id. */
250 /* ltt-facility-loader-name.h : facility specific loader info. */
252 /* ltt-facility-loader-name.c : generic faciilty loader */
256 /* close the facility */
257 ltt_facility_close(fac
);
This page took 0.037602 seconds and 3 git commands to generate.