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