X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Freadconf.c;h=2c444f5a56b4062fd24028edded3d8c6e4c25019;hp=3b3687487007ccaa8405169068612bc35d6a01a6;hb=0d6f3ee9720647761ff74414a46828c0b9711ac0;hpb=c6e47cbbff56f39f6d81b079ebaeac41d793d4d9 diff --git a/src/readconf.c b/src/readconf.c index 3b36874..2c444f5 100644 --- a/src/readconf.c +++ b/src/readconf.c @@ -1,62 +1,18 @@ -/* - * Copyright (C) 1994-2000, Index Data - * All rights reserved. - * Sebastian Hammer, Adam Dickmeiss - * - * $Log: readconf.c,v $ - * Revision 1.1 2003-10-27 12:21:35 adam - * Source restructure. yaz-marcdump part of installation - * - * Revision 1.10 2000/02/29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.9 1999/11/30 13:47:12 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.8 1999/08/27 09:40:32 adam - * Renamed logf function to yaz_log. Removed VC++ project files. - * - * Revision 1.7 1999/06/30 09:10:32 adam - * Fixed reading of MS-DOS files. - * - * Revision 1.6 1998/10/13 16:09:55 adam - * Added support for arbitrary OID's for tagsets, schemas and attribute sets. - * Added support for multiple attribute set references and tagset references - * from an abstract syntax file. - * Fixed many bad logs-calls in routines that read the various - * specifications regarding data1 (*.abs,*.att,...) and made the messages - * consistent whenever possible. - * Added extra 'lineno' argument to function readconf_line. - * - * Revision 1.5 1997/09/04 07:53:02 adam - * Added include readconf.h. - * - * Revision 1.4 1997/05/14 06:54:07 adam - * C++ support. - * - * Revision 1.3 1996/05/29 15:48:48 quinn - * Added \n to the isspace rule. - * - * Revision 1.2 1996/05/29 10:05:01 quinn - * Changed space criteria to support 8-bit characters - * - * Revision 1.1 1995/11/01 13:55:06 quinn - * Minor adjustments - * - * Revision 1.2 1995/10/30 13:54:27 quinn - * iRemoved fclose(). - * - * Revision 1.1 1995/10/10 16:28:18 quinn - * Initial revision - * - * +/* This file is part of the YAZ toolkit. + * Copyright (C) Index Data + * See the file LICENSE for details. + */ + +/** + * \file readconf.c + * \brief Implements config file reading */ + #if HAVE_CONFIG_H #include #endif #include -#include #include #include @@ -64,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; } @@ -101,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(LOG_WARN|LOG_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 (!(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; - } + 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 + */ +