2 * Copyright (C) 1995-2005, Index Data ApS
5 * $Id: readconf.c,v 1.6 2005-06-25 15:46:04 adam Exp $
10 * \brief Implements config file reading
21 #include <yaz/readconf.h>
23 #define l_isspace(c) ((c) == '\t' || (c) == ' ' || (c) == '\n' || (c) == '\r')
25 int readconf_line(FILE *f, int *lineno, char *line, int len,
26 char *argv[], int num)
31 while ((p = fgets(line, len, f)))
34 while (*p && l_isspace(*p))
42 for (argc = 0; *p ; argc++)
44 if (*p == '#') /* trailing comment */
47 while (*p && !l_isspace(*p))
52 while (*p && l_isspace(*p))
60 * Read lines of a configuration file.
62 int readconf(char *name, void *rprivate,
63 int (*fun)(char *name, void *rprivate, int argc, char *argv[]))
66 char line[512], *m_argv[50];
70 if (!(f = fopen(name, "r")))
72 yaz_log(YLOG_WARN|YLOG_ERRNO, "readconf: %s", name);
79 if (!(m_argc = readconf_line(f, &lineno, line, 512, m_argv, 50)))
85 if ((res = (*fun)(name, rprivate, m_argc, m_argv)))
95 * indent-tabs-mode: nil
97 * vim: shiftwidth=4 tabstop=8 expandtab