summaryrefslogtreecommitdiff
path: root/ascii2map.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2016-09-02 08:19:29 +0000
committerIan C <ianc@noddybox.co.uk>2016-09-02 08:19:29 +0000
commit54bb3c9abdd34b92be44b87382a7b3c03a5991d9 (patch)
tree7d791e8b6758a2aeec37c94d4a5871d9b9d5b7da /ascii2map.c
parentd1b2a8b7d86d8b02f635b112a7f39e7437eac829 (diff)
Added README and clamped code point values.
Diffstat (limited to 'ascii2map.c')
-rw-r--r--ascii2map.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/ascii2map.c b/ascii2map.c
index 30a2c44..f24cb77 100644
--- a/ascii2map.c
+++ b/ascii2map.c
@@ -105,6 +105,24 @@ static void EndOutput(FILE *fp)
}
+static unsigned CodePoint(char c)
+{
+ int offset = c - code_point;
+
+ if (offset < 0)
+ {
+ offset = 0;
+ }
+
+ if (offset > 255)
+ {
+ offset = 255;
+ }
+
+ return (unsigned)offset;
+}
+
+
static void Output(FILE *fp, char c)
{
static int column;
@@ -138,7 +156,7 @@ static void Output(FILE *fp, char c)
}
else
{
- fprintf(fp, "%u", c - code_point);
+ fprintf(fp, "%u", CodePoint(c));
}
break;
@@ -150,7 +168,7 @@ static void Output(FILE *fp, char c)
}
else
{
- putc(c - code_point, fp);
+ putc(CodePoint(c), fp);
}
break;
@@ -177,7 +195,7 @@ static void Output(FILE *fp, char c)
}
else
{
- fprintf(fp, "%u", c - code_point);
+ fprintf(fp, "%u", CodePoint(c));
}
break;