IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 5, 2006, 11:46:36 AM (20 years ago)
Author:
jhoblitt
Message:

always use the PXTOOL_MODE macro

File:
1 edited

Legend:

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

    r7037 r7815  
    66
    77#include "pxtools.h"
    8 
     8#include "dettool.h"
     9
     10// this function can not fail -- exits on error
    911bool p0searchConfig(pxConfig *config, int argc, char **argv) {
    1012    if (!config) {
     
    1214    }
    1315
    14     config->modules = pmConfigRead(&argc, argv);
    15 
    16     if (! config->modules) {
    17         psError(PS_ERR_UNKNOWN, false, "Can't find site configuration!\n");
    18         exit(EXIT_FAILURE);
    19     }
    20 
    21     int N;
    22     config->mode = PX_MODE_NONE;
    23     if ((N = psArgumentGet (argc, argv, "-pending"))) {
    24         psArgumentRemove (N, &argc, argv);
    25         if (config->mode) {
    26             psError(PS_ERR_UNKNOWN, true, "only one mode selection is allowed");
    27         }
    28         config->mode = PX_MODE_PENDING;
    29     }
    30     if ((N = psArgumentGet (argc, argv, "-update"))) {
    31         psArgumentRemove (N, &argc, argv);
    32         if (config->mode) {
    33             psError(PS_ERR_UNKNOWN, true, "only one mode selection is allowed");
    34         }
    35         config->mode = PX_MODE_UPDATE;
    36     }
    37 
    38     // paul's argument parsing convention requires: -key value
    39     // Parse other command-line arguments
    40     psMetadata *args = psMetadataAlloc();
    41     psMetadataAddStr(args , PS_LIST_TAIL, "-pending", 0,
    42         "examine pending image table, write ppImage output", "");
    43     psMetadataAddStr(args , PS_LIST_TAIL, "-update",  0,
    44         "update pending image table", "");
    45 
    46 
    47     // -pending search
     16    // setup site config
     17    config->modules = pmConfigRead(argc, argv);
     18    if (!config->modules) {
     19        psError(PS_ERR_UNKNOWN, false, "Can't find site configuration");
     20        goto FAIL;
     21    }
     22    argc = config->argc;
     23
     24    // -pending
    4825    psMetadata *pendingArgs = psMetadataAlloc();
    4926    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-exp_id",  0,
     
    5936
    6037
    61     // -update inputs
     38    // -update
    6239    psMetadata *updateArgs = psMetadataAlloc();
    6340    psMetadataAddStr(updateArgs, PS_LIST_TAIL, "-exp_id",  0,
     
    7249        "define URL", "");
    7350
     51#define PXTOOL_MODE(option, modeval, argset) \
     52    if ((N = psArgumentGet (argc, argv, option))) { \
     53        psArgumentRemove (N, &argc, argv); \
     54        if (config->mode) { \
     55            psError(PS_ERR_UNKNOWN, true, "only one mode selection is allowed"); \
     56        } \
     57        config->mode = modeval; \
     58        config->args = psMemIncrRefCounter(argset); \
     59    }
     60
     61    // find which mode we're running under
     62    PXTOOL_MODE("-pending",     P0SEARCH_MODE_PENDING,      pendingArgs);
     63    PXTOOL_MODE("-update",      P0SEARCH_MODE_UPDATE,       updatergs);
     64
     65
    7466    bool argErr = false;
    75     if (config->mode == PX_MODE_NONE) {
     67    if (config->mode == P0SEARCH_MODE_NONE) {
    7668        argErr = true;
    7769        fprintf (stderr, "mode argument is required\n");
     
    8375    if (argErr) {
    8476        printf("\nPan-STARRS Phase 0 Search Tool\n");
    85         printf("Usage: %s <mode> [<options>]\n\n", argv[0]);
     77        printf("Usage: %s <mode> [-update|-pending]\n\n", argv[0]);
    8678        printf(" <mode> : -pending | -update\n\n");
    8779        fprintf (stdout, "-pending ");
    8880        psArgumentHelp(pendingArgs);
     81        psFree(pendingArgs);
    8982        fprintf (stdout, "-update ");
    9083        psArgumentHelp(updateArgs);
    91         psFree(args);
    92         psFree(pendingArgs);
    9384        psFree(updateArgs);
    94         exit(EXIT_FAILURE);
    95     }
    96 
    97     // XXX why is "" being returned when -[foo] isn't specified?
    98 #define EMPTY_TO_NULL_STRING(var) \
    99     if (var != NULL && strcmp(var, "") == 0) { \
    100         var = NULL; \
    101     }
     85
     86        goto FAIL;
     87    }
     88
     89    psFree(pendingArgs);
     90    psFree(updateArgs);
     91
     92    // setup search criterion
     93#define addWhereStr(name) \
     94    if ((str = psMetadataLookupStr(&status, config->args, "-" #name))) { \
     95        if (!psMetadataAddStr(config->where, PS_LIST_TAIL, #name, 0, "==", str)) {\
     96            psError(PS_ERR_UNKNOWN, false, "failed to add item " #name); \
     97            goto FAIL; \
     98        } \
     99    }
     100
     101    // generate SQL where claus
     102    config->where = psMetadataAlloc();
     103
     104{
     105    psString str = NULL;
     106    int n = 0;
     107    bool status = false;
     108    bool boolean = false;
     109
    102110
    103111    switch (config->mode) {
     
    196204    if (!config->dbh) {
    197205        psError(PS_ERR_UNKNOWN, false, "Can't configure database");
    198         exit(EXIT_FAILURE);
    199     }
    200 
    201     return true;
     206        goto FAIL;
     207    }
     208
     209    // save argv/argc
     210    config->argv = argv;
     211    config->argc = argc;
     212
     213
     214    return config;
     215
     216FAIL:
     217    psFree(config);
     218    pmConfigDone();
     219    psLibFinalize();
     220    exit(EXIT_FAILURE);
    202221}
Note: See TracChangeset for help on using the changeset viewer.