2000-08-31 02:16:55 -05:00
|
|
|
/********************************************************************\
|
|
|
|
* gnc-exp-parser.h -- Interface to expression parsing for GnuCash *
|
|
|
|
* Copyright (C) 2000 Dave Peticolas <dave@krondo.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
|
|
|
* along with this program; if not, write to the Free Software *
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
|
|
|
|
\********************************************************************/
|
|
|
|
|
2001-07-03 01:49:39 -05:00
|
|
|
#ifndef GNC_EXP_PARSER_H
|
|
|
|
#define GNC_EXP_PARSER_H
|
2000-08-31 02:16:55 -05:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2000-10-30 04:46:46 -06:00
|
|
|
#include "gnc-numeric.h"
|
|
|
|
|
2000-08-31 02:16:55 -05:00
|
|
|
/* Initialize the expression parser. If this function is not
|
|
|
|
* called before one of the other parsing routines (other than
|
2001-07-30 03:32:02 -05:00
|
|
|
* gnc_exp_parser_shutdown), it will be called if needed.
|
|
|
|
*/
|
2000-08-31 02:16:55 -05:00
|
|
|
void gnc_exp_parser_init (void);
|
|
|
|
|
2001-07-30 03:32:02 -05:00
|
|
|
/* Shutdown the expression parser and free any associated memory in the ParserState. */
|
2000-08-31 02:16:55 -05:00
|
|
|
void gnc_exp_parser_shutdown (void);
|
|
|
|
|
|
|
|
/* Return a list of variable names which are currently defined
|
|
|
|
* in the parser. The names should not be modified or freed. */
|
|
|
|
GList * gnc_exp_parser_get_variable_names (void);
|
|
|
|
|
|
|
|
/* Undefine the variable name if it is already defined. */
|
|
|
|
void gnc_exp_parser_remove_variable (const char *variable_name);
|
|
|
|
|
|
|
|
/* Undefine every variable name appearing in the list. Variables in
|
|
|
|
* the list which are not defined are ignored. */
|
|
|
|
void gnc_exp_parser_remove_variable_names (GList * variable_names);
|
|
|
|
|
|
|
|
/* Return TRUE if the variable is defined, FALSE otherwise. If defined
|
|
|
|
* and value_p != NULL, return the value in *value_p, otherwise, *value_p
|
|
|
|
* is unchanged. */
|
|
|
|
gboolean gnc_exp_parser_get_value (const char * variable_name,
|
2000-10-30 04:46:46 -06:00
|
|
|
gnc_numeric *value_p);
|
2000-08-31 02:16:55 -05:00
|
|
|
|
|
|
|
/* Set the value of the variable to the given value. If the variable is
|
|
|
|
* not already defined, it will be after the call. */
|
2001-07-30 03:32:02 -05:00
|
|
|
void gnc_exp_parser_set_value (const char * variable_name,
|
|
|
|
gnc_numeric value);
|
2000-08-31 02:16:55 -05:00
|
|
|
|
|
|
|
/* Parse the given expression using the current variable definitions.
|
|
|
|
* If the parse was successful, return TRUE and, if value_p is
|
|
|
|
* non-NULL, return the value of the resulting expression in *value_p.
|
|
|
|
* Otherwise, return FALSE and *value_p is unchanged. If FALSE is
|
|
|
|
* returned and error_loc_p is non-NULL, *error_loc_p is set to the
|
|
|
|
* character in expression where parsing aborted. If TRUE is returned
|
|
|
|
* and error_loc_p is non-NULL, *error_loc_p is set to NULL. */
|
2001-07-30 03:32:02 -05:00
|
|
|
gboolean gnc_exp_parser_parse (const char * expression,
|
|
|
|
gnc_numeric *value_p,
|
|
|
|
char **error_loc_p );
|
|
|
|
|
|
|
|
/* Parses as per gnc_exp_parser_parse, but with an optional last argument
|
|
|
|
* dealing with a non-shared variable list and state, local to the expression
|
|
|
|
* being parsed. This is a hashTable of variable names mapping to
|
|
|
|
* gnc_numeric pointers. */
|
2001-08-03 18:17:31 -05:00
|
|
|
gboolean gnc_exp_parser_parse_separate_vars (const char * expression,
|
2001-07-30 03:32:02 -05:00
|
|
|
gnc_numeric *value_p,
|
|
|
|
char **error_loc_p,
|
|
|
|
GHashTable *varHash );
|
2000-08-31 02:16:55 -05:00
|
|
|
|
|
|
|
/* If the last parse returned FALSE, return an error string describing
|
|
|
|
* the problem. Otherwise, return NULL. */
|
|
|
|
const char * gnc_exp_parser_error_string (void);
|
|
|
|
|
|
|
|
#endif
|