Subversion Repositories wimsdev

Rev

Rev 14712 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 reyssat 1
/*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
2
 *
3
 *  This program is free software; you can redistribute it and/or modify
4
 *  it under the terms of the GNU General Public License as published by
5
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  (at your option) any later version.
7
 *
8
 *  This program is distributed in the hope that it will be useful,
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  GNU General Public License for more details.
12
 *
13
 *  You should have received a copy of the GNU General Public License
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
17
 
18
/* WWW multipurpose server, dynamic library definitions */
19
 
20
#include "../config.h"
21
#include "../includes.h"
22
#include "../wimsdef.h"
23
 
7798 bpr 24
/* for mt19937ar.c */
10 reyssat 25
#ifdef RAND_MAX
26
# undef RAND_MAX
27
#endif
28
#define RAND_MAX 2147483647
29
#define random genrand_int31
30
#define srandom init_genrand
31
long int genrand_int31(void);
8100 bpr 32
void init_genrand(unsigned long s);
10 reyssat 33
 
8195 bpr 34
/* errors.c
10 reyssat 35
void (*error1) (char *msg);
36
void (*error2) (char *msg);
37
void (*error3) (char *msg);
8195 bpr 38
*/
10 reyssat 39
 
8122 bpr 40
/* liblines.c */
10 reyssat 41
char *int2str(int i);
42
void *xmalloc(size_t n);
7798 bpr 43
int msleep(int ms); /* millisecond sleeper */
44
void _tolinux(char *p);  /* dos/mac to unix/linux translation */
45
void ovlstrcpy(char *dest, char *src); /* strcpy of possibly overlapping strings (64 bits problem)*/
46
void mystrncpy(char *dest, const char *src, size_t lim); /* optimized and secured strncpy */
47
/* find matching parenthesis.
48
 * The entrance point should be after the opening parenthesis.
49
 * Returns NULL if unmatched.
50
 */
10 reyssat 51
char *find_matching(char *p, char c);
7798 bpr 52
char *find_word_start(char *p);       /* Strips leading spaces */
53
char *find_word_end(char *p);         /* Points to the end of the word */
54
char *strparchr(char *p, char c);     /* search for char, skipping parentheses */
55
char *strparstr(char *p, char *fnd);  /* search for string, skipping parentheses */
56
char *find_item_end(char *p);         /* Points to the end of an item */
57
char *find_line_end(char *p);         /* Points to the end of a line */
10 reyssat 58
char *charchr(char *p,char *w);
7798 bpr 59
char *wordchr(char *p, char *w);      /* Find first occurrence of word */
60
char *itemchr(char *p, char *w);      /* Find first occurrence of item */
61
char *linechr(char *p, char *w);      /* Find first occurrence of line */
62
char *varchr(char *p, char *v);       /* Find first occurrence of math variable */
63
int cutitems(char *p, char *list[], int max);       /* Cut items of a string */
64
int cutwords(char *p, char *list[], int max);       /* Cut words of a string */
65
int cutlines(char *p, char *list[], int max);       /* Cut lines of a string */
66
int cutchars(char *p, char *list[], int max);       /* Cut chars of a string */
67
char *strip_trailing_spaces(char *p);      /* strip trailing spaces; return string end. */
68
/* Verify whether a list is well-ordered. For debugging uses.
69
 * Returns 0 if order is OK, -1 otherwise.
70
 */
10 reyssat 71
int verify_order(void *list, int items, size_t item_size);
8079 bpr 72
/* searches a list. Returns index if found, (-1-index of insertion) if nomatch.
73
 * Uses binary search, list must be sorted.
74
 */
10 reyssat 75
int search_list(void *list, int items, size_t item_size, const char *str);
7798 bpr 76
unsigned int linenum(char *p);             /* Returns number of lines in string p */
77
unsigned int itemnum(char *p);             /* Returns number of items in the list p, comma separated */
78
unsigned int wordnum(char *p);             /* Returns number of words in string p */
79
unsigned int charnum(char *p);             /* This is just to suppress an annoying compiler warning message. */
10 reyssat 80
char *fnd_line(char *p, int n, char bf[]); /* find n-th line in string p */
81
char *fnd_item(char *p, int n, char bf[]); /* find n-th item in list p, comma separated */
82
char *fnd_word(char *p, int n, char bf[]); /* find n-th word in string p */
83
char *fnd_char(char *p, int n, char bf[]); /* find n-th char in string p */
7798 bpr 84
char *fnd_row(char *p, int n, char bf[]);  /* find n-th row in a matrix p */
85
/* Separate items in the string p, end each item with 0,
86
 * and store item pointers in parm[]. Does not parse past max.
8079 bpr 87
 * Returns the number of fields.
88
 */
