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