home *** CD-ROM | disk | FTP | other *** search
- head 0.4;
- access;
- symbols;
- locks
- simons:0.4; strict;
- comment @ * @;
-
-
- 0.4
- date 93.12.15.20.08.37; author simons; state Exp;
- branches;
- next 0.3;
-
- 0.3
- date 93.12.11.14.22.18; author simons; state Exp;
- branches;
- next 0.2;
-
- 0.2
- date 93.12.11.14.16.44; author simons; state Exp;
- branches;
- next 0.1;
-
- 0.1
- date 93.12.11.14.00.27; author simons; state Exp;
- branches;
- next ;
-
-
- desc
- @A set of subroutines designed to handle config file parsing.
- @
-
-
- 0.4
- log
- @The buffer GetConfigEntry() returns now isn't static anymore!!
- @
- text
- @/*
- * $Filename: ConfigFiles.c $
- * $Revision: 0.3 $
- * $Date: 1993/12/11 14:22:18 $
- *
- * Copyright (C) 1993 by Peter Simons <simons@@peti.GUN.de>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- * $Id: ConfigFiles.c,v 0.3 1993/12/11 14:22:18 simons Exp simons $
- *
- * ------------------------------- log history ----------------------------
- * $Log: ConfigFiles.c,v $
- * Revision 0.3 1993/12/11 14:22:18 simons
- * Added file-locking.
- *
- * Revision 0.2 1993/12/11 14:16:44 simons
- * Removed the netsupport.library specific stuff and added LoadFile().
- *
- * Revision 0.1 1993/12/11 14:00:27 simons
- * Taken from the netsupport.library. Several changes will be necessary
- * to make it work with LharcUUCP.
- */
-
-
- /**************************************************************************
- * *
- * SEKTION: Labels, Macros, Switches, Structures *
- * *
- **************************************************************************/
-
- /************************************* Includes ***********/
- #include <string.h>
- #include <stdlib.h>
-
- #include <dos/dos.h>
- #include <proto/dos.h>
-
- /************************************* Defines ************/
-
- /************************************* Prototypes *********/
- char * GetConfigEntry(char * , char * , char * );
- char * LoadUUConfig(void);
- char * GetKeyword(char * , char * );
- char * GetKeywordLine(char * , char * );
- char * InterpretKeywordLine(char * );
- char * LoadFile(char * );
-
- void LockFile(char *);
- int FileIsLocked(char *);
- void UnLockFile(char *);
- void UnLockFiles(void);
-
- /************************************* global variables ***/
-
- static const char __RCSId[] = "$Id: ConfigFiles.c,v 0.3 1993/12/11 14:22:18 simons Exp simons $";
-
- /**************************************************************************
- * *
- * SEKTION: main functions *
- * *
- **************************************************************************/
-
- char *GetConfigEntry(char *filename, char *keyword, char *def)
- {
- char *parameter, *filebuffer;
-
- /* If no filename is given, we assume the UUCP main config
- * file.
- */
-
- if (filename) {
- LockFile(filename);
- filebuffer = LoadFile(filename);
- UnLockFile(filename);
- }
- else
- filebuffer = LoadUUConfig();
-
-
- /* If the file has been loaded successfully, find the keyword
- * and returen the parameter.
- */
-
- if (filebuffer) {
- if (parameter = GetKeywordLine(keyword, filebuffer))
- parameter = InterpretKeywordLine(parameter);
-
- free(filebuffer); /* free filebuffer */
- }
-
- return (parameter) ? parameter : def;
- }
-
-
-
- /**************************************************************************
- * *
- * SEKTION: internal functions *
- * *
- **************************************************************************/
-
- char *LoadUUConfig(void)
- {
- char *filebuffer;
-
-
- LockFile("S:UUConfig");
- filebuffer = LoadFile("S:UUConfig");
- UnLockFile("S:UUConfig");
-
- if (!filebuffer) {
- LockFile("UULIB:Config");
- filebuffer = LoadFile("UULIB:Config");
- UnLockFile("UULIB:Config");
- }
-
- return filebuffer;
- }
-
-
- char * GetKeyword(char *keyword, char *buffer)
- {
- char *parameter;
-
- if (parameter = GetKeywordLine(keyword, buffer))
- parameter = InterpretKeywordLine(parameter);
-
-
- /* If GetKeywordLine() didn't find the keyword, return a pointer
- * to the provided default. */
-
- if (!(*parameter))
- parameter = &keyword[strlen(keyword)+1];
-
- return parameter;
- }
-
-
- char * GetKeywordLine(char *keyword, char *buffer)
- {
- int keywdlen;
-
- if (!(keywdlen = strlen(keyword)))
- return NULL; /* no keyword provided */
-
- while (strnicmp(keyword, buffer, keywdlen)) {
- while(*buffer != '\0' && *buffer != '\n')
- buffer++; /* search for '\0' or '\n' */
-
- if (!(*buffer)) /* if '\0', break loop */
- break;
-
- buffer++; /* skip '\n' and compare next line */
- }
-
- return (*buffer) ? buffer : NULL;
- }
-
- char * InterpretKeywordLine(char *keywordline)
- {
- char *parameter;
- int i;
-
- while (*keywordline != ' ' && *keywordline != '\t')
- keywordline++; /* skip keyword */
-
- while (*keywordline == ' ' || *keywordline == '\t')
- keywordline++; /* skip leading blanks or tabs */
-
- for (i = 0; keywordline[i] != '\n' && keywordline[i] != '\0'; i++)
- ; /* find end of line */
-
- while (keywordline[i-1] == ' ' || keywordline[i-1] == '\t')
- i--; /* remove trailing blanks or tabs */
-
- if (parameter = malloc(i+1)) {
- parameter[i] = '\0'; /* send end of string */
- while (i--) /* copy string to keywordline */
- parameter[i] = keywordline[i];
- }
-
- return parameter;
- }
-
-
- /*
- * LoadFile() -- determines the length of a given file, allocates the
- * appropiate buffer and actually loads the file. If everything works,
- * the address of the buffer is returned and the length of the file is
- * available via IoErr().
- *
- * ATTENTION: A zero-byte is appended to the loaded file, to enable the
- * usage of standard C string routines on the contents.
- *
- * The buffer should be freed after usage using free().
- */
-
- char *LoadFile(char *filename)
- {
- BPTR fh, fh2;
- struct FileInfoBlock *fib;
- char *memblock, *filebuffer = NULL;
- BOOL isfile = FALSE;
- int readlen;
-
- if (fh = Lock(filename, ACCESS_READ)) {
- if (fib = malloc(sizeof(struct FileInfoBlock))) {
- if (Examine(fh, fib)) {
- if (fh2 = OpenFromLock(fh)) {
- isfile = TRUE;
- if (memblock = malloc(fib->fib_Size + 1)) {
- if ((readlen = Read(fh2, memblock, fib->fib_Size)) != -1L) {
- memblock[readlen] = '\0';
- filebuffer = memblock;
- SetIoErr(readlen);
- }
- else
- free(memblock);
- }
- Close(fh2);
- }
- }
- free(fib);
- }
- if (!(isfile))
- UnLock(fh);
- }
-
- return filebuffer;
- }
-
- @
-
-
- 0.3
- log
- @Added file-locking.
- @
- text
- @d3 2
- a4 2
- * $Revision: 0.2 $
- * $Date: 1993/12/11 14:16:44 $
- d23 1
- a23 1
- * $Id: ConfigFiles.c,v 0.2 1993/12/11 14:16:44 simons Exp simons $
- d27 3
- d69 1
- a69 1
- static const char __RCSId[] = "$Id: ConfigFiles.c,v 0.2 1993/12/11 14:16:44 simons Exp simons $";
- d79 1
- a79 8
- char *parameter = NULL, *filebuffer;
- static char *GCEntryBuffer = NULL;
-
-
- /* Free the buffer we used last time */
-
- if (GCEntryBuffer)
- free(GCEntryBuffer);
- a80 1
-
- d105 1
- a105 8
- if (parameter) { /* track buffer for later usage */
- GCEntryBuffer = parameter;
- return parameter;
- }
- else { /* no buffer allocated--return default */
- GCEntryBuffer = NULL;
- return def;
- }
- @
-
-
- 0.2
- log
- @Removed the netsupport.library specific stuff and added LoadFile().
- @
- text
- @d3 2
- a4 2
- * $Revision: 0.1 $
- * $Date: 1993/12/11 14:00:27 $
- d23 1
- a23 1
- * $Id: ConfigFiles.c,v 0.1 1993/12/11 14:00:27 simons Exp simons $
- d27 3
- d59 5
- d66 1
- a66 1
- static const char __RCSId[] = "$Id: ConfigFiles.c,v 0.1 1993/12/11 14:00:27 simons Exp simons $";
- d90 2
- a91 1
- if (filename)
- d93 2
- d132 7
- a138 1
- if (!(filebuffer = LoadFile("S:UUConfig")))
- d140 2
- @
-
-
- 0.1
- log
- @Taken from the netsupport.library. Several changes will be necessary
- to make it work with LharcUUCP.
- @
- text
- @d3 2
- a4 2
- * $Revision: 1.1 $
- * $Date: 1993/12/11 13:59:29 $
- d23 1
- a23 1
- * $Id: ConfigFiles.c,v 1.1 1993/12/11 13:59:29 simons Exp simons $
- d27 3
- a29 3
- * Revision 1.1 1993/12/11 13:59:29 simons
- * Initial revision
- *
- d41 1
- a41 2
- #include <proto/utility.h>
- #include <exec/types.h>
- d43 2
- a44 3
- #include "libraries/netsupport.h"
- #include "NetSupportLibrary.h"
- #include "MemoryHandling.h"
- d49 8
- a56 2
- #include "ConfigFiles.h"
- #include "SupportRoutines.h"
- d58 1
- a58 1
- static const char __RCSId[] = "$Id: ConfigFiles.c,v 1.1 1993/12/11 13:59:29 simons Exp simons $";
- d62 1
- a62 1
- * SEKTION: Public library functions *
- d66 1
- a66 3
- STRPTR __asm GetConfigEntry(register __a0 STRPTR filename,
- register __a1 STRPTR keyword,
- register __a2 STRPTR def)
- d69 1
- a69 1
- void *GCEntryBuffer = (GetStaticBuffer())->nspsb_GCEntryBuffer;
- d75 1
- a75 1
- NSPFreeMemPooled(GCEntryBuffer);
- d88 1
- a88 1
- /* If the file has be loaded successfully, find the keyword
- d96 1
- a96 1
- NSPFreeMemPooled(filebuffer); /* free filebuffer */
- d111 1
- a111 1
- /*************************************************************************
- d113 1
- a113 1
- * SEKTION: Internal library functions *
- d117 1
- a117 1
- char * __asm LoadUUConfig(void)
- d128 1
- a128 2
- char * __asm GetKeyword(register __a0 char *keyword,
- register __a1 char *buffer)
- d146 1
- a146 2
- char * __asm GetKeywordLine(register __a0 char *keyword,
- register __a1 char *buffer)
- a147 1
- struct UtilityBase *UtilityBase = NetSupportBase->nsp_UtilityBase;
- d153 1
- a153 1
- while (Strnicmp(keyword, buffer, keywdlen)) {
- d166 1
- a166 1
- char * __asm InterpretKeywordLine(register __a0 char *keywordline)
- d183 1
- a183 1
- if (parameter = NSPAllocMemPooled(i+1, 0L)) {
- d192 46
- @
-