int main( int argc, char *argv[] ) { int exit_status = EXIT_SUCCESS; const char *i_file = NULL; const char *o_file = NULL; FILE *fp = NULL; if( argc < 2 ) { // absolute minimum args: <executable name> <input matrix> _print_usage( argv[0], stdout, USAGE_SHORT ); exit( EXIT_SUCCESS ); } _jit_initialization(); do { static const char *CHAR_OPTIONS #ifdef HAVE_LUA = "s:hrt:N:C:P:n:x:c:DM:p:f:q:v:?X"; #else = "hrt:N:C:P:n:x:DM:p:f:q:v:?X"; #endif static struct option LONG_OPTIONS[] = { #ifdef HAVE_LUA {"script", required_argument, 0,'s'}, #endif {"no-header", no_argument, 0,'h'}, {"no-row-labels", no_argument, 0,'r'}, {"type-parser", required_argument, 0,'t'}, {"na-regex", required_argument, 0,'N'}, {"crossprod", required_argument, 0,'C'}, {"pair", required_argument, 0,'P'}, {"by-name", required_argument, 0,'n'}, {"by-index", required_argument, 0,'x'}, #ifdef HAVE_LUA {"coroutine", required_argument, 0,'c'}, #endif {"dry-run", no_argument, 0,'D'}, {"min-ct-cell", required_argument, 0, 256 }, // no short equivalents {"min-mx-cell", required_argument, 0, 257 }, // no short equivalents {"min-samples", required_argument, 0,'M'}, {"p-value", required_argument, 0,'p'}, {"format", required_argument, 0,'f'}, {"fdr", required_argument, 0,'q'}, {"verbosity", required_argument, 0,'v'}, #ifdef _DEBUG {"debug", required_argument, 0, 258 }, // no short equivalents #endif {"help", no_argument, 0,'?'}, { NULL, 0, 0, 0 } }; int arg_index = 0; const int c = getopt_long( argc, argv, CHAR_OPTIONS, LONG_OPTIONS, &arg_index ); switch (c) { case 's': // script opt_script = optarg; break; case 'h': // no-header opt_header = false; break; case 'r': // no-row-labels opt_row_labels = false; break; case 't': // type-parser opt_type_parser = optarg; break; case 'N': // na-regex opt_na_regex = optarg; break; case 'C': // cross-product of matrices opt_preproc_matrix = optarg; break; case 'P': // pair opt_single_pair = optarg; break; case 'n': // by-name opt_pairlist_source = optarg; opt_by_name = true; break; case 'x': // by-index opt_pairlist_source = optarg; opt_by_name = false; break; case 'c': // coroutine opt_coroutine = optarg; break; case 'D': // dry-run opt_dry_run = true; break; //////////////////////////////////////////////////////////////////// case 256: // ...because I haven't defined a short form for this arg_min_cell_count = atoi( optarg ); break; case 257: // ...because I haven't defined a short form for this arg_min_mixb_count = atoi( optarg ); break; case 'M': arg_min_sample_count = atoi( optarg ); if( arg_min_sample_count < 2 ) { warnx( "Seriously...%d samples is acceptable?\n" "I don't think so... ;)\n", arg_min_sample_count ); exit( EXIT_FAILURE ); } break; //////////////////////////////////////////////////////////////////// case 'p': opt_p_value = atof( optarg ); if( ! ( 0 < opt_p_value ) ) { warnx( "specified p-value %.3f will preclude all output.\n", opt_p_value ); abort(); } else if( ! ( opt_p_value < 1.0 ) ) { warnx( "p-value %.3f will filter nothing.\n" "\tIs this really what you want?\n", opt_p_value ); } break; case 'J': // JSON format case 'f': // tabular format // Check for magic-value strings first if( strcmp( MAGIC_FORMAT_ID_STD, optarg ) == 0 ) _emit = format_standard; else if( strcmp( MAGIC_FORMAT_ID_TCGA, optarg ) == 0 ) _emit = format_tcga; else { const char *specifier = emit_config( optarg, c=='J' ? FORMAT_JSON : FORMAT_TABULAR ); if( specifier ) { errx( -1, "invalid specifier \"%s\"", specifier ); } _emit = emit_exec; } break; case 'q': arg_q_value = atof( optarg ); _analyze = _fdr_cache; break; case 'v': // verbosity opt_verbosity = atoi( optarg ); break; case '?': // help _print_usage( argv[0], stdout, USAGE_SHORT ); exit( EXIT_SUCCESS ); break; case 'X': // help _print_usage( argv[0], stdout, USAGE_LONG ); exit( EXIT_SUCCESS ); break; #ifdef _DEBUG case 258: if( strchr( optarg, 'X' ) != NULL ) { // Turn OFF all filtering to turn on "exhaustive" // output mode. opt_status_mask = 0; opt_p_value = 1.0; } dbg_silent = strchr( optarg, 'S' ) != NULL; break; #endif case -1: // ...signals no more options. break; default: printf ("error: unknown option: %c\n", c ); exit( EXIT_FAILURE ); } if( -1 == c ) break; } while( true );
int main(int argc, const char *argv[]) { int is_config = (argc == 2) && (strcmp(argv[1], "config") == 0); return is_config ? emit_config() : emit_fetch(); }