Added --with-yc option to configure. For the data1_node in data1.h:
[yaz-moved-to-github.git] / util / options.c
1 /*
2  * Copyright (c) 1995, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: options.c,v $
7  * Revision 1.6  1997-09-01 08:54:13  adam
8  * New windows NT/95 port using MSV5.0. Made prefix query handling
9  * thread safe. The function options ignores empty arguments when met.
10  *
11  * Revision 1.5  1995/12/06 13:00:19  adam
12  * Minus alone not treated as an option.
13  *
14  * Revision 1.4  1995/09/29  17:12:35  quinn
15  * Smallish
16  *
17  * Revision 1.3  1995/09/27  15:03:03  quinn
18  * Modified function heads & prototypes.
19  *
20  * Revision 1.2  1995/05/16  08:51:13  quinn
21  * License, documentation, and memory fixes
22  *
23  * Revision 1.1  1995/03/27  08:35:18  quinn
24  * Created util library
25  * Added memory debugging module. Imported options-manager
26  *
27  * Revision 1.2  1994/10/04  17:47:10  adam
28  * Function options now returns arg with error option.
29  *
30  * Revision 1.1  1994/08/16  15:57:22  adam
31  * The first utility modules.
32  *
33  */
34 #include <stdlib.h>
35
36 #include <options.h>
37
38 static int arg_no = 1;
39 static int arg_off = 0;
40
41 int options (const char *desc, char **argv, int argc, char **arg)
42 {
43     int ch, i = 0;
44     
45     if (arg_no >= argc)
46         return -2;
47     if (arg_off == 0)
48     {
49         while (argv[arg_no][0] == '\0')
50         {
51             arg_no++;
52             if (arg_no >= argc)
53                 return -2;
54         }
55         if (argv[arg_no][0] != '-' || argv[arg_no][1] == '\0')
56         {
57             *arg = argv[arg_no++];
58             return 0;
59         }
60         arg_off++;
61     }
62     ch = argv[arg_no][arg_off++];
63     while (desc[i])
64     {
65         int desc_char = desc[i++];
66         int type = 0;
67         if (desc[i] == ':')
68         {       /* string argument */
69             type = desc[i++];
70         }
71         if (desc_char == ch)
72         { /* option with argument */
73             if (type)
74             {
75                 if (argv[arg_no][arg_off])
76                 {
77                     *arg = argv[arg_no]+arg_off;
78                     arg_no++;
79                     arg_off =  0;
80                 }
81                 else
82                 {
83                     arg_no++;
84                     arg_off = 0;
85                     if (arg_no < argc)
86                         *arg = argv[arg_no++];
87                     else
88                         *arg = "";
89                 }
90             }
91             else /* option with no argument */
92             {
93                 if (argv[arg_no][arg_off])
94                     arg_off++;
95                 else
96                 {
97                     arg_off = 0;
98                     arg_no++;
99                 }
100             }
101             return ch;
102         }               
103     }
104     *arg = argv[arg_no]+arg_off-1;
105     arg_no = arg_no + 1;
106     arg_off = 0;
107     return -1;
108 }