bug-hurd
[Top][All Lists]
Advanced

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

PATCH 1/2 - fix all compiler warnings. (was XMLFS for GSoC)


From: Michael Walker
Subject: PATCH 1/2 - fix all compiler warnings. (was XMLFS for GSoC)
Date: Mon, 4 Apr 2011 13:35:21 +0100

The below patch fixes all compiler warnings. It's quite long as I use
a lot of warning flags (habit from when I was working on my own kernel
project):

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e20fc66
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.o
+xmlfs
diff --git a/Makefile b/Makefile
index 3c66000..d646475 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,7 @@
 CC = gcc
-CFLAGS = `pkg-config libxml-2.0 --cflags` -Wall -ggdb3 -O0 -std=c99
-D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
-COMPILE=$(CC) $(CFLAGS)
+CFLAGS = `pkg-config libxml-2.0 --cflags` -ggdb3 -O0 -std=c99
-D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
+WARN = -Wall -Wextra -Wshadow -Wpointer-arith -Wcast-align
-Wwrite-strings -Wmissing-declarations -Wredundant-decls
-Wnested-externs -Winline -Wno-long-long -Winit-self
-Wmissing-prototypes -Wstrict-prototypes -Wconversion -pedantic
+COMPILE=$(CC) $(CFLAGS) $(WARN)
 LDFLAGS = `pkg-config libxml-2.0 --libs` -lnetfs -liohelp -lfshelp -lports
 OBJS = fs.o xmlfs.o xml.o netfs.o fsutils.o
 BINARY = xmlfs
diff --git a/fs.c b/fs.c
index 01cceca..d59385b 100644
--- a/fs.c
+++ b/fs.c
@@ -25,7 +25,7 @@
 FILE *debug;

 error_t
