From 50f21014e56920997dcd0c09b8320f9762eebe8f Mon Sep 17 00:00:00 2001 From: Ian C Date: Mon, 19 Sep 2016 09:46:34 +0000 Subject: Added new string:number format to help with non-character code following mappings. --- Makefile | 2 +- README | 15 ++++++++++----- ascii2map.c | 53 +++++++++++++++++++++++++++++++++++++++++++---------- example | 3 ++- 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 490d266..b37e046 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ascii2map: ascii2map.c - $(CC) -o ascii2map ascii2map.c + $(CC) -g -o ascii2map ascii2map.c clean: rm -f ascii2map diff --git a/README b/README index 05582aa..a53c089 100644 --- a/README +++ b/README @@ -24,11 +24,12 @@ Input files look like the following: #:1 *:128 !63 +0123456789ABCDEF:2 ~ ######## # # #ABCDEF# -#1# # *# +#0#1# *# ######## The "#:1" line defines that when a '#' character appears in the map then code @@ -40,14 +41,18 @@ character code. In ASCII this would mean 'A' becomes 2, 'B' becomes 3, and so on. Any codes generated that fall outside the range 0 to 255 will be clamped to that range. -The line with a tilde (~) on its own indicates the end of the definitions. By -default, unless redefined, space is automatically defined to be code zero. +A line with a long_string:number overrides a line starting with '!' and means +that each character in the string will be defined as the zero-based index in +the string added to the trailing number. This is useful if your tile mappings +use characters in a non-standard order. + +The line with a tilde (~) on its own indicates the end of the definitions. Following it is the map to produce the definition for, eg. $ ascii2map example byte 1, 1, 1, 1, 1, 1, 1, 1 byte 1, 0, 0, 0, 0, 0, 0, 1 - byte 1, 2, 3, 4, 5, 6, 7, 1 - byte 1, 0, 1, 0, 1, 0, 128, 1 + byte 1, 12, 13, 14, 15, 16, 17, 1 + byte 1, 2, 1, 3, 1, 0, 128, 1 byte 1, 1, 1, 1, 1, 1, 1, 1 diff --git a/ascii2map.c b/ascii2map.c index ce6347e..2f6cd97 100644 --- a/ascii2map.c +++ b/ascii2map.c @@ -55,6 +55,7 @@ typedef enum /* ---------------------------------------- GLOBALS */ static int code_point = 'A'; +static char code_string[256] = {0}; static uchar point[256]; static uchar used[256]; static const char *directive = "byte"; @@ -107,7 +108,23 @@ static void EndOutput(FILE *fp) static unsigned CodePoint(char c) { - int offset = c - code_point; + int offset; + + if (code_string[0]) + { + char *p = strchr(code_string, c); + + if (p) + { + c = p - code_string; + } + + offset = c + code_point; + } + else + { + offset = c - code_point; + } if (offset < 0) { @@ -354,19 +371,35 @@ int main(int argc, char *argv[]) { code_point = atoi(line + 1); } - - if (line[0] && line[1] == ':' && line[2]) + else { - char c; - int i; + if (line[0] && line[1] && line[1] != ':') + { + char *p = strrchr(line, ':'); - c = line[0]; - i = atoi(line + 2); + if (p) + { + *p++ = 0; + code_point = atoi(p); - if (c >= 0 && c <= 255) + strncpy(code_string, line, sizeof code_string); + code_string[(sizeof code_string) - 1] = 0; + } + } + + if (line[0] && line[1] == ':' && line[2]) { - point[c] = i; - used[c] = 1; + char c; + int i; + + c = line[0]; + i = atoi(line + 2); + + if (c >= 0 && c <= 255) + { + point[c] = i; + used[c] = 1; + } } } } diff --git a/example b/example index 329c0b6..beefdbd 100644 --- a/example +++ b/example @@ -1,9 +1,10 @@ #:1 *:128 !63 +0123456789ABCDEF:2 ~ ######## # # #ABCDEF# -#1# # *# +#0#1# *# ######## -- cgit v1.2.3