Changeset 19579 for trunk/Ohana/src/opihi/dvo/dbCmdlineFields.c
- Timestamp:
- Sep 16, 2008, 9:16:26 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/dvo/dbCmdlineFields.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/dvo/dbCmdlineFields.c
r19571 r19579 1 1 # include "dvoshell.h" 2 2 3 // identify the fields to be extracted (test for where, check syntax) 3 // check for 'where' or 'matched to'; return first field after the word, and the value 4 int dbCmdlineConditions (int argc, char **argv, int first, int *nextField) { 5 6 int isWhere, isMatch; 7 8 *nextField = argc; 9 10 // require 'where' or 'matched to' before boolean math 11 if (first == argc) return DVO_DB_CMDLINE_IS_END; 12 13 isWhere = !strcasecmp(argv[first], "where"); 14 isMatch = !strcasecmp(argv[first], "match"); 15 16 if (!isMatch && !isWhere) { 17 gprint (GP_ERR, "WHERE or MATCH TO\n"); 18 return DVO_DB_CMDLINE_ERROR; 19 } 20 if (isMatch && ((first + 1 >= argc - 1) || strcasecmp(argv[first+1], "to"))) { 21 gprint (GP_ERR, "missing boolean expression\n"); 22 return DVO_DB_CMDLINE_ERROR; 23 } 24 if (isWhere && (first >= argc - 1)) { 25 gprint (GP_ERR, "missing boolean expression\n"); 26 return DVO_DB_CMDLINE_ERROR; 27 } 28 29 if (isWhere) { 30 *nextField = first + 1; 31 return DVO_DB_CMDLINE_IS_WHERE; 32 } 33 34 if (isMatch) { 35 *nextField = first + 2; 36 return DVO_DB_CMDLINE_IS_MATCH; 37 } 38 39 gprint (GP_ERR, "programming error?\n"); 40 return DVO_DB_CMDLINE_ERROR; 41 } 42 43 // identify the fields to be extracted (check syntax) 44 // the 'last' pointer ends on the first word after the fields (where, match or EOL) 4 45 dbField *dbCmdlineFields (int argc, char **argv, int table, int *last, int *nfields) { 5 46 … … 15 56 16 57 // examine each argv[i] entry until we reach a 'where' or a 'matched' 17 for (i = 1; (i < argc) && strcasecmp (argv[i], "where") && strcasecmp (argv[i], "match ed"); i++) {58 for (i = 1; (i < argc) && strcasecmp (argv[i], "where") && strcasecmp (argv[i], "match"); i++) { 18 59 // split the word by "," 19 60 p = argv[i]; … … 50 91 } 51 92 52 // require 'where' or 'matched to' before boolean math53 // XXX push this to a test up one level54 if (i != argc) {55 if (strcasecmp(argv[i], "where")) {56 gprint (GP_ERR, "syntax error\n");57 free (fields);58 return (NULL);59 }60 if (i > argc - 2) {61 gprint (GP_ERR, "missing boolean expression\n");62 free (fields);63 return (NULL);64 }65 i++; // skip over the 'where'66 }67 68 93 *last = i; 69 94 *nfields = Nfields;
Note:
See TracChangeset
for help on using the changeset viewer.
