int main(int argc, char *argv[]) { if (!argv[1]) { return usage(); } char *arg = argv[1]; argc -= 1; argv += 1; if (!strcmp(arg, "split")) { return split_main(argc, argv); } else if (!strcmp(arg, "pack")) { return pack_main(argc, argv); } else { fprintf(stderr, "unknown option : %s\n", arg); return usage(); } }
int setup_options(int argc, char *argv[]){ const struct option long_opts[] = { /*{"setup", no_argument, 0, 's'}, {"split", no_argument, 0, 'p'}, {"mstep", no_argument, 0, 'm'}, {"merge", no_argument, 0, 'e'}, {"estep", no_argument, 0, 't'}, */ {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'v'}, { NULL, 0, NULL, 0} }; //End of declaring opts int index = 0; int iarg = 0; if(argc < 2){ print_usage(0); }else if(argc >= 2){ char *option = argv[1]; if(strcmp(option,"setup")==0){ argv[1]= ""; return setup_main(argc,argv); }else if(strcmp(option,"split")==0){ argv[1]= ""; return split_main(argc,argv); }else if(strcmp(option,"mstep")==0){ argv[1]= ""; return mstep_main(argc,argv); }else if(strcmp(option,"merge")==0){ argv[1]= ""; return merge_main(argc,argv); }else if(strcmp(option,"estep")==0){ argv[1]= ""; return estep_main(argc,argv); } } //Iterate through options while((iarg = getopt_long(argc, argv, "vh", long_opts, &index)) != -1){ switch(iarg){ case 'h': print_usage(0); break; case 'v': printf ("%s\n",CAVEMAN_VERSION); return 0; case '?': print_usage(1); break; default: print_usage(1); }; // End of args switch statement }//End of iteration through options return 0; }