GnuCash  5.6-150-g038405b370+
gnc-exp-parser.h
1 /********************************************************************\
2  * gnc-exp-parser.h -- Interface to expression parsing for GnuCash *
3  * Copyright (C) 2000 Dave Peticolas <dave@krondo.com> *
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 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
34 typedef enum
35 {
36  NO_ERR,
37  VARIABLE_IN_EXP,
38  NUM_ERRORS
39 } GNCParseError;
40 
41 /* Initialize the expression parser. If this function is not
42  * called before one of the other parsing routines (other than
43  * gnc_exp_parser_shutdown), it will be called if needed.
44  */
45 void gnc_exp_parser_init (void);
46 
54 void gnc_exp_parser_real_init( gboolean addPredefined );
55 
56 /* Shutdown the expression parser and free any associated memory in the ParserState. */
57 void gnc_exp_parser_shutdown (void);
58 
59 /* Undefine the variable name if it is already defined. */
60 void gnc_exp_parser_remove_variable (const char *variable_name);
61 
62 /* Set the value of the variable to the given value. If the variable is
63  * not already defined, it will be after the call. */
64 void gnc_exp_parser_set_value (const char * variable_name,
65  gnc_numeric value);
66 
67 /* Parse the given expression using the current variable definitions.
68  * If the parse was successful, return TRUE and, if value_p is
69  * non-NULL, return the value of the resulting expression in *value_p.
70  * Otherwise, return FALSE and *value_p is unchanged. If FALSE is
71  * returned and error_loc_p is non-NULL, *error_loc_p is set to the
72  * character in expression where parsing aborted. If TRUE is returned
73  * and error_loc_p is non-NULL, *error_loc_p is set to NULL. */
74 gboolean gnc_exp_parser_parse (const char * expression,
75  gnc_numeric *value_p,
76  char **error_loc_p );
77 
87 gboolean gnc_exp_parser_parse_separate_vars (const char * expression,
88  gnc_numeric *value_p,
89  char **error_loc_p,
90  GHashTable *varHash );
91 
92 /* If the last parse returned FALSE, return an error string describing
93  * the problem. Otherwise, return NULL. */
94 const char * gnc_exp_parser_error_string (void);
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 #endif