Make sure libtraceread is completely licensed LGPL
[lttv.git] / ltt / branches / poly / ltt / parser.c
index bfa645643fde76932c19559ed7bfec597f2a2429..492f766724f9aaa38c5eb3be12194af3d6bbcb95 100644 (file)
@@ -1,24 +1,25 @@
 /*
-
-parser.c: Generate helper declarations and functions to trace events
-  from an event description file.
-
-           Copyright (C) 2005, Mathieu Desnoyers
-      Copyright (C) 2002, Xianxiu Yang
-      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.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-*/
+ * parser.c: Generate helper declarations and functions to trace events
+ * from an event description file.
+ *
+ *    Copyright (C) 2005, Mathieu Desnoyers
+ *    Copyright (C) 2002, Xianxiu Yang
+ *    Copyright (C) 2002, Michel Dagenais 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License Version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
 
 /* This program reads the ".xml" event definitions input files 
    and constructs structure for each event.
@@ -182,6 +183,7 @@ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t,
 
   t->fmt = NULL;
   t->size = 0;
+  t->custom_write = 0;
   
   while(1) {
     token = getToken(in); 
@@ -202,6 +204,8 @@ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t,
     } else if(!strcmp("size",token)) {
       getEqual(in);
       t->size = getSize(in);
+    } else if(!strcmp("custom_write", token)) {
+      t->custom_write = 1;
     }
   }
 }
@@ -267,6 +271,7 @@ void getFacilityAttributes(parse_file_t *in, facility_t *fac)
   char car;
   
   fac->name = NULL;
+  fac->arch = NULL;
 
   while(1) {
     token = getToken(in); 
@@ -281,7 +286,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));
-    }
+    } else if(!strcmp("arch", token)) {
+      getEqual(in);
+      car = seekNextChar(in);
+      if(car == '\"') fac->name = allocAndCopy(getQuotedString(in));
+                       else fac->arch = allocAndCopy(getName(in));
+               }
   }
 }
 
@@ -420,7 +430,7 @@ void parseFacility(parse_file_t *in, facility_t * fac)
   
   getFacilityAttributes(in, fac);
   if(fac->name == NULL) in->error(in, "Attribute not named");
-
+       
   fac->capname = allocAndCopy(fac->name);
        strupper(fac->capname);
   getRAnglebracket(in);    
@@ -674,8 +684,8 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
   else if(strcmp(token,"sequence") == 0) {
     t->type = SEQUENCE;
     sequence_init(&(t->fields));
-    //getTypeAttributes(in, t, unnamed_types, named_types);
-    //getForwardslash(in);
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getForwardslash(in);
     getRAnglebracket(in); //<sequence>
 
     //getLAnglebracket(in); //<sequence size type> 
@@ -741,7 +751,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
     while(strcmp("label",token) == 0){
       int *label_value = malloc(sizeof(int));
       
-      str   = allocAndCopy(getNameAttribute(in));      
+      str   = allocAndCopy(getNameAttribute(in));
       token = getValueStrAttribute(in);
       
        sequence_push(&(t->labels),str);
@@ -784,29 +794,29 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
   }
   else if(strcmp(token,"char") == 0) {
     t->type = CHAR;
-               t->size = 1;
     getTypeAttributes(in, t, unnamed_types, named_types);
+               t->size = 1;
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"uchar") == 0) {
     t->type = UCHAR;
-               t->size = 1;
     getTypeAttributes(in, t, unnamed_types, named_types);
+               t->size = 1;
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"short") == 0) {
     t->type = SHORT;
-               t->size = 2;
     getTypeAttributes(in, t, unnamed_types, named_types);
+               t->size = 2;
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"ushort") == 0) {
     t->type = USHORT;
-               t->size = 2;
     getTypeAttributes(in, t, unnamed_types, named_types);
+               t->size = 2;
     getForwardslash(in);
     getRAnglebracket(in); 
   }
@@ -972,7 +982,8 @@ char *getName(parse_file_t * in)
   char *token;
 
   token = getToken(in);
-  if(in->type != NAME) in->error(in,"Name token was expected");
+  // Optional descriptions
+       // if(in->type != NAME) in->error(in,"Name token was expected");
   return token;
 }
 
@@ -1154,11 +1165,11 @@ char *getToken(parse_file_t * in)
         if(pos == BUFFER_SIZE) in->error(in, "number token too large");
         in->type = NUMBER;
       }    
-      else if(isalpha(car)) {
+      else if(isalnum(car) || car == '_' || car == '-') {
         in->buffer[0] = car;
         pos = 1;
         while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
-          if(!(isalnum(car) || car == '_')) {
+          if(!(isalnum(car) || car == '_' || car == '-')) {
             ungetc(car,fp);
             break;
           }
@@ -1344,8 +1355,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type)
       flag = 1;
       break;
     case SEQUENCE:
-      sprintf(buf,"%zu", type->size);
-      str = appendString("sequence ",buf);
+      str = allocAndCopy("sequence ");
       flag = 1;
       break;
     case STRUCT:
@@ -1551,5 +1561,3 @@ char *appendString(char *s, char *suffix)
   strcat(tmp,suffix);  
   return tmp;
 }
-
-
This page took 0.024807 seconds and 4 git commands to generate.