X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Fparser.c;h=bee3b5f98a6de52bc97d7c6271cfdb5a6590075e;hb=cf25ea22e105edf1f620d740b628af67c8559f7e;hp=2851188f34ddd6e961ba078f113091e2144b892c;hpb=6cd62ccfe338056a2a7571addbb63e0e16354e86;p=lttv.git diff --git a/ltt/branches/poly/ltt/parser.c b/ltt/branches/poly/ltt/parser.c index 2851188f..bee3b5f9 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,18 +30,34 @@ 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 #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 @@ -86,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); } /***************************************************************************** @@ -100,7 +114,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 +135,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 || 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) +{ + /* skip name and equal */ + getName(in); + getEqual(in); + + return getSize(in); +} + +int getValueAttribute(parse_file *in) +{ + /* skip name and equal */ + getName(in); + getEqual(in); + + return getNumber(in); +} + +//for