1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 Index Data
3 * See the file LICENSE for details.
8 * \brief Implements config file reading
18 #include <yaz/readconf.h>
20 #define l_isspace(c) ((c) == '\t' || (c) == ' ' || (c) == '\n' || (c) == '\r')
22 int readconf_line(FILE *f, int *lineno, char *line, int len,
23 char *argv[], int num)
28 while ((p = fgets(line, len, f)))
31 while (*p && l_isspace(*p))
39 for (argc = 0; *p && argc < num ; argc++)
41 if (*p == '#') /* trailing comment */
44 while (*p && !l_isspace(*p))
49 while (*p && l_isspace(*p))
57 * Read lines of a configuration file.
59 int readconf(char *name, void *rprivate,
60 int (*fun)(char *name, void *rprivate, int argc, char *argv[]))
63 char line[512], *m_argv[50];
67 if (!(f = fopen(name, "r")))
69 yaz_log(YLOG_WARN|YLOG_ERRNO, "readconf: %s", name);
76 if (!(m_argc = readconf_line(f, &lineno, line, 512, m_argv, 50)))
82 if ((res = (*fun)(name, rprivate, m_argc, m_argv)))
92 * c-file-style: "Stroustrup"
93 * indent-tabs-mode: nil
95 * vim: shiftwidth=4 tabstop=8 expandtab