fix print style
[lttv.git] / ltt / branches / poly / ltt / parser.c
index 3183367e7ff16a97e479c7d52dcd1b6ce540d5e0..ab24a6c2e0030898d11c8141edff00c2ec8cd0c4 100644 (file)
@@ -96,24 +96,28 @@ int getSizeindex(unsigned int value)
 
 unsigned long long int getSize(parse_file_t *in)
 {
-  char *token;
-       int has_quotes = 0;
-       unsigned long long int ret;
+  char *token, *token2;
+  unsigned long long int ret;
 
   token = getToken(in);
-       if(token[0] == '"') {
-               has_quotes = 1;
-               token = getToken(in);
-       }
+
+
+  if(in->type == QUOTEDSTRING) {
+    in->type = NUMBER;
+    token2 = token;
+    do {
+       if (!isdigit(*token2)) {
+          in->type = QUOTEDSTRING;
+          break;
+                               }
+    } while (*(++token2) != '\0');
+  }
+
   if(in->type == NUMBER) {
                ret = strtoull(token, NULL, 0);
   } else {
                goto error;
        }
-       if(has_quotes) {
-               token = getToken(in);
-               if(token[0] != '"') goto error;
-       }
                
        return ret;
 error:
@@ -194,6 +198,7 @@ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t,
                           sequence_t * unnamed_types, table_t * named_types) 
 {
   char * token;
+  int car;
 
   t->fmt = NULL;
   t->size = 0;
@@ -221,10 +226,26 @@ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t,
       t->size = getSize(in);
     } else if(!strcmp("custom_write", token)) {
       t->custom_write = 1;
-    } else if(!strcmp("network", token)) {
-                       t->network = 1;
-               }
-  }
+               } else if(!strcmp("byte_order",token)) {
+       getEqual(in);
+       car = seekNextChar(in);
+       if(car == EOF) in->error(in,"byte order was expected (network?)");
+       else if(car == '\"') token = getQuotedString(in);
+       else token = getName(in);
+                       if(!strcmp("network", token)) {
+                       t->network = 1;
+                       }
+               } else if(!strcmp("write",token)) {
+       getEqual(in);
+       car = seekNextChar(in);
+       if(car == EOF) in->error(in,"write type was expected (custom?)");
+       else if(car == '\"') token = getQuotedString(in);
+       else token = getName(in);
+                       if(!strcmp("custom", token)) {
+                       t->custom_write = 1;
+                       }
+         }
+       }
 }
 
 /**************************************************************************
@@ -242,11 +263,13 @@ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t,
 void getEventAttributes(parse_file_t *in, event_t *ev)
 {
   char * token;
-  char car;
+  int car;
   
   ev->name = NULL;
   ev->per_trace = 0;
   ev->per_tracefile = 0;
+  ev->param_buffer = 0;
+       ev->no_instrument_function = 0;
 
   while(1) {
     token = getToken(in); 
@@ -261,12 +284,30 @@ void getEventAttributes(parse_file_t *in, event_t *ev)
       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;
+    } else if(!strcmp("scope", token)) {
+                       getEqual(in);
+                       car = seekNextChar(in);
+                       if(car == EOF) in->error(in,"scope was expected");
+      else if(car == '\"') token = getQuotedString(in);
+      else token = getName(in);
+                       if(!strcmp(token, "trace")) ev->per_trace = 1;
+                       else if(!strcmp(token, "tracefile")) ev->per_tracefile = 1;
+         } else if(!strcmp("param", token)) {
+                       getEqual(in);
+                       car = seekNextChar(in);
+                       if(car == EOF) in->error(in,"parameter type was expected");
+      else if(car == '\"') token = getQuotedString(in);
+      else token = getName(in);
+                       if(!strcmp(token, "buffer")) ev->param_buffer = 1;
+               } else if(!strcmp("attribute", token)) {
+                       getEqual(in);
+                       car = seekNextChar(in);
+                       if(car == EOF) in->error(in,"attribute was expected");
+      else if(car == '\"') token = getQuotedString(in);
+      else token = getName(in);
+                       if(!strcmp(token, "no_instrument_function"))
+                               ev->no_instrument_function = 1;
     }
-
   }
 }
 
@@ -285,7 +326,7 @@ void getEventAttributes(parse_file_t *in, event_t *ev)
 void getFacilityAttributes(parse_file_t *in, facility_t *fac)
 {
   char * token;
-  char car;
+  int car;
   
   fac->name = NULL;
   fac->arch = NULL;
@@ -304,12 +345,12 @@ void getFacilityAttributes(parse_file_t *in, facility_t *fac)
       if(car == EOF) in->error(in,"name was expected");
       else if(car == '\"') fac->name = allocAndCopy(getQuotedString(in));
       else fac->name = allocAndCopy(getName(in));
-                       if(!strncmp(fac->name, "user_", sizeof("user_")) == 0)
+                       if(!strncmp(fac->name, "user_", sizeof("user_")-1))
                                fac->user = 1;
     } else if(!strcmp("arch", token)) {
       getEqual(in);
       car = seekNextChar(in);
-      if(car == '\"') fac->name = allocAndCopy(getQuotedString(in));
+      if(car == '\"') fac->arch = allocAndCopy(getQuotedString(in));
                        else fac->arch = allocAndCopy(getName(in));
                }
   }
@@ -330,7 +371,7 @@ void getFacilityAttributes(parse_file_t *in, facility_t *fac)
 void getFieldAttributes(parse_file_t *in, field_t *f)
 {
   char * token;
-  char car;
+  int car;
 
   f->name = NULL;
 
@@ -355,7 +396,7 @@ char *getNameAttribute(parse_file_t *in)
 {
   char * token;
   char *name = NULL;
-  char car;
+  int car;
   
   while(1) {
     token = getToken(in); 
@@ -377,38 +418,39 @@ char *getNameAttribute(parse_file_t *in)
 
 
 
-//for <label name=label_name value=n format="..."/>, value is an option
+//for <label name=label_name value=n format="...">, value is an option
 //Return value : 0 : no value,   1 : has a value
 int getValueAttribute(parse_file_t *in, long long *value)
 {
-  char * token;
-       int has_quotes = 0;
+  char * token, *token2;
 
-  token = getToken(in); 
-  if(strcmp("/",token) == 0){
+  token = getToken(in);
+       
+  if(strcmp("/",token) == 0 || strcmp(">", token) == 0){
     ungetToken(in);
     return 0;
   }
-  
   if(strcmp("value",token))in->error(in,"value was expected");
+       
   getEqual(in);
   token = getToken(in);
 
-       if(token[0] == '"') {
-               has_quotes = 1;
-               token = getToken(in);
-       }
-  if(in->type == NUMBER) {
+  if(in->type == QUOTEDSTRING) {
+    in->type = NUMBER;
+    token2 = token;
+    do {
+       if (!isdigit(*token2)) {
+          in->type = QUOTEDSTRING;
+          break;
+                        }
+    } while (*(++token2) != '\0');
+  }
+
+  if(in->type == NUMBER)
                *value = strtoll(token, NULL, 0);
-  } else {
+       else
                goto error;
-       }
-       if(has_quotes) {
-               token = getToken(in);
-               if(token[0] != '"') goto error;
-       }
   return 1;
-
 error:
   in->error(in,"incorrect size specification");
   return 0;
@@ -417,7 +459,8 @@ error:
 char * getDescription(parse_file_t *in)
 {
   long int pos;
-  char * token, car, *str;
+  char * token, *str;
+  int car;
 
   pos = ftell(in->fp);
 
@@ -707,8 +750,10 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
 
     //getLAnglebracket(in); //<subtype> 
                /* subfield */
