Apply a custom mapping for characters. The command is followed by two
- numbers. The first one is the index of the source character (range 1..255),
+ numbers. The first one is the index of the source character (range 0..255);
the second one is the mapping (range 0..255). The mapping applies to all
- character and string constants when they generate output, and overrides a
- mapping table specified with the
+ character and string constants [
command line switch.
Example:
-
]
- .charmap $41, $61 ; Map 'A' to 'a'
+ .charmap $41, $61 ; Map 'A' to 'a'
diff --git a/doc/cc65.sgml b/doc/cc65.sgml
index 8346bac6b..3e59d4cf0 100644
--- a/doc/cc65.sgml
+++ b/doc/cc65.sgml
@@ -4,7 +4,7 @@
cc65 Users Guide
,
-2016-04-22
+2016-06-11
cc65 is a C compiler for 6502 targets. It supports several 6502 based home
@@ -478,15 +478,15 @@ Here is a description of all the command line options:
- -W name[,name]
+ -W name[,name,...]
This option allows to control warnings generated by the compiler. It is
- followed by a comma separated list of warnings that should be enabled or
+ followed by a comma-separated list of warnings that should be enabled or
disabled. To disable a warning, its name is prefixed by a minus sign. If
no such prefix exists, or the name is prefixed by a plus sign, the warning
is enabled.
- The following warning names are currently recognized:
+ The following warning names currently are recognized:
Warn if the result of a comparison is constant.
@@ -494,10 +494,13 @@ Here is a description of all the command line options:
Treat all warnings as errors.
Warn about statements that don't have an effect.
+
+ Warn about a /
+ that changes a character's code number from/to 0x00.
Warn when passing structs by value.
- Warn about known #pragmas.
+ Warn about #pragmas that aren't recognized by cc65.
Warn about unused labels.
@@ -506,11 +509,11 @@ Here is a description of all the command line options:
Warn about unused variables.
- The full list of available warning names may be retrieved by using the
+ The full list of available warning names can be retrieved by using the
option .
- You may also use to
- control this setting for smaller pieces of code from within your code.
+ You may use also to
+ control this setting, for smaller pieces of code, from within your sources.
@@ -931,34 +934,38 @@ parameter with the #pragma charmap (<index>, <code>)
Each literal string and each literal character in the source is translated
- by use of a translation table. This translation table is preset when the
- compiler is started depending on the target system, for example to map
- ISO-8859-1 characters into PETSCII if the target is a commodore machine.
+ by use of a translation table. That translation table is preset when the
+ compiler is started, depending on the target system; for example, to map
+ ISO-8859-1 characters into PETSCII if the target is a Commodore machine.
This pragma allows to change entries in the translation table, so the
translation for individual characters, or even the complete table may be
- adjusted.
+ adjusted. Both arguments are assumed to be unsigned characters with a valid
+ range of 0-255.
- Both arguments are assumed to be unsigned characters with a valid range of
- 1-255.
-
- Beware of two pitfalls:
-
-
- - The character index is actually the code of the character in the
- C source, so character mappings do always depend on the source
- character set. This means that
While it is possible to use character literals as indices, the
- result may be somewhat unexpected, since character literals are
- itself translated. For this reason I would suggest to avoid
- character literals and use numeric character codes instead.
-
+ Beware of some pitfalls:
+
+ - The character index is actually the code of the character in the
+ C source; so, character mappings do always depend on the source
+ character set. That means that
While it is possible to use character literals as indices, the
+ result may be somewhat unexpected, since character literals are
+ themselves translated. For that reason, I would suggest to avoid
+ character literals, and use numeric character codes instead.
+ - It is risky to change index
/).
+
Example:
- /* Use a space wherever an 'a' occurs in ISO-8859-1 source */
- #pragma charmap (0x61, 0x20);
+ /* Use a space wherever an 'a' occurs in ISO-8859-1 source */
+ #pragma charmap (0x61, 0x20);
@@ -1129,7 +1136,7 @@ parameter with the / compiler option for a list). The name is
- either followed by "pop", which restores the last pushed state, or by "on" or
+ followed either by "pop", which restores the last pushed state, or by "on" or
"off", optionally preceeded by "push" to push the current state before
changing it.
@@ -1144,6 +1151,7 @@ parameter with the
+
#pragma writable-strings ([push,] on|off)
Changes the storage location of string literals. For historical reasons,
diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c
index 4db780318..250ceecc9 100644
--- a/src/ca65/pseudo.c
+++ b/src/ca65/pseudo.c
@@ -618,16 +618,16 @@ static void DoCase (void)
static void DoCharMap (void)
-/* Allow custome character mappings */
+/* Allow custom character mappings */
{
long Index;
long Code;
/* Read the index as numerical value */
Index = ConstExpression ();
- if (Index <= 0 || Index > 255) {
+ if (Index < 0 || Index > 255) {
/* Value out of range */
- ErrorSkip ("Range error");
+ ErrorSkip ("Index range error");
return;
}
@@ -638,7 +638,7 @@ static void DoCharMap (void)
Code = ConstExpression ();
if (Code < 0 || Code > 255) {
/* Value out of range */
- ErrorSkip ("Range error");
+ ErrorSkip ("Code range error");
return;
}
diff --git a/src/cc65/error.c b/src/cc65/error.c
index 5218d195c..858a80826 100644
--- a/src/cc65/error.c
+++ b/src/cc65/error.c
@@ -66,11 +66,12 @@ IntStack WarningsAreErrors = INTSTACK(0); /* Treat warnings as errors */
/* Warn about: */
IntStack WarnConstComparison= INTSTACK(1); /* - constant comparison results */
IntStack WarnNoEffect = INTSTACK(1); /* - statements without an effect */
+IntStack WarnRemapZero = INTSTACK(1); /* - remapping character code zero */
IntStack WarnStructParam = INTSTACK(1); /* - structs passed by val */
+IntStack WarnUnknownPragma = INTSTACK(1); /* - unknown #pragmas */
IntStack WarnUnusedLabel = INTSTACK(1); /* - unused labels */
IntStack WarnUnusedParam = INTSTACK(1); /* - unused parameters */
IntStack WarnUnusedVar = INTSTACK(1); /* - unused variables */
-IntStack WarnUnknownPragma = INTSTACK(1); /* - unknown #pragmas */
/* Map the name of a warning to the intstack that holds its state */
typedef struct WarnMapEntry WarnMapEntry;
@@ -79,10 +80,11 @@ struct WarnMapEntry {
const char* Name;
};
static WarnMapEntry WarnMap[] = {
- /* Keep sorted, even if this isn't used for now */
- { &WarningsAreErrors, "error" },
+ /* Keep names sorted, even if it isn't used for now */
{ &WarnConstComparison, "const-comparison" },
+ { &WarningsAreErrors, "error" },
{ &WarnNoEffect, "no-effect" },
+ { &WarnRemapZero, "remap-zero" },
{ &WarnStructParam, "struct-param" },
{ &WarnUnknownPragma, "unknown-pragma" },
{ &WarnUnusedLabel, "unused-label" },
diff --git a/src/cc65/error.h b/src/cc65/error.h
index 9aec10c77..97ee09591 100644
--- a/src/cc65/error.h
+++ b/src/cc65/error.h
@@ -65,11 +65,12 @@ extern IntStack WarningsAreErrors; /* Treat warnings as errors */
/* Warn about: */
extern IntStack WarnConstComparison; /* - constant comparison results */
extern IntStack WarnNoEffect; /* - statements without an effect */
+extern IntStack WarnRemapZero; /* - remapping character code zero */
extern IntStack WarnStructParam; /* - structs passed by val */
+extern IntStack WarnUnknownPragma; /* - unknown #pragmas */
extern IntStack WarnUnusedLabel; /* - unused labels */
extern IntStack WarnUnusedParam; /* - unused parameters */
extern IntStack WarnUnusedVar; /* - unused variables */
-extern IntStack WarnUnknownPragma; /* - unknown #pragmas */
diff --git a/src/cc65/pragma.c b/src/cc65/pragma.c
index f42274922..52af1e722 100644
--- a/src/cc65/pragma.c
+++ b/src/cc65/pragma.c
@@ -453,13 +453,14 @@ static void CharMapPragma (StrBuf* B)
return;
}
if (Index < 1 || Index > 255) {
- if (Index == 0) {
- /* For groepaz */
- Error ("Remapping 0 is not allowed");
- } else {
+ if (Index != 0) {
Error ("Character index out of range");
+ return;
+ }
+ /* For groepaz and Christian */
+ if (IS_Get (&WarnRemapZero)) {
+ Warning ("Remapping from 0 is dangerous with string functions");
}
- return;
}
/* Comma follows */
@@ -472,13 +473,14 @@ static void CharMapPragma (StrBuf* B)
return;
}
if (C < 1 || C > 255) {
- if (C == 0) {
- /* For groepaz */
- Error ("Remapping 0 is not allowed");
- } else {
+ if (C != 0) {
Error ("Character code out of range");
+ return;
+ }
+ /* For groepaz and Christian */
+ if (IS_Get (&WarnRemapZero)) {
+ Warning ("Remapping to 0 can make string functions stop unexpectedly");
}
- return;
}
/* Remap the character */
diff --git a/src/cc65/pragma.h b/src/cc65/pragma.h
index f12dbaa83..d1b94fa23 100644
--- a/src/cc65/pragma.h
+++ b/src/cc65/pragma.h
@@ -6,10 +6,10 @@
/* */
/* */
/* */
-/* (C) 1998-2002 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2002, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
diff --git a/src/common/tgttrans.c b/src/common/tgttrans.c
index 95bdf8662..bd2056505 100644
--- a/src/common/tgttrans.c
+++ b/src/common/tgttrans.c
@@ -124,6 +124,6 @@ void TgtTranslateStrBuf (StrBuf* Buf)
void TgtTranslateSet (unsigned Index, unsigned char C)
/* Set the translation code for the given character */
{
- CHECK (Index > 0 && Index < sizeof (Tab));
+ CHECK (Index < sizeof (Tab));
Tab[Index] = C;
}