Added string handling functions: .STRLEN and .STRAT
git-svn-id: svn://svn.cc65.org/cc65/trunk@199 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -467,6 +467,71 @@ static int FuncReferenced (void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int FuncStrAt (void)
|
||||||
|
/* Handle the .STRAT function */
|
||||||
|
{
|
||||||
|
char Str [sizeof(SVal)];
|
||||||
|
long Index;
|
||||||
|
|
||||||
|
/* String constant expected */
|
||||||
|
if (Tok != TOK_STRCON) {
|
||||||
|
Error (ERR_STRCON_EXPECTED);
|
||||||
|
NextTok ();
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remember the string and skip it */
|
||||||
|
strcpy (Str, SVal);
|
||||||
|
NextTok ();
|
||||||
|
|
||||||
|
/* Comma must follow */
|
||||||
|
ConsumeComma ();
|
||||||
|
|
||||||
|
/* Expression expected */
|
||||||
|
Index = ConstExpression ();
|
||||||
|
|
||||||
|
/* Must be a valid index */
|
||||||
|
if (Index >= strlen (Str)) {
|
||||||
|
Error (ERR_RANGE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the char, handle as unsigned */
|
||||||
|
return (unsigned char) Str[(size_t)Index];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int FuncStrLen (void)
|
||||||
|
/* Handle the .STRLEN function */
|
||||||
|
{
|
||||||
|
/* String constant expected */
|
||||||
|
if (Tok != TOK_STRCON) {
|
||||||
|
|
||||||
|
Error (ERR_STRCON_EXPECTED);
|
||||||
|
/* Smart error recovery */
|
||||||
|
if (Tok != TOK_RPAREN) {
|
||||||
|
NextTok ();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/* Get the length of the string */
|
||||||
|
int Len = strlen (SVal);
|
||||||
|
|
||||||
|
/* Skip the string */
|
||||||
|
NextTok ();
|
||||||
|
|
||||||
|
/* Return the length */
|
||||||
|
return Len;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int FuncTCount (void)
|
static int FuncTCount (void)
|
||||||
/* Handle the .TCOUNT function */
|
/* Handle the .TCOUNT function */
|
||||||
{
|
{
|
||||||
@@ -658,6 +723,14 @@ static ExprNode* Factor (void)
|
|||||||
N = Function (FuncReferenced);
|
N = Function (FuncReferenced);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TOK_STRAT:
|
||||||
|
N = Function (FuncStrAt);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TOK_STRLEN:
|
||||||
|
N = Function (FuncStrLen);
|
||||||
|
break;
|
||||||
|
|
||||||
case TOK_TCOUNT:
|
case TOK_TCOUNT:
|
||||||
N = Function (FuncTCount);
|
N = Function (FuncTCount);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1162,7 +1162,9 @@ static CtrlDesc CtrlCmdTab [] = {
|
|||||||
{ ccNone, DoROData },
|
{ ccNone, DoROData },
|
||||||
{ ccNone, DoSegment },
|
{ ccNone, DoSegment },
|
||||||
{ ccNone, DoSmart },
|
{ ccNone, DoSmart },
|
||||||
|
{ ccNone, DoUnexpected }, /* .STRAT */
|
||||||
{ ccNone, DoUnexpected }, /* .STRING */
|
{ ccNone, DoUnexpected }, /* .STRING */
|
||||||
|
{ ccNone, DoUnexpected }, /* .STRLEN */
|
||||||
{ ccNone, DoSunPlus },
|
{ ccNone, DoSunPlus },
|
||||||
{ ccNone, DoUnexpected }, /* .TCOUNT */
|
{ ccNone, DoUnexpected }, /* .TCOUNT */
|
||||||
{ ccNone, DoWord },
|
{ ccNone, DoWord },
|
||||||
|
|||||||
@@ -219,7 +219,9 @@ struct DotKeyword {
|
|||||||
{ "SHL", TOK_SHL },
|
{ "SHL", TOK_SHL },
|
||||||
{ "SHR", TOK_SHR },
|
{ "SHR", TOK_SHR },
|
||||||
{ "SMART", TOK_SMART },
|
{ "SMART", TOK_SMART },
|
||||||
|
{ "STRAT", TOK_STRAT },
|
||||||
{ "STRING", TOK_STRING },
|
{ "STRING", TOK_STRING },
|
||||||
|
{ "STRLEN", TOK_STRLEN },
|
||||||
{ "SUNPLUS", TOK_SUNPLUS },
|
{ "SUNPLUS", TOK_SUNPLUS },
|
||||||
{ "TCOUNT", TOK_TCOUNT },
|
{ "TCOUNT", TOK_TCOUNT },
|
||||||
{ "WORD", TOK_WORD },
|
{ "WORD", TOK_WORD },
|
||||||
|
|||||||
@@ -188,7 +188,9 @@ enum Token {
|
|||||||
TOK_RODATA,
|
TOK_RODATA,
|
||||||
TOK_SEGMENT,
|
TOK_SEGMENT,
|
||||||
TOK_SMART,
|
TOK_SMART,
|
||||||
|
TOK_STRAT,
|
||||||
TOK_STRING,
|
TOK_STRING,
|
||||||
|
TOK_STRLEN,
|
||||||
TOK_SUNPLUS,
|
TOK_SUNPLUS,
|
||||||
TOK_TCOUNT,
|
TOK_TCOUNT,
|
||||||
TOK_WORD,
|
TOK_WORD,
|
||||||
|
|||||||
Reference in New Issue
Block a user