IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 30, 2006, 2:00:11 PM (20 years ago)
Author:
magnier
Message:

added psPipe, psIOBuffer, added to detselect

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmDetrendDB.c

    r7589 r7770  
    8585pmDetrendSelectResults *pmDetrendSelect (pmDetrendSelectOptions *options)
    8686{
    87 
    88     char answer[128];
    89     char line[1024];
     87    bool status;
     88    char *line = NULL;
    9089
    9190    char *time = psTimeToISO (&options->time);
    9291    char *type = pmDetrendTypeToString (options->type);
    9392
    94     sprintf (line, "detselect -camera %s -time %s -type %s",
    95             options->camera, time, type);
     93    // generate the detselect command
     94    psStringAppend (&line, "detselect -camera %s -time %s -type %s", options->camera, time, type);
    9695    psFree (time);
    9796    psFree (type);
    9897
    99     // XXX put this in a fork/exec to catch the timeout
    100     FILE *p = popen (line, "r");
    101     fgets (answer, 127, p);
    102     pclose (p);
     98    // use psPipe to exec the command, wait for response
     99    psIOBuffer *buffer = psIOBufferAlloc (512);
     100    psPipe *pipe = psPipeOpen (line);
     101    status = psIOBufferReadEmpty (buffer, 100, pipe->stdout);
     102    if (!status) {
     103        psError (PS_ERR_IO, false, "detselect is not responding");
     104        psFree (buffer);
     105        psFree (pipe);
     106        psFree (line);
     107        return NULL;
     108    }
     109    psPipeClose (pipe);
     110    psFree (pipe);
     111    psFree (line);
    103112
    104     psList *list = psStringSplit (answer, " ", false);
    105     psArray *array = psListToArray (list);
     113    // XXX need to parse the response more robustly
     114    // XXX for now, assume a single line
     115    psArray *array = psStringSplitArray (buffer->data, " ", false);
     116    psFree (buffer);
    106117
    107118    if (!array)
     
    121132
    122133    psFree (array);
    123     psFree (list);
    124 
    125134    return results;
    126135}
     
    130139char *pmDetrendFile (char *detID, char *classID)
    131140{
     141    bool status;
     142    char *line = NULL;
    132143
    133     char answer[128];
    134     char line[1024];
     144    // generate the detselect command
     145    psStringAppend (&line, "detselect -select -detID %s -classID %s", detID, classID);
    135146
    136     sprintf (line, "detselect -select -detID %s -classID %s", detID, classID);
     147    // use psPipe to exec the command, wait for response
     148    psIOBuffer *buffer = psIOBufferAlloc (512);
     149    psPipe *pipe = psPipeOpen (line);
     150    status = psIOBufferReadEmpty (buffer, 100, pipe->stdout);
     151    if (!status) {
     152        psError (PS_ERR_IO, false, "detselect is not responding");
     153        psFree (buffer);
     154        psFree (pipe);
     155        psFree (line);
     156        return NULL;
     157    }
     158    psPipeClose (pipe);
     159    psFree (pipe);
     160    psFree (line);
    137161
    138     // XXX put this in a fork/exec to catch the timeout
    139     FILE *p = popen (line, "r");
    140     fgets (answer, 127, p);
    141     pclose (p);
    142 
    143     psList *list = psStringSplit (answer, " ", false);
    144     psArray *array = psListToArray (list);
     162    // XXX need to parse the response more robustly
     163    // XXX for now, assume a single line
     164    psArray *array = psStringSplitArray (buffer->data, " ", false);
     165    psFree (buffer);
    145166
    146167    if (!array)
     
    154175
    155176    psFree (array);
    156     psFree (list);
    157 
    158177    return result;
    159178}
Note: See TracChangeset for help on using the changeset viewer.