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
;
327 c
= (unsigned char)*buf
++;
332 curr
->w_rend
.font
= curr
->w_FontL
; /* Default: GL */
335 /* The next part is only for speedup */
336 if (curr
->w_state
== LIT
&&
338 curr
->w_encoding
!= UTF8
&&
341 !is_dw_font(curr
->w_rend
.font
) &&
343 curr
->w_rend
.font
!= KANA
&& !curr
->w_mbcs
&&
347 curr
->w_rend
.font
!= '<' &&
349 c
>= ' ' && c
!= 0x7f &&
350 ((c
& 0x80) == 0 || ((c
>= 0xa0 || !curr
->w_c1
) && !curr
->w_gr
)) && !curr
->w_ss
&&
351 !curr
->w_insert
&& curr
->w_x
< cols
- 1)
353 register int currx
= curr
->w_x
;
356 while (currx
< cols
- 1)
361 c
= (unsigned char)*buf
++;
362 if (c
< ' ' || c
== 0x7f || ((c
& 0x80) && ((c
< 0xa0 && curr
->w_c1
) || curr
->w_gr
)))
368 MPutStr(curr
, imp
, currx
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
369 LPutStr(&curr
->w_layer
, imp
, currx
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
375 /* end of speedup code */
378 if (curr
->w_encoding
== UTF8
)
380 c
= FromUtf8(c
, &curr
->w_decodestate
);
391 debug1("read UNICODE %04x\n", c
);
396 switch (curr
->w_state
)
402 curr
->w_state
= PRINESC
;
412 curr
->w_state
= PRINCSI
;
417 curr
->w_state
= PRIN
;
424 curr
->w_state
= PRIN4
;
430 curr
->w_state
= PRIN
;
439 if (curr
->w_pdisplay
&& curr
->w_pdisplay
->d_printfd
>= 0)
441 close(curr
->w_pdisplay
->d_printfd
);
442 curr
->w_pdisplay
->d_printfd
= -1;
444 curr
->w_pdisplay
= 0;
451 curr
->w_state
= PRIN
;
459 curr
->w_state
= STRESC
;
462 /* special xterm hack: accept SetStatus sequence. Yucc! */
463 /* allow ^E for title escapes */
464 if (!(curr
->w_StringType
== OSC
&& c
< ' ' && c
!= '\005'))
465 if (!curr
->w_c1
|| c
!= ('\\' ^ 0xc0))
476 if (StringEnd() == 0 || len
<= 1)
478 /* check if somewhere a status is displayed */
479 for (cv
= curr
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
481 display
= cv
->c_display
;
482 if (D_status
== STATUS_ON_WIN
)
487 if (len
> IOSIZE
+ 1)
489 curr
->w_outlen
= len
- 1;
490 bcopy(buf
, curr
->w_outbuf
, len
- 1);
491 return; /* wait till status is gone */
498 curr
->w_state
= ASTR
;
509 curr
->w_intermediate
= 0;
510 bzero((char *) curr
->w_args
, MAXARGS
* sizeof(int));
538 debug1("not special. c = %x\n", c
);
539 if (c
>= ' ' && c
<= '/')
541 if (curr
->w_intermediate
)
544 if (curr
->w_intermediate
== '$')
550 curr
->w_intermediate
= c
;
552 else if (c
>= '0' && c
<= '~')
554 DoESC(c
, curr
->w_intermediate
);
567 case '0': case '1': case '2': case '3': case '4':
568 case '5': case '6': case '7': case '8': case '9':
569 if (curr
->w_NumArgs
< MAXARGS
)
571 if (curr
->w_args
[curr
->w_NumArgs
] < 100000000)
572 curr
->w_args
[curr
->w_NumArgs
] =
573 10 * curr
->w_args
[curr
->w_NumArgs
] + (c
- '0');
578 if (curr
->w_NumArgs
< MAXARGS
)
584 if (c
>= '@' && c
<= '~')
586 if (curr
->w_NumArgs
< MAXARGS
)
588 DoCSI(c
, curr
->w_intermediate
);
589 if (curr
->w_state
!= PRIN
)
592 else if ((c
>= ' ' && c
<= '/') || (c
>= '<' && c
<= '?'))
593 curr
->w_intermediate
= curr
->w_intermediate
? -1 : c
;
605 if (c
<= ' ' || c
== 0x7f || (c
>= 0x80 && c
< 0xa0 && curr
->w_c1
))
612 curr
->w_intermediate
= 0;
614 if (curr
->w_autoaka
< 0)
621 if (c
>= 0x80 && c
< 0xa0 && curr
->w_c1
)
623 if ((curr
->w_FontR
& 0xf0) != 0x20
625 || curr
->w_encoding
== UTF8
636 case 0xc0 ^ 'N': /* SS2 */
637 case 0xc0 ^ 'O': /* SS3 */
641 if (curr
->w_autoaka
< 0)
644 curr
->w_intermediate
= 0;
645 bzero((char *) curr
->w_args
, MAXARGS
* sizeof(int));
662 if (c
< 0x80 || curr
->w_gr
== 0)
663 curr
->w_rend
.font
= curr
->w_FontL
;
665 else if (curr
->w_gr
== 2 && !curr
->w_ss
)
666 curr
->w_rend
.font
= curr
->w_FontE
;
669 curr
->w_rend
.font
= curr
->w_FontR
;
674 if (curr
->w_encoding
== UTF8
)
676 if (curr
->w_rend
.font
== '0')
678 struct mchar mc
, *mcp
;
680 debug1("SPECIAL %x\n", c
);
684 mcp
= recode_mchar(&mc
, 0, UTF8
);
685 debug2("%02x %02x\n", mcp
->image
, mcp
->font
);
686 c
= mcp
->image
| mcp
->font
<< 8;
688 curr
->w_rend
.font
= 0;
691 if (curr
->w_encoding
== UTF8
&& utf8_isdouble(c
))
694 if (curr
->w_encoding
== UTF8
&& c
>= 0x0300 && utf8_iscomb(c
))
703 ox
= curr
->w_width
- 1;
708 copy_mline2mchar(&omc
, &curr
->w_mlines
[oy
], ox
);
709 if (omc
.image
== 0xff && omc
.font
== 0xff)
714 copy_mline2mchar(&omc
, &curr
->w_mlines
[oy
], ox
);
720 utf8_handle_comb(c
, &omc
);
721 MFixLine(curr
, oy
, &omc
);
722 copy_mchar2mline(&omc
, &curr
->w_mlines
[oy
], ox
);
723 LPutChar(&curr
->w_layer
, &omc
, ox
, oy
);
724 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
728 font
= curr
->w_rend
.font
;
732 if (font
== KANA
&& curr
->w_encoding
== SJIS
&& curr
->w_mbcs
== 0)
734 /* Lets see if it is the first byte of a kanji */
735 debug1("%x may be first of SJIS\n", c
);
736 if ((0x81 <= c
&& c
<= 0x9f) || (0xe0 <= c
&& c
<= 0xef))
744 if (font
== 031 && c
== 0x80 && !curr
->w_mbcs
)
745 font
= curr
->w_rend
.font
= 0;
746 if (is_dw_font(font
) && c
== ' ')
747 font
= curr
->w_rend
.font
= 0;
748 if (is_dw_font(font
) || curr
->w_mbcs
)
751 if (curr
->w_mbcs
== 0)
756 if (curr
->w_x
== cols
- 1)
758 curr
->w_x
+= curr
->w_wrap
? 1 : -1;
759 debug1("Patched w_x to %d\n", curr
->w_x
);
762 if (curr
->w_encoding
!= UTF8
)
767 if (font
== KANA
&& curr
->w_encoding
== SJIS
)
769 debug2("SJIS !! %x %x\n", c
, t
);
771 * SJIS -> EUC mapping:
773 * 81,82...9f -> 21,23...5d
774 * e0,e1...ef -> 5f,61...7d
778 * 9f-fc -> 21-7e (increment first byte!)
780 if (0x40 <= t
&& t
<= 0xfc && t
!= 0x7f)
782 if (c
<= 0x9f) c
= (c
- 0x81) * 2 + 0x21;
783 else c
= (c
- 0xc1) * 2 + 0x21;
784 if (t
<= 0x7e) t
-= 0x1f;
785 else if (t
<= 0x9e) t
-= 0x20;
787 curr
->w_rend
.font
= KANJI
;
791 /* Incomplete shift-jis - skip first byte */
795 debug2("SJIS after %x %x\n", c
, t
);
798 if (t
&& curr
->w_gr
&& font
!= 030 && font
!= 031)
809 # endif /* DW_CHARS */
810 if (font
== '<' && c
>= ' ')
812 font
= curr
->w_rend
.font
= 0;
816 else if (curr
->w_gr
&& curr
->w_encoding
!= UTF8
)
822 if (c
== 0x80 && font
== 0 && curr
->w_encoding
== GBK
)
826 if (c
< ' ' && font
!= 031)
830 if (c
< ' ') /* this is ugly but kanji support */
831 goto tryagain
; /* prevents nicer programming */
837 curr
->w_rend
.image
= c
;
839 if (curr
->w_encoding
== UTF8
)
840 curr
->w_rend
.font
= c
>> 8;
843 curr
->w_rend
.mbcs
= curr
->w_mbcs
;
845 if (curr
->w_x
< cols
- 1)
849 save_mline(&curr
->w_mlines
[curr
->w_y
], cols
);
850 MInsChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
851 LInsChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
, &mline_old
);
856 MPutChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
857 LPutChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
861 else if (curr
->w_x
== cols
- 1)
863 MPutChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
864 LPutChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
870 MWrapChar(curr
, &curr
->w_rend
, curr
->w_y
, curr
->w_top
, curr
->w_bot
, curr
->w_insert
);
871 LWrapChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_y
, curr
->w_top
, curr
->w_bot
, curr
->w_insert
);
872 if (curr
->w_y
!= curr
->w_bot
&& curr
->w_y
!= curr
->w_height
- 1)
880 curr
->w_rend
.mbcs
= curr
->w_mbcs
= 0;
886 curr
->w_FontL
= curr
->w_charsets
[curr
->w_Charset
];
887 curr
->w_FontR
= curr
->w_charsets
[curr
->w_CharsetR
];
888 curr
->w_rend
.font
= curr
->w_FontL
;
889 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
898 if (!printcmd
&& curr
->w_state
== PRIN
)
903 WLogString(p
, buf
, len
)
910 if (logtstamp_on
&& p
->w_logsilence
>= logtstamp_after
* 2)
912 char *t
= MakeWinMsg(logtstamp_string
, p
, '%');
913 logfwrite(p
->w_log
, t
, strlen(t
)); /* long time no write */
916 if (logfwrite(p
->w_log
, buf
, len
) < 1)
918 WMsg(p
, errno
, "Error writing logfile");
944 WBell(curr
, visual_bell
);
950 case '\017': /* SI */
953 case '\016': /* SO */
962 DoESC(c
, intermediate
)
965 debug2("DoESC: %x - inter = %x\n", c
, intermediate
);
966 switch (intermediate
)
981 curr
->w_tabs
[curr
->w_x
] = 1;
983 case 'Z': /* jph: Identify as VT100 */
984 Report("\033[?%d;%dc", 1, 2);
995 LKeypadMode(&curr
->w_layer
, 0);
996 LCursorkeysMode(&curr
->w_layer
, 0);
998 WNewAutoFlow(curr
, 1);
1001 SetRendition(&mchar_null);
1003 ChangeScrollRegion(0, rows - 1);
1005 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1008 LKeypadMode(&curr
->w_layer
, curr
->w_keypad
= 1);
1010 WNewAutoFlow(curr
, 0);
1011 #endif /* !TIOCPKT */
1014 LKeypadMode(&curr
->w_layer
, curr
->w_keypad
= 0);
1016 WNewAutoFlow(curr
, 1);
1017 #endif /* !TIOCPKT */
1027 MapCharsetR(G1
); /* LS1R */
1031 MapCharsetR(G2
); /* LS2R */
1034 MapCharsetR(G3
); /* LS3R */
1037 if (curr
->w_charsets
[curr
->w_Charset
] != curr
->w_charsets
[G2
]
1038 || curr
->w_charsets
[curr
->w_CharsetR
] != curr
->w_charsets
[G2
])
1039 curr
->w_FontR
= curr
->w_FontL
= curr
->w_charsets
[curr
->w_ss
= G2
];
1044 if (curr
->w_charsets
[curr
->w_Charset
] != curr
->w_charsets
[G3
]
1045 || curr
->w_charsets
[curr
->w_CharsetR
] != curr
->w_charsets
[G3
])
1046 curr
->w_FontR
= curr
->w_FontL
= curr
->w_charsets
[curr
->w_ss
= G3
];
1051 case 'g': /* VBELL, private screen sequence */
1066 DesignateCharset(c
, G0
);
1069 DesignateCharset(c
, G1
);
1072 DesignateCharset(c
, G2
);
1075 DesignateCharset(c
, G3
);
1079 * ESC $ ( Fn: invoke multi-byte charset, Fn, to G0
1080 * ESC $ Fn: same as above. (old sequence)
1081 * ESC $ ) Fn: invoke multi-byte charset, Fn, to G1
1082 * ESC $ * Fn: invoke multi-byte charset, Fn, to G2
1083 * ESC $ + Fn: invoke multi-byte charset, Fn, to G3
1087 DesignateCharset(c
& 037, G0
);
1090 DesignateCharset(c
& 037, G1
);
1093 DesignateCharset(c
& 037, G2
);
1096 DesignateCharset(c
& 037, G3
);
1104 DoCSI(c
, intermediate
)
1105 int c
, intermediate
;
1107 register int i
, a1
= curr
->w_args
[0], a2
= curr
->w_args
[1];
1109 if (curr
->w_NumArgs
> MAXARGS
)
1110 curr
->w_NumArgs
= MAXARGS
;
1111 switch (intermediate
)
1128 LGotoPos(&curr
->w_layer
, --a2
, --a1
);
1131 if (curr
->w_autoaka
)
1132 curr
->w_autoaka
= a1
+ 1;
1135 if (a1
< 0 || a1
> 2)
1147 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1152 if (a1
< 0 || a1
> 2)
1157 ClearLineRegion(curr
->w_x
, cols
- 1);
1160 ClearLineRegion(0, curr
->w_x
);
1163 ClearLineRegion(0, cols
- 1);
1168 a1
= curr
->w_x
+ (a1
? a1
- 1 : 0);
1169 ClearLineRegion(curr
->w_x
, a1
< cols
? a1
: cols
- 1);
1172 CursorUp(a1
? a1
: 1);
1175 CursorDown(a1
? a1
: 1);
1178 CursorRight(a1
? a1
: 1);
1181 CursorLeft(a1
? a1
: 1);
1185 CursorDown(a1
? a1
: 1); /* positions cursor */
1189 CursorUp(a1
? a1
: 1); /* positions cursor */
1193 curr
->w_x
= a1
? a1
- 1 : 0;
1194 if (curr
->w_x
>= cols
)
1195 curr
->w_x
= cols
- 1;
1196 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1199 curr
->w_y
= a1
? a1
- 1 : 0;
1200 if (curr
->w_y
>= rows
)
1201 curr
->w_y
= rows
- 1;
1202 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1209 curr
->w_tabs
[curr
->w_x
] = 0;
1211 bzero(curr
->w_tabs
, cols
);
1218 if (a1
< 1 || a2
> rows
|| a1
>= a2
)
1220 curr
->w_top
= a1
- 1;
1221 curr
->w_bot
= a2
- 1;
1222 /* ChangeScrollRegion(curr->w_top, curr->w_bot); */
1225 curr
->w_y
= curr
->w_top
;
1229 curr
->w_y
= curr
->w_x
= 0;
1230 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1239 if (curr
->w_layer
.l_cvlist
)
1240 Report("\033[1t", 0, 0);
1242 Report("\033[2t", 0, 0);
1245 LRefreshAll(&curr
->w_layer
, 0);
1248 a1
= strlen(curr
->w_title
);
1249 if ((unsigned)(curr
->w_inlen
+ 5 + a1
) <= sizeof(curr
->w_inbuf
))
1251 bcopy("\033]l", curr
->w_inbuf
+ curr
->w_inlen
, 3);
1252 bcopy(curr
->w_title
, curr
->w_inbuf
+ curr
->w_inlen
+ 3, a1
);
1253 bcopy("\033\\", curr
->w_inbuf
+ curr
->w_inlen
+ 3 + a1
, 2);
1254 curr
->w_inlen
+= 5 + a1
;
1258 a1
= curr
->w_args
[2];
1262 a2
= curr
->w_height
;
1263 if (a1
> 10000 || a2
> 10000)
1265 WChangeSize(curr
, a1
, a2
);
1266 cols
= curr
->w_width
;
1267 rows
= curr
->w_height
;
1289 InsertLine(a1
? a1
: 1);
1292 DeleteLine(a1
? a1
: 1);
1295 DeleteChar(a1
? a1
: 1);
1298 InsertChar(a1
? a1
: 1);
1306 case 'i': /* MC Media Control */
1311 if (a1
== 5) /* Report terminal status */
1312 Report("\033[0n", 0, 0);
1313 else if (a1
== 6) /* Report cursor position */
1314 Report("\033[%d;%dR", curr
->w_y
+ 1, curr
->w_x
+ 1);
1316 case 'c': /* Identify as VT100 */
1318 Report("\033[?%d;%dc", 1, 2);
1320 case 'x': /* decreqtparm */
1321 if (a1
== 0 || a1
== 1)
1322 Report("\033[%d;1;1;112;112;1;0x", a1
+ 2, 0);
1324 case 'p': /* obscure code from a 97801 term */
1325 if (a1
== 6 || a1
== 7)
1327 curr
->w_curinv
= 7 - a1
;
1328 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
1331 case 'S': /* code from a 97801 term / DEC vt400 */
1332 ScrollRegion(a1
? a1
: 1);
1334 case 'T': /* code from a 97801 term / DEC vt400 */
1335 case '^': /* SD as per ISO 6429 */
1336 ScrollRegion(a1
? -a1
: -1);
1341 for (a2
= 0; a2
< curr
->w_NumArgs
; a2
++)
1343 a1
= curr
->w_args
[a2
];
1344 debug2("\\E[?%d%c\n",a1
,c
);
1345 if (c
!= 'h' && c
!= 'l')
1350 case 1: /* CKM: cursor key mode */
1351 LCursorkeysMode(&curr
->w_layer
, curr
->w_cursorkeys
= i
);
1353 WNewAutoFlow(curr
, !i
);
1354 #endif /* !TIOCPKT */
1356 case 2: /* ANM: ansi/vt52 mode */
1361 if (curr
->w_encoding
)
1364 curr
->w_charsets
[0] = curr
->w_charsets
[1] =
1365 curr
->w_charsets
[2] = curr
->w_charsets
[2] =
1366 curr
->w_FontL
= curr
->w_FontR
= ASCII
;
1367 curr
->w_Charset
= 0;
1368 curr
->w_CharsetR
= 2;
1373 case 3: /* COLM: column mode */
1374 i
= (i
? Z0width
: Z1width
);
1375 WChangeSize(curr
, i
, curr
->w_height
);
1376 cols
= curr
->w_width
;
1377 rows
= curr
->w_height
;
1379 /* case 4: SCLM: scrolling mode */
1380 case 5: /* SCNM: screen mode */
1381 if (i
!= curr
->w_revvid
)
1382 WReverseVideo(curr
, i
);
1385 case 6: /* OM: origin mode */
1386 if ((curr
->w_origin
= i
) != 0)
1388 curr
->w_y
= curr
->w_top
;
1392 curr
->w_y
= curr
->w_x
= 0;
1393 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1395 case 7: /* AWM: auto wrap mode */
1398 /* case 8: ARM: auto repeat mode */
1399 /* case 9: INLM: interlace mode */
1400 case 9: /* X10 mouse tracking */
1401 curr
->w_mouse
= i
? 9 : 0;
1402 LMouseMode(&curr
->w_layer
, curr
->w_mouse
);
1404 /* case 10: EDM: edit mode */
1405 /* case 11: LTM: line transmit mode */
1406 /* case 13: SCFDM: space compression / field delimiting */
1407 /* case 14: TEM: transmit execution mode */
1408 /* case 16: EKEM: edit key execution mode */
1409 /* case 18: PFF: Printer term form feed */
1410 /* case 19: PEX: Printer extend screen / scroll. reg */
1411 case 25: /* TCEM: text cursor enable mode */
1412 curr
->w_curinv
= !i
;
1413 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
1415 /* case 34: RLM: Right to left mode */
1416 /* case 35: HEBM: hebrew keyboard map */
1417 /* case 36: HEM: hebrew encoding */
1418 /* case 38: TeK Mode */
1419 /* case 40: 132 col enable */
1420 /* case 42: NRCM: 7bit NRC character mode */
1421 /* case 44: margin bell enable */
1422 case 47: /* xterm-like alternate screen */
1423 case 1047: /* xterm-like alternate screen */
1424 case 1049: /* xterm-like alternate screen */
1428 EnterAltScreen(curr
);
1430 LeaveAltScreen(curr
);
1433 LRefreshAll(&curr
->w_layer
, 0);
1434 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1437 /* case 66: NKM: Numeric keypad appl mode */
1438 /* case 68: KBUM: Keyboard usage mode (data process) */
1439 case 1000: /* VT200 mouse tracking */
1440 case 1001: /* VT200 highlight mouse */
1441 case 1002: /* button event mouse*/
1442 case 1003: /* any event mouse*/
1443 curr
->w_mouse
= i
? a1
: 0;
1444 LMouseMode(&curr
->w_layer
, curr
->w_mouse
);
1452 case 'c': /* secondary DA */
1454 Report("\033[>%d;%d;0c", 83, nversion
); /* 83 == 'S' */
1466 curr
->w_StringType
= type
;
1467 curr
->w_stringp
= curr
->w_string
;
1468 curr
->w_state
= ASTR
;
1475 if (curr
->w_stringp
>= curr
->w_string
+ MAXSTR
- 1)
1476 curr
->w_state
= LIT
;
1478 *(curr
->w_stringp
)++ = c
;
1482 * Do string processing. Returns -1 if output should be suspended
1483 * until status is gone.
1492 curr
->w_state
= LIT
;
1493 *curr
->w_stringp
= '\0';
1494 switch (curr
->w_StringType
)
1496 case OSC
: /* special xterm compatibility hack */
1497 if (curr
->w_string
[0] == ';' || (p
= index(curr
->w_string
, ';')) == 0)
1499 typ
= atoi(curr
->w_string
);
1502 if (typ
== 83) /* 83 = 'S' */
1504 /* special execute commands sequence */
1505 char *args
[MAXARGS
];
1507 struct acluser
*windowuser
;
1509 windowuser
= *FindUserPtr(":window:");
1510 if (windowuser
&& Parse(p
, sizeof(curr
->w_string
) - (p
- curr
->w_string
), args
, argl
))
1512 for (display
= displays
; display
; display
= display
->d_next
)
1513 if (D_forecv
->c_layer
->l_bottom
== &curr
->w_layer
)
1514 break; /* found it */
1515 if (display
== 0 && curr
->w_layer
.l_cvlist
)
1516 display
= curr
->w_layer
.l_cvlist
->c_display
;
1519 EffectiveAclUser
= windowuser
;
1521 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1522 DoCommand(args
, argl
);
1523 EffectiveAclUser
= 0;
1531 if (typ
== 0 || typ
== 1 || typ
== 20 || typ
== 39 || typ
== 49)
1537 if (strcmp(curr
->w_xtermosc
[typ2
], p
))
1539 strncpy(curr
->w_xtermosc
[typ2
], p
, sizeof(curr
->w_xtermosc
[typ2
]) - 1);
1540 curr
->w_xtermosc
[typ2
][sizeof(curr
->w_xtermosc
[typ2
]) - 1] = 0;
1542 for (display
= displays
; display
; display
= display
->d_next
)
1546 if (D_forecv
->c_layer
->l_bottom
== &curr
->w_layer
)
1547 SetXtermOSC(typ2
, curr
->w_xtermosc
[typ2
]);
1548 if ((typ2
== 2 || typ2
== 3) && D_xtermosc
[typ2
])
1553 if (typ
!= 0 && typ
!= 2)
1556 if (typ
< 0 || typ
> 2)
1560 curr
->w_stringp
-= p
- curr
->w_string
;
1561 if (curr
->w_stringp
> curr
->w_string
)
1562 bcopy(p
, curr
->w_string
, curr
->w_stringp
- curr
->w_string
);
1563 *curr
->w_stringp
= '\0';
1566 if (curr
->w_hstatus
)
1568 if (strcmp(curr
->w_hstatus
, curr
->w_string
) == 0)
1569 break; /* not changed */
1570 free(curr
->w_hstatus
);
1571 curr
->w_hstatus
= 0;
1573 if (curr
->w_string
!= curr
->w_stringp
)
1574 curr
->w_hstatus
= SaveStr(curr
->w_string
);
1575 WindowChanged(curr
, 'h');
1579 for (display
= displays
; display
; display
= display
->d_next
)
1581 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
1582 if (cv
->c_layer
->l_bottom
== &curr
->w_layer
)
1584 if (cv
|| curr
->w_StringType
== GM
)
1585 MakeStatus(curr
->w_string
);
1589 LAY_DISPLAYS(&curr
->w_layer
, AddStr(curr
->w_string
));
1592 if (curr
->w_title
== curr
->w_akabuf
&& !*curr
->w_string
)
1594 ChangeAKA(curr
, curr
->w_string
, strlen(curr
->w_string
));
1595 if (!*curr
->w_string
)
1596 curr
->w_autoaka
= curr
->w_y
+ 1;
1607 curr
->w_pdisplay
= 0;
1609 /* find us a nice display to print on, fore prefered */
1610 display
= curr
->w_lastdisp
;
1611 if (!(display
&& curr
== D_fore
&& (printcmd
|| D_PO
)))
1612 for (display
= displays
; display
; display
= display
->d_next
)
1613 if (curr
== D_fore
&& (printcmd
|| D_PO
))
1618 for (cv
= curr
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
1620 display
= cv
->c_display
;
1621 if (printcmd
|| D_PO
)
1627 if (!display
|| display
->d_next
|| !(printcmd
|| D_PO
))
1631 curr
->w_pdisplay
= display
;
1632 curr
->w_stringp
= curr
->w_string
;
1633 curr
->w_state
= PRIN
;
1634 if (printcmd
&& curr
->w_pdisplay
->d_printfd
< 0)
1635 curr
->w_pdisplay
->d_printfd
= printpipe(curr
, printcmd
);
1642 if (curr
->w_stringp
>= curr
->w_string
+ MAXSTR
- 1)
1644 *(curr
->w_stringp
)++ = c
;
1650 display
= curr
->w_pdisplay
;
1651 if (display
&& printcmd
)
1653 char *bp
= curr
->w_string
;
1654 int len
= curr
->w_stringp
- curr
->w_string
;
1656 while (len
&& display
->d_printfd
>= 0)
1658 r
= write(display
->d_printfd
, bp
, len
);
1661 WMsg(curr
, errno
, "printing aborted");
1662 close(display
->d_printfd
);
1663 display
->d_printfd
= -1;
1670 else if (display
&& curr
->w_stringp
> curr
->w_string
)
1673 AddStrn(curr
->w_string
, curr
->w_stringp
- curr
->w_string
);
1677 curr
->w_stringp
= curr
->w_string
;
1682 WNewAutoFlow(win
, on
)
1686 debug1("WNewAutoFlow: %d\n", on
);
1687 if (win
->w_flow
& FLOW_AUTOFLAG
)
1688 win
->w_flow
= FLOW_AUTOFLAG
| (FLOW_AUTO
|FLOW_NOW
) * on
;
1690 win
->w_flow
= (win
->w_flow
& ~FLOW_AUTO
) | FLOW_AUTO
* on
;
1691 LSetFlow(&win
->w_layer
, win
->w_flow
& FLOW_NOW
);
1698 DesignateCharset(c
, n
)
1703 if (c
== ('@' & 037)) /* map JIS 6226 to 0208 */
1708 if (curr
->w_charsets
[n
] != c
)
1710 curr
->w_charsets
[n
] = c
;
1711 if (curr
->w_Charset
== n
)
1714 curr
->w_rend
.font
= curr
->w_FontL
;
1715 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1717 if (curr
->w_CharsetR
== n
)
1727 if (curr
->w_Charset
!= n
)
1729 curr
->w_Charset
= n
;
1730 curr
->w_FontL
= curr
->w_charsets
[n
];
1731 curr
->w_rend
.font
= curr
->w_FontL
;
1732 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1741 if (curr
->w_CharsetR
!= n
)
1743 curr
->w_CharsetR
= n
;
1744 curr
->w_FontR
= curr
->w_charsets
[n
];
1755 curr
->w_Saved_x
= curr
->w_x
;
1756 curr
->w_Saved_y
= curr
->w_y
;
1757 curr
->w_SavedRend
= curr
->w_rend
;
1759 curr
->w_SavedCharset
= curr
->w_Charset
;
1760 curr
->w_SavedCharsetR
= curr
->w_CharsetR
;
1761 bcopy((char *) curr
->w_charsets
, (char *) curr
->w_SavedCharsets
,
1771 LGotoPos(&curr
->w_layer
, curr
->w_Saved_x
, curr
->w_Saved_y
);
1772 curr
->w_x
= curr
->w_Saved_x
;
1773 curr
->w_y
= curr
->w_Saved_y
;
1774 curr
->w_rend
= curr
->w_SavedRend
;
1776 bcopy((char *) curr
->w_SavedCharsets
, (char *) curr
->w_charsets
,
1778 curr
->w_Charset
= curr
->w_SavedCharset
;
1779 curr
->w_CharsetR
= curr
->w_SavedCharsetR
;
1781 curr
->w_FontL
= curr
->w_charsets
[curr
->w_Charset
];
1782 curr
->w_FontR
= curr
->w_charsets
[curr
->w_CharsetR
];
1784 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1794 else if (curr
->w_wrap
&& curr
->w_y
> 0)
1796 curr
->w_x
= cols
- 1;
1799 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1808 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1815 /* out_mode: 0=lf, 1=cr+lf */
1818 if (curr
->w_y
!= curr
->w_bot
) /* Don't scroll */
1820 if (curr
->w_y
< rows
-1)
1822 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1825 if (curr
->w_autoaka
> 1)
1827 MScrollV(curr
, 1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1828 LScrollV(&curr
->w_layer
, 1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1829 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1835 if (curr
->w_y
== curr
->w_top
)
1837 MScrollV(curr
, -1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1838 LScrollV(&curr
->w_layer
, -1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1839 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1841 else if (curr
->w_y
> 0)
1849 register int y
= curr
->w_y
, x
= curr
->w_x
;
1855 save_mline(&curr
->w_mlines
[y
], cols
);
1856 MScrollH(curr
, -n
, y
, x
, curr
->w_width
- 1, CURR_BCE
);
1857 LScrollH(&curr
->w_layer
, -n
, y
, x
, curr
->w_width
- 1, CURR_BCE
, &mline_old
);
1858 LGotoPos(&curr
->w_layer
, x
, y
);
1865 register int y
= curr
->w_y
, x
= curr
->w_x
;
1869 save_mline(&curr
->w_mlines
[y
], cols
);
1870 MScrollH(curr
, n
, y
, x
, curr
->w_width
- 1, CURR_BCE
);
1871 LScrollH(&curr
->w_layer
, n
, y
, x
, curr
->w_width
- 1, CURR_BCE
, &mline_old
);
1872 LGotoPos(&curr
->w_layer
, x
, y
);
1879 if (curr
->w_y
< curr
->w_top
|| curr
->w_y
> curr
->w_bot
)
1881 if (n
> curr
->w_bot
- curr
->w_y
+ 1)
1882 n
= curr
->w_bot
- curr
->w_y
+ 1;
1883 MScrollV(curr
, n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1884 LScrollV(&curr
->w_layer
, n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1885 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1892 if (curr
->w_y
< curr
->w_top
|| curr
->w_y
> curr
->w_bot
)
1894 if (n
> curr
->w_bot
- curr
->w_y
+ 1)
1895 n
= curr
->w_bot
- curr
->w_y
+ 1;
1896 MScrollV(curr
, -n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1897 LScrollV(&curr
->w_layer
, -n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1898 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1905 MScrollV(curr
, n
, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1906 LScrollV(&curr
->w_layer
, n
, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1907 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1914 register int x
= curr
->w_x
;
1921 if (curr
->w_tabs
[x
] && x
< cols
- 1)
1923 while (x
< cols
- 1 && !curr
->w_tabs
[x
])
1926 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1932 register int x
= curr
->w_x
;
1934 if (curr
->w_tabs
[x
] && x
> 0)
1936 while (x
> 0 && !curr
->w_tabs
[x
])
1939 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1945 LClearArea(&curr
->w_layer
, 0, 0, curr
->w_width
- 1, curr
->w_height
- 1, CURR_BCE
, 1);
1947 MScrollV(curr
, curr
->w_height
, 0, curr
->w_height
- 1, CURR_BCE
);
1949 MClearArea(curr
, 0, 0, curr
->w_width
- 1, curr
->w_height
- 1, CURR_BCE
);
1956 register int y
= curr
->w_y
, x
= curr
->w_x
;
1958 LClearArea(&curr
->w_layer
, 0, 0, x
, y
, CURR_BCE
, 1);
1959 MClearArea(curr
, 0, 0, x
, y
, CURR_BCE
);
1960 RestorePosRendition();
1966 register int y
= curr
->w_y
, x
= curr
->w_x
;
1968 if (x
== 0 && y
== 0)
1971 RestorePosRendition();
1974 LClearArea(&curr
->w_layer
, x
, y
, cols
- 1, rows
- 1, CURR_BCE
, 1);
1975 MClearArea(curr
, x
, y
, cols
- 1, rows
- 1, CURR_BCE
);
1976 RestorePosRendition();
1980 ClearLineRegion(from
, to
)
1983 register int y
= curr
->w_y
;
1984 LClearArea(&curr
->w_layer
, from
, y
, to
, y
, CURR_BCE
, 1);
1985 MClearArea(curr
, from
, y
, to
, y
, CURR_BCE
);
1986 RestorePosRendition();
1993 register int x
= curr
->w_x
;
2000 if ((curr
->w_x
+= n
) >= cols
)
2001 curr
->w_x
= cols
- 1;
2002 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2009 if (curr
->w_y
< curr
->w_top
) /* if above scrolling rgn, */
2011 if ((curr
->w_y
-= n
) < 0) /* ignore its limits */
2015 if ((curr
->w_y
-= n
) < curr
->w_top
)
2016 curr
->w_y
= curr
->w_top
;
2017 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2024 if (curr
->w_y
> curr
->w_bot
) /* if below scrolling rgn, */
2026 if ((curr
->w_y
+= n
) > rows
- 1) /* ignore its limits */
2027 curr
->w_y
= rows
- 1;
2030 if ((curr
->w_y
+= n
) > curr
->w_bot
)
2031 curr
->w_y
= curr
->w_bot
;
2032 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2039 if ((curr
->w_x
-= n
) < 0)
2041 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2050 for (i
= 0; i
< curr
->w_NumArgs
; ++i
)
2052 switch (curr
->w_args
[i
])
2054 /* case 2: KAM: Lock keyboard */
2055 case 4: /* IRM: Insert mode */
2056 curr
->w_insert
= on
;
2057 LAY_DISPLAYS(&curr
->w_layer
, InsertMode(on
));
2059 /* case 12: SRM: Echo mode on */
2060 case 20: /* LNM: Linefeed mode */
2061 curr
->w_autolf
= on
;
2064 curr
->w_curvvis
= !on
;
2065 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
2073 static char rendlist
[] =
2075 ~((1 << NATTR
) - 1), A_BD
, A_DI
, A_SO
, A_US
, A_BL
, 0, A_RV
, 0, 0,
2076 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2077 0, 0, ~(A_BD
|A_SO
|A_DI
), ~A_SO
, ~A_US
, ~A_BL
, 0, ~A_RV
2084 register int j
, i
= 0, a
= curr
->w_rend
.attr
, c
= curr
->w_rend
.color
;
2086 int cx
= curr
->w_rend
.colorx
;
2089 register int j
, i
= 0, a
= curr
->w_rend
.attr
;
2094 j
= curr
->w_args
[i
];
2096 if ((j
== 38 || j
== 48) && i
+ 2 < curr
->w_NumArgs
&& curr
->w_args
[i
+ 1] == 5)
2101 jj
= curr
->w_args
[i
];
2102 if (jj
< 0 || jj
> 255)
2107 c
= (c
& 0xf0) | ((jj
& 0x0f) ^ 9);
2109 if (jj
>= 8 && jj
< 16)
2113 a
= (a
& 0xbf) | (jj
& 8 ? 0x40 : 0);
2114 cx
= (cx
& 0xf0) | (jj
>> 4 & 0x0f);
2118 c
= (c
& 0x0f) | ((jj
& 0x0f) ^ 9) << 4;
2120 if (jj
>= 8 && jj
< 16)
2124 cx
= (cx
& 0x0f) | (jj
& 0xf0);
2128 jj
= color256to16(jj
) + 30;
2131 j
= j
== 38 ? jj
: jj
+ 10;
2135 if (j
== 0 || (j
>= 30 && j
<= 39 && j
!= 38))
2137 if (j
== 0 || (j
>= 40 && j
<= 49 && j
!= 48))
2139 if (j
>= 90 && j
<= 97)
2141 if (j
>= 100 && j
<= 107)
2144 if (j
>= 90 && j
<= 97)
2146 if (j
>= 100 && j
<= 107)
2148 if (j
>= 30 && j
<= 39 && j
!= 38)
2149 c
= (c
& 0xf0) | ((j
- 30) ^ 9);
2150 else if (j
>= 40 && j
<= 49 && j
!= 48)
2151 c
= (c
& 0x0f) | (((j
- 40) ^ 9) << 4);
2155 if (j
== 0 || (j
>= 30 && j
<= 39 && j
!= 38))
2157 if (j
== 0 || (j
>= 40 && j
<= 49 && j
!= 48))
2161 if (j
< 0 || j
>= (int)(sizeof(rendlist
)/sizeof(*rendlist
)))
2164 if (j
& (1 << NATTR
))
2169 while (++i
< curr
->w_NumArgs
);
2170 curr
->w_rend
.attr
= a
;
2172 curr
->w_rend
.color
= c
;
2174 curr
->w_rend
.colorx
= cx
;
2177 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
2184 register unsigned char *p
, *ep
;
2186 LClearAll(&curr
->w_layer
, 1);
2187 curr
->w_y
= curr
->w_x
= 0;
2188 for (i
= 0; i
< rows
; ++i
)
2190 clear_mline(&curr
->w_mlines
[i
], 0, cols
+ 1);
2191 p
= curr
->w_mlines
[i
].image
;
2196 LRefreshAll(&curr
->w_layer
, 1);
2201 * Ugly autoaka hack support:
2202 * ChangeAKA() sets a new aka
2203 * FindAKA() searches for an autoaka match
2214 for (i
= 0; l
> 0; l
--)
2216 if (p
->w_akachange
+ i
== p
->w_akabuf
+ sizeof(p
->w_akabuf
) - 1)
2218 c
= (unsigned char)*s
++;
2221 if (c
< 32 || c
== 127 || (c
>= 128 && c
< 160 && p
->w_c1
))
2223 p
->w_akachange
[i
++] = c
;
2225 p
->w_akachange
[i
] = 0;
2226 p
->w_title
= p
->w_akachange
;
2227 if (p
->w_akachange
!= p
->w_akabuf
)
2228 if (p
->w_akachange
[0] == 0 || p
->w_akachange
[-1] == ':')
2229 p
->w_title
= p
->w_akabuf
+ strlen(p
->w_akabuf
) + 1;
2230 WindowChanged(p
, 't');
2231 WindowChanged((struct win
*)0, 'w');
2232 WindowChanged((struct win
*)0, 'W');
2238 register unsigned char *cp
, *line
;
2239 register struct win
*wp
= curr
;
2240 register int len
= strlen(wp
->w_akabuf
);
2243 y
= (wp
->w_autoaka
> 0 && wp
->w_autoaka
<= wp
->w_height
) ? wp
->w_autoaka
- 1 : wp
->w_y
;
2246 cp
= line
= wp
->w_mlines
[y
].image
;
2247 if (wp
->w_autoaka
> 0 && *wp
->w_akabuf
!= '\0')
2251 if (cp
- line
>= cols
- len
)
2253 if (++y
== wp
->w_autoaka
&& y
< rows
)
2257 if (strncmp((char *)cp
, wp
->w_akabuf
, len
) == 0)
2263 for (len
= cols
- (cp
- line
); len
&& *cp
== ' '; len
--, cp
++)
2267 if (wp
->w_autoaka
> 0 && (*cp
== '!' || *cp
== '%' || *cp
== '^'))
2272 while (len
&& *cp
!= ' ')
2278 ChangeAKA(wp
, (char *)line
, cp
- line
);
2285 RestorePosRendition()
2287 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2288 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
2291 /* Send a terminal report as if it were typed. */
2298 char rbuf
[40]; /* enough room for all replys */
2300 sprintf(rbuf
, fmt
, n1
, n2
);
2306 if ((unsigned)(curr
->w_pwin
->p_inlen
+ len
) <= sizeof(curr
->w_pwin
->p_inbuf
))
2308 bcopy(rbuf
, curr
->w_pwin
->p_inbuf
+ curr
->w_pwin
->p_inlen
, len
);
2309 curr
->w_pwin
->p_inlen
+= len
;
2315 if ((unsigned)(curr
->w_inlen
+ len
) <= sizeof(curr
->w_inbuf
))
2317 bcopy(rbuf
, curr
->w_inbuf
+ curr
->w_inlen
, len
);
2318 curr
->w_inlen
+= len
;
2326 *====================================================================*
2327 *====================================================================*
2330 /**********************************************************************
2342 struct mline
*ml
= &p
->w_mlines
[y
];
2343 if (mc
->attr
&& ml
->attr
== null
)
2345 if ((ml
->attr
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2348 mc
->attr
= p
->w_rend
.attr
= 0;
2349 WMsg(p
, 0, "Warning: no space for attr - turned off");
2353 if (mc
->font
&& ml
->font
== null
)
2355 if ((ml
->font
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2358 p
->w_FontL
= p
->w_charsets
[p
->w_ss
? p
->w_ss
: p
->w_Charset
] = 0;
2359 p
->w_FontR
= p
->w_charsets
[p
->w_ss
? p
->w_ss
: p
->w_CharsetR
] = 0;
2360 mc
->font
= p
->w_rend
.font
= 0;
2361 WMsg(p
, 0, "Warning: no space for font - turned off");
2366 if (mc
->color
&& ml
->color
== null
)
2368 if ((ml
->color
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2371 mc
->color
= p
->w_rend
.color
= 0;
2372 WMsg(p
, 0, "Warning: no space for color - turned off");
2376 if (mc
->colorx
&& ml
->colorx
== null
)
2378 if ((ml
->colorx
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2381 mc
->colorx
= p
->w_rend
.colorx
= 0;
2382 WMsg(p
, 0, "Warning: no space for extended colors - turned off");
2389 /*****************************************************************/
2392 # define MKillDwRight(p, ml, x) \
2393 if (dw_right(ml, x, p->w_encoding)) \
2396 copy_mchar2mline(&mchar_blank, ml, x - 1); \
2397 copy_mchar2mline(&mchar_blank, ml, x); \
2400 # define MKillDwLeft(p, ml, x) \
2401 if (dw_left(ml, x, p->w_encoding)) \
2403 copy_mchar2mline(&mchar_blank, ml, x); \
2404 copy_mchar2mline(&mchar_blank, ml, x + 1); \
2407 # define MKillDwRight(p, ml, x) ;
2408 # define MKillDwLeft(p, ml, x) ;
2412 MScrollH(p
, n
, y
, xs
, xe
, bce
)
2414 int n
, y
, xs
, xe
, bce
;
2420 ml
= &p
->w_mlines
[y
];
2421 MKillDwRight(p
, ml
, xs
);
2422 MKillDwLeft(p
, ml
, xe
);
2425 if (xe
- xs
+ 1 > n
)
2427 MKillDwRight(p
, ml
, xs
+ n
);
2428 bcopy_mline(ml
, xs
+ n
, xs
, xe
+ 1 - xs
- n
);
2432 clear_mline(ml
, xe
+ 1 - n
, n
);
2435 MBceLine(p
, y
, xe
+ 1 - n
, n
, bce
);
2441 if (xe
- xs
+ 1 > n
)
2443 MKillDwLeft(p
, ml
, xe
- n
);
2444 bcopy_mline(ml
, xs
, xs
+ n
, xe
+ 1 - xs
- n
);
2448 clear_mline(ml
, xs
, n
);
2451 MBceLine(p
, y
, xs
, n
, bce
);
2457 MScrollV(p
, n
, ys
, ye
, bce
)
2462 struct mline tmp
[256];
2471 MScrollV(p
, n
- 256, ys
, ye
, bce
);
2474 if (ye
- ys
+ 1 < n
)
2479 ye
= MFindUsedLine(p
, ye
, ys
);
2480 if (ye
- ys
+ 1 < n
)
2487 ml
= p
->w_mlines
+ ys
;
2488 for (i
= ys
; i
< ys
+ n
; i
++, ml
++)
2492 WAddLineToHist(p
, ml
);
2494 if (ml
->attr
!= null
)
2498 if (ml
->font
!= null
)
2503 if (ml
->color
!= null
)
2507 if (ml
->colorx
!= null
)
2512 bclear((char *)ml
->image
, p
->w_width
+ 1);
2515 MBceLine(p
, i
, 0, p
->w_width
, bce
);
2518 /* switch 'em over */
2519 cnt1
= n
* sizeof(struct mline
);
2520 cnt2
= (ye
- ys
+ 1 - n
) * sizeof(struct mline
);
2522 Scroll((char *)(p
->w_mlines
+ ys
), cnt1
, cnt2
, (char *)tmp
);
2528 MScrollV(p
, n
+ 256, ys
, ye
, bce
);
2532 if (ye
- ys
+ 1 < n
)
2535 ml
= p
->w_mlines
+ ye
;
2537 for (i
= ye
; i
> ye
- n
; i
--, ml
--)
2539 if (ml
->attr
!= null
)
2543 if (ml
->font
!= null
)
2548 if (ml
->color
!= null
)
2552 if (ml
->colorx
!= null
)
2557 bclear((char *)ml
->image
, p
->w_width
+ 1);
2560 MBceLine(p
, i
, 0, p
->w_width
, bce
);
2563 cnt1
= n
* sizeof(struct mline
);
2564 cnt2
= (ye
- ys
+ 1 - n
) * sizeof(struct mline
);
2566 Scroll((char *)(p
->w_mlines
+ ys
), cnt2
, cnt1
, (char *)tmp
);
2571 Scroll(cp
, cnt1
, cnt2
, tmp
)
2579 bcopy(cp
, tmp
, cnt1
);
2580 bcopy(cp
+ cnt1
, cp
, cnt2
);
2581 bcopy(tmp
, cp
+ cnt2
, cnt1
);
2585 bcopy(cp
+ cnt1
, tmp
, cnt2
);
2586 bcopy(cp
, cp
+ cnt2
, cnt1
);
2587 bcopy(tmp
, cp
, cnt2
);
2592 MClearArea(p
, xs
, ys
, xe
, ye
, bce
)
2594 int xs
, ys
, xe
, ye
, bce
;
2600 /* Check for zero-height window */
2601 if (ys
< 0 || ye
< ys
)
2604 /* check for magic margin condition */
2605 if (xs
>= p
->w_width
)
2606 xs
= p
->w_width
- 1;
2607 if (xe
>= p
->w_width
)
2608 xe
= p
->w_width
- 1;
2610 MKillDwRight(p
, p
->w_mlines
+ ys
, xs
);
2611 MKillDwLeft(p
, p
->w_mlines
+ ye
, xe
);
2613 ml
= p
->w_mlines
+ ys
;
2614 for (y
= ys
; y
<= ye
; y
++, ml
++)
2616 xxe
= (y
== ye
) ? xe
: p
->w_width
- 1;
2619 clear_mline(ml
, xs
, n
);
2622 MBceLine(p
, y
, xs
, xs
+ n
- 1, bce
);
2629 MInsChar(p
, c
, x
, y
)
2637 ASSERT(x
>= 0 && x
< p
->w_width
);
2639 ml
= p
->w_mlines
+ y
;
2640 n
= p
->w_width
- x
- 1;
2641 MKillDwRight(p
, ml
, x
);
2644 MKillDwRight(p
, ml
, p
->w_width
- 1);
2645 bcopy_mline(ml
, x
, x
+ 1, n
);
2647 copy_mchar2mline(c
, ml
, x
);
2653 MKillDwRight(p
, ml
, p
->w_width
- 1);
2654 bcopy_mline(ml
, x
+ 1, x
+ 2, n
);
2656 copy_mchar2mline(c
, ml
, x
+ 1);
2657 ml
->image
[x
+ 1] = c
->mbcs
;
2659 if (p
->w_encoding
!= UTF8
)
2660 ml
->font
[x
+ 1] |= 0x80;
2661 else if (p
->w_encoding
== UTF8
&& c
->mbcs
)
2662 ml
->font
[x
+ 1] = c
->mbcs
;
2664 ml
->font
[x
+ 1] |= 0x80;
2671 MPutChar(p
, c
, x
, y
)
2679 ml
= &p
->w_mlines
[y
];
2680 MKillDwRight(p
, ml
, x
);
2681 MKillDwLeft(p
, ml
, x
);
2682 copy_mchar2mline(c
, ml
, x
);
2686 MKillDwLeft(p
, ml
, x
+ 1);
2687 copy_mchar2mline(c
, ml
, x
+ 1);
2688 ml
->image
[x
+ 1] = c
->mbcs
;
2690 if (p
->w_encoding
!= UTF8
)
2691 ml
->font
[x
+ 1] |= 0x80;
2692 else if (p
->w_encoding
== UTF8
&& c
->mbcs
)
2693 ml
->font
[x
+ 1] = c
->mbcs
;
2695 ml
->font
[x
+ 1] |= 0x80;
2703 MWrapChar(p
, c
, y
, top
, bot
, ins
)
2713 bce
= rend_getbg(c
);
2718 ml
= &p
->w_mlines
[y
];
2719 copy_mchar2mline(&mchar_null
, ml
, p
->w_width
);
2721 MScrollV(p
, 1, top
, bot
, bce
);
2722 else if (y
< p
->w_height
- 1)
2725 MInsChar(p
, c
, 0, y
);
2727 MPutChar(p
, c
, 0, y
);
2731 MPutStr(p
, s
, n
, r
, x
, y
)
2745 ml
= &p
->w_mlines
[y
];
2746 MKillDwRight(p
, ml
, x
);
2747 MKillDwLeft(p
, ml
, x
+ n
- 1);
2748 bcopy(s
, (char *)ml
->image
+ x
, n
);
2750 for (i
= n
; i
-- > 0;)
2754 for (i
= n
; i
-- > 0;)
2759 for (i
= n
; i
-- > 0;)
2763 for (i
= n
; i
-- > 0;)
2771 MBceLine(p
, y
, xs
, xe
, bce
)
2780 rend_setbg(&mc
, bce
);
2781 MFixLine(p
, y
, &mc
);
2782 ml
= p
->w_mlines
+ y
;
2785 for (x
= xs
; x
<= xe
; x
++)
2786 ml
->attr
[x
] = mc
.attr
;
2789 for (x
= xs
; x
<= xe
; x
++)
2790 ml
->color
[x
] = mc
.color
;
2793 for (x
= xs
; x
<= xe
; x
++)
2794 ml
->colorx
[x
] = mc
.colorx
;
2802 WAddLineToHist(wp
, ml
)
2806 register unsigned char *q
, *o
;
2809 if (wp
->w_histheight
== 0)
2811 hml
= &wp
->w_hlines
[wp
->w_histidx
];
2812 q
= ml
->image
; ml
->image
= hml
->image
; hml
->image
= q
;
2814 q
= ml
->attr
; o
= hml
->attr
; hml
->attr
= q
; ml
->attr
= null
;
2819 q
= ml
->font
; o
= hml
->font
; hml
->font
= q
; ml
->font
= null
;
2825 q
= ml
->color
; o
= hml
->color
; hml
->color
= q
; ml
->color
= null
;
2829 q
= ml
->colorx
; o
= hml
->colorx
; hml
->colorx
= q
; ml
->colorx
= null
;
2835 if (++wp
->w_histidx
>= wp
->w_histheight
)
2841 MFindUsedLine(p
, ye
, ys
)
2846 struct mline
*ml
= p
->w_mlines
+ ye
;
2848 debug2("MFindUsedLine: %d %d\n", ye
, ys
);
2849 for (y
= ye
; y
>= ys
; y
--, ml
--)
2851 if (bcmp((char*)ml
->image
, blank
, p
->w_width
))
2853 if (ml
->attr
!= null
&& bcmp((char*)ml
->attr
, null
, p
->w_width
))
2856 if (ml
->color
!= null
&& bcmp((char*)ml
->color
, null
, p
->w_width
))
2859 if (ml
->colorx
!= null
&& bcmp((char*)ml
->colorx
, null
, p
->w_width
))
2864 debug1("MFindUsedLine returning %d\n", y
);
2870 *====================================================================*
2871 *====================================================================*
2875 * Tricky: send only one bell even if the window is displayed
2884 for (display
= displays
; display
; display
= display
->d_next
)
2886 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2887 if (cv
->c_layer
->l_bottom
== &p
->w_layer
)
2891 else if (cv
&& D_VB
)
2894 p
->w_bell
= visual
? BELL_VISUAL
: BELL_FOUND
;
2899 * This should be reverse video.
2900 * Only change video if window is fore.
2901 * Because it is used in some termcaps to emulate
2902 * a visual bell we do this hack here.
2903 * (screen uses \Eg as special vbell sequence)
2906 WReverseVideo(p
, on
)
2911 for (cv
= p
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
2913 display
= cv
->c_display
;
2917 if (!on
&& p
->w_revvid
&& !D_CVR
)
2922 p
->w_bell
= BELL_VISUAL
;
2933 extern struct layer
*flayer
;
2934 struct layer
*oldflayer
= flayer
;
2935 flayer
= &p
->w_layer
;
2941 WChangeSize(p
, w
, h
)
2948 if (p
->w_layer
.l_cvlist
== 0)
2950 /* window not displayed -> works always */
2951 ChangeWindowSize(p
, w
, h
, p
->w_histheight
);
2954 for (cv
= p
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
2956 display
= cv
->c_display
;
2958 continue; /* change only fore */
2961 if (D_CZ0
&& (w
== Z0width
|| w
== Z1width
))
2964 if (cv
== 0 && wok
== 0) /* can't change any display */
2968 ChangeWindowSize(p
, w
, h
, p
->w_histheight
);
2969 for (display
= displays
; display
; display
= display
->d_next
)
2973 if (D_cvlist
&& D_cvlist
->c_next
== 0)
2974 ResizeDisplay(w
, h
);
2976 ResizeDisplay(w
, D_height
);
2977 ResizeLayersToCanvases(); /* XXX Hmm ? */
2980 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2981 if (cv
->c_layer
->l_bottom
== &p
->w_layer
)
2989 WindowChangedCheck(s
, what
, hp
)
2998 if (*s
++ != (hp
? '%' : '\005'))
3003 while (*s
>= '0' && *s
<= '9')
3012 if (*s
== what
|| ((*s
| l
) == what
) || what
== 'd')
3023 WindowChanged(p
, what
)
3027 int inwstr
, inhstr
, inlstr
;
3028 int inwstrh
= 0, inhstrh
= 0, inlstrh
= 0;
3030 struct display
*olddisplay
= display
;
3033 inwstr
= inhstr
= 0;
3037 WindowChanged((struct win
*)0, 'w'|0x100);
3038 WindowChanged((struct win
*)0, 'W'|0x100);
3043 inwstr
= WindowChangedCheck(captionstring
, what
, &inwstrh
);
3044 inhstr
= WindowChangedCheck(hstatusstring
, what
, &inhstrh
);
3045 inlstr
= WindowChangedCheck(wliststr
, what
, &inlstrh
);
3049 inwstr
= inhstr
= 0;
3055 for (display
= displays
; display
; display
= display
->d_next
)
3059 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
3061 if (inlstr
|| (inlstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3062 WListUpdatecv(cv
, (struct win
*)0);
3063 p
= Layer2Window(cv
->c_layer
);
3064 if (inwstr
|| (inwstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3065 if (cv
->c_ye
+ 1 < D_height
)
3066 RefreshLine(cv
->c_ye
+ 1, 0, D_width
- 1, 0);
3069 if (inhstr
|| (inhstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3071 if (ox
!= -1 && ox
!= -1)
3074 display
= olddisplay
;
3078 if (p
->w_hstatus
&& *p
->w_hstatus
&& (inwstrh
|| inhstrh
|| inlstrh
) && WindowChangedCheck(p
->w_hstatus
, what
, (int *)0))
3084 if (!inwstr
&& !inhstr
&& !inlstr
)
3086 for (display
= displays
; display
; display
= display
->d_next
)
3091 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
3094 WListUpdatecv(cv
, p
);
3095 if (Layer2Window(cv
->c_layer
) != p
)
3098 if (inwstr
&& cv
->c_ye
+ 1 < D_height
)
3099 RefreshLine(cv
->c_ye
+ 1, 0, D_width
- 1, 0);
3101 if (got
&& inhstr
&& p
== D_fore
)
3103 if (ox
!= -1 && ox
!= -1)
3106 display
= olddisplay
;