10 reyssat 89
int separate_item(char *p, char *parm[], int max);
90
int separate_line(char *p, char *parm[], int max);
91
int separate_word(char *p, char *parm[], int max);
92
int _separator(char *p,char *parm[], int max, char fs);
7798 bpr 93
int rows2lines(char *p);        /* Returns 1 if semicolons changed to new lines */
10 reyssat 94
void lines2rows(char *p);
95
unsigned int rownum(char *p);
7798 bpr 96
void words2items(char *p);      /* change words to items */
97
void words2lines(char *p);      /* change words to lines */
98
void lines2items(char *p);      /* change lines to items */
99
void lines2words(char *p);      /* change lines to words */
100
void items2words(char *p);      /* change items to words */
101
void items2lines(char *p);      /* change items to lines */
102
void strip_enclosing_par(char *p); /* Strip enclosing pairs of parentheses */
103
/* strstr but may have embedded zeros.
104
 * Returns memory end if not found.
105
 * Supposes memory ends with 0.
106
 */
10 reyssat 107
char *memstr(char *s1, char *s2, int len);
7798 bpr 108
/* Check whether parentheses are balanced in a given string.
109
 * Returns 0 if OK.
110
 */
111
/* style=0: simple check. style<>0: strong check. */
10 reyssat 112
int check_parentheses(char *p, int style);
7798 bpr 113
void nospace(char *p);             /* collapses all space characters in string. */
114
void singlespace(char *p);         /* change all spaces into ' ', and collapse multiple occurences */
115
void deaccent(char *p);            /* fold accented letters to unaccented */
116
void reaccent(char *p);            /* compose accented letters using symbols */
14712 bpr 117
int mystrcmp (char*p1, char*p2);   /* strip accents and case before comparaison */
118
 
7798 bpr 119
/* modify a string. Bufferlen must be at least MAX_LINELEN */
8086 bpr 120
extern void (*string_modify)(char *start, char *bad_beg, char *bad_end, char *good,...);
121
void string_modify1(char *start, char *bad_beg, char *bad_end, char *good,...);
122
void string_modify2(char *start, char *bad_beg, char *bad_end, char *good,...);
123
 
8880 bpr 124
char *parend(char *p);
10 reyssat 125
long int filelength(char *fn,...);
126
int catfile(FILE *outf, char *fn,...);
8160 bpr 127
extern char *fnd_position;
128
extern char *fnd_nextpos;
10 reyssat 129
 
8100 bpr 130
extern char *acctab, *deatab;
131
 
13757 bpr 132
extern char *htmlsymbs[][2];
133
extern int htmltrans[][256];
134
void inithtmltrans();
135
 
7798 bpr 136
/* evalue.c */
137
#define EV_S "EVLS"
138
#define EV_T "EVLT"
139
#define EV_X "EVLX"
140
#define EV_Y "EVLY"
10 reyssat 141
typedef struct ev_variable{
142
    char *name; double value;
143
} ev_variable;
8160 bpr 144
 
145
extern int *ev_varcnt;
146
extern ev_variable *ev_var;
147
 
148
 
10 reyssat 149
char *moneyprint(char *p, double s);
150
double factorial(double d);
151
void init_random(void);
152
double drand(double m);
153
double irand(double n);
154
double sign(double d);
155
double factorial(double d);
156
double binomial(double d1,double d2);
157
double max(double d1, double d2);
158
double min(double d1, double d2);
159
double gcd(double n1, double n2);
160
double lcm(double n1, double n2);
7798 bpr 161
int eval_getpos(char *name);            /* get position of name in nametable */
162
void eval_setval(int pos, double v);    /* set value to name */
7847 bpr 163
/*void set_evalue_pointer(char *p); */      /* prepare pointer for evaluation */
164
/* char *get_evalue_pointer(void); */        /* get string pointer (after evaluation) */
165
/* double _evalue(int ord);*/
166
double strevalue(char *p);              /* evalue a string to double after checking it*/
167
double checked_eval (char* p);  /* evalue a string to double */
14873 georgesk 168
 
