GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-exp-parser.h
1 /********************************************************************\
2  * gnc-exp-parser.h -- Interface to expression parsing for GnuCash *
3  * Copyright (C) 2000 Dave Peticolas <[email protected]> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program 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 *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
18 \********************************************************************/
19 
20 #ifndef GNC_EXP_PARSER_H
21 #define GNC_EXP_PARSER_H
22 
23 #include <glib.h>
24 
25 #include "qof.h"
26 
30 typedef enum
31 {
32  NO_ERR,
33  VARIABLE_IN_EXP,
34  NUM_ERRORS
35 } GNCParseError;
36 
37 /* Initialize the expression parser. If this function is not
38  * called before one of the other parsing routines (other than
39  * gnc_exp_parser_shutdown), it will be called if needed.
40  */
41 void gnc_exp_parser_init (void);
42 
50 void gnc_exp_parser_real_init( gboolean addPredefined );
51 
52 /* Shutdown the expression parser and free any associated memory in the ParserState. */
53 void gnc_exp_parser_shutdown (void);
54 
55 /* Undefine the variable name if it is already defined. */
56 void gnc_exp_parser_remove_variable (const char *variable_name);
57 
58 /* Set the value of the variable to the given value. If the variable is
59  * not already defined, it will be after the call. */
60 void gnc_exp_parser_set_value (const char * variable_name,
61  gnc_numeric value);
62 
63 /* Parse the given expression using the current variable definitions.
64  * If the parse was successful, return TRUE and, if value_p is
65  * non-NULL, return the value of the resulting expression in *value_p.
66  * Otherwise, return FALSE and *value_p is unchanged. If FALSE is
67  * returned and error_loc_p is non-NULL, *error_loc_p is set to the
68  * character in expression where parsing aborted. If TRUE is returned
69  * and error_loc_p is non-NULL, *error_loc_p is set to NULL. */
70 gboolean gnc_exp_parser_parse (const char * expression,
71  gnc_numeric *value_p,
72  char **error_loc_p );
73 
83 gboolean gnc_exp_parser_parse_separate_vars (const char * expression,
84  gnc_numeric *value_p,
85  char **error_loc_p,
86  GHashTable *varHash );
87 
88 /* If the last parse returned FALSE, return an error string describing
89  * the problem. Otherwise, return NULL. */
90 const char * gnc_exp_parser_error_string (void);
91 
92 #endif