1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
8 * \brief Implements config file reading
19 #include <yaz/readconf.h>
21 #define l_isspace(c) ((c) == '\t' || (c) == ' ' || (c) == '\n' || (c) == '\r')
23 int readconf_line(FILE *f, int *lineno, char *line, int len,
24 char *argv[], int num)
29 while ((p = fgets(line, len, f)))
32 while (*p && l_isspace(*p))
40 for (argc = 0; *p ; argc++)
42 if (*p == '#') /* trailing comment */
45 while (*p && !l_isspace(*p))
50 while (*p && l_isspace(*p))
58 * Read lines of a configuration file.
60 int readconf(char *name, void *rprivate,
61 int (*fun)(char *name, void *rprivate, int argc, char *argv[]))
64 char line[512], *m_argv[50];
68 if (!(f = fopen(name, "r")))
70 yaz_log(YLOG_WARN|YLOG_ERRNO, "readconf: %s", name);
77 if (!(m_argc = readconf_line(f, &lineno, line, 512, m_argv, 50)))
83 if ((res = (*fun)(name, rprivate, m_argc, m_argv)))
93 * indent-tabs-mode: nil
95 * vim: shiftwidth=4 tabstop=8 expandtab