Add new XML parser from genevent
[lttv.git] / ltt / branches / poly / ltt / parser.c
index 8e409aa927736ac2f9334a58d14e55e23f928626..b4bd088b5c8fb8e22859d7e20dc6fe0c43b03a96 100644 (file)
@@ -4,9 +4,7 @@ parser.c: Generate helper declarations and functions to trace events
   from an event description file.
 
 Copyright (C) 2002, Xianxiu Yang
-Copyright (C) 2002, Michel Dagenais
-Copyright (C) 2005, Mathieu Desnoyers
-
+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.
@@ -34,21 +32,46 @@ This program is distributed in the hope that it will be useful,
    all types is maintained to facilitate the freeing of all type 
    information when the processing of an ".xml" file is finished. */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <stdlib.h> 
 #include <string.h>
 #include <stdio.h>
 #include <stdarg.h>
-#include <ctype.h>
-#include <linux/errno.h>
-#include <glib.h>
+#include <linux/errno.h>  
+#include <assert.h>
 
 
 #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
@@ -60,19 +83,19 @@ This program is distributed in the hope that it will be useful,
 
 int getSize(parse_file *in)
 {
-  gchar *token;
+  char *token;
 
   token = getToken(in);
   if(in->type == NUMBER) {
-    if(g_ascii_strcasecmp(token,"1") == 0) return 0;
-    else if(g_ascii_strcasecmp(token,"2") == 0) return 1;
-    else if(g_ascii_strcasecmp(token,"4") == 0) return 2;
-    else if(g_ascii_strcasecmp(token,"8") == 0) return 3;
+    if(strcmp(token,"1") == 0) return 0;
+    else if(strcmp(token,"2") == 0) return 1;
+    else if(strcmp(token,"4") == 0) return 2;
+    else if(strcmp(token,"8") == 0) return 3;
   }
   else if(in->type == NAME) {
-    if(g_ascii_strcasecmp(token,"short") == 0) return 4;
-    else if(g_ascii_strcasecmp(token,"medium") == 0) return 5;
-    else if(g_ascii_strcasecmp(token,"long") == 0) return 6;
+    if(strcmp(token,"short") == 0) return 4;
+    else if(strcmp(token,"medium") == 0) return 5;
+    else if(strcmp(token,"long") == 0) return 6;
   }
   in->error(in,"incorrect size specification");
   return -1;
@@ -89,91 +112,254 @@ int getSize(parse_file *in)
 void error_callback(parse_file *in, char *msg)
 {
   if(in)
-    g_printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg);
+    printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg);
   else
     printf("%s\n",msg);
+  assert(0);
+  exit(1);
+}
+
+/*****************************************************************************
+ *Function name
+ *    memAlloc  : allocate memory                    
+ *Input params 
+ *    size      : required memory size               
+ *return value 
+ *    void *    : pointer to allocate memory or NULL 
+ ****************************************************************************/
+
+void * memAlloc(int size)
+{
+  void * addr;
+  if(size == 0) return NULL;
+  addr = malloc(size);
+  if(!addr){
+    printf("Failed to allocate memory");    
+    exit(1);
+  }
+  return addr;   
+}
+
+/*****************************************************************************
+ *Function name
+ *    allocAndCopy : allocate memory and initialize it  
+ *Input params 
+ *    str          : string to be put in memory         
+ *return value 
+ *    char *       : pointer to allocate memory or NULL
+ ****************************************************************************/
+
+char *allocAndCopy(char *str)
+{
+  char * addr;
+  if(str == NULL) return NULL;
+  addr = (char *)memAlloc(strlen(str)+1);
+  strcpy(addr,str);
+  return addr;
 }
 
 /**************************************************************************
  * Function :
- *    getNameAttribute,getFormatAttribute,getSizeAttribute,getValueAttribute 
- *    getValueStrAttribute
+ *    getTypeAttributes
  * Description :
  *    Read the attribute from the input file.
  *
  * Parameters :
  *    in , input file handle.
- *
- * Return values :
- *    address of the attribute.
+ *    t , the type descriptor to fill.
  *
  **************************************************************************/
 
-gchar * getNameAttribute(parse_file *in)
+void getTypeAttributes(parse_file *in, type_descriptor *t)
 {
-  gchar * token;
-  gunichar car;
-  GIOStatus status;
-  
-  token = getName(in);
-  if(g_ascii_strcasecmp("name",token))in->error(in,"name was expected");
-  getEqual(in);
+  char * token;
+  char car;
+
+  t->fmt = NULL;
+  t->size = -1;
+  t->alignment = 0;
   
-  status = seekNextChar(in, &car);
-  if(status == G_IO_STATUS_EOF || status == G_IO_STATUS_ERROR)
-    in->error(in,"name was expected");
-  else if(car == '\"') token = getQuotedString(in);
-  else token = getName(in);
-  return token;
+  while(1) {
+    token = getToken(in); 
+    if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+      ungetToken(in);
+      break;
+    }
+    
+    if(!strcmp("format",token)) {
+      getEqual(in);
+      t->fmt = allocAndCopy(getQuotedString(in));
+    //} else if(!strcmp("name",token)) {
+     // getEqual(in);
+     // car = seekNextChar(in);
+     // if(car == EOF) in->error(in,"name was expected");
+     // else if(car == '\"') t->type_name = allocAndCopy(getQuotedString(in));
+     // else t->type_name = allocAndCopy(getName(in));
+    } else if(!strcmp("size",token)) {
+      getEqual(in);
+      t->size = getSize(in);
+    } else if(!strcmp("align",token)) {
+      getEqual(in);
+      t->alignment = getNumber(in);
+    }
+  }
 }
 
