Deleted Added
full compact
charset.c (60786) charset.c (89019)
1/*
2 * Copyright (C) 1984-2000 Mark Nudelman
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
6 *
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.

--- 18 unchanged lines hidden (view full) ---

27 * selected by the LESSCHARSET environment variable.
28 */
29struct charset {
30 char *name;
31 int *p_flag;
32 char *desc;
33} charsets[] = {
34 { "ascii", NULL, "8bcccbcc18b95.b" },
1/*
2 * Copyright (C) 1984-2000 Mark Nudelman
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
6 *
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.

--- 18 unchanged lines hidden (view full) ---

27 * selected by the LESSCHARSET environment variable.
28 */
29struct charset {
30 char *name;
31 int *p_flag;
32 char *desc;
33} charsets[] = {
34 { "ascii", NULL, "8bcccbcc18b95.b" },
35 { "dos", NULL, "8bcccbcc12bc5b95.b." },
35 { "dos", NULL, "8bcccbcc12bc5b223.b" },
36 { "ebcdic", NULL, "5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b." },
36 { "ebcdic", NULL, "5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b." },
37 { "IBM-1047", NULL, "4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc191.b" },
37 { "iso8859", NULL, "8bcccbcc18b95.33b." },
38 { "koi8-r", NULL, "8bcccbcc18b95.b128." },
38 { "iso8859", NULL, "8bcccbcc18b95.33b." },
39 { "koi8-r", NULL, "8bcccbcc18b95.b128." },
39 { "latin1", NULL, "8bcccbcc18b95.33b." },
40 { "next", NULL, "8bcccbcc18b95.bb125.bb" },
41 { "utf-8", &utf_mode, "8bcccbcc18b." },
42 { NULL, NULL, NULL }
43};
44
40 { "next", NULL, "8bcccbcc18b95.bb125.bb" },
41 { "utf-8", &utf_mode, "8bcccbcc18b." },
42 { NULL, NULL, NULL }
43};
44
45struct cs_alias {
46 char *name;
47 char *oname;
48} cs_aliases[] = {
49 { "latin1", "iso8859" },
50 { "latin9", "iso8859" },
51 { NULL, NULL }
52};
53
45#define IS_BINARY_CHAR 01
46#define IS_CONTROL_CHAR 02
47
48static char chardef[256];
49static char *binfmt = NULL;
50public int binattr = AT_STANDOUT;
51
52

--- 68 unchanged lines hidden (view full) ---

121 * Define a charset, given a charset name.
122 * The valid charset names are listed in the "charsets" array.
123 */
124 static int
125icharset(name)
126 register char *name;
127{
128 register struct charset *p;
54#define IS_BINARY_CHAR 01
55#define IS_CONTROL_CHAR 02
56
57static char chardef[256];
58static char *binfmt = NULL;
59public int binattr = AT_STANDOUT;
60
61

--- 68 unchanged lines hidden (view full) ---

130 * Define a charset, given a charset name.
131 * The valid charset names are listed in the "charsets" array.
132 */
133 static int
134icharset(name)
135 register char *name;
136{
137 register struct charset *p;
138 register struct cs_alias *a;
129
130 if (name == NULL || *name == '\0')
131 return (0);
132
139
140 if (name == NULL || *name == '\0')
141 return (0);
142
143 /* First see if the name is an alias. */
144 for (a = cs_aliases; a->name != NULL; a++)
145 {
146 if (strcmp(name, a->name) == 0)
147 {
148 name = a->oname;
149 break;
150 }
151 }
152
133 for (p = charsets; p->name != NULL; p++)
134 {
135 if (strcmp(name, p->name) == 0)
136 {
137 ichardef(p->desc);
138 if (p->p_flag != NULL)
139 *(p->p_flag) = 1;
140 return (1);

--- 96 unchanged lines hidden (view full) ---

237#endif
238
239#if HAVE_LOCALE
240 /*
241 * Use setlocale.
242 */
243 ilocale();
244#else
153 for (p = charsets; p->name != NULL; p++)
154 {
155 if (strcmp(name, p->name) == 0)
156 {
157 ichardef(p->desc);
158 if (p->p_flag != NULL)
159 *(p->p_flag) = 1;
160 return (1);

--- 96 unchanged lines hidden (view full) ---

257#endif
258
259#if HAVE_LOCALE
260 /*
261 * Use setlocale.
262 */
263 ilocale();
264#else
265#if MSDOS_COMPILER
245 /*
266 /*
267 * Default to "dos".
268 */
269 (void) icharset("dos");
270#else
271 /*
246 * Default to "latin1".
247 */
248 (void) icharset("latin1");
249#endif
272 * Default to "latin1".
273 */
274 (void) icharset("latin1");
275#endif
276#endif
250}
251
252/*
253 * Is a given character a "binary" character?
254 */
255 public int
256binary_char(c)
257 unsigned char c;

--- 23 unchanged lines hidden (view full) ---

281{
282 static char buf[8];
283
284 c &= 0377;
285 if (!control_char(c))
286 sprintf(buf, "%c", c);
287 else if (c == ESC)
288 sprintf(buf, "ESC");
277}
278
279/*
280 * Is a given character a "binary" character?
281 */
282 public int
283binary_char(c)
284 unsigned char c;

--- 23 unchanged lines hidden (view full) ---

308{
309 static char buf[8];
310
311 c &= 0377;
312 if (!control_char(c))
313 sprintf(buf, "%c", c);
314 else if (c == ESC)
315 sprintf(buf, "ESC");
289 else if (c < 128 && !control_char(c ^ 0100))
290 sprintf(buf, "^%c", c ^ 0100);
316#if IS_EBCDIC_HOST
317 else if (!binary_char(c) && c < 64)
318 sprintf(buf, "^%c",
319 /*
320 * This array roughly inverts CONTROL() #defined in less.h,
321 * and should be kept in sync with CONTROL() and IBM-1047.
322 */
323 "@ABC.I.?...KLMNO"
324 "PQRS.JH.XY.."
325 "\\]^_"
326 "......W[.....EFG"
327 "..V....D....TU.Z"[c]);
328#else
329 else if (c < 128 && !control_char(c ^ 0100))
330 sprintf(buf, "^%c", c ^ 0100);
331#endif
291 else
292 sprintf(buf, binfmt, c);
293 return (buf);
294}
332 else
333 sprintf(buf, binfmt, c);
334 return (buf);
335}