author | llornkcor <llornkcor> | 2002-10-31 20:32:13 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-10-31 20:32:13 (UTC) |
commit | 73b03f932dd43d684e67db1837bf506ee015f2eb (patch) (side-by-side diff) | |
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 @@ -8,9 +8,9 @@ * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the @@ -18,8 +18,9 @@ * Boston, MA 02111-1307, USA. */ #define __CSV_C__ +#ifdef __UNIX__ #include <string.h> #include <stdlib.h> #include <stdio.h> @@ -125,154 +126,154 @@ stock *parse_csv_file(char *csv) test = line; valid = 0; while ( (test = strstr(test, "N/A")) ) - { - valid ++; - test = test +3; - } + { + valid ++; + test = test +3; + } if (valid < 6) - { - /* This Symbol is valid */ - - StockPtr = malloc_stock(); - - ptr = csv_strtok(line, ","); - if (!ptr) 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; - - 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; - sscanf(ptr,"%f",&(StockPtr->CurrentPrice)); - - ptr = csv_strtok(NULL, ","); - if (!ptr) 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; - - 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; - 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; - sscanf(ptr,"%f",&(StockPtr->OpenPrice)); - - ptr = csv_strtok(NULL, ","); - if (!ptr) return 0; - sscanf(ptr,"%f",&(StockPtr->MaxPrice)); - - ptr = csv_strtok(NULL, ","); - if (!ptr) return 0; - sscanf(ptr,"%f",&(StockPtr->MinPrice)); + { + /* This Symbol is valid */ + + StockPtr = malloc_stock(); + + ptr = csv_strtok(line, ","); + if (!ptr) 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; + + 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; + sscanf(ptr,"%f",&(StockPtr->CurrentPrice)); + + ptr = csv_strtok(NULL, ","); + if (!ptr) 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; + + 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; + 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; + sscanf(ptr,"%f",&(StockPtr->OpenPrice)); + + ptr = csv_strtok(NULL, ","); + if (!ptr) return 0; + sscanf(ptr,"%f",&(StockPtr->MaxPrice)); + + ptr = csv_strtok(NULL, ","); + if (!ptr) return 0; + sscanf(ptr,"%f",&(StockPtr->MinPrice)); - ptr = csv_strtok(NULL, ","); - if (!ptr) return 0; - StockPtr->Volume = atoi(ptr); - - if( !FirstStockPtr ) - { - FirstStockPtr = StockPtr; - StockPtr->PreviousStock = 0; - } - - StockPtr->NextStock = 0; - - if (LastStockPtr) - { - LastStockPtr->NextStock = StockPtr; - StockPtr->PreviousStock = LastStockPtr; - } - - LastStockPtr = StockPtr; - - } + ptr = csv_strtok(NULL, ","); + if (!ptr) return 0; + StockPtr->Volume = atoi(ptr); + + if( !FirstStockPtr ) + { + FirstStockPtr = StockPtr; + StockPtr->PreviousStock = 0; + } + + StockPtr->NextStock = 0; + + if (LastStockPtr) + { + LastStockPtr->NextStock = StockPtr; + StockPtr->PreviousStock = LastStockPtr; + } + + LastStockPtr = StockPtr; + + } else - { - /* this symbol is not valid */ - /* 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; - - 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; - - if( !FirstStockPtr ) - { - FirstStockPtr = StockPtr; - StockPtr->PreviousStock = 0; - } - - StockPtr->NextStock = 0; - - if (LastStockPtr) - { - LastStockPtr->NextStock = StockPtr; - StockPtr->PreviousStock = LastStockPtr; - } - - LastStockPtr = StockPtr; - } + { + /* this symbol is not valid */ + /* 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; + + 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; + + if( !FirstStockPtr ) + { + FirstStockPtr = StockPtr; + StockPtr->PreviousStock = 0; + } + + StockPtr->NextStock = 0; + + if (LastStockPtr) + { + LastStockPtr->NextStock = StockPtr; + StockPtr->PreviousStock = LastStockPtr; + } + + LastStockPtr = StockPtr; + } end_line++; line = end_line; @@ -320,9 +321,9 @@ stock *parse_csv_history_file(char *csv_file) { *end_line = 0; StockPtr = malloc_stock(); - + /* Date */ ptr = strtok(line, ","); if (!ptr) return 0; @@ -339,13 +340,13 @@ stock *parse_csv_history_file(char *csv_file) month = i+1; date = (char *)malloc(DATE_LENGTH); if (date==NULL) - { - fprintf(stderr,"Memory allocating error (%s line %d)\n" - ,__FILE__, __LINE__); - exit(1); - } + { + fprintf(stderr,"Memory allocating error (%s line %d)\n" + ,__FILE__, __LINE__); + exit(1); + } sprintf(date,"%.2d%.2d%.2d", year, month, day); StockPtr->Date = date; /* Open */ @@ -371,27 +372,27 @@ stock *parse_csv_history_file(char *csv_file) /* Volume */ ptr = strtok(NULL, ","); if (!ptr) - /* It seems to be an indice */ - /* No volume for indices */ - StockPtr->Volume = 0; + /* It seems to be an indice */ + /* No volume for indices */ + StockPtr->Volume = 0; else - StockPtr->Volume = atoi(ptr); + StockPtr->Volume = atoi(ptr); if( !FirstStockPtr ) - { - FirstStockPtr = StockPtr; - StockPtr->PreviousStock = 0; - } + { + FirstStockPtr = StockPtr; + StockPtr->PreviousStock = 0; + } StockPtr->NextStock = 0; if (LastStockPtr) - { - LastStockPtr->NextStock = StockPtr; - StockPtr->PreviousStock = LastStockPtr; - } + { + LastStockPtr->NextStock = StockPtr; + StockPtr->PreviousStock = LastStockPtr; + } LastStockPtr = StockPtr; end_line++; 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 @@ -8,9 +8,9 @@ * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the @@ -18,8 +18,9 @@ * Boston, MA 02111-1307, USA. */ #define __HTTP_C__ +#define __UNIX__ #ifdef __UNIX__ #include <sys/socket.h> #include <netinet/in.h> @@ -84,11 +85,11 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) } else { #ifdef DEBUG - printf(" gethostbyname : NOK\n"); + printf(" gethostbyname : NOK\n"); #endif - return ERRHOST; + return ERRHOST; } /* create socket */ if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) @@ -120,9 +121,9 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) /* create header */ if (http_proxy_server) { sprintf(header,"GET http://%.128s:80%.256s HTTP/1.0\015\012\015\012", - http_server, http_file); + http_server, http_file); } else { sprintf(header,"GET %s HTTP/1.0\015\012\015\012",http_file); @@ -137,9 +138,9 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) if (send(s,header,hlg, 0)!=hlg) #endif { #ifdef DEBUG - printf(" send header : NOK\n"); + printf(" send header : NOK\n"); #endif return ERRWHEA; } @@ -156,38 +157,38 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) r=recv(s,buf,BUF_SIZE,0); #endif if (r) - { - if(!data_lgr) - { - if((data = malloc(r+1))==NULL) - { - fprintf(stderr,"Memory allocating error (%s line %d)\n" - ,__FILE__, __LINE__); - exit(1); - } - - memcpy(data,buf,r); - data_lgr = r; - data[r]=0; - } - else - { - if((temp = malloc(r+data_lgr+1))==NULL) - { - fprintf(stderr,"Memory allocating error (%s line %d)\n" - ,__FILE__, __LINE__); - exit(1); - } - memcpy(temp, data, data_lgr); - memcpy(temp+data_lgr, buf, r); - temp[r+data_lgr]=0; - data_lgr += r; - free(data); - data = temp; - } - } + { + if(!data_lgr) + { + if((data = malloc(r+1))==NULL) + { + fprintf(stderr,"Memory allocating error (%s line %d)\n" + ,__FILE__, __LINE__); + exit(1); + } + + memcpy(data,buf,r); + data_lgr = r; + data[r]=0; + } + else + { + if((temp = malloc(r+data_lgr+1))==NULL) + { + fprintf(stderr,"Memory allocating error (%s line %d)\n" + ,__FILE__, __LINE__); + exit(1); + } + memcpy(temp, data, data_lgr); + memcpy(temp+data_lgr, buf, r); + temp[r+data_lgr]=0; + data_lgr += r; + free(data); + data = temp; + } + } } /* close socket */ #ifdef __UNIX__ @@ -209,16 +210,16 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) { if (*temp==0) return ERRRHEA; if( *temp==0x0A ) - { - /* test if it is the header end */ - temp ++; - if (*temp == 0x0D) temp++; - if (*temp == 0x0A) header_founded = 1; - } + { + /* test if it is the header end */ + temp ++; + if (*temp == 0x0D) temp++; + if (*temp == 0x0A) header_founded = 1; + } else - temp++; + temp++; } *temp = 0; temp++; @@ -237,9 +238,9 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) if ((csv_ptr = malloc(strlen(temp)+1))==NULL) { free(data); fprintf(stderr,"Memory allocating error (%s line %d)\n" - ,__FILE__, __LINE__); + ,__FILE__, __LINE__); exit(1); } memcpy(csv_ptr, temp, strlen(temp)+1); |