* size
*****************************************************************************/
-int getSize(parse_file *in)
+int getSize(parse_file_t *in)
{
char *token;
* msg : message to be printed
****************************************************************************/
-void error_callback(parse_file *in, char *msg)
+void error_callback(parse_file_t *in, char *msg)
{
if(in)
printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg);
*
**************************************************************************/
-void getTypeAttributes(parse_file *in, type_descriptor *t)
+void getTypeAttributes(parse_file_t *in, type_descriptor_t *t)
{
char * token;
char car;
*
**************************************************************************/
-void getEventAttributes(parse_file *in, event *ev)
+void getEventAttributes(parse_file_t *in, event_t *ev)
{
char * token;
char car;
*
**************************************************************************/
-void getFacilityAttributes(parse_file *in, facility *fac)
+void getFacilityAttributes(parse_file_t *in, facility_t *fac)
{
char * token;
char car;
*
**************************************************************************/
-void getFieldAttributes(parse_file *in, field *f)
+void getFieldAttributes(parse_file_t *in, field_t *f)
{
char * token;
char car;
}
}
-char *getNameAttribute(parse_file *in)
+char *getNameAttribute(parse_file_t *in)
{
char * token;
char *name = NULL;
//for <label name=label_name value=n format="..."/>, value is an option
-char * getValueStrAttribute(parse_file *in)
+char * getValueStrAttribute(parse_file_t *in)
{
char * token;
return token;
}
-char * getDescription(parse_file *in)
+char * getDescription(parse_file_t *in)
{
long int pos;
char * token, car, *str;
* fac : facility filled with event list
****************************************************************************/
-void parseFacility(parse_file *in, facility * fac)
+void parseFacility(parse_file_t *in, facility_t * fac)
{
char * token;
- event *ev;
+ event_t *ev;
getFacilityAttributes(in, fac);
if(fac->name == NULL) in->error(in, "Attribute not named");
in->error(in,"the definition of the facility is not finished");
if(strcmp("event",token) == 0){
- ev = (event*) memAlloc(sizeof(event));
+ ev = (event_t*) memAlloc(sizeof(event_t));
sequence_push(&(fac->events),ev);
parseEvent(in,ev, &(fac->unnamed_types), &(fac->named_types));
}else if(strcmp("type",token) == 0){
* ev : new event (parameters are passed to it)
****************************************************************************/
-void parseEvent(parse_file *in, event * ev, sequence * unnamed_types,
- table * named_types)
+void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types,
+ table_t * named_types)
{
char *token;
- type_descriptor *t;
+ type_descriptor_t *t;
//<event name=eventtype_name>
getEventAttributes(in, ev);
* named_types : array of named types
****************************************************************************/
-void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types,
- table * named_types)
+void parseFields(parse_file_t *in, type_descriptor_t *t,
+ sequence_t * unnamed_types,
+ table_t * named_types)
{
char * token;
- field *f;
+ field_t *f;
- f = (field *)memAlloc(sizeof(field));
+ f = (field_t *)memAlloc(sizeof(field_t));
sequence_push(&(t->fields),f);
//<field name=field_name> <description> <type> </field>
* type_descriptor* : a type descriptor
****************************************************************************/
-type_descriptor *parseType(parse_file *in, type_descriptor *inType,
- sequence * unnamed_types, table * named_types)
+type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
+ sequence_t * unnamed_types, table_t * named_types)
{
char *token;
- type_descriptor *t;
+ type_descriptor_t *t;
if(inType == NULL) {
- t = (type_descriptor *) memAlloc(sizeof(type_descriptor));
+ t = (type_descriptor_t *) memAlloc(sizeof(type_descriptor_t));
t->type_name = NULL;
t->type = NONE;
t->fmt = NULL;
* type_descriptor * : a type descriptor
*****************************************************************************/
-type_descriptor * find_named_type(char *name, table * named_types)
+type_descriptor_t * find_named_type(char *name, table_t * named_types)
{
- type_descriptor *t;
+ type_descriptor_t *t;
t = table_find(named_types,name);
if(t == NULL) {
- t = (type_descriptor *)memAlloc(sizeof(type_descriptor));
+ t = (type_descriptor_t *)memAlloc(sizeof(type_descriptor_t));
t->type_name = allocAndCopy(name);
t->type = NONE;
t->fmt = NULL;
* named_types : array of named types
*****************************************************************************/
-void parseTypeDefinition(parse_file * in, sequence * unnamed_types,
- table * named_types)
+void parseTypeDefinition(parse_file_t * in, sequence_t * unnamed_types,
+ table_t * named_types)
{
char *token;
- type_descriptor *t;
+ type_descriptor_t *t;
token = getNameAttribute(in);
if(token == NULL) in->error(in, "Type has empty name");
*
**************************************************************************/
-char *getName(parse_file * in)
+char *getName(parse_file_t * in)
{
char *token;
return token;
}
-int getNumber(parse_file * in)
+int getNumber(parse_file_t * in)
{
char *token;
return atoi(token);
}
-char *getForwardslash(parse_file * in)
+char *getForwardslash(parse_file_t * in)
{
char *token;
return token;
}
-char *getLAnglebracket(parse_file * in)
+char *getLAnglebracket(parse_file_t * in)
{
char *token;
return token;
}
-char *getRAnglebracket(parse_file * in)
+char *getRAnglebracket(parse_file_t * in)
{
char *token;
return token;
}
-char *getQuotedString(parse_file * in)
+char *getQuotedString(parse_file_t * in)
{
char *token;
return token;
}
-char * getEqual(parse_file *in)
+char * getEqual(parse_file_t *in)
{
char *token;
return token;
}
-char seekNextChar(parse_file *in)
+char seekNextChar(parse_file_t *in)
{
char car;
while((car = getc(in->fp)) != EOF) {
*
******************************************************************/
-void ungetToken(parse_file * in)
+void ungetToken(parse_file_t * in)
{
in->unget = 1;
}
-char *getToken(parse_file * in)
+char *getToken(parse_file_t * in)
{
FILE *fp = in->fp;
char car, car1;
return in->buffer;
}
-void skipComment(parse_file * in)
+void skipComment(parse_file_t * in)
{
char car;
while((car = getc(in->fp)) != EOF) {
if(car == EOF) in->error(in,"comment begining with '/*' has no ending '*/'");
}
-void skipEOL(parse_file * in)
+void skipEOL(parse_file_t * in)
{
char car;
while((car = getc(in->fp)) != EOF) {
* checkNamedTypesImplemented : check if all named types have definition
****************************************************************************/
-void checkNamedTypesImplemented(table * named_types)
+void checkNamedTypesImplemented(table_t * named_types)
{
- type_descriptor *t;
+ type_descriptor_t *t;
int pos;
char str[256];
for(pos = 0 ; pos < named_types->values.position; pos++) {
- t = (type_descriptor *) named_types->values.array[pos];
+ t = (type_descriptor_t *) named_types->values.array[pos];
if(t->type == NONE){
- sprintf(str,"named type '%s' has no definition",(char*)named_types->keys.array[pos]);
+ sprintf(str,"named type '%s' has no definition",
+ (char*)named_types->keys.array[pos]);
error_callback(NULL,str);
}
}
* checksum : checksum for the facility
****************************************************************************/
-void generateChecksum( char* facName, unsigned long * checksum, sequence * events)
+void generateChecksum(char* facName,
+ unsigned long * checksum, sequence_t * events)
{
unsigned long crc ;
int pos;
- event * ev;
+ event_t * ev;
char str[256];
crc = crc32(facName);
for(pos = 0; pos < events->position; pos++){
- ev = (event *)(events->array[pos]);
+ ev = (event_t *)(events->array[pos]);
crc = partial_crc32(ev->name,crc);
if(!ev->type) continue; //event without type
if(ev->type->type != STRUCT){
* unsigned long : checksum
*****************************************************************************/
-unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type)
+unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type)
{
unsigned long crc = aCrc;
char * str = NULL, buf[16];
int flag = 0, pos;
- field * fld;
+ field_t * fld;
switch(type->type){
case INT:
crc = getTypeChecksum(crc,type->nested_type);
}else if(type->type == STRUCT || type->type == UNION){
for(pos =0; pos < type->fields.position; pos++){
- fld = (field *) type->fields.array[pos];
+ fld = (field_t *) type->fields.array[pos];
crc = partial_crc32(fld->name,crc);
crc = getTypeChecksum(crc, fld->type);
}
/* Event type descriptors */
-void freeType(type_descriptor * tp)
+void freeType(type_descriptor_t * tp)
{
int pos2;
- field *f;
+ field_t *f;
if(tp->fmt != NULL) free(tp->fmt);
if(tp->type == ENUM) {
}
if(tp->type == STRUCT) {
for(pos2 = 0; pos2 < tp->fields.position; pos2++) {
- f = (field *) tp->fields.array[pos2];
+ f = (field_t *) tp->fields.array[pos2];
free(f->name);
free(f->description);
free(f);
}
}
-void freeNamedType(table * t)
+void freeNamedType(table_t * t)
{
int pos;
- type_descriptor * td;
+ type_descriptor_t * td;
for(pos = 0 ; pos < t->keys.position; pos++) {
free((char *)t->keys.array[pos]);
- td = (type_descriptor*)t->values.array[pos];
+ td = (type_descriptor_t*)t->values.array[pos];
freeType(td);
free(td);
}
}
-void freeTypes(sequence *t)
+void freeTypes(sequence_t *t)
{
int pos, pos2;
- type_descriptor *tp;
- field *f;
+ type_descriptor_t *tp;
+ field_t *f;
for(pos = 0 ; pos < t->position; pos++) {
- tp = (type_descriptor *)t->array[pos];
+ tp = (type_descriptor_t *)t->array[pos];
freeType(tp);
free(tp);
}
}
-void freeEvents(sequence *t)
+void freeEvents(sequence_t *t)
{
int pos;
- event *ev;
+ event_t *ev;
for(pos = 0 ; pos < t->position; pos++) {
- ev = (event *) t->array[pos];
+ ev = (event_t *) t->array[pos];
free(ev->name);
free(ev->description);
free(ev);
/* Extensible array */
-void sequence_init(sequence *t)
+void sequence_init(sequence_t *t)
{
t->size = 10;
t->position = 0;
t->array = (void **)memAlloc(t->size * sizeof(void *));
}
-void sequence_dispose(sequence *t)
+void sequence_dispose(sequence_t *t)
{
t->size = 0;
free(t->array);
t->array = NULL;
}
-void sequence_push(sequence *t, void *elem)
+void sequence_push(sequence_t *t, void *elem)
{
void **tmp;
t->position++;
}
-void *sequence_pop(sequence *t)
+void *sequence_pop(sequence_t *t)
{
return t->array[t->position--];
}
/* Hash table API, implementation is just linear search for now */
-void table_init(table *t)
+void table_init(table_t *t)
{
sequence_init(&(t->keys));
sequence_init(&(t->values));
}
-void table_dispose(table *t)
+void table_dispose(table_t *t)
{
sequence_dispose(&(t->keys));
sequence_dispose(&(t->values));
}
-void table_insert(table *t, char *key, void *value)
+void table_insert(table_t *t, char *key, void *value)
{
sequence_push(&(t->keys),key);
sequence_push(&(t->values),value);
}
-void *table_find(table *t, char *key)
+void *table_find(table_t *t, char *key)
{
int pos;
for(pos = 0 ; pos < t->keys.position; pos++) {
return NULL;
}
-void table_insert_int(table *t, int *key, void *value)
+void table_insert_int(table_t *t, int *key, void *value)
{
sequence_push(&(t->keys),key);
sequence_push(&(t->values),value);
}
-void *table_find_int(table *t, int *key)
+void *table_find_int(table_t *t, int *key)
{
int pos;
for(pos = 0 ; pos < t->keys.position; pos++) {
int size;
int position;
void **array;
-} sequence;
+} sequence_t;
-void sequence_init(sequence *t);
-void sequence_dispose(sequence *t);
-void sequence_push(sequence *t, void *elem);
-void *sequence_pop(sequence *t);
+void sequence_init(sequence_t *t);
+void sequence_dispose(sequence_t *t);
+void sequence_push(sequence_t *t, void *elem);
+void *sequence_pop(sequence_t *t);
/* Hash table */
typedef struct _table {
- sequence keys;
- sequence values;
-} table;
+ sequence_t keys;
+ sequence_t values;
+} table_t;
-void table_init(table *t);
-void table_dispose(table *t);
-void table_insert(table *t, char *key, void *value);
-void *table_find(table *t, char *key);
-void table_insert_int(table *t, int *key, void *value);
-void *table_find_int(table *t, int *key);
+void table_init(table_t *t);
+void table_dispose(table_t *t);
+void table_insert(table_t *t, char *key, void *value);
+void *table_find(table_t *t, char *key);
+void table_insert_int(table_t *t, int *key, void *value);
+void *table_find_int(table_t *t, int *key);
/* Token types */
QUOTEDSTRING,
NUMBER,
NAME
-} token_type;
+} token_type_t;
/* State associated with a file being parsed */
FILE * fp;
int lineno;
char *buffer;
- token_type type;
+ token_type_t type;
int unget;
void (*error) (struct _parse_file *, char *);
-} parse_file;
-
-void ungetToken(parse_file * in);
-char *getToken(parse_file *in);
-char *getForwardslash(parse_file *in);
-char *getLAnglebracket(parse_file *in);
-char *getRAnglebracket(parse_file *in);
-char *getQuotedString(parse_file *in);
-char *getName(parse_file *in);
-int getNumber(parse_file *in);
-char *getEqual(parse_file *in);
-char seekNextChar(parse_file *in);
-
-void skipComment(parse_file * in);
-void skipEOL(parse_file * in);
+} parse_file_t;
+
+void ungetToken(parse_file_t * in);
+char *getToken(parse_file_t *in);
+char *getForwardslash(parse_file_t *in);
+char *getLAnglebracket(parse_file_t *in);
+char *getRAnglebracket(parse_file_t *in);
+char *getQuotedString(parse_file_t *in);
+char *getName(parse_file_t *in);
+int getNumber(parse_file_t *in);
+char *getEqual(parse_file_t *in);
+char seekNextChar(parse_file_t *in);
+
+void skipComment(parse_file_t * in);
+void skipEOL(parse_file_t * in);
/* Some constants */
STRUCT,
UNION,
NONE
-} data_type;
+} data_type_t;
/* Event type descriptors */
typedef struct _type_descriptor {
char * type_name; //used for named type
- data_type type;
+ data_type_t type;
char *fmt;
int size;
- sequence labels; // for enumeration
- sequence labels_description;
+ sequence_t labels; // for enumeration
+ sequence_t labels_description;
int already_printed;
- sequence fields; // for structure
+ sequence_t fields; // for structure
struct _type_descriptor *nested_type; // for array and sequence
int alignment;
-} type_descriptor;
+} type_descriptor_t;
/* Fields within types */
typedef struct _field{
char *name;
char *description;
- type_descriptor *type;
-} field;
+ type_descriptor_t *type;
+} field_t;
/* Events definitions */
typedef struct _event {
char *name;
char *description;
- type_descriptor *type;
+ type_descriptor_t *type;
int per_trace; /* Is the event able to be logged to a specific trace ? */
int per_tracefile; /* Must we log this event in a specific tracefile ? */
-} event;
+} event_t;
typedef struct _facility {
char * name;
char * capname;
char * description;
- sequence events;
- sequence unnamed_types;
- table named_types;
-} facility;
-
-int getSize(parse_file *in);
-unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type);
-
-void parseFacility(parse_file *in, facility * fac);
-void parseEvent(parse_file *in, event *ev, sequence * unnamed_types, table * named_types);
-void parseTypeDefinition(parse_file *in, sequence * unnamed_types, table * named_types);
-type_descriptor *parseType(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
-void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
-void checkNamedTypesImplemented(table * namedTypes);
-type_descriptor * find_named_type(char *name, table * named_types);
-void generateChecksum(char * facName, unsigned long * checksum, sequence * events);
+ sequence_t events;
+ sequence_t unnamed_types;
+ table_t named_types;
+} facility_t;
+
+int getSize(parse_file_t *in);
+unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
+
+void parseFacility(parse_file_t *in, facility_t * fac);
+void parseEvent(parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
+ table_t * named_types);
+void parseTypeDefinition(parse_file_t *in,
+ sequence_t * unnamed_types, table_t * named_types);
+type_descriptor_t *parseType(parse_file_t *in,
+ type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
+void parseFields(parse_file_t *in, type_descriptor_t *t,
+ sequence_t * unnamed_types, table_t * named_types);
+void checkNamedTypesImplemented(table_t * namedTypes);
+type_descriptor_t * find_named_type(char *name, table_t * named_types);
+void generateChecksum(char * facName,
+ unsigned long * checksum, sequence_t * events);
/* get attributes */
-char * getNameAttribute(parse_file *in);
-char * getFormatAttribute(parse_file *in);
-int getSizeAttribute(parse_file *in);
-int getValueAttribute(parse_file *in);
-char * getValueStrAttribute(parse_file *in);
+char * getNameAttribute(parse_file_t *in);
+char * getFormatAttribute(parse_file_t *in);
+int getSizeAttribute(parse_file_t *in);
+int getValueAttribute(parse_file_t *in);
+char * getValueStrAttribute(parse_file_t *in);
-char * getDescription(parse_file *in);
+char * getDescription(parse_file_t *in);
static char *intOutputTypes[] = {
void * memAlloc(int size);
char *allocAndCopy(char * str);
char *appendString(char *s, char *suffix);
-void freeTypes(sequence *t);
-void freeType(type_descriptor * td);
-void freeEvents(sequence *t);
-void freeNamedType(table * t);
-void error_callback(parse_file *in, char *msg);
+void freeTypes(sequence_t *t);
+void freeType(type_descriptor_t * td);
+void freeEvents(sequence_t *t);
+void freeNamedType(table_t * t);
+void error_callback(parse_file_t *in, char *msg);
//checksum part
/* search for the (named) type in the table, if it does not exist
create a new one */
-LttType * lookup_named_type(LttFacility *fac, type_descriptor * td);
+LttType * lookup_named_type(LttFacility *fac, type_descriptor_t * td);
/* construct directed acyclic graph for types, and tree for fields */
-void construct_types_and_fields(LttFacility * fac,type_descriptor * td,
+void construct_types_and_fields(LttFacility * fac, type_descriptor_t * td,
LttField * fld);
/* generate the facility according to the events belongin to it */
int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname)
{
gchar *token;
- parse_file in;
+ parse_file_t in;
gsize length;
facility_t * fac;
- guint32 checksum;
+ unsigned long checksum;
GError * error = NULL;
gchar buffer[BUFFER_SIZE];
in.error = error_callback;
in.name = pathname;
- in.fd = g_open(in.name, O_RDONLY, 0);
- if(in.fd < 0 ) {
+ //in.fd = g_open(in.name, O_RDONLY, 0);
+ //if(in.fd < 0 ) {
+ in.fp = fopen(in.name, "r");
+ if(in.fp < 0 ) {
g_warning("cannot open facility description file %s",
in.name);
return 1;
}
- in.channel = g_io_channel_unix_new(in.fd);
- in.pos = 0;
+ //in.channel = g_io_channel_unix_new(in.fd);
+ //in.pos = 0;
while(1){
token = getToken(&in);
parseFacility(&in, fac);
//check if any namedType is not defined
- g_assert(checkNamedTypesImplemented(&fac->named_types) == 0);
+ checkNamedTypesImplemented(&fac->named_types);
- g_assert(generateChecksum(fac->name, &checksum, &fac->events) == 0);
+ generateChecksum(fac->name, &checksum, &fac->events);
generateFacility(f, fac, checksum);
}
parse_error:
- g_io_channel_shutdown(in.channel, FALSE, &error); /* No flush */
- if(error != NULL) {
- g_warning("Can not close file: \n%s\n", error->message);
- g_error_free(error);
- }
+ //g_io_channel_shutdown(in.channel, FALSE, &error); /* No flush */
+ //if(error != NULL) {
+ fclose(in.fp);
+ // g_warning("Can not close file: \n%s\n", error->message);
+ // g_error_free(error);
+ //}
- g_close(in.fd);
+ //g_close(in.fd);
}
void generateFacility(LttFacility *f, facility_t *fac, guint32 checksum)
{
char * facilityName = fac->name;
- sequence * events = &fac->events;
+ sequence_t * events = &fac->events;
int i;
//LttEventType * evType;
LttEventType * event_type;
****************************************************************************/
-void construct_types_and_fields(LttFacility * fac, type_descriptor * td,
+void construct_types_and_fields(LttFacility * fac, type_descriptor_t * td,
LttField * fld)
{
int i, flag;
- type_descriptor * tmpTd;
+ type_descriptor_t * tmpTd;
switch(td->type) {
case LTT_ENUM:
fld->child = g_new(LttField*, td->fields.position);
for(i=0;i<td->fields.position;i++){
- tmpTd = ((type_fields*)(td->fields.array[i]))->type;
+ tmpTd = ((field_t*)(td->fields.array[i]))->type;
fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
fld->child[i] = g_new(LttField,1);
fld->child[i]->field_type = fld->field_type->element_type[i];
fld->child[i]->field_type->element_name
- = g_quark_from_string(((type_fields*)(td->fields.array[i]))->name);
+ = g_quark_from_string(((field_t*)(td->fields.array[i]))->name);
fld->child[i]->offset_root = 0;
fld->child[i]->fixed_root = FIELD_UNKNOWN;
* : either find the named type, or create a new LttType
****************************************************************************/
-LttType * lookup_named_type(LttFacility *fac, type_descriptor * td)
+LttType * lookup_named_type(LttFacility *fac, type_descriptor_t * td)
{
GQuark name = g_quark_from_string(td->type_name);
* size
*****************************************************************************/
-int getSize(parse_file *in)
+int getSize(parse_file_t *in)
{
char *token;
* msg : message to be printed
****************************************************************************/
-void error_callback(parse_file *in, char *msg)
+void error_callback(parse_file_t *in, char *msg)
{
if(in)
printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg);
*
**************************************************************************/
-void getTypeAttributes(parse_file *in, type_descriptor *t)
+void getTypeAttributes(parse_file_t *in, type_descriptor_t *t)
{
char * token;
char car;
*
**************************************************************************/
-void getEventAttributes(parse_file *in, event *ev)
+void getEventAttributes(parse_file_t *in, event_t *ev)
{
char * token;
char car;
*
**************************************************************************/
-void getFacilityAttributes(parse_file *in, facility *fac)
+void getFacilityAttributes(parse_file_t *in, facility_t *fac)
{
char * token;
char car;
*
**************************************************************************/
-void getFieldAttributes(parse_file *in, field *f)
+void getFieldAttributes(parse_file_t *in, field_t *f)
{
char * token;
char car;
}
}
-char *getNameAttribute(parse_file *in)
+char *getNameAttribute(parse_file_t *in)
{
char * token;
char *name = NULL;
//for <label name=label_name value=n format="..."/>, value is an option
-char * getValueStrAttribute(parse_file *in)
+char * getValueStrAttribute(parse_file_t *in)
{
char * token;
return token;
}
-char * getDescription(parse_file *in)
+char * getDescription(parse_file_t *in)
{
long int pos;
char * token, car, *str;
* fac : facility filled with event list
****************************************************************************/
-void parseFacility(parse_file *in, facility * fac)
+void parseFacility(parse_file_t *in, facility_t * fac)
{
char * token;
- event *ev;
+ event_t *ev;
getFacilityAttributes(in, fac);
if(fac->name == NULL) in->error(in, "Attribute not named");
in->error(in,"the definition of the facility is not finished");
if(strcmp("event",token) == 0){
- ev = (event*) memAlloc(sizeof(event));
+ ev = (event_t*) memAlloc(sizeof(event_t));
sequence_push(&(fac->events),ev);
parseEvent(in,ev, &(fac->unnamed_types), &(fac->named_types));
}else if(strcmp("type",token) == 0){
* ev : new event (parameters are passed to it)
****************************************************************************/
-void parseEvent(parse_file *in, event * ev, sequence * unnamed_types,
- table * named_types)
+void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types,
+ table_t * named_types)
{
char *token;
- type_descriptor *t;
+ type_descriptor_t *t;
//<event name=eventtype_name>
getEventAttributes(in, ev);
* named_types : array of named types
****************************************************************************/
-void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types,
- table * named_types)
+void parseFields(parse_file_t *in, type_descriptor_t *t,
+ sequence_t * unnamed_types,
+ table_t * named_types)
{
char * token;
- field *f;
+ field_t *f;
- f = (field *)memAlloc(sizeof(field));
+ f = (field_t *)memAlloc(sizeof(field_t));
sequence_push(&(t->fields),f);
//<field name=field_name> <description> <type> </field>
* type_descriptor* : a type descriptor
****************************************************************************/
-type_descriptor *parseType(parse_file *in, type_descriptor *inType,
- sequence * unnamed_types, table * named_types)
+type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
+ sequence_t * unnamed_types, table_t * named_types)
{
char *token;
- type_descriptor *t;
+ type_descriptor_t *t;
if(inType == NULL) {
- t = (type_descriptor *) memAlloc(sizeof(type_descriptor));
+ t = (type_descriptor_t *) memAlloc(sizeof(type_descriptor_t));
t->type_name = NULL;
t->type = NONE;
t->fmt = NULL;
* type_descriptor * : a type descriptor
*****************************************************************************/
-type_descriptor * find_named_type(char *name, table * named_types)
+type_descriptor_t * find_named_type(char *name, table_t * named_types)
{
- type_descriptor *t;
+ type_descriptor_t *t;
t = table_find(named_types,name);
if(t == NULL) {
- t = (type_descriptor *)memAlloc(sizeof(type_descriptor));
+ t = (type_descriptor_t *)memAlloc(sizeof(type_descriptor_t));
t->type_name = allocAndCopy(name);
t->type = NONE;
t->fmt = NULL;
* named_types : array of named types
*****************************************************************************/
-void parseTypeDefinition(parse_file * in, sequence * unnamed_types,
- table * named_types)
+void parseTypeDefinition(parse_file_t * in, sequence_t * unnamed_types,
+ table_t * named_types)
{
char *token;
- type_descriptor *t;
+ type_descriptor_t *t;
token = getNameAttribute(in);
if(token == NULL) in->error(in, "Type has empty name");
*
**************************************************************************/
-char *getName(parse_file * in)
+char *getName(parse_file_t * in)
{
char *token;
return token;
}
-int getNumber(parse_file * in)
+int getNumber(parse_file_t * in)
{
char *token;
return atoi(token);
}
-char *getForwardslash(parse_file * in)
+char *getForwardslash(parse_file_t * in)
{
char *token;
return token;
}
-char *getLAnglebracket(parse_file * in)
+char *getLAnglebracket(parse_file_t * in)
{
char *token;
return token;
}
-char *getRAnglebracket(parse_file * in)
+char *getRAnglebracket(parse_file_t * in)
{
char *token;
return token;
}
-char *getQuotedString(parse_file * in)
+char *getQuotedString(parse_file_t * in)
{
char *token;
return token;
}
-char * getEqual(parse_file *in)
+char * getEqual(parse_file_t *in)
{
char *token;
return token;
}
-char seekNextChar(parse_file *in)
+char seekNextChar(parse_file_t *in)
{
char car;
while((car = getc(in->fp)) != EOF) {
*
******************************************************************/
-void ungetToken(parse_file * in)
+void ungetToken(parse_file_t * in)
{
in->unget = 1;
}
-char *getToken(parse_file * in)
+char *getToken(parse_file_t * in)
{
FILE *fp = in->fp;
char car, car1;
return in->buffer;
}
-void skipComment(parse_file * in)
+void skipComment(parse_file_t * in)
{
char car;
while((car = getc(in->fp)) != EOF) {
if(car == EOF) in->error(in,"comment begining with '/*' has no ending '*/'");
}
-void skipEOL(parse_file * in)
+void skipEOL(parse_file_t * in)
{
char car;
while((car = getc(in->fp)) != EOF) {
* checkNamedTypesImplemented : check if all named types have definition
****************************************************************************/
-void checkNamedTypesImplemented(table * named_types)
+void checkNamedTypesImplemented(table_t * named_types)
{
- type_descriptor *t;
+ type_descriptor_t *t;
int pos;
char str[256];
for(pos = 0 ; pos < named_types->values.position; pos++) {
- t = (type_descriptor *) named_types->values.array[pos];
+ t = (type_descriptor_t *) named_types->values.array[pos];
if(t->type == NONE){
- sprintf(str,"named type '%s' has no definition",(char*)named_types->keys.array[pos]);
+ sprintf(str,"named type '%s' has no definition",
+ (char*)named_types->keys.array[pos]);
error_callback(NULL,str);
}
}
* checksum : checksum for the facility
****************************************************************************/
-void generateChecksum( char* facName, unsigned long * checksum, sequence * events)
+void generateChecksum(char* facName,
+ unsigned long * checksum, sequence_t * events)
{
unsigned long crc ;
int pos;
- event * ev;
+ event_t * ev;
char str[256];
crc = crc32(facName);
for(pos = 0; pos < events->position; pos++){
- ev = (event *)(events->array[pos]);
+ ev = (event_t *)(events->array[pos]);
crc = partial_crc32(ev->name,crc);
if(!ev->type) continue; //event without type
if(ev->type->type != STRUCT){
* unsigned long : checksum
*****************************************************************************/
-unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type)
+unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type)
{
unsigned long crc = aCrc;
char * str = NULL, buf[16];
int flag = 0, pos;
- field * fld;
+ field_t * fld;
switch(type->type){
case INT:
crc = getTypeChecksum(crc,type->nested_type);
}else if(type->type == STRUCT || type->type == UNION){
for(pos =0; pos < type->fields.position; pos++){
- fld = (field *) type->fields.array[pos];
+ fld = (field_t *) type->fields.array[pos];
crc = partial_crc32(fld->name,crc);
crc = getTypeChecksum(crc, fld->type);
}
/* Event type descriptors */
-void freeType(type_descriptor * tp)
+void freeType(type_descriptor_t * tp)
{
int pos2;
- field *f;
+ field_t *f;
if(tp->fmt != NULL) free(tp->fmt);
if(tp->type == ENUM) {
}
if(tp->type == STRUCT) {
for(pos2 = 0; pos2 < tp->fields.position; pos2++) {
- f = (field *) tp->fields.array[pos2];
+ f = (field_t *) tp->fields.array[pos2];
free(f->name);
free(f->description);
free(f);
}
}
-void freeNamedType(table * t)
+void freeNamedType(table_t * t)
{
int pos;
- type_descriptor * td;
+ type_descriptor_t * td;
for(pos = 0 ; pos < t->keys.position; pos++) {
free((char *)t->keys.array[pos]);
- td = (type_descriptor*)t->values.array[pos];
+ td = (type_descriptor_t*)t->values.array[pos];
freeType(td);
free(td);
}
}
-void freeTypes(sequence *t)
+void freeTypes(sequence_t *t)
{
int pos, pos2;
- type_descriptor *tp;
- field *f;
+ type_descriptor_t *tp;
+ field_t *f;
for(pos = 0 ; pos < t->position; pos++) {
- tp = (type_descriptor *)t->array[pos];
+ tp = (type_descriptor_t *)t->array[pos];
freeType(tp);
free(tp);
}
}
-void freeEvents(sequence *t)
+void freeEvents(sequence_t *t)
{
int pos;
- event *ev;
+ event_t *ev;
for(pos = 0 ; pos < t->position; pos++) {
- ev = (event *) t->array[pos];
+ ev = (event_t *) t->array[pos];
free(ev->name);
free(ev->description);
free(ev);
/* Extensible array */
-void sequence_init(sequence *t)
+void sequence_init(sequence_t *t)
{
t->size = 10;
t->position = 0;
t->array = (void **)memAlloc(t->size * sizeof(void *));
}
-void sequence_dispose(sequence *t)
+void sequence_dispose(sequence_t *t)
{
t->size = 0;
free(t->array);
t->array = NULL;
}
-void sequence_push(sequence *t, void *elem)
+void sequence_push(sequence_t *t, void *elem)
{
void **tmp;
t->position++;
}
-void *sequence_pop(sequence *t)
+void *sequence_pop(sequence_t *t)
{
return t->array[t->position--];
}
/* Hash table API, implementation is just linear search for now */
-void table_init(table *t)
+void table_init(table_t *t)
{
sequence_init(&(t->keys));
sequence_init(&(t->values));
}
-void table_dispose(table *t)
+void table_dispose(table_t *t)
{
sequence_dispose(&(t->keys));
sequence_dispose(&(t->values));
}
-void table_insert(table *t, char *key, void *value)
+void table_insert(table_t *t, char *key, void *value)
{
sequence_push(&(t->keys),key);
sequence_push(&(t->values),value);
}
-void *table_find(table *t, char *key)
+void *table_find(table_t *t, char *key)
{
int pos;
for(pos = 0 ; pos < t->keys.position; pos++) {
return NULL;
}
-void table_insert_int(table *t, int *key, void *value)
+void table_insert_int(table_t *t, int *key, void *value)
{
sequence_push(&(t->keys),key);
sequence_push(&(t->values),value);
}
-void *table_find_int(table *t, int *key)
+void *table_find_int(table_t *t, int *key)
{
int pos;
for(pos = 0 ; pos < t->keys.position; pos++) {
int size;
int position;
void **array;
-} sequence;
+} sequence_t;
-void sequence_init(sequence *t);
-void sequence_dispose(sequence *t);
-void sequence_push(sequence *t, void *elem);
-void *sequence_pop(sequence *t);
+void sequence_init(sequence_t *t);
+void sequence_dispose(sequence_t *t);
+void sequence_push(sequence_t *t, void *elem);
+void *sequence_pop(sequence_t *t);
/* Hash table */
typedef struct _table {
- sequence keys;
- sequence values;
-} table;
+ sequence_t keys;
+ sequence_t values;
+} table_t;
-void table_init(table *t);
-void table_dispose(table *t);
-void table_insert(table *t, char *key, void *value);
-void *table_find(table *t, char *key);
-void table_insert_int(table *t, int *key, void *value);
-void *table_find_int(table *t, int *key);
+void table_init(table_t *t);
+void table_dispose(table_t *t);
+void table_insert(table_t *t, char *key, void *value);
+void *table_find(table_t *t, char *key);
+void table_insert_int(table_t *t, int *key, void *value);
+void *table_find_int(table_t *t, int *key);
/* Token types */
QUOTEDSTRING,
NUMBER,
NAME
-} token_type;
+} token_type_t;
/* State associated with a file being parsed */
FILE * fp;
int lineno;
char *buffer;
- token_type type;
+ token_type_t type;
int unget;
void (*error) (struct _parse_file *, char *);
-} parse_file;
-
-void ungetToken(parse_file * in);
-char *getToken(parse_file *in);
-char *getForwardslash(parse_file *in);
-char *getLAnglebracket(parse_file *in);
-char *getRAnglebracket(parse_file *in);
-char *getQuotedString(parse_file *in);
-char *getName(parse_file *in);
-int getNumber(parse_file *in);
-char *getEqual(parse_file *in);
-char seekNextChar(parse_file *in);
-
-void skipComment(parse_file * in);
-void skipEOL(parse_file * in);
+} parse_file_t;
+
+void ungetToken(parse_file_t * in);
+char *getToken(parse_file_t *in);
+char *getForwardslash(parse_file_t *in);
+char *getLAnglebracket(parse_file_t *in);
+char *getRAnglebracket(parse_file_t *in);
+char *getQuotedString(parse_file_t *in);
+char *getName(parse_file_t *in);
+int getNumber(parse_file_t *in);
+char *getEqual(parse_file_t *in);
+char seekNextChar(parse_file_t *in);
+
+void skipComment(parse_file_t * in);
+void skipEOL(parse_file_t * in);
/* Some constants */
STRUCT,
UNION,
NONE
-} data_type;
+} data_type_t;
/* Event type descriptors */
typedef struct _type_descriptor {
char * type_name; //used for named type
- data_type type;
+ data_type_t type;
char *fmt;
int size;
- sequence labels; // for enumeration
- sequence labels_description;
+ sequence_t labels; // for enumeration
+ sequence_t labels_description;
int already_printed;
- sequence fields; // for structure
+ sequence_t fields; // for structure
struct _type_descriptor *nested_type; // for array and sequence
int alignment;
-} type_descriptor;
+} type_descriptor_t;
/* Fields within types */
typedef struct _field{
char *name;
char *description;
- type_descriptor *type;
-} field;
+ type_descriptor_t *type;
+} field_t;
/* Events definitions */
typedef struct _event {
char *name;
char *description;
- type_descriptor *type;
+ type_descriptor_t *type;
int per_trace; /* Is the event able to be logged to a specific trace ? */
int per_tracefile; /* Must we log this event in a specific tracefile ? */
-} event;
+} event_t;
typedef struct _facility {
char * name;
char * capname;
char * description;
- sequence events;
- sequence unnamed_types;
- table named_types;
-} facility;
-
-int getSize(parse_file *in);
-unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type);
-
-void parseFacility(parse_file *in, facility * fac);
-void parseEvent(parse_file *in, event *ev, sequence * unnamed_types, table * named_types);
-void parseTypeDefinition(parse_file *in, sequence * unnamed_types, table * named_types);
-type_descriptor *parseType(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
-void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
-void checkNamedTypesImplemented(table * namedTypes);
-type_descriptor * find_named_type(char *name, table * named_types);
-void generateChecksum(char * facName, unsigned long * checksum, sequence * events);
+ sequence_t events;
+ sequence_t unnamed_types;
+ table_t named_types;
+} facility_t;
+
+int getSize(parse_file_t *in);
+unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
+
+void parseFacility(parse_file_t *in, facility_t * fac);
+void parseEvent(parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
+ table_t * named_types);
+void parseTypeDefinition(parse_file_t *in,
+ sequence_t * unnamed_types, table_t * named_types);
+type_descriptor_t *parseType(parse_file_t *in,
+ type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
+void parseFields(parse_file_t *in, type_descriptor_t *t,
+ sequence_t * unnamed_types, table_t * named_types);
+void checkNamedTypesImplemented(table_t * namedTypes);
+type_descriptor_t * find_named_type(char *name, table_t * named_types);
+void generateChecksum(char * facName,
+ unsigned long * checksum, sequence_t * events);
/* get attributes */
-char * getNameAttribute(parse_file *in);
-char * getFormatAttribute(parse_file *in);
-int getSizeAttribute(parse_file *in);
-int getValueAttribute(parse_file *in);
-char * getValueStrAttribute(parse_file *in);
+char * getNameAttribute(parse_file_t *in);
+char * getFormatAttribute(parse_file_t *in);
+int getSizeAttribute(parse_file_t *in);
+int getValueAttribute(parse_file_t *in);
+char * getValueStrAttribute(parse_file_t *in);
-char * getDescription(parse_file *in);
+char * getDescription(parse_file_t *in);
static char *intOutputTypes[] = {
void * memAlloc(int size);
char *allocAndCopy(char * str);
char *appendString(char *s, char *suffix);
-void freeTypes(sequence *t);
-void freeType(type_descriptor * td);
-void freeEvents(sequence *t);
-void freeNamedType(table * t);
-void error_callback(parse_file *in, char *msg);
+void freeTypes(sequence_t *t);
+void freeType(type_descriptor_t * td);
+void freeEvents(sequence_t *t);
+void freeNamedType(table_t * t);
+void error_callback(parse_file_t *in, char *msg);
//checksum part