source: trunk/athena/bin/ispell/icombine.c @ 362

Revision 362, 2.7 KB checked in by ambar, 37 years ago (diff)
Initial revision
Line 
1/*
2 * icombine:  combine multiple ispell dictionary entries into a single
3 *            entry with the options of all entries
4 *
5 * Author:  Gary Puckering
6 *          Cognos, Inc.
7 *
8 * Written:  January 29, 1987
9 *
10 * Notes:  Input lines consist of a word followed optionally by
11 *         by one or more flags.  e.g CREATE/V/N/S
12 *         
13 *         No editing on flags is performed.
14 *         The input line is upshifted.
15 *         An improper flag, like /XN will be output as /X/N.
16 *         Flags are output in alphabetical order.
17 *         Non-letter appearing before the first "/" are retained,
18 *           those after are dropped.
19 */
20
21#include <stdio.h>
22#include <ctype.h>
23
24#define MAXFLAGS 26     /* letters A-Z */
25#define MAXLINE 255     /* maximum line size */
26
27#define TRUE 1
28#define FALSE 0
29typedef int bool;
30
31bool flagtbl[MAXFLAGS]; /* array of flag options */
32
33char line[MAXLINE];     /* current line */
34char lastword[MAXLINE]; /* previous word */
35char word[MAXLINE];     /* current word */
36char flags[MAXLINE];    /* current flags */
37int  expand = 0;        /* if NZ, expand instead of combining */
38
39extern char *strcpy ();
40
41
42char *getline()
43{
44    char *rvalue;
45    char *p;
46
47    if (rvalue=gets(line))     
48    { p = line;
49      while (*p) { if (islower(*p)) *p=toupper(*p); p++; }
50    }
51    return(rvalue);
52}
53
54main(argc,argv)
55int argc;
56char *argv[];
57{
58
59    if (argc > 1  &&  strcmp (argv[1], "-e") == 0)
60        expand = 1;
61    if (getline())
62    {
63        parse(line,lastword,flags);
64        getflags(flags);
65    }
66    else
67        return 0;
68
69    while (getline())
70    {
71        parse(line,word,flags);
72        if (strcmp(word,lastword)!=0)   /* different word */
73        {
74            putword();
75            (void) strcpy(lastword,word);
76        }
77        getflags(flags);
78    }
79    putword();
80    return 0;
81}
82
83putword()
84{
85    printf("%s",lastword);
86    putflags();
87}
88
89parse(ln,wrd,flgs)
90    char ln[];
91    char wrd[];
92    char flgs[];
93{
94    register char *p, *q;
95
96    /* copy line up to first "/" or to end */
97    for (p=ln,q=wrd; *p && *p != '/'; p++,q++) *q = *p;
98    *q = NULL;
99
100    (void) strcpy(flgs,p);     /* copy from "/" to end */
101}
102
103getflags(flgs)
104    char *flgs;
105{
106    register char *p;
107
108    for (p=flgs; *p; p++)
109        if (*p != '/')
110        {
111            if (islower (*p))
112                *p = toupper (*p);
113            if (isupper(*p))
114                flagtbl[(*p)-'A'] = TRUE;
115        }
116}
117
118putflags()
119{
120    register int i;
121    int slashout = 0;
122
123    if (expand)
124        putchar ('\n');
125
126    for (i=0; i<MAXFLAGS; i++)
127        if (flagtbl[i])
128        {
129            if (expand)
130                printf("%s/%c\n", lastword, i + 'A');
131            else
132            {
133                if (!slashout)
134                    putchar('/');
135                slashout = 1;
136                putchar(i+'A');
137            }
138            flagtbl[i]=FALSE;
139        }
140    if (!expand)
141        putchar('\n');
142}
Note: See TracBrowser for help on using the repository browser.