3
|
1 /*
|
|
2 FASTX-toolkit - FASTA/FASTQ preprocessing tools.
|
|
3 Copyright (C) 2009 A. Gordon (gordon@cshl.edu)
|
|
4
|
|
5 This program is free software: you can redistribute it and/or modify
|
|
6 it under the terms of the GNU Affero General Public License as
|
|
7 published by the Free Software Foundation, either version 3 of the
|
|
8 License, or (at your option) any later version.
|
|
9
|
|
10 This program is distributed in the hope that it will be useful,
|
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 GNU Affero General Public License for more details.
|
|
14
|
|
15 You should have received a copy of the GNU Affero General Public License
|
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17 */
|
|
18 #include <err.h>
|
|
19 #include <stdio.h>
|
|
20 #include <stdlib.h>
|
|
21 #include <unistd.h>
|
|
22 #include <sys/types.h>
|
|
23 #include <string.h>
|
|
24 #include <getopt.h>
|
|
25
|
|
26 #include "fastx_args.h"
|
|
27
|
|
28 /*
|
|
29 * Each program should specify its own usage string
|
|
30 */
|
|
31 extern char* usage;
|
|
32
|
|
33
|
|
34 /*
|
|
35 * globals.. yuck
|
|
36 *
|
|
37 * some day this will be a stand alone class
|
|
38 */
|
|
39 const char* input_filename = "-";
|
|
40 const char* output_filename = "-";
|
|
41 int verbose = 0;
|
|
42 int compress_output = 0 ;
|
|
43 FILE* report_file;
|
|
44
|
|
45 const char* get_input_filename()
|
|
46 {
|
|
47 return input_filename;
|
|
48 }
|
|
49
|
|
50 const char* get_output_filename()
|
|
51 {
|
|
52 return output_filename;
|
|
53 }
|
|
54
|
|
55 int verbose_flag()
|
|
56 {
|
|
57 return verbose;
|
|
58 }
|
|
59
|
|
60 int compress_output_flag()
|
|
61 {
|
|
62 return compress_output ;
|
|
63 }
|
|
64
|
|
65 FILE* get_report_file()
|
|
66 {
|
|
67 return report_file;
|
|
68 }
|
|
69
|
|
70 int fastx_parse_cmdline( int argc, char* argv[],
|
|
71 const char* program_options,
|
|
72 parse_argument_func program_parse_args )
|
|
73 {
|
|
74 int opt;
|
|
75
|
|
76 char combined_options_string[100];
|
|
77
|
|
78 strcpy(combined_options_string, "zhvi:o:");
|
|
79 strcat(combined_options_string, program_options);
|
|
80
|
|
81 report_file = stderr ; //since the default output is STDOUT, the report goes by default to STDERR
|
|
82
|
|
83 while ( (opt = getopt(argc, argv, combined_options_string) ) != -1 ) {
|
|
84
|
|
85 // Parse the program's custom options
|
|
86 if ( strchr(program_options, opt) != NULL ) {
|
|
87 if (!program_parse_args(optind, opt, optarg))
|
|
88 return 0;
|
|
89 continue;
|
|
90 }
|
|
91
|
|
92 //Parse the default options
|
|
93 switch(opt) {
|
|
94 case 'h':
|
|
95 printf("%s", usage);
|
|
96 exit(1);
|
|
97
|
|
98 case 'v':
|
|
99 verbose = 1 ;
|
|
100 break ;
|
|
101
|
|
102 case 'z':
|
|
103 compress_output = 1 ;
|
|
104 break ;
|
|
105
|
|
106
|
|
107 case 'i':
|
|
108 if (optarg==NULL)
|
|
109 errx(1,"[-i] option requires FILENAME argument");
|
|
110 input_filename = optarg;
|
|
111 break;
|
|
112
|
|
113 case 'o':
|
|
114 if (optarg==NULL)
|
|
115 errx(1,"[-o] option requires FILENAME argument");
|
|
116 output_filename = optarg;
|
|
117
|
|
118 //The user specified a specific output file, so the report can go to STDOUT
|
|
119 report_file = stdout;
|
|
120 break;
|
|
121
|
|
122 default:
|
|
123 printf("use '-h' for usage information.\n");
|
|
124 exit(1);
|
|
125 break;
|
|
126
|
|
127 }
|
|
128 }
|
|
129
|
|
130 return 1;
|
|
131 }
|
|
132
|