1 /* Copyright (c) 1993-2002
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Copyright (c) 1987 Oliver Laumann
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program (see the file COPYING); if not, write to the
18 * Free Software Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 ****************************************************************
24 #include <sys/types.h>
26 #ifndef sun /* we want to know about TIOCPKT. */
27 # include <sys/ioctl.h>
36 extern struct display
*display
, *displays
;
37 extern struct win
*fore
; /* for 83 escape */
38 extern struct layer
*flayer
; /* for 83 escape */
40 extern struct NewWindow nwin_default
; /* for ResetWindow() */
41 extern int nversion
; /* numerical version of screen */
42 extern int log_flush
, logtstamp_on
, logtstamp_after
;
43 extern char *logtstamp_string
;
44 extern char *captionstring
;
45 extern char *hstatusstring
;
46 extern char *wliststr
;
48 extern int compacthist
;
51 extern struct acluser
*EffectiveAclUser
;
54 int Z0width
, Z1width
; /* widths for Z0/Z1 switching */
56 /* globals set in WriteString */
57 static struct win
*curr
; /* window we are working on */
58 static int rows
, cols
; /* window size of the curr window */
61 int use_hardstatus
= 1; /* display status line in hs */
63 int use_altscreen
= 0; /* enable alternate screen support? */
65 unsigned char *blank
; /* line filled with spaces */
66 unsigned char *null
; /* line filled with '\0' */
68 struct mline mline_old
;
69 struct mline mline_blank
;
70 struct mline mline_null
;
72 struct mchar mchar_null
;
73 struct mchar mchar_blank
= {' ' /* , 0, 0, ... */};
74 struct mchar mchar_so
= {' ', A_SO
/* , 0, 0, ... */};
76 /* keep string_t and string_t_string in sync! */
77 static char *string_t_string
[] =
80 "DCS", /* Device control string */
81 "OSC", /* Operating system command */
82 "APC", /* Application program command */
83 /* - used for status change */
84 "PM", /* Privacy message */
85 "AKA", /* title for current screen */
86 "GM", /* Global message to every display */
87 "STATUS" /* User hardstatus line */
90 /* keep state_t and state_t_string in sync! */
91 static char *state_t_string
[] =
93 "LIT", /* Literal input */
94 "ESC", /* Start of escape sequence */
95 "ASTR", /* Start of control string */
96 "STRESC", /* ESC seen in control string */
97 "CSI", /* Reading arguments in "CSI Pn ;...*/
98 "PRIN", /* Printer mode */
99 "PRINESC", /* ESC seen in printer mode */
100 "PRINCSI", /* CSI seen in printer mode */
101 "PRIN4" /* CSI 4 seen in printer mode */
104 static int Special
__P((int));
105 static void DoESC
__P((int, int));
106 static void DoCSI
__P((int, int));
107 static void StringStart
__P((enum string_t
));
108 static void StringChar
__P((int));
109 static int StringEnd
__P((void));
110 static void PrintStart
__P((void));
111 static void PrintChar
__P((int));
112 static void PrintFlush
__P((void));
114 static void DesignateCharset
__P((int, int));
115 static void MapCharset
__P((int));
116 static void MapCharsetR
__P((int));
118 static void SaveCursor
__P((void));
119 static void RestoreCursor
__P((void));
120 static void BackSpace
__P((void));
121 static void Return
__P((void));
122 static void LineFeed
__P((int));
123 static void ReverseLineFeed
__P((void));
124 static void InsertChar
__P((int));
125 static void DeleteChar
__P((int));
126 static void DeleteLine
__P((int));
127 static void InsertLine
__P((int));
128 static void Scroll
__P((char *, int, int, char *));
129 static void ForwardTab
__P((void));
130 static void BackwardTab
__P((void));
131 static void ClearScreen
__P((void));
132 static void ClearFromBOS
__P((void));
133 static void ClearToEOS
__P((void));
134 static void ClearLineRegion
__P((int, int));
135 static void CursorRight
__P((int));
136 static void CursorUp
__P((int));
137 static void CursorDown
__P((int));
138 static void CursorLeft
__P((int));
139 static void ASetMode
__P((int));
140 static void SelectRendition
__P((void));
141 static void RestorePosRendition
__P((void));
142 static void FillWithEs
__P((void));
143 static void FindAKA
__P((void));
144 static void Report
__P((char *, int, int));
145 static void ScrollRegion
__P((int));
147 static void WAddLineToHist
__P((struct win
*, struct mline
*));
149 static void WLogString
__P((struct win
*, char *, int));
150 static void WReverseVideo
__P((struct win
*, int));
151 static int WindowChangedCheck
__P((char *, int, int *));
152 static void MFixLine
__P((struct win
*, int, struct mchar
*));
153 static void MScrollH
__P((struct win
*, int, int, int, int, int));
154 static void MScrollV
__P((struct win
*, int, int, int, int));
155 static void MClearArea
__P((struct win
*, int, int, int, int, int));
156 static void MInsChar
__P((struct win
*, struct mchar
*, int, int));
157 static void MPutChar
__P((struct win
*, struct mchar
*, int, int));
158 static void MPutStr
__P((struct win
*, char *, int, struct mchar
*, int, int));
159 static void MWrapChar
__P((struct win
*, struct mchar
*, int, int, int, int));
161 static void MBceLine
__P((struct win
*, int, int, int, int));
165 # define CURR_BCE (curr->w_bce ? rend_getbg(&curr->w_rend) : 0)
175 p
->w_StringType
= NONE
;
180 register struct win
*p
;
184 p
->w_wrap
= nwin_default
.wrap
;
195 p
->w_bot
= p
->w_height
- 1;
199 p
->w_StringType
= NONE
;
200 bzero(p
->w_tabs
, p
->w_width
);
201 for (i
= 8; i
< p
->w_width
; i
+= 8)
203 p
->w_rend
= mchar_null
;
208 p
->w_bce
= nwin_default
.bce
;
212 /* adds max 22 bytes */
214 GetAnsiStatus(w
, buf
)
220 if (w
->w_state
== LIT
)
223 strcpy(p
, state_t_string
[w
->w_state
]);
225 if (w
->w_intermediate
)
228 if (w
->w_intermediate
> 0xff)
229 p
+= AddXChar(p
, w
->w_intermediate
>> 8);
230 p
+= AddXChar(p
, w
->w_intermediate
& 0xff);
233 if (w
->w_state
== ASTR
|| w
->w_state
== STRESC
)
234 sprintf(p
, "-%s", string_t_string
[w
->w_StringType
]);
246 p
->w_gr
= nwin_default
.gr
;
247 p
->w_c1
= nwin_default
.c1
;
248 SetCharsets(p
, "BBBB02");
249 if (nwin_default
.charset
)
250 SetCharsets(p
, nwin_default
.charset
);
263 for (i
= 0; i
< 4 && *s
; i
++, s
++)
265 p
->w_charsets
[i
] = ((*s
== 'B') ? ASCII
: *s
);
266 if (*s
&& *s
++ != '.')
267 p
->w_Charset
= s
[-1] - '0';
269 p
->w_CharsetR
= *s
- '0';
271 p
->w_FontL
= p
->w_charsets
[p
->w_Charset
];
272 p
->w_FontR
= p
->w_charsets
[p
->w_CharsetR
];
276 /*****************************************************************/
280 * Here comes the vt100 emulator
282 * - sets timestamp and flags activity in window.
283 * - record program output in window scrollback
284 * - translate program output for the display and put it into the obuf.
288 WriteString(wp
, buf
, len
)
302 WLogString(wp
, buf
, len
);
304 /* set global variables (yuck!) */
306 cols
= curr
->w_width
;
307 rows
= curr
->w_height
;
310 SetTimeout(&curr
->w_silenceev
, curr
->w_silencewait
* 1000);
312 if (curr
->w_monitor
== MON_ON
)
314 debug2("ACTIVITY %d %d\n", curr
->w_monitor
, curr
->w_bell
);
315 curr
->w_monitor
= MON_FOUND
;
320 c
= (unsigned char)*buf
++;
325 curr
->w_rend
.font
= curr
->w_FontL
; /* Default: GL */
328 /* The next part is only for speedup */
329 if (curr
->w_state
== LIT
&&
331 curr
->w_encoding
!= UTF8
&&
334 !is_dw_font(curr
->w_rend
.font
) &&
336 curr
->w_rend
.font
!= KANA
&& !curr
->w_mbcs
&&
340 curr
->w_rend
.font
!= '<' &&
342 c
>= ' ' && c
!= 0x7f &&
343 ((c
& 0x80) == 0 || ((c
>= 0xa0 || !curr
->w_c1
) && !curr
->w_gr
)) && !curr
->w_ss
&&
344 !curr
->w_insert
&& curr
->w_x
< cols
- 1)
346 register int currx
= curr
->w_x
;
349 while (currx
< cols
- 1)
354 c
= (unsigned char)*buf
++;
355 if (c
< ' ' || c
== 0x7f || ((c
& 0x80) && ((c
< 0xa0 && curr
->w_c1
) || curr
->w_gr
)))
361 MPutStr(curr
, imp
, currx
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
362 LPutStr(&curr
->w_layer
, imp
, currx
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
368 /* end of speedup code */
371 if (curr
->w_encoding
== UTF8
)
373 c
= FromUtf8(c
, &curr
->w_decodestate
);
384 debug1("read UNICODE %04x\n", c
);
389 switch (curr
->w_state
)
395 curr
->w_state
= PRINESC
;
405 curr
->w_state
= PRINCSI
;
410 curr
->w_state
= PRIN
;
417 curr
->w_state
= PRIN4
;
423 curr
->w_state
= PRIN
;
432 if (curr
->w_pdisplay
&& curr
->w_pdisplay
->d_printfd
>= 0)
434 close(curr
->w_pdisplay
->d_printfd
);
435 curr
->w_pdisplay
->d_printfd
= -1;
437 curr
->w_pdisplay
= 0;
444 curr
->w_state
= PRIN
;
452 curr
->w_state
= STRESC
;
455 /* special xterm hack: accept SetStatus sequence. Yucc! */
456 /* allow ^E for title escapes */
457 if (!(curr
->w_StringType
== OSC
&& c
< ' ' && c
!= '\005'))
458 if (!curr
->w_c1
|| c
!= ('\\' ^ 0xc0))
469 if (StringEnd() == 0 || len
<= 1)
471 /* check if somewhere a status is displayed */
472 for (cv
= curr
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
474 display
= cv
->c_display
;
475 if (D_status
== STATUS_ON_WIN
)
480 if (len
> IOSIZE
+ 1)
482 curr
->w_outlen
= len
- 1;
483 bcopy(buf
, curr
->w_outbuf
, len
- 1);
484 return; /* wait till status is gone */
491 curr
->w_state
= ASTR
;
502 curr
->w_intermediate
= 0;
503 bzero((char *) curr
->w_args
, MAXARGS
* sizeof(int));
531 debug1("not special. c = %x\n", c
);
532 if (c
>= ' ' && c
<= '/')
534 if (curr
->w_intermediate
)
537 if (curr
->w_intermediate
== '$')
543 curr
->w_intermediate
= c
;
545 else if (c
>= '0' && c
<= '~')
547 DoESC(c
, curr
->w_intermediate
);
560 case '0': case '1': case '2': case '3': case '4':
561 case '5': case '6': case '7': case '8': case '9':
562 if (curr
->w_NumArgs
< MAXARGS
)
564 if (curr
->w_args
[curr
->w_NumArgs
] < 100000000)
565 curr
->w_args
[curr
->w_NumArgs
] =
566 10 * curr
->w_args
[curr
->w_NumArgs
] + (c
- '0');
571 if (curr
->w_NumArgs
< MAXARGS
)
577 if (c
>= '@' && c
<= '~')
579 if (curr
->w_NumArgs
< MAXARGS
)
581 DoCSI(c
, curr
->w_intermediate
);
582 if (curr
->w_state
!= PRIN
)
585 else if ((c
>= ' ' && c
<= '/') || (c
>= '<' && c
<= '?'))
586 curr
->w_intermediate
= curr
->w_intermediate
? -1 : c
;
598 if (c
<= ' ' || c
== 0x7f || (c
>= 0x80 && c
< 0xa0 && curr
->w_c1
))
605 curr
->w_intermediate
= 0;
607 if (curr
->w_autoaka
< 0)
614 if (c
>= 0x80 && c
< 0xa0 && curr
->w_c1
)
616 if ((curr
->w_FontR
& 0xf0) != 0x20
618 || curr
->w_encoding
== UTF8
629 case 0xc0 ^ 'N': /* SS2 */
630 case 0xc0 ^ 'O': /* SS3 */
634 if (curr
->w_autoaka
< 0)
637 curr
->w_intermediate
= 0;
638 bzero((char *) curr
->w_args
, MAXARGS
* sizeof(int));
655 if (c
< 0x80 || curr
->w_gr
== 0)
656 curr
->w_rend
.font
= curr
->w_FontL
;
658 else if (curr
->w_gr
== 2 && !curr
->w_ss
)
659 curr
->w_rend
.font
= curr
->w_FontE
;
662 curr
->w_rend
.font
= curr
->w_FontR
;
667 if (curr
->w_encoding
== UTF8
)
669 if (curr
->w_rend
.font
== '0')
671 struct mchar mc
, *mcp
;
673 debug1("SPECIAL %x\n", c
);
677 mcp
= recode_mchar(&mc
, 0, UTF8
);
678 debug2("%02x %02x\n", mcp
->image
, mcp
->font
);
679 c
= mcp
->image
| mcp
->font
<< 8;
681 curr
->w_rend
.font
= 0;
684 if (curr
->w_encoding
== UTF8
&& c
>= 0x1100 && utf8_isdouble(c
))
687 if (curr
->w_encoding
== UTF8
&& c
>= 0x0300 && utf8_iscomb(c
))
696 ox
= curr
->w_width
- 1;
701 copy_mline2mchar(&omc
, &curr
->w_mlines
[oy
], ox
);
702 if (omc
.image
== 0xff && omc
.font
== 0xff)
707 copy_mline2mchar(&omc
, &curr
->w_mlines
[oy
], ox
);
713 utf8_handle_comb(c
, &omc
);
714 MFixLine(curr
, oy
, &omc
);
715 copy_mchar2mline(&omc
, &curr
->w_mlines
[oy
], ox
);
716 LPutChar(&curr
->w_layer
, &omc
, ox
, oy
);
717 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
721 font
= curr
->w_rend
.font
;
725 if (font
== KANA
&& curr
->w_encoding
== SJIS
&& curr
->w_mbcs
== 0)
727 /* Lets see if it is the first byte of a kanji */
728 debug1("%x may be first of SJIS\n", c
);
729 if ((0x81 <= c
&& c
<= 0x9f) || (0xe0 <= c
&& c
<= 0xef))
737 if (font
== 031 && c
== 0x80 && !curr
->w_mbcs
)
738 font
= curr
->w_rend
.font
= 0;
739 if (is_dw_font(font
) && c
== ' ')
740 font
= curr
->w_rend
.font
= 0;
741 if (is_dw_font(font
) || curr
->w_mbcs
)
744 if (curr
->w_mbcs
== 0)
749 if (curr
->w_x
== cols
- 1)
751 curr
->w_x
+= curr
->w_wrap
? 1 : -1;
752 debug1("Patched w_x to %d\n", curr
->w_x
);
755 if (curr
->w_encoding
!= UTF8
)
760 if (font
== KANA
&& curr
->w_encoding
== SJIS
)
762 debug2("SJIS !! %x %x\n", c
, t
);
764 * SJIS -> EUC mapping:
766 * 81,82...9f -> 21,23...5d
767 * e0,e1...ef -> 5f,61...7d
771 * 9f-fc -> 21-7e (increment first byte!)
773 if (0x40 <= t
&& t
<= 0xfc && t
!= 0x7f)
775 if (c
<= 0x9f) c
= (c
- 0x81) * 2 + 0x21;
776 else c
= (c
- 0xc1) * 2 + 0x21;
777 if (t
<= 0x7e) t
-= 0x1f;
778 else if (t
<= 0x9e) t
-= 0x20;
780 curr
->w_rend
.font
= KANJI
;
784 /* Incomplete shift-jis - skip first byte */
788 debug2("SJIS after %x %x\n", c
, t
);
791 if (t
&& curr
->w_gr
&& font
!= 030 && font
!= 031)
802 # endif /* DW_CHARS */
803 if (font
== '<' && c
>= ' ')
805 font
= curr
->w_rend
.font
= 0;
809 else if (curr
->w_gr
&& curr
->w_encoding
!= UTF8
)
815 if (c
== 0x80 && font
== 0 && curr
->w_encoding
== GBK
)
819 if (c
< ' ' && font
!= 031)
823 if (c
< ' ') /* this is ugly but kanji support */
824 goto tryagain
; /* prevents nicer programming */
830 curr
->w_rend
.image
= c
;
832 if (curr
->w_encoding
== UTF8
)
833 curr
->w_rend
.font
= c
>> 8;
836 curr
->w_rend
.mbcs
= curr
->w_mbcs
;
838 if (curr
->w_x
< cols
- 1)
842 save_mline(&curr
->w_mlines
[curr
->w_y
], cols
);
843 MInsChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
844 LInsChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
, &mline_old
);
849 MPutChar(curr
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
850 LPutChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_x
, curr
->w_y
);
854 else if (curr
->w_x
== cols
- 1)
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
);
863 MWrapChar(curr
, &curr
->w_rend
, curr
->w_y
, curr
->w_top
, curr
->w_bot
, curr
->w_insert
);
864 LWrapChar(&curr
->w_layer
, &curr
->w_rend
, curr
->w_y
, curr
->w_top
, curr
->w_bot
, curr
->w_insert
);
865 if (curr
->w_y
!= curr
->w_bot
&& curr
->w_y
!= curr
->w_height
- 1)
873 curr
->w_rend
.mbcs
= curr
->w_mbcs
= 0;
879 curr
->w_FontL
= curr
->w_charsets
[curr
->w_Charset
];
880 curr
->w_FontR
= curr
->w_charsets
[curr
->w_CharsetR
];
881 curr
->w_rend
.font
= curr
->w_FontL
;
882 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
890 if (!printcmd
&& curr
->w_state
== PRIN
)
895 WLogString(p
, buf
, len
)
902 if (logtstamp_on
&& p
->w_logsilence
>= logtstamp_after
* 2)
904 char *t
= MakeWinMsg(logtstamp_string
, p
, '%');
905 logfwrite(p
->w_log
, t
, strlen(t
)); /* long time no write */
908 if (logfwrite(p
->w_log
, buf
, len
) < 1)
910 WMsg(p
, errno
, "Error writing logfile");
936 WBell(curr
, visual_bell
);
942 case '\017': /* SI */
945 case '\016': /* SO */
954 DoESC(c
, intermediate
)
957 debug2("DoESC: %x - inter = %x\n", c
, intermediate
);
958 switch (intermediate
)
973 curr
->w_tabs
[curr
->w_x
] = 1;
975 case 'Z': /* jph: Identify as VT100 */
976 Report("\033[?%d;%dc", 1, 2);
987 LKeypadMode(&curr
->w_layer
, 0);
988 LCursorkeysMode(&curr
->w_layer
, 0);
990 WNewAutoFlow(curr
, 1);
993 SetRendition(&mchar_null);
995 ChangeScrollRegion(0, rows - 1);
997 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1000 LKeypadMode(&curr
->w_layer
, curr
->w_keypad
= 1);
1002 WNewAutoFlow(curr
, 0);
1003 #endif /* !TIOCPKT */
1006 LKeypadMode(&curr
->w_layer
, curr
->w_keypad
= 0);
1008 WNewAutoFlow(curr
, 1);
1009 #endif /* !TIOCPKT */
1019 MapCharsetR(G1
); /* LS1R */
1023 MapCharsetR(G2
); /* LS2R */
1026 MapCharsetR(G3
); /* LS3R */
1029 if (curr
->w_charsets
[curr
->w_Charset
] != curr
->w_charsets
[G2
]
1030 || curr
->w_charsets
[curr
->w_CharsetR
] != curr
->w_charsets
[G2
])
1031 curr
->w_FontR
= curr
->w_FontL
= curr
->w_charsets
[curr
->w_ss
= G2
];
1036 if (curr
->w_charsets
[curr
->w_Charset
] != curr
->w_charsets
[G3
]
1037 || curr
->w_charsets
[curr
->w_CharsetR
] != curr
->w_charsets
[G3
])
1038 curr
->w_FontR
= curr
->w_FontL
= curr
->w_charsets
[curr
->w_ss
= G3
];
1043 case 'g': /* VBELL, private screen sequence */
1058 DesignateCharset(c
, G0
);
1061 DesignateCharset(c
, G1
);
1064 DesignateCharset(c
, G2
);
1067 DesignateCharset(c
, G3
);
1071 * ESC $ ( Fn: invoke multi-byte charset, Fn, to G0
1072 * ESC $ Fn: same as above. (old sequence)
1073 * ESC $ ) Fn: invoke multi-byte charset, Fn, to G1
1074 * ESC $ * Fn: invoke multi-byte charset, Fn, to G2
1075 * ESC $ + Fn: invoke multi-byte charset, Fn, to G3
1079 DesignateCharset(c
& 037, G0
);
1082 DesignateCharset(c
& 037, G1
);
1085 DesignateCharset(c
& 037, G2
);
1088 DesignateCharset(c
& 037, G3
);
1096 DoCSI(c
, intermediate
)
1097 int c
, intermediate
;
1099 register int i
, a1
= curr
->w_args
[0], a2
= curr
->w_args
[1];
1101 if (curr
->w_NumArgs
> MAXARGS
)
1102 curr
->w_NumArgs
= MAXARGS
;
1103 switch (intermediate
)
1120 LGotoPos(&curr
->w_layer
, --a2
, --a1
);
1123 if (curr
->w_autoaka
)
1124 curr
->w_autoaka
= a1
+ 1;
1127 if (a1
< 0 || a1
> 2)
1139 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1144 if (a1
< 0 || a1
> 2)
1149 ClearLineRegion(curr
->w_x
, cols
- 1);
1152 ClearLineRegion(0, curr
->w_x
);
1155 ClearLineRegion(0, cols
- 1);
1160 a1
= curr
->w_x
+ (a1
? a1
- 1 : 0);
1161 ClearLineRegion(curr
->w_x
, a1
< cols
? a1
: cols
- 1);
1164 CursorUp(a1
? a1
: 1);
1167 CursorDown(a1
? a1
: 1);
1170 CursorRight(a1
? a1
: 1);
1173 CursorLeft(a1
? a1
: 1);
1177 CursorDown(a1
? a1
: 1); /* positions cursor */
1181 CursorUp(a1
? a1
: 1); /* positions cursor */
1185 curr
->w_x
= a1
? a1
- 1 : 0;
1186 if (curr
->w_x
>= cols
)
1187 curr
->w_x
= cols
- 1;
1188 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1191 curr
->w_y
= a1
? a1
- 1 : 0;
1192 if (curr
->w_y
>= rows
)
1193 curr
->w_y
= rows
- 1;
1194 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1201 curr
->w_tabs
[curr
->w_x
] = 0;
1203 bzero(curr
->w_tabs
, cols
);
1210 if (a1
< 1 || a2
> rows
|| a1
>= a2
)
1212 curr
->w_top
= a1
- 1;
1213 curr
->w_bot
= a2
- 1;
1214 /* ChangeScrollRegion(curr->w_top, curr->w_bot); */
1217 curr
->w_y
= curr
->w_top
;
1221 curr
->w_y
= curr
->w_x
= 0;
1222 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1231 if (curr
->w_layer
.l_cvlist
)
1232 Report("\033[1t", 0, 0);
1234 Report("\033[2t", 0, 0);
1237 LRefreshAll(&curr
->w_layer
, 0);
1240 a1
= strlen(curr
->w_title
);
1241 if ((unsigned)(curr
->w_inlen
+ 5 + a1
) <= sizeof(curr
->w_inbuf
))
1243 bcopy("\033]l", curr
->w_inbuf
+ curr
->w_inlen
, 3);
1244 bcopy(curr
->w_title
, curr
->w_inbuf
+ curr
->w_inlen
+ 3, a1
);
1245 bcopy("\033\\", curr
->w_inbuf
+ curr
->w_inlen
+ 3 + a1
, 2);
1246 curr
->w_inlen
+= 5 + a1
;
1250 a1
= curr
->w_args
[2];
1254 a2
= curr
->w_height
;
1255 if (a1
> 10000 || a2
> 10000)
1257 WChangeSize(curr
, a1
, a2
);
1258 cols
= curr
->w_width
;
1259 rows
= curr
->w_height
;
1281 InsertLine(a1
? a1
: 1);
1284 DeleteLine(a1
? a1
: 1);
1287 DeleteChar(a1
? a1
: 1);
1290 InsertChar(a1
? a1
: 1);
1298 case 'i': /* MC Media Control */
1303 if (a1
== 5) /* Report terminal status */
1304 Report("\033[0n", 0, 0);
1305 else if (a1
== 6) /* Report cursor position */
1306 Report("\033[%d;%dR", curr
->w_y
+ 1, curr
->w_x
+ 1);
1308 case 'c': /* Identify as VT100 */
1310 Report("\033[?%d;%dc", 1, 2);
1312 case 'x': /* decreqtparm */
1313 if (a1
== 0 || a1
== 1)
1314 Report("\033[%d;1;1;112;112;1;0x", a1
+ 2, 0);
1316 case 'p': /* obscure code from a 97801 term */
1317 if (a1
== 6 || a1
== 7)
1319 curr
->w_curinv
= 7 - a1
;
1320 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
1323 case 'S': /* code from a 97801 term / DEC vt400 */
1324 ScrollRegion(a1
? a1
: 1);
1326 case 'T': /* code from a 97801 term / DEC vt400 */
1327 case '^': /* SD as per ISO 6429 */
1328 ScrollRegion(a1
? -a1
: -1);
1333 for (a2
= 0; a2
< curr
->w_NumArgs
; a2
++)
1335 a1
= curr
->w_args
[a2
];
1336 debug2("\\E[?%d%c\n",a1
,c
);
1337 if (c
!= 'h' && c
!= 'l')
1342 case 1: /* CKM: cursor key mode */
1343 LCursorkeysMode(&curr
->w_layer
, curr
->w_cursorkeys
= i
);
1345 WNewAutoFlow(curr
, !i
);
1346 #endif /* !TIOCPKT */
1348 case 2: /* ANM: ansi/vt52 mode */
1353 if (curr
->w_encoding
)
1356 curr
->w_charsets
[0] = curr
->w_charsets
[1] =
1357 curr
->w_charsets
[2] = curr
->w_charsets
[2] =
1358 curr
->w_FontL
= curr
->w_FontR
= ASCII
;
1359 curr
->w_Charset
= 0;
1360 curr
->w_CharsetR
= 2;
1365 case 3: /* COLM: column mode */
1366 i
= (i
? Z0width
: Z1width
);
1367 WChangeSize(curr
, i
, curr
->w_height
);
1368 cols
= curr
->w_width
;
1369 rows
= curr
->w_height
;
1371 /* case 4: SCLM: scrolling mode */
1372 case 5: /* SCNM: screen mode */
1373 if (i
!= curr
->w_revvid
)
1374 WReverseVideo(curr
, i
);
1377 case 6: /* OM: origin mode */
1378 if ((curr
->w_origin
= i
) != 0)
1380 curr
->w_y
= curr
->w_top
;
1384 curr
->w_y
= curr
->w_x
= 0;
1385 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1387 case 7: /* AWM: auto wrap mode */
1390 /* case 8: ARM: auto repeat mode */
1391 /* case 9: INLM: interlace mode */
1392 case 9: /* X10 mouse tracking */
1393 curr
->w_mouse
= i
? 9 : 0;
1394 LMouseMode(&curr
->w_layer
, curr
->w_mouse
);
1396 /* case 10: EDM: edit mode */
1397 /* case 11: LTM: line transmit mode */
1398 /* case 13: SCFDM: space compression / field delimiting */
1399 /* case 14: TEM: transmit execution mode */
1400 /* case 16: EKEM: edit key execution mode */
1401 /* case 18: PFF: Printer term form feed */
1402 /* case 19: PEX: Printer extend screen / scroll. reg */
1403 case 25: /* TCEM: text cursor enable mode */
1404 curr
->w_curinv
= !i
;
1405 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
1407 /* case 34: RLM: Right to left mode */
1408 /* case 35: HEBM: hebrew keyboard map */
1409 /* case 36: HEM: hebrew encoding */
1410 /* case 38: TeK Mode */
1411 /* case 40: 132 col enable */
1412 /* case 42: NRCM: 7bit NRC character mode */
1413 /* case 44: margin bell enable */
1414 case 47: /* xterm-like alternate screen */
1415 case 1047: /* xterm-like alternate screen */
1416 case 1049: /* xterm-like alternate screen */
1420 EnterAltScreen(curr
);
1422 LeaveAltScreen(curr
);
1425 LRefreshAll(&curr
->w_layer
, 0);
1426 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1429 /* case 66: NKM: Numeric keypad appl mode */
1430 /* case 68: KBUM: Keyboard usage mode (data process) */
1431 case 1000: /* VT200 mouse tracking */
1432 case 1001: /* VT200 highlight mouse */
1433 case 1002: /* button event mouse*/
1434 case 1003: /* any event mouse*/
1435 curr
->w_mouse
= i
? a1
: 0;
1436 LMouseMode(&curr
->w_layer
, curr
->w_mouse
);
1444 case 'c': /* secondary DA */
1446 Report("\033[>%d;%d;0c", 83, nversion
); /* 83 == 'S' */
1458 curr
->w_StringType
= type
;
1459 curr
->w_stringp
= curr
->w_string
;
1460 curr
->w_state
= ASTR
;
1467 if (curr
->w_stringp
>= curr
->w_string
+ MAXSTR
- 1)
1468 curr
->w_state
= LIT
;
1470 *(curr
->w_stringp
)++ = c
;
1474 * Do string processing. Returns -1 if output should be suspended
1475 * until status is gone.
1484 curr
->w_state
= LIT
;
1485 *curr
->w_stringp
= '\0';
1486 switch (curr
->w_StringType
)
1488 case OSC
: /* special xterm compatibility hack */
1489 if (curr
->w_string
[0] == ';' || (p
= index(curr
->w_string
, ';')) == 0)
1491 typ
= atoi(curr
->w_string
);
1494 if (typ
== 83) /* 83 = 'S' */
1496 /* special execute commands sequence */
1497 char *args
[MAXARGS
];
1499 struct acluser
*windowuser
;
1501 windowuser
= *FindUserPtr(":window:");
1502 if (windowuser
&& Parse(p
, sizeof(curr
->w_string
) - (p
- curr
->w_string
), args
, argl
))
1504 for (display
= displays
; display
; display
= display
->d_next
)
1505 if (D_forecv
->c_layer
->l_bottom
== &curr
->w_layer
)
1506 break; /* found it */
1507 if (display
== 0 && curr
->w_layer
.l_cvlist
)
1508 display
= curr
->w_layer
.l_cvlist
->c_display
;
1511 EffectiveAclUser
= windowuser
;
1513 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1514 DoCommand(args
, argl
);
1515 EffectiveAclUser
= 0;
1523 if (typ
== 0 || typ
== 1 || typ
== 20 || typ
== 39 || typ
== 49)
1529 if (strcmp(curr
->w_xtermosc
[typ2
], p
))
1531 strncpy(curr
->w_xtermosc
[typ2
], p
, sizeof(curr
->w_xtermosc
[typ2
]) - 1);
1532 curr
->w_xtermosc
[typ2
][sizeof(curr
->w_xtermosc
[typ2
]) - 1] = 0;
1534 for (display
= displays
; display
; display
= display
->d_next
)
1538 if (D_forecv
->c_layer
->l_bottom
== &curr
->w_layer
)
1539 SetXtermOSC(typ2
, curr
->w_xtermosc
[typ2
]);
1540 if ((typ2
== 2 || typ2
== 3) && D_xtermosc
[typ2
])
1545 if (typ
!= 0 && typ
!= 2)
1548 if (typ
< 0 || typ
> 2)
1552 curr
->w_stringp
-= p
- curr
->w_string
;
1553 if (curr
->w_stringp
> curr
->w_string
)
1554 bcopy(p
, curr
->w_string
, curr
->w_stringp
- curr
->w_string
);
1555 *curr
->w_stringp
= '\0';
1558 if (curr
->w_hstatus
)
1560 if (strcmp(curr
->w_hstatus
, curr
->w_string
) == 0)
1561 break; /* not changed */
1562 free(curr
->w_hstatus
);
1563 curr
->w_hstatus
= 0;
1565 if (curr
->w_string
!= curr
->w_stringp
)
1566 curr
->w_hstatus
= SaveStr(curr
->w_string
);
1567 WindowChanged(curr
, 'h');
1571 for (display
= displays
; display
; display
= display
->d_next
)
1573 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
1574 if (cv
->c_layer
->l_bottom
== &curr
->w_layer
)
1576 if (cv
|| curr
->w_StringType
== GM
)
1577 MakeStatus(curr
->w_string
);
1581 LAY_DISPLAYS(&curr
->w_layer
, AddStr(curr
->w_string
));
1584 if (curr
->w_title
== curr
->w_akabuf
&& !*curr
->w_string
)
1586 ChangeAKA(curr
, curr
->w_string
, strlen(curr
->w_string
));
1587 if (!*curr
->w_string
)
1588 curr
->w_autoaka
= curr
->w_y
+ 1;
1599 curr
->w_pdisplay
= 0;
1601 /* find us a nice display to print on, fore prefered */
1602 display
= curr
->w_lastdisp
;
1603 if (!(display
&& curr
== D_fore
&& (printcmd
|| D_PO
)))
1604 for (display
= displays
; display
; display
= display
->d_next
)
1605 if (curr
== D_fore
&& (printcmd
|| D_PO
))
1610 for (cv
= curr
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
1612 display
= cv
->c_display
;
1613 if (printcmd
|| D_PO
)
1619 if (!display
|| display
->d_next
|| !(printcmd
|| D_PO
))
1623 curr
->w_pdisplay
= display
;
1624 curr
->w_stringp
= curr
->w_string
;
1625 curr
->w_state
= PRIN
;
1626 if (printcmd
&& curr
->w_pdisplay
->d_printfd
< 0)
1627 curr
->w_pdisplay
->d_printfd
= printpipe(curr
, printcmd
);
1634 if (curr
->w_stringp
>= curr
->w_string
+ MAXSTR
- 1)
1636 *(curr
->w_stringp
)++ = c
;
1642 display
= curr
->w_pdisplay
;
1643 if (display
&& printcmd
)
1645 char *bp
= curr
->w_string
;
1646 int len
= curr
->w_stringp
- curr
->w_string
;
1648 while (len
&& display
->d_printfd
>= 0)
1650 r
= write(display
->d_printfd
, bp
, len
);
1653 WMsg(curr
, errno
, "printing aborted");
1654 close(display
->d_printfd
);
1655 display
->d_printfd
= -1;
1662 else if (display
&& curr
->w_stringp
> curr
->w_string
)
1665 AddStrn(curr
->w_string
, curr
->w_stringp
- curr
->w_string
);
1669 curr
->w_stringp
= curr
->w_string
;
1674 WNewAutoFlow(win
, on
)
1678 debug1("WNewAutoFlow: %d\n", on
);
1679 if (win
->w_flow
& FLOW_AUTOFLAG
)
1680 win
->w_flow
= FLOW_AUTOFLAG
| (FLOW_AUTO
|FLOW_NOW
) * on
;
1682 win
->w_flow
= (win
->w_flow
& ~FLOW_AUTO
) | FLOW_AUTO
* on
;
1683 LSetFlow(&win
->w_layer
, win
->w_flow
& FLOW_NOW
);
1690 DesignateCharset(c
, n
)
1695 if (c
== ('@' & 037)) /* map JIS 6226 to 0208 */
1700 if (curr
->w_charsets
[n
] != c
)
1702 curr
->w_charsets
[n
] = c
;
1703 if (curr
->w_Charset
== n
)
1706 curr
->w_rend
.font
= curr
->w_FontL
;
1707 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1709 if (curr
->w_CharsetR
== n
)
1719 if (curr
->w_Charset
!= n
)
1721 curr
->w_Charset
= n
;
1722 curr
->w_FontL
= curr
->w_charsets
[n
];
1723 curr
->w_rend
.font
= curr
->w_FontL
;
1724 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1733 if (curr
->w_CharsetR
!= n
)
1735 curr
->w_CharsetR
= n
;
1736 curr
->w_FontR
= curr
->w_charsets
[n
];
1747 curr
->w_Saved_x
= curr
->w_x
;
1748 curr
->w_Saved_y
= curr
->w_y
;
1749 curr
->w_SavedRend
= curr
->w_rend
;
1751 curr
->w_SavedCharset
= curr
->w_Charset
;
1752 curr
->w_SavedCharsetR
= curr
->w_CharsetR
;
1753 bcopy((char *) curr
->w_charsets
, (char *) curr
->w_SavedCharsets
,
1763 LGotoPos(&curr
->w_layer
, curr
->w_Saved_x
, curr
->w_Saved_y
);
1764 curr
->w_x
= curr
->w_Saved_x
;
1765 curr
->w_y
= curr
->w_Saved_y
;
1766 curr
->w_rend
= curr
->w_SavedRend
;
1768 bcopy((char *) curr
->w_SavedCharsets
, (char *) curr
->w_charsets
,
1770 curr
->w_Charset
= curr
->w_SavedCharset
;
1771 curr
->w_CharsetR
= curr
->w_SavedCharsetR
;
1773 curr
->w_FontL
= curr
->w_charsets
[curr
->w_Charset
];
1774 curr
->w_FontR
= curr
->w_charsets
[curr
->w_CharsetR
];
1776 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
1786 else if (curr
->w_wrap
&& curr
->w_y
> 0)
1788 curr
->w_x
= cols
- 1;
1791 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1800 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1807 /* out_mode: 0=lf, 1=cr+lf */
1810 if (curr
->w_y
!= curr
->w_bot
) /* Don't scroll */
1812 if (curr
->w_y
< rows
-1)
1814 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1817 if (curr
->w_autoaka
> 1)
1819 MScrollV(curr
, 1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1820 LScrollV(&curr
->w_layer
, 1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1821 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1827 if (curr
->w_y
== curr
->w_top
)
1829 MScrollV(curr
, -1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1830 LScrollV(&curr
->w_layer
, -1, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1831 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1833 else if (curr
->w_y
> 0)
1841 register int y
= curr
->w_y
, x
= curr
->w_x
;
1847 save_mline(&curr
->w_mlines
[y
], cols
);
1848 MScrollH(curr
, -n
, y
, x
, curr
->w_width
- 1, CURR_BCE
);
1849 LScrollH(&curr
->w_layer
, -n
, y
, x
, curr
->w_width
- 1, CURR_BCE
, &mline_old
);
1850 LGotoPos(&curr
->w_layer
, x
, y
);
1857 register int y
= curr
->w_y
, x
= curr
->w_x
;
1861 save_mline(&curr
->w_mlines
[y
], cols
);
1862 MScrollH(curr
, n
, y
, x
, curr
->w_width
- 1, CURR_BCE
);
1863 LScrollH(&curr
->w_layer
, n
, y
, x
, curr
->w_width
- 1, CURR_BCE
, &mline_old
);
1864 LGotoPos(&curr
->w_layer
, x
, y
);
1871 if (curr
->w_y
< curr
->w_top
|| curr
->w_y
> curr
->w_bot
)
1873 if (n
> curr
->w_bot
- curr
->w_y
+ 1)
1874 n
= curr
->w_bot
- curr
->w_y
+ 1;
1875 MScrollV(curr
, n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1876 LScrollV(&curr
->w_layer
, n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1877 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1884 if (curr
->w_y
< curr
->w_top
|| curr
->w_y
> curr
->w_bot
)
1886 if (n
> curr
->w_bot
- curr
->w_y
+ 1)
1887 n
= curr
->w_bot
- curr
->w_y
+ 1;
1888 MScrollV(curr
, -n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1889 LScrollV(&curr
->w_layer
, -n
, curr
->w_y
, curr
->w_bot
, CURR_BCE
);
1890 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1897 MScrollV(curr
, n
, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1898 LScrollV(&curr
->w_layer
, n
, curr
->w_top
, curr
->w_bot
, CURR_BCE
);
1899 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1906 register int x
= curr
->w_x
;
1913 if (curr
->w_tabs
[x
] && x
< cols
- 1)
1915 while (x
< cols
- 1 && !curr
->w_tabs
[x
])
1918 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1924 register int x
= curr
->w_x
;
1926 if (curr
->w_tabs
[x
] && x
> 0)
1928 while (x
> 0 && !curr
->w_tabs
[x
])
1931 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
1937 LClearArea(&curr
->w_layer
, 0, 0, curr
->w_width
- 1, curr
->w_height
- 1, CURR_BCE
, 1);
1939 MScrollV(curr
, curr
->w_height
, 0, curr
->w_height
- 1, CURR_BCE
);
1941 MClearArea(curr
, 0, 0, curr
->w_width
- 1, curr
->w_height
- 1, CURR_BCE
);
1948 register int y
= curr
->w_y
, x
= curr
->w_x
;
1950 LClearArea(&curr
->w_layer
, 0, 0, x
, y
, CURR_BCE
, 1);
1951 MClearArea(curr
, 0, 0, x
, y
, CURR_BCE
);
1952 RestorePosRendition();
1958 register int y
= curr
->w_y
, x
= curr
->w_x
;
1960 if (x
== 0 && y
== 0)
1963 RestorePosRendition();
1966 LClearArea(&curr
->w_layer
, x
, y
, cols
- 1, rows
- 1, CURR_BCE
, 1);
1967 MClearArea(curr
, x
, y
, cols
- 1, rows
- 1, CURR_BCE
);
1968 RestorePosRendition();
1972 ClearLineRegion(from
, to
)
1975 register int y
= curr
->w_y
;
1976 LClearArea(&curr
->w_layer
, from
, y
, to
, y
, CURR_BCE
, 1);
1977 MClearArea(curr
, from
, y
, to
, y
, CURR_BCE
);
1978 RestorePosRendition();
1985 register int x
= curr
->w_x
;
1992 if ((curr
->w_x
+= n
) >= cols
)
1993 curr
->w_x
= cols
- 1;
1994 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2001 if (curr
->w_y
< curr
->w_top
) /* if above scrolling rgn, */
2003 if ((curr
->w_y
-= n
) < 0) /* ignore its limits */
2007 if ((curr
->w_y
-= n
) < curr
->w_top
)
2008 curr
->w_y
= curr
->w_top
;
2009 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2016 if (curr
->w_y
> curr
->w_bot
) /* if below scrolling rgn, */
2018 if ((curr
->w_y
+= n
) > rows
- 1) /* ignore its limits */
2019 curr
->w_y
= rows
- 1;
2022 if ((curr
->w_y
+= n
) > curr
->w_bot
)
2023 curr
->w_y
= curr
->w_bot
;
2024 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2031 if ((curr
->w_x
-= n
) < 0)
2033 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2042 for (i
= 0; i
< curr
->w_NumArgs
; ++i
)
2044 switch (curr
->w_args
[i
])
2046 /* case 2: KAM: Lock keyboard */
2047 case 4: /* IRM: Insert mode */
2048 curr
->w_insert
= on
;
2049 LAY_DISPLAYS(&curr
->w_layer
, InsertMode(on
));
2051 /* case 12: SRM: Echo mode on */
2052 case 20: /* LNM: Linefeed mode */
2053 curr
->w_autolf
= on
;
2056 curr
->w_curvvis
= !on
;
2057 LCursorVisibility(&curr
->w_layer
, curr
->w_curinv
? -1 : curr
->w_curvvis
);
2065 static char rendlist
[] =
2067 ~((1 << NATTR
) - 1), A_BD
, A_DI
, A_SO
, A_US
, A_BL
, 0, A_RV
, 0, 0,
2068 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2069 0, 0, ~(A_BD
|A_SO
|A_DI
), ~A_SO
, ~A_US
, ~A_BL
, 0, ~A_RV
2076 register int j
, i
= 0, a
= curr
->w_rend
.attr
, c
= curr
->w_rend
.color
;
2078 int cx
= curr
->w_rend
.colorx
;
2081 register int j
, i
= 0, a
= curr
->w_rend
.attr
;
2086 j
= curr
->w_args
[i
];
2088 if ((j
== 38 || j
== 48) && i
+ 2 < curr
->w_NumArgs
&& curr
->w_args
[i
+ 1] == 5)
2093 jj
= curr
->w_args
[i
];
2094 if (jj
< 0 || jj
> 255)
2099 c
= (c
& 0xf0) | ((jj
& 0x0f) ^ 9);
2101 if (jj
>= 8 && jj
< 16)
2105 a
= (a
& 0xbf) | (jj
& 8 ? 0x40 : 0);
2106 cx
= (cx
& 0xf0) | (jj
>> 4 & 0x0f);
2110 c
= (c
& 0x0f) | ((jj
& 0x0f) ^ 9) << 4;
2112 if (jj
>= 8 && jj
< 16)
2116 cx
= (cx
& 0x0f) | (jj
& 0xf0);
2120 jj
= color256to16(jj
) + 30;
2123 j
= j
== 38 ? jj
: jj
+ 10;
2127 if (j
== 0 || (j
>= 30 && j
<= 39 && j
!= 38))
2129 if (j
== 0 || (j
>= 40 && j
<= 49 && j
!= 48))
2131 if (j
>= 90 && j
<= 97)
2133 if (j
>= 100 && j
<= 107)
2136 if (j
>= 90 && j
<= 97)
2138 if (j
>= 100 && j
<= 107)
2140 if (j
>= 30 && j
<= 39 && j
!= 38)
2141 c
= (c
& 0xf0) | ((j
- 30) ^ 9);
2142 else if (j
>= 40 && j
<= 49 && j
!= 48)
2143 c
= (c
& 0x0f) | (((j
- 40) ^ 9) << 4);
2147 if (j
== 0 || (j
>= 30 && j
<= 39 && j
!= 38))
2149 if (j
== 0 || (j
>= 40 && j
<= 49 && j
!= 48))
2153 if (j
< 0 || j
>= (int)(sizeof(rendlist
)/sizeof(*rendlist
)))
2156 if (j
& (1 << NATTR
))
2161 while (++i
< curr
->w_NumArgs
);
2162 curr
->w_rend
.attr
= a
;
2164 curr
->w_rend
.color
= c
;
2166 curr
->w_rend
.colorx
= cx
;
2169 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
2176 register unsigned char *p
, *ep
;
2178 LClearAll(&curr
->w_layer
, 1);
2179 curr
->w_y
= curr
->w_x
= 0;
2180 for (i
= 0; i
< rows
; ++i
)
2182 clear_mline(&curr
->w_mlines
[i
], 0, cols
+ 1);
2183 p
= curr
->w_mlines
[i
].image
;
2188 LRefreshAll(&curr
->w_layer
, 1);
2193 * Ugly autoaka hack support:
2194 * ChangeAKA() sets a new aka
2195 * FindAKA() searches for an autoaka match
2206 for (i
= 0; l
> 0; l
--)
2208 if (p
->w_akachange
+ i
== p
->w_akabuf
+ sizeof(p
->w_akabuf
) - 1)
2210 c
= (unsigned char)*s
++;
2213 if (c
< 32 || c
== 127 || (c
>= 128 && c
< 160 && p
->w_c1
))
2215 p
->w_akachange
[i
++] = c
;
2217 p
->w_akachange
[i
] = 0;
2218 p
->w_title
= p
->w_akachange
;
2219 if (p
->w_akachange
!= p
->w_akabuf
)
2220 if (p
->w_akachange
[0] == 0 || p
->w_akachange
[-1] == ':')
2221 p
->w_title
= p
->w_akabuf
+ strlen(p
->w_akabuf
) + 1;
2222 WindowChanged(p
, 't');
2223 WindowChanged((struct win
*)0, 'w');
2224 WindowChanged((struct win
*)0, 'W');
2230 register unsigned char *cp
, *line
;
2231 register struct win
*wp
= curr
;
2232 register int len
= strlen(wp
->w_akabuf
);
2235 y
= (wp
->w_autoaka
> 0 && wp
->w_autoaka
<= wp
->w_height
) ? wp
->w_autoaka
- 1 : wp
->w_y
;
2238 cp
= line
= wp
->w_mlines
[y
].image
;
2239 if (wp
->w_autoaka
> 0 && *wp
->w_akabuf
!= '\0')
2243 if (cp
- line
>= cols
- len
)
2245 if (++y
== wp
->w_autoaka
&& y
< rows
)
2249 if (strncmp((char *)cp
, wp
->w_akabuf
, len
) == 0)
2255 for (len
= cols
- (cp
- line
); len
&& *cp
== ' '; len
--, cp
++)
2259 if (wp
->w_autoaka
> 0 && (*cp
== '!' || *cp
== '%' || *cp
== '^'))
2264 while (len
&& *cp
!= ' ')
2270 ChangeAKA(wp
, (char *)line
, cp
- line
);
2277 RestorePosRendition()
2279 LGotoPos(&curr
->w_layer
, curr
->w_x
, curr
->w_y
);
2280 LSetRendition(&curr
->w_layer
, &curr
->w_rend
);
2283 /* Send a terminal report as if it were typed. */
2290 char rbuf
[40]; /* enough room for all replys */
2292 sprintf(rbuf
, fmt
, n1
, n2
);
2295 if ((unsigned)(curr
->w_inlen
+ len
) <= sizeof(curr
->w_inbuf
))
2297 bcopy(rbuf
, curr
->w_inbuf
+ curr
->w_inlen
, len
);
2298 curr
->w_inlen
+= len
;
2305 *====================================================================*
2306 *====================================================================*
2309 /**********************************************************************
2321 struct mline
*ml
= &p
->w_mlines
[y
];
2322 if (mc
->attr
&& ml
->attr
== null
)
2324 if ((ml
->attr
= (unsigned char *)malloc(p
->w_width
+ 1)) == 0)
2327 mc
->attr
= p
->w_rend
.attr
= 0;
2328 WMsg(p
, 0, "Warning: no space for attr - turned off");
2330 bzero((char *)ml
->attr
, p
->w_width
+ 1);
2333 if (mc
->font
&& ml
->font
== null
)
2335 if ((ml
->font
= (unsigned char *)malloc(p
->w_width
+ 1)) == 0)
2338 p
->w_FontL
= p
->w_charsets
[p
->w_ss
? p
->w_ss
: p
->w_Charset
] = 0;
2339 p
->w_FontR
= p
->w_charsets
[p
->w_ss
? p
->w_ss
: p
->w_CharsetR
] = 0;
2340 mc
->font
= p
->w_rend
.font
= 0;
2341 WMsg(p
, 0, "Warning: no space for font - turned off");
2343 bzero((char *)ml
->font
, p
->w_width
+ 1);
2347 if (mc
->color
&& ml
->color
== null
)
2349 if ((ml
->color
= (unsigned char *)malloc(p
->w_width
+ 1)) == 0)
2352 mc
->color
= p
->w_rend
.color
= 0;
2353 WMsg(p
, 0, "Warning: no space for color - turned off");
2355 bzero((char *)ml
->color
, p
->w_width
+ 1);
2358 if (mc
->colorx
&& ml
->colorx
== null
)
2360 if ((ml
->colorx
= (unsigned char *)malloc(p
->w_width
+ 1)) == 0)
2363 mc
->colorx
= p
->w_rend
.colorx
= 0;
2364 WMsg(p
, 0, "Warning: no space for extended colors - turned off");
2366 bzero((char *)ml
->colorx
, p
->w_width
+ 1);
2372 /*****************************************************************/
2375 # define MKillDwRight(p, ml, x) \
2376 if (dw_right(ml, x, p->w_encoding)) \
2379 copy_mchar2mline(&mchar_blank, ml, x - 1); \
2380 copy_mchar2mline(&mchar_blank, ml, x); \
2383 # define MKillDwLeft(p, ml, x) \
2384 if (dw_left(ml, x, p->w_encoding)) \
2386 copy_mchar2mline(&mchar_blank, ml, x); \
2387 copy_mchar2mline(&mchar_blank, ml, x + 1); \
2390 # define MKillDwRight(p, ml, x) ;
2391 # define MKillDwLeft(p, ml, x) ;
2395 MScrollH(p
, n
, y
, xs
, xe
, bce
)
2397 int n
, y
, xs
, xe
, bce
;
2403 ml
= &p
->w_mlines
[y
];
2404 MKillDwRight(p
, ml
, xs
);
2405 MKillDwLeft(p
, ml
, xe
);
2408 if (xe
- xs
+ 1 > n
)
2410 MKillDwRight(p
, ml
, xs
+ n
);
2411 bcopy_mline(ml
, xs
+ n
, xs
, xe
+ 1 - xs
- n
);
2415 clear_mline(ml
, xe
+ 1 - n
, n
);
2418 MBceLine(p
, y
, xe
+ 1 - n
, n
, bce
);
2424 if (xe
- xs
+ 1 > n
)
2426 MKillDwLeft(p
, ml
, xe
- n
);
2427 bcopy_mline(ml
, xs
, xs
+ n
, xe
+ 1 - xs
- n
);
2431 clear_mline(ml
, xs
, n
);
2434 MBceLine(p
, y
, xs
, n
, bce
);
2440 MScrollV(p
, n
, ys
, ye
, bce
)
2445 struct mline tmp
[256];
2454 MScrollV(p
, n
- 256, ys
, ye
, bce
);
2457 if (ye
- ys
+ 1 < n
)
2462 ye
= MFindUsedLine(p
, ye
, ys
);
2463 if (ye
- ys
+ 1 < n
)
2470 ml
= p
->w_mlines
+ ys
;
2471 for (i
= ys
; i
< ys
+ n
; i
++, ml
++)
2475 WAddLineToHist(p
, ml
);
2477 if (ml
->attr
!= null
)
2481 if (ml
->font
!= null
)
2486 if (ml
->color
!= null
)
2490 if (ml
->colorx
!= null
)
2495 bclear((char *)ml
->image
, p
->w_width
+ 1);
2498 MBceLine(p
, i
, 0, p
->w_width
, bce
);
2501 /* switch 'em over */
2502 cnt1
= n
* sizeof(struct mline
);
2503 cnt2
= (ye
- ys
+ 1 - n
) * sizeof(struct mline
);
2505 Scroll((char *)(p
->w_mlines
+ ys
), cnt1
, cnt2
, (char *)tmp
);
2511 MScrollV(p
, n
+ 256, ys
, ye
, bce
);
2515 if (ye
- ys
+ 1 < n
)
2518 ml
= p
->w_mlines
+ ye
;
2520 for (i
= ye
; i
> ye
- n
; i
--, ml
--)
2522 if (ml
->attr
!= null
)
2526 if (ml
->font
!= null
)
2531 if (ml
->color
!= null
)
2535 if (ml
->colorx
!= null
)
2540 bclear((char *)ml
->image
, p
->w_width
+ 1);
2543 MBceLine(p
, i
, 0, p
->w_width
, bce
);
2546 cnt1
= n
* sizeof(struct mline
);
2547 cnt2
= (ye
- ys
+ 1 - n
) * sizeof(struct mline
);
2549 Scroll((char *)(p
->w_mlines
+ ys
), cnt2
, cnt1
, (char *)tmp
);
2554 Scroll(cp
, cnt1
, cnt2
, tmp
)
2562 bcopy(cp
, tmp
, cnt1
);
2563 bcopy(cp
+ cnt1
, cp
, cnt2
);
2564 bcopy(tmp
, cp
+ cnt2
, cnt1
);
2568 bcopy(cp
+ cnt1
, tmp
, cnt2
);
2569 bcopy(cp
, cp
+ cnt2
, cnt1
);
2570 bcopy(tmp
, cp
, cnt2
);
2575 MClearArea(p
, xs
, ys
, xe
, ye
, bce
)
2577 int xs
, ys
, xe
, ye
, bce
;
2583 /* check for magic margin condition */
2584 if (xs
>= p
->w_width
)
2585 xs
= p
->w_width
- 1;
2586 if (xe
>= p
->w_width
)
2587 xe
= p
->w_width
- 1;
2589 MKillDwRight(p
, p
->w_mlines
+ ys
, xs
);
2590 MKillDwLeft(p
, p
->w_mlines
+ ye
, xe
);
2592 ml
= p
->w_mlines
+ ys
;
2593 for (y
= ys
; y
<= ye
; y
++, ml
++)
2595 xxe
= (y
== ye
) ? xe
: p
->w_width
- 1;
2598 clear_mline(ml
, xs
, n
);
2601 MBceLine(p
, y
, xs
, xs
+ n
- 1, bce
);
2608 MInsChar(p
, c
, x
, y
)
2616 ASSERT(x
>= 0 && x
< p
->w_width
);
2618 ml
= p
->w_mlines
+ y
;
2619 n
= p
->w_width
- x
- 1;
2620 MKillDwRight(p
, ml
, x
);
2623 MKillDwRight(p
, ml
, p
->w_width
- 1);
2624 bcopy_mline(ml
, x
, x
+ 1, n
);
2626 copy_mchar2mline(c
, ml
, x
);
2632 MKillDwRight(p
, ml
, p
->w_width
- 1);
2633 bcopy_mline(ml
, x
+ 1, x
+ 2, n
);
2635 copy_mchar2mline(c
, ml
, x
+ 1);
2636 ml
->image
[x
+ 1] = c
->mbcs
;
2638 if (p
->w_encoding
!= UTF8
)
2639 ml
->font
[x
+ 1] |= 0x80;
2640 else if (p
->w_encoding
== UTF8
&& c
->mbcs
)
2641 ml
->font
[x
+ 1] = c
->mbcs
;
2643 ml
->font
[x
+ 1] |= 0x80;
2650 MPutChar(p
, c
, x
, y
)
2658 ml
= &p
->w_mlines
[y
];
2659 MKillDwRight(p
, ml
, x
);
2660 MKillDwLeft(p
, ml
, x
);
2661 copy_mchar2mline(c
, ml
, x
);
2665 MKillDwLeft(p
, ml
, x
+ 1);
2666 copy_mchar2mline(c
, ml
, x
+ 1);
2667 ml
->image
[x
+ 1] = c
->mbcs
;
2669 if (p
->w_encoding
!= UTF8
)
2670 ml
->font
[x
+ 1] |= 0x80;
2671 else if (p
->w_encoding
== UTF8
&& c
->mbcs
)
2672 ml
->font
[x
+ 1] = c
->mbcs
;
2674 ml
->font
[x
+ 1] |= 0x80;
2682 MWrapChar(p
, c
, y
, top
, bot
, ins
)
2692 bce
= rend_getbg(c
);
2697 ml
= &p
->w_mlines
[y
];
2698 copy_mchar2mline(&mchar_null
, ml
, p
->w_width
);
2700 MScrollV(p
, 1, top
, bot
, bce
);
2701 else if (y
< p
->w_height
- 1)
2704 MInsChar(p
, c
, 0, y
);
2706 MPutChar(p
, c
, 0, y
);
2710 MPutStr(p
, s
, n
, r
, x
, y
)
2724 ml
= &p
->w_mlines
[y
];
2725 MKillDwRight(p
, ml
, x
);
2726 MKillDwLeft(p
, ml
, x
+ n
- 1);
2727 bcopy(s
, (char *)ml
->image
+ x
, n
);
2729 for (i
= n
; i
-- > 0;)
2733 for (i
= n
; i
-- > 0;)
2738 for (i
= n
; i
-- > 0;)
2742 for (i
= n
; i
-- > 0;)
2750 MBceLine(p
, y
, xs
, xe
, bce
)
2759 rend_setbg(&mc
, bce
);
2760 MFixLine(p
, y
, &mc
);
2761 ml
= p
->w_mlines
+ y
;
2764 for (x
= xs
; x
<= xe
; x
++)
2765 ml
->attr
[x
] = mc
.attr
;
2768 for (x
= xs
; x
<= xe
; x
++)
2769 ml
->color
[x
] = mc
.color
;
2772 for (x
= xs
; x
<= xe
; x
++)
2773 ml
->colorx
[x
] = mc
.colorx
;
2781 WAddLineToHist(wp
, ml
)
2785 register unsigned char *q
, *o
;
2788 if (wp
->w_histheight
== 0)
2790 hml
= &wp
->w_hlines
[wp
->w_histidx
];
2791 q
= ml
->image
; ml
->image
= hml
->image
; hml
->image
= q
;
2793 q
= ml
->attr
; o
= hml
->attr
; hml
->attr
= q
; ml
->attr
= null
;
2798 q
= ml
->font
; o
= hml
->font
; hml
->font
= q
; ml
->font
= null
;
2804 q
= ml
->color
; o
= hml
->color
; hml
->color
= q
; ml
->color
= null
;
2808 q
= ml
->colorx
; o
= hml
->colorx
; hml
->colorx
= q
; ml
->colorx
= null
;
2814 if (++wp
->w_histidx
>= wp
->w_histheight
)
2820 MFindUsedLine(p
, ye
, ys
)
2825 struct mline
*ml
= p
->w_mlines
+ ye
;
2827 debug2("MFindUsedLine: %d %d\n", ye
, ys
);
2828 for (y
= ye
; y
>= ys
; y
--, ml
--)
2830 if (bcmp((char*)ml
->image
, blank
, p
->w_width
))
2832 if (ml
->attr
!= null
&& bcmp((char*)ml
->attr
, null
, p
->w_width
))
2835 if (ml
->color
!= null
&& bcmp((char*)ml
->color
, null
, p
->w_width
))
2838 if (ml
->colorx
!= null
&& bcmp((char*)ml
->colorx
, null
, p
->w_width
))
2843 debug1("MFindUsedLine returning %d\n", y
);
2849 *====================================================================*
2850 *====================================================================*
2854 * Tricky: send only one bell even if the window is displayed
2863 for (display
= displays
; display
; display
= display
->d_next
)
2865 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2866 if (cv
->c_layer
->l_bottom
== &p
->w_layer
)
2870 else if (cv
&& D_VB
)
2873 p
->w_bell
= visual
? BELL_VISUAL
: BELL_FOUND
;
2878 * This should be reverse video.
2879 * Only change video if window is fore.
2880 * Because it is used in some termcaps to emulate
2881 * a visual bell we do this hack here.
2882 * (screen uses \Eg as special vbell sequence)
2885 WReverseVideo(p
, on
)
2890 for (cv
= p
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
2892 display
= cv
->c_display
;
2896 if (!on
&& p
->w_revvid
&& !D_CVR
)
2901 p
->w_bell
= BELL_VISUAL
;
2912 extern struct layer
*flayer
;
2913 struct layer
*oldflayer
= flayer
;
2914 flayer
= &p
->w_layer
;
2920 WChangeSize(p
, w
, h
)
2927 if (p
->w_layer
.l_cvlist
== 0)
2929 /* window not displayed -> works always */
2930 ChangeWindowSize(p
, w
, h
, p
->w_histheight
);
2933 for (cv
= p
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
2935 display
= cv
->c_display
;
2937 continue; /* change only fore */
2940 if (D_CZ0
&& (w
== Z0width
|| w
== Z1width
))
2943 if (cv
== 0 && wok
== 0) /* can't change any display */
2947 ChangeWindowSize(p
, w
, h
, p
->w_histheight
);
2948 for (display
= displays
; display
; display
= display
->d_next
)
2952 if (D_cvlist
&& D_cvlist
->c_next
== 0)
2953 ResizeDisplay(w
, h
);
2955 ResizeDisplay(w
, D_height
);
2956 ResizeLayersToCanvases(); /* XXX Hmm ? */
2959 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2960 if (cv
->c_layer
->l_bottom
== &p
->w_layer
)
2968 WindowChangedCheck(s
, what
, hp
)
2977 if (*s
++ != (hp
? '%' : '\005'))
2982 while (*s
>= '0' && *s
<= '9')
2991 if (*s
== what
|| ((*s
| l
) == what
) || what
== 'd')
3002 WindowChanged(p
, what
)
3006 int inwstr
, inhstr
, inlstr
;
3007 int inwstrh
= 0, inhstrh
= 0, inlstrh
= 0;
3009 struct display
*olddisplay
= display
;
3012 inwstr
= inhstr
= 0;
3016 WindowChanged((struct win
*)0, 'w'|0x100);
3017 WindowChanged((struct win
*)0, 'W'|0x100);
3022 inwstr
= WindowChangedCheck(captionstring
, what
, &inwstrh
);
3023 inhstr
= WindowChangedCheck(hstatusstring
, what
, &inhstrh
);
3024 inlstr
= WindowChangedCheck(wliststr
, what
, &inlstrh
);
3028 inwstr
= inhstr
= 0;
3034 for (display
= displays
; display
; display
= display
->d_next
)
3038 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
3040 if (inlstr
|| (inlstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3041 WListUpdatecv(cv
, (struct win
*)0);
3042 p
= Layer2Window(cv
->c_layer
);
3043 if (inwstr
|| (inwstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3044 if (cv
->c_ye
+ 1 < D_height
)
3045 RefreshLine(cv
->c_ye
+ 1, 0, D_width
- 1, 0);
3048 if (inhstr
|| (inhstrh
&& p
&& p
->w_hstatus
&& *p
->w_hstatus
&& WindowChangedCheck(p
->w_hstatus
, what
, (int *)0)))
3050 if (ox
!= -1 && ox
!= -1)
3053 display
= olddisplay
;
3057 if (p
->w_hstatus
&& *p
->w_hstatus
&& (inwstrh
|| inhstrh
|| inlstrh
) && WindowChangedCheck(p
->w_hstatus
, what
, (int *)0))
3063 if (!inwstr
&& !inhstr
&& !inlstr
)
3065 for (display
= displays
; display
; display
= display
->d_next
)
3070 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
3073 WListUpdatecv(cv
, p
);
3074 if (Layer2Window(cv
->c_layer
) != p
)
3077 if (inwstr
&& cv
->c_ye
+ 1 < D_height
)
3078 RefreshLine(cv
->c_ye
+ 1, 0, D_width
- 1, 0);
3080 if (got
&& inhstr
&& p
== D_fore
)
3082 if (ox
!= -1 && ox
!= -1)
3085 display
= olddisplay
;