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