Subversion Repositories wimsdev

Rev

Rev 8148 | Rev 8896 | 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
 
66
void collapse_item(char *p, int n)
67
{
68
    int i;
69
    char *pp;
70
    if(n<1) return;
71
    for(i=1,pp=strchr(p,','); i<n && pp!=NULL; i++,pp=strchr(pp+1,','));
72
    if(pp==NULL) *p=0;
3718 reyssat 73
    else ovlstrcpy(p,pp+1);
10 reyssat 74
}
75
 
8067 bpr 76
/* modify a string. Bufferlen must be at least MAX_LINELEN */
10 reyssat 77
void string_modify2(char *start, char *bad_beg, char *bad_end, char *good,...)
78
{
79
    char buf[MAX_LINELEN+1];
80
    va_list vp;
7678 bpr 81
 
10 reyssat 82
    va_start(vp,good);
83
    vsnprintf(buf,sizeof(buf),good,vp); va_end(vp);
84
    if(strlen(start)-(bad_end-bad_beg)+strlen(buf)>=MAX_LINELEN)
85
      bailout(inlen,0,"string too long");
86
    strcat(buf,bad_end);
3718 reyssat 87
    ovlstrcpy(bad_beg,buf);
10 reyssat 88
}
89
 
7678 bpr 90
/* strcmp() to be used within qsort(). */
10 reyssat 91
int _scmp(const void *p1, const void *p2)
92
{
93
    const char **s1,**s2;
7678 bpr 94
 
10 reyssat 95
    s1=(const char **) p1; s2=(const char **) p2;
96
    return strcmp(*s1,*s2);
97
}
98
 
99
char *substit(char *p)
100
{
101
    char *pp;
102
    while((pp=strchr(p,'$'))!=NULL) *pp=' ';
103
    return p;
104
}
105