Subversion Repositories wimsdev

Rev

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

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