1 /* Copyright (c) 2008, 2009
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Micah Cowan (micah@cowan.name)
5 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
6 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
7 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
8 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
9 * Copyright (c) 1987 Oliver Laumann
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, see
23 * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 ****************************************************************
29 #include <sys/types.h>
31 #ifndef sun /* we want to know about TIOCPKT. */
32 # include <sys/ioctl.h>
41 extern struct display
*display
, *displays
;
42 extern struct win
*fore
; /* for 83 escape */
43 extern struct layer
*flayer
; /* for 83 escape */
45 extern struct NewWindow nwin_default
; /* for ResetWindow() */
46 extern int nversion
; /* numerical version of screen */
47 extern int log_flush
, logtstamp_on
, logtstamp_after
;
48 extern char *logtstamp_string
;
49 extern char *captionstring
;
50 extern char *hstatusstring
;
51 extern char *wliststr
;
53 extern int compacthist
;
56 extern struct acluser
*EffectiveAclUser
;
59 int Z0width
, Z1width
; /* widths for Z0/Z1 switching */
61 /* globals set in WriteString */
62 static struct win
*curr
; /* window we are working on */
63 static int rows
, cols
; /* window size of the curr window */
66 int use_hardstatus
= 1; /* display status line in hs */
68 int use_altscreen
= 0; /* enable alternate screen support? */
70 unsigned char *blank
; /* line filled with spaces */
71 unsigned char *null
; /* line filled with '\0' */
73 struct mline mline_old
;
74 struct mline mline_blank
;
75 struct mline mline_null
;
77 struct mchar mchar_null
;
78 struct mchar mchar_blank
= {' ' /* , 0, 0, ... */};
79 struct mchar mchar_so
= {' ', A_SO
/* , 0, 0, ... */};
81 int renditions
[NUM_RENDS
] = {65529 /* =ub */, 65531 /* =b */};
83 /* keep string_t and string_t_string in sync! */
84 static char *string_t_string
[] =
87 "DCS", /* Device control string */
88 "OSC", /* Operating system command */
89 "APC", /* Application program command */
90 /* - used for status change */
91 "PM", /* Privacy message */
92 "AKA", /* title for current screen */
93 "GM", /* Global message to every display */
94 "STATUS" /* User hardstatus line */
97 /* keep state_t and state_t_string in sync! */
98 static char *state_t_string
[] =
100 "LIT", /* Literal input */
101 "ESC", /* Start of escape sequence */
102 "ASTR", /* Start of control string */
103 "STRESC", /* ESC seen in control string */
104 "CSI", /* Reading arguments in "CSI Pn ;...*/
105 "PRIN", /* Printer mode */
106 "PRINESC", /* ESC seen in printer mode */
107 "PRINCSI", /* CSI seen in printer mode */
108 "PRIN4" /* CSI 4 seen in printer mode */
111 static int Special
__P((int));
112 static void DoESC
__P((int, int));
113 static void DoCSI
__P((int, int));
114 static void StringStart
__P((enum string_t
));
115 static void StringChar
__P((int));
116 static int StringEnd
__P((void));
117 static void PrintStart
__P((void));
118 static void PrintChar
__P((int));
119 static void PrintFlush
__P((void));
121 static void DesignateCharset
__P((int, int));
122 static void MapCharset
__P((int));
123 static void MapCharsetR
__P((int));
125 static void SaveCursor
__P((void));
126 static void RestoreCursor
__P((void));
127 static void BackSpace
__P((void));
128 static void Return
__P((void));
129 static void LineFeed
__P((int));
130 static void ReverseLineFeed
__P((void));
131 static void InsertChar
__P((int));
132 static void DeleteChar
__P((int));
133 static void DeleteLine
__P((int));
134 static void InsertLine
__P((int));
135 static void Scroll
__P((char *, int, int, char *));
136 static void ForwardTab
__P((void));
137 static void BackwardTab
__P((void));
138 static void ClearScreen
__P((void));
139 static void ClearFromBOS
__P((void));
140 static void ClearToEOS
__P((void));
141 static void ClearLineRegion
__P((int, int));
142 static void CursorRight
__P((int));
143 static void CursorUp
__P((int));
144 static void CursorDown
__P((int));
145 static void CursorLeft
__P((int));
146 static void ASetMode
__P((int));
147 static void SelectRendition
__P((void));
148 static void RestorePosRendition
__P((void));
149 static void FillWithEs
__P((void));
150 static void FindAKA
__P((void));
151 static void Report
__P((char *, int, int));
152 static void ScrollRegion
__P((int));
154 static void WAddLineToHist
__P((struct win
*, struct mline
*));
156 static void WLogString
__P((struct win
*, char *, int));
157 static void WReverseVideo
__P((struct win
*, int));
158 static int WindowChangedCheck
__P((char *, int, int *));
159 static void MFixLine
__P((struct win
*, int, struct mchar
*));
160 static void MScrollH
__P((struct win
*, int, int, int, int, int));
161 static void MScrollV
__P((struct win
*, int, int, int, int));
162 static void MClearArea
__P((struct win
*, int, int, int, int, int));
163 static void MInsChar
__P((struct win
*, struct mchar
*, int, int));
164 static void MPutChar
__P((struct win
*, struct mchar
*, int, int));
165 static void MPutStr
__P((struct win
*, char *, int, struct mchar
*, int, int));
166 static void MWrapChar
__P((struct win
*, struct mchar
*, int, int, int, int));
168 static void MBceLine
__P((struct win
*, int, int, int, int));
172 # define CURR_BCE (curr->w_bce ? rend_getbg(&curr->w_rend) : 0)
182 p
->w_StringType
= NONE
;
187 register struct win
*p
;
191 p
->w_wrap
= nwin_default
.wrap
;
202 p
->w_bot
= p
->w_height
- 1;
206 p
->w_StringType
= NONE
;
207 bzero(p
->w_tabs
, p
->w_width
);
208 for (i
= 8; i
< p
->w_width
; i
+= 8)
210 p
->w_rend
= mchar_null
;
215 p
->w_bce
= nwin_default
.bce
;
219 /* adds max 22 bytes */
221 GetAnsiStatus(w
, buf
)
227 if (w
->w_state
== LIT
)
230 strcpy(p
, state_t_string
[w
->w_state
]);
232 if (w
->w_intermediate
)
235 if (w
->w_intermediate
> 0xff)
236 p
+= AddXChar(p
, w
->w_intermediate
>> 8);
237 p
+= AddXChar(p
, w
->w_intermediate
& 0xff);
240 if (w
->w_state
== ASTR
|| w
->w_state
== STRESC
)
241 sprintf(p
, "-%s", string_t_string
[w
->w_StringType
]);
253 p
->w_gr
= nwin_default
.gr
;
254 p
->w_c1
= nwin_default
.c1
;
255 SetCharsets(p
, "BBBB02");
256 if (nwin_default
.charset
)
257 SetCharsets(p
, nwin_default
.charset
);
270 for (i
= 0; i
< 4 && *s
; i
++, s
++)
272 p
->w_charsets
[i
] = ((*s
== 'B') ? ASCII
: *s
);
273 if (*s
&& *s
++ != '.')
274 p
->w_Charset
= s
[-1] - '0';
276 p
->w_CharsetR
= *s
- '0';
278 p
->w_FontL
= p
->w_charsets
[p
->w_Charset
];
279 p
->w_FontR
= p
->w_charsets
[p
->w_CharsetR
];
283 /*****************************************************************/
287 * Here comes the vt100 emulator
289 * - sets timestamp and flags activity in window.
290 * - record program output in window scrollback
291 * - translate program output for the display and put it into the obuf.
295 WriteString(wp
, buf
, len
)
309 WLogString(wp
, buf
, len
);
311 /* set global variables (yuck!) */
313 cols
= curr
->w_width
;
314 rows
= curr
->w_height
;
317 SetTimeout(&curr
->w_silenceev
, curr
->w_silencewait
* 1000);
319 if (curr
->w_monitor
== MON_ON
)
321 debug2("ACTIVITY %d %d\n", curr
->w_monitor
, curr
->w_bell
);
322 curr
->w_monitor
= MON_FOUND
;
329 c
= (unsigned char)*buf
++;
334 curr
->w_rend
.font
= curr
->w_FontL
; /* Default: GL */
337 /* The next part is only for speedup */
338 if (curr
->w_state
== LIT
&&
340 curr
->w_encoding
!= UTF8
&&
343 !is_dw_font(curr
->w_rend
.font
) &&
345 curr
->w_rend
.font
!= KANA
&& !curr
->w_mbcs
&&
349 curr
->w_rend
.font
!= '<' &&
351 c
>= ' ' && c
!= 0x7f &&
352 ((c
& 0x80) == 0 || ((c
>= 0xa0 || !curr
->w_c1
) && !curr
->w_gr
)) && !curr
->w_ss
&&
353 !curr
->w_insert
&& curr
->w_x
< cols
- 1)
355 register int currx
= curr
->w_x
;
358 while (currx
< cols
- 1)
363 c
= (unsigned char)*buf
++;
364 if (c
< ' ' || c
== 0x7f || ((c
& 0x80) && ((c
< 0xa0 && curr
->w_c1
) || curr
->w_gr
)))
370 MPutStr(curr
, imp
, currx
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
371 LPutStr(&curr
->w_layer
, imp
, currx
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
377 /* end of speedup code */
380 if (curr
->w_encoding
== UTF8
)
382 c
= FromUtf8(c
, &curr
->w_decodestate
);
393 debug1("read UNICODE %04x\n", c
);
398 switch (curr
->w_state
)
404 curr
->w_state
= PRINESC
;
414 curr
->w_state
= PRINCSI
;
419 curr
->w_state
= PRIN
;
426 curr
->w_state
= PRIN4
;
432 curr
->w_state
= PRIN
;
441 if (curr
->w_pdisplay
&& curr
->w_pdisplay
->d_printfd
>= 0)
443 close(curr
->w_pdisplay
->d_printfd
);
444 curr
->w_pdisplay
->d_printfd
= -1;
446 curr
->w_pdisplay
= 0;
453 curr
->w_state
= PRIN
;
461 curr
->w_state
= STRESC
;
464 /* special xterm hack: accept SetStatus sequence. Yucc! */
465 /* allow ^E for title escapes */
466 if (!(curr
->w_StringType
== OSC
&& c
< ' ' && c
!= '\005'))
467 if (!curr
->w_c1
|| c
!= ('\\' ^ 0xc0))
478 if (StringEnd() == 0 || len
<= 1)
480 /* check if somewhere a status is displayed */
481 for (cv
= curr
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
483 display
= cv
->c_display
;
484 if (D_status
== STATUS_ON_WIN
)
489 if (len
> IOSIZE
+ 1)
491 curr
->w_outlen
= len
- 1;
492 bcopy(buf
, curr
->w_outbuf
, len
- 1);
493 return; /* wait till status is gone */
500 curr
->w_state
= ASTR
;
511 curr
->w_intermediate
= 0;
512 bzero((char *) curr
->w_args
, MAXARGS
* sizeof(int));
540 debug1("not special. c = %x\n", c
);
541 if (c
>= ' ' && c
<= '/')
543 if (curr
->w_intermediate
)
546 if (curr
->w_intermediate
== '$')
552 curr
->w_intermediate
= c
;
554 else if (c
>= '0' && c
<= '~')
556 DoESC(c
, curr
->w_intermediate
);
569 case '0': case '1': case '2': case '3': case '4':
570 case '5': case '6': case '7': case '8': case '9':
571 if (curr
->w_NumArgs
< MAXARGS
)
573 if (curr
->w_args
[curr
->w_NumArgs
] < 100000000)
574 curr
->w_args
[curr
->w_NumArgs
] =
575 10 * curr
->w_args
[curr
->w_NumArgs
] + (c
- '0');
580 if (curr
->w_NumArgs
< MAXARGS
)
586 if (c
>= '@' && c
<= '~')
588 if (curr
->w_NumArgs
< MAXARGS
)
590 DoCSI(c
, curr
->w_intermediate
);
591 if (curr
->w_state
!= PRIN
)
594 else if ((c
>= ' ' && c
<= '/') || (c
>= '<' && c
<= '?'))
595 curr
->w_intermediate
= curr
->w_intermediate
? -1 : c
;
607 if (c
<= ' ' || c
== 0x7f || (c
>= 0x80 && c
< 0xa0 && curr
->w_c1
))
614 curr
->w_intermediate
= 0;
616 if (curr
->w_autoaka
< 0)
623 if (c
>= 0x80 && c
< 0xa0 && curr
->w_c1
)
625 if ((curr
->w_FontR
& 0xf0) != 0x20
627 || curr
->w_encoding
== UTF8
638 case 0xc0 ^ 'N': /* SS2 */
639 case 0xc0 ^ 'O': /* SS3 */
643 if (curr
->w_autoaka
< 0)
646 curr
->w_intermediate
= 0;
647 bzero((char *) curr
->w_args
, MAXARGS
* sizeof(int));
664 if (c
< 0x80 || curr
->w_gr
== 0)
665 curr
->w_rend
.font
= curr
->w_FontL
;
667 else if (curr
->w_gr
== 2 && !curr
->w_ss
)
668 curr
->w_rend
.font
= curr
->w_FontE
;
671 curr
->w_rend
.font
= curr
->w_FontR
;
676 if (curr
->w_encoding
== UTF8
)
678 if (curr
->w_rend
.font
== '0')
680 struct mchar mc
, *mcp
;
682 debug1("SPECIAL %x\n", c
);
686 mcp
= recode_mchar(&mc
, 0, UTF8
);
687 debug2("%02x %02x\n", mcp
->image
, mcp
->font
);
688 c
= mcp
->image
| mcp
->font
<< 8;
690 curr
->w_rend
.font
= 0;
693 if (curr
->w_encoding
== UTF8
&& utf8_isdouble(c
))
696 if (curr
->w_encoding
== UTF8
&& c
>= 0x0300 && utf8_iscomb(c
))
705 ox
= curr
->w_width
- 1;
710 copy_mline2mchar(&omc
, &curr
->w_mlines
[oy
], ox
);
711 if (omc
.image
== 0xff && omc
.font
== 0xff)
716 copy_mline2mchar(&omc
, &curr
->w_mlines
[oy
], ox
);
722 utf8_handle_comb(c
, &omc
);
723 MFixLine(curr
, oy
, &omc
);
724 copy_mchar2mline(&omc
, &curr
->w_mlines
[oy
], ox
);
725 LPutChar(&curr
->w_layer
, &omc
, ox
, oy
);
726 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
730 font
= curr
->w_rend
.font
;
734 if (font
== KANA
&& curr
->w_encoding
== SJIS
&& curr
->w_mbcs
== 0)
736 /* Lets see if it is the first byte of a kanji */
737 debug1("%x may be first of SJIS\n", c
);
738 if ((0x81 <= c
&& c
<= 0x9f) || (0xe0 <= c
&& c
<= 0xef))
746 if (font
== 031 && c
== 0x80 && !curr
->w_mbcs
)
747 font
= curr
->w_rend
.font
= 0;
748 if (is_dw_font(font
) && c
== ' ')
749 font
= curr
->w_rend
.font
= 0;
750 if (is_dw_font(font
) || curr
->w_mbcs
)
753 if (curr
->w_mbcs
== 0)
758 if (curr
->w_x
== cols
- 1)
760 curr
->w_x
+= curr
->w_wrap
? 1 : -1;
761 debug1("Patched w_x to %d\n", curr
->w_x
);
764 if (curr
->w_encoding
!= UTF8
)
769 if (font
== KANA
&& curr
->w_encoding
== SJIS
)
771 debug2("SJIS !! %x %x\n", c
, t
);
773 * SJIS -> EUC mapping:
775 * 81,82...9f -> 21,23...5d
776 * e0,e1...ef -> 5f,61...7d
780 * 9f-fc -> 21-7e (increment first byte!)
782 if (0x40 <= t
&& t
<= 0xfc && t
!= 0x7f)
784 if (c
<= 0x9f) c
= (c
- 0x81) * 2 + 0x21;
785 else c
= (c
- 0xc1) * 2 + 0x21;
786 if (t
<= 0x7e) t
-= 0x1f;
787 else if (t
<= 0x9e) t
-= 0x20;
789 curr
->w_rend
.font
= KANJI
;
793 /* Incomplete shift-jis - skip first byte */
797 debug2("SJIS after %x %x\n", c
, t
);
800 if (t
&& curr
->w_gr
&& font
!= 030 && font
!= 031)
811 # endif /* DW_CHARS */
812 if (font
== '<' && c
>= ' ')
814 font
= curr
->w_rend
.font
= 0;
818 else if (curr
->w_gr
&& curr
->w_encoding
!= UTF8
)
824 if (c
== 0x80 && font
== 0 && curr
->w_encoding
== GBK
)
828 if (c
< ' ' && font
!= 031)
832 if (c
< ' ') /* this is ugly but kanji support */
833 goto tryagain
; /* prevents nicer programming */
839 curr
->w_rend
.image
= c
;
841 if (curr
->w_encoding
== UTF8
)
842 curr
->w_rend
.font
= c
>> 8;
845 curr
->w_rend
.mbcs
= curr
->w_mbcs
;
847 if (curr
->w_x
< cols
- 1)
851 save_mline(&curr
->w_mlines
[curr
->w_y
], cols
);
852 MInsChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
853 LInsChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
, &mline_old
);
858 MPutChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
859 LPutChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
863 else if (curr
->w_x
== cols
- 1)
865 MPutChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
866 LPutChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
872 MWrapChar(curr
, &curr
->w_rend
, curr
->w_y
, curr
->w_top
, curr
->w_bot
, curr
->w_insert
);
873 LWrapChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_y
, curr
->w_top
, curr
->w_bot
, curr
->w_insert
);
874 if (curr
->w_y
!= curr
->w_bot
&& curr
->w_y
!= curr
->w_height
- 1)
882 curr
->w_rend
.mbcs
= curr
->w_mbcs
= 0;
888 curr
->w_FontL
= curr
->w_charsets
[curr
->w_Charset
];
889 curr
->w_FontR
= curr
->w_charsets
[curr
->w_CharsetR
];
890 curr
->w_rend
.font
= curr
->w_FontL
;
891 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
900 if (!printcmd
&& curr
->w_state
== PRIN
)
905 WLogString(p
, buf
, len
)
912 if (logtstamp_on
&& p
->w_logsilence
>= logtstamp_after
* 2)
914 char *t
= MakeWinMsg(logtstamp_string
, p
, '%');
915 logfwrite(p
->w_log
, t
, strlen(t
)); /* long time no write */
918 if (logfwrite(p
->w_log
, buf
, len
) < 1)
920 WMsg(p
, errno
, "Error writing logfile");
946 WBell(curr
, visual_bell
);
952 case '\017': /* SI */
955 case '\016': /* SO */
964 DoESC(c
, intermediate
)
967 debug2("DoESC: %x - inter = %x\n", c
, intermediate
);
968 switch (intermediate
)
983 curr
->w_tabs
[curr
->w_x
] = 1;
985 case 'Z': /* jph: Identify as VT100 */
986 Report("\033[?%d;%dc", 1, 2);
997 LKeypadMode(&curr
->w_layer
, 0);
998 LCursorkeysMode(&curr
->w_layer
, 0);
1000 WNewAutoFlow(curr
, 1);
1003 SetRendition(&mchar_null);
1005 ChangeScrollRegion(0, rows - 1);
1007 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1010 LKeypadMode(&curr
->w_layer
, curr
->w_keypad
= 1);
1012 WNewAutoFlow(curr
, 0);
1013 #endif /* !TIOCPKT */
1016 LKeypadMode(&curr
->w_layer
, curr
->w_keypad
= 0);
1018 WNewAutoFlow(curr
, 1);
1019 #endif /* !TIOCPKT */
1029 MapCharsetR(G1
); /* LS1R */
1033 MapCharsetR(G2
); /* LS2R */
1036 MapCharsetR(G3
); /* LS3R */
1039 if (curr
->w_charsets
[curr
->w_Charset
] != curr
->w_charsets
[G2
]
1040 || curr
->w_charsets
[curr
->w_CharsetR
] != curr
->w_charsets
[G2
])
1041 curr
->w_FontR
= curr
->w_FontL
= curr
->w_charsets
[curr
->w_ss
= G2
];
1046 if (curr
->w_charsets
[curr
->w_Charset
] != curr
->w_charsets
[G3
]
1047 || curr
->w_charsets
[curr
->w_CharsetR
] != curr
->w_charsets
[G3
])
1048 curr
->w_FontR
= curr
->w_FontL
= curr
->w_charsets
[curr
->w_ss
= G3
];
1053 case 'g': /* VBELL, private screen sequence */
1068 DesignateCharset(c
, G0
);
1071 DesignateCharset(c
, G1
);
1074 DesignateCharset(c
, G2
);
1077 DesignateCharset(c
, G3
);
1081 * ESC $ ( Fn: invoke multi-byte charset, Fn, to G0
1082 * ESC $ Fn: same as above. (old sequence)
1083 * ESC $ ) Fn: invoke multi-byte charset, Fn, to G1
1084 * ESC $ * Fn: invoke multi-byte charset, Fn, to G2
1085 * ESC $ + Fn: invoke multi-byte charset, Fn, to G3
1089 DesignateCharset(c
& 037, G0
);
1092 DesignateCharset(c
& 037, G1
);
1095 DesignateCharset(c
& 037, G2
);
1098 DesignateCharset(c
& 037, G3
);
1106 DoCSI(c
, intermediate
)
1107 int c
, intermediate
;
1109 register int i
, a1
= curr
->w_args
[0], a2
= curr
->w_args
[1];
1111 if (curr
->w_NumArgs
> MAXARGS
)
1112 curr
->w_NumArgs
= MAXARGS
;
1113 switch (intermediate
)
1130 LGotoPos(&curr
->w_layer
, --a2
, --a1
);
1133 if (curr
->w_autoaka
)
1134 curr
->w_autoaka
= a1
+ 1;
1137 if (a1
< 0 || a1
> 2)
1149 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1154 if (a1
< 0 || a1
> 2)
1159 ClearLineRegion(curr
->w_x
, cols
- 1);
1162 ClearLineRegion(0, curr
->w_x
);
1165 ClearLineRegion(0, cols
- 1);
1170 a1
= curr
->w_x
+ (a1
? a1
- 1 : 0);
1171 ClearLineRegion(curr
->w_x
, a1
< cols
? a1
: cols
- 1);
1174 CursorUp(a1
? a1
: 1);
1177 CursorDown(a1
? a1
: 1);
1180 CursorRight(a1
? a1
: 1);
1183 CursorLeft(a1
? a1
: 1);
1187 CursorDown(a1
? a1
: 1); /* positions cursor */
1191 CursorUp(a1
? a1
: 1); /* positions cursor */
1195 curr
->w_x
= a1
? a1
- 1 : 0;
1196 if (curr
->w_x
>= cols
)
1197 curr
->w_x
= cols
- 1;
1198 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1201 curr
->w_y
= a1
? a1
- 1 : 0;
1202 if (curr
->w_y
>= rows
)
1203 curr
->w_y
= rows
- 1;
1204 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1211 curr
->w_tabs
[curr
->w_x
] = 0;
1213 bzero(curr
->w_tabs
, cols
);
1220 if (a1
< 1 || a2
> rows
|| a1
>= a2
)
1222 curr
->w_top
= a1
- 1;
1223 curr
->w_bot
= a2
- 1;
1224 /* ChangeScrollRegion(curr->w_top, curr->w_bot); */
1227 curr
->w_y
= curr
->w_top
;
1231 curr
->w_y
= curr
->w_x
= 0;
1232 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1241 if (curr
->w_layer
.l_cvlist
)
1242 Report("\033[1t", 0, 0);
1244 Report("\033[2t", 0, 0);
1247 LRefreshAll(&curr
->w_layer
, 0);
1250 a1
= strlen(curr
->w_title
);
1251 if ((unsigned)(curr
->w_inlen
+ 5 + a1
) <= sizeof(curr
->w_inbuf
))
1253 bcopy("\033]l", curr
->w_inbuf
+ curr
->w_inlen
, 3);
1254 bcopy(curr
->w_title
, curr
->w_inbuf
+ curr
->w_inlen
+ 3, a1
);
1255 bcopy("\033\\", curr
->w_inbuf
+ curr
->w_inlen
+ 3 + a1
, 2);
1256 curr
->w_inlen
+= 5 + a1
;
1260 a1
= curr
->w_args
[2];
1264 a2
= curr
->w_height
;
1265 if (a1
> 10000 || a2
> 10000)
1267 WChangeSize(curr
, a1
, a2
);
1268 cols
= curr
->w_width
;
1269 rows
= curr
->w_height
;
1291 InsertLine(a1
? a1
: 1);
1294 DeleteLine(a1
? a1
: 1);
1297 DeleteChar(a1
? a1
: 1);
1300 InsertChar(a1
? a1
: 1);
1308 case 'i': /* MC Media Control */
1313 if (a1
== 5) /* Report terminal status */
1314 Report("\033[0n", 0, 0);
1315 else if (a1
== 6) /* Report cursor position */
1316 Report("\033[%d;%dR", curr
->w_y
+ 1, curr
->w_x
+ 1);
1318 case 'c': /* Identify as VT100 */
1320 Report("\033[?%d;%dc", 1, 2);
1322 case 'x': /* decreqtparm */
1323 if (a1
== 0 || a1
== 1)
1324 Report("\033[%d;1;1;112;112;1;0x", a1
+ 2, 0);
1326 case 'p': /* obscure code from a 97801 term */
1327 if (a1
== 6 || a1
== 7)
1329 curr
->w_curinv
= 7 - a1
;
1330 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
1333 case 'S': /* code from a 97801 term / DEC vt400 */
1334 ScrollRegion(a1
? a1
: 1);
1336 case 'T': /* code from a 97801 term / DEC vt400 */
1337 case '^': /* SD as per ISO 6429 */
1338 ScrollRegion(a1
? -a1
: -1);
1343 for (a2
= 0; a2
< curr
->w_NumArgs
; a2
++)
1345 a1
= curr
->w_args
[a2
];
1346 debug2("\\E[?%d%c\n",a1
,c
);
1347 if (c
!= 'h' && c
!= 'l')
1352 case 1: /* CKM: cursor key mode */
1353 LCursorkeysMode(&curr
->w_layer
, curr
->w_cursorkeys
= i
);
1355 WNewAutoFlow(curr
, !i
);
1356 #endif /* !TIOCPKT */
1358 case 2: /* ANM: ansi/vt52 mode */
1363 if (curr
->w_encoding
)
1366 curr
->w_charsets
[0] = curr
->w_charsets
[1] =
1367 curr
->w_charsets
[2] = curr
->w_charsets
[2] =
1368 curr
->w_FontL
= curr
->w_FontR
= ASCII
;
1369 curr
->w_Charset
= 0;
1370 curr
->w_CharsetR
= 2;
1375 case 3: /* COLM: column mode */
1376 i
= (i
? Z0width
: Z1width
);
1377 WChangeSize(curr
, i
, curr
->w_height
);
1378 cols
= curr
->w_width
;
1379 rows
= curr
->w_height
;
1381 /* case 4: SCLM: scrolling mode */
1382 case 5: /* SCNM: screen mode */
1383 if (i
!= curr
->w_revvid
)
1384 WReverseVideo(curr
, i
);
1387 case 6: /* OM: origin mode */
1388 if ((curr
->w_origin
= i
) != 0)
1390 curr
->w_y
= curr
->w_top
;
1394 curr
->w_y
= curr
->w_x
= 0;
1395 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1397 case 7: /* AWM: auto wrap mode */
1400 /* case 8: ARM: auto repeat mode */
1401 /* case 9: INLM: interlace mode */
1402 case 9: /* X10 mouse tracking */
1403 curr
->w_mouse
= i
? 9 : 0;
1404 LMouseMode(&curr
->w_layer
, curr
->w_mouse
);
1406 /* case 10: EDM: edit mode */
1407 /* case 11: LTM: line transmit mode */
1408 /* case 13: SCFDM: space compression / field delimiting */
1409 /* case 14: TEM: transmit execution mode */
1410 /* case 16: EKEM: edit key execution mode */
1411 /* case 18: PFF: Printer term form feed */
1412 /* case 19: PEX: Printer extend screen / scroll. reg */
1413 case 25: /* TCEM: text cursor enable mode */
1414 curr
->w_curinv
= !i
;
1415 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
1417 /* case 34: RLM: Right to left mode */
1418 /* case 35: HEBM: hebrew keyboard map */
1419 /* case 36: HEM: hebrew encoding */
1420 /* case 38: TeK Mode */
1421 /* case 40: 132 col enable */
1422 /* case 42: NRCM: 7bit NRC character mode */
1423 /* case 44: margin bell enable */
1424 case 47: /* xterm-like alternate screen */
1425 case 1047: /* xterm-like alternate screen */
1426 case 1049: /* xterm-like alternate screen */
1430 EnterAltScreen(curr
);
1432 LeaveAltScreen(curr
);
1435 LRefreshAll(&curr
->w_layer
, 0);
1436 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1439 /* case 66: NKM: Numeric keypad appl mode */
1440 /* case 68: KBUM: Keyboard usage mode (data process) */
1441 case 1000: /* VT200 mouse tracking */
1442 case 1001: /* VT200 highlight mouse */
1443 case 1002: /* button event mouse*/
1444 case 1003: /* any event mouse*/
1445 curr
->w_mouse
= i
? a1
: 0;
1446 LMouseMode(&curr
->w_layer
, curr
->w_mouse
);
1454 case 'c': /* secondary DA */
1456 Report("\033[>%d;%d;0c", 83, nversion
); /* 83 == 'S' */
1468 curr
->w_StringType
= type
;
1469 curr
->w_stringp
= curr
->w_string
;
1470 curr
->w_state
= ASTR
;
1477 if (curr
->w_stringp
>= curr
->w_string
+ MAXSTR
- 1)
1478 curr
->w_state
= LIT
;
1480 *(curr
->w_stringp
)++ = c
;
1484 * Do string processing. Returns -1 if output should be suspended
1485 * until status is gone.
1494 curr
->w_state
= LIT
;
1495 *curr
->w_stringp
= '\0';
1496 switch (curr
->w_StringType
)
1498 case OSC
: /* special xterm compatibility hack */
1499 if (curr
->w_string
[0] == ';' || (p
= index(curr
->w_string
, ';')) == 0)
1501 typ
= atoi(curr
->w_string
);
1504 if (typ
== 83) /* 83 = 'S' */
1506 /* special execute commands sequence */
1507 char *args
[MAXARGS
];
1509 struct acluser
*windowuser
;
1511 windowuser
= *FindUserPtr(":window:");
1512 if (windowuser
&& Parse(p
, sizeof(curr
->w_string
) - (p
- curr
->w_string
), args
, argl
))
1514 for (display
= displays
; display
; display
= display
->d_next
)
1515 if (D_forecv
->c_layer
->l_bottom
== &curr
->w_layer
)
1516 break; /* found it */
1517 if (display
== 0 && curr
->w_layer
.l_cvlist
)
1518 display
= curr
->w_layer
.l_cvlist
->c_display
;
1521 EffectiveAclUser
= windowuser
;
1523 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1524 DoCommand(args
, argl
);
1525 EffectiveAclUser
= 0;
1533 if (typ
== 0 || typ
== 1 || typ
== 20 || typ
== 39 || typ
== 49)
1539 if (strcmp(curr
->w_xtermosc
[typ2
], p
))
1541 strncpy(curr
->w_xtermosc
[typ2
], p
, sizeof(curr
->w_xtermosc
[typ2
]) - 1);
1542 curr
->w_xtermosc
[typ2
][sizeof(curr
->w_xtermosc
[typ2
]) - 1] = 0;
1544 for (display
= displays
; display
; display
= display
->d_next
)
1548 if (D_forecv
->c_layer
->l_bottom
== &curr
->w_layer
)
1549 SetXtermOSC(typ2
, curr
->w_xtermosc
[typ2
]);
1550 if ((typ2
== 2 || typ2
== 3) && D_xtermosc
[typ2
])
1555 if (typ
!= 0 && typ
!= 2)
1558 if (typ
< 0 || typ
> 2)
1562 curr
->w_stringp
-= p
- curr
->w_string
;
1563 if (curr
->w_stringp
> curr
->w_string
)
1564 bcopy(p
, curr
->w_string
, curr
->w_stringp
- curr
->w_string
);
1565 *curr
->w_stringp
= '\0';
1568 if (curr
->w_hstatus
)
1570 if (strcmp(curr
->w_hstatus
, curr
->w_string
) == 0)
1571 break; /* not changed */
1572 free(curr
->w_hstatus
);
1573 curr
->w_hstatus
= 0;
1575 if (curr
->w_string
!= curr
->w_stringp
)
1576 curr
->w_hstatus
= SaveStr(curr
->w_string
);
1577 WindowChanged(curr
, 'h');
1581 for (display
= displays
; display
; display
= display
->d_next
)
1583 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
1584 if (cv
->c_layer
->l_bottom
== &curr
->w_layer
)
1586 if (cv
|| curr
->w_StringType
== GM
)
1587 MakeStatus(curr
->w_string
);
1591 LAY_DISPLAYS(&curr
->w_layer
, AddStr(curr
->w_string
));
1594 if (curr
->w_title
== curr
->w_akabuf
&& !*curr
->w_string
)
1596 ChangeAKA(curr
, curr
->w_string
, strlen(curr
->w_string
));
1597 if (!*curr
->w_string
)
1598 curr
->w_autoaka
= curr
->w_y
+ 1;
1609 curr
->w_pdisplay
= 0;
1611 /* find us a nice display to print on, fore prefered */
1612 display
= curr
->w_lastdisp
;
1613 if (!(display
&& curr
== D_fore
&& (printcmd
|| D_PO
)))
1614 for (display
= displays
; display
; display
= display
->d_next
)
1615 if (curr
== D_fore
&& (printcmd
|| D_PO
))
1620 for (cv
= curr
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
1622 display
= cv
->c_display
;
1623 if (printcmd
|| D_PO
)
1629 if (!display
|| display
->d_next
|| !(printcmd
|| D_PO
))
1633 curr
->w_pdisplay
= display
;
1634 curr
->w_stringp
= curr
->w_string
;
1635 curr
->w_state
= PRIN
;
1636 if (printcmd
&& curr
->w_pdisplay
->d_printfd
< 0)
1637 curr
->w_pdisplay
->d_printfd
= printpipe(curr
, printcmd
);
1644 if (curr
->w_stringp
>= curr
->w_string
+ MAXSTR
- 1)
1646 *(curr
->w_stringp
)++ = c
;
1652 display
= curr
->w_pdisplay
;
1653 if (display
&& printcmd
)
1655 char *bp
= curr
->w_string
;
1656 int len
= curr
->w_stringp
- curr
->w_string
;
1658 while (len
&& display
->d_printfd
>= 0)
1660 r
= write(display
->d_printfd
, bp
, len
);
1663 WMsg(curr
, errno
, "printing aborted");
1664 close(display
->d_printfd
);
1665 display
->d_printfd
= -1;
1672 else if (display
&& curr
->w_stringp
> curr
->w_string
)
1675 AddStrn(curr
->w_string
, curr
->w_stringp
- curr
->w_string
);
1679 curr
->w_stringp
= curr
->w_string
;
1684 WNewAutoFlow(win
, on
)
1688 debug1("WNewAutoFlow: %d\n", on
);
1689 if (win
->w_flow
& FLOW_AUTOFLAG
)
1690 win
->w_flow
= FLOW_AUTOFLAG
| (FLOW_AUTO
|FLOW_NOW
) * on
;
1692 win
->w_flow
= (win
->w_flow
& ~FLOW_AUTO
) | FLOW_AUTO
* on
;
1693 LSetFlow(&win
->w_layer
, win
->w_flow
& FLOW_NOW
);
1700 DesignateCharset(c
, n
)
1705 if (c
== ('@' & 037)) /* map JIS 6226 to 0208 */
1710 if (curr
->w_charsets
[n
] != c
)
1712 curr
->w_charsets
[n
] = c
;
1713 if (curr
->w_Charset
== n
)
1716 curr
->w_rend
.font
= curr
->w_FontL
;
1717 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1719 if (curr
->w_CharsetR
== n
)
1729 if (curr
->w_Charset
!= n
)
1731 curr
->w_Charset
= n
;
1732 curr
->w_FontL
= curr
->w_charsets
[n
];
1733 curr
->w_rend
.font
= curr
->w_FontL
;
1734 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1743 if (curr
->w_CharsetR
!= n
)
1745 curr
->w_CharsetR
= n
;
1746 curr
->w_FontR
= curr
->w_charsets
[n
];
1757 curr
->w_Saved_x
= curr
->w_x
;
1758 curr
->w_Saved_y
= curr
->w_y
;
1759 curr
->w_SavedRend
= curr
->w_rend
;
1761 curr
->w_SavedCharset
= curr
->w_Charset
;
1762 curr
->w_SavedCharsetR
= curr
->w_CharsetR
;
1763 bcopy((char *) curr
->w_charsets
, (char *) curr
->w_SavedCharsets
,
1773 LGotoPos(&curr
->w_layer
, curr
->w_Saved_x
, curr
->w_Saved_y
);
1774 curr
->w_x
= curr
->w_Saved_x
;
1775 curr
->w_y
= curr
->w_Saved_y
;
1776 curr
->w_rend
= curr
->w_SavedRend
;
1778 bcopy((char *) curr
->w_SavedCharsets
, (char *) curr
->w_charsets
,
1780 curr
->w_Charset
= curr
->w_SavedCharset
;
1781 curr
->w_CharsetR
= curr
->w_SavedCharsetR
;
1783 curr
->w_FontL
= curr
->w_charsets
[curr
->w_Charset
];
1784 curr
->w_FontR
= curr
->w_charsets
[curr
->w_CharsetR
];
1786 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1796 else if (curr
->w_wrap
&& curr
->w_y
> 0)
1798 curr
->w_x
= cols
- 1;
1801 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1810 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1817 /* out_mode: 0=lf, 1=cr+lf */
1820 if (curr
->w_y
!= curr
->w_bot
) /* Don't scroll */
1822 if (curr
->w_y
< rows
-1)
1824 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1827 if (curr
->w_autoaka
> 1)
1829 MScrollV(curr
, 1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1830 LScrollV(&curr
->w_layer
, 1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1831 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1837 if (curr
->w_y
== curr
->w_top
)
1839 MScrollV(curr
, -1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1840 LScrollV(&curr
->w_layer
, -1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1841 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1843 else if (curr
->w_y
> 0)
1851 register int y
= curr
->w_y
, x
= curr
->w_x
;
1857 save_mline(&curr
->w_mlines
[y
], cols
);
1858 MScrollH(curr
, -n
, y
, x
, curr
->w_width
- 1, CURR_BCE
);
1859 LScrollH(&curr
->w_layer
, -n
, y
, x
, curr
->w_width
- 1, CURR_BCE
, &mline_old
);
1860 LGotoPos(&curr
->w_layer
, x
, y
);
1867 register int y
= curr
->w_y
, x
= curr
->w_x
;
1871 save_mline(&curr
->w_mlines
[y
], cols
);
1872 MScrollH(curr
, n
, y
, x
, curr
->w_width
- 1, CURR_BCE
);
1873 LScrollH(&curr
->w_layer
, n
, y
, x
, curr
->w_width
- 1, CURR_BCE
, &mline_old
);
1874 LGotoPos(&curr
->w_layer
, x
, y
);
1881 if (curr
->w_y
< curr
->w_top
|| curr
->w_y
> curr
->w_bot
)
1883 if (n
> curr
->w_bot
- curr
->w_y
+ 1)
1884 n
= curr
->w_bot
- curr
->w_y
+ 1;
1885 MScrollV(curr
, n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1886 LScrollV(&curr
->w_layer
, n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1887 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1894 if (curr
->w_y
< curr
->w_top
|| curr
->w_y
> curr
->w_bot
)
1896 if (n
> curr
->w_bot
- curr
->w_y
+ 1)
1897 n
= curr
->w_bot
- curr
->w_y
+ 1;
1898 MScrollV(curr
, -n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1899 LScrollV(&curr
->w_layer
, -n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1900 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1907 MScrollV(curr
, n
, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1908 LScrollV(&curr
->w_layer
, n
, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1909 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1916 register int x
= curr
->w_x
;
1923 if (curr
->w_tabs
[x
] && x
< cols
- 1)
1925 while (x
< cols
- 1 && !curr
->w_tabs
[x
])
1928 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1934 register int x
= curr
->w_x
;
1936 if (curr
->w_tabs
[x
] && x
> 0)
1938 while (x
> 0 && !curr
->w_tabs
[x
])
1941 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1947 LClearArea(&curr
->w_layer
, 0, 0, curr
->w_width
- 1, curr
->w_height
- 1, CURR_BCE
, 1);
1949 MScrollV(curr
, curr
->w_height
, 0, curr
->w_height
- 1, CURR_BCE
);
1951 MClearArea(curr
, 0, 0, curr
->w_width
- 1, curr
->w_height
- 1, CURR_BCE
);
1958 register int y
= curr
->w_y
, x
= curr
->w_x
;
1960 LClearArea(&curr
->w_layer
, 0, 0, x
, y
, CURR_BCE
, 1);
1961 MClearArea(curr
, 0, 0, x
, y
, CURR_BCE
);
1962 RestorePosRendition();
1968 register int y
= curr
->w_y
, x
= curr
->w_x
;
1970 if (x
== 0 && y
== 0)
1973 RestorePosRendition();
1976 LClearArea(&curr
->w_layer
, x
, y
, cols
- 1, rows
- 1, CURR_BCE
, 1);
1977 MClearArea(curr
, x
, y
, cols
- 1, rows
- 1, CURR_BCE
);
1978 RestorePosRendition();
1982 ClearLineRegion(from
, to
)
1985 register int y
= curr
->w_y
;
1986 LClearArea(&curr
->w_layer
, from
, y
, to
, y
, CURR_BCE
, 1);
1987 MClearArea(curr
, from
, y
, to
, y
, CURR_BCE
);
1988 RestorePosRendition();
1995 register int x
= curr
->w_x
;
2002 if ((curr
->w_x
+= n
) >= cols
)
2003 curr
->w_x
= cols
- 1;
2004 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2011 if (curr
->w_y
< curr
->w_top
) /* if above scrolling rgn, */
2013 if ((curr
->w_y
-= n
) < 0) /* ignore its limits */
2017 if ((curr
->w_y
-= n
) < curr
->w_top
)
2018 curr
->w_y
= curr
->w_top
;
2019 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2026 if (curr
->w_y
> curr
->w_bot
) /* if below scrolling rgn, */
2028 if ((curr
->w_y
+= n
) > rows
- 1) /* ignore its limits */
2029 curr
->w_y
= rows
- 1;
2032 if ((curr
->w_y
+= n
) > curr
->w_bot
)
2033 curr
->w_y
= curr
->w_bot
;
2034 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2041 if ((curr
->w_x
-= n
) < 0)
2043 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2052 for (i
= 0; i
< curr
->w_NumArgs
; ++i
)
2054 switch (curr
->w_args
[i
])
2056 /* case 2: KAM: Lock keyboard */
2057 case 4: /* IRM: Insert mode */
2058 curr
->w_insert
= on
;
2059 LAY_DISPLAYS(&curr
->w_layer
, InsertMode(on
));
2061 /* case 12: SRM: Echo mode on */
2062 case 20: /* LNM: Linefeed mode */
2063 curr
->w_autolf
= on
;
2066 curr
->w_curvvis
= !on
;
2067 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
2075 static char rendlist
[] =
2077 ~((1 << NATTR
) - 1), A_BD
, A_DI
, A_SO
, A_US
, A_BL
, 0, A_RV
, 0, 0,
2078 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2079 0, 0, ~(A_BD
|A_SO
|A_DI
), ~A_SO
, ~A_US
, ~A_BL
, 0, ~A_RV
2086 register int j
, i
= 0, a
= curr
->w_rend
.attr
, c
= curr
->w_rend
.color
;
2088 int cx
= curr
->w_rend
.colorx
;
2091 register int j
, i
= 0, a
= curr
->w_rend
.attr
;
2096 j
= curr
->w_args
[i
];
2098 if ((j
== 38 || j
== 48) && i
+ 2 < curr
->w_NumArgs
&& curr
->w_args
[i
+ 1] == 5)
2103 jj
= curr
->w_args
[i
];
2104 if (jj
< 0 || jj
> 255)
2109 c
= (c
& 0xf0) | ((jj
& 0x0f) ^ 9);
2111 if (jj
>= 8 && jj
< 16)
2115 a
= (a
& 0xbf) | (jj
& 8 ? 0x40 : 0);
2116 cx
= (cx
& 0xf0) | (jj
>> 4 & 0x0f);
2120 c
= (c
& 0x0f) | ((jj
& 0x0f) ^ 9) << 4;
2122 if (jj
>= 8 && jj
< 16)
2126 cx
= (cx
& 0x0f) | (jj
& 0xf0);
2130 jj
= color256to16(jj
) + 30;
2133 j
= j
== 38 ? jj
: jj
+ 10;
2137 if (j
== 0 || (j
>= 30 && j
<= 39 && j
!= 38))
2139 if (j
== 0 || (j
>= 40 && j
<= 49 && j
!= 48))
2141 if (j
>= 90 && j
<= 97)
2143 if (j
>= 100 && j
<= 107)
2146 if (j
>= 90 && j
<= 97)
2148 if (j
>= 100 && j
<= 107)
2150 if (j
>= 30 && j
<= 39 && j
!= 38)
2151 c
= (c
& 0xf0) | ((j
- 30) ^ 9);
2152 else if (j
>= 40 && j
<= 49 && j
!= 48)
2153 c
= (c
& 0x0f) | (((j
- 40) ^ 9) << 4);
2157 if (j
== 0 || (j
>= 30 && j
<= 39 && j
!= 38))
2159 if (j
== 0 || (j
>= 40 && j
<= 49 && j
!= 48))
2163 if (j
< 0 || j
>= (int)(sizeof(rendlist
)/sizeof(*rendlist
)))
2166 if (j
& (1 << NATTR
))
2171 while (++i
< curr
->w_NumArgs
);
2172 curr
->w_rend
.attr
= a
;
2174 curr
->w_rend
.color
= c
;
2176 curr
->w_rend
.colorx
= cx
;
2179 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
2186 register unsigned char *p
, *ep
;
2188 LClearAll(&curr
->w_layer
, 1);
2189 curr
->w_y
= curr
->w_x
= 0;
2190 for (i
= 0; i
< rows
; ++i
)
2192 clear_mline(&curr
->w_mlines
[i
], 0, cols
+ 1);
2193 p
= curr
->w_mlines
[i
].image
;
2198 LRefreshAll(&curr
->w_layer
, 1);
2203 * Ugly autoaka hack support:
2204 * ChangeAKA() sets a new aka
2205 * FindAKA() searches for an autoaka match
2216 for (i
= 0; l
> 0; l
--)
2218 if (p
->w_akachange
+ i
== p
->w_akabuf
+ sizeof(p
->w_akabuf
) - 1)
2220 c
= (unsigned char)*s
++;
2223 if (c
< 32 || c
== 127 || (c
>= 128 && c
< 160 && p
->w_c1
))
2225 p
->w_akachange
[i
++] = c
;
2227 p
->w_akachange
[i
] = 0;
2228 p
->w_title
= p
->w_akachange
;
2229 if (p
->w_akachange
!= p
->w_akabuf
)
2230 if (p
->w_akachange
[0] == 0 || p
->w_akachange
[-1] == ':')
2231 p
->w_title
= p
->w_akabuf
+ strlen(p
->w_akabuf
) + 1;
2232 WindowChanged(p
, 't');
2233 WindowChanged((struct win
*)0, 'w');
2234 WindowChanged((struct win
*)0, 'W');
2240 register unsigned char *cp
, *line
;
2241 register struct win
*wp
= curr
;
2242 register int len
= strlen(wp
->w_akabuf
);
2245 y
= (wp
->w_autoaka
> 0 && wp
->w_autoaka
<= wp
->w_height
) ? wp
->w_autoaka
- 1 : wp
->w_y
;
2248 cp
= line
= wp
->w_mlines
[y
].image
;
2249 if (wp
->w_autoaka
> 0 && *wp
->w_akabuf
!= '\0')
2253 if (cp
- line
>= cols
- len
)
2255 if (++y
== wp
->w_autoaka
&& y
< rows
)
2259 if (strncmp((char *)cp
, wp
->w_akabuf
, len
) == 0)
2265 for (len
= cols
- (cp
- line
); len
&& *cp
== ' '; len
--, cp
++)
2269 if (wp
->w_autoaka
> 0 && (*cp
== '!' || *cp
== '%' || *cp
== '^'))
2274 while (len
&& *cp
!= ' ')
2280 ChangeAKA(wp
, (char *)line
, cp
- line
);
2287 RestorePosRendition()
2289 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2290 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
2293 /* Send a terminal report as if it were typed. */
2300 char rbuf
[40]; /* enough room for all replys */
2302 sprintf(rbuf
, fmt
, n1
, n2
);
2308 if ((unsigned)(curr
->w_pwin
->p_inlen
+ len
) <= sizeof(curr
->w_pwin
->p_inbuf
))
2310 bcopy(rbuf
, curr
->w_pwin
->p_inbuf
+ curr
->w_pwin
->p_inlen
, len
);
2311 curr
->w_pwin
->p_inlen
+= len
;
2317 if ((unsigned)(curr
->w_inlen
+ len
) <= sizeof(curr
->w_inbuf
))
2319 bcopy(rbuf
, curr
->w_inbuf
+ curr
->w_inlen
, len
);
2320 curr
->w_inlen
+= len
;
2328 *====================================================================*
2329 *====================================================================*
2332 /**********************************************************************
2344 struct mline
*ml
= &p
->w_mlines
[y
];
2345 if (mc
->attr
&& ml
->attr
== null
)
2347 if ((ml
->attr
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2350 mc
->attr
= p
->w_rend
.attr
= 0;
2351 WMsg(p
, 0, "Warning: no space for attr - turned off");
2355 if (mc
->font
&& ml
->font
== null
)
2357 if ((ml
->font
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2360 p
->w_FontL
= p
->w_charsets
[p
->w_ss
? p
->w_ss
: p
->w_Charset
] = 0;
2361 p
->w_FontR
= p
->w_charsets
[p
->w_ss
? p
->w_ss
: p
->w_CharsetR
] = 0;
2362 mc
->font
= p
->w_rend
.font
= 0;
2363 WMsg(p
, 0, "Warning: no space for font - turned off");
2368 if (mc
->color
&& ml
->color
== null
)
2370 if ((ml
->color
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2373 mc
->color
= p
->w_rend
.color
= 0;
2374 WMsg(p
, 0, "Warning: no space for color - turned off");
2378 if (mc
->colorx
&& ml
->colorx
== null
)
2380 if ((ml
->colorx
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2383 mc
->colorx
= p
->w_rend
.colorx
= 0;
2384 WMsg(p
, 0, "Warning: no space for extended colors - turned off");
2391 /*****************************************************************/
2394 # define MKillDwRight(p, ml, x) \
2395 if (dw_right(ml, x, p->w_encoding)) \
2398 copy_mchar2mline(&mchar_blank, ml, x - 1); \
2399 copy_mchar2mline(&mchar_blank, ml, x); \
2402 # define MKillDwLeft(p, ml, x) \
2403 if (dw_left(ml, x, p->w_encoding)) \
2405 copy_mchar2mline(&mchar_blank, ml, x); \
2406 copy_mchar2mline(&mchar_blank, ml, x + 1); \
2409 # define MKillDwRight(p, ml, x) ;
2410 # define MKillDwLeft(p, ml, x) ;
2414 MScrollH(p
, n
, y
, xs
, xe
, bce
)
2416 int n
, y
, xs
, xe
, bce
;
2422 ml
= &p
->w_mlines
[y
];
2423 MKillDwRight(p
, ml
, xs
);
2424 MKillDwLeft(p
, ml
, xe
);
2427 if (xe
- xs
+ 1 > n
)
2429 MKillDwRight(p
, ml
, xs
+ n
);
2430 bcopy_mline(ml
, xs
+ n
, xs
, xe
+ 1 - xs
- n
);
2434 clear_mline(ml
, xe
+ 1 - n
, n
);
2437 MBceLine(p
, y
, xe
+ 1 - n
, n
, bce
);
2443 if (xe
- xs
+ 1 > n
)
2445 MKillDwLeft(p
, ml
, xe
- n
);
2446 bcopy_mline(ml
, xs
, xs
+ n
, xe
+ 1 - xs
- n
);
2450 clear_mline(ml
, xs
, n
);
2453 MBceLine(p
, y
, xs
, n
, bce
);
2459 MScrollV(p
, n
, ys
, ye
, bce
)
2464 struct mline tmp
[256];
2473 MScrollV(p
, n
- 256, ys
, ye
, bce
);
2476 if (ye
- ys
+ 1 < n
)
2481 ye
= MFindUsedLine(p
, ye
, ys
);
2482 if (ye
- ys
+ 1 < n
)
2489 ml
= p
->w_mlines
+ ys
;
2490 for (i
= ys
; i
< ys
+ n
; i
++, ml
++)
2494 WAddLineToHist(p
, ml
);
2496 if (ml
->attr
!= null
)
2500 if (ml
->font
!= null
)
2505 if (ml
->color
!= null
)
2509 if (ml
->colorx
!= null
)
2514 bclear((char *)ml
->image
, p
->w_width
+ 1);
2517 MBceLine(p
, i
, 0, p
->w_width
, bce
);
2520 /* switch 'em over */
2521 cnt1
= n
* sizeof(struct mline
);
2522 cnt2
= (ye
- ys
+ 1 - n
) * sizeof(struct mline
);
2524 Scroll((char *)(p
->w_mlines
+ ys
), cnt1
, cnt2
, (char *)tmp
);
2530 MScrollV(p
, n
+ 256, ys
, ye
, bce
);
2534 if (ye
- ys
+ 1 < n
)
2537 ml
= p
->w_mlines
+ ye
;
2539 for (i
= ye
; i
> ye
- n
; i
--, ml
--)
2541 if (ml
->attr
!= null
)
2545 if (ml
->font
!= null
)
2550 if (ml
->color
!= null
)
2554 if (ml
->colorx
!= null
)
2559 bclear((char *)ml
->image
, p
->w_width
+ 1);
2562 MBceLine(p
, i
, 0, p
->w_width
, bce
);
2565 cnt1
= n
* sizeof(struct mline
);
2566 cnt2
= (ye
- ys
+ 1 - n
) * sizeof(struct mline
);
2568 Scroll((char *)(p
->w_mlines
+ ys
), cnt2
, cnt1
, (char *)tmp
);
2573 Scroll(cp
, cnt1
, cnt2
, tmp
)
2581 bcopy(cp
, tmp
, cnt1
);
2582 bcopy(cp
+ cnt1
, cp
, cnt2
);
2583 bcopy(tmp
, cp
+ cnt2
, cnt1
);
2587 bcopy(cp
+ cnt1
, tmp
, cnt2
);
2588 bcopy(cp
, cp
+ cnt2
, cnt1
);
2589 bcopy(tmp
, cp
, cnt2
);
2594 MClearArea(p
, xs
, ys
, xe
, ye
, bce
)
2596 int xs
, ys
, xe
, ye
, bce
;
2602 /* Check for zero-height window */
2603 if (ys
< 0 || ye
< ys
)
2606 /* check for magic margin condition */
2607 if (xs
>= p
->w_width
)
2608 xs
= p
->w_width
- 1;
2609 if (xe
>= p
->w_width
)
2610 xe
= p
->w_width
- 1;
2612 MKillDwRight(p
, p
->w_mlines
+ ys
, xs
);
2613 MKillDwLeft(p
, p
->w_mlines
+ ye
, xe
);
2615 ml
= p
->w_mlines
+ ys
;
2616 for (y
= ys
; y
<= ye
; y
++, ml
++)
2618 xxe
= (y
== ye
) ? xe
: p
->w_width
- 1;
2621 clear_mline(ml
, xs
, n
);
2624 MBceLine(p
, y
, xs
, xs
+ n
- 1, bce
);
2631 MInsChar(p
, c
, x
, y
)
2639 ASSERT(x
>= 0 && x
< p
->w_width
);
2641 ml
= p
->w_mlines
+ y
;
2642 n
= p
->w_width
- x
- 1;
2643 MKillDwRight(p
, ml
, x
);
2646 MKillDwRight(p
, ml
, p
->w_width
- 1);
2647 bcopy_mline(ml
, x
, x
+ 1, n
);
2649 copy_mchar2mline(c
, ml
, x
);
2655 MKillDwRight(p
, ml
, p
->w_width
- 1);
2656 bcopy_mline(ml
, x
+ 1, x
+ 2, n
);
2658 copy_mchar2mline(c
, ml
, x
+ 1);
2659 ml
->image
[x
+ 1] = c
->mbcs
;
2661 if (p
->w_encoding
!= UTF8
)
2662 ml
->font
[x
+ 1] |= 0x80;
2663 else if (p
->w_encoding
== UTF8
&& c
->mbcs
)
2664 ml
->font
[x
+ 1] = c
->mbcs
;
2666 ml
->font
[x
+ 1] |= 0x80;
2673 MPutChar(p
, c
, x
, y
)
2681 ml
= &p
->w_mlines
[y
];
2682 MKillDwRight(p
, ml
, x
);
2683 MKillDwLeft(p
, ml
, x
);
2684 copy_mchar2mline(c
, ml
, x
);
2688 MKillDwLeft(p
, ml
, x
+ 1);
2689 copy_mchar2mline(c
, ml
, x
+ 1);
2690 ml
->image
[x
+ 1] = c
->mbcs
;
2692 if (p
->w_encoding
!= UTF8
)
2693 ml
->font
[x
+ 1] |= 0x80;
2694 else if (p
->w_encoding
== UTF8
&& c
->mbcs
)
2695 ml
->font
[x
+ 1] = c
->mbcs
;
2697 ml
->font
[x
+ 1] |= 0x80;
2705 MWrapChar(p
, c
, y
, top
, bot
, ins
)
2715 bce
= rend_getbg(c
);
2720 ml
= &p
->w_mlines
[y
];
2721 copy_mchar2mline(&mchar_null
, ml
, p
->w_width
);
2723 MScrollV(p
, 1, top
, bot
, bce
);
2724 else if (y
< p
->w_height
- 1)
2727 MInsChar(p
, c
, 0, y
);
2729 MPutChar(p
, c
, 0, y
);
2733 MPutStr(p
, s
, n
, r
, x
, y
)
2747 ml
= &p
->w_mlines
[y
];
2748 MKillDwRight(p
, ml
, x
);
2749 MKillDwLeft(p
, ml
, x
+ n
- 1);
2750 bcopy(s
, (char *)ml
->image
+ x
, n
);
2752 for (i
= n
; i
-- > 0;)
2756 for (i
= n
; i
-- > 0;)
2761 for (i
= n
; i
-- > 0;)
2765 for (i
= n
; i
-- > 0;)
2773 MBceLine(p
, y
, xs
, xe
, bce
)
2782 rend_setbg(&mc
, bce
);
2783 MFixLine(p
, y
, &mc
);
2784 ml
= p
->w_mlines
+ y
;
2787 for (x
= xs
; x
<= xe
; x
++)
2788 ml
->attr
[x
] = mc
.attr
;
2791 for (x
= xs
; x
<= xe
; x
++)
2792 ml
->color
[x
] = mc
.color
;
2795 for (x
= xs
; x
<= xe
; x
++)
2796 ml
->colorx
[x
] = mc
.colorx
;
2804 WAddLineToHist(wp
, ml
)
2808 register unsigned char *q
, *o
;
2811 if (wp
->w_histheight
== 0)
2813 hml
= &wp
->w_hlines
[wp
->w_histidx
];
2814 q
= ml
->image
; ml
->image
= hml
->image
; hml
->image
= q
;
2816 q
= ml
->attr
; o
= hml
->attr
; hml
->attr
= q
; ml
->attr
= null
;
2821 q
= ml
->font
; o
= hml
->font
; hml
->font
= q
; ml
->font
= null
;
2827 q
= ml
->color
; o
= hml
->color
; hml
->color
= q
; ml
->color
= null
;
2831 q
= ml
->colorx
; o
= hml
->colorx
; hml
->colorx
= q
; ml
->colorx
= null
;
2837 if (++wp
->w_histidx
>= wp
->w_histheight
)
2843 MFindUsedLine(p
, ye
, ys
)
2848 struct mline
*ml
= p
->w_mlines
+ ye
;
2850 debug2("MFindUsedLine: %d %d\n", ye
, ys
);
2851 for (y
= ye
; y
>= ys
; y
--, ml
--)
2853 if (bcmp((char*)ml
->image
, blank
, p
->w_width
))
2855 if (ml
->attr
!= null
&& bcmp((char*)ml
->attr
, null
, p
->w_width
))
2858 if (ml
->color
!= null
&& bcmp((char*)ml
->color
, null
, p
->w_width
))
2861 if (ml
->colorx
!= null
&& bcmp((char*)ml
->colorx
, null
, p
->w_width
))
2866 debug1("MFindUsedLine returning %d\n", y
);
2872 *====================================================================*
2873 *====================================================================*
2877 * Tricky: send only one bell even if the window is displayed
2886 for (display
= displays
; display
; display
= display
->d_next
)
2888 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2889 if (cv
->c_layer
->l_bottom
== &p
->w_layer
)
2893 else if (cv
&& D_VB
)
2896 p
->w_bell
= visual
? BELL_VISUAL
: BELL_FOUND
;
2901 * This should be reverse video.
2902 * Only change video if window is fore.
2903 * Because it is used in some termcaps to emulate
2904 * a visual bell we do this hack here.
2905 * (screen uses \Eg as special vbell sequence)
2908 WReverseVideo(p
, on
)
2913 for (cv
= p
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
2915 display
= cv
->c_display
;
2919 if (!on
&& p
->w_revvid
&& !D_CVR
)
2924 p
->w_bell
= BELL_VISUAL
;
2935 extern struct layer
*flayer
;
2936 struct layer
*oldflayer
= flayer
;
2937 flayer
= &p
->w_layer
;
2943 WChangeSize(p
, w
, h
)
2950 if (p
->w_layer
.l_cvlist
== 0)
2952 /* window not displayed -> works always */
2953 ChangeWindowSize(p
, w
, h
, p
->w_histheight
);
2956 for (cv
= p
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
2958 display
= cv
->c_display
;
2960 continue; /* change only fore */
2963 if (D_CZ0
&& (w
== Z0width
|| w
== Z1width
))
2966 if (cv
== 0 && wok
== 0) /* can't change any display */
2970 ChangeWindowSize(p
, w
, h
, p
->w_histheight
);
2971 for (display
= displays
; display
; display
= display
->d_next
)
2975 if (D_cvlist
&& D_cvlist
->c_next
== 0)
2976 ResizeDisplay(w
, h
);
2978 ResizeDisplay(w
, D_height
);
2979 ResizeLayersToCanvases(); /* XXX Hmm ? */
2982 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2983 if (cv
->c_layer
->l_bottom
== &p
->w_layer
)
2991 WindowChangedCheck(s
, what
, hp
)
3000 if (*s
++ != (hp
? '%' : '\005'))
3005 while (*s
>= '0' && *s
<= '9')
3014 if (*s
== what
|| ((*s
| l
) == what
) || what
== 'd')
3025 WindowChanged(p
, what
)
3029 int inwstr
, inhstr
, inlstr
;
3030 int inwstrh
= 0, inhstrh
= 0, inlstrh
= 0;
3032 struct display
*olddisplay
= display
;
3035 inwstr
= inhstr
= 0;
3039 WindowChanged((struct win
*)0, 'w'|0x100);
3040 WindowChanged((struct win
*)0, 'W'|0x100);
3045 inwstr
= WindowChangedCheck(captionstring
, what
, &inwstrh
);
3046 inhstr
= WindowChangedCheck(hstatusstring
, what
, &inhstrh
);
3047 inlstr
= WindowChangedCheck(wliststr
, what
, &inlstrh
);
3051 inwstr
= inhstr
= 0;
3057 for (display
= displays
; display
; display
= display
->d_next
)
3061 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
3063 if (inlstr
|| (inlstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3064 WListUpdatecv(cv
, (struct win
*)0);
3065 p
= Layer2Window(cv
->c_layer
);
3066 if (inwstr
|| (inwstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3067 if (cv
->c_ye
+ 1 < D_height
)
3068 RefreshLine(cv
->c_ye
+ 1, 0, D_width
- 1, 0);
3071 if (inhstr
|| (inhstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3073 if (ox
!= -1 && ox
!= -1)
3076 display
= olddisplay
;
3080 if (p
->w_hstatus
&& *p
->w_hstatus
&& (inwstrh
|| inhstrh
|| inlstrh
) && WindowChangedCheck(p
->w_hstatus
, what
, (int *)0))
3086 if (!inwstr
&& !inhstr
&& !inlstr
)
3088 for (display
= displays
; display
; display
= display
->d_next
)
3093 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
3096 WListUpdatecv(cv
, p
);
3097 if (Layer2Window(cv
->c_layer
) != p
)
3100 if (inwstr
&& cv
->c_ye
+ 1 < D_height
)
3101 RefreshLine(cv
->c_ye
+ 1, 0, D_width
- 1, 0);
3103 if (got
&& inhstr
&& p
== D_fore
)
3105 if (ox
!= -1 && ox
!= -1)
3108 display
= olddisplay
;