Subversion Repositories wimsdev

Rev

Blame | 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.         /* errors.c */
  21. void (*error1) (char *msg);
  22. void (*error2) (char *msg);
  23. void (*error3) (char *msg);
  24.  
  25.         /* lines.c */
  26. char *int2str(int i);
  27. void *xmalloc(size_t n);
  28. int msleep(int ms);     /* millisecond sleeper */
  29. void _tolinux(char *p);         /* dos/mac to unix/linux translation */
  30. void mystrncpy(char *dest, char *src, int lim); /* optimized and secured strncpy */
  31.         /* find matching parenthesis.
  32.          * The entrance point should be after the opening parenthesis.
  33.          * Returns NULL if unmatched. */
  34. char *find_matching(char *p, char c);
  35. char *find_word_start(char *p); /* Strips leading spaces */
  36. char *find_word_end(char *p);   /* Points to the end of the word */
  37. char *strparchr(char *p, char c);       /* search for char, skipping parentheses */
  38. char *strparstr(char *p, char *fnd);    /* search for string, skipping parentheses */
  39. char *find_item_end(char *p);   /* Points to the end of an item */
  40. char *find_line_end(char *p);   /* Points to the end of a line */
  41. char *charchr(char *p,char *w);
  42. char *wordchr(char *p, char *w);        /* Find first occurrence of word */
  43. char *itemchr(char *p, char *w);        /* Find first occurrence of item */
  44. char *linechr(char *p, char *w);        /* Find first occurrence of line */
  45. char *varchr(char *p, char *v);         /* Find first occurrence of math variable */
  46. int cutitems(char *p, char *list[], int max);   /* Cut items of a string */
  47. int cutwords(char *p, char *list[], int max);   /* Cut words of a string */
  48. int cutlines(char *p, char *list[], int max);   /* Cut lines of a string */
  49. int cutchars(char *p, char *list[], int max);   /* Cut chars of a string */
  50. char *strip_trailing_spaces(char *p);   /* strip trailing spaces; return string end. */
  51.         /* Verify whether a list is well-ordered. For debugging uses.
  52.          * Returns 0 if order is OK, -1 otherwise. */
  53. int verify_order(void *list, int items, size_t item_size);
  54.         /* searches a list. Returns index if found, -1 if nomatch.
  55.          * Uses binary search, list must be sorted. */
  56. int search_list(void *list, int items, size_t item_size, const char *str);
  57. unsigned int linenum(char *p);          /* Returns number of lines in string p */
  58. unsigned int itemnum(char *p);          /* Returns number of items in the list p, comma separated */
  59. unsigned int wordnum(char *p);          /* Returns number of words in string p */
  60. unsigned int charnum(char *p);          /* This is just to suppress an annoying compiler warning message. */
  61. char *fnd_line(char *p, int n, char bf[]); /* find n-th line in string p */
  62. char *fnd_item(char *p, int n, char bf[]); /* find n-th item in list p, comma separated */
  63. char *fnd_word(char *p, int n, char bf[]); /* find n-th word in string p */
  64. char *fnd_char(char *p, int n, char bf[]); /* find n-th char in string p */
  65. char *fnd_row(char *p, int n, char bf[]); /* find n-th row in a matrix p */
  66.         /* Separate items in the string p, end each item with 0,
  67.          * and store item pointers in parm[]. Does not parse past max.
  68.          * Returns the number of fields. */
  69. int separate_item(char *p, char *parm[], int max);
  70. int separate_line(char *p, char *parm[], int max);
  71. int separate_word(char *p, char *parm[], int max);
  72. int _separator(char *p,char *parm[], int max, char fs);
  73. int rows2lines(char *p);                /* Returns 1 if semicolons changed to new lines */
  74. void lines2rows(char *p);
  75. unsigned int rownum(char *p);
  76. void words2items(char *p);      /* change words to items */
  77. void words2lines(char *p);      /* change words to lines */
  78. void lines2items(char *p);      /* change lines to items */
  79. void lines2words(char *p);      /* change lines to words */
  80. void items2words(char *p);      /* change items to words */
  81. void items2lines(char *p);      /* change items to lines */
  82. void strip_enclosing_par(char *p);      /* Strip enclosing pairs of parentheses */
  83.         /* strstr but may have embedde deros.
  84.          * Returns memory end if not found.
  85.          * Supposes memory ends with 0. */
  86. char *memstr(char *s1, char *s2, int len);
  87.         /* Check whether parentheses are balanced in a given string.
  88.          * Returns 0 if OK. */
  89.         /* style=0: simple check. style<>0: strong check. */
  90. int check_parentheses(char *p, int style);
  91. void nospace(char *p);          /* collapses all space characters in string. */
  92. void singlespace(char *p);      /* change all spaces into ' ', and collapse multiple occurences */
  93. void deaccent(char *p);         /* fold accented letters to unaccented */
  94. void reaccent(char *p);         /* compose accented letters using symbols */
  95.         /* modify a string. Bufferlen must be ast least MAX_LINELEN */
  96. void string_modify(char *start, char *bad_beg, char *bad_end, char *good,...);
  97. long int filelength(char *fn,...);
  98. int catfile(FILE *outf, char *fn,...);
  99. char *fnd_position;
  100. char *fnd_nextpos;
  101.  
  102. /* My accelerated definitions. */
  103. #define myisdigit(x) (x>='0' && x<='9')
  104. #define myisalpha(x) ((x&~32)>='A' && (x&~32)<='Z')
  105. #define myisalnum(x) (myisalpha(x) || myisdigit(x))
  106. #define myisupper(x) (x>='A' && x<='Z')
  107. #define myislower(x) (x>='a' && x<='z')
  108. #define myislspace(x) (x==' ' || x=='\t')
  109. #define myisspace(x) (x==' ' || x=='\t' || x=='\n' || x=='\r')
  110.