From 70f46ac34d0f9f1f92f96c6d970e8278daa3308a Mon Sep 17 00:00:00 2001 From: compudj Date: Thu, 15 Dec 2005 16:12:54 +0000 Subject: [PATCH] fix enums git-svn-id: http://ltt.polymtl.ca/svn@1383 04897980-b3bd-0310-b5e0-8ef037075253 --- genevent-new/genevent.c | 3 ++- genevent-new/parser.c | 28 ++++++++++++++++++---------- genevent-new/parser.h | 3 ++- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/genevent-new/genevent.c b/genevent-new/genevent.c index 88cecb69..9113a11c 100644 --- a/genevent-new/genevent.c +++ b/genevent-new/genevent.c @@ -411,7 +411,8 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs, fprintf(fd, " {\n"); for(unsigned int i=0;ilabels.position;i++){ print_tabs(1, fd); - fprintf(fd, "LTTNG_%s", ((char*)(td->labels.array[i]))); + fprintf(fd, "LTTNG_%s = %d", ((char*)td->labels.array[i]), + (*(int*)td->labels_values.array[i])); fprintf(fd, ",\n"); } fprintf(fd, "};\n"); diff --git a/genevent-new/parser.c b/genevent-new/parser.c index 425d390c..42c38c31 100644 --- a/genevent-new/parser.c +++ b/genevent-new/parser.c @@ -723,9 +723,12 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, getRAnglebracket(in); // } else if(strcmp(token,"enum") == 0) { - char * str, *str1; + char * str; + int value = -1; + t->type = ENUM; sequence_init(&(t->labels)); + sequence_init(&(t->labels_values)); sequence_init(&(t->labels_description)); t->already_printed = 0; getTypeAttributes(in, t, unnamed_types, named_types); @@ -740,17 +743,18 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, getLAnglebracket(in); token = getToken(in); //"label" or "/" while(strcmp("label",token) == 0){ + int *label_value = malloc(sizeof(int)); + str = allocAndCopy(getNameAttribute(in)); token = getValueStrAttribute(in); - if(token){ - str1 = appendString(str,"="); - free(str); - str = appendString(str1,token); - free(str1); - sequence_push(&(t->labels),str); - } - else - sequence_push(&(t->labels),str); + + sequence_push(&(t->labels),str); + + if(token) value = strtol(token, NULL, 0); + else value++; + + *label_value = value; + sequence_push(&(t->labels_values), label_value); getForwardslash(in); getRAnglebracket(in); @@ -1397,6 +1401,10 @@ void freeType(type_descriptor_t * tp) free(tp->labels.array[pos2]); } sequence_dispose(&(tp->labels)); + for(pos2 = 0; pos2 < tp->labels_values.position; pos2++) { + free(tp->labels_values.array[pos2]); + } + sequence_dispose(&(tp->labels_values)); } if(tp->type == STRUCT) { for(pos2 = 0; pos2 < tp->fields.position; pos2++) { diff --git a/genevent-new/parser.h b/genevent-new/parser.h index cf90b7a7..810c46cb 100644 --- a/genevent-new/parser.h +++ b/genevent-new/parser.h @@ -107,6 +107,7 @@ typedef struct _type_descriptor { char *fmt; size_t size; sequence_t labels; // for enumeration + sequence_t labels_values; // for enumeration sequence_t labels_description; int already_printed; sequence_t fields; // for structure, array and sequence @@ -139,7 +140,7 @@ typedef struct _facility { char * capname; char * description; sequence_t events; - sequence_t unnamed_types; + sequence_t unnamed_types; //FIXME : remove table_t named_types; unsigned int checksum; } facility_t; -- 2.34.1