X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Freadconf.c;h=2c444f5a56b4062fd24028edded3d8c6e4c25019;hp=849995cefa14cc86b68cecdcf182d7f17af171c2;hb=0d6f3ee9720647761ff74414a46828c0b9711ac0;hpb=f4c095a042b1bcccb78136be87944e46412386aa diff --git a/src/readconf.c b/src/readconf.c index 849995c..2c444f5 100644 --- a/src/readconf.c +++ b/src/readconf.c @@ -1,8 +1,6 @@ -/* - * Copyright (C) 1994-2004, Index Data - * All rights reserved. - * - * $Id: readconf.c,v 1.4 2004-12-13 14:21:55 heikki Exp $ +/* This file is part of the YAZ toolkit. + * Copyright (C) Index Data + * See the file LICENSE for details. */ /** @@ -15,7 +13,6 @@ #endif #include -#include #include #include @@ -23,35 +20,35 @@ #define l_isspace(c) ((c) == '\t' || (c) == ' ' || (c) == '\n' || (c) == '\r') int readconf_line(FILE *f, int *lineno, char *line, int len, - char *argv[], int num) + char *argv[], int num) { char *p; int argc; - + while ((p = fgets(line, len, f))) { - (*lineno)++; - while (*p && l_isspace(*p)) - p++; - if (*p && *p != '#') - break; + (*lineno)++; + while (*p && l_isspace(*p)) + p++; + if (*p && *p != '#') + break; } if (!p) - return 0; - - for (argc = 0; *p ; argc++) + return 0; + + for (argc = 0; *p && argc < num ; argc++) { - if (*p == '#') /* trailing comment */ - break; - argv[argc] = p; - while (*p && !l_isspace(*p)) - p++; - if (*p) - { - *(p++) = '\0'; - while (*p && l_isspace(*p)) - p++; - } + if (*p == '#') /* trailing comment */ + break; + argv[argc] = p; + while (*p && !l_isspace(*p)) + p++; + if (*p) + { + *(p++) = '\0'; + while (*p && l_isspace(*p)) + p++; + } } return argc; } @@ -60,32 +57,41 @@ int readconf_line(FILE *f, int *lineno, char *line, int len, * Read lines of a configuration file. */ int readconf(char *name, void *rprivate, - int (*fun)(char *name, void *rprivate, int argc, char *argv[])) + int (*fun)(char *name, void *rprivate, int argc, char *argv[])) { FILE *f; char line[512], *m_argv[50]; int m_argc; int lineno = 0; - + if (!(f = fopen(name, "r"))) { - yaz_log(YLOG_WARN|YLOG_ERRNO, "readconf: %s", name); - return -1; + yaz_log(YLOG_WARN|YLOG_ERRNO, "readconf: %s", name); + return -1; } for (;;) { - int res; - - if (!(m_argc = readconf_line(f, &lineno, line, 512, m_argv, 50))) - { - fclose(f); - return 0; - } + int res; - if ((res = (*fun)(name, rprivate, m_argc, m_argv))) - { - fclose(f); - return res; - } + if (!(m_argc = readconf_line(f, &lineno, line, 512, m_argv, 50))) + { + fclose(f); + return 0; + } + + if ((res = (*fun)(name, rprivate, m_argc, m_argv))) + { + fclose(f); + return res; + } } } +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +