commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/geas lib/classdefs/classdata.c lib/classde...


From: Neil Tiffin
Subject: gnue/geas lib/classdefs/classdata.c lib/classde...
Date: Fri, 18 May 2001 20:23:27 -0700

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Neil Tiffin <address@hidden>    01/05/18 20:23:27

Modified files:
        geas/lib/classdefs: classdata.c gcdparser.c lparser.l yparser.y 
        geas/tools     : gcdverifier.c 

Log message:
        Fix include logic such that different relative file name paths will
        not cause the file to be included twice.  Reformat some code.
        All .gcd filenames must be unique without the path.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/classdata.c.diff?cvsroot=OldCVS&tr1=1.44&tr2=1.45&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/gcdparser.c.diff?cvsroot=OldCVS&tr1=1.30&tr2=1.31&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/lparser.l.diff?cvsroot=OldCVS&tr1=1.18&tr2=1.19&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/yparser.y.diff?cvsroot=OldCVS&tr1=1.23&tr2=1.24&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/tools/gcdverifier.c.diff?cvsroot=OldCVS&tr1=1.15&tr2=1.16&r1=text&r2=text

Patches:
Index: gnue/geas/lib/classdefs/classdata.c
diff -u gnue/geas/lib/classdefs/classdata.c:1.44 
gnue/geas/lib/classdefs/classdata.c:1.45
--- gnue/geas/lib/classdefs/classdata.c:1.44    Tue May 15 10:59:07 2001
+++ gnue/geas/lib/classdefs/classdata.c Fri May 18 20:23:26 2001
@@ -22,7 +22,7 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
 
-   $Id: classdata.c,v 1.44 2001/05/15 17:59:07 ntiffin Exp $
+   $Id: classdata.c,v 1.45 2001/05/19 03:23:26 ntiffin Exp $
    
 */
 
@@ -289,7 +289,7 @@
   GList *l;
 
 #ifdef DEBUG
-  printf ("---- odl_namelist_free() ----\n");
+  /* printf ("---- odl_namelist_free() ----\n"); */
   assert (list != NULL);
 #endif
   l = (GList *) list;
@@ -298,7 +298,7 @@
       if (l->data)
         {
 #ifdef DEBUG
-          printf( "...... %s\n" , l->data );
+          /* printf( "...... %s\n" , l->data ); */
 #endif
           g_free (l->data);
         }
@@ -310,7 +310,7 @@
       g_list_free ((GList *) list);
     }
 #ifdef DEBUG
-  printf( "---- end of odl_namelist_free() ----\n" );
+  /* printf( "---- end of odl_namelist_free() ----\n" ); */
 #endif
 }
 
@@ -872,13 +872,13 @@
   if (classd->base.mangledname == NULL)
     {
 #ifdef DEBUG
-      printf( "mangling name %s\n" , classd->base.name );
+      /* printf( "mangling name %s\n" , classd->base.name ); */
 #endif
       classd->base.mangledname =
         odl_mangle_qualified_name (odl_class_get_full_name (classd));
     }
 #ifdef DEBUG
-  printf( "mangled name: %s\n" , classd->base.mangledname );
+  /* printf( "mangled name: %s\n" , classd->base.mangledname ); */
 #endif
   return (classd->base.mangledname);
 }
@@ -1414,7 +1414,7 @@
   
 #ifdef DEBUG
   assert (qualifiedname != NULL);
-  printf( "---- odl_split_qualified_name() is splitting: '%s'\n" , 
qualifiedname );
+  /* printf( "---- odl_split_qualified_name() is splitting: '%s'\n" , 
qualifiedname ); */
 #endif
   /* char *tmp; */
   /* gboolean done = FALSE; */
@@ -1433,7 +1433,7 @@
     {
       names = g_list_append (NULL, g_strdup ("root"));
 #ifdef DEBUG
-      printf( " <root>\n" );
+      /* printf( " <root>\n" ); */
 #endif
       p = &qualifiedname[2];
     }
@@ -1468,7 +1468,7 @@
         {
           names = g_list_append (names, g_strdup (p));
 #ifdef DEBUG
-          printf( " :%s:\n" , p );
+          /* printf( " :%s:\n" , p ); */
 #endif
           p = q + 2;
         }
@@ -1499,8 +1499,8 @@
     }
   name = g_strdup (qualifiedname);
 #ifdef DEBUG
-  printf( "---- odl_mangle_qualified_name()\n" , name , strlen(name) );
-  printf( "     > '%s' (%d)\n" , name , strlen(name) );
+  /* printf( "---- odl_mangle_qualified_name()\n" , name , strlen(name) ); */
+  /* printf( "     > '%s' (%d)\n" , name , strlen(name) ); */
 #endif
   if (strncmp (name, "root::", 6) == 0)
     {
@@ -1521,7 +1521,7 @@
 
       /* next, if any */
 #ifdef DEBUG
-      printf( ": '%s' (%d)\n" , name , strlen(name) );
+      /* printf( ": '%s' (%d)\n" , name , strlen(name) ); */
 #endif
       p = strstr (p, "::");
     }
