aboutsummaryrefslogtreecommitdiff
path: root/listamsb.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-02-26 16:42:04 -0500
committerB. Watson <urchlay@slackware.uk>2025-02-26 16:42:04 -0500
commit59406751d8bc07a64b944830560d1d709c105fd3 (patch)
treedb222c9a14e7195445afcd500cd5a157617344dd /listamsb.c
parentcac9e4b320c22a01f043b6b6281c8e13dc0b1ed5 (diff)
downloadbw-atari8-tools-59406751d8bc07a64b944830560d1d709c105fd3.tar.gz
listamsb: complain about lines >128 bytes long.
Diffstat (limited to 'listamsb.c')
-rw-r--r--listamsb.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/listamsb.c b/listamsb.c
index 01c6881..efcaf00 100644
--- a/listamsb.c
+++ b/listamsb.c
@@ -18,6 +18,10 @@
#define MIN_EXT_TOK 0xa3 /* SGN */
#define MAX_EXT_TOK 0xc5 /* STACK */
+/* AMSB's tokens for "!" and "'", used to introduce comments */
+#define TOK_SQUOTE 0x9a
+#define TOK_BANG 0x9b
+
/* good old Atari EOL character */
#define EOL 0x9b
@@ -29,6 +33,12 @@
even with cart-based AMSB2 and no DOS loaded. */
#define MAX_PROGLEN 30000
+/* there should never be a valid line of BASIC longer than this many
+ bytes, since there would be no way to enter it in the editor. AMSB
+ uses the standard E: device, which limits you to 4 screen lines, or
+ max 120 bytes. */
+#define MAX_LINE_LEN 0x80
+
/* a program whose header has a length less than MIN_PROGLEN can't be
a real AMSB program. EMPTY_PROGLEN is what you get if you
SAVE when there's no program in memory (right after boot or
@@ -220,7 +230,7 @@ int next_line(void) {
} else if(byte == ':') {
/* don't print the colon if the next token is a ! or ' for a comment */
unsigned char next = read_byte();
- if( !(next == 0x9a || next == 0x9b) )
+ if( !(next == TOK_SQUOTE || next == TOK_BANG) )
if(printing) putc(byte, outfile);
ungetc(next, infile);
bytes_read--;
@@ -230,7 +240,7 @@ int next_line(void) {
if(printing) putc(byte, outfile);
} else if(was_ff) {
if(byte >= MIN_EXT_TOK && byte <= MAX_EXT_TOK) {
- if(printing) fprintf(outfile, "%s", ext_tokens[byte - MIN_EXT_TOK]);
+ if(printing) fputs(ext_tokens[byte - MIN_EXT_TOK], outfile);
} else {
if(printing) unknown_token(lineno, byte, 1);
warnings++;
@@ -239,7 +249,7 @@ int next_line(void) {
} else if(byte == 0xff) {
was_ff = 1;
} else if(byte >= MIN_STD_TOK && byte <= MAX_STD_TOK) {
- if(printing) fprintf(outfile, "%s", std_tokens[byte - MIN_STD_TOK]);
+ if(printing) fputs(std_tokens[byte - MIN_STD_TOK], outfile);
} else if(byte >= 0x80) {
if(printing) unknown_token(lineno, byte, 0);
warnings++;
@@ -262,6 +272,12 @@ int next_line(void) {
fprintf(stderr, " line %d length: %d\n", lineno, len);
}
+ if(len > MAX_LINE_LEN) {
+ fprintf(stderr, "%s: line %d is suspiciously long (length %d > %d)\n",
+ self, lineno, len, MAX_LINE_LEN);
+ warnings++;
+ }
+
if(last_ptr != -1) {
int plen = ptr - last_ptr;
if(len != plen) {