-               f = (field_t *)memAlloc(sizeof(field_t));
-               sequence_push(&(t->fields),f);
+    f = (field_t *)memAlloc(sizeof(field_t));
+    
+    f->name = NULL;
+    sequence_push(&(t->fields),f);
     parseFields(in, f, unnamed_types, named_types, 0);
 
     //getLAnglebracket(in); //<type struct> 
@@ -729,14 +774,16 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
 
     //getLAnglebracket(in); //<sequence size type> 
                /* subfield */
-               f = (field_t *)memAlloc(sizeof(field_t));
-               sequence_push(&(t->fields),f);
+    f = (field_t *)memAlloc(sizeof(field_t));
+    f->name = NULL;
+    sequence_push(&(t->fields),f);
     parseFields(in, f, unnamed_types, named_types, 0);
 
     //getLAnglebracket(in); //<subtype> 
                /* subfield */
-               f = (field_t *)memAlloc(sizeof(field_t));
-               sequence_push(&(t->fields),f);
+    f = (field_t *)memAlloc(sizeof(field_t));
+    f->name = NULL;
+    sequence_push(&(t->fields),f);
     parseFields(in, f, unnamed_types, named_types, 0);
 
     //getLAnglebracket(in); //<type sequence> 
@@ -795,7 +842,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
       str   = allocAndCopy(getNameAttribute(in));
       has_value = getValueAttribute(in, &loc_value);
       
