d6952ea6e7ab7595bcac126704df12bc1c03264d
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 /* keep string_t and string_t_string in sync! */
82 static char *string_t_string
[] =
85 "DCS", /* Device control string */
86 "OSC", /* Operating system command */
87 "APC", /* Application program command */
88 /* - used for status change */
89 "PM", /* Privacy message */
90 "AKA", /* title for current screen */
91 "GM", /* Global message to every display */
92 "STATUS" /* User hardstatus line */
95 /* keep state_t and state_t_string in sync! */
96 static char *state_t_string
[] =
98 "LIT", /* Literal input */
99 "ESC", /* Start of escape sequence */
100 "ASTR", /* Start of control string */
101 "STRESC", /* ESC seen in control string */
102 "CSI", /* Reading arguments in "CSI Pn ;...*/
103 "PRIN", /* Printer mode */
104 "PRINESC", /* ESC seen in printer mode */
105 "PRINCSI", /* CSI seen in printer mode */
106 "PRIN4" /* CSI 4 seen in printer mode */
109 static int Special
__P((int));
110 static void DoESC
__P((int, int));
111 static void DoCSI
__P((int, int));
112 static void StringStart
__P((enum string_t
));
113 static void StringChar
__P((int));
114 static int StringEnd
__P((void));
115 static void PrintStart
__P((void));
116 static void PrintChar
__P((int));
117 static void PrintFlush
__P((void));
119 static void DesignateCharset
__P((int, int));
120 static void MapCharset
__P((int));
121 static void MapCharsetR
__P((int));
123 static void SaveCursor
__P((void));
124 static void RestoreCursor
__P((void));
125 static void BackSpace
__P((void));
126 static void Return
__P((void));
127 static void LineFeed
__P((int));
128 static void ReverseLineFeed
__P((void));
129 static void InsertChar
__P((int));
130 static void DeleteChar
__P((int));
131 static void DeleteLine
__P((int));
132 static void InsertLine
__P((int));
133 static void Scroll
__P((char *, int, int, char *));
134 static void ForwardTab
__P((void));
135 static void BackwardTab
__P((void));
136 static void ClearScreen
__P((void));
137 static void ClearFromBOS
__P((void));
138 static void ClearToEOS
__P((void));
139 static void ClearLineRegion
__P((int, int));
140 static void CursorRight
__P((int));
141 static void CursorUp
__P((int));
142 static void CursorDown
__P((int));
143 static void CursorLeft
__P((int));
144 static void ASetMode
__P((int));
145 static void SelectRendition
__P((void));
146 static void RestorePosRendition
__P((void));
147 static void FillWithEs
__P((void));
148 static void FindAKA
__P((void));
149 static void Report
__P((char *, int, int));
150 static void ScrollRegion
__P((int));
152 static void WAddLineToHist
__P((struct win
*, struct mline
*));
154 static void WLogString
__P((struct win
*, char *, int));
155 static void WReverseVideo
__P((struct win
*, int));
156 static int WindowChangedCheck
__P((char *, int, int *));
157 static void MFixLine
__P((struct win
*, int, struct mchar
*));
158 static void MScrollH
__P((struct win
*, int, int, int, int, int));
159 static void MScrollV
__P((struct win
*, int, int, int, int));
160 static void MClearArea
__P((struct win
*, int, int, int, int, int));
161 static void MInsChar
__P((struct win
*, struct mchar
*, int, int));
162 static void MPutChar
__P((struct win
*, struct mchar
*, int, int));
163 static void MPutStr
__P((struct win
*, char *, int, struct mchar
*, int, int));
164 static void MWrapChar
__P((struct win
*, struct mchar
*, int, int, int, int));
166 static void MBceLine
__P((struct win
*, int, int, int, int));
170 # define CURR_BCE (curr->w_bce ? rend_getbg(&curr->w_rend) : 0)
180 p
->w_StringType
= NONE
;
185 register struct win
*p
;
189 p
->w_wrap
= nwin_default
.wrap
;
200 p
->w_bot
= p
->w_height
- 1;
204 p
->w_StringType
= NONE
;
205 bzero(p
->w_tabs
, p
->w_width
);
206 for (i
= 8; i
< p
->w_width
; i
+= 8)
208 p
->w_rend
= mchar_null
;
213 p
->w_bce
= nwin_default
.bce
;
217 /* adds max 22 bytes */
219 GetAnsiStatus(w
, buf
)
225 if (w
->w_state
== LIT
)
228 strcpy(p
, state_t_string
[w
->w_state
]);
230 if (w
->w_intermediate
)
233 if (w
->w_intermediate
> 0xff)
234 p
+= AddXChar(p
, w
->w_intermediate
>> 8);
235 p
+= AddXChar(p
, w
->w_intermediate
& 0xff);
238 if (w
->w_state
== ASTR
|| w
->w_state
== STRESC
)
239 sprintf(p
, "-%s", string_t_string
[w
->w_StringType
]);
251 p
->w_gr
= nwin_default
.gr
;
252 p
->w_c1
= nwin_default
.c1
;
253 SetCharsets(p
, "BBBB02");
254 if (nwin_default
.charset
)
255 SetCharsets(p
, nwin_default
.charset
);
268 for (i
= 0; i
< 4 && *s
; i
++, s
++)
270 p
->w_charsets
[i
] = ((*s
== 'B') ? ASCII
: *s
);
271 if (*s
&& *s
++ != '.')
272 p
->w_Charset
= s
[-1] - '0';
274 p
->w_CharsetR
= *s
- '0';
276 p
->w_FontL
= p
->w_charsets
[p
->w_Charset
];
277 p
->w_FontR
= p
->w_charsets
[p
->w_CharsetR
];
281 /*****************************************************************/
285 * Here comes the vt100 emulator
287 * - sets timestamp and flags activity in window.
288 * - record program output in window scrollback
289 * - translate program output for the display and put it into the obuf.
293 WriteString(wp
, buf
, len
)
307 WLogString(wp
, buf
, len
);
309 /* set global variables (yuck!) */
311 cols
= curr
->w_width
;
312 rows
= curr
->w_height
;
315 SetTimeout(&curr
->w_silenceev
, curr
->w_silencewait
* 1000);
317 if (curr
->w_monitor
== MON_ON
)
319 debug2("ACTIVITY %d %d\n", curr
->w_monitor
, curr
->w_bell
);
320 curr
->w_monitor
= MON_FOUND
;
325 c
= (unsigned char)*buf
++;
330 curr
->w_rend
.font
= curr
->w_FontL
; /* Default: GL */
333 /* The next part is only for speedup */
334 if (curr
->w_state
== LIT
&&
336 curr
->w_encoding
!= UTF8
&&
339 !is_dw_font(curr
->w_rend
.font
) &&
341 curr
->w_rend
.font
!= KANA
&& !curr
->w_mbcs
&&
345 curr
->w_rend
.font
!= '<' &&
347 c
>= ' ' && c
!= 0x7f &&
348 ((c
& 0x80) == 0 || ((c
>= 0xa0 || !curr
->w_c1
) && !curr
->w_gr
)) && !curr
->w_ss
&&
349 !curr
->w_insert
&& curr
->w_x
< cols
- 1)
351 register int currx
= curr
->w_x
;
354 while (currx
< cols
- 1)
359 c
= (unsigned char)*buf
++;
360 if (c
< ' ' || c
== 0x7f || ((c
& 0x80) && ((c
< 0xa0 && curr
->w_c1
) || curr
->w_gr
)))
366 MPutStr(curr
, imp
, currx
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
367 LPutStr(&curr
->w_layer
, imp
, currx
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
373 /* end of speedup code */
376 if (curr
->w_encoding
== UTF8
)
378 c
= FromUtf8(c
, &curr
->w_decodestate
);
389 debug1("read UNICODE %04x\n", c
);
394 switch (curr
->w_state
)
400 curr
->w_state
= PRINESC
;
410 curr
->w_state
= PRINCSI
;
415 curr
->w_state
= PRIN
;
422 curr
->w_state
= PRIN4
;
428 curr
->w_state
= PRIN
;
437 if (curr
->w_pdisplay
&& curr
->w_pdisplay
->d_printfd
>= 0)
439 close(curr
->w_pdisplay
->d_printfd
);
440 curr
->w_pdisplay
->d_printfd
= -1;
442 curr
->w_pdisplay
= 0;
449 curr
->w_state
= PRIN
;
457 curr
->w_state
= STRESC
;
460 /* special xterm hack: accept SetStatus sequence. Yucc! */
461 /* allow ^E for title escapes */
462 if (!(curr
->w_StringType
== OSC
&& c
< ' ' && c
!= '\005'))
463 if (!curr
->w_c1
|| c
!= ('\\' ^ 0xc0))
474 if (StringEnd() == 0 || len
<= 1)
476 /* check if somewhere a status is displayed */
477 for (cv
= curr
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
479 display
= cv
->c_display
;
480 if (D_status
== STATUS_ON_WIN
)
485 if (len
> IOSIZE
+ 1)
487 curr
->w_outlen
= len
- 1;
488 bcopy(buf
, curr
->w_outbuf
, len
- 1);
489 return; /* wait till status is gone */
496 curr
->w_state
= ASTR
;
507 curr
->w_intermediate
= 0;
508 bzero((char *) curr
->w_args
, MAXARGS
* sizeof(int));
536 debug1("not special. c = %x\n", c
);
537 if (c
>= ' ' && c
<= '/')
539 if (curr
->w_intermediate
)
542 if (curr
->w_intermediate
== '$')
548 curr
->w_intermediate
= c
;
550 else if (c
>= '0' && c
<= '~')
552 DoESC(c
, curr
->w_intermediate
);
565 case '0': case '1': case '2': case '3': case '4':
566 case '5': case '6': case '7': case '8': case '9':
567 if (curr
->w_NumArgs
< MAXARGS
)
569 if (curr
->w_args
[curr
->w_NumArgs
] < 100000000)
570 curr
->w_args
[curr
->w_NumArgs
] =
571 10 * curr
->w_args
[curr
->w_NumArgs
] + (c
- '0');
576 if (curr
->w_NumArgs
< MAXARGS
)
582 if (c
>= '@' && c
<= '~')
584 if (curr
->w_NumArgs
< MAXARGS
)
586 DoCSI(c
, curr
->w_intermediate
);
587 if (curr
->w_state
!= PRIN
)
590 else if ((c
>= ' ' && c
<= '/') || (c
>= '<' && c
<= '?'))
591 curr
->w_intermediate
= curr
->w_intermediate
? -1 : c
;
603 if (c
<= ' ' || c
== 0x7f || (c
>= 0x80 && c
< 0xa0 && curr
->w_c1
))
610 curr
->w_intermediate
= 0;
612 if (curr
->w_autoaka
< 0)
619 if (c
>= 0x80 && c
< 0xa0 && curr
->w_c1
)
621 if ((curr
->w_FontR
& 0xf0) != 0x20
623 || curr
->w_encoding
== UTF8
634 case 0xc0 ^ 'N': /* SS2 */
635 case 0xc0 ^ 'O': /* SS3 */
639 if (curr
->w_autoaka
< 0)
642 curr
->w_intermediate
= 0;
643 bzero((char *) curr
->w_args
, MAXARGS
* sizeof(int));
660 if (c
< 0x80 || curr
->w_gr
== 0)
661 curr
->w_rend
.font
= curr
->w_FontL
;
663 else if (curr
->w_gr
== 2 && !curr
->w_ss
)
664 curr
->w_rend
.font
= curr
->w_FontE
;
667 curr
->w_rend
.font
= curr
->w_FontR
;
672 if (curr
->w_encoding
== UTF8
)
674 if (curr
->w_rend
.font
== '0')
676 struct mchar mc
, *mcp
;
678 debug1("SPECIAL %x\n", c
);
682 mcp
= recode_mchar(&mc
, 0, UTF8
);
683 debug2("%02x %02x\n", mcp
->image
, mcp
->font
);
684 c
= mcp
->image
| mcp
->font
<< 8;
686 curr
->w_rend
.font
= 0;
689 if (curr
->w_encoding
== UTF8
&& utf8_isdouble(c
))
692 if (curr
->w_encoding
== UTF8
&& c
>= 0x0300 && utf8_iscomb(c
))
701 ox
= curr
->w_width
- 1;
706 copy_mline2mchar(&omc
, &curr
->w_mlines
[oy
], ox
);
707 if (omc
.image
== 0xff && omc
.font
== 0xff)
712 copy_mline2mchar(&omc
, &curr
->w_mlines
[oy
], ox
);
718 utf8_handle_comb(c
, &omc
);
719 MFixLine(curr
, oy
, &omc
);
720 copy_mchar2mline(&omc
, &curr
->w_mlines
[oy
], ox
);
721 LPutChar(&curr
->w_layer
, &omc
, ox
, oy
);
722 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
726 font
= curr
->w_rend
.font
;
730 if (font
== KANA
&& curr
->w_encoding
== SJIS
&& curr
->w_mbcs
== 0)
732 /* Lets see if it is the first byte of a kanji */
733 debug1("%x may be first of SJIS\n", c
);
734 if ((0x81 <= c
&& c
<= 0x9f) || (0xe0 <= c
&& c
<= 0xef))
742 if (font
== 031 && c
== 0x80 && !curr
->w_mbcs
)
743 font
= curr
->w_rend
.font
= 0;
744 if (is_dw_font(font
) && c
== ' ')
745 font
= curr
->w_rend
.font
= 0;
746 if (is_dw_font(font
) || curr
->w_mbcs
)
749 if (curr
->w_mbcs
== 0)
754 if (curr
->w_x
== cols
- 1)
756 curr
->w_x
+= curr
->w_wrap
? 1 : -1;
757 debug1("Patched w_x to %d\n", curr
->w_x
);
760 if (curr
->w_encoding
!= UTF8
)
765 if (font
== KANA
&& curr
->w_encoding
== SJIS
)
767 debug2("SJIS !! %x %x\n", c
, t
);
769 * SJIS -> EUC mapping:
771 * 81,82...9f -> 21,23...5d
772 * e0,e1...ef -> 5f,61...7d
776 * 9f-fc -> 21-7e (increment first byte!)
778 if (0x40 <= t
&& t
<= 0xfc && t
!= 0x7f)
780 if (c
<= 0x9f) c
= (c
- 0x81) * 2 + 0x21;
781 else c
= (c
- 0xc1) * 2 + 0x21;
782 if (t
<= 0x7e) t
-= 0x1f;
783 else if (t
<= 0x9e) t
-= 0x20;
785 curr
->w_rend
.font
= KANJI
;
789 /* Incomplete shift-jis - skip first byte */
793 debug2("SJIS after %x %x\n", c
, t
);
796 if (t
&& curr
->w_gr
&& font
!= 030 && font
!= 031)
807 # endif /* DW_CHARS */
808 if (font
== '<' && c
>= ' ')
810 font
= curr
->w_rend
.font
= 0;
814 else if (curr
->w_gr
&& curr
->w_encoding
!= UTF8
)
820 if (c
== 0x80 && font
== 0 && curr
->w_encoding
== GBK
)
824 if (c
< ' ' && font
!= 031)
828 if (c
< ' ') /* this is ugly but kanji support */
829 goto tryagain
; /* prevents nicer programming */
835 curr
->w_rend
.image
= c
;
837 if (curr
->w_encoding
== UTF8
)
838 curr
->w_rend
.font
= c
>> 8;
841 curr
->w_rend
.mbcs
= curr
->w_mbcs
;
843 if (curr
->w_x
< cols
- 1)
847 save_mline(&curr
->w_mlines
[curr
->w_y
], cols
);
848 MInsChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
849 LInsChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
, &mline_old
);
854 MPutChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
855 LPutChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
859 else if (curr
->w_x
== cols
- 1)
861 MPutChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
862 LPutChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
868 MWrapChar(curr
, &curr
->w_rend
, curr
->w_y
, curr
->w_top
, curr
->w_bot
, curr
->w_insert
);
869 LWrapChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_y
, curr
->w_top
, curr
->w_bot
, curr
->w_insert
);
870 if (curr
->w_y
!= curr
->w_bot
&& curr
->w_y
!= curr
->w_height
- 1)
878 curr
->w_rend
.mbcs
= curr
->w_mbcs
= 0;
884 curr
->w_FontL
= curr
->w_charsets
[curr
->w_Charset
];
885 curr
->w_FontR
= curr
->w_charsets
[curr
->w_CharsetR
];
886 curr
->w_rend
.font
= curr
->w_FontL
;
887 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
895 if (!printcmd
&& curr
->w_state
== PRIN
)
900 WLogString(p
, buf
, len
)
907 if (logtstamp_on
&& p
->w_logsilence
>= logtstamp_after
* 2)
909 char *t
= MakeWinMsg(logtstamp_string
, p
, '%');
910 logfwrite(p
->w_log
, t
, strlen(t
)); /* long time no write */
913 if (logfwrite(p
->w_log
, buf
, len
) < 1)
915 WMsg(p
, errno
, "Error writing logfile");
941 WBell(curr
, visual_bell
);
947 case '\017': /* SI */
950 case '\016': /* SO */
959 DoESC(c
, intermediate
)
962 debug2("DoESC: %x - inter = %x\n", c
, intermediate
);
963 switch (intermediate
)
978 curr
->w_tabs
[curr
->w_x
] = 1;
980 case 'Z': /* jph: Identify as VT100 */
981 Report("\033[?%d;%dc", 1, 2);
992 LKeypadMode(&curr
->w_layer
, 0);
993 LCursorkeysMode(&curr
->w_layer
, 0);
995 WNewAutoFlow(curr
, 1);
998 SetRendition(&mchar_null);
1000 ChangeScrollRegion(0, rows - 1);
1002 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1005 LKeypadMode(&curr
->w_layer
, curr
->w_keypad
= 1);
1007 WNewAutoFlow(curr
, 0);
1008 #endif /* !TIOCPKT */
1011 LKeypadMode(&curr
->w_layer
, curr
->w_keypad
= 0);
1013 WNewAutoFlow(curr
, 1);
1014 #endif /* !TIOCPKT */
1024 MapCharsetR(G1
); /* LS1R */
1028 MapCharsetR(G2
); /* LS2R */
1031 MapCharsetR(G3
); /* LS3R */
1034 if (curr
->w_charsets
[curr
->w_Charset
] != curr
->w_charsets
[G2
]
1035 || curr
->w_charsets
[curr
->w_CharsetR
] != curr
->w_charsets
[G2
])
1036 curr
->w_FontR
= curr
->w_FontL
= curr
->w_charsets
[curr
->w_ss
= G2
];
1041 if (curr
->w_charsets
[curr
->w_Charset
] != curr
->w_charsets
[G3
]
1042 || curr
->w_charsets
[curr
->w_CharsetR
] != curr
->w_charsets
[G3
])
1043 curr
->w_FontR
= curr
->w_FontL
= curr
->w_charsets
[curr
->w_ss
= G3
];
1048 case 'g': /* VBELL, private screen sequence */
1063 DesignateCharset(c
, G0
);
1066 DesignateCharset(c
, G1
);
1069 DesignateCharset(c
, G2
);
1072 DesignateCharset(c
, G3
);
1076 * ESC $ ( Fn: invoke multi-byte charset, Fn, to G0
1077 * ESC $ Fn: same as above. (old sequence)
1078 * ESC $ ) Fn: invoke multi-byte charset, Fn, to G1
1079 * ESC $ * Fn: invoke multi-byte charset, Fn, to G2
1080 * ESC $ + Fn: invoke multi-byte charset, Fn, to G3
1084 DesignateCharset(c
& 037, G0
);
1087 DesignateCharset(c
& 037, G1
);
1090 DesignateCharset(c
& 037, G2
);
1093 DesignateCharset(c
& 037, G3
);
1101 DoCSI(c
, intermediate
)
1102 int c
, intermediate
;
1104 register int i
, a1
= curr
->w_args
[0], a2
= curr
->w_args
[1];
1106 if (curr
->w_NumArgs
> MAXARGS
)
1107 curr
->w_NumArgs
= MAXARGS
;
1108 switch (intermediate
)
1125 LGotoPos(&curr
->w_layer
, --a2
, --a1
);
1128 if (curr
->w_autoaka
)
1129 curr
->w_autoaka
= a1
+ 1;
1132 if (a1
< 0 || a1
> 2)
1144 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1149 if (a1
< 0 || a1
> 2)
1154 ClearLineRegion(curr
->w_x
, cols
- 1);
1157 ClearLineRegion(0, curr
->w_x
);
1160 ClearLineRegion(0, cols
- 1);
1165 a1
= curr
->w_x
+ (a1
? a1
- 1 : 0);
1166 ClearLineRegion(curr
->w_x
, a1
< cols
? a1
: cols
- 1);
1169 CursorUp(a1
? a1
: 1);
1172 CursorDown(a1
? a1
: 1);
1175 CursorRight(a1
? a1
: 1);
1178 CursorLeft(a1
? a1
: 1);
1182 CursorDown(a1
? a1
: 1); /* positions cursor */
1186 CursorUp(a1
? a1
: 1); /* positions cursor */
1190 curr
->w_x
= a1
? a1
- 1 : 0;
1191 if (curr
->w_x
>= cols
)
1192 curr
->w_x
= cols
- 1;
1193 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1196 curr
->w_y
= a1
? a1
- 1 : 0;
1197 if (curr
->w_y
>= rows
)
1198 curr
->w_y
= rows
- 1;
1199 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1206 curr
->w_tabs
[curr
->w_x
] = 0;
1208 bzero(curr
->w_tabs
, cols
);
1215 if (a1
< 1 || a2
> rows
|| a1
>= a2
)
1217 curr
->w_top
= a1
- 1;
1218 curr
->w_bot
= a2
- 1;
1219 /* ChangeScrollRegion(curr->w_top, curr->w_bot); */
1222 curr
->w_y
= curr
->w_top
;
1226 curr
->w_y
= curr
->w_x
= 0;
1227 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1236 if (curr
->w_layer
.l_cvlist
)
1237 Report("\033[1t", 0, 0);
1239 Report("\033[2t", 0, 0);
1242 LRefreshAll(&curr
->w_layer
, 0);
1245 a1
= strlen(curr
->w_title
);
1246 if ((unsigned)(curr
->w_inlen
+ 5 + a1
) <= sizeof(curr
->w_inbuf
))
1248 bcopy("\033]l", curr
->w_inbuf
+ curr
->w_inlen
, 3);
1249 bcopy(curr
->w_title
, curr
->w_inbuf
+ curr
->w_inlen
+ 3, a1
);
1250 bcopy("\033\\", curr
->w_inbuf
+ curr
->w_inlen
+ 3 + a1
, 2);
1251 curr
->w_inlen
+= 5 + a1
;
1255 a1
= curr
->w_args
[2];
1259 a2
= curr
->w_height
;
1260 if (a1
> 10000 || a2
> 10000)
1262 WChangeSize(curr
, a1
, a2
);
1263 cols
= curr
->w_width
;
1264 rows
= curr
->w_height
;
1286 InsertLine(a1
? a1
: 1);
1289 DeleteLine(a1
? a1
: 1);
1292 DeleteChar(a1
? a1
: 1);
1295 InsertChar(a1
? a1
: 1);
1303 case 'i': /* MC Media Control */
1308 if (a1
== 5) /* Report terminal status */
1309 Report("\033[0n", 0, 0);
1310 else if (a1
== 6) /* Report cursor position */
1311 Report("\033[%d;%dR", curr
->w_y
+ 1, curr
->w_x
+ 1);
1313 case 'c': /* Identify as VT100 */
1315 Report("\033[?%d;%dc", 1, 2);
1317 case 'x': /* decreqtparm */
1318 if (a1
== 0 || a1
== 1)
1319 Report("\033[%d;1;1;112;112;1;0x", a1
+ 2, 0);
1321 case 'p': /* obscure code from a 97801 term */
1322 if (a1
== 6 || a1
== 7)
1324 curr
->w_curinv
= 7 - a1
;
1325 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
1328 case 'S': /* code from a 97801 term / DEC vt400 */
1329 ScrollRegion(a1
? a1
: 1);
1331 case 'T': /* code from a 97801 term / DEC vt400 */
1332 case '^': /* SD as per ISO 6429 */
1333 ScrollRegion(a1
? -a1
: -1);
1338 for (a2
= 0; a2
< curr
->w_NumArgs
; a2
++)
1340 a1
= curr
->w_args
[a2
];
1341 debug2("\\E[?%d%c\n",a1
,c
);
1342 if (c
!= 'h' && c
!= 'l')
1347 case 1: /* CKM: cursor key mode */
1348 LCursorkeysMode(&curr
->w_layer
, curr
->w_cursorkeys
= i
);
1350 WNewAutoFlow(curr
, !i
);
1351 #endif /* !TIOCPKT */
1353 case 2: /* ANM: ansi/vt52 mode */
1358 if (curr
->w_encoding
)
1361 curr
->w_charsets
[0] = curr
->w_charsets
[1] =
1362 curr
->w_charsets
[2] = curr
->w_charsets
[2] =
1363 curr
->w_FontL
= curr
->w_FontR
= ASCII
;
1364 curr
->w_Charset
= 0;
1365 curr
->w_CharsetR
= 2;
1370 case 3: /* COLM: column mode */
1371 i
= (i
? Z0width
: Z1width
);
1372 WChangeSize(curr
, i
, curr
->w_height
);
1373 cols
= curr
->w_width
;
1374 rows
= curr
->w_height
;
1376 /* case 4: SCLM: scrolling mode */
1377 case 5: /* SCNM: screen mode */
1378 if (i
!= curr
->w_revvid
)
1379 WReverseVideo(curr
, i
);
1382 case 6: /* OM: origin mode */
1383 if ((curr
->w_origin
= i
) != 0)
1385 curr
->w_y
= curr
->w_top
;
1389 curr
->w_y
= curr
->w_x
= 0;
1390 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1392 case 7: /* AWM: auto wrap mode */
1395 /* case 8: ARM: auto repeat mode */
1396 /* case 9: INLM: interlace mode */
1397 case 9: /* X10 mouse tracking */
1398 curr
->w_mouse
= i
? 9 : 0;
1399 LMouseMode(&curr
->w_layer
, curr
->w_mouse
);
1401 /* case 10: EDM: edit mode */
1402 /* case 11: LTM: line transmit mode */
1403 /* case 13: SCFDM: space compression / field delimiting */
1404 /* case 14: TEM: transmit execution mode */
1405 /* case 16: EKEM: edit key execution mode */
1406 /* case 18: PFF: Printer term form feed */
1407 /* case 19: PEX: Printer extend screen / scroll. reg */
1408 case 25: /* TCEM: text cursor enable mode */
1409 curr
->w_curinv
= !i
;
1410 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
1412 /* case 34: RLM: Right to left mode */
1413 /* case 35: HEBM: hebrew keyboard map */
1414 /* case 36: HEM: hebrew encoding */
1415 /* case 38: TeK Mode */
1416 /* case 40: 132 col enable */
1417 /* case 42: NRCM: 7bit NRC character mode */
1418 /* case 44: margin bell enable */
1419 case 47: /* xterm-like alternate screen */
1420 case 1047: /* xterm-like alternate screen */
1421 case 1049: /* xterm-like alternate screen */
1425 EnterAltScreen(curr
);
1427 LeaveAltScreen(curr
);
1430 LRefreshAll(&curr
->w_layer
, 0);
1431 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1434 /* case 66: NKM: Numeric keypad appl mode */
1435 /* case 68: KBUM: Keyboard usage mode (data process) */
1436 case 1000: /* VT200 mouse tracking */
1437 case 1001: /* VT200 highlight mouse */
1438 case 1002: /* button event mouse*/
1439 case 1003: /* any event mouse*/
1440 curr
->w_mouse
= i
? a1
: 0;
1441 LMouseMode(&curr
->w_layer
, curr
->w_mouse
);
1449 case 'c': /* secondary DA */
1451 Report("\033[>%d;%d;0c", 83, nversion
); /* 83 == 'S' */
1463 curr
->w_StringType
= type
;
1464 curr
->w_stringp
= curr
->w_string
;
1465 curr
->w_state
= ASTR
;
1472 if (curr
->w_stringp
>= curr
->w_string
+ MAXSTR
- 1)
1473 curr
->w_state
= LIT
;
1475 *(curr
->w_stringp
)++ = c
;
1479 * Do string processing. Returns -1 if output should be suspended
1480 * until status is gone.
1489 curr
->w_state
= LIT
;
1490 *curr
->w_stringp
= '\0';
1491 switch (curr
->w_StringType
)
1493 case OSC
: /* special xterm compatibility hack */
1494 if (curr
->w_string
[0] == ';' || (p
= index(curr
->w_string
, ';')) == 0)
1496 typ
= atoi(curr
->w_string
);
1499 if (typ
== 83) /* 83 = 'S' */
1501 /* special execute commands sequence */
1502 char *args
[MAXARGS
];
1504 struct acluser
*windowuser
;
1506 windowuser
= *FindUserPtr(":window:");
1507 if (windowuser
&& Parse(p
, sizeof(curr
->w_string
) - (p
- curr
->w_string
), args
, argl
))
1509 for (display
= displays
; display
; display
= display
->d_next
)
1510 if (D_forecv
->c_layer
->l_bottom
== &curr
->w_layer
)
1511 break; /* found it */
1512 if (display
== 0 && curr
->w_layer
.l_cvlist
)
1513 display
= curr
->w_layer
.l_cvlist
->c_display
;
1516 EffectiveAclUser
= windowuser
;
1518 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1519 DoCommand(args
, argl
);
1520 EffectiveAclUser
= 0;
1528 if (typ
== 0 || typ
== 1 || typ
== 20 || typ
== 39 || typ
== 49)
1534 if (strcmp(curr
->w_xtermosc
[typ2
], p
))
1536 strncpy(curr
->w_xtermosc
[typ2
], p
, sizeof(curr
->w_xtermosc
[typ2
]) - 1);
1537 curr
->w_xtermosc
[typ2
][sizeof(curr
->w_xtermosc
[typ2
]) - 1] = 0;
1539 for (display
= displays
; display
; display
= display
->d_next
)
1543 if (D_forecv
->c_layer
->l_bottom
== &curr
->w_layer
)
1544 SetXtermOSC(typ2
, curr
->w_xtermosc
[typ2
]);
1545 if ((typ2
== 2 || typ2
== 3) && D_xtermosc
[typ2
])
1550 if (typ
!= 0 && typ
!= 2)
1553 if (typ
< 0 || typ
> 2)
1557 curr
->w_stringp
-= p
- curr
->w_string
;
1558 if (curr
->w_stringp
> curr
->w_string
)
1559 bcopy(p
, curr
->w_string
, curr
->w_stringp
- curr
->w_string
);
1560 *curr
->w_stringp
= '\0';
1563 if (curr
->w_hstatus
)
1565 if (strcmp(curr
->w_hstatus
, curr
->w_string
) == 0)
1566 break; /* not changed */
1567 free(curr
->w_hstatus
);
1568 curr
->w_hstatus
= 0;
1570 if (curr
->w_string
!= curr
->w_stringp
)
1571 curr
->w_hstatus
= SaveStr(curr
->w_string
);
1572 WindowChanged(curr
, 'h');
1576 for (display
= displays
; display
; display
= display
->d_next
)
1578 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
1579 if (cv
->c_layer
->l_bottom
== &curr
->w_layer
)
1581 if (cv
|| curr
->w_StringType
== GM
)
1582 MakeStatus(curr
->w_string
);
1586 LAY_DISPLAYS(&curr
->w_layer
, AddStr(curr
->w_string
));
1589 if (curr
->w_title
== curr
->w_akabuf
&& !*curr
->w_string
)
1591 ChangeAKA(curr
, curr
->w_string
, strlen(curr
->w_string
));
1592 if (!*curr
->w_string
)
1593 curr
->w_autoaka
= curr
->w_y
+ 1;
1604 curr
->w_pdisplay
= 0;
1606 /* find us a nice display to print on, fore prefered */
1607 display
= curr
->w_lastdisp
;
1608 if (!(display
&& curr
== D_fore
&& (printcmd
|| D_PO
)))
1609 for (display
= displays
; display
; display
= display
->d_next
)
1610 if (curr
== D_fore
&& (printcmd
|| D_PO
))
1615 for (cv
= curr
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
1617 display
= cv
->c_display
;
1618 if (printcmd
|| D_PO
)
1624 if (!display
|| display
->d_next
|| !(printcmd
|| D_PO
))
1628 curr
->w_pdisplay
= display
;
1629 curr
->w_stringp
= curr
->w_string
;
1630 curr
->w_state
= PRIN
;
1631 if (printcmd
&& curr
->w_pdisplay
->d_printfd
< 0)
1632 curr
->w_pdisplay
->d_printfd
= printpipe(curr
, printcmd
);
1639 if (curr
->w_stringp
>= curr
->w_string
+ MAXSTR
- 1)
1641 *(curr
->w_stringp
)++ = c
;
1647 display
= curr
->w_pdisplay
;
1648 if (display
&& printcmd
)
1650 char *bp
= curr
->w_string
;
1651 int len
= curr
->w_stringp
- curr
->w_string
;
1653 while (len
&& display
->d_printfd
>= 0)
1655 r
= write(display
->d_printfd
, bp
, len
);
1658 WMsg(curr
, errno
, "printing aborted");
1659 close(display
->d_printfd
);
1660 display
->d_printfd
= -1;
1667 else if (display
&& curr
->w_stringp
> curr
->w_string
)
1670 AddStrn(curr
->w_string
, curr
->w_stringp
- curr
->w_string
);
1674 curr
->w_stringp
= curr
->w_string
;
1679 WNewAutoFlow(win
, on
)
1683 debug1("WNewAutoFlow: %d\n", on
);
1684 if (win
->w_flow
& FLOW_AUTOFLAG
)
1685 win
->w_flow
= FLOW_AUTOFLAG
| (FLOW_AUTO
|FLOW_NOW
) * on
;
1687 win
->w_flow
= (win
->w_flow
& ~FLOW_AUTO
) | FLOW_AUTO
* on
;
1688 LSetFlow(&win
->w_layer
, win
->w_flow
& FLOW_NOW
);
1695 DesignateCharset(c
, n
)
1700 if (c
== ('@' & 037)) /* map JIS 6226 to 0208 */
1705 if (curr
->w_charsets
[n
] != c
)
1707 curr
->w_charsets
[n
] = c
;
1708 if (curr
->w_Charset
== n
)
1711 curr
->w_rend
.font
= curr
->w_FontL
;
1712 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1714 if (curr
->w_CharsetR
== n
)
1724 if (curr
->w_Charset
!= n
)
1726 curr
->w_Charset
= n
;
1727 curr
->w_FontL
= curr
->w_charsets
[n
];
1728 curr
->w_rend
.font
= curr
->w_FontL
;
1729 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1738 if (curr
->w_CharsetR
!= n
)
1740 curr
->w_CharsetR
= n
;
1741 curr
->w_FontR
= curr
->w_charsets
[n
];
1752 curr
->w_Saved_x
= curr
->w_x
;
1753 curr
->w_Saved_y
= curr
->w_y
;
1754 curr
->w_SavedRend
= curr
->w_rend
;
1756 curr
->w_SavedCharset
= curr
->w_Charset
;
1757 curr
->w_SavedCharsetR
= curr
->w_CharsetR
;
1758 bcopy((char *) curr
->w_charsets
, (char *) curr
->w_SavedCharsets
,
1768 LGotoPos(&curr
->w_layer
, curr
->w_Saved_x
, curr
->w_Saved_y
);
1769 curr
->w_x
= curr
->w_Saved_x
;
1770 curr
->w_y
= curr
->w_Saved_y
;
1771 curr
->w_rend
= curr
->w_SavedRend
;
1773 bcopy((char *) curr
->w_SavedCharsets
, (char *) curr
->w_charsets
,
1775 curr
->w_Charset
= curr
->w_SavedCharset
;
1776 curr
->w_CharsetR
= curr
->w_SavedCharsetR
;
1778 curr
->w_FontL
= curr
->w_charsets
[curr
->w_Charset
];
1779 curr
->w_FontR
= curr
->w_charsets
[curr
->w_CharsetR
];
1781 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1791 else if (curr
->w_wrap
&& curr
->w_y
> 0)
1793 curr
->w_x
= cols
- 1;
1796 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1805 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1812 /* out_mode: 0=lf, 1=cr+lf */
1815 if (curr
->w_y
!= curr
->w_bot
) /* Don't scroll */
1817 if (curr
->w_y
< rows
-1)
1819 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1822 if (curr
->w_autoaka
> 1)
1824 MScrollV(curr
, 1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1825 LScrollV(&curr
->w_layer
, 1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1826 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1832 if (curr
->w_y
== curr
->w_top
)
1834 MScrollV(curr
, -1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1835 LScrollV(&curr
->w_layer
, -1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1836 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1838 else if (curr
->w_y
> 0)
1846 register int y
= curr
->w_y
, x
= curr
->w_x
;
1852 save_mline(&curr
->w_mlines
[y
], cols
);
1853 MScrollH(curr
, -n
, y
, x
, curr
->w_width
- 1, CURR_BCE
);
1854 LScrollH(&curr
->w_layer
, -n
, y
, x
, curr
->w_width
- 1, CURR_BCE
, &mline_old
);
1855 LGotoPos(&curr
->w_layer
, x
, y
);
1862 register int y
= curr
->w_y
, x
= curr
->w_x
;
1866 save_mline(&curr
->w_mlines
[y
], cols
);
1867 MScrollH(curr
, n
, y
, x
, curr
->w_width
- 1, CURR_BCE
);
1868 LScrollH(&curr
->w_layer
, n
, y
, x
, curr
->w_width
- 1, CURR_BCE
, &mline_old
);
1869 LGotoPos(&curr
->w_layer
, x
, y
);
1876 if (curr
->w_y
< curr
->w_top
|| curr
->w_y
> curr
->w_bot
)
1878 if (n
> curr
->w_bot
- curr
->w_y
+ 1)
1879 n
= curr
->w_bot
- curr
->w_y
+ 1;
1880 MScrollV(curr
, n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1881 LScrollV(&curr
->w_layer
, n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1882 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1889 if (curr
->w_y
< curr
->w_top
|| curr
->w_y
> curr
->w_bot
)
1891 if (n
> curr
->w_bot
- curr
->w_y
+ 1)
1892 n
= curr
->w_bot
- curr
->w_y
+ 1;
1893 MScrollV(curr
, -n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1894 LScrollV(&curr
->w_layer
, -n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1895 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1902 MScrollV(curr
, n
, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1903 LScrollV(&curr
->w_layer
, n
, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1904 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1911 register int x
= curr
->w_x
;
1918 if (curr
->w_tabs
[x
] && x
< cols
- 1)
1920 while (x
< cols
- 1 && !curr
->w_tabs
[x
])
1923 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1929 register int x
= curr
->w_x
;
1931 if (curr
->w_tabs
[x
] && x
> 0)
1933 while (x
> 0 && !curr
->w_tabs
[x
])
1936 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1942 LClearArea(&curr
->w_layer
, 0, 0, curr
->w_width
- 1, curr
->w_height
- 1, CURR_BCE
, 1);
1944 MScrollV(curr
, curr
->w_height
, 0, curr
->w_height
- 1, CURR_BCE
);
1946 MClearArea(curr
, 0, 0, curr
->w_width
- 1, curr
->w_height
- 1, CURR_BCE
);
1953 register int y
= curr
->w_y
, x
= curr
->w_x
;
1955 LClearArea(&curr
->w_layer
, 0, 0, x
, y
, CURR_BCE
, 1);
1956 MClearArea(curr
, 0, 0, x
, y
, CURR_BCE
);
1957 RestorePosRendition();
1963 register int y
= curr
->w_y
, x
= curr
->w_x
;
1965 if (x
== 0 && y
== 0)
1968 RestorePosRendition();
1971 LClearArea(&curr
->w_layer
, x
, y
, cols
- 1, rows
- 1, CURR_BCE
, 1);
1972 MClearArea(curr
, x
, y
, cols
- 1, rows
- 1, CURR_BCE
);
1973 RestorePosRendition();
1977 ClearLineRegion(from
, to
)
1980 register int y
= curr
->w_y
;
1981 LClearArea(&curr
->w_layer
, from
, y
, to
, y
, CURR_BCE
, 1);
1982 MClearArea(curr
, from
, y
, to
, y
, CURR_BCE
);
1983 RestorePosRendition();
1990 register int x
= curr
->w_x
;
1997 if ((curr
->w_x
+= n
) >= cols
)
1998 curr
->w_x
= cols
- 1;
1999 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2006 if (curr
->w_y
< curr
->w_top
) /* if above scrolling rgn, */
2008 if ((curr
->w_y
-= n
) < 0) /* ignore its limits */
2012 if ((curr
->w_y
-= n
) < curr
->w_top
)
2013 curr
->w_y
= curr
->w_top
;
2014 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2021 if (curr
->w_y
> curr
->w_bot
) /* if below scrolling rgn, */
2023 if ((curr
->w_y
+= n
) > rows
- 1) /* ignore its limits */
2024 curr
->w_y
= rows
- 1;
2027 if ((curr
->w_y
+= n
) > curr
->w_bot
)
2028 curr
->w_y
= curr
->w_bot
;
2029 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2036 if ((curr
->w_x
-= n
) < 0)
2038 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2047 for (i
= 0; i
< curr
->w_NumArgs
; ++i
)
2049 switch (curr
->w_args
[i
])
2051 /* case 2: KAM: Lock keyboard */
2052 case 4: /* IRM: Insert mode */
2053 curr
->w_insert
= on
;
2054 LAY_DISPLAYS(&curr
->w_layer
, InsertMode(on
));
2056 /* case 12: SRM: Echo mode on */
2057 case 20: /* LNM: Linefeed mode */
2058 curr
->w_autolf
= on
;
2061 curr
->w_curvvis
= !on
;
2062 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
2070 static char rendlist
[] =
2072 ~((1 << NATTR
) - 1), A_BD
, A_DI
, A_SO
, A_US
, A_BL
, 0, A_RV
, 0, 0,
2073 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2074 0, 0, ~(A_BD
|A_SO
|A_DI
), ~A_SO
, ~A_US
, ~A_BL
, 0, ~A_RV
2081 register int j
, i
= 0, a
= curr
->w_rend
.attr
, c
= curr
->w_rend
.color
;
2083 int cx
= curr
->w_rend
.colorx
;
2086 register int j
, i
= 0, a
= curr
->w_rend
.attr
;
2091 j
= curr
->w_args
[i
];
2093 if ((j
== 38 || j
== 48) && i
+ 2 < curr
->w_NumArgs
&& curr
->w_args
[i
+ 1] == 5)
2098 jj
= curr
->w_args
[i
];
2099 if (jj
< 0 || jj
> 255)
2104 c
= (c
& 0xf0) | ((jj
& 0x0f) ^ 9);
2106 if (jj
>= 8 && jj
< 16)
2110 a
= (a
& 0xbf) | (jj
& 8 ? 0x40 : 0);
2111 cx
= (cx
& 0xf0) | (jj
>> 4 & 0x0f);
2115 c
= (c
& 0x0f) | ((jj
& 0x0f) ^ 9) << 4;
2117 if (jj
>= 8 && jj
< 16)
2121 cx
= (cx
& 0x0f) | (jj
& 0xf0);
2125 jj
= color256to16(jj
) + 30;
2128 j
= j
== 38 ? jj
: jj
+ 10;
2132 if (j
== 0 || (j
>= 30 && j
<= 39 && j
!= 38))
2134 if (j
== 0 || (j
>= 40 && j
<= 49 && j
!= 48))
2136 if (j
>= 90 && j
<= 97)
2138 if (j
>= 100 && j
<= 107)
2141 if (j
>= 90 && j
<= 97)
2143 if (j
>= 100 && j
<= 107)
2145 if (j
>= 30 && j
<= 39 && j
!= 38)
2146 c
= (c
& 0xf0) | ((j
- 30) ^ 9);
2147 else if (j
>= 40 && j
<= 49 && j
!= 48)
2148 c
= (c
& 0x0f) | (((j
- 40) ^ 9) << 4);
2152 if (j
== 0 || (j
>= 30 && j
<= 39 && j
!= 38))
2154 if (j
== 0 || (j
>= 40 && j
<= 49 && j
!= 48))
2158 if (j
< 0 || j
>= (int)(sizeof(rendlist
)/sizeof(*rendlist
)))
2161 if (j
& (1 << NATTR
))
2166 while (++i
< curr
->w_NumArgs
);
2167 curr
->w_rend
.attr
= a
;
2169 curr
->w_rend
.color
= c
;
2171 curr
->w_rend
.colorx
= cx
;
2174 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
2181 register unsigned char *p
, *ep
;
2183 LClearAll(&curr
->w_layer
, 1);
2184 curr
->w_y
= curr
->w_x
= 0;
2185 for (i
= 0; i
< rows
; ++i
)
2187 clear_mline(&curr
->w_mlines
[i
], 0, cols
+ 1);
2188 p
= curr
->w_mlines
[i
].image
;
2193 LRefreshAll(&curr
->w_layer
, 1);
2198 * Ugly autoaka hack support:
2199 * ChangeAKA() sets a new aka
2200 * FindAKA() searches for an autoaka match
2211 for (i
= 0; l
> 0; l
--)
2213 if (p
->w_akachange
+ i
== p
->w_akabuf
+ sizeof(p
->w_akabuf
) - 1)
2215 c
= (unsigned char)*s
++;
2218 if (c
< 32 || c
== 127 || (c
>= 128 && c
< 160 && p
->w_c1
))
2220 p
->w_akachange
[i
++] = c
;
2222 p
->w_akachange
[i
] = 0;
2223 p
->w_title
= p
->w_akachange
;
2224 if (p
->w_akachange
!= p
->w_akabuf
)
2225 if (p
->w_akachange
[0] == 0 || p
->w_akachange
[-1] == ':')
2226 p
->w_title
= p
->w_akabuf
+ strlen(p
->w_akabuf
) + 1;
2227 WindowChanged(p
, 't');
2228 WindowChanged((struct win
*)0, 'w');
2229 WindowChanged((struct win
*)0, 'W');
2235 register unsigned char *cp
, *line
;
2236 register struct win
*wp
= curr
;
2237 register int len
= strlen(wp
->w_akabuf
);
2240 y
= (wp
->w_autoaka
> 0 && wp
->w_autoaka
<= wp
->w_height
) ? wp
->w_autoaka
- 1 : wp
->w_y
;
2243 cp
= line
= wp
->w_mlines
[y
].image
;
2244 if (wp
->w_autoaka
> 0 && *wp
->w_akabuf
!= '\0')
2248 if (cp
- line
>= cols
- len
)
2250 if (++y
== wp
->w_autoaka
&& y
< rows
)
2254 if (strncmp((char *)cp
, wp
->w_akabuf
, len
) == 0)
2260 for (len
= cols
- (cp
- line
); len
&& *cp
== ' '; len
--, cp
++)
2264 if (wp
->w_autoaka
> 0 && (*cp
== '!' || *cp
== '%' || *cp
== '^'))
2269 while (len
&& *cp
!= ' ')
2275 ChangeAKA(wp
, (char *)line
, cp
- line
);
2282 RestorePosRendition()
2284 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2285 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
2288 /* Send a terminal report as if it were typed. */
2295 char rbuf
[40]; /* enough room for all replys */
2297 sprintf(rbuf
, fmt
, n1
, n2
);
2303 if ((unsigned)(curr
->w_pwin
->p_inlen
+ len
) <= sizeof(curr
->w_pwin
->p_inbuf
))
2305 bcopy(rbuf
, curr
->w_pwin
->p_inbuf
+ curr
->w_pwin
->p_inlen
, len
);
2306 curr
->w_pwin
->p_inlen
+= len
;
2312 if ((unsigned)(curr
->w_inlen
+ len
) <= sizeof(curr
->w_inbuf
))
2314 bcopy(rbuf
, curr
->w_inbuf
+ curr
->w_inlen
, len
);
2315 curr
->w_inlen
+= len
;
2323 *====================================================================*
2324 *====================================================================*
2327 /**********************************************************************
2339 struct mline
*ml
= &p
->w_mlines
[y
];
2340 if (mc
->attr
&& ml
->attr
== null
)
2342 if ((ml
->attr
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2345 mc
->attr
= p
->w_rend
.attr
= 0;
2346 WMsg(p
, 0, "Warning: no space for attr - turned off");
2350 if (mc
->font
&& ml
->font
== null
)
2352 if ((ml
->font
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2355 p
->w_FontL
= p
->w_charsets
[p
->w_ss
? p
->w_ss
: p
->w_Charset
] = 0;
2356 p
->w_FontR
= p
->w_charsets
[p
->w_ss
? p
->w_ss
: p
->w_CharsetR
] = 0;
2357 mc
->font
= p
->w_rend
.font
= 0;
2358 WMsg(p
, 0, "Warning: no space for font - turned off");
2363 if (mc
->color
&& ml
->color
== null
)
2365 if ((ml
->color
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2368 mc
->color
= p
->w_rend
.color
= 0;
2369 WMsg(p
, 0, "Warning: no space for color - turned off");
2373 if (mc
->colorx
&& ml
->colorx
== null
)
2375 if ((ml
->colorx
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2378 mc
->colorx
= p
->w_rend
.colorx
= 0;
2379 WMsg(p
, 0, "Warning: no space for extended colors - turned off");
2386 /*****************************************************************/
2389 # define MKillDwRight(p, ml, x) \
2390 if (dw_right(ml, x, p->w_encoding)) \
2393 copy_mchar2mline(&mchar_blank, ml, x - 1); \
2394 copy_mchar2mline(&mchar_blank, ml, x); \
2397 # define MKillDwLeft(p, ml, x) \
2398 if (dw_left(ml, x, p->w_encoding)) \
2400 copy_mchar2mline(&mchar_blank, ml, x); \
2401 copy_mchar2mline(&mchar_blank, ml, x + 1); \
2404 # define MKillDwRight(p, ml, x) ;
2405 # define MKillDwLeft(p, ml, x) ;
2409 MScrollH(p
, n
, y
, xs
, xe
, bce
)
2411 int n
, y
, xs
, xe
, bce
;
2417 ml
= &p
->w_mlines
[y
];
2418 MKillDwRight(p
, ml
, xs
);
2419 MKillDwLeft(p
, ml
, xe
);
2422 if (xe
- xs
+ 1 > n
)
2424 MKillDwRight(p
, ml
, xs
+ n
);
2425 bcopy_mline(ml
, xs
+ n
, xs
, xe
+ 1 - xs
- n
);
2429 clear_mline(ml
, xe
+ 1 - n
, n
);
2432 MBceLine(p
, y
, xe
+ 1 - n
, n
, bce
);
2438 if (xe
- xs
+ 1 > n
)
2440 MKillDwLeft(p
, ml
, xe
- n
);
2441 bcopy_mline(ml
, xs
, xs
+ n
, xe
+ 1 - xs
- n
);
2445 clear_mline(ml
, xs
, n
);
2448 MBceLine(p
, y
, xs
, n
, bce
);
2454 MScrollV(p
, n
, ys
, ye
, bce
)
2459 struct mline tmp
[256];
2468 MScrollV(p
, n
- 256, ys
, ye
, bce
);
2471 if (ye
- ys
+ 1 < n
)
2476 ye
= MFindUsedLine(p
, ye
, ys
);
2477 if (ye
- ys
+ 1 < n
)
2484 ml
= p
->w_mlines
+ ys
;
2485 for (i
= ys
; i
< ys
+ n
; i
++, ml
++)
2489 WAddLineToHist(p
, ml
);
2491 if (ml
->attr
!= null
)
2495 if (ml
->font
!= null
)
2500 if (ml
->color
!= null
)
2504 if (ml
->colorx
!= null
)
2509 bclear((char *)ml
->image
, p
->w_width
+ 1);
2512 MBceLine(p
, i
, 0, p
->w_width
, bce
);
2515 /* switch 'em over */
2516 cnt1
= n
* sizeof(struct mline
);
2517 cnt2
= (ye
- ys
+ 1 - n
) * sizeof(struct mline
);
2519 Scroll((char *)(p
->w_mlines
+ ys
), cnt1
, cnt2
, (char *)tmp
);
2525 MScrollV(p
, n
+ 256, ys
, ye
, bce
);
2529 if (ye
- ys
+ 1 < n
)
2532 ml
= p
->w_mlines
+ ye
;
2534 for (i
= ye
; i
> ye
- n
; i
--, ml
--)
2536 if (ml
->attr
!= null
)
2540 if (ml
->font
!= null
)
2545 if (ml
->color
!= null
)
2549 if (ml
->colorx
!= null
)
2554 bclear((char *)ml
->image
, p
->w_width
+ 1);
2557 MBceLine(p
, i
, 0, p
->w_width
, bce
);
2560 cnt1
= n
* sizeof(struct mline
);
2561 cnt2
= (ye
- ys
+ 1 - n
) * sizeof(struct mline
);
2563 Scroll((char *)(p
->w_mlines
+ ys
), cnt2
, cnt1
, (char *)tmp
);
2568 Scroll(cp
, cnt1
, cnt2
, tmp
)
2576 bcopy(cp
, tmp
, cnt1
);
2577 bcopy(cp
+ cnt1
, cp
, cnt2
);
2578 bcopy(tmp
, cp
+ cnt2
, cnt1
);
2582 bcopy(cp
+ cnt1
, tmp
, cnt2
);
2583 bcopy(cp
, cp
+ cnt2
, cnt1
);
2584 bcopy(tmp
, cp
, cnt2
);
2589 MClearArea(p
, xs
, ys
, xe
, ye
, bce
)
2591 int xs
, ys
, xe
, ye
, bce
;
2597 /* check for magic margin condition */
2598 if (xs
>= p
->w_width
)
2599 xs
= p
->w_width
- 1;
2600 if (xe
>= p
->w_width
)
2601 xe
= p
->w_width
- 1;
2603 MKillDwRight(p
, p
->w_mlines
+ ys
, xs
);
2604 MKillDwLeft(p
, p
->w_mlines
+ ye
, xe
);
2606 ml
= p
->w_mlines
+ ys
;
2607 for (y
= ys
; y
<= ye
; y
++, ml
++)
2609 xxe
= (y
== ye
) ? xe
: p
->w_width
- 1;
2612 clear_mline(ml
, xs
, n
);
2615 MBceLine(p
, y
, xs
, xs
+ n
- 1, bce
);
2622 MInsChar(p
, c
, x
, y
)
2630 ASSERT(x
>= 0 && x
< p
->w_width
);
2632 ml
= p
->w_mlines
+ y
;
2633 n
= p
->w_width
- x
- 1;
2634 MKillDwRight(p
, ml
, x
);
2637 MKillDwRight(p
, ml
, p
->w_width
- 1);
2638 bcopy_mline(ml
, x
, x
+ 1, n
);
2640 copy_mchar2mline(c
, ml
, x
);
2646 MKillDwRight(p
, ml
, p
->w_width
- 1);
2647 bcopy_mline(ml
, x
+ 1, x
+ 2, n
);
2649 copy_mchar2mline(c
, ml
, x
+ 1);
2650 ml
->image
[x
+ 1] = c
->mbcs
;
2652 if (p
->w_encoding
!= UTF8
)
2653 ml
->font
[x
+ 1] |= 0x80;
2654 else if (p
->w_encoding
== UTF8
&& c
->mbcs
)
2655 ml
->font
[x
+ 1] = c
->mbcs
;
2657 ml
->font
[x
+ 1] |= 0x80;
2664 MPutChar(p
, c
, x
, y
)
2672 ml
= &p
->w_mlines
[y
];
2673 MKillDwRight(p
, ml
, x
);
2674 MKillDwLeft(p
, ml
, x
);
2675 copy_mchar2mline(c
, ml
, x
);
2679 MKillDwLeft(p
, ml
, x
+ 1);
2680 copy_mchar2mline(c
, ml
, x
+ 1);
2681 ml
->image
[x
+ 1] = c
->mbcs
;
2683 if (p
->w_encoding
!= UTF8
)
2684 ml
->font
[x
+ 1] |= 0x80;
2685 else if (p
->w_encoding
== UTF8
&& c
->mbcs
)
2686 ml
->font
[x
+ 1] = c
->mbcs
;
2688 ml
->font
[x
+ 1] |= 0x80;
2696 MWrapChar(p
, c
, y
, top
, bot
, ins
)
2706 bce
= rend_getbg(c
);
2711 ml
= &p
->w_mlines
[y
];
2712 copy_mchar2mline(&mchar_null
, ml
, p
->w_width
);
2714 MScrollV(p
, 1, top
, bot
, bce
);
2715 else if (y
< p
->w_height
- 1)
2718 MInsChar(p
, c
, 0, y
);
2720 MPutChar(p
, c
, 0, y
);
2724 MPutStr(p
, s
, n
, r
, x
, y
)
2738 ml
= &p
->w_mlines
[y
];
2739 MKillDwRight(p
, ml
, x
);
2740 MKillDwLeft(p
, ml
, x
+ n
- 1);
2741 bcopy(s
, (char *)ml
->image
+ x
, n
);
2743 for (i
= n
; i
-- > 0;)
2747 for (i
= n
; i
-- > 0;)
2752 for (i
= n
; i
-- > 0;)
2756 for (i
= n
; i
-- > 0;)
2764 MBceLine(p
, y
, xs
, xe
, bce
)
2773 rend_setbg(&mc
, bce
);
2774 MFixLine(p
, y
, &mc
);
2775 ml
= p
->w_mlines
+ y
;
2778 for (x
= xs
; x
<= xe
; x
++)
2779 ml
->attr
[x
] = mc
.attr
;
2782 for (x
= xs
; x
<= xe
; x
++)
2783 ml
->color
[x
] = mc
.color
;
2786 for (x
= xs
; x
<= xe
; x
++)
2787 ml
->colorx
[x
] = mc
.colorx
;
2795 WAddLineToHist(wp
, ml
)
2799 register unsigned char *q
, *o
;
2802 if (wp
->w_histheight
== 0)
2804 hml
= &wp
->w_hlines
[wp
->w_histidx
];
2805 q
= ml
->image
; ml
->image
= hml
->image
; hml
->image
= q
;
2807 q
= ml
->attr
; o
= hml
->attr
; hml
->attr
= q
; ml
->attr
= null
;
2812 q
= ml
->font
; o
= hml
->font
; hml
->font
= q
; ml
->font
= null
;
2818 q
= ml
->color
; o
= hml
->color
; hml
->color
= q
; ml
->color
= null
;
2822 q
= ml
->colorx
; o
= hml
->colorx
; hml
->colorx
= q
; ml
->colorx
= null
;
2828 if (++wp
->w_histidx
>= wp
->w_histheight
)
2834 MFindUsedLine(p
, ye
, ys
)
2839 struct mline
*ml
= p
->w_mlines
+ ye
;
2841 debug2("MFindUsedLine: %d %d\n", ye
, ys
);
2842 for (y
= ye
; y
>= ys
; y
--, ml
--)
2844 if (bcmp((char*)ml
->image
, blank
, p
->w_width
))
2846 if (ml
->attr
!= null
&& bcmp((char*)ml
->attr
, null
, p
->w_width
))
2849 if (ml
->color
!= null
&& bcmp((char*)ml
->color
, null
, p
->w_width
))
2852 if (ml
->colorx
!= null
&& bcmp((char*)ml
->colorx
, null
, p
->w_width
))
2857 debug1("MFindUsedLine returning %d\n", y
);
2863 *====================================================================*
2864 *====================================================================*
2868 * Tricky: send only one bell even if the window is displayed
2877 for (display
= displays
; display
; display
= display
->d_next
)
2879 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2880 if (cv
->c_layer
->l_bottom
== &p
->w_layer
)
2884 else if (cv
&& D_VB
)
2887 p
->w_bell
= visual
? BELL_VISUAL
: BELL_FOUND
;
2892 * This should be reverse video.
2893 * Only change video if window is fore.
2894 * Because it is used in some termcaps to emulate
2895 * a visual bell we do this hack here.
2896 * (screen uses \Eg as special vbell sequence)
2899 WReverseVideo(p
, on
)
2904 for (cv
= p
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
2906 display
= cv
->c_display
;
2910 if (!on
&& p
->w_revvid
&& !D_CVR
)
2915 p
->w_bell
= BELL_VISUAL
;
2926 extern struct layer
*flayer
;
2927 struct layer
*oldflayer
= flayer
;
2928 flayer
= &p
->w_layer
;
2934 WChangeSize(p
, w
, h
)
2941 if (p
->w_layer
.l_cvlist
== 0)
2943 /* window not displayed -> works always */
2944 ChangeWindowSize(p
, w
, h
, p
->w_histheight
);
2947 for (cv
= p
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
2949 display
= cv
->c_display
;
2951 continue; /* change only fore */
2954 if (D_CZ0
&& (w
== Z0width
|| w
== Z1width
))
2957 if (cv
== 0 && wok
== 0) /* can't change any display */
2961 ChangeWindowSize(p
, w
, h
, p
->w_histheight
);
2962 for (display
= displays
; display
; display
= display
->d_next
)
2966 if (D_cvlist
&& D_cvlist
->c_next
== 0)
2967 ResizeDisplay(w
, h
);
2969 ResizeDisplay(w
, D_height
);
2970 ResizeLayersToCanvases(); /* XXX Hmm ? */
2973 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2974 if (cv
->c_layer
->l_bottom
== &p
->w_layer
)
2982 WindowChangedCheck(s
, what
, hp
)
2991 if (*s
++ != (hp
? '%' : '\005'))
2996 while (*s
>= '0' && *s
<= '9')
3005 if (*s
== what
|| ((*s
| l
) == what
) || what
== 'd')
3016 WindowChanged(p
, what
)
3020 int inwstr
, inhstr
, inlstr
;
3021 int inwstrh
= 0, inhstrh
= 0, inlstrh
= 0;
3023 struct display
*olddisplay
= display
;
3026 inwstr
= inhstr
= 0;
3030 WindowChanged((struct win
*)0, 'w'|0x100);
3031 WindowChanged((struct win
*)0, 'W'|0x100);
3036 inwstr
= WindowChangedCheck(captionstring
, what
, &inwstrh
);
3037 inhstr
= WindowChangedCheck(hstatusstring
, what
, &inhstrh
);
3038 inlstr
= WindowChangedCheck(wliststr
, what
, &inlstrh
);
3042 inwstr
= inhstr
= 0;
3048 for (display
= displays
; display
; display
= display
->d_next
)
3052 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
3054 if (inlstr
|| (inlstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3055 WListUpdatecv(cv
, (struct win
*)0);
3056 p
= Layer2Window(cv
->c_layer
);
3057 if (inwstr
|| (inwstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3058 if (cv
->c_ye
+ 1 < D_height
)
3059 RefreshLine(cv
->c_ye
+ 1, 0, D_width
- 1, 0);
3062 if (inhstr
|| (inhstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3064 if (ox
!= -1 && ox
!= -1)
3067 display
= olddisplay
;
3071 if (p
->w_hstatus
&& *p
->w_hstatus
&& (inwstrh
|| inhstrh
|| inlstrh
) && WindowChangedCheck(p
->w_hstatus
, what
, (int *)0))
3077 if (!inwstr
&& !inhstr
&& !inlstr
)
3079 for (display
= displays
; display
; display
= display
->d_next
)
3084 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
3087 WListUpdatecv(cv
, p
);
3088 if (Layer2Window(cv
->c_layer
) != p
)
3091 if (inwstr
&& cv
->c_ye
+ 1 < D_height
)
3092 RefreshLine(cv
->c_ye
+ 1, 0, D_width
- 1, 0);
3094 if (got
&& inhstr
&& p
== D_fore
)
3096 if (ox
!= -1 && ox
!= -1)
3099 display
= olddisplay
;