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 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;
00110
00111 switch (c)
00112 {
00113 case 'h':
00114 clear_args ();
00115 cmdline_parser_print_help ();
00116 exit (EXIT_SUCCESS);
00117
00118 case 'V':
00119 clear_args ();
00120 cmdline_parser_print_version ();
00121 exit (EXIT_SUCCESS);
00122
00123 case 'd':
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':
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:
00147
00148 case '?':
00149
00150 exit (EXIT_FAILURE);
00151
00152 default:
00153 fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
00154 abort ();
00155 }
00156 }
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 }