author | llornkcor <llornkcor> | 2002-10-31 20:32:13 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-10-31 20:32:13 (UTC) |
commit | 73b03f932dd43d684e67db1837bf506ee015f2eb (patch) (unidiff) | |
tree | 87be47c236586177c65b38216818951337c0b59a | |
parent | 50f1091ee877020c9864ce24202951f49bec8cd7 (diff) | |
download | opie-73b03f932dd43d684e67db1837bf506ee015f2eb.zip opie-73b03f932dd43d684e67db1837bf506ee015f2eb.tar.gz opie-73b03f932dd43d684e67db1837bf506ee015f2eb.tar.bz2 |
make define __UNIX__ inherent
-rw-r--r-- | noncore/todayplugins/stockticker/libstocks/csv.c | 323 | ||||
-rw-r--r-- | noncore/todayplugins/stockticker/libstocks/http.c | 87 |
2 files changed, 206 insertions, 204 deletions
diff --git a/noncore/todayplugins/stockticker/libstocks/csv.c b/noncore/todayplugins/stockticker/libstocks/csv.c index 99a44e4..27bcce6 100644 --- a/noncore/todayplugins/stockticker/libstocks/csv.c +++ b/noncore/todayplugins/stockticker/libstocks/csv.c | |||
@@ -11,3 +11,3 @@ | |||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. | 13 | * Library General Public License for more details. |
@@ -21,2 +21,3 @@ | |||
21 | #define __CSV_C__ | 21 | #define __CSV_C__ |
22 | #ifdef __UNIX__ | ||
22 | 23 | ||
@@ -128,148 +129,148 @@ stock *parse_csv_file(char *csv) | |||
128 | while ( (test = strstr(test, "N/A")) ) | 129 | while ( (test = strstr(test, "N/A")) ) |
129 | { | 130 | { |
130 | valid ++; | 131 | valid ++; |
131 | test = test +3; | 132 | test = test +3; |
132 | } | 133 | } |
133 | 134 | ||
134 | if (valid < 6) | 135 | if (valid < 6) |
135 | { | 136 | { |
136 | /* This Symbol is valid */ | 137 | /* This Symbol is valid */ |
137 | 138 | ||
138 | StockPtr = malloc_stock(); | 139 | StockPtr = malloc_stock(); |
139 | 140 | ||
140 | ptr = csv_strtok(line, ","); | 141 | ptr = csv_strtok(line, ","); |
141 | if (!ptr) return 0; | 142 | if (!ptr) return 0; |
142 | 143 | ||
143 | symbol = (char *)malloc(strlen(ptr)+1); | 144 | symbol = (char *)malloc(strlen(ptr)+1); |
144 | if (symbol==NULL) | 145 | if (symbol==NULL) |
145 | { | 146 | { |
146 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 147 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
147 | ,__FILE__, __LINE__); | 148 | ,__FILE__, __LINE__); |
148 | exit(1); | 149 | exit(1); |
149 | } | 150 | } |
150 | strcpy((char *)(symbol), ptr); | 151 | strcpy((char *)(symbol), ptr); |
151 | StockPtr->Symbol = symbol; | 152 | StockPtr->Symbol = symbol; |
152 | 153 | ||
153 | ptr = csv_strtok(NULL, ","); | 154 | ptr = csv_strtok(NULL, ","); |
154 | if (!ptr) return 0; | 155 | if (!ptr) return 0; |
155 | 156 | ||
156 | name = (char *)malloc(strlen(ptr)+1); | 157 | name = (char *)malloc(strlen(ptr)+1); |
157 | if (name==NULL) | 158 | if (name==NULL) |
158 | { | 159 | { |
159 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 160 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
160 | ,__FILE__, __LINE__); | 161 | ,__FILE__, __LINE__); |
161 | exit(1); | 162 | exit(1); |
162 | } | 163 | } |
163 | strcpy((char *)(name), ptr); | 164 | strcpy((char *)(name), ptr); |
164 | StockPtr->Name = name; | 165 | StockPtr->Name = name; |
165 | 166 | ||
166 | ptr = csv_strtok(NULL, ","); | 167 | ptr = csv_strtok(NULL, ","); |
167 | if (!ptr) return 0; | 168 | if (!ptr) return 0; |
168 | sscanf(ptr,"%f",&(StockPtr->CurrentPrice)); | 169 | sscanf(ptr,"%f",&(StockPtr->CurrentPrice)); |
169 | 170 | ||
170 | ptr = csv_strtok(NULL, ","); | 171 | ptr = csv_strtok(NULL, ","); |
171 | if (!ptr) return 0; | 172 | if (!ptr) return 0; |
172 | 173 | ||
173 | date = (char *)malloc(strlen(ptr)+1); | 174 | date = (char *)malloc(strlen(ptr)+1); |
174 | if (date==NULL) | 175 | if (date==NULL) |
175 | { | 176 | { |
176 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 177 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
177 | ,__FILE__, __LINE__); | 178 | ,__FILE__, __LINE__); |
178 | exit(1); | 179 | exit(1); |
179 | } | 180 | } |
180 | strcpy((char *)(date), ptr); | 181 | strcpy((char *)(date), ptr); |
181 | StockPtr->Date = date; | 182 | StockPtr->Date = date; |
182 | 183 | ||
183 | ptr = csv_strtok(NULL, ","); | 184 | ptr = csv_strtok(NULL, ","); |
184 | if (!ptr) return 0; | 185 | if (!ptr) return 0; |
185 | 186 | ||
186 | time = (char *)malloc(strlen(ptr)+1); | 187 | time = (char *)malloc(strlen(ptr)+1); |
187 | if (time==NULL) | 188 | if (time==NULL) |
188 | { | 189 | { |
189 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 190 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
190 | ,__FILE__, __LINE__); | 191 | ,__FILE__, __LINE__); |
191 | exit(1); | 192 | exit(1); |
192 | } | 193 | } |
193 | strcpy((char *)(time), ptr); | 194 | strcpy((char *)(time), ptr); |
194 | StockPtr->Time = time; | 195 | StockPtr->Time = time; |
195 | 196 | ||
196 | ptr = csv_strtok(NULL, ","); | 197 | ptr = csv_strtok(NULL, ","); |
197 | if (!ptr) return 0; | 198 | if (!ptr) return 0; |
198 | sscanf(ptr,"%f",&(StockPtr->Variation)); | 199 | sscanf(ptr,"%f",&(StockPtr->Variation)); |
199 | 200 | ||
200 | StockPtr->Pourcentage = 100 * StockPtr->Variation / | 201 | StockPtr->Pourcentage = 100 * StockPtr->Variation / |
201 | (StockPtr->CurrentPrice - StockPtr->Variation); | 202 | (StockPtr->CurrentPrice - StockPtr->Variation); |
202 | 203 | ||
203 | StockPtr->LastPrice = StockPtr->CurrentPrice - StockPtr->Variation; | 204 | StockPtr->LastPrice = StockPtr->CurrentPrice - StockPtr->Variation; |
204 | 205 | ||
205 | ptr = csv_strtok(NULL, ","); | 206 | ptr = csv_strtok(NULL, ","); |
206 | if (!ptr) return 0; | 207 | if (!ptr) return 0; |
207 | sscanf(ptr,"%f",&(StockPtr->OpenPrice)); | 208 | sscanf(ptr,"%f",&(StockPtr->OpenPrice)); |
208 | 209 | ||
209 | ptr = csv_strtok(NULL, ","); | 210 | ptr = csv_strtok(NULL, ","); |
210 | if (!ptr) return 0; | 211 | if (!ptr) return 0; |
211 | sscanf(ptr,"%f",&(StockPtr->MaxPrice)); | 212 | sscanf(ptr,"%f",&(StockPtr->MaxPrice)); |
212 | 213 | ||
213 | ptr = csv_strtok(NULL, ","); | 214 | ptr = csv_strtok(NULL, ","); |
214 | if (!ptr) return 0; | 215 | if (!ptr) return 0; |
215 | sscanf(ptr,"%f",&(StockPtr->MinPrice)); | 216 | sscanf(ptr,"%f",&(StockPtr->MinPrice)); |
216 | 217 | ||
217 | ptr = csv_strtok(NULL, ","); | 218 | ptr = csv_strtok(NULL, ","); |
218 | if (!ptr) return 0; | 219 | if (!ptr) return 0; |
219 | StockPtr->Volume = atoi(ptr); | 220 | StockPtr->Volume = atoi(ptr); |
220 | 221 | ||
221 | if( !FirstStockPtr ) | 222 | if( !FirstStockPtr ) |
222 | { | 223 | { |
223 | FirstStockPtr = StockPtr; | 224 | FirstStockPtr = StockPtr; |
224 | StockPtr->PreviousStock = 0; | 225 | StockPtr->PreviousStock = 0; |
225 | } | 226 | } |
226 | 227 | ||
227 | StockPtr->NextStock = 0; | 228 | StockPtr->NextStock = 0; |
228 | 229 | ||
229 | if (LastStockPtr) | 230 | if (LastStockPtr) |
230 | { | 231 | { |
231 | LastStockPtr->NextStock = StockPtr; | 232 | LastStockPtr->NextStock = StockPtr; |
232 | StockPtr->PreviousStock = LastStockPtr; | 233 | StockPtr->PreviousStock = LastStockPtr; |
233 | } | 234 | } |
234 | 235 | ||
235 | LastStockPtr = StockPtr; | 236 | LastStockPtr = StockPtr; |
236 | 237 | ||
237 | } | 238 | } |
238 | else | 239 | else |
239 | { | 240 | { |
240 | /* this symbol is not valid */ | 241 | /* this symbol is not valid */ |
241 | /* Set the stock struct just with Symbol, all other are NULL */ | 242 | /* Set the stock struct just with Symbol, all other are NULL */ |
242 | /* This can be used to see if the symbol has been reached are not */ | 243 | /* This can be used to see if the symbol has been reached are not */ |
243 | 244 | ||
244 | StockPtr = malloc_stock(); | 245 | StockPtr = malloc_stock(); |
245 | 246 | ||
246 | ptr = csv_strtok(line, ","); | 247 | ptr = csv_strtok(line, ","); |
247 | if (!ptr) return 0; | 248 | if (!ptr) return 0; |
248 | 249 | ||
249 | symbol = (char *)malloc(strlen(ptr)+1); | 250 | symbol = (char *)malloc(strlen(ptr)+1); |
250 | if (symbol==NULL) | 251 | if (symbol==NULL) |
251 | { | 252 | { |
252 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 253 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
253 | ,__FILE__, __LINE__); | 254 | ,__FILE__, __LINE__); |
254 | exit(1); | 255 | exit(1); |
255 | } | 256 | } |
256 | strcpy((char *)(symbol), ptr); | 257 | strcpy((char *)(symbol), ptr); |
257 | StockPtr->Symbol = symbol; | 258 | StockPtr->Symbol = symbol; |
258 | 259 | ||
259 | if( !FirstStockPtr ) | 260 | if( !FirstStockPtr ) |
260 | { | 261 | { |
261 | FirstStockPtr = StockPtr; | 262 | FirstStockPtr = StockPtr; |
262 | StockPtr->PreviousStock = 0; | 263 | StockPtr->PreviousStock = 0; |
263 | } | 264 | } |
264 | 265 | ||
265 | StockPtr->NextStock = 0; | 266 | StockPtr->NextStock = 0; |
266 | 267 | ||
267 | if (LastStockPtr) | 268 | if (LastStockPtr) |
268 | { | 269 | { |
269 | LastStockPtr->NextStock = StockPtr; | 270 | LastStockPtr->NextStock = StockPtr; |
270 | StockPtr->PreviousStock = LastStockPtr; | 271 | StockPtr->PreviousStock = LastStockPtr; |
271 | } | 272 | } |
272 | 273 | ||
273 | LastStockPtr = StockPtr; | 274 | LastStockPtr = StockPtr; |
274 | } | 275 | } |
275 | 276 | ||
@@ -323,3 +324,3 @@ stock *parse_csv_history_file(char *csv_file) | |||
323 | StockPtr = malloc_stock(); | 324 | StockPtr = malloc_stock(); |
324 | 325 | ||
325 | /* Date */ | 326 | /* Date */ |
@@ -342,7 +343,7 @@ stock *parse_csv_history_file(char *csv_file) | |||
342 | if (date==NULL) | 343 | if (date==NULL) |
343 | { | 344 | { |
344 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 345 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
345 | ,__FILE__, __LINE__); | 346 | ,__FILE__, __LINE__); |
346 | exit(1); | 347 | exit(1); |
347 | } | 348 | } |
348 | sprintf(date,"%.2d%.2d%.2d", year, month, day); | 349 | sprintf(date,"%.2d%.2d%.2d", year, month, day); |
@@ -374,13 +375,13 @@ stock *parse_csv_history_file(char *csv_file) | |||
374 | if (!ptr) | 375 | if (!ptr) |
375 | /* It seems to be an indice */ | 376 | /* It seems to be an indice */ |
376 | /* No volume for indices */ | 377 | /* No volume for indices */ |
377 | StockPtr->Volume = 0; | 378 | StockPtr->Volume = 0; |
378 | else | 379 | else |
379 | StockPtr->Volume = atoi(ptr); | 380 | StockPtr->Volume = atoi(ptr); |
380 | 381 | ||
381 | if( !FirstStockPtr ) | 382 | if( !FirstStockPtr ) |
382 | { | 383 | { |
383 | FirstStockPtr = StockPtr; | 384 | FirstStockPtr = StockPtr; |
384 | StockPtr->PreviousStock = 0; | 385 | StockPtr->PreviousStock = 0; |
385 | } | 386 | } |
386 | 387 | ||
@@ -389,6 +390,6 @@ stock *parse_csv_history_file(char *csv_file) | |||
389 | if (LastStockPtr) | 390 | if (LastStockPtr) |
390 | { | 391 | { |
391 | LastStockPtr->NextStock = StockPtr; | 392 | LastStockPtr->NextStock = StockPtr; |
392 | StockPtr->PreviousStock = LastStockPtr; | 393 | StockPtr->PreviousStock = LastStockPtr; |
393 | } | 394 | } |
394 | 395 | ||
diff --git a/noncore/todayplugins/stockticker/libstocks/http.c b/noncore/todayplugins/stockticker/libstocks/http.c index 462080d..3078746 100644 --- a/noncore/todayplugins/stockticker/libstocks/http.c +++ b/noncore/todayplugins/stockticker/libstocks/http.c | |||
@@ -11,3 +11,3 @@ | |||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. | 13 | * Library General Public License for more details. |
@@ -21,2 +21,3 @@ | |||
21 | #define __HTTP_C__ | 21 | #define __HTTP_C__ |
22 | #define __UNIX__ | ||
22 | 23 | ||
@@ -87,5 +88,5 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) | |||
87 | #ifdef DEBUG | 88 | #ifdef DEBUG |
88 | printf(" gethostbyname : NOK\n"); | 89 | printf(" gethostbyname : NOK\n"); |
89 | #endif | 90 | #endif |
90 | return ERRHOST; | 91 | return ERRHOST; |
91 | } | 92 | } |
@@ -123,3 +124,3 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) | |||
123 | sprintf(header,"GET http://%.128s:80%.256s HTTP/1.0\015\012\015\012", | 124 | sprintf(header,"GET http://%.128s:80%.256s HTTP/1.0\015\012\015\012", |
124 | http_server, http_file); | 125 | http_server, http_file); |
125 | } | 126 | } |
@@ -140,3 +141,3 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) | |||
140 | #ifdef DEBUG | 141 | #ifdef DEBUG |
141 | printf(" send header : NOK\n"); | 142 | printf(" send header : NOK\n"); |
142 | #endif | 143 | #endif |
@@ -159,32 +160,32 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) | |||
159 | if (r) | 160 | if (r) |
160 | { | 161 | { |
161 | if(!data_lgr) | 162 | if(!data_lgr) |
162 | { | 163 | { |
163 | if((data = malloc(r+1))==NULL) | 164 | if((data = malloc(r+1))==NULL) |
164 | { | 165 | { |
165 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 166 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
166 | ,__FILE__, __LINE__); | 167 | ,__FILE__, __LINE__); |
167 | exit(1); | 168 | exit(1); |
168 | } | 169 | } |
169 | 170 | ||
170 | memcpy(data,buf,r); | 171 | memcpy(data,buf,r); |
171 | data_lgr = r; | 172 | data_lgr = r; |
172 | data[r]=0; | 173 | data[r]=0; |
173 | } | 174 | } |
174 | else | 175 | else |
175 | { | 176 | { |
176 | if((temp = malloc(r+data_lgr+1))==NULL) | 177 | if((temp = malloc(r+data_lgr+1))==NULL) |
177 | { | 178 | { |
178 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 179 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
179 | ,__FILE__, __LINE__); | 180 | ,__FILE__, __LINE__); |
180 | exit(1); | 181 | exit(1); |
181 | } | 182 | } |
182 | memcpy(temp, data, data_lgr); | 183 | memcpy(temp, data, data_lgr); |
183 | memcpy(temp+data_lgr, buf, r); | 184 | memcpy(temp+data_lgr, buf, r); |
184 | temp[r+data_lgr]=0; | 185 | temp[r+data_lgr]=0; |
185 | data_lgr += r; | 186 | data_lgr += r; |
186 | free(data); | 187 | free(data); |
187 | data = temp; | 188 | data = temp; |
188 | } | 189 | } |
189 | } | 190 | } |
190 | } | 191 | } |
@@ -212,10 +213,10 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) | |||
212 | if( *temp==0x0A ) | 213 | if( *temp==0x0A ) |
213 | { | 214 | { |
214 | /* test if it is the header end */ | 215 | /* test if it is the header end */ |
215 | temp ++; | 216 | temp ++; |
216 | if (*temp == 0x0D) temp++; | 217 | if (*temp == 0x0D) temp++; |
217 | if (*temp == 0x0A) header_founded = 1; | 218 | if (*temp == 0x0A) header_founded = 1; |
218 | } | 219 | } |
219 | else | 220 | else |
220 | temp++; | 221 | temp++; |
221 | } | 222 | } |
@@ -240,3 +241,3 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) | |||
240 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 241 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
241 | ,__FILE__, __LINE__); | 242 | ,__FILE__, __LINE__); |
242 | exit(1); | 243 | exit(1); |