X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Fparser.c;h=31e89a51036f84f4dd3353fbf6ae8ee2e66ce45b;hb=963b5f2df23dc1c70bdc70d4aecb76f50651997b;hp=2851188f34ddd6e961ba078f113091e2144b892c;hpb=8a2d0e7181075408c8fa1b35b2a755e200863997;p=lttv.git diff --git a/ltt/branches/poly/ltt/parser.c b/ltt/branches/poly/ltt/parser.c index 2851188f..31e89a51 100644 --- a/ltt/branches/poly/ltt/parser.c +++ b/ltt/branches/poly/ltt/parser.c @@ -19,9 +19,8 @@ This program is distributed in the hope that it will be useful, Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* This program reads the ".event" event definitions input files - specified as command line arguments and generates corresponding - ".c" and ".h" files required to trace such events in the kernel. +/* This program reads the ".xml" event definitions input files + and constructs structure for each event. The program uses a very simple tokenizer, called from a hand written recursive descent parser to fill a data structure describing the events. @@ -31,7 +30,7 @@ This program is distributed in the hope that it will be useful, A table of named types is maintained to allow refering to types by name when the same type is used at several places. Finally a sequence of all types is maintained to facilitate the freeing of all type - information when the processing of an ".event" file is finished. */ + information when the processing of an ".xml" file is finished. */ #include #include @@ -100,7 +99,9 @@ void error_callback(parse_file *in, char *msg) void * memAlloc(int size) { - void *addr = malloc(size); + void * addr; + if(size == 0) return NULL; + addr = malloc(size); if(!addr){ printf("Failed to allocate memory"); exit(1); @@ -119,11 +120,173 @@ void * memAlloc(int size) char *allocAndCopy(char *str) { - char *addr = (char *)memAlloc(strlen(str)+1); + char * addr; + if(str == NULL) return NULL; + addr = (char *)memAlloc(strlen(str)+1); strcpy(addr,str); return addr; } +/************************************************************************** + * Function : + * getNameAttribute,getFormatAttribute,getSizeAttribute,getValueAttribute + * getValueStrAttribute + * Description : + * Read the attribute from the input file. + * + * Parameters : + * in , input file handle. + * + * Return values : + * address of the attribute. + * + **************************************************************************/ + +char * getNameAttribute(parse_file *in) +{ + char * token, car; + token = getName(in); + if(strcmp("name",token))in->error(in,"name was expected"); + getEqual(in); + + car = seekNextChar(in); + if(car == EOF)in->error(in,"name was expected"); + else if(car == '\"')token = getQuotedString(in); + else token = getName(in); + return token; +} + +char * getFormatAttribute(parse_file *in) +{ + char * token; + + //format is an option + token = getToken(in); + if(strcmp("/",token) == 0){ + ungetToken(in); + return NULL; + } + + if(strcmp("format",token))in->error(in,"format was expected"); + getEqual(in); + token = getQuotedString(in); + return token; +} + +int getSizeAttribute(parse_file *in) +{ + char * token; + getName(in); + getEqual(in); + + return getSize(in); +} + +int getValueAttribute(parse_file *in) +{ + char * token; + getName(in); + getEqual(in); + + return getNumber(in); +} + +//for