Rev 5476 | Rev 7847 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5476 | Rev 7798 | ||
---|---|---|---|
Line 19... | Line 19... | ||
19 | 19 | ||
20 | #include "../config.h" |
20 | #include "../config.h" |
21 | #include "../includes.h" |
21 | #include "../includes.h" |
22 | #include "../wimsdef.h" |
22 | #include "../wimsdef.h" |
23 | 23 | ||
24 |
|
24 | /* for mt19937ar.c */ |
25 | #ifdef RAND_MAX |
25 | #ifdef RAND_MAX |
26 | # undef RAND_MAX |
26 | # undef RAND_MAX |
27 | #endif |
27 | #endif |
28 | #define RAND_MAX 2147483647 |
28 | #define RAND_MAX 2147483647 |
29 | #define random genrand_int31 |
29 | #define random genrand_int31 |
30 | #define srandom init_genrand |
30 | #define srandom init_genrand |
31 | long int genrand_int31(void); |
31 | long int genrand_int31(void); |
32 | 32 | ||
33 |
|
33 | /* errors.c */ |
34 | void (*error1) (char *msg); |
34 | void (*error1) (char *msg); |
35 | void (*error2) (char *msg); |
35 | void (*error2) (char *msg); |
36 | void (*error3) (char *msg); |
36 | void (*error3) (char *msg); |
37 | 37 | ||
38 |
|
38 | /* lines.c */ |
39 | char *int2str(int i); |
39 | char *int2str(int i); |
40 | void *xmalloc(size_t n); |
40 | void *xmalloc(size_t n); |
41 | int msleep(int ms); |
41 | int msleep(int ms); /* millisecond sleeper */ |
42 | void _tolinux(char *p); |
42 | void _tolinux(char *p); /* dos/mac to unix/linux translation */ |
43 | void ovlstrcpy(char *dest, char *src); |
43 | void ovlstrcpy(char *dest, char *src); /* strcpy of possibly overlapping strings (64 bits problem)*/ |
44 | void mystrncpy(char *dest, const char *src, size_t lim); |
44 | void mystrncpy(char *dest, const char *src, size_t lim); /* optimized and secured strncpy */ |
45 |
|
45 | /* find matching parenthesis. |
46 |
|
46 | * The entrance point should be after the opening parenthesis. |
47 | |
47 | * Returns NULL if unmatched. |
- | 48 | */ |
|
48 | char *find_matching(char *p, char c); |
49 | char *find_matching(char *p, char c); |
49 | char *find_word_start(char *p); /* Strips leading spaces */ |
50 | char *find_word_start(char *p); /* Strips leading spaces */ |
50 | char *find_word_end(char *p); /* Points to the end of the word */ |
51 | char *find_word_end(char *p); /* Points to the end of the word */ |
51 | char *strparchr(char *p, char c); |
52 | char *strparchr(char *p, char c); /* search for char, skipping parentheses */ |
52 | char *strparstr(char *p, char *fnd); |
53 | char *strparstr(char *p, char *fnd); /* search for string, skipping parentheses */ |
53 | char *find_item_end(char *p); /* Points to the end of an item */ |
54 | char *find_item_end(char *p); /* Points to the end of an item */ |
54 | char *find_line_end(char *p); /* Points to the end of a line */ |
55 | char *find_line_end(char *p); /* Points to the end of a line */ |
55 | char *charchr(char *p,char *w); |
56 | char *charchr(char *p,char *w); |
56 | char *wordchr(char *p, char *w); |
57 | char *wordchr(char *p, char *w); /* Find first occurrence of word */ |
57 | char *itemchr(char *p, char *w); |
58 | char *itemchr(char *p, char *w); /* Find first occurrence of item */ |
58 | char *linechr(char *p, char *w); |
59 | char *linechr(char *p, char *w); /* Find first occurrence of line */ |
59 | char *varchr(char *p, char *v); |
60 | char *varchr(char *p, char *v); /* Find first occurrence of math variable */ |
60 | int cutitems(char *p, char *list[], int max); /* Cut items of a string */ |
61 | int cutitems(char *p, char *list[], int max); /* Cut items of a string */ |
61 | int cutwords(char *p, char *list[], int max); /* Cut words of a string */ |
62 | int cutwords(char *p, char *list[], int max); /* Cut words of a string */ |
62 | int cutlines(char *p, char *list[], int max); /* Cut lines of a string */ |
63 | int cutlines(char *p, char *list[], int max); /* Cut lines of a string */ |
63 | int cutchars(char *p, char *list[], int max); /* Cut chars of a string */ |
64 | int cutchars(char *p, char *list[], int max); /* Cut chars of a string */ |
64 | char *strip_trailing_spaces(char *p); /* strip trailing spaces; return string end. */ |
65 | char *strip_trailing_spaces(char *p); /* strip trailing spaces; return string end. */ |
65 |
|
66 | /* Verify whether a list is well-ordered. For debugging uses. |
66 |
|
67 | * Returns 0 if order is OK, -1 otherwise. |
- | 68 | */ |
|
67 | int verify_order(void *list, int items, size_t item_size); |
69 | int verify_order(void *list, int items, size_t item_size); |
68 | /* searches a list. Returns index if found, -1 if nomatch. |
70 | /* searches a list. Returns index if found, -1 if nomatch. |
69 |
|
71 | * Uses binary search, list must be sorted. */ |
70 | int search_list(void *list, int items, size_t item_size, const char *str); |
72 | int search_list(void *list, int items, size_t item_size, const char *str); |
71 | unsigned int linenum(char *p); /* Returns number of lines in string p */ |
73 | unsigned int linenum(char *p); /* Returns number of lines in string p */ |
72 | unsigned int itemnum(char *p); /* Returns number of items in the list p, comma separated */ |
74 | unsigned int itemnum(char *p); /* Returns number of items in the list p, comma separated */ |
73 | unsigned int wordnum(char *p); /* Returns number of words in string p */ |
75 | unsigned int wordnum(char *p); /* Returns number of words in string p */ |
74 | unsigned int charnum(char *p); /* This is just to suppress an annoying compiler warning message. */ |
76 | unsigned int charnum(char *p); /* This is just to suppress an annoying compiler warning message. */ |
75 | char *fnd_line(char *p, int n, char bf[]); /* find n-th line in string p */ |
77 | char *fnd_line(char *p, int n, char bf[]); /* find n-th line in string p */ |
76 | char *fnd_item(char *p, int n, char bf[]); /* find n-th item in list p, comma separated */ |
78 | char *fnd_item(char *p, int n, char bf[]); /* find n-th item in list p, comma separated */ |
77 | char *fnd_word(char *p, int n, char bf[]); /* find n-th word in string p */ |
79 | char *fnd_word(char *p, int n, char bf[]); /* find n-th word in string p */ |
78 | char *fnd_char(char *p, int n, char bf[]); /* find n-th char in string p */ |
80 | char *fnd_char(char *p, int n, char bf[]); /* find n-th char in string p */ |
79 | char *fnd_row(char *p, int n, char bf[]); /* find n-th row in a matrix p */ |
81 | char *fnd_row(char *p, int n, char bf[]); /* find n-th row in a matrix p */ |
80 |
|
82 | /* Separate items in the string p, end each item with 0, |
81 |
|
83 | * and store item pointers in parm[]. Does not parse past max. |
82 |
|
84 | * Returns the number of fields. */ |
83 | int separate_item(char *p, char *parm[], int max); |
85 | int separate_item(char *p, char *parm[], int max); |
84 | int separate_line(char *p, char *parm[], int max); |
86 | int separate_line(char *p, char *parm[], int max); |
85 | int separate_word(char *p, char *parm[], int max); |
87 | int separate_word(char *p, char *parm[], int max); |
86 | int _separator(char *p,char *parm[], int max, char fs); |
88 | int _separator(char *p,char *parm[], int max, char fs); |
87 | int rows2lines(char *p); |
89 | int rows2lines(char *p); /* Returns 1 if semicolons changed to new lines */ |
88 | void lines2rows(char *p); |
90 | void lines2rows(char *p); |
89 | unsigned int rownum(char *p); |
91 | unsigned int rownum(char *p); |
90 | void words2items(char *p); |
92 | void words2items(char *p); /* change words to items */ |
91 | void words2lines(char *p); |
93 | void words2lines(char *p); /* change words to lines */ |
92 | void lines2items(char *p); |
94 | void lines2items(char *p); /* change lines to items */ |
93 | void lines2words(char *p); |
95 | void lines2words(char *p); /* change lines to words */ |
94 | void items2words(char *p); |
96 | void items2words(char *p); /* change items to words */ |
95 | void items2lines(char *p); |
97 | void items2lines(char *p); /* change items to lines */ |
96 | void strip_enclosing_par(char *p); |
98 | void strip_enclosing_par(char *p); /* Strip enclosing pairs of parentheses */ |
97 |
|
99 | /* strstr but may have embedded zeros. |
98 |
|
100 | * Returns memory end if not found. |
99 | |
101 | * Supposes memory ends with 0. |
- | 102 | */ |
|
100 | char *memstr(char *s1, char *s2, int len); |
103 | char *memstr(char *s1, char *s2, int len); |
101 |
|
104 | /* Check whether parentheses are balanced in a given string. |
102 | |
105 | * Returns 0 if OK. |
- | 106 | */ |
|
103 |
|
107 | /* style=0: simple check. style<>0: strong check. */ |
104 | int check_parentheses(char *p, int style); |
108 | int check_parentheses(char *p, int style); |
105 | void nospace(char *p); /* collapses all space characters in string. */ |
109 | void nospace(char *p); /* collapses all space characters in string. */ |
106 | void singlespace(char *p); /* change all spaces into ' ', and collapse multiple occurences */ |
110 | void singlespace(char *p); /* change all spaces into ' ', and collapse multiple occurences */ |
107 | void deaccent(char *p); /* fold accented letters to unaccented */ |
111 | void deaccent(char *p); /* fold accented letters to unaccented */ |
108 | void reaccent(char *p); /* compose accented letters using symbols */ |
112 | void reaccent(char *p); /* compose accented letters using symbols */ |
109 |
|
113 | /* modify a string. Bufferlen must be at least MAX_LINELEN */ |
110 | void string_modify(char *start, char *bad_beg, char *bad_end, char *good,...); |
114 | void string_modify(char *start, char *bad_beg, char *bad_end, char *good,...); |
111 | long int filelength(char *fn,...); |
115 | long int filelength(char *fn,...); |
112 | int catfile(FILE *outf, char *fn,...); |
116 | int catfile(FILE *outf, char *fn,...); |
113 | #ifdef libwims |
117 | #ifdef libwims |
114 | char *fnd_position; |
118 | char *fnd_position; |
Line 116... | Line 120... | ||
116 | #else |
120 | #else |
117 | extern char *fnd_position; |
121 | extern char *fnd_position; |
118 | extern char *fnd_nextpos; |
122 | extern char *fnd_nextpos; |
119 | #endif |
123 | #endif |
120 | 124 | ||
121 |
|
125 | /* evalue.c */ |
122 | #define EV_S |
126 | #define EV_S "EVLS" |
123 | #define EV_T |
127 | #define EV_T "EVLT" |
124 | #define EV_X |
128 | #define EV_X "EVLX" |
125 | #define EV_Y |
129 | #define EV_Y "EVLY" |
126 | typedef struct ev_variable{ |
130 | typedef struct ev_variable{ |
127 | char *name; double value; |
131 | char *name; double value; |
128 | } ev_variable; |
132 | } ev_variable; |
129 | #ifdef LIBWIMS |
133 | #ifdef LIBWIMS |
130 | int *ev_varcnt=NULL; |
134 | int *ev_varcnt=NULL; |
Line 143... | Line 147... | ||
143 | double binomial(double d1,double d2); |
147 | double binomial(double d1,double d2); |
144 | double max(double d1, double d2); |
148 | double max(double d1, double d2); |
145 | double min(double d1, double d2); |
149 | double min(double d1, double d2); |
146 | double gcd(double n1, double n2); |
150 | double gcd(double n1, double n2); |
147 | double lcm(double n1, double n2); |
151 | double lcm(double n1, double n2); |
148 | int eval_getpos(char *name); |
152 | int eval_getpos(char *name); /* get position of name in nametable */ |
149 | void eval_setval(int pos, double v); |
153 | void eval_setval(int pos, double v); /* set value to name */ |
150 | void set_evalue_pointer(char *p); /* prepare pointer for evaluation */ |
154 | void set_evalue_pointer(char *p); /* prepare pointer for evaluation */ |
151 | char *get_evalue_pointer(void); /* get string pointer (after evaluation) */ |
155 | char *get_evalue_pointer(void); /* get string pointer (after evaluation) */ |
152 | double _evalue(int ord); |
156 | double _evalue(int ord); |
153 | double strevalue(char *p); |
157 | double strevalue(char *p); /* evalue a string to double */ |
154 | char *(*substitute) (char *p); |
158 | char *(*substitute) (char *p); |
155 | int get_evalue_error(void); |
159 | int get_evalue_error(void); |
156 | void set_evalue_error(int e); |
160 | void set_evalue_error(int e); |
157 | int get_evalcnt(void); |
161 | int get_evalcnt(void); |
158 | char *get_evalname(int i); |
162 | char *get_evalname(int i); |
159 | int get_evaltype(int i); |
163 | int get_evaltype(int i); |
160 | int evaltab_verify(void); |
164 | int evaltab_verify(void); |
161 | int search_evaltab(char *p); |
165 | int search_evaltab(char *p); |
162 |
|
166 | /* compile an expression for faster evaluation |
163 |
|
167 | * returns -1 if cannot be compiled. |
164 | |
168 | * else returns the number of compilations. |
- | 169 | */ |
|
165 | int evalue_compile(char *p); |
170 | int evalue_compile(char *p); |
166 | 171 | ||
167 |
|
172 | /* math.c */ |
168 | char *find_mathvar_start(char *p); |
173 | char *find_mathvar_start(char *p); /* Points to the start of a mathematics variable (or number) */ |
169 | char *find_mathvar_end(char *p); |
174 | char *find_mathvar_end(char *p); /* Points to the end of a mathematics variable (or number) */ |
170 | void mathvarlist(char *p); |
175 | void mathvarlist(char *p); /* list variable (function) names in an expression. buffer is modified to contain the list. */ |
171 | 176 | ||
172 |
|
177 | /* dir.c */ |
173 | int remove_tree(char *dirname); |
178 | int remove_tree(char *dirname); /* remove a directory tree */ |
174 | void mkdirs(char *s); |
179 | void mkdirs(char *s); /* recursively generate a directory structure */ |
175 | 180 | ||
176 |
|
181 | /* text.c */ |
177 | void text(char *p); /* main entry point for text routines */ |
182 | void text(char *p); /* main entry point for text routines */ |
178 | int textab_verify(void); |
183 | int textab_verify(void); |
179 | 184 | ||
180 |
|
185 | /* levelcurve.c */ |
181 | #define LEVEL_LIM |
186 | #define LEVEL_LIM 256 |
182 | #define LEVELPOINT_LIM |
187 | #define LEVELPOINT_LIM 16384 |
183 | #define LEVELSIZE_LIM |
188 | #define LEVELSIZE_LIM 2048 |
184 | #define LEVELGRAIN_LIM |
189 | #define LEVELGRAIN_LIM 16 |
185 | typedef struct { |
190 | typedef struct { |
186 | char *fn, *xname, *yname; |
191 | char *fn, *xname, *yname; |
187 | double levels[LEVEL_LIM]; |
192 | double levels[LEVEL_LIM]; |
188 | int xsize,ysize,grain,levelcnt,datacnt,xevpos,yevpos; |
193 | int xsize,ysize,grain,levelcnt,datacnt,xevpos,yevpos; |
189 | double xrange[2],yrange[2],xspan,yspan; |
194 | double xrange[2],yrange[2],xspan,yspan; |
190 | short unsigned int xdata[LEVELPOINT_LIM],ydata[LEVELPOINT_LIM]; |
195 | short unsigned int xdata[LEVELPOINT_LIM],ydata[LEVELPOINT_LIM]; |
191 | } leveldata; |
196 | } leveldata; |
192 | int levelcurve(leveldata *ld); |
197 | int levelcurve(leveldata *ld); /* produces level curve data. Returns non-zero if error. */ |
193 | 198 | ||
194 | /* My accelerated definitions. */ |
199 | /* My accelerated definitions. */ |
195 | #define myisdigit(x) (x>='0' && x<='9') |
200 | #define myisdigit(x) (x>='0' && x<='9') |
196 | #define myisalpha(x) ((x&~32)>='A' && (x&~32)<='Z') |
201 | #define myisalpha(x) ((x&~32)>='A' && (x&~32)<='Z') |
197 | #define myisalnum(x) (myisalpha(x) || myisdigit(x)) |
202 | #define myisalnum(x) (myisalpha(x) || myisdigit(x)) |