From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- support/word2x/map_chars.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 support/word2x/map_chars.cc (limited to 'support/word2x/map_chars.cc') diff --git a/support/word2x/map_chars.cc b/support/word2x/map_chars.cc new file mode 100644 index 0000000000..f3b112f2ce --- /dev/null +++ b/support/word2x/map_chars.cc @@ -0,0 +1,57 @@ +/* $Id: map_chars.cc,v 1.2 1997/03/23 13:19:26 dps Exp $ */ + +#include "tblock.h" +#ifndef NULL +#define NULL (void *) 0 +#endif +#define __EXCLUDE_READER_CLASSES +#include "lib.h" + + +static const char *map_char(unsigned char s, const cmap *map, int n) +{ + int l, m, r; + + l=0; + r=n-1; + while (l<=r) + { + m=(l+r)/2; + if (map[m].win==s) + return map[m].ascii; + if (map[m].wins) + r=m-1; + } + return NULL; +} + +tblock *__map_string(const char *s, const cmap *map, int map_size) +{ + const char *scan, *sptr; + tblock *res; + + res=new(tblock); + scan=s; + while (*scan!='\0') + { + if ((sptr=map_char(*scan, map, map_size))==NULL) + { + scan++; + continue; + } + if (scan!=s) + res->add(s, scan-s); + res->add(sptr); + scan++; + s=scan; + } + if (scan!=s) + res->add(s, scan-s); + + return res; +} + + + -- cgit v1.2.3