@@ -1743,6 +1743,7 @@
   expecting_fieldprop = 0;
   expect_triggertype = 0;
   yycurrent_container = odl_tree_get_root (newtree);
+  g_assert( yycurrent_container != NULL);
   l = (GList *) files;
   while (l)
     {
Index: gnue/geas/lib/classdefs/gcdparser.c
diff -u gnue/geas/lib/classdefs/gcdparser.c:1.30 
gnue/geas/lib/classdefs/gcdparser.c:1.31
--- gnue/geas/lib/classdefs/gcdparser.c:1.30    Tue May 15 10:59:07 2001
+++ gnue/geas/lib/classdefs/gcdparser.c Fri May 18 20:23:26 2001
@@ -22,7 +22,7 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
 
-   $Id: gcdparser.c,v 1.30 2001/05/15 17:59:07 ntiffin Exp $
+   $Id: gcdparser.c,v 1.31 2001/05/19 03:23:26 ntiffin Exp $
    
 */
 
@@ -480,6 +480,7 @@
   while (f)
     {
       /* get the field */
+     if (current_pass != 2)  return fields;
       i = (odl_item *) f->data;
 
       /* store the datatype in this field data */
@@ -498,7 +499,7 @@
           i->datatypeclass = g_strdup (datatype->name);
         }
       /* only do the reference and list types on pass 2 */
-      /* if (current_pass != 2)  return fields; */
+      if (current_pass != 2)  return fields;
       if ((datatype->dt == DT_class || datatype->dt == DT_enum))
         {
           if (i->fieldtype == FT_basic && i->datatype == DT_class)
Index: gnue/geas/lib/classdefs/lparser.l
diff -u gnue/geas/lib/classdefs/lparser.l:1.18 
gnue/geas/lib/classdefs/lparser.l:1.19
--- gnue/geas/lib/classdefs/lparser.l:1.18      Tue May 15 10:59:07 2001
+++ gnue/geas/lib/classdefs/lparser.l   Fri May 18 20:23:26 2001
@@ -24,7 +24,7 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    
-   $Id: lparser.l,v 1.18 2001/05/15 17:59:07 ntiffin Exp $
+   $Id: lparser.l,v 1.19 2001/05/19 03:23:26 ntiffin Exp $
 
 */
 
@@ -88,8 +88,8 @@
 
 static char         **processed_files = NULL;
 static unsigned int   processed_count = 0;
-static int is_file_done( char *filename );
-static int record_file_processed( char *filename );
+static int file_processed( const char *filename );
+static int record_file_processed( const char *filename );
 typedef char *charptr;
 
 %}
@@ -120,7 +120,6 @@
         /* setup to read the first line of the primary file */
         first_line = 0; BEGIN(FULLLINE);
     }
-
     /* update token pos by the length of the last token */
     token_pos += lastyyleng;
 %}
@@ -129,35 +128,71 @@
 <*>\/\/.*            { /* ignore rest of line */ }
 
 <incl>{whitespace} { /* ignore */ token_pos += yyleng; }
