Back to index

wims  3.65+svn20090927
lines.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        /* errors.c */
00021 void (*error1) (char *msg);
00022 void (*error2) (char *msg);
00023 void (*error3) (char *msg);
00024 
00025        /* lines.c */
00026 char *int2str(int i);
00027 void *xmalloc(size_t n);
00028 int msleep(int ms);  /* millisecond sleeper */
00029 void _tolinux(char *p);            /* dos/mac to unix/linux translation */
00030 void mystrncpy(char *dest, char *src, int lim);  /* optimized and secured strncpy */
00031         /* find matching parenthesis.
00032         * The entrance point should be after the opening parenthesis.
00033         * Returns NULL if unmatched. */
00034 char *find_matching(char *p, char c);
00035 char *find_word_start(char *p);    /* Strips leading spaces */
00036 char *find_word_end(char *p);      /* Points to the end of the word */
00037 char *strparchr(char *p, char c);  /* search for char, skipping parentheses */
00038 char *strparstr(char *p, char *fnd);      /* search for string, skipping parentheses */
00039 char *find_item_end(char *p);      /* Points to the end of an item */
00040 char *find_line_end(char *p);      /* Points to the end of a line */
00041 char *charchr(char *p,char *w);
00042 char *wordchr(char *p, char *w);   /* Find first occurrence of word */
00043 char *itemchr(char *p, char *w);   /* Find first occurrence of item */
00044 char *linechr(char *p, char *w);   /* Find first occurrence of line */
00045 char *varchr(char *p, char *v);           /* Find first occurrence of math variable */
00046 int cutitems(char *p, char *list[], int max);    /* Cut items of a string */
00047 int cutwords(char *p, char *list[], int max);    /* Cut words of a string */
00048 int cutlines(char *p, char *list[], int max);    /* Cut lines of a string */
00049 int cutchars(char *p, char *list[], int max);    /* Cut chars of a string */
00050 char *strip_trailing_spaces(char *p);     /* strip trailing spaces; return string end. */
00051         /* Verify whether a list is well-ordered. For debugging uses.
00052         * Returns 0 if order is OK, -1 otherwise. */
00053 int verify_order(void *list, int items, size_t item_size);
00054         /* searches a list. Returns index if found, -1 if nomatch. 
00055         * Uses binary search, list must be sorted. */
00056 int search_list(void *list, int items, size_t item_size, const char *str);
00057 unsigned int linenum(char *p);            /* Returns number of lines in string p */
00058 unsigned int itemnum(char *p);            /* Returns number of items in the list p, comma separated */
00059 unsigned int wordnum(char *p);            /* Returns number of words in string p */
00060 unsigned int charnum(char *p);            /* This is just to suppress an annoying compiler warning message. */
00061 char *fnd_line(char *p, int n, char bf[]); /* find n-th line in string p */
00062 char *fnd_item(char *p, int n, char bf[]); /* find n-th item in list p, comma separated */
00063 char *fnd_word(char *p, int n, char bf[]); /* find n-th word in string p */
00064 char *fnd_char(char *p, int n, char bf[]); /* find n-th char in string p */
00065 char *fnd_row(char *p, int n, char bf[]); /* find n-th row in a matrix p */
00066         /* Separate items in the string p, end each item with 0,
00067         * and store item pointers in parm[]. Does not parse past max.
00068         * Returns the number of fields. */
00069 int separate_item(char *p, char *parm[], int max);
00070 int separate_line(char *p, char *parm[], int max);
00071 int separate_word(char *p, char *parm[], int max);
00072 int _separator(char *p,char *parm[], int max, char fs);
00073 int rows2lines(char *p);           /* Returns 1 if semicolons changed to new lines */
00074 void lines2rows(char *p);
00075 unsigned int rownum(char *p);
00076 void words2items(char *p);  /* change words to items */
00077 void words2lines(char *p);  /* change words to lines */
00078 void lines2items(char *p);  /* change lines to items */
00079 void lines2words(char *p);  /* change lines to words */
00080 void items2words(char *p);  /* change items to words */
00081 void items2lines(char *p);  /* change items to lines */
00082 void strip_enclosing_par(char *p); /* Strip enclosing pairs of parentheses */
00083         /* strstr but may have embedde deros. 
00084         * Returns memory end if not found.
00085         * Supposes memory ends with 0. */
00086 char *memstr(char *s1, char *s2, int len);
00087         /* Check whether parentheses are balanced in a given string.
00088         * Returns 0 if OK. */
00089         /* style=0: simple check. style<>0: strong check. */
00090 int check_parentheses(char *p, int style);
00091 void nospace(char *p);             /* collapses all space characters in string. */
00092 void singlespace(char *p);  /* change all spaces into ' ', and collapse multiple occurences */
00093 void deaccent(char *p);            /* fold accented letters to unaccented */
00094 void reaccent(char *p);            /* compose accented letters using symbols */
00095        /* modify a string. Bufferlen must be ast least MAX_LINELEN */
00096 void string_modify(char *start, char *bad_beg, char *bad_end, char *good,...);
00097 long int filelength(char *fn,...);
00098 int catfile(FILE *outf, char *fn,...);
00099 char *fnd_position;
00100 char *fnd_nextpos;
00101 
00102 /* My accelerated definitions. */
00103 #define myisdigit(x) (x>='0' && x<='9')
00104 #define myisalpha(x) ((x&~32)>='A' && (x&~32)<='Z')
00105 #define myisalnum(x) (myisalpha(x) || myisdigit(x))
00106 #define myisupper(x) (x>='A' && x<='Z')
00107 #define myislower(x) (x>='a' && x<='z')
00108 #define myislspace(x) (x==' ' || x=='\t')
00109 #define myisspace(x) (x==' ' || x=='\t' || x=='\n' || x=='\r')