large files support
[lttv.git] / genevent / parser.c
index b6561ca57793f38c48ad6837680bd924aefa5b7e..d998c81381b17672b4bf0caf8de0fd45d03abaa7 100644 (file)
@@ -42,6 +42,35 @@ This program is distributed in the hope that it will be useful,
 #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
@@ -261,6 +290,8 @@ void parseFacility(parse_file *in, facility * fac)
   event *ev;
   
   fac->name = allocAndCopy(getNameAttribute(in));    
+  fac->capname = allocAndCopy(fac->name);
+       strupper(fac->capname);
   getRAnglebracket(in);    
   
   fac->description = getDescription(in);
@@ -482,6 +513,8 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
     char * str, *str1;
     t->type = ENUM;
     sequence_init(&(t->labels));
+    sequence_init(&(t->labels_description));
+               t->already_printed = 0;
     t->size = getSizeAttribute(in);
     t->fmt = allocAndCopy(getFormatAttribute(in));
     getRAnglebracket(in);
@@ -493,17 +526,22 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
       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);
+       str1 = appendString(str,"=");
+       free(str);
+       str = appendString(str1,token);
+       free(str1);
+       sequence_push(&(t->labels),str);
+      }
+      else
+       sequence_push(&(t->labels),str);
 
       getForwardslash(in);
       getRAnglebracket(in);
       
+      //read description if any. May be NULL.
+      str = allocAndCopy(getDescription(in));
+                       sequence_push(&(t->labels_description),str);
+                             
       //next label definition
       getLAnglebracket(in);
       token = getToken(in); //"label" or "/"      
@@ -511,7 +549,7 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
     if(strcmp("/",token))in->error(in, "not a valid enum definition");
     token = getName(in);
     if(strcmp("enum",token))in->error(in, "not a valid enum definition");
-    getRAnglebracket(in); //</label>
+      getRAnglebracket(in); //</label>
   }
   else if(strcmp(token,"int") == 0) {
     t->type = INT;
@@ -527,6 +565,48 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
     getForwardslash(in);
     getRAnglebracket(in); 
   }
+  else if(strcmp(token,"pointer") == 0) {
+    t->type = POINTER;
+    t->size = 0;
+    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"long") == 0) {
+    t->type = LONG;
+    t->size = 0;
+    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"ulong") == 0) {
+    t->type = ULONG;
+    t->size = 0;
+    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"size_t") == 0) {
+    t->type = SIZE_T;
+    t->size = 0;
+    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"ssize_t") == 0) {
+    t->type = SSIZE_T;
+    t->size = 0;
+    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"off_t") == 0) {
+    t->type = OFF_T;
+    t->size = 0;
+    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
   else if(strcmp(token,"float") == 0) {
     t->type = FLOAT;
     t->size = getSizeAttribute(in);
@@ -606,7 +686,7 @@ void parseTypeDefinition(parse_file * in, sequence * unnamed_types,
   getRAnglebracket(in); //<type name=type_name>
   getLAnglebracket(in); //<struct>
   token = getName(in);
-  if(strcmp("struct",token))in->error(in,"not a valid type definition");
+  //MD ??if(strcmp("struct",token))in->error(in,"not a valid type definition");
   ungetToken(in);
   parseType(in,t, unnamed_types, named_types);
   
@@ -820,7 +900,7 @@ char *getToken(parse_file * in)
         in->buffer[0] = car;
         pos = 1;
         while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
-          if(!isalnum(car)) {
+          if(!(isalnum(car) || car == '_')) {
             ungetc(car,fp);
             break;
           }
@@ -864,21 +944,6 @@ 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
@@ -954,6 +1019,30 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type)
     case UINT:
       str = uintOutputTypes[type->size];
       break;
+    case POINTER:
+      str = allocAndCopy("void *");
+                       flag = 1;
+      break;
+    case LONG:
+      str = allocAndCopy("long");
+                       flag = 1;
+      break;
+    case ULONG:
+      str = allocAndCopy("unsigned long");
+                       flag = 1;
+      break;
+    case SIZE_T:
+      str = allocAndCopy("size_t");
+                       flag = 1;
+      break;
+    case SSIZE_T:
+      str = allocAndCopy("ssize_t");
+                       flag = 1;
+      break;
+    case OFF_T:
+      str = allocAndCopy("off_t");
+                       flag = 1;
+      break;
     case FLOAT:
       str = floatOutputTypes[type->size];
       break;
This page took 0.029959 seconds and 4 git commands to generate.