commit-gnue
[Top][All Lists]
Advanced

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

gnue/geas/tools gcdverifier.c


From: Neil Tiffin
Subject: gnue/geas/tools gcdverifier.c
Date: Sat, 05 May 2001 09:03:53 -0700

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Neil Tiffin <address@hidden>    01/05/05 09:03:53

Modified files:
        geas/tools     : gcdverifier.c 

Log message:
        Revise format to GNU standards.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/tools/gcdverifier.c.diff?cvsroot=OldCVS&tr1=1.12&tr2=1.13&r1=text&r2=text

Patches:
Index: gnue/geas/tools/gcdverifier.c
diff -u gnue/geas/tools/gcdverifier.c:1.12 gnue/geas/tools/gcdverifier.c:1.13
--- gnue/geas/tools/gcdverifier.c:1.12  Thu Apr 19 11:22:47 2001
+++ gnue/geas/tools/gcdverifier.c       Sat May  5 09:03:53 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.12 2001/04/19 18:22:47 ntiffin Exp $
+   $Id: gcdverifier.c,v 1.13 2001/05/05 16:03:53 ntiffin Exp $
 */
 
 #include <glib.h>
@@ -36,259 +36,279 @@
 
 /* #define errormsg(fmt,args...) 
error_message_out("error",__FILE__,__PRETTY_FUNCTION__,__LINE__ , fmt , ##args 
) */
 
-void verify_class_files(const char * name);
+void verify_class_files (const char *name);
 
 odl_filenamelist *fl = NULL;
 
 /** \brief Message output function
  */
 void
-error_message_out(char *type, char *file, char *func,
-                  unsigned int line, char *msg)
-   {
+error_message_out (char *type, char *file, char *func,
+                   unsigned int line, char *msg)
+{
 
 #ifdef DEBUG
-   fprintf(stderr, "%s: ", type);
-   /* where was the error detected - debug mode only, because most users
-      won't be able to do much with it. */
-   if (file != NULL)
-      fprintf(stderr, "[%s/%d] [%s] ", file, line, func);
+  fprintf (stderr, "%s: ", type);
+  /* where was the error detected - debug mode only, because most users
+     won't be able to do much with it. */
+  if (file != NULL)
+    {
+      fprintf (stderr, "[%s/%d] [%s] ", file, line, func);
+    }
 #else
-   fprintf(stderr, "%s: ", type);
+  fprintf (stderr, "%s: ", type);
 #endif
 
-   fprintf(stderr, msg);
-   fprintf(stderr, "\n");
+  fprintf (stderr, msg);
+  fprintf (stderr, "\n");
 
-   /* write buffers */
-   fflush(NULL);
-   }
+  /* write buffers */
+  fflush (NULL);
+}
 
 
 /** \brief Test if a file ends with a particular extension
  */
 gboolean
-is_extension(const char *filename, const char *ext)
+is_extension (const char *filename, const char *ext)
 {
-   int flen = strlen(filename);
-   int elen = strlen(ext);
-                /*
-                printf( "filename: '%s' (%d)\n" , filename , strlen(filename) 
);
-                printf( "ext     : '%s' (%d)\n" , ext      , strlen(ext) );
-                printf( "compare(%s,%s)\n" , &filename[flen - elen], ext );
-                */
-    if ((elen + 1) > flen)
+  int flen = strlen (filename);
+  int elen = strlen (ext);
+  /*
+     printf( "filename: '%s' (%d)\n" , filename , strlen(filename) );
+     printf( "ext     : '%s' (%d)\n" , ext      , strlen(ext) );
+     printf( "compare(%s,%s)\n" , &filename[flen - elen], ext );
+   */
+  if ((elen + 1) > flen)
     {
-        return (FALSE);
+      return (FALSE);
     }
-    if (g_strcasecmp(&filename[flen - elen], ext) == 0 && filename[flen - elen 
- 1] == '.')
+  if (g_strcasecmp (&filename[flen - elen], ext) == 0
+      && filename[flen - elen - 1] == '.')
     {
-        return (TRUE);
+      return (TRUE);
     }
-       return (FALSE);
+  return (FALSE);
 }
 
 
 int
