Subversion Repositories wimsdev

Rev

Rev 8148 | Rev 8896 | Go to most recent revision | Blame | Compare with Previous | 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.  
  21. /*#include <stdarg.h>*/
  22. #include "../Lib/libwims.h"
  23. #include "msg2wims.h"
  24.  
  25. void msg_error(char *p)
  26. {
  27.     fprintf(stderr,"%s\n",p);
  28. }
  29.  
  30. void bailout(int i1, int i2, char *msg)
  31. {
  32.     if(*msg) msg_error(msg);
  33.     printf("%d %d",i1,i2); exit(0);
  34. }
  35.  
  36. /* find html tag end */
  37. char *find_tag_end(char *p)
  38. {
  39.     char *pp;
  40.  
  41.     p++; if(*p=='!') {
  42.       if(*(p+1)=='-' && *(p+2)=='-') {
  43.           pp=strstr(p,"-->"); if(pp==NULL) return p+strlen(p);
  44.           else return p+2;
  45.       }
  46.     }
  47.     /* else */ {
  48.       pp=strchr(p,'>'); if(pp==NULL) return p+strlen(p);
  49.       else return pp;
  50.     }
  51. /* Now the following is not executed. */
  52. /*    for(pp=p;*pp;pp++) {
  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.       }
  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;
  73.     else ovlstrcpy(p,pp+1);
  74. }
  75.  
  76. /* modify a string. Bufferlen must be at least MAX_LINELEN */
  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;
  81.  
  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);
  87.     ovlstrcpy(bad_beg,buf);
  88. }
  89.  
  90. /* strcmp() to be used within qsort(). */
  91. int _scmp(const void *p1, const void *p2)
  92. {
  93.     const char **s1,**s2;
  94.  
  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.  
  106.