summaryrefslogtreecommitdiff
path: root/ascii2map.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2016-09-19 09:46:34 +0000
committerIan C <ianc@noddybox.co.uk>2016-09-19 09:46:34 +0000
commit50f21014e56920997dcd0c09b8320f9762eebe8f (patch)
tree9ae58b7eef7e321584f8d7bce1ac4844e7795e69 /ascii2map.c
parent54c55e7b92581488da1433432fb58ee79e5ac3e7 (diff)
Added new string:number format to help with non-character code following
mappings.
Diffstat (limited to 'ascii2map.c')
-rw-r--r--ascii2map.c53
1 files changed, 43 insertions, 10 deletions
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;
+ }
}
}
}