2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* scanner.c */
|
|
|
|
/* */
|
|
|
|
/* Configuration file scanner for the ld65 linker */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2009-09-28 15:59:18 +00:00
|
|
|
/* (C) 1998-2009, Ullrich von Bassewitz */
|
2008-03-31 20:54:45 +00:00
|
|
|
/* Roemerstrasse 52 */
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
/* */
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
/* */
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
/* distribution. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2000-09-07 21:32:54 +00:00
|
|
|
/* common */
|
2002-04-20 11:49:53 +00:00
|
|
|
#include "chartype.h"
|
2005-01-08 21:38:17 +00:00
|
|
|
#include "strbuf.h"
|
2000-09-07 21:32:54 +00:00
|
|
|
#include "xsprintf.h"
|
2000-06-08 18:18:40 +00:00
|
|
|
|
2000-09-07 21:32:54 +00:00
|
|
|
/* ld65 */
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "global.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "scanner.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Data */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Current token and attributes */
|
2000-11-20 15:22:57 +00:00
|
|
|
cfgtok_t CfgTok;
|
2010-03-20 17:23:51 +00:00
|
|
|
StrBuf CfgSVal = STATIC_STRBUF_INITIALIZER;
|
2000-05-28 13:40:48 +00:00
|
|
|
unsigned long CfgIVal;
|
|
|
|
|
|
|
|
/* Error location */
|
|
|
|
unsigned CfgErrorLine;
|
|
|
|
unsigned CfgErrorCol;
|
|
|
|
|
|
|
|
/* Input sources for the configuration */
|
|
|
|
static const char* CfgName = 0;
|
|
|
|
static const char* CfgBuf = 0;
|
|
|
|
|
|
|
|
/* Other input stuff */
|
2000-06-08 18:18:40 +00:00
|
|
|
static int C = ' ';
|
2000-05-28 13:40:48 +00:00
|
|
|
static unsigned InputLine = 1;
|
|
|
|
static unsigned InputCol = 0;
|
|
|
|
static FILE* InputFile = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-09-07 21:32:54 +00:00
|
|
|
/* Error handling */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgWarning (const char* Format, ...)
|
|
|
|
/* Print a warning message adding file name and line number of the config file */
|
|
|
|
{
|
2005-01-08 21:38:17 +00:00
|
|
|
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
|
2000-09-07 21:32:54 +00:00
|
|
|
va_list ap;
|
2000-06-08 18:18:40 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
va_start (ap, Format);
|
2005-01-08 21:38:17 +00:00
|
|
|
SB_VPrintf (&Buf, Format, ap);
|
2000-06-08 18:18:40 +00:00
|
|
|
va_end (ap);
|
|
|
|
|
2005-01-08 21:38:17 +00:00
|
|
|
Warning ("%s(%u): %s", CfgGetName(), CfgErrorLine, SB_GetConstBuf (&Buf));
|
2008-03-31 20:54:45 +00:00
|
|
|
SB_Done (&Buf);
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgError (const char* Format, ...)
|
|
|
|
/* Print an error message adding file name and line number of the config file */
|
|
|
|
{
|
2005-01-08 21:38:17 +00:00
|
|
|
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
|
2000-05-28 13:40:48 +00:00
|
|
|
va_list ap;
|
2000-06-08 18:18:40 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
va_start (ap, Format);
|
2005-01-08 21:38:17 +00:00
|
|
|
SB_VPrintf (&Buf, Format, ap);
|
2000-06-08 18:18:40 +00:00
|
|
|
va_end (ap);
|
|
|
|
|
2005-01-08 21:38:17 +00:00
|
|
|
Error ("%s(%u): %s", CfgGetName(), CfgErrorLine, SB_GetConstBuf (&Buf));
|
2008-03-31 20:54:45 +00:00
|
|
|
SB_Done (&Buf);
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void NextChar (void)
|
|
|
|
/* Read the next character from the input file */
|
|
|
|
{
|
|
|
|
if (CfgBuf) {
|
|
|
|
/* Read from buffer */
|
|
|
|
C = (unsigned char)(*CfgBuf);
|
|
|
|
if (C == 0) {
|
2001-10-25 18:51:49 +00:00
|
|
|
C = EOF;
|
2000-05-28 13:40:48 +00:00
|
|
|
} else {
|
|
|
|
++CfgBuf;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Read from the file */
|
|
|
|
C = getc (InputFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Count columns */
|
|
|
|
if (C != EOF) {
|
|
|
|
++InputCol;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Count lines */
|
|
|
|
if (C == '\n') {
|
|
|
|
++InputLine;
|
|
|
|
InputCol = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned DigitVal (int C)
|
|
|
|
/* Return the value for a numeric digit */
|
|
|
|
{
|
|
|
|
if (isdigit (C)) {
|
|
|
|
return C - '0';
|
|
|
|
} else {
|
|
|
|
return toupper (C) - 'A' + 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-03-20 17:48:15 +00:00
|
|
|
static void StrVal (void)
|
|
|
|
/* Parse a string value and expand escape sequences */
|
|
|
|
{
|
|
|
|
/* Skip the starting double quotes */
|
|
|
|
NextChar ();
|
|
|
|
|
|
|
|
/* Read input chars */
|
|
|
|
SB_Clear (&CfgSVal);
|
|
|
|
while (C != '\"') {
|
|
|
|
switch (C) {
|
|
|
|
|
|
|
|
case EOF:
|
|
|
|
case '\n':
|
|
|
|
CfgError ("Unterminated string");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
NextChar ();
|
|
|
|
switch (C) {
|
|
|
|
|
|
|
|
case EOF:
|
|
|
|
case '\n':
|
|
|
|
case '\"':
|
|
|
|
CfgError ("Unterminated '%%' escape sequence");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
SB_AppendChar (&CfgSVal, '%');
|
|
|
|
NextChar ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'O':
|
|
|
|
/* Replace by output file */
|
|
|
|
if (OutputName) {
|
|
|
|
SB_AppendStr (&CfgSVal, OutputName);
|
|
|
|
}
|
|
|
|
NextChar ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
CfgWarning ("Unkown escape sequence `%%%c'", C);
|
|
|
|
SB_AppendChar (&CfgSVal, '%');
|
|
|
|
SB_AppendChar (&CfgSVal, C);
|
|
|
|
NextChar ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SB_AppendChar (&CfgSVal, C);
|
|
|
|
NextChar ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip the terminating double quotes */
|
|
|
|
NextChar ();
|
|
|
|
|
|
|
|
/* Terminate the string */
|
|
|
|
SB_Terminate (&CfgSVal);
|
|
|
|
|
|
|
|
/* We've read a string value */
|
|
|
|
CfgTok = CFGTOK_STRCON;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
void CfgNextTok (void)
|
|
|
|
/* Read the next token from the input stream */
|
|
|
|
{
|
|
|
|
Again:
|
|
|
|
/* Skip whitespace */
|
|
|
|
while (isspace (C)) {
|
|
|
|
NextChar ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remember the current position */
|
|
|
|
CfgErrorLine = InputLine;
|
|
|
|
CfgErrorCol = InputCol;
|
|
|
|
|
|
|
|
/* Identifier? */
|
2002-04-20 11:49:53 +00:00
|
|
|
if (C == '_' || IsAlpha (C)) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Read the identifier */
|
2010-03-20 17:23:51 +00:00
|
|
|
SB_Clear (&CfgSVal);
|
2002-04-20 11:49:53 +00:00
|
|
|
while (C == '_' || IsAlNum (C)) {
|
2010-03-20 17:23:51 +00:00
|
|
|
SB_AppendChar (&CfgSVal, C);
|
2000-05-28 13:40:48 +00:00
|
|
|
NextChar ();
|
|
|
|
}
|
2010-03-20 17:23:51 +00:00
|
|
|
SB_Terminate (&CfgSVal);
|
2000-05-28 13:40:48 +00:00
|
|
|
CfgTok = CFGTOK_IDENT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hex number? */
|
|
|
|
if (C == '$') {
|
|
|
|
NextChar ();
|
|
|
|
if (!isxdigit (C)) {
|
2005-01-08 21:38:17 +00:00
|
|
|
CfgError ("Hex digit expected");
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
CfgIVal = 0;
|
|
|
|
while (isxdigit (C)) {
|
|
|
|
CfgIVal = CfgIVal * 16 + DigitVal (C);
|
|
|
|
NextChar ();
|
|
|
|
}
|
|
|
|
CfgTok = CFGTOK_INTCON;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decimal number? */
|
|
|
|
if (isdigit (C)) {
|
|
|
|
CfgIVal = 0;
|
|
|
|
while (isdigit (C)) {
|
|
|
|
CfgIVal = CfgIVal * 10 + DigitVal (C);
|
|
|
|
NextChar ();
|
|
|
|
}
|
|
|
|
CfgTok = CFGTOK_INTCON;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Other characters */
|
|
|
|
switch (C) {
|
|
|
|
|
2005-07-28 19:50:22 +00:00
|
|
|
case '-':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_MINUS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '+':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_PLUS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '*':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_MUL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '/':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_DIV;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '(':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_LPAR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ')':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_RPAR;
|
|
|
|
break;
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
case '{':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_LCURLY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '}':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_RCURLY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ';':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_SEMI;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '.':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_DOT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ',':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_COMMA;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '=':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_EQ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ':':
|
|
|
|
NextChar ();
|
|
|
|
CfgTok = CFGTOK_COLON;
|
2001-10-25 18:51:49 +00:00
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
case '\"':
|
2010-03-20 17:48:15 +00:00
|
|
|
StrVal ();
|
2000-05-28 13:40:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '#':
|
|
|
|
/* Comment */
|
|
|
|
while (C != '\n' && C != EOF) {
|
|
|
|
NextChar ();
|
|
|
|
}
|
|
|
|
if (C != EOF) {
|
|
|
|
goto Again;
|
|
|
|
}
|
|
|
|
CfgTok = CFGTOK_EOF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
NextChar ();
|
|
|
|
switch (C) {
|
|
|
|
|
|
|
|
case 'O':
|
|
|
|
NextChar ();
|
|
|
|
if (OutputName) {
|
2010-03-20 17:23:51 +00:00
|
|
|
SB_CopyStr (&CfgSVal, OutputName);
|
2000-05-28 13:40:48 +00:00
|
|
|
} else {
|
2010-03-20 17:23:51 +00:00
|
|
|
SB_Clear (&CfgSVal);
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
2010-03-20 17:23:51 +00:00
|
|
|
SB_Terminate (&CfgSVal);
|
2000-05-28 13:40:48 +00:00
|
|
|
CfgTok = CFGTOK_STRCON;
|
2001-10-25 18:51:49 +00:00
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
case 'S':
|
|
|
|
NextChar ();
|
|
|
|
CfgIVal = StartAddr;
|
|
|
|
CfgTok = CFGTOK_INTCON;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
CfgError ("Invalid format specification");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EOF:
|
|
|
|
CfgTok = CFGTOK_EOF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-01-08 21:38:17 +00:00
|
|
|
CfgError ("Invalid character `%c'", C);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-20 15:22:57 +00:00
|
|
|
void CfgConsume (cfgtok_t T, const char* Msg)
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Skip a token, print an error message if not found */
|
|
|
|
{
|
|
|
|
if (CfgTok != T) {
|
2009-09-28 15:59:18 +00:00
|
|
|
CfgError ("%s", Msg);
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
CfgNextTok ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgConsumeSemi (void)
|
|
|
|
/* Consume a semicolon */
|
|
|
|
{
|
|
|
|
CfgConsume (CFGTOK_SEMI, "`;' expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgConsumeColon (void)
|
|
|
|
/* Consume a colon */
|
|
|
|
{
|
|
|
|
CfgConsume (CFGTOK_COLON, "`:' expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgOptionalComma (void)
|
|
|
|
/* Consume a comma if there is one */
|
|
|
|
{
|
|
|
|
if (CfgTok == CFGTOK_COMMA) {
|
|
|
|
CfgNextTok ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgOptionalAssign (void)
|
|
|
|
/* Consume an equal sign if there is one */
|
|
|
|
{
|
|
|
|
if (CfgTok == CFGTOK_EQ) {
|
|
|
|
CfgNextTok ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgAssureInt (void)
|
|
|
|
/* Make sure the next token is an integer */
|
|
|
|
{
|
|
|
|
if (CfgTok != CFGTOK_INTCON) {
|
|
|
|
CfgError ("Integer constant expected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgAssureStr (void)
|
|
|
|
/* Make sure the next token is a string constant */
|
|
|
|
{
|
|
|
|
if (CfgTok != CFGTOK_STRCON) {
|
|
|
|
CfgError ("String constant expected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgAssureIdent (void)
|
|
|
|
/* Make sure the next token is an identifier */
|
|
|
|
{
|
|
|
|
if (CfgTok != CFGTOK_IDENT) {
|
|
|
|
CfgError ("Identifier expected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgRangeCheck (unsigned long Lo, unsigned long Hi)
|
|
|
|
/* Check the range of CfgIVal */
|
|
|
|
{
|
|
|
|
if (CfgIVal < Lo || CfgIVal > Hi) {
|
|
|
|
CfgError ("Range error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name)
|
|
|
|
/* Map an identifier to one of the special tokens in the table */
|
|
|
|
{
|
|
|
|
unsigned I;
|
|
|
|
|
|
|
|
/* We need an identifier */
|
|
|
|
if (CfgTok == CFGTOK_IDENT) {
|
|
|
|
|
|
|
|
/* Make it upper case */
|
2010-03-20 17:23:51 +00:00
|
|
|
SB_ToUpper (&CfgSVal);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Linear search */
|
|
|
|
for (I = 0; I < Size; ++I) {
|
2010-03-20 17:23:51 +00:00
|
|
|
if (SB_CompareStr (&CfgSVal, Table[I].Ident) == 0) {
|
|
|
|
CfgTok = Table[I].Tok;
|
2000-05-28 13:40:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not found or no identifier */
|
2005-01-08 21:38:17 +00:00
|
|
|
CfgError ("%s expected", Name);
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgBoolToken (void)
|
|
|
|
/* Map an identifier or integer to a boolean token */
|
|
|
|
{
|
|
|
|
static const IdentTok Booleans [] = {
|
|
|
|
{ "YES", CFGTOK_TRUE },
|
|
|
|
{ "NO", CFGTOK_FALSE },
|
|
|
|
{ "TRUE", CFGTOK_TRUE },
|
|
|
|
{ "FALSE", CFGTOK_FALSE },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* If we have an identifier, map it to a boolean token */
|
|
|
|
if (CfgTok == CFGTOK_IDENT) {
|
|
|
|
CfgSpecialToken (Booleans, ENTRY_COUNT (Booleans), "Boolean");
|
|
|
|
} else {
|
|
|
|
/* We expected an integer here */
|
|
|
|
if (CfgTok != CFGTOK_INTCON) {
|
|
|
|
CfgError ("Boolean value expected");
|
|
|
|
}
|
|
|
|
CfgTok = (CfgIVal == 0)? CFGTOK_FALSE : CFGTOK_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgSetName (const char* Name)
|
|
|
|
/* Set a name for a config file */
|
|
|
|
{
|
|
|
|
CfgName = Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char* CfgGetName (void)
|
|
|
|
/* Get the name of the config file */
|
|
|
|
{
|
2001-10-25 18:51:49 +00:00
|
|
|
if (CfgName) {
|
|
|
|
return CfgName;
|
|
|
|
} else if (CfgBuf) {
|
|
|
|
return "[builtin config]";
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgSetBuf (const char* Buf)
|
|
|
|
/* Set a memory buffer for the config */
|
|
|
|
{
|
|
|
|
CfgBuf = Buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int CfgAvail (void)
|
|
|
|
/* Return true if we have a configuration available */
|
|
|
|
{
|
|
|
|
return CfgName != 0 || CfgBuf != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgOpenInput (void)
|
|
|
|
/* Open the input file if we have one */
|
|
|
|
{
|
|
|
|
/* If we have a config name given, open the file, otherwise we will read
|
|
|
|
* from a buffer.
|
|
|
|
*/
|
|
|
|
if (!CfgBuf) {
|
|
|
|
|
|
|
|
/* Open the file */
|
|
|
|
InputFile = fopen (CfgName, "r");
|
|
|
|
if (InputFile == 0) {
|
|
|
|
Error ("Cannot open `%s': %s", CfgName, strerror (errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize variables */
|
|
|
|
C = ' ';
|
2002-04-20 11:49:53 +00:00
|
|
|
InputLine = 1;
|
2000-05-28 13:40:48 +00:00
|
|
|
InputCol = 0;
|
|
|
|
|
|
|
|
/* Start the ball rolling ... */
|
|
|
|
CfgNextTok ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CfgCloseInput (void)
|
|
|
|
/* Close the input file if we have one */
|
|
|
|
{
|
|
|
|
/* Close the input file if we had one */
|
|
|
|
if (InputFile) {
|
|
|
|
(void) fclose (InputFile);
|
|
|
|
InputFile = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-10-25 18:51:49 +00:00
|
|
|
|