summaryrefslogtreecommitdiff
path: root/support/word2x/map_chars.cc
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/word2x/map_chars.cc
Initial commit
Diffstat (limited to 'support/word2x/map_chars.cc')
-rw-r--r--support/word2x/map_chars.cc57
1 files changed, 57 insertions, 0 deletions
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].win<s)
+ l=m+1;
+ if (map[m].win>s)
+ 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;
+}
+
+
+