%% options copyright owner = Dirk Krause copyright year = 2012-2014 license = bsd %% header #ifdef __cplusplus extern "C" { #endif /** Retrieve encoding for one character. @param c Character to retrieve encoding for. @return LaTeX encoding for character or NULL. */ char const * f2ll2l_get_encoding(char c); /** Write ISO-LATIN-1 encoded string to LaTeX source, recode characters if necessary. @param fipo Output file. @param str String to write. */ void f2ll2l_write_string(FILE *fipo, char const *str); #ifdef __cplusplus } #endif %% module #include "dk3all.h" $!trace-include /** Encodings for 0x00-0xFF. */ static char const * const f2ll2l_encodings[] = { /* 000 00 */ "", /* 001 01 */ "", /* 002 02 */ "", /* 003 03 */ "", /* 004 04 */ "", /* 005 05 */ "", /* 006 06 */ "", /* 007 07 */ "", /* 008 08 */ "", /* 009 09 */ "\t", /* 010 0a */ "\\\\*", /* 011 0b */ "", /* 012 0c */ "", /* 013 0d */ "", /* 014 0e */ "", /* 015 0f */ "", /* 016 10 */ "", /* 017 11 */ "", /* 018 12 */ "", /* 019 13 */ "", /* 020 14 */ "", /* 021 15 */ "", /* 022 16 */ "", /* 023 17 */ "", /* 024 18 */ "", /* 025 19 */ "", /* 026 1a */ "", /* 027 1b */ "", /* 028 1c */ "", /* 029 1d */ "", /* 030 1e */ "", /* 031 1f */ "", /* 032 20 */ " ", /* 033 21 */ "!", /* 034 22 */ "\\textquotedbl{}", /* 035 23 */ "\\#", /* 036 24 */ "\\textdollar{}", /* 037 25 */ "\\%", /* 038 26 */ "\\&", /* 039 27 */ "\\textquoteright{}", /* 040 28 */ "(", /* 041 29 */ ")", /* 042 2a */ "\\textasteriskcentered{}", /* 043 2b */ "+", /* 044 2c */ ",", /* 045 2d */ "-", /* 046 2e */ ".", /* 047 2f */ "/", /* 048 30 */ "0", /* 049 31 */ "1", /* 050 32 */ "2", /* 051 33 */ "3", /* 052 34 */ "4", /* 053 35 */ "5", /* 054 36 */ "6", /* 055 37 */ "7", /* 056 38 */ "8", /* 057 39 */ "9", /* 058 3a */ ":", /* 059 3b */ ";", /* 060 3c */ "\\textless{}", /* 061 3d */ "=", /* 062 3e */ "\\textgreater{}", /* 063 3f */ "?", /* 064 40 */ "@", /* 065 41 */ "A", /* 066 42 */ "B", /* 067 43 */ "C", /* 068 44 */ "D", /* 069 45 */ "E", /* 070 46 */ "F", /* 071 47 */ "G", /* 072 48 */ "H", /* 073 49 */ "I", /* 074 4a */ "J", /* 075 4b */ "K", /* 076 4c */ "L", /* 077 4d */ "M", /* 078 4e */ "N", /* 079 4f */ "O", /* 080 50 */ "P", /* 081 51 */ "Q", /* 082 52 */ "R", /* 083 53 */ "S", /* 084 54 */ "T", /* 085 55 */ "U", /* 086 56 */ "V", /* 087 57 */ "W", /* 088 58 */ "X", /* 089 59 */ "Y", /* 090 5a */ "Z", /* 091 5b */ "[", /* 092 5c */ "\\textbackslash{}", /* 093 5d */ "]", /* 094 5e */ "\\textasciicircum{}", /* 095 5f */ "\\textunderscore{}", /* 096 60 */ "\\textasciigrave{}", /* 097 61 */ "a", /* 098 62 */ "b", /* 099 63 */ "c", /* 100 64 */ "d", /* 101 65 */ "e", /* 102 66 */ "f", /* 103 67 */ "g", /* 104 68 */ "h", /* 105 69 */ "i", /* 106 6a */ "j", /* 107 6b */ "k", /* 108 6c */ "l", /* 109 6d */ "m", /* 110 6e */ "n", /* 111 6f */ "o", /* 112 70 */ "p", /* 113 71 */ "q", /* 114 72 */ "r", /* 115 73 */ "s", /* 116 74 */ "t", /* 117 75 */ "u", /* 118 76 */ "v", /* 119 77 */ "w", /* 120 78 */ "x", /* 121 79 */ "y", /* 122 7a */ "z", /* 123 7b */ "\\textbraceleft{}", /* 124 7c */ "\\textbar{}", /* 125 7d */ "\\textbraceright{}", /* 126 7e */ "\\textasciitilde{}", /* 127 7f */ "", /* 128 80 */ "", /* 129 81 */ "", /* 130 82 */ "", /* 131 83 */ "", /* 132 84 */ "", /* 133 85 */ "", /* 134 86 */ "", /* 135 87 */ "", /* 136 88 */ "", /* 137 89 */ "", /* 138 8a */ "", /* 139 8b */ "", /* 140 8c */ "", /* 141 8d */ "", /* 142 8e */ "", /* 143 8f */ "", /* 144 90 */ "", /* 145 91 */ "", /* 146 92 */ "", /* 147 93 */ "", /* 148 94 */ "", /* 149 95 */ "", /* 150 96 */ "", /* 151 97 */ "", /* 152 98 */ "", /* 153 99 */ "", /* 154 9a */ "", /* 155 9b */ "", /* 156 9c */ "", /* 157 9d */ "", /* 158 9e */ "", /* 159 9f */ "", /* 160 a0 */ "", /* 161 a1 */ "\\textexclamdown{}", /* 162 a2 */ "\\textcentoldstyle{}", /* 163 a3 */ "\\textstirling{}", /* 164 a4 */ "\\textcurrency{}", /* 165 a5 */ "\\textyen{}", /* 166 a6 */ "\\textbrokenbar{}", /* 167 a7 */ "\\textsection{}", /* 168 a8 */ "\\textasciidieresis{}", /* 169 a9 */ "\\textcopyright{}", /* 170 aa */ "\\textordfeminine{}", /* 171 ab */ "\\quillemotleft{}", /* 172 ac */ "\\textlnot{}", /* 173 ad */ "", /* 174 ae */ "\\textregistered{}", /* 175 af */ "\\textasciimacron{}", /* 176 b0 */ "\\textdegree{}", /* 177 b1 */ "\\textpm{}", /* 178 b2 */ "\\texttwosuperior{}", /* 179 b3 */ "\\textthreesuperior{}", /* 180 b4 */ "\\textasciiacute{}", /* 181 b5 */ "\\textmu{}", /* 182 b6 */ "\\P{}", /* 183 b7 */ "\\textperiodcentered{}", /* 184 b8 */ "\\c{}", /* 185 b9 */ "\\textonesuperior{}", /* 186 ba */ "\\textordmasculine{}", /* 187 bb */ "\\quillemotright{}", /* 188 bc */ "\\textonequarter{}", /* 189 bd */ "\\textonehalf{}", /* 190 be */ "\\textthreequarters{}", /* 191 bf */ "?`", /* 192 c0 */ "\\`{A}", /* 193 c1 */ "\\'{A}", /* 194 c2 */ "\\^{A}", /* 195 c3 */ "\\~{A}", /* 196 c4 */ "\\\"{A}", /* 197 c5 */ "\\AA{}", /* 198 c6 */ "\\AE{}", /* 199 c7 */ "\\c{C}", /* 200 c8 */ "\\`{E}", /* 201 c9 */ "\\'{E}", /* 202 ca */ "\\^{E}", /* 203 cb */ "\\\"{E}", /* 204 cc */ "\\`{I}", /* 205 cd */ "\\'{I}", /* 206 ce */ "\\^{I}", /* 207 cf */ "\\\"{I}", /* 208 d0 */ "\\DH{}", /* 209 d1 */ "\\~{N}", /* 210 d2 */ "\\`{O}", /* 211 d3 */ "\\'{O}", /* 212 d4 */ "\\^{O}", /* 213 d5 */ "\\~{O}", /* 214 d6 */ "\\\"{O}", /* 215 d7 */ "\\texttimes{}", /* 216 d8 */ "\\O{}", /* 217 d9 */ "\\`{U}", /* 218 da */ "\\'{U}", /* 219 db */ "\\^{U}", /* 220 dc */ "\\\"{U}", /* 221 dd */ "\\'{Y}", /* 222 de */ "\\TH{}", /* 223 df */ "\\ss{}", /* 224 e0 */ "\\`{a}", /* 225 e1 */ "\\'{a}", /* 226 e2 */ "\\^{a}", /* 227 e3 */ "\\~{a}", /* 228 e4 */ "\\\"{a}", /* 229 e5 */ "\\aa{}", /* 230 e6 */ "\\ae{}", /* 231 e7 */ "\\c{c}", /* 232 e8 */ "\\`{e}", /* 233 e9 */ "\\'{e}", /* 234 ea */ "\\^{e}", /* 235 eb */ "\\\"{e}", /* 236 ec */ "\\`{i}", /* 237 ed */ "\\'{i}", /* 238 ee */ "\\^{i}", /* 239 ef */ "\\\"{i}", /* 240 f0 */ "\\dh{}", /* 241 f1 */ "\\~{n}", /* 242 f2 */ "\\`{o}", /* 243 f3 */ "\\'{o}", /* 244 f4 */ "\\^{o}", /* 245 f5 */ "\\~{o}", /* 246 f6 */ "\\\"{o}", /* 247 f7 */ "\\textdiv{}", /* 248 f8 */ "\\o{}", /* 249 f9 */ "\\`{u}", /* 250 fa */ "\\'{u}", /* 251 fb */ "\\^{u}", /* 252 fc */ "\\\"{u}", /* 253 fd */ "\\'{y}", /* 254 fe */ "\\th{}", /* 255 ff */ "\\\"{y}" }; char const * f2ll2l_get_encoding(char c) { char const * back = NULL; size_t s; /* c converted to an index. */ unsigned char uc; /* c converted to unsigned char. */ uc = (unsigned char)c; s = (size_t)uc; s &= 0x00FF; back = f2ll2l_encodings[s]; return back; } void f2ll2l_write_string(FILE *fipo, char const *str) { char const *ptr; /* Current character to process. */ char const *xptr; /* Encoding for current character. */ char c; /* Current character to process. */ if((fipo) && (str)) { ptr = str; while(*ptr) { c = *(ptr++); xptr = f2ll2l_get_encoding(c); if(xptr) { fputs(xptr, fipo); } else { fputc(c, fipo); } } } }