Changeset 7815 for trunk/ippTools/src/regtoolConfig.c
- Timestamp:
- Jul 5, 2006, 11:46:36 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/regtoolConfig.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/regtoolConfig.c
r7037 r7815 6 6 7 7 #include "pxtools.h" 8 8 #include "dettool.h" 9 10 // this function can not fail -- exits on error 9 11 bool p0searchConfig(pxConfig *config, int argc, char **argv) { 10 12 if (!config) { … … 12 14 } 13 15 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 48 25 psMetadata *pendingArgs = psMetadataAlloc(); 49 26 psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-exp_id", 0, … … 59 36 60 37 61 // -update inputs38 // -update 62 39 psMetadata *updateArgs = psMetadataAlloc(); 63 40 psMetadataAddStr(updateArgs, PS_LIST_TAIL, "-exp_id", 0, … … 72 49 "define URL", ""); 73 50 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 74 66 bool argErr = false; 75 if (config->mode == P X_MODE_NONE) {67 if (config->mode == P0SEARCH_MODE_NONE) { 76 68 argErr = true; 77 69 fprintf (stderr, "mode argument is required\n"); … … 83 75 if (argErr) { 84 76 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]); 86 78 printf(" <mode> : -pending | -update\n\n"); 87 79 fprintf (stdout, "-pending "); 88 80 psArgumentHelp(pendingArgs); 81 psFree(pendingArgs); 89 82 fprintf (stdout, "-update "); 90 83 psArgumentHelp(updateArgs); 91 psFree(args);92 psFree(pendingArgs);93 84 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 102 110 103 111 switch (config->mode) { … … 196 204 if (!config->dbh) { 197 205 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 216 FAIL: 217 psFree(config); 218 pmConfigDone(); 219 psLibFinalize(); 220 exit(EXIT_FAILURE); 202 221 }
Note:
See TracChangeset
for help on using the changeset viewer.
