Changeset 7921
- Timestamp:
- Jul 17, 2006, 3:06:21 PM (20 years ago)
- Location:
- trunk/ippTools/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pztool.c
r6978 r7921 16 16 static bool pzsearchFlushPendingExp(pxConfig *config); 17 17 18 # define MODECASE(caseName, func) \ 19 case caseName: \ 20 if (!func(config)) { \ 21 goto FAIL; \ 22 } \ 23 break; 24 25 18 26 int main(int argc, char **argv) 19 27 { 28 psLibInit(NULL); 29 20 30 pxConfig *config = pzsearchConfig(NULL, argc, argv); 21 31 22 32 switch (config->mode) { 23 case PX_MODE_SEEN: 24 if (!seenMode(config)) { 25 goto FAIL; 26 } 27 break; 28 case PX_MODE_PENDING: 29 if (!pendingMode(config)) { 30 goto FAIL; 31 } 32 break; 33 case PX_MODE_COPYDONE: 34 if (!copydoneMode(config)) { 35 goto FAIL; 36 } 37 break; 33 MODECASE(PZSEARCH_MODE_SEEN, seenMode); 34 MODECASE(PZSEARCH_MODE_PENDING, pendingMode); 35 MODECASE(PZSEARCH_MODE_COPYDONE, copydoneMode); 38 36 default: 39 37 psAbort(argv[0], "invalid option (this should not happen)"); 40 38 } 41 39 40 psFree(config); 41 pmConfigDone(); 42 psLibFinalize(); 43 44 42 45 exit(EXIT_SUCCESS); 43 46 44 47 FAIL: 45 48 psFree(config); 49 pmConfigDone(); 50 psLibFinalize(); 51 46 52 exit(EXIT_FAILURE); 47 53 } -
trunk/ippTools/src/pztool.h
r6978 r7921 4 4 #include "pxtools.h" 5 5 6 typedef enum { 7 PZSEARCH_MODE_NONE = 0x0, 8 PZSEARCH_MODE_SEEN, 9 PZSEARCH_MODE_PENDING, 10 PZSEARCH_MODE_COPYDONE 11 } pzsearchMode; 12 6 13 pxConfig *pzsearchConfig(pxConfig *config, int argc, char **argv); 7 14 -
trunk/ippTools/src/pztoolConfig.c
r7037 r7921 6 6 7 7 #include "pxtools.h" 8 #include "pzsearch.h" 8 9 10 // this function can not fail -- exits on error 9 11 pxConfig *pzsearchConfig(pxConfig *config, int argc, char **argv) { 10 12 if (!config) { … … 12 14 } 13 15 16 // setup site config 14 17 config->modules = pmConfigRead(&argc, argv); 15 16 18 if (! config->modules) { 17 19 psError(PS_ERR_UNKNOWN, false, "Can't find site configuration!\n"); … … 19 21 } 20 22 21 int N; 22 config->mode = PX_MODE_NONE; 23 if ((N = psArgumentGet (argc, argv, "-seen"))) { 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_SEEN; 29 } 30 if ((N = psArgumentGet (argc, argv, "-pending"))) { 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_PENDING; 36 } 37 if ((N = psArgumentGet (argc, argv, "-copydone"))) { 38 psArgumentRemove (N, &argc, argv); 39 if (config->mode) { 40 psError(PS_ERR_UNKNOWN, true, "only one mode selection is allowed"); 41 } 42 config->mode = PX_MODE_COPYDONE; 43 } 23 // -seen 24 psMetadata *seenArgs = psMetadataAlloc(); 25 psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-exp_id", 0, 26 "define exposure ID", NULL); 27 psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-inst", 0, 28 "define camera ID", NULL); 29 psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-telescope", 0, 30 "define telescope ID", NULL); 31 psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-exp_type", 0, 32 "define exposure type", NULL); 33 34 // -pending 35 psMetadata *pendingArgs = psMetadataAlloc(); 36 psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-exp_id", 0, 37 "define exposure ID", NULL); 38 psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-inst", 0, 39 "define camera ID", NULL); 40 psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-telescope", 0, 41 "define telescope ID", NULL); 42 psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-exp_type", 0, 43 "define exposure type", NULL); 44 44 45 // paul's argument parsing convention requires: -key value 46 // Parse other command-line arguments 47 psMetadata *args = psMetadataAlloc(); 48 psMetadataAddStr(args , PS_LIST_TAIL, "-seen", 0, 49 "list all uncopied exposure IDs", ""); 50 psMetadataAddStr(args , PS_LIST_TAIL, "-pending", 0, 51 "list all image files pending download", ""); 52 psMetadataAddStr(args , PS_LIST_TAIL, "-copydone", 0, 53 "indicate that an image file has been downloaded", ""); 54 55 // -copydone search 45 // -copydone 56 46 psMetadata *copydoneArgs = psMetadataAlloc(); 57 47 psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-exp_id", 0, 58 "define exposure ID", "");48 "define exposure ID", NULL); 59 49 psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-class", 0, 60 "define class", "");50 "define class", NULL); 61 51 psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-class_id", 0, 62 "define class_id", "");52 "define class_id", NULL); 63 53 psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-suri", 0, 64 "define storage uri", ""); 54 "define storage uri", NULL); 55 56 #define PXTOOL_MODE(option, modeval, argset) \ 57 { \ 58 int N = 0; \ 59 if ((N = psArgumentGet (argc, argv, option))) { \ 60 psArgumentRemove (N, &argc, argv); \ 61 if (config->mode) { \ 62 psError(PS_ERR_UNKNOWN, true, "only one mode selection is allowed"); \ 63 } \ 64 config->mode = modeval; \ 65 config->args = psMemIncrRefCounter(argset); \ 66 } \ 67 } 68 69 PXTOOL_MODE("-seen", PZSEARCH_MODE_SEEN, seenArgs); 70 PXTOOL_MODE("-pending", PZSEARCH_MODE_PENDING, pendingArgs); 71 PXTOOL_MODE("-copydone", PZSEARCH_MODE_COPYDONE, copydoneArgs); 65 72 66 73 bool argErr = false; 67 if (config->mode == P X_MODE_NONE) {74 if (config->mode == PZSEARCH_MODE_NONE) { 68 75 argErr = true; 69 76 fprintf (stderr, "mode argument is required\n"); 70 } else if (! psArgumentParse( args, &argc, argv) || argc != 1) {77 } else if (! psArgumentParse(config->args, &argc, argv) || argc != 1) { 71 78 argErr = true; 72 79 fprintf (stderr, "error parsing arguments\n"); … … 77 84 printf("Usage: %s <mode> [<options>]\n\n", argv[0]); 78 85 printf(" <mode> : -seen | -pending | -copydone\n\n"); 86 87 fprintf (stdout, "-seen "); 88 psArgumentHelp(seenArgs); 89 psFree(seenArgs); 90 91 fprintf (stdout, "-pending "); 92 psArgumentHelp(pendingArgs); 93 psFree(pendingArgs); 94 79 95 fprintf (stdout, "-copydone "); 80 96 psArgumentHelp(copydoneArgs); 81 psFree(args);82 97 psFree(copydoneArgs); 83 exit(EXIT_FAILURE); 98 99 goto FAIL; 84 100 } 85 101 102 psFree(seenArgs); 103 psArgumentHelp(pendingArgs); 86 104 psFree(copydoneArgs); 87 105 88 // XXX why is "" being returned when -[foo] isn't specified? 89 #define EMPTY_TO_NULL_STRING(var) \ 90 if (var != NULL && strcmp(var, "") == 0) { \ 91 var = NULL; \ 106 // setup search criterion 107 #define addWhereStr(name) \ 108 { \ 109 psString str = NULL; \ 110 bool status = false; \ 111 if ((str = psMetadataLookupStr(&status, config->args, "-" #name))) { \ 112 if (!psMetadataAddStr(config->where, PS_LIST_TAIL, #name, 0, "==", str)) {\ 113 psError(PS_ERR_UNKNOWN, false, "failed to add item " #name); \ 114 goto FAIL; \ 115 } \ 116 } \ 117 } 118 119 // generate SQL where claus 120 config->where = psMetadataAlloc(); 121 122 addWhereStr(exp_id); 123 addWhereStr(class); 124 addWhereStr(class_id); 125 126 if (config->where->list->n < 1) { 127 psFree(config->where); 128 config->where = NULL; 92 129 } 93 130 94 config->args = args;95 96 if (config->mode == PX_MODE_COPYDONE) {97 psMetadata *where = psMetadataAlloc();98 99 bool status;100 psString str;101 if ((str = psMetadataLookupStr(&status, args, "-exp_id"))) {102 if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", str)) {103 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");104 psFree(where);105 exit(EXIT_FAILURE);106 }107 }108 if ((str = psMetadataLookupStr(&status, args, "-class"))) {109 if (!psMetadataAddStr(where, PS_LIST_TAIL, "class", 0, "==", str)) {110 psError(PS_ERR_UNKNOWN, false, "failed to add item class");111 psFree(where);112 exit(EXIT_FAILURE);113 }114 }115 if ((str = psMetadataLookupStr(&status, args, "-class_id"))) {116 if (!psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==", str)) {117 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");118 psFree(where);119 exit(EXIT_FAILURE);120 }121 }122 123 if (where->list->n < 1) {124 psFree(where);125 where = NULL;126 }127 config->where = where;128 }129 130 131 // define Database handle, if used 132 // do this last so we don't setup a connection before CLI options are 133 // validated 131 134 config->dbh = pmConfigDB(config->modules); 132 135 if (!config->dbh) { 133 136 psError(PS_ERR_UNKNOWN, false, "Can't configure database"); 134 exit(EXIT_FAILURE);137 goto FAIL; 135 138 } 136 139 140 // save argv/argc 141 config->argv = argv; 142 config->argc = argc; 143 137 144 return config; 145 146 FAIL: 147 psFree(config); 148 pmConfigDone(); 149 psLibFinalize(); 150 exit(EXIT_FAILURE); 138 151 }
Note:
See TracChangeset
for help on using the changeset viewer.
