Add config.h support : will fix the LARGEFILE problem
[lttv.git] / ltt / branches / poly / ltt / facility.c
index f8e8962ffdb089e33e8b4508d57e1f178cd232aa..84baac98421ce92a6c4a5907015e908b90bba2b7 100644 (file)
  * MA 02111-1307, USA.
  */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <stdlib.h> 
 #include <string.h>
 #include <stdio.h>
+#include <glib.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>
 
+#ifndef g_open
+#define g_open open
+#endif
+
+#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 +69,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 +120,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 +132,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);
 }
 
 
@@ -286,17 +314,18 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td,
 LttType * lookup_named_type(LttFacility *fac, type_descriptor * td)
 {
   LttType * lttType = NULL;
-  unsigned int i;
-  char * name;
+  unsigned int i=0;
+  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){
-       lttType = fac->named_types[i];  
+      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;
-       break;  
+             break;    
       }
     }
   }
@@ -313,7 +342,7 @@ LttType * lookup_named_type(LttFacility *fac, type_descriptor * td)
     lttType->element_name = NULL;
     if(td->type_name){
       lttType->type_name = g_strdup(td->type_name);
-      fac->named_types[i] = lttType;
+      fac->named_types[i] = lttType; /* i is initialized, checked. */
     }
     else{
       lttType->type_name = NULL;
@@ -448,7 +477,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;
 }
@@ -516,22 +545,24 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *f, unsigned i)
  *                     : obtain the event type according to event name
  *                       event name is unique in the facility
  *Input params
- *    f                : the facility that will be closed
+ *    f                : the facility
  *    name             : the name of the event
  *Return value
  *    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;
+  LttEventType * ev = NULL;
+  
   for(i=0;i<f->event_number;i++){
-    ev = f->events[i];
-    if(strcmp(ev->name, name) == 0)break;      
+    LttEventType *iter_ev = f->events[i];
+    if(g_ascii_strcasecmp(iter_ev->name, name) == 0) {
+      ev = iter_ev;
+      break;
+    }
   }
-
-  if(i==f->event_number) return NULL;
-  else return ev;
+  return ev;
 }
 
This page took 0.026443 seconds and 4 git commands to generate.