summaryrefslogtreecommitdiff
path: root/noncore/todayplugins/stockticker/libstocks/csv.c
Unidiff
Diffstat (limited to 'noncore/todayplugins/stockticker/libstocks/csv.c') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/stockticker/libstocks/csv.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/noncore/todayplugins/stockticker/libstocks/csv.c b/noncore/todayplugins/stockticker/libstocks/csv.c
index 6170bed..86d8607 100644
--- a/noncore/todayplugins/stockticker/libstocks/csv.c
+++ b/noncore/todayplugins/stockticker/libstocks/csv.c
@@ -269,97 +269,98 @@ stock *parse_csv_file(char *csv)
269 269
270 if (LastStockPtr) 270 if (LastStockPtr)
271 { 271 {
272 LastStockPtr->NextStock = StockPtr; 272 LastStockPtr->NextStock = StockPtr;
273 StockPtr->PreviousStock = LastStockPtr; 273 StockPtr->PreviousStock = LastStockPtr;
274 } 274 }
275 275
276 LastStockPtr = StockPtr; 276 LastStockPtr = StockPtr;
277 } 277 }
278 278
279 end_line++; 279 end_line++;
280 line = end_line; 280 line = end_line;
281 281
282 } 282 }
283 283
284 return (FirstStockPtr); 284 return (FirstStockPtr);
285} 285}
286 286
287/*****************************************************************************/ 287/*****************************************************************************/
288/* Parses the history quotes file and return a stock structure list. */ 288/* Parses the history quotes file and return a stock structure list. */
289/*****************************************************************************/ 289/*****************************************************************************/
290stock *parse_csv_history_file(char *csv_file) 290stock *parse_csv_history_file(char *csv_file)
291{ 291{
292 292
293 char *line; 293 char *line;
294 char *end_line; 294 char *end_line;
295 char *ptr; 295 char *ptr;
296 296
297 int day; 297 int day;
298 char smonth[10]; 298 char smonth[10];
299 int month; 299 int month;
300 int year; 300 int year;
301 301
302 char *date; 302 char *date;
303 303
304 int i; 304 int i;
305 int test; 305 int test;
306 306
307 stock *StockPtr=NULL; 307 stock *StockPtr=NULL;
308 stock *LastStockPtr=NULL; 308 stock *LastStockPtr=NULL;
309 309
310 /* Used to return the pointer to the list */ 310 /* Used to return the pointer to the list */
311 stock *FirstStockPtr=NULL; 311 stock *FirstStockPtr=NULL;
312 312
313 line = csv_file; 313 line = csv_file;
314 end_line = csv_file; 314 end_line = csv_file;
315 315
316 /* do not use the first line */ 316 /* do not use the first line */
317 end_line = strstr(line, "\n"); 317 if (!(end_line = strstr(line, "\n")))
318 return 0;
318 *end_line = 0; 319 *end_line = 0;
319 end_line++; 320 end_line++;
320 line = end_line; 321 line = end_line;
321 322
322 while ((end_line = strstr(line, "\n"))) 323 while ((end_line = strstr(line, "\n")))
323 { 324 {
324 *end_line = 0; 325 *end_line = 0;
325 326
326 StockPtr = malloc_stock(); 327 StockPtr = malloc_stock();
327 328
328 /* Date */ 329 /* Date */
329 ptr = strtok(line, ","); 330 ptr = strtok(line, ",");
330 if (!ptr) return 0; 331 if (!ptr) return 0;
331 332
332 sscanf(ptr,"%d-%3s-%d",&day,smonth,&year); 333 sscanf(ptr,"%d-%3s-%d",&day,smonth,&year);
333 334
334 i=0; 335 i=0;
335 336
336#ifdef __UNIX__ 337#ifdef __UNIX__
337 while((test=strcasecmp(months[i], smonth))) i++; 338 while((test=strcasecmp(months[i], smonth))) i++;
338#elif __WINDOWS__ 339#elif __WINDOWS__
339 while(test=_mbsnbicmp(months[i], smonth, strlen(months[i]))) i++; 340 while(test=_mbsnbicmp(months[i], smonth, strlen(months[i]))) i++;
340#endif 341#endif
341 342
342 month = i+1; 343 month = i+1;
343 344
344 date = (char *)malloc(DATE_LENGTH); 345 date = (char *)malloc(DATE_LENGTH);
345 if (date==NULL) 346 if (date==NULL)
346 { 347 {
347 fprintf(stderr,"Memory allocating error (%s line %d)\n" 348 fprintf(stderr,"Memory allocating error (%s line %d)\n"
348 ,__FILE__, __LINE__); 349 ,__FILE__, __LINE__);
349 exit(1); 350 exit(1);
350 } 351 }
351 sprintf(date,"%.2d%.2d%.2d", year, month, day); 352 sprintf(date,"%.2d%.2d%.2d", year, month, day);
352 StockPtr->Date = date; 353 StockPtr->Date = date;
353 354
354 /* Open */ 355 /* Open */
355 ptr = strtok(NULL, ","); 356 ptr = strtok(NULL, ",");
356 if (!ptr) return 0; 357 if (!ptr) return 0;
357 sscanf(ptr,"%f",&(StockPtr->OpenPrice)); 358 sscanf(ptr,"%f",&(StockPtr->OpenPrice));
358 359
359 /* High */ 360 /* High */
360 ptr = strtok(NULL, ","); 361 ptr = strtok(NULL, ",");
361 if (!ptr) return 0; 362 if (!ptr) return 0;
362 sscanf(ptr,"%f",&(StockPtr->MaxPrice)); 363 sscanf(ptr,"%f",&(StockPtr->MaxPrice));
363 364
364 /* Low */ 365 /* Low */
365 ptr = strtok(NULL, ","); 366 ptr = strtok(NULL, ",");