Function options now returns arg with error option.
[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.3  1994-10-04 17:46:54  adam
8  * Function options now returns arg with error option.
9  *
10  * Revision 1.2  1994/09/28  13:07:08  adam
11  * Use log_mask_str now.
12  *
13  * Revision 1.1  1994/09/16  15:39:11  adam
14  * Initial code of lookup - not tested yet.
15  *
16  */
17
18 #include <string.h>
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <assert.h>
22 #include <ctype.h>
23
24 #include <util.h>
25
26 char *prog;
27
28 int main (int argc, char **argv)
29 {
30     char *arg;
31     int ret;
32     char *inputfile = NULL;
33     FILE *ipf = stdin;
34     char ipf_buf[1024];
35
36     prog = *argv;
37     while ((ret = options ("vh", argv, argc, &arg)) != -2)
38     {
39         if (ret == 0)
40         {
41             if (!inputfile)
42                 inputfile = arg;
43             else
44             {
45                 log (LOG_FATAL, "too many files specified\n");
46                 exit (1);
47             }
48         }
49         else if (ret == 'v')
50         {
51             log_init (log_mask_str(arg), prog, NULL);
52         }
53         else if (ret == 'h')
54         {
55             fprintf (stderr, "usage:\n"
56                      "  %s [-h] [-v n] [file]\n", prog);
57             exit (1);
58         }
59         else
60         {
61             log (LOG_FATAL, "Unknown option '-%s'", arg);
62             exit (1);
63         }
64     }
65     if (inputfile)
66     {
67         ipf = fopen (inputfile, "r");
68         if (!ipf)
69         {
70             log (LOG_FATAL|LOG_ERRNO, "cannot open '%s'", inputfile);
71             exit (1);
72         }
73     }
74     while (fgets (ipf_buf, 1023, ipf))
75     {
76         char *ipf_ptr = ipf_buf;
77         for (;*ipf_ptr && *ipf_ptr != '\n';ipf_ptr++)
78         {
79             if (isalpha(*ipf_ptr) || *ipf_ptr == '_')
80             {
81                 int i = 1;
82                 while (ipf_ptr[i] && (isalnum(ipf_ptr[i]) ||
83                                       ipf_ptr[i] == '_'))
84                     i++;
85                 if (ipf_ptr[i])
86                     ipf_ptr[i++] = '\0';
87                 printf ("%s\n", ipf_ptr);
88                 ipf_ptr += (i-1);
89             }
90         }
91     }
92     return 0;
93 }
94
95
96