home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / GRECODE / BANGBANG.C < prev    next >
C/C++ Source or Header  |  1993-12-09  |  12KB  |  372 lines

  1. /* Conversion of files between different charsets and usages.
  2.    Copyright (C) 1990, 1993 Free Software Foundation, Inc.
  3.    Francois Pinard <pinard@iro.umontreal.ca>, 1988.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful, but
  11.    WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include "recode.h"
  21.  
  22. static const char *const translation_table[256] =
  23.   {
  24.     "!!@",            /*   0 */
  25.     "!!a",            /*   1 */
  26.     "!!b",            /*   2 */
  27.     "!!c",            /*   3 */
  28.     "!!d",            /*   4 */
  29.     "!!e",            /*   5 */
  30.     "!!f",            /*   6 */
  31.     "!!g",            /*   7 */
  32.     "!!h",            /*   8 */
  33.     "!!i",            /*   9 */
  34.     "\n",            /*  10, would have been "!!j" */
  35.     "!!k",            /*  11 */
  36.     "!!l",            /*  12 */
  37.     "!!m",            /*  13 */
  38.     "!!n",            /*  14 */
  39.     "!!o",            /*  15 */
  40.     "!!p",            /*  16 */
  41.     "!!q",            /*  17 */
  42.     "!!r",            /*  18 */
  43.     "!!s",            /*  19 */
  44.     "!!t",            /*  20 */
  45.     "!!u",            /*  21 */
  46.     "!!v",            /*  22 */
  47.     "!!w",            /*  23 */
  48.     "!!x",            /*  24 */
  49.     "!!y",            /*  25 */
  50.     "!!z",            /*  26 */
  51.     "!![",            /*  27 */
  52.     "!!\\",            /*  28 */
  53.     "!!]",            /*  29 */
  54.     "!!^",            /*  30 */
  55.     "!!_",            /*  31 */
  56.     " ",            /*  32 */
  57.     "!\"",            /*  33 */
  58.     "\"",            /*  34 */
  59.     "#",            /*  35 */
  60.     "$",            /*  36 */
  61.     "%",            /*  37 */
  62.     "&",            /*  38 */
  63.     "'",            /*  39 */
  64.     "(",            /*  40 */
  65.     ")",            /*  41 */
  66.     "*",            /*  42 */
  67.     "+",            /*  43 */
  68.     ",",            /*  44 */
  69.     "-",            /*  45 */
  70.     ".",            /*  46 */
  71.     "/",            /*  47 */
  72.     "0",            /*  48 */
  73.     "1",            /*  49 */
  74.     "2",            /*  50 */
  75.     "3",            /*  51 */
  76.     "4",            /*  52 */
  77.     "5",            /*  53 */
  78.     "6",            /*  54 */
  79.     "7",            /*  55 */
  80.     "8",            /*  56 */
  81.     "9",            /*  57 */
  82.     ":",            /*  58 */
  83.     ";",            /*  59 */
  84.     "<",            /*  60 */
  85.     "=",            /*  61 */
  86.     ">",            /*  62 */
  87.     "?",            /*  63 */
  88.     "@",            /*  64 */
  89.     "!a",            /*  65 */
  90.     "!b",            /*  66 */
  91.     "!c",            /*  67 */
  92.     "!d",            /*  68 */
  93.     "!e",            /*  69 */
  94.     "!f",            /*  70 */
  95.     "!g",            /*  71 */
  96.     "!h",            /*  72 */
  97.     "!i",            /*  73 */
  98.     "!j",            /*  74 */
  99.     "!k",            /*  75 */
  100.     "!l",            /*  76 */
  101.     "!m",            /*  77 */
  102.     "!n",            /*  78 */
  103.     "!o",            /*  79 */
  104.     "!p",            /*  80 */
  105.     "!q",            /*  81 */
  106.     "!r",            /*  82 */
  107.     "!s",            /*  83 */
  108.     "!t",            /*  84 */
  109.     "!u",            /*  85 */
  110.     "!v",            /*  86 */
  111.     "!w",            /*  87 */
  112.     "!x",            /*  88 */
  113.     "!y",            /*  89 */
  114.     "!z",            /*  90 */
  115.     "[",            /*  91 */
  116.     "\\",            /*  92 */
  117.     "]",            /*  93 */
  118.     "^",            /*  94 */
  119.     "_",            /*  95 */
  120.     "!@",            /*  96 */
  121.     "a",            /*  97 */
  122.     "b",            /*  98 */
  123.     "c",            /*  99 */
  124.     "d",            /* 100 */
  125.     "e",            /* 101 */
  126.     "f",            /* 102 */
  127.     "g",            /* 103 */
  128.     "h",            /* 104 */
  129.     "i",            /* 105 */
  130.     "j",            /* 106 */
  131.     "k",            /* 107 */
  132.     "l",            /* 108 */
  133.     "m",            /* 109 */
  134.     "n",            /* 110 */
  135.     "o",            /* 111 */
  136.     "p",            /* 112 */
  137.     "q",            /* 113 */
  138.     "r",            /* 114 */
  139.     "s",            /* 115 */
  140.     "t",            /* 116 */
  141.     "u",            /* 117 */
  142.     "v",            /* 118 */
  143.     "w",            /* 119 */
  144.     "x",            /* 120 */
  145.     "y",            /* 121 */
  146.     "z",            /* 122 */
  147.     "![",            /* 123 */
  148.     "!\\",            /* 124 */
  149.     "!]",            /* 125 */
  150.     "!^",            /* 126 */
  151.     "!_",            /* 127 */
  152.  
  153.     NULL,            /* 128 */
  154.     NULL,            /* 129 */
  155.     NULL,            /* 130 */
  156.     NULL,            /* 131 */
  157.     NULL,            /* 132 */
  158.     NULL,            /* 133 */
  159.     NULL,            /* 134 */
  160.     NULL,            /* 135 */
  161.     NULL,            /* 136 */
  162.     NULL,            /* 137 */
  163.     NULL,            /* 138 */
  164.     NULL,            /* 139 */
  165.     NULL,            /* 140 */
  166.     NULL,            /* 141 */
  167.     NULL,            /* 142 */
  168.     NULL,            /* 143 */
  169.     NULL,            /* 144 */
  170.     NULL,            /* 145 */
  171.     NULL,            /* 146 */
  172.     NULL,            /* 147 */
  173.     NULL,            /* 148 */
  174.     NULL,            /* 149 */
  175.     NULL,            /* 150 */
  176.     NULL,            /* 151 */
  177.     NULL,            /* 152 */
  178.     NULL,            /* 153 */
  179.     NULL,            /* 154 */
  180.     NULL,            /* 155 */
  181.     NULL,            /* 156 */
  182.     NULL,            /* 157 */
  183.     NULL,            /* 158 */
  184.     NULL,            /* 159 */
  185.  
  186.     " ",            /* 160 no-break space */
  187.     NULL,            /* 161 inverted exclamation mark */
  188.     NULL,            /* 162 cent sign */
  189.     NULL,            /* 163 pound sign */
  190.     NULL,            /* 164 currency sign */
  191.     NULL,            /* 165 yen sign */
  192.     NULL,            /* 166 broken bar */
  193.     NULL,            /* 167 paragraph sign, section sign */
  194.     NULL,            /* 168 diaeresis */
  195.     NULL,            /* 169 copyright sign */
  196.     NULL,            /* 170 feminine ordinal indicator */
  197.     "!>",            /* 171 left angle quotation mark */
  198.     NULL,            /* 172 not sign */
  199.     NULL,            /* 173 soft hyphen */
  200.     NULL,            /* 174 registered trade mark sign */
  201.     NULL,            /* 175 macron */
  202.     NULL,            /* 176 degree sign */
  203.     NULL,            /* 177 plus-minus sign */
  204.     NULL,            /* 178 superscript two */
  205.     NULL,            /* 179 superscript three */
  206.     NULL,            /* 180 acute accent */
  207.     NULL,            /* 181 small greek mu, micro sign */
  208.     NULL,            /* 182 pilcrow sign */
  209.     NULL,            /* 183 middle dot */
  210.     NULL,            /* 184 cedilla */
  211.     NULL,            /* 185 superscript one */
  212.     NULL,            /* 186 masculine ordinal indicator */
  213.     "!?",            /* 187 right angle quotation mark */
  214.     NULL,            /* 188 vulgar fraction one quarter */
  215.     NULL,            /* 189 vulgar fraction one half */
  216.     NULL,            /* 190 vulgar fraction three quarters */
  217.     NULL,            /* 191 inverted question mark */
  218.     NULL,            /* 192 capital A with grave accent */
  219.     NULL,            /* 193 capital A with acute accent */
  220.     NULL,            /* 194 capital A with circumflex accent */
  221.     NULL,            /* 195 capital A with tilde */
  222.     NULL,            /* 196 capital A diaeresis */
  223.     NULL,            /* 197 capital A with ring above */
  224.     NULL,            /* 198 capital diphthong A with E */
  225.     NULL,            /* 199 capital C with cedilla */
  226.     NULL,            /* 200 capital E with grave accent */
  227.     NULL,            /* 201 capital E with acute accent */
  228.     NULL,            /* 202 capital E with circumflex accent */
  229.     NULL,            /* 203 capital E with diaeresis */
  230.     NULL,            /* 204 capital I with grave accent */
  231.     NULL,            /* 205 capital I with acute accent */
  232.     NULL,            /* 206 capital I with circumflex accent */
  233.     NULL,            /* 207 capital I with diaeresis */
  234.     NULL,            /* 208 capital icelandic ETH */
  235.     NULL,            /* 209 capital N with tilde */
  236.     NULL,            /* 210 capital O with grave accent */
  237.     NULL,            /* 211 capital O with acute accent */
  238.     NULL,            /* 212 capital O with circumflex accent */
  239.     NULL,            /* 213 capital O with tilde */
  240.     NULL,            /* 214 capital O with diaeresis */
  241.     NULL,            /* 215 multiplication sign */
  242.     NULL,            /* 216 capital O with oblique stroke */
  243.     NULL,            /* 217 capital U with grave accent */
  244.     NULL,            /* 218 capital U with acute accent */
  245.     NULL,            /* 219 capital U with circumflex accent */
  246.     NULL,            /* 220 capital U with diaeresis */
  247.     NULL,            /* 221 capital Y with acute accent */
  248.     NULL,            /* 222 capital icelandic THORN */
  249.     NULL,            /* 223 small german sharp s */
  250.     "!0",            /* 224 small a with grave accent */
  251.     NULL,            /* 225 small a with acute accent */
  252.     "!1",            /* 226 small a with circumflex accent */
  253.     NULL,            /* 227 small a with tilde */
  254.     NULL,            /* 228 small a with diaeresis */
  255.     NULL,            /* 229 small a with ring above */
  256.     "!;",            /* 230 small diphthong a with e */
  257.     "!=",            /* 231 small c with cedilla */
  258.     "!3",            /* 232 small e with grave accent */
  259.     "!2",            /* 233 small e with acute accent */
  260.     "!5",            /* 234 small e with circumflex accent */
  261.     "!4",            /* 235 small e with diaeresis */
  262.     NULL,            /* 236 small i with grave accent */
  263.     NULL,            /* 237 small i with acute accent */
  264.     "!7",            /* 238 small i with circumflex accent */
  265.     "!6",            /* 239 small i with diaeresis */
  266.     NULL,            /* 240 small icelandic eth */
  267.     NULL,            /* 241 small n with tilde */
  268.     NULL,            /* 242 small o with grave accent */
  269.     NULL,            /* 243 small o with acute accent */
  270.     "!8",            /* 244 small o with circumflex accent */
  271.     NULL,            /* 245 small o with tilde */
  272.     NULL,            /* 246 small o with diaeresis */
  273.     "!<",            /* 247 division sign (or French oe?) */
  274.     NULL,            /* 248 small o with oblique stroke */
  275.     "!9",            /* 249 small u with grave accent */
  276.     NULL,            /* 250 small u with acute accent */
  277.     "!:",            /* 251 small u with circumflex accent */
  278.     NULL,            /* 252 small u with diaeresis */
  279.     NULL,            /* 253 small y with acute accent */
  280.     NULL,            /* 254 small icelandic thorn */
  281.     NULL,            /* 255 small y with diaeresis */
  282.   };
  283.  
  284. static void
  285. init_latin1_bangbang (STEP *step)
  286. {
  287.   step->one_to_many = translation_table;
  288. }
  289.  
  290. static void
  291. file_bangbang_latin1 (const STEP *step, FILE *input_file, FILE *output_file)
  292. {
  293.   int input_char;        /* current character */
  294.  
  295.   while (input_char = getc (input_file), input_char != EOF)
  296.     {
  297.       if (input_char >= 'A' && input_char <= 'Z')
  298.         input_char += 'a' - 'A';
  299.       else if (input_char == '!')
  300.     {
  301.       input_char = getc (input_file);
  302.       if (input_char >= 'a' && input_char <= 'z')
  303.         input_char += 'A' - 'a';
  304.       else if (input_char < 'A' || input_char > 'Z')
  305.         switch (input_char)
  306.           {
  307.           case '"': input_char = '!'; break;
  308.           case '0': input_char = 224; break; /* a` */
  309.           case '1': input_char = 226; break; /* a^ */
  310.           case '2': input_char = 233; break; /* e' */
  311.           case '3': input_char = 232; break; /* e` */
  312.           case '4': input_char = 235; break; /* e" */
  313.           case '5': input_char = 234; break; /* e^ */
  314.           case '6': input_char = 236; break; /* e" */
  315.           case '7': input_char = 238; break; /* i^ */
  316.           case '8': input_char = 244; break; /* o^ */
  317.           case '9': input_char = 249; break; /* u` */
  318.           case ':': input_char = 251; break; /* u^ */
  319.           case '=': input_char = 231; break; /* c, */
  320.           case '>': input_char = 171; break; /* `` */
  321.           case '?': input_char = 187; break; /* '' */
  322.           case ';': input_char = 230; break; /* ae */
  323.           case '<':    input_char = 247; break; /* oe ??? */
  324.           case '@': input_char = '`'; break;
  325.           case '[': input_char = '{'; break;
  326.           case '\\': input_char = '|'; break;
  327.           case ']': input_char = '}'; break;
  328.           case '^': input_char = '~'; break;
  329.           case '_': input_char = 127; break; /* del */
  330.  
  331.           case '!':
  332.             input_char = getc (input_file);
  333.         if (input_char >= 'A' && input_char <= 'Z')
  334.           input_char += 1 - 'A';
  335.             else if (input_char >= 'a' && input_char <= 'z')
  336.           input_char += 1 - 'a';
  337.             else
  338.           switch (input_char)
  339.             {
  340.             case '@': input_char =   0; break;
  341.             case '[': input_char =  27; break;
  342.             case '\\': input_char =  28; break;
  343.             case ']': input_char =  29; break;
  344.             case '^': input_char =  30; break;
  345.             case '_': input_char =  31; break;
  346.  
  347.             default:
  348.               putc ('!', output_file);
  349.               putc ('!', output_file);
  350.               if (input_char == EOF)
  351.                 return;
  352.             }
  353.         break;
  354.  
  355.           default:
  356.             putc ('!', output_file);
  357.             if (input_char == EOF)
  358.           return;
  359.           }
  360.     }
  361.       putc (input_char, output_file);
  362.     }
  363. }
  364.  
  365. void
  366. module_bangbang (void)
  367. {
  368.   declare_step ("latin1", "bangbang", ONE_TO_MANY, init_latin1_bangbang,
  369.         file_one_to_many);
  370.   declare_step ("bangbang", "latin1", MANY_TO_ONE, NULL, file_bangbang_latin1);
  371. }
  372.