Mercurial > repos > xilinxu > xilinxu
diff fastx_toolkit-0.0.6/src/libfastx/fastx_args.c @ 3:997f5136985f draft default tip
Uploaded
author | xilinxu |
---|---|
date | Thu, 14 Aug 2014 04:52:17 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fastx_toolkit-0.0.6/src/libfastx/fastx_args.c Thu Aug 14 04:52:17 2014 -0400 @@ -0,0 +1,132 @@ +/* + FASTX-toolkit - FASTA/FASTQ preprocessing tools. + Copyright (C) 2009 A. Gordon (gordon@cshl.edu) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <string.h> +#include <getopt.h> + +#include "fastx_args.h" + +/* + * Each program should specify its own usage string + */ +extern char* usage; + + +/* + * globals.. yuck + * + * some day this will be a stand alone class + */ +const char* input_filename = "-"; +const char* output_filename = "-"; +int verbose = 0; +int compress_output = 0 ; +FILE* report_file; + +const char* get_input_filename() +{ + return input_filename; +} + +const char* get_output_filename() +{ + return output_filename; +} + +int verbose_flag() +{ + return verbose; +} + +int compress_output_flag() +{ + return compress_output ; +} + +FILE* get_report_file() +{ + return report_file; +} + +int fastx_parse_cmdline( int argc, char* argv[], + const char* program_options, + parse_argument_func program_parse_args ) +{ + int opt; + + char combined_options_string[100]; + + strcpy(combined_options_string, "zhvi:o:"); + strcat(combined_options_string, program_options); + + report_file = stderr ; //since the default output is STDOUT, the report goes by default to STDERR + + while ( (opt = getopt(argc, argv, combined_options_string) ) != -1 ) { + + // Parse the program's custom options + if ( strchr(program_options, opt) != NULL ) { + if (!program_parse_args(optind, opt, optarg)) + return 0; + continue; + } + + //Parse the default options + switch(opt) { + case 'h': + printf("%s", usage); + exit(1); + + case 'v': + verbose = 1 ; + break ; + + case 'z': + compress_output = 1 ; + break ; + + + case 'i': + if (optarg==NULL) + errx(1,"[-i] option requires FILENAME argument"); + input_filename = optarg; + break; + + case 'o': + if (optarg==NULL) + errx(1,"[-o] option requires FILENAME argument"); + output_filename = optarg; + + //The user specified a specific output file, so the report can go to STDOUT + report_file = stdout; + break; + + default: + printf("use '-h' for usage information.\n"); + exit(1); + break; + + } + } + + return 1; +} +