1 dawes 3.1 /*
|
2 dawes 3.6 * $XFree86: xc/programs/xterm/testxmc.c,v 3.5 1999/04/11 13:11:35 dawes Exp $
|
3 dawes 3.1 */
4
5 /************************************************************
6
7 Copyright 1997 by Thomas E. Dickey <dickey@clark.net>
8
9 All Rights Reserved
10
11 Permission is hereby granted, free of charge, to any person obtaining a
12 copy of this software and associated documentation files (the
13 "Software"), to deal in the Software without restriction, including
14 without limitation the rights to use, copy, modify, merge, publish,
15 distribute, sublicense, and/or sell copies of the Software, and to
16 permit persons to whom the Software is furnished to do so, subject to
17 the following conditions:
18
19 The above copyright notice and this permission notice shall be included
20 in all copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 dawes 3.1 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
26 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 Except as contained in this notice, the name(s) of the above copyright
31 holders shall not be used in advertising or otherwise to promote the
32 sale, use or other dealings in this Software without prior written
33 authorization.
34
35 ********************************************************/
36
37 /*
38 * This module provides test support for curses applications that must work
39 * with terminals that have the xmc (magic cookie) glitch. The xmc_glitch
40 * resource denotes the number of spaces that are emitted when switching to or
41 * from standout (reverse) mode. Some terminals implement this by storing the
42 * attribute controls in the character cell that is skipped. So if the cell is
43 * overwritten by text, then the attribute change in the cell is cancelled,
44 * causing attributes to the left of the change to propagate.
45 dawes 3.1 *
46 * We implement the glitch by writing a character that won't be mistaken for
47 * other normal characters (and mapping normal writes to that character to a
48 * different one).
49 *
50 * Since xmc isn't normally part of xterm, we document it here rather than in
51 * the man-page. This module is driven by resources rather than by the
52 * termcap/terminfo description to make it a little more flexible for testing
53 * purposes.
54 *
55 * Resources:
56 *
57 * xmcGlitch (class XmcGlitch)
58 * When true, enables this extension. The default is `0', which disables
59 * the module. (termcap sg, terminfo xmc).
60 *
61 * xmcAttributes (class XmcAttributes)
62 * The attributes for which we'll generate a glitch, as a bitmask.
63 *
64 * INVERSE 1
65 * UNDERLINE 2
66 dawes 3.1 * BOLD 4
67 *
68 * The default is `1' (INVERSE). Some terminals emit glitches for
69 * underline.
70 *
71 * xmcInline (class XmcInline)
72 * When true, limits the extent of an SGR change to the current line.
73 * The default is `false'. (No termcap or terminfo equivalent, though
74 * there are comments in some entries relating to this issue).
75 *
76 * xmcMoveSGR (class XmcMoveSGR)
77 * When false, a cursor movement will leave a glitch when SGR's are
78 * active. The default is `true'. (termcap ms, terminfo msgr).
79 *
80 * TODO:
81 * When xmc is active, the terminfo max_attributes (ma) capability is
82 * assumed to be 1.
83 *
84 * The xmcAttributes resource should also apply to alternate character
85 * sets and to color.
86 */
|
87 dawes 3.4
88 #include <xterm.h>
89 #include <data.h>
|
90 dawes 3.1
91 #define MARK_ON(a) (my_attrs & a) != 0 && (term->flags & (whichone = a)) == 0
92 #define MARK_OFF(a) (my_attrs & a) != 0 && (term->flags & (whichone = a)) != 0
93
94 void Mark_XMC(register TScreen *screen, int param)
95 {
|
96 dawes 3.6 static IChar *glitch;
|
97 dawes 3.1 Boolean found = FALSE;
98 Char my_attrs = (screen->xmc_attributes & XMC_FLAGS);
99 Char whichone = 0;
100
101 if (glitch == 0) {
|
102 dawes 3.6 unsigned len = screen->xmc_glitch;
103 glitch = (IChar *)malloc(len * sizeof(IChar));
104 while (len--)
105 glitch[len] = XMC_GLITCH;
|
106 dawes 3.1 }
107 switch (param) {
108 case -1:/* DEFAULT */
109 case 0: /* FALLTHRU */
|
110 hohndel 3.2 found = MARK_OFF((term->flags & XMC_FLAGS));
|
111 dawes 3.1 break;
112 case 1:
113 found = MARK_ON(BOLD);
114 break;
115 case 4:
116 found = MARK_ON(UNDERLINE);
117 break;
118 case 7:
119 found = MARK_ON(INVERSE);
120 break;
121 case 22:
122 found = MARK_OFF(BOLD);
123 break;
124 case 24:
125 found = MARK_OFF(UNDERLINE);
126 break;
127 case 27:
128 found = MARK_OFF(INVERSE);
129 break;
130 }
131
132 dawes 3.1 /*
133 * Write a glitch with the attributes temporarily set to the new(er)
134 * ones.
135 */
136 if (found) {
137 unsigned save = term->flags;
138 term->flags ^= whichone;
|
139 hohndel 3.2 TRACE(("XMC Writing glitch (%d/%d) after SGR %d\n", my_attrs, whichone, param))
|
140 dawes 3.6 dotext(screen, '?', glitch, screen->xmc_glitch);
|
141 dawes 3.1 term->flags = save;
142 }
143 }
144
145 /*
146 * Force a glitch on cursor movement when we're in standout mode and not at the
147 * end of a line.
148 */
149 void Jump_XMC(register TScreen *screen)
150 {
151 if (!screen->move_sgr_ok
152 && screen->cur_col <= CurMaxCol(screen, screen->cur_row)) {
153 Mark_XMC(screen, -1);
154 }
155 }
156
157 /*
158 * After writing text to the screen, resolve mismatch between the current
159 * location and any attributes that would have been set by preceding locations.
160 */
161 void Resolve_XMC(register TScreen *screen)
162 dawes 3.1 {
163 Boolean changed = False;
164 Char start;
165 Char my_attrs = (screen->xmc_attributes & XMC_FLAGS);
166 int row = screen->cur_row;
167 int col = screen->cur_col;
168
169 /* Find the preceding cell.
170 */
|
171 dawes 3.5 if (getXtermCell(screen, row, col) != XMC_GLITCH) {
|
172 dawes 3.1 if (col != 0) {
173 col--;
174 } else if (!screen->xmc_inline && row != 0) {
175 row--;
176 col = CurMaxCol(screen, row);
177 }
178 }
179 start = (SCRN_BUF_ATTRS(screen, row)[col] & my_attrs);
180
181 /* Now propagate the starting state until we reach a cell which holds
182 * a glitch.
183 */
184 for (;;) {
185 if (col < CurMaxCol(screen, row)) {
186 col++;
187 } else if (!screen->xmc_inline && row < screen->max_row) {
188 row++;
189 col = 0;
190 } else
191 break;
|
192 dawes 3.5 if (getXtermCell(screen, row, col) == XMC_GLITCH)
|
193 dawes 3.1 break;
194 if ((SCRN_BUF_ATTRS(screen, row)[col] & my_attrs) != start) {
195 SCRN_BUF_ATTRS(screen, row)[col] = start |
196 (SCRN_BUF_ATTRS(screen, row)[col] & ~my_attrs);
197 changed = True;
198 }
199 }
200
201 TRACE(("XMC %s (%s:%d/%d) from %d,%d to %d,%d\n",
202 changed ? "Ripple" : "Nochange",
203 term->flags & my_attrs ? "on" : "off",
204 my_attrs, start,
205 screen->cur_row, screen->cur_col, row, col))
206
207 if (changed) {
208 ScrnRefresh (screen, screen->cur_row, 0, row + 1 - screen->cur_row, screen->max_col + 1, True);
209 }
210 }
|