Initial code of lookup - not tested yet.
[idzebra-moved-to-github.git] / dict / dictext.c
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: dictext.c,v $
7  * Revision 1.1  1994-09-16 15:39:11  adam
8  * Initial code of lookup - not tested yet.
9  *
10  */
11
12 #include <string.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <assert.h>
16 #include <ctype.h>
17
18 #include <util.h>
19
20 char *prog;
21
22 int main (int argc, char **argv)
23 {
24     char *arg;
25     int ret;
26     char *inputfile = NULL;
27     FILE *ipf = stdin;
28     char ipf_buf[1024];
29
30     prog = *argv;
31     while ((ret = options ("vh", argv, argc, &arg)) != -2)
32     {
33         if (ret == 0)
34         {
35             if (!inputfile)
36                 inputfile = arg;
37             else
38             {
39                 log (LOG_FATAL, "too many files specified\n");
40                 exit (1);
41             }
42         }
43         else if (ret == 'v')
44         {
45             log_init (atoi(arg), prog, NULL);
46         }
47         else if (ret == 'h')
48         {
49             fprintf (stderr, "usage:\n"
50                      "  %s [-h] [-v n] [file]\n", prog);
51             exit (1);
52         }
53         else
54         {
55             log (LOG_FATAL, "unknown option");
56             exit (1);
57         }
58     }
59     if (inputfile)
60     {
61         ipf = fopen (inputfile, "r");
62         if (!ipf)
63         {
64             log (LOG_FATAL|LOG_ERRNO, "cannot open '%s'", inputfile);
65             exit (1);
66         }
67     }
68     while (fgets (ipf_buf, 1023, ipf))
69     {
70         char *ipf_ptr = ipf_buf;
71         for (;*ipf_ptr && *ipf_ptr != '\n';ipf_ptr++)
72         {
73             if (isalpha(*ipf_ptr) || *ipf_ptr == '_')
74             {
75                 int i = 1;
76                 while (ipf_ptr[i] && (isalnum(ipf_ptr[i]) ||
77                                       ipf_ptr[i] == '_'))
78                     i++;
79                 if (ipf_ptr[i])
80                     ipf_ptr[i++] = '\0';
81                 printf ("%s\n", ipf_ptr);
82                 ipf_ptr += (i-1);
83             }
84         }
85     }
86     return 0;
87 }
88
89
90