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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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;
}