Subversion Repositories wimsdev

Rev

Go to most recent revision | 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.         /* line input / output / translation routines
  18.          * and error routines */
  19.  
  20. #include <stdarg.h>
  21.  
  22.         /* these are patches for rawmath.c */
  23. char *getvar(char *p) {return NULL;}
  24. void setvar(char *p, char *v) {return;}
  25.  
  26. void error(char *p)
  27. {
  28.     fprintf(stderr,"%s\n",p);
  29. }
  30.  
  31. void bailout(int i1, int i2, char *msg)
  32. {
  33.     if(*msg) error(msg);
  34.     printf("%d %d",i1,i2); exit(0);
  35. }
  36.  
  37.         /* find html tag end */
  38. char *find_tag_end(char *p)
  39. {
  40.     char *pp;
  41.    
  42.     p++; if(*p=='!') {
  43.         if(*(p+1)=='-' && *(p+2)=='-') {
  44.             pp=strstr(p,"-->"); if(pp==NULL) return p+strlen(p);
  45.             else return p+2;
  46.         }
  47.     }
  48.     /* else */ {
  49.         pp=strchr(p,'>'); if(pp==NULL) return p+strlen(p);
  50.         else return pp;
  51.     }
  52.         /* Now the following is not executed. */
  53. /*    for(pp=p;*pp;pp++) {
  54.         switch(*pp) {
  55.             case '>': return pp;
  56.             case '"': {
  57.                 pp=strchr(++pp,'"'); if(pp==NULL) return p+strlen(p);
  58.                 break;
  59.             }
  60.             default: break;
  61.         }
  62.     }
  63.     return pp;
  64. */
  65. }
  66.  
  67.         /* Points to the end of a name */
  68. char *find_name_end(char *p)
  69. {
  70.     int i;
  71.     for(i=0;isalnum(*p) && i<MAX_LINELEN; p++,i++);
  72.     return p;
  73. }
  74.  
  75.         /* Find the beginning of a name */
  76. char *find_name_start(char *p)
  77. {
  78.     int i;
  79.     for(i=0; !isalpha(*p) && i<MAX_LINELEN; p++,i++);
  80.     return p;
  81. }
  82.  
  83. void collapse_item(char *p, int n)
  84. {
  85.     int i;
  86.     char *pp;
  87.     if(n<1) return;
  88.     for(i=1,pp=strchr(p,','); i<n && pp!=NULL; i++,pp=strchr(pp+1,','));
  89.     if(pp==NULL) *p=0;
  90.     else strcpy(p,pp+1);
  91. }
  92.  
  93.         /* modify a string. Bufferlen must be ast least MAX_LINELEN */
  94. void string_modify2(char *start, char *bad_beg, char *bad_end, char *good,...)
  95. {
  96.     char buf[MAX_LINELEN+1];
  97.     va_list vp;
  98.    
  99.     va_start(vp,good);
  100.     vsnprintf(buf,sizeof(buf),good,vp); va_end(vp);
  101.     if(strlen(start)-(bad_end-bad_beg)+strlen(buf)>=MAX_LINELEN)
  102.       bailout(inlen,0,"string too long");
  103.     strcat(buf,bad_end);
  104.     strcpy(bad_beg,buf);
  105. }
  106.  
  107.         /* strcmp() to be used within qsort(). */
  108. int _scmp(const void *p1, const void *p2)
  109. {
  110.     const char **s1,**s2;
  111.    
  112.     s1=(const char **) p1; s2=(const char **) p2;
  113.     return strcmp(*s1,*s2);
  114. }
  115.  
  116. char *substit(char *p)
  117. {
  118.     char *pp;
  119.     while((pp=strchr(p,'$'))!=NULL) *pp=' ';
  120.     return p;
  121. }
  122.  
  123.