bug-hurd
[Top][All Lists]
Advanced

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

[PATCH 5/5] Changed argp parsing policy


From: Sergiu Ivanov
Subject: [PATCH 5/5] Changed argp parsing policy
Date: Tue, 26 May 2009 23:31:59 +0300

diff --git a/Makefile b/Makefile
index b7e5716..7b7ce01 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@
 # USA.

 # Get the information from under /usr.
-prefix = /usr/
+prefix = /usr

 CPP = gcc -E -x c
 MIGCOM = mig -cc cat - /dev/null
@@ -30,8 +30,8 @@ CFLAGS += -Wall -g -O2 -D_FILE_OFFSET_BITS=64 -std=gnu99 \
          -DDEBUG
 LDFLAGS += -lnetfs -lfshelp -liohelp -lthreads \
            -lports -lihash -lshouldbeinlibc
-OBJS = main.o node.o lnode.o ulfs.o ncache.o netfs.o \
-       lib.o options.o pattern.o stow.o update.o
+OBJS = main.o node.o lnode.o ulfs.o ncache.o netfs.o lib.o options.o   \
+       pattern.o stow.o update.o unionmount.o

 MIGCOMSFLAGS = -prefix stow_
 fs_notify-MIGSFLAGS = -imacros ./stow-mutations.h
diff --git a/main.c b/main.c
index e407926..43e4846 100644
--- a/main.c
+++ b/main.c
@@ -36,6 +36,7 @@
 #include "options.h"
 #include "stow.h"
 #include "update.h"
+#include "unionmount.h"

 char *netfs_server_name = "unionfs";
 char *netfs_server_version = HURD_VERSION;
diff --git a/options.c b/options.c
index beed9f4..c12974c 100644
--- a/options.c
+++ b/options.c
@@ -6,12 +6,12 @@
    modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation; either version 2 of the
    License, or * (at your option) any later version.
-
+
    This program 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-1307
@@ -22,6 +22,7 @@
 #define _GNU_SOURCE

 #include <argp.h>
+#include <argz.h>
 #include <error.h>

 #include "options.h"
@@ -33,6 +34,7 @@
 #include "pattern.h"
 #include "stow.h"
 #include "update.h"
+#include "unionmount.h"

 /* This variable is set to a non-zero value after parsing of the
    startup options.  Whenever the argument parser is later called to
@@ -78,7 +80,7 @@ argp_parse_common_options (int key, char *arg,
struct argp_state *state)
   static int ulfs_flags = 0, ulfs_mode = 0, ulfs_modified = 0,
     ulfs_match = 0, ulfs_priority = 0;
   static struct patternlist ulfs_patternlist =
-    {
+    {
       .lock = MUTEX_INITIALIZER,
       .head = NULL
     };
@@ -103,7 +105,7 @@ argp_parse_common_options (int key, char *arg,
struct argp_state *state)
       break;

       /* --add */
-      /*case OPT_ADD:          
+      /*case OPT_ADD:
       ulfs_mode = ULFS_MODE_ADD;
       break;*/

@@ -128,19 +130,17 @@ argp_parse_common_options (int key, char *arg,
struct argp_state *state)

       /*case OPT_UNDERLYING:*/ /* --underlying  */
     case ARGP_KEY_ARG:
-
-      if (ulfs_mode == ULFS_MODE_REMOVE)
-       {
-         err = ulfs_unregister (arg);
-         if (err == ENOENT)
-           /* It is not a fatal error, when the user tries to remove
-              a filesystem, which is not used by unionfs.  */
-           err = 0;
-       }
-      else
-       err = ulfs_register (arg, ulfs_flags, ulfs_priority);
+      /* We've reached the translator command, hence the remaining
+        part of the command line should be fed to the
+        translator.  */
+      err = argz_create
+       (state->argv + state->next - 1, &trans_argz, &trans_argz_len);
       if (err)
-       error (EXIT_FAILURE, err, "ulfs_register");
+       error (EXIT_FAILURE, err,
+              "argz_create: Could not create options vector");
+
+      state->next = state->argc; /* stop parsing */
+
       ulfs_modified = 1;
       ulfs_flags = ulfs_mode = ulfs_priority = 0;
       ulfs_match = 0;
@@ -182,7 +182,7 @@ argp_parse_startup_options (int key, char *arg,
struct argp_state *state)
       err = ARGP_ERR_UNKNOWN;
       break;
     }
-
+
   return err;
 }

@@ -212,7 +212,7 @@ const struct argp_child argp_children_startup[] =
   };

 const char *argp_program_version = STANDARD_HURD_VERSION (unionfs);
-const char *argp_program_bug_address =
+const char *argp_program_bug_address =
 "Gianluca Guida <glguida@gmail.com>";

 #define ARGS_DOC "FILESYSTEMS ..."
diff --git a/unionmount.c b/unionmount.c
new file mode 100644
index 0000000..a8939f8
--- /dev/null
+++ b/unionmount.c
@@ -0,0 +1,38 @@
+/*---------------------------------------------------------------------------*/
+/* Hurd unionmount */
+/* The core of unionmount functionality. */
+/*---------------------------------------------------------------------------*/
+/* Copyright (C) 2009 Free Software Foundation, Inc.  Written by
+   Sergiu Ivanov <unlimitedscolobb@gmail.com>.
+
+   This program 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 of the
+   License, or * (at your option) any later version.
+
+   This program 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-1307
+   USA.  */
+/*---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+#include "unionmount.h"
+/*---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+/*---------Global Variables--------------------------------------------------*/
+/*The command line for starting the translator. */
+char * trans_argz;
+size_t trans_argz_len;
+/*---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
diff --git a/unionmount.h b/unionmount.h
new file mode 100644
index 0000000..7e4481b
--- /dev/null
+++ b/unionmount.h
@@ -0,0 +1,37 @@
+/*---------------------------------------------------------------------------*/
+/* Hurd unionmount */
+/* General information and properties for unionmount/unionfs. */
+/*---------------------------------------------------------------------------*/
+/* Copyright (C) 2009 Free Software Foundation, Inc.  Written by
+   Sergiu Ivanov <unlimitedscolobb@gmail.com>.
+
+   This program 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 of the
+   License, or * (at your option) any later version.
+
+   This program 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-1307
+   USA.  */
+/*---------------------------------------------------------------------------*/
+#ifndef INCLUDED_UNIONMOUNT_H
+#define INCLUDED_UNIONMOUNT_H
+
+/*---------------------------------------------------------------------------*/
+#include <unistd.h>
+/*---------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------*/
+/*---------Global Variables--------------------------------------------------*/
+/*The command line for starting the translator. */
+extern char * trans_argz;
+extern size_t trans_argz_len;
+/*---------------------------------------------------------------------------*/
+
+#endif /*INCLUDED_UNIONMOUNT_H*/
-- 
1.5.2.4




reply via email to

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