home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / MMSRC029.ZIP / mmail-0.29 / interfac / isoconv.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-27  |  2.4 KB  |  82 lines

  1. /*
  2.  * MultiMail offline mail reader
  3.  * conversion tables ISO 8859-1 <-> IBM codepage 437
  4.  
  5.  Copyright (c) 1996 Peter Karlsson <dat95pkn@idt.mdh.se>,
  6.                     Toth Istvan <stoty@vma.bme.hu>
  7.  Copyright (c) 1999 William McBrine <wmcbrine@clark.net>
  8.  
  9.  Distributed under the GNU General Public License.
  10.  For details, see the file COPYING in the parent directory. */
  11.  
  12. /* Original tables by Peter Karlsson, modified by William McBrine after 
  13.    DOSEmu's video/terminal.h, by Mark D. Rejhon. */
  14.  
  15. #include "interfac.h"
  16.  
  17. enum cdirtype {CC_ISOTO437, CC_437TOISO};
  18.  
  19. bool isoConsole;
  20.  
  21. const char *dos2isotab =
  22.   "\307\374\351\342\344\340\345\347\352\353\350\357\356\354\304\305"
  23.   "\311\346\306\364\366\362\373\371\377\326\334\242\243\245\120\146"
  24.   "\341\355\363\372\361\321\252\272\277\055\254\275\274\241\253\273"
  25.   ":%&|{{{..{I.'''.``+}-+}}`.**}=**+*+``..**'.#_][~"
  26.   "a\337\254\266{\363\265t\330\364\326\363o\370En"
  27.   "=\261><()\367=\260\267\267%\140\262= ";
  28.  
  29. const char *iso2dostab =
  30.   "\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217"
  31.   "\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237 "
  32.   "\255\233\234$\235|\025\"c\246\256\252-r-\370\361\3753\'\346\024\371,1"
  33.   "\370\257\254\253/\250AAAA\216\217\222\200E\220EEIIIID\245OOOO\231x"
  34.   "\231UUU\232Y \341\205\240\203a\204\206\221\207\212\202\210\211\215\241"
  35.   "\214\213 \244\225\242\223o\224\366\224\227\243\226\201y \230";
  36.  
  37. char *charconv(char *buf, cdirtype cdir)
  38. {
  39.     const char *ct = (cdir == CC_ISOTO437) ? iso2dostab : dos2isotab;
  40.  
  41.     for (char *p = buf; *p; p++) {
  42.         unsigned char c = *p;
  43.         if (c & 0x80)
  44.             *p = ct[c & 0x7f];
  45.     }
  46.     return buf;
  47. }
  48.  
  49. char *charconv_in(char *buf)
  50. {
  51.     return (isoConsole ? charconv(buf, CC_437TOISO) : buf);
  52. }
  53.  
  54. char *charconv_out(char *buf)
  55. {
  56.     return (isoConsole ? charconv(buf, CC_ISOTO437) : buf);
  57. }
  58.  
  59. char *letterconv_in(char *buf)
  60. {
  61.     return (mm.letterList->isLatin() ^ isoConsole) ?
  62.         charconv(buf, isoConsole ? CC_437TOISO : CC_ISOTO437) : buf;
  63. }
  64.  
  65. char *letterconv_out(char *buf)
  66. {
  67.     return (mm.letterList->isLatin() ^ isoConsole) ?
  68.         charconv(buf, isoConsole ? CC_ISOTO437 : CC_437TOISO) : buf;
  69. }
  70.  
  71. char *areaconv_in(char *buf)
  72. {
  73.     return (mm.areaList->isLatin() ^ isoConsole) ?
  74.         charconv(buf, isoConsole ? CC_437TOISO : CC_ISOTO437) : buf;
  75. }
  76.  
  77. char *areaconv_out(char *buf)
  78. {
  79.     return (mm.areaList->isLatin() ^ isoConsole) ?
  80.         charconv(buf, isoConsole ? CC_ISOTO437 : CC_437TOISO) : buf;
  81. }
  82.