diff options
author | Sergiu Ivanov <unlimitedscolobb@gmail.com> | 2008-11-22 00:25:17 +0200 |
---|---|---|
committer | Sergiu Ivanov <unlimitedscolobb@gmail.com> | 2008-11-22 00:25:17 +0200 |
commit | 9401ed47c6d00cca32b581e096502f9534998bcd (patch) | |
tree | 5e601b6d3c6dd10c71c579e6c89b609b3e4f292d /options.c | |
parent | 4e81430d26eef24f5bb8464c8c54a11b042f1842 (diff) |
Moved the code to GCS
The code now complies (hopefully) with GNU Coding Standards.
Diffstat (limited to 'options.c')
-rw-r--r-- | options.c | 276 |
1 files changed, 129 insertions, 147 deletions
@@ -1,10 +1,10 @@ -/*----------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ /*options.h*/ -/*----------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ /*Definitions for parsing the command line switches*/ -/*----------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ /*Based on the code of unionfs translator.*/ -/*----------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ /*Copyright (C) 2001, 2002, 2005, 2008 Free Software Foundation, Inc. Written by Sergiu Ivanov <unlimitedscolobb@gmail.com>. @@ -22,180 +22,162 @@ 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 <argp.h> #include <error.h> -/*----------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ #include "debug.h" #include "options.h" #include "node.h" -/*----------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ -/*----------------------------------------------------------------------------*/ -/*--------Macros--------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ +/*--------Macros-------------------------------------------------------------*/ /*Short documentation for argp*/ #define ARGS_DOC "TARGET-NAME" #define DOC "Finds the bottommost translator called TARGET-NAME in the \ static stack of translators and reads and write to it." -/*----------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ -/*----------------------------------------------------------------------------*/ -/*--------Forward Declarations------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ +/*--------Forward Declarations-----------------------------------------------*/ /*Argp parser function for the common options*/ static -error_t -argp_parse_common_options - ( - int key, - char * arg, - struct argp_state * state - ); -/*----------------------------------------------------------------------------*/ + error_t + argp_parse_common_options (int key, char *arg, struct argp_state *state); +/*---------------------------------------------------------------------------*/ /*Argp parser function for the startup options*/ static -error_t -argp_parse_startup_options - ( - int key, - char * arg, - struct argp_state * state - ); -/*----------------------------------------------------------------------------*/ - -/*----------------------------------------------------------------------------*/ -/*--------Global Variables----------------------------------------------------*/ -/*This variable is set to a non-zero value after the parsing of starup options - is finished*/ + error_t + argp_parse_startup_options (int key, char *arg, struct argp_state *state); +/*---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------*/ +/*--------Global Variables---------------------------------------------------*/ +/*This variable is set to a non-zero value after the parsing of starup + options is finished*/ static int parsing_startup_options_finished; -/*----------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ /*Argp options common to both the runtime and the startup parser*/ -static const struct argp_option argp_common_options[] = - { - {0} - }; -/*----------------------------------------------------------------------------*/ +static const struct argp_option argp_common_options[] = { + {0} +}; + +/*---------------------------------------------------------------------------*/ /*Argp options only meaningful for startupp parsing*/ -static const struct argp_option argp_startup_options[] = - { - {0} - }; -/*----------------------------------------------------------------------------*/ +static const struct argp_option argp_startup_options[] = { + {0} +}; + +/*---------------------------------------------------------------------------*/ /*Argp parser for only the common options*/ static const struct argp argp_parser_common_options = - {argp_common_options, argp_parse_common_options, 0, 0, 0}; -/*----------------------------------------------------------------------------*/ + { argp_common_options, argp_parse_common_options, 0, 0, 0 }; +/*---------------------------------------------------------------------------*/ /*Argp parser for only the startup options*/ static const struct argp argp_parser_startup_options = - {argp_startup_options, argp_parse_startup_options, 0, 0, 0}; -/*----------------------------------------------------------------------------*/ + { argp_startup_options, argp_parse_startup_options, 0, 0, 0 }; +/*---------------------------------------------------------------------------*/ /*The list of children parsers for runtime arguments*/ -static const struct argp_child argp_children_runtime[] = - { - {&argp_parser_common_options}, - {&netfs_std_runtime_argp}, - {0} - }; -/*----------------------------------------------------------------------------*/ +static const struct argp_child argp_children_runtime[] = { + {&argp_parser_common_options}, + {&netfs_std_runtime_argp}, + {0} +}; + +/*---------------------------------------------------------------------------*/ /*The list of children parsers for startup arguments*/ -static const struct argp_child argp_children_startup[] = - { - {&argp_parser_startup_options}, - {&argp_parser_common_options}, - {&netfs_std_startup_argp}, - {0} - }; -/*----------------------------------------------------------------------------*/ +static const struct argp_child argp_children_startup[] = { + {&argp_parser_startup_options}, + {&argp_parser_common_options}, + {&netfs_std_startup_argp}, + {0} +}; + +/*---------------------------------------------------------------------------*/ /*The version of the server for argp*/ -const char * argp_program_version = "0.0"; -/*----------------------------------------------------------------------------*/ +const char *argp_program_version = "0.0"; +/*---------------------------------------------------------------------------*/ /*The arpg parser for runtime arguments*/ -struct argp argp_runtime = - {0, 0, 0, 0, argp_children_runtime}; -/*----------------------------------------------------------------------------*/ +struct argp argp_runtime = { 0, 0, 0, 0, argp_children_runtime }; + +/*---------------------------------------------------------------------------*/ /*The argp parser for startup arguments*/ -struct argp argp_startup = - {0, 0, ARGS_DOC, DOC, argp_children_startup}; -/*----------------------------------------------------------------------------*/ +struct argp argp_startup = { 0, 0, ARGS_DOC, DOC, argp_children_startup }; -/*----------------------------------------------------------------------------*/ -/*--------Functions-----------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------*/ +/*--------Functions----------------------------------------------------------*/ /*Argp parser function for the common options*/ static -error_t -argp_parse_common_options - ( - int key, - char * arg, - struct argp_state * state - ) - { - error_t err = 0; - - /*Go through the possible options*/ - switch(key) - { - case ARGP_KEY_END: - { - /*If parsing of startup options has not finished*/ - if(!parsing_startup_options_finished) - { - /*set the flag that the startup options have already been parsed*/ - parsing_startup_options_finished = 1; - } - else - { - } - - break; - } - case ARGP_KEY_ARG: // the translator to filter out; - { - target_name = strdup(arg); - if(!target_name) - error(EXIT_FAILURE, ENOMEM, "argp_parse_common_options: " - "Could not strdup the translator name"); - - break; - } - /*If the option could not be recognized*/ - default: - { - /*set the error code*/ - err = ARGP_ERR_UNKNOWN; - } - } - - /*Return the result*/ - return err; - }/*argp_parse_common_options*/ -/*----------------------------------------------------------------------------*/ + error_t + argp_parse_common_options (int key, char *arg, struct argp_state *state) +{ + error_t err = 0; + + /*Go through the possible options */ + switch (key) + { + case ARGP_KEY_END: + { + /*If parsing of startup options has not finished */ + if (!parsing_startup_options_finished) + { + /*set the flag that the startup options have already been parsed */ + parsing_startup_options_finished = 1; + } + else + { + } + + break; + } + case ARGP_KEY_ARG: // the translator to filter out; + { + target_name = strdup (arg); + if (!target_name) + error (EXIT_FAILURE, ENOMEM, "argp_parse_common_options: " + "Could not strdup the translator name"); + + break; + } + /*If the option could not be recognized */ + default: + { + /*set the error code */ + err = ARGP_ERR_UNKNOWN; + } + } + + /*Return the result */ + return err; +} /*argp_parse_common_options */ + +/*---------------------------------------------------------------------------*/ /*Argp parser function for the startup options*/ static -error_t -argp_parse_startup_options - ( - int key, - char * arg, - struct argp_state * state - ) - { - /*Do nothing in a beautiful way*/ - error_t err = 0; - - switch(key) - { - default: - { - err = ARGP_ERR_UNKNOWN; - - break; - } - } - - return err; - }/*argp_parse_startup_options*/ -/*----------------------------------------------------------------------------*/ + error_t + argp_parse_startup_options (int key, char *arg, struct argp_state *state) +{ + /*Do nothing in a beautiful way */ + error_t err = 0; + + switch (key) + { + default: + { + err = ARGP_ERR_UNKNOWN; + + break; + } + } + + return err; +} /*argp_parse_startup_options */ + +/*---------------------------------------------------------------------------*/ |