-<incl>{qstring}    { char *p,*q;
+<incl>{qstring}    { 
+                     char *p,*q;
                      p = yytext + 1;
                      q = strchr( p , '"' );
                      *q = '\0';
-                     if( is_file_done(p) ) BEGIN(endincl);
-                     else {
-                       /* not already processed, so start it now */
-                       record_file_processed(p);
-                       if( push_file(p) ) {
-                           BEGIN(FULLLINE);
+                     /* printf("lparser found file include: %s\n", p); */
+                     if( file_processed(p) )
+                       {
+                         BEGIN(endincl);
+                       }
+                     else
+                       {
+                         /* not already processed, so start it now */
+                         /* printf("lparser processing file include: %s\n", 
p); */
+                         record_file_processed(p);
+                         if( push_file(p) )
+                           {
+                             BEGIN(FULLLINE);
+                           }
+                         else
+                           {
+                             BEGIN(failinclude);
+                           }
                        }
-                       else BEGIN(failinclude);
-                     }
-                   }
+                    }
 
 <incl>{whitespace}{newline}  { yywarn("No filename given for include 
directive"); BEGIN(failinclude); }
 <incl>{whitespace}[^\"\n]+\n |
 <incl>{whitespace}[^\"\n]*   { yywarn("Include filename must be quoted.\n"); 
BEGIN(failinclude); }
 
 <endincl>{whitespace}*  /* ignore whitespace */
-<endincl>\n             { currentfile.line++; BEGIN(FULLLINE); /* return to 
normal processing */ }
-
-<failinclude>.*\n       { currentfile.line++; BEGIN(FULLLINE); /* return to 
normal processing after skipping failed include */ }
+<endincl>\n             {
+                          currentfile.line++;
+                          BEGIN(FULLLINE); /* return to normal processing */
+                        }
 
-<<EOF>> { if(pop_file() == 0 ) { yy_delete_buffer(YY_CURRENT_BUFFER); 
YY_CURRENT_BUFFER = NULL; /*printf( "fclose : %08lx\n" , yyin );*/ 
fclose(yyin);  yyterminate(); } else BEGIN(endincl); }
+<failinclude>.*\n   {
+                      currentfile.line++;
+                      BEGIN(FULLLINE); /* return to normal processing after 
skipping failed include */
+                    }
+
+<<EOF>> {
+          if(pop_file() == 0 )
+            {
+              yy_delete_buffer(YY_CURRENT_BUFFER);
+              YY_CURRENT_BUFFER = NULL;
+              /*printf( "fclose : %08lx\n" , yyin );*/
+              fclose(yyin);
+              yyterminate();
+            }
+          else
+            {
+              BEGIN(endincl);
+            }
+        }
 
 <FULLLINE>\n      |
 <FULLLINE>[^\n]*  { /* record the current line, truncating if necessary */
-                      strncpy( linebuf , yytext , LINEBUF_LENGTH-1 );\
+                      if (strlen( yytext) > LINEBUF_LENGTH)
+                        {
+                          yyerror( "Current line too long." );
+                          yyerror( yytext );
+                          g_assert_not_reached();
+                        }
+                      strncpy( linebuf , yytext , LINEBUF_LENGTH-1 );
                       linebuf[ strlen(linebuf) ] = '\0';
                       token_pos = 1;
                       BEGIN(INITIAL);
@@ -171,11 +206,15 @@
 {newline}    { currentfile.line++; BEGIN(FULLLINE); }
 {whitespace} { /* ignore whitespace*/ token_pos += yyleng; } 
 
-{qstring}           { ST;
+{qstring}           {
+                      ST;
                       while( yytext[strlen(yytext)-1] == '"' )
+                        {
                           yytext[strlen(yytext)-1] = '\0';
+                        }
                       yylval.string = g_strdup(&yytext[1]);
-                      return(STRING);  }
+                      return(STRING);
+                    }
 [+-]?[0-9]+         { ST; yylval.integer  = atol(yytext); return(INTEGER);   }
 [+-]?[0-9]+.[0-9]+  { ST; yylval.floating = atof(yytext); return(DOUBLE);    }
 
@@ -257,258 +296,392 @@
 .                   { ST; return( yytext[0] ); }
 
 %%
-
-int yyerror( char *format , ... )
-{
-    int i;
 
-    va_list ap;
-
-    yyerrorcount++;
-    fprintf( stderr , "error: " );
-    if( yy_show_file_error == 1 ) fprintf( stderr , "file %s, line %d:\n", 
currentfile.name , currentfile.line );
-
-    va_start( ap , format );
-    vfprintf( stderr , format , ap );
-    va_end( ap );
-    fprintf( stderr , "\n" );
-
-    if( yy_show_file_error == 1 ) {
-        fprintf( stderr , "%s\n" , linebuf );
-        for( i=1 ; i<token_pos ; i++ ) 
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
+int
+yyerror (char *format, ...)
+{
+  int i;
+  va_list ap;
+
+  yyerrorcount++;
+  fprintf (stderr, "error: ");
+  if (yy_show_file_error == 1)
+    {
+      fprintf (stderr, "file %s, line %d:\n", currentfile.name,
+               currentfile.line);
+    }
+  va_start (ap, format);
+  vfprintf (stderr, format, ap);
+  va_end (ap);
+  fprintf (stderr, "\n");
+  if (yy_show_file_error == 1)
+    {
+      fprintf (stderr, "%s\n", linebuf);
+      for (i = 1; i < token_pos; i++)
         {
-            if( linebuf[i] == '\t' ) 
-                fprintf( stderr , "\t" );
-            else
-                fprintf( stderr , " " );
+          if (linebuf[i] == '\t')
+            {
+              fprintf (stderr, "\t");
+            }
+          else
+            {
+              fprintf (stderr, " ");
+            }
         }
-        fprintf( stderr , "^\n" );
+      fprintf (stderr, "^\n");
     }
-    fprintf( stderr , "\n" );
-    return( 0 );
+  fprintf (stderr, "\n");
+  return (0);
 }
-                                
-int yywarn( char *format , ... )
-{
-    int i;
-
-    va_list ap;
-
-    yywarncount++;
-    fprintf( stderr , "warning: " );
-    if( yy_show_file_error == 1 ) fprintf( stderr , "file %s, line %d:\n", 
currentfile.name , currentfile.line );
-
-    va_start( ap , format );
-    vfprintf( stderr , format , ap );
-    va_end( ap );
-    fprintf( stderr , "\n" );
-
-    if( yy_show_file_error == 1 ) {
-        fprintf( stderr , "%s\n" , linebuf );    
 
-        for( i=1 ; i<token_pos ; i++ ) 
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
+int
+yywarn (char *format, ...)
+{
+  int i;
+  va_list ap;
+
+  yywarncount++;
+  fprintf (stderr, "warning: ");
+  if (yy_show_file_error == 1)
+    {
+      fprintf (stderr, "file %s, line %d:\n", currentfile.name,
+               currentfile.line);
+    }
+  va_start (ap, format);
+  vfprintf (stderr, format, ap);
+  va_end (ap);
+  fprintf (stderr, "\n");
+  if (yy_show_file_error == 1)
+    {
+      fprintf (stderr, "%s\n", linebuf);
+      for (i = 1; i < token_pos; i++)
         {
-            if( linebuf[i] == '\t' ) 
-                fprintf( stderr , "\t" );
-            else
-                fprintf( stderr , " " );
+          if (linebuf[i] == '\t')
+            {
+              fprintf (stderr, "\t");
+            }
+          else
+            {
+              fprintf (stderr, " ");
+            }
         }
 
-        fprintf( stderr , "^\n" );
+      fprintf (stderr, "^\n");
     }
-    fprintf( stderr , "\n" );
-    return( 0 );
+  fprintf (stderr, "\n");
+  return (0);
 }
-                                
-int yymessage( char *format , ... )
-{
-    int i;
-
-    va_list ap;
-
-    fprintf( stderr , "message: " );
-    if( yy_show_file_error == 1 ) fprintf( stderr , "file %s, line %d:\n", 
currentfile.name , currentfile.line );
 
-    va_start( ap , format );
-    vfprintf( stderr , format , ap );
-    va_end( ap );
-    fprintf( stderr , "\n" );
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
+int
+yymessage (char *format, ...)
+{
+  /*int i;*/
+  va_list ap;
 
-    return( 0 );
+  fprintf (stderr, "message: ");
+  if (yy_show_file_error == 1)
+    {
+      fprintf (stderr, "file %s, line %d:\n", currentfile.name,
+               currentfile.line);
+    }
+  va_start (ap, format);
+  vfprintf (stderr, format, ap);
+  va_end (ap);
+  fprintf (stderr, "\n");
+  return (0);
 }
 
-void yy_setfirstfilename( char *filename )
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
+void
+yy_setfirstfilename (char *filename)
 {
-    strcpy( currentfile.name , filename );
+  strcpy (currentfile.name, filename);
 }
 
-static int push_file( char *fn )
-{
-   FILE *newfile;
-   struct FileData *tmp;
-   char *filename;
-   char *p;
-
-   filename = g_strdup( currentfile.name );
-   p = &filename[ strlen(filename)-1 ];
-   while( p != filename ) {
-       if( *p == '/' ) {
-           *p = '\0';
-           break;
-       }
-       p--;
-   }
-
-   if( strcmp(filename,"(reading from stdin)")==0 ) {
-      g_free( filename );
-      filename = g_strdup(fn);
-   }
-   else if( p != filename ) {
-       char *tmp = g_strdup_printf( "%s/%s" , filename , fn );
-       g_free( filename );
-       filename = tmp;
-   }
-   else {
-      g_free( filename );
-      filename = g_strdup(fn);
-   }
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
+static int
+push_file (char *fn)
+{
+  FILE *newfile;
+  struct FileData *tmp;
+  char *filename;
+  char *p;
+  /*
+  printf ("push_file() fn: %s\n", fn);
+  printf ("push_file() current.name: %s\n", currentfile.name);
+  */
+  filename = g_strdup (currentfile.name);
+  p = &filename[strlen (filename) - 1];
+  /* strip filename from path/filename */
+  while (p != filename)
+    {
+      if (*p == '/')
+        {
+          *p = '\0';
+          break;
+        }
+      p--;
+    }
+  /* printf ("push_file() p: %s\n", p); */
 
-   newfile = fopen( filename , "r" );
-   if( !newfile ) {
-      yywarn( "Could not open include file %s" , filename );
-      return(0);
-   }
-   /* printf( "fopen : %08lx\n" , newfile ); */
+  /* if necessary add new path/file to old path */
+  /* include file name is relative to current file location */
+  if (strcmp (filename, "(reading from stdin)") == 0)
+    {
+      g_free (filename);
+      filename = g_strdup (fn);
+    }
+  else if (p != filename)
+    {
+      char *tmp = g_strdup_printf ("%s/%s", filename, fn);
+      g_free (filename);
+      filename = tmp;
+    }
+  else
+    {
+      g_free (filename);
+      filename = g_strdup (fn);
+    }
 
-   tmp = (struct FileData *)g_malloc( sizeof(struct FileData) );
-   if( tmp ) {
-       tmp->next = file_stack;
-       file_stack = tmp;
-       memcpy( tmp , &currentfile , sizeof(struct FileData) );
-       tmp->yybuffer = YY_CURRENT_BUFFER;
-       
-       yyin = newfile;
-       yy_switch_to_buffer( yy_create_buffer(yyin,YY_BUF_SIZE) );
+  newfile = fopen (filename, "r");
+  if (!newfile)
+    {
+      yywarn ("Could not open include file %s", filename);
+      return (0);
+    }
+  /* printf( "fopen : %08lx\n" , newfile ); */
+  /* printf ("push_file() filename: %s\n", filename); */
 
-       strcpy( currentfile.name , filename );
-       currentfile.line = 1;
-       strcpy( currentfile.modulename   , "" );
-       strcpy( currentfile.moduleprefix , "" );
+  tmp = (struct FileData *) g_malloc (sizeof (struct FileData));
+  g_assert (tmp != NULL);
+  if (tmp)
+    {
+      tmp->next = file_stack;
+      file_stack = tmp;
+      memcpy (tmp, &currentfile, sizeof (struct FileData));
+      tmp->yybuffer = YY_CURRENT_BUFFER;
+
+      yyin = newfile;
+      yy_switch_to_buffer (yy_create_buffer (yyin, YY_BUF_SIZE));
+
+      strcpy (currentfile.name, filename);
+      currentfile.line = 1;
+      strcpy (currentfile.modulename, "");
+      strcpy (currentfile.moduleprefix, "");
 
-       return( 1 );
-   }
+      return (1);
+    }
 
-   /* out of memory */
-   /* printf( "fclose : %08lx\n" , newfile ); */
-   fclose( newfile );
-   return(0);
+  /* out of memory */
+  /* printf( "fclose : %08lx\n" , newfile ); */
+  fclose (newfile);
+  return (0);
 }
 
-static int  pop_file()
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
+static int
+pop_file ()
 {
-   struct FileData *tmp;
+  struct FileData *tmp;
 
-   if( file_stack == NULL ) return(0);
-   tmp = file_stack;
-   file_stack = file_stack->next;
-
-   memcpy( &currentfile , tmp , sizeof(struct FileData) );
-   yy_delete_buffer( YY_CURRENT_BUFFER );
-   yy_switch_to_buffer( tmp->yybuffer );
-   g_free( tmp );
-   currentfile.next = NULL;
-
-   return( 1 );
-}
+  if (file_stack == NULL)
+    {
+      return (0);
+    }
+  tmp = file_stack;
+  /* printf ("pop_file() - Done with file named: %s\n", file_stack->name); */
 
-int yystartfile( char *filename )
+  file_stack = file_stack->next;
+  /*
+  if (file_stack != NULL)
+    printf ("pop_file() - Pop file named: %s\n", file_stack->name);
+  else
+    printf ("pop_file() - Pop file named: NULL\n");
+  */
+  memcpy (&currentfile, tmp, sizeof (struct FileData));
+  yy_delete_buffer (YY_CURRENT_BUFFER);
+  yy_switch_to_buffer (tmp->yybuffer);
+  g_free (tmp);
+  currentfile.next = NULL;
+
+  return (1);
+}
+
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
+int
+yystartfile (char *filename)
 {
-    FILE *fp;
-    
-    /* if file has been processed, skip it */
-    if( is_file_done(filename) ) return(0);
-    record_file_processed(filename);
+  FILE *fp;
 
-    /* open it */
-    fp = fopen( filename , "r" );
-    if( !fp ) return(-1);
-    
-    /* printf( "fopen : %08lx\n" , fp ); */
-
-    /* ntiffin */ /* reset lexer state */
-        expecting_datatype  = 1;        
-        expecting_fieldprop = 0;
-        expect_triggertype  = 0;
+  /* if file has been processed, skip it */
+  if (file_processed (filename))
+    {
+      return (0);
+    }
+  record_file_processed (filename);
 
-    /* setup lexer */
-    yyrestart( fp );
-    yy_setfirstfilename( filename );
+  /* open it */
+  fp = fopen (filename, "r");
+  if (!fp)
+    {
+      return (-1);
+    }
 
-    /* clear data */
-    first_line = 1;
-    currentfile.line = 1;
-    strcpy( currentfile.modulename , "" );
-    strcpy( currentfile.moduleprefix , "" );
-    currentfile.next = NULL;
-    
-    /* done */
-    return(1);
-}
+  /* printf( "fopen : %08lx\n" , fp ); */
 
-static int record_file_processed( char *filename )
+/* ntiffin *//* reset lexer state */
+  expecting_datatype = 1;
+  expecting_fieldprop = 0;
+  expect_triggertype = 0;
+
+  /* setup lexer */
+  yyrestart (fp);
+  yy_setfirstfilename (filename);
+
+  /* clear data */
+  first_line = 1;
+  currentfile.line = 1;
+  strcpy (currentfile.modulename, "");
+  strcpy (currentfile.moduleprefix, "");
+  currentfile.next = NULL;
+
+  /* done */
+  return (1);
+}
+
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
+static int
+record_file_processed (const char *filename)
 {
-    char *f;
-
-    if( is_file_done(filename) ) return(1);
-
-    processed_count++;
-    processed_files = (char **)realloc( processed_files , 
(processed_count)*(sizeof(char *)) );    
-    processed_files[processed_count-1] = g_strdup(filename);
-    
-    return(1);
-
+  g_assert( filename != NULL);
+  if ((file_processed (filename) == 0) && (filename != NULL))
+    {
+      processed_count++;
+      processed_files =
+        (char **) realloc (processed_files,
+                          (processed_count) * (sizeof (char *)));
+      processed_files[processed_count - 1] = g_strdup (filename);
+    }
+  return (1);
 }
-
-static int is_file_done( char *filename )
-{
-    int i;
 
-    /* empty list? */
-    if( processed_files == NULL ) return(0);
-
-    for( i=0 ; i <processed_count ; i++ ) {
-        if( strcasecmp(processed_files[i],filename) == 0 ) return(1); 
+/* ------------------------------------------------------------------------- *\
+ * compare the name only and ignore path in filename
+\* ------------------------------------------------------------------------- */
+static gboolean
+compare_file_name_only( const char * name1, const char *name2)
+{
+  char * ptr1;
+  char * ptr2;
+  
+  g_assert( name1 );
+  g_assert( name2 );
+
+  ptr1 = g_basename( name1);
+  ptr2 = g_basename( name2);
+  g_assert( ptr1 );
+  g_assert( ptr2 );
+  /*
+  printf( "compare_file_name_only() - file 1: %s\n", name1);
+  printf( "compare_file_name_only() - file 2: %s\n", name2);
+  printf( "compare_file_name_only() - base 1: %s\n", ptr1);
+  printf( "compare_file_name_only() - base 2: %s\n", ptr2);
+  */
+  if ( strcasecmp( ptr1, ptr2) == 0)
+    {
+      /* printf("compare_file_name_only() - true\n"); */
+      return TRUE;
+     }
+  /* printf("compare_file_name_only() - false\n"); */
+  return FALSE;
+}
+
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
+static int
+file_processed (const char *filename)
+{
+  int i;
+  
+  /* empty list? */
+  if (processed_files == NULL)
+    {
+      return (0);
     }
-    return(0);
+  for (i = 0; i < processed_count; i++)
+    {
+      if (compare_file_name_only (processed_files[i], filename) == TRUE)
+        {
+          /* printf( "file_processed() - true\n"); */
+          return (1);
+        }
+    }
+  return (0);
 }
 
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
 void
-clear_file_history( )
+clear_file_history ()
 {
-    int i;
-
-    if( processed_files == NULL ) return;
-
-/* printf( "freeing elemts: 0 - %d\n" , processed_files->len ); */
-/* printf( "freeing elements: 0 - %d\n" , processed_count ); */
+  int i;
+  g_assert (processed_files);
+  if (processed_files == NULL)
+    {
+      return;
+    }
+  /* printf( "freeing elemts: 0 - %d\n" , processed_files->len ); */
+  /* printf( "freeing elements: 0 - %d\n" , processed_count ); */
 
-for( i=0 ; i <processed_count ; i++ ) {
-    if( processed_files[i] ) free( processed_files[i] );
-}
-free( processed_files );
-    processed_count = 0;
+  for (i = 0; i < processed_count; i++)
+    {
+      if (processed_files[i])
+        {
+          free (processed_files[i]);
+        }
+    }
+  free (processed_files);
+  processed_count = 0;
 
-    processed_files = NULL;
-/*        printf( "freed processed files array\n" ); */
+  processed_files = NULL;
+  /* printf( "freed processed files array\n" ); */
 }
 
-int yywrap()
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
+int
+yywrap ()
 {
-   return(1); /* stop scanning */
+  return (1);                   /* stop scanning */
 }
 
-void errors_show_file( int state )
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
+void
+errors_show_file (int state)
 {
-   yy_show_file_error = state;
+  yy_show_file_error = state;
 }
-
Index: gnue/geas/lib/classdefs/yparser.y
diff -u gnue/geas/lib/classdefs/yparser.y:1.23 
gnue/geas/lib/classdefs/yparser.y:1.24
--- gnue/geas/lib/classdefs/yparser.y:1.23      Tue May 15 11:32:26 2001
+++ gnue/geas/lib/classdefs/yparser.y   Fri May 18 20:23:26 2001
@@ -112,6 +112,7 @@
 
 pop_module:  /* */   {
                        if( current_pass == 1 ) {
+                         /* printf( "pop_module:\n"); */
                          yycurrent_container = (odl_container *)
                              odl_container_get_parent(yycurrent_container);
                          /* indent-=4; doindent(); printf( "pop module\n" ); */
@@ -126,12 +127,15 @@
                        if( current_pass == 1 )
                          {
                            odl_class *newone;
+                           /* printf( "push_class name: %s\n", $<list>-0); */
+                            /*  TODO start hack to stop duplicate classes
                            odl_class *check_class;
                            check_class = odl_find_class(yycurrenttree, 
$<string>0, NULL);
                            if (check_class != NULL)
                              {
                                yyerror( "duplicate class name found" );
                              }
+                           */
                            newone = odl_new_class($<uint>-4,$<string>0);
                            odl_container_insert_container( yycurrent_container 
,
                                                          (odl_container 
*)newone );
@@ -149,36 +153,47 @@
                      }
   ;
 
-pop_class:   /* */   {
-                GList *l;
-                odl_class *c = NULL;
-                if( current_pass == 1 ) {
-                         c = (odl_class *)yycurrent_container;
-                         yycurrent_container = (odl_container *)
-                             odl_container_get_parent(yycurrent_container);
-                         /* indent-=4; doindent(); printf( "pop class\n" ); */
-
-                /* add all the class's info to yycurrent_container */
-
-                /* add fields in the class (any subclasses already added) */
-                if( $<list>-1 ) {
-                    if( c->contents ) {
-                      c->contents = g_list_concat( c->contents , $<list>-1 );
-                    }
-                    else {
-                      c->contents = $<list>-1;
-                    }
-                }
-
-                /* add parents */
-                c->parents = $<list>-4;
-                }
-
-                else { /* current_pass == 2 */
-                    odl_standardise_parents( (odl_class *)yycurrent_container 
);
-                    yycurrent_container = (odl_container 
*)yycurrent_container->base.parent;
-                }
-         }
+pop_class:   /* */    {
+                        GList *l;
+                        odl_class *c = NULL;
+                        if (current_pass == 1)
+                          {
+                            /*
+                            odl_container * tmp;
+                            tmp = (odl_container *) yycurrent_container;
+                            printf( "pop_class current name: %s\n", 
tmp->base.name);
+                            */
+                            c = (odl_class *) yycurrent_container;
+                            yycurrent_container = (odl_container *)
+                              odl_container_get_parent (yycurrent_container);
+                            /*
+                            tmp = (odl_container *) yycurrent_container;
+                            printf( "pop_class new name: %s\n", 
tmp->base.fullname);
+                            */
+                            /* indent-=4; doindent(); printf( "pop class\n" ); 
*/
+                            /* add all the class's info to yycurrent_container 
*/
+                            /* add fields in the class (any subclasses already 
added) */
+                            if ($<list>-1)
+                              {
+                                if (c->contents)
+                                  {
+                                    c->contents = g_list_concat (c->contents, 
$<list>-1);
+                                  }
+                                else
+                                  {
+                                    c->contents = $<list>-1;
+                                  }
+                              }
+                            /* add parents */
+                            c->parents = $<list>-4;
+                          }
+                        else
+                          {                           /* current_pass == 2 */
+                            odl_standardise_parents ((odl_class *) 
yycurrent_container);
+                            yycurrent_container =
+                              (odl_container *) 
yycurrent_container->base.parent;
+                          }
+                      }
   ;
 
 unit_list: unit
Index: gnue/geas/tools/gcdverifier.c
diff -u gnue/geas/tools/gcdverifier.c:1.15 gnue/geas/tools/gcdverifier.c:1.16
--- gnue/geas/tools/gcdverifier.c:1.15  Tue May 15 10:50:39 2001
+++ gnue/geas/tools/gcdverifier.c       Fri May 18 20:23:26 2001
@@ -20,7 +20,7 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
  
-   $Id: gcdverifier.c,v 1.15 2001/05/15 17:50:39 ntiffin Exp $
+   $Id: gcdverifier.c,v 1.16 2001/05/19 03:23:26 ntiffin Exp $
 */
 
 #include <glib.h>
@@ -42,6 +42,9 @@
 
 /** \brief Message output function
  */
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
 void
 error_message_out (char *type, char *file, char *func,
                    unsigned int line, char *msg)
@@ -69,11 +72,20 @@
 
 /** \brief Test if a file ends with a particular extension
  */
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
 gboolean
 is_extension (const char *filename, const char *ext)
 {
-  int flen = strlen (filename);
-  int elen = strlen (ext);
+  int flen;
+  int elen;
+  
+  g_assert( filename );
+  g_assert( ext );
+  
+  flen = strlen (filename);
+  elen= strlen (ext);
   /*
      printf( "filename: '%s' (%d)\n" , filename , strlen(filename) );
      printf( "ext     : '%s' (%d)\n" , ext      , strlen(ext) );
@@ -92,6 +104,9 @@
 }
 
 
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
 int
 main (int argc, char *argv[])
 {
@@ -125,7 +140,7 @@
           else if (strcmp (argv[i], "--version") == 0)
             {
               GString *revision;
-              revision = g_string_new ("$Revision: 1.15 $");
+              revision = g_string_new ("$Revision: 1.16 $");
               if (revision->len > 14)
                 {
                   revision = g_string_erase (revision, 0, 11);  /* remove the 
'$Revsion:' part */
@@ -178,54 +193,55 @@
 
 /** \brief Load the GCD files
  */
+/* ------------------------------------------------------------------------- *\
+ * 
+\* ------------------------------------------------------------------------- */
 void
 verify_class_files (const char *name)
 {
   struct dirent *next;
   DIR *reading;
-  /* int error; */
-  /* odl_filenamelist *fl = NULL; */
-  /* char *name; */
   char *linkbuf;
   char *classdir;
-  GList /* *l, */  * subdirs = NULL, *tmp;
+  GList * subdirs = NULL;
+  GList *tmp;
   GString *currpath = NULL;
-  struct stat s, s2;
+  struct stat s;
+  struct stat s2;
   int linksize;
   gboolean is_dir = FALSE;
 
-  /* name = (char *)get_global_option_str(configdata, "classdir", "."); */
-
+  g_assert( name );
   if (name == NULL)
     {
-      perror ("Cannot parse classdir option");
+      perror ("Empty name.");
       exit (-1);
     }
-  /* debug_output(DEBUGLEVEL_HIGH,"Name = %s", name); */
   classdir = g_strdup (name);
 
-  /* debug_output(DEBUGLEVEL_HIGH,"Classdir = %s", classdir); */
-
   /* find GCD files */
+  g_assert( classdir );
   if (classdir == NULL)
     {
       perror
-        ("No class definitions were found. Please ensure the arguments include 
a directory with valid '.gcd' files.");
+        ("Not able to copy name.\n");
       exit (-1);
     }
+  /* whack out ending slashes to create path */
   while (classdir[strlen (classdir) - 1] == '\\' ||
-         classdir[strlen (classdir) - 1] == '/')
+         classdir[strlen (classdir) - 1] == G_DIR_SEPARATOR)
     {
       classdir[strlen (classdir) - 1] = '\0';
     }
   currpath = g_string_new (classdir);
-  currpath = g_string_append (currpath, "/");
+  currpath = g_string_append (currpath, G_DIR_SEPARATOR_S);
   subdirs = g_list_append (subdirs, g_strdup (classdir));
-  /* debug_output(DEBUGLEVEL_HIGH,"Current path = %s", currpath->str); */
+  printf("Current path = %s\n", currpath->str);
 
   while (g_list_length (subdirs) != 0)
     {
       reading = opendir (currpath->str);
+      g_assert(reading);
       if (!reading)
         {
           perror ((const char *) currpath->str);
@@ -234,17 +250,24 @@
         }
       else
         {
-          /* Skip ./ and ../ directories */
-          readdir (reading);
-          readdir (reading);
-
-          while ((next = readdir (reading)) != NULL)
+          next = readdir (reading);
+          while (next != NULL)
             {
-              lstat (g_strdup_printf ("%s%s", currpath->str, next->d_name),
-                     &s);
-
+              /* Skip "." and ".." directories */
+              if ( strcmp( next->d_name, ".") == 0)
+                {
+                  next = readdir (reading);
+                  continue;
+                }
+              if ( strcmp( next->d_name, "..") == 0)
+                {
+                  next = readdir (reading);
+                  continue;
+                }
+              lstat (g_strdup_printf ("%s%s", currpath->str, next->d_name), 
&s);
               if (S_ISLNK (s.st_mode))
                 {
+                  /* file is a link */
                   linkbuf = g_new (gchar, PATH_MAX + 2);
                   linksize =
                     readlink (g_strdup_printf
@@ -252,37 +275,39 @@
                               PATH_MAX + 1);
                   /* debug_output(DEBUGLEVEL_HIGH,"Link found: %s -> %s", 
g_strdup_printf ("%s%s", currpath->str,
                      next->d_name), linkbuf); */
-                  if (g_strcasecmp (classdir, linkbuf) &&
-                      g_strcasecmp ("./", linkbuf) &&
-                      g_strcasecmp ("../", linkbuf) &&
-                      g_strcasecmp (currpath->str, linkbuf))
+                  if (g_strcasecmp (classdir, linkbuf)
+                      || g_strcasecmp ("./", linkbuf)
+                      || g_strcasecmp ("../", linkbuf)
+                      || g_strcasecmp (currpath->str, linkbuf))
                     {
+                      ;  /* do nothing */
+                    }
+                  else
+                    {
                       stat (linkbuf, &s2);
                       if (S_ISDIR (s2.st_mode))
                         {
-#warning "FIXME: Bug in symlinks to directories -- chillywilly"
+                          #warning "FIXME: Bug in symlinks to directories -- 
chillywilly"
                           /* debug_output(DEBUGLEVEL_MEDIUM,"Appending %s/", 
linkbuf); */
                           subdirs =
-                            g_list_append (subdirs,
-                                           g_strdup_printf ("%s/", linkbuf));
+                            g_list_append (subdirs, g_strdup_printf ("%s/", 
linkbuf));
                         }
                     }
                   g_free (linkbuf);
                 }
-
               if (S_ISDIR (s.st_mode))
                 {
+                  /* file is a directory */
                   is_dir = TRUE;
-                  /* debug_output(DEBUGLEVEL_MEDIUM,"Appending %s%s/", 
currpath->str, next->d_name); */
+                  /* printf("Found directory path %s\n", currpath->str); */
+                  /* printf("Found directory name %s\n", next->d_name); */
                   subdirs =
-                    g_list_append (subdirs,
-                                   g_strdup_printf ("%s%s/", currpath->str,
-                                                    next->d_name));
+                    g_list_append (subdirs, g_strdup_printf ("%s%s/", 
currpath->str, next->d_name));
                 }
-              if (is_extension (next->d_name, "gcd"))
+              if ((S_ISREG (s.st_mode)) && (is_extension (next->d_name, 
"gcd")))
                 {
-                  char *tmp =
-                    g_strdup_printf ("%s%s", currpath->str, next->d_name);
+                  /* file is a regular file with an extension of ".gcd" */
+                  char *tmp = g_strdup_printf ("%s%s", currpath->str, 
next->d_name);
                   if (tmp)
                     {
                       /* debug_output(DEBUGLEVEL_MEDIUM,"Adding %s to odl file 
name list", tmp); */
@@ -290,6 +315,7 @@
                       g_free (tmp);
                     }
                 }
+              next = readdir (reading);
             }
           closedir (reading);
           subdirs = g_list_remove (subdirs, (g_list_first (subdirs))->data);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]