-main(int argc, char *argv[])
+main (int argc, char *argv[])
 {
-       odl_tree *t = NULL;
-       int i, count;
-       gboolean fullname = FALSE;
-    gboolean verbose = FALSE;
-    int number_entries = 0;            /* keeps track if we have any files or 
dir to process */
-       if (argc < 2)
-       {
-               printf("Usage: %s [-f] [-version] [file | directory] ... [fileN 
| directoryN]\n", argv[0]);
-               exit(EXIT_FAILURE);
-       }
-       count = 1;
-       while (count < 2)
-       {
-               count++;
-                                                                               
                /* select files to load */
-               for (i = 1; i < argc; i++)
-               {
-                       if( strcmp(argv[i],"-f") == 0 )         /* show full 
name on output */
-                       {
-                               fullname = TRUE;
-                       }
-            if( strcmp(argv[i],"-verbose") == 0 )
+  odl_tree *t = NULL;
+  int i, count;
+  gboolean fullname = FALSE;
+  gboolean verbose = FALSE;
+  int number_entries = 0;       /* keeps track if we have any files or dir to 
process */
+  if (argc < 2)
+    {
+      printf
+        ("Usage: %s [-f] [-version] [file | directory] ... [fileN | 
directoryN]\n",
+         argv[0]);
+      exit (EXIT_FAILURE);
+    }
+  count = 1;
+  while (count < 2)
+    {
+      count++;
+      /* select files to load */
+      for (i = 1; i < argc; i++)
+        {
+          if (strcmp (argv[i], "-f") == 0)      /* show full name on output */
+            {
+              fullname = TRUE;
+            }
+          if (strcmp (argv[i], "-verbose") == 0)
             {
-                verbose = TRUE;
+              verbose = TRUE;
             }
-                       else if ( strcmp(argv[i],"-version") == 0 )
-                       {
-                GString *revision;
-                revision = g_string_new("$Revision: 1.12 $");
-                if ( revision->len > 14)
+          else if (strcmp (argv[i], "-version") == 0)
+            {
+              GString *revision;
+              revision = g_string_new ("$Revision: 1.13 $");
+              if (revision->len > 14)
                 {
-                    revision = g_string_erase( revision, 0, 11); /* remove the 
'$Revsion:' part */
-                    revision = g_string_erase( revision, (revision->len)-2, 
2); /* remove the last two characters */
-                               }
-                printf("GNUe GCD File Format Verifier, version %s\n", 
revision->str);
-                printf("Part of the GNU Enterprise Project.\n");
-                printf("Copyright (c) 2000, 2001 Free Software Foundation\n");
-                printf("This is free software; see the source for copying 
conditions.\n");
-                printf("There is NO warranty; not even for MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.\n");
-                g_string_free( revision, TRUE);
-           }
-                       else if (is_extension(argv[i], "gcd"))  /* is a file 
with an extension of '.gcd. */
+                  revision = g_string_erase (revision, 0, 11);  /* remove the 
'$Revsion:' part */
+                  revision = g_string_erase (revision, (revision->len) - 2, 
2); /* remove the last two characters */
+                }
+              printf ("GNUe GCD File Format Verifier, version %s\n",
+                      revision->str);
+              printf ("Part of the GNU Enterprise Project.\n");
+              printf ("Copyright (c) 2000, 2001 Free Software Foundation\n");
+              printf
+                ("This is free software; see the source for copying 
conditions.\n");
+              printf
+                ("There is NO warranty; not even for MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.\n");
+              g_string_free (revision, TRUE);
+            }
+          else if (is_extension (argv[i], "gcd"))       /* is a file with an 
extension of '.gcd. */
             {
-                number_entries++;
-                fl = odl_filenamelist_add( fl , argv[i] );
+              number_entries++;
+              fl = odl_filenamelist_add (fl, argv[i]);
             }
-            else                                                               
/* must be a directory */
-                       {                                                       
                /* means directories with .gcd at the end will not work */
-                number_entries++;
-                               verify_class_files(argv[i]);
-                       }
-               }
-        if (number_entries > 0)
+          else                  /* must be a directory */
+            {                   /* means directories with .gcd at the end will 
not work */
+              number_entries++;
+              verify_class_files (argv[i]);
+            }
+        }
+      if (number_entries > 0)
         {
-                                                                               
                /* load them */
-            t = odl_load_files(fl, NULL);
-            odl_display_tree(stdout, t, fullname);
-                                                                               
                /* free memory */
-            if (verbose)
-                printf( "Freeing class data.\n" );
+          /* load them */
+          t = odl_load_files (fl, NULL);
+          odl_display_tree (stdout, t, fullname);
+          /* free memory */
+          if (verbose)
+            {
+              printf ("Freeing class data.\n");
+            }
         }
-               odl_free_tree(t);
-               odl_filenamelist_free(fl);
-               fl = NULL;
-       }
-exit(EXIT_SUCCESS);
+      odl_free_tree (t);
+      odl_filenamelist_free (fl);
+      fl = NULL;
+    }
+  exit (EXIT_SUCCESS);
 }
 
 /** \brief Load the GCD files
  */
 void
