Skip to content

Commit

Permalink
Ignore line comments in #define definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
totalspectrum committed Apr 20, 2024
1 parent 11a6e18 commit 29e3dae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Version 6.9.3
- Fixed typo in datetime
- Ignore ' style comments in #define definitions

Version 6.9.2
- Fixed $ relative ORGF (thanks, Ada)
Expand Down
17 changes: 13 additions & 4 deletions preprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ static char *parse_getword(ParseState *P)
return word;
}

static char *parse_restofline(ParseState *P)
static char *parse_restofline(struct preprocess *pp, ParseState *P)
{
char *ptr;
char *ret;
Expand All @@ -639,6 +639,15 @@ static char *parse_restofline(ParseState *P)
} else {
P->save = NULL;
}

// ignore line comments
if (pp->linecomment) {
size_t len = strlen(pp->linecomment);
ptr = ret;
while (*ptr && 0 != strncmp(ptr, pp->linecomment, len))
ptr++;
*ptr = 0;
}
P->str = ret;
return P->str;
}
Expand Down Expand Up @@ -871,7 +880,7 @@ handle_error(struct preprocess *pp, ParseState *P)
if (!pp_active(pp)) {
return;
}
msg = parse_restofline(P);
msg = parse_restofline(pp, P);
doerror(pp, "#error: %s", msg);
}

Expand All @@ -882,7 +891,7 @@ handle_warn(struct preprocess *pp, ParseState *P)
if (!pp_active(pp)) {
return;
}
msg = parse_restofline(P);
msg = parse_restofline(pp, P);
dowarning(pp, "#warn: %s", msg);
}

Expand Down Expand Up @@ -910,7 +919,7 @@ handle_define(struct preprocess *pp, ParseState *P, int isDef)

if (isDef) {
parse_skipspaces(P);
def = parse_restofline(P);
def = parse_restofline(pp, P);
flexbuf_init(&newdef, 80);
do_expand(pp, &newdef, def, 0);
def = flexbuf_get(&newdef);
Expand Down

0 comments on commit 29e3dae

Please sign in to comment.