Updated footer comment
[idzebra-moved-to-github.git] / dict / dictext.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2009 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20
21
22 #include <string.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <assert.h>
26 #include <ctype.h>
27
28 #include <idzebra/util.h>
29 #include <yaz/yaz-util.h>
30
31 char *prog;
32
33 int main (int argc, char **argv)
34 {
35     char *arg;
36     int ret;
37     int use8 = 0;
38     char *inputfile = NULL;
39     FILE *ipf = stdin;
40     char ipf_buf[1024];
41
42     prog = *argv;
43     while ((ret = options("8vh", argv, argc, &arg)) != -2)
44     {
45         if (ret == 0)
46         {
47             if (!inputfile)
48                 inputfile = arg;
49             else
50             {
51                 yaz_log (YLOG_FATAL, "too many files specified\n");
52                 exit (1);
53             }
54         }
55         else if (ret == 'v')
56         {
57             yaz_log_init (yaz_log_mask_str(arg), prog, NULL);
58         }
59         else if (ret == 'h')
60         {
61             fprintf (stderr, "usage:\n"
62                      "  %s [-8] [-h] [-v n] [file]\n", prog);
63             exit (1);
64         }
65         else if (ret == '8')
66             use8 = 1;
67         else
68         {
69             yaz_log (YLOG_FATAL, "Unknown option '-%s'", arg);
70             exit (1);
71         }
72     }
73     if (inputfile)
74     {
75         ipf = fopen (inputfile, "r");
76         if (!ipf)
77         {
78             yaz_log (YLOG_FATAL|YLOG_ERRNO, "cannot open '%s'", inputfile);
79             exit (1);
80         }
81     }
82     while (fgets (ipf_buf, 1023, ipf))
83     {
84         char *ipf_ptr = ipf_buf;
85         for (;*ipf_ptr && *ipf_ptr != '\n';ipf_ptr++)
86         {
87             if ((use8 && *ipf_ptr<0)
88                 || (*ipf_ptr > 0 && isalpha(*ipf_ptr))
89                 || *ipf_ptr == '_')
90             {
91                 int i = 1;
92                 while (ipf_ptr[i] && ((use8 && ipf_ptr[i] < 0)
93                                       || (ipf_ptr[i]>0 && isalnum(ipf_ptr[i]))
94                                       || ipf_ptr[i] == '_'))
95                     i++;
96                 if (ipf_ptr[i])
97                     ipf_ptr[i++] = '\0';
98                 printf ("%s\n", ipf_ptr);
99                 ipf_ptr += (i-1);
100             }
101         }
102     }
103     return 0;
104 }
105
106
107
108 /*
109  * Local variables:
110  * c-basic-offset: 4
111  * c-file-style: "Stroustrup"
112  * indent-tabs-mode: nil
113  * End:
114  * vim: shiftwidth=4 tabstop=8 expandtab
115  */
116