1 /* @(#)ctab.c 1.16 18/08/23 Copyright 1986-2018 J. Schilling */
2 #include <schily/mconfig.h>
3 #ifndef lint
4 static UConst char sccsid[] =
5 "@(#)ctab.c 1.16 18/08/23 Copyright 1986-2018 J. Schilling";
6 #endif
7 /*
8 * Character string and stringlength tables for screen
9 * output functions.
10 *
11 * Copyright (c) 1986-2018 J. Schilling
12 */
13 /*
14 * The contents of this file are subject to the terms of the
15 * Common Development and Distribution License, Version 1.0 only
16 * (the "License"). You may not use this file except in compliance
17 * with the License.
18 *
19 * See the file CDDL.Schily.txt in this distribution for details.
20 * A copy of the CDDL is also available via the Internet at
21 * http://www.opensource.org/licenses/cddl1.txt
22 *
23 * When distributing Covered Code, include this CDDL HEADER in each
24 * file and include the License file CDDL.Schily.txt from this distribution.
25 */
26
27 #include "ved.h"
28
29 EXPORT Uchar csize[256];
30 EXPORT Uchar *ctab[256];
31
32 LOCAL Uchar *cmakestr __PR((ewin_t *wp, Uchar* s));
33 EXPORT void init_charset __PR((ewin_t *wp));
34 LOCAL void init_csize __PR((ewin_t *wp));
35 LOCAL void init_ctab __PR((ewin_t *wp));
36
37 LOCAL Uchar *
cmakestr(wp,s)38 cmakestr(wp, s)
39 ewin_t *wp;
40 register Uchar *s;
41 {
42 Uchar *tmp;
43 register Uchar *s1;
44
45 if ((tmp = (Uchar *) malloc(strlen(C s)+1)) == NULL) {
46 rsttmodes(wp);
47 raisecond("makstr", 0L);
48 }
49 for (s1 = tmp; (*s1++ = *s++) != '\0'; );
50 return (tmp);
51 }
52
53 EXPORT void
init_charset(wp)54 init_charset(wp)
55 ewin_t *wp;
56 {
57 init_ctab(wp);
58 init_csize(wp);
59 }
60
61 LOCAL void
init_csize(wp)62 init_csize(wp)
63 ewin_t *wp;
64 {
65 register unsigned c;
66 register Uchar *rcsize = csize;
67
68 for (c = 0; c <= 255; c++, rcsize++) {
69 if (c < SP || c == DEL) /*ctl */
70 *rcsize = 2;
71 #ifdef DEL8
72 else if ((c > DEL && c < SP8) || c == DEL8) /* 8bit ctl */
73 #else
74 else if (c > DEL && c < SP8) /* 8bit ctl */
75 #endif
76 *rcsize = 3;
77 else if (c >= SP8 && !wp->raw8) /* 8bit norm */
78 *rcsize = 2;
79 else /* normal char */
80 *rcsize = 1;
81 }
82 }
83
84 LOCAL char chpre[] = " ";
85 LOCAL char ctlpre[] = "^ ";
86 LOCAL char eightpre[] = "~ ";
87 LOCAL char eightctlpre[] = "~^ ";
88
89 LOCAL void
init_ctab(wp)90 init_ctab(wp)
91 ewin_t *wp;
92 {
93 register unsigned c;
94 register Uchar *p;
95 register Uchar **rctab = ctab;
96 register Uchar *ch = (Uchar *) chpre;
97 register Uchar *ctl = (Uchar *) ctlpre;
98 register Uchar *eight = (Uchar *) eightpre;
99 register Uchar *eightctl = (Uchar *) eightctlpre;
100
101 for (c = 0; c <= 255; c++, rctab++) {
102 if (c < SP || c == DEL) { /* ctl char */
103 p = cmakestr(wp, ctl);
104 p[1] = c ^ 0100;
105 #ifdef DEL8
106 } else if ((c > DEL && c < SP8) || c == DEL8) { /* 8 bit ctl */
107 #else
108 } else if (c > DEL && c < SP8) { /* 8 bit ctl */
109 #endif
110 p = cmakestr(wp, eightctl);
111 p[2] = c ^ 0300;
112 } else if (c >= SP8 && !wp->raw8) { /* 8 bit char */
113 p = cmakestr(wp, eight);
114 p[1] = c & 0177;
115 } else { /* normal char */
116 p = cmakestr(wp, ch);
117 p[0] = (Uchar)c;
118 }
119 *rctab = p;
120 }
121 }
122