-verify_class_files(const char * name)
+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;
-       GString *currpath = NULL;
-       struct stat s, s2;
-       int linksize;
-       gboolean is_dir = FALSE;
-
-       /* name = (char *)get_global_option_str(configdata, "classdir", ".");*/
-       
-       if (name == NULL)
-       {
-               perror ("Cannot parse classdir option");
-               exit (-1);
-       }
-       /* debug_output(DEBUGLEVEL_HIGH,"Name = %s", name); */
-       classdir = g_strdup(name);
-
-       /* debug_output(DEBUGLEVEL_HIGH,"Classdir = %s", classdir); */
-
-       /* find GCD files */
-       if (classdir == NULL)
-       {
-               perror ("No class definitions were found. Please ensure the 
arguments include a directory with valid '.gcd' files.");
-               exit( -1);
-       }
-       while (classdir[strlen(classdir) - 1] == '\\' ||
-               classdir[strlen(classdir) - 1] == '/')
-               classdir[strlen(classdir) - 1] = '\0';
-
-       currpath = g_string_new (classdir);
-       currpath = g_string_append (currpath, "/");
-       subdirs = g_list_append (subdirs, g_strdup (classdir));
-       /* debug_output(DEBUGLEVEL_HIGH,"Current path = %s", currpath->str); */
-
-       while (g_list_length (subdirs) != 0)
-       {
-               reading = opendir (currpath->str);
-               if (!reading)
-               {
-                       perror ((const char *)currpath->str);
-                       closedir (reading);
-                       exit (-1);
-               }
-               else
-               {
-                       /* Skip ./ and ../ directories */
-                       readdir (reading);
-                       readdir (reading);
-
-                       while ((next = readdir(reading)) != NULL)
-                       {
-                               lstat (g_strdup_printf ("%s%s", currpath->str, 
next->d_name), &s);
-                               
-                               if (S_ISLNK (s.st_mode))
-                               {
-                                       linkbuf = g_new (gchar, PATH_MAX + 2);
-                                       linksize = readlink (g_strdup_printf 
("%s/%s", currpath->str, next->d_name),
-                                       linkbuf, 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))
-                                       {
-                                               stat (linkbuf, &s2);
-                                               if (S_ISDIR (s2.st_mode))
-                                               {
+  struct dirent *next;
+  DIR *reading;
+  /* int error; */
+  /* odl_filenamelist *fl = NULL; */
+  /* char *name; */
+  char *linkbuf;
+  char *classdir;
+  GList /* *l, */  * subdirs = NULL, *tmp;
+  GString *currpath = NULL;
+  struct stat s, s2;
+  int linksize;
+  gboolean is_dir = FALSE;
+
+  /* name = (char *)get_global_option_str(configdata, "classdir", "."); */
+
+  if (name == NULL)
+    {
+      perror ("Cannot parse classdir option");
+      exit (-1);
+    }
+  /* debug_output(DEBUGLEVEL_HIGH,"Name = %s", name); */
+  classdir = g_strdup (name);
+
+  /* debug_output(DEBUGLEVEL_HIGH,"Classdir = %s", classdir); */
+
+  /* find GCD files */
+  if (classdir == NULL)
+    {
+      perror
+        ("No class definitions were found. Please ensure the arguments include 
a directory with valid '.gcd' files.");
+      exit (-1);
+    }
+  while (classdir[strlen (classdir) - 1] == '\\' ||
+         classdir[strlen (classdir) - 1] == '/')
+    {
+      classdir[strlen (classdir) - 1] = '\0';
+    }
+  currpath = g_string_new (classdir);
+  currpath = g_string_append (currpath, "/");
+  subdirs = g_list_append (subdirs, g_strdup (classdir));
+  /* debug_output(DEBUGLEVEL_HIGH,"Current path = %s", currpath->str); */
+
+  while (g_list_length (subdirs) != 0)
+    {
+      reading = opendir (currpath->str);
+      if (!reading)
+        {
+          perror ((const char *) currpath->str);
+          closedir (reading);
+          exit (-1);
+        }
+      else
+        {
+          /* Skip ./ and ../ directories */
+          readdir (reading);
+          readdir (reading);
+
+          while ((next = readdir (reading)) != NULL)
+            {
+              lstat (g_strdup_printf ("%s%s", currpath->str, next->d_name),
+                     &s);
+
+              if (S_ISLNK (s.st_mode))
+                {
+                  linkbuf = g_new (gchar, PATH_MAX + 2);
+                  linksize =
+                    readlink (g_strdup_printf
+                              ("%s/%s", currpath->str, next->d_name), linkbuf,
+                              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))
+                    {
+                      stat (linkbuf, &s2);
+                      if (S_ISDIR (s2.st_mode))
+                        {
 #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_free (linkbuf);
-                               }
-                               
-                               if (S_ISDIR (s.st_mode))
-                               {
-                                       is_dir = TRUE;
-                                       /* 
debug_output(DEBUGLEVEL_MEDIUM,"Appending %s%s/", currpath->str, next->d_name); 
*/
-                                       subdirs = g_list_append (subdirs, 
g_strdup_printf ("%s%s/", currpath->str, 
-                                       next->d_name));
-                               }
-                               if (is_extension(next->d_name, "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); */
-                                               fl = odl_filenamelist_add( fl , 
tmp );
-                                               g_free( tmp );
-                                       }
-                               }
-                       }
-                       closedir(reading);
-                       subdirs = g_list_remove (subdirs, (g_list_first 
(subdirs))->data);
-                       if (subdirs)
-                       {
-                               g_string_free (currpath, TRUE);
-                               currpath = g_string_new ((g_list_first 
(subdirs))->data);
-                       }
-               }
-       }
-       g_free(classdir);
-       tmp = subdirs;
-       while (tmp)
-       {
-               g_free (tmp->data);
-               tmp = g_list_next (tmp);
-       }
-       g_list_free (subdirs);
-       if (!fl)
-       {
-               error_message_out
-                       ("error",__FILE__,__PRETTY_FUNCTION__,__LINE__ ,
-                       "No class definitions were found. Please ensure the 
arguments include a directory with valid '.gcd' files.");
-               exit( -1);
-       }
+                          /* debug_output(DEBUGLEVEL_MEDIUM,"Appending %s/", 
linkbuf); */
+                          subdirs =
+                            g_list_append (subdirs,
+                                           g_strdup_printf ("%s/", linkbuf));
+                        }
+                    }
+                  g_free (linkbuf);
+                }
+
+              if (S_ISDIR (s.st_mode))
+                {
+                  is_dir = TRUE;
+                  /* debug_output(DEBUGLEVEL_MEDIUM,"Appending %s%s/", 
currpath->str, next->d_name); */
+                  subdirs =
+                    g_list_append (subdirs,
+                                   g_strdup_printf ("%s%s/", currpath->str,
+                                                    next->d_name));
+                }
+              if (is_extension (next->d_name, "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); */
+                      fl = odl_filenamelist_add (fl, tmp);
+                      g_free (tmp);
+                    }
+                }
+            }
+          closedir (reading);
+          subdirs = g_list_remove (subdirs, (g_list_first (subdirs))->data);
+          if (subdirs)
+            {
+              g_string_free (currpath, TRUE);
+              currpath = g_string_new ((g_list_first (subdirs))->data);
+            }
+        }
+    }
+  g_free (classdir);
+  tmp = subdirs;
+  while (tmp)
+    {
+      g_free (tmp->data);
+      tmp = g_list_next (tmp);
+    }
+  g_list_free (subdirs);
+  if (!fl)
+    {
+      error_message_out
+        ("error", __FILE__, __PRETTY_FUNCTION__, __LINE__,
+         "No class definitions were found. Please ensure the arguments include 
a directory with valid '.gcd' files.");
+      exit (-1);
+    }
 }
 
 



reply via email to

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