cmdline.c

Go to the documentation of this file.
00001 /*
00002   File autogenerated by gengetopt version 2.8.1
00003   generated with the following command:
00004   gengetopt --input trapper.ggo --unamed-opts 
00005 
00006   The developers of gengetopt consider the fixed text that goes in all
00007   gengetopt output files to be in the public domain:
00008   we make no copyright claims on it.
00009 */
00010 
00011 
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 #include <string.h>
00015 /* If we use autoconf.  */
00016 #ifdef HAVE_CONFIG_H
00017 #include "config.h"
00018 #endif
00019 /* Check for configure's getopt check result.  */
00020 #ifndef HAVE_GETOPT_LONG
00021 #include "getopt.h"
00022 #else
00023 #include <getopt.h>
00024 #endif
00025 
00026 #ifndef HAVE_STRDUP
00027 #define strdup gengetopt_strdup
00028 #endif /* HAVE_STRDUP */
00029 
00030 #include "cmdline.h"
00031 
00032 
00033 void
00034 cmdline_parser_print_version (void)
00035 {
00036   printf ("%s %s\n", PACKAGE, VERSION);
00037 }
00038 
00039 void
00040 cmdline_parser_print_help (void)
00041 {
00042   cmdline_parser_print_version ();
00043   printf("\n"
00044   "Purpose:\n"
00045   "  This program is a visualizing, editing and prosessing tool for dna reads coming from \n"
00046   "  dna sequence readers. The data\n"
00047   "  is stored in a Berkeley Db database which gives fast access to hugh amount of data\n"
00048   "\n"
00049   "Usage: %s [OPTIONS]... [FILES]...\n", PACKAGE);
00050   printf("   -h         --help                       Print help and exit\n");
00051   printf("   -V         --version                    Print version and exit\n");
00052   printf("   -dSTRING   --dbhome-dir=STRING          directory home for the database environment ( try to avoid nfs file system )\n");
00053   printf("   -cSTRING   --configuration-file=STRING  configuration file for view modes\n");
00054 }
00055 
00056 
00057 #ifndef HAVE_STRDUP
00058 /* gengetopt_strdup(): automatically generated from strdup.c. */
00059 /* strdup.c replacement of strdup, which is not standard */
00060 static char *
00061 gengetopt_strdup (const char *s)
00062 {
00063   char *result = (char*)malloc(strlen(s) + 1);
00064   if (result == (char*)0)
00065     return (char*)0;
00066   strcpy(result, s);
00067   return result;
00068 }
00069 #endif /* HAVE_STRDUP */
00070 
00071 int
00072 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
00073 {
00074   int c;        /* Character of the parsed option.  */
00075   int missing_required_options = 0;
00076 
00077   args_info->help_given = 0 ;
00078   args_info->version_given = 0 ;
00079   args_info->dbhome_dir_given = 0 ;
00080   args_info->configuration_file_given = 0 ;
00081 #define clear_args() { \
00082   args_info->dbhome_dir_arg = NULL; \
00083   args_info->configuration_file_arg = NULL; \
00084 }
00085 
00086   clear_args();
00087 
00088   args_info->inputs = NULL;
00089   args_info->inputs_num = 0;
00090 
00091   optarg = 0;
00092   optind = 1;
00093   opterr = 1;
00094   optopt = '?';
00095 
00096   while (1)
00097     {
00098       int option_index = 0;
00099       static struct option long_options[] = {
00100         { "help",       0, NULL, 'h' },
00101         { "version",    0, NULL, 'V' },
00102         { "dbhome-dir", 1, NULL, 'd' },
00103         { "configuration-file", 1, NULL, 'c' },
00104         { NULL, 0, NULL, 0 }
00105       };
00106 
00107       c = getopt_long (argc, argv, "hVd:c:", long_options, &option_index);
00108 
00109       if (c == -1) break;       /* Exit from `while (1)' loop.  */
00110 
00111       switch (c)
00112         {
00113         case 'h':       /* Print help and exit.  */
00114           clear_args ();
00115           cmdline_parser_print_help ();
00116           exit (EXIT_SUCCESS);
00117 
00118         case 'V':       /* Print version and exit.  */
00119           clear_args ();
00120           cmdline_parser_print_version ();
00121           exit (EXIT_SUCCESS);
00122 
00123         case 'd':       /* directory home for the database environment ( try to avoid nfs file system ).  */
00124           if (args_info->dbhome_dir_given)
00125             {
00126               fprintf (stderr, "%s: `--dbhome-dir' (`-d') option given more than once\n", PACKAGE);
00127               clear_args ();
00128               exit (EXIT_FAILURE);
00129             }
00130           args_info->dbhome_dir_given = 1;
00131           args_info->dbhome_dir_arg = strdup (optarg);
00132           break;
00133 
00134         case 'c':       /* configuration file for view modes.  */
00135           if (args_info->configuration_file_given)
00136             {
00137               fprintf (stderr, "%s: `--configuration-file' (`-c') option given more than once\n", PACKAGE);
00138               clear_args ();
00139               exit (EXIT_FAILURE);
00140             }
00141           args_info->configuration_file_given = 1;
00142           args_info->configuration_file_arg = strdup (optarg);
00143           break;
00144 
00145 
00146         case 0: /* Long option with no short option */
00147 
00148         case '?':       /* Invalid option.  */
00149           /* `getopt_long' already printed an error message.  */
00150           exit (EXIT_FAILURE);
00151 
00152         default:        /* bug: option not considered.  */
00153           fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
00154           abort ();
00155         } /* switch */
00156     } /* while */
00157 
00158 
00159   if (! args_info->dbhome_dir_given)
00160     {
00161       fprintf (stderr, "%s: '--dbhome-dir' ('-d') option required\n", PACKAGE);
00162       missing_required_options = 1;
00163     }
00164   if (! args_info->configuration_file_given)
00165     {
00166       fprintf (stderr, "%s: '--configuration-file' ('-c') option required\n", PACKAGE);
00167       missing_required_options = 1;
00168     }
00169   if ( missing_required_options )
00170     exit (EXIT_FAILURE);
00171 
00172   if (optind < argc)
00173     {
00174       int i = 0 ;
00175   
00176       args_info->inputs_num = argc - optind ;
00177       args_info->inputs = 
00178         (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
00179       while (optind < argc)
00180         args_info->inputs[ i++ ] = strdup (argv[optind++]) ; 
00181     }
00182   
00183   return 0;
00184 }

Generated on Fri Jul 17 20:19:29 2009 for ngsview by  doxygen 1.5.1