1826
|
1 |
/*
|
|
2 |
* translation functions
|
|
3 |
* table ranges are checked
|
|
4 |
*/
|
|
5 |
|
|
6 |
|
|
7 |
#include <stdio.h>
|
|
8 |
#include "conv-defs.h"
|
|
9 |
|
|
10 |
extern char *translationTableLow[END_LOW_TABLE - START_LOW_TABLE + 1];
|
|
11 |
extern char *translationTableHi[END_HI_TABLE - START_HI_TABLE + 1][2];
|
|
12 |
extern char *translationTableSeq[SEQ_TABLE][2];
|
|
13 |
|
|
14 |
char *translateLow(int ch) {
|
|
15 |
if ((ch >= START_LOW_TABLE) && (ch <= END_LOW_TABLE))
|
|
16 |
return (translationTableLow[ch - START_LOW_TABLE]);
|
|
17 |
else {
|
|
18 |
fprintf(stderr, "Error in translateLow!\n");
|
|
19 |
exit(-1);
|
|
20 |
}
|
|
21 |
}
|
|
22 |
|
|
23 |
char *translateHi(int ch, int code) {
|
|
24 |
/*(256 + ch) is used to convert from character to unsigned short */
|
|
25 |
if (((256 + ch) >= START_HI_TABLE) && ((256 + ch) <= END_HI_TABLE))
|
|
26 |
return (translationTableHi[(256 + ch) - START_HI_TABLE][code]);
|
|
27 |
else {
|
|
28 |
fprintf(stderr, "Sorry, the file contains a high-bit character which\n");
|
|
29 |
fprintf(stderr, "is not in the translation table!\n");
|
|
30 |
exit(-1);
|
|
31 |
}
|
|
32 |
}
|
|
33 |
|
|
34 |
char *translateLong(int ch, int code) {
|
|
35 |
if ((ch < SEQ_TABLE))
|
|
36 |
return (translationTableSeq[ch][code]);
|
|
37 |
else {
|
|
38 |
fprintf(stderr, "Error in translateLong!\n");
|
|
39 |
exit(-1);
|
|
40 |
}
|
|
41 |
}
|
|
42 |
|