File: iconqnx.c

package info (click to toggle)
recode 3.4.1-11
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,560 kB
  • ctags: 622
  • sloc: ansic: 10,572; perl: 339; makefile: 317; lisp: 243; sh: 173; lex: 165; awk: 127; sed: 10
file content (228 lines) | stat: -rw-r--r-- 5,625 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/* Conversion of files between different charsets and usages.
   Copyright (C) 1990, 1993, 1994 Free Software Foundation, Inc.
   Francois Pinard <pinard@iro.umontreal.ca>, 1988.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "recode.h"

#define DOS_CR 13		/* carriage return */
#define DOS_LF 10		/* line feed */
#define DOS_EOF 26		/* old end of file */

#define ESCAPE 25		/* escape for diacritic application */
#define ENDLINE 30		/* end-line code for QNX */

#define TRANSLATE_AND_BREAK(c2, c3) \
  putc (ESCAPE, output_file); \
  putc (c2, output_file); \
  putc (c3, output_file); \
  input_char = getc (input_file); \
  break;

static int
file_ibmpc_iconqnx (const STEP *step, FILE *input_file, FILE *output_file)
{
  int reversible;		/* reversibility of recoding */
  int input_char;

  reversible = 1;
  input_char = getc (input_file);
  while (1)
    switch (input_char)
      {
      case EOF:
	return reversible;

      case DOS_EOF:
	return 0;

      case 133: TRANSLATE_AND_BREAK ('A', 'a');
      case 138: TRANSLATE_AND_BREAK ('A', 'e');
      case 151: TRANSLATE_AND_BREAK ('A', 'u');
      case 130: TRANSLATE_AND_BREAK ('B', 'e');
      case 144: TRANSLATE_AND_BREAK ('B', 'E');
      case 131: TRANSLATE_AND_BREAK ('C', 'a');
      case 136: TRANSLATE_AND_BREAK ('C', 'e');
      case 140: TRANSLATE_AND_BREAK ('C', 'i');
      case 147: TRANSLATE_AND_BREAK ('C', 'o');
      case 150: TRANSLATE_AND_BREAK ('C', 'u');
      case 137: TRANSLATE_AND_BREAK ('H', 'e');
      case 139: TRANSLATE_AND_BREAK ('H', 'i');
      case 129: TRANSLATE_AND_BREAK ('H', 'u');
      case 135: TRANSLATE_AND_BREAK ('K', 'c');
      case 128: TRANSLATE_AND_BREAK ('K', 'C');

      case DOS_CR:
	input_char = getc (input_file);
	if (input_char == DOS_LF)
	  {
	    putc (ENDLINE, output_file);
	    input_char = getc (input_file);
	  }
	else
	  putc (DOS_CR, output_file);
	break;

      case ENDLINE:
      case ESCAPE:
	reversible = 0;
	/* Fall through.  */

      default:
	putc (input_char, output_file);
	input_char = getc (input_file);
      }
}

static int
file_iconqnx_ibmpc (const STEP *step, FILE *input_file, FILE *output_file)
{
  int reversible;		/* reversibility of recoding */
  int input_char;		/* current character */

  reversible = 1;
  input_char = getc (input_file);
  while (1)
    switch (input_char)
      {
      case EOF:
	return reversible;

      case ENDLINE:
	putc (DOS_CR, output_file);
	putc (DOS_LF, output_file);
	input_char = getc (input_file);
	break;

      case DOS_CR:
	input_char = getc (input_file);
	if (input_char == DOS_LF)
	  reversible = 0;
	putc (DOS_CR, output_file);
	break;

      case ESCAPE:
	input_char = getc (input_file);
	switch (input_char)
	  {
	  case 'A':
	    input_char = getc (input_file);
	    switch (input_char)
	      {
	      case 'a': input_char = 133; break;
	      case 'e': input_char = 138; break;
	      case 'u': input_char = 151; break;

	      default:
		reversible = 0;
		putc (ESCAPE, output_file);
		putc ('A', output_file);
		if (input_char == EOF)
		  return 0;
	      }
	    break;

	  case 'B':
	    input_char = getc (input_file);
	    switch (input_char)
	      {
	      case 'e': input_char = 130; break;
	      case 'E': input_char = 144; break;

	      default:
		reversible = 0;
		putc (ESCAPE, output_file);
		putc ('B', output_file);
		if (input_char == EOF)
		  return 0;
	      }
	    break;

	  case 'C':
	    input_char = getc (input_file);
	    switch (input_char)
	      {
	      case 'a': input_char = 131; break;
	      case 'e': input_char = 136; break;
	      case 'i': input_char = 140; break;
	      case 'o': input_char = 147; break;
	      case 'u': input_char = 150; break;

	      default:
		reversible = 0;
		putc (ESCAPE, output_file);
		putc ('C', output_file);
		if (input_char == EOF)
		  return 0;
	      }
	    break;

	  case 'H':
	    input_char = getc (input_file);
	    switch (input_char)
	      {
	      case 'e': input_char = 137; break;
	      case 'i': input_char = 139; break;
	      case 'u': input_char = 129; break;

	      default:
		reversible = 0;
		putc (ESCAPE, output_file);
		putc ('H', output_file);
		if (input_char == EOF)
		  return 0;
	      }
	    break;

	  case 'K':
	    input_char = getc (input_file);
	    switch (input_char)
	      {
	      case 'c': input_char = 135; break;
	      case 'C': input_char = 128; break;

	      default:
		reversible = 0;
		putc (ESCAPE, output_file);
		putc ('K', output_file);
		if (input_char == EOF)
		  return 0;
	      }
	    break;

	  default:
	    reversible = 0;
	    putc (ESCAPE, output_file);
	    if (input_char == EOF)
	      return 0;
	  }
	/* Fall through.  */

      default:
	putc (input_char, output_file);
	input_char = getc (input_file);
      }
}

void
module_iconqnx (void)
{
  declare_step ("IBM-PC", "Icon-QNX", MANY_TO_MANY, NULL, file_ibmpc_iconqnx);
  declare_step ("Icon-QNX", "IBM-PC", MANY_TO_MANY, NULL, file_iconqnx_ibmpc);

  declare_alias ("QNX", "Icon-QNX");
}