X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Fparser.c;h=bee3b5f98a6de52bc97d7c6271cfdb5a6590075e;hb=1c736ed5fd25e728fa1df0899be03c4853c556d8;hp=31e89a51036f84f4dd3353fbf6ae8ee2e66ce45b;hpb=963b5f2df23dc1c70bdc70d4aecb76f50651997b;p=lttv.git diff --git a/ltt/branches/poly/ltt/parser.c b/ltt/branches/poly/ltt/parser.c index 31e89a51..bee3b5f9 100644 --- a/ltt/branches/poly/ltt/parser.c +++ b/ltt/branches/poly/ltt/parser.c @@ -36,12 +36,28 @@ This program is distributed in the hope that it will be useful, #include #include #include +#include #include #include "parser.h" +static int ltt_isalpha(char c) +{ + int i,j; + if(c == '_')return 1; + i = c - 'a'; + j = c - 'A'; + if((i>=0 && i<26) || (j>=0 && j<26)) return 1; + return 0; +} + +static int ltt_isalnum(char c) +{ + return (ltt_isalpha(c) || isdigit(c)); +} + /***************************************************************************** *Function name * getSize : translate from string to integer @@ -85,7 +101,6 @@ void error_callback(parse_file *in, char *msg) printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg); else printf("%s\n",msg); - exit(1); } /***************************************************************************** @@ -162,7 +177,7 @@ char * getFormatAttribute(parse_file *in) //format is an option token = getToken(in); - if(strcmp("/",token) == 0){ + if(strcmp("/",token) == 0 || strcmp(">",token) == 0){ ungetToken(in); return NULL; } @@ -175,7 +190,7 @@ char * getFormatAttribute(parse_file *in) int getSizeAttribute(parse_file *in) { - char * token; + /* skip name and equal */ getName(in); getEqual(in); @@ -184,7 +199,7 @@ int getSizeAttribute(parse_file *in) int getValueAttribute(parse_file *in) { - char * token; + /* skip name and equal */ getName(in); getEqual(in); @@ -255,15 +270,15 @@ char * getDescription(parse_file *in) * fac : facility filled with event list ****************************************************************************/ -void parseFacility(parse_file *in, facility * fac) +void parseFacility(parse_file *in, facility_t * fac) { char * token; - event *ev; + event_t *ev; fac->name = allocAndCopy(getNameAttribute(in)); getRAnglebracket(in); - fac->description = allocAndCopy(getDescription(in)); + fac->description = getDescription(in); while(1){ getLAnglebracket(in); @@ -273,7 +288,7 @@ void parseFacility(parse_file *in, facility * fac) 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){ @@ -300,18 +315,17 @@ void parseFacility(parse_file *in, facility * fac) * ev : new event (parameters are passed to it) ****************************************************************************/ -void parseEvent(parse_file *in, event * ev, sequence * unnamed_types, +void parseEvent(parse_file *in, event_t * ev, sequence * unnamed_types, table * named_types) { char *token; - type_descriptor *t; // ev->name = allocAndCopy(getNameAttribute(in)); getRAnglebracket(in); //... - ev->description = allocAndCopy(getDescription(in)); + ev->description = getDescription(in); //event can have STRUCT, TYPEREF or NOTHING getLAnglebracket(in); @@ -350,16 +364,16 @@ void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types) { char * token; - field *f; + type_fields *f; - f = (field *)memAlloc(sizeof(field)); + f = (type_fields *)memAlloc(sizeof(type_fields)); sequence_push(&(t->fields),f); // f->name = allocAndCopy(getNameAttribute(in)); getRAnglebracket(in); - f->description = allocAndCopy(getDescription(in)); + f->description = getDescription(in); // getLAnglebracket(in); @@ -497,10 +511,9 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType, free(str); str = appendString(str1,token); free(str1); - sequence_push(&(t->labels),allocAndCopy(str)); - free(str); + sequence_push(&(t->labels),str); }else - sequence_push(&(t->labels),allocAndCopy(str)); + sequence_push(&(t->labels),str); getForwardslash(in); getRAnglebracket(in); @@ -579,7 +592,8 @@ type_descriptor * find_named_type(char *name, table * named_types) t->type_name = allocAndCopy(name); t->type = NONE; t->fmt = NULL; - table_insert(named_types,allocAndCopy(name),t); + table_insert(named_types,t->type_name,t); + // table_insert(named_types,allocAndCopy(name),t); } return t; } @@ -816,11 +830,11 @@ char *getToken(parse_file * in) if(pos == BUFFER_SIZE) in->error(in, "number token too large"); in->type = NUMBER; } - else if(isalpha(car)) { + else if(ltt_isalpha(car)) { in->buffer[0] = car; pos = 1; while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) { - if(!isalnum(car)) { + if(!ltt_isalnum(car)) { ungetc(car,fp); break; } @@ -864,27 +878,13 @@ void skipEOL(parse_file * in) if(car == EOF)ungetc(car, in->fp); } -int isalpha(char c) -{ - int i,j; - if(c == '_')return 1; - i = c - 'a'; - j = c - 'A'; - if((i>=0 && i<26) || (j>=0 && j<26)) return 1; - return 0; -} - -int isalnum(char c) -{ - return (isalpha(c) || isdigit(c)); -} - /***************************************************************************** *Function name * checkNamedTypesImplemented : check if all named types have definition + * returns -1 on error, 0 if ok ****************************************************************************/ -void checkNamedTypesImplemented(table * named_types) +int checkNamedTypesImplemented(table * named_types) { type_descriptor *t; int pos; @@ -893,10 +893,13 @@ void checkNamedTypesImplemented(table * named_types) for(pos = 0 ; pos < named_types->values.position; pos++) { t = (type_descriptor *) named_types->values.array[pos]; if(t->type == NONE){ - sprintf(str,"named type '%s' has no definition",(char*)named_types->keys.array[pos]); - error_callback(NULL,str); + sprintf(str,"named type '%s' has no definition", + (char*)named_types->keys.array[pos]); + error_callback(NULL,str); + return -1; } } + return 0; } @@ -909,25 +912,27 @@ void checkNamedTypesImplemented(table * named_types) * checksum : checksum for the facility ****************************************************************************/ -void generateChecksum( char* facName, unsigned long * checksum, sequence * events) +int generateChecksum(char* facName, unsigned long * checksum, sequence * 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){ sprintf(str,"event '%s' has a type other than STRUCT",ev->name); error_callback(NULL, str); + return -1; } crc = getTypeChecksum(crc, ev->type); } *checksum = crc; + return 0; } /***************************************************************************** @@ -945,7 +950,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type) unsigned long crc = aCrc; char * str = NULL, buf[16]; int flag = 0, pos; - field * fld; + type_fields * fld; switch(type->type){ case INT: @@ -966,12 +971,12 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type) flag = 1; break; case ARRAY: - sprintf(buf,"%d\0",type->size); + sprintf(buf,"%d",type->size); str = appendString("array ",buf); flag = 1; break; case SEQUENCE: - sprintf(buf,"%d\0",type->size); + sprintf(buf,"%d",type->size); str = appendString("sequence ",buf); flag = 1; break; @@ -997,7 +1002,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type) 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 = (type_fields *) type->fields.array[pos]; crc = partial_crc32(fld->name,crc); crc = getTypeChecksum(crc, fld->type); } @@ -1014,7 +1019,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type) void freeType(type_descriptor * tp) { int pos2; - field *f; + type_fields *f; if(tp->fmt != NULL) free(tp->fmt); if(tp->type == ENUM) { @@ -1025,7 +1030,7 @@ void freeType(type_descriptor * tp) } if(tp->type == STRUCT) { for(pos2 = 0; pos2 < tp->fields.position; pos2++) { - f = (field *) tp->fields.array[pos2]; + f = (type_fields *) tp->fields.array[pos2]; free(f->name); free(f->description); free(f); @@ -1049,9 +1054,8 @@ void freeNamedType(table * t) void freeTypes(sequence *t) { - int pos, pos2; + int pos; type_descriptor *tp; - field *f; for(pos = 0 ; pos < t->position; pos++) { tp = (type_descriptor *)t->array[pos]; @@ -1063,10 +1067,10 @@ void freeTypes(sequence *t) void freeEvents(sequence *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);