UTF8 fix
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Fri, 13 May 2005 23:52:48 +0000 (23:52 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Fri, 13 May 2005 23:52:48 +0000 (23:52 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@929 04897980-b3bd-0310-b5e0-8ef037075253

ltt/branches/poly/ltt/event.c
ltt/branches/poly/ltt/event.h
ltt/branches/poly/ltt/facility.c
ltt/branches/poly/ltt/facility.h
ltt/branches/poly/ltt/ltt-private.h
ltt/branches/poly/ltt/parser.c
ltt/branches/poly/ltt/parser.h
ltt/branches/poly/ltt/trace.h
ltt/branches/poly/ltt/tracefile.c
ltt/branches/poly/ltt/type.c
ltt/branches/poly/ltt/type.h

index fab8ed324aa6304c9c6b75b2d8433dbc87eb5e68..b7da64e5d7362a10bc04486f5f658329bddfce16 100644 (file)
@@ -90,7 +90,7 @@ int ltt_event_refresh_fields(int offsetRoot,int offsetParent,
       break;
 
     case LTT_STRING:
-      size = strlen((char*)evD) + 1; //include end : '\0'
+      size = strlen((gchar*)evD) + 1; //include end : '\0'
       break;
 
     case LTT_STRUCT:
@@ -452,7 +452,7 @@ void ltt_event_position_copy(LttEventPosition *dest,
 
 unsigned ltt_event_cpu_id(LttEvent *e)
 { 
-  char * c1, * c2, * c3;
+  gchar * c1, * c2, * c3;
   c1 = strrchr(e->tracefile->name,'\\');
   c2 = strrchr(e->tracefile->name,'/');
   if(c1 == NULL && c2 == NULL){
@@ -701,5 +701,5 @@ char *ltt_event_get_string(LttEvent *e, LttField *f)
 {
   g_assert(f->field_type->type_class == LTT_STRING);
 
-  return (char*)g_strdup((char*)(e->data + f->offset_root));
+  return (gchar*)g_strdup((gchar*)(e->data + f->offset_root));
 }
index f13710754bfd2124335188f8937bf90b7a125b82..3f1f89725a49fa96f872cdf7785cca4f5ac0ef30 100644 (file)
@@ -130,6 +130,6 @@ double ltt_event_get_double(LttEvent *e, LttField *f);
 /* The string obtained is only valid until the next read from
    the same tracefile. */
 
-char *ltt_event_get_string(LttEvent *e, LttField *f);
+gchar *ltt_event_get_string(LttEvent *e, LttField *f);
 
 #endif // EVENT_H
index 55077aa3d1d713b529d8f561791bcfdd68e2827a..47db6b80c29c7108fc1e1b0e95162814b339bc39 100644 (file)
 #include <stdlib.h> 
 #include <string.h>
 #include <stdio.h>
+#include <glib/gstdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+
 
 #include "parser.h"
 #include <ltt/ltt.h>
 #include "ltt-private.h"
 #include <ltt/facility.h>
 
+#define g_close close
+
 /* search for the (named) type in the table, if it does not exist
    create a new one */
 LttType * lookup_named_type(LttFacility *fac, type_descriptor * td);
@@ -53,31 +61,36 @@ void freeLttNamedType(LttType * type);
  *    pathname                : the path name of the facility   
  ****************************************************************************/
 
-void ltt_facility_open(LttTrace * t, char * pathname)
+void ltt_facility_open(LttTrace * t, gchar * pathname)
 {
-  char *token;
+  gchar *token;
   parse_file in;
-  char buffer[BUFFER_SIZE];
+  gsize length;
   facility_t * fac;
   LttFacility * f;
   LttChecksum checksum;
+  GError * error = NULL;
+  gchar buffer[BUFFER_SIZE];
 
-  in.buffer = buffer;
+  in.buffer = &(buffer[0]);
   in.lineno = 0;
   in.error = error_callback;
   in.name = pathname;
 
-  in.fp = fopen(in.name, "r");
-  if(!in.fp ) in.error(&in,"cannot open input file");
+  in.fd = g_open(in.name, O_RDONLY, 0);
+  if(in.fd < 0 ) in.error(&in,"cannot open input file");
+
+  in.channel = g_io_channel_unix_new(in.fd);
+  in.pos = 0;
 
   while(1){
     token = getToken(&in);
     if(in.type == ENDFILE) break;
     
-    if(strcmp(token, "<")) in.error(&in,"not a facility file");
+    if(g_ascii_strcasecmp(token, "<")) in.error(&in,"not a facility file");
     token = getName(&in);
-    
-    if(strcmp("facility",token) == 0) {
+
+    if(g_ascii_strcasecmp("facility",token) == 0) {
       fac = g_new(facility_t, 1);
       fac->name = NULL;
       fac->description = NULL;
@@ -99,8 +112,8 @@ void ltt_facility_open(LttTrace * t, char * pathname)
       t->facility_number++;
       g_ptr_array_add(t->facilities,f);
 
-      free(fac->name);
-      free(fac->description);
+      g_free(fac->name);
+      g_free(fac->description);
       freeEvents(&fac->events);
       sequence_dispose(&fac->events);
       freeNamedType(&fac->named_types);
@@ -111,7 +124,14 @@ void ltt_facility_open(LttTrace * t, char * pathname)
     }
     else in.error(&in,"facility token was expected");
   }
-  fclose(in.fp);
+
+  g_io_channel_shutdown(in.channel, FALSE, &error); /* No flush */
+  if(error != NULL) {
+    g_warning("Can not close file: \n%s\n", error->message);
+    g_error_free(error);
+  }
+
+  g_close(in.fd);
 }
 
 
@@ -287,13 +307,13 @@ LttType * lookup_named_type(LttFacility *fac, type_descriptor * td)
 {
   LttType * lttType = NULL;
   unsigned int i=0;
-  char * name;
+  gchar * name;
 
   if(td->type_name){
     for(i=0;i<fac->named_types_number; i++){
       if(fac->named_types[i] == NULL) break;
       name = fac->named_types[i]->type_name;
-      if(strcmp(name, td->type_name)==0){
+      if(g_ascii_strcasecmp(name, td->type_name)==0){
              lttType = fac->named_types[i];    
        //      if(lttType->element_name) g_free(lttType->element_name);
        //      lttType->element_name = NULL;
@@ -449,7 +469,7 @@ void freeLttField(LttField * fld)
  *    char *                  : the facility's name
  ****************************************************************************/
 
-char *ltt_facility_name(LttFacility *f)
+gchar *ltt_facility_name(LttFacility *f)
 {
   return f->name;
 }
@@ -523,14 +543,14 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *f, unsigned i)
  *    LttEventType *  : the event type required  
  ****************************************************************************/
 
-LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, char *name)
+LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, gchar *name)
 {
   unsigned int i;
   LttEventType * ev = NULL;
   
   for(i=0;i<f->event_number;i++){
     LttEventType *iter_ev = f->events[i];
-    if(strcmp(iter_ev->name, name) == 0) {
+    if(g_ascii_strcasecmp(iter_ev->name, name) == 0) {
       ev = iter_ev;
       break;
     }
index 1608e818b4637b24e9527a0d0238c006dfcafdd4..290dca7b1900efacbe7a6135055fb7beac605211 100644 (file)
    with a facility are released when the trace is closed. Each facility
    is characterized by its name and checksum. */
 
-char *ltt_facility_name(LttFacility *f);
+gchar *ltt_facility_name(LttFacility *f);
 
 LttChecksum ltt_facility_checksum(LttFacility *f);
 
 /* open facility */
-void ltt_facility_open(LttTrace * t, char * facility_name);
+void ltt_facility_open(LttTrace * t, gchar * facility_name);
 
 /* Discover the event types within the facility. The event type integer id
    relative to the trace is from 0 to nb_event_types - 1. The event
@@ -43,7 +43,7 @@ unsigned ltt_facility_eventtype_number(LttFacility *f);
 
 LttEventType *ltt_facility_eventtype_get(LttFacility *f, unsigned i);
 
-LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, char *name);
+LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, gchar *name);
 
 int ltt_facility_close(LttFacility *f);
 
index d10e35f91164f58c753253c9dbc602b0ddb22f6c..05c18c0ffdb3bc472eadb85fba22e635d2d1ac81 100644 (file)
@@ -38,7 +38,7 @@ typedef enum _BuildinEvent{
 /* structure definition */
 
 typedef struct _FacilityLoad{
-  char * name;
+  gchar * name;
   LttChecksum checksum;
   guint32     base_code;
 } LTT_PACKED_STRUCT FacilityLoad;
@@ -62,20 +62,20 @@ typedef struct _TimeHeartbeat {
 
 
 struct _LttType{
-  char * type_name;                //type name if it is a named type
-  char * element_name;             //elements name of the struct
-  char * fmt;
+  gchar * type_name;                //type name if it is a named type
+  gchar * element_name;             //elements name of the struct
+  gchar * fmt;
   unsigned int size;
   LttTypeEnum type_class;          //which type
-  char ** enum_strings;            //for enum labels
+  gchar ** enum_strings;            //for enum labels
   struct _LttType ** element_type; //for array, sequence and struct
   unsigned element_number;         //the number of elements 
                                    //for enum, array, sequence and structure
 };
 
 struct _LttEventType{
-  char * name;
-  char * description;
+  gchar * name;
+  gchar * description;
   int index;              //id of the event type within the facility
   LttFacility * facility; //the facility that contains the event type
   LttField * root_field;  //root field
@@ -139,7 +139,7 @@ struct _LttField{
 
 
 struct _LttFacility{
-  char * name;               //facility name 
+  gchar * name;               //facility name 
   unsigned int event_number;          //number of events in the facility 
   LttChecksum checksum;      //checksum of the facility 
   guint32  base_id;          //base id of the facility
@@ -149,7 +149,7 @@ struct _LttFacility{
 };
 
 struct _LttTracefile{
-  char * name;                       //tracefile name
+  gchar * name;                       //tracefile name
   LttTrace * trace;                  //trace containing the tracefile
   int fd;                            //file descriptor 
   off_t file_size;                   //file size
@@ -183,7 +183,7 @@ struct _LttTracefile{
 };
 
 struct _LttTrace{
-  char * pathname;                          //the pathname of the trace
+  gchar * pathname;                          //the pathname of the trace
   guint facility_number;                    //the number of facilities 
   guint control_tracefile_number;           //the number of control files 
   guint per_cpu_tracefile_number;           //the number of per cpu files 
@@ -221,19 +221,19 @@ struct _LttEventPosition{
    is described in a LttSystemDescription structure. */
 
 struct _LttSystemDescription {
-  char *description;
-  char *node_name;
-  char *domain_name;
+  gchar *description;
+  gchar *node_name;
+  gchar *domain_name;
   unsigned nb_cpu;
   LttArchSize size;
   LttArchEndian endian;
-  char *kernel_name;
-  char *kernel_release;
-  char *kernel_version;
-  char *machine;
-  char *processor;
-  char *hardware_platform;
-  char *operating_system;
+  gchar *kernel_name;
+  gchar *kernel_release;
+  gchar *kernel_version;
+  gchar *machine;
+  gchar *processor;
+  gchar *hardware_platform;
+  gchar *operating_system;
   unsigned ltt_major_version;
   unsigned ltt_minor_version;
   unsigned ltt_block_size;
index 58a6a10e4626054a41f6a28035c9ee6c8c926761..5c90c983631f60215933ce681cce90ea397ab044 100644 (file)
@@ -4,7 +4,9 @@ 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) 2002, Michel Dagenais
+Copyright (C) 2005, Mathieu Desnoyers
+
 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.
@@ -43,22 +45,6 @@ This program is distributed in the hope that it will be useful,
 
 #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
@@ -70,19 +56,19 @@ static int ltt_isalnum(char c)
 
 int getSize(parse_file *in)
 {
-  char *token;
+  gchar *token;
 
   token = getToken(in);
   if(in->type == NUMBER) {
-    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;
+    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;
   }
   else if(in->type == NAME) {
-    if(strcmp(token,"short") == 0) return 4;
-    else if(strcmp(token,"medium") == 0) return 5;
-    else if(strcmp(token,"long") == 0) return 6;
+    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;
   }
   in->error(in,"incorrect size specification");
   return -1;
@@ -99,50 +85,11 @@ int getSize(parse_file *in)
 void error_callback(parse_file *in, char *msg)
 {
   if(in)
-    printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg);
+    g_printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg);
   else
     printf("%s\n",msg);
 }
 
-/*****************************************************************************
- *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 
@@ -158,16 +105,20 @@ char *allocAndCopy(char *str)
  *
  **************************************************************************/
 
-char * getNameAttribute(parse_file *in)
+gchar * getNameAttribute(parse_file *in)
 {
-  char * token, car;
+  gchar * token;
+  gunichar car;
+  GIOStatus status;
+  
   token = getName(in);
-  if(strcmp("name",token))in->error(in,"name was expected");
+  if(g_ascii_strcasecmp("name",token))in->error(in,"name was expected");
   getEqual(in);
   
-  car = seekNextChar(in);
-  if(car == EOF)in->error(in,"name was expected");
-  else if(car == '\"')token = getQuotedString(in);
+  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;
 }
@@ -178,12 +129,12 @@ char * getFormatAttribute(parse_file *in)
 
   //format is an option
   token = getToken(in); 
-  if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+  if(g_ascii_strcasecmp("/",token) == 0 || g_ascii_strcasecmp(">",token) == 0){
     ungetToken(in);
     return NULL;
   }
 
-  if(strcmp("format",token))in->error(in,"format was expected");
+  if(g_ascii_strcasecmp("format",token))in->error(in,"format was expected");
   getEqual(in);
   token = getQuotedString(in);
   return token;
@@ -213,12 +164,12 @@ char * getValueStrAttribute(parse_file *in)
   char * token;
 
   token = getToken(in); 
-  if(strcmp("/",token) == 0){
+  if(g_ascii_strcasecmp("/",token) == 0){
     ungetToken(in);
     return NULL;
   }
   
-  if(strcmp("value",token))in->error(in,"value was expected");
+  if(g_ascii_strcasecmp("value",token))in->error(in,"value was expected");
   getEqual(in);
   token = getToken(in);
   if(in->type != NUMBER) in->error(in,"number was expected");
@@ -227,22 +178,35 @@ char * getValueStrAttribute(parse_file *in)
 
 char * getDescription(parse_file *in)
 {
-  long int pos;
-  char * token, car, *str;
+  gint64 pos;
+  gchar * token, *str;
+  gunichar car;
+  GError * error = NULL;
 
-  pos = ftell(in->fp);
+  pos = in->pos;
 
   getLAnglebracket(in);
   token = getName(in);
-  if(strcmp("description",token)){
-    fseek(in->fp, pos, SEEK_SET);
+  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;
+
     return NULL;
   }
   
   getRAnglebracket(in);
 
   pos = 0;
-  while((car = getc(in->fp)) != EOF) {
+  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++;
+
     if(car == '<') break;
     if(car == '\0') continue;
     in->buffer[pos] = car;
@@ -251,11 +215,11 @@ char * getDescription(parse_file *in)
   if(car == EOF)in->error(in,"not a valid description");
   in->buffer[pos] = '\0';
 
-  str = allocAndCopy(in->buffer);
+  str = g_strdup(in->buffer);
 
   getForwardslash(in);
   token = getName(in);
-  if(strcmp("description", token))in->error(in,"not a valid description");
+  if(g_ascii_strcasecmp("description", token))in->error(in,"not a valid description");
   getRAnglebracket(in);
 
   return str;
@@ -276,7 +240,7 @@ void parseFacility(parse_file *in, facility_t * fac)
   char * token;
   event_t *ev;
   
-  fac->name = allocAndCopy(getNameAttribute(in));    
+  fac->name = g_strdup(getNameAttribute(in));    
   getRAnglebracket(in);    
   
   fac->description = getDescription(in);
@@ -288,11 +252,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(strcmp("event",token) == 0){
-      ev = (event_t*) memAlloc(sizeof(event_t));
+    if(g_ascii_strcasecmp("event",token) == 0){
+      ev = (event_t*) g_new(event_t,1);
       sequence_push(&(fac->events),ev);
       parseEvent(in,ev, &(fac->unnamed_types), &(fac->named_types));    
-    }else if(strcmp("type",token) == 0){
+    }else if(g_ascii_strcasecmp("type",token) == 0){
       parseTypeDefinition(in, &(fac->unnamed_types), &(fac->named_types));
     }else if(in->type == FORWARDSLASH){
       break;
@@ -300,7 +264,7 @@ void parseFacility(parse_file *in, facility_t * fac)
   }
 
   token = getName(in);
-  if(strcmp("facility",token)) in->error(in,"not the end of the facility");
+  if(g_ascii_strcasecmp("facility",token)) in->error(in,"not the end of the facility");
   getRAnglebracket(in); //</facility>
 }
 
@@ -322,7 +286,7 @@ void parseEvent(parse_file *in, event_t * ev, sequence * unnamed_types,
   char *token;
 
   //<event name=eventtype_name>
-  ev->name = allocAndCopy(getNameAttribute(in));
+  ev->name = g_strdup(getNameAttribute(in));
   getRAnglebracket(in);  
 
   //<description>...</descriptio>
@@ -335,7 +299,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(strcmp("struct",token)==0 || strcmp("typeref",token)==0){
+    if(g_ascii_strcasecmp("struct",token)==0 || g_ascii_strcasecmp("typeref",token)==0){
       ungetToken(in);
       ev->type = parseType(in,NULL, unnamed_types, named_types);
       if(ev->type->type != STRUCT && ev->type->type != NONE) 
@@ -347,7 +311,7 @@ void parseEvent(parse_file *in, event_t * ev, sequence * unnamed_types,
   }else in->error(in,"not a struct type");
 
   token = getName(in);
-  if(strcmp("event",token))in->error(in,"not an event definition");
+  if(g_ascii_strcasecmp("event",token))in->error(in,"not an event definition");
   getRAnglebracket(in);  //</event>
 }
 
@@ -367,11 +331,11 @@ void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types,
   char * token;
   type_fields *f;
 
-  f = (type_fields *)memAlloc(sizeof(type_fields));
+  f = g_new(type_fields,1);
   sequence_push(&(t->fields),f);
 
   //<field name=field_name> <description> <type> </field>
-  f->name = allocAndCopy(getNameAttribute(in)); 
+  f->name = g_strdup(getNameAttribute(in)); 
   getRAnglebracket(in);
 
   f->description = getDescription(in);
@@ -383,7 +347,7 @@ void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types,
   getLAnglebracket(in);
   getForwardslash(in);
   token = getName(in);
-  if(strcmp("field",token))in->error(in,"not a valid field definition");
+  if(g_ascii_strcasecmp("field",token))in->error(in,"not a valid field definition");
   getRAnglebracket(in); //</field>
 }
 
@@ -415,7 +379,7 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
   type_descriptor *t;
 
   if(inType == NULL) {
-    t = (type_descriptor *) memAlloc(sizeof(type_descriptor));
+    t = g_new(type_descriptor,1);
     t->type_name = NULL;
     t->type = NONE;
     t->fmt = NULL;
@@ -425,26 +389,26 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
 
   token = getName(in);
 
-  if(strcmp(token,"struct") == 0) {
+  if(g_ascii_strcasecmp(token,"struct") == 0) {
     t->type = STRUCT;
     getRAnglebracket(in); //<struct>
     getLAnglebracket(in); //<field name=..>
     token = getToken(in);
     sequence_init(&(t->fields));
-    while(strcmp("field",token) == 0){
+    while(g_ascii_strcasecmp("field",token) == 0){
       parseFields(in,t, unnamed_types, named_types);
       
       //next field
       getLAnglebracket(in);
       token = getToken(in);    
     }
-    if(strcmp("/",token))in->error(in,"not a valid structure definition");
+    if(g_ascii_strcasecmp("/",token))in->error(in,"not a valid structure definition");
     token = getName(in);
-    if(strcmp("struct",token)!=0)
+    if(g_ascii_strcasecmp("struct",token)!=0)
       in->error(in,"not a valid structure definition");
     getRAnglebracket(in); //</struct>
   }
-  else if(strcmp(token,"union") == 0) {
+  else if(g_ascii_strcasecmp(token,"union") == 0) {
     t->type = UNION;
     t->size = getSizeAttribute(in);
     getRAnglebracket(in); //<union typecodesize=isize>
@@ -452,20 +416,20 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
     getLAnglebracket(in); //<field name=..>
     token = getToken(in);
     sequence_init(&(t->fields));
-    while(strcmp("field",token) == 0){
+    while(g_ascii_strcasecmp("field",token) == 0){
       parseFields(in,t, unnamed_types, named_types);
       
       //next field
       getLAnglebracket(in);
       token = getToken(in);    
     }
-    if(strcmp("/",token))in->error(in,"not a valid union definition");
+    if(g_ascii_strcasecmp("/",token))in->error(in,"not a valid union definition");
     token = getName(in);
-    if(strcmp("union",token)!=0)
+    if(g_ascii_strcasecmp("union",token)!=0)
       in->error(in,"not a valid union definition");        
     getRAnglebracket(in); //</union>
   }
-  else if(strcmp(token,"array") == 0) {
+  else if(g_ascii_strcasecmp(token,"array") == 0) {
     t->type = ARRAY;
     t->size = getValueAttribute(in);
     getRAnglebracket(in); //<array size=n>
@@ -476,10 +440,10 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
     getLAnglebracket(in); //</array>
     getForwardslash(in);
     token = getName(in);
-    if(strcmp("array",token))in->error(in,"not a valid array definition");
+    if(g_ascii_strcasecmp("array",token))in->error(in,"not a valid array definition");
     getRAnglebracket(in);  //</array>
   }
-  else if(strcmp(token,"sequence") == 0) {
+  else if(g_ascii_strcasecmp(token,"sequence") == 0) {
     t->type = SEQUENCE;
     t->size = getSizeAttribute(in);
     getRAnglebracket(in); //<array lengthsize=isize>
@@ -490,31 +454,29 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
     getLAnglebracket(in); //</sequence>
     getForwardslash(in);
     token = getName(in);
-    if(strcmp("sequence",token))in->error(in,"not a valid sequence definition");
+    if(g_ascii_strcasecmp("sequence",token))in->error(in,"not a valid sequence definition");
     getRAnglebracket(in); //</sequence>
   }
-  else if(strcmp(token,"enum") == 0) {
+  else if(g_ascii_strcasecmp(token,"enum") == 0) {
     char * str, *str1;
     t->type = ENUM;
     sequence_init(&(t->labels));
     t->size = getSizeAttribute(in);
-    t->fmt = allocAndCopy(getFormatAttribute(in));
+    t->fmt = g_strdup(getFormatAttribute(in));
     getRAnglebracket(in);
 
     //<label name=label1 value=n/>
     getLAnglebracket(in);
     token = getToken(in); //"label" or "/"
-    while(strcmp("label",token) == 0){
-      str   = allocAndCopy(getNameAttribute(in));      
+    while(g_ascii_strcasecmp("label",token) == 0){
+      str1   = g_strdup(getNameAttribute(in));      
       token = getValueStrAttribute(in);
       if(token){
-       str1 = appendString(str,"=");
-       free(str);
-       str = appendString(str1,token);
-       free(str1);
-       sequence_push(&(t->labels),str);
+             str = g_strconcat(str1,"=",token,NULL);
+       g_free(str1);
+       sequence_push(&(t->labels),str);
       }else
-       sequence_push(&(t->labels),str);
+       sequence_push(&(t->labels),str1);
 
       getForwardslash(in);
       getRAnglebracket(in);
@@ -523,44 +485,44 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
       getLAnglebracket(in);
       token = getToken(in); //"label" or "/"      
     }
-    if(strcmp("/",token))in->error(in, "not a valid enum definition");
+    if(g_ascii_strcasecmp("/",token))in->error(in, "not a valid enum definition");
     token = getName(in);
-    if(strcmp("enum",token))in->error(in, "not a valid enum definition");
+    if(g_ascii_strcasecmp("enum",token))in->error(in, "not a valid enum definition");
     getRAnglebracket(in); //</label>
   }
-  else if(strcmp(token,"int") == 0) {
+  else if(g_ascii_strcasecmp(token,"int") == 0) {
     t->type = INT;
     t->size = getSizeAttribute(in);
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    t->fmt  = g_strdup(getFormatAttribute(in));
     getForwardslash(in);
     getRAnglebracket(in); 
   }
-  else if(strcmp(token,"uint") == 0) {
+  else if(g_ascii_strcasecmp(token,"uint") == 0) {
     t->type = UINT;
     t->size = getSizeAttribute(in);
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    t->fmt  = g_strdup(getFormatAttribute(in));
     getForwardslash(in);
     getRAnglebracket(in); 
   }
-  else if(strcmp(token,"float") == 0) {
+  else if(g_ascii_strcasecmp(token,"float") == 0) {
     t->type = FLOAT;
     t->size = getSizeAttribute(in);
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    t->fmt  = g_strdup(getFormatAttribute(in));
     getForwardslash(in);
     getRAnglebracket(in); 
   }
-  else if(strcmp(token,"string") == 0) {
+  else if(g_ascii_strcasecmp(token,"string") == 0) {
     t->type = STRING;
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    t->fmt  = g_strdup(getFormatAttribute(in));
     getForwardslash(in);
     getRAnglebracket(in); 
   }
-  else if(strcmp(token,"typeref") == 0){
+  else if(g_ascii_strcasecmp(token,"typeref") == 0){
     // Must be a named type
     if(inType != NULL) 
       in->error(in,"Named type cannot refer to a named type");
     else {
-      free(t);
+      g_free(t);
       sequence_pop(unnamed_types);
       token = getNameAttribute(in);
       t = find_named_type(token, named_types);
@@ -583,18 +545,18 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
  *    type_descriptor *   : a type descriptor                       
  *****************************************************************************/
 
-type_descriptor * find_named_type(char *name, table * named_types)
+type_descriptor * find_named_type(gchar *name, table * named_types)
 { 
   type_descriptor *t;
 
   t = table_find(named_types,name);
   if(t == NULL) {
-    t = (type_descriptor *)memAlloc(sizeof(type_descriptor));
-    t->type_name = allocAndCopy(name);
+    t = g_new(type_descriptor,1);
+    t->type_name = g_strdup(name);
     t->type = NONE;
     t->fmt = NULL;
     table_insert(named_types,t->type_name,t);
-    //    table_insert(named_types,allocAndCopy(name),t);
+    //    table_insert(named_types,g_strdup(name),t);
   }
   return t;
 }  
@@ -621,7 +583,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");
+  if(g_ascii_strcasecmp("struct",token))in->error(in,"not a valid type definition");
   ungetToken(in);
   parseType(in,t, unnamed_types, named_types);
   
@@ -629,7 +591,7 @@ void parseTypeDefinition(parse_file * in, sequence * unnamed_types,
   getLAnglebracket(in);
   getForwardslash(in);
   token = getName(in);
-  if(strcmp("type",token))in->error(in,"not a valid type definition");  
+  if(g_ascii_strcasecmp("type",token))in->error(in,"not a valid type definition");  
   getRAnglebracket(in); //</type>
 }
 
@@ -710,18 +672,38 @@ char * getEqual(parse_file *in)
   return token;
 }
 
-char seekNextChar(parse_file *in)
+gunichar seekNextChar(parse_file *in, gunichar *car)
 {
-  char car;
-  while((car = getc(in->fp)) != EOF) {
-    if(!isspace(car)){
-      ungetc(car,in->fp);
-      return car;
+  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;
     }
-  }  
-  return EOF;
+
+  } while(status != G_IO_STATUS_EOF && status != G_IO_STATUS_ERROR);
+
+  return status;
 }
 
+
 /******************************************************************
  * Function :
  *    getToken, ungetToken
@@ -742,11 +724,11 @@ void ungetToken(parse_file * in)
   in->unget = 1;
 }
 
-char *getToken(parse_file * in)
+gchar *getToken(parse_file * in)
 {
-  FILE *fp = in->fp;
-  char car, car1;
+  gunichar car, car1;
   int pos = 0, escaped;
+  GError * error = NULL;
 
   if(in->unget == 1) {
     in->unget = 0;
@@ -755,20 +737,35 @@ char *getToken(parse_file * in)
 
   /* skip whitespace and comments */
 
-  while((car = getc(fp)) != EOF) {
+  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++;
+
     if(car == '/') {
-      car1 = getc(fp); 
+      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++;
+
       if(car1 == '*') skipComment(in);
       else if(car1 == '/') skipEOL(in);
-      else { 
-        car1 = ungetc(car1,fp);
+      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--;
         break;
       }
     }
     else if(car == '\n') in->lineno++;
-    else if(!isspace(car)) break;
+    else if(!g_unichar_isspace(car)) break;
   }
-
   switch(car) {
     case EOF:
       in->type = ENDFILE;
@@ -795,10 +792,17 @@ char *getToken(parse_file * in)
       break;
     case '"':
       escaped = 0;
-      while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
+      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(car == '\\' && escaped == 0) {
-         in->buffer[pos] = car;
-         pos++;
+               in->buffer[pos] = car;
+         pos++;
           escaped = 1;
           continue;
         }
@@ -816,33 +820,67 @@ char *getToken(parse_file * in)
       in->type = QUOTEDSTRING;
       break;
     default:
-      if(isdigit(car)) {
+      if(g_unichar_isdigit(car)) {
         in->buffer[pos] = car;
         pos++;
-        while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
+        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(!isdigit(car)) {
-            ungetc(car,fp);
+            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--;
             break;
           }
           in->buffer[pos] = car;
           pos++;
         }
-       if(car == EOF) ungetc(car,fp);
+             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(pos == BUFFER_SIZE) in->error(in, "number token too large");
         in->type = NUMBER;
       }    
-      else if(ltt_isalpha(car)) {
+      else if(g_unichar_isalpha(car)) {
         in->buffer[0] = car;
         pos = 1;
-        while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
-          if(!ltt_isalnum(car)) {
-            ungetc(car,fp);
+        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--;
             break;
           }
           in->buffer[pos] = car;
           pos++;
         }
-       if(car == EOF) ungetc(car,fp);
+             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(pos == BUFFER_SIZE) in->error(in, "name token too large");
         in->type = NAME;
       }
@@ -854,14 +892,35 @@ char *getToken(parse_file * in)
 
 void skipComment(parse_file * in)
 {
-  char car;
-  while((car = getc(in->fp)) != EOF) {
+  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++;
+
     if(car == '\n') in->lineno++;
     else if(car == '*') {
-      car = getc(in->fp);
+
+      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++;
+
       if(car ==EOF) break;
       if(car == '/') return;
-      ungetc(car,in->fp);
+
+      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) in->error(in,"comment begining with '/*' has no ending '*/'");
@@ -869,14 +928,27 @@ void skipComment(parse_file * in)
 
 void skipEOL(parse_file * in)
 {
-  char car;
-  while((car = getc(in->fp)) != EOF) {
+  gunichar car;
+  GError * error = NULL;
+
+  while(g_io_channel_read_unichar(in->channel, &car, &error)
+                                          != G_IO_STATUS_EOF) {
     if(car == '\n') {
-      ungetc(car,in->fp);
+      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--;
       break;
     }
   }
-  if(car == EOF)ungetc(car, in->fp);
+  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--;
+  }
 }
 
 /*****************************************************************************
@@ -964,29 +1036,29 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type)
       str = floatOutputTypes[type->size];
       break;
     case STRING:
-      str = allocAndCopy("string");
+      str = g_strdup("string");
       flag = 1;
       break;
     case ENUM:
-      str = appendString("enum ", uintOutputTypes[type->size]);
+      str = g_strconcat("enum ", uintOutputTypes[type->size], NULL);
       flag = 1;
       break;
     case ARRAY:
       sprintf(buf,"%d",type->size);
-      str = appendString("array ",buf);
+      str = g_strconcat("array ",buf, NULL);
       flag = 1;
       break;
     case SEQUENCE:
       sprintf(buf,"%d",type->size);
-      str = appendString("sequence ",buf);
+      str = g_strconcat("sequence ",buf, NULL);
       flag = 1;
       break;
     case STRUCT:
-      str = allocAndCopy("struct");
+      str = g_strdup("struct");
       flag = 1;
       break;
     case UNION:
-      str = allocAndCopy("union");
+      str = g_strdup("union");
       flag = 1;
       break;
     default:
@@ -995,7 +1067,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type)
   }
 
   crc = partial_crc32(str,crc);
-  if(flag) free(str);
+  if(flag) g_free(str);
 
   if(type->fmt) crc = partial_crc32(type->fmt,crc);
     
@@ -1022,19 +1094,19 @@ void freeType(type_descriptor * tp)
   int pos2;
   type_fields *f;
 
-  if(tp->fmt != NULL) free(tp->fmt);
+  if(tp->fmt != NULL) g_free(tp->fmt);
   if(tp->type == ENUM) {
     for(pos2 = 0; pos2 < tp->labels.position; pos2++) {
-      free(tp->labels.array[pos2]);
+      g_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];
-      free(f->name);
-      free(f->description);
-      free(f);
+      g_free(f->name);
+      g_free(f->description);
+      g_free(f);
     }
     sequence_dispose(&(tp->fields));
   }
@@ -1046,10 +1118,10 @@ void freeNamedType(table * t)
   type_descriptor * td;
 
   for(pos = 0 ; pos < t->keys.position; pos++) {
-    free((char *)t->keys.array[pos]);
+    g_free((char *)t->keys.array[pos]);
     td = (type_descriptor*)t->values.array[pos];
     freeType(td);
-    free(td);
+    g_free(td);
   }
 }
 
@@ -1061,7 +1133,7 @@ void freeTypes(sequence *t)
   for(pos = 0 ; pos < t->position; pos++) {
     tp = (type_descriptor *)t->array[pos];
     freeType(tp);
-    free(tp);
+    g_free(tp);
   }
 }
 
@@ -1072,9 +1144,9 @@ void freeEvents(sequence *t)
 
   for(pos = 0 ; pos < t->position; pos++) {
     ev = (event_t *) t->array[pos];
-    free(ev->name);
-    free(ev->description);
-    free(ev);
+    g_free(ev->name);
+    g_free(ev->description);
+    g_free(ev);
   }
 
 }
@@ -1086,13 +1158,13 @@ void sequence_init(sequence *t)
 {
   t->size = 10;
   t->position = 0;
-  t->array = (void **)memAlloc(t->size * sizeof(void *));
+  t->array = g_new(void*, t->size);
 }
 
 void sequence_dispose(sequence *t) 
 {
   t->size = 0;
-  free(t->array);
+  g_free(t->array);
   t->array = NULL;
 }
 
@@ -1102,10 +1174,10 @@ void sequence_push(sequence *t, void *elem)
 
   if(t->position >= t->size) {
     tmp = t->array;
-    t->array = (void **)memAlloc(t->size * 2 * sizeof(void *));
+    t->array = g_new(void*, 2*t->size);
     memcpy(t->array, tmp, t->size * sizeof(void *));
     t->size = t->size * 2;
-    free(tmp);
+    g_free(tmp);
   }
   t->array[t->position] = elem;
   t->position++;
@@ -1141,7 +1213,7 @@ void *table_find(table *t, char *key)
 {
   int pos;
   for(pos = 0 ; pos < t->keys.position; pos++) {
-    if(strcmp((char *)key,(char *)t->keys.array[pos]) == 0)
+    if(g_ascii_strcasecmp((char *)key,(char *)t->keys.array[pos]) == 0)
       return(t->values.array[pos]);
   }
   return NULL;
@@ -1164,17 +1236,3 @@ 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;
-}
-
-
index 1d56d462c6fc55f0cc31b2389d673e5c566a41bb..c2c5d9177aa381741c498cd9ac41bd8d70ede184 100644 (file)
@@ -69,32 +69,34 @@ typedef enum _token_type {
 
 /* State associated with a file being parsed */
 typedef struct _parse_file {
-  char *name;
-  FILE * fp;
+  gchar *name;
+  int fd;
+  guint64 pos;
+  GIOChannel *channel;
   int lineno;
-  char *buffer;
+  gchar *buffer;
   token_type type; 
   int unget;
   void (*error) (struct _parse_file *, char *);
 } parse_file;
 
 void ungetToken(parse_file * in);
-char *getToken(parse_file *in);
-char *getForwardslash(parse_file *in);
-char *getLAnglebracket(parse_file *in);
-char *getRAnglebracket(parse_file *in);
-char *getQuotedString(parse_file *in);
-char *getName(parse_file *in);
+gchar *getToken(parse_file *in);
+gchar *getForwardslash(parse_file *in);
+gchar *getLAnglebracket(parse_file *in);
+gchar *getRAnglebracket(parse_file *in);
+gchar *getQuotedString(parse_file *in);
+gchar *getName(parse_file *in);
 int   getNumber(parse_file *in);
-char *getEqual(parse_file *in);
-char  seekNextChar(parse_file *in);
+gchar *getEqual(parse_file *in);
+GIOStatus seekNextChar(parse_file *in, gunichar *car);
 
 void skipComment(parse_file * in);
 void skipEOL(parse_file * in);
 
 /* Some constants */
 
-static const int BUFFER_SIZE = 1024;
+#define BUFFER_SIZE 1024
 
 
 /* Events data types */
@@ -187,9 +189,6 @@ static char *floatOutputTypes[] = {
 
 /* Dynamic memory allocation and freeing */
 
-void * memAlloc(int size);
-char *allocAndCopy(char * str);
-char *appendString(char *s, char *suffix);
 void freeTypes(sequence *t);
 void freeType(type_descriptor * td);
 void freeEvents(sequence *t);
index 9981f1f0772f084854a6dec4d8ede3e1ed4e82af..a2360bb53caeb97a9b4e2cef1848fe088bd445f4 100644 (file)
@@ -32,7 +32,7 @@
    
    */
 
-LttTrace *ltt_trace_open(const char *pathname);
+LttTrace *ltt_trace_open(const gchar *pathname);
 
 /* copy reopens a trace 
  *
@@ -40,7 +40,7 @@ LttTrace *ltt_trace_open(const char *pathname);
  */
 LttTrace *ltt_trace_copy(LttTrace *self);
 
-char * ltt_trace_name(LttTrace *t);
+gchar * ltt_trace_name(LttTrace *t);
 
 void ltt_trace_close(LttTrace *t); 
 
@@ -65,7 +65,7 @@ LttFacility * ltt_trace_facility_by_id(LttTrace * trace, unsigned id);
    position, returning n, the facilities are from position to 
    position + n - 1. */
 
-unsigned ltt_trace_facility_find(LttTrace *t, char *name, unsigned *position);
+unsigned ltt_trace_facility_find(LttTrace *t, gchar *name, unsigned *position);
 
 
 /* Functions to discover all the event types in the trace */
@@ -133,11 +133,11 @@ LttEvent *ltt_tracefile_read(LttTracefile *t, LttEvent *event);
 
 /* open tracefile */
 
-LttTracefile * ltt_tracefile_open(LttTrace *t, char * tracefile_name);
+LttTracefile * ltt_tracefile_open(LttTrace *t, gchar * tracefile_name);
 
-void ltt_tracefile_open_cpu(LttTrace *t, char * tracefile_name);
+void ltt_tracefile_open_cpu(LttTrace *t, gchar * tracefile_name);
 
-gint ltt_tracefile_open_control(LttTrace *t, char * control_name);
+gint ltt_tracefile_open_control(LttTrace *t, gchar * control_name);
 
 
 /* get the data type size and endian type of the local machine */
@@ -151,17 +151,17 @@ gint64 getIntNumber(gboolean reverse_byte_order, int size1, void *evD);
 
 /* get the node name of the system */
 
-char * ltt_trace_system_description_node_name (LttSystemDescription * s);
+gchar * ltt_trace_system_description_node_name (LttSystemDescription * s);
 
 
 /* get the domain name of the system */
 
-char * ltt_trace_system_description_domain_name (LttSystemDescription * s);
+gchar * ltt_trace_system_description_domain_name (LttSystemDescription * s);
 
 
 /* get the description of the system */
 
-char * ltt_trace_system_description_description (LttSystemDescription * s);
+gchar * ltt_trace_system_description_description (LttSystemDescription * s);
 
 
 /* get the start time of the trace */
@@ -173,6 +173,6 @@ LttTracefile *ltt_tracefile_new();
 void ltt_tracefile_destroy(LttTracefile *tf);
 void ltt_tracefile_copy(LttTracefile *dest, const LttTracefile *src);
 
-void get_absolute_pathname(const char *pathname, char * abs_pathname);
+void get_absolute_pathname(const gchar *pathname, gchar * abs_pathname);
 
 #endif // TRACE_H
index c263240f91f14f9e3feff992902b44d02d0e0a50..3451d769ce207c6693785759f9db93b1b27ff351 100644 (file)
@@ -25,6 +25,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <math.h>
+#include <glib/gstdio.h>
 
 // For realpath
 #include <limits.h>
@@ -46,6 +47,7 @@
 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
 
+#define g_close close
 
 /* obtain the time of an event */
 
@@ -63,7 +65,7 @@ static inline gint getFieldtypeSize(LttTracefile * tf,
                     gint offsetParent, LttField *fld, void *evD, LttTrace* t);
 
 /* read a fixed size or a block information from the file (fd) */
-int readFile(int fd, void * buf, size_t size, char * mesg);
+int readFile(int fd, void * buf, size_t size, gchar * mesg);
 int readBlock(LttTracefile * tf, int whichBlock);
 
 /* calculate cycles per nsec for current block */
@@ -162,7 +164,7 @@ static void  parser_characters   (GMarkupParseContext __UNUSED__ *context,
  *                       : a pointer to a tracefile
  ****************************************************************************/ 
 
-LttTracefile* ltt_tracefile_open(LttTrace * t, char * fileName)
+LttTracefile* ltt_tracefile_open(LttTrace * t, gchar * fileName)
 {
   LttTracefile * tf;
   struct stat    lTDFStat;    /* Trace data file status */
@@ -172,7 +174,7 @@ LttTracefile* ltt_tracefile_open(LttTrace * t, char * fileName)
   //open the file
   tf->name = g_strdup(fileName);
   tf->trace = t;
-  tf->fd = open(fileName, O_RDONLY, 0);
+  tf->fd = g_open(fileName, O_RDONLY, 0);
   if(tf->fd < 0){
     g_warning("Unable to open input data file %s\n", fileName);
     g_free(tf->name);
@@ -184,7 +186,7 @@ LttTracefile* ltt_tracefile_open(LttTrace * t, char * fileName)
   if(fstat(tf->fd, &lTDFStat) < 0){
     g_warning("Unable to get the status of the input data file %s\n", fileName);
     g_free(tf->name);
-    close(tf->fd);
+    g_close(tf->fd);
     g_free(tf);
     return NULL;
   }
@@ -193,7 +195,7 @@ LttTracefile* ltt_tracefile_open(LttTrace * t, char * fileName)
   if(lTDFStat.st_size < (off_t)(sizeof(BlockStart) + EVENT_HEADER_SIZE)){
     g_print("The input data file %s does not contain a trace\n", fileName);
     g_free(tf->name);
-    close(tf->fd);
+    g_close(tf->fd);
     g_free(tf);
     return NULL;
   }
@@ -205,7 +207,7 @@ LttTracefile* ltt_tracefile_open(LttTrace * t, char * fileName)
   tf->which_block = 0;
 
   //allocate memory to contain the info of a block
-  tf->buffer = (void *) g_new(char, t->system_description->ltt_block_size);
+  tf->buffer = (void *) g_new(gchar, t->system_description->ltt_block_size);
 
   //read the first block
   if(readBlock(tf,1)) exit(1);
@@ -218,7 +220,7 @@ LttTracefile* ltt_tracefile_open(LttTrace * t, char * fileName)
  *Open control and per cpu tracefiles
  ****************************************************************************/
 
-void ltt_tracefile_open_cpu(LttTrace *t, char * tracefile_name)
+void ltt_tracefile_open_cpu(LttTrace *t, gchar * tracefile_name)
 {
   LttTracefile * tf;
   tf = ltt_tracefile_open(t,tracefile_name);
@@ -227,7 +229,7 @@ void ltt_tracefile_open_cpu(LttTrace *t, char * tracefile_name)
   g_ptr_array_add(t->per_cpu_tracefiles, tf);
 }
 
-gint ltt_tracefile_open_control(LttTrace *t, char * control_name)
+gint ltt_tracefile_open_control(LttTrace *t, gchar * control_name)
 {
   LttTracefile * tf;
   LttEvent ev;
@@ -251,7 +253,7 @@ gint ltt_tracefile_open_control(LttTrace *t, char * control_name)
 
       if(ev.event_id == TRACE_FACILITY_LOAD){
        pos = ev.data;
-       fLoad.name = (char*)pos;
+       fLoad.name = (gchar*)pos;
        fLoad.checksum = *(LttChecksum*)(pos + strlen(fLoad.name));
        fLoad.base_code = *(guint32 *)(pos + strlen(fLoad.name) + sizeof(LttChecksum));
 
@@ -299,10 +301,12 @@ void ltt_tracefile_close(LttTracefile *t)
 /*****************************************************************************
  *Get system information
  ****************************************************************************/
-gint getSystemInfo(LttSystemDescription* des, char * pathname)
+gint getSystemInfo(LttSystemDescription* des, gchar * pathname)
 {
-  FILE * fp;
-  char buf[DIR_NAME_SIZE];
+  int fd;
+  GIOChannel *iochan;
+  gchar *buf = NULL;
+  gsize length;
 
   GMarkupParseContext * context;
   GError * error = NULL;
@@ -315,27 +319,52 @@ gint getSystemInfo(LttSystemDescription* des, char * pathname)
       NULL   /*  error        */
     };
 
-  fp = fopen(pathname,"r");
-  if(!fp){
+  fd = g_open(pathname, O_RDONLY, 0);
+  if(fd == -1){
     g_warning("Can not open file : %s\n", pathname);
     return -1;
   }
   
+  iochan = g_io_channel_unix_new(fd);
+  
   context = g_markup_parse_context_new(&markup_parser, 0, des,NULL);
   
-  while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
-    if(!g_markup_parse_context_parse(context, buf, DIR_NAME_SIZE, &error)){
+  //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
+  while(g_io_channel_read_line(iochan, &buf, &length, NULL, &error)
+      != G_IO_STATUS_EOF) {
+
+    if(error != NULL) {
+      g_warning("Can not read xml file: \n%s\n", error->message);
+      g_error_free(error);
+    }
+    if(!g_markup_parse_context_parse(context, buf, length, &error)){
       if(error != NULL) {
         g_warning("Can not parse xml file: \n%s\n", error->message);
         g_error_free(error);
       }
       g_markup_parse_context_free(context);
-      fclose(fp);
+
+      g_io_channel_shutdown(iochan, FALSE, &error); /* No flush */
+      if(error != NULL) {
+        g_warning("Can not close file: \n%s\n", error->message);
+        g_error_free(error);
+      }
+
+      close(fd);
       return -1;
     }
   }
   g_markup_parse_context_free(context);
-  fclose(fp);
+
+  g_io_channel_shutdown(iochan, FALSE, &error); /* No flush */
+  if(error != NULL) {
+    g_warning("Can not close file: \n%s\n", error->message);
+    g_error_free(error);
+  }
+
+  g_close(fd);
+
+  g_free(buf);
   return 0;
 }
 
@@ -343,30 +372,31 @@ gint getSystemInfo(LttSystemDescription* des, char * pathname)
  *The following functions get facility/tracefile information
  ****************************************************************************/
 
-gint getFacilityInfo(LttTrace *t, char* eventdefs)
+gint getFacilityInfo(LttTrace *t, gchar* eventdefs)
 {
-  DIR * dir;
-  struct dirent *entry;
-  char * ptr;
+  GDir * dir;
+  const gchar * name;
   unsigned int i,j;
   LttFacility * f;
   LttEventType * et;
-  char name[DIR_NAME_SIZE];
+  gchar fullname[DIR_NAME_SIZE];
+  GError * error = NULL;
+
+  dir = g_dir_open(eventdefs, 0, &error);
 
-  dir = opendir(eventdefs);
-  if(!dir) {
-    g_warning("Can not open directory: %s\n", eventdefs);
+  if(error != NULL) {
+    g_warning("Can not open directory: %s, %s\n", eventdefs, error->message);
+    g_error_free(error);
     return -1;
   }
 
-  while((entry = readdir(dir)) != NULL){
-    ptr = &entry->d_name[strlen(entry->d_name)-4];
-    if(strcmp(ptr,".xml") != 0) continue;
-    strcpy(name,eventdefs);
-    strcat(name,entry->d_name);
-    ltt_facility_open(t,name);
-  }  
-  closedir(dir);
+  while((name = g_dir_read_name(dir)) != NULL){
+    if(!g_pattern_match_simple("*.xml", name)) continue;
+    strcpy(fullname,eventdefs);
+    strcat(fullname,name);
+    ltt_facility_open(t,fullname);
+  }
+  g_dir_close(dir);
   
   for(j=0;j<t->facility_number;j++){
     f = (LttFacility*)g_ptr_array_index(t->facilities, j);
@@ -378,54 +408,60 @@ gint getFacilityInfo(LttTrace *t, char* eventdefs)
   return 0;
 }
 
-gint getControlFileInfo(LttTrace *t, char* control)
+gint getControlFileInfo(LttTrace *t, gchar* control)
 {
-  DIR * dir;
-  struct dirent *entry;
-  char name[DIR_NAME_SIZE];
+  GDir * dir;
+  const gchar *name;
+  gchar fullname[DIR_NAME_SIZE];
+  GError * error = NULL;
+
+  dir = g_dir_open(control, 0, &error);
 
-  dir = opendir(control);
-  if(!dir) {
-    g_warning("Can not open directory: %s\n", control);
+  if(error != NULL) {
+    g_warning("Can not open directory: %s, %s\n", control, error->message);
+    g_error_free(error);
     return -1;
   }
 
-  while((entry = readdir(dir)) != NULL){
-    if(strcmp(entry->d_name,"facilities") != 0 &&
-       strcmp(entry->d_name,"interrupts") != 0 &&
-       strcmp(entry->d_name,"processes") != 0) continue;
+  while((name = g_dir_read_name(dir)) != NULL){
+    if(strcmp(name,"facilities") != 0 &&
+       strcmp(name,"interrupts") != 0 &&
+       strcmp(name,"processes") != 0) continue;
     
-    strcpy(name,control);
-    strcat(name,entry->d_name);
-    if(ltt_tracefile_open_control(t,name))
+    strcpy(fullname,control);
+    strcat(fullname,name);
+    if(ltt_tracefile_open_control(t,fullname)) {
+      g_dir_close(dir);
       return -1;
+    }
   }  
-  closedir(dir);
+  g_dir_close(dir);
   return 0;
 }
 
 gint getCpuFileInfo(LttTrace *t, char* cpu)
 {
-  DIR * dir;
-  struct dirent *entry;
-  char name[DIR_NAME_SIZE];
+  GDir * dir;
+  const gchar * name;
+  gchar fullname[DIR_NAME_SIZE];
+  GError * error = NULL;
+
+  dir = g_dir_open(cpu, 0, &error);
 
-  dir = opendir(cpu);
-  if(!dir) {
-    g_warning("Can not open directory: %s\n", cpu);
+  if(error != NULL) {
+    g_warning("Can not open directory: %s, %s\n", cpu, error->message);
+    g_error_free(error);
     return -1;
   }
 
-  while((entry = readdir(dir)) != NULL){
-    if(strcmp(entry->d_name,".") != 0 &&
-       strcmp(entry->d_name,"..") != 0 &&
-       strcmp(entry->d_name,".svn") != 0){      
-      strcpy(name,cpu);
-      strcat(name,entry->d_name);
-      ltt_tracefile_open_cpu(t,name);
+  while((name = g_dir_read_name(dir)) != NULL){
+    if(strcmp(name,".svn") != 0){     /* . and .. already excluded */
+      strcpy(fullname,cpu);
+      strcat(fullname,name);
+      ltt_tracefile_open_cpu(t,fullname);
     }else continue;
   }  
-  closedir(dir);
+  g_dir_close(dir);
   return 0;
 }
 
@@ -448,7 +484,7 @@ gint getCpuFileInfo(LttTrace *t, char* cpu)
  * forgotten cases (.. were not used correctly before).
  *
  ****************************************************************************/
-void get_absolute_pathname(const char *pathname, char * abs_pathname)
+void get_absolute_pathname(const gchar *pathname, gchar * abs_pathname)
 {
   abs_pathname[0] = '\0';
 
@@ -463,16 +499,16 @@ void get_absolute_pathname(const char *pathname, char * abs_pathname)
   return;
 }
 
-LttTrace *ltt_trace_open(const char *pathname)
+LttTrace *ltt_trace_open(const gchar *pathname)
 {
   LttTrace  * t;
   LttSystemDescription * sys_description;
-  char eventdefs[DIR_NAME_SIZE];
-  char info[DIR_NAME_SIZE];
-  char control[DIR_NAME_SIZE];
-  char cpu[DIR_NAME_SIZE];
-  char tmp[DIR_NAME_SIZE];
-  char abs_path[DIR_NAME_SIZE];
+  gchar eventdefs[DIR_NAME_SIZE];
+  gchar info[DIR_NAME_SIZE];
+  gchar control[DIR_NAME_SIZE];
+  gchar cpu[DIR_NAME_SIZE];
+  gchar tmp[DIR_NAME_SIZE];
+  gchar abs_path[DIR_NAME_SIZE];
   gboolean has_slash = FALSE;
 
   get_absolute_pathname(pathname, abs_path);
index 793f901eee307095cff380d7a7f5aa3979b205d3..34eeb4e01ac356eb78acf891e927a9d57bee1487 100644 (file)
@@ -48,7 +48,7 @@ static unsigned floatSizes[] = {
  *    char *             : the name of the event type
  ****************************************************************************/
 
-char *ltt_eventtype_name(LttEventType *et)
+gchar *ltt_eventtype_name(LttEventType *et)
 {
   return et->name;
 }
@@ -62,7 +62,7 @@ char *ltt_eventtype_name(LttEventType *et)
  *    char *             : the description of the event type
  ****************************************************************************/
 
-char *ltt_eventtype_description(LttEventType *et)
+gchar *ltt_eventtype_description(LttEventType *et)
 {
   return et->description;
 }
@@ -147,7 +147,7 @@ LttField *ltt_eventtype_field(LttEventType *et)
  *    char *         : the name of the type
  ****************************************************************************/
 
-char *ltt_type_name(LttType *t)
+gchar *ltt_type_name(LttType *t)
 {
   return t->element_name;
 }
@@ -283,7 +283,7 @@ unsigned ltt_type_member_number(LttType *t)
  *    LttType *           : the type of structure member
  ****************************************************************************/
 
-LttType *ltt_type_member_type(LttType *t, unsigned i, char ** name)
+LttType *ltt_type_member_type(LttType *t, unsigned i, gchar ** name)
 {
   LttType *member_type = NULL;
 
@@ -315,7 +315,7 @@ LttType *ltt_type_member_type(LttType *t, unsigned i, char ** name)
 
 char *ltt_enum_string_get(LttType *t, unsigned i)
 { 
-  char *string = NULL;
+  gchar *string = NULL;
   
   if(likely(t->type_class == LTT_ENUM && i < t->element_number))
     string = t->enum_strings[i];
index 918281260cca81b45cce21e1c469c7d36577e438..01cbbb38ac5d003c563c0fdb7735d847f63c7d09 100644 (file)
@@ -31,9 +31,9 @@
 /* Obtain the name, description, facility, facility relative id, global id, 
    type and root field for an eventtype */
 
-char *ltt_eventtype_name(LttEventType *et);
+gchar *ltt_eventtype_name(LttEventType *et);
 
-char *ltt_eventtype_description(LttEventType *et);
+gchar *ltt_eventtype_description(LttEventType *et);
 
 LttFacility *ltt_eventtype_facility(LttEventType *et);
 
@@ -50,7 +50,7 @@ LttField *ltt_eventtype_field(LttEventType *et);
    primitive types (INT, UINT, FLOAT, ENUM), or the size for the unsigned
    integer length count for sequences. */
  
-char *ltt_type_name(LttType *t);
+gchar *ltt_type_name(LttType *t);
 
 LttTypeEnum ltt_type_class(LttType *t);
 
@@ -80,7 +80,7 @@ LttType *ltt_type_member_type(LttType *t, unsigned i, char ** name);
 /* For enumerations, obtain the symbolic string associated with a value
    (0 to n - 1 for an enumeration of n elements). */
 
-char *ltt_enum_string_get(LttType *t, unsigned i);
+gchar *ltt_enum_string_get(LttType *t, unsigned i);
 
 
 /* The fields form a tree representing a depth first search of the 
This page took 0.052545 seconds and 4 git commands to generate.