int main (int argc, char *argv[]) { static struct option long_option[] = { {"debug", no_argument, NULL, 'd'}, {"source_start_sector", required_argument, NULL, 's'}, {"destination_start_sector", required_argument, NULL, 't'}, {"source_media_type", required_argument, NULL, 'r'}, {"destination_media_type", required_argument, NULL, 'w'}, {"source_file", required_argument, NULL, 'i'}, {"destination_file", required_argument, NULL, 'o'}, {"verbose", no_argument, NULL, 'v'}, {0, 0, 0, 0} }; // now define some variables to store user options unsigned int source_start_sector = 0; unsigned int destination_start_sector = 0; // We are ignorering the next two variables because we do not have // physical disk handling code anyway. // unsigned int source_media_type = 0; // unsigned int destination_media_type = 0; char *source_file = NULL; char *destination_file = NULL; int indexptr; while(1) { int done=0; int retval = getopt_long (argc, argv, "ds:t:r:w:i:o:v", long_option, &indexptr); // cout<<"retval = "<<retval<<endl; switch (retval) { case 'd': // this is for debug enable cout<<"Enabling debug mode "<<endl; System.SetBoolOption(DEBUG_OPTION); // enable debug mode. break; case 's': cout<<"Source start sector :: "<<optarg<<endl; source_start_sector = atoi(optarg); break; case 't': cout<<"Destination start sector :: "<<optarg<<endl; destination_start_sector = atoi(optarg); break; case 'r': cout<<"[IGNORING]Source Media type :: "<<optarg<<endl; break; case 'w': cout<<"[IGNORING]Destination Media type :: "<<optarg<<endl; break; case 'i': cout<<"Source file :: "<<optarg<<endl; source_file = optarg; break; case 'o': cout<<"Destination file :: "<<optarg<<endl; destination_file = optarg; break; case 'v': cout<<"Enabling verbose mode"<<endl; SetBoolOption (VERBOSE_OPTION); // enable verbose mode. break; case -1: // getopt_long function's job is over cout<<"I have exhaused all my options"<<endl; done = 1; break; case 0: DEBUG("No reason why zero is returned here", FATAL); break; case '?': // show no mercy DEBUG("Invalid option encountered",FATAL); return -1; default: DEBUG("Unrecognized value from getopt_long", NOTE); break; } if (done){ // let check if we have more options int i; for(i=optind; i<argc; i++){ cout<<"option "<<i<<" :: "<<argv[i]<<endl; } break; } } }