Back to index

wims  3.65+svn20090927
lines.c
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        /* line input / output / translation routines
00018         * and error routines */
00019 
00020 #include <stdarg.h>
00021 
00022        /* these are patches for rawmath.c */
00023 char *getvar(char *p) {return NULL;}
00024 void setvar(char *p, char *v) {return;}
00025 
00026 void error(char *p)
00027 {
00028     fprintf(stderr,"%s\n",p);
00029 }
00030 
00031 void bailout(int i1, int i2, char *msg)
00032 {
00033     if(*msg) error(msg);
00034     printf("%d %d",i1,i2); exit(0);
00035 }
00036 
00037        /* find html tag end */
00038 char *find_tag_end(char *p)
00039 {
00040     char *pp;
00041     
00042     p++; if(*p=='!') {
00043        if(*(p+1)=='-' && *(p+2)=='-') {
00044            pp=strstr(p,"-->"); if(pp==NULL) return p+strlen(p);
00045            else return p+2;
00046        }
00047     }
00048     /* else */ {
00049        pp=strchr(p,'>'); if(pp==NULL) return p+strlen(p); 
00050        else return pp;
00051     }
00052        /* Now the following is not executed. */
00053 /*    for(pp=p;*pp;pp++) {
00054        switch(*pp) {
00055            case '>': return pp;
00056            case '"': {
00057               pp=strchr(++pp,'"'); if(pp==NULL) return p+strlen(p);
00058               break;
00059            }
00060            default: break;
00061        }
00062     }
00063     return pp;
00064 */
00065 }
00066 
00067        /* Points to the end of a name */
00068 char *find_name_end(char *p)
00069 {
00070     int i;
00071     for(i=0;isalnum(*p) && i<MAX_LINELEN; p++,i++);
00072     return p;
00073 }
00074 
00075        /* Find the beginning of a name */
00076 char *find_name_start(char *p)
00077 {
00078     int i;
00079     for(i=0; !isalpha(*p) && i<MAX_LINELEN; p++,i++);
00080     return p;
00081 }
00082 
00083 void collapse_item(char *p, int n)
00084 {
00085     int i;
00086     char *pp;
00087     if(n<1) return;
00088     for(i=1,pp=strchr(p,','); i<n && pp!=NULL; i++,pp=strchr(pp+1,','));
00089     if(pp==NULL) *p=0;
00090     else strcpy(p,pp+1);
00091 }
00092 
00093        /* modify a string. Bufferlen must be ast least MAX_LINELEN */
00094 void string_modify2(char *start, char *bad_beg, char *bad_end, char *good,...)
00095 {
00096     char buf[MAX_LINELEN+1];
00097     va_list vp;
00098     
00099     va_start(vp,good);
00100     vsnprintf(buf,sizeof(buf),good,vp); va_end(vp);
00101     if(strlen(start)-(bad_end-bad_beg)+strlen(buf)>=MAX_LINELEN)
00102       bailout(inlen,0,"string too long");
00103     strcat(buf,bad_end);
00104     strcpy(bad_beg,buf);
00105 }
00106 
00107        /* strcmp() to be used within qsort(). */
00108 int _scmp(const void *p1, const void *p2)
00109 {
00110     const char **s1,**s2;
00111     
00112     s1=(const char **) p1; s2=(const char **) p2;
00113     return strcmp(*s1,*s2);
00114 }
00115 
00116 char *substit(char *p)
00117 {
00118     char *pp;
00119     while((pp=strchr(p,'$'))!=NULL) *pp=' ';
00120     return p;
00121 }
00122