IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6837


Ignore:
Timestamp:
Apr 11, 2006, 5:30:00 PM (20 years ago)
Author:
jhoblitt
Message:

partial implimentation of pzgetexp
change pzgetexpConfig() to allocate a pxConfig if passed NULL for config

Location:
trunk/ippTools/src
Files:
3 edited

Legend:

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

    r6833 r6837  
    33
    44#include "pxtools.h"
     5#include "pzgetexp.h"
    56
    6 //static psString slurp(FILE *stream);
    7 static bool parseInput();
     7static bool parseInput(pxConfig *config);
    88
    99int main(int argc, char **argv)
    1010{
    11 //    pxConfig *config = pxConfigAlloc();
    12 
    13 //    pzsearchConfig(config, argc, argv);
     11    pxConfig *config = pzgetexpConfig(config, argc, argv);
    1412
    1513    /*
     
    2523    */
    2624
    27     parseInput();
     25    parseInput(config);
    2826
    2927    exit(EXIT_SUCCESS);
     
    3432}
    3533
    36 static bool parseInput()
     34static bool parseInput(pxConfig *config)
    3735{
    3836    psString input = slurp(stdin);
    39     psList *tokens = psStringSplit(input, " ");
     37    psList *lines = psStringSplit(input, "\n");
    4038
    41 }
     39    psListIterator *lineCursor = psListIteratorAlloc(lines, 0, false);
    4240
    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);
    5045
    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, " ");
    5548
    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        }
    5955
    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;
    6983        }
    7084    }
    7185
    72     // append '\0' to the end of the string
    73     str[used + 1] = '\0';
    74 
    75     return str;
     86    psFree(summitExps);
    7687}
    77 */
  • trunk/ippTools/src/pzgetexp.h

    r6835 r6837  
    44#include "pxtools.h"
    55
    6 bool pzgetexpConfig(pxConfig *config, int argc, char **argv);
     6pxConfig *pzgetexpConfig(pxConfig *config, int argc, char **argv);
    77
    88#endif // PZGETEXP_H
  • trunk/ippTools/src/pzgetexpConfig.c

    r6836 r6837  
    33#include "pxtools.h"
    44
    5 bool pzgetexpConfig(pxConfig *config, int argc, char **argv) {
    6     PS_ASSERT_PTR_NON_NULL(config, false);
     5pxConfig *pzgetexpConfig(pxConfig *config, int argc, char **argv) {
     6    if (!config) {
     7        config = pxConfigAlloc();           
     8    }
    79
    810    if (! pmConfigRead(&config->site, &config->camera, &config->recipe, &argc, argv, RECIPE)) {
     
    3840    config->dbh = pmConfigDB(config->site);
    3941
    40     return true;
     42    return config;
    4143}
Note: See TracChangeset for help on using the changeset viewer.