Diffstat (limited to 'noncore/todayplugins/stockticker') (more/less context) (show whitespace changes)
4 files changed, 104 insertions, 27 deletions
diff --git a/noncore/todayplugins/stockticker/libstocks/csv.c b/noncore/todayplugins/stockticker/libstocks/csv.c index 86d8607..110df7c 100644 --- a/noncore/todayplugins/stockticker/libstocks/csv.c +++ b/noncore/todayplugins/stockticker/libstocks/csv.c | |||
@@ -138,90 +138,130 @@ stock *parse_csv_file(char *csv) | |||
138 | { | 138 | { |
139 | /* This Symbol is valid */ | 139 | /* This Symbol is valid */ |
140 | 140 | ||
141 | StockPtr = malloc_stock(); | 141 | StockPtr = malloc_stock(); |
142 | 142 | ||
143 | ptr = csv_strtok(line, ","); | 143 | ptr = csv_strtok(line, ","); |
144 | if (!ptr) return 0; | 144 | if (!ptr) |
145 | { | ||
146 | free_stock(StockPtr); | ||
147 | return 0; | ||
148 | } | ||
145 | 149 | ||
146 | symbol = (char *)malloc(strlen(ptr)+1); | 150 | symbol = (char *)malloc(strlen(ptr)+1); |
147 | if (symbol==NULL) | 151 | if (symbol==NULL) |
148 | { | 152 | { |
149 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 153 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
150 | ,__FILE__, __LINE__); | 154 | ,__FILE__, __LINE__); |
151 | exit(1); | 155 | exit(1); |
152 | } | 156 | } |
153 | strcpy((char *)(symbol), ptr); | 157 | strcpy((char *)(symbol), ptr); |
154 | StockPtr->Symbol = symbol; | 158 | StockPtr->Symbol = symbol; |
155 | 159 | ||
156 | ptr = csv_strtok(NULL, ","); | 160 | ptr = csv_strtok(NULL, ","); |
157 | if (!ptr) return 0; | 161 | if (!ptr) |
162 | { | ||
163 | free_stock(StockPtr); | ||
164 | return 0; | ||
165 | } | ||
158 | 166 | ||
159 | name = (char *)malloc(strlen(ptr)+1); | 167 | name = (char *)malloc(strlen(ptr)+1); |
160 | if (name==NULL) | 168 | if (name==NULL) |
161 | { | 169 | { |
162 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 170 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
163 | ,__FILE__, __LINE__); | 171 | ,__FILE__, __LINE__); |
164 | exit(1); | 172 | exit(1); |
165 | } | 173 | } |
166 | strcpy((char *)(name), ptr); | 174 | strcpy((char *)(name), ptr); |
167 | StockPtr->Name = name; | 175 | StockPtr->Name = name; |
168 | 176 | ||
169 | ptr = csv_strtok(NULL, ","); | 177 | ptr = csv_strtok(NULL, ","); |
170 | if (!ptr) return 0; | 178 | if (!ptr) |
179 | { | ||
180 | free_stock(StockPtr); | ||
181 | return 0; | ||
182 | } | ||
171 | sscanf(ptr,"%f",&(StockPtr->CurrentPrice)); | 183 | sscanf(ptr,"%f",&(StockPtr->CurrentPrice)); |
172 | 184 | ||
173 | ptr = csv_strtok(NULL, ","); | 185 | ptr = csv_strtok(NULL, ","); |
174 | if (!ptr) return 0; | 186 | if (!ptr) |
187 | { | ||
188 | free_stock(StockPtr); | ||
189 | return 0; | ||
190 | } | ||
175 | 191 | ||
176 | date = (char *)malloc(strlen(ptr)+1); | 192 | date = (char *)malloc(strlen(ptr)+1); |
177 | if (date==NULL) | 193 | if (date==NULL) |
178 | { | 194 | { |
179 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 195 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
180 | ,__FILE__, __LINE__); | 196 | ,__FILE__, __LINE__); |
181 | exit(1); | 197 | exit(1); |
182 | } | 198 | } |
183 | strcpy((char *)(date), ptr); | 199 | strcpy((char *)(date), ptr); |
184 | StockPtr->Date = date; | 200 | StockPtr->Date = date; |
185 | 201 | ||
186 | ptr = csv_strtok(NULL, ","); | 202 | ptr = csv_strtok(NULL, ","); |
187 | if (!ptr) return 0; | 203 | if (!ptr) |
204 | { | ||
205 | free_stock(StockPtr); | ||
206 | return 0; | ||
207 | } | ||
188 | 208 | ||
189 | time = (char *)malloc(strlen(ptr)+1); | 209 | time = (char *)malloc(strlen(ptr)+1); |
190 | if (time==NULL) | 210 | if (time==NULL) |
191 | { | 211 | { |
192 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 212 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
193 | ,__FILE__, __LINE__); | 213 | ,__FILE__, __LINE__); |
194 | exit(1); | 214 | exit(1); |
195 | } | 215 | } |
196 | strcpy((char *)(time), ptr); | 216 | strcpy((char *)(time), ptr); |
197 | StockPtr->Time = time; | 217 | StockPtr->Time = time; |
198 | 218 | ||
199 | ptr = csv_strtok(NULL, ","); | 219 | ptr = csv_strtok(NULL, ","); |
200 | if (!ptr) return 0; | 220 | if (!ptr) |
221 | { | ||
222 | free_stock(StockPtr); | ||
223 | return 0; | ||
224 | } | ||
201 | sscanf(ptr,"%f",&(StockPtr->Variation)); | 225 | sscanf(ptr,"%f",&(StockPtr->Variation)); |
202 | 226 | ||
203 | StockPtr->Pourcentage = 100 * StockPtr->Variation / | 227 | StockPtr->Pourcentage = 100 * StockPtr->Variation / |
204 | (StockPtr->CurrentPrice - StockPtr->Variation); | 228 | (StockPtr->CurrentPrice - StockPtr->Variation); |
205 | 229 | ||
206 | StockPtr->LastPrice = StockPtr->CurrentPrice - StockPtr->Variation; | 230 | StockPtr->LastPrice = StockPtr->CurrentPrice - StockPtr->Variation; |
207 | 231 | ||
208 | ptr = csv_strtok(NULL, ","); | 232 | ptr = csv_strtok(NULL, ","); |
209 | if (!ptr) return 0; | 233 | if (!ptr) |
234 | { | ||
235 | free_stock(StockPtr); | ||
236 | return 0; | ||
237 | } | ||
210 | sscanf(ptr,"%f",&(StockPtr->OpenPrice)); | 238 | sscanf(ptr,"%f",&(StockPtr->OpenPrice)); |
211 | 239 | ||
212 | ptr = csv_strtok(NULL, ","); | 240 | ptr = csv_strtok(NULL, ","); |
213 | if (!ptr) return 0; | 241 | if (!ptr) |
242 | { | ||
243 | free_stock(StockPtr); | ||
244 | return 0; | ||
245 | } | ||
214 | sscanf(ptr,"%f",&(StockPtr->MaxPrice)); | 246 | sscanf(ptr,"%f",&(StockPtr->MaxPrice)); |
215 | 247 | ||
216 | ptr = csv_strtok(NULL, ","); | 248 | ptr = csv_strtok(NULL, ","); |
217 | if (!ptr) return 0; | 249 | if (!ptr) |
250 | { | ||
251 | free_stock(StockPtr); | ||
252 | return 0; | ||
253 | } | ||
218 | sscanf(ptr,"%f",&(StockPtr->MinPrice)); | 254 | sscanf(ptr,"%f",&(StockPtr->MinPrice)); |
219 | 255 | ||
220 | ptr = csv_strtok(NULL, ","); | 256 | ptr = csv_strtok(NULL, ","); |
221 | if (!ptr) return 0; | 257 | if (!ptr) |
258 | { | ||
259 | free_stock(StockPtr); | ||
260 | return 0; | ||
261 | } | ||
222 | StockPtr->Volume = atoi(ptr); | 262 | StockPtr->Volume = atoi(ptr); |
223 | 263 | ||
224 | if( !FirstStockPtr ) | 264 | if( !FirstStockPtr ) |
225 | { | 265 | { |
226 | FirstStockPtr = StockPtr; | 266 | FirstStockPtr = StockPtr; |
227 | StockPtr->PreviousStock = 0; | 267 | StockPtr->PreviousStock = 0; |
@@ -244,13 +284,17 @@ stock *parse_csv_file(char *csv) | |||
244 | /* Set the stock struct just with Symbol, all other are NULL */ | 284 | /* Set the stock struct just with Symbol, all other are NULL */ |
245 | /* This can be used to see if the symbol has been reached are not */ | 285 | /* This can be used to see if the symbol has been reached are not */ |
246 | 286 | ||
247 | StockPtr = malloc_stock(); | 287 | StockPtr = malloc_stock(); |
248 | 288 | ||
249 | ptr = csv_strtok(line, ","); | 289 | ptr = csv_strtok(line, ","); |
250 | if (!ptr) return 0; | 290 | if (!ptr) |
291 | { | ||
292 | free_stock(StockPtr); | ||
293 | return 0; | ||
294 | } | ||
251 | 295 | ||
252 | symbol = (char *)malloc(strlen(ptr)+1); | 296 | symbol = (char *)malloc(strlen(ptr)+1); |
253 | if (symbol==NULL) | 297 | if (symbol==NULL) |
254 | { | 298 | { |
255 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 299 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
256 | ,__FILE__, __LINE__); | 300 | ,__FILE__, __LINE__); |
@@ -325,13 +369,19 @@ stock *parse_csv_history_file(char *csv_file) | |||
325 | *end_line = 0; | 369 | *end_line = 0; |
326 | 370 | ||
327 | StockPtr = malloc_stock(); | 371 | StockPtr = malloc_stock(); |
328 | 372 | ||
329 | /* Date */ | 373 | /* Date */ |
330 | ptr = strtok(line, ","); | 374 | ptr = strtok(line, ","); |
331 | if (!ptr) return 0; | 375 | if (!ptr) |
376 | { | ||
377 | free_stock(StockPtr); | ||
378 | free_stock(FirstStockPtr); | ||
379 | free_stock(LastStockPtr); | ||
380 | return 0; | ||
381 | } | ||
332 | 382 | ||
333 | sscanf(ptr,"%d-%3s-%d",&day,smonth,&year); | 383 | sscanf(ptr,"%d-%3s-%d",&day,smonth,&year); |
334 | 384 | ||
335 | i=0; | 385 | i=0; |
336 | 386 | ||
337 | #ifdef __UNIX__ | 387 | #ifdef __UNIX__ |
@@ -351,28 +401,52 @@ stock *parse_csv_history_file(char *csv_file) | |||
351 | } | 401 | } |
352 | sprintf(date,"%.2d%.2d%.2d", year, month, day); | 402 | sprintf(date,"%.2d%.2d%.2d", year, month, day); |
353 | StockPtr->Date = date; | 403 | StockPtr->Date = date; |
354 | 404 | ||
355 | /* Open */ | 405 | /* Open */ |
356 | ptr = strtok(NULL, ","); | 406 | ptr = strtok(NULL, ","); |
357 | if (!ptr) return 0; | 407 | if (!ptr) |
408 | { | ||
409 | free_stock(StockPtr); | ||
410 | free_stock(FirstStockPtr); | ||
411 | free_stock(LastStockPtr); | ||
412 | return 0; | ||
413 | } | ||
358 | sscanf(ptr,"%f",&(StockPtr->OpenPrice)); | 414 | sscanf(ptr,"%f",&(StockPtr->OpenPrice)); |
359 | 415 | ||
360 | /* High */ | 416 | /* High */ |
361 | ptr = strtok(NULL, ","); | 417 | ptr = strtok(NULL, ","); |
362 | if (!ptr) return 0; | 418 | if (!ptr) |
419 | { | ||
420 | free_stock(StockPtr); | ||
421 | free_stock(FirstStockPtr); | ||
422 | free_stock(LastStockPtr); | ||
423 | return 0; | ||
424 | } | ||
363 | sscanf(ptr,"%f",&(StockPtr->MaxPrice)); | 425 | sscanf(ptr,"%f",&(StockPtr->MaxPrice)); |
364 | 426 | ||
365 | /* Low */ | 427 | /* Low */ |
366 | ptr = strtok(NULL, ","); | 428 | ptr = strtok(NULL, ","); |
367 | if (!ptr) return 0; | 429 | if (!ptr) |
430 | { | ||
431 | free_stock(StockPtr); | ||
432 | free_stock(FirstStockPtr); | ||
433 | free_stock(LastStockPtr); | ||
434 | return 0; | ||
435 | } | ||
368 | sscanf(ptr,"%f",&(StockPtr->MinPrice)); | 436 | sscanf(ptr,"%f",&(StockPtr->MinPrice)); |
369 | 437 | ||
370 | /* Close */ | 438 | /* Close */ |
371 | ptr = strtok(NULL, ","); | 439 | ptr = strtok(NULL, ","); |
372 | if (!ptr) return 0; | 440 | if (!ptr) |
441 | { | ||
442 | free_stock(StockPtr); | ||
443 | free_stock(FirstStockPtr); | ||
444 | free_stock(LastStockPtr); | ||
445 | return 0; | ||
446 | } | ||
373 | sscanf(ptr,"%f",&(StockPtr->LastPrice)); | 447 | sscanf(ptr,"%f",&(StockPtr->LastPrice)); |
374 | 448 | ||
375 | /* Volume */ | 449 | /* Volume */ |
376 | 450 | ||
377 | ptr = strtok(NULL, ","); | 451 | ptr = strtok(NULL, ","); |
378 | if (!ptr) | 452 | if (!ptr) |
diff --git a/noncore/todayplugins/stockticker/libstocks/currency.c b/noncore/todayplugins/stockticker/libstocks/currency.c index 9a08a9d..e0090e2 100644 --- a/noncore/todayplugins/stockticker/libstocks/currency.c +++ b/noncore/todayplugins/stockticker/libstocks/currency.c | |||
@@ -49,12 +49,13 @@ libstocks_return_code get_currency_exchange(char *from, | |||
49 | 49 | ||
50 | strcpy(symbol, from); | 50 | strcpy(symbol, from); |
51 | strcat(symbol, into); | 51 | strcat(symbol, into); |
52 | strcat(symbol, "=X"); | 52 | strcat(symbol, "=X"); |
53 | 53 | ||
54 | error = get_stocks(symbol, &data); | 54 | error = get_stocks(symbol, &data); |
55 | free(symbol); | ||
55 | if (error) | 56 | if (error) |
56 | { | 57 | { |
57 | *exchange = 0; | 58 | *exchange = 0; |
58 | return(error); | 59 | return(error); |
59 | } | 60 | } |
60 | 61 | ||
diff --git a/noncore/todayplugins/stockticker/libstocks/lists.h b/noncore/todayplugins/stockticker/libstocks/lists.h index 0132317..a0eb434 100644 --- a/noncore/todayplugins/stockticker/libstocks/lists.h +++ b/noncore/todayplugins/stockticker/libstocks/lists.h | |||
@@ -27,9 +27,10 @@ | |||
27 | #define PUBEXT_LISTS | 27 | #define PUBEXT_LISTS |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #include "stocks.h" | 30 | #include "stocks.h" |
31 | 31 | ||
32 | PUBEXT_LISTS stock *malloc_stock(void); | 32 | PUBEXT_LISTS stock *malloc_stock(void); |
33 | PUBEXT_LISTS void free_stock(stock*); | ||
33 | 34 | ||
34 | 35 | ||
35 | #endif /* __LISTS_H */ | 36 | #endif /* __LISTS_H */ |
diff --git a/noncore/todayplugins/stockticker/libstocks/stocks.c b/noncore/todayplugins/stockticker/libstocks/stocks.c index eb04ba9..3a26a47 100644 --- a/noncore/todayplugins/stockticker/libstocks/stocks.c +++ b/noncore/todayplugins/stockticker/libstocks/stocks.c | |||
@@ -234,23 +234,22 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) | |||
234 | /* look for "." in the symbol */ | 234 | /* look for "." in the symbol */ |
235 | source = find_yahoo_source(symbol); | 235 | source = find_yahoo_source(symbol); |
236 | 236 | ||
237 | switch (source) | 237 | switch (source) |
238 | { | 238 | { |
239 | case YAHOO_US: | 239 | case YAHOO_US: |
240 | |||
241 | if (us_quotes) | 240 | if (us_quotes) |
242 | { | 241 | { |
243 | lgr_us_quotes = strlen(us_quotes); | 242 | lgr_us_quotes = strlen(us_quotes); |
244 | lgr_symbol = strlen(symbol); | 243 | lgr_symbol = strlen(symbol); |
245 | 244 | ||
246 | us_quotes_temp = malloc(lgr_us_quotes + lgr_symbol +2); | 245 | us_quotes_temp = malloc(lgr_us_quotes + lgr_symbol +2); |
247 | if(us_quotes_temp==NULL) | 246 | if(us_quotes_temp==NULL) |
248 | { | 247 | { |
249 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 248 | fprintf(stderr,"Memory allocating error (%s line %d)\n", |
250 | ,__FILE__, __LINE__); | 249 | __FILE__, __LINE__); |
251 | exit(1); | 250 | exit(1); |
252 | } | 251 | } |
253 | strcpy(us_quotes_temp, us_quotes); | 252 | strcpy(us_quotes_temp, us_quotes); |
254 | strcat(us_quotes_temp,"+"); | 253 | strcat(us_quotes_temp,"+"); |
255 | strcat(us_quotes_temp,symbol); | 254 | strcat(us_quotes_temp,symbol); |
256 | 255 | ||
@@ -260,33 +259,32 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) | |||
260 | else | 259 | else |
261 | { | 260 | { |
262 | us_quotes = malloc(strlen(symbol)+1); | 261 | us_quotes = malloc(strlen(symbol)+1); |
263 | 262 | ||
264 | if(us_quotes==NULL) | 263 | if(us_quotes==NULL) |
265 | { | 264 | { |
266 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 265 | fprintf(stderr,"Memory allocating error (%s line %d)\n", |
267 | ,__FILE__, __LINE__); | 266 | __FILE__, __LINE__); |
268 | exit(1); | 267 | exit(1); |
269 | } | 268 | } |
270 | strcpy(us_quotes, symbol); | 269 | strcpy(us_quotes, symbol); |
271 | } | 270 | } |
272 | 271 | ||
273 | break; | 272 | break; |
274 | 273 | ||
275 | case YAHOO_EUROPE: | 274 | case YAHOO_EUROPE: |
276 | |||
277 | if (eu_quotes) | 275 | if (eu_quotes) |
278 | { | 276 | { |
279 | lgr_eu_quotes = strlen(eu_quotes); | 277 | lgr_eu_quotes = strlen(eu_quotes); |
280 | lgr_symbol = strlen(symbol); | 278 | lgr_symbol = strlen(symbol); |
281 | 279 | ||
282 | eu_quotes_temp = malloc(lgr_eu_quotes + lgr_symbol +2); | 280 | eu_quotes_temp = malloc(lgr_eu_quotes + lgr_symbol +2); |
283 | if(eu_quotes_temp==NULL) | 281 | if(eu_quotes_temp==NULL) |
284 | { | 282 | { |
285 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 283 | fprintf(stderr,"Memory allocating error (%s line %d)\n", |
286 | ,__FILE__, __LINE__); | 284 | __FILE__, __LINE__); |
287 | exit(1); | 285 | exit(1); |
288 | } | 286 | } |
289 | strcpy(eu_quotes_temp, eu_quotes); | 287 | strcpy(eu_quotes_temp, eu_quotes); |
290 | strcat(eu_quotes_temp, "+"); | 288 | strcat(eu_quotes_temp, "+"); |
291 | strcat(eu_quotes_temp, symbol); | 289 | strcat(eu_quotes_temp, symbol); |
292 | 290 | ||
@@ -295,14 +293,14 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) | |||
295 | } | 293 | } |
296 | else | 294 | else |
297 | { | 295 | { |
298 | eu_quotes = malloc(strlen(symbol)+1); | 296 | eu_quotes = malloc(strlen(symbol)+1); |
299 | if(eu_quotes==NULL) | 297 | if(eu_quotes==NULL) |
300 | { | 298 | { |
301 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 299 | fprintf(stderr,"Memory allocating error (%s line %d)\n", |
302 | ,__FILE__, __LINE__); | 300 | __FILE__, __LINE__); |
303 | exit(1); | 301 | exit(1); |
304 | } | 302 | } |
305 | strcpy(eu_quotes, symbol); | 303 | strcpy(eu_quotes, symbol); |
306 | } | 304 | } |
307 | break; | 305 | break; |
308 | } | 306 | } |
@@ -311,19 +309,21 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) | |||
311 | free(tok_ptr); | 309 | free(tok_ptr); |
312 | 310 | ||
313 | if (us_quotes) | 311 | if (us_quotes) |
314 | { | 312 | { |
315 | /* Gets us quotes */ | 313 | /* Gets us quotes */ |
316 | error = download_stocks(us_quotes, &stocks_tmp, YAHOO_US); | 314 | error = download_stocks(us_quotes, &stocks_tmp, YAHOO_US); |
315 | free(us_quotes); | ||
317 | if (error) return error; | 316 | if (error) return error; |
318 | } | 317 | } |
319 | 318 | ||
320 | if (eu_quotes) | 319 | if (eu_quotes) |
321 | { | 320 | { |
322 | /* Gets european quotes */ | 321 | /* Gets european quotes */ |
323 | error = download_stocks(eu_quotes, &stocks_getted, YAHOO_EUROPE); | 322 | error = download_stocks(eu_quotes, &stocks_getted, YAHOO_EUROPE); |
323 | free(eu_quotes); | ||
324 | if (error) return error; | 324 | if (error) return error; |
325 | 325 | ||
326 | /* concats lists if needed */ | 326 | /* concats lists if needed */ |
327 | if (stocks_tmp) | 327 | if (stocks_tmp) |
328 | { | 328 | { |
329 | stocks_tmp2 = stocks_tmp; | 329 | stocks_tmp2 = stocks_tmp; |
@@ -335,13 +335,14 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) | |||
335 | } | 335 | } |
336 | 336 | ||
337 | last_stock->NextStock = stocks_getted; | 337 | last_stock->NextStock = stocks_getted; |
338 | stocks_getted->PreviousStock = last_stock; | 338 | stocks_getted->PreviousStock = last_stock; |
339 | 339 | ||
340 | } | 340 | } |
341 | else (stocks_tmp = stocks_getted); | 341 | else |
342 | (stocks_tmp = stocks_getted); | ||
342 | } | 343 | } |
343 | 344 | ||
344 | *stock_datas = stocks_tmp; | 345 | *stock_datas = stocks_tmp; |
345 | 346 | ||
346 | return(0); | 347 | return(0); |
347 | } | 348 | } |