1 /* Copyright (c) 2008, 2009
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Micah Cowan (micah@cowan.name)
5 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
6 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
7 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
8 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
9 * Copyright (c) 1987 Oliver Laumann
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, see
23 * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 ****************************************************************
29 #include <sys/types.h>
31 #ifndef sun /* we want to know about TIOCPKT. */
32 # include <sys/ioctl.h>
41 extern struct display
*display
, *displays
;
42 extern struct win
*fore
; /* for 83 escape */
43 extern struct layer
*flayer
; /* for 83 escape */
45 extern struct NewWindow nwin_default
; /* for ResetWindow() */
46 extern int nversion
; /* numerical version of screen */
47 extern int log_flush
, logtstamp_on
, logtstamp_after
;
48 extern char *logtstamp_string
;
49 extern char *captionstring
;
50 extern char *hstatusstring
;
51 extern char *wliststr
;
53 extern int compacthist
;
56 extern struct acluser
*EffectiveAclUser
;
59 int Z0width
, Z1width
; /* widths for Z0/Z1 switching */
61 /* globals set in WriteString */
62 static struct win
*curr
; /* window we are working on */
63 static int rows
, cols
; /* window size of the curr window */
66 int use_hardstatus
= 1; /* display status line in hs */
68 int use_altscreen
= 0; /* enable alternate screen support? */
70 unsigned char *blank
; /* line filled with spaces */
71 unsigned char *null
; /* line filled with '\0' */
73 struct mline mline_old
;
74 struct mline mline_blank
;
75 struct mline mline_null
;
77 struct mchar mchar_null
;
78 struct mchar mchar_blank
= {' ' /* , 0, 0, ... */};
79 struct mchar mchar_so
= {' ', A_SO
/* , 0, 0, ... */};
81 int renditions
[NUM_RENDS
] = {65529 /* =ub */, 65531 /* =b */};
83 /* keep string_t and string_t_string in sync! */
84 static char *string_t_string
[] =
87 "DCS", /* Device control string */
88 "OSC", /* Operating system command */
89 "APC", /* Application program command */
90 /* - used for status change */
91 "PM", /* Privacy message */
92 "AKA", /* title for current screen */
93 "GM", /* Global message to every display */
94 "STATUS" /* User hardstatus line */
97 /* keep state_t and state_t_string in sync! */
98 static char *state_t_string
[] =
100 "LIT", /* Literal input */
101 "ESC", /* Start of escape sequence */
102 "ASTR", /* Start of control string */
103 "STRESC", /* ESC seen in control string */
104 "CSI", /* Reading arguments in "CSI Pn ;...*/
105 "PRIN", /* Printer mode */
106 "PRINESC", /* ESC seen in printer mode */
107 "PRINCSI", /* CSI seen in printer mode */
108 "PRIN4" /* CSI 4 seen in printer mode */
111 static int Special
__P((int));
112 static void DoESC
__P((int, int));
113 static void DoCSI
__P((int, int));
114 static void StringStart
__P((enum string_t
));
115 static void StringChar
__P((int));
116 static int StringEnd
__P((void));
117 static void PrintStart
__P((void));
118 static void PrintChar
__P((int));
119 static void PrintFlush
__P((void));
121 static void DesignateCharset
__P((int, int));
122 static void MapCharset
__P((int));
123 static void MapCharsetR
__P((int));
125 static void SaveCursor
__P((void));
126 static void RestoreCursor
__P((void));
127 static void BackSpace
__P((void));
128 static void Return
__P((void));
129 static void LineFeed
__P((int));
130 static void ReverseLineFeed
__P((void));
131 static void InsertChar
__P((int));
132 static void DeleteChar
__P((int));
133 static void DeleteLine
__P((int));
134 static void InsertLine
__P((int));
135 static void Scroll
__P((char *, int, int, char *));
136 static void ForwardTab
__P((void));
137 static void BackwardTab
__P((void));
138 static void ClearScreen
__P((void));
139 static void ClearFromBOS
__P((void));
140 static void ClearToEOS
__P((void));
141 static void ClearLineRegion
__P((int, int));
142 static void CursorRight
__P((int));
143 static void CursorUp
__P((int));
144 static void CursorDown
__P((int));
145 static void CursorLeft
__P((int));
146 static void ASetMode
__P((int));
147 static void SelectRendition
__P((void));
148 static void RestorePosRendition
__P((void));
149 static void FillWithEs
__P((void));
150 static void FindAKA
__P((void));
151 static void Report
__P((char *, int, int));
152 static void ScrollRegion
__P((int));
154 static void WAddLineToHist
__P((struct win
*, struct mline
*));
156 static void WLogString
__P((struct win
*, char *, int));
157 static void WReverseVideo
__P((struct win
*, int));
158 static int WindowChangedCheck
__P((char *, int, int *));
159 static void MFixLine
__P((struct win
*, int, struct mchar
*));
160 static void MScrollH
__P((struct win
*, int, int, int, int, int));
161 static void MScrollV
__P((struct win
*, int, int, int, int));
162 static void MClearArea
__P((struct win
*, int, int, int, int, int));
163 static void MInsChar
__P((struct win
*, struct mchar
*, int, int));
164 static void MPutChar
__P((struct win
*, struct mchar
*, int, int));
165 static void MPutStr
__P((struct win
*, char *, int, struct mchar
*, int, int));
166 static void MWrapChar
__P((struct win
*, struct mchar
*, int, int, int, int));
168 static void MBceLine
__P((struct win
*, int, int, int, int));
172 # define CURR_BCE (curr->w_bce ? rend_getbg(&curr->w_rend) : 0)
182 p
->w_StringType
= NONE
;
187 register struct win
*p
;
191 p
->w_wrap
= nwin_default
.wrap
;
202 p
->w_bot
= p
->w_height
- 1;
206 p
->w_StringType
= NONE
;
207 bzero(p
->w_tabs
, p
->w_width
);
208 for (i
= 8; i
< p
->w_width
; i
+= 8)
210 p
->w_rend
= mchar_null
;
215 p
->w_bce
= nwin_default
.bce
;
219 /* adds max 22 bytes */
221 GetAnsiStatus(w
, buf
)
227 if (w
->w_state
== LIT
)
230 strcpy(p
, state_t_string
[w
->w_state
]);
232 if (w
->w_intermediate
)
235 if (w
->w_intermediate
> 0xff)
236 p
+= AddXChar(p
, w
->w_intermediate
>> 8);
237 p
+= AddXChar(p
, w
->w_intermediate
& 0xff);
240 if (w
->w_state
== ASTR
|| w
->w_state
== STRESC
)
241 sprintf(p
, "-%s", string_t_string
[w
->w_StringType
]);
253 p
->w_gr
= nwin_default
.gr
;
254 p
->w_c1
= nwin_default
.c1
;
255 SetCharsets(p
, "BBBB02");
256 if (nwin_default
.charset
)
257 SetCharsets(p
, nwin_default
.charset
);
270 for (i
= 0; i
< 4 && *s
; i
++, s
++)
272 p
->w_charsets
[i
] = ((*s
== 'B') ? ASCII
: *s
);
273 if (*s
&& *s
++ != '.')
274 p
->w_Charset
= s
[-1] - '0';
276 p
->w_CharsetR
= *s
- '0';
278 p
->w_FontL
= p
->w_charsets
[p
->w_Charset
];
279 p
->w_FontR
= p
->w_charsets
[p
->w_CharsetR
];
283 /*****************************************************************/
287 * Here comes the vt100 emulator
289 * - sets timestamp and flags activity in window.
290 * - record program output in window scrollback
291 * - translate program output for the display and put it into the obuf.
295 WriteString(wp
, buf
, len
)
309 WLogString(wp
, buf
, len
);
311 /*May it cause buffer overrun?*/
314 trigger_sevent(&wp
->w_sev
.onoutput
, wp
, buf
);
317 /* set global variables (yuck!) */
319 cols
= curr
->w_width
;
320 rows
= curr
->w_height
;
323 SetTimeout(&curr
->w_silenceev
, curr
->w_silencewait
* 1000);
325 if (curr
->w_monitor
== MON_ON
)
327 debug2("ACTIVITY %d %d\n", curr
->w_monitor
, curr
->w_bell
);
328 curr
->w_monitor
= MON_FOUND
;
335 c
= (unsigned char)*buf
++;
340 curr
->w_rend
.font
= curr
->w_FontL
; /* Default: GL */
343 /* The next part is only for speedup */
344 if (curr
->w_state
== LIT
&&
346 curr
->w_encoding
!= UTF8
&&
349 !is_dw_font(curr
->w_rend
.font
) &&
351 curr
->w_rend
.font
!= KANA
&& !curr
->w_mbcs
&&
355 curr
->w_rend
.font
!= '<' &&
357 c
>= ' ' && c
!= 0x7f &&
358 ((c
& 0x80) == 0 || ((c
>= 0xa0 || !curr
->w_c1
) && !curr
->w_gr
)) && !curr
->w_ss
&&
359 !curr
->w_insert
&& curr
->w_x
< cols
- 1)
361 register int currx
= curr
->w_x
;
364 while (currx
< cols
- 1)
369 c
= (unsigned char)*buf
++;
370 if (c
< ' ' || c
== 0x7f || ((c
& 0x80) && ((c
< 0xa0 && curr
->w_c1
) || curr
->w_gr
)))
376 MPutStr(curr
, imp
, currx
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
377 LPutStr(&curr
->w_layer
, imp
, currx
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
383 /* end of speedup code */
386 if (curr
->w_encoding
== UTF8
)
388 c
= FromUtf8(c
, &curr
->w_decodestate
);
399 debug1("read UNICODE %04x\n", c
);
404 switch (curr
->w_state
)
410 curr
->w_state
= PRINESC
;
420 curr
->w_state
= PRINCSI
;
425 curr
->w_state
= PRIN
;
432 curr
->w_state
= PRIN4
;
438 curr
->w_state
= PRIN
;
447 if (curr
->w_pdisplay
&& curr
->w_pdisplay
->d_printfd
>= 0)
449 close(curr
->w_pdisplay
->d_printfd
);
450 curr
->w_pdisplay
->d_printfd
= -1;
452 curr
->w_pdisplay
= 0;
459 curr
->w_state
= PRIN
;
467 curr
->w_state
= STRESC
;
470 /* special xterm hack: accept SetStatus sequence. Yucc! */
471 /* allow ^E for title escapes */
472 if (!(curr
->w_StringType
== OSC
&& c
< ' ' && c
!= '\005'))
473 if (!curr
->w_c1
|| c
!= ('\\' ^ 0xc0))
484 if (StringEnd() == 0 || len
<= 1)
486 /* check if somewhere a status is displayed */
487 for (cv
= curr
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
489 display
= cv
->c_display
;
490 if (D_status
== STATUS_ON_WIN
)
495 if (len
> IOSIZE
+ 1)
497 curr
->w_outlen
= len
- 1;
498 bcopy(buf
, curr
->w_outbuf
, len
- 1);
499 return; /* wait till status is gone */
506 curr
->w_state
= ASTR
;
517 curr
->w_intermediate
= 0;
518 bzero((char *) curr
->w_args
, MAXARGS
* sizeof(int));
546 debug1("not special. c = %x\n", c
);
547 if (c
>= ' ' && c
<= '/')
549 if (curr
->w_intermediate
)
552 if (curr
->w_intermediate
== '$')
558 curr
->w_intermediate
= c
;
560 else if (c
>= '0' && c
<= '~')
562 DoESC(c
, curr
->w_intermediate
);
575 case '0': case '1': case '2': case '3': case '4':
576 case '5': case '6': case '7': case '8': case '9':
577 if (curr
->w_NumArgs
< MAXARGS
)
579 if (curr
->w_args
[curr
->w_NumArgs
] < 100000000)
580 curr
->w_args
[curr
->w_NumArgs
] =
581 10 * curr
->w_args
[curr
->w_NumArgs
] + (c
- '0');
586 if (curr
->w_NumArgs
< MAXARGS
)
592 if (c
>= '@' && c
<= '~')
594 if (curr
->w_NumArgs
< MAXARGS
)
596 DoCSI(c
, curr
->w_intermediate
);
597 if (curr
->w_state
!= PRIN
)
600 else if ((c
>= ' ' && c
<= '/') || (c
>= '<' && c
<= '?'))
601 curr
->w_intermediate
= curr
->w_intermediate
? -1 : c
;
613 if (c
<= ' ' || c
== 0x7f || (c
>= 0x80 && c
< 0xa0 && curr
->w_c1
))
620 curr
->w_intermediate
= 0;
622 if (curr
->w_autoaka
< 0)
629 if (c
>= 0x80 && c
< 0xa0 && curr
->w_c1
)
631 if ((curr
->w_FontR
& 0xf0) != 0x20
633 || curr
->w_encoding
== UTF8
644 case 0xc0 ^ 'N': /* SS2 */
645 case 0xc0 ^ 'O': /* SS3 */
649 if (curr
->w_autoaka
< 0)
652 curr
->w_intermediate
= 0;
653 bzero((char *) curr
->w_args
, MAXARGS
* sizeof(int));
670 if (c
< 0x80 || curr
->w_gr
== 0)
671 curr
->w_rend
.font
= curr
->w_FontL
;
673 else if (curr
->w_gr
== 2 && !curr
->w_ss
)
674 curr
->w_rend
.font
= curr
->w_FontE
;
677 curr
->w_rend
.font
= curr
->w_FontR
;
682 if (curr
->w_encoding
== UTF8
)
684 if (curr
->w_rend
.font
== '0')
686 struct mchar mc
, *mcp
;
688 debug1("SPECIAL %x\n", c
);
692 mcp
= recode_mchar(&mc
, 0, UTF8
);
693 debug2("%02x %02x\n", mcp
->image
, mcp
->font
);
694 c
= mcp
->image
| mcp
->font
<< 8;
696 curr
->w_rend
.font
= 0;
699 if (curr
->w_encoding
== UTF8
&& utf8_isdouble(c
))
702 if (curr
->w_encoding
== UTF8
&& c
>= 0x0300 && utf8_iscomb(c
))
711 ox
= curr
->w_width
- 1;
716 copy_mline2mchar(&omc
, &curr
->w_mlines
[oy
], ox
);
717 if (omc
.image
== 0xff && omc
.font
== 0xff)
722 copy_mline2mchar(&omc
, &curr
->w_mlines
[oy
], ox
);
728 utf8_handle_comb(c
, &omc
);
729 MFixLine(curr
, oy
, &omc
);
730 copy_mchar2mline(&omc
, &curr
->w_mlines
[oy
], ox
);
731 LPutChar(&curr
->w_layer
, &omc
, ox
, oy
);
732 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
736 font
= curr
->w_rend
.font
;
740 if (font
== KANA
&& curr
->w_encoding
== SJIS
&& curr
->w_mbcs
== 0)
742 /* Lets see if it is the first byte of a kanji */
743 debug1("%x may be first of SJIS\n", c
);
744 if ((0x81 <= c
&& c
<= 0x9f) || (0xe0 <= c
&& c
<= 0xef))
752 if (font
== 031 && c
== 0x80 && !curr
->w_mbcs
)
753 font
= curr
->w_rend
.font
= 0;
754 if (is_dw_font(font
) && c
== ' ')
755 font
= curr
->w_rend
.font
= 0;
756 if (is_dw_font(font
) || curr
->w_mbcs
)
759 if (curr
->w_mbcs
== 0)
764 if (curr
->w_x
== cols
- 1)
766 curr
->w_x
+= curr
->w_wrap
? 1 : -1;
767 debug1("Patched w_x to %d\n", curr
->w_x
);
770 if (curr
->w_encoding
!= UTF8
)
775 if (font
== KANA
&& curr
->w_encoding
== SJIS
)
777 debug2("SJIS !! %x %x\n", c
, t
);
779 * SJIS -> EUC mapping:
781 * 81,82...9f -> 21,23...5d
782 * e0,e1...ef -> 5f,61...7d
786 * 9f-fc -> 21-7e (increment first byte!)
788 if (0x40 <= t
&& t
<= 0xfc && t
!= 0x7f)
790 if (c
<= 0x9f) c
= (c
- 0x81) * 2 + 0x21;
791 else c
= (c
- 0xc1) * 2 + 0x21;
792 if (t
<= 0x7e) t
-= 0x1f;
793 else if (t
<= 0x9e) t
-= 0x20;
795 curr
->w_rend
.font
= KANJI
;
799 /* Incomplete shift-jis - skip first byte */
803 debug2("SJIS after %x %x\n", c
, t
);
806 if (t
&& curr
->w_gr
&& font
!= 030 && font
!= 031)
817 # endif /* DW_CHARS */
818 if (font
== '<' && c
>= ' ')
820 font
= curr
->w_rend
.font
= 0;
824 else if (curr
->w_gr
&& curr
->w_encoding
!= UTF8
)
830 if (c
== 0x80 && font
== 0 && curr
->w_encoding
== GBK
)
834 if (c
< ' ' && font
!= 031)
838 if (c
< ' ') /* this is ugly but kanji support */
839 goto tryagain
; /* prevents nicer programming */
845 curr
->w_rend
.image
= c
;
847 if (curr
->w_encoding
== UTF8
)
848 curr
->w_rend
.font
= c
>> 8;
851 curr
->w_rend
.mbcs
= curr
->w_mbcs
;
853 if (curr
->w_x
< cols
- 1)
857 save_mline(&curr
->w_mlines
[curr
->w_y
], cols
);
858 MInsChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
859 LInsChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
, &mline_old
);
864 MPutChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
865 LPutChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
869 else if (curr
->w_x
== cols
- 1)
871 MPutChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
872 LPutChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
878 MWrapChar(curr
, &curr
->w_rend
, curr
->w_y
, curr
->w_top
, curr
->w_bot
, curr
->w_insert
);
879 LWrapChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_y
, curr
->w_top
, curr
->w_bot
, curr
->w_insert
);
880 if (curr
->w_y
!= curr
->w_bot
&& curr
->w_y
!= curr
->w_height
- 1)
888 curr
->w_rend
.mbcs
= curr
->w_mbcs
= 0;
894 curr
->w_FontL
= curr
->w_charsets
[curr
->w_Charset
];
895 curr
->w_FontR
= curr
->w_charsets
[curr
->w_CharsetR
];
896 curr
->w_rend
.font
= curr
->w_FontL
;
897 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
906 if (!printcmd
&& curr
->w_state
== PRIN
)
911 WLogString(p
, buf
, len
)
918 if (logtstamp_on
&& p
->w_logsilence
>= logtstamp_after
* 2)
920 char *t
= MakeWinMsg(logtstamp_string
, p
, '%');
921 logfwrite(p
->w_log
, t
, strlen(t
)); /* long time no write */
924 if (logfwrite(p
->w_log
, buf
, len
) < 1)
926 WMsg(p
, errno
, "Error writing logfile");
952 WBell(curr
, visual_bell
);
958 case '\017': /* SI */
961 case '\016': /* SO */
970 DoESC(c
, intermediate
)
973 debug2("DoESC: %x - inter = %x\n", c
, intermediate
);
974 switch (intermediate
)
989 curr
->w_tabs
[curr
->w_x
] = 1;
991 case 'Z': /* jph: Identify as VT100 */
992 Report("\033[?%d;%dc", 1, 2);
1003 LKeypadMode(&curr
->w_layer
, 0);
1004 LCursorkeysMode(&curr
->w_layer
, 0);
1006 WNewAutoFlow(curr
, 1);
1009 SetRendition(&mchar_null);
1011 ChangeScrollRegion(0, rows - 1);
1013 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1016 LKeypadMode(&curr
->w_layer
, curr
->w_keypad
= 1);
1018 WNewAutoFlow(curr
, 0);
1019 #endif /* !TIOCPKT */
1022 LKeypadMode(&curr
->w_layer
, curr
->w_keypad
= 0);
1024 WNewAutoFlow(curr
, 1);
1025 #endif /* !TIOCPKT */
1035 MapCharsetR(G1
); /* LS1R */
1039 MapCharsetR(G2
); /* LS2R */
1042 MapCharsetR(G3
); /* LS3R */
1045 if (curr
->w_charsets
[curr
->w_Charset
] != curr
->w_charsets
[G2
]
1046 || curr
->w_charsets
[curr
->w_CharsetR
] != curr
->w_charsets
[G2
])
1047 curr
->w_FontR
= curr
->w_FontL
= curr
->w_charsets
[curr
->w_ss
= G2
];
1052 if (curr
->w_charsets
[curr
->w_Charset
] != curr
->w_charsets
[G3
]
1053 || curr
->w_charsets
[curr
->w_CharsetR
] != curr
->w_charsets
[G3
])
1054 curr
->w_FontR
= curr
->w_FontL
= curr
->w_charsets
[curr
->w_ss
= G3
];
1059 case 'g': /* VBELL, private screen sequence */
1074 DesignateCharset(c
, G0
);
1077 DesignateCharset(c
, G1
);
1080 DesignateCharset(c
, G2
);
1083 DesignateCharset(c
, G3
);
1087 * ESC $ ( Fn: invoke multi-byte charset, Fn, to G0
1088 * ESC $ Fn: same as above. (old sequence)
1089 * ESC $ ) Fn: invoke multi-byte charset, Fn, to G1
1090 * ESC $ * Fn: invoke multi-byte charset, Fn, to G2
1091 * ESC $ + Fn: invoke multi-byte charset, Fn, to G3
1095 DesignateCharset(c
& 037, G0
);
1098 DesignateCharset(c
& 037, G1
);
1101 DesignateCharset(c
& 037, G2
);
1104 DesignateCharset(c
& 037, G3
);
1112 DoCSI(c
, intermediate
)
1113 int c
, intermediate
;
1115 register int i
, a1
= curr
->w_args
[0], a2
= curr
->w_args
[1];
1117 if (curr
->w_NumArgs
> MAXARGS
)
1118 curr
->w_NumArgs
= MAXARGS
;
1119 switch (intermediate
)
1136 LGotoPos(&curr
->w_layer
, --a2
, --a1
);
1139 if (curr
->w_autoaka
)
1140 curr
->w_autoaka
= a1
+ 1;
1143 if (a1
< 0 || a1
> 2)
1155 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1160 if (a1
< 0 || a1
> 2)
1165 ClearLineRegion(curr
->w_x
, cols
- 1);
1168 ClearLineRegion(0, curr
->w_x
);
1171 ClearLineRegion(0, cols
- 1);
1176 a1
= curr
->w_x
+ (a1
? a1
- 1 : 0);
1177 ClearLineRegion(curr
->w_x
, a1
< cols
? a1
: cols
- 1);
1180 CursorUp(a1
? a1
: 1);
1183 CursorDown(a1
? a1
: 1);
1186 CursorRight(a1
? a1
: 1);
1189 CursorLeft(a1
? a1
: 1);
1193 CursorDown(a1
? a1
: 1); /* positions cursor */
1197 CursorUp(a1
? a1
: 1); /* positions cursor */
1201 curr
->w_x
= a1
? a1
- 1 : 0;
1202 if (curr
->w_x
>= cols
)
1203 curr
->w_x
= cols
- 1;
1204 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1207 curr
->w_y
= a1
? a1
- 1 : 0;
1208 if (curr
->w_y
>= rows
)
1209 curr
->w_y
= rows
- 1;
1210 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1217 curr
->w_tabs
[curr
->w_x
] = 0;
1219 bzero(curr
->w_tabs
, cols
);
1226 if (a1
< 1 || a2
> rows
|| a1
>= a2
)
1228 curr
->w_top
= a1
- 1;
1229 curr
->w_bot
= a2
- 1;
1230 /* ChangeScrollRegion(curr->w_top, curr->w_bot); */
1233 curr
->w_y
= curr
->w_top
;
1237 curr
->w_y
= curr
->w_x
= 0;
1238 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1247 if (curr
->w_layer
.l_cvlist
)
1248 Report("\033[1t", 0, 0);
1250 Report("\033[2t", 0, 0);
1253 LRefreshAll(&curr
->w_layer
, 0);
1256 a1
= strlen(curr
->w_title
);
1257 if ((unsigned)(curr
->w_inlen
+ 5 + a1
) <= sizeof(curr
->w_inbuf
))
1259 bcopy("\033]l", curr
->w_inbuf
+ curr
->w_inlen
, 3);
1260 bcopy(curr
->w_title
, curr
->w_inbuf
+ curr
->w_inlen
+ 3, a1
);
1261 bcopy("\033\\", curr
->w_inbuf
+ curr
->w_inlen
+ 3 + a1
, 2);
1262 curr
->w_inlen
+= 5 + a1
;
1266 a1
= curr
->w_args
[2];
1270 a2
= curr
->w_height
;
1271 if (a1
> 10000 || a2
> 10000)
1273 WChangeSize(curr
, a1
, a2
);
1274 cols
= curr
->w_width
;
1275 rows
= curr
->w_height
;
1297 InsertLine(a1
? a1
: 1);
1300 DeleteLine(a1
? a1
: 1);
1303 DeleteChar(a1
? a1
: 1);
1306 InsertChar(a1
? a1
: 1);
1314 case 'i': /* MC Media Control */
1319 if (a1
== 5) /* Report terminal status */
1320 Report("\033[0n", 0, 0);
1321 else if (a1
== 6) /* Report cursor position */
1322 Report("\033[%d;%dR", curr
->w_y
+ 1, curr
->w_x
+ 1);
1324 case 'c': /* Identify as VT100 */
1326 Report("\033[?%d;%dc", 1, 2);
1328 case 'x': /* decreqtparm */
1329 if (a1
== 0 || a1
== 1)
1330 Report("\033[%d;1;1;112;112;1;0x", a1
+ 2, 0);
1332 case 'p': /* obscure code from a 97801 term */
1333 if (a1
== 6 || a1
== 7)
1335 curr
->w_curinv
= 7 - a1
;
1336 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
1339 case 'S': /* code from a 97801 term / DEC vt400 */
1340 ScrollRegion(a1
? a1
: 1);
1342 case 'T': /* code from a 97801 term / DEC vt400 */
1343 case '^': /* SD as per ISO 6429 */
1344 ScrollRegion(a1
? -a1
: -1);
1349 for (a2
= 0; a2
< curr
->w_NumArgs
; a2
++)
1351 a1
= curr
->w_args
[a2
];
1352 debug2("\\E[?%d%c\n",a1
,c
);
1353 if (c
!= 'h' && c
!= 'l')
1358 case 1: /* CKM: cursor key mode */
1359 LCursorkeysMode(&curr
->w_layer
, curr
->w_cursorkeys
= i
);
1361 WNewAutoFlow(curr
, !i
);
1362 #endif /* !TIOCPKT */
1364 case 2: /* ANM: ansi/vt52 mode */
1369 if (curr
->w_encoding
)
1372 curr
->w_charsets
[0] = curr
->w_charsets
[1] =
1373 curr
->w_charsets
[2] = curr
->w_charsets
[2] =
1374 curr
->w_FontL
= curr
->w_FontR
= ASCII
;
1375 curr
->w_Charset
= 0;
1376 curr
->w_CharsetR
= 2;
1381 case 3: /* COLM: column mode */
1382 i
= (i
? Z0width
: Z1width
);
1383 WChangeSize(curr
, i
, curr
->w_height
);
1384 cols
= curr
->w_width
;
1385 rows
= curr
->w_height
;
1387 /* case 4: SCLM: scrolling mode */
1388 case 5: /* SCNM: screen mode */
1389 if (i
!= curr
->w_revvid
)
1390 WReverseVideo(curr
, i
);
1393 case 6: /* OM: origin mode */
1394 if ((curr
->w_origin
= i
) != 0)
1396 curr
->w_y
= curr
->w_top
;
1400 curr
->w_y
= curr
->w_x
= 0;
1401 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1403 case 7: /* AWM: auto wrap mode */
1406 /* case 8: ARM: auto repeat mode */
1407 /* case 9: INLM: interlace mode */
1408 case 9: /* X10 mouse tracking */
1409 curr
->w_mouse
= i
? 9 : 0;
1410 LMouseMode(&curr
->w_layer
, curr
->w_mouse
);
1412 /* case 10: EDM: edit mode */
1413 /* case 11: LTM: line transmit mode */
1414 /* case 13: SCFDM: space compression / field delimiting */
1415 /* case 14: TEM: transmit execution mode */
1416 /* case 16: EKEM: edit key execution mode */
1417 /* case 18: PFF: Printer term form feed */
1418 /* case 19: PEX: Printer extend screen / scroll. reg */
1419 case 25: /* TCEM: text cursor enable mode */
1420 curr
->w_curinv
= !i
;
1421 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
1423 /* case 34: RLM: Right to left mode */
1424 /* case 35: HEBM: hebrew keyboard map */
1425 /* case 36: HEM: hebrew encoding */
1426 /* case 38: TeK Mode */
1427 /* case 40: 132 col enable */
1428 /* case 42: NRCM: 7bit NRC character mode */
1429 /* case 44: margin bell enable */
1430 case 47: /* xterm-like alternate screen */
1431 case 1047: /* xterm-like alternate screen */
1432 case 1049: /* xterm-like alternate screen */
1436 EnterAltScreen(curr
);
1438 LeaveAltScreen(curr
);
1441 LRefreshAll(&curr
->w_layer
, 0);
1442 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1445 /* case 66: NKM: Numeric keypad appl mode */
1446 /* case 68: KBUM: Keyboard usage mode (data process) */
1447 case 1000: /* VT200 mouse tracking */
1448 case 1001: /* VT200 highlight mouse */
1449 case 1002: /* button event mouse*/
1450 case 1003: /* any event mouse*/
1451 curr
->w_mouse
= i
? a1
: 0;
1452 LMouseMode(&curr
->w_layer
, curr
->w_mouse
);
1460 case 'c': /* secondary DA */
1462 Report("\033[>%d;%d;0c", 83, nversion
); /* 83 == 'S' */
1474 curr
->w_StringType
= type
;
1475 curr
->w_stringp
= curr
->w_string
;
1476 curr
->w_state
= ASTR
;
1483 if (curr
->w_stringp
>= curr
->w_string
+ MAXSTR
- 1)
1484 curr
->w_state
= LIT
;
1486 *(curr
->w_stringp
)++ = c
;
1490 * Do string processing. Returns -1 if output should be suspended
1491 * until status is gone.
1500 curr
->w_state
= LIT
;
1501 *curr
->w_stringp
= '\0';
1502 switch (curr
->w_StringType
)
1504 case OSC
: /* special xterm compatibility hack */
1505 if (curr
->w_string
[0] == ';' || (p
= index(curr
->w_string
, ';')) == 0)
1507 typ
= atoi(curr
->w_string
);
1510 if (typ
== 83) /* 83 = 'S' */
1512 /* special execute commands sequence */
1513 char *args
[MAXARGS
];
1515 struct acluser
*windowuser
;
1517 windowuser
= *FindUserPtr(":window:");
1518 if (windowuser
&& Parse(p
, sizeof(curr
->w_string
) - (p
- curr
->w_string
), args
, argl
))
1520 for (display
= displays
; display
; display
= display
->d_next
)
1521 if (D_forecv
->c_layer
->l_bottom
== &curr
->w_layer
)
1522 break; /* found it */
1523 if (display
== 0 && curr
->w_layer
.l_cvlist
)
1524 display
= curr
->w_layer
.l_cvlist
->c_display
;
1527 EffectiveAclUser
= windowuser
;
1529 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1530 DoCommand(args
, argl
);
1531 EffectiveAclUser
= 0;
1539 if (typ
== 0 || typ
== 1 || typ
== 20 || typ
== 39 || typ
== 49)
1545 if (strcmp(curr
->w_xtermosc
[typ2
], p
))
1547 strncpy(curr
->w_xtermosc
[typ2
], p
, sizeof(curr
->w_xtermosc
[typ2
]) - 1);
1548 curr
->w_xtermosc
[typ2
][sizeof(curr
->w_xtermosc
[typ2
]) - 1] = 0;
1550 for (display
= displays
; display
; display
= display
->d_next
)
1554 if (D_forecv
->c_layer
->l_bottom
== &curr
->w_layer
)
1555 SetXtermOSC(typ2
, curr
->w_xtermosc
[typ2
]);
1556 if ((typ2
== 2 || typ2
== 3) && D_xtermosc
[typ2
])
1561 if (typ
!= 0 && typ
!= 2)
1564 if (typ
< 0 || typ
> 2)
1568 curr
->w_stringp
-= p
- curr
->w_string
;
1569 if (curr
->w_stringp
> curr
->w_string
)
1570 bcopy(p
, curr
->w_string
, curr
->w_stringp
- curr
->w_string
);
1571 *curr
->w_stringp
= '\0';
1574 if (curr
->w_hstatus
)
1576 if (strcmp(curr
->w_hstatus
, curr
->w_string
) == 0)
1577 break; /* not changed */
1578 free(curr
->w_hstatus
);
1579 curr
->w_hstatus
= 0;
1581 if (curr
->w_string
!= curr
->w_stringp
)
1582 curr
->w_hstatus
= SaveStr(curr
->w_string
);
1583 WindowChanged(curr
, 'h');
1587 for (display
= displays
; display
; display
= display
->d_next
)
1589 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
1590 if (cv
->c_layer
->l_bottom
== &curr
->w_layer
)
1592 if (cv
|| curr
->w_StringType
== GM
)
1593 MakeStatus(curr
->w_string
);
1597 LAY_DISPLAYS(&curr
->w_layer
, AddStr(curr
->w_string
));
1600 if (curr
->w_title
== curr
->w_akabuf
&& !*curr
->w_string
)
1602 ChangeAKA(curr
, curr
->w_string
, strlen(curr
->w_string
));
1603 if (!*curr
->w_string
)
1604 curr
->w_autoaka
= curr
->w_y
+ 1;
1615 curr
->w_pdisplay
= 0;
1617 /* find us a nice display to print on, fore prefered */
1618 display
= curr
->w_lastdisp
;
1619 if (!(display
&& curr
== D_fore
&& (printcmd
|| D_PO
)))
1620 for (display
= displays
; display
; display
= display
->d_next
)
1621 if (curr
== D_fore
&& (printcmd
|| D_PO
))
1626 for (cv
= curr
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
1628 display
= cv
->c_display
;
1629 if (printcmd
|| D_PO
)
1635 if (!display
|| display
->d_next
|| !(printcmd
|| D_PO
))
1639 curr
->w_pdisplay
= display
;
1640 curr
->w_stringp
= curr
->w_string
;
1641 curr
->w_state
= PRIN
;
1642 if (printcmd
&& curr
->w_pdisplay
->d_printfd
< 0)
1643 curr
->w_pdisplay
->d_printfd
= printpipe(curr
, printcmd
);
1650 if (curr
->w_stringp
>= curr
->w_string
+ MAXSTR
- 1)
1652 *(curr
->w_stringp
)++ = c
;
1658 display
= curr
->w_pdisplay
;
1659 if (display
&& printcmd
)
1661 char *bp
= curr
->w_string
;
1662 int len
= curr
->w_stringp
- curr
->w_string
;
1664 while (len
&& display
->d_printfd
>= 0)
1666 r
= write(display
->d_printfd
, bp
, len
);
1669 WMsg(curr
, errno
, "printing aborted");
1670 close(display
->d_printfd
);
1671 display
->d_printfd
= -1;
1678 else if (display
&& curr
->w_stringp
> curr
->w_string
)
1681 AddStrn(curr
->w_string
, curr
->w_stringp
- curr
->w_string
);
1685 curr
->w_stringp
= curr
->w_string
;
1690 WNewAutoFlow(win
, on
)
1694 debug1("WNewAutoFlow: %d\n", on
);
1695 if (win
->w_flow
& FLOW_AUTOFLAG
)
1696 win
->w_flow
= FLOW_AUTOFLAG
| (FLOW_AUTO
|FLOW_NOW
) * on
;
1698 win
->w_flow
= (win
->w_flow
& ~FLOW_AUTO
) | FLOW_AUTO
* on
;
1699 LSetFlow(&win
->w_layer
, win
->w_flow
& FLOW_NOW
);
1706 DesignateCharset(c
, n
)
1711 if (c
== ('@' & 037)) /* map JIS 6226 to 0208 */
1716 if (curr
->w_charsets
[n
] != c
)
1718 curr
->w_charsets
[n
] = c
;
1719 if (curr
->w_Charset
== n
)
1722 curr
->w_rend
.font
= curr
->w_FontL
;
1723 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1725 if (curr
->w_CharsetR
== n
)
1735 if (curr
->w_Charset
!= n
)
1737 curr
->w_Charset
= n
;
1738 curr
->w_FontL
= curr
->w_charsets
[n
];
1739 curr
->w_rend
.font
= curr
->w_FontL
;
1740 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1749 if (curr
->w_CharsetR
!= n
)
1751 curr
->w_CharsetR
= n
;
1752 curr
->w_FontR
= curr
->w_charsets
[n
];
1763 curr
->w_Saved_x
= curr
->w_x
;
1764 curr
->w_Saved_y
= curr
->w_y
;
1765 curr
->w_SavedRend
= curr
->w_rend
;
1767 curr
->w_SavedCharset
= curr
->w_Charset
;
1768 curr
->w_SavedCharsetR
= curr
->w_CharsetR
;
1769 bcopy((char *) curr
->w_charsets
, (char *) curr
->w_SavedCharsets
,
1779 LGotoPos(&curr
->w_layer
, curr
->w_Saved_x
, curr
->w_Saved_y
);
1780 curr
->w_x
= curr
->w_Saved_x
;
1781 curr
->w_y
= curr
->w_Saved_y
;
1782 curr
->w_rend
= curr
->w_SavedRend
;
1784 bcopy((char *) curr
->w_SavedCharsets
, (char *) curr
->w_charsets
,
1786 curr
->w_Charset
= curr
->w_SavedCharset
;
1787 curr
->w_CharsetR
= curr
->w_SavedCharsetR
;
1789 curr
->w_FontL
= curr
->w_charsets
[curr
->w_Charset
];
1790 curr
->w_FontR
= curr
->w_charsets
[curr
->w_CharsetR
];
1792 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1802 else if (curr
->w_wrap
&& curr
->w_y
> 0)
1804 curr
->w_x
= cols
- 1;
1807 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1816 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1823 /* out_mode: 0=lf, 1=cr+lf */
1826 if (curr
->w_y
!= curr
->w_bot
) /* Don't scroll */
1828 if (curr
->w_y
< rows
-1)
1830 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1833 if (curr
->w_autoaka
> 1)
1835 MScrollV(curr
, 1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1836 LScrollV(&curr
->w_layer
, 1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1837 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1843 if (curr
->w_y
== curr
->w_top
)
1845 MScrollV(curr
, -1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1846 LScrollV(&curr
->w_layer
, -1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1847 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1849 else if (curr
->w_y
> 0)
1857 register int y
= curr
->w_y
, x
= curr
->w_x
;
1863 save_mline(&curr
->w_mlines
[y
], cols
);
1864 MScrollH(curr
, -n
, y
, x
, curr
->w_width
- 1, CURR_BCE
);
1865 LScrollH(&curr
->w_layer
, -n
, y
, x
, curr
->w_width
- 1, CURR_BCE
, &mline_old
);
1866 LGotoPos(&curr
->w_layer
, x
, y
);
1873 register int y
= curr
->w_y
, x
= curr
->w_x
;
1877 save_mline(&curr
->w_mlines
[y
], cols
);
1878 MScrollH(curr
, n
, y
, x
, curr
->w_width
- 1, CURR_BCE
);
1879 LScrollH(&curr
->w_layer
, n
, y
, x
, curr
->w_width
- 1, CURR_BCE
, &mline_old
);
1880 LGotoPos(&curr
->w_layer
, x
, y
);
1887 if (curr
->w_y
< curr
->w_top
|| curr
->w_y
> curr
->w_bot
)
1889 if (n
> curr
->w_bot
- curr
->w_y
+ 1)
1890 n
= curr
->w_bot
- curr
->w_y
+ 1;
1891 MScrollV(curr
, n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1892 LScrollV(&curr
->w_layer
, n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1893 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1900 if (curr
->w_y
< curr
->w_top
|| curr
->w_y
> curr
->w_bot
)
1902 if (n
> curr
->w_bot
- curr
->w_y
+ 1)
1903 n
= curr
->w_bot
- curr
->w_y
+ 1;
1904 MScrollV(curr
, -n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1905 LScrollV(&curr
->w_layer
, -n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1906 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1913 MScrollV(curr
, n
, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1914 LScrollV(&curr
->w_layer
, n
, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1915 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1922 register int x
= curr
->w_x
;
1929 if (curr
->w_tabs
[x
] && x
< cols
- 1)
1931 while (x
< cols
- 1 && !curr
->w_tabs
[x
])
1934 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1940 register int x
= curr
->w_x
;
1942 if (curr
->w_tabs
[x
] && x
> 0)
1944 while (x
> 0 && !curr
->w_tabs
[x
])
1947 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1953 LClearArea(&curr
->w_layer
, 0, 0, curr
->w_width
- 1, curr
->w_height
- 1, CURR_BCE
, 1);
1955 MScrollV(curr
, curr
->w_height
, 0, curr
->w_height
- 1, CURR_BCE
);
1957 MClearArea(curr
, 0, 0, curr
->w_width
- 1, curr
->w_height
- 1, CURR_BCE
);
1964 register int y
= curr
->w_y
, x
= curr
->w_x
;
1966 LClearArea(&curr
->w_layer
, 0, 0, x
, y
, CURR_BCE
, 1);
1967 MClearArea(curr
, 0, 0, x
, y
, CURR_BCE
);
1968 RestorePosRendition();
1974 register int y
= curr
->w_y
, x
= curr
->w_x
;
1976 if (x
== 0 && y
== 0)
1979 RestorePosRendition();
1982 LClearArea(&curr
->w_layer
, x
, y
, cols
- 1, rows
- 1, CURR_BCE
, 1);
1983 MClearArea(curr
, x
, y
, cols
- 1, rows
- 1, CURR_BCE
);
1984 RestorePosRendition();
1988 ClearLineRegion(from
, to
)
1991 register int y
= curr
->w_y
;
1992 LClearArea(&curr
->w_layer
, from
, y
, to
, y
, CURR_BCE
, 1);
1993 MClearArea(curr
, from
, y
, to
, y
, CURR_BCE
);
1994 RestorePosRendition();
2001 register int x
= curr
->w_x
;
2008 if ((curr
->w_x
+= n
) >= cols
)
2009 curr
->w_x
= cols
- 1;
2010 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2017 if (curr
->w_y
< curr
->w_top
) /* if above scrolling rgn, */
2019 if ((curr
->w_y
-= n
) < 0) /* ignore its limits */
2023 if ((curr
->w_y
-= n
) < curr
->w_top
)
2024 curr
->w_y
= curr
->w_top
;
2025 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2032 if (curr
->w_y
> curr
->w_bot
) /* if below scrolling rgn, */
2034 if ((curr
->w_y
+= n
) > rows
- 1) /* ignore its limits */
2035 curr
->w_y
= rows
- 1;
2038 if ((curr
->w_y
+= n
) > curr
->w_bot
)
2039 curr
->w_y
= curr
->w_bot
;
2040 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2047 if ((curr
->w_x
-= n
) < 0)
2049 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2058 for (i
= 0; i
< curr
->w_NumArgs
; ++i
)
2060 switch (curr
->w_args
[i
])
2062 /* case 2: KAM: Lock keyboard */
2063 case 4: /* IRM: Insert mode */
2064 curr
->w_insert
= on
;
2065 LAY_DISPLAYS(&curr
->w_layer
, InsertMode(on
));
2067 /* case 12: SRM: Echo mode on */
2068 case 20: /* LNM: Linefeed mode */
2069 curr
->w_autolf
= on
;
2072 curr
->w_curvvis
= !on
;
2073 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
2081 static char rendlist
[] =
2083 ~((1 << NATTR
) - 1), A_BD
, A_DI
, A_SO
, A_US
, A_BL
, 0, A_RV
, 0, 0,
2084 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2085 0, 0, ~(A_BD
|A_SO
|A_DI
), ~A_SO
, ~A_US
, ~A_BL
, 0, ~A_RV
2092 register int j
, i
= 0, a
= curr
->w_rend
.attr
, c
= curr
->w_rend
.color
;
2094 int cx
= curr
->w_rend
.colorx
;
2097 register int j
, i
= 0, a
= curr
->w_rend
.attr
;
2102 j
= curr
->w_args
[i
];
2104 if ((j
== 38 || j
== 48) && i
+ 2 < curr
->w_NumArgs
&& curr
->w_args
[i
+ 1] == 5)
2109 jj
= curr
->w_args
[i
];
2110 if (jj
< 0 || jj
> 255)
2115 c
= (c
& 0xf0) | ((jj
& 0x0f) ^ 9);
2117 if (jj
>= 8 && jj
< 16)
2121 a
= (a
& 0xbf) | (jj
& 8 ? 0x40 : 0);
2122 cx
= (cx
& 0xf0) | (jj
>> 4 & 0x0f);
2126 c
= (c
& 0x0f) | ((jj
& 0x0f) ^ 9) << 4;
2128 if (jj
>= 8 && jj
< 16)
2132 cx
= (cx
& 0x0f) | (jj
& 0xf0);
2136 jj
= color256to16(jj
) + 30;
2139 j
= j
== 38 ? jj
: jj
+ 10;
2143 if (j
== 0 || (j
>= 30 && j
<= 39 && j
!= 38))
2145 if (j
== 0 || (j
>= 40 && j
<= 49 && j
!= 48))
2147 if (j
>= 90 && j
<= 97)
2149 if (j
>= 100 && j
<= 107)
2152 if (j
>= 90 && j
<= 97)
2154 if (j
>= 100 && j
<= 107)
2156 if (j
>= 30 && j
<= 39 && j
!= 38)
2157 c
= (c
& 0xf0) | ((j
- 30) ^ 9);
2158 else if (j
>= 40 && j
<= 49 && j
!= 48)
2159 c
= (c
& 0x0f) | (((j
- 40) ^ 9) << 4);
2163 if (j
== 0 || (j
>= 30 && j
<= 39 && j
!= 38))
2165 if (j
== 0 || (j
>= 40 && j
<= 49 && j
!= 48))
2169 if (j
< 0 || j
>= (int)(sizeof(rendlist
)/sizeof(*rendlist
)))
2172 if (j
& (1 << NATTR
))
2177 while (++i
< curr
->w_NumArgs
);
2178 curr
->w_rend
.attr
= a
;
2180 curr
->w_rend
.color
= c
;
2182 curr
->w_rend
.colorx
= cx
;
2185 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
2192 register unsigned char *p
, *ep
;
2194 LClearAll(&curr
->w_layer
, 1);
2195 curr
->w_y
= curr
->w_x
= 0;
2196 for (i
= 0; i
< rows
; ++i
)
2198 clear_mline(&curr
->w_mlines
[i
], 0, cols
+ 1);
2199 p
= curr
->w_mlines
[i
].image
;
2204 LRefreshAll(&curr
->w_layer
, 1);
2209 * Ugly autoaka hack support:
2210 * ChangeAKA() sets a new aka
2211 * FindAKA() searches for an autoaka match
2222 for (i
= 0; l
> 0; l
--)
2224 if (p
->w_akachange
+ i
== p
->w_akabuf
+ sizeof(p
->w_akabuf
) - 1)
2226 c
= (unsigned char)*s
++;
2229 if (c
< 32 || c
== 127 || (c
>= 128 && c
< 160 && p
->w_c1
))
2231 p
->w_akachange
[i
++] = c
;
2233 p
->w_akachange
[i
] = 0;
2234 p
->w_title
= p
->w_akachange
;
2235 if (p
->w_akachange
!= p
->w_akabuf
)
2236 if (p
->w_akachange
[0] == 0 || p
->w_akachange
[-1] == ':')
2237 p
->w_title
= p
->w_akabuf
+ strlen(p
->w_akabuf
) + 1;
2238 WindowChanged(p
, 't');
2239 WindowChanged((struct win
*)0, 'w');
2240 WindowChanged((struct win
*)0, 'W');
2246 register unsigned char *cp
, *line
;
2247 register struct win
*wp
= curr
;
2248 register int len
= strlen(wp
->w_akabuf
);
2251 y
= (wp
->w_autoaka
> 0 && wp
->w_autoaka
<= wp
->w_height
) ? wp
->w_autoaka
- 1 : wp
->w_y
;
2254 cp
= line
= wp
->w_mlines
[y
].image
;
2255 if (wp
->w_autoaka
> 0 && *wp
->w_akabuf
!= '\0')
2259 if (cp
- line
>= cols
- len
)
2261 if (++y
== wp
->w_autoaka
&& y
< rows
)
2265 if (strncmp((char *)cp
, wp
->w_akabuf
, len
) == 0)
2271 for (len
= cols
- (cp
- line
); len
&& *cp
== ' '; len
--, cp
++)
2275 if (wp
->w_autoaka
> 0 && (*cp
== '!' || *cp
== '%' || *cp
== '^'))
2280 while (len
&& *cp
!= ' ')
2286 ChangeAKA(wp
, (char *)line
, cp
- line
);
2293 RestorePosRendition()
2295 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2296 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
2299 /* Send a terminal report as if it were typed. */
2306 char rbuf
[40]; /* enough room for all replys */
2308 sprintf(rbuf
, fmt
, n1
, n2
);
2314 if ((unsigned)(curr
->w_pwin
->p_inlen
+ len
) <= sizeof(curr
->w_pwin
->p_inbuf
))
2316 bcopy(rbuf
, curr
->w_pwin
->p_inbuf
+ curr
->w_pwin
->p_inlen
, len
);
2317 curr
->w_pwin
->p_inlen
+= len
;
2323 if ((unsigned)(curr
->w_inlen
+ len
) <= sizeof(curr
->w_inbuf
))
2325 bcopy(rbuf
, curr
->w_inbuf
+ curr
->w_inlen
, len
);
2326 curr
->w_inlen
+= len
;
2334 *====================================================================*
2335 *====================================================================*
2338 /**********************************************************************
2350 struct mline
*ml
= &p
->w_mlines
[y
];
2351 if (mc
->attr
&& ml
->attr
== null
)
2353 if ((ml
->attr
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2356 mc
->attr
= p
->w_rend
.attr
= 0;
2357 WMsg(p
, 0, "Warning: no space for attr - turned off");
2361 if (mc
->font
&& ml
->font
== null
)
2363 if ((ml
->font
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2366 p
->w_FontL
= p
->w_charsets
[p
->w_ss
? p
->w_ss
: p
->w_Charset
] = 0;
2367 p
->w_FontR
= p
->w_charsets
[p
->w_ss
? p
->w_ss
: p
->w_CharsetR
] = 0;
2368 mc
->font
= p
->w_rend
.font
= 0;
2369 WMsg(p
, 0, "Warning: no space for font - turned off");
2374 if (mc
->color
&& ml
->color
== null
)
2376 if ((ml
->color
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2379 mc
->color
= p
->w_rend
.color
= 0;
2380 WMsg(p
, 0, "Warning: no space for color - turned off");
2384 if (mc
->colorx
&& ml
->colorx
== null
)
2386 if ((ml
->colorx
= (unsigned char *)calloc(p
->w_width
+ 1, 1)) == 0)
2389 mc
->colorx
= p
->w_rend
.colorx
= 0;
2390 WMsg(p
, 0, "Warning: no space for extended colors - turned off");
2397 /*****************************************************************/
2400 # define MKillDwRight(p, ml, x) \
2401 if (dw_right(ml, x, p->w_encoding)) \
2404 copy_mchar2mline(&mchar_blank, ml, x - 1); \
2405 copy_mchar2mline(&mchar_blank, ml, x); \
2408 # define MKillDwLeft(p, ml, x) \
2409 if (dw_left(ml, x, p->w_encoding)) \
2411 copy_mchar2mline(&mchar_blank, ml, x); \
2412 copy_mchar2mline(&mchar_blank, ml, x + 1); \
2415 # define MKillDwRight(p, ml, x) ;
2416 # define MKillDwLeft(p, ml, x) ;
2420 MScrollH(p
, n
, y
, xs
, xe
, bce
)
2422 int n
, y
, xs
, xe
, bce
;
2428 ml
= &p
->w_mlines
[y
];
2429 MKillDwRight(p
, ml
, xs
);
2430 MKillDwLeft(p
, ml
, xe
);
2433 if (xe
- xs
+ 1 > n
)
2435 MKillDwRight(p
, ml
, xs
+ n
);
2436 bcopy_mline(ml
, xs
+ n
, xs
, xe
+ 1 - xs
- n
);
2440 clear_mline(ml
, xe
+ 1 - n
, n
);
2443 MBceLine(p
, y
, xe
+ 1 - n
, n
, bce
);
2449 if (xe
- xs
+ 1 > n
)
2451 MKillDwLeft(p
, ml
, xe
- n
);
2452 bcopy_mline(ml
, xs
, xs
+ n
, xe
+ 1 - xs
- n
);
2456 clear_mline(ml
, xs
, n
);
2459 MBceLine(p
, y
, xs
, n
, bce
);
2465 MScrollV(p
, n
, ys
, ye
, bce
)
2470 struct mline tmp
[256];
2479 MScrollV(p
, n
- 256, ys
, ye
, bce
);
2482 if (ye
- ys
+ 1 < n
)
2487 ye
= MFindUsedLine(p
, ye
, ys
);
2488 if (ye
- ys
+ 1 < n
)
2495 ml
= p
->w_mlines
+ ys
;
2496 for (i
= ys
; i
< ys
+ n
; i
++, ml
++)
2500 WAddLineToHist(p
, ml
);
2502 if (ml
->attr
!= null
)
2506 if (ml
->font
!= null
)
2511 if (ml
->color
!= null
)
2515 if (ml
->colorx
!= null
)
2520 bclear((char *)ml
->image
, p
->w_width
+ 1);
2523 MBceLine(p
, i
, 0, p
->w_width
, bce
);
2526 /* switch 'em over */
2527 cnt1
= n
* sizeof(struct mline
);
2528 cnt2
= (ye
- ys
+ 1 - n
) * sizeof(struct mline
);
2530 Scroll((char *)(p
->w_mlines
+ ys
), cnt1
, cnt2
, (char *)tmp
);
2536 MScrollV(p
, n
+ 256, ys
, ye
, bce
);
2540 if (ye
- ys
+ 1 < n
)
2543 ml
= p
->w_mlines
+ ye
;
2545 for (i
= ye
; i
> ye
- n
; i
--, ml
--)
2547 if (ml
->attr
!= null
)
2551 if (ml
->font
!= null
)
2556 if (ml
->color
!= null
)
2560 if (ml
->colorx
!= null
)
2565 bclear((char *)ml
->image
, p
->w_width
+ 1);
2568 MBceLine(p
, i
, 0, p
->w_width
, bce
);
2571 cnt1
= n
* sizeof(struct mline
);
2572 cnt2
= (ye
- ys
+ 1 - n
) * sizeof(struct mline
);
2574 Scroll((char *)(p
->w_mlines
+ ys
), cnt2
, cnt1
, (char *)tmp
);
2579 Scroll(cp
, cnt1
, cnt2
, tmp
)
2587 bcopy(cp
, tmp
, cnt1
);
2588 bcopy(cp
+ cnt1
, cp
, cnt2
);
2589 bcopy(tmp
, cp
+ cnt2
, cnt1
);
2593 bcopy(cp
+ cnt1
, tmp
, cnt2
);
2594 bcopy(cp
, cp
+ cnt2
, cnt1
);
2595 bcopy(tmp
, cp
, cnt2
);
2600 MClearArea(p
, xs
, ys
, xe
, ye
, bce
)
2602 int xs
, ys
, xe
, ye
, bce
;
2608 /* Check for zero-height window */
2609 if (ys
< 0 || ye
< ys
)
2612 /* check for magic margin condition */
2613 if (xs
>= p
->w_width
)
2614 xs
= p
->w_width
- 1;
2615 if (xe
>= p
->w_width
)
2616 xe
= p
->w_width
- 1;
2618 MKillDwRight(p
, p
->w_mlines
+ ys
, xs
);
2619 MKillDwLeft(p
, p
->w_mlines
+ ye
, xe
);
2621 ml
= p
->w_mlines
+ ys
;
2622 for (y
= ys
; y
<= ye
; y
++, ml
++)
2624 xxe
= (y
== ye
) ? xe
: p
->w_width
- 1;
2627 clear_mline(ml
, xs
, n
);
2630 MBceLine(p
, y
, xs
, xs
+ n
- 1, bce
);
2637 MInsChar(p
, c
, x
, y
)
2645 ASSERT(x
>= 0 && x
< p
->w_width
);
2647 ml
= p
->w_mlines
+ y
;
2648 n
= p
->w_width
- x
- 1;
2649 MKillDwRight(p
, ml
, x
);
2652 MKillDwRight(p
, ml
, p
->w_width
- 1);
2653 bcopy_mline(ml
, x
, x
+ 1, n
);
2655 copy_mchar2mline(c
, ml
, x
);
2661 MKillDwRight(p
, ml
, p
->w_width
- 1);
2662 bcopy_mline(ml
, x
+ 1, x
+ 2, n
);
2664 copy_mchar2mline(c
, ml
, x
+ 1);
2665 ml
->image
[x
+ 1] = c
->mbcs
;
2667 if (p
->w_encoding
!= UTF8
)
2668 ml
->font
[x
+ 1] |= 0x80;
2669 else if (p
->w_encoding
== UTF8
&& c
->mbcs
)
2670 ml
->font
[x
+ 1] = c
->mbcs
;
2672 ml
->font
[x
+ 1] |= 0x80;
2679 MPutChar(p
, c
, x
, y
)
2687 ml
= &p
->w_mlines
[y
];
2688 MKillDwRight(p
, ml
, x
);
2689 MKillDwLeft(p
, ml
, x
);
2690 copy_mchar2mline(c
, ml
, x
);
2694 MKillDwLeft(p
, ml
, x
+ 1);
2695 copy_mchar2mline(c
, ml
, x
+ 1);
2696 ml
->image
[x
+ 1] = c
->mbcs
;
2698 if (p
->w_encoding
!= UTF8
)
2699 ml
->font
[x
+ 1] |= 0x80;
2700 else if (p
->w_encoding
== UTF8
&& c
->mbcs
)
2701 ml
->font
[x
+ 1] = c
->mbcs
;
2703 ml
->font
[x
+ 1] |= 0x80;
2711 MWrapChar(p
, c
, y
, top
, bot
, ins
)
2721 bce
= rend_getbg(c
);
2726 ml
= &p
->w_mlines
[y
];
2727 copy_mchar2mline(&mchar_null
, ml
, p
->w_width
);
2729 MScrollV(p
, 1, top
, bot
, bce
);
2730 else if (y
< p
->w_height
- 1)
2733 MInsChar(p
, c
, 0, y
);
2735 MPutChar(p
, c
, 0, y
);
2739 MPutStr(p
, s
, n
, r
, x
, y
)
2753 ml
= &p
->w_mlines
[y
];
2754 MKillDwRight(p
, ml
, x
);
2755 MKillDwLeft(p
, ml
, x
+ n
- 1);
2756 bcopy(s
, (char *)ml
->image
+ x
, n
);
2758 for (i
= n
; i
-- > 0;)
2762 for (i
= n
; i
-- > 0;)
2767 for (i
= n
; i
-- > 0;)
2771 for (i
= n
; i
-- > 0;)
2779 MBceLine(p
, y
, xs
, xe
, bce
)
2788 rend_setbg(&mc
, bce
);
2789 MFixLine(p
, y
, &mc
);
2790 ml
= p
->w_mlines
+ y
;
2793 for (x
= xs
; x
<= xe
; x
++)
2794 ml
->attr
[x
] = mc
.attr
;
2797 for (x
= xs
; x
<= xe
; x
++)
2798 ml
->color
[x
] = mc
.color
;
2801 for (x
= xs
; x
<= xe
; x
++)
2802 ml
->colorx
[x
] = mc
.colorx
;
2810 WAddLineToHist(wp
, ml
)
2814 register unsigned char *q
, *o
;
2817 if (wp
->w_histheight
== 0)
2819 hml
= &wp
->w_hlines
[wp
->w_histidx
];
2820 q
= ml
->image
; ml
->image
= hml
->image
; hml
->image
= q
;
2822 q
= ml
->attr
; o
= hml
->attr
; hml
->attr
= q
; ml
->attr
= null
;
2827 q
= ml
->font
; o
= hml
->font
; hml
->font
= q
; ml
->font
= null
;
2833 q
= ml
->color
; o
= hml
->color
; hml
->color
= q
; ml
->color
= null
;
2837 q
= ml
->colorx
; o
= hml
->colorx
; hml
->colorx
= q
; ml
->colorx
= null
;
2843 if (++wp
->w_histidx
>= wp
->w_histheight
)
2849 MFindUsedLine(p
, ye
, ys
)
2854 struct mline
*ml
= p
->w_mlines
+ ye
;
2856 debug2("MFindUsedLine: %d %d\n", ye
, ys
);
2857 for (y
= ye
; y
>= ys
; y
--, ml
--)
2859 if (bcmp((char*)ml
->image
, blank
, p
->w_width
))
2861 if (ml
->attr
!= null
&& bcmp((char*)ml
->attr
, null
, p
->w_width
))
2864 if (ml
->color
!= null
&& bcmp((char*)ml
->color
, null
, p
->w_width
))
2867 if (ml
->colorx
!= null
&& bcmp((char*)ml
->colorx
, null
, p
->w_width
))
2872 debug1("MFindUsedLine returning %d\n", y
);
2878 *====================================================================*
2879 *====================================================================*
2883 * Tricky: send only one bell even if the window is displayed
2892 for (display
= displays
; display
; display
= display
->d_next
)
2894 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2895 if (cv
->c_layer
->l_bottom
== &p
->w_layer
)
2899 else if (cv
&& D_VB
)
2902 p
->w_bell
= visual
? BELL_VISUAL
: BELL_FOUND
;
2907 * This should be reverse video.
2908 * Only change video if window is fore.
2909 * Because it is used in some termcaps to emulate
2910 * a visual bell we do this hack here.
2911 * (screen uses \Eg as special vbell sequence)
2914 WReverseVideo(p
, on
)
2919 for (cv
= p
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
2921 display
= cv
->c_display
;
2925 if (!on
&& p
->w_revvid
&& !D_CVR
)
2930 p
->w_bell
= BELL_VISUAL
;
2941 extern struct layer
*flayer
;
2942 struct layer
*oldflayer
= flayer
;
2943 flayer
= &p
->w_layer
;
2949 WChangeSize(p
, w
, h
)
2956 if (p
->w_layer
.l_cvlist
== 0)
2958 /* window not displayed -> works always */
2959 ChangeWindowSize(p
, w
, h
, p
->w_histheight
);
2962 for (cv
= p
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
2964 display
= cv
->c_display
;
2966 continue; /* change only fore */
2969 if (D_CZ0
&& (w
== Z0width
|| w
== Z1width
))
2972 if (cv
== 0 && wok
== 0) /* can't change any display */
2976 ChangeWindowSize(p
, w
, h
, p
->w_histheight
);
2977 for (display
= displays
; display
; display
= display
->d_next
)
2981 if (D_cvlist
&& D_cvlist
->c_next
== 0)
2982 ResizeDisplay(w
, h
);
2984 ResizeDisplay(w
, D_height
);
2985 ResizeLayersToCanvases(); /* XXX Hmm ? */
2988 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2989 if (cv
->c_layer
->l_bottom
== &p
->w_layer
)
2997 WindowChangedCheck(s
, what
, hp
)
3006 if (*s
++ != (hp
? '%' : '\005'))
3011 while (*s
>= '0' && *s
<= '9')
3020 if (*s
== what
|| ((*s
| l
) == what
) || what
== 'd')
3031 WindowChanged(p
, what
)
3035 int inwstr
, inhstr
, inlstr
;
3036 int inwstrh
= 0, inhstrh
= 0, inlstrh
= 0;
3038 struct display
*olddisplay
= display
;
3041 inwstr
= inhstr
= 0;
3045 WindowChanged((struct win
*)0, 'w'|0x100);
3046 WindowChanged((struct win
*)0, 'W'|0x100);
3051 inwstr
= WindowChangedCheck(captionstring
, what
, &inwstrh
);
3052 inhstr
= WindowChangedCheck(hstatusstring
, what
, &inhstrh
);
3053 inlstr
= WindowChangedCheck(wliststr
, what
, &inlstrh
);
3057 inwstr
= inhstr
= 0;
3063 for (display
= displays
; display
; display
= display
->d_next
)
3067 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
3069 if (inlstr
|| (inlstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3070 WListUpdatecv(cv
, (struct win
*)0);
3071 p
= Layer2Window(cv
->c_layer
);
3072 if (inwstr
|| (inwstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3073 if (cv
->c_ye
+ 1 < D_height
)
3074 RefreshLine(cv
->c_ye
+ 1, 0, D_width
- 1, 0);
3077 if (inhstr
|| (inhstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3079 if (ox
!= -1 && ox
!= -1)
3082 display
= olddisplay
;
3086 if (p
->w_hstatus
&& *p
->w_hstatus
&& (inwstrh
|| inhstrh
|| inlstrh
) && WindowChangedCheck(p
->w_hstatus
, what
, (int *)0))
3092 if (!inwstr
&& !inhstr
&& !inlstr
)
3094 for (display
= displays
; display
; display
= display
->d_next
)
3099 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
3102 WListUpdatecv(cv
, p
);
3103 if (Layer2Window(cv
->c_layer
) != p
)
3106 if (inwstr
&& cv
->c_ye
+ 1 < D_height
)
3107 RefreshLine(cv
->c_ye
+ 1, 0, D_width
- 1, 0);
3109 if (got
&& inhstr
&& p
== D_fore
)
3111 if (ox
!= -1 && ox
!= -1)
3114 display
= olddisplay
;