Debian Codegraph @

src/flat.c

raw symbols SCIP
1 /* Conversion of files between different charsets and surfaces.
2 Copyright © 1990-2018 Free Software Foundation, Inc.
3 Contributed by François Pinard <[email protected]>, 1988.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License
7 as published by the Free Software Foundation; either version 3 of the
8 License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the Recode Library; see the file `COPYING.LIB'.
17 If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "config.h"
21 #include "common.h"
22 #include "decsteps.h"
23
24 static bool
25 transform_ascii_flat (RECODE_SUBTASK subtask)
26 {
27 int input_char; /* current character */
28 int temp_char; /* look ahead character */
29
30 input_char = recode_get_byte (subtask);
31 while (true)
32 switch (input_char)
33 {
34 case EOF:
35 SUBTASK_RETURN (subtask);
36
37 case '\n':
38 case '\t':
39 recode_put_byte (input_char, subtask);
40 input_char = recode_get_byte (subtask);
41 break;
42
43 case '\b':
44 input_char = recode_get_byte (subtask);
45 switch (input_char)
46 {
47 case '\'':
48 case '`':
49 case '^':
50 case '"':
51 case '~':
52 case ',':
53 case '_':
54 RETURN_IF_NOGO (RECODE_AMBIGUOUS_OUTPUT, subtask);
55 input_char = recode_get_byte (subtask);
56 break;
57
58 default:
59 recode_put_byte ('\b', subtask);
60 }
61 break;
62
63 case '\'':
64 case '`':
65 case '^':
66 case '"':
67 case '~':
68 case ',':
69 case '_':
70 temp_char = recode_get_byte (subtask);
71 if (temp_char == '\b')
72 {
73 RETURN_IF_NOGO (RECODE_AMBIGUOUS_OUTPUT, subtask);
74 input_char = recode_get_byte (subtask);
75 }
76 else
77 {
78 recode_put_byte (input_char, subtask);
79 input_char = temp_char;
80 }
81 break;
82
83 default:
84 if (!IS_ASCII (input_char))
85 {
86 RETURN_IF_NOGO (RECODE_AMBIGUOUS_OUTPUT, subtask);
87 recode_put_byte ('M', subtask);
88 recode_put_byte ('-', subtask);
89 input_char &= BIT_MASK (7);
90 }
91 if (input_char < ' ' || input_char == BIT_MASK (7))
92 {
93 RETURN_IF_NOGO (RECODE_AMBIGUOUS_OUTPUT, subtask);
94 recode_put_byte ('^', subtask);
95 input_char ^= (1 << 6);
96 }
97 recode_put_byte (input_char, subtask);
98 input_char = recode_get_byte (subtask);
99 }
100 }
101
102 bool
103 module_flat (RECODE_OUTER outer)
104 {
105 if (!recode_declare_single (outer, "ASCII-BS", "flat",
106 outer->quality_variable_to_variable,
107 NULL, transform_ascii_flat))
108 return false;
109
110 return true;
111 }
112
113 void
114 delmodule_flat (_GL_UNUSED RECODE_OUTER outer)
115 {
116 }