Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"@{5E}" and "@{7E}" escapes are wrong in Z-code #249

Open
erkyrath opened this issue Sep 23, 2023 · 5 comments
Open

"@{5E}" and "@{7E}" escapes are wrong in Z-code #249

erkyrath opened this issue Sep 23, 2023 · 5 comments

Comments

@erkyrath
Copy link
Contributor

You're supposed to be able to escape string characters in two ways: "@@DEC" and "@{HEX}". The latter is newer and supports any Unicode value.

However, the hex form doesn't come out right for a couple of characters:

	print "@@92 is backslash, @@64 is atsign, @@94 is caret, @@126 is tilde.^";
	print "@{5C} is backslash, @{40} is atsign, @{5E} is caret, @{7E} is tilde.^";

\ is backslash, @ is atsign, ^ is caret, ~ is tilde.
\ is backslash, @ is atsign,
is caret, " is tilde.

That is, "@{5E}" is interpreted as "^" which is then interpreted as a newline. "@{7E}" similarly gets double-interpreted as a quote character.

(In Glulx both lines print the same thing, as expected.)

This bug goes back to 6.31 (at least) so it might not be desirable to fix it. Some old Z-code games might depend on this behavior, inconsistent as it is. But it's worth noting.

@heasm66
Copy link
Contributor

heasm66 commented Dec 12, 2024

In an attempt to close some old issues...

Suggestion is to add a warning that points to the syntax required for printing caret and tilde with @@-syntax. This won't break behavior if some game, against all odds, depend on this inconsistency.

chars.c

@@ -1183,6 +1183,15 @@ extern int32 text_to_unicode(char *text)
        while ((text[i] != '}') && (text[i] != 0)) i++;
        if (text[i] == '}') i++;
        textual_form_length = i;
        switch (total) {
        /* Warn that ~ and ^ is being translated to double-quote and new-line. */
        case 94:   
            warning("@{5E} will print a newline instead of a caret (^), use @@94 for a caret.");
            break;
        case 126:              
            warning("@{7E} will print a double-quote (\") instead of a tilde (~), use @@126 for tilde.");
            break;
        }
        return total;
    }


@erkyrath
Copy link
Contributor Author

The @{HEX} notation is newer and preferred in Glulx, so we should support it correctly.

@heasm66
Copy link
Contributor

heasm66 commented Dec 12, 2024

Because it already works for Glulx, maybe only warn for Z-code?

@erkyrath
Copy link
Contributor Author

How about we fix the bug instead.

@heasm66
Copy link
Contributor

heasm66 commented Dec 12, 2024

Fine by me, but you raised concerns about backward compability above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants