Changeset 7770 for trunk/psModules/src/detrend/pmDetrendDB.c
- Timestamp:
- Jun 30, 2006, 2:00:11 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmDetrendDB.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmDetrendDB.c
r7589 r7770 85 85 pmDetrendSelectResults *pmDetrendSelect (pmDetrendSelectOptions *options) 86 86 { 87 88 char answer[128]; 89 char line[1024]; 87 bool status; 88 char *line = NULL; 90 89 91 90 char *time = psTimeToISO (&options->time); 92 91 char *type = pmDetrendTypeToString (options->type); 93 92 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); 96 95 psFree (time); 97 96 psFree (type); 98 97 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); 103 112 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); 106 117 107 118 if (!array) … … 121 132 122 133 psFree (array); 123 psFree (list);124 125 134 return results; 126 135 } … … 130 139 char *pmDetrendFile (char *detID, char *classID) 131 140 { 141 bool status; 142 char *line = NULL; 132 143 133 char answer[128];134 char line[1024];144 // generate the detselect command 145 psStringAppend (&line, "detselect -select -detID %s -classID %s", detID, classID); 135 146 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); 137 161 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); 145 166 146 167 if (!array) … … 154 175 155 176 psFree (array); 156 psFree (list);157 158 177 return result; 159 178 }
Note:
See TracChangeset
for help on using the changeset viewer.
