Updated WIN32 code specific sections. Changed header.
[idzebra-moved-to-github.git] / dict / dictext.c
1 /*
2  * Copyright (C) 1994-1999, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: dictext.c,v $
7  * Revision 1.7  1999-02-02 14:50:18  adam
8  * Updated WIN32 code specific sections. Changed header.
9  *
10  * Revision 1.6  1996/10/29 14:00:02  adam
11  * Page size given by DICT_DEFAULT_PAGESIZE in dict.h.
12  *
13  * Revision 1.5  1996/01/31 21:03:59  adam
14  * Extra options.
15  *
16  * Revision 1.4  1995/09/04  12:33:31  adam
17  * Various cleanup. YAZ util used instead.
18  *
19  * Revision 1.3  1994/10/04  17:46:54  adam
20  * Function options now returns arg with error option.
21  *
22  * Revision 1.2  1994/09/28  13:07:08  adam
23  * Use log_mask_str now.
24  *
25  * Revision 1.1  1994/09/16  15:39:11  adam
26  * Initial code of lookup - not tested yet.
27  *
28  */
29
30 #include <string.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <assert.h>
34 #include <ctype.h>
35
36 #include <zebrautl.h>
37
38 char *prog;
39
40 int main (int argc, char **argv)
41 {
42     char *arg;
43     int ret;
44     int use8 = 0;
45     char *inputfile = NULL;
46     FILE *ipf = stdin;
47     char ipf_buf[1024];
48
49     prog = *argv;
50     while ((ret = options ("8vh", argv, argc, &arg)) != -2)
51     {
52         if (ret == 0)
53         {
54             if (!inputfile)
55                 inputfile = arg;
56             else
57             {
58                 logf (LOG_FATAL, "too many files specified\n");
59                 exit (1);
60             }
61         }
62         else if (ret == 'v')
63         {
64             log_init (log_mask_str(arg), prog, NULL);
65         }
66         else if (ret == 'h')
67         {
68             fprintf (stderr, "usage:\n"
69                      "  %s [-8] [-h] [-v n] [file]\n", prog);
70             exit (1);
71         }
72         else if (ret == '8')
73             use8 = 1;
74         else
75         {
76             logf (LOG_FATAL, "Unknown option '-%s'", arg);
77             exit (1);
78         }
79     }
80     if (inputfile)
81     {
82         ipf = fopen (inputfile, "r");
83         if (!ipf)
84         {
85             logf (LOG_FATAL|LOG_ERRNO, "cannot open '%s'", inputfile);
86             exit (1);
87         }
88     }
89     while (fgets (ipf_buf, 1023, ipf))
90     {
91         char *ipf_ptr = ipf_buf;
92         for (;*ipf_ptr && *ipf_ptr != '\n';ipf_ptr++)
93         {
94             if ((use8 && *ipf_ptr<0)
95                 || (*ipf_ptr > 0 && isalpha(*ipf_ptr))
96                 || *ipf_ptr == '_')
97             {
98                 int i = 1;
99                 while (ipf_ptr[i] && ((use8 && ipf_ptr[i] < 0)
100                                       || (ipf_ptr[i]>0 && isalnum(ipf_ptr[i]))
101                                       || ipf_ptr[i] == '_'))
102                     i++;
103                 if (ipf_ptr[i])
104                     ipf_ptr[i++] = '\0';
105                 printf ("%s\n", ipf_ptr);
106                 ipf_ptr += (i-1);
107             }
108         }
109     }
110     return 0;
111 }
112
113
114