>From 499bfb2490c2d7e2bc3e948fca5213c5e993e14d Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov <unlimitedscol...@gmail.com> Date: Thu, 28 May 2009 23:55:50 +0300 Subject: [PATCH] Change argp parsing policy.
* Makefile (OBJS): Add unionmount.o to the list. * options.c: (argp_parse_common_options): Make the parser stop parsing when it encounters a non-option argument. * unionmount.c: Add this file. Define trans_argz and trans_argz_len. * unionmount.h: Add this file. Declare trans_argz and trans_argz_len. --- Makefile | 2 +- options.c | 24 ++++++++++++------------ unionmount.c | 34 ++++++++++++++++++++++++++++++++++ unionmount.h | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 unionmount.c create mode 100644 unionmount.h diff --git a/Makefile b/Makefile index a521ea0..0846234 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ CFLAGS += -Wall -g -O2 -D_FILE_OFFSET_BITS=64 -std=gnu99 \ 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 + 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/options.c b/options.c index c173d6e..7a3a5d5 100644 --- a/options.c +++ b/options.c @@ -25,6 +25,7 @@ #define _GNU_SOURCE #include <argp.h> +#include <argz.h> #include <error.h> #include "options.h" @@ -36,6 +37,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 @@ -114,19 +116,17 @@ argp_parse_common_options (int key, char *arg, struct argp_state *state) break; 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; diff --git a/unionmount.c b/unionmount.c new file mode 100644 index 0000000..46783c2 --- /dev/null +++ b/unionmount.c @@ -0,0 +1,34 @@ +/*---------------------------------------------------------------------------*/ +/* Hurd unionmount */ +/* The core of unionmount functionality. */ +/*---------------------------------------------------------------------------*/ +/* Copyright (C) 2009 Free Software Foundation, Inc. + + Written by Sergiu Ivanov <unlimitedscol...@gmail.com>. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License version + 2 as published by the Free Software Foundation. + + 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. */ +/*---------------------------------------------------------------------------*/ + +#define _GNU_SOURCE 1 +/*---------------------------------------------------------------------------*/ +#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..29c8d73 --- /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 <unlimitedscol...@gmail.com>. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License version + 2 as published by the Free Software Foundation. + + 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