IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 31, 2007, 2:58:32 PM (19 years ago)
Author:
jhoblitt
Message:

convert to mulit-level option help

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/detselectConfig.c

    r11856 r13578  
    7878            "use the simple output format", false);
    7979   
    80 #define PXTOOL_MODE(option, modeval, argset) \
    81 { \
    82     int N = 0; \
    83     if ((N = psArgumentGet (argc, argv, option))) { \
    84         psArgumentRemove (N, &argc, argv); \
    85         if (config->mode) { \
    86             psError(PS_ERR_UNKNOWN, true, "only one mode selection is allowed"); \
    87             psFree(config); \
    88             return NULL; \
    89         } \
    90         config->mode = modeval; \
    91         config->args = psMemIncrRefCounter(argset); \
    92     } \
    93     if (!psMetadataAddMetadata(argSets, PS_LIST_TAIL, option, 0, NULL, argset)) {;\
    94         psError(PS_ERR_UNKNOWN, false, "failed to add argset for %s", option);\
    95     } \
    96     psFree(argset); \
    97 }
    98 
    9980    psMetadata *argSets = psMetadataAlloc();
    100     // find which mode we're running under
    101     PXTOOL_MODE("-search",  DETSELECT_MODE_SEARCH, searchArgs);
    102     PXTOOL_MODE("-select",  DETSELECT_MODE_SELECT, selectArgs);
    103 
    104     bool argErr = false;
    105     if (config->mode == DETSELECT_MODE_NONE) {
    106         argErr = true;
    107         fprintf (stderr, "mode argument is required\n");
    108     } else if (! psArgumentParse(config->args, &argc, argv) || argc != 1) {
    109         argErr = true;
    110         fprintf (stderr, "error parsing arguments\n");
    111     }
    112 
    113     if (argErr) {
    114         printf("\nPan-STARRS detrend select Tool\n");
    115         printf("Usage: %s <mode> [<options>]\n\n", argv[0]);
    116         printf(" <mode> :\n\n");
    117 
    118         psMetadataIterator *iter = psMetadataIteratorAlloc(argSets, 0, NULL);
    119         psMetadataItem *item = NULL;
    120         while ((item = psMetadataGetAndIncrement(iter))) {
    121             if (!item->type == PS_DATA_METADATA) {
    122                 psAbort("all options must be specified as a metadata");            }
    123 
    124             fprintf(stdout, "%s ", item->name);
    125             psArgumentHelp(item->data.md);
    126         }
    127         psFree(iter);
    128 
     81    psMetadata *modes = psMetadataAlloc();
     82
     83    PXTOOL_ADD_MODE("-search",  "search for an appropriate detrend", DETSELECT_MODE_SEARCH, searchArgs);
     84    PXTOOL_ADD_MODE("-select",  "retreive detrend information", DETSELECT_MODE_SELECT, selectArgs);
     85
     86    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
     87        psError(PS_ERR_UNKNOWN, true, "option parsing failed");
    12988        psFree(argSets);
     89        psFree(modes);
    13090        psFree(config);
    13191        return NULL;
     
    13393
    13494    psFree(argSets);
     95    psFree(modes);
    13596
    13697    // setup search criterion
     
    262223    }
    263224
    264     // save argv/argc
    265     config->argv = argv;
    266     config->argc = argc;
    267 
    268225    return config;
    269226}
Note: See TracChangeset for help on using the changeset viewer.