many compile fix
[lttv.git] / ltt / branches / poly / ltt / parser.c
index 6b0fbd621a3b16b8b3b74881bfba084d1d7b6461..58a6a10e4626054a41f6a28035c9ee6c8c926761 100644 (file)
@@ -36,12 +36,29 @@ This program is distributed in the hope that it will be useful,
 #include <string.h>
 #include <stdio.h>
 #include <stdarg.h>
-#include <linux/errno.h>  
+#include <ctype.h>
+#include <linux/errno.h>
+#include <glib.h>
 
 
 #include "parser.h"
 
 
+static int ltt_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;
+}
+
+static int ltt_isalnum(char c)
+{
+  return (ltt_isalpha(c) || isdigit(c));
+}
+
 /*****************************************************************************
  *Function name
  *    getSize    : translate from string to integer
@@ -85,7 +102,6 @@ void error_callback(parse_file *in, char *msg)
     printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg);
   else
     printf("%s\n",msg);
-  exit(1);
 }
 
 /*****************************************************************************
@@ -175,7 +191,7 @@ char * getFormatAttribute(parse_file *in)
 
 int getSizeAttribute(parse_file *in)
 {
-  char * token;
+  /* skip name and equal */
   getName(in);
   getEqual(in);
 
@@ -184,7 +200,7 @@ int getSizeAttribute(parse_file *in)
 
 int getValueAttribute(parse_file *in)
 {
-  char * token;
+  /* skip name and equal */
   getName(in);
   getEqual(in);
   
@@ -255,15 +271,15 @@ char * getDescription(parse_file *in)
  *    fac           : facility filled with event list
  ****************************************************************************/
 
-void parseFacility(parse_file *in, facility * fac)
+void parseFacility(parse_file *in, facility_t * fac)
 {
   char * token;
-  event *ev;
+  event_t *ev;
   
   fac->name = allocAndCopy(getNameAttribute(in));    
   getRAnglebracket(in);    
   
-  fac->description = allocAndCopy(getDescription(in));
+  fac->description = getDescription(in);
   
   while(1){
     getLAnglebracket(in);    
@@ -273,7 +289,7 @@ void parseFacility(parse_file *in, facility * fac)
       in->error(in,"the definition of the facility is not finished");
 
     if(strcmp("event",token) == 0){
-      ev = (event*) memAlloc(sizeof(event));
+      ev = (event_t*) memAlloc(sizeof(event_t));
       sequence_push(&(fac->events),ev);
       parseEvent(in,ev, &(fac->unnamed_types), &(fac->named_types));    
     }else if(strcmp("type",token) == 0){
@@ -300,18 +316,17 @@ void parseFacility(parse_file *in, facility * fac)
  *    ev            : new event (parameters are passed to it)   
  ****************************************************************************/
 
-void parseEvent(parse_file *in, event * ev, sequence * unnamed_types, 
+void parseEvent(parse_file *in, event_t * ev, sequence * unnamed_types, 
                table * named_types) 
 {
   char *token;
-  type_descriptor *t;
 
   //<event name=eventtype_name>
   ev->name = allocAndCopy(getNameAttribute(in));
   getRAnglebracket(in);  
 
   //<description>...</descriptio>
-  ev->description = allocAndCopy(getDescription(in)); 
+  ev->description = getDescription(in); 
   
   //event can have STRUCT, TYPEREF or NOTHING
   getLAnglebracket(in);
@@ -350,16 +365,16 @@ void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types,
                 table * named_types) 
 {
   char * token;
-  field *f;
+  type_fields *f;
 
-  f = (field *)memAlloc(sizeof(field));
+  f = (type_fields *)memAlloc(sizeof(type_fields));
   sequence_push(&(t->fields),f);
 
   //<field name=field_name> <description> <type> </field>
   f->name = allocAndCopy(getNameAttribute(in)); 
   getRAnglebracket(in);
 
-  f->description = allocAndCopy(getDescription(in));
+  f->description = getDescription(in);
 
   //<int size=...>
   getLAnglebracket(in);
@@ -497,10 +512,9 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
        free(str);
        str = appendString(str1,token);
        free(str1);
-       sequence_push(&(t->labels),allocAndCopy(str));
-       free(str);
+       sequence_push(&(t->labels),str);
       }else
-       sequence_push(&(t->labels),allocAndCopy(str));
+       sequence_push(&(t->labels),str);
 
       getForwardslash(in);
       getRAnglebracket(in);
@@ -579,7 +593,8 @@ type_descriptor * find_named_type(char *name, table * named_types)
     t->type_name = allocAndCopy(name);
     t->type = NONE;
     t->fmt = NULL;
-    table_insert(named_types,allocAndCopy(name),t);
+    table_insert(named_types,t->type_name,t);
+    //    table_insert(named_types,allocAndCopy(name),t);
   }
   return t;
 }  
@@ -816,11 +831,11 @@ char *getToken(parse_file * in)
         if(pos == BUFFER_SIZE) in->error(in, "number token too large");
         in->type = NUMBER;
       }    
-      else if(isalpha(car)) {
+      else if(ltt_isalpha(car)) {
         in->buffer[0] = car;
         pos = 1;
         while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
-          if(!isalnum(car)) {
+          if(!ltt_isalnum(car)) {
             ungetc(car,fp);
             break;
           }
@@ -864,27 +879,13 @@ 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
+ *    returns -1 on error, 0 if ok
  ****************************************************************************/
 
-void checkNamedTypesImplemented(table * named_types)
+int checkNamedTypesImplemented(table * named_types)
 {
   type_descriptor *t;
   int pos;
@@ -893,10 +894,13 @@ void checkNamedTypesImplemented(table * named_types)
   for(pos = 0 ; pos < named_types->values.position; pos++) {
     t = (type_descriptor *) named_types->values.array[pos];
     if(t->type == NONE){
-      sprintf(str,"named type '%s' has no definition",(char*)named_types->keys.array[pos]);
-      error_callback(NULL,str);   
+      sprintf(str,"named type '%s' has no definition",
+              (char*)named_types->keys.array[pos]);
+      error_callback(NULL,str);
+      return -1;
     }
   }
+  return 0;
 }
 
 
@@ -909,25 +913,27 @@ void checkNamedTypesImplemented(table * named_types)
  *    checksum          : checksum for the facility
  ****************************************************************************/
 
-void generateChecksum( char* facName, unsigned long * checksum, sequence * events)
+int generateChecksum(char* facName, guint32 * checksum, sequence * events)
 {
   unsigned long crc ;
   int pos;
-  event * ev;
+  event_t * ev;
   char str[256];
 
   crc = crc32(facName);
   for(pos = 0; pos < events->position; pos++){
-    ev = (event *)(events->array[pos]);
+    ev = (event_t *)(events->array[pos]);
     crc = partial_crc32(ev->name,crc);    
     if(!ev->type) continue; //event without type
     if(ev->type->type != STRUCT){
       sprintf(str,"event '%s' has a type other than STRUCT",ev->name);
       error_callback(NULL, str);
+      return -1;
     }
     crc = getTypeChecksum(crc, ev->type);
   }
   *checksum = crc;
+  return 0;
 }
 
 /*****************************************************************************
@@ -945,7 +951,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type)
   unsigned long crc = aCrc;
   char * str = NULL, buf[16];
   int flag = 0, pos;
-  field * fld;
+  type_fields * fld;
 
   switch(type->type){
     case INT:
@@ -966,12 +972,12 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type)
       flag = 1;
       break;
     case ARRAY:
-      sprintf(buf,"%d\0",type->size);
+      sprintf(buf,"%d",type->size);
       str = appendString("array ",buf);
       flag = 1;
       break;
     case SEQUENCE:
-      sprintf(buf,"%d\0",type->size);
+      sprintf(buf,"%d",type->size);
       str = appendString("sequence ",buf);
       flag = 1;
       break;
@@ -997,7 +1003,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type)
     crc = getTypeChecksum(crc,type->nested_type);
   }else if(type->type == STRUCT || type->type == UNION){
     for(pos =0; pos < type->fields.position; pos++){
-      fld = (field *) type->fields.array[pos];
+      fld = (type_fields *) type->fields.array[pos];
       crc = partial_crc32(fld->name,crc);
       crc = getTypeChecksum(crc, fld->type);
     }    
@@ -1014,7 +1020,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type)
 void freeType(type_descriptor * tp)
 {
   int pos2;
-  field *f;
+  type_fields *f;
 
   if(tp->fmt != NULL) free(tp->fmt);
   if(tp->type == ENUM) {
@@ -1025,7 +1031,7 @@ void freeType(type_descriptor * tp)
   }
   if(tp->type == STRUCT) {
     for(pos2 = 0; pos2 < tp->fields.position; pos2++) {
-      f = (field *) tp->fields.array[pos2];
+      f = (type_fields *) tp->fields.array[pos2];
       free(f->name);
       free(f->description);
       free(f);
@@ -1049,9 +1055,8 @@ void freeNamedType(table * t)
 
 void freeTypes(sequence *t) 
 {
-  int pos, pos2;
+  int pos;
   type_descriptor *tp;
-  field *f;
 
   for(pos = 0 ; pos < t->position; pos++) {
     tp = (type_descriptor *)t->array[pos];
@@ -1063,10 +1068,10 @@ void freeTypes(sequence *t)
 void freeEvents(sequence *t) 
 {
   int pos;
-  event *ev;
+  event_t *ev;
 
   for(pos = 0 ; pos < t->position; pos++) {
-    ev = (event *) t->array[pos];
+    ev = (event_t *) t->array[pos];
     free(ev->name);
     free(ev->description);
     free(ev);
This page took 0.027998 seconds and 4 git commands to generate.