Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

eval.h

Go to the documentation of this file.
00001 /* 
00002  *      HT Editor
00003  *      eval.h
00004  *
00005  *      Copyright (C) 1999, 2000, 2001 Stefan Weyergraf (stefan@weyergraf.de)
00006  *
00007  *      This program is free software; you can redistribute it and/or modify
00008  *      it under the terms of the GNU General Public License version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifndef __EVAL_H__
00022 #define __EVAL_H__
00023 
00024 /*#define EVAL_DEBUG*/
00025 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif /* __cplusplus */
00029 
00030 #include <math.h>
00031 #include <stdarg.h>
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 
00036 #ifdef HAVE_CONFIG_H
00037 #include "config.h"
00038 #endif
00039 
00040 #include "evaltype.h"
00041 
00042 typedef int (*eval_func_handler)(eval_scalar *result, char *name, eval_scalarlist *params);
00043 typedef int (*eval_symbol_handler)(eval_scalar *result, char *name);
00044 
00045 #include "lex.h"
00046 #include "evalx.h"
00047 
00048 #ifdef EVAL_DEBUG
00049 
00050 int debug_dump_ident;
00051 
00052 #endif
00053 
00054 /*
00055  *
00056  */
00057 
00058 #define MAX_FUNCNAME_LEN                16
00059 #define MAX_SYMBOLNAME_LEN      32
00060 #define MAX_ERRSTR_LEN          128
00061 
00062 /*
00063 int f2i(double f);
00064 char *binstr2cstr(char *s, int len);
00065 int bin2str(char *result, void *S, int len);
00066 */
00067 
00068 /*
00069  *      ERROR HANDLING
00070  */
00071 
00072 void clear_eval_error();
00073 int get_eval_error(char **str, int *pos);
00074 void set_eval_error(char *format,...);
00075 void set_eval_error_ex(int pos, char *format, ...);
00076 
00077 /*
00078  *
00079  */
00080 
00081 
00082 #ifdef EVAL_DEBUG
00083 
00084 void integer_dump(eval_int *i);
00085 void float_dump(eval_float *f);
00086 void string_dump(eval_str *s);
00087 
00088 #endif
00089 
00090 void string_destroy(eval_str *s);
00091 
00092 /*
00093  *      SCALARLIST
00094  */
00095 
00096 void scalarlist_set(eval_scalarlist *l, eval_scalar *s);
00097 void scalarlist_concat(eval_scalarlist *l, eval_scalarlist *a, eval_scalarlist *b);
00098 void scalarlist_destroy(eval_scalarlist *l);
00099 void scalarlist_destroy_gentle(eval_scalarlist *l);
00100 
00101 #ifdef EVAL_DEBUG
00102 void scalarlist_dump(eval_scalarlist *l);
00103 #endif
00104 
00105 /*
00106  *      SCALAR
00107  */
00108 
00109 void scalar_setint(eval_scalar *s, eval_int *i);
00110 void scalar_setstr(eval_scalar *s, eval_str *t);
00111 
00112 #ifdef EVAL_DEBUG
00113 void scalar_dump(eval_scalar *s);
00114 #endif
00115 
00116 void scalar_create_int(eval_scalar *result, const eval_int *t);
00117 void scalar_create_int_c(eval_scalar *result, const int i);
00118 void scalar_create_int_q(eval_scalar *result, const qword q);
00119 void scalar_create_str(eval_scalar *result, const eval_str *t);
00120 void scalar_create_str_c(eval_scalar *result, const char *cstr);
00121 void scalar_create_float(eval_scalar *result, const eval_float *t);
00122 void scalar_create_float_c(eval_scalar *result, const double f);
00123 
00124 void scalar_clone(eval_scalar *result, const eval_scalar *s);
00125 
00126 void scalar_context_str(const eval_scalar *s, eval_str *t);
00127 void scalar_context_int(const eval_scalar *s, eval_int *t);
00128 void scalar_context_float(const eval_scalar *s, eval_float *t);
00129 void string_concat(eval_str *s, eval_str *a, eval_str *b);
00130 void scalar_concat(eval_scalar *s, const eval_scalar *a, const eval_scalar *b);
00131 void scalar_destroy(eval_scalar *s);
00132 int string_compare(const eval_str *a, const eval_str *b);
00133 int scalar_strop(eval_scalar *xr, const eval_scalar *xa, const eval_scalar *xb, int op);
00134 int scalar_float_op(eval_scalar *xr, const eval_scalar *xa, const eval_scalar *xb, int op);
00135 int scalar_int_op(eval_scalar *xr, const eval_scalar *xa, const eval_scalar *xb, int op);
00136 int scalar_op(eval_scalar *xr, eval_scalar *xa, eval_scalar *xb, int op);
00137 void scalar_negset(eval_scalar *xr, eval_scalar *xa);
00138 void scalar_notset(eval_scalar *xr, eval_scalar *xa);
00139 void scalar_lnotset(eval_scalar *xr, eval_scalar *xa);
00140 void scalar_miniif(eval_scalar *xr, eval_scalar *xa, eval_scalar *xb, eval_scalar *xc);
00141 void sprintf_puts(char **b, char *blimit, char *buf);
00142 int sprintf_percent(char **fmt, int *fmtl, char **b, char *blimit, eval_scalar *s);
00143 int func_sprintf(eval_scalar *r, const eval_str *format, const eval_scalarlist *scalars);
00144 
00145 /*
00146  *      FUNCTIONS
00147  */
00148 
00149 int func_eval(eval_scalar *r, eval_str *p);
00150 int func_error(eval_scalar *r, eval_str *s);
00151 eval_protomatch match_evalfunc_proto(char *name, eval_scalarlist *params, eval_func *proto);
00152 int exec_evalfunc(eval_scalar *r, eval_scalarlist *params, eval_func *proto);
00153 int evalsymbol(eval_scalar *r, char *sname);
00154 int std_eval_func_handler(eval_scalar *r, char *fname, eval_scalarlist *params, eval_func *protos);
00155 int evalfunc(eval_scalar *r, char *fname, eval_scalarlist *params);
00156 void *eval_get_context();
00157 void eval_set_context(void *context);
00158 void eval_set_func_handler(eval_func_handler func_handler);
00159 void eval_set_symbol_handler(eval_symbol_handler symbol_handler);
00160 
00161 #ifdef __cplusplus
00162 }
00163 #endif /* __cplusplus */
00164 
00165 /*
00166  *      Debugging
00167  */
00168 
00169 #ifdef EVAL_DEBUG
00170 
00171 extern int debug_dump_ident;
00172 
00173 #define DEBUG_DUMP_INDENT {\
00174         int i;\
00175         for (i=0; i<debug_dump_ident; i++) printf("\t");\
00176 }
00177 
00178 #define DEBUG_DUMP(text...) {\
00179         DEBUG_DUMP_INDENT;\
00180         printf(text);\
00181         printf("\n");\
00182 }
00183         
00184 #define DEBUG_DUMP_SCALAR(scalarptr, text...) {\
00185         DEBUG_DUMP_INDENT;\
00186         printf(text);\
00187         scalar_dump(scalarptr);\
00188         printf("\n");\
00189 }
00190 
00191 #define DEBUG_DUMP_SCALARLIST(scalarlistptr, text...) {\
00192         DEBUG_DUMP_INDENT;\
00193         printf(text);\
00194         scalarlist_dump(scalarlistptr);\
00195         printf("\n");\
00196 }
00197 
00198 #define DEBUG_DUMP_INDENT_IN debug_dump_ident++
00199 #define DEBUG_DUMP_INDENT_OUT debug_dump_ident--
00200 
00201 #else
00202 
00203 #define DEBUG_DUMP(text...)
00204 #define DEBUG_DUMP_SCALAR(scalarptr, text...)
00205 #define DEBUG_DUMP_SCALARLIST(scalarlistptr, text...)
00206 #define DEBUG_DUMP_INDENT_IN
00207 #define DEBUG_DUMP_INDENT_OUT
00208 
00209 #endif
00210 
00211 #endif /* __EVAL_H__ */
00212 

Generated on Fri May 7 21:15:30 2004 by doxygen 1.3.5