[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas lib/classdefs/classdata.c lib/classde...
From: |
Daniel E. Baumann |
Subject: |
gnue/geas lib/classdefs/classdata.c lib/classde... |
Date: |
Tue, 29 May 2001 12:46:40 -0700 |
CVSROOT: /cvs
Module name: gnue
Changes by: Daniel E. Baumann <address@hidden> 01/05/29 12:46:40
Modified files:
geas/lib/classdefs: classdata.c classdata.h
geas/src : geas-server.c geas-server.h
geas/tools : gcdverifier.c
Log message:
Moved is_extension from geas-server.c to classdata.h and renamed to
odl_is_extension. Removed directory processing code from
load_class_files and
merged with get_files_from_dir in gcdverifier.c, then moved this to
classdata.c and renamed to odl_get_files_from_dir. Updated all callers,
included proper headers in classdata.h and added prototypes for the new
odl
functions.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/classdata.c.diff?cvsroot=OldCVS&tr1=1.55&tr2=1.56&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/classdata.h.diff?cvsroot=OldCVS&tr1=1.30&tr2=1.31&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/geas-server.c.diff?cvsroot=OldCVS&tr1=1.89&tr2=1.90&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/geas-server.h.diff?cvsroot=OldCVS&tr1=1.42&tr2=1.43&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/tools/gcdverifier.c.diff?cvsroot=OldCVS&tr1=1.21&tr2=1.22&r1=text&r2=text
Patches:
Index: gnue/geas/lib/classdefs/classdata.c
diff -u gnue/geas/lib/classdefs/classdata.c:1.55
gnue/geas/lib/classdefs/classdata.c:1.56
--- gnue/geas/lib/classdefs/classdata.c:1.55 Sun May 27 18:24:06 2001
+++ gnue/geas/lib/classdefs/classdata.c Tue May 29 12:46:40 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.55 2001/05/28 01:24:06 ntiffin Exp $
+ $Id: classdata.c,v 1.56 2001/05/29 19:46:40 baumannd Exp $
*/
@@ -31,6 +31,13 @@
#include <time.h>
#include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <dirent.h>
+#include <errno.h>
+
/* #include "gcdparser.h" */
#include "classdata.h"
@@ -2719,4 +2726,173 @@
odl_create_empty_tree ()
{
return (alloc_odl_tree ());
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
+odl_filenamelist *
+odl_get_files_from_dir (odl_filenamelist * filelist, const char *name)
+{
+ struct dirent *next;
+ DIR *reading;
+ odl_filenamelist *fl = NULL;
+ char *linkbuf, *classdir;
+ GList *subdirs = NULL, *tmp;
+ GString *currpath = NULL;
+ struct stat s, s2;
+ int linksize, err;
+ gboolean is_dir = FALSE;
+
+ g_assert( name );
+ if (name == NULL)
+ {
+ perror ("Empty name.");
+ exit (-1);
+ }
+ classdir = g_strdup (name);
+
+ /* find GCD files */
+ if (classdir == NULL)
+ {
+ perror
+ ("No class definitions were found. Please ensure the configuration
file\ndefines a directory with valid '.gcd' files.");
+ exit (-1);
+ }
+ /* whack out ending slashes to create path */
+ while (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, G_DIR_SEPARATOR_S);
+ subdirs = g_list_append (subdirs, g_strdup (classdir));
+
+ while (g_list_length (subdirs) != 0)
+ {
+ reading = opendir (currpath->str);
+ if (!reading)
+ {
+ perror ((const char *) currpath->str);
+ closedir (reading);
+ exit (-1);
+ }
+ else
+ {
+ while ((next = readdir (reading)) != NULL)
+ {
+ /* Skip ./ and ../ directories */
+ if (strcmp (next->d_name, ".") == 0)
+ {
+ next = readdir (reading);
+ continue;
+ }
+ if (strcmp (next->d_name, "..") == 0)
+ {
+ next = readdir (reading);
+ continue;
+ }
+ err = lstat (g_strdup_printf ("%s%s", currpath->str,
next->d_name), &s);
+ if (err == -1)
+ {
+ perror (strerror (errno));
+ exit (-1);
+ }
+ if (S_ISLNK (s.st_mode))
+ {
+ linkbuf = (char *)g_new (gchar *, PATH_MAX + 2);
+ linksize = readlink (g_strdup_printf ("%s/%s",
currpath->str, next->d_name),
+ linkbuf, PATH_MAX + 1);
+ if (linksize == -1)
+ {
+ perror (strerror (errno));
+ exit (-1);
+ }
+ linkbuf[linksize] = '\0';
+ if (g_strcasecmp (classdir, linkbuf)
+ && g_strncasecmp ("./", linkbuf, 2)
+ && g_strncasecmp ("../", linkbuf, 3)
+ && g_strcasecmp (currpath->str, linkbuf))
+ {
+ err = stat (linkbuf, &s2);
+ if (err == -1)
+ {
+ perror (strerror (errno));
+ exit (-1);
+ }
+ if (S_ISDIR (s2.st_mode))
+ {
+ subdirs =
+ g_list_append (subdirs,
+ g_strdup_printf ("%s/", linkbuf));
+ }
+ }
+ g_free (linkbuf);
+ }
+ if (S_ISDIR (s.st_mode))
+ {
+ is_dir = TRUE;
+ subdirs =
+ g_list_append (subdirs,
+ g_strdup_printf ("%s%s/", currpath->str,
+ next->d_name));
+ }
+ if (odl_is_extension (next->d_name, "gcd"))
+ {
+ char *tmp =
+ g_strdup_printf ("%s%s", currpath->str, next->d_name);
+ if (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);
+
+ return fl;
+}
+
+/** \brief Test if a file ends with a particular extension
+ */
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
+gboolean
+odl_is_extension(char *filename, 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)
+ return (FALSE);
+ if (g_strcasecmp (&filename[flen - elen], ext) == 0 &&
+ filename[flen - elen - 1] == '.')
+ return (TRUE);
+
+ return (FALSE);
}
Index: gnue/geas/lib/classdefs/classdata.h
diff -u gnue/geas/lib/classdefs/classdata.h:1.30
gnue/geas/lib/classdefs/classdata.h:1.31
--- gnue/geas/lib/classdefs/classdata.h:1.30 Sun May 27 18:24:07 2001
+++ gnue/geas/lib/classdefs/classdata.h Tue May 29 12:46:40 2001
@@ -310,6 +310,12 @@
odl_base *odl_find_in_container(odl_base * c, const char *name);
+odl_filenamelist *
+odl_get_files_from_dir (odl_filenamelist * filelist, const char *name);
+
+gboolean
+odl_is_extension(char *filename, char *ext);
+
#include "classdata_database.h"
#endif
Index: gnue/geas/src/geas-server.c
diff -u gnue/geas/src/geas-server.c:1.89 gnue/geas/src/geas-server.c:1.90
--- gnue/geas/src/geas-server.c:1.89 Tue May 29 11:25:50 2001
+++ gnue/geas/src/geas-server.c Tue May 29 12:46:40 2001
@@ -1261,41 +1261,13 @@
}
#endif
-/** \brief Test if a file ends with a particular extension
- */
-gboolean
-is_extension (char *filename, 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)
- return (FALSE);
- if (g_strcasecmp (&filename[flen - elen], ext) == 0 &&
- filename[flen - elen - 1] == '.')
- return (TRUE);
-
- return (FALSE);
-}
-
/** \brief Load the GCD files
*/
void
load_class_files (void)
{
- struct dirent *next;
- DIR *reading;
+ char *name;
odl_filenamelist *fl = NULL;
- char *name, *linkbuf, *classdir;
- GList *l, *subdirs = NULL, *tmp;
- GString *currpath = NULL;
- struct stat s, s2;
- int linksize, err;
- gboolean is_dir = FALSE;
name = (char *) get_global_option_str (configdata, "classdir", ".");
if (name == NULL)
@@ -1303,134 +1275,8 @@
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)
- {
- errormsg
- ("No class definitions were found. Please ensure the configuration
file\ndefines 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)
- {
- err =
- lstat (g_strdup_printf ("%s%s", currpath->str, next->d_name),
- &s);
- if (err == -1)
- {
- perror (errno);
- exit (-1);
- }
- 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);
- if (linksize == -1)
- {
- perror (errno);
- exit (-1);
- }
- linkbuf[linksize] = '\0';
- 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_strncasecmp ("./", linkbuf, 2)
- && g_strncasecmp ("../", linkbuf, 3)
- && g_strcasecmp (currpath->str, linkbuf))
- {
- err = stat (linkbuf, &s2);
- if (err == -1)
- {
- perror (strerror (errno));
- exit (-1);
- }
- if (S_ISDIR (s2.st_mode))
- {
- 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))
- {
- debug_output (DEBUGLEVEL_HIGH, "%s%s/ is a Directory.",
- currpath->str, next->d_name);
- 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);
+ fl = odl_get_files_from_dir (fl, name);
if (!fl)
{
Index: gnue/geas/src/geas-server.h
diff -u gnue/geas/src/geas-server.h:1.42 gnue/geas/src/geas-server.h:1.43
--- gnue/geas/src/geas-server.h:1.42 Fri May 25 13:24:07 2001
+++ gnue/geas/src/geas-server.h Tue May 29 12:46:40 2001
@@ -34,9 +34,6 @@
/** \brief username reserved for the server */
#define SERVER_PRIVATE_USERNAME "server_private_user"
-/* utility function prototypes */
-gboolean is_extension(char *filename, char *ext);
-
/* error messages */
void do_fatal_error(char *file, int line,char *func, char *fmt, ...);
Index: gnue/geas/tools/gcdverifier.c
diff -u gnue/geas/tools/gcdverifier.c:1.21 gnue/geas/tools/gcdverifier.c:1.22
--- gnue/geas/tools/gcdverifier.c:1.21 Sun May 27 15:56:07 2001
+++ gnue/geas/tools/gcdverifier.c Tue May 29 12:46:40 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.21 2001/05/27 22:56:07 ntiffin Exp $
+ $Id: gcdverifier.c,v 1.22 2001/05/29 19:46:40 baumannd Exp $
*/
#include <glib.h>
@@ -31,17 +31,11 @@
#include <string.h>
#include <stdlib.h>
-#include <dirent.h>
#include "classdata.h"
/* #define errormsg(fmt,args...)
error_message_out("error",__FILE__,__PRETTY_FUNCTION__,__LINE__ , fmt , ##args
) */
-odl_filenamelist *
-get_files_from_dir (odl_filenamelist * filelist, const char *name);
-
-/* odl_filenamelist *fl = NULL; */
-
/** \brief Message output function
*/
/* ------------------------------------------------------------------------- *\
@@ -71,41 +65,6 @@
fflush (NULL);
}
-
-/** \brief Test if a file ends with a particular extension
- */
-/* ------------------------------------------------------------------------- *\
- *
-\* ------------------------------------------------------------------------- */
-gboolean
-is_extension (const char *filename, const char *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) );
- printf( "compare(%s,%s)\n" , &filename[flen - elen], ext );
- */
- if ((elen + 1) > flen)
- {
- return (FALSE);
- }
- if (g_strcasecmp (&filename[flen - elen], ext) == 0
- && filename[flen - elen - 1] == '.')
- {
- return (TRUE);
- }
- return (FALSE);
-}
-
-
/* ------------------------------------------------------------------------- *\
*
\* ------------------------------------------------------------------------- */
@@ -143,7 +102,7 @@
else if (strcmp (argv[i], "--version") == 0)
{
GString *revision;
- revision = g_string_new ("$Revision: 1.21 $");
+ revision = g_string_new ("$Revision: 1.22 $");
if (revision->len > 14)
{
revision = g_string_erase (revision, 0, 11); /* remove the
'$Revsion:' part */
@@ -159,7 +118,7 @@
("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. */
+ else if (odl_is_extension (argv[i], "gcd")) /* is a file with
an extension of '.gcd. */
{
number_entries++;
fl = odl_filenamelist_add (fl, argv[i]);
@@ -169,7 +128,7 @@
/* must be a directory */
/* means directories with .gcd at the end will not work */
number_entries++;
- fl = get_files_from_dir (fl, argv[i]);
+ fl = odl_get_files_from_dir (fl, argv[i]);
}
}
if (number_entries > 0)
@@ -198,159 +157,3 @@
}
exit (EXIT_SUCCESS);
}
-
-/** \brief Load the GCD files
- */
-/* ------------------------------------------------------------------------- *\
- *
-\* ------------------------------------------------------------------------- */
-odl_filenamelist *
-get_files_from_dir (odl_filenamelist * filelist, const char *name)
-{
- struct dirent *next;
- DIR *reading;
- char *linkbuf;
- char *classdir;
- GList * subdirs = NULL;
- GList *tmp;
- GString *currpath = NULL;
- struct stat s;
- struct stat s2;
- int linksize;
- gboolean is_dir = FALSE;
-
- g_assert( name );
- if (name == NULL)
- {
- perror ("Empty name.");
- exit (-1);
- }
- classdir = g_strdup (name);
-
- /* find GCD files */
- g_assert( classdir );
- if (classdir == NULL)
- {
- perror
- ("Not able to copy name.\n");
- exit (-1);
- }
- /* whack out ending slashes to create path */
- while (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, G_DIR_SEPARATOR_S);
- subdirs = g_list_append (subdirs, g_strdup (classdir));
- 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);
- closedir (reading);
- exit (-1);
- }
- else
- {
- next = readdir (reading);
- while (next != NULL)
- {
- /* 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
- ("%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))
- {
- ; /* do nothing */
- }
- else
- {
- 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))
- {
- /* file is a directory */
- is_dir = TRUE;
- /* 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));
- }
- if ((S_ISREG (s.st_mode)) && (is_extension (next->d_name,
"gcd")))
- {
- /* 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); */
- filelist = odl_filenamelist_add (filelist, tmp);
- g_free (tmp);
- }
- }
- next = readdir (reading);
- }
- 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 (!filelist)
- {
- 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);
- }
- return filelist;
-}
-
-
-/* http://www.gnu.org/manual/glibc-2.0.6/html_chapter/libc_toc.html#TOC157 */