author | llornkcor <llornkcor> | 2002-10-31 00:09:31 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-10-31 00:09:31 (UTC) |
commit | 5a08fd92ac139820e1a1202d0b4b67190f24ccdb (patch) (unidiff) | |
tree | e9c0692cf445a886cd529b60f8e535922a7f5d4d /noncore/todayplugins/stockticker/libstocks/lists.c | |
parent | ad396dd7b58fc772423f95be050f645fc7a6d9b9 (diff) | |
download | opie-5a08fd92ac139820e1a1202d0b4b67190f24ccdb.zip opie-5a08fd92ac139820e1a1202d0b4b67190f24ccdb.tar.gz opie-5a08fd92ac139820e1a1202d0b4b67190f24ccdb.tar.bz2 |
added - initial check in
Diffstat (limited to 'noncore/todayplugins/stockticker/libstocks/lists.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/todayplugins/stockticker/libstocks/lists.c | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/noncore/todayplugins/stockticker/libstocks/lists.c b/noncore/todayplugins/stockticker/libstocks/lists.c new file mode 100644 index 0000000..1ed66b3 --- a/dev/null +++ b/noncore/todayplugins/stockticker/libstocks/lists.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /* libstocks - Library to get current stock quotes from Yahoo Finance | ||
2 | * | ||
3 | * Copyright (C) 2000 Eric Laeuffer | ||
4 | * | ||
5 | * This library is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Library General Public | ||
7 | * License as published by the Free Software Foundation; either | ||
8 | * version 2 of the License, or (at your option) any later version. | ||
9 | * | ||
10 | * This library is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * Library General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Library General Public | ||
16 | * License along with this library; if not, write to the | ||
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | * Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | #define __LISTS_C__ | ||
22 | |||
23 | #include <malloc.h> | ||
24 | #include <stdio.h> | ||
25 | #include <string.h> | ||
26 | |||
27 | #ifdef __WINDOWS__ | ||
28 | #include <stdlib.h> | ||
29 | #endif | ||
30 | |||
31 | #include "stocks.h" | ||
32 | #include "lists.h" | ||
33 | |||
34 | /******************************************************************************/ | ||
35 | /* Finds a stock in the stocks list and return the stock pointer. */ | ||
36 | /* *stocks points to the stocks list */ | ||
37 | /* *stock_to_find is the stock to find :)) */ | ||
38 | /******************************************************************************/ | ||
39 | stock *find_stock(stock *stocks, char *stock_to_find) | ||
40 | { | ||
41 | char *test=NULL; | ||
42 | |||
43 | while(stocks != NULL) | ||
44 | { | ||
45 | test = strstr(stocks->Symbol, stock_to_find); | ||
46 | if(test) return(stocks); | ||
47 | stocks = stocks->NextStock; | ||
48 | } | ||
49 | |||
50 | return(0); | ||
51 | } | ||
52 | |||
53 | /******************************************************************************/ | ||
54 | /* Allocate memory for a stock structure and return the pointer of this */ | ||
55 | /* structure. */ | ||
56 | /******************************************************************************/ | ||
57 | stock *malloc_stock(void) | ||
58 | { | ||
59 | stock *stockptr; | ||
60 | |||
61 | if((stockptr = (stock *)malloc(sizeof(stock)))==NULL) | ||
62 | { | ||
63 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | ||
64 | ,__FILE__, __LINE__); | ||
65 | exit(1); | ||
66 | } | ||
67 | |||
68 | stockptr->Symbol=NULL; | ||
69 | stockptr->Name=NULL; | ||
70 | stockptr->Time=NULL; | ||
71 | stockptr->Date=NULL; | ||
72 | stockptr->CurrentPrice=0; | ||
73 | stockptr->LastPrice=0; | ||
74 | stockptr->OpenPrice=0; | ||
75 | stockptr->MinPrice=0; | ||
76 | stockptr->MaxPrice=0; | ||
77 | stockptr->Variation=0; | ||
78 | stockptr->Pourcentage=0; | ||
79 | stockptr->Volume=0; | ||
80 | stockptr->PreviousStock=0; | ||
81 | stockptr->NextStock=0; | ||
82 | |||
83 | return(stockptr); | ||
84 | } | ||
85 | |||
86 | /******************************************************************************/ | ||
87 | /* Deallocates a stock structure. */ | ||
88 | /* *stocks_to_free is the pointer of the structure to free */ | ||
89 | /******************************************************************************/ | ||
90 | void free_stocks(stock *stock_to_free) | ||
91 | { | ||
92 | stock *next_stock; | ||
93 | |||
94 | while(stock_to_free) | ||
95 | { | ||
96 | next_stock = stock_to_free->NextStock; | ||
97 | free(stock_to_free->Symbol); | ||
98 | free(stock_to_free->Name); | ||
99 | free(stock_to_free->Time); | ||
100 | free(stock_to_free->Date); | ||
101 | free(stock_to_free); | ||
102 | stock_to_free = next_stock; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | /******************************************************************************/ | ||
107 | /* Returns the next stock structure from the list. */ | ||
108 | /* *the_stocks points to the list. */ | ||
109 | /******************************************************************************/ | ||
110 | stock *next_stock(stock *the_stock) | ||
111 | { | ||
112 | return((stock *)(the_stock->NextStock)); | ||
113 | } | ||
114 | |||
115 | /******************************************************************************/ | ||
116 | /* Returns the previous stock structure from the list. */ | ||
117 | /* *the_stocks points to the list. */ | ||
118 | /******************************************************************************/ | ||
119 | stock *previous_stock(stock *the_stock) | ||
120 | { | ||
121 | return((stock *)(the_stock->PreviousStock)); | ||
122 | } | ||
123 | |||