Cmdline * parseCmdline(int argc, char **argv) { int i; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for(i=1, cmd.argc=1; i<argc; i++) { if( 0==strcmp("--", argv[i]) ) { while( ++i<argc ) argv[cmd.argc++] = argv[i]; continue; } if( 0==strcmp("-dm", argv[i]) ) { int keep = i; cmd.dmP = 1; i = getDoubleOpt(argc, argv, i, &cmd.dm, 1); cmd.dmC = i-keep; checkDoubleLower("-dm", &cmd.dm, cmd.dmC, 10000.0); checkDoubleHigher("-dm", &cmd.dm, cmd.dmC, 0.0); continue; } if( 0==strcmp("-nsub", argv[i]) ) { int keep = i; cmd.nsubP = 1; i = getIntOpt(argc, argv, i, &cmd.nsub, 1); cmd.nsubC = i-keep; checkIntLower("-nsub", &cmd.nsub, cmd.nsubC, 4096); checkIntHigher("-nsub", &cmd.nsub, cmd.nsubC, 1); continue; } if( 0==strcmp("-dstime", argv[i]) ) { int keep = i; cmd.dstimeP = 1; i = getIntOpt(argc, argv, i, &cmd.dstime, 1); cmd.dstimeC = i-keep; checkIntLower("-dstime", &cmd.dstime, cmd.dstimeC, 128); checkIntHigher("-dstime", &cmd.dstime, cmd.dstimeC, 1); continue; } if( 0==strcmp("-startfile", argv[i]) ) { int keep = i; cmd.startfileP = 1; i = getIntOpt(argc, argv, i, &cmd.startfile, 1); cmd.startfileC = i-keep; checkIntLower("-startfile", &cmd.startfile, cmd.startfileC, 2000); checkIntHigher("-startfile", &cmd.startfile, cmd.startfileC, 1); continue; } if( 0==strcmp("-numfiles", argv[i]) ) { int keep = i; cmd.numfilesP = 1; i = getIntOpt(argc, argv, i, &cmd.numfiles, 1); cmd.numfilesC = i-keep; checkIntLower("-numfiles", &cmd.numfiles, cmd.numfilesC, 2000); checkIntHigher("-numfiles", &cmd.numfiles, cmd.numfilesC, 1); continue; } if( 0==strcmp("-outbits", argv[i]) ) { int keep = i; cmd.outbitsP = 1; i = getIntOpt(argc, argv, i, &cmd.outbits, 1); cmd.outbitsC = i-keep; checkIntLower("-outbits", &cmd.outbits, cmd.outbitsC, 8); checkIntHigher("-outbits", &cmd.outbits, cmd.outbitsC, 2); continue; } if( 0==strcmp("-filetime", argv[i]) ) { int keep = i; cmd.filetimeP = 1; i = getFloatOpt(argc, argv, i, &cmd.filetime, 1); cmd.filetimeC = i-keep; checkFloatLower("-filetime", &cmd.filetime, cmd.filetimeC, 100000.0); checkFloatHigher("-filetime", &cmd.filetime, cmd.filetimeC, 0.0); continue; } if( 0==strcmp("-filelen", argv[i]) ) { int keep = i; cmd.filelenP = 1; i = getFloatOpt(argc, argv, i, &cmd.filelen, 1); cmd.filelenC = i-keep; checkFloatLower("-filelen", &cmd.filelen, cmd.filelenC, 1000.0); checkFloatHigher("-filelen", &cmd.filelen, cmd.filelenC, 0.0); continue; } if( 0==strcmp("-tgtstd", argv[i]) ) { int keep = i; cmd.tgtstdP = 1; i = getFloatOpt(argc, argv, i, &cmd.tgtstd, 1); cmd.tgtstdC = i-keep; checkFloatLower("-tgtstd", &cmd.tgtstd, cmd.tgtstdC, 100000.0); checkFloatHigher("-tgtstd", &cmd.tgtstd, cmd.tgtstdC, 0.0); continue; } if( 0==strcmp("-tgtavg", argv[i]) ) { int keep = i; cmd.tgtavgP = 1; i = getFloatOpt(argc, argv, i, &cmd.tgtavg, 1); cmd.tgtavgC = i-keep; checkFloatLower("-tgtavg", &cmd.tgtavg, cmd.tgtavgC, 100000.0); checkFloatHigher("-tgtavg", &cmd.tgtavg, cmd.tgtavgC, 0.0); continue; } if( 0==strcmp("-onlyI", argv[i]) ) { cmd.onlyIP = 1; continue; } if( 0==strcmp("-weights", argv[i]) ) { int keep = i; cmd.wgtsfileP = 1; i = getStringOpt(argc, argv, i, &cmd.wgtsfile, 1); cmd.wgtsfileC = i-keep; continue; } if( 0==strcmp("-bandpass", argv[i]) ) { int keep = i; cmd.bandpassfileP = 1; i = getStringOpt(argc, argv, i, &cmd.bandpassfile, 1); cmd.bandpassfileC = i-keep; continue; } if( 0==strcmp("-o", argv[i]) ) { int keep = i; cmd.outputbasenameP = 1; i = getStringOpt(argc, argv, i, &cmd.outputbasename, 1); cmd.outputbasenameC = i-keep; continue; } if( argv[i][0]=='-' ) { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; }/* for i */ /*@-mustfree*/ cmd.argv = argv+1; /*@=mustfree*/ cmd.argc -= 1; if( 1>cmd.argc ) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if( 2000<cmd.argc ) { fprintf(stderr, "%s: there should be at most 2000 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass*/ return &cmd; }
Cmdline *parseCmdline(int argc, char **argv) { int i; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for (i = 1, cmd.argc = 1; i < argc; i++) { if (0 == strcmp("--", argv[i])) { while (++i < argc) argv[cmd.argc++] = argv[i]; continue; } if (0 == strcmp("-startwidth", argv[i])) { int keep = i; cmd.startwidthP = 1; i = getIntOpt(argc, argv, i, &cmd.startwidth, 1); cmd.startwidthC = i - keep; checkIntLower("-startwidth", &cmd.startwidth, cmd.startwidthC, 50); checkIntHigher("-startwidth", &cmd.startwidth, cmd.startwidthC, 2); continue; } if (0 == strcmp("-endwidth", argv[i])) { int keep = i; cmd.endwidthP = 1; i = getIntOpt(argc, argv, i, &cmd.endwidth, 1); cmd.endwidthC = i - keep; checkIntLower("-endwidth", &cmd.endwidth, cmd.endwidthC, 500); checkIntHigher("-endwidth", &cmd.endwidth, cmd.endwidthC, 50); continue; } if (0 == strcmp("-endfreq", argv[i])) { int keep = i; cmd.endfreqP = 1; i = getDoubleOpt(argc, argv, i, &cmd.endfreq, 1); cmd.endfreqC = i - keep; checkDoubleLower("-endfreq", &cmd.endfreq, cmd.endfreqC, 10); checkDoubleHigher("-endfreq", &cmd.endfreq, cmd.endfreqC, 0.1); continue; } if (argv[i][0] == '-') { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; } /* for i */ /*@-mustfree */ cmd.argv = argv + 1; /*@=mustfree */ cmd.argc -= 1; if (1 > cmd.argc) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if (1 < cmd.argc) { fprintf(stderr, "%s: there should be at most 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass */ return &cmd; }
Cmdline * parseCmdline(int argc, char **argv) { int i; char missingMandatory = 0; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for(i=1, cmd.argc=1; i<argc; i++) { if( 0==strcmp("--", argv[i]) ) { while( ++i<argc ) argv[cmd.argc++] = argv[i]; continue; } if( 0==strcmp("-o", argv[i]) ) { int keep = i; cmd.outfileP = 1; i = getStringOpt(argc, argv, i, &cmd.outfile, 1); cmd.outfileC = i-keep; continue; } if( 0==strcmp("-pkmb", argv[i]) ) { cmd.pkmbP = 1; continue; } if( 0==strcmp("-gmrt", argv[i]) ) { cmd.gmrtP = 1; continue; } if( 0==strcmp("-bcpm", argv[i]) ) { cmd.bcpmP = 1; continue; } if( 0==strcmp("-spigot", argv[i]) ) { cmd.spigotP = 1; continue; } if( 0==strcmp("-filterbank", argv[i]) ) { cmd.filterbankP = 1; continue; } if( 0==strcmp("-psrfits", argv[i]) ) { cmd.psrfitsP = 1; continue; } if( 0==strcmp("-noweights", argv[i]) ) { cmd.noweightsP = 1; continue; } if( 0==strcmp("-noscales", argv[i]) ) { cmd.noscalesP = 1; continue; } if( 0==strcmp("-nooffsets", argv[i]) ) { cmd.nooffsetsP = 1; continue; } if( 0==strcmp("-wapp", argv[i]) ) { cmd.wappP = 1; continue; } if( 0==strcmp("-window", argv[i]) ) { cmd.windowP = 1; continue; } if( 0==strcmp("-numwapps", argv[i]) ) { int keep = i; cmd.numwappsP = 1; i = getIntOpt(argc, argv, i, &cmd.numwapps, 1); cmd.numwappsC = i-keep; checkIntLower("-numwapps", &cmd.numwapps, cmd.numwappsC, 8); checkIntHigher("-numwapps", &cmd.numwapps, cmd.numwappsC, 1); continue; } if( 0==strcmp("-if", argv[i]) ) { int keep = i; cmd.ifsP = 1; i = getIntOpt(argc, argv, i, &cmd.ifs, 1); cmd.ifsC = i-keep; checkIntLower("-if", &cmd.ifs, cmd.ifsC, 1); checkIntHigher("-if", &cmd.ifs, cmd.ifsC, 0); continue; } if( 0==strcmp("-clip", argv[i]) ) { int keep = i; cmd.clipP = 1; i = getFloatOpt(argc, argv, i, &cmd.clip, 1); cmd.clipC = i-keep; checkFloatLower("-clip", &cmd.clip, cmd.clipC, 1000.0); checkFloatHigher("-clip", &cmd.clip, cmd.clipC, 0); continue; } if( 0==strcmp("-noclip", argv[i]) ) { cmd.noclipP = 1; continue; } if( 0==strcmp("-runavg", argv[i]) ) { cmd.runavgP = 1; continue; } if( 0==strcmp("-zerodm", argv[i]) ) { cmd.zerodmP = 1; continue; } if( 0==strcmp("-sub", argv[i]) ) { cmd.subP = 1; continue; } if( 0==strcmp("-subdm", argv[i]) ) { int keep = i; cmd.subdmP = 1; i = getDoubleOpt(argc, argv, i, &cmd.subdm, 1); cmd.subdmC = i-keep; checkDoubleLower("-subdm", &cmd.subdm, cmd.subdmC, 4000.0); checkDoubleHigher("-subdm", &cmd.subdm, cmd.subdmC, 0); continue; } if( 0==strcmp("-numout", argv[i]) ) { int keep = i; cmd.numoutP = 1; i = getIntOpt(argc, argv, i, &cmd.numout, 1); cmd.numoutC = i-keep; checkIntHigher("-numout", &cmd.numout, cmd.numoutC, 1); continue; } if( 0==strcmp("-nobary", argv[i]) ) { cmd.nobaryP = 1; continue; } if( 0==strcmp("-DE405", argv[i]) ) { cmd.de405P = 1; continue; } if( 0==strcmp("-lodm", argv[i]) ) { int keep = i; cmd.lodmP = 1; i = getDoubleOpt(argc, argv, i, &cmd.lodm, 1); cmd.lodmC = i-keep; checkDoubleHigher("-lodm", &cmd.lodm, cmd.lodmC, 0); continue; } if( 0==strcmp("-dmstep", argv[i]) ) { int keep = i; cmd.dmstepP = 1; i = getDoubleOpt(argc, argv, i, &cmd.dmstep, 1); cmd.dmstepC = i-keep; checkDoubleHigher("-dmstep", &cmd.dmstep, cmd.dmstepC, 0); continue; } if( 0==strcmp("-numdms", argv[i]) ) { int keep = i; cmd.numdmsP = 1; i = getIntOpt(argc, argv, i, &cmd.numdms, 1); cmd.numdmsC = i-keep; checkIntLower("-numdms", &cmd.numdms, cmd.numdmsC, 1000); checkIntHigher("-numdms", &cmd.numdms, cmd.numdmsC, 1); continue; } if( 0==strcmp("-nsub", argv[i]) ) { int keep = i; cmd.nsubP = 1; i = getIntOpt(argc, argv, i, &cmd.nsub, 1); cmd.nsubC = i-keep; checkIntLower("-nsub", &cmd.nsub, cmd.nsubC, 1024); checkIntHigher("-nsub", &cmd.nsub, cmd.nsubC, 1); continue; } if( 0==strcmp("-downsamp", argv[i]) ) { int keep = i; cmd.downsampP = 1; i = getIntOpt(argc, argv, i, &cmd.downsamp, 1); cmd.downsampC = i-keep; checkIntLower("-downsamp", &cmd.downsamp, cmd.downsampC, 128); checkIntHigher("-downsamp", &cmd.downsamp, cmd.downsampC, 1); continue; } if( 0==strcmp("-mask", argv[i]) ) { int keep = i; cmd.maskfileP = 1; i = getStringOpt(argc, argv, i, &cmd.maskfile, 1); cmd.maskfileC = i-keep; continue; } if( argv[i][0]=='-' ) { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; }/* for i */ if( !cmd.outfileP ) { missingErr("-o"); missingMandatory = 1; } if( missingMandatory ) exit(EXIT_FAILURE); /*@-mustfree*/ cmd.argv = argv+1; /*@=mustfree*/ cmd.argc -= 1; if( 1>cmd.argc ) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if( 16384<cmd.argc ) { fprintf(stderr, "%s: there should be at most 16384 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass*/ return &cmd; }
Cmdline * parseCmdline(int argc, char **argv) { int i; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for(i=1, cmd.argc=1; i<argc; i++) { if( 0==strcmp("--", argv[i]) ) { while( ++i<argc ) argv[cmd.argc++] = argv[i]; continue; } if( 0==strcmp("-ncand", argv[i]) ) { int keep = i; cmd.ncandP = 1; i = getIntOpt(argc, argv, i, &cmd.ncand, 1); cmd.ncandC = i-keep; checkIntLower("-ncand", &cmd.ncand, cmd.ncandC, 10000); checkIntHigher("-ncand", &cmd.ncand, cmd.ncandC, 1); continue; } if( 0==strcmp("-zlo", argv[i]) ) { int keep = i; cmd.zloP = 1; i = getIntOpt(argc, argv, i, &cmd.zlo, 1); cmd.zloC = i-keep; checkIntLower("-zlo", &cmd.zlo, cmd.zloC, 2000000); checkIntHigher("-zlo", &cmd.zlo, cmd.zloC, -2000000); continue; } if( 0==strcmp("-zhi", argv[i]) ) { int keep = i; cmd.zhiP = 1; i = getIntOpt(argc, argv, i, &cmd.zhi, 1); cmd.zhiC = i-keep; checkIntLower("-zhi", &cmd.zhi, cmd.zhiC, 2000000); checkIntHigher("-zhi", &cmd.zhi, cmd.zhiC, -2000000); continue; } if( 0==strcmp("-rlo", argv[i]) ) { int keep = i; cmd.rloP = 1; i = getIntOpt(argc, argv, i, &cmd.rlo, 1); cmd.rloC = i-keep; checkIntHigher("-rlo", &cmd.rlo, cmd.rloC, 0); continue; } if( 0==strcmp("-rhi", argv[i]) ) { int keep = i; cmd.rhiP = 1; i = getIntOpt(argc, argv, i, &cmd.rhi, 1); cmd.rhiC = i-keep; checkIntHigher("-rhi", &cmd.rhi, cmd.rhiC, 0); continue; } if( 0==strcmp("-flo", argv[i]) ) { int keep = i; cmd.floP = 1; i = getIntOpt(argc, argv, i, &cmd.flo, 1); cmd.floC = i-keep; checkIntHigher("-flo", &cmd.flo, cmd.floC, 0); continue; } if( 0==strcmp("-fhi", argv[i]) ) { int keep = i; cmd.fhiP = 1; i = getIntOpt(argc, argv, i, &cmd.fhi, 1); cmd.fhiC = i-keep; checkIntHigher("-fhi", &cmd.fhi, cmd.fhiC, 0); continue; } if( 0==strcmp("-lobin", argv[i]) ) { int keep = i; cmd.lobinP = 1; i = getIntOpt(argc, argv, i, &cmd.lobin, 1); cmd.lobinC = i-keep; checkIntHigher("-lobin", &cmd.lobin, cmd.lobinC, 0); continue; } if( 0==strcmp("-zapfile", argv[i]) ) { int keep = i; cmd.zapfileP = 1; i = getStringOpt(argc, argv, i, &cmd.zapfile, 1); cmd.zapfileC = i-keep; continue; } if( 0==strcmp("-baryv", argv[i]) ) { int keep = i; cmd.baryvP = 1; i = getDoubleOpt(argc, argv, i, &cmd.baryv, 1); cmd.baryvC = i-keep; checkDoubleLower("-baryv", &cmd.baryv, cmd.baryvC, 0.1); checkDoubleHigher("-baryv", &cmd.baryv, cmd.baryvC, -0.1); continue; } if( 0==strcmp("-photon", argv[i]) ) { cmd.photonP = 1; continue; } if( argv[i][0]=='-' ) { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; }/* for i */ /*@-mustfree*/ cmd.argv = argv+1; /*@=mustfree*/ cmd.argc -= 1; if( 1>cmd.argc ) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if( 1<cmd.argc ) { fprintf(stderr, "%s: there should be at most 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass*/ return &cmd; }
Cmdline * parseCmdline(int argc, char **argv) { int i; char missingMandatory = 0; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for(i=1, cmd.argc=1; i<argc; i++) { if( 0==strcmp("--", argv[i]) ) { while( ++i<argc ) argv[cmd.argc++] = argv[i]; continue; } if( 0==strcmp("-o", argv[i]) ) { int keep = i; cmd.outfileP = 1; i = getStringOpt(argc, argv, i, &cmd.outfile, 1); cmd.outfileC = i-keep; continue; } if( 0==strcmp("-pkmb", argv[i]) ) { cmd.pkmbP = 1; continue; } if( 0==strcmp("-gmrt", argv[i]) ) { cmd.gmrtP = 1; continue; } if( 0==strcmp("-bcpm", argv[i]) ) { cmd.bcpmP = 1; continue; } if( 0==strcmp("-spigot", argv[i]) ) { cmd.spigotP = 1; continue; } if( 0==strcmp("-filterbank", argv[i]) ) { cmd.filterbankP = 1; continue; } if( 0==strcmp("-psrfits", argv[i]) ) { cmd.psrfitsP = 1; continue; } if( 0==strcmp("-noweights", argv[i]) ) { cmd.noweightsP = 1; continue; } if( 0==strcmp("-noscales", argv[i]) ) { cmd.noscalesP = 1; continue; } if( 0==strcmp("-nooffsets", argv[i]) ) { cmd.nooffsetsP = 1; continue; } if( 0==strcmp("-wapp", argv[i]) ) { cmd.wappP = 1; continue; } if( 0==strcmp("-window", argv[i]) ) { cmd.windowP = 1; continue; } if( 0==strcmp("-numwapps", argv[i]) ) { int keep = i; cmd.numwappsP = 1; i = getIntOpt(argc, argv, i, &cmd.numwapps, 1); cmd.numwappsC = i-keep; checkIntLower("-numwapps", &cmd.numwapps, cmd.numwappsC, 8); checkIntHigher("-numwapps", &cmd.numwapps, cmd.numwappsC, 1); continue; } if( 0==strcmp("-if", argv[i]) ) { int keep = i; cmd.ifsP = 1; i = getIntOpt(argc, argv, i, &cmd.ifs, 1); cmd.ifsC = i-keep; checkIntLower("-if", &cmd.ifs, cmd.ifsC, 1); checkIntHigher("-if", &cmd.ifs, cmd.ifsC, 0); continue; } if( 0==strcmp("-clip", argv[i]) ) { int keep = i; cmd.clipP = 1; i = getFloatOpt(argc, argv, i, &cmd.clip, 1); cmd.clipC = i-keep; checkFloatLower("-clip", &cmd.clip, cmd.clipC, 1000.0); checkFloatHigher("-clip", &cmd.clip, cmd.clipC, 0); continue; } if( 0==strcmp("-noclip", argv[i]) ) { cmd.noclipP = 1; continue; } if( 0==strcmp("-xwin", argv[i]) ) { cmd.xwinP = 1; continue; } if( 0==strcmp("-nocompute", argv[i]) ) { cmd.nocomputeP = 1; continue; } if( 0==strcmp("-rfixwin", argv[i]) ) { cmd.rfixwinP = 1; continue; } if( 0==strcmp("-rfips", argv[i]) ) { cmd.rfipsP = 1; continue; } if( 0==strcmp("-time", argv[i]) ) { int keep = i; cmd.timeP = 1; i = getDoubleOpt(argc, argv, i, &cmd.time, 1); cmd.timeC = i-keep; checkDoubleHigher("-time", &cmd.time, cmd.timeC, 0); continue; } if( 0==strcmp("-blocks", argv[i]) ) { int keep = i; cmd.blocksP = 1; i = getIntOpt(argc, argv, i, &cmd.blocks, 1); cmd.blocksC = i-keep; checkIntHigher("-blocks", &cmd.blocks, cmd.blocksC, 1); continue; } if( 0==strcmp("-timesig", argv[i]) ) { int keep = i; cmd.timesigmaP = 1; i = getFloatOpt(argc, argv, i, &cmd.timesigma, 1); cmd.timesigmaC = i-keep; checkFloatHigher("-timesig", &cmd.timesigma, cmd.timesigmaC, 0); continue; } if( 0==strcmp("-freqsig", argv[i]) ) { int keep = i; cmd.freqsigmaP = 1; i = getFloatOpt(argc, argv, i, &cmd.freqsigma, 1); cmd.freqsigmaC = i-keep; checkFloatHigher("-freqsig", &cmd.freqsigma, cmd.freqsigmaC, 0); continue; } if( 0==strcmp("-chanfrac", argv[i]) ) { int keep = i; cmd.chantrigfracP = 1; i = getFloatOpt(argc, argv, i, &cmd.chantrigfrac, 1); cmd.chantrigfracC = i-keep; checkFloatLower("-chanfrac", &cmd.chantrigfrac, cmd.chantrigfracC, 1.0); checkFloatHigher("-chanfrac", &cmd.chantrigfrac, cmd.chantrigfracC, 0.0); continue; } if( 0==strcmp("-intfrac", argv[i]) ) { int keep = i; cmd.inttrigfracP = 1; i = getFloatOpt(argc, argv, i, &cmd.inttrigfrac, 1); cmd.inttrigfracC = i-keep; checkFloatLower("-intfrac", &cmd.inttrigfrac, cmd.inttrigfracC, 1.0); checkFloatHigher("-intfrac", &cmd.inttrigfrac, cmd.inttrigfracC, 0.0); continue; } if( 0==strcmp("-zapchan", argv[i]) ) { int keep = i; cmd.zapchanstrP = 1; i = getStringOpt(argc, argv, i, &cmd.zapchanstr, 1); cmd.zapchanstrC = i-keep; continue; } if( 0==strcmp("-zapints", argv[i]) ) { int keep = i; cmd.zapintsstrP = 1; i = getStringOpt(argc, argv, i, &cmd.zapintsstr, 1); cmd.zapintsstrC = i-keep; continue; } if( 0==strcmp("-mask", argv[i]) ) { int keep = i; cmd.maskfileP = 1; i = getStringOpt(argc, argv, i, &cmd.maskfile, 1); cmd.maskfileC = i-keep; continue; } if( argv[i][0]=='-' ) { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; }/* for i */ if( !cmd.outfileP ) { missingErr("-o"); missingMandatory = 1; } if( missingMandatory ) exit(EXIT_FAILURE); /*@-mustfree*/ cmd.argv = argv+1; /*@=mustfree*/ cmd.argc -= 1; if( 1>cmd.argc ) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if( 16384<cmd.argc ) { fprintf(stderr, "%s: there should be at most 16384 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass*/ return &cmd; }
Cmdline * parseCmdline(int argc, char **argv) { int i; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for(i=1, cmd.argc=1; i<argc; i++) { if( 0==strcmp("--", argv[i]) ) { while( ++i<argc ) argv[cmd.argc++] = argv[i]; continue; } if( 0==strcmp("-page", argv[i]) ) { cmd.pageP = 1; continue; } if( 0==strcmp("-byte", argv[i]) ) { cmd.bytP = 1; continue; } if( 0==strcmp("-b", argv[i]) ) { cmd.sbytP = 1; continue; } if( 0==strcmp("-float", argv[i]) ) { cmd.fltP = 1; continue; } if( 0==strcmp("-f", argv[i]) ) { cmd.sfltP = 1; continue; } if( 0==strcmp("-double", argv[i]) ) { cmd.dblP = 1; continue; } if( 0==strcmp("-d", argv[i]) ) { cmd.sdblP = 1; continue; } if( 0==strcmp("-fcomplex", argv[i]) ) { cmd.fcxP = 1; continue; } if( 0==strcmp("-fc", argv[i]) ) { cmd.sfcxP = 1; continue; } if( 0==strcmp("-dcomplex", argv[i]) ) { cmd.dcxP = 1; continue; } if( 0==strcmp("-dc", argv[i]) ) { cmd.sdcxP = 1; continue; } if( 0==strcmp("-short", argv[i]) ) { cmd.shtP = 1; continue; } if( 0==strcmp("-s", argv[i]) ) { cmd.sshtP = 1; continue; } if( 0==strcmp("-int", argv[i]) ) { cmd.igrP = 1; continue; } if( 0==strcmp("-i", argv[i]) ) { cmd.sigrP = 1; continue; } if( 0==strcmp("-long", argv[i]) ) { cmd.lngP = 1; continue; } if( 0==strcmp("-l", argv[i]) ) { cmd.slngP = 1; continue; } if( 0==strcmp("-rzwcand", argv[i]) ) { cmd.rzwP = 1; continue; } if( 0==strcmp("-rzw", argv[i]) ) { cmd.srzwP = 1; continue; } if( 0==strcmp("-bincand", argv[i]) ) { cmd.binP = 1; continue; } if( 0==strcmp("-bin", argv[i]) ) { cmd.sbinP = 1; continue; } if( 0==strcmp("-position", argv[i]) ) { cmd.posP = 1; continue; } if( 0==strcmp("-pos", argv[i]) ) { cmd.sposP = 1; continue; } if( 0==strcmp("-pkmb", argv[i]) ) { cmd.pkmbP = 1; continue; } if( 0==strcmp("-bcpm", argv[i]) ) { cmd.bcpmP = 1; continue; } if( 0==strcmp("-wapp", argv[i]) ) { cmd.wappP = 1; continue; } if( 0==strcmp("-spigot", argv[i]) ) { cmd.spigotP = 1; continue; } if( 0==strcmp("-filterbank", argv[i]) ) { cmd.filterbankP = 1; continue; } if( 0==strcmp("-psrfits", argv[i]) ) { cmd.psrfitsP = 1; continue; } if( 0==strcmp("-fortran", argv[i]) ) { cmd.fortranP = 1; continue; } if( 0==strcmp("-index", argv[i]) ) { int keep = i; cmd.indexP = 1; i = getIntOpts(argc, argv, i, &cmd.index, 0, 2); cmd.indexC = i-keep; checkIntHigher("-index", cmd.index, cmd.indexC, -1); continue; } if( 0==strcmp("-nph", argv[i]) ) { int keep = i; cmd.nphP = 1; i = getDoubleOpt(argc, argv, i, &cmd.nph, 1); cmd.nphC = i-keep; continue; } if( argv[i][0]=='-' ) { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; }/* for i */ /*@-mustfree*/ cmd.argv = argv+1; /*@=mustfree*/ cmd.argc -= 1; if( 1>cmd.argc ) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if( 1<cmd.argc ) { fprintf(stderr, "%s: there should be at most 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass*/ return &cmd; }
Cmdline * parseCmdline(int argc, char **argv) { int i; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for(i=1, cmd.argc=1; i<argc; i++) { if( 0==strcmp("--", argv[i]) ) { while( ++i<argc ) argv[cmd.argc++] = argv[i]; continue; } if( 0==strcmp("-o", argv[i]) ) { int keep = i; cmd.outfileP = 1; i = getStringOpt(argc, argv, i, &cmd.outfile, 1); cmd.outfileC = i-keep; continue; } if( 0==strcmp("-nohdr", argv[i]) ) { cmd.nohdrP = 1; continue; } if( 0==strcmp("-stdout", argv[i]) ) { cmd.stdoutP = 1; continue; } if( 0==strcmp("-floats", argv[i]) ) { cmd.floatsP = 1; continue; } if( 0==strcmp("-zerolags", argv[i]) ) { cmd.zerolagsP = 1; continue; } if( 0==strcmp("-skip", argv[i]) ) { int keep = i; cmd.skipP = 1; i = getIntOpt(argc, argv, i, &cmd.skip, 1); cmd.skipC = i-keep; checkIntHigher("-skip", &cmd.skip, cmd.skipC, 0); continue; } if( 0==strcmp("-numout", argv[i]) ) { int keep = i; cmd.numoutP = 1; i = getIntOpt(argc, argv, i, &cmd.numout, 1); cmd.numoutC = i-keep; checkIntHigher("-numout", &cmd.numout, cmd.numoutC, 0); continue; } if( 0==strcmp("-downsamp", argv[i]) ) { int keep = i; cmd.downsampP = 1; i = getIntOpt(argc, argv, i, &cmd.downsamp, 1); cmd.downsampC = i-keep; checkIntHigher("-downsamp", &cmd.downsamp, cmd.downsampC, 0); continue; } if( 0==strcmp("-lokill", argv[i]) ) { int keep = i; cmd.lokillP = 1; i = getIntOpt(argc, argv, i, &cmd.lokill, 1); cmd.lokillC = i-keep; checkIntHigher("-lokill", &cmd.lokill, cmd.lokillC, 0); continue; } if( 0==strcmp("-hikill", argv[i]) ) { int keep = i; cmd.hikillP = 1; i = getIntOpt(argc, argv, i, &cmd.hikill, 1); cmd.hikillC = i-keep; checkIntHigher("-hikill", &cmd.hikill, cmd.hikillC, 0); continue; } if( argv[i][0]=='-' ) { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; }/* for i */ /*@-mustfree*/ cmd.argv = argv+1; /*@=mustfree*/ cmd.argc -= 1; if( 1>cmd.argc ) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if( 1024<cmd.argc ) { fprintf(stderr, "%s: there should be at most 1024 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass*/ return &cmd; }
Cmdline *parseCmdline(int argc, char **argv) { int i; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for (i = 1, cmd.argc = 1; i < argc; i++) { if (0 == strcmp("--", argv[i])) { while (++i < argc) argv[cmd.argc++] = argv[i]; continue; } if (0 == strcmp("-phs", argv[i])) { int keep = i; cmd.phsP = 1; i = getDoubleOpt(argc, argv, i, &cmd.phs, 1); cmd.phsC = i - keep; checkDoubleLower("-phs", &cmd.phs, cmd.phsC, 1); checkDoubleHigher("-phs", &cmd.phs, cmd.phsC, 0); continue; } if (0 == strcmp("-p", argv[i])) { int keep = i; cmd.pP = 1; i = getDoubleOpt(argc, argv, i, &cmd.p, 1); cmd.pC = i - keep; checkDoubleHigher("-p", &cmd.p, cmd.pC, 0); continue; } if (0 == strcmp("-pd", argv[i])) { int keep = i; cmd.pdP = 1; i = getDoubleOpt(argc, argv, i, &cmd.pd, 1); cmd.pdC = i - keep; continue; } if (0 == strcmp("-pdd", argv[i])) { int keep = i; cmd.pddP = 1; i = getDoubleOpt(argc, argv, i, &cmd.pdd, 1); cmd.pddC = i - keep; continue; } if (0 == strcmp("-f", argv[i])) { int keep = i; cmd.fP = 1; i = getDoubleOpt(argc, argv, i, &cmd.f, 1); cmd.fC = i - keep; checkDoubleHigher("-f", &cmd.f, cmd.fC, 0); continue; } if (0 == strcmp("-fd", argv[i])) { int keep = i; cmd.fdP = 1; i = getDoubleOpt(argc, argv, i, &cmd.fd, 1); cmd.fdC = i - keep; continue; } if (0 == strcmp("-fdd", argv[i])) { int keep = i; cmd.fddP = 1; i = getDoubleOpt(argc, argv, i, &cmd.fdd, 1); cmd.fddC = i - keep; continue; } if (0 == strcmp("-n", argv[i])) { int keep = i; cmd.proflenP = 1; i = getIntOpt(argc, argv, i, &cmd.proflen, 1); cmd.proflenC = i - keep; continue; } if (0 == strcmp("-psr", argv[i])) { int keep = i; cmd.psrnameP = 1; i = getStringOpt(argc, argv, i, &cmd.psrname, 1); cmd.psrnameC = i - keep; continue; } if (0 == strcmp("-rzwcand", argv[i])) { int keep = i; cmd.rzwcandP = 1; i = getIntOpt(argc, argv, i, &cmd.rzwcand, 1); cmd.rzwcandC = i - keep; checkIntHigher("-rzwcand", &cmd.rzwcand, cmd.rzwcandC, 1); continue; } if (0 == strcmp("-rzwfile", argv[i])) { int keep = i; cmd.rzwfileP = 1; i = getStringOpt(argc, argv, i, &cmd.rzwfile, 1); cmd.rzwfileC = i - keep; continue; } if (0 == strcmp("-bincand", argv[i])) { int keep = i; cmd.bincandP = 1; i = getIntOpt(argc, argv, i, &cmd.bincand, 1); cmd.bincandC = i - keep; checkIntHigher("-bincand", &cmd.bincand, cmd.bincandC, 1); continue; } if (0 == strcmp("-onoff", argv[i])) { int keep = i; cmd.onoffP = 1; i = getStringOpt(argc, argv, i, &cmd.onoff, 1); cmd.onoffC = i - keep; continue; } if (0 == strcmp("-bin", argv[i])) { cmd.binaryP = 1; continue; } if (0 == strcmp("-pb", argv[i])) { int keep = i; cmd.pbP = 1; i = getDoubleOpt(argc, argv, i, &cmd.pb, 1); cmd.pbC = i - keep; checkDoubleHigher("-pb", &cmd.pb, cmd.pbC, 0); continue; } if (0 == strcmp("-x", argv[i])) { int keep = i; cmd.asinicP = 1; i = getDoubleOpt(argc, argv, i, &cmd.asinic, 1); cmd.asinicC = i - keep; checkDoubleHigher("-x", &cmd.asinic, cmd.asinicC, 0); continue; } if (0 == strcmp("-e", argv[i])) { int keep = i; cmd.eP = 1; i = getDoubleOpt(argc, argv, i, &cmd.e, 1); cmd.eC = i - keep; checkDoubleLower("-e", &cmd.e, cmd.eC, 0.9999999); checkDoubleHigher("-e", &cmd.e, cmd.eC, 0); continue; } if (0 == strcmp("-To", argv[i])) { int keep = i; cmd.ToP = 1; i = getDoubleOpt(argc, argv, i, &cmd.To, 1); cmd.ToC = i - keep; checkDoubleHigher("-To", &cmd.To, cmd.ToC, 0); continue; } if (0 == strcmp("-w", argv[i])) { int keep = i; cmd.wP = 1; i = getDoubleOpt(argc, argv, i, &cmd.w, 1); cmd.wC = i - keep; checkDoubleLower("-w", &cmd.w, cmd.wC, 360); checkDoubleHigher("-w", &cmd.w, cmd.wC, 0); continue; } if (0 == strcmp("-wdot", argv[i])) { int keep = i; cmd.wdotP = 1; i = getDoubleOpt(argc, argv, i, &cmd.wdot, 1); cmd.wdotC = i - keep; continue; } if (0 == strcmp("-xwin", argv[i])) { cmd.xwinP = 1; continue; } if (0 == strcmp("-ps", argv[i])) { cmd.psP = 1; continue; } if (0 == strcmp("-both", argv[i])) { cmd.bothP = 1; continue; } if (0 == strcmp("-disp", argv[i])) { cmd.dispP = 1; continue; } if (0 == strcmp("-mak", argv[i])) { cmd.makefileP = 1; continue; } if (0 == strcmp("-noerr", argv[i])) { cmd.noerrP = 1; continue; } if (argv[i][0] == '-') { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; } /* for i */ /*@-mustfree */ cmd.argv = argv + 1; /*@=mustfree */ cmd.argc -= 1; if (1 > cmd.argc) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if (1 < cmd.argc) { fprintf(stderr, "%s: there should be at most 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass */ return &cmd; }
Cmdline *parseCmdline(int argc, char **argv) { int i; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for (i = 1, cmd.argc = 1; i < argc; i++) { if (0 == strcmp("--", argv[i])) { while (++i < argc) argv[cmd.argc++] = argv[i]; continue; } if (0 == strcmp("-ncpus", argv[i])) { int keep = i; cmd.ncpusP = 1; i = getIntOpt(argc, argv, i, &cmd.ncpus, 1); cmd.ncpusC = i - keep; checkIntHigher("-ncpus", &cmd.ncpus, cmd.ncpusC, 1); continue; } if (0 == strcmp("-lobin", argv[i])) { int keep = i; cmd.lobinP = 1; i = getIntOpt(argc, argv, i, &cmd.lobin, 1); cmd.lobinC = i - keep; checkIntHigher("-lobin", &cmd.lobin, cmd.lobinC, 0); continue; } if (0 == strcmp("-numharm", argv[i])) { int keep = i; cmd.numharmP = 1; i = getIntOpt(argc, argv, i, &cmd.numharm, 1); cmd.numharmC = i - keep; checkIntLower("-numharm", &cmd.numharm, cmd.numharmC, 16); checkIntHigher("-numharm", &cmd.numharm, cmd.numharmC, 1); continue; } if (0 == strcmp("-zmax", argv[i])) { int keep = i; cmd.zmaxP = 1; i = getIntOpt(argc, argv, i, &cmd.zmax, 1); cmd.zmaxC = i - keep; checkIntLower("-zmax", &cmd.zmax, cmd.zmaxC, 1200); checkIntHigher("-zmax", &cmd.zmax, cmd.zmaxC, 0); continue; } if (0 == strcmp("-sigma", argv[i])) { int keep = i; cmd.sigmaP = 1; i = getFloatOpt(argc, argv, i, &cmd.sigma, 1); cmd.sigmaC = i - keep; checkFloatLower("-sigma", &cmd.sigma, cmd.sigmaC, 30.0); checkFloatHigher("-sigma", &cmd.sigma, cmd.sigmaC, 1.0); continue; } if (0 == strcmp("-rlo", argv[i])) { int keep = i; cmd.rloP = 1; i = getDoubleOpt(argc, argv, i, &cmd.rlo, 1); cmd.rloC = i - keep; checkDoubleHigher("-rlo", &cmd.rlo, cmd.rloC, 0.0); continue; } if (0 == strcmp("-rhi", argv[i])) { int keep = i; cmd.rhiP = 1; i = getDoubleOpt(argc, argv, i, &cmd.rhi, 1); cmd.rhiC = i - keep; checkDoubleHigher("-rhi", &cmd.rhi, cmd.rhiC, 0.0); continue; } if (0 == strcmp("-flo", argv[i])) { int keep = i; cmd.floP = 1; i = getDoubleOpt(argc, argv, i, &cmd.flo, 1); cmd.floC = i - keep; checkDoubleHigher("-flo", &cmd.flo, cmd.floC, 0.0); continue; } if (0 == strcmp("-fhi", argv[i])) { int keep = i; cmd.fhiP = 1; i = getDoubleOpt(argc, argv, i, &cmd.fhi, 1); cmd.fhiC = i - keep; checkDoubleHigher("-fhi", &cmd.fhi, cmd.fhiC, 0.0); continue; } if (0 == strcmp("-inmem", argv[i])) { cmd.inmemP = 1; continue; } if (0 == strcmp("-photon", argv[i])) { cmd.photonP = 1; continue; } if (0 == strcmp("-median", argv[i])) { cmd.medianP = 1; continue; } if (0 == strcmp("-locpow", argv[i])) { cmd.locpowP = 1; continue; } if (0 == strcmp("-zaplist", argv[i])) { int keep = i; cmd.zaplistP = 1; i = getStringOpt(argc, argv, i, &cmd.zaplist, 1); cmd.zaplistC = i - keep; continue; } if (0 == strcmp("-baryv", argv[i])) { int keep = i; cmd.baryvP = 1; i = getDoubleOpt(argc, argv, i, &cmd.baryv, 1); cmd.baryvC = i - keep; checkDoubleLower("-baryv", &cmd.baryv, cmd.baryvC, 0.1); checkDoubleHigher("-baryv", &cmd.baryv, cmd.baryvC, -0.1); continue; } if (0 == strcmp("-otheropt", argv[i])) { cmd.otheroptP = 1; continue; } if (0 == strcmp("-noharmpolish", argv[i])) { cmd.noharmpolishP = 1; continue; } if (0 == strcmp("-noharmremove", argv[i])) { cmd.noharmremoveP = 1; continue; } if (argv[i][0] == '-') { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; } /* for i */ /*@-mustfree */ cmd.argv = argv + 1; /*@=mustfree */ cmd.argc -= 1; if (1 > cmd.argc) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if (1 < cmd.argc) { fprintf(stderr, "%s: there should be at most 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass */ return &cmd; }
Cmdline * parseCmdline(int argc, char **argv) { int i; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for(i=1, cmd.argc=1; i<argc; i++) { if( 0==strcmp("--", argv[i]) ) { while( ++i<argc ) argv[cmd.argc++] = argv[i]; continue; } if( 0==strcmp("-ncand", argv[i]) ) { int keep = i; cmd.ncandP = 1; i = getIntOpt(argc, argv, i, &cmd.ncand, 1); cmd.ncandC = i-keep; checkIntLower("-ncand", &cmd.ncand, cmd.ncandC, 10000); checkIntHigher("-ncand", &cmd.ncand, cmd.ncandC, 1); continue; } if( 0==strcmp("-minfft", argv[i]) ) { int keep = i; cmd.minfftP = 1; i = getIntOpt(argc, argv, i, &cmd.minfft, 1); cmd.minfftC = i-keep; checkIntLower("-minfft", &cmd.minfft, cmd.minfftC, 1048576); checkIntHigher("-minfft", &cmd.minfft, cmd.minfftC, 8); continue; } if( 0==strcmp("-maxfft", argv[i]) ) { int keep = i; cmd.maxfftP = 1; i = getIntOpt(argc, argv, i, &cmd.maxfft, 1); cmd.maxfftC = i-keep; checkIntLower("-maxfft", &cmd.maxfft, cmd.maxfftC, 1048576); checkIntHigher("-maxfft", &cmd.maxfft, cmd.maxfftC, 8); continue; } if( 0==strcmp("-flo", argv[i]) ) { int keep = i; cmd.floP = 1; i = getFloatOpt(argc, argv, i, &cmd.flo, 1); cmd.floC = i-keep; checkFloatHigher("-flo", &cmd.flo, cmd.floC, 0); continue; } if( 0==strcmp("-fhi", argv[i]) ) { int keep = i; cmd.fhiP = 1; i = getFloatOpt(argc, argv, i, &cmd.fhi, 1); cmd.fhiC = i-keep; checkFloatHigher("-fhi", &cmd.fhi, cmd.fhiC, 0); continue; } if( 0==strcmp("-rlo", argv[i]) ) { int keep = i; cmd.rloP = 1; i = getIntOpt(argc, argv, i, &cmd.rlo, 1); cmd.rloC = i-keep; checkIntHigher("-rlo", &cmd.rlo, cmd.rloC, 0); continue; } if( 0==strcmp("-rhi", argv[i]) ) { int keep = i; cmd.rhiP = 1; i = getIntOpt(argc, argv, i, &cmd.rhi, 1); cmd.rhiC = i-keep; checkIntHigher("-rhi", &cmd.rhi, cmd.rhiC, 0); continue; } if( 0==strcmp("-lobin", argv[i]) ) { int keep = i; cmd.lobinP = 1; i = getIntOpt(argc, argv, i, &cmd.lobin, 1); cmd.lobinC = i-keep; checkIntHigher("-lobin", &cmd.lobin, cmd.lobinC, 0); continue; } if( 0==strcmp("-overlap", argv[i]) ) { int keep = i; cmd.overlapP = 1; i = getDoubleOpt(argc, argv, i, &cmd.overlap, 1); cmd.overlapC = i-keep; checkDoubleLower("-overlap", &cmd.overlap, cmd.overlapC, 1.0); checkDoubleHigher("-overlap", &cmd.overlap, cmd.overlapC, 0.05); continue; } if( 0==strcmp("-harmsum", argv[i]) ) { int keep = i; cmd.harmsumP = 1; i = getIntOpt(argc, argv, i, &cmd.harmsum, 1); cmd.harmsumC = i-keep; checkIntLower("-harmsum", &cmd.harmsum, cmd.harmsumC, 20); checkIntHigher("-harmsum", &cmd.harmsum, cmd.harmsumC, 1); continue; } if( 0==strcmp("-numbetween", argv[i]) ) { int keep = i; cmd.numbetweenP = 1; i = getIntOpt(argc, argv, i, &cmd.numbetween, 1); cmd.numbetweenC = i-keep; checkIntLower("-numbetween", &cmd.numbetween, cmd.numbetweenC, 16); checkIntHigher("-numbetween", &cmd.numbetween, cmd.numbetweenC, 1); continue; } if( 0==strcmp("-stack", argv[i]) ) { int keep = i; cmd.stackP = 1; i = getIntOpt(argc, argv, i, &cmd.stack, 1); cmd.stackC = i-keep; checkIntHigher("-stack", &cmd.stack, cmd.stackC, 0); continue; } if( 0==strcmp("-interbin", argv[i]) ) { cmd.interbinP = 1; continue; } if( 0==strcmp("-noalias", argv[i]) ) { cmd.noaliasP = 1; continue; } if( argv[i][0]=='-' ) { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; }/* for i */ /*@-mustfree*/ cmd.argv = argv+1; /*@=mustfree*/ cmd.argc -= 1; if( 1>cmd.argc ) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if( 1<cmd.argc ) { fprintf(stderr, "%s: there should be at most 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass*/ return &cmd; }
Cmdline * parseCmdline(int argc, char **argv) { int i; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for(i=1, cmd.argc=1; i<argc; i++) { if( 0==strcmp("--", argv[i]) ) { while( ++i<argc ) argv[cmd.argc++] = argv[i]; continue; } if( 0==strcmp("-plo", argv[i]) ) { int keep = i; cmd.ploP = 1; i = getDoubleOpt(argc, argv, i, &cmd.plo, 1); cmd.ploC = i-keep; checkDoubleHigher("-plo", &cmd.plo, cmd.ploC, 0); continue; } if( 0==strcmp("-phi", argv[i]) ) { int keep = i; cmd.phiP = 1; i = getDoubleOpt(argc, argv, i, &cmd.phi, 1); cmd.phiC = i-keep; checkDoubleHigher("-phi", &cmd.phi, cmd.phiC, 0); continue; } if( 0==strcmp("-rlo", argv[i]) ) { int keep = i; cmd.rloP = 1; i = getDoubleOpt(argc, argv, i, &cmd.rlo, 1); cmd.rloC = i-keep; checkDoubleHigher("-rlo", &cmd.rlo, cmd.rloC, 0); continue; } if( 0==strcmp("-rhi", argv[i]) ) { int keep = i; cmd.rhiP = 1; i = getDoubleOpt(argc, argv, i, &cmd.rhi, 1); cmd.rhiC = i-keep; checkDoubleHigher("-rhi", &cmd.rhi, cmd.rhiC, 0); continue; } if( 0==strcmp("-psr", argv[i]) ) { int keep = i; cmd.psrnameP = 1; i = getStringOpt(argc, argv, i, &cmd.psrname, 1); cmd.psrnameC = i-keep; continue; } if( 0==strcmp("-candnum", argv[i]) ) { int keep = i; cmd.candnumP = 1; i = getIntOpt(argc, argv, i, &cmd.candnum, 1); cmd.candnumC = i-keep; checkIntHigher("-candnum", &cmd.candnum, cmd.candnumC, 1); continue; } if( 0==strcmp("-candfile", argv[i]) ) { int keep = i; cmd.candfileP = 1; i = getStringOpt(argc, argv, i, &cmd.candfile, 1); cmd.candfileC = i-keep; continue; } if( 0==strcmp("-usr", argv[i]) ) { cmd.usrP = 1; continue; } if( 0==strcmp("-pb", argv[i]) ) { int keep = i; cmd.pbP = 1; i = getDoubleOpt(argc, argv, i, &cmd.pb, 1); cmd.pbC = i-keep; checkDoubleHigher("-pb", &cmd.pb, cmd.pbC, 0); continue; } if( 0==strcmp("-x", argv[i]) ) { int keep = i; cmd.asinicP = 1; i = getDoubleOpt(argc, argv, i, &cmd.asinic, 1); cmd.asinicC = i-keep; checkDoubleHigher("-x", &cmd.asinic, cmd.asinicC, 0); continue; } if( 0==strcmp("-e", argv[i]) ) { int keep = i; cmd.eP = 1; i = getDoubleOpt(argc, argv, i, &cmd.e, 1); cmd.eC = i-keep; checkDoubleLower("-e", &cmd.e, cmd.eC, 0.9999999); checkDoubleHigher("-e", &cmd.e, cmd.eC, 0); continue; } if( 0==strcmp("-To", argv[i]) ) { int keep = i; cmd.ToP = 1; i = getDoubleOpt(argc, argv, i, &cmd.To, 1); cmd.ToC = i-keep; checkDoubleHigher("-To", &cmd.To, cmd.ToC, 0); continue; } if( 0==strcmp("-w", argv[i]) ) { int keep = i; cmd.wP = 1; i = getDoubleOpt(argc, argv, i, &cmd.w, 1); cmd.wC = i-keep; checkDoubleLower("-w", &cmd.w, cmd.wC, 360); checkDoubleHigher("-w", &cmd.w, cmd.wC, 0); continue; } if( 0==strcmp("-wdot", argv[i]) ) { int keep = i; cmd.wdotP = 1; i = getDoubleOpt(argc, argv, i, &cmd.wdot, 1); cmd.wdotC = i-keep; continue; } if( 0==strcmp("-mak", argv[i]) ) { cmd.makefileP = 1; continue; } if( argv[i][0]=='-' ) { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; }/* for i */ /*@-mustfree*/ cmd.argv = argv+1; /*@=mustfree*/ cmd.argc -= 1; if( 1>cmd.argc ) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if( 1<cmd.argc ) { fprintf(stderr, "%s: there should be at most 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass*/ return &cmd; }
Cmdline * parseCmdline(int argc, char **argv) { int i; char missingMandatory = 0; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for(i=1, cmd.argc=1; i<argc; i++) { if( 0==strcmp("--", argv[i]) ) { while( ++i<argc ) argv[cmd.argc++] = argv[i]; continue; } if( 0==strcmp("-factor", argv[i]) ) { int keep = i; cmd.factorP = 1; i = getIntOpt(argc, argv, i, &cmd.factor, 1); cmd.factorC = i-keep; checkIntLower("-factor", &cmd.factor, cmd.factorC, 100); checkIntHigher("-factor", &cmd.factor, cmd.factorC, 1); continue; } if( 0==strcmp("-o", argv[i]) ) { int keep = i; cmd.outfileP = 1; i = getStringOpt(argc, argv, i, &cmd.outfile, 1); cmd.outfileC = i-keep; continue; } if( argv[i][0]=='-' ) { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; }/* for i */ if( !cmd.factorP ) { missingErr("-factor"); missingMandatory = 1; } if( missingMandatory ) exit(EXIT_FAILURE); /*@-mustfree*/ cmd.argv = argv+1; /*@=mustfree*/ cmd.argc -= 1; if( 1>cmd.argc ) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if( 1<cmd.argc ) { fprintf(stderr, "%s: there should be at most 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass*/ return &cmd; }
Cmdline * parseCmdline(int argc, char **argv) { int i; char missingMandatory = 0; Program = argv[0]; cmd.full_cmd_line = catArgv(argc, argv); for(i=1, cmd.argc=1; i<argc; i++) { if( 0==strcmp("--", argv[i]) ) { while( ++i<argc ) argv[cmd.argc++] = argv[i]; continue; } if( 0==strcmp("-ncpus", argv[i]) ) { int keep = i; cmd.ncpusP = 1; i = getIntOpt(argc, argv, i, &cmd.ncpus, 1); cmd.ncpusC = i-keep; checkIntHigher("-ncpus", &cmd.ncpus, cmd.ncpusC, 1); continue; } if( 0==strcmp("-o", argv[i]) ) { int keep = i; cmd.outfileP = 1; i = getStringOpt(argc, argv, i, &cmd.outfile, 1); cmd.outfileC = i-keep; continue; } if( 0==strcmp("-filterbank", argv[i]) ) { cmd.filterbankP = 1; continue; } if( 0==strcmp("-psrfits", argv[i]) ) { cmd.psrfitsP = 1; continue; } if( 0==strcmp("-noweights", argv[i]) ) { cmd.noweightsP = 1; continue; } if( 0==strcmp("-noscales", argv[i]) ) { cmd.noscalesP = 1; continue; } if( 0==strcmp("-nooffsets", argv[i]) ) { cmd.nooffsetsP = 1; continue; } if( 0==strcmp("-window", argv[i]) ) { cmd.windowP = 1; continue; } if( 0==strcmp("-if", argv[i]) ) { int keep = i; cmd.ifsP = 1; i = getIntOpt(argc, argv, i, &cmd.ifs, 1); cmd.ifsC = i-keep; checkIntLower("-if", &cmd.ifs, cmd.ifsC, 1); checkIntHigher("-if", &cmd.ifs, cmd.ifsC, 0); continue; } if( 0==strcmp("-clip", argv[i]) ) { int keep = i; cmd.clipP = 1; i = getFloatOpt(argc, argv, i, &cmd.clip, 1); cmd.clipC = i-keep; checkFloatLower("-clip", &cmd.clip, cmd.clipC, 1000.0); checkFloatHigher("-clip", &cmd.clip, cmd.clipC, 0); continue; } if( 0==strcmp("-noclip", argv[i]) ) { cmd.noclipP = 1; continue; } if( 0==strcmp("-invert", argv[i]) ) { cmd.invertP = 1; continue; } if( 0==strcmp("-zerodm", argv[i]) ) { cmd.zerodmP = 1; continue; } if( 0==strcmp("-nobary", argv[i]) ) { cmd.nobaryP = 1; continue; } if( 0==strcmp("-shorts", argv[i]) ) { cmd.shortsP = 1; continue; } if( 0==strcmp("-numout", argv[i]) ) { int keep = i; cmd.numoutP = 1; i = getLongOpt(argc, argv, i, &cmd.numout, 1); cmd.numoutC = i-keep; checkLongHigher("-numout", &cmd.numout, cmd.numoutC, 1); continue; } if( 0==strcmp("-downsamp", argv[i]) ) { int keep = i; cmd.downsampP = 1; i = getIntOpt(argc, argv, i, &cmd.downsamp, 1); cmd.downsampC = i-keep; checkIntLower("-downsamp", &cmd.downsamp, cmd.downsampC, 128); checkIntHigher("-downsamp", &cmd.downsamp, cmd.downsampC, 1); continue; } if( 0==strcmp("-offset", argv[i]) ) { int keep = i; cmd.offsetP = 1; i = getLongOpt(argc, argv, i, &cmd.offset, 1); cmd.offsetC = i-keep; checkLongHigher("-offset", &cmd.offset, cmd.offsetC, 0); continue; } if( 0==strcmp("-start", argv[i]) ) { int keep = i; cmd.startP = 1; i = getDoubleOpt(argc, argv, i, &cmd.start, 1); cmd.startC = i-keep; checkDoubleLower("-start", &cmd.start, cmd.startC, 1.0); checkDoubleHigher("-start", &cmd.start, cmd.startC, 0.0); continue; } if( 0==strcmp("-dm", argv[i]) ) { int keep = i; cmd.dmP = 1; i = getDoubleOpt(argc, argv, i, &cmd.dm, 1); cmd.dmC = i-keep; checkDoubleHigher("-dm", &cmd.dm, cmd.dmC, 0); continue; } if( 0==strcmp("-mask", argv[i]) ) { int keep = i; cmd.maskfileP = 1; i = getStringOpt(argc, argv, i, &cmd.maskfile, 1); cmd.maskfileC = i-keep; continue; } if( 0==strcmp("-ignorechan", argv[i]) ) { int keep = i; cmd.ignorechanstrP = 1; i = getStringOpt(argc, argv, i, &cmd.ignorechanstr, 1); cmd.ignorechanstrC = i-keep; continue; } if( argv[i][0]=='-' ) { fprintf(stderr, "\n%s: unknown option `%s'\n\n", Program, argv[i]); usage(); } argv[cmd.argc++] = argv[i]; }/* for i */ if( !cmd.outfileP ) { missingErr("-o"); missingMandatory = 1; } if( missingMandatory ) exit(EXIT_FAILURE); /*@-mustfree*/ cmd.argv = argv+1; /*@=mustfree*/ cmd.argc -= 1; if( 1>cmd.argc ) { fprintf(stderr, "%s: there should be at least 1 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } if( 512<cmd.argc ) { fprintf(stderr, "%s: there should be at most 512 non-option argument(s)\n", Program); exit(EXIT_FAILURE); } /*@-compmempass*/ return &cmd; }