Subversion Repositories wimsdev

Rev

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