#include <errno.h>
#include <ctype.h>
+/* common */
+#include "chartype.h"
+#include "xsprintf.h"
+
+/* ld65 */
#include "global.h"
#include "error.h"
#include "scanner.h"
/* Current token and attributes */
-unsigned CfgTok;
+cfgtok_t CfgTok;
char CfgSVal [CFG_MAX_IDENT_LEN+1];
unsigned long CfgIVal;
static const char* CfgBuf = 0;
/* Other input stuff */
-static int C = ' ';
+static int C = ' ';
static unsigned InputLine = 1;
static unsigned InputCol = 0;
static FILE* InputFile = 0;
/*****************************************************************************/
-/* Error handling */
+/* Error handling */
/*****************************************************************************/
{
char Buf [512];
va_list ap;
+
va_start (ap, Format);
-#ifdef __WATCOMC__
- _vbprintf (Buf, sizeof (Buf), Format, ap);
-#else
- vsnprintf (Buf, sizeof (Buf), Format, ap);
-#endif
- Warning ("%s(%u): %s", CfgName, CfgErrorLine, Buf);
+ xvsprintf (Buf, sizeof (Buf), Format, ap);
+ va_end (ap);
+
+ Warning ("%s(%u): %s", CfgGetName(), CfgErrorLine, Buf);
}
{
char Buf [512];
va_list ap;
+
va_start (ap, Format);
-#ifdef __WATCOMC__
- _vbprintf (Buf, sizeof (Buf), Format, ap);
-#else
- vsnprintf (Buf, sizeof (Buf), Format, ap);
-#endif
- Error ("%s(%u): %s", CfgName, CfgErrorLine, Buf);
+ xvsprintf (Buf, sizeof (Buf), Format, ap);
+ va_end (ap);
+
+ Error ("%s(%u): %s", CfgGetName(), CfgErrorLine, Buf);
}
/* Read from buffer */
C = (unsigned char)(*CfgBuf);
if (C == 0) {
- C = EOF;
+ C = EOF;
} else {
++CfgBuf;
}
CfgErrorCol = InputCol;
/* Identifier? */
- if (C == '_' || isalpha (C)) {
+ if (C == '_' || IsAlpha (C)) {
/* Read the identifier */
I = 0;
- while (C == '_' || isalnum (C)) {
+ while (C == '_' || IsAlNum (C)) {
if (I < CFG_MAX_IDENT_LEN) {
CfgSVal [I++] = C;
}
case ':':
NextChar ();
CfgTok = CFGTOK_COLON;
- break;
+ break;
case '\"':
NextChar ();
CfgSVal [0] = '\0';
}
CfgTok = CFGTOK_STRCON;
- break;
+ break;
case 'S':
NextChar ();
-void CfgConsume (unsigned T, const char* Msg)
+void CfgConsume (cfgtok_t T, const char* Msg)
/* Skip a token, print an error message if not found */
{
if (CfgTok != T) {
/* Linear search */
for (I = 0; I < Size; ++I) {
- if (strcmp (CfgSVal, Table [I].Ident) == 0) {
+ if (strcmp (CfgSVal, Table [I].Ident) == 0) {
CfgTok = Table [I].Tok;
return;
}
const char* CfgGetName (void)
/* Get the name of the config file */
{
- return CfgName? CfgName : "";
+ if (CfgName) {
+ return CfgName;
+ } else if (CfgBuf) {
+ return "[builtin config]";
+ } else {
+ return "";
+ }
}
+