home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / word2x0a.zip / source / map_chars.cc < prev    next >
C/C++ Source or Header  |  1997-03-23  |  864b  |  58 lines

  1. /* $Id: map_chars.cc,v 1.2 1997/03/23 13:19:26 dps Exp $ */
  2.  
  3. #include "tblock.h"
  4. #ifndef NULL
  5. #define NULL (void *) 0
  6. #endif
  7. #define __EXCLUDE_READER_CLASSES
  8. #include "lib.h"
  9.  
  10.  
  11. static const char *map_char(unsigned char s, const cmap *map, int n)
  12. {
  13.     int l, m, r;
  14.  
  15.     l=0;
  16.     r=n-1;
  17.     while (l<=r)
  18.     {
  19.     m=(l+r)/2;
  20.     if (map[m].win==s)
  21.         return map[m].ascii;
  22.     if (map[m].win<s)
  23.         l=m+1;
  24.     if (map[m].win>s)
  25.         r=m-1;
  26.     }
  27.     return NULL;
  28. }
  29.  
  30. tblock *__map_string(const char *s, const cmap *map, int map_size)
  31. {
  32.     const char *scan, *sptr;
  33.     tblock *res;
  34.  
  35.     res=new(tblock);
  36.     scan=s;
  37.     while (*scan!='\0')
  38.     {
  39.     if ((sptr=map_char(*scan, map, map_size))==NULL)
  40.     {
  41.         scan++;
  42.         continue;
  43.     }
  44.     if (scan!=s)
  45.         res->add(s, scan-s);
  46.     res->add(sptr);
  47.     scan++;
  48.     s=scan;
  49.     }    
  50.     if (scan!=s)
  51.     res->add(s, scan-s);
  52.  
  53.     return res;
  54. }
  55.  
  56.  
  57.  
  58.