]> git.sur5r.net Git - cc65/blobdiff - src/ld65/scanner.c
Added the NES target
[cc65] / src / ld65 / scanner.c
index 69db9f23f1a947d6def34e741494e71be40475b5..82a04010757c7287dd27884c9c8d0d01aeb984bc 100644 (file)
 #include <errno.h>
 #include <ctype.h>
 
+/* common */
+#include "chartype.h"
+#include "xsprintf.h"
+
+/* ld65 */
 #include "global.h"
 #include "error.h"
 #include "scanner.h"
@@ -52,7 +57,7 @@
 
 
 /* Current token and attributes */
-unsigned        CfgTok;
+cfgtok_t       CfgTok;
 char                   CfgSVal [CFG_MAX_IDENT_LEN+1];
 unsigned long   CfgIVal;
 
@@ -65,7 +70,7 @@ static const char*            CfgName         = 0;
 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;
@@ -73,7 +78,7 @@ static FILE*                  InputFile       = 0;
 
 
 /*****************************************************************************/
-/*                             Error handling                               */
+/*                             Error handling                               */
 /*****************************************************************************/
 
 
@@ -83,13 +88,12 @@ void CfgWarning (const char* Format, ...)
 {
     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);
 }
 
 
@@ -99,13 +103,12 @@ void CfgError (const char* Format, ...)
 {
     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);
 }
 
 
@@ -123,7 +126,7 @@ static void NextChar (void)
        /* Read from buffer */
        C = (unsigned char)(*CfgBuf);
        if (C == 0) {
-           C = EOF;
+           C = EOF;
        } else {
            ++CfgBuf;
        }
@@ -175,11 +178,11 @@ Again:
     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;
            }
@@ -252,7 +255,7 @@ Again:
         case ':':
            NextChar ();
            CfgTok = CFGTOK_COLON;
-           break;
+           break;
 
         case '\"':
            NextChar ();
@@ -295,7 +298,7 @@ Again:
                        CfgSVal [0] = '\0';
                    }
                    CfgTok = CFGTOK_STRCON;
-                   break;
+                   break;
 
                case 'S':
                    NextChar ();
@@ -320,7 +323,7 @@ Again:
 
 
 
-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) {
@@ -424,7 +427,7 @@ void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name)
 
                /* 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;
            }
@@ -473,7 +476,13 @@ void CfgSetName (const char* Name)
 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 "";
+    }
 }
 
 
@@ -533,3 +542,4 @@ void CfgCloseInput (void)
 
 
 
+