-char * getFormatAttribute(parse_file *in)
+/**************************************************************************
+ * Function :
+ *    getEventAttributes
+ * Description :
+ *    Read the attribute from the input file.
+ *
+ * Parameters :
+ *    in , input file handle.
+ *    ev , the event to fill.
+ *
+ **************************************************************************/
+
+void getEventAttributes(parse_file *in, event *ev)
 {
   char * token;
+  char car;
+  
+  ev->name = NULL;
+  ev->per_trace = 0;
+  ev->per_tracefile = 0;
+
+  while(1) {
+    token = getToken(in); 
+    if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+      ungetToken(in);
+      break;
+    }
+
+    if(!strcmp("name",token)) {
+      getEqual(in);
+      car = seekNextChar(in);
+      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;
+    }
 
-  //format is an option
-  token = getToken(in); 
-  if(g_ascii_strcasecmp("/",token) == 0 || g_ascii_strcasecmp(">",token) == 0){
-    ungetToken(in);
-    return NULL;
   }
+}
 
-  if(g_ascii_strcasecmp("format",token))in->error(in,"format was expected");
-  getEqual(in);
-  token = getQuotedString(in);
-  return token;
+/**************************************************************************
+ * Function :
+ *    getFacilityAttributes
+ * Description :
+ *    Read the attribute from the input file.
+ *
+ * Parameters :
+ *    in , input file handle.
+ *    fac , the facility to fill.
+ *
+ **************************************************************************/
+
+void getFacilityAttributes(parse_file *in, facility *fac)
+{
+  char * token;
+  char car;
+  
+  fac->name = NULL;
+
+  while(1) {
+    token = getToken(in); 
+    if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+      ungetToken(in);
+      break;
+    }
+
+    if(!strcmp("name",token)) {
+      getEqual(in);
+      car = seekNextChar(in);
+      if(car == EOF) in->error(in,"name was expected");
+      else if(car == '\"') fac->name = allocAndCopy(getQuotedString(in));
+      else fac->name = allocAndCopy(getName(in));
+    }
+  }
 }
 
-int getSizeAttribute(parse_file *in)
+/**************************************************************************
+ * Function :
+ *    getFieldAttributes
+ * Description :
+ *    Read the attribute from the input file.
+ *
+ * Parameters :
+ *    in , input file handle.
+ *    f , the field to fill.
+ *
+ **************************************************************************/
+
+void getFieldAttributes(parse_file *in, field *f)
 {
-  /* skip name and equal */
-  getName(in);
-  getEqual(in);
+  char * token;
+  char car;
+
+  f->name = NULL;
+
+  while(1) {
+    token = getToken(in); 
+    if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+      ungetToken(in);
+      break;
+    }
 
-  return getSize(in);
+    if(!strcmp("name",token)) {
+      getEqual(in);
+      car = seekNextChar(in);
+      if(car == EOF) in->error(in,"name was expected");
+      else if(car == '\"') f->name = allocAndCopy(getQuotedString(in));
+      else f->name = allocAndCopy(getName(in));
+    }
+  }
 }
 
-int getValueAttribute(parse_file *in)
+char *getNameAttribute(parse_file *in)
 {
-  /* skip name and equal */
-  getName(in);
-  getEqual(in);
+  char * token;
+  char *name = NULL;
+  char car;
+  
+  while(1) {
+    token = getToken(in); 
+    if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+      ungetToken(in);
+      break;
+    }
+
+    if(!strcmp("name",token)) {
+      getEqual(in);
+      car = seekNextChar(in);
+      if(car == EOF) in->error(in,"name was expected");
+      else if(car == '\"') name = allocAndCopy(getQuotedString(in));
+      else name = allocAndCopy(getName(in));
+    }
+  }
+  if(name == NULL) in->error(in, "Name was expected");
+  return name;
   
-  return getNumber(in);
 }
 