-xmlfs_create (file_t fd, struct xmlfs *xmlfs)
+xmlfs_create (file_t fd, struct xmlfs *thexmlfs)
 {
   error_t err;

@@ -44,28 +44,28 @@ xmlfs_create (file_t fd, struct xmlfs *xmlfs)

   netfs_root_node->nn_stat.st_nlink = 2;

-  xmlfs->root = netfs_root_node;
+  thexmlfs->root = netfs_root_node;

   DEBUG ("INFO: building XML tree...\n");

   /* Build an XML tree from the file */
-  xmlfs->doc = xmlReadFd (fd, NULL, NULL, XML_PARSE_NOCDATA);
+  thexmlfs->doc = xmlReadFd ((int) fd, NULL, NULL, XML_PARSE_NOCDATA);

-  if (xmlfs->doc == NULL)
+  if (thexmlfs->doc == NULL)
     error (-1, 0, "E: (%s, %d): couldn't parse",
           __FILE__, __LINE__);

-  xmlfs->root_node = xmlDocGetRootElement (xmlfs->doc);
+  thexmlfs->root_node = xmlDocGetRootElement (thexmlfs->doc);

-  if (xmlfs->root_node == NULL)
+  if (thexmlfs->root_node == NULL)
     {
-      xmlFreeDoc (xmlfs->doc);
+      xmlFreeDoc (thexmlfs->doc);
       error (-1, 0, "E: (%s, %d): couldn't get root element",
             __FILE__, __LINE__);
     }

   /* Make our pathname XPath compliant. */
-  asprintf(&netfs_root_node->nn->pathname, "/%s", xmlfs->root_node->name);
+  asprintf(&netfs_root_node->nn->pathname, "/%s", thexmlfs->root_node->name);

   DEBUG ("NOTICE: %s returns with 0.\n", __PRETTY_FUNCTION__);

diff --git a/fsutils.c b/fsutils.c
index 7a90900..2f1e549 100644
--- a/fsutils.c
+++ b/fsutils.c
@@ -115,8 +115,8 @@ _make_node (struct node **n, struct node *dir,
char* name, mode_t m)

   /* General stat */
   st.st_fstype  = FSTYPE_MISC;
-  st.st_fsid    = pid;
-  st.st_dev     = st.st_rdev = pid;    /* unique device id */
+  st.st_fsid    = (__fsid_t) pid;
+  st.st_dev     = st.st_rdev = (__dev_t) pid;  /* unique device id */
   st.st_uid     = st.st_author = uid;
   st.st_gid     = gid;
   st.st_mode    = m;
@@ -270,7 +270,7 @@ char*
 get_path_from_root (struct node *root, struct node *node)
 {
 #define REVERSE_COPY(dst, src) \
-       { int i; \
+       { unsigned int i; \
          for (i=0; i < strlen ((src)); i++) \
            (dst)[i] = src[strlen ((src)) - 1 - i]; \
          (dst)[strlen ((src))] = '\0'; \
diff --git a/fsutils.h b/fsutils.h
index 3573e36..a823dc8 100644
--- a/fsutils.h
+++ b/fsutils.h
@@ -33,7 +33,7 @@

 /* Initialization.
  */
-extern int fs_init ();
+extern int fs_init (void);

 /* Creates a new node in directory DIR, with name NAME and mode M. If not NULL,
  * N points to the newly created node.
diff --git a/netfs.c b/netfs.c
index e23fe08..b95c908 100644
--- a/netfs.c
+++ b/netfs.c
@@ -21,6 +21,7 @@

 #include "xmlfs.h"
 #include "xml.h"
+#include "netfs.h"

 #include <mach.h>
 #include <libxml/xpath.h>
@@ -42,6 +43,9 @@ FILE *debug;
 error_t
 netfs_validate_stat (struct node *np, struct iouser *cred)
 {
+  (void) np;
+  (void) cred;
+
   return 0; /* everything is good for us ;P */
 }

@@ -51,6 +55,11 @@ error_t
 netfs_attempt_chown (struct iouser *cred, struct node *np,
                              uid_t uid, uid_t gid)
 {
+  (void) cred;
+  (void) np;
+  (void) uid;
+  (void) gid;
+
   return EROFS;
 }

@@ -60,6 +69,10 @@ error_t
 netfs_attempt_chauthor (struct iouser *cred, struct node *np,
                                 uid_t author)
 {
+  (void) cred;
+  (void) np;
+  (void) author;
+
   return EROFS;
 }

@@ -72,6 +85,10 @@ error_t
 netfs_attempt_chmod (struct iouser *cred, struct node *node,
                     mode_t mode)
 {
+  (void) cred;
+  (void) node;
+  (void) mode;
+
   return EROFS;
 }
 /* The user must define this function.  Attempt to turn locked node NP
@@ -80,6 +97,10 @@ error_t
 netfs_attempt_mksymlink (struct iouser *cred, struct node *np,
                         char *name)
 {
+  (void) cred;
+  (void) np;
+  (void) name;
+
   return EROFS;
 }
 /* The user must define this function.  Attempt to turn NODE (user
@@ -88,6 +109,11 @@ netfs_attempt_mksymlink (struct iouser *cred,
struct node *np,
 error_t netfs_attempt_mkdev (struct iouser *cred, struct node *np,
                              mode_t type, dev_t indexes)
 {
+  (void) cred;
+  (void) np;
+  (void) type;
+  (void) indexes;
+
   return EROFS;
 }
 /* The user must define this function.  This should attempt a chflags
@@ -96,6 +122,10 @@ error_t netfs_attempt_mkdev (struct iouser *cred,
struct node *np,
 error_t netfs_attempt_chflags (struct iouser *cred, struct node *np,
                                int flags)
 {
+  (void) cred;
+  (void) np;
+  (void) flags;
+
   return EROFS;
 }
 /* This should attempt a utimes call for the user specified by CRED on
@@ -104,6 +134,11 @@ error_t netfs_attempt_chflags (struct iouser
*cred, struct node *np,
 error_t netfs_attempt_utimes (struct iouser *cred, struct node *np,
                               struct timespec *atime, struct timespec *mtime)
 {
+  (void) cred;
+  (void) np;
+  (void) atime;
+  (void) mtime;
+
   return EROFS;
 }

@@ -112,6 +147,10 @@ error_t netfs_attempt_utimes (struct iouser
*cred, struct node *np,
 error_t netfs_attempt_set_size (struct iouser *cred, struct node *np,
                                 loff_t size)
 {
+  (void) cred;
+  (void) np;
+  (void) size;
+
   return EROFS;
 }

@@ -121,6 +160,10 @@ error_t netfs_attempt_set_size (struct iouser
*cred, struct node *np,
 error_t netfs_attempt_statfs (struct iouser *cred, struct node *np,
                              fsys_statfsbuf_t *st)
 {
+  (void) cred;
+  (void) np;
+  (void) st;
+
   return EOPNOTSUPP;
 }
 /* This should sync the locked file NP completely to disk, for the user CRED.
@@ -129,6 +172,10 @@ error_t
 netfs_attempt_sync (struct iouser *cred, struct node *np,
                             int wait)
 {
+  (void) cred;
+  (void) np;
+  (void) wait;
+
   return 0;
 }
 /* The user must define this function.  This should sync the entire
@@ -137,6 +184,9 @@ netfs_attempt_sync (struct iouser *cred, struct node *np,
 error_t
 netfs_attempt_syncfs (struct iouser *cred, int wait)
 {
+  (void) cred;
+  (void) wait;
+
   return 0;
 }

@@ -151,9 +201,11 @@ netfs_attempt_lookup (struct iouser *user, struct
node *dir,
 {
   struct node *nd;
   error_t err;
-
+
+  (void) user;
+
   DEBUG ("NOTICE: netfs_attempt_lookup (name: %s, dir: %p)\n",
-        name, dir);
+        name, (void*) dir);

   if (!dir || dir->nn->type == CONTENT)
     {
@@ -218,6 +270,10 @@ error_t
 netfs_attempt_unlink (struct iouser *user, struct node *dir,
                               char *name)
 {
+  (void) user;
+  (void) dir;
+  (void) name;
+
   return EROFS;
 }

@@ -228,6 +284,13 @@ netfs_attempt_rename (struct iouser *user, struct
node *fromdir,
                               char *fromname, struct node *todir,
                               char *toname, int excl)
 {
+  (void) user;
+  (void) fromdir;
+  (void) fromname;
+  (void) todir;
+  (void) toname;
+  (void) excl;
+
   return EROFS;
 }
 /* Attempt to create a new directory named NAME in DIR (which is locked)
@@ -235,6 +298,11 @@ netfs_attempt_rename (struct iouser *user, struct
node *fromdir,
 error_t netfs_attempt_mkdir (struct iouser *user, struct node *dir,
                              char *name, mode_t mode)
 {
+  (void) user;
+  (void) dir;
+  (void) name;
+  (void) mode;
+
   return EROFS;
 }
 /* Attempt to remove directory named NAME in DIR (which is locked) for
@@ -242,6 +310,10 @@ error_t netfs_attempt_mkdir (struct iouser *user,
struct node *dir,
 error_t netfs_attempt_rmdir (struct iouser *user,
                              struct node *dir, char *name)
 {
+  (void) user;
+  (void) dir;
+  (void) name;
+
   return EROFS;
 }

@@ -251,6 +323,12 @@ error_t netfs_attempt_rmdir (struct iouser *user,
 error_t netfs_attempt_link (struct iouser *user, struct node *dir,
                             struct node *file, char *name, int excl)
 {
+  (void) user;
+  (void) dir;
+  (void) file;
+  (void) name;
+  (void) excl;
+
   return EROFS;
 }

@@ -261,6 +339,11 @@ error_t netfs_attempt_mkfile (struct iouser
*user, struct node *dir,
                               mode_t mode, struct node **np)

 {
+  (void) user;
+  (void) dir;
+  (void) mode;
+  (void) np;
+
   return EROFS;
 }

@@ -273,6 +356,12 @@ error_t
 netfs_attempt_create_file (struct iouser *user, struct node *dir,
                           char *name, mode_t mode, struct node **np)
 {
+  (void) user;
+  (void) dir;
+  (void) name;
+  (void) mode;
+  (void) np;
+
   return EROFS;
 }

@@ -281,6 +370,10 @@ netfs_attempt_create_file (struct iouser *user,
struct node *dir,
 error_t netfs_attempt_readlink (struct iouser *user, struct node *np,
                                 char *buf)
 {
+  (void) user;
+  (void) np;
+  (void) buf;
+
   return EOPNOTSUPP;
 }

@@ -292,6 +385,8 @@ netfs_check_open_permissions (struct iouser *user,
struct node *node,
                              int flags, int newnode)
 {
   error_t err = 0;
+
+  (void) newnode;

   if (!err && (flags & O_READ))
     err = fshelp_access (&node->nn_stat, S_IREAD, user);
@@ -311,9 +406,11 @@ error_t netfs_attempt_read (struct iouser *cred,
struct node *node,
 {
   xmlNodePtr cur = NULL;
   char *content = NULL;
-  size_t size = -1;
+  size_t size = (size_t) -1;
   error_t err;

+  (void) cred;
+
   DEBUG ("NOTICE: %s (node: %s, offset: %lld, len: %d)\n",
         __PRETTY_FUNCTION__, node->nn->name, offset, *len);

@@ -336,7 +433,7 @@ error_t netfs_attempt_read (struct iouser *cred,
struct node *node,
   if (offset < size)
     {
       DEBUG ("INFO: copying the node\n");
-      int gsize = size;
+      int gsize = (int) size;

       /* We got more than requested. Copy only the first *len bytes. */
       if (size > *len)
@@ -346,7 +443,7 @@ error_t netfs_attempt_read (struct iouser *cred,
struct node *node,

       /* Adding newline for user's convenience. */
       if (offset + size == gsize)
-         memcpy (data + size++, "\n", 1);
+         memcpy ((void*) ((size_t) data + size++), "\n", 1);

       *len = size;
     }
@@ -372,6 +469,12 @@ error_t netfs_attempt_read (struct iouser *cred,
struct node *node,
 error_t netfs_attempt_write (struct iouser *cred, struct node *np,
                             loff_t offset, size_t *len, void *data)
 {
+  (void) cred;
+  (void) np;
+  (void) offset;
+  (void) len;
+  (void) data;
+
   return EROFS;
 }

@@ -380,6 +483,10 @@ error_t netfs_attempt_write (struct iouser *cred,
struct node *np,
 error_t netfs_report_access (struct iouser *cred, struct node *np,
                             int *types)
 {
+  (void) cred;
+  (void) np;
+  (void) types;
+
   return EROFS;
 }

@@ -387,12 +494,19 @@ error_t netfs_report_access (struct iouser
*cred, struct node *np,
 struct iouser *netfs_make_user (uid_t *uids, int nuids,
                                       uid_t *gids, int ngids)
 {
+  (void) uids;
+  (void) nuids;
+  (void) gids;
+  (void) ngids;
+
   return NULL;
 }

 /* Node NP has no more references; free all its associated storage. */
 void netfs_node_norefs (struct node *np)
 {
+  (void) np;
+
   return;
 }

@@ -405,7 +519,62 @@ void netfs_node_norefs (struct node *np)
    padded to a four-byte alignment.  */
 #define DIRENT_LEN(name_len)                                                 \
   ((DIRENT_NAME_OFFS + (name_len) + 1 + (DIRENT_ALIGN - 1))                  \
-   & ~(DIRENT_ALIGN - 1))
+   & (unsigned int) ~(DIRENT_ALIGN - 1))
+
+/* Add the length of a directory entry for NAME to SIZE and return true,
+   unless it would overflow MAX_DATA_LEN or NUM_ENTRIES, in which case
+   return false.  */
+int
+bump_size (const char *name, int num_entries, int *count,
+           size_t *size, vm_size_t max_data_len)
+{
+  if (num_entries == -1 || *count < num_entries)
+    {
+      size_t new_size = *size + DIRENT_LEN (strlen (name));
+      if (max_data_len > 0 && new_size > max_data_len)
+        return 0;
+
+      *size = new_size;
+      *count = *count + 1;
+      return 1;
+    }
+
+  return 0;
+}
+
+int
+add_dir_entry (const char *name, ino_t thefileno, int type, struct node *dir,
+               int num_entries, int *count, size_t size, char **p)
+{
+  if (num_entries == -1 || *count < num_entries)
+    {
+      struct dirent hdr;
+      size_t name_len = strlen (name);
+      size_t sz = DIRENT_LEN (name_len);
+
+      DEBUG ("NOTICE: %s contains %s (fileno: %llu)\n",
dir->nn->name, name, thefileno);
+       
+      if (sz > size)
+       return 0;
+      else
+       size -= sz;
+       
+      hdr.d_fileno = thefileno;
+      hdr.d_reclen = (short unsigned int) sz;
+      hdr.d_type = (unsigned char) type;
+      hdr.d_namlen = (unsigned char) name_len;
+       
+      memcpy (*p, &hdr, DIRENT_NAME_OFFS);
+      strcpy (*p + DIRENT_NAME_OFFS, name);
+
+      *p += sz;
+
+      *count += 1;
+
+      return 1;
+    }
+  return 0;
+}

 /* Fill the  array *DATA of  size MAX_DATA_LEN with up  to NUM_ENTRIES
    dirents from  DIR (which is  locked) starting with entry  ENTRY for
@@ -425,26 +594,10 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
   size_t size = 0;
   error_t err;

-  /* Add the length of a directory entry for NAME to SIZE and return true,
-     unless it would overflow MAX_DATA_LEN or NUM_ENTRIES, in which case
-     return false.  */
-  int bump_size (const char *name)
-    {
-      if (num_entries == -1 || count < num_entries)
-       {
-         size_t new_size = size + DIRENT_LEN (strlen (name));
-         if (max_data_len > 0 && new_size > max_data_len)
-           return 0;
-         size = new_size;
-         count++;
-         return 1;
-       }
-      else
-       return 0;
-    }
+  (void) cred;

   DEBUG ("NOTICE: %s (dir: [addr: %p, name: %s, path: %s], offset:
%d, count: %d)\n",
-        __PRETTY_FUNCTION__, dir, dir->nn->name, dir->nn->pathname,
+        __PRETTY_FUNCTION__, (void*) dir, dir->nn->name, dir->nn->pathname,
         first_entry, num_entries);

   if (!dir)
@@ -473,9 +626,9 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
   count = 0;

   if (first_entry == 0)
-    bump_size (".");
+    bump_size (".", num_entries, &count, &size, max_data_len);
   if (first_entry <= 1)
-    bump_size ("..");
+    bump_size ("..", num_entries, &count, &size, max_data_len);

   if (!nd || num_entries == 0)
     {
@@ -486,8 +639,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
     }

   for (struct node *n = nd; n; n = n->next)
-    if (!bump_size (n->nn->name))
-      ;
+    if (!bump_size (n->nn->name, num_entries, &count, &size, max_data_len)) {;}

   *data = mmap (0, size, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);

@@ -496,39 +648,6 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
     {
       char *p = *data;

-      int add_dir_entry (const char *name, ino_t fileno, int type)
-       {
-         if (num_entries == -1 || count < num_entries)
-           {
-             struct dirent hdr;
-             size_t name_len = strlen (name);
-             size_t sz = DIRENT_LEN (name_len);
-
-             DEBUG ("NOTICE: %s contains %s (fileno: %llu)\n",
dir->nn->name, name, fileno);
-       
-             if (sz > size)
-               return 0;
-             else
-               size -= sz;
-       
-             hdr.d_fileno = fileno;
-             hdr.d_reclen = sz;
-             hdr.d_type = type;
-             hdr.d_namlen = name_len;
-       
-             memcpy (p, &hdr, DIRENT_NAME_OFFS);
-             strcpy (p + DIRENT_NAME_OFFS, name);
-
-             p += sz;
-
-             count++;
-
-             return 1;
-           }
-         else
-           return 0;
-       }
-
       *data_len = size;
       *data_entries = count;

@@ -536,14 +655,15 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,

       /* Add `.' and `..' entries.  */
       if (first_entry == 0)
-       add_dir_entry (".", dir->nn_stat.st_ino, DT_DIR);
+       add_dir_entry (".", dir->nn_stat.st_ino, DT_DIR, dir, num_entries,
&count, size, &p);
       if (first_entry <= 1)
-       add_dir_entry ("..", 2, DT_DIR);
+       add_dir_entry ("..", 2, DT_DIR, dir, num_entries, &count, size, &p);

       /* Fill in the real directory entries.  */
       for (struct node *n = nd; n; n = n->next)
        if (!add_dir_entry (n->nn->name, n->nn_stat.st_ino,
-                           n->nn->type == CONTENT ? DT_REG : DT_DIR))
+                           n->nn->type == CONTENT ? DT_REG : DT_DIR,
+                            dir, num_entries, &count, size, &p))
          break;
     }

diff --git a/netfs.h b/netfs.h
new file mode 100644
index 0000000..bca16c5
--- /dev/null
+++ b/netfs.h
@@ -0,0 +1,38 @@
+/* xmlfs -- a translator for accessing XML documents
+
+   Copyright (C) 2002, 2005 HurdFR.
+   Written by  Marc de Saint Sauveur <address@hidden>
+           and Manuel Menal          <address@hidden>
+
+   xmlfs 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; either version 2, or (at
+   your option) any later version.
+
+   xmlfs is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+*/
+
+#ifndef __NETFS_H__
+#define __NETFS_H__
+
+#define _GNU_SOURCE 1
+
+/* Add the length of a directory entry for NAME to SIZE and return true,
+   unless it would overflow MAX_DATA_LEN or NUM_ENTRIES, in which case
+   return false.  */
+int bump_size (const char *name, int num_entries,
+               int *count, size_t *size, vm_size_t max_data_len);
+
+/* Add a directory named NAME to DIR */
+int add_dir_entry (const char *name, ino_t thefileno, int type,
+                   struct node *dir, int num_entries, int *count,
+                   size_t size, char **p);
+
+#endif
diff --git a/xml.c b/xml.c
index 8ba9a3f..6d6dbc2 100644
--- a/xml.c
+++ b/xml.c
@@ -20,6 +20,7 @@
 */

 #include "xmlfs.h"
+#include "xml.h"
 #include "fsutils.h"

 #include <string.h>
@@ -146,14 +147,15 @@ xml_find_children_sorted (const char *xpath)
   xmlNodeSetPtr set = xml_find_children (xpath);

   /* Sort the nodes so we can make their names unique easily. */
-  qsort (set->nodeTab, xmlXPathNodeSetGetLength (set),
+  qsort (set->nodeTab, (size_t) xmlXPathNodeSetGetLength (set),
         sizeof (xmlNodePtr), xml_node_compare);

   return set;
 }

 static void
-make_unique_name (xmlNodePtr node, struct node *dir, int count, int
index, char **name, char **pathname)
+make_unique_name (xmlNodePtr node, struct node *dir, int count,
+                  int theindex, char **name, char **pathname)
 {
   /* Create a unique name AND pathname. */
   char *prefixed_name = NULL, *node_name = NULL;
@@ -172,10 +174,10 @@ make_unique_name (xmlNodePtr node, struct node
*dir, int count, int index, char
       break;
     }

-  if (index == -1)
+  if (theindex == -1)
     *name = strdup (prefixed_name);
   else
-    asprintf (name, "%s%d", prefixed_name, index);
+    asprintf (name, "%s%d", prefixed_name, theindex);

   if (count == -1)
     sindex = strdup ("");
@@ -204,7 +206,7 @@ fill_dir_with_nodes (struct node *dir)
   int count = -1;
   /* Keep track of the index to add to the node name. Differs from count
      because it does not consider blank nodes and such. */
-  int index = -1;
+  int theindex = -1;

   for (int i = 0; i < xmlXPathNodeSetGetLength (set); i++)
     {
@@ -220,10 +222,10 @@ fill_dir_with_nodes (struct node *dir)

       if (count != -1)
        count++;
-      if (index != -1)
-       index++;
+      if (theindex != -1)
+       theindex++;

-      cur_index = index;
+      cur_index = theindex;
       cur_count = count;

       /* Compute index so that name is unique in DIR. */
@@ -233,12 +235,12 @@ fill_dir_with_nodes (struct node *dir)
          if (!diff && count == -1)
            {
              DEBUG ("INFO: setting count = 0 (starting a serie)\n");
-             index = count = cur_index = cur_count = 0;
+             theindex = count = cur_index = cur_count = 0;
            }
          else if (diff && count != -1)
            {
              DEBUG ("INFO: setting count = -1 (stopping a serie)\n");
-             count = index = -1;
+             count = theindex = -1;
            }
        }

@@ -246,7 +248,7 @@ fill_dir_with_nodes (struct node *dir)
       if (xmlIsBlankNode (cur))
        {
          /* Finally we're not going to add it... */
-         if (index != 0) index--;
+         if (theindex != 0) theindex--;
          DEBUG ("INFO: entry is blank\n");
          continue;
        }
@@ -330,7 +332,7 @@ fill_dirnode (struct node *dir)
   assert (dir);

   DEBUG ("NOTICE: %s (DIR (%p, name: %s, pathname: %s)\n",
__PRETTY_FUNCTION__,
-        dir, dir->nn->name, dir->nn->pathname);
+        (void*)dir, dir->nn->name, dir->nn->pathname);

   err = fill_dir_with_nodes (dir);
   if (err)
diff --git a/xml.h b/xml.h
index b87e203..8d51c80 100644
--- a/xml.h
+++ b/xml.h
@@ -25,13 +25,34 @@
 #define _GNU_SOURCE 1

 #include <hurd/netfs.h>
+#include <libxml/xpath.h>

 /* Find the node with pathname PATH. */
 xmlNodePtr xml_find_node (const char *path);
+
 /* Dump NODE to BUF and write the content size to SIZE. */
 error_t xml_dump_node (xmlNodePtr node, char **buf, size_t *size);

 /* Create all the children node in DIR. */
 error_t fill_dirnode (struct node *dir);

+/* Compare two nodes returning 0 if equal, < 0 if a < b, > 0 if a > b */
+int xml_node_compare (const void *a, const void *b);
+
+/* Return all nodes under PATH in the original document */
+xmlNodeSetPtr xml_find_nodeset (const char *path);
+
+/* Return all nodes which are children of PATH */
+xmlNodeSetPtr xml_find_children (const char *cpath);
+
+/* Return all nodes which are children of PATH, sorted (stable) to give
+   unique named. */
+xmlNodeSetPtr xml_find_children_sorted (const char *cpath);
+
+/* Find children nodes adn populate DIR with them */
+error_t fill_dir_with_nodes (struct node *dir);
+
+/* Find attributes and populate DIR with them */
+error_t fill_dir_with_attrs (struct node *dir);
+
 #endif
diff --git a/xmlfs.c b/xmlfs.c
index ced136d..bd39dec 100644
--- a/xmlfs.c
+++ b/xmlfs.c
@@ -30,10 +30,13 @@

 FILE *debug;

-char *netfs_server_name = "xmlfs";
-char *netfs_server_version = XMLFS_VERSION; /* defined in version.h */
+char *netfs_server_name = (char*) "xmlfs";
+char *netfs_server_version = (char*) XMLFS_VERSION; /* defined in version.h */
 const char *argp_program_version;

+/* The filename of the XML */
+char *xmlfilename = NULL;
+
 /* our filesystem */
 struct xmlfs *xmlfs;

@@ -41,9 +44,8 @@ int netfs_maxsymlinks = 0; /* not much sense ... */

 static const struct argp_option options[] =
 {
-  { "debug-filen", 'd', "FILE", 0,
-    "Enable debug and write debug statements to FILE." },
-  { 0 }
+  { "debug-filen", 'd', "FILE", 0, "Enable debug and write debug
statements to FILE.", 0},
+  { 0, 0, 0, 0, 0, 0 }
 };

 static const char args_doc[] = "XML-DOC";
@@ -52,37 +54,39 @@ static const char doc[] =
   "\vThis translator appears like a directory which tries to match the XML"
   " tree in XML-DOC as closely as possible.";

+error_t parse_opt (int key, char *arg, struct argp_state *state)
+{
+  switch (key)
+  {
+    case 'd':
+      debug = fopen (arg, "w");
+      setbuf (debug, NULL);
+      break;
+    case ARGP_KEY_ARG:
+      if (state->arg_num == 0)
+        xmlfilename = arg;
+      else
+        return ARGP_ERR_UNKNOWN;
+      break;
+    default:
+      return ARGP_ERR_UNKNOWN;
+    }
+
+    return 0;
+}
+
 int
 main (int argc, char **argv)
 {
   mach_port_t bootstrap, underlying_node;
   io_statbuf_t underlying_stat;
   file_t xmlfile;
-  char *xmlfilename = NULL;
   error_t err;

+  xmlfilename = NULL;
   debug = NULL;

-  error_t parse_opt (int key, char *arg, struct argp_state *state)
-    {
-      switch (key)
-       {
-       case 'd':
-         debug = fopen (arg, "w");
-         setbuf (debug, NULL);
-         break;
-       case ARGP_KEY_ARG:
-         if (state->arg_num == 0)
-           xmlfilename = arg;
-         else
-           return ARGP_ERR_UNKNOWN;
-         break;
-       default:
-         return ARGP_ERR_UNKNOWN;
-       }
-      return 0;
-    }
-  struct argp argp = { options, parse_opt, args_doc, doc };
+  struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 };

   asprintf ((char **) &argp_program_version, "%s %s",
netfs_server_name, netfs_server_version);

@@ -104,9 +108,9 @@ main (int argc, char **argv)
   if (!xmlfilename)
       /* Try to open the underlying node, which is incidently
         our default XML file. */
-    xmlfile = openport (underlying_node, O_READ);
+    xmlfile = (file_t) openport (underlying_node, O_READ);
   else
-    xmlfile = open (xmlfilename, O_READ);
+    xmlfile = (file_t) open (xmlfilename, O_READ);

   xmlfs = malloc (sizeof (struct xmlfs));

@@ -114,7 +118,7 @@ main (int argc, char **argv)

   netfs_root_node->nn_stat = underlying_stat;
   netfs_root_node->nn_stat.st_mode =
-    S_IFDIR | (underlying_stat.st_mode & ~S_IFMT & ~S_ITRANS);
+    S_IFDIR | (underlying_stat.st_mode & (unsigned int) ~S_IFMT &
(unsigned int) ~S_ITRANS);

   if (err)
     error (1, err, "Cannot create filesystem");
diff --git a/xmlfs.h b/xmlfs.h
index e3c0af6..d47613e 100644
--- a/xmlfs.h
+++ b/xmlfs.h
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <error.h>
+#include <argp.h>

 #include <hurd/netfs.h>

@@ -61,7 +62,12 @@ extern struct xmlfs *xmlfs;

 error_t xmlfs_create (file_t, struct xmlfs *);

+/* Parse an option from the argv array */
+error_t parse_opt (int key, char *arg, struct argp_state *state);
+
+extern char *xmlfilename;
+
 extern FILE *debug;
-#define DEBUG(format, ...) if (debug) fprintf (debug, format, ## __VA_ARGS__)
+#define DEBUG(...) if (debug) fprintf (debug, __VA_ARGS__)

 #endif /* __XMLFS_H__ */


-- 
Michael Walker (http://www.barrucadu.co.uk)

Arch Hurd Developer;      GNU Webmaster;       FSF member #8385
http://www.archhurd.org   http://www.gnu.org   http://www.fsf.org



reply via email to

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