00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 #include <string.h>
00015
00016 #ifdef HAVE_CONFIG_H
00017 #include "config.h"
00018 #endif
00019
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
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
00059
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
00070
00071 int
00072 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
00073 {
00074 int c;
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 char *stop_char;
00100 static struct option long_options[] = {
00101 { "help", 0, NULL, 'h' },
00102 { "version", 0, NULL, 'V' },
00103 { "dbhome-dir", 1, NULL, 'd' },
00104 { "configuration-file", 1, NULL, 'c' },
00105 { NULL, 0, NULL, 0 }
00106 };
00107
00108 c = getopt_long (argc, argv, "hVd:c:", long_options, &option_index);
00109
00110 if (c == -1) break;
00111
00112 switch (c)
00113 {
00114 case 'h':
00115 clear_args ();
00116 cmdline_parser_print_help ();
00117 exit (EXIT_SUCCESS);
00118
00119 case 'V':
00120 clear_args ();
00121 cmdline_parser_print_version ();
00122 exit (EXIT_SUCCESS);
00123
00124 case 'd':
00125 if (args_info->dbhome_dir_given)
00126 {
00127 fprintf (stderr, "%s: `--dbhome-dir' (`-d') option given more than once\n", PACKAGE);
00128 clear_args ();
00129 exit (EXIT_FAILURE);
00130 }
00131 args_info->dbhome_dir_given = 1;
00132 args_info->dbhome_dir_arg = strdup (optarg);
00133 break;
00134
00135 case 'c':
00136 if (args_info->configuration_file_given)
00137 {
00138 fprintf (stderr, "%s: `--configuration-file' (`-c') option given more than once\n", PACKAGE);
00139 clear_args ();
00140 exit (EXIT_FAILURE);
00141 }
00142 args_info->configuration_file_given = 1;
00143 args_info->configuration_file_arg = strdup (optarg);
00144 break;
00145
00146
00147 case 0:
00148
00149 case '?':
00150
00151 exit (EXIT_FAILURE);
00152
00153 default:
00154 fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
00155 abort ();
00156 }
00157 }
00158
00159
00160 if (! args_info->dbhome_dir_given)
00161 {
00162 fprintf (stderr, "%s: '--dbhome-dir' ('-d') option required\n", PACKAGE);
00163 missing_required_options = 1;
00164 }
00165 if (! args_info->configuration_file_given)
00166 {
00167 fprintf (stderr, "%s: '--configuration-file' ('-c') option required\n", PACKAGE);
00168 missing_required_options = 1;
00169 }
00170 if ( missing_required_options )
00171 exit (EXIT_FAILURE);
00172
00173 if (optind < argc)
00174 {
00175 int i = 0 ;
00176
00177 args_info->inputs_num = argc - optind ;
00178 args_info->inputs =
00179 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
00180 while (optind < argc)
00181 args_info->inputs[ i++ ] = strdup (argv[optind++]) ;
00182 }
00183
00184 return 0;
00185 }