X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Fparser.c;h=aa87db950f66ede7cbfe018efdb477b6b7c97590;hb=d3d34f492bdbd2326ff345d8d1f84998df19f459;hp=5c90c983631f60215933ce681cce90ea397ab044;hpb=45e14832eebe9f25938b2c668d8ef1acd56a2436;p=lttv.git diff --git a/ltt/branches/poly/ltt/parser.c b/ltt/branches/poly/ltt/parser.c index 5c90c983..aa87db95 100644 --- a/ltt/branches/poly/ltt/parser.c +++ b/ltt/branches/poly/ltt/parser.c @@ -4,9 +4,7 @@ parser.c: Generate helper declarations and functions to trace events from an event description file. Copyright (C) 2002, Xianxiu Yang -Copyright (C) 2002, Michel Dagenais -Copyright (C) 2005, Mathieu Desnoyers - +Copyright (C) 2002, Michel Dagenais This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. @@ -38,13 +36,42 @@ This program is distributed in the hope that it will be useful, #include #include #include -#include -#include -#include +#include +#include #include "parser.h" + +/* helper function */ +void strupper(char *string) +{ + char *ptr = string; + + while(*ptr != '\0') { + *ptr = toupper(*ptr); + ptr++; + } +} + + +int getSizeindex(int value) +{ + switch(value) { + case 1: + return 0; + case 2: + return 1; + case 4: + return 2; + case 8: + return 3; + default: + printf("Error : unknown value size %d\n", value); + exit(-1); + } +} + /***************************************************************************** *Function name * getSize : translate from string to integer @@ -54,21 +81,21 @@ This program is distributed in the hope that it will be useful, * size *****************************************************************************/ -int getSize(parse_file *in) +int getSize(parse_file_t *in) { - gchar *token; + char *token; token = getToken(in); if(in->type == NUMBER) { - if(g_ascii_strcasecmp(token,"1") == 0) return 0; - else if(g_ascii_strcasecmp(token,"2") == 0) return 1; - else if(g_ascii_strcasecmp(token,"4") == 0) return 2; - else if(g_ascii_strcasecmp(token,"8") == 0) return 3; + if(strcmp(token,"1") == 0) return 0; + else if(strcmp(token,"2") == 0) return 1; + else if(strcmp(token,"4") == 0) return 2; + else if(strcmp(token,"8") == 0) return 3; } else if(in->type == NAME) { - if(g_ascii_strcasecmp(token,"short") == 0) return 4; - else if(g_ascii_strcasecmp(token,"medium") == 0) return 5; - else if(g_ascii_strcasecmp(token,"long") == 0) return 6; + if(strcmp(token,"short") == 0) return 4; + else if(strcmp(token,"medium") == 0) return 5; + else if(strcmp(token,"long") == 0) return 6; } in->error(in,"incorrect size specification"); return -1; @@ -82,131 +109,281 @@ int getSize(parse_file *in) * msg : message to be printed ****************************************************************************/ -void error_callback(parse_file *in, char *msg) +void error_callback(parse_file_t *in, char *msg) { if(in) - g_printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg); + printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg); else printf("%s\n",msg); + assert(0); + exit(1); +} + +/***************************************************************************** + *Function name + * memAlloc : allocate memory + *Input params + * size : required memory size + *return value + * void * : pointer to allocate memory or NULL + ****************************************************************************/ + +void * memAlloc(int size) +{ + void * addr; + if(size == 0) return NULL; + addr = malloc(size); + if(!addr){ + printf("Failed to allocate memory"); + exit(1); + } + return addr; +} + +/***************************************************************************** + *Function name + * allocAndCopy : allocate memory and initialize it + *Input params + * str : string to be put in memory + *return value + * char * : pointer to allocate memory or NULL + ****************************************************************************/ + +char *allocAndCopy(char *str) +{ + char * addr; + if(str == NULL) return NULL; + addr = (char *)memAlloc(strlen(str)+1); + strcpy(addr,str); + return addr; } /************************************************************************** * Function : - * getNameAttribute,getFormatAttribute,getSizeAttribute,getValueAttribute - * getValueStrAttribute + * getTypeAttributes * Description : * Read the attribute from the input file. * * Parameters : * in , input file handle. - * - * Return values : - * address of the attribute. + * t , the type descriptor to fill. * **************************************************************************/ -gchar * getNameAttribute(parse_file *in) +void getTypeAttributes(parse_file_t *in, type_descriptor_t *t) { - gchar * token; - gunichar car; - GIOStatus status; - - token = getName(in); - if(g_ascii_strcasecmp("name",token))in->error(in,"name was expected"); - getEqual(in); + char * token; + char car; + + t->fmt = NULL; + t->size = -1; + t->alignment = 0; - status = seekNextChar(in, &car); - if(status == G_IO_STATUS_EOF || status == G_IO_STATUS_ERROR) - in->error(in,"name was expected"); - else if(car == '\"') token = getQuotedString(in); - else token = getName(in); - return token; + while(1) { + token = getToken(in); + if(strcmp("/",token) == 0 || strcmp(">",token) == 0){ + ungetToken(in); + break; + } + + if(!strcmp("format",token)) { + getEqual(in); + t->fmt = allocAndCopy(getQuotedString(in)); + //} else if(!strcmp("name",token)) { + // getEqual(in); + // car = seekNextChar(in); + // if(car == EOF) in->error(in,"name was expected"); + // else if(car == '\"') t->type_name = allocAndCopy(getQuotedString(in)); + // else t->type_name = allocAndCopy(getName(in)); + } else if(!strcmp("size",token)) { + getEqual(in); + t->size = getSize(in); + } else if(!strcmp("align",token)) { + getEqual(in); + t->alignment = getNumber(in); + } + } } -char * getFormatAttribute(parse_file *in) +/************************************************************************** + * Function : + * getEventAttributes + * Description : + * Read the attribute from the input file. + * + * Parameters : + * in , input file handle. + * ev , the event to fill. + * + **************************************************************************/ + +void getEventAttributes(parse_file_t *in, event_t *ev) { char * token; + char car; + + ev->name = NULL; + ev->per_trace = 0; + ev->per_tracefile = 0; + + while(1) { + token = getToken(in); + if(strcmp("/",token) == 0 || strcmp(">",token) == 0){ + ungetToken(in); + break; + } + + if(!strcmp("name",token)) { + getEqual(in); + car = seekNextChar(in); + if(car == EOF) in->error(in,"name was expected"); + else if(car == '\"') ev->name = allocAndCopy(getQuotedString(in)); + else ev->name = allocAndCopy(getName(in)); + } else if(!strcmp("per_trace", token)) { + ev->per_trace = 1; + } else if(!strcmp("per_tracefile", token)) { + ev->per_tracefile = 1; + } - //format is an option - token = getToken(in); - if(g_ascii_strcasecmp("/",token) == 0 || g_ascii_strcasecmp(">",token) == 0){ - ungetToken(in); - return NULL; } +} - if(g_ascii_strcasecmp("format",token))in->error(in,"format was expected"); - getEqual(in); - token = getQuotedString(in); - return token; +/************************************************************************** + * Function : + * getFacilityAttributes + * Description : + * Read the attribute from the input file. + * + * Parameters : + * in , input file handle. + * fac , the facility to fill. + * + **************************************************************************/ + +void getFacilityAttributes(parse_file_t *in, facility_t *fac) +{ + char * token; + char car; + + fac->name = NULL; + + while(1) { + token = getToken(in); + if(strcmp("/",token) == 0 || strcmp(">",token) == 0){ + ungetToken(in); + break; + } + + if(!strcmp("name",token)) { + getEqual(in); + car = seekNextChar(in); + if(car == EOF) in->error(in,"name was expected"); + else if(car == '\"') fac->name = allocAndCopy(getQuotedString(in)); + else fac->name = allocAndCopy(getName(in)); + } + } } -int getSizeAttribute(parse_file *in) +/************************************************************************** + * Function : + * getFieldAttributes + * Description : + * Read the attribute from the input file. + * + * Parameters : + * in , input file handle. + * f , the field to fill. + * + **************************************************************************/ + +void getFieldAttributes(parse_file_t *in, field_t *f) { - /* skip name and equal */ - getName(in); - getEqual(in); + char * token; + char car; + + f->name = NULL; - return getSize(in); + while(1) { + token = getToken(in); + if(strcmp("/",token) == 0 || strcmp(">",token) == 0){ + ungetToken(in); + break; + } + + if(!strcmp("name",token)) { + getEqual(in); + car = seekNextChar(in); + if(car == EOF) in->error(in,"name was expected"); + else if(car == '\"') f->name = allocAndCopy(getQuotedString(in)); + else f->name = allocAndCopy(getName(in)); + } + } } -int getValueAttribute(parse_file *in) +char *getNameAttribute(parse_file_t *in) { - /* skip name and equal */ - getName(in); - getEqual(in); + char * token; + char *name = NULL; + char car; + + while(1) { + token = getToken(in); + if(strcmp("/",token) == 0 || strcmp(">",token) == 0){ + ungetToken(in); + break; + } + + if(!strcmp("name",token)) { + getEqual(in); + car = seekNextChar(in); + if(car == EOF) in->error(in,"name was expected"); + else if(car == '\"') name = allocAndCopy(getQuotedString(in)); + else name = allocAndCopy(getName(in)); + } + } + if(name == NULL) in->error(in, "Name was expected"); + return name; - return getNumber(in); } -//for