-       sequence_push(&(t->labels),str);
+      sequence_push(&(t->labels),str);
 
       if(has_value) value = loc_value;
       else value++;
@@ -1085,9 +1132,9 @@ char * getEqual(parse_file_t *in)
   return token;
 }
 
-char seekNextChar(parse_file_t *in)
+int seekNextChar(parse_file_t *in)
 {
-  char car;
+  int car;
   while((car = getc(in->fp)) != EOF) {
     if(!isspace(car)){
       ungetc(car,in->fp);
@@ -1120,7 +1167,7 @@ void ungetToken(parse_file_t * in)
 char *getToken(parse_file_t * in)
 {
   FILE *fp = in->fp;
-  char car, car1;
+  int car, car1;
   int pos = 0, escaped;
 
   if(in->unget == 1) {
@@ -1172,8 +1219,8 @@ char *getToken(parse_file_t * in)
       escaped = 0;
       while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
         if(car == '\\' && escaped == 0) {
-         in->buffer[pos] = car;
-         pos++;
+                               in->buffer[pos] = car;
+                                 pos++;
           escaped = 1;
           continue;
         }
@@ -1202,10 +1249,10 @@ char *getToken(parse_file_t * in)
           in->buffer[pos] = car;
           pos++;
         }
-       if(car == EOF) ungetc(car,fp);
+                               if(car == EOF) ungetc(car,fp);
         if(pos == BUFFER_SIZE) in->error(in, "number token too large");
         in->type = NUMBER;
-      }    
+      }
       else if(isalnum(car) || car == '_' || car == '-') {
         in->buffer[0] = car;
         pos = 1;
@@ -1217,10 +1264,13 @@ char *getToken(parse_file_t * in)
           in->buffer[pos] = car;
           pos++;
         }
-       if(car == EOF) ungetc(car,fp);
+                       if(car == EOF) ungetc(car,fp);
         if(pos == BUFFER_SIZE) in->error(in, "name token too large");
         in->type = NAME;
-      }
+      } else if(car == '?') {
+                               in->buffer[0] = car;
+                               pos++;
+                       }
       else in->error(in, "invalid character, unrecognized token");
   }
   in->buffer[pos] = 0;
@@ -1229,7 +1279,7 @@ char *getToken(parse_file_t * in)
 
 void skipComment(parse_file_t * in)
 {
-  char car;
+  int car;
   while((car = getc(in->fp)) != EOF) {
     if(car == '\n') in->lineno++;
     else if(car == '*') {
@@ -1244,7 +1294,7 @@ void skipComment(parse_file_t * in)
 
 void skipEOL(parse_file_t * in)
 {
-  char car;
+  int car;
   while((car = getc(in->fp)) != EOF) {
     if(car == '\n') {
       ungetc(car,in->fp);
This page took 0.040975 seconds and 4 git commands to generate.