Added --with-yc option to configure. For the data1_node in data1.h:
[yaz-moved-to-github.git] / util / readconf.c
1 /*
2  * Copyright (C) 1994-1998, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: readconf.c,v $
7  * Revision 1.6  1998-10-13 16:09:55  adam
8  * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
9  * Added support for multiple attribute set references and tagset references
10  * from an abstract syntax file.
11  * Fixed many bad logs-calls in routines that read the various
12  * specifications regarding data1 (*.abs,*.att,...) and made the messages
13  * consistent whenever possible.
14  * Added extra 'lineno' argument to function readconf_line.
15  *
16  * Revision 1.5  1997/09/04 07:53:02  adam
17  * Added include readconf.h.
18  *
19  * Revision 1.4  1997/05/14 06:54:07  adam
20  * C++ support.
21  *
22  * Revision 1.3  1996/05/29 15:48:48  quinn
23  * Added \n to the isspace rule.
24  *
25  * Revision 1.2  1996/05/29  10:05:01  quinn
26  * Changed space criteria to support 8-bit characters
27  *
28  * Revision 1.1  1995/11/01  13:55:06  quinn
29  * Minor adjustments
30  *
31  * Revision 1.2  1995/10/30  13:54:27  quinn
32  * iRemoved fclose().
33  *
34  * Revision 1.1  1995/10/10  16:28:18  quinn
35  * Initial revision
36  *
37  *
38  */
39
40 #include <stdio.h>
41 #include <ctype.h>
42
43 #include <log.h>
44 #include <readconf.h>
45
46 #define l_isspace(c) ((c) == '\t' || (c) == ' ' || (c) == '\n')
47
48 int readconf_line(FILE *f, int *lineno, char *line, int len,
49                   char *argv[], int num)
50 {
51     char *p;
52     int argc;
53     
54     while ((p = fgets(line, len, f)))
55     {
56         (*lineno)++;
57         while (*p && l_isspace(*p))
58             p++;
59         if (*p && *p != '#')
60             break;
61     }
62     if (!p)
63         return 0;
64     
65     for (argc = 0; *p ; argc++)
66     {
67         if (*p == '#')  /* trailing comment */
68             break;
69         argv[argc] = p;
70         while (*p && !l_isspace(*p))
71             p++;
72         if (*p)
73         {
74             *(p++) = '\0';
75             while (*p && l_isspace(*p))
76                 p++;
77         }
78     }
79     return argc;
80 }
81
82 /*
83  * Read lines of a configuration file.
84  */
85 int readconf(char *name, void *rprivate,
86              int (*fun)(char *name, void *rprivate, int argc, char *argv[]))
87 {
88     FILE *f;
89     char line[512], *m_argv[50];
90     int m_argc;
91     int lineno = 0;
92     
93     if (!(f = fopen(name, "r")))
94     {
95         logf(LOG_WARN|LOG_ERRNO, "readconf: %s", name);
96         return -1;
97     }
98     for (;;)
99     {
100         int res;
101         
102         if (!(m_argc = readconf_line(f, &lineno, line, 512, m_argv, 50)))
103         {
104             fclose(f);
105             return 0;
106         }
107
108         if ((res = (*fun)(name, rprivate, m_argc, m_argv)))
109         {
110             fclose(f);
111             return res;
112         }
113     }
114 }