Changed to version 1.3.1.1.
[rpn.git] / src / include / rpn.h
blob3187626e3ae0c0fd6d701570bc2f9382d19afa70
1 /*******************************************************************************
2 * Reverse Polish Notation calculator. *
3 * Copyright (c) 2007-2008, Samuel Fredrickson <kinghajj@gmail.com> *
4 * All rights reserved. *
5 * *
6 * Redistribution and use in source and binary forms, with or without *
7 * modification, are permitted provided that the following conditions are met: *
8 * * Redistributions of source code must retain the above copyright *
9 * notice, this list of conditions and the following disclaimer. *
10 * * Redistributions in binary form must reproduce the above copyright *
11 * notice, this list of conditions and the following disclaimer in the *
12 * documentation and/or other materials provided with the distribution. *
13 * *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS *
15 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY *
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
24 * DAMAGE. *
25 ******************************************************************************/
27 /*******************************************************************************
28 * This is stack-based, so expressions can be as long as memory will allow. *
29 * Operators must be one-character long. You can add your own by editing *
30 * the RPN_operator function in parser.c. *
31 * I've commented this code to explain any 'magic' or otherwise cryptic *
32 * sections. I hope they will suffice. *
33 ******************************************************************************/
35 #ifndef __RPN_H__
36 #define __RPN_H__
38 #ifdef __cplusplus
39 extern "C" {
40 #endif // __cplusplus
42 #include <stdbool.h>
44 /* This wonderful header provides hashing for C structures. I use it to
45 * implement a hash table to store and find variables, commands, and operators.
47 * No library is needed; it is implemented entirely as C macros in the header.
49 #include "uthash.h"
51 // versioning
52 //! The major version number.
53 #define __RPN_MAJOR__ 1
54 //! The minor version number.
55 #define __RPN_MINOR__ 3
56 //! The revision version number.
57 #define __RPN_REVIS__ 1
58 //! The build version number.
59 #define __RPN_BUILD__ 1
61 #ifndef __cplusplus
62 //! Handy-dandy macro for allocating structures
63 #define new(x) (x*)RPN_malloc(sizeof(x))
64 #endif // __cplusplus
66 // setup the type of RPNValue and other auxillary macros.
67 #ifdef RPN_LONG_DOUBLE
68 typedef long double RPNValue;
69 #define RPN_VALUE_LONG_FORMAT "%Lf"
70 #define RPN_VALUE_SHORT_FORMAT "%Lg"
71 #define RPN_strtod strtold
73 #elif RPN_DOUBLE
74 typedef double RPNValue;
75 #define RPN_VALUE_LONG_FORMAT "%f"
76 #define RPN_VALUE_SHORT_FORMAT "%g"
77 #define RPN_strtod strtod
79 #else
80 #error Please define either RPN_LONG_DOUBLE or RPN_DOUBLE.
81 #endif
83 // header for circular-dependency of structures.
84 #include "structs.h"
86 #ifdef RPN_CONSOLE
87 #include "console/arguments.h"
88 #include "console/error.h"
89 #include "console/help.h"
90 #endif
92 // headers for structures and their methods.
93 #include "calculator.h"
94 #include "commands.h"
95 #include "history.h"
96 #include "operators.h"
97 #include "parser.h"
98 #include "stack.h"
99 #include "tokens.h"
100 #include "variables.h"
102 /* Conditionally include PSP declarations.
104 #ifdef RPN_PSP
105 #include "psp/psp.h"
106 #endif // RPN_PSP
108 /* Conditionally include Wii declarations.
110 #ifdef RPN_WII
111 #include "wii/wii.h"
112 #endif // RPN_WII
114 #ifdef __cplusplus
116 #endif // __cplusplus
118 #endif // __RPN_H__