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