Changeset 6837 for trunk/ippTools/src/pzgetexp.c
- Timestamp:
- Apr 11, 2006, 5:30:00 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pzgetexp.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pzgetexp.c
r6833 r6837 3 3 4 4 #include "pxtools.h" 5 #include "pzgetexp.h" 5 6 6 //static psString slurp(FILE *stream); 7 static bool parseInput(); 7 static bool parseInput(pxConfig *config); 8 8 9 9 int main(int argc, char **argv) 10 10 { 11 // pxConfig *config = pxConfigAlloc(); 12 13 // pzsearchConfig(config, argc, argv); 11 pxConfig *config = pzgetexpConfig(config, argc, argv); 14 12 15 13 /* … … 25 23 */ 26 24 27 parseInput( );25 parseInput(config); 28 26 29 27 exit(EXIT_SUCCESS); … … 34 32 } 35 33 36 static bool parseInput( )34 static bool parseInput(pxConfig *config) 37 35 { 38 36 psString input = slurp(stdin); 39 psList * tokens = psStringSplit(input, "");37 psList *lines = psStringSplit(input, "\n"); 40 38 41 } 39 psListIterator *lineCursor = psListIteratorAlloc(lines, 0, false); 42 40 43 /* 44 #define SLURP_SIZE 1024 45 static psString slurp(FILE *stream) 46 { 47 psString str = NULL; 48 size_t strSize = 1; // bytes allocated - make sure there is room for '\0' 49 size_t used = 0; // bytes actually used 41 psArray *summitExps = psArrayAlloc(psListLength(lines)); 42 psString item; 43 while ((item = psListGetAndIncrement(lineCursor))) { 44 printf("-> %s\n", item); 50 45 51 for (;;) { 52 // increase the allocated string size 53 strSize += SLURP_SIZE; 54 str = psRealloc(str, strSize); 46 // split line into tokens 47 psList *tokens = psStringSplit(item, " "); 55 48 56 // read a block from the stream 57 size_t bytes = fread(str + used, 1, SLURP_SIZE, stream); 58 used += bytes; 49 // check that we have the right number of tokens 50 // print "# uri fileset datetime type\n"; 51 if (psListLength(tokens) != 4) { 52 // error 53 return false; 54 } 59 55 60 // is this the end of the file or an error? 61 if (bytes != SLURP_SIZE) { 62 if (feof(stream)) { 63 // eof 64 break; 65 } 66 // else - it's an error 67 psError(PS_ERR_UNKNOWN, true, "slurp failed"); 68 return NULL; 56 psListIterator *tokenCursor = psListIteratorAlloc(tokens, 0, false); 57 58 char *uri = psListGetAndIncrement(tokenCursor); 59 char *exp_id = psListGetAndIncrement(tokenCursor); // fileset 60 char *time = psListGetAndIncrement(tokenCursor); // datetime 61 char *exp_type = psListGetAndIncrement(tokenCursor); // type 62 63 psFree(tokenCursor); 64 65 summitExpRow *row = summitExpRowAlloc( 66 exp_id, 67 config->camera, 68 config->telescope, 69 exp_type, 70 uri 71 ); 72 psArrayAdd(summitExps, 0, row); 73 } 74 75 psFree(lineCursor); 76 psFree(lines); 77 psFree(input); 78 79 for (long i = 0; i < psArrayLength(summitExps); i++) { 80 if (!summitExpInsertObject(config->dbh, summitExps->data[i])) { 81 psError(PS_ERR_UNKNOWN, false, "dbh access failed"); 82 return false; 69 83 } 70 84 } 71 85 72 // append '\0' to the end of the string 73 str[used + 1] = '\0'; 74 75 return str; 86 psFree(summitExps); 76 87 } 77 */
Note:
See TracChangeset
for help on using the changeset viewer.
