2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
4 * Copyright (c) 2008, 2009
5 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
6 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
7 * Micah Cowan (micah@cowan.name)
8 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
9 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
10 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
11 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
12 * Copyright (c) 1987 Oliver Laumann
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program (see the file COPYING); if not, see
26 * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
29 ****************************************************************
34 #include <sys/types.h>
38 #if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
43 #include <sys/ioctl.h>
47 /* for solaris 2.1, Unixware (SVR4.2) and possibly others: */
49 # include <sys/stropts.h>
57 #include "list_generic.h"
59 extern struct comm comms
[];
61 extern char *RcFileName
, *home
;
62 extern char *BellString
, *ActivityString
, *ShellProg
, *ShellArgs
[];
63 extern char *hstatusstring
, *captionstring
, *timestring
;
64 extern char *wliststr
, *wlisttit
;
65 extern int captionalways
;
67 extern char *hardcopydir
, *screenlogfile
, *logtstamp_string
;
68 extern int log_flush
, logtstamp_on
, logtstamp_after
;
69 extern char *VisualBellString
;
70 extern int VBellWait
, MsgWait
, MsgMinWait
, SilenceWait
;
71 extern char SockPath
[], *SockName
;
72 extern int TtyMode
, auto_detach
, use_altscreen
;
73 extern int iflag
, maxwin
;
74 extern int focusminwidth
, focusminheight
;
75 extern int use_hardstatus
, visual_bell
;
77 extern int attr2color
[][4];
78 extern int nattr2color
;
80 extern int hardstatusemu
;
81 extern char *printcmd
;
82 extern int default_startup
;
83 extern int defobuflimit
;
84 extern int defnonblock
;
85 extern int defmousetrack
;
86 extern int ZombieKey_destroy
;
87 extern int ZombieKey_resurrect
;
88 extern int ZombieKey_onerror
;
90 extern int defautonuke
;
92 extern int separate_sids
;
93 extern struct NewWindow nwin_default
, nwin_undef
;
95 extern int join_with_cr
;
96 extern int compacthist
;
101 extern unsigned char mark_key_tab
[];
102 extern char *BufferFile
;
105 extern char *BufferFile
, *PowDetachString
;
108 extern struct acluser
*EffectiveAclUser
; /* acl.c */
110 extern struct term term
[]; /* terminal capabilities */
112 extern char *kmapdef
[];
113 extern char *kmapadef
[];
114 extern char *kmapmdef
[];
116 extern struct mchar mchar_so
, mchar_null
;
117 extern int renditions
[];
118 extern int VerboseCreate
;
120 extern char *screenencodings
;
126 static int CheckArgNum
__P((int, char **));
127 static void ClearAction
__P((struct action
*));
128 static void SaveAction
__P((struct action
*, int, char **, int *));
129 static int NextWindow
__P((void));
130 static int PreviousWindow
__P((void));
131 static int MoreWindows
__P((void));
132 static void LogToggle
__P((int));
133 static void ShowInfo
__P((void));
134 static void ShowDInfo
__P((void));
135 static struct win
*WindowByName
__P((char *));
136 static int WindowByNumber
__P((char *));
137 static int ParseOnOff
__P((struct action
*, int *));
138 static int ParseWinNum
__P((struct action
*, int *));
139 static int ParseBase
__P((struct action
*, char *, int *, int, char *));
140 static int ParseNum1000
__P((struct action
*, int *));
141 static char **SaveArgs
__P((char **));
142 static int IsNum
__P((char *, int));
143 static void Colonfin
__P((char *, int, char *));
144 static void InputSelect
__P((void));
145 static void InputSetenv
__P((char *));
146 static void InputAKA
__P((void));
148 static int InputSu
__P((struct win
*, struct acluser
**, char *));
149 static void su_fin
__P((char *, int, char *));
151 static void AKAfin
__P((char *, int, char *));
153 static void copy_reg_fn
__P((char *, int, char *));
154 static void ins_reg_fn
__P((char *, int, char *));
156 static void process_fn
__P((char *, int, char *));
158 static void pass1
__P((char *, int, char *));
159 static void pass2
__P((char *, int, char *));
162 static void pow_detach_fn
__P((char *, int, char *));
164 static void digraph_fn
__P((char *, int, char *));
165 static int digraph_find
__P((const char *buf
));
166 static void confirm_fn
__P((char *, int, char *));
167 static int IsOnDisplay
__P((struct win
*));
168 static void ResizeRegions
__P((char *, int));
169 static void ResizeFin
__P((char *, int, char *));
170 static struct action
*FindKtab
__P((char *, int));
171 static void SelectFin
__P((char *, int, char *));
172 static void SelectLayoutFin
__P((char *, int, char *));
175 extern struct layer
*flayer
;
176 extern struct display
*display
, *displays
;
177 extern struct win
*fore
, *console_window
, *windows
;
178 extern struct acluser
*users
;
179 extern struct layout
*layouts
, *layout_attach
, layout_last_marker
;
180 extern struct layout
*laytab
[];
182 extern char screenterm
[], HostName
[], version
[];
183 extern struct NewWindow nwin_undef
, nwin_default
;
184 extern struct LayFuncs WinLf
, MarkLf
;
186 extern int Z0width
, Z1width
;
187 extern int real_uid
, real_gid
;
190 extern int nethackflag
;
194 extern struct win
**wtab
;
198 extern int maxusercount
;
202 struct plop plop_tab
[MAX_PLOP_DEFS
];
205 # define PTYMODE 0622
208 int TtyMode
= PTYMODE
;
209 int hardcopy_append
= 0;
210 int all_norefresh
= 0;
213 char *zmodem_sendcmd
;
214 char *zmodem_recvcmd
;
215 static char *zmodes
[4] = {"off", "auto", "catch", "pass"};
219 struct action idleaction
;
224 struct action ktab
[256 + KMAP_KEYS
]; /* command key translation table */
228 struct action ktab
[256 + KMAP_KEYS
];
230 struct kclass
*kclasses
;
233 struct action umtab
[KMAP_KEYS
+KMAP_AKEYS
];
234 struct action dmtab
[KMAP_KEYS
+KMAP_AKEYS
];
235 struct action mmtab
[KMAP_KEYS
+KMAP_AKEYS
];
236 struct kmap_ext
*kmap_exts
;
238 static int maptimeout
= 300;
242 #define MAX_DIGRAPH 512
251 /* digraph table taken from old vim and rfc1345 */
252 static struct digraph digraphs
[MAX_DIGRAPH
+ 1] = {
253 {' ', ' ', 160}, /* */
254 {'N', 'S', 160}, /* */
255 {'~', '!', 161}, /* ¡ */
256 {'!', '!', 161}, /* ¡ */
257 {'!', 'I', 161}, /* ¡ */
258 {'c', '|', 162}, /* ¢ */
259 {'c', 't', 162}, /* ¢ */
260 {'$', '$', 163}, /* £ */
261 {'P', 'd', 163}, /* £ */
262 {'o', 'x', 164}, /* ¤ */
263 {'C', 'u', 164}, /* ¤ */
264 {'C', 'u', 164}, /* ¤ */
265 {'E', 'u', 164}, /* ¤ */
266 {'Y', '-', 165}, /* ¥ */
267 {'Y', 'e', 165}, /* ¥ */
268 {'|', '|', 166}, /* ¦ */
269 {'B', 'B', 166}, /* ¦ */
270 {'p', 'a', 167}, /* § */
271 {'S', 'E', 167}, /* § */
272 {'"', '"', 168}, /* ¨ */
273 {'\'', ':', 168}, /* ¨ */
274 {'c', 'O', 169}, /* © */
275 {'C', 'o', 169}, /* © */
276 {'a', '-', 170}, /* ª */
277 {'<', '<', 171}, /* « */
278 {'-', ',', 172}, /* ¬ */
279 {'N', 'O', 172}, /* ¬ */
280 {'-', '-', 173}, /* */
281 {'r', 'O', 174}, /* ® */
282 {'R', 'g', 174}, /* ® */
283 {'-', '=', 175}, /* ¯ */
284 {'\'', 'm', 175}, /* ¯ */
285 {'~', 'o', 176}, /* ° */
286 {'D', 'G', 176}, /* ° */
287 {'+', '-', 177}, /* ± */
288 {'2', '2', 178}, /* ² */
289 {'2', 'S', 178}, /* ² */
290 {'3', '3', 179}, /* ³ */
291 {'3', 'S', 179}, /* ³ */
292 {'\'', '\'', 180}, /* ´ */
293 {'j', 'u', 181}, /* µ */
294 {'M', 'y', 181}, /* µ */
295 {'p', 'p', 182}, /* ¶ */
296 {'P', 'I', 182}, /* ¶ */
297 {'~', '.', 183}, /* · */
298 {'.', 'M', 183}, /* · */
299 {',', ',', 184}, /* ¸ */
300 {'\'', ',', 184}, /* ¸ */
301 {'1', '1', 185}, /* ¹ */
302 {'1', 'S', 185}, /* ¹ */
303 {'o', '-', 186}, /* º */
304 {'>', '>', 187}, /* » */
305 {'1', '4', 188}, /* ¼ */
306 {'1', '2', 189}, /* ½ */
307 {'3', '4', 190}, /* ¾ */
308 {'~', '?', 191}, /* ¿ */
309 {'?', '?', 191}, /* ¿ */
310 {'?', 'I', 191}, /* ¿ */
311 {'A', '`', 192}, /* À */
312 {'A', '!', 192}, /* À */
313 {'A', '\'', 193}, /* Á */
314 {'A', '^', 194}, /* Â */
315 {'A', '>', 194}, /* Â */
316 {'A', '~', 195}, /* Ã */
317 {'A', '?', 195}, /* Ã */
318 {'A', '"', 196}, /* Ä */
319 {'A', ':', 196}, /* Ä */
320 {'A', '@', 197}, /* Å */
321 {'A', 'A', 197}, /* Å */
322 {'A', 'E', 198}, /* Æ */
323 {'C', ',', 199}, /* Ç */
324 {'E', '`', 200}, /* È */
325 {'E', '!', 200}, /* È */
326 {'E', '\'', 201}, /* É */
327 {'E', '^', 202}, /* Ê */
328 {'E', '>', 202}, /* Ê */
329 {'E', '"', 203}, /* Ë */
330 {'E', ':', 203}, /* Ë */
331 {'I', '`', 204}, /* Ì */
332 {'I', '!', 204}, /* Ì */
333 {'I', '\'', 205}, /* Í */
334 {'I', '^', 206}, /* Î */
335 {'I', '>', 206}, /* Î */
336 {'I', '"', 207}, /* Ï */
337 {'I', ':', 207}, /* Ï */
338 {'D', '-', 208}, /* Ð */
339 {'N', '~', 209}, /* Ñ */
340 {'N', '?', 209}, /* Ñ */
341 {'O', '`', 210}, /* Ò */
342 {'O', '!', 210}, /* Ò */
343 {'O', '\'', 211}, /* Ó */
344 {'O', '^', 212}, /* Ô */
345 {'O', '>', 212}, /* Ô */
346 {'O', '~', 213}, /* Õ */
347 {'O', '?', 213}, /* Õ */
348 {'O', '"', 214}, /* Ö */
349 {'O', ':', 214}, /* Ö */
350 {'/', '\\', 215}, /* × */
351 {'*', 'x', 215}, /* × */
352 {'O', '/', 216}, /* Ø */
353 {'U', '`', 217}, /* Ù */
354 {'U', '!', 217}, /* Ù */
355 {'U', '\'', 218}, /* Ú */
356 {'U', '^', 219}, /* Û */
357 {'U', '>', 219}, /* Û */
358 {'U', '"', 220}, /* Ü */
359 {'U', ':', 220}, /* Ü */
360 {'Y', '\'', 221}, /* Ý */
361 {'I', 'p', 222}, /* Þ */
362 {'T', 'H', 222}, /* Þ */
363 {'s', 's', 223}, /* ß */
364 {'s', '"', 223}, /* ß */
365 {'a', '`', 224}, /* à */
366 {'a', '!', 224}, /* à */
367 {'a', '\'', 225}, /* á */
368 {'a', '^', 226}, /* â */
369 {'a', '>', 226}, /* â */
370 {'a', '~', 227}, /* ã */
371 {'a', '?', 227}, /* ã */
372 {'a', '"', 228}, /* ä */
373 {'a', ':', 228}, /* ä */
374 {'a', 'a', 229}, /* å */
375 {'a', 'e', 230}, /* æ */
376 {'c', ',', 231}, /* ç */
377 {'e', '`', 232}, /* è */
378 {'e', '!', 232}, /* è */
379 {'e', '\'', 233}, /* é */
380 {'e', '^', 234}, /* ê */
381 {'e', '>', 234}, /* ê */
382 {'e', '"', 235}, /* ë */
383 {'e', ':', 235}, /* ë */
384 {'i', '`', 236}, /* ì */
385 {'i', '!', 236}, /* ì */
386 {'i', '\'', 237}, /* í */
387 {'i', '^', 238}, /* î */
388 {'i', '>', 238}, /* î */
389 {'i', '"', 239}, /* ï */
390 {'i', ':', 239}, /* ï */
391 {'d', '-', 240}, /* ð */
392 {'n', '~', 241}, /* ñ */
393 {'n', '?', 241}, /* ñ */
394 {'o', '`', 242}, /* ò */
395 {'o', '!', 242}, /* ò */
396 {'o', '\'', 243}, /* ó */
397 {'o', '^', 244}, /* ô */
398 {'o', '>', 244}, /* ô */
399 {'o', '~', 245}, /* õ */
400 {'o', '?', 245}, /* õ */
401 {'o', '"', 246}, /* ö */
402 {'o', ':', 246}, /* ö */
403 {':', '-', 247}, /* ÷ */
404 {'o', '/', 248}, /* ø */
405 {'u', '`', 249}, /* ù */
406 {'u', '!', 249}, /* ù */
407 {'u', '\'', 250}, /* ú */
408 {'u', '^', 251}, /* û */
409 {'u', '>', 251}, /* û */
410 {'u', '"', 252}, /* ü */
411 {'u', ':', 252}, /* ü */
412 {'y', '\'', 253}, /* ý */
413 {'i', 'p', 254}, /* þ */
414 {'t', 'h', 254}, /* þ */
415 {'y', '"', 255}, /* ÿ */
416 {'y', ':', 255}, /* ÿ */
417 {'"', '[', 196}, /* Ä */
418 {'"', '\\', 214}, /* Ö */
419 {'"', ']', 220}, /* Ü */
420 {'"', '{', 228}, /* ä */
421 {'"', '|', 246}, /* ö */
422 {'"', '}', 252}, /* ü */
423 {'"', '~', 223} /* ß */
426 #define RESIZE_FLAG_H 1
427 #define RESIZE_FLAG_V 2
428 #define RESIZE_FLAG_L 4
430 static char *resizeprompts
[] = {
432 "resize -h # lines: ",
433 "resize -v # lines: ",
434 "resize -b # lines: ",
435 "resize -l # lines: ",
436 "resize -l -h # lines: ",
437 "resize -l -v # lines: ",
438 "resize -l -b # lines: ",
442 parse_input_int(buf
, len
, val
)
448 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
451 for (i
= 2; i
< len
; i
++)
453 if (buf
[i
] >= '0' && buf
[i
] <= '9')
454 x
= x
* 16 | (buf
[i
] - '0');
455 else if (buf
[i
] >= 'a' && buf
[i
] <= 'f')
456 x
= x
* 16 | (buf
[i
] - ('a' - 10));
457 else if (buf
[i
] >= 'A' && buf
[i
] <= 'F')
458 x
= x
* 16 | (buf
[i
] - ('A' - 10));
463 else if (buf
[0] == '0')
466 for (i
= 1; i
< len
; i
++)
468 if (buf
[i
] < '0' || buf
[i
] > '7')
470 x
= x
* 8 | (buf
[i
] - '0');
484 register unsigned int i
;
489 for (i
= 0; i
< sizeof(ktab
)/sizeof(*ktab
); i
++)
491 ktab
[i
].nr
= RC_ILLEGAL
;
492 ktab
[i
].args
= noargs
;
496 for (i
= 0; i
< KMAP_KEYS
+KMAP_AKEYS
; i
++)
498 umtab
[i
].nr
= RC_ILLEGAL
;
499 umtab
[i
].args
= noargs
;
501 dmtab
[i
].nr
= RC_ILLEGAL
;
502 dmtab
[i
].args
= noargs
;
504 mmtab
[i
].nr
= RC_ILLEGAL
;
505 mmtab
[i
].args
= noargs
;
509 for (i
= 0; i
< NKMAPDEF
; i
++)
511 if (i
+ KMAPDEFSTART
< T_CAPS
)
513 if (i
+ KMAPDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
517 argarr
[0] = kmapdef
[i
];
518 SaveAction(dmtab
+ i
+ (KMAPDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
520 for (i
= 0; i
< NKMAPADEF
; i
++)
522 if (i
+ KMAPADEFSTART
< T_CURSOR
)
524 if (i
+ KMAPADEFSTART
>= T_CURSOR
+ KMAP_AKEYS
)
526 if (kmapadef
[i
] == 0)
528 argarr
[0] = kmapadef
[i
];
529 SaveAction(dmtab
+ i
+ (KMAPADEFSTART
- T_CURSOR
+ KMAP_KEYS
), RC_STUFF
, argarr
, 0);
531 for (i
= 0; i
< NKMAPMDEF
; i
++)
533 if (i
+ KMAPMDEFSTART
< T_CAPS
)
535 if (i
+ KMAPMDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
537 if (kmapmdef
[i
] == 0)
539 argarr
[0] = kmapmdef
[i
];
541 SaveAction(mmtab
+ i
+ (KMAPMDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
545 ktab
['h'].nr
= RC_HARDCOPY
;
547 ktab
['z'].nr
= ktab
[Ctrl('z')].nr
= RC_SUSPEND
;
549 ktab
['c'].nr
= ktab
[Ctrl('c')].nr
= RC_SCREEN
;
550 ktab
[' '].nr
= ktab
[Ctrl(' ')].nr
=
551 ktab
['n'].nr
= ktab
[Ctrl('n')].nr
= RC_NEXT
;
552 ktab
['N'].nr
= RC_NUMBER
;
553 ktab
[Ctrl('h')].nr
= ktab
[0177].nr
= ktab
['p'].nr
= ktab
[Ctrl('p')].nr
= RC_PREV
;
554 ktab
['k'].nr
= ktab
[Ctrl('k')].nr
= RC_KILL
;
555 ktab
['l'].nr
= ktab
[Ctrl('l')].nr
= RC_REDISPLAY
;
556 ktab
['w'].nr
= ktab
[Ctrl('w')].nr
= RC_WINDOWS
;
557 ktab
['v'].nr
= RC_VERSION
;
558 ktab
[Ctrl('v')].nr
= RC_DIGRAPH
;
559 ktab
['q'].nr
= ktab
[Ctrl('q')].nr
= RC_XON
;
560 ktab
['s'].nr
= ktab
[Ctrl('s')].nr
= RC_XOFF
;
561 ktab
['t'].nr
= ktab
[Ctrl('t')].nr
= RC_TIME
;
562 ktab
['i'].nr
= ktab
[Ctrl('i')].nr
= RC_INFO
;
563 ktab
['m'].nr
= ktab
[Ctrl('m')].nr
= RC_LASTMSG
;
564 ktab
['A'].nr
= RC_TITLE
;
565 #if defined(UTMPOK) && defined(LOGOUTOK)
566 ktab
['L'].nr
= RC_LOGIN
;
568 ktab
[','].nr
= RC_LICENSE
;
569 ktab
['W'].nr
= RC_WIDTH
;
570 ktab
['.'].nr
= RC_DUMPTERMCAP
;
571 ktab
[Ctrl('\\')].nr
= RC_QUIT
;
573 ktab
['d'].nr
= ktab
[Ctrl('d')].nr
= RC_DETACH
;
575 ktab
['D'].nr
= RC_POW_DETACH
;
578 ktab
['r'].nr
= ktab
[Ctrl('r')].nr
= RC_WRAP
;
579 ktab
['f'].nr
= ktab
[Ctrl('f')].nr
= RC_FLOW
;
580 ktab
['C'].nr
= RC_CLEAR
;
581 ktab
['Z'].nr
= RC_RESET
;
582 ktab
['H'].nr
= RC_LOG
;
583 ktab
['M'].nr
= RC_MONITOR
;
584 ktab
['?'].nr
= RC_HELP
;
586 ktab
['*'].nr
= RC_DISPLAYS
;
592 SaveAction(ktab
+ '-', RC_SELECT
, args
, 0);
594 for (i
= 0; i
< ((maxwin
&& maxwin
< 10) ? maxwin
: 10); i
++)
596 char *args
[2], arg1
[10];
599 sprintf(arg1
, "%d", i
);
600 SaveAction(ktab
+ '0' + i
, RC_SELECT
, args
, 0);
602 ktab
['\''].nr
= RC_SELECT
; /* calling a window by name */
607 SaveAction(ktab
+ '"', RC_WINDOWLIST
, args
, 0);
609 ktab
[Ctrl('G')].nr
= RC_VBELL
;
610 ktab
[':'].nr
= RC_COLON
;
612 ktab
['['].nr
= ktab
[Ctrl('[')].nr
= RC_COPY
;
617 SaveAction(ktab
+ ']', RC_PASTE
, args
, 0);
618 SaveAction(ktab
+ Ctrl(']'), RC_PASTE
, args
, 0);
620 ktab
['{'].nr
= RC_HISTORY
;
621 ktab
['}'].nr
= RC_HISTORY
;
622 ktab
['>'].nr
= RC_WRITEBUF
;
623 ktab
['<'].nr
= RC_READBUF
;
624 ktab
['='].nr
= RC_REMOVEBUF
;
627 ktab
['D'].nr
= RC_POW_DETACH
;
630 ktab
['x'].nr
= ktab
[Ctrl('x')].nr
= RC_LOCKSCREEN
;
632 ktab
['b'].nr
= ktab
[Ctrl('b')].nr
= RC_BREAK
;
633 ktab
['B'].nr
= RC_POW_BREAK
;
634 ktab
['_'].nr
= RC_SILENCE
;
635 ktab
['S'].nr
= RC_SPLIT
;
636 ktab
['Q'].nr
= RC_ONLY
;
637 ktab
['X'].nr
= RC_REMOVE
;
638 ktab
['F'].nr
= RC_FIT
;
639 ktab
['\t'].nr
= RC_FOCUS
;
644 SaveAction(ktab
+ T_BACKTAB
- T_CAPS
+ 256, RC_FOCUS
, args
, 0);
650 SaveAction(ktab
+ '|', RC_SPLIT
, args
, 0);
652 /* These come last; they may want overwrite others: */
655 ClearAction(&ktab
[DefaultEsc
]);
656 ktab
[DefaultEsc
].nr
= RC_OTHER
;
658 if (DefaultMetaEsc
>= 0)
660 ClearAction(&ktab
[DefaultMetaEsc
]);
661 ktab
[DefaultMetaEsc
].nr
= RC_META
;
664 idleaction
.nr
= RC_BLANKER
;
665 idleaction
.args
= noargs
;
669 static struct action
*
670 FindKtab(class, create
)
674 struct kclass
*kp
, **kpp
;
679 for (kpp
= &kclasses
; (kp
= *kpp
) != 0; kpp
= &kp
->next
)
680 if (!strcmp(kp
->name
, class))
686 if (strlen(class) > 80)
688 Msg(0, "Command class name too long.");
691 kp
= malloc(sizeof(*kp
));
694 Msg(0, "%s", strnomem
);
697 kp
->name
= SaveStr(class);
698 for (i
= 0; i
< (int)(sizeof(kp
->ktab
)/sizeof(*kp
->ktab
)); i
++)
700 kp
->ktab
[i
].nr
= RC_ILLEGAL
;
701 kp
->ktab
[i
].args
= noargs
;
702 kp
->ktab
[i
].argl
= 0;
703 kp
->ktab
[i
].quiet
= 0;
717 if (act
->nr
== RC_ILLEGAL
)
719 act
->nr
= RC_ILLEGAL
;
720 if (act
->args
== noargs
)
722 for (p
= act
->args
; *p
; p
++)
724 free((char *)act
->args
);
730 * ProcessInput: process input from display and feed it into
731 * the layer on canvas D_forecv.
737 * This ProcessInput just does the keybindings and passes
738 * everything else on to ProcessInput2.
742 ProcessInput(ibuf
, ilen
)
747 unsigned char *s
, *q
;
751 debug1("ProcessInput: %d bytes\n", ilen
);
752 if (display
== 0 || ilen
== 0)
757 s
= (unsigned char *)ibuf
;
761 if (D_dontmap
|| !D_nseqs
)
768 debug3("cmp %c %c[%d]\n", ch
, *D_seqp
, D_seqp
- D_kmaps
);
771 l
= D_seqp
[D_seqp
[-D_seql
-1] + 1];
775 debug1("miss %d\n", D_seqp
- D_kmaps
);
778 debug("complete miss\n");
781 p
= (char *)D_seqp
- l
;
783 D_seqp
= D_kmaps
+ 3;
786 if ((q
= D_seqh
) != 0)
789 i
= q
[0] << 8 | q
[1];
790 i
&= ~KMAP_NOTIMEOUT
;
791 debug1("Mapping former hit #%d - ", i
);
792 debug2("%d(%s) - ", q
[2], q
+ 3);
794 ProcessInput2((char *)q
+ 3, q
[2]);
802 debug1("flush old %d\n", l
);
811 /* Finish old stuff */
813 debug1("finish old %d\n", slen
);
815 ProcessInput2(ibuf
, slen
);
824 debug2("length am %d, want %d\n", l
, D_seqp
[-l
- 1]);
825 if (l
== D_seqp
[-l
- 1])
830 if (D_kmaps
+ D_nseqs
> q
&& q
[2] > l
&& !bcmp(D_seqp
- l
, q
+ 3, l
))
832 debug1("have another mapping (%s), delay execution\n", q
+ 3);
833 D_seqh
= D_seqp
- 3 - l
;
838 i
= D_seqp
[-l
- 3] << 8 | D_seqp
[-l
- 2];
839 i
&= ~KMAP_NOTIMEOUT
;
840 debug1("Mapping #%d - ", i
);
841 p
= (char *)D_seqp
- l
;
842 debug2("%d(%s) - ", l
, p
);
844 D_seqp
= D_kmaps
+ 3;
856 debug("am in sequence -> check for timeout\n");
858 for (s
= D_seqp
; ; s
+= i
* 2 + 4)
860 if (s
[-l
-3] & KMAP_NOTIMEOUT
>> 8)
862 if ((i
= s
[s
[-l
-1] + 1]) == 0)
864 SetTimeout(&D_mapev
, maptimeout
);
870 ProcessInput2(ibuf
, slen
);
874 # define ProcessInput2 ProcessInput
879 * Here only the screen escape commands are handled.
883 ProcessInput2(ibuf
, ilen
)
889 struct action
*ktabp
;
891 debug1("ProcessInput2: %d bytes\n", ilen
);
892 while (ilen
&& display
)
894 debug1(" - ilen now %d bytes\n", ilen
);
895 flayer
= D_forecv
->c_layer
;
903 if ((unsigned char)*s
++ == D_user
->u_Esc
)
909 DoProcess(fore
, &ibuf
, &slen
, 0);
915 ktabp
= D_ESCseen
? D_ESCseen
: ktab
;
917 ch
= (unsigned char)*s
;
920 * As users have different esc characters, but a common ktab[],
921 * we fold back the users esc and meta-esc key to the Default keys
922 * that can be looked up in the ktab[]. grmbl. jw.
923 * XXX: make ktab[] a per user thing.
925 if (ch
== D_user
->u_Esc
)
927 else if (ch
== D_user
->u_MetaEsc
)
931 DoAction(&ktabp
[ch
], ch
);
932 ibuf
= (char *)(s
+ 1);
938 DoProcess(p
, bufp
, lenp
, pa
)
945 struct display
*d
= display
;
948 /* XXX -> PasteStart */
949 if (pa
&& *lenp
> 1 && p
&& p
->w_slowpaste
)
951 /* schedule slowpaste event */
952 SetTimeout(&p
->w_paster
.pa_slowev
, p
->w_slowpaste
);
953 evenq(&p
->w_paster
.pa_slowev
);
957 while (flayer
&& *lenp
)
960 if (!pa
&& p
&& p
->w_paster
.pa_pastelen
&& flayer
== p
->w_paster
.pa_pastelayer
)
962 debug("layer is busy - beep!\n");
963 WBell(p
, visual_bell
);
971 LayProcess(bufp
, lenp
);
973 if (pa
&& !pa
->pa_pastelayer
)
974 break; /* flush rest of paste */
983 /* We're full, let's beep */
984 debug("layer is full - beep!\n");
985 WBell(p
, visual_bell
);
993 if (pa
&& pa
->pa_pastelen
== 0)
1002 int x
, m
, l
= 0, r
= RC_LAST
;
1006 x
= strcmp(str
, comms
[m
].name
);
1018 CheckArgNum(nr
, args
)
1023 static char *argss
[] = {"no", "one", "two", "three", "four", "OOPS"};
1024 static char *orformat
[] =
1026 "%s: %s: %s argument%s required",
1027 "%s: %s: %s or %s argument%s required",
1028 "%s: %s: %s, %s or %s argument%s required",
1029 "%s: %s: %s, %s, %s or %s argument%s required"
1032 n
= comms
[nr
].flags
& ARGS_MASK
;
1033 for (i
= 0; args
[i
]; i
++)
1035 if (comms
[nr
].flags
& ARGS_ORMORE
)
1039 Msg(0, "%s: %s: at least %s argument%s required",
1040 rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1044 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1045 (comms
[nr
].flags
& ARGS_PLUS2
) &&
1046 (comms
[nr
].flags
& ARGS_PLUS3
))
1048 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2 && i
!= n
+ 3)
1050 Msg(0, orformat
[3], rc_name
, comms
[nr
].name
, argss
[n
],
1051 argss
[n
+ 1], argss
[n
+ 2], argss
[n
+ 3], "");
1055 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1056 (comms
[nr
].flags
& ARGS_PLUS2
))
1058 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2)
1060 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1061 argss
[n
+ 1], argss
[n
+ 2], "");
1065 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1066 (comms
[nr
].flags
& ARGS_PLUS3
))
1068 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 3)
1070 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1071 argss
[n
+ 1], argss
[n
+ 3], "");
1075 else if ((comms
[nr
].flags
& ARGS_PLUS2
) &&
1076 (comms
[nr
].flags
& ARGS_PLUS3
))
1078 if (i
!= n
&& i
!= n
+ 2 && i
!= n
+ 3)
1080 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1081 argss
[n
+ 2], argss
[n
+ 3], "");
1085 else if (comms
[nr
].flags
& ARGS_PLUS1
)
1087 if (i
!= n
&& i
!= n
+ 1)
1089 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1090 argss
[n
+ 1], n
!= 0 ? "s" : "");
1094 else if (comms
[nr
].flags
& ARGS_PLUS2
)
1096 if (i
!= n
&& i
!= n
+ 2)
1098 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1103 else if (comms
[nr
].flags
& ARGS_PLUS3
)
1105 if (i
!= n
&& i
!= n
+ 3)
1107 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1114 Msg(0, orformat
[0], rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1121 StuffFin(buf
, len
, data
)
1129 LayProcess(&buf
, &len
);
1132 /* If the command is not 'quieted', then use Msg to output the message. If it's a remote
1133 * query, then Msg takes care of also outputting the message to the querying client.
1135 * If we want the command to be quiet, and it's a remote query, then use QueryMsg so that
1136 * the response does go back to the querying client.
1138 * If the command is quieted, and it's not a remote query, then just don't print the message.
1140 #define OutputMsg (!act->quiet ? Msg : queryflag >= 0 ? QueryMsg : Dummy)
1149 char **args
= act
->args
;
1150 int *argl
= act
->argl
;
1152 int argc
, i
, n
, msgok
;
1155 struct display
*odisplay
= display
;
1156 struct acluser
*user
;
1158 user
= display
? D_user
: users
;
1159 if (nr
== RC_ILLEGAL
)
1161 debug1("key '%c': No action\n", key
);
1164 n
= comms
[nr
].flags
;
1165 /* Commands will have a CAN_QUERY flag, depending on whether they have
1166 * something to return on a query. For example, 'windows' can return a result,
1167 * but 'other' cannot.
1168 * If some command causes an error, then it should reset queryflag to -1, so that
1169 * the process requesting the query can be notified that an error happened.
1171 if (!(n
& CAN_QUERY
) && queryflag
>= 0)
1173 /* Query flag is set, but this command cannot be queried. */
1174 OutputMsg(0, "%s command cannot be queried.", comms
[nr
].name
);
1178 if ((n
& NEED_DISPLAY
) && display
== 0)
1180 OutputMsg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1184 if ((n
& NEED_FORE
) && fore
== 0)
1186 OutputMsg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1190 if ((n
& NEED_LAYER
) && flayer
== 0)
1192 OutputMsg(0, "%s: %s: display or window required", rc_name
, comms
[nr
].name
);
1196 if ((argc
= CheckArgNum(nr
, args
)) < 0)
1201 if (AclCheckPermCmd(D_user
, ACL_EXEC
, &comms
[nr
]))
1203 OutputMsg(0, "%s: %s: permission denied (user %s)",
1204 rc_name
, comms
[nr
].name
, (EffectiveAclUser
? EffectiveAclUser
: D_user
)->u_name
);
1209 #endif /* MULTIUSER */
1211 msgok
= display
&& !*rc_name
;
1217 else if (args
[0][0] == '-' && !args
[0][1])
1219 SetForeWindow((struct win
*)0);
1222 else if (args
[0][0] == '.' && !args
[0][1])
1226 OutputMsg(0, "select . needs a window");
1231 SetForeWindow(fore
);
1235 else if (ParseWinNum(act
, &n
) == 0)
1237 else if (queryflag
>= 0)
1238 queryflag
= -1; /* ParseWinNum already prints out an appropriate error message. */
1241 case RC_DEFAUTONUKE
:
1242 if (ParseOnOff(act
, &defautonuke
) == 0 && msgok
)
1243 OutputMsg(0, "Default autonuke turned %s", defautonuke
? "on" : "off");
1244 if (display
&& *rc_name
)
1245 D_auto_nuke
= defautonuke
;
1248 if (ParseOnOff(act
, &D_auto_nuke
) == 0 && msgok
)
1249 OutputMsg(0, "Autonuke turned %s", D_auto_nuke
? "on" : "off");
1252 case RC_DEFOBUFLIMIT
:
1253 if (ParseNum(act
, &defobuflimit
) == 0 && msgok
)
1254 OutputMsg(0, "Default limit set to %d", defobuflimit
);
1255 if (display
&& *rc_name
)
1257 D_obufmax
= defobuflimit
;
1258 D_obuflenmax
= D_obuflen
- D_obufmax
;
1263 OutputMsg(0, "Limit is %d, current buffer size is %d", D_obufmax
, D_obuflen
);
1264 else if (ParseNum(act
, &D_obufmax
) == 0 && msgok
)
1265 OutputMsg(0, "Limit set to %d", D_obufmax
);
1266 D_obuflenmax
= D_obuflen
- D_obufmax
;
1268 case RC_DUMPTERMCAP
:
1269 WriteFile(user
, (char *)0, DUMP_TERMCAP
);
1273 int mode
= DUMP_HARDCOPY
;
1278 if (!strcmp(*args
, "-h"))
1280 mode
= DUMP_SCROLLBACK
;
1283 else if (!strcmp(*args
, "--") && args
[1])
1289 if (args
[0] && file
== args
[0] && args
[1])
1291 OutputMsg(0, "%s: hardcopy: too many arguments", rc_name
);
1294 WriteFile(user
, file
, mode
);
1298 (void)ParseOnOff(act
, &nwin_default
.Lflag
);
1301 n
= fore
->w_log
? 1 : 0;
1302 ParseSwitch(act
, &n
);
1312 SwitchWindow(NextWindow());
1316 SwitchWindow(PreviousWindow());
1325 Input(fore
->w_pwin
? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1327 Input("Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1335 FreePseudowin(fore
);
1336 OutputMsg(0, "Filter removed.");
1340 name
= SaveStr(fore
->w_title
);
1342 OutputMsg(0, "Window %d (%s) killed.", n
, name
);
1350 Input("Really quit and kill all your windows [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_QUIT
);
1357 if (*args
&& !strcmp(*args
, "-h"))
1369 Input(buf
, 1, INP_RAW
, pow_detach_fn
, NULL
, 0);
1372 Detach(D_POWER
); /* detach and kill Attacher's parent */
1381 OutputMsg(0, "debugging info is written to %s/", DEBUGDIR
);
1383 OutputMsg(0, "debugging is currently off. Use 'debug on' to enable.");
1388 debug("debug: closing debug file.\n");
1393 if (strcmp("off", *args
))
1397 kill(D_userpid
, SIG_NODEBUG
); /* a one shot item, but hey... */
1398 # endif /* SIG_NODEBUG */
1400 if (*args
== 0 || strcmp("off", *args
))
1401 OutputMsg(0, "Sorry, screen was compiled without -DDEBUG option.");
1406 if (*args
&& !strcmp(*args
, "sendcmd"))
1410 free(zmodem_sendcmd
);
1411 zmodem_sendcmd
= SaveStr(args
[1]);
1414 OutputMsg(0, "zmodem sendcmd: %s", zmodem_sendcmd
);
1417 if (*args
&& !strcmp(*args
, "recvcmd"))
1421 free(zmodem_recvcmd
);
1422 zmodem_recvcmd
= SaveStr(args
[1]);
1425 OutputMsg(0, "zmodem recvcmd: %s", zmodem_recvcmd
);
1430 for (i
= 0; i
< 4; i
++)
1431 if (!strcmp(zmodes
[i
], *args
))
1433 if (i
== 4 && !strcmp(*args
, "on"))
1437 OutputMsg(0, "usage: zmodem off|auto|catch|pass");
1443 OutputMsg(0, "zmodem mode is %s", zmodes
[zmodem_mode
]);
1448 register unsigned int i
;
1450 for (i
= 0; i
< sizeof(ktab
)/sizeof(*ktab
); i
++)
1451 ClearAction(&ktab
[i
]);
1452 OutputMsg(0, "Unbound all keys." );
1459 ZombieKey_destroy
= 0;
1462 if (*argl
== 0 || *argl
> 2)
1464 OutputMsg(0, "%s:zombie: one or two characters expected.", rc_name
);
1469 if (!strcmp(args
[1], "onerror"))
1471 ZombieKey_onerror
= 1;
1473 OutputMsg(0, "usage: zombie [keys [onerror]]");
1477 ZombieKey_onerror
= 0;
1478 ZombieKey_destroy
= args
[0][0];
1479 ZombieKey_resurrect
= *argl
== 2 ? args
[0][1] : 0;
1489 struct display
*olddisplay
= display
;
1490 display
= 0; /* no display will cause a broadcast */
1491 OutputMsg(0, "%s: %s", s
, *args
);
1492 display
= olddisplay
;
1496 /* where this AT command comes from: */
1500 s
= SaveStr(user
->u_name
);
1501 /* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
1502 EffectiveAclUser
= user
;
1504 s
= SaveStr(display
? D_usertty
: user
->u_name
);
1506 n
= strlen(args
[0]);
1509 * the windows/displays loops are quite dangerous here, take extra
1510 * care not to trigger landmines. Things may appear/disappear while
1511 * we are walking along.
1515 case '*': /* user */
1524 for (u
= users
; u
; u
= u
->u_next
)
1526 debug3("strncmp('%s', '%s', %d)\n", *args
, u
->u_name
, n
);
1527 if (!strncmp(*args
, u
->u_name
, n
))
1533 OutputMsg(0, "Did not find any user matching '%s'", args
[0]);
1537 debug1("at all displays of user %s\n", u
->u_name
);
1538 for (display
= displays
; display
; display
= nd
)
1540 nd
= display
->d_next
;
1543 flayer
= D_forecv
->c_layer
;
1547 debug1("AT display %s\n", D_usertty
);
1548 DoCommand(args
+ 1, argl
+ 1);
1550 OutputMsg(0, "command from %s: %s %s",
1551 s
, args
[1], args
[2] ? args
[2] : "");
1558 case '%': /* display */
1562 debug1("at display matching '%s'\n", args
[0]);
1563 for (display
= displays
; display
; display
= nd
)
1565 nd
= display
->d_next
;
1569 flayer
= D_forecv
->c_layer
;
1570 if (strncmp(args
[0], D_usertty
, n
) &&
1571 (strncmp("/dev/", D_usertty
, 5) ||
1572 strncmp(args
[0], D_usertty
+ 5, n
)) &&
1573 (strncmp("/dev/tty", D_usertty
, 8) ||
1574 strncmp(args
[0], D_usertty
+ 8, n
)))
1576 debug1("AT display %s\n", D_usertty
);
1577 DoCommand(args
+ 1, argl
+ 1);
1579 OutputMsg(0, "command from %s: %s %s",
1580 s
, args
[1], args
[2] ? args
[2] : "");
1587 case '#': /* window */
1598 if (!*args
[0] || (i
= WindowByNumber(args
[0])) < 0)
1600 args
[0][n
] = ch
; /* must restore string in case of bind */
1601 /* try looping over titles */
1602 for (fore
= windows
; fore
; fore
= nw
)
1605 if (strncmp(args
[0], fore
->w_title
, n
))
1607 debug2("AT window %d(%s)\n", fore
->w_number
, fore
->w_title
);
1609 * consider this a bug or a feature:
1610 * while looping through windows, we have fore AND
1611 * display context. This will confuse users who try to
1612 * set up loops inside of loops, but often allows to do
1613 * what you mean, even when you adress your context wrong.
1616 /* XXX: other displays? */
1617 if (fore
->w_layer
.l_cvlist
)
1618 display
= fore
->w_layer
.l_cvlist
->c_display
;
1619 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1620 DoCommand(args
+ 1, argl
+ 1); /* may destroy our display */
1621 if (fore
&& fore
->w_layer
.l_cvlist
)
1623 display
= fore
->w_layer
.l_cvlist
->c_display
;
1624 OutputMsg(0, "command from %s: %s %s",
1625 s
, args
[1], args
[2] ? args
[2] : "");
1631 OutputMsg(0, "%s: at '%s': no such window.\n", rc_name
, args
[0]);
1634 else if (i
< maxwin
&& (fore
= wtab
[i
]))
1636 args
[0][n
] = ch
; /* must restore string in case of bind */
1637 debug2("AT window %d (%s)\n", fore
->w_number
, fore
->w_title
);
1638 if (fore
->w_layer
.l_cvlist
)
1639 display
= fore
->w_layer
.l_cvlist
->c_display
;
1640 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1641 DoCommand(args
+ 1, argl
+ 1);
1642 if (fore
&& fore
->w_layer
.l_cvlist
)
1644 display
= fore
->w_layer
.l_cvlist
->c_display
;
1645 OutputMsg(0, "command from %s: %s %s",
1646 s
, args
[1], args
[2] ? args
[2] : "");
1652 OutputMsg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name
);
1658 EffectiveAclUser
= NULL
;
1665 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1666 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1668 i
= FindEncoding(args
[1]);
1671 OutputMsg(0, "%s: readreg: unknown encoding", rc_name
);
1678 * Without arguments we prompt for a destination register.
1679 * It will receive the copybuffer contents.
1680 * This is not done by RC_PASTE, as we prompt for source
1683 if ((s
= *args
) == NULL
)
1685 Input("Copy to register:", 1, INP_RAW
, copy_reg_fn
, NULL
, 0);
1690 OutputMsg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name
);
1695 * With two arguments we *really* read register contents from file
1701 OutputMsg(0, "%s: readreg: too many arguments", rc_name
);
1704 if ((s
= ReadFile(args
[1], &n
)))
1706 struct plop
*pp
= plop_tab
+ (int)(unsigned char)ch
;
1719 * with one argument we copy the copybuffer into a specified register
1720 * This could be done with RC_PASTE too, but is here to be consistent
1721 * with the zero argument call.
1723 copy_reg_fn(&ch
, 0, NULL
);
1728 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1729 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1731 i
= FindEncoding(args
[1]);
1734 OutputMsg(0, "%s: register: unknown encoding", rc_name
);
1743 OutputMsg(0, "%s: register: illegal number of arguments.", rc_name
);
1748 OutputMsg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name
);
1755 if (user
->u_plop
.buf
!= NULL
)
1756 UserFreeCopyBuffer(user
);
1757 if (args
[1] && args
[1][0])
1759 user
->u_plop
.buf
= SaveStrn(args
[1], argl
[1]);
1760 user
->u_plop
.len
= argl
[1];
1762 user
->u_plop
.enc
= i
;
1769 struct plop
*plp
= plop_tab
+ (int)(unsigned char)ch
;
1773 plp
->buf
= SaveStrn(args
[1], argl
[1]);
1781 if ((s
= *args
) == NULL
)
1783 Input("Process register:", 1, INP_RAW
, process_fn
, NULL
, 0);
1788 OutputMsg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name
);
1792 process_fn(&ch
, 0, NULL
);
1798 Input("Stuff:", 100, INP_COOKED
, StuffFin
, NULL
, 0);
1804 if (strcmp(s
, "-k"))
1806 OutputMsg(0, "%s: stuff: invalid option %s", rc_name
, s
);
1810 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
1811 if (strcmp(term
[i
].tcname
, s
) == 0)
1815 OutputMsg(0, "%s: stuff: unknown key '%s'", rc_name
, s
);
1819 if (StuffKey(i
- T_CAPS
) == 0)
1822 s
= display
? D_tcs
[i
].str
: 0;
1837 OutputMsg(0, "screen %s", version
);
1842 timestring
= SaveStr(*args
);
1845 OutputMsg(0, "%s", MakeWinMsg(timestring
, fore
, '%'));
1855 struct action
*ktabp
= ktab
;
1856 if (argc
== 2 && !strcmp(*args
, "-c"))
1858 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
1860 OutputMsg(0, "Unknown command class '%s'", args
[1]);
1864 if (D_ESCseen
!= ktab
|| ktabp
!= ktab
)
1874 SwitchWindow(display
&& D_other
? D_other
->w_number
: NextWindow());
1877 if (user
->u_Esc
== -1)
1896 case RC_DEFBREAKTYPE
:
1899 static char *types
[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL
};
1900 extern int breaktype
;
1904 if (ParseNum(act
, &n
))
1905 for (n
= 0; n
< (int)(sizeof(types
)/sizeof(*types
)); n
++)
1907 for (i
= 0; i
< 4; i
++)
1910 if (ch
>= 'a' && ch
<= 'z')
1912 if (ch
!= types
[n
][i
] && (ch
+ ('a' - 'A')) != types
[n
][i
])
1918 if (n
< 0 || n
>= (int)(sizeof(types
)/sizeof(*types
)))
1919 OutputMsg(0, "%s invalid, chose one of %s, %s or %s", *args
, types
[0], types
[1], types
[2]);
1923 OutputMsg(0, "breaktype set to (%d) %s", n
, types
[n
]);
1927 OutputMsg(0, "breaktype is (%d) %s", breaktype
, types
[breaktype
]);
1933 if (*args
&& ParseNum(act
, &n
))
1935 SendBreak(fore
, n
, nr
== RC_POW_BREAK
);
1949 if (*args
&& !strcmp(*args
, "-w"))
1951 else if (*args
&& !strcmp(*args
, "-d"))
1955 if (what
== 0 && flayer
&& !display
)
1961 OutputMsg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1964 w
= flayer
->l_width
;
1965 h
= flayer
->l_height
;
1971 OutputMsg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1977 if (*args
&& args
[0][0] == '-')
1979 OutputMsg(0, "%s: %s: unknown option %s", rc_name
, comms
[nr
].name
, *args
);
1982 if (nr
== RC_HEIGHT
)
1990 else if (h
== H1height
)
1992 else if (h
> (H0height
+ H1height
) / 2)
2010 else if (w
== Z1width
)
2012 else if (w
> (Z0width
+ Z1width
) / 2)
2024 if (*args
&& args
[1] && args
[2])
2026 OutputMsg(0, "%s: %s: too many arguments", rc_name
, comms
[nr
].name
);
2031 OutputMsg(0, "Illegal width");
2036 OutputMsg(0, "Illegal height");
2041 if (flayer
->l_width
== w
&& flayer
->l_height
== h
)
2043 ResizeLayer(flayer
, w
, h
, (struct display
*)0);
2046 if (D_width
== w
&& D_height
== h
)
2050 ChangeScreenSize(w
, h
, 1);
2054 if (ResizeDisplay(w
, h
) == 0)
2056 Activate(D_fore
? D_fore
->w_norefresh
: 0);
2058 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
2062 OutputMsg(0, "Your termcap does not specify how to change the terminal's width to %d.", w
);
2063 else if (w
== D_width
)
2064 OutputMsg(0, "Your termcap does not specify how to change the terminal's height to %d.", h
);
2066 OutputMsg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w
, h
);
2074 OutputMsg(0, "%s", fore
->w_title
);
2082 ChangeAKA(fore
, *args
, strlen(*args
));
2085 Input(":", 100, INP_EVERY
, Colonfin
, NULL
, 0);
2086 if (*args
&& **args
)
2094 if (D_status_lastmsg
)
2095 OutputMsg(0, "%s", D_status_lastmsg
);
2098 DoScreen("key", args
);
2101 if (ParseSwitch(act
, &fore
->w_wrap
) == 0 && msgok
)
2102 OutputMsg(0, "%cwrap", fore
->w_wrap
? '+' : '-');
2107 if (args
[0][0] == 'a')
2109 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) ? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
2113 if (ParseOnOff(act
, &n
))
2115 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | n
;
2120 if (fore
->w_flow
& FLOW_AUTOFLAG
)
2121 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | FLOW_NOW
;
2122 else if (fore
->w_flow
& FLOW_NOW
)
2123 fore
->w_flow
&= ~FLOW_NOW
;
2125 fore
->w_flow
= fore
->w_flow
? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
2127 SetFlow(fore
->w_flow
& FLOW_NOW
);
2129 OutputMsg(0, "%cflow%s", (fore
->w_flow
& FLOW_NOW
) ? '+' : '-',
2130 (fore
->w_flow
& FLOW_AUTOFLAG
) ? "(auto)" : "");
2133 case RC_DEFWRITELOCK
:
2134 if (args
[0][0] == 'a')
2135 nwin_default
.wlock
= WLOCK_AUTO
;
2138 if (ParseOnOff(act
, &n
))
2140 nwin_default
.wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2146 if (args
[0][0] == 'a')
2148 fore
->w_wlock
= WLOCK_AUTO
;
2152 if (ParseOnOff(act
, &n
))
2154 fore
->w_wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2157 * user may have permission to change the writelock setting,
2158 * but he may never aquire the lock himself without write permission
2160 if (!AclCheckPermWin(D_user
, ACL_WRITE
, fore
))
2161 fore
->w_wlockuser
= D_user
;
2163 OutputMsg(0, "writelock %s", (fore
->w_wlock
== WLOCK_AUTO
) ? "auto" :
2164 ((fore
->w_wlock
== WLOCK_OFF
) ? "off" : "on"));
2168 ResetAnsiState(fore
);
2169 WriteString(fore
, "\033[H\033[J", 6);
2172 ResetAnsiState(fore
);
2174 if (fore
->w_zdisplay
)
2175 zmodem_abort(fore
, fore
->w_zdisplay
);
2177 WriteString(fore
, "\033c", 2);
2180 n
= fore
->w_monitor
!= MON_OFF
;
2183 n
= n
&& (ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
));
2185 if (ParseSwitch(act
, &n
))
2190 if (display
) /* we tell only this user */
2191 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2193 for (i
= 0; i
< maxusercount
; i
++)
2194 ACLBYTE(fore
->w_mon_notify
, i
) |= ACLBIT(i
);
2196 if (fore
->w_monitor
== MON_OFF
)
2197 fore
->w_monitor
= MON_ON
;
2198 OutputMsg(0, "Window %d (%s) is now being monitored for all activity.", fore
->w_number
, fore
->w_title
);
2203 if (display
) /* we remove only this user */
2204 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
)
2205 &= ~ACLBIT(D_user
->u_id
);
2207 for (i
= 0; i
< maxusercount
; i
++)
2208 ACLBYTE(fore
->w_mon_notify
, i
) &= ~ACLBIT(i
);
2209 for (i
= maxusercount
- 1; i
>= 0; i
--)
2210 if (ACLBYTE(fore
->w_mon_notify
, i
))
2214 fore
->w_monitor
= MON_OFF
;
2215 OutputMsg(0, "Window %d (%s) is no longer being monitored for activity.", fore
->w_number
, fore
->w_title
);
2225 display_windows(0, WLIST_NUM
, (struct win
*)0);
2226 else if (!strcmp(*args
, "string"))
2232 wliststr
= SaveStr(args
[1]);
2235 OutputMsg(0, "windowlist string is '%s'", wliststr
);
2237 else if (!strcmp(*args
, "title"))
2243 wlisttit
= SaveStr(args
[1]);
2246 OutputMsg(0, "windowlist title is '%s'", wlisttit
);
2252 for (i
= 0; i
< argc
; i
++)
2255 else if (!strcmp(args
[i
], "-m"))
2257 else if (!strcmp(args
[i
], "-b"))
2259 else if (!strcmp(args
[i
], "-g"))
2260 flag
|= WLIST_NESTED
;
2263 OutputMsg(0, "usage: windowlist [-b] [-g] [-m] [string [string] | title [title]]");
2267 display_windows(blank
, flag
, (struct win
*)0);
2271 if (argc
== 2 && !strcmp(*args
, "-c"))
2273 struct action
*ktabp
;
2274 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
2276 OutputMsg(0, "Unknown command class '%s'", args
[1]);
2279 display_help(args
[1], ktabp
);
2282 display_help((char *)0, ktab
);
2285 display_copyright();
2289 if (flayer
->l_layfn
!= &WinLf
)
2291 OutputMsg(0, "Must be on a window layer");
2295 WindowChanged(fore
, 'P');
2299 static char *pasteargs
[] = {".", 0};
2300 static int pasteargl
[] = {1};
2302 if (flayer
->l_layfn
!= &WinLf
)
2304 OutputMsg(0, "Must be on a window layer");
2307 if (GetHistory() == 0)
2309 if (user
->u_plop
.buf
== NULL
)
2317 char *ss
, *dbuf
, dch
;
2324 * without args we prompt for one(!) register to be pasted in the window
2326 if ((s
= *args
) == NULL
)
2328 Input("Paste from register:", 1, INP_RAW
, ins_reg_fn
, NULL
, 0);
2331 if (args
[1] == 0 && !fore
) /* no window? */
2334 * with two arguments we paste into a destination register
2335 * (no window needed here).
2337 if (args
[1] && argl
[1] != 1)
2339 OutputMsg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
2345 enc
= fore
->w_encoding
;
2349 * measure length of needed buffer
2351 for (ss
= s
= *args
; (ch
= *ss
); ss
++)
2357 enc
= user
->u_plop
.enc
;
2358 if (enc
!= user
->u_plop
.enc
)
2359 l
+= RecodeBuf((unsigned char *)user
->u_plop
.buf
, user
->u_plop
.len
, user
->u_plop
.enc
, enc
, (unsigned char *)0);
2362 l
+= user
->u_plop
.len
;
2368 enc
= plop_tab
[(int)(unsigned char)ch
].enc
;
2369 if (enc
!= plop_tab
[(int)(unsigned char)ch
].enc
)
2370 l
+= RecodeBuf((unsigned char *)plop_tab
[(int)(unsigned char)ch
].buf
, plop_tab
[(int)(unsigned char)ch
].len
, plop_tab
[(int)(unsigned char)ch
].enc
, enc
, (unsigned char *)0);
2373 l
+= plop_tab
[(int)(unsigned char)ch
].len
;
2378 OutputMsg(0, "empty buffer");
2383 * if there is only one source and the destination is a window, then
2384 * pass a pointer rather than duplicating the buffer.
2386 if (s
[1] == 0 && args
[1] == 0)
2388 if (enc
== (*s
== '.' ? user
->u_plop
.enc
: plop_tab
[(int)(unsigned char)*s
].enc
))
2391 MakePaster(&fore
->w_paster
, *s
== '.' ? user
->u_plop
.buf
: plop_tab
[(int)(unsigned char)*s
].buf
, l
, 0);
2395 * if no shortcut, we construct a buffer
2397 if ((dbuf
= (char *)malloc(l
)) == 0)
2399 OutputMsg(0, "%s", strnomem
);
2404 * concatenate all sources into our own buffer, copy buffer is
2405 * special and is skipped if no display exists.
2407 for (ss
= s
; (ch
= *ss
); ss
++)
2409 struct plop
*pp
= (ch
== '.' ? &user
->u_plop
: &plop_tab
[(int)(unsigned char)ch
]);
2413 l
+= RecodeBuf((unsigned char *)pp
->buf
, pp
->len
, pp
->enc
, enc
, (unsigned char *)dbuf
+ l
);
2417 bcopy(pp
->buf
, dbuf
+ l
, pp
->len
);
2421 * when called with one argument we paste our buffer into the window
2425 MakePaster(&fore
->w_paster
, dbuf
, l
, 1);
2430 * we have two arguments, the second is already in dch.
2431 * use this as destination rather than the window.
2436 if (user
->u_plop
.buf
!= NULL
)
2437 UserFreeCopyBuffer(user
);
2438 user
->u_plop
.buf
= dbuf
;
2439 user
->u_plop
.len
= l
;
2441 user
->u_plop
.enc
= enc
;
2446 struct plop
*pp
= plop_tab
+ (int)(unsigned char)dch
;
2459 if (!user
->u_plop
.buf
)
2461 OutputMsg(0, "empty buffer");
2466 struct plop oldplop
;
2468 oldplop
= user
->u_plop
;
2469 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2474 enc
= FindEncoding(args
[1]);
2477 OutputMsg(0, "%s: writebuf: unknown encoding", rc_name
);
2480 if (enc
!= oldplop
.enc
)
2482 l
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)0);
2483 newbuf
= malloc(l
+ 1);
2486 OutputMsg(0, "%s", strnomem
);
2489 user
->u_plop
.len
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)newbuf
);
2490 user
->u_plop
.buf
= newbuf
;
2491 user
->u_plop
.enc
= enc
;
2496 if (args
[0] && args
[1])
2497 OutputMsg(0, "%s: writebuf: too many arguments", rc_name
);
2499 WriteFile(user
, args
[0], DUMP_EXCHANGE
);
2501 if (user
->u_plop
.buf
!= oldplop
.buf
)
2502 free(user
->u_plop
.buf
);
2503 user
->u_plop
= oldplop
;
2509 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
2510 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2512 i
= FindEncoding(args
[1]);
2515 OutputMsg(0, "%s: readbuf: unknown encoding", rc_name
);
2521 if (args
[0] && args
[1])
2523 OutputMsg(0, "%s: readbuf: too many arguments", rc_name
);
2526 if ((s
= ReadFile(args
[0] ? args
[0] : BufferFile
, &n
)))
2528 if (user
->u_plop
.buf
)
2529 UserFreeCopyBuffer(user
);
2530 user
->u_plop
.len
= n
;
2531 user
->u_plop
.buf
= s
;
2533 user
->u_plop
.enc
= i
;
2541 (void)ParseSwitch(act
, &search_ic
);
2543 OutputMsg(0, "Will %signore case in searches", search_ic
? "" : "not ");
2545 #endif /* COPY_PASTE */
2548 SetEscape(user
, -1, -1);
2549 else if (*argl
== 2)
2550 SetEscape(user
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2553 OutputMsg(0, "%s: two characters required after escape.", rc_name
);
2556 /* Change defescape if master user. This is because we only
2559 if (display
&& user
!= users
)
2564 SetEscape(NULL
, -1, -1);
2565 else if (*argl
== 2)
2566 SetEscape(NULL
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2569 OutputMsg(0, "%s: two characters required after defescape.", rc_name
);
2577 s
= *args
? *args
: home
;
2579 OutputMsg(errno
, "%s", s
);
2583 if (ParseSaveStr(act
, &ShellProg
) == 0)
2584 ShellArgs
[0] = ShellProg
;
2586 case RC_HARDCOPYDIR
:
2588 (void)ParseSaveStr(act
, &hardcopydir
);
2590 OutputMsg(0, "hardcopydir is %s\n", hardcopydir
&& *hardcopydir
? hardcopydir
: "<cwd>");
2595 if (args
[1] && !(strcmp(*args
, "flush")))
2597 log_flush
= atoi(args
[1]);
2599 OutputMsg(0, "log flush timeout set to %ds\n", log_flush
);
2602 if (ParseSaveStr(act
, &screenlogfile
) || !msgok
)
2605 OutputMsg(0, "logfile is '%s'", screenlogfile
);
2608 if (!*args
|| !strcmp(*args
, "on") || !strcmp(*args
, "off"))
2610 if (ParseSwitch(act
, &logtstamp_on
) == 0 && msgok
)
2611 OutputMsg(0, "timestamps turned %s", logtstamp_on
? "on" : "off");
2613 else if (!strcmp(*args
, "string"))
2617 if (logtstamp_string
)
2618 free(logtstamp_string
);
2619 logtstamp_string
= SaveStr(args
[1]);
2622 OutputMsg(0, "logfile timestamp is '%s'", logtstamp_string
);
2624 else if (!strcmp(*args
, "after"))
2628 logtstamp_after
= atoi(args
[1]);
2632 OutputMsg(0, "timestamp printed after %ds\n", logtstamp_after
);
2635 OutputMsg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
2638 (void)ParseSaveStr(act
, &nwin_default
.aka
);
2641 case RC_TERMCAPINFO
:
2643 if (!rc_name
|| !*rc_name
)
2644 OutputMsg(0, "Sorry, too late now. Place that in your .screenrc file.");
2647 break; /* Already handled */
2650 if (ParseSaveStr(act
, &s
))
2652 if (strlen(s
) >= 20)
2654 OutputMsg(0, "%s: term: argument too long ( < 20)", rc_name
);
2658 strcpy(screenterm
, s
);
2660 debug1("screenterm set to %s\n", screenterm
);
2661 MakeTermcap((display
== 0));
2662 debug("new termcap made\n");
2665 if (!msgok
&& (!rc_name
|| strcmp(rc_name
, "-X")))
2668 * user typed ^A:echo... well, echo isn't FinishRc's job,
2669 * but as he wanted to test us, we show good will
2671 if (argc
> 1 && !strcmp(*args
, "-n"))
2677 if (argc
> 1 && !strcmp(*args
, "-p"))
2683 s
= MakeWinMsg(s
, fore
, '%');
2686 OutputMsg(0, "%s", s
);
2689 OutputMsg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name
);
2698 AddXChars(buf
, sizeof(buf
), BellString
);
2699 OutputMsg(0, "bell_msg is '%s'", buf
);
2702 (void)ParseSaveStr(act
, &BellString
);
2707 BufferFile
= SaveStr(DEFAULT_BUFFERFILE
);
2708 else if (ParseSaveStr(act
, &BufferFile
))
2711 OutputMsg(0, "Bufferfile is now '%s'", BufferFile
);
2715 (void)ParseSaveStr(act
, &ActivityString
);
2717 #if defined(DETACH) && defined(POW_DETACH)
2718 case RC_POW_DETACH_MSG
:
2722 AddXChars(buf
, sizeof(buf
), PowDetachString
);
2723 OutputMsg(0, "pow_detach_msg is '%s'", buf
);
2726 (void)ParseSaveStr(act
, &PowDetachString
);
2729 #if defined(UTMPOK) && defined(LOGOUTOK)
2731 n
= fore
->w_slot
!= (slot_t
)-1;
2732 if (*args
&& !strcmp(*args
, "always"))
2739 if (*args
&& !strcmp(*args
, "attached"))
2746 if (ParseSwitch(act
, &n
) == 0)
2750 if (!strcmp(*args
, "always"))
2751 nwin_default
.lflag
|= 2;
2752 else if (!strcmp(*args
, "attached"))
2753 nwin_default
.lflag
&= ~2;
2755 (void)ParseOnOff(act
, &nwin_default
.lflag
);
2759 if (args
[0] && args
[1] && args
[1][0] == 'i')
2762 for (display
= displays
; display
; display
= display
->d_next
)
2766 #if defined(TERMIO) || defined(POSIX)
2767 D_NewMode
.tio
.c_cc
[VINTR
] = D_OldMode
.tio
.c_cc
[VINTR
];
2768 D_NewMode
.tio
.c_lflag
|= ISIG
;
2769 #else /* TERMIO || POSIX */
2770 D_NewMode
.m_tchars
.t_intrc
= D_OldMode
.m_tchars
.t_intrc
;
2771 #endif /* TERMIO || POSIX */
2772 SetTTY(D_userfd
, &D_NewMode
);
2775 if (args
[0] && args
[0][0] == 'a')
2776 nwin_default
.flowflag
= FLOW_AUTOFLAG
;
2778 (void)ParseOnOff(act
, &nwin_default
.flowflag
);
2781 (void)ParseOnOff(act
, &nwin_default
.wrap
);
2784 (void)ParseOnOff(act
, &nwin_default
.c1
);
2788 (void)ParseOnOff(act
, &nwin_default
.bce
);
2792 (void)ParseOnOff(act
, &nwin_default
.gr
);
2795 if (ParseOnOff(act
, &n
) == 0)
2796 nwin_default
.monitor
= (n
== 0) ? MON_OFF
: MON_ON
;
2798 case RC_DEFMOUSETRACK
:
2799 if (ParseOnOff(act
, &n
) == 0)
2800 defmousetrack
= (n
== 0) ? 0 : 1000;
2805 OutputMsg(0, "Mouse tracking for this display is turned %s", D_mousetrack
? "on" : "off");
2807 else if (ParseOnOff(act
, &n
) == 0)
2809 D_mousetrack
= n
== 0 ? 0 : 1000;
2811 MouseMode(D_fore
->w_mouse
);
2815 if (ParseOnOff(act
, &n
) == 0)
2816 nwin_default
.silence
= (n
== 0) ? SILENCE_OFF
: SILENCE_ON
;
2820 OutputMsg(0, "W%s echo command when creating windows.",
2821 VerboseCreate
? "ill" : "on't");
2822 else if (ParseOnOff(act
, &n
) == 0)
2828 OutputMsg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
2831 if (args
[0] && strcmp(args
[0], "on") && strcmp(args
[0], "off"))
2833 struct display
*olddisplay
= display
;
2834 int old_use
, new_use
= -1;
2837 if (!strncmp(s
, "always", 6))
2839 if (!strcmp(s
, "lastline"))
2840 new_use
= HSTATUS_LASTLINE
;
2841 else if (!strcmp(s
, "ignore"))
2842 new_use
= HSTATUS_IGNORE
;
2843 else if (!strcmp(s
, "message"))
2844 new_use
= HSTATUS_MESSAGE
;
2845 else if (!strcmp(args
[0], "string"))
2850 AddXChars(buf
, sizeof(buf
), hstatusstring
);
2851 OutputMsg(0, "hardstatus string is '%s'", buf
);
2857 OutputMsg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name
);
2862 hardstatusemu
= new_use
| (s
== args
[0] ? 0 : HSTATUS_ALWAYS
);
2863 for (display
= displays
; display
; display
= display
->d_next
)
2866 new_use
= hardstatusemu
& ~HSTATUS_ALWAYS
;
2867 if (D_HS
&& s
== args
[0])
2868 new_use
= HSTATUS_HS
;
2869 ShowHStatus((char *)0);
2870 old_use
= D_has_hstatus
;
2871 D_has_hstatus
= new_use
;
2872 if ((new_use
== HSTATUS_LASTLINE
&& old_use
!= HSTATUS_LASTLINE
) || (new_use
!= HSTATUS_LASTLINE
&& old_use
== HSTATUS_LASTLINE
))
2873 ChangeScreenSize(D_width
, D_height
, 1);
2880 free(hstatusstring
);
2881 hstatusstring
= SaveStr(args
[1]);
2882 for (display
= displays
; display
; display
= display
->d_next
)
2885 display
= olddisplay
;
2888 (void)ParseSwitch(act
, &use_hardstatus
);
2890 OutputMsg(0, "messages displayed on %s", use_hardstatus
? "hardstatus line" : "window");
2893 if (strcmp(args
[0], "always") == 0 || strcmp(args
[0], "splitonly") == 0)
2895 struct display
*olddisplay
= display
;
2897 captionalways
= args
[0][0] == 'a';
2898 for (display
= displays
; display
; display
= display
->d_next
)
2899 ChangeScreenSize(D_width
, D_height
, 1);
2900 display
= olddisplay
;
2902 else if (strcmp(args
[0], "string") == 0)
2907 AddXChars(buf
, sizeof(buf
), captionstring
);
2908 OutputMsg(0, "caption string is '%s'", buf
);
2914 OutputMsg(0, "%s: usage: caption always|splitonly|string <string>", rc_name
);
2920 free(captionstring
);
2921 captionstring
= SaveStr(args
[1]);
2922 RedisplayDisplays(0);
2925 n
= (console_window
!= 0);
2926 if (ParseSwitch(act
, &n
))
2928 if (TtyGrabConsole(fore
->w_ptyfd
, n
, rc_name
))
2931 OutputMsg(0, "%s: releasing console %s", rc_name
, HostName
);
2932 else if (console_window
)
2933 OutputMsg(0, "%s: stealing console %s from window %d (%s)", rc_name
,
2934 HostName
, console_window
->w_number
, console_window
->w_title
);
2936 OutputMsg(0, "%s: grabbing console %s", rc_name
, HostName
);
2937 console_window
= n
? fore
: 0;
2940 if (ParseOnOff(act
, &all_norefresh
))
2942 if (!all_norefresh
&& fore
)
2945 OutputMsg(0, all_norefresh
? "No refresh on window change!\n" :
2946 "Window specific refresh\n");
2949 (void)ParseSwitch(act
, &n
);
2950 fore
->w_norefresh
= n
;
2953 if (ParseSwitch(act
, &visual_bell
) || !msgok
)
2955 if (visual_bell
== 0)
2956 OutputMsg(0, "switched to audible bell.");
2958 OutputMsg(0, "switched to visual bell.");
2961 if (ParseNum1000(act
, &VBellWait
) == 0 && msgok
)
2962 OutputMsg(0, "vbellwait set to %.10g seconds", VBellWait
/1000.);
2965 if (ParseNum1000(act
, &MsgWait
) == 0 && msgok
)
2966 OutputMsg(0, "msgwait set to %.10g seconds", MsgWait
/1000.);
2969 if (ParseNum1000(act
, &MsgMinWait
) == 0 && msgok
)
2970 OutputMsg(0, "msgminwait set to %.10g seconds", MsgMinWait
/1000.);
2972 case RC_SILENCEWAIT
:
2973 if (ParseNum(act
, &SilenceWait
))
2975 if (SilenceWait
< 1)
2977 for (p
= windows
; p
; p
= p
->w_next
)
2978 p
->w_silencewait
= SilenceWait
;
2980 OutputMsg(0, "silencewait set to %d seconds", SilenceWait
);
2984 OutputMsg(0, queryflag
>= 0 ? "%d (%s)" : "This is window %d (%s).", fore
->w_number
, fore
->w_title
);
2987 int old
= fore
->w_number
;
2989 if (args
[0][0] == '+')
2991 else if (args
[0][0] == '-')
2995 parse
= ParseNum(act
, &n
);
3004 if (!WindowChangeNumber(fore
, n
))
3006 /* Window number could not be changed. */
3013 n
= fore
->w_silence
!= 0;
3014 i
= fore
->w_silencewait
;
3015 if (args
[0] && (args
[0][0] == '-' || (args
[0][0] >= '0' && args
[0][0] <= '9')))
3017 if (ParseNum(act
, &i
))
3021 else if (ParseSwitch(act
, &n
))
3026 if (display
) /* we tell only this user */
3027 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
3029 for (n
= 0; n
< maxusercount
; n
++)
3030 ACLBYTE(fore
->w_lio_notify
, n
) |= ACLBIT(n
);
3032 fore
->w_silencewait
= i
;
3033 fore
->w_silence
= SILENCE_ON
;
3034 SetTimeout(&fore
->w_silenceev
, fore
->w_silencewait
* 1000);
3035 evenq(&fore
->w_silenceev
);
3039 OutputMsg(0, "The window is now being monitored for %d sec. silence.", fore
->w_silencewait
);
3044 if (display
) /* we remove only this user */
3045 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
)
3046 &= ~ACLBIT(D_user
->u_id
);
3048 for (n
= 0; n
< maxusercount
; n
++)
3049 ACLBYTE(fore
->w_lio_notify
, n
) &= ~ACLBIT(n
);
3050 for (i
= maxusercount
- 1; i
>= 0; i
--)
3051 if (ACLBYTE(fore
->w_lio_notify
, i
))
3056 fore
->w_silence
= SILENCE_OFF
;
3057 evdeq(&fore
->w_silenceev
);
3061 OutputMsg(0, "The window is no longer being monitored for silence.");
3065 case RC_DEFSCROLLBACK
:
3066 (void)ParseNum(act
, &nwin_default
.histheight
);
3069 if (flayer
->l_layfn
== &MarkLf
)
3071 OutputMsg(0, "Cannot resize scrollback buffer in copy/scrollback mode.");
3074 (void)ParseNum(act
, &n
);
3075 ChangeWindowSize(fore
, fore
->w_width
, fore
->w_height
, n
);
3077 OutputMsg(0, "scrollback set to %d", fore
->w_histheight
);
3080 case RC_SESSIONNAME
:
3082 OutputMsg(0, "This session is named '%s'\n", SockName
);
3085 char buf
[MAXPATHLEN
];
3088 if (ParseSaveStr(act
, &s
))
3090 if (!*s
|| strlen(s
) + (SockName
- SockPath
) > MAXPATHLEN
- 13 || index(s
, '/'))
3092 OutputMsg(0, "%s: bad session name '%s'\n", rc_name
, s
);
3096 strncpy(buf
, SockPath
, SockName
- SockPath
);
3097 sprintf(buf
+ (SockName
- SockPath
), "%d.%s", (int)getpid(), s
);
3099 if ((access(buf
, F_OK
) == 0) || (errno
!= ENOENT
))
3101 OutputMsg(0, "%s: inappropriate path: '%s'.", rc_name
, buf
);
3104 if (rename(SockPath
, buf
))
3106 OutputMsg(errno
, "%s: failed to rename(%s, %s)", rc_name
, SockPath
, buf
);
3109 debug2("rename(%s, %s) done\n", SockPath
, buf
);
3110 strcpy(SockPath
, buf
);
3112 WindowChanged((struct win
*)0, 'S');
3116 if (!args
[0] || !args
[1])
3118 debug1("RC_SETENV arguments missing: %s\n", args
[0] ? args
[0] : "");
3119 InputSetenv(args
[0]);
3123 xsetenv(args
[0], args
[1]);
3132 case RC_DEFSLOWPASTE
:
3133 (void)ParseNum(act
, &nwin_default
.slow
);
3137 OutputMsg(0, fore
->w_slowpaste
?
3138 "Slowpaste in window %d is %d milliseconds." :
3139 "Slowpaste in window %d is unset.",
3140 fore
->w_number
, fore
->w_slowpaste
);
3141 else if (ParseNum(act
, &fore
->w_slowpaste
) == 0 && msgok
)
3142 OutputMsg(0, fore
->w_slowpaste
?
3143 "Slowpaste in window %d set to %d milliseconds." :
3144 "Slowpaste in window %d now unset.",
3145 fore
->w_number
, fore
->w_slowpaste
);
3148 if (CompileKeys(*args
, *argl
, mark_key_tab
))
3150 OutputMsg(0, "%s: markkeys: syntax error.", rc_name
);
3153 debug1("markkeys %s\n", *args
);
3157 if (ParseSwitch(act
, &pastefont
) == 0 && msgok
)
3158 OutputMsg(0, "Will %spaste font settings", pastefont
? "" : "not ");
3162 (void)ParseSwitch(act
, &join_with_cr
);
3164 case RC_COMPACTHIST
:
3165 if (ParseSwitch(act
, &compacthist
) == 0 && msgok
)
3166 OutputMsg(0, "%scompacting history lines", compacthist
? "" : "not ");
3171 (void)ParseOnOff(act
, &nethackflag
);
3174 case RC_HARDCOPY_APPEND
:
3175 (void)ParseOnOff(act
, &hardcopy_append
);
3181 AddXChars(buf
, sizeof(buf
), VisualBellString
);
3182 OutputMsg(0, "vbell_msg is '%s'", buf
);
3185 (void)ParseSaveStr(act
, &VisualBellString
);
3186 debug1(" new vbellstr '%s'\n", VisualBellString
);
3189 if (ParseBase(act
, *args
, &n
, 8, "octal"))
3191 if (n
< 0 || n
> 0777)
3193 OutputMsg(0, "%s: mode: Invalid tty mode %o", rc_name
, n
);
3198 OutputMsg(0, "Ttymode set to %03o", TtyMode
);
3201 (void)ParseOnOff(act
, &auto_detach
);
3203 case RC_STARTUP_MESSAGE
:
3204 (void)ParseOnOff(act
, &default_startup
);
3210 n
= (*user
->u_password
) ? 1 : 0;
3211 if (user
->u_password
!= NullStr
) free((char *)user
->u_password
);
3212 user
->u_password
= SaveStr(*args
);
3213 if (!strcmp(user
->u_password
, "none"))
3216 OutputMsg(0, "Password checking disabled");
3217 free(user
->u_password
);
3218 user
->u_password
= NullStr
;
3225 OutputMsg(0, "%s: password: window required", rc_name
);
3228 Input("New screen password:", 100, INP_NOECHO
, pass1
, display
? (char *)D_user
: (char *)users
, 0);
3231 #endif /* PASSWORD */
3234 struct action
*ktabp
= ktab
;
3239 if (argc
> 2 && !strcmp(*args
, "-c"))
3241 ktabp
= FindKtab(args
[1], 1);
3248 else if (argc
> 1 && !strcmp(*args
, "-k"))
3261 for (n
= 0; n
< KMAP_KEYS
; n
++)
3262 if (strcmp(term
[n
+ T_CAPS
].tcname
, *args
) == 0)
3266 OutputMsg(0, "%s: bind: unknown key '%s'", rc_name
, *args
);
3275 OutputMsg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name
);
3279 n
= (unsigned char)args
[0][0];
3283 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3285 OutputMsg(0, "%s: bind: unknown command '%s'", rc_name
, args
[1]);
3288 if (CheckArgNum(i
, args
+ 2) < 0)
3290 ClearAction(&ktabp
[n
]);
3291 SaveAction(ktabp
+ n
, i
, args
+ 2, argl
+ 2);
3294 ClearAction(&ktabp
[n
]);
3300 struct action
*newact
;
3301 int newnr
, fl
= 0, kf
= 0, af
= 0, df
= 0, mf
= 0;
3302 struct display
*odisp
= display
;
3304 struct kmap_ext
*kme
;
3306 for (; *args
&& **args
== '-'; args
++, argl
++)
3308 if (strcmp(*args
, "-t") == 0)
3309 fl
= KMAP_NOTIMEOUT
;
3310 else if (strcmp(*args
, "-k") == 0)
3312 else if (strcmp(*args
, "-a") == 0)
3314 else if (strcmp(*args
, "-d") == 0)
3316 else if (strcmp(*args
, "-m") == 0)
3318 else if (strcmp(*args
, "--") == 0)
3326 OutputMsg(0, "%s: bindkey: invalid option %s", rc_name
, *args
);
3332 OutputMsg(0, "%s: bindkey: -d does not work with -m", rc_name
);
3338 display_bindkey("Edit mode", mmtab
);
3340 display_bindkey("Default", dmtab
);
3342 display_bindkey("User", umtab
);
3349 OutputMsg(0, "%s: bindkey: -a only works with -k", rc_name
);
3354 OutputMsg(0, "%s: bindkey: empty string makes no sense", rc_name
);
3357 for (i
= 0, kme
= kmap_exts
; i
< kmap_extn
; i
++, kme
++)
3364 if (*argl
== (kme
->fl
& ~KMAP_NOTIMEOUT
) && bcmp(kme
->str
, *args
, *argl
) == 0)
3370 OutputMsg(0, "%s: bindkey: keybinding not found", rc_name
);
3374 kmap_exts
= (struct kmap_ext
*)xrealloc((char *)kmap_exts
, kmap_extn
* sizeof(*kmap_exts
));
3375 kme
= kmap_exts
+ i
;
3376 bzero((char *)kme
, 8 * sizeof(*kmap_exts
));
3377 for (; i
< kmap_extn
; i
++, kme
++)
3380 kme
->dm
.nr
= kme
->mm
.nr
= kme
->um
.nr
= RC_ILLEGAL
;
3381 kme
->dm
.args
= kme
->mm
.args
= kme
->um
.args
= noargs
;
3382 kme
->dm
.argl
= kme
->mm
.argl
= kme
->um
.argl
= 0;
3387 if (df
== 0 && kme
->dm
.nr
!= RC_ILLEGAL
)
3389 if (mf
== 0 && kme
->mm
.nr
!= RC_ILLEGAL
)
3391 if ((df
|| mf
) && kme
->um
.nr
!= RC_ILLEGAL
)
3393 i
+= KMAP_KEYS
+ KMAP_AKEYS
;
3394 newact
= df
? &kme
->dm
: mf
? &kme
->mm
: &kme
->um
;
3398 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
3399 if (strcmp(term
[i
].tcname
, *args
) == 0)
3403 OutputMsg(0, "%s: bindkey: unknown key '%s'", rc_name
, *args
);
3406 if (af
&& i
>= T_CURSOR
&& i
< T_OCAPS
)
3407 i
-= T_CURSOR
- KMAP_KEYS
;
3410 newact
= df
? &dmtab
[i
] : mf
? &mmtab
[i
] : &umtab
[i
];
3414 if ((newnr
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3416 OutputMsg(0, "%s: bindkey: unknown command '%s'", rc_name
, args
[1]);
3419 if (CheckArgNum(newnr
, args
+ 2) < 0)
3421 ClearAction(newact
);
3422 SaveAction(newact
, newnr
, args
+ 2, argl
+ 2);
3423 if (kf
== 0 && args
[1])
3427 kme
->str
= SaveStrn(*args
, *argl
);
3428 kme
->fl
= fl
| *argl
;
3432 ClearAction(newact
);
3433 for (display
= displays
; display
; display
= display
->d_next
)
3434 remap(i
, args
[1] ? 1 : 0);
3435 if (kf
== 0 && !args
[1])
3437 if (!used
&& kme
->str
)
3450 if (ParseNum(act
, &n
))
3454 OutputMsg(0, "%s: maptimeout: illegal time %d", rc_name
, n
);
3459 if (*args
== 0 || msgok
)
3460 OutputMsg(0, "maptimeout is %dms", maptimeout
);
3474 UsersAcl(NULL
, argc
, args
);
3477 if (UserDel(args
[0], NULL
))
3480 OutputMsg(0, "%s removed from acl database", args
[0]);
3484 * modify a user to gain or lose rights granted to a group.
3485 * This group is actually a normal user whose rights were defined
3486 * with chacl in the usual way.
3490 if (strcmp(args
[1], "none")) /* link a user to another user */
3492 if (AclLinkUser(args
[0], args
[1]))
3495 OutputMsg(0, "User %s joined acl-group %s", args
[0], args
[1]);
3497 else /* remove all groups from user */
3500 struct aclusergroup
*g
;
3502 if (!(u
= *FindUserPtr(args
[0])))
3504 while ((g
= u
->u_group
))
3506 u
->u_group
= g
->next
;
3511 else /* show all groups of user */
3513 char buf
[256], *p
= buf
;
3516 struct aclusergroup
*g
;
3518 if (!(u
= *FindUserPtr(args
[0])))
3521 OutputMsg(0, "User %s does not exist.", args
[0]);
3528 sprintf(p
, "%s ", g
->u
->u_name
);
3536 OutputMsg(0, "%s's group%s: %s.", args
[0], (ngroups
== 1) ? "" : "s",
3537 (ngroups
== 0) ? "none" : buf
);
3542 while ((s
= *args
++))
3546 if (AclUmask(display
? D_user
: users
, s
, &err
))
3547 OutputMsg(0, "umask: %s\n", err
);
3551 if (ParseOnOff(act
, &n
))
3556 OutputMsg(0, "Multiuser mode %s", multi
? "enabled" : "disabled");
3558 #endif /* MULTIUSER */
3566 i
= D_nonblock
>= 0;
3567 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3569 if (ParseNum1000(act
, &i
))
3572 else if (!ParseSwitch(act
, &i
))
3573 i
= i
== 0 ? -1 : 1000;
3576 if (msgok
&& i
== -1)
3577 OutputMsg(0, "display set to blocking mode");
3578 else if (msgok
&& i
== 0)
3579 OutputMsg(0, "display set to nonblocking mode, no timeout");
3581 OutputMsg(0, "display set to nonblocking mode, %.10gs timeout", i
/1000.);
3583 if (D_nonblock
<= 0)
3584 evdeq(&D_blockedev
);
3586 case RC_DEFNONBLOCK
:
3587 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3589 if (ParseNum1000(act
, &defnonblock
))
3592 else if (!ParseOnOff(act
, &defnonblock
))
3593 defnonblock
= defnonblock
== 0 ? -1 : 1000;
3596 if (display
&& *rc_name
)
3598 D_nonblock
= defnonblock
;
3599 if (D_nonblock
<= 0)
3600 evdeq(&D_blockedev
);
3606 if (fore
->w_gr
== 2)
3609 if (ParseSwitch(act
, &fore
->w_gr
) == 0 && msgok
)
3610 OutputMsg(0, "Will %suse GR", fore
->w_gr
? "" : "not ");
3612 if (fore
->w_gr
== 0 && fore
->w_FontE
)
3617 if (ParseSwitch(act
, &fore
->w_c1
) == 0 && msgok
)
3618 OutputMsg(0, "Will %suse C1", fore
->w_c1
? "" : "not ");
3622 if (ParseSwitch(act
, &fore
->w_bce
) == 0 && msgok
)
3623 OutputMsg(0, "Will %serase with background color", fore
->w_bce
? "" : "not ");
3630 if (*args
&& !strcmp(args
[0], "-d"))
3633 OutputMsg(0, "encodings directory is %s", screenencodings
? screenencodings
: "<unset>");
3636 free(screenencodings
);
3637 screenencodings
= SaveStr(args
[1]);
3641 if (*args
&& !strcmp(args
[0], "-l"))
3644 OutputMsg(0, "encoding: -l: argument required");
3645 else if (LoadFontTranslation(-1, args
[1]))
3646 OutputMsg(0, "encoding: could not load utf8 encoding file");
3648 OutputMsg(0, "encoding: utf8 encoding file loaded");
3652 if (*args
&& (!strcmp(args
[0], "-l") || !strcmp(args
[0], "-d")))
3655 OutputMsg(0, "encoding: screen is not compiled for UTF-8.");
3659 for (i
= 0; i
< 2; i
++)
3663 if (!strcmp(args
[i
], "."))
3665 n
= FindEncoding(args
[i
]);
3668 OutputMsg(0, "encoding: unknown encoding '%s'", args
[i
]);
3673 WinSwitchEncoding(fore
, n
);
3674 ResetCharsets(fore
);
3676 else if (i
&& display
)
3681 case RC_DEFENCODING
:
3682 n
= FindEncoding(*args
);
3685 OutputMsg(0, "defencoding: unknown encoding '%s'", *args
);
3688 nwin_default
.encoding
= n
;
3694 n
= nwin_default
.encoding
== UTF8
;
3695 if (ParseSwitch(act
, &n
) == 0)
3697 nwin_default
.encoding
= n
? UTF8
: 0;
3699 OutputMsg(0, "Will %suse UTF-8 encoding for new windows", n
? "" : "not ");
3703 for (i
= 0; i
< 2; i
++)
3705 if (i
&& args
[i
] == 0)
3708 n
= fore
->w_encoding
!= UTF8
;
3709 else if (strcmp(args
[i
], "off") == 0)
3711 else if (strcmp(args
[i
], "on") == 0)
3715 OutputMsg(0, "utf8: illegal argument (%s)", args
[i
]);
3720 WinSwitchEncoding(fore
, n
? UTF8
: 0);
3722 OutputMsg(0, "Will %suse UTF-8 encoding", n
? "" : "not ");
3725 D_encoding
= n
? UTF8
: 0;
3739 printcmd
= SaveStr(*args
);
3741 if (*args
== 0 || msgok
)
3744 OutputMsg(0, "using '%s' as print command", printcmd
);
3746 OutputMsg(0, "using termcap entries for printing");
3752 if (argl
&& argl
[0] > 0 && argl
[1] > 0)
3756 OutputMsg(0, "Two characters expected to define a digraph");
3759 i
= digraph_find(args
[0]);
3760 digraphs
[i
].d
[0] = args
[0][0];
3761 digraphs
[i
].d
[1] = args
[0][1];
3762 if (!parse_input_int(args
[1], argl
[1], &digraphs
[i
].value
))
3764 if (!(digraphs
[i
].value
= atoi(args
[1])))
3767 digraphs
[i
].value
= (int)args
[1][0];
3772 unsigned char *s
= args
[1];
3773 digraphs
[i
].value
= 0;
3776 t
= FromUtf8(*s
++, &digraphs
[i
].value
);
3780 digraphs
[i
].value
= 0;
3782 digraphs
[i
].value
= t
;
3791 Input("Enter digraph: ", 10, INP_EVERY
, digraph_fn
, NULL
, 0);
3792 if (*args
&& **args
)
3805 if (nwin_default
.hstatus
)
3806 AddXChars(buf
, sizeof(buf
), nwin_default
.hstatus
);
3807 OutputMsg(0, "default hstatus is '%s'", buf
);
3810 (void)ParseSaveStr(act
, &nwin_default
.hstatus
);
3811 if (*nwin_default
.hstatus
== 0)
3813 free(nwin_default
.hstatus
);
3814 nwin_default
.hstatus
= 0;
3818 (void)ParseSaveStr(act
, &fore
->w_hstatus
);
3819 if (*fore
->w_hstatus
== 0)
3821 free(fore
->w_hstatus
);
3822 fore
->w_hstatus
= 0;
3824 WindowChanged(fore
, 'h');
3834 if (nwin_default
.charset
)
3835 AddXChars(buf
, sizeof(buf
), nwin_default
.charset
);
3836 OutputMsg(0, "default charset is '%s'", buf
);
3840 if (n
== 0 || n
> 6)
3842 OutputMsg(0, "%s: %s: string has illegal size.", rc_name
, comms
[nr
].name
);
3846 ((args
[0][4] < '0' || args
[0][4] > '3') && args
[0][4] != '.') ||
3847 ((args
[0][5] < '0' || args
[0][5] > '3') && args
[0][5] && args
[0][5] != '.')))
3849 OutputMsg(0, "%s: %s: illegal mapping number.", rc_name
, comms
[nr
].name
);
3852 if (nr
== RC_CHARSET
)
3854 SetCharsets(fore
, *args
);
3857 if (nwin_default
.charset
)
3858 free(nwin_default
.charset
);
3859 nwin_default
.charset
= SaveStr(*args
);
3865 if (*s
>= '0' && *s
<= '9')
3868 for (i
= 0; i
< 8; i
++)
3869 if (*s
== "dubrsBiI"[i
])
3873 if (*s
&& s
[1] && !s
[2])
3875 if (*s
== 'd' && s
[1] == 'd')
3877 else if (*s
== '.' && s
[1] == 'd')
3879 else if (*s
== 'd' && s
[1] == '.')
3881 else if (*s
!= '.' || s
[1] != '.')
3885 if (*s
|| i
< 0 || i
>= 8)
3887 OutputMsg(0, "%s: attrcolor: unknown attribute '%s'.", rc_name
, args
[0]);
3892 n
= ParseAttrColor(args
[1], args
[2], 1);
3895 attr2color
[i
][nr
] = n
;
3897 for (i
= 0; i
< 8; i
++)
3898 if (attr2color
[i
][0] || attr2color
[i
][1] || attr2color
[i
][2] || attr2color
[i
][3])
3905 if (strcmp(args
[0], "bell") == 0)
3909 else if (strcmp(args
[0], "monitor") == 0)
3913 else if (strcmp(args
[0], "silence") == 0)
3917 else if (strcmp(args
[0], "so") != 0)
3919 OutputMsg(0, "Invalid option '%s' for rendition", args
[0]);
3928 renditions
[i
] = ParseAttrColor(args
[0], args
[1], 1);
3929 WindowChanged((struct win
*)0, 'w');
3930 WindowChanged((struct win
*)0, 'W');
3931 WindowChanged((struct win
*)0, 0);
3935 /* We are here, means we want to set the sorendition. */
3937 case RC_SORENDITION
:
3941 i
= ParseAttrColor(*args
, args
[1], 1);
3944 ApplyAttrColor(i
, &mchar_so
);
3945 WindowChanged((struct win
*)0, 0);
3946 debug2("--> %x %x\n", mchar_so
.attr
, mchar_so
.color
);
3950 OutputMsg(0, "Standout attributes 0x%02x color 0x%02x", (unsigned char)mchar_so
.attr
, 0x99 ^ (unsigned char)mchar_so
.color
);
3952 OutputMsg(0, "Standout attributes 0x%02x ", (unsigned char)mchar_so
.attr
);
3965 OutputMsg(0, "%s:%s screen login", HostName
, SockPath
);
3966 InputSu(D_fore
, &D_user
, NULL
);
3969 InputSu(D_fore
, &D_user
, args
[0]);
3971 s
= DoSu(&D_user
, args
[0], args
[1], "\377");
3973 s
= DoSu(&D_user
, args
[0], args
[1], args
[2]);
3975 OutputMsg(0, "%s", s
);
3977 #endif /* MULTIUSER */
3980 if (s
&& !strcmp(s
, "-v"))
3981 AddCanvas(SLICE_HORI
);
3983 AddCanvas(SLICE_VERT
);
3995 D_forecv
->c_xoff
= D_forecv
->c_xs
;
3996 D_forecv
->c_yoff
= D_forecv
->c_ys
;
3997 RethinkViewportOffsets(D_forecv
);
3998 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
3999 flayer
= D_forecv
->c_layer
;
4004 struct canvas
*cv
= 0;
4005 if (!*args
|| !strcmp(*args
, "next"))
4006 cv
= D_forecv
->c_next
? D_forecv
->c_next
: D_cvlist
;
4007 else if (!strcmp(*args
, "prev"))
4009 for (cv
= D_cvlist
; cv
->c_next
&& cv
->c_next
!= D_forecv
; cv
= cv
->c_next
)
4012 else if (!strcmp(*args
, "top"))
4014 else if (!strcmp(*args
, "bottom"))
4016 for (cv
= D_cvlist
; cv
->c_next
; cv
= cv
->c_next
)
4019 else if (!strcmp(*args
, "up"))
4020 cv
= FindCanvas(D_forecv
->c_xs
, D_forecv
->c_ys
- 1);
4021 else if (!strcmp(*args
, "down"))
4022 cv
= FindCanvas(D_forecv
->c_xs
, D_forecv
->c_ye
+ 2);
4023 else if (!strcmp(*args
, "left"))
4024 cv
= FindCanvas(D_forecv
->c_xs
- 1, D_forecv
->c_ys
);
4025 else if (!strcmp(*args
, "right"))
4026 cv
= FindCanvas(D_forecv
->c_xe
+ 1, D_forecv
->c_ys
);
4029 OutputMsg(0, "%s: usage: focus [next|prev|up|down|left|right|top|bottom]", rc_name
);
4032 SetForeCanvas(display
, cv
);
4037 if (D_forecv
->c_slorient
== SLICE_UNKN
)
4039 OutputMsg(0, "resize: need more than one region");
4042 for (; *args
; args
++)
4044 if (!strcmp(*args
, "-h"))
4046 else if (!strcmp(*args
, "-v"))
4048 else if (!strcmp(*args
, "-b"))
4049 i
|= RESIZE_FLAG_H
| RESIZE_FLAG_V
;
4050 else if (!strcmp(*args
, "-p"))
4051 i
|= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
4052 else if (!strcmp(*args
, "-l"))
4057 if (*args
&& args
[1])
4059 OutputMsg(0, "%s: usage: resize [-h] [-v] [-l] [num]\n", rc_name
);
4063 ResizeRegions(*args
, i
);
4065 Input(resizeprompts
[i
], 20, INP_EVERY
, ResizeFin
, (char*)0, i
);
4068 (void)ParseSwitch(act
, &separate_sids
);
4071 args
= SaveArgs(args
);
4072 for (i
= 0; args
[i
]; i
++)
4075 Colonfin(args
[i
], strlen(args
[i
]), (char *)0);
4081 (void)ParseSwitch(act
, &use_altscreen
);
4083 OutputMsg(0, "Will %sdo alternate screen switching", use_altscreen
? "" : "not ");
4088 OutputMsg(0, "maximum windows allowed: %d", maxwin
);
4091 if (ParseNum(act
, &n
))
4094 OutputMsg(0, "illegal maxwin number specified");
4096 OutputMsg(0, "maximum 2048 windows allowed");
4097 else if (n
> maxwin
&& windows
)
4098 OutputMsg(0, "may increase maxwin only when there's no window");
4102 wtab
= realloc(wtab
, n
* sizeof(struct win
*));
4107 if (ParseBase(act
, *args
, &n
, 10, "decimal"))
4110 setbacktick(n
, 0, 0, (char **)0);
4116 OutputMsg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name
);
4119 if (ParseBase(act
, args
[1], &lifespan
, 10, "decimal"))
4121 if (ParseBase(act
, args
[2], &tick
, 10, "decimal"))
4123 setbacktick(n
, lifespan
, tick
, SaveArgs(args
+ 3));
4125 WindowChanged(0, '`');
4131 RunBlanker(blankerprg
);
4136 CursorVisibility(-1);
4145 char path
[MAXPATHLEN
];
4146 char *p
= path
, **pp
;
4147 for (pp
= blankerprg
; *pp
; pp
++)
4148 p
+= snprintf(p
, sizeof(path
) - (p
- path
) - 1, "%s ", *pp
);
4150 OutputMsg(0, "blankerprg: %s", path
);
4153 OutputMsg(0, "No blankerprg set.");
4159 for (pp
= blankerprg
; *pp
; pp
++)
4165 blankerprg
= SaveArgs(args
);
4171 struct display
*olddisplay
= display
;
4172 if (!strcmp(*args
, "off"))
4174 else if (args
[0][0])
4175 idletimo
= atoi(*args
) * 1000;
4178 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
4180 OutputMsg(0, "%s: idle: unknown command '%s'", rc_name
, args
[1]);
4183 if (CheckArgNum(i
, args
+ 2) < 0)
4185 ClearAction(&idleaction
);
4186 SaveAction(&idleaction
, i
, args
+ 2, argl
+ 2);
4188 for (display
= displays
; display
; display
= display
->d_next
)
4190 display
= olddisplay
;
4195 OutputMsg(0, "idle timeout %ds, %s", idletimo
/ 1000, comms
[idleaction
.nr
].name
);
4197 OutputMsg(0, "idle off");
4200 case RC_FOCUSMINSIZE
:
4201 for (i
= 0; i
< 2 && args
[i
]; i
++)
4203 if (!strcmp(args
[i
], "max") || !strcmp(args
[i
], "_"))
4215 for (i
= 0; i
< 2; i
++)
4217 n
= i
== 0 ? focusminwidth
: focusminheight
;
4219 strcpy(b
[i
], "max");
4221 sprintf(b
[i
], "%d", n
);
4223 OutputMsg(0, "focus min size is %s %s\n", b
[0], b
[1]);
4232 fore
->w_group
= WindowByName(*args
);
4233 if (fore
->w_group
== fore
|| (fore
->w_group
&& fore
->w_group
->w_type
!= W_TYPE_GROUP
))
4236 WindowChanged((struct win
*)0, 'w');
4237 WindowChanged((struct win
*)0, 'W');
4238 WindowChanged((struct win
*)0, 0);
4243 OutputMsg(0, "window group is %d (%s)\n", fore
->w_group
->w_number
, fore
->w_group
->w_title
);
4245 OutputMsg(0, "window belongs to no group");
4249 if (!strcmp(args
[0], "title"))
4253 OutputMsg(0, "not on a layout");
4258 OutputMsg(0, "current layout is %d (%s)", D_layout
->lay_number
, D_layout
->lay_title
);
4261 free(D_layout
->lay_title
);
4262 D_layout
->lay_title
= SaveStr(args
[1]);
4264 else if (!strcmp(args
[0], "number"))
4270 OutputMsg(0, "not on a layout");
4275 OutputMsg(0, "This is layout %d (%s).\n", D_layout
->lay_number
, D_layout
->lay_title
);
4278 old
= D_layout
->lay_number
;
4280 if (n
< 0 || n
>= MAXLAY
)
4283 laytab
[n
] = D_layout
;
4284 D_layout
->lay_number
= n
;
4287 lay
->lay_number
= old
;
4290 else if (!strcmp(args
[0], "autosave"))
4294 OutputMsg(0, "not on a layout");
4299 if (!strcmp(args
[1], "on"))
4300 D_layout
->lay_autosave
= 1;
4301 else if (!strcmp(args
[1], "off"))
4302 D_layout
->lay_autosave
= 0;
4305 OutputMsg(0, "invalid argument. Give 'on' or 'off");
4310 OutputMsg(0, "autosave is %s", D_layout
->lay_autosave
? "on" : "off");
4312 else if (!strcmp(args
[0], "new"))
4318 while (*t
>= '0' && *t
<= '9')
4320 if (t
!= args
[1] && (!*t
|| *t
== ':'))
4334 else if (!strcmp(args
[0], "save"))
4338 OutputMsg(0, "usage: layout save <name>");
4341 SaveLayout(args
[1], &D_canvas
);
4343 else if (!strcmp(args
[0], "select"))
4347 Input("Switch to layout: ", 20, INP_COOKED
, SelectLayoutFin
, NULL
, 0);
4350 SelectLayoutFin(args
[1], strlen(args
[1]), (char *)0);
4352 else if (!strcmp(args
[0], "next"))
4354 struct layout
*lay
= D_layout
;
4356 lay
= lay
->lay_next
? lay
->lay_next
: layouts
;
4361 OutputMsg(0, "no layout defined");
4364 if (lay
== D_layout
)
4366 LoadLayout(lay
, &D_canvas
);
4369 else if (!strcmp(args
[0], "prev"))
4371 struct layout
*lay
= D_layout
;
4374 for (lay
= layouts
; lay
->lay_next
&& lay
->lay_next
!= D_layout
; lay
= lay
->lay_next
)
4381 OutputMsg(0, "no layout defined");
4384 if (lay
== D_layout
)
4386 LoadLayout(lay
, &D_canvas
);
4389 else if (!strcmp(args
[0], "attach"))
4394 OutputMsg(0, "no attach layout set");
4395 else if (layout_attach
== &layout_last_marker
)
4396 OutputMsg(0, "will attach to last layout");
4398 OutputMsg(0, "will attach to layout %d (%s)", layout_attach
->lay_number
, layout_attach
->lay_title
);
4401 if (!strcmp(args
[1], ":last"))
4402 layout_attach
= &layout_last_marker
;
4403 else if (!args
[1][0])
4408 lay
= FindLayout(args
[1]);
4411 OutputMsg(0, "unknown layout '%s'", args
[1]);
4414 layout_attach
= lay
;
4417 else if (!strcmp(args
[0], "show"))
4421 else if (!strcmp(args
[0], "remove"))
4423 struct layout
*lay
= display
? D_layout
: layouts
;
4426 lay
= layouts
? FindLayout(args
[1]) : (struct layout
*)0;
4429 OutputMsg(0, "unknown layout '%s'", args
[1]);
4436 else if (!strcmp(args
[0], "dump"))
4439 OutputMsg(0, "Must have a display for 'layout dump'.");
4440 else if (!LayoutDumpCanvas(&D_canvas
, args
[1] ? args
[1] : "layout-dump"))
4441 OutputMsg(errno
, "Error dumping layout.");
4443 OutputMsg(0, "Layout dumped to \"%s\"", args
[1] ? args
[1] : "layout-dump");
4446 OutputMsg(0, "unknown layout subcommand");
4450 if(ParseSwitch(act
, &cjkwidth
) == 0)
4453 OutputMsg(0, "Treat ambiguous width characters as %s width", cjkwidth
? "full" : "half");
4459 /* key == -2: input from braille keybord, msgok always 0 */
4460 DoBrailleAction(act
, key
== -2 ? 0 : msgok
);
4464 if (display
!= odisplay
)
4466 for (display
= displays
; display
; display
= display
->d_next
)
4467 if (display
== odisplay
)
4474 DoCommand(argv
, argl
)
4479 const char *cmd
= *argv
;
4482 /* For now, we actually treat both 'supress error' and 'suppress normal message' as the
4483 * same, and ignore all messages on either flag. If we wanted to do otherwise, we would
4484 * need to change the definition of 'OutputMsg' slightly. */
4485 if (*cmd
== '@') /* Suppress error */
4490 if (*cmd
== '-') /* Suppress normal message */
4496 if ((act
.nr
= FindCommnr(cmd
)) == RC_ILLEGAL
)
4498 Msg(0, "%s: unknown command '%s'", rc_name
, cmd
);
4501 act
.args
= argv
+ 1;
4502 act
.argl
= argl
+ 1;
4507 SaveAction(act
, nr
, args
, argl
)
4513 register int argc
= 0;
4527 if ((pp
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4528 Panic(0, "%s", strnomem
);
4529 if ((lp
= (int *)malloc((unsigned)(argc
) * sizeof(int *))) == 0)
4530 Panic(0, "%s", strnomem
);
4536 *lp
= argl
? *argl
++ : (int)strlen(*args
);
4537 *pp
++ = SaveStrn(*args
++, *lp
++);
4546 register char **ap
, **pp
;
4547 register int argc
= 0;
4551 if ((pp
= ap
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4552 Panic(0, "%s", strnomem
);
4554 *pp
++ = SaveStr(*args
++);
4561 * buf is split into argument vector args.
4562 * leading whitespace is removed.
4563 * @!| abbreviations are expanded.
4564 * the end of buffer is recognized by '\0' or an un-escaped '#'.
4565 * " and ' are interpreted.
4570 Parse(buf
, bufl
, args
, argl
)
4574 register char *p
= buf
, **ap
= args
, *pp
;
4575 register int delim
, argc
;
4578 debug2("Parse %d %s\n", bufl
, buf
);
4585 while (*p
&& (*p
== ' ' || *p
== '\t'))
4588 if (argc
== 0 && *p
== '!')
4597 if (*p
== '\0' || *p
== '#' || *p
== '\n')
4600 for (delim
= 0; delim
< argc
; delim
++)
4601 debug1("-- %s\n", args
[delim
]);
4605 if (++argc
>= MAXARGS
)
4607 Msg(0, "%s: too many tokens.", rc_name
);
4612 debug1("- new arg %s\n", p
);
4617 else if (delim
!= '\'' && *p
== '\\' && (p
[1] == 'n' || p
[1] == 'r' || p
[1] == 't' || p
[1] == '\'' || p
[1] == '"' || p
[1] == '\\' || p
[1] == '$' || p
[1] == '#' || p
[1] == '^' || (p
[1] >= '0' && p
[1] <= '7')))
4620 if (*p
>= '0' && *p
<= '7')
4623 if (p
[1] >= '0' && p
[1] <= '7')
4626 *pp
= (*pp
<< 3) | (*p
- '0');
4627 if (p
[1] >= '0' && p
[1] <= '7')
4630 *pp
= (*pp
<< 3) | (*p
- '0');
4639 case 'n': *pp
= '\n'; break;
4640 case 'r': *pp
= '\r'; break;
4641 case 't': *pp
= '\t'; break;
4642 default: *pp
= *p
; break;
4647 else if (delim
!= '\'' && *p
== '$' && (p
[1] == '{' || p
[1] == ':' || (p
[1] >= 'a' && p
[1] <= 'z') || (p
[1] >= 'A' && p
[1] <= 'Z') || (p
[1] >= '0' && p
[1] <= '9') || p
[1] == '_'))
4650 char *ps
, *pe
, op
, *v
, xbuf
[11], path
[MAXPATHLEN
];
4654 debug1("- var %s\n", ps
);
4658 if (*ps
== '{' && *p
== '}')
4660 if (*ps
== ':' && *p
== ':')
4662 if (*ps
!= '{' && *ps
!= ':' && (*p
< 'a' || *p
> 'z') && (*p
< 'A' || *p
> 'Z') && (*p
< '0' || *p
> '9') && *p
!= '_')
4667 if (*ps
== '{' || *ps
== ':')
4671 Msg(0, "%s: bad variable name.", rc_name
);
4678 debug1("- var is '%s'\n", ps
);
4680 v
= gettermcapstring(ps
+ 1);
4686 if (!strcmp(ps
, "TERM"))
4687 v
= display
? D_termname
: "unknown";
4688 else if (!strcmp(ps
, "COLUMNS"))
4689 sprintf(xbuf
, "%d", display
? D_width
: -1);
4690 else if (!strcmp(ps
, "LINES"))
4691 sprintf(xbuf
, "%d", display
? D_height
: -1);
4692 else if (!strcmp(ps
, "PID"))
4693 sprintf(xbuf
, "%d", getpid());
4694 else if (!strcmp(ps
, "PWD"))
4696 if (getcwd(path
, sizeof(path
) - 1) == 0)
4701 else if (!strcmp(ps
, "STY"))
4703 if ((v
= strchr(SockName
, '.'))) /* Skip the PID */
4712 vl
= v
? strlen(v
) : 0;
4715 debug1("- sub is '%s'\n", v
);
4718 int right
= buf
+ bufl
- (p
+ strlen(p
) + 1);
4721 bcopy(p
, p
+ right
, strlen(p
) + 1);
4727 Msg(0, "%s: no space left for variable expansion.", rc_name
);
4735 else if (delim
!= '\'' && *p
== '^' && p
[1])
4738 *pp
++ = *p
== '?' ? '\177' : *p
& 0x1f;
4740 else if (delim
== 0 && (*p
== '\'' || *p
== '"'))
4742 else if (delim
== 0 && (*p
== ' ' || *p
== '\t' || *p
== '\n'))
4750 Msg(0, "%s: Missing %c quote.", rc_name
, delim
);
4756 debug2("- arg done, '%s' rest %s\n", ap
[-1], p
);
4757 *lp
++ = pp
- ap
[-1];
4776 if (DefaultEsc
>= 0)
4777 ClearAction(&ktab
[DefaultEsc
]);
4778 if (DefaultMetaEsc
>= 0)
4779 ClearAction(&ktab
[DefaultMetaEsc
]);
4782 DefaultMetaEsc
= me
;
4785 if (DefaultEsc
>= 0)
4787 ClearAction(&ktab
[DefaultEsc
]);
4788 ktab
[DefaultEsc
].nr
= RC_OTHER
;
4790 if (DefaultMetaEsc
>= 0)
4792 ClearAction(&ktab
[DefaultMetaEsc
]);
4793 ktab
[DefaultMetaEsc
].nr
= RC_META
;
4800 ParseSwitch(act
, var
)
4804 if (*act
->args
== 0)
4809 return ParseOnOff(act
, var
);
4813 ParseOnOff(act
, var
)
4817 register int num
= -1;
4818 char **args
= act
->args
;
4822 if (strcmp(args
[0], "on") == 0)
4824 else if (strcmp(args
[0], "off") == 0)
4829 Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name
, comms
[act
->nr
].name
);
4837 ParseSaveStr(act
, var
)
4841 char **args
= act
->args
;
4842 if (*args
== 0 || args
[1])
4844 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4849 *var
= SaveStr(*args
);
4859 char *p
, **args
= act
->args
;
4862 if (p
== 0 || *p
== 0 || args
[1])
4864 Msg(0, "%s: %s: invalid argument. Give one argument.",
4865 rc_name
, comms
[act
->nr
].name
);
4871 if (*p
>= '0' && *p
<= '9')
4872 i
= 10 * i
+ (*p
- '0');
4875 Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4876 rc_name
, comms
[act
->nr
].name
);
4881 debug1("ParseNum got %d\n", i
);
4887 ParseNum1000(act
, var
)
4892 char *p
, **args
= act
->args
;
4896 if (p
== 0 || *p
== 0 || args
[1])
4898 Msg(0, "%s: %s: invalid argument. Give one argument.",
4899 rc_name
, comms
[act
->nr
].name
);
4905 if (*p
>= '0' && *p
<= '9')
4908 i
= 10 * i
+ (*p
- '0');
4909 else if (dig
== 4 && *p
>= '5')
4914 else if (*p
== '.' && !dig
)
4918 Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4919 rc_name
, comms
[act
->nr
].name
);
4930 i
= (int)((unsigned int)~0 >> 1);
4931 debug1("ParseNum1000 got %d\n", i
);
4942 for (p
= windows
; p
; p
= p
->w_next
)
4943 if (!strcmp(p
->w_title
, s
))
4945 for (p
= windows
; p
; p
= p
->w_next
)
4946 if (!strncmp(p
->w_title
, s
, strlen(s
)))
4958 for (i
= 0, s
= str
; *s
; s
++)
4960 if (*s
< '0' || *s
> '9')
4962 i
= i
* 10 + (*s
- '0');
4968 * Get window number from Name or Number string.
4969 * Numbers are tried first, then names, a prefix match suffices.
4970 * Be careful when assigning numeric strings as WindowTitles.
4979 if ((i
= WindowByNumber(str
)) < 0 || i
>= maxwin
)
4981 if ((p
= WindowByName(str
)))
4989 ParseWinNum(act
, var
)
4993 char **args
= act
->args
;
4996 if (*args
== 0 || args
[1])
4998 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
5002 i
= WindowByNoN(*args
);
5005 Msg(0, "%s: %s: invalid argument. Give window number or name.",
5006 rc_name
, comms
[act
->nr
].name
);
5009 debug1("ParseWinNum got %d\n", i
);
5015 ParseBase(act
, p
, var
, base
, bname
)
5027 Msg(0, "%s: %s: empty argument.", rc_name
, comms
[act
->nr
].name
);
5032 if (c
>= 'a' && c
<= 'z')
5034 if (c
>= 'A' && c
<= 'Z')
5035 c
-= 'A' - ('0' + 10);
5037 if (c
< 0 || c
>= base
)
5039 Msg(0, "%s: %s: argument is not %s.", rc_name
, comms
[act
->nr
].name
, bname
);
5044 debug1("ParseBase got %d\n", i
);
5054 for (base
+= '0'; *s
; ++s
)
5055 if (*s
< '0' || *s
> base
)
5061 IsNumColon(s
, base
, p
, psize
)
5066 if ((q
= rindex(s
, ':')) != 0)
5068 strncpy(p
, q
+ 1, psize
- 1);
5069 p
[psize
- 1] = '\0';
5074 return IsNum(s
, base
);
5083 debug1("SwitchWindow %d\n", n
);
5084 if (n
< 0 || n
>= maxwin
)
5089 if ((p
= wtab
[n
]) == 0)
5101 Msg(0, "This IS window %d (%s).", n
, p
->w_title
);
5105 if (AclCheckPermWin(D_user
, ACL_READ
, p
))
5107 Msg(0, "Access to window %d denied.", p
->w_number
);
5112 Activate(fore
->w_norefresh
);
5116 * SetForeWindow changes the window in the input focus of the display.
5117 * Puts window wi in canvas display->d_forecv.
5129 p
= Layer2Window(D_forecv
->c_layer
);
5130 SetCanvasWindow(D_forecv
, wi
);
5132 WindowChanged(p
, 'u');
5134 WindowChanged(wi
, 'u');
5135 flayer
= D_forecv
->c_layer
;
5136 /* Activate called afterwards, so no RefreshHStatus needed */
5140 /*****************************************************************/
5143 * Activate - make fore window active
5144 * norefresh = -1 forces a refresh, disregard all_norefresh then.
5150 debug1("Activate(%d)\n", norefresh
);
5155 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
5159 if (MayResizeLayer(D_forecv
->c_layer
))
5160 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, display
);
5166 if (fore
->w_monitor
!= MON_OFF
)
5167 fore
->w_monitor
= MON_ON
;
5168 fore
->w_bell
= BELL_ON
;
5169 WindowChanged(fore
, 'f');
5172 if (ResizeDisplay(fore
->w_width
, fore
->w_height
))
5174 debug2("Cannot resize from (%d,%d)", D_width
, D_height
);
5175 debug2(" to (%d,%d) -> resize window\n", fore
->w_width
, fore
->w_height
);
5176 DoResize(D_width
, D_height
);
5180 Redisplay(norefresh
+ all_norefresh
);
5187 register struct win
**pp
;
5188 int n
= fore
? fore
->w_number
: maxwin
;
5189 struct win
*group
= fore
? fore
->w_group
: 0;
5191 for (pp
= fore
? wtab
+ n
+ 1 : wtab
; pp
!= wtab
+ n
; pp
++)
5193 if (pp
== wtab
+ maxwin
)
5197 if (!fore
|| group
== (*pp
)->w_group
)
5209 register struct win
**pp
;
5210 int n
= fore
? fore
->w_number
: -1;
5211 struct win
*group
= fore
? fore
->w_group
: 0;
5213 for (pp
= wtab
+ n
- 1; pp
!= wtab
+ n
; pp
--)
5216 pp
= wtab
+ maxwin
- 1;
5219 if (!fore
|| group
== (*pp
)->w_group
)
5231 char *m
= "No other window.";
5232 if (windows
&& (fore
== 0 || windows
->w_next
))
5236 Msg(0, "No window available");
5239 Msg(0, m
, fore
->w_number
); /* other arg for nethack */
5247 struct win
**pp
, *p
;
5253 * Remove window from linked list.
5255 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5261 wtab
[wi
->w_number
] = 0;
5270 * switch to different window on all canvases
5272 for (display
= displays
; display
; display
= display
->d_next
)
5275 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5277 if (Layer2Window(cv
->c_layer
) != wi
)
5279 /* switch to other window */
5280 SetCanvasWindow(cv
, FindNiceWindow(D_other
, 0));
5286 if (wi
->w_zdisplay
== display
)
5289 D_readev
.condpos
= D_readev
.condneg
= 0;
5296 /* do the same for the layouts */
5297 for (lay
= layouts
; lay
; lay
= lay
->lay_next
)
5298 UpdateLayoutCanvas(&lay
->lay_canvas
, wi
);
5301 WindowChanged((struct win
*)0, 'w');
5302 WindowChanged((struct win
*)0, 'W');
5303 WindowChanged((struct win
*)0, 0);
5312 if ((fore
->w_log
!= 0) == on
)
5314 if (display
&& !*rc_name
)
5315 Msg(0, "You are %s logging.", on
? "already" : "not");
5318 if (fore
->w_log
!= 0)
5320 Msg(0, "Logfile \"%s\" closed.", fore
->w_log
->name
);
5321 logfclose(fore
->w_log
);
5323 WindowChanged(fore
, 'f');
5326 if (DoStartLog(fore
, buf
, sizeof(buf
)))
5328 Msg(errno
, "Error opening logfile \"%s\"", buf
);
5331 if (ftell(fore
->w_log
->fp
) == 0)
5332 Msg(0, "Creating logfile \"%s\".", fore
->w_log
->name
);
5334 Msg(0, "Appending to logfile \"%s\".", fore
->w_log
->name
);
5335 WindowChanged(fore
, 'f');
5339 AddWindows(buf
, len
, flags
, where
)
5345 register char *s
, *ss
;
5346 register struct win
**pp
, *p
;
5351 if ((flags
& 8) && where
< 0)
5356 for (pp
= ((flags
& 4) && where
>= 0) ? wtab
+ where
+ 1: wtab
; pp
< wtab
+ maxwin
; pp
++)
5359 if (pp
- wtab
== where
&& ss
== buf
)
5363 if ((flags
& 1) && display
&& p
== D_fore
)
5365 if (display
&& D_fore
&& D_fore
->w_group
!= p
->w_group
)
5372 if (s
- buf
+ l
> len
- 24)
5374 if (s
> buf
|| (flags
& 4))
5379 if (p
->w_number
== where
)
5385 if (!(flags
& 4) || where
< 0 || ((flags
& 4) && where
< p
->w_number
))
5387 if (p
->w_monitor
== MON_DONE
&& renditions
[REND_MONITOR
] != -1)
5388 rend
= renditions
[REND_MONITOR
];
5389 else if ((p
->w_bell
== BELL_DONE
|| p
->w_bell
== BELL_FOUND
) && renditions
[REND_BELL
] != -1)
5390 rend
= renditions
[REND_BELL
];
5391 else if ((p
->w_silence
== SILENCE_FOUND
|| p
->w_silence
== SILENCE_DONE
) && renditions
[REND_SILENCE
] != -1)
5392 rend
= renditions
[REND_SILENCE
];
5395 AddWinMsgRend(s
, rend
);
5396 sprintf(s
, "%d", p
->w_number
);
5398 if (display
&& p
== D_fore
)
5402 if (display
&& p
== D_other
)
5404 s
= AddWindowFlags(s
, len
, p
);
5410 AddWinMsgRend(s
, -1);
5417 AddWindowFlags(buf
, len
, p
)
5423 if (p
== 0 || len
< 12)
5429 if (display
&& p
== D_fore
)
5431 if (display
&& p
== D_other
)
5434 if (p
->w_layer
.l_cvlist
&& p
->w_layer
.l_cvlist
->c_lnext
)
5436 if (p
->w_monitor
== MON_DONE
5438 && (ACLBYTE(p
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5442 if (p
->w_bell
== BELL_DONE
)
5445 if (p
->w_slot
!= (slot_t
) 0 && p
->w_slot
!= (slot_t
) -1)
5453 if (p
->w_ptyfd
< 0 && p
->w_type
!= W_TYPE_GROUP
)
5460 AddOtherUsers(buf
, len
, p
)
5465 struct display
*d
, *olddisplay
= display
;
5471 for (display
= displays
; display
; display
= display
->d_next
)
5473 if (olddisplay
&& D_user
== olddisplay
->d_user
)
5475 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5476 if (Layer2Window(cv
->c_layer
) == p
)
5480 for (d
= displays
; d
&& d
!= display
; d
= d
->d_next
)
5481 if (D_user
== d
->d_user
)
5483 if (d
&& d
!= display
)
5485 if (len
> 1 && s
!= buf
)
5490 l
= strlen(D_user
->u_name
);
5493 strcpy(s
, D_user
->u_name
);
5498 display
= olddisplay
;
5509 if (display
&& where
== -1 && D_fore
)
5510 where
= D_fore
->w_number
;
5511 ss
= AddWindows(buf
, sizeof(buf
), 0, where
);
5512 s
= buf
+ strlen(buf
);
5513 if (display
&& ss
- buf
> D_width
/ 2)
5516 if (s
- ss
< D_width
)
5532 register struct win
*wp
= fore
;
5537 Msg(0, "(%d,%d)/(%d,%d) no window", D_x
+ 1, D_y
+ 1, D_width
, D_height
);
5541 if (buf
< (p
+= GetAnsiStatus(wp
, p
)))
5543 sprintf(p
, "(%d,%d)/(%d,%d)",
5544 wp
->w_x
+ 1, wp
->w_y
+ 1, wp
->w_width
, wp
->w_height
);
5546 sprintf(p
+= strlen(p
), "+%d", wp
->w_histheight
);
5548 sprintf(p
+= strlen(p
), " %c%sflow",
5549 (wp
->w_flow
& FLOW_NOW
) ? '+' : '-',
5550 (wp
->w_flow
& FLOW_AUTOFLAG
) ? "" :
5551 ((wp
->w_flow
& FLOW_AUTO
) ? "(+)" : "(-)"));
5552 if (!wp
->w_wrap
) sprintf(p
+= strlen(p
), " -wrap");
5553 if (wp
->w_insert
) sprintf(p
+= strlen(p
), " ins");
5554 if (wp
->w_origin
) sprintf(p
+= strlen(p
), " org");
5555 if (wp
->w_keypad
) sprintf(p
+= strlen(p
), " app");
5556 if (wp
->w_log
) sprintf(p
+= strlen(p
), " log");
5557 if (wp
->w_monitor
!= MON_OFF
5559 && (ACLBYTE(wp
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5562 sprintf(p
+= strlen(p
), " mon");
5563 if (wp
->w_mouse
) sprintf(p
+= strlen(p
), " mouse");
5565 if (wp
->w_bce
) sprintf(p
+= strlen(p
), " bce");
5567 if (!wp
->w_c1
) sprintf(p
+= strlen(p
), " -c1");
5568 if (wp
->w_norefresh
) sprintf(p
+= strlen(p
), " nored");
5573 if (wp
->w_encoding
&& (display
== 0 || D_encoding
!= wp
->w_encoding
|| EncodingDefFont(wp
->w_encoding
) <= 0))
5576 strcpy(p
, EncodingName(wp
->w_encoding
));
5580 if (wp
->w_encoding
!= UTF8
)
5583 if (D_CC0
|| (D_CS0
&& *D_CS0
))
5587 sprintf(p
, " G%c", wp
->w_Charset
+ '0');
5588 if (wp
->w_FontE
>= ' ')
5593 p
[4] = wp
->w_FontE
^ 0x40;
5600 sprintf(p
++, " G%c%c[", wp
->w_Charset
+ '0', wp
->w_CharsetR
+ '0');
5602 sprintf(p
, " G%c[", wp
->w_Charset
+ '0');
5604 for (i
= 0; i
< 4; i
++)
5606 if (wp
->w_charsets
[i
] == ASCII
)
5608 else if (wp
->w_charsets
[i
] >= ' ')
5609 *p
++ = wp
->w_charsets
[i
];
5613 *p
++ = wp
->w_charsets
[i
] ^ 0x40;
5621 if (wp
->w_type
== W_TYPE_PLAIN
)
5623 /* add info about modem control lines */
5625 TtyGetModemStatus(wp
->w_ptyfd
, p
);
5627 #ifdef BUILTIN_TELNET
5628 else if (wp
->w_type
== W_TYPE_TELNET
)
5631 TelStatus(wp
, p
, sizeof(buf
) - 1 - (p
- buf
));
5634 Msg(0, "%s %d(%s)", buf
, wp
->w_number
, wp
->w_title
);
5644 sprintf(p
, "(%d,%d)", D_width
, D_height
),
5650 strcpy(p
, EncodingName(D_encoding
));
5656 strcpy(p
, " xterm");
5662 strcpy(p
, " color");
5669 strcpy(p
, " iso2022");
5672 else if (D_CS0
&& *D_CS0
)
5674 strcpy(p
, " altchar");
5682 AKAfin(buf
, len
, data
)
5685 char *data
; /* dummy */
5689 ChangeAKA(fore
, buf
, strlen(buf
));
5697 Input("Set window's title to: ", sizeof(fore
->w_akabuf
) - 1, INP_COOKED
, AKAfin
, NULL
, 0);
5703 if ((*(unsigned char *)s
& 0x7f) < 0x20 || *s
== 0x7f)
5707 LayProcess(&ss
, &n
);
5712 Colonfin(buf
, len
, data
)
5715 char *data
; /* dummy */
5720 if (buf
[len
] == '\t')
5723 int l
= 0, r
= RC_LAST
;
5724 int showmessage
= 0;
5727 while (*s
&& s
- buf
< len
)
5731 /* Showing a message when there's no hardstatus or caption cancels the input */
5733 (captionalways
|| D_has_hstatus
== HSTATUS_LASTLINE
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
)))
5739 x
= strncmp(buf
, comms
[m
].name
, len
);
5747 for (l
= m
- 1; l
>= 0 && strncmp(buf
, comms
[l
].name
, len
) == 0; l
--)
5749 for (m
= ++l
; m
<= r
&& strncmp(buf
, comms
[m
].name
, len
) == 0 && s
- mbuf
< sizeof(mbuf
); m
++)
5750 s
+= snprintf(s
, sizeof(mbuf
) - (s
- mbuf
), " %s", comms
[m
].name
);
5754 Msg(0, "Possible commands:%s", mbuf
);
5759 len
= snprintf(mbuf
, sizeof(mbuf
), "%s \t", comms
[l
].name
+ len
);
5760 if (len
> 0 && len
< sizeof(mbuf
))
5761 LayProcess(&s
, &len
);
5766 if (l
> r
&& showmessage
)
5767 Msg(0, "No commands matching '%*s'", len
, buf
);
5771 if (!len
|| buf
[len
])
5774 len
= strlen(buf
) + 1;
5775 if (len
> (int)sizeof(mbuf
))
5779 bcopy(buf
, mbuf
, len
);
5780 RcLine(mbuf
, sizeof mbuf
);
5785 SelectFin(buf
, len
, data
)
5788 char *data
; /* dummy */
5792 if (!len
|| !display
)
5794 if (len
== 1 && *buf
== '-')
5796 SetForeWindow((struct win
*)0);
5800 if ((n
= WindowByNoN(buf
)) < 0)
5806 SelectLayoutFin(buf
, len
, data
)
5809 char *data
; /* dummy */
5813 if (!len
|| !display
)
5815 if (len
== 1 && *buf
== '-')
5817 LoadLayout((struct layout
*)0, (struct canvas
*)0);
5821 lay
= FindLayout(buf
);
5823 Msg(0, "No such layout\n");
5824 else if (lay
== D_layout
)
5825 Msg(0, "This IS layout %d (%s).\n", lay
->lay_number
, lay
->lay_title
);
5828 LoadLayout(lay
, &D_canvas
);
5837 Input("Switch to window: ", 20, INP_COOKED
, SelectFin
, NULL
, 0);
5840 static char setenv_var
[31];
5844 SetenvFin1(buf
, len
, data
)
5847 char *data
; /* dummy */
5849 if (!len
|| !display
)
5855 SetenvFin2(buf
, len
, data
)
5858 char *data
; /* dummy */
5860 if (!len
|| !display
)
5862 debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var
, buf
);
5863 xsetenv(setenv_var
, buf
);
5871 static char setenv_buf
[50 + sizeof(setenv_var
)]; /* need to be static here, cannot be freed */
5875 strncpy(setenv_var
, arg
, sizeof(setenv_var
) - 1);
5876 sprintf(setenv_buf
, "Enter value for %s: ", setenv_var
);
5877 Input(setenv_buf
, 30, INP_COOKED
, SetenvFin2
, NULL
, 0);
5880 Input("Setenv: Enter variable name: ", 30, INP_COOKED
, SetenvFin1
, NULL
, 0);
5884 * the following options are understood by this parser:
5885 * -f, -f0, -f1, -fy, -fa
5886 * -t title, -T terminal-type, -h height-of-scrollback,
5887 * -ln, -l0, -ly, -l1, -l
5894 struct NewWindow nwin
;
5899 while (av
&& *av
&& av
[0][0] == '-')
5901 if (av
[0][1] == '-')
5913 nwin
.flowflag
= FLOW_NOW
* 0;
5918 nwin
.flowflag
= FLOW_NOW
* 1;
5921 nwin
.flowflag
= FLOW_AUTOFLAG
;
5927 case 't': /* no more -k */
5929 nwin
.aka
= &av
[0][2];
5937 nwin
.term
= &av
[0][2];
5945 nwin
.histheight
= atoi(av
[0] + 2);
5947 nwin
.histheight
= atoi(*av
);
5976 nwin
.monitor
= MON_ON
;
5982 Msg(0, "%s: screen: invalid option -%c.", fn
, av
[0][1]);
5988 if (av
&& *av
&& IsNumColon(*av
, 10, buf
, sizeof(buf
)))
5993 if (num
< 0 || (maxwin
&& num
> maxwin
- 1) || (!maxwin
&& num
> MAXWIN
- 1))
5995 Msg(0, "%s: illegal screen number %d.", fn
, num
);
6005 nwin
.aka
= Filename(*av
);
6012 * CompileKeys must be called before Markroutine is first used.
6013 * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
6015 * s is an ascii string in a termcap-like syntax. It looks like
6016 * "j=u:k=d:l=r:h=l: =.:" and so on...
6017 * this example rebinds the cursormovement to the keys u (up), d (down),
6018 * l (left), r (right). placing a mark will now be done with ".".
6021 CompileKeys(s
, sl
, array
)
6024 unsigned char *array
;
6027 unsigned char key
, value
;
6031 for (i
= 0; i
< 256; i
++)
6035 debug1("CompileKeys: '%s'\n", s
);
6038 key
= *(unsigned char *)s
++;
6039 if (*s
!= '=' || sl
< 3)
6046 value
= *(unsigned char *)s
++;
6049 while (*s
== '=' && sl
>= 2);
6058 #endif /* COPY_PASTE */
6061 * Asynchronous input functions
6064 #if defined(DETACH) && defined(POW_DETACH)
6066 pow_detach_fn(buf
, len
, data
)
6069 char *data
; /* dummy */
6071 debug("pow_detach_fn called\n");
6077 if (ktab
[(int)(unsigned char)*buf
].nr
!= RC_POW_DETACH
)
6080 write(D_userfd
, "\007", 1);
6081 Msg(0, "Detach aborted.");
6086 #endif /* POW_DETACH */
6090 copy_reg_fn(buf
, len
, data
)
6093 char *data
; /* dummy */
6095 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6106 if (D_user
->u_plop
.len
)
6108 if ((pp
->buf
= (char *)malloc(D_user
->u_plop
.len
)) == NULL
)
6110 Msg(0, "%s", strnomem
);
6113 bcopy(D_user
->u_plop
.buf
, pp
->buf
, D_user
->u_plop
.len
);
6115 pp
->len
= D_user
->u_plop
.len
;
6117 pp
->enc
= D_user
->u_plop
.enc
;
6119 Msg(0, "Copied %d characters into register %c", D_user
->u_plop
.len
, *buf
);
6123 ins_reg_fn(buf
, len
, data
)
6126 char *data
; /* dummy */
6128 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6136 return; /* Input() should not call us w/o fore, but you never know... */
6138 Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
6141 MakePaster(&fore
->w_paster
, pp
->buf
, pp
->len
, 0);
6144 Msg(0, "Empty register.");
6146 #endif /* COPY_PASTE */
6149 process_fn(buf
, len
, data
)
6152 char *data
; /* dummy */
6154 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6163 ProcessInput(pp
->buf
, pp
->len
);
6166 Msg(0, "Empty register.");
6170 confirm_fn(buf
, len
, data
)
6177 if (len
|| (*buf
!= 'y' && *buf
!= 'Y'))
6182 act
.nr
= *(int *)data
;
6192 struct acluser
**up
;
6194 char pw1
[130]; /* FreeBSD crypts to 128 bytes */
6199 su_fin(buf
, len
, data
)
6204 struct inputsu
*i
= (struct inputsu
*)data
;
6209 { p
= i
->name
; l
= sizeof(i
->name
) - 1; }
6211 { strcpy(p
= i
->pw1
, "\377"); l
= sizeof(i
->pw1
) - 1; }
6213 { strcpy(p
= i
->pw2
, "\377"); l
= sizeof(i
->pw2
) - 1; }
6215 strncpy(p
, buf
, 1 + (l
< len
) ? l
: len
);
6217 Input("Screen User: ", sizeof(i
->name
) - 1, INP_COOKED
, su_fin
, (char *)i
, 0);
6219 Input("User's UNIX Password: ", sizeof(i
->pw1
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6221 Input("User's Screen Password: ", sizeof(i
->pw2
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6224 if ((p
= DoSu(i
->up
, i
->name
, i
->pw2
, i
->pw1
)))
6231 InputSu(w
, up
, name
)
6233 struct acluser
**up
;
6238 if (!(i
= (struct inputsu
*)calloc(1, sizeof(struct inputsu
))))
6243 su_fin(name
, (int)strlen(name
), (char *)i
); /* can also initialise stuff */
6245 su_fin((char *)0, 0, (char *)i
);
6248 #endif /* MULTIUSER */
6253 pass1(buf
, len
, data
)
6258 struct acluser
*u
= (struct acluser
*)data
;
6263 if (u
->u_password
!= NullStr
)
6264 free((char *)u
->u_password
);
6265 u
->u_password
= SaveStr(buf
);
6266 bzero(buf
, strlen(buf
));
6267 Input("Retype new password:", 100, INP_NOECHO
, pass2
, data
, 0);
6271 pass2(buf
, len
, data
)
6278 struct acluser
*u
= (struct acluser
*)data
;
6281 if (!buf
|| strcmp(u
->u_password
, buf
))
6283 Msg(0, "[ Passwords don't match - checking turned off ]");
6284 if (u
->u_password
!= NullStr
)
6286 bzero(u
->u_password
, strlen(u
->u_password
));
6287 free((char *)u
->u_password
);
6289 u
->u_password
= NullStr
;
6291 else if (u
->u_password
[0] == '\0')
6293 Msg(0, "[ No password - no secure ]");
6295 bzero(buf
, strlen(buf
));
6298 if (u
->u_password
!= NullStr
)
6300 for (st
= 0; st
< 2; st
++)
6301 salt
[st
] = 'A' + (int)((time(0) >> 6 * st
) % 26);
6303 buf
= crypt(u
->u_password
, salt
);
6304 bzero(u
->u_password
, strlen(u
->u_password
));
6305 free((char *)u
->u_password
);
6306 u
->u_password
= SaveStr(buf
);
6307 bzero(buf
, strlen(buf
));
6310 UserFreeCopyBuffer(u
);
6311 u
->u_plop
.len
= strlen(u
->u_password
);
6315 if (!(u
->u_plop
.buf
= SaveStr(u
->u_password
)))
6317 Msg(0, "%s", strnomem
);
6318 D_user
->u_plop
.len
= 0;
6321 Msg(0, "[ Password moved into copybuffer ]");
6322 #else /* COPY_PASTE */
6323 Msg(0, "[ Crypted password is \"%s\" ]", u
->u_password
);
6324 #endif /* COPY_PASTE */
6327 #endif /* PASSWORD */
6334 for (i
= 0; i
< MAX_DIGRAPH
&& digraphs
[i
].d
[0]; i
++)
6335 if ((digraphs
[i
].d
[0] == (unsigned char)buf
[0] && digraphs
[i
].d
[1] == (unsigned char)buf
[1]) ||
6336 (digraphs
[i
].d
[0] == (unsigned char)buf
[1] && digraphs
[i
].d
[1] == (unsigned char)buf
[0]))
6342 digraph_fn(buf
, len
, data
)
6345 char *data
; /* dummy */
6352 buf
[len
+ 1] = ch
; /* so we can restore it later */
6353 if (ch
< ' ' || ch
== '\177')
6355 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6359 if ((ch
< '0' || ch
> '9') && (ch
< 'a' || ch
> 'f') && (ch
< 'A' || ch
> 'F'))
6361 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6364 if (len
== (*buf
== 'U' ? 5 : 3))
6368 if (len
&& *buf
== '0')
6370 if (ch
< '0' || ch
> '7')
6372 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6387 buf
[len
] = buf
[len
+ 1]; /* stored above */
6392 if (!parse_input_int(buf
, len
, &x
))
6394 i
= digraph_find(buf
);
6395 if ((x
= digraphs
[i
].value
) <= 0)
6397 Msg(0, "Unknown digraph");
6404 if (flayer
->l_encoding
== UTF8
)
6405 i
= ToUtf8(buf
, x
); /* buf is big enough for all UTF-8 codes */
6408 LayProcess(&buf
, &i
);
6419 debug1("StuffKey #%d", i
);
6422 debug1(" - %s", term
[i
+ T_CAPS
].tcname
);
6425 if (i
< KMAP_KEYS
&& D_ESCseen
)
6427 struct action
*act
= &D_ESCseen
[i
+ 256];
6428 if (act
->nr
!= RC_ILLEGAL
)
6431 DoAction(act
, i
+ 256);
6437 if (i
>= T_CURSOR
- T_CAPS
&& i
< T_KEYPAD
- T_CAPS
&& D_cursorkeys
)
6438 i
+= T_OCAPS
- T_CURSOR
;
6439 else if (i
>= T_KEYPAD
- T_CAPS
&& i
< T_OCAPS
- T_CAPS
&& D_keypad
)
6440 i
+= T_OCAPS
- T_CURSOR
;
6441 debug1(" - action %d\n", i
);
6442 flayer
= D_forecv
->c_layer
;
6446 if (flayer
&& flayer
->l_mode
== 1)
6447 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &mmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].mm
;
6449 if ((!act
|| act
->nr
== RC_ILLEGAL
) && !D_mapdefault
)
6450 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &umtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].um
;
6451 if (!act
|| act
->nr
== RC_ILLEGAL
)
6452 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &dmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].dm
;
6454 if (discard
&& (!act
|| act
->nr
!= RC_COMMAND
))
6461 if (act
== 0 || act
->nr
== RC_ILLEGAL
)
6475 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6476 if (Layer2Window(cv
->c_layer
) == wi
)
6482 FindNiceWindow(wi
, presel
)
6488 debug2("FindNiceWindow %d %s\n", wi
? wi
->w_number
: -1 , presel
? presel
: "NULL");
6491 i
= WindowByNoN(presel
);
6498 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6501 if (!wi
|| (IsOnDisplay(wi
) && !presel
))
6503 /* try to get another window */
6506 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6507 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6510 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6511 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6514 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6515 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6518 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6519 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6523 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6524 if (!wi
->w_layer
.l_cvlist
)
6527 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6528 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
))
6532 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6540 /* sorted list of all commands */
6541 static struct comm
**commtab
;
6542 static int ncommtab
;
6547 void (*hand
) __P((struct comm
*, char **, int));
6550 for (n
= 0; cos
[n
].name
; n
++)
6555 commtab
= (struct commt
*)realloc(commtab
, sizeof(*commtab
) * (ncommtab
+ n
));
6557 commtab
= (struct commt
*)malloc(sizeof(*commtab
) * (ncommtab
+ n
));
6560 for (i
= 0; i
< n
; i
++)
6562 for (j
= 0; j
< ncommtab
; j
++)
6564 r
= strcmp(cos
[i
].name
, commtab
[j
]->name
);
6566 Panic(0, "Duplicate command: %s\n", cos
[i
].name
);
6570 for (r
= ncommtab
; r
> j
; r
--)
6571 commtab
[r
] = commtab
[r
- 1];
6572 commtab
[j
] = cos
+ i
;
6573 cos
[i
].handler
= hand
;
6574 bzero(cos
[i
].userbits
, sizeof(cos
[i
].userbits
));
6583 int x
, m
, l
= 0, r
= ncommtab
- 1;
6587 x
= strcmp(str
, commtab
[m
]->name
);
6601 CalcSlicePercent(cv
, percent
)
6606 if (!cv
|| !cv
->c_slback
)
6608 up
= CalcSlicePercent(cv
->c_slback
->c_slback
, percent
);
6610 for (cv
= cv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6611 wsum
+= cv
->c_slweight
;
6614 return (up
* w
) / wsum
;
6618 ChangeCanvasSize(fcv
, abs
, diff
, gflag
, percent
)
6619 struct canvas
*fcv
; /* make this canvas bigger */
6620 int abs
; /* mode: 0:rel 1:abs 2:max */
6621 int diff
; /* change this much */
6622 int gflag
; /* go up if neccessary */
6626 int done
, have
, m
, dir
;
6628 debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs
, diff
, percent
);
6629 if (abs
== 0 && diff
== 0)
6634 fcv
->c_slweight
= 0;
6637 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6639 fcv
->c_slweight
= 1;
6640 cv
= fcv
->c_slback
->c_slback
;
6641 if (gflag
&& cv
&& cv
->c_slback
)
6642 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6650 if (percent
&& diff
> percent
)
6656 for (cv
= fcv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6657 wsum
+= cv
->c_slweight
;
6660 up
= gflag
? CalcSlicePercent(fcv
->c_slback
->c_slback
, percent
) : percent
;
6661 debug3("up=%d, wsum=%d percent=%d\n", up
, wsum
, percent
);
6664 int scale
= wsum
< 10 ? 1000 : 100;
6665 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6666 cv
->c_slweight
*= scale
;
6668 debug1("scaled wsum to %d\n", wsum
);
6670 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6674 cv
->c_slweight
= (cv
->c_slweight
* up
) / percent
;
6675 if (cv
->c_slweight
== 0)
6678 debug1(" - weight %d\n", cv
->c_slweight
);
6680 diff
= (diff
* wsum
) / percent
;
6686 if (abs
&& diff
== (fcv
->c_slorient
== SLICE_VERT
? fcv
->c_ye
- fcv
->c_ys
+ 2 : fcv
->c_xe
- fcv
->c_xs
+ 2))
6688 /* fix weights to real size (can't be helped, sorry) */
6689 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6691 cv
->c_slweight
= cv
->c_slorient
== SLICE_VERT
? cv
->c_ye
- cv
->c_ys
+ 2 : cv
->c_xe
- cv
->c_xs
+ 2;
6692 debug1(" - weight %d\n", cv
->c_slweight
);
6696 diff
= diff
- fcv
->c_slweight
;
6697 debug1("diff = %d\n", diff
);
6702 cv
= fcv
->c_slnext
? fcv
->c_slnext
: fcv
->c_slprev
;
6703 fcv
->c_slweight
+= diff
;
6704 cv
->c_slweight
-= diff
;
6709 for (cv
= fcv
->c_slnext
; diff
> 0; cv
= dir
> 0 ? cv
->c_slnext
: cv
->c_slprev
)
6713 debug1("reached end, dir is %d\n", dir
);
6723 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 : 2;
6724 debug2("min is %d, have %d\n", m
, cv
->c_slweight
);
6725 if (cv
->c_slweight
> m
)
6727 have
= cv
->c_slweight
- m
;
6730 debug1("subtract %d\n", have
);
6731 cv
->c_slweight
-= have
;
6738 /* need more room! */
6739 cv
= fcv
->c_slback
->c_slback
;
6740 if (cv
&& cv
->c_slback
)
6741 done
+= ChangeCanvasSize(fcv
->c_slback
->c_slback
, 0, diff
, gflag
, percent
);
6743 fcv
->c_slweight
+= done
;
6744 debug1("ChangeCanvasSize returns %d\n", done
);
6749 ResizeRegions(arg
, flags
)
6755 int gflag
= 0, abs
= 0, percent
= 0;
6761 if (D_forecv
->c_slorient
== SLICE_UNKN
)
6763 Msg(0, "resize: need more than one region");
6766 gflag
= flags
& RESIZE_FLAG_L
? 0 : 1;
6767 orient
|= flags
& RESIZE_FLAG_H
? SLICE_HORI
: 0;
6768 orient
|= flags
& RESIZE_FLAG_V
? SLICE_VERT
: 0;
6770 orient
= D_forecv
->c_slorient
;
6774 /* make all regions the same height */
6775 struct canvas
*cv
= gflag
? &D_canvas
: D_forecv
->c_slback
;
6776 if (cv
->c_slperp
->c_slorient
& orient
)
6777 EqualizeCanvas(cv
->c_slperp
, gflag
);
6778 /* can't use cv->c_slorient directly as it can be D_canvas */
6779 if ((cv
->c_slperp
->c_slorient
^ (SLICE_HORI
^ SLICE_VERT
)) & orient
)
6784 EqualizeCanvas(cv
->c_slperp
, gflag
);
6787 EqualizeCanvas(cv
, gflag
);
6790 RecreateCanvasChain();
6791 RethinkDisplayViewports();
6792 ResizeLayersToCanvases();
6795 if (!strcmp(arg
, "min") || !strcmp(arg
, "0"))
6800 else if (!strcmp(arg
, "max") || !strcmp(arg
, "_"))
6807 if (l
> 0 && arg
[l
- 1] == '%')
6810 diff
= atoi(arg
+ 1);
6811 else if (*arg
== '-')
6812 diff
= -atoi(arg
+ 1);
6815 diff
= atoi(arg
); /* +1 because of caption line */
6818 abs
= diff
== 0 ? 2 : 1;
6824 diff
= diff
* percent
/ 100;
6826 if (cv
->c_slorient
& orient
)
6827 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6828 if (cv
->c_slback
->c_slorient
& orient
)
6829 ChangeCanvasSize(cv
->c_slback
, abs
, diff
, gflag
, percent
);
6831 ResizeCanvas(&D_canvas
);
6832 RecreateCanvasChain();
6833 RethinkDisplayViewports();
6834 ResizeLayersToCanvases();
6841 if (siz
+ diff
> dsize
- (nreg
- 1) * 2 - 1)
6842 diff
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6843 if (diff
== 0 || siz
+ diff
< 1)
6848 if (D_forecv
->c_next
)
6850 D_forecv
->c_ye
+= diff
;
6851 D_forecv
->c_next
->c_ys
+= diff
;
6852 D_forecv
->c_next
->c_yoff
+= diff
;
6856 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6857 if (cv
->c_next
== D_forecv
)
6861 D_forecv
->c_ys
-= diff
;
6862 D_forecv
->c_yoff
-= diff
;
6867 int s
, i
= 0, found
= 0, di
= diff
, d2
;
6868 s
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6869 for (cv
= D_cvlist
; cv
; i
= cv
->c_ye
+ 2, cv
= cv
->c_next
)
6873 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) + diff
;
6874 cv
->c_yoff
-= cv
->c_ys
- i
;
6879 s
-= cv
->c_ye
- cv
->c_ys
;
6887 d2
= di
> cv
->c_ye
- cv
->c_ys
? cv
->c_ye
- cv
->c_ys
: di
;
6889 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) - d2
;
6890 cv
->c_yoff
-= cv
->c_ys
- i
;
6894 RethinkDisplayViewports();
6895 ResizeLayersToCanvases();
6900 ResizeFin(buf
, len
, data
)
6906 int flags
= *(int *)data
;
6907 ch
= ((unsigned char *)buf
)[len
];
6910 ResizeRegions(buf
, flags
);
6914 flags
^= RESIZE_FLAG_H
;
6916 flags
^= RESIZE_FLAG_V
;
6918 flags
|= RESIZE_FLAG_H
|RESIZE_FLAG_V
;
6920 flags
^= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
6922 flags
^= RESIZE_FLAG_L
;
6925 inp_setprompt(resizeprompts
[flags
], NULL
);
6926 *(int *)data
= flags
;
6931 SetForeCanvas(d
, cv
)
6935 struct display
*odisplay
= display
;
6936 if (d
->d_forecv
== cv
)
6941 if ((focusminwidth
&& (focusminwidth
< 0 || D_forecv
->c_xe
- D_forecv
->c_xs
+ 1 < focusminwidth
)) ||
6942 (focusminheight
&& (focusminheight
< 0 || D_forecv
->c_ye
- D_forecv
->c_ys
+ 1 < focusminheight
)))
6944 ResizeCanvas(&D_canvas
);
6945 RecreateCanvasChain();
6946 RethinkDisplayViewports();
6947 ResizeLayersToCanvases(); /* redisplays */
6949 fore
= D_fore
= Layer2Window(D_forecv
->c_layer
);
6950 if (D_other
== fore
)
6952 flayer
= D_forecv
->c_layer
;
6954 if (D_xtermosc
[2] || D_xtermosc
[3])
6965 flayer
= D_forecv
->c_layer
;
6966 CV_CALL(D_forecv
, LayRestore();LaySetCursor());
6967 WindowChanged(0, 'F');
6980 p
= Layer2Window(D_forecv
->c_layer
);
6981 for (i
= 3; i
>=0; i
--)
6982 SetXtermOSC(i
, p
? p
->w_xtermosc
[i
] : 0);
6987 ParseAttrColor(s1
, s2
, msgok
)
6999 while (*ss
&& *ss
!= ' ')
7003 if (*s
&& (s2
|| *ss
|| !((*s
>= 'a' && *s
<= 'z') || (*s
>= 'A' && *s
<= 'Z') || *s
== '.')))
7005 int mode
= 0, n
= 0;
7023 if (*s
>= '0' && *s
<= '9')
7026 if (*s
>= '0' && *s
<= '9')
7027 n
= n
* 16 + (*s
++ - '0');
7028 else if (*s
>= 'a' && *s
<= 'f')
7029 n
= n
* 16 + (*s
++ - ('a' - 10));
7030 else if (*s
>= 'A' && *s
<= 'F')
7031 n
= n
* 16 + (*s
++ - ('A' - 10));
7032 else if (*s
&& *s
!= ' ')
7035 Msg(0, "Illegal attribute hexchar '%c'", *s
);
7041 while (*s
&& *s
!= ' ')
7058 Msg(0, "Illegal attribute specifier '%c'", *s
);
7064 if (*s
&& *s
!= ' ')
7067 Msg(0, "junk after attribute description: '%c'", *s
);
7079 while (*s
&& *s
== ' ')
7087 Msg(0, "junk after description: '%c'", *s
);
7091 while (*s
&& *s
== ' ')
7098 static char costr
[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
7108 for (j
= 0; j
< 2 && *s
&& *s
!= ' '; j
++)
7110 for (i
= 0; costr
[i
]; i
++)
7116 Msg(0, "illegal color descriptor: '%c'", *s
);
7120 n
= n
<< 4 | (i
& 15);
7123 n
= (n
& 0x20ff) | 0x200;
7127 if ((n
& 0xf00) == 0xf00)
7128 n
^= 0xf00; /* clear superflous bits */
7131 n
^= 0x2400; /* shift bit into right position */
7134 n
|= 0xf0; /* don't change bg color */
7135 if (numco
!= 2 && n
!= 0xff)
7136 n
|= 0x100; /* special invert mode */
7137 if (*s
&& *s
!= ' ')
7140 Msg(0, "junk after color description: '%c'", *s
);
7148 while (*s
&& *s
== ' ')
7153 Msg(0, "junk after description: '%c'", *s
);
7156 debug1("ParseAttrColor %06x\n", r
);
7164 * e just set intensity
7165 * f don't change anything
7166 * Intensity is encoded into bits 17(fg) and 18(bg).
7169 ApplyAttrColor(i
, mc
)
7173 debug1("ApplyAttrColor %06x\n", i
);
7174 mc
->attr
|= i
>> 8 & 255;
7175 mc
->attr
^= i
& 255;
7177 i
= (i
>> 16) ^ 0xff;
7178 if ((i
& 0x100) != 0)
7181 if (mc
->attr
& (A_SO
|A_RV
))
7183 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4) | ((i
& 0x200) << 1) | ((i
& 0x400) >> 1);
7185 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4);
7189 if ((i
& 0x0f) != 0x0f)
7190 mc
->attr
= (mc
->attr
& 0xbf) | ((i
>> 3) & 0x40);
7191 if ((i
& 0xf0) != 0xf0)
7192 mc
->attr
= (mc
->attr
& 0x7f) | ((i
>> 3) & 0x80);
7194 mc
->color
= 0x99 ^ mc
->color
;
7195 if ((i
& 0x0e) == 0x0e)
7196 i
= (i
& 0xf0) | (mc
->color
& 0x0f);
7197 if ((i
& 0xe0) == 0xe0)
7198 i
= (i
& 0x0f) | (mc
->color
& 0xf0);
7199 mc
->color
= 0x99 ^ i
;
7200 debug2("ApplyAttrColor - %02x %02x\n", mc
->attr
, i
);