-//for <label name=label_name value=n/>, value is an option
+
+
+//for <label name=label_name value=n format="..."/>, value is an option
 char * getValueStrAttribute(parse_file *in)
 {
   char * token;
 
   token = getToken(in); 
-  if(g_ascii_strcasecmp("/",token) == 0){
+  if(strcmp("/",token) == 0){
     ungetToken(in);
     return NULL;
   }
   
-  if(g_ascii_strcasecmp("value",token))in->error(in,"value was expected");
+  if(strcmp("value",token))in->error(in,"value was expected");
   getEqual(in);
   token = getToken(in);
   if(in->type != NUMBER) in->error(in,"number was expected");
@@ -182,35 +368,22 @@ char * getValueStrAttribute(parse_file *in)
 
 char * getDescription(parse_file *in)
 {
-  gint64 pos;
-  gchar * token, *str;
-  gunichar car;
-  GError * error = NULL;
+  long int pos;
+  char * token, car, *str;
 
-  pos = in->pos;
+  pos = ftell(in->fp);
 
   getLAnglebracket(in);
   token = getName(in);
-  if(g_ascii_strcasecmp("description",token)){
-    g_io_channel_seek_position(in->channel, pos-(in->pos), G_SEEK_CUR, &error);
-    if(error != NULL) {
-      g_warning("Can not seek file: \n%s\n", error->message);
-      g_error_free(error);
-    } else in->pos = pos;
-
+  if(strcmp("description",token)){
+    fseek(in->fp, pos, SEEK_SET);
     return NULL;
   }
   
   getRAnglebracket(in);
 
   pos = 0;
-  while((g_io_channel_read_unichar(in->channel, &car, &error))
-            != G_IO_STATUS_EOF) {
-    if(error != NULL) {
-      g_warning("Can not seek file: \n%s\n", error->message);
-      g_error_free(error);
-    } else in->pos++;
-
+  while((car = getc(in->fp)) != EOF) {
     if(car == '<') break;
     if(car == '\0') continue;
     in->buffer[pos] = car;
@@ -219,11 +392,11 @@ char * getDescription(parse_file *in)
   if(car == EOF)in->error(in,"not a valid description");
   in->buffer[pos] = '\0';
 
-  str = g_strdup(in->buffer);
+  str = allocAndCopy(in->buffer);
 
   getForwardslash(in);
   token = getName(in);
-  if(g_ascii_strcasecmp("description", token))in->error(in,"not a valid description");
+  if(strcmp("description", token))in->error(in,"not a valid description");
   getRAnglebracket(in);
 
   return str;
@@ -239,12 +412,16 @@ char * getDescription(parse_file *in)
  *    fac           : facility filled with event list
  ****************************************************************************/
 
-void parseFacility(parse_file *in, facility_t * fac)
+void parseFacility(parse_file *in, facility * fac)
 {
   char * token;
-  event_t *ev;
+  event *ev;
   
-  fac->name = g_strdup(getNameAttribute(in));    
+  getFacilityAttributes(in, fac);
+  if(fac->name == NULL) in->error(in, "Attribute not named");
+
+  fac->capname = allocAndCopy(fac->name);
+       strupper(fac->capname);
   getRAnglebracket(in);    
   
   fac->description = getDescription(in);
@@ -256,11 +433,11 @@ void parseFacility(parse_file *in, facility_t * fac)
     if(in->type == ENDFILE)
       in->error(in,"the definition of the facility is not finished");
 
-    if(g_ascii_strcasecmp("event",token) == 0){
-      ev = (event_t*) g_new(event_t,1);
+    if(strcmp("event",token) == 0){
+      ev = (event*) memAlloc(sizeof(event));
       sequence_push(&(fac->events),ev);
       parseEvent(in,ev, &(fac->unnamed_types), &(fac->named_types));    
-    }else if(g_ascii_strcasecmp("type",token) == 0){
+    }else if(strcmp("type",token) == 0){
       parseTypeDefinition(in, &(fac->unnamed_types), &(fac->named_types));
     }else if(in->type == FORWARDSLASH){
       break;
@@ -268,7 +445,7 @@ void parseFacility(parse_file *in, facility_t * fac)
   }
 
   token = getName(in);
-  if(g_ascii_strcasecmp("facility",token)) in->error(in,"not the end of the facility");
+  if(strcmp("facility",token)) in->error(in,"not the end of the facility");
   getRAnglebracket(in); //</facility>
 }
 
@@ -284,13 +461,15 @@ void parseFacility(parse_file *in, facility_t * fac)
  *    ev            : new event (parameters are passed to it)   
  ****************************************************************************/
 
-void parseEvent(parse_file *in, event_t * ev, sequence * unnamed_types, 
+void parseEvent(parse_file *in, event * ev, sequence * unnamed_types, 
                table * named_types) 
 {
   char *token;
+  type_descriptor *t;
 
   //<event name=eventtype_name>
-  ev->name = g_strdup(getNameAttribute(in));
+  getEventAttributes(in, ev);
+  if(ev->name == NULL) in->error(in, "Event not named");
   getRAnglebracket(in);  
 
   //<description>...</descriptio>
@@ -303,7 +482,7 @@ void parseEvent(parse_file *in, event_t * ev, sequence * unnamed_types,
   if(in->type == FORWARDSLASH){ //</event> NOTHING
     ev->type = NULL;
   }else if(in->type == NAME){
-    if(g_ascii_strcasecmp("struct",token)==0 || g_ascii_strcasecmp("typeref",token)==0){
+    if(strcmp("struct",token)==0 || strcmp("typeref",token)==0){
       ungetToken(in);
       ev->type = parseType(in,NULL, unnamed_types, named_types);
       if(ev->type->type != STRUCT && ev->type->type != NONE) 
@@ -315,7 +494,7 @@ void parseEvent(parse_file *in, event_t * ev, sequence * unnamed_types,
   }else in->error(in,"not a struct type");
 
   token = getName(in);
-  if(g_ascii_strcasecmp("event",token))in->error(in,"not an event definition");
+  if(strcmp("event",token))in->error(in,"not an event definition");
   getRAnglebracket(in);  //</event>
 }
 
@@ -333,13 +512,14 @@ void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types,
                 table * named_types) 
 {
   char * token;
-  type_fields *f;
+  field *f;
 
-  f = g_new(type_fields,1);
+  f = (field *)memAlloc(sizeof(field));
   sequence_push(&(t->fields),f);
 
   //<field name=field_name> <description> <type> </field>
-  f->name = g_strdup(getNameAttribute(in)); 
+  getFieldAttributes(in, f);
+  if(f->name == NULL) in->error(in, "Field not named");
   getRAnglebracket(in);
 
   f->description = getDescription(in);
@@ -351,7 +531,7 @@ void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types,
   getLAnglebracket(in);
   getForwardslash(in);
   token = getName(in);
-  if(g_ascii_strcasecmp("field",token))in->error(in,"not a valid field definition");
+  if(strcmp("field",token))in->error(in,"not a valid field definition");
   getRAnglebracket(in); //</field>
 }
 
@@ -383,7 +563,7 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
   type_descriptor *t;
 
   if(inType == NULL) {
-    t = g_new(type_descriptor,1);
+    t = (type_descriptor *) memAlloc(sizeof(type_descriptor));
     t->type_name = NULL;
     t->type = NONE;
     t->fmt = NULL;
@@ -393,63 +573,67 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
 
   token = getName(in);
 
-  if(g_ascii_strcasecmp(token,"struct") == 0) {
+  if(strcmp(token,"struct") == 0) {
     t->type = STRUCT;
+    getTypeAttributes(in, t);
     getRAnglebracket(in); //<struct>
     getLAnglebracket(in); //<field name=..>
     token = getToken(in);
     sequence_init(&(t->fields));
-    while(g_ascii_strcasecmp("field",token) == 0){
+    while(strcmp("field",token) == 0){
       parseFields(in,t, unnamed_types, named_types);
       
       //next field
       getLAnglebracket(in);
       token = getToken(in);    
     }
-    if(g_ascii_strcasecmp("/",token))in->error(in,"not a valid structure definition");
+    if(strcmp("/",token))in->error(in,"not a valid structure definition");
     token = getName(in);
-    if(g_ascii_strcasecmp("struct",token)!=0)
+    if(strcmp("struct",token)!=0)
       in->error(in,"not a valid structure definition");
     getRAnglebracket(in); //</struct>
   }
-  else if(g_ascii_strcasecmp(token,"union") == 0) {
+  else if(strcmp(token,"union") == 0) {
     t->type = UNION;
-    t->size = getSizeAttribute(in);
+    getTypeAttributes(in, t);
+    if(t->size == -1) in->error(in, "Union has empty size");
     getRAnglebracket(in); //<union typecodesize=isize>
 
     getLAnglebracket(in); //<field name=..>
     token = getToken(in);
     sequence_init(&(t->fields));
-    while(g_ascii_strcasecmp("field",token) == 0){
+    while(strcmp("field",token) == 0){
       parseFields(in,t, unnamed_types, named_types);
       
       //next field
       getLAnglebracket(in);
       token = getToken(in);    
     }
-    if(g_ascii_strcasecmp("/",token))in->error(in,"not a valid union definition");
+    if(strcmp("/",token))in->error(in,"not a valid union definition");
     token = getName(in);
-    if(g_ascii_strcasecmp("union",token)!=0)
+    if(strcmp("union",token)!=0)
       in->error(in,"not a valid union definition");        
     getRAnglebracket(in); //</union>
   }
-  else if(g_ascii_strcasecmp(token,"array") == 0) {
+  else if(strcmp(token,"array") == 0) {
     t->type = ARRAY;
-    t->size = getValueAttribute(in);
+    getTypeAttributes(in, t);
+    if(t->size == -1) in->error(in, "Array has empty size");
     getRAnglebracket(in); //<array size=n>
 
     getLAnglebracket(in); //<type struct> 
-    t->nested_type = parseType(in,NULL, unnamed_types, named_types);
+    t->nested_type = parseType(in, NULL, unnamed_types, named_types);
 
     getLAnglebracket(in); //</array>
     getForwardslash(in);
     token = getName(in);
-    if(g_ascii_strcasecmp("array",token))in->error(in,"not a valid array definition");
+    if(strcmp("array",token))in->error(in,"not a valid array definition");
     getRAnglebracket(in);  //</array>
   }
-  else if(g_ascii_strcasecmp(token,"sequence") == 0) {
+  else if(strcmp(token,"sequence") == 0) {
     t->type = SEQUENCE;
-    t->size = getSizeAttribute(in);
+    getTypeAttributes(in, t);
+    if(t->size == -1) in->error(in, "Sequence has empty size");
     getRAnglebracket(in); //<array lengthsize=isize>
 
     getLAnglebracket(in); //<type struct> 
@@ -458,75 +642,119 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
     getLAnglebracket(in); //</sequence>
     getForwardslash(in);
     token = getName(in);
-    if(g_ascii_strcasecmp("sequence",token))in->error(in,"not a valid sequence definition");
+    if(strcmp("sequence",token))in->error(in,"not a valid sequence definition");
     getRAnglebracket(in); //</sequence>
   }
-  else if(g_ascii_strcasecmp(token,"enum") == 0) {
+  else if(strcmp(token,"enum") == 0) {
     char * str, *str1;
     t->type = ENUM;
     sequence_init(&(t->labels));
-    t->size = getSizeAttribute(in);
-    t->fmt = g_strdup(getFormatAttribute(in));
+    sequence_init(&(t->labels_description));
+               t->already_printed = 0;
+    getTypeAttributes(in, t);
+    if(t->size == -1) in->error(in, "Sequence has empty size");
     getRAnglebracket(in);
 
     //<label name=label1 value=n/>
     getLAnglebracket(in);
     token = getToken(in); //"label" or "/"
-    while(g_ascii_strcasecmp("label",token) == 0){
-      str1   = g_strdup(getNameAttribute(in));      
+    while(strcmp("label",token) == 0){
+      str   = allocAndCopy(getNameAttribute(in));      
       token = getValueStrAttribute(in);
       if(token){
-             str = g_strconcat(str1,"=",token,NULL);
-       g_free(str1);
+       str1 = appendString(str,"=");
+       free(str);
+       str = appendString(str1,token);
+       free(str1);
+       sequence_push(&(t->labels),str);
+      }
+      else
        sequence_push(&(t->labels),str);
-      }else
-       sequence_push(&(t->labels),str1);
 
       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 "/"      
     }
-    if(g_ascii_strcasecmp("/",token))in->error(in, "not a valid enum definition");
+    if(strcmp("/",token))in->error(in, "not a valid enum definition");
     token = getName(in);
-    if(g_ascii_strcasecmp("enum",token))in->error(in, "not a valid enum definition");
-    getRAnglebracket(in); //</label>
+    if(strcmp("enum",token))in->error(in, "not a valid enum definition");
+      getRAnglebracket(in); //</label>
   }
-  else if(g_ascii_strcasecmp(token,"int") == 0) {
+  else if(strcmp(token,"int") == 0) {
     t->type = INT;
-    t->size = getSizeAttribute(in);
-    t->fmt  = g_strdup(getFormatAttribute(in));
+    getTypeAttributes(in, t);
+    if(t->size == -1) in->error(in, "int has empty size");
     getForwardslash(in);
     getRAnglebracket(in); 
   }
-  else if(g_ascii_strcasecmp(token,"uint") == 0) {
+  else if(strcmp(token,"uint") == 0) {
     t->type = UINT;
-    t->size = getSizeAttribute(in);
-    t->fmt  = g_strdup(getFormatAttribute(in));
+    getTypeAttributes(in, t);
+    if(t->size == -1) in->error(in, "uint has empty size");
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"pointer") == 0) {
+    t->type = POINTER;
+    getTypeAttributes(in, t);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
-  else if(g_ascii_strcasecmp(token,"float") == 0) {
+  else if(strcmp(token,"long") == 0) {
+    t->type = LONG;
+    getTypeAttributes(in, t);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"ulong") == 0) {
+    t->type = ULONG;
+    getTypeAttributes(in, t);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"size_t") == 0) {
+    t->type = SIZE_T;
+    getTypeAttributes(in, t);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"ssize_t") == 0) {
+    t->type = SSIZE_T;
+    getTypeAttributes(in, t);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"off_t") == 0) {
+    t->type = OFF_T;
+    getTypeAttributes(in, t);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"float") == 0) {
     t->type = FLOAT;
-    t->size = getSizeAttribute(in);
-    t->fmt  = g_strdup(getFormatAttribute(in));
+    getTypeAttributes(in, t);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
-  else if(g_ascii_strcasecmp(token,"string") == 0) {
+  else if(strcmp(token,"string") == 0) {
     t->type = STRING;
-    t->fmt  = g_strdup(getFormatAttribute(in));
+    getTypeAttributes(in, t);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
-  else if(g_ascii_strcasecmp(token,"typeref") == 0){
+  else if(strcmp(token,"typeref") == 0){
     // Must be a named type
     if(inType != NULL) 
       in->error(in,"Named type cannot refer to a named type");
     else {
-      g_free(t);
+      free(t);
       sequence_pop(unnamed_types);
       token = getNameAttribute(in);
       t = find_named_type(token, named_types);
@@ -549,18 +777,18 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
  *    type_descriptor *   : a type descriptor                       
  *****************************************************************************/
 
-type_descriptor * find_named_type(gchar *name, table * named_types)
+type_descriptor * find_named_type(char *name, table * named_types)
 { 
   type_descriptor *t;
 
   t = table_find(named_types,name);
   if(t == NULL) {
-    t = g_new(type_descriptor,1);
-    t->type_name = g_strdup(name);
+    t = (type_descriptor *)memAlloc(sizeof(type_descriptor));
+    t->type_name = allocAndCopy(name);
     t->type = NONE;
     t->fmt = NULL;
     table_insert(named_types,t->type_name,t);
-    //    table_insert(named_types,g_strdup(name),t);
+    //    table_insert(named_types,allocAndCopy(name),t);
   }
   return t;
 }  
@@ -581,13 +809,14 @@ void parseTypeDefinition(parse_file * in, sequence * unnamed_types,
   type_descriptor *t;
 
   token = getNameAttribute(in);
+  if(token == NULL) in->error(in, "Type has empty name");
   t = find_named_type(token, named_types);
 
   if(t->type != NONE) in->error(in,"redefinition of named type");
   getRAnglebracket(in); //<type name=type_name>
-  getLAnglebracket(in); //<struct>
+  getLAnglebracket(in); //<
   token = getName(in);
-  if(g_ascii_strcasecmp("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);
   
@@ -595,7 +824,7 @@ void parseTypeDefinition(parse_file * in, sequence * unnamed_types,
   getLAnglebracket(in);
   getForwardslash(in);
   token = getName(in);
-  if(g_ascii_strcasecmp("type",token))in->error(in,"not a valid type definition");  
+  if(strcmp("type",token))in->error(in,"not a valid type definition");  
   getRAnglebracket(in); //</type>
 }
 
@@ -676,38 +905,18 @@ char * getEqual(parse_file *in)
   return token;
 }
 
-gunichar seekNextChar(parse_file *in, gunichar *car)
+char seekNextChar(parse_file *in)
 {
-  GError * error = NULL;
-  GIOStatus status;
-
-  do {
-
-    status = g_io_channel_read_unichar(in->channel, car, &error);
-    
-    if(error != NULL) {
-      g_warning("Can not read file: \n%s\n", error->message);
-      g_error_free(error);
-      break;
-    }
-    in->pos++;
-   
-    if(!g_unichar_isspace(*car)) {
-      g_io_channel_seek_position(in->channel, -1, G_SEEK_CUR, &error);
-      if(error != NULL) {
-        g_warning("Can not seek file: \n%s\n", error->message);
-        g_error_free(error);
-      }
-      in->pos--;
-      break;
+  char car;
+  while((car = getc(in->fp)) != EOF) {
+    if(!isspace(car)){
+      ungetc(car,in->fp);
+      return car;
     }
-
-  } while(status != G_IO_STATUS_EOF && status != G_IO_STATUS_ERROR);
-
-  return status;
+  }  
+  return EOF;
 }
 
-
 /******************************************************************
  * Function :
  *    getToken, ungetToken
@@ -728,11 +937,11 @@ void ungetToken(parse_file * in)
   in->unget = 1;
 }
 
-gchar *getToken(parse_file * in)
+char *getToken(parse_file * in)
 {
-  gunichar car, car1;
+  FILE *fp = in->fp;
+  char car, car1;
   int pos = 0, escaped;
-  GError * error = NULL;
 
   if(in->unget == 1) {
     in->unget = 0;
@@ -741,35 +950,20 @@ gchar *getToken(parse_file * in)
 
   /* skip whitespace and comments */
 
-  while((g_io_channel_read_unichar(in->channel, &car, &error))
-      != G_IO_STATUS_EOF) {
-
-    if(error != NULL) {
-      g_warning("Can not read file: \n%s\n", error->message);
-      g_error_free(error);
-    } else in->pos++;
-
+  while((car = getc(fp)) != EOF) {
     if(car == '/') {
-      g_io_channel_read_unichar(in->channel, &car1, &error);
-      if(error != NULL) {
-        g_warning("Can not read file: \n%s\n", error->message);
-        g_error_free(error);
-      } else in->pos++;
-
+      car1 = getc(fp); 
       if(car1 == '*') skipComment(in);
       else if(car1 == '/') skipEOL(in);
-      else {
-        g_io_channel_seek_position(in->channel, -1, G_SEEK_CUR, &error);
-        if(error != NULL) {
-          g_warning("Can not seek file: \n%s\n", error->message);
-          g_error_free(error);
-        } else in->pos--;
+      else { 
+        car1 = ungetc(car1,fp);
         break;
       }
     }
     else if(car == '\n') in->lineno++;
-    else if(!g_unichar_isspace(car)) break;
+    else if(!isspace(car)) break;
   }
+
   switch(car) {
     case EOF:
       in->type = ENDFILE;
@@ -796,17 +990,10 @@ gchar *getToken(parse_file * in)
       break;
     case '"':
       escaped = 0;
-      while(g_io_channel_read_unichar(in->channel, &car, &error)
-                  != G_IO_STATUS_EOF && pos < BUFFER_SIZE) {
-
-        if(error != NULL) {
-          g_warning("Can not read file: \n%s\n", error->message);
-          g_error_free(error);
-        } else in->pos++;
-
+      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;
         }
@@ -824,67 +1011,33 @@ gchar *getToken(parse_file * in)
       in->type = QUOTEDSTRING;
       break;
     default:
-      if(g_unichar_isdigit(car)) {
+      if(isdigit(car)) {
         in->buffer[pos] = car;
         pos++;
-        while(g_io_channel_read_unichar(in->channel, &car, &error)
-                    != G_IO_STATUS_EOF && pos < BUFFER_SIZE) {
-
-          if(error != NULL) {
-            g_warning("Can not read file: \n%s\n", error->message);
-            g_error_free(error);
-          } else in->pos++;
-
+        while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
           if(!isdigit(car)) {
-            g_io_channel_seek_position(in->channel, -1, G_SEEK_CUR, &error);
-            if(error != NULL) {
-              g_warning("Can not seek file: \n%s\n", error->message);
-              g_error_free(error);
-            } else in->pos--;
+            ungetc(car,fp);
             break;
           }
           in->buffer[pos] = car;
           pos++;
         }
-             if(car == EOF) {
-          g_io_channel_seek_position(in->channel, -1, G_SEEK_CUR, &error);
-          if(error != NULL) {
-            g_warning("Can not seek file: \n%s\n", error->message);
-            g_error_free(error);
-          } else in->pos--;
-        }
+       if(car == EOF) ungetc(car,fp);
         if(pos == BUFFER_SIZE) in->error(in, "number token too large");
         in->type = NUMBER;
       }    
-      else if(g_unichar_isalpha(car)) {
+      else if(isalpha(car)) {
         in->buffer[0] = car;
         pos = 1;
-        while(g_io_channel_read_unichar(in->channel, &car, &error)
-                              != G_IO_STATUS_EOF && pos < BUFFER_SIZE) {
-
-          if(error != NULL) {
-            g_warning("Can not read file: \n%s\n", error->message);
-            g_error_free(error);
-          } else in->pos++;
-
-          if(!(g_unichar_isalnum(car) || car == '_')) {
-            g_io_channel_seek_position(in->channel, -1, G_SEEK_CUR, &error);
-            if(error != NULL) {
-              g_warning("Can not seek file: \n%s\n", error->message);
-              g_error_free(error);
-            } else in->pos--;
+        while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
+          if(!(isalnum(car) || car == '_')) {
+            ungetc(car,fp);
             break;
           }
           in->buffer[pos] = car;
           pos++;
         }
-             if(car == EOF) {
-          g_io_channel_seek_position(in->channel, -1, G_SEEK_CUR, &error);
-          if(error != NULL) {
-            g_warning("Can not seek file: \n%s\n", error->message);
-            g_error_free(error);
-          } else in->pos--;
-        }
+       if(car == EOF) ungetc(car,fp);
         if(pos == BUFFER_SIZE) in->error(in, "name token too large");
         in->type = NAME;
       }
@@ -896,35 +1049,14 @@ gchar *getToken(parse_file * in)
 
 void skipComment(parse_file * in)
 {
-  gunichar car;
-  GError * error = NULL;
-
-  while(g_io_channel_read_unichar(in->channel, &car, &error)
-                                    != G_IO_STATUS_EOF) {
-
-    if(error != NULL) {
-      g_warning("Can not read file: \n%s\n", error->message);
-      g_error_free(error);
-    } else in->pos++;
-
+  char car;
+  while((car = getc(in->fp)) != EOF) {
     if(car == '\n') in->lineno++;
     else if(car == '*') {
-
-      g_io_channel_read_unichar(in->channel, &car, &error);
-      if(error != NULL) {
-        g_warning("Can not read file: \n%s\n", error->message);
-        g_error_free(error);
-      } else in->pos++;
-
+      car = getc(in->fp);
       if(car ==EOF) break;
       if(car == '/') return;
-
-      g_io_channel_seek_position(in->channel, -1, G_SEEK_CUR, &error);
-      if(error != NULL) {
-        g_warning("Can not seek file: \n%s\n", error->message);
-        g_error_free(error);
-      } else in->pos--;
-
+      ungetc(car,in->fp);
     }
   }
   if(car == EOF) in->error(in,"comment begining with '/*' has no ending '*/'");
@@ -932,36 +1064,22 @@ void skipComment(parse_file * in)
 
 void skipEOL(parse_file * in)
 {
-  gunichar car;
-  GError * error = NULL;
-
-  while(g_io_channel_read_unichar(in->channel, &car, &error)
-                                          != G_IO_STATUS_EOF) {
+  char car;
+  while((car = getc(in->fp)) != EOF) {
     if(car == '\n') {
-      g_io_channel_seek_position(in->channel, -1, G_SEEK_CUR, &error);
-      if(error != NULL) {
-        g_warning("Can not seek file: \n%s\n", error->message);
-        g_error_free(error);
-      } else in->pos--;
+      ungetc(car,in->fp);
       break;
     }
   }
-  if(car == EOF) {
-    g_io_channel_seek_position(in->channel, -1, G_SEEK_CUR, &error);
-    if(error != NULL) {
-      g_warning("Can not seek file: \n%s\n", error->message);
-      g_error_free(error);
-    } else in->pos--;
-  }
+  if(car == EOF)ungetc(car, in->fp);
 }
 
 /*****************************************************************************
  *Function name
  *    checkNamedTypesImplemented : check if all named types have definition
- *    returns -1 on error, 0 if ok
  ****************************************************************************/
 
-int checkNamedTypesImplemented(table * named_types)
+void checkNamedTypesImplemented(table * named_types)
 {
   type_descriptor *t;
   int pos;
@@ -970,13 +1088,10 @@ int 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);
-      return -1;
+      sprintf(str,"named type '%s' has no definition",(char*)named_types->keys.array[pos]);
+      error_callback(NULL,str);   
     }
   }
-  return 0;
 }
 
 
@@ -989,27 +1104,25 @@ int checkNamedTypesImplemented(table * named_types)
  *    checksum          : checksum for the facility
  ****************************************************************************/
 
-int generateChecksum(char* facName, guint32 * checksum, sequence * events)
+void generateChecksum( char* facName, unsigned long * checksum, sequence * events)
 {
   unsigned long crc ;
   int pos;
-  event_t * ev;
+  event * ev;
   char str[256];
 
   crc = crc32(facName);
   for(pos = 0; pos < events->position; pos++){
-    ev = (event_t *)(events->array[pos]);
+    ev = (event *)(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;
 }
 
 /*****************************************************************************
@@ -1027,7 +1140,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type)
   unsigned long crc = aCrc;
   char * str = NULL, buf[16];
   int flag = 0, pos;
-  type_fields * fld;
+  field * fld;
 
   switch(type->type){
     case INT:
@@ -1036,33 +1149,57 @@ 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;
     case STRING:
-      str = g_strdup("string");
+      str = allocAndCopy("string");
       flag = 1;
       break;
     case ENUM:
-      str = g_strconcat("enum ", uintOutputTypes[type->size], NULL);
+      str = appendString("enum ", uintOutputTypes[type->size]);
       flag = 1;
       break;
     case ARRAY:
-      sprintf(buf,"%d",type->size);
-      str = g_strconcat("array ",buf, NULL);
+      sprintf(buf,"%d\0",type->size);
+      str = appendString("array ",buf);
       flag = 1;
       break;
     case SEQUENCE:
-      sprintf(buf,"%d",type->size);
-      str = g_strconcat("sequence ",buf, NULL);
+      sprintf(buf,"%d\0",type->size);
+      str = appendString("sequence ",buf);
       flag = 1;
       break;
     case STRUCT:
-      str = g_strdup("struct");
+      str = allocAndCopy("struct");
       flag = 1;
       break;
     case UNION:
-      str = g_strdup("union");
+      str = allocAndCopy("union");
       flag = 1;
       break;
     default:
@@ -1071,7 +1208,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type)
   }
 
   crc = partial_crc32(str,crc);
-  if(flag) g_free(str);
+  if(flag) free(str);
 
   if(type->fmt) crc = partial_crc32(type->fmt,crc);
     
@@ -1079,7 +1216,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 = (type_fields *) type->fields.array[pos];
+      fld = (field *) type->fields.array[pos];
       crc = partial_crc32(fld->name,crc);
       crc = getTypeChecksum(crc, fld->type);
     }    
@@ -1096,21 +1233,21 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type)
 void freeType(type_descriptor * tp)
 {
   int pos2;
-  type_fields *f;
+  field *f;
 
-  if(tp->fmt != NULL) g_free(tp->fmt);
+  if(tp->fmt != NULL) free(tp->fmt);
   if(tp->type == ENUM) {
     for(pos2 = 0; pos2 < tp->labels.position; pos2++) {
-      g_free(tp->labels.array[pos2]);
+      free(tp->labels.array[pos2]);
     }
     sequence_dispose(&(tp->labels));
   }
   if(tp->type == STRUCT) {
     for(pos2 = 0; pos2 < tp->fields.position; pos2++) {
-      f = (type_fields *) tp->fields.array[pos2];
-      g_free(f->name);
-      g_free(f->description);
-      g_free(f);
+      f = (field *) tp->fields.array[pos2];
+      free(f->name);
+      free(f->description);
+      free(f);
     }
     sequence_dispose(&(tp->fields));
   }
@@ -1122,35 +1259,36 @@ void freeNamedType(table * t)
   type_descriptor * td;
 
   for(pos = 0 ; pos < t->keys.position; pos++) {
-    g_free((char *)t->keys.array[pos]);
+    free((char *)t->keys.array[pos]);
     td = (type_descriptor*)t->values.array[pos];
     freeType(td);
-    g_free(td);
+    free(td);
   }
 }
 
 void freeTypes(sequence *t) 
 {
-  int pos;
+  int pos, pos2;
   type_descriptor *tp;
+  field *f;
 
   for(pos = 0 ; pos < t->position; pos++) {
     tp = (type_descriptor *)t->array[pos];
     freeType(tp);
-    g_free(tp);
+    free(tp);
   }
 }
 
 void freeEvents(sequence *t) 
 {
   int pos;
-  event_t *ev;
+  event *ev;
 
   for(pos = 0 ; pos < t->position; pos++) {
-    ev = (event_t *) t->array[pos];
-    g_free(ev->name);
-    g_free(ev->description);
-    g_free(ev);
+    ev = (event *) t->array[pos];
+    free(ev->name);
+    free(ev->description);
+    free(ev);
   }
 
 }
@@ -1162,13 +1300,13 @@ void sequence_init(sequence *t)
 {
   t->size = 10;
   t->position = 0;
-  t->array = g_new(void*, t->size);
+  t->array = (void **)memAlloc(t->size * sizeof(void *));
 }
 
 void sequence_dispose(sequence *t) 
 {
   t->size = 0;
-  g_free(t->array);
+  free(t->array);
   t->array = NULL;
 }
 
@@ -1178,10 +1316,10 @@ void sequence_push(sequence *t, void *elem)
 
   if(t->position >= t->size) {
     tmp = t->array;
-    t->array = g_new(void*, 2*t->size);
+    t->array = (void **)memAlloc(t->size * 2 * sizeof(void *));
     memcpy(t->array, tmp, t->size * sizeof(void *));
     t->size = t->size * 2;
-    g_free(tmp);
+    free(tmp);
   }
   t->array[t->position] = elem;
   t->position++;
@@ -1217,7 +1355,7 @@ void *table_find(table *t, char *key)
 {
   int pos;
   for(pos = 0 ; pos < t->keys.position; pos++) {
-    if(g_ascii_strcasecmp((char *)key,(char *)t->keys.array[pos]) == 0)
+    if(strcmp((char *)key,(char *)t->keys.array[pos]) == 0)
       return(t->values.array[pos]);
   }
   return NULL;
@@ -1240,3 +1378,17 @@ void *table_find_int(table *t, int *key)
 }
 
 
+/* Concatenate strings */
+
+char *appendString(char *s, char *suffix) 
+{
+  char *tmp;
+  if(suffix == NULL) return s;
+
+  tmp = (char *)memAlloc(strlen(s) + strlen(suffix) + 1);
+  strcpy(tmp,s);
+  strcat(tmp,suffix);  
+  return tmp;
+}
+
+
This page took 0.058299 seconds and 4 git commands to generate.