summaryrefslogtreecommitdiff
path: root/noncore/todayplugins/stockticker/libstocks/currency.c
blob: e0090e2c2a65f6b8c61fe727dcf6d6c49f0d277b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* libstocks - Library to get current stock quotes from Yahoo Finance
 *
 * Copyright (C) 2000 Eric Laeuffer
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * 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
 * 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
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#define __CURRENCY_C__


#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>

#include "stocks.h"

/*****************************************************************************/
/* returns the currency exchange rate of "from" currency into                */
/* "into" currency.                                                          */
/*****************************************************************************/
libstocks_return_code get_currency_exchange(char *from, 
					    char *into, 
					    float *exchange)
{
  char *symbol;
  stock *data;
  libstocks_return_code error;

  if((symbol = (char *)malloc(strlen(from)+strlen(into)+3))==NULL)
    {
      fprintf(stderr,"Memory allocating error (%s line %d)\n"
	      ,__FILE__, __LINE__);
      exit(1);
    }

  strcpy(symbol, from);
  strcat(symbol, into);
  strcat(symbol, "=X");
  
  error = get_stocks(symbol, &data);
  free(symbol);
  if (error) 
    {
      *exchange = 0;
      return(error);
    }

  free_stocks(data);

  *exchange = data->CurrentPrice;
  return(error);
 
}