summaryrefslogtreecommitdiff
path: root/noncore/todayplugins
Side-by-side diff
Diffstat (limited to 'noncore/todayplugins') (more/less context) (show whitespace changes)
-rw-r--r--noncore/todayplugins/stockticker/libstocks/csv.c106
-rw-r--r--noncore/todayplugins/stockticker/libstocks/currency.c1
-rw-r--r--noncore/todayplugins/stockticker/libstocks/lists.h1
-rw-r--r--noncore/todayplugins/stockticker/libstocks/stocks.c23
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)
{
/* This Symbol is valid */
StockPtr = malloc_stock();
ptr = csv_strtok(line, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
symbol = (char *)malloc(strlen(ptr)+1);
if (symbol==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
strcpy((char *)(symbol), ptr);
StockPtr->Symbol = symbol;
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
name = (char *)malloc(strlen(ptr)+1);
if (name==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
strcpy((char *)(name), ptr);
StockPtr->Name = name;
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->CurrentPrice));
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
date = (char *)malloc(strlen(ptr)+1);
if (date==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
strcpy((char *)(date), ptr);
StockPtr->Date = date;
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
time = (char *)malloc(strlen(ptr)+1);
if (time==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
exit(1);
}
strcpy((char *)(time), ptr);
StockPtr->Time = time;
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->Variation));
StockPtr->Pourcentage = 100 * StockPtr->Variation /
(StockPtr->CurrentPrice - StockPtr->Variation);
StockPtr->LastPrice = StockPtr->CurrentPrice - StockPtr->Variation;
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->OpenPrice));
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->MaxPrice));
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->MinPrice));
ptr = csv_strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
StockPtr->Volume = atoi(ptr);
if( !FirstStockPtr )
{
FirstStockPtr = StockPtr;
StockPtr->PreviousStock = 0;
@@ -244,13 +284,17 @@ stock *parse_csv_file(char *csv)
/* Set the stock struct just with Symbol, all other are NULL */
/* This can be used to see if the symbol has been reached are not */
StockPtr = malloc_stock();
ptr = csv_strtok(line, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ return 0;
+ }
symbol = (char *)malloc(strlen(ptr)+1);
if (symbol==NULL)
{
fprintf(stderr,"Memory allocating error (%s line %d)\n"
,__FILE__, __LINE__);
@@ -325,13 +369,19 @@ stock *parse_csv_history_file(char *csv_file)
*end_line = 0;
StockPtr = malloc_stock();
/* Date */
ptr = strtok(line, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ free_stock(FirstStockPtr);
+ free_stock(LastStockPtr);
+ return 0;
+ }
sscanf(ptr,"%d-%3s-%d",&day,smonth,&year);
i=0;
#ifdef __UNIX__
@@ -351,28 +401,52 @@ stock *parse_csv_history_file(char *csv_file)
}
sprintf(date,"%.2d%.2d%.2d", year, month, day);
StockPtr->Date = date;
/* Open */
ptr = strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ free_stock(FirstStockPtr);
+ free_stock(LastStockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->OpenPrice));
/* High */
ptr = strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ free_stock(FirstStockPtr);
+ free_stock(LastStockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->MaxPrice));
/* Low */
ptr = strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ free_stock(FirstStockPtr);
+ free_stock(LastStockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->MinPrice));
/* Close */
ptr = strtok(NULL, ",");
- if (!ptr) return 0;
+ if (!ptr)
+ {
+ free_stock(StockPtr);
+ free_stock(FirstStockPtr);
+ free_stock(LastStockPtr);
+ return 0;
+ }
sscanf(ptr,"%f",&(StockPtr->LastPrice));
/* Volume */
ptr = strtok(NULL, ",");
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,
strcpy(symbol, from);
strcat(symbol, into);
strcat(symbol, "=X");
error = get_stocks(symbol, &data);
+ free(symbol);
if (error)
{
*exchange = 0;
return(error);
}
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 @@
#define PUBEXT_LISTS
#endif
#include "stocks.h"
PUBEXT_LISTS stock *malloc_stock(void);
+PUBEXT_LISTS void free_stock(stock*);
#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)
/* look for "." in the symbol */
source = find_yahoo_source(symbol);
switch (source)
{
case YAHOO_US:
-
if (us_quotes)
{
lgr_us_quotes = strlen(us_quotes);
lgr_symbol = strlen(symbol);
us_quotes_temp = malloc(lgr_us_quotes + lgr_symbol +2);
if(us_quotes_temp==NULL)
{
- fprintf(stderr,"Memory allocating error (%s line %d)\n"
- ,__FILE__, __LINE__);
+ fprintf(stderr,"Memory allocating error (%s line %d)\n",
+ __FILE__, __LINE__);
exit(1);
}
strcpy(us_quotes_temp, us_quotes);
strcat(us_quotes_temp,"+");
strcat(us_quotes_temp,symbol);
@@ -260,33 +259,32 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas)
else
{
us_quotes = malloc(strlen(symbol)+1);
if(us_quotes==NULL)
{
- fprintf(stderr,"Memory allocating error (%s line %d)\n"
- ,__FILE__, __LINE__);
+ fprintf(stderr,"Memory allocating error (%s line %d)\n",
+ __FILE__, __LINE__);
exit(1);
}
strcpy(us_quotes, symbol);
}
break;
case YAHOO_EUROPE:
-
if (eu_quotes)
{
lgr_eu_quotes = strlen(eu_quotes);
lgr_symbol = strlen(symbol);
eu_quotes_temp = malloc(lgr_eu_quotes + lgr_symbol +2);
if(eu_quotes_temp==NULL)
{
- fprintf(stderr,"Memory allocating error (%s line %d)\n"
- ,__FILE__, __LINE__);
+ fprintf(stderr,"Memory allocating error (%s line %d)\n",
+ __FILE__, __LINE__);
exit(1);
}
strcpy(eu_quotes_temp, eu_quotes);
strcat(eu_quotes_temp, "+");
strcat(eu_quotes_temp, symbol);
@@ -295,14 +293,14 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas)
}
else
{
eu_quotes = malloc(strlen(symbol)+1);
if(eu_quotes==NULL)
{
- fprintf(stderr,"Memory allocating error (%s line %d)\n"
- ,__FILE__, __LINE__);
+ fprintf(stderr,"Memory allocating error (%s line %d)\n",
+ __FILE__, __LINE__);
exit(1);
}
strcpy(eu_quotes, symbol);
}
break;
}
@@ -311,19 +309,21 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas)
free(tok_ptr);
if (us_quotes)
{
/* Gets us quotes */
error = download_stocks(us_quotes, &stocks_tmp, YAHOO_US);
+ free(us_quotes);
if (error) return error;
}
if (eu_quotes)
{
/* Gets european quotes */
error = download_stocks(eu_quotes, &stocks_getted, YAHOO_EUROPE);
+ free(eu_quotes);
if (error) return error;
/* concats lists if needed */
if (stocks_tmp)
{
stocks_tmp2 = stocks_tmp;
@@ -335,13 +335,14 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas)
}
last_stock->NextStock = stocks_getted;
stocks_getted->PreviousStock = last_stock;
}
- else (stocks_tmp = stocks_getted);
+ else
+ (stocks_tmp = stocks_getted);
}
*stock_datas = stocks_tmp;
return(0);
}