Subversion Repositories wimsdev

Rev

Rev 8195 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 reyssat 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
 */
7678 bpr 17
/* line input / output / translation routines
8067 bpr 18
 * and error routines
19
 */
10 reyssat 20
 
8195 bpr 21
/*#include <stdarg.h>*/
8135 bpr 22
#include "../Lib/libwims.h"
23
#include "msg2wims.h"
10 reyssat 24
 
8195 bpr 25
void msg_error(char *p)
10 reyssat 26
{
27
    fprintf(stderr,"%s\n",p);
28
}
29
 
30
void bailout(int i1, int i2, char *msg)
31
{
8195 bpr 32
    if(*msg) msg_error(msg);
10 reyssat 33
    printf("%d %d",i1,i2); exit(0);
34
}
35
 
7678 bpr 36
/* find html tag end */
10 reyssat 37
char *find_tag_end(char *p)
38
{
39
    char *pp;
7678 bpr 40
 
10 reyssat 41
    p++; if(*p=='!') {
7678 bpr 42
      if(*(p+1)=='-' && *(p+2)=='-') {
43
          pp=strstr(p,"-->"); if(pp==NULL) return p+strlen(p);
44
          else return p+2;
45
      }
10 reyssat 46
    }
47
    /* else */ {
7678 bpr 48
      pp=strchr(p,'>'); if(pp==NULL) return p+strlen(p);
49
      else return pp;
10 reyssat 50
    }
7678 bpr 51
/* Now the following is not executed. */
10 reyssat 52
/*    for(pp=p;*pp;pp++) {
7678 bpr 53
      switch(*pp) {
54
          case '>': return pp;
55
          case '"': {
56
            pp=strchr(++pp,'"'); if(pp==NULL) return p+strlen(p);
57
            break;
58
          }
59
          default: break;
60
      }
10 reyssat 61
    }
62
    return pp;
63
*/
64
}
65
 
8067 bpr 66
/* modify a string. Bufferlen must be at least MAX_LINELEN */
10 reyssat 67
void string_modify2(char *start, char *bad_beg, char *bad_end, char *good,...)
68
{
69
    char buf[MAX_LINELEN+1];
70
    va_list vp;
7678 bpr 71
 
10 reyssat 72
    va_start(vp,good);
73
    vsnprintf(buf,sizeof(buf),good,vp); va_end(vp);
74
    if(strlen(start)-(bad_end-bad_beg)+strlen(buf)>=MAX_LINELEN)
75
      bailout(inlen,0,"string too long");
76
    strcat(buf,bad_end);
3718 reyssat 77
    ovlstrcpy(bad_beg,buf);
10 reyssat 78
}
79
 
7678 bpr 80
/* strcmp() to be used within qsort(). */
10 reyssat 81
int _scmp(const void *p1, const void *p2)
82
{
83
    const char **s1,**s2;
7678 bpr 84
 
10 reyssat 85
    s1=(const char **) p1; s2=(const char **) p2;
86
    return strcmp(*s1,*s2);
87
}
88
 
89
char *substit(char *p)
90
{
91
    char *pp;
92
    while((pp=strchr(p,'$'))!=NULL) *pp=' ';
93
    return p;
94
}
95