169
/**
170
 * GK 2020-04-17
171
 * the following line is a varaible declaration : it should never be used
172
 * in a header file. So it is commented out and replaced by an "extern"
173
 * clause. The actual variable is defined in evalue.c, line 447
10 reyssat 174
char *(*substitute) (char *p);
14873 georgesk 175
 **/
176
extern char *(*substitute) (char *p);
177
 
7847 bpr 178
/* int get_evalue_error(void);
179
void set_evalue_error(int e);*/
10 reyssat 180
int get_evalcnt(void);
181
char *get_evalname(int i);
182
int get_evaltype(int i);
183
int evaltab_verify(void);
184
int search_evaltab(char *p);
7798 bpr 185
/* compile an expression for faster evaluation
186
 * returns -1 if cannot be compiled.
187
 * else returns the number of compilations.
188
 */
10 reyssat 189
int evalue_compile(char *p);
7847 bpr 190
typedef struct eval_struct {char *texte; int x; int y; int s; int t;} eval_struct;
191
eval_struct * eval_create (char *in_p); /* speed up the evaluation by
192
  "precompiling" the string to be evaluated.*/
193
/* evaluate standard functions with at most four variables named
194
 * "x", "y", "s" and "t"
195
 */
10 reyssat 196
 
7847 bpr 197
double eval_x (eval_struct *p, double x); /* evaluate standard function in x*/
198
double eval_t (eval_struct *p, double t); /* evaluate standard function in t*/
199
double eval_x_y (eval_struct *p, double x, double y); /* evaluate standard function in x and y*/
200
double eval_multiple (eval_struct *p, double x, double y, double s, double t);
201
void eval_destroy (eval_struct *q); /* reclaim the memory */
202
 
7798 bpr 203
/* math.c */
204
char *find_mathvar_start(char *p);  /* Points to the start of a mathematics variable (or number) */
205
char *find_mathvar_end(char *p);    /* Points to the end of a mathematics variable (or number) */
206
void mathvarlist(char *p);          /* list variable (function) names in an expression. buffer is modified to contain the list. */
10 reyssat 207
 
7798 bpr 208
/* dir.c */
209
int remove_tree(char *dirname);     /* remove a directory tree */
210
void mkdirs(char *s);               /* recursively generate a directory structure */
10 reyssat 211
 
7798 bpr 212
/* text.c */
213
void text(char *p);                 /* main entry point for text routines */
10 reyssat 214
int textab_verify(void);
215
 
7798 bpr 216
/* levelcurve.c */
217
#define LEVEL_LIM      256
218
#define LEVELPOINT_LIM 16384
219
#define LEVELSIZE_LIM  2048
220
#define LEVELGRAIN_LIM 16
10 reyssat 221
typedef struct {
222
    char *fn, *xname, *yname;
223
    double levels[LEVEL_LIM];
224
    int xsize,ysize,grain,levelcnt,datacnt,xevpos,yevpos;
225
    double xrange[2],yrange[2],xspan,yspan;
226
    short unsigned int xdata[LEVELPOINT_LIM],ydata[LEVELPOINT_LIM];
227
} leveldata;
7798 bpr 228
int levelcurve(leveldata *ld);      /* produces level curve data. Returns non-zero if error. */
10 reyssat 229
 
230
/* My accelerated definitions. */
8079 bpr 231
#define myisdigit(x) ((x)>='0' && (x)<='9')
5456 bpr 232
#define myisalpha(x) (((x)&~32)>='A' && ((x)&~32)<='Z')
233
#define myisalnum(x) (myisalpha(x) || myisdigit(x))
234
#define myisupper(x) ((x)>='A' && (x)<='Z')
235
#define myislower(x) ((x)>='a' && (x)<='z')
8647 bpr 236
#define myislspace(x) ((x)==' ' || (x)=='\t' || (x)=='\xa0')
237
#define myisspace(x) ((x)==' ' || (x)=='\t' || (x)=='\n' || (x)=='\r' )
238
#define myismspace(x) ((x)==' ' || (x)=='\t' || (x)=='\n' || (x)=='\r' || (x)=='\xa0')
8079 bpr 239
 
8647 bpr 240
 
5456 bpr 241
/*ou
242
inline int myisdigit(char x) { return x>='0' && x<='9'; }
5476 bpr 243
*/
8177 bpr 244
 
8195 bpr 245
/* from libwims.c */
246
void error(char *msg);
247
 
248
 
8177 bpr 249
#ifndef isfinite
250
# define isfinite(x) (finite(x))
251
#endif