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