Skip to content

Commit 7836e37

Browse files
committed
fix first half of #2192 - output all invalid codes outside quotes as control codes
git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@45944 379a1393-f5fb-40a0-bcee-ef074d9b53f7
1 parent 83c8bd0 commit 7836e37

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

vice/src/tools/petcat/petcat.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,7 @@ static int p_expand(int version, int addr, int ctrls)
19001900

19011901
while ((fread(line, 1, 2, source) == 2) && (line[1]) && fread(line + 2, 1, 2, source) == 2) {
19021902
quote = 0;
1903+
/* the line number */
19031904
fprintf(dest, "%5d ", (spnum = (line[2] & 0xff) + ((line[3] & 0xff) << 8)));
19041905
if (checksummer) {
19051906
checksummer->init(checksummer_data, spnum);
@@ -1925,19 +1926,16 @@ static int p_expand(int version, int addr, int ctrls)
19251926
}
19261927

19271928
do {
1928-
if (checksummer)
1929+
if (checksummer) {
19291930
checksummer->process(checksummer_data, c, quote);
1931+
}
19301932

19311933
if (c == 0x22) {
19321934
quote ^= c;
19331935
}
19341936

1935-
/*
1936-
* Simons' basic. Any flag for this is not needed since it is
1937-
* mutually exclusive with all other implemented modes.
1938-
*/
1939-
1940-
if (!quote && (c == 0x64)) {
1937+
/* Simons' basic. Tokens are prefixed by $64 */
1938+
if (!quote && (c == 0x64) && (version == B_SIMON)) {
19411939
if (((c = getc(source)) < 0x80) && basic_list[version - 1].tokens) {
19421940
fprintf(dest, "%s", basic_list[version - 1].tokens[c]);
19431941
continue;
@@ -1948,7 +1946,7 @@ static int p_expand(int version, int addr, int ctrls)
19481946

19491947
/* basic 2.0, 7.0, 10.0, 65.0 and extensions */
19501948

1951-
if (!quote && c > 0x7f) {
1949+
if (!quote && (c > 0x7f)) {
19521950
/* check for keywords common to all versions, include pi */
19531951
if (c <= basic_list[B_1 - 1].max_token || c == 0xff) {
19541952
fprintf(dest, "%s", keyword[c & 0x7f]);
@@ -2037,8 +2035,13 @@ static int p_expand(int version, int addr, int ctrls)
20372035
case B_EVE:
20382036
case B_TT64:
20392037
case B_HANDY:
2040-
if (basic_list[version - 1].tokens && c >= basic_list[version - 1].token_start && c <= basic_list[version - 1].max_token) {
2038+
if ((basic_list[version - 1].tokens) &&
2039+
(c >= basic_list[version - 1].token_start) &&
2040+
(c <= basic_list[version - 1].max_token)) {
20412041
fprintf(dest, "%s", basic_list[version - 1].tokens[c - basic_list[version - 1].token_start]);
2042+
} else {
2043+
/* not a valid token */
2044+
out_ctrl((int)c); /* output byte as control code */
20422045
}
20432046
break;
20442047

@@ -2053,7 +2056,12 @@ static int p_expand(int version, int addr, int ctrls)
20532056
continue;
20542057
}
20552058

2056-
_p_toascii((int)c, version, ctrls, quote); /* convert character */
2059+
if (c == 13) {
2060+
/* return outside quotes, this can only be a control code */
2061+
out_ctrl((int)c); /* output as control code */
2062+
} else {
2063+
_p_toascii((int)c, version, ctrls, quote); /* convert character */
2064+
}
20572065
} while ((c = getc(source)) != EOF && c);
20582066
if (checksummer) {
20592067
char *chksum = checksummer->finalize(checksummer_data);

0 commit comments

Comments
 (0)