Subversion Repositories wimsdev

Rev

Rev 10 | Rev 8100 | 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.  
  18.         /* This special program selects words composed by
  19.          * selected characters, each selected character being used
  20.          * at most once in the word */
  21.  
  22.         /* Selected characters are entered by the env var 'oncechar'.
  23.          * Words entered by stdin. Output to stdout. */
  24.  
  25. #include "../wims.h"
  26. #include "../Lib/basicstr.c"
  27. #define MAX_WORDLEN 1023
  28.  
  29. char wbuf[MAX_WORDLEN+1];
  30. char selbuf[256];
  31.  
  32. int getword(void)
  33. {
  34.     int t,c;
  35.    
  36.     do c=getchar(); while(isspace(c));
  37.     for(t=0; t<MAX_WORDLEN && isalnum(c); t++, c=getchar()) wbuf[t]=c;
  38.     wbuf[t]=0; return c;    
  39. }
  40.  
  41. void checkword(void)
  42. {
  43.     char sbuf[256];
  44.     char *p, *pt;
  45.     memmove(sbuf,selbuf,sizeof(sbuf));
  46.     for(p=wbuf; *p; p++) {
  47.         pt=strchr(sbuf,*p); if(pt==NULL) return;
  48.         else *pt=' ';
  49.     }
  50.     printf("%s\n",wbuf);
  51. }
  52.  
  53. int main(int argc, char *argv[])
  54. {
  55.     int c;
  56.     char *p;
  57.    
  58.     p=getenv("oncechar"); if(p==NULL || *p==0) return 0;
  59.     snprintf(selbuf,sizeof(selbuf),"%s",p);
  60.     for(p=selbuf; *p; p++)
  61.       if(isspace(*p) || strchr("^?*.${}[]()\\",*p)!=NULL) ovlstrcpy(p,p+1);
  62.     do{
  63.         c=getword(); checkword();
  64.     }
  65.     while(c!=EOF);
  66.     return 0;
  67. }
  68.  
  69.