Back to index

wims  3.65+svn20090927
libwims.h
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018 /* WWW multipurpose server, dynamic library definitions */
00019 
00020 #include "../config.h"
00021 #include "../includes.h"
00022 #include "../wimsdef.h"
00023 
00024        /* for mt19937ar.c */
00025 #ifdef RAND_MAX
00026 # undef RAND_MAX
00027 #endif
00028 #define RAND_MAX 2147483647
00029 #define random genrand_int31
00030 #define srandom init_genrand
00031 long int genrand_int31(void);
00032 
00033        /* errors.c */
00034 void (*error1) (char *msg);
00035 void (*error2) (char *msg);
00036 void (*error3) (char *msg);
00037 
00038        /* lines.c */
00039 char *int2str(int i);
00040 void *xmalloc(size_t n);
00041 int msleep(int ms);  /* millisecond sleeper */
00042 void _tolinux(char *p);            /* dos/mac to unix/linux translation */
00043 void mystrncpy(char *dest, char *src, int lim);  /* optimized and secured strncpy */
00044         /* find matching parenthesis.
00045         * The entrance point should be after the opening parenthesis.
00046         * Returns NULL if unmatched. */
00047 char *find_matching(char *p, char c);
00048 char *find_word_start(char *p);    /* Strips leading spaces */
00049 char *find_word_end(char *p);      /* Points to the end of the word */
00050 char *strparchr(char *p, char c);  /* search for char, skipping parentheses */
00051 char *strparstr(char *p, char *fnd);      /* search for string, skipping parentheses */
00052 char *find_item_end(char *p);      /* Points to the end of an item */
00053 char *find_line_end(char *p);      /* Points to the end of a line */
00054 char *charchr(char *p,char *w);
00055 char *wordchr(char *p, char *w);   /* Find first occurrence of word */
00056 char *itemchr(char *p, char *w);   /* Find first occurrence of item */
00057 char *linechr(char *p, char *w);   /* Find first occurrence of line */
00058 char *varchr(char *p, char *v);           /* Find first occurrence of math variable */
00059 int cutitems(char *p, char *list[], int max);    /* Cut items of a string */
00060 int cutwords(char *p, char *list[], int max);    /* Cut words of a string */
00061 int cutlines(char *p, char *list[], int max);    /* Cut lines of a string */
00062 int cutchars(char *p, char *list[], int max);    /* Cut chars of a string */
00063 char *strip_trailing_spaces(char *p);     /* strip trailing spaces; return string end. */
00064         /* Verify whether a list is well-ordered. For debugging uses.
00065         * Returns 0 if order is OK, -1 otherwise. */
00066 int verify_order(void *list, int items, size_t item_size);
00067         /* searches a list. Returns index if found, -1 if nomatch. 
00068         * Uses binary search, list must be sorted. */
00069 int search_list(void *list, int items, size_t item_size, const char *str);
00070 unsigned int linenum(char *p);            /* Returns number of lines in string p */
00071 unsigned int itemnum(char *p);            /* Returns number of items in the list p, comma separated */
00072 unsigned int wordnum(char *p);            /* Returns number of words in string p */
00073 unsigned int charnum(char *p);            /* This is just to suppress an annoying compiler warning message. */
00074 char *fnd_line(char *p, int n, char bf[]); /* find n-th line in string p */
00075 char *fnd_item(char *p, int n, char bf[]); /* find n-th item in list p, comma separated */
00076 char *fnd_word(char *p, int n, char bf[]); /* find n-th word in string p */
00077 char *fnd_char(char *p, int n, char bf[]); /* find n-th char in string p */
00078 char *fnd_row(char *p, int n, char bf[]); /* find n-th row in a matrix p */
00079         /* Separate items in the string p, end each item with 0,
00080         * and store item pointers in parm[]. Does not parse past max.
00081         * Returns the number of fields. */
00082 int separate_item(char *p, char *parm[], int max);
00083 int separate_line(char *p, char *parm[], int max);
00084 int separate_word(char *p, char *parm[], int max);
00085 int _separator(char *p,char *parm[], int max, char fs);
00086 int rows2lines(char *p);           /* Returns 1 if semicolons changed to new lines */
00087 void lines2rows(char *p);
00088 unsigned int rownum(char *p);
00089 void words2items(char *p);  /* change words to items */
00090 void words2lines(char *p);  /* change words to lines */
00091 void lines2items(char *p);  /* change lines to items */
00092 void lines2words(char *p);  /* change lines to words */
00093 void items2words(char *p);  /* change items to words */
00094 void items2lines(char *p);  /* change items to lines */
00095 void strip_enclosing_par(char *p); /* Strip enclosing pairs of parentheses */
00096         /* strstr but may have embedde deros. 
00097         * Returns memory end if not found.
00098         * Supposes memory ends with 0. */
00099 char *memstr(char *s1, char *s2, int len);
00100         /* Check whether parentheses are balanced in a given string.
00101         * Returns 0 if OK. */
00102         /* style=0: simple check. style<>0: strong check. */
00103 int check_parentheses(char *p, int style);
00104 void nospace(char *p);             /* collapses all space characters in string. */
00105 void singlespace(char *p);  /* change all spaces into ' ', and collapse multiple occurences */
00106 void deaccent(char *p);            /* fold accented letters to unaccented */
00107 void reaccent(char *p);            /* compose accented letters using symbols */
00108        /* modify a string. Bufferlen must be ast least MAX_LINELEN */
00109 void string_modify(char *start, char *bad_beg, char *bad_end, char *good,...);
00110 long int filelength(char *fn,...);
00111 int catfile(FILE *outf, char *fn,...);
00112 #ifdef libwims
00113  char *fnd_position;
00114  char *fnd_nextpos;
00115 #else
00116  extern char *fnd_position;
00117  extern char *fnd_nextpos;
00118 #endif
00119 
00120        /* evalue.c */
00121 #define EV_S  "EVLS"
00122 #define EV_T  "EVLT"
00123 #define EV_X  "EVLX"
00124 #define EV_Y  "EVLY"
00125 typedef struct ev_variable{
00126     char *name; double value;
00127 } ev_variable;
00128 #ifdef LIBWIMS
00129  int *ev_varcnt=NULL;
00130  ev_variable *ev_var=NULL;
00131 #else
00132  extern int *ev_varcnt;
00133  extern ev_variable *ev_var;
00134 #endif
00135 char *moneyprint(char *p, double s);
00136 double factorial(double d);
00137 void init_random(void);
00138 double drand(double m);
00139 double irand(double n);
00140 double sign(double d);
00141 double factorial(double d);
00142 double binomial(double d1,double d2);
00143 double max(double d1, double d2);
00144 double min(double d1, double d2);
00145 double gcd(double n1, double n2);
00146 double lcm(double n1, double n2);
00147 int eval_getpos(char *name);              /* get position of name in nametable */
00148 void eval_setval(int pos, double v);      /* set value to name */
00149 void set_evalue_pointer(char *p);  /* prepare pointer for evaluation */
00150 char *get_evalue_pointer(void);           /* get string pointer (after evaluation) */
00151 double _evalue(int ord);
00152 double strevalue(char *p);         /* evalue a string to double */
00153 char *(*substitute) (char *p);
00154 int get_evalue_error(void);
00155 void set_evalue_error(int e);
00156 int get_evalcnt(void);
00157 char *get_evalname(int i);
00158 int get_evaltype(int i);
00159 int evaltab_verify(void);
00160 int search_evaltab(char *p);
00161        /* compile an expression for faster evaluation
00162         * returns -1 if cannot be compiled.
00163         * else returns the number of compilations. */
00164 int evalue_compile(char *p);
00165 
00166        /* math.c */
00167 char *find_mathvar_start(char *p); /* Points to the start of a mathematics variable (or number) */
00168 char *find_mathvar_end(char *p);   /* Points to the end of a mathematics variable (or number) */
00169 void mathvarlist(char *p);         /* list variable (function) names in an expression. buffer is modified to contain the list. */
00170 
00171        /* dir.c */
00172 int remove_tree(char *dirname);           /* remove a directory tree */
00173 void mkdirs(char *s);                     /* recursively generate a directory structure */
00174 
00175        /* text.c */
00176 void text(char *p);         /* main entry point for text routines */
00177 int textab_verify(void);
00178 
00179        /* levelcurve.c */
00180 #define LEVEL_LIM    256
00181 #define LEVELPOINT_LIM      16384
00182 #define LEVELSIZE_LIM       2048
00183 #define LEVELGRAIN_LIM      16
00184 typedef struct {
00185     char *fn, *xname, *yname;
00186     double levels[LEVEL_LIM];
00187     int xsize,ysize,grain,levelcnt,datacnt,xevpos,yevpos;
00188     double xrange[2],yrange[2],xspan,yspan;
00189     short unsigned int xdata[LEVELPOINT_LIM],ydata[LEVELPOINT_LIM];
00190 } leveldata;
00191 int levelcurve(leveldata *ld);     /* produces level curve data. Returns non-zero if error. */
00192 
00193 /* My accelerated definitions. */
00194 #define myisdigit(x) (x>='0' && x<='9')
00195 #define myisalpha(x) ((x&~32)>='A' && (x&~32)<='Z')
00196 #define myisalnum(x) (myisalpha(x) || myisdigit(x))
00197 #define myisupper(x) (x>='A' && x<='Z')
00198 #define myislower(x) (x>='a' && x<='z')
00199 #define myislspace(x) (x==' ' || x=='\t')
00200 #define myisspace(x) (x==' ' || x=='\t' || x=='\n' || x=='\r')