options.o \
pseudo.o \
scanner.o \
- strexpr.o \
symtab.o \
toklist.o \
ulabel.o
options.obj \
pseudo.obj \
scanner.obj \
- strexpr.obj \
symtab.obj \
toklist.obj \
ulabel.obj
FILE options.obj
FILE pseudo.obj
FILE scanner.obj
-FILE strexpr.obj
FILE symtab.obj
FILE toklist.obj
FILE ulabel.obj
+#include <stdio.h>
+
#include "error.h"
#include "expr.h"
#include "scanner.h"
+static void FuncConcat (void)
+/* Handle the .CONCAT function */
+{
+ char Buf[MAX_STR_LEN+1];
+ char* B;
+ unsigned Length;
+ unsigned L;
+
+ /* Skip it */
+ NextTok ();
+
+ /* Left paren expected */
+ ConsumeLParen ();
+
+ /* Concatenate any number of strings */
+ B = Buf;
+ B[0] = '\0';
+ Length = 0;
+ while (1) {
+
+ /* Next token must be a string */
+ if (Tok != TOK_STRCON) {
+ Error (ERR_STRCON_EXPECTED);
+ SkipUntilSep ();
+ return;
+ }
+
+ /* Get the length of the string const and check total length */
+ L = strlen (SVal);
+ if (Length + L > MAX_STR_LEN) {
+ Error (ERR_STRING_TOO_LONG);
+ /* Try to recover */
+ SkipUntilSep ();
+ return;
+ }
+
+ /* Add the new string */
+ memcpy (B, SVal, L);
+ Length += L;
+ B += L;
+
+ /* Skip the string token */
+ NextTok ();
+
+ /* Comma means another argument */
+ if (Tok == TOK_COMMA) {
+ NextTok ();
+ } else {
+ /* Done */
+ break;
+ }
+ }
+
+ /* Terminate the string */
+ *B = '\0';
+
+ /* We expect a closing parenthesis, but will not skip it but replace it
+ * by the string token just created.
+ */
+ if (Tok != TOK_RPAREN) {
+ Error (ERR_RPAREN_EXPECTED);
+ } else {
+ Tok = TOK_STRCON;
+ strcpy (SVal, Buf);
+ }
+}
+
+
+
static void FuncMid (void)
/* Handle the .MID function */
{
- long Start;
+ long Start;
long Count;
TokList* List;
NextTok ();
/* Left paren expected */
- ConsumeRParen ();
+ ConsumeLParen ();
/* Start argument */
Start = ConstExpression ();
if (Start < 0 || Start > 100) {
Error (ERR_RANGE);
- Start = 0;
+ Start = 0;
}
ConsumeComma ();
+static void FuncString (void)
+/* Handle the .STRING function */
+{
+ char Buf[MAX_STR_LEN+1];
+
+ /* Skip it */
+ NextTok ();
+
+ /* Left paren expected */
+ ConsumeLParen ();
+
+ /* Accept identifiers or numeric expressions */
+ if (Tok == TOK_IDENT) {
+ /* Save the identifier, then skip it */
+ strcpy (Buf, SVal);
+ NextTok ();
+ } else {
+ /* Numeric expression */
+ long Val = ConstExpression ();
+ sprintf (Buf, "%ld", Val);
+ }
+
+ /* We expect a closing parenthesis, but will not skip it but replace it
+ * by the string token just created.
+ */
+ if (Tok != TOK_RPAREN) {
+ Error (ERR_RPAREN_EXPECTED);
+ } else {
+ Tok = TOK_STRCON;
+ strcpy (SVal, Buf);
+ }
+}
+
+
+
void NextTok (void)
/* Get next token and handle token level functions */
{
/* Check for token handling functions */
switch (Tok) {
+ case TOK_CONCAT:
+ FuncConcat ();
+ break;
+
case TOK_MID:
FuncMid ();
break;
+ case TOK_STRING:
+ FuncString ();
+ break;
+
default:
/* Quiet down gcc */
break;
#include "nexttok.h"
#include "objcode.h"
#include "options.h"
-#include "strexpr.h"
#include "symtab.h"
#include "pseudo.h"
/* Define text with a zero terminator */
{
while (1) {
- if (StringExpression () == 0) {
+ if (Tok != TOK_STRCON) {
ErrorSkip (ERR_STRCON_EXPECTED);
return;
}
/* Define bytes */
{
while (1) {
- if (StringExpression () != 0) {
+ if (Tok == TOK_STRCON) {
/* A string */
EmitData (SVal, strlen (SVal));
NextTok ();
static void DoError (void)
/* Use error */
{
- if (StringExpression () == 0) {
+ if (Tok == TOK_STRCON) {
ErrorSkip (ERR_STRCON_EXPECTED);
} else {
Error (ERR_USER, SVal);
ConsumeComma ();
/* We accept only string options for now */
- if (StringExpression () == 0) {
+ if (Tok != TOK_STRCON) {
ErrorSkip (ERR_STRCON_EXPECTED);
return;
}
ConsumeComma ();
/* We accept only string options for now */
- if (StringExpression () == 0) {
+ if (Tok != TOK_STRCON) {
ErrorSkip (ERR_STRCON_EXPECTED);
return;
}
/* Include a binary file */
{
/* Name must follow */
- if (StringExpression () == 0) {
+ if (Tok != TOK_STRCON) {
ErrorSkip (ERR_STRCON_EXPECTED);
} else {
/* Try to open the file */
char Name [MAX_STR_LEN+1];
/* Name must follow */
- if (StringExpression () == 0) {
+ if (Tok != TOK_STRCON) {
ErrorSkip (ERR_STRCON_EXPECTED);
} else {
strcpy (Name, SVal);
static void DoOut (void)
/* Output a string */
{
- if (StringExpression () == 0) {
+ if (Tok != TOK_STRCON) {
ErrorSkip (ERR_STRCON_EXPECTED);
} else {
/* Output the string and be sure to flush the output to keep it in
char Name [sizeof (SVal)];
int SegType;
- if (StringExpression () == 0) {
+ if (Tok != TOK_STRCON) {
ErrorSkip (ERR_STRCON_EXPECTED);
} else {
{ ccNone, DoByte },
{ ccNone, DoCase },
{ ccNone, DoCode },
+ { ccNone, DoUnexpected, }, /* .CONCAT */
{ ccNone, DoUnexpected }, /* .CONST */
{ ccNone, DoUnexpected }, /* .CPU */
{ ccNone, DoData },
{ "BYTE", TOK_BYTE },
{ "CASE", TOK_CASE },
{ "CODE", TOK_CODE },
+ { "CONCAT", TOK_CONCAT },
{ "CONST", TOK_CONST },
{ "CPU", TOK_CPU },
{ "DATA", TOK_DATA },
TOK_BYTE,
TOK_CASE,
TOK_CODE,
+ TOK_CONCAT,
TOK_CONST,
TOK_CPU,
TOK_DATA,
+++ /dev/null
-/*****************************************************************************/
-/* */
-/* strexpr.c */
-/* */
-/* String expressions for the ca65 macroassembler */
-/* */
-/* */
-/* */
-/* (C) 2000 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
-/* */
-/* */
-/* 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 <stdio.h>
-
-#include "error.h"
-#include "expr.h"
-#include "scanner.h"
-#include "strexpr.h"
-
-
-
-/*****************************************************************************/
-/* Code */
-/*****************************************************************************/
-
-
-
-const char* StringExpression (void)
-/* Evaluate a string expression. If there are no errors, the function will
- * place the string into the token attribute buffer SVal and the token will
- * be TOK_STRCON. A pointer to the buffer is returned.
- * If there was an error, a NULL pointer is returned.
- */
-{
- char Buf [sizeof (SVal)];
-
- /* Check for a string constant or a function that returns a string */
- switch (Tok) {
-
- case TOK_STRING:
- NextTok ();
- ConsumeLParen ();
- if (Tok == TOK_IDENT) {
- /* Save the identifier, then skip it */
- strcpy (Buf, SVal);
- NextTok ();
- } else {
- /* Numeric expression */
- long Val = ConstExpression ();
- sprintf (Buf, "%ld", Val);
- }
- if (Tok != TOK_RPAREN) {
- Error (ERR_RPAREN_EXPECTED);
- }
- /* Overwrite the token, do not skip it! */
- strcpy (SVal, Buf);
- Tok = TOK_STRCON;
- break;
-
- case TOK_STRCON:
- /* We already have a string */
- break;
-
- default:
- /* Error - no string constant */
- return 0;
- }
-
- /* Return a pointer to the buffer */
- return SVal;
-}
-
-
-
+++ /dev/null
-/*****************************************************************************/
-/* */
-/* strexpr.h */
-/* */
-/* String expressions for the ca65 macroassembler */
-/* */
-/* */
-/* */
-/* (C) 2000 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
-/* */
-/* */
-/* 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. */
-/* */
-/*****************************************************************************/
-
-
-
-#ifndef STREXPR_H
-#define STREXPR_H
-
-
-
-/*****************************************************************************/
-/* Code */
-/*****************************************************************************/
-
-
-
-const char* StringExpression (void);
-/* Evaluate a string expression. If there are no errors, the function will
- * place the string into the token attribute buffer SVal and the token will
- * be TOK_STRCON. A pointer to the buffer is returned.
- * If there was an error, a NULL pointer is returned.
- */
-
-
-
-/* End of strexpr.h */
-
-#endif
-
-
-