Subversion Repositories wimsdev

Rev

Rev 3718 | Rev 8100 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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