1 /* Copyright (c) 2008, 2009
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Micah Cowan (micah@cowan.name)
5 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
6 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
7 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
8 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
9 * Copyright (c) 1987 Oliver Laumann
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, see
23 * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 ****************************************************************
31 #include <sys/types.h>
35 #if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
40 #include <sys/ioctl.h>
44 /* for solaris 2.1, Unixware (SVR4.2) and possibly others: */
46 # include <sys/stropts.h>
55 extern struct comm comms
[];
57 extern char *RcFileName
, *home
;
58 extern char *BellString
, *ActivityString
, *ShellProg
, *ShellArgs
[];
59 extern char *hstatusstring
, *captionstring
, *timestring
;
60 extern char *wliststr
, *wlisttit
;
61 extern int captionalways
;
63 extern char *hardcopydir
, *screenlogfile
, *logtstamp_string
;
64 extern int log_flush
, logtstamp_on
, logtstamp_after
;
65 extern char *VisualBellString
;
66 extern int VBellWait
, MsgWait
, MsgMinWait
, SilenceWait
;
67 extern char SockPath
[], *SockName
;
68 extern int TtyMode
, auto_detach
, use_altscreen
;
69 extern int iflag
, maxwin
;
70 extern int focusminwidth
, focusminheight
;
71 extern int use_hardstatus
, visual_bell
;
73 extern int attr2color
[][4];
74 extern int nattr2color
;
76 extern int hardstatusemu
;
77 extern char *printcmd
;
78 extern int default_startup
;
79 extern int defobuflimit
;
80 extern int defnonblock
;
81 extern int defmousetrack
;
82 extern int ZombieKey_destroy
;
83 extern int ZombieKey_resurrect
;
84 extern int ZombieKey_onerror
;
86 extern int defautonuke
;
88 extern int separate_sids
;
89 extern struct NewWindow nwin_default
, nwin_undef
;
91 extern int join_with_cr
;
92 extern int compacthist
;
97 extern unsigned char mark_key_tab
[];
98 extern char *BufferFile
;
101 extern char *BufferFile
, *PowDetachString
;
104 extern struct acluser
*EffectiveAclUser
; /* acl.c */
106 extern struct term term
[]; /* terminal capabilities */
108 extern char *kmapdef
[];
109 extern char *kmapadef
[];
110 extern char *kmapmdef
[];
112 extern struct mchar mchar_so
, mchar_null
;
113 extern int renditions
[];
114 extern int VerboseCreate
;
116 extern char *screenencodings
;
122 static int CheckArgNum
__P((int, char **));
123 static void ClearAction
__P((struct action
*));
124 static void SaveAction
__P((struct action
*, int, char **, int *));
125 static int NextWindow
__P((void));
126 static int PreviousWindow
__P((void));
127 static int MoreWindows
__P((void));
128 static void LogToggle
__P((int));
129 static void ShowInfo
__P((void));
130 static void ShowDInfo
__P((void));
131 static struct win
*WindowByName
__P((char *));
132 static int WindowByNumber
__P((char *));
133 static int ParseOnOff
__P((struct action
*, int *));
134 static int ParseWinNum
__P((struct action
*, int *));
135 static int ParseBase
__P((struct action
*, char *, int *, int, char *));
136 static int ParseNum1000
__P((struct action
*, int *));
137 static char **SaveArgs
__P((char **));
138 static int IsNum
__P((char *, int));
139 static void Colonfin
__P((char *, int, char *));
140 static void InputSelect
__P((void));
141 static void InputSetenv
__P((char *));
142 static void InputAKA
__P((void));
144 static int InputSu
__P((struct win
*, struct acluser
**, char *));
145 static void su_fin
__P((char *, int, char *));
147 static void AKAfin
__P((char *, int, char *));
149 static void copy_reg_fn
__P((char *, int, char *));
150 static void ins_reg_fn
__P((char *, int, char *));
152 static void process_fn
__P((char *, int, char *));
154 static void pass1
__P((char *, int, char *));
155 static void pass2
__P((char *, int, char *));
158 static void pow_detach_fn
__P((char *, int, char *));
160 static void digraph_fn
__P((char *, int, char *));
161 static int digraph_find
__P((const char *buf
));
162 static void confirm_fn
__P((char *, int, char *));
163 static int IsOnDisplay
__P((struct win
*));
164 static void ResizeRegions
__P((char *, int));
165 static void ResizeFin
__P((char *, int, char *));
166 static struct action
*FindKtab
__P((char *, int));
167 static void SelectFin
__P((char *, int, char *));
168 static void SelectLayoutFin
__P((char *, int, char *));
171 extern struct layer
*flayer
;
172 extern struct display
*display
, *displays
;
173 extern struct win
*fore
, *console_window
, *windows
;
174 extern struct acluser
*users
;
175 extern struct layout
*layouts
, *layout_attach
, layout_last_marker
;
176 extern struct layout
*laytab
[];
178 extern char screenterm
[], HostName
[], version
[];
179 extern struct NewWindow nwin_undef
, nwin_default
;
180 extern struct LayFuncs WinLf
, MarkLf
;
182 extern int Z0width
, Z1width
;
183 extern int real_uid
, real_gid
;
186 extern int nethackflag
;
190 extern struct win
**wtab
;
194 extern int maxusercount
;
198 struct plop plop_tab
[MAX_PLOP_DEFS
];
201 # define PTYMODE 0622
204 int TtyMode
= PTYMODE
;
205 int hardcopy_append
= 0;
206 int all_norefresh
= 0;
209 char *zmodem_sendcmd
;
210 char *zmodem_recvcmd
;
211 static char *zmodes
[4] = {"off", "auto", "catch", "pass"};
215 struct action idleaction
;
220 struct action ktab
[256 + KMAP_KEYS
]; /* command key translation table */
224 struct action ktab
[256 + KMAP_KEYS
];
226 struct kclass
*kclasses
;
229 struct action umtab
[KMAP_KEYS
+KMAP_AKEYS
];
230 struct action dmtab
[KMAP_KEYS
+KMAP_AKEYS
];
231 struct action mmtab
[KMAP_KEYS
+KMAP_AKEYS
];
232 struct kmap_ext
*kmap_exts
;
234 static int maptimeout
= 300;
238 #define MAX_DIGRAPH 512
247 /* digraph table taken from old vim and rfc1345 */
248 static struct digraph digraphs
[MAX_DIGRAPH
+ 1] = {
249 {' ', ' ', 160}, /* */
250 {'N', 'S', 160}, /* */
251 {'~', '!', 161}, /* ¡ */
252 {'!', '!', 161}, /* ¡ */
253 {'!', 'I', 161}, /* ¡ */
254 {'c', '|', 162}, /* ¢ */
255 {'c', 't', 162}, /* ¢ */
256 {'$', '$', 163}, /* £ */
257 {'P', 'd', 163}, /* £ */
258 {'o', 'x', 164}, /* ¤ */
259 {'C', 'u', 164}, /* ¤ */
260 {'C', 'u', 164}, /* ¤ */
261 {'E', 'u', 164}, /* ¤ */
262 {'Y', '-', 165}, /* ¥ */
263 {'Y', 'e', 165}, /* ¥ */
264 {'|', '|', 166}, /* ¦ */
265 {'B', 'B', 166}, /* ¦ */
266 {'p', 'a', 167}, /* § */
267 {'S', 'E', 167}, /* § */
268 {'"', '"', 168}, /* ¨ */
269 {'\'', ':', 168}, /* ¨ */
270 {'c', 'O', 169}, /* © */
271 {'C', 'o', 169}, /* © */
272 {'a', '-', 170}, /* ª */
273 {'<', '<', 171}, /* « */
274 {'-', ',', 172}, /* ¬ */
275 {'N', 'O', 172}, /* ¬ */
276 {'-', '-', 173}, /* */
277 {'r', 'O', 174}, /* ® */
278 {'R', 'g', 174}, /* ® */
279 {'-', '=', 175}, /* ¯ */
280 {'\'', 'm', 175}, /* ¯ */
281 {'~', 'o', 176}, /* ° */
282 {'D', 'G', 176}, /* ° */
283 {'+', '-', 177}, /* ± */
284 {'2', '2', 178}, /* ² */
285 {'2', 'S', 178}, /* ² */
286 {'3', '3', 179}, /* ³ */
287 {'3', 'S', 179}, /* ³ */
288 {'\'', '\'', 180}, /* ´ */
289 {'j', 'u', 181}, /* µ */
290 {'M', 'y', 181}, /* µ */
291 {'p', 'p', 182}, /* ¶ */
292 {'P', 'I', 182}, /* ¶ */
293 {'~', '.', 183}, /* · */
294 {'.', 'M', 183}, /* · */
295 {',', ',', 184}, /* ¸ */
296 {'\'', ',', 184}, /* ¸ */
297 {'1', '1', 185}, /* ¹ */
298 {'1', 'S', 185}, /* ¹ */
299 {'o', '-', 186}, /* º */
300 {'>', '>', 187}, /* » */
301 {'1', '4', 188}, /* ¼ */
302 {'1', '2', 189}, /* ½ */
303 {'3', '4', 190}, /* ¾ */
304 {'~', '?', 191}, /* ¿ */
305 {'?', '?', 191}, /* ¿ */
306 {'?', 'I', 191}, /* ¿ */
307 {'A', '`', 192}, /* À */
308 {'A', '!', 192}, /* À */
309 {'A', '\'', 193}, /* Á */
310 {'A', '^', 194}, /* Â */
311 {'A', '>', 194}, /* Â */
312 {'A', '~', 195}, /* Ã */
313 {'A', '?', 195}, /* Ã */
314 {'A', '"', 196}, /* Ä */
315 {'A', ':', 196}, /* Ä */
316 {'A', '@', 197}, /* Å */
317 {'A', 'A', 197}, /* Å */
318 {'A', 'E', 198}, /* Æ */
319 {'C', ',', 199}, /* Ç */
320 {'E', '`', 200}, /* È */
321 {'E', '!', 200}, /* È */
322 {'E', '\'', 201}, /* É */
323 {'E', '^', 202}, /* Ê */
324 {'E', '>', 202}, /* Ê */
325 {'E', '"', 203}, /* Ë */
326 {'E', ':', 203}, /* Ë */
327 {'I', '`', 204}, /* Ì */
328 {'I', '!', 204}, /* Ì */
329 {'I', '\'', 205}, /* Í */
330 {'I', '^', 206}, /* Î */
331 {'I', '>', 206}, /* Î */
332 {'I', '"', 207}, /* Ï */
333 {'I', ':', 207}, /* Ï */
334 {'D', '-', 208}, /* Ð */
335 {'N', '~', 209}, /* Ñ */
336 {'N', '?', 209}, /* Ñ */
337 {'O', '`', 210}, /* Ò */
338 {'O', '!', 210}, /* Ò */
339 {'O', '\'', 211}, /* Ó */
340 {'O', '^', 212}, /* Ô */
341 {'O', '>', 212}, /* Ô */
342 {'O', '~', 213}, /* Õ */
343 {'O', '?', 213}, /* Õ */
344 {'O', '"', 214}, /* Ö */
345 {'O', ':', 214}, /* Ö */
346 {'/', '\\', 215}, /* × */
347 {'*', 'x', 215}, /* × */
348 {'O', '/', 216}, /* Ø */
349 {'U', '`', 217}, /* Ù */
350 {'U', '!', 217}, /* Ù */
351 {'U', '\'', 218}, /* Ú */
352 {'U', '^', 219}, /* Û */
353 {'U', '>', 219}, /* Û */
354 {'U', '"', 220}, /* Ü */
355 {'U', ':', 220}, /* Ü */
356 {'Y', '\'', 221}, /* Ý */
357 {'I', 'p', 222}, /* Þ */
358 {'T', 'H', 222}, /* Þ */
359 {'s', 's', 223}, /* ß */
360 {'s', '"', 223}, /* ß */
361 {'a', '`', 224}, /* à */
362 {'a', '!', 224}, /* à */
363 {'a', '\'', 225}, /* á */
364 {'a', '^', 226}, /* â */
365 {'a', '>', 226}, /* â */
366 {'a', '~', 227}, /* ã */
367 {'a', '?', 227}, /* ã */
368 {'a', '"', 228}, /* ä */
369 {'a', ':', 228}, /* ä */
370 {'a', 'a', 229}, /* å */
371 {'a', 'e', 230}, /* æ */
372 {'c', ',', 231}, /* ç */
373 {'e', '`', 232}, /* è */
374 {'e', '!', 232}, /* è */
375 {'e', '\'', 233}, /* é */
376 {'e', '^', 234}, /* ê */
377 {'e', '>', 234}, /* ê */
378 {'e', '"', 235}, /* ë */
379 {'e', ':', 235}, /* ë */
380 {'i', '`', 236}, /* ì */
381 {'i', '!', 236}, /* ì */
382 {'i', '\'', 237}, /* í */
383 {'i', '^', 238}, /* î */
384 {'i', '>', 238}, /* î */
385 {'i', '"', 239}, /* ï */
386 {'i', ':', 239}, /* ï */
387 {'d', '-', 240}, /* ð */
388 {'n', '~', 241}, /* ñ */
389 {'n', '?', 241}, /* ñ */
390 {'o', '`', 242}, /* ò */
391 {'o', '!', 242}, /* ò */
392 {'o', '\'', 243}, /* ó */
393 {'o', '^', 244}, /* ô */
394 {'o', '>', 244}, /* ô */
395 {'o', '~', 245}, /* õ */
396 {'o', '?', 245}, /* õ */
397 {'o', '"', 246}, /* ö */
398 {'o', ':', 246}, /* ö */
399 {':', '-', 247}, /* ÷ */
400 {'o', '/', 248}, /* ø */
401 {'u', '`', 249}, /* ù */
402 {'u', '!', 249}, /* ù */
403 {'u', '\'', 250}, /* ú */
404 {'u', '^', 251}, /* û */
405 {'u', '>', 251}, /* û */
406 {'u', '"', 252}, /* ü */
407 {'u', ':', 252}, /* ü */
408 {'y', '\'', 253}, /* ý */
409 {'i', 'p', 254}, /* þ */
410 {'t', 'h', 254}, /* þ */
411 {'y', '"', 255}, /* ÿ */
412 {'y', ':', 255}, /* ÿ */
413 {'"', '[', 196}, /* Ä */
414 {'"', '\\', 214}, /* Ö */
415 {'"', ']', 220}, /* Ü */
416 {'"', '{', 228}, /* ä */
417 {'"', '|', 246}, /* ö */
418 {'"', '}', 252}, /* ü */
419 {'"', '~', 223} /* ß */
422 #define RESIZE_FLAG_H 1
423 #define RESIZE_FLAG_V 2
424 #define RESIZE_FLAG_L 4
426 static char *resizeprompts
[] = {
428 "resize -h # lines: ",
429 "resize -v # lines: ",
430 "resize -b # lines: ",
431 "resize -l # lines: ",
432 "resize -l -h # lines: ",
433 "resize -l -v # lines: ",
434 "resize -l -b # lines: ",
438 parse_input_int(buf
, len
, val
)
444 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
447 for (i
= 2; i
< len
; i
++)
449 if (buf
[i
] >= '0' && buf
[i
] <= '9')
450 x
= x
* 16 | (buf
[i
] - '0');
451 else if (buf
[i
] >= 'a' && buf
[i
] <= 'f')
452 x
= x
* 16 | (buf
[i
] - ('a' - 10));
453 else if (buf
[i
] >= 'A' && buf
[i
] <= 'F')
454 x
= x
* 16 | (buf
[i
] - ('A' - 10));
459 else if (buf
[0] == '0')
462 for (i
= 1; i
< len
; i
++)
464 if (buf
[i
] < '0' || buf
[i
] > '7')
466 x
= x
* 8 | (buf
[i
] - '0');
480 register unsigned int i
;
485 for (i
= 0; i
< sizeof(ktab
)/sizeof(*ktab
); i
++)
487 ktab
[i
].nr
= RC_ILLEGAL
;
488 ktab
[i
].args
= noargs
;
492 for (i
= 0; i
< KMAP_KEYS
+KMAP_AKEYS
; i
++)
494 umtab
[i
].nr
= RC_ILLEGAL
;
495 umtab
[i
].args
= noargs
;
497 dmtab
[i
].nr
= RC_ILLEGAL
;
498 dmtab
[i
].args
= noargs
;
500 mmtab
[i
].nr
= RC_ILLEGAL
;
501 mmtab
[i
].args
= noargs
;
505 for (i
= 0; i
< NKMAPDEF
; i
++)
507 if (i
+ KMAPDEFSTART
< T_CAPS
)
509 if (i
+ KMAPDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
513 argarr
[0] = kmapdef
[i
];
514 SaveAction(dmtab
+ i
+ (KMAPDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
516 for (i
= 0; i
< NKMAPADEF
; i
++)
518 if (i
+ KMAPADEFSTART
< T_CURSOR
)
520 if (i
+ KMAPADEFSTART
>= T_CURSOR
+ KMAP_AKEYS
)
522 if (kmapadef
[i
] == 0)
524 argarr
[0] = kmapadef
[i
];
525 SaveAction(dmtab
+ i
+ (KMAPADEFSTART
- T_CURSOR
+ KMAP_KEYS
), RC_STUFF
, argarr
, 0);
527 for (i
= 0; i
< NKMAPMDEF
; i
++)
529 if (i
+ KMAPMDEFSTART
< T_CAPS
)
531 if (i
+ KMAPMDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
533 if (kmapmdef
[i
] == 0)
535 argarr
[0] = kmapmdef
[i
];
537 SaveAction(mmtab
+ i
+ (KMAPMDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
541 ktab
['h'].nr
= RC_HARDCOPY
;
543 ktab
['z'].nr
= ktab
[Ctrl('z')].nr
= RC_SUSPEND
;
545 ktab
['c'].nr
= ktab
[Ctrl('c')].nr
= RC_SCREEN
;
546 ktab
[' '].nr
= ktab
[Ctrl(' ')].nr
=
547 ktab
['n'].nr
= ktab
[Ctrl('n')].nr
= RC_NEXT
;
548 ktab
['N'].nr
= RC_NUMBER
;
549 ktab
[Ctrl('h')].nr
= ktab
[0177].nr
= ktab
['p'].nr
= ktab
[Ctrl('p')].nr
= RC_PREV
;
550 ktab
['k'].nr
= ktab
[Ctrl('k')].nr
= RC_KILL
;
551 ktab
['l'].nr
= ktab
[Ctrl('l')].nr
= RC_REDISPLAY
;
552 ktab
['w'].nr
= ktab
[Ctrl('w')].nr
= RC_WINDOWS
;
553 ktab
['v'].nr
= RC_VERSION
;
554 ktab
[Ctrl('v')].nr
= RC_DIGRAPH
;
555 ktab
['q'].nr
= ktab
[Ctrl('q')].nr
= RC_XON
;
556 ktab
['s'].nr
= ktab
[Ctrl('s')].nr
= RC_XOFF
;
557 ktab
['t'].nr
= ktab
[Ctrl('t')].nr
= RC_TIME
;
558 ktab
['i'].nr
= ktab
[Ctrl('i')].nr
= RC_INFO
;
559 ktab
['m'].nr
= ktab
[Ctrl('m')].nr
= RC_LASTMSG
;
560 ktab
['A'].nr
= RC_TITLE
;
561 #if defined(UTMPOK) && defined(LOGOUTOK)
562 ktab
['L'].nr
= RC_LOGIN
;
564 ktab
[','].nr
= RC_LICENSE
;
565 ktab
['W'].nr
= RC_WIDTH
;
566 ktab
['.'].nr
= RC_DUMPTERMCAP
;
567 ktab
[Ctrl('\\')].nr
= RC_QUIT
;
569 ktab
['d'].nr
= ktab
[Ctrl('d')].nr
= RC_DETACH
;
571 ktab
['D'].nr
= RC_POW_DETACH
;
574 ktab
['r'].nr
= ktab
[Ctrl('r')].nr
= RC_WRAP
;
575 ktab
['f'].nr
= ktab
[Ctrl('f')].nr
= RC_FLOW
;
576 ktab
['C'].nr
= RC_CLEAR
;
577 ktab
['Z'].nr
= RC_RESET
;
578 ktab
['H'].nr
= RC_LOG
;
579 ktab
['M'].nr
= RC_MONITOR
;
580 ktab
['?'].nr
= RC_HELP
;
582 ktab
['*'].nr
= RC_DISPLAYS
;
588 SaveAction(ktab
+ '-', RC_SELECT
, args
, 0);
590 for (i
= 0; i
< ((maxwin
&& maxwin
< 10) ? maxwin
: 10); i
++)
592 char *args
[2], arg1
[10];
595 sprintf(arg1
, "%d", i
);
596 SaveAction(ktab
+ '0' + i
, RC_SELECT
, args
, 0);
598 ktab
['\''].nr
= RC_SELECT
; /* calling a window by name */
603 SaveAction(ktab
+ '"', RC_WINDOWLIST
, args
, 0);
605 ktab
[Ctrl('G')].nr
= RC_VBELL
;
606 ktab
[':'].nr
= RC_COLON
;
608 ktab
['['].nr
= ktab
[Ctrl('[')].nr
= RC_COPY
;
613 SaveAction(ktab
+ ']', RC_PASTE
, args
, 0);
614 SaveAction(ktab
+ Ctrl(']'), RC_PASTE
, args
, 0);
616 ktab
['{'].nr
= RC_HISTORY
;
617 ktab
['}'].nr
= RC_HISTORY
;
618 ktab
['>'].nr
= RC_WRITEBUF
;
619 ktab
['<'].nr
= RC_READBUF
;
620 ktab
['='].nr
= RC_REMOVEBUF
;
623 ktab
['D'].nr
= RC_POW_DETACH
;
626 ktab
['x'].nr
= ktab
[Ctrl('x')].nr
= RC_LOCKSCREEN
;
628 ktab
['b'].nr
= ktab
[Ctrl('b')].nr
= RC_BREAK
;
629 ktab
['B'].nr
= RC_POW_BREAK
;
630 ktab
['_'].nr
= RC_SILENCE
;
631 ktab
['S'].nr
= RC_SPLIT
;
632 ktab
['Q'].nr
= RC_ONLY
;
633 ktab
['X'].nr
= RC_REMOVE
;
634 ktab
['F'].nr
= RC_FIT
;
635 ktab
['\t'].nr
= RC_FOCUS
;
640 SaveAction(ktab
+ T_BACKTAB
- T_CAPS
+ 256, RC_FOCUS
, args
, 0);
646 SaveAction(ktab
+ '|', RC_SPLIT
, args
, 0);
648 /* These come last; they may want overwrite others: */
651 ClearAction(&ktab
[DefaultEsc
]);
652 ktab
[DefaultEsc
].nr
= RC_OTHER
;
654 if (DefaultMetaEsc
>= 0)
656 ClearAction(&ktab
[DefaultMetaEsc
]);
657 ktab
[DefaultMetaEsc
].nr
= RC_META
;
660 idleaction
.nr
= RC_BLANKER
;
661 idleaction
.args
= noargs
;
665 static struct action
*
666 FindKtab(class, create
)
670 struct kclass
*kp
, **kpp
;
675 for (kpp
= &kclasses
; (kp
= *kpp
) != 0; kpp
= &kp
->next
)
676 if (!strcmp(kp
->name
, class))
682 if (strlen(class) > 80)
684 Msg(0, "Command class name too long.");
687 kp
= malloc(sizeof(*kp
));
693 kp
->name
= SaveStr(class);
694 for (i
= 0; i
< (int)(sizeof(kp
->ktab
)/sizeof(*kp
->ktab
)); i
++)
696 kp
->ktab
[i
].nr
= RC_ILLEGAL
;
697 kp
->ktab
[i
].args
= noargs
;
698 kp
->ktab
[i
].argl
= 0;
699 kp
->ktab
[i
].quiet
= 0;
713 if (act
->nr
== RC_ILLEGAL
)
715 act
->nr
= RC_ILLEGAL
;
716 if (act
->args
== noargs
)
718 for (p
= act
->args
; *p
; p
++)
720 free((char *)act
->args
);
726 * ProcessInput: process input from display and feed it into
727 * the layer on canvas D_forecv.
733 * This ProcessInput just does the keybindings and passes
734 * everything else on to ProcessInput2.
738 ProcessInput(ibuf
, ilen
)
743 unsigned char *s
, *q
;
747 debug1("ProcessInput: %d bytes\n", ilen
);
748 if (display
== 0 || ilen
== 0)
753 s
= (unsigned char *)ibuf
;
757 if (D_dontmap
|| !D_nseqs
)
764 debug3("cmp %c %c[%d]\n", ch
, *D_seqp
, D_seqp
- D_kmaps
);
767 l
= D_seqp
[D_seqp
[-D_seql
-1] + 1];
771 debug1("miss %d\n", D_seqp
- D_kmaps
);
774 debug("complete miss\n");
777 p
= (char *)D_seqp
- l
;
779 D_seqp
= D_kmaps
+ 3;
782 if ((q
= D_seqh
) != 0)
785 i
= q
[0] << 8 | q
[1];
786 i
&= ~KMAP_NOTIMEOUT
;
787 debug1("Mapping former hit #%d - ", i
);
788 debug2("%d(%s) - ", q
[2], q
+ 3);
790 ProcessInput2((char *)q
+ 3, q
[2]);
798 debug1("flush old %d\n", l
);
807 /* Finish old stuff */
809 debug1("finish old %d\n", slen
);
811 ProcessInput2(ibuf
, slen
);
820 debug2("length am %d, want %d\n", l
, D_seqp
[-l
- 1]);
821 if (l
== D_seqp
[-l
- 1])
826 if (D_kmaps
+ D_nseqs
> q
&& q
[2] > l
&& !bcmp(D_seqp
- l
, q
+ 3, l
))
828 debug1("have another mapping (%s), delay execution\n", q
+ 3);
829 D_seqh
= D_seqp
- 3 - l
;
834 i
= D_seqp
[-l
- 3] << 8 | D_seqp
[-l
- 2];
835 i
&= ~KMAP_NOTIMEOUT
;
836 debug1("Mapping #%d - ", i
);
837 p
= (char *)D_seqp
- l
;
838 debug2("%d(%s) - ", l
, p
);
840 D_seqp
= D_kmaps
+ 3;
852 debug("am in sequence -> check for timeout\n");
854 for (s
= D_seqp
; ; s
+= i
* 2 + 4)
856 if (s
[-l
-3] & KMAP_NOTIMEOUT
>> 8)
858 if ((i
= s
[s
[-l
-1] + 1]) == 0)
860 SetTimeout(&D_mapev
, maptimeout
);
866 ProcessInput2(ibuf
, slen
);
870 # define ProcessInput2 ProcessInput
875 * Here only the screen escape commands are handled.
879 ProcessInput2(ibuf
, ilen
)
885 struct action
*ktabp
;
887 debug1("ProcessInput2: %d bytes\n", ilen
);
888 while (ilen
&& display
)
890 debug1(" - ilen now %d bytes\n", ilen
);
891 flayer
= D_forecv
->c_layer
;
899 if ((unsigned char)*s
++ == D_user
->u_Esc
)
905 DoProcess(fore
, &ibuf
, &slen
, 0);
911 ktabp
= D_ESCseen
? D_ESCseen
: ktab
;
913 ch
= (unsigned char)*s
;
916 * As users have different esc characters, but a common ktab[],
917 * we fold back the users esc and meta-esc key to the Default keys
918 * that can be looked up in the ktab[]. grmbl. jw.
919 * XXX: make ktab[] a per user thing.
921 if (ch
== D_user
->u_Esc
)
923 else if (ch
== D_user
->u_MetaEsc
)
927 DoAction(&ktabp
[ch
], ch
);
928 ibuf
= (char *)(s
+ 1);
934 DoProcess(p
, bufp
, lenp
, pa
)
941 struct display
*d
= display
;
944 /* XXX -> PasteStart */
945 if (pa
&& *lenp
> 1 && p
&& p
->w_slowpaste
)
947 /* schedule slowpaste event */
948 SetTimeout(&p
->w_paster
.pa_slowev
, p
->w_slowpaste
);
949 evenq(&p
->w_paster
.pa_slowev
);
953 while (flayer
&& *lenp
)
956 if (!pa
&& p
&& p
->w_paster
.pa_pastelen
&& flayer
== p
->w_paster
.pa_pastelayer
)
958 debug("layer is busy - beep!\n");
959 WBell(p
, visual_bell
);
967 LayProcess(bufp
, lenp
);
969 if (pa
&& !pa
->pa_pastelayer
)
970 break; /* flush rest of paste */
979 /* We're full, let's beep */
980 debug("layer is full - beep!\n");
981 WBell(p
, visual_bell
);
989 if (pa
&& pa
->pa_pastelen
== 0)
998 int x
, m
, l
= 0, r
= RC_LAST
;
1002 x
= strcmp(str
, comms
[m
].name
);
1014 CheckArgNum(nr
, args
)
1019 static char *argss
[] = {"no", "one", "two", "three", "four", "OOPS"};
1020 static char *orformat
[] =
1022 "%s: %s: %s argument%s required",
1023 "%s: %s: %s or %s argument%s required",
1024 "%s: %s: %s, %s or %s argument%s required",
1025 "%s: %s: %s, %s, %s or %s argument%s required"
1028 n
= comms
[nr
].flags
& ARGS_MASK
;
1029 for (i
= 0; args
[i
]; i
++)
1031 if (comms
[nr
].flags
& ARGS_ORMORE
)
1035 Msg(0, "%s: %s: at least %s argument%s required",
1036 rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1040 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1041 (comms
[nr
].flags
& ARGS_PLUS2
) &&
1042 (comms
[nr
].flags
& ARGS_PLUS3
))
1044 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2 && i
!= n
+ 3)
1046 Msg(0, orformat
[3], rc_name
, comms
[nr
].name
, argss
[n
],
1047 argss
[n
+ 1], argss
[n
+ 2], argss
[n
+ 3], "");
1051 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1052 (comms
[nr
].flags
& ARGS_PLUS2
))
1054 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2)
1056 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1057 argss
[n
+ 1], argss
[n
+ 2], "");
1061 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1062 (comms
[nr
].flags
& ARGS_PLUS3
))
1064 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 3)
1066 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1067 argss
[n
+ 1], argss
[n
+ 3], "");
1071 else if ((comms
[nr
].flags
& ARGS_PLUS2
) &&
1072 (comms
[nr
].flags
& ARGS_PLUS3
))
1074 if (i
!= n
&& i
!= n
+ 2 && i
!= n
+ 3)
1076 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1077 argss
[n
+ 2], argss
[n
+ 3], "");
1081 else if (comms
[nr
].flags
& ARGS_PLUS1
)
1083 if (i
!= n
&& i
!= n
+ 1)
1085 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1086 argss
[n
+ 1], n
!= 0 ? "s" : "");
1090 else if (comms
[nr
].flags
& ARGS_PLUS2
)
1092 if (i
!= n
&& i
!= n
+ 2)
1094 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1099 else if (comms
[nr
].flags
& ARGS_PLUS3
)
1101 if (i
!= n
&& i
!= n
+ 3)
1103 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1110 Msg(0, orformat
[0], rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1117 StuffFin(buf
, len
, data
)
1125 LayProcess(&buf
, &len
);
1135 char **args
= act
->args
;
1136 int *argl
= act
->argl
;
1138 int argc
, i
, n
, msgok
;
1141 struct display
*odisplay
= display
;
1142 struct acluser
*user
;
1144 user
= display
? D_user
: users
;
1145 if (nr
== RC_ILLEGAL
)
1147 debug1("key '%c': No action\n", key
);
1150 n
= comms
[nr
].flags
;
1151 /* Commands will have a CAN_QUERY flag, depending on whether they have
1152 * something to return on a query. For example, 'windows' can return a result,
1153 * but 'other' cannot.
1154 * If some command causes an error, then it should reset queryflag to -1, so that
1155 * the process requesting the query can be notified that an error happened.
1157 if (!(n
& CAN_QUERY
) && queryflag
>= 0)
1159 /* Query flag is set, but this command cannot be queried. */
1160 Msg(0, "%s command cannot be queried.", comms
[nr
].name
);
1164 if ((n
& NEED_DISPLAY
) && display
== 0)
1166 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1170 if ((n
& NEED_FORE
) && fore
== 0)
1172 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1176 if ((n
& NEED_LAYER
) && flayer
== 0)
1178 Msg(0, "%s: %s: display or window required", rc_name
, comms
[nr
].name
);
1182 if ((argc
= CheckArgNum(nr
, args
)) < 0)
1187 if (AclCheckPermCmd(D_user
, ACL_EXEC
, &comms
[nr
]))
1189 Msg(0, "%s: %s: permission denied (user %s)",
1190 rc_name
, comms
[nr
].name
, (EffectiveAclUser
? EffectiveAclUser
: D_user
)->u_name
);
1195 #endif /* MULTIUSER */
1197 msgok
= display
&& !*rc_name
;
1203 else if (args
[0][0] == '-' && !args
[0][1])
1205 SetForeWindow((struct win
*)0);
1208 else if (args
[0][0] == '.' && !args
[0][1])
1212 Msg(0, "select . needs a window");
1217 SetForeWindow(fore
);
1221 else if (ParseWinNum(act
, &n
) == 0)
1223 else if (queryflag
>= 0)
1224 queryflag
= -1; /* ParseWinNum already prints out an appropriate error message. */
1227 case RC_DEFAUTONUKE
:
1228 if (ParseOnOff(act
, &defautonuke
) == 0 && msgok
)
1229 Msg(0, "Default autonuke turned %s", defautonuke
? "on" : "off");
1230 if (display
&& *rc_name
)
1231 D_auto_nuke
= defautonuke
;
1234 if (ParseOnOff(act
, &D_auto_nuke
) == 0 && msgok
)
1235 Msg(0, "Autonuke turned %s", D_auto_nuke
? "on" : "off");
1238 case RC_DEFOBUFLIMIT
:
1239 if (ParseNum(act
, &defobuflimit
) == 0 && msgok
)
1240 Msg(0, "Default limit set to %d", defobuflimit
);
1241 if (display
&& *rc_name
)
1243 D_obufmax
= defobuflimit
;
1244 D_obuflenmax
= D_obuflen
- D_obufmax
;
1249 Msg(0, "Limit is %d, current buffer size is %d", D_obufmax
, D_obuflen
);
1250 else if (ParseNum(act
, &D_obufmax
) == 0 && msgok
)
1251 Msg(0, "Limit set to %d", D_obufmax
);
1252 D_obuflenmax
= D_obuflen
- D_obufmax
;
1254 case RC_DUMPTERMCAP
:
1255 WriteFile(user
, (char *)0, DUMP_TERMCAP
);
1259 int mode
= DUMP_HARDCOPY
;
1261 if (argc
> 1 && !strcmp(*args
, "-h"))
1263 mode
= DUMP_SCROLLBACK
;
1267 if (*args
&& args
[1])
1269 Msg(0, "%s: hardcopy: too many arguments", rc_name
);
1272 if (fore
== 0 && *args
== 0)
1273 Msg(0, "%s: hardcopy: window required", rc_name
);
1275 WriteFile(user
, *args
, mode
);
1279 (void)ParseOnOff(act
, &nwin_default
.Lflag
);
1282 n
= fore
->w_log
? 1 : 0;
1283 ParseSwitch(act
, &n
);
1293 SwitchWindow(NextWindow());
1297 SwitchWindow(PreviousWindow());
1306 Input(fore
->w_pwin
? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1308 Input("Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1316 FreePseudowin(fore
);
1317 Msg(0, "Filter removed.");
1321 name
= SaveStr(fore
->w_title
);
1323 Msg(0, "Window %d (%s) killed.", n
, name
);
1331 Input("Really quit and kill all your windows [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_QUIT
);
1338 if (*args
&& !strcmp(*args
, "-h"))
1350 Input(buf
, 1, INP_RAW
, pow_detach_fn
, NULL
, 0);
1353 Detach(D_POWER
); /* detach and kill Attacher's parent */
1362 Msg(0, "debugging info is written to %s/", DEBUGDIR
);
1364 Msg(0, "debugging is currently off. Use 'debug on' to enable.");
1369 debug("debug: closing debug file.\n");
1374 if (strcmp("off", *args
))
1378 kill(D_userpid
, SIG_NODEBUG
); /* a one shot item, but hey... */
1379 # endif /* SIG_NODEBUG */
1381 if (*args
== 0 || strcmp("off", *args
))
1382 Msg(0, "Sorry, screen was compiled without -DDEBUG option.");
1387 if (*args
&& !strcmp(*args
, "sendcmd"))
1391 free(zmodem_sendcmd
);
1392 zmodem_sendcmd
= SaveStr(args
[1]);
1395 Msg(0, "zmodem sendcmd: %s", zmodem_sendcmd
);
1398 if (*args
&& !strcmp(*args
, "recvcmd"))
1402 free(zmodem_recvcmd
);
1403 zmodem_recvcmd
= SaveStr(args
[1]);
1406 Msg(0, "zmodem recvcmd: %s", zmodem_recvcmd
);
1411 for (i
= 0; i
< 4; i
++)
1412 if (!strcmp(zmodes
[i
], *args
))
1414 if (i
== 4 && !strcmp(*args
, "on"))
1418 Msg(0, "usage: zmodem off|auto|catch|pass");
1424 Msg(0, "zmodem mode is %s", zmodes
[zmodem_mode
]);
1429 register unsigned int i
;
1431 for (i
= 0; i
< sizeof(ktab
)/sizeof(*ktab
); i
++)
1432 ClearAction(&ktab
[i
]);
1433 Msg(0, "Unbound all keys." );
1440 ZombieKey_destroy
= 0;
1443 if (*argl
== 0 || *argl
> 2)
1445 Msg(0, "%s:zombie: one or two characters expected.", rc_name
);
1450 if (!strcmp(args
[1], "onerror"))
1452 ZombieKey_onerror
= 1;
1454 Msg(0, "usage: zombie [keys [onerror]]");
1458 ZombieKey_onerror
= 0;
1459 ZombieKey_destroy
= args
[0][0];
1460 ZombieKey_resurrect
= *argl
== 2 ? args
[0][1] : 0;
1470 struct display
*olddisplay
= display
;
1471 display
= 0; /* no display will cause a broadcast */
1472 Msg(0, "%s: %s", s
, *args
);
1473 display
= olddisplay
;
1477 /* where this AT command comes from: */
1481 s
= SaveStr(user
->u_name
);
1482 /* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
1483 EffectiveAclUser
= user
;
1485 s
= SaveStr(display
? D_usertty
: user
->u_name
);
1487 n
= strlen(args
[0]);
1490 * the windows/displays loops are quite dangerous here, take extra
1491 * care not to trigger landmines. Things may appear/disappear while
1492 * we are walking along.
1496 case '*': /* user */
1505 for (u
= users
; u
; u
= u
->u_next
)
1507 debug3("strncmp('%s', '%s', %d)\n", *args
, u
->u_name
, n
);
1508 if (!strncmp(*args
, u
->u_name
, n
))
1514 Msg(0, "Did not find any user matching '%s'", args
[0]);
1518 debug1("at all displays of user %s\n", u
->u_name
);
1519 for (display
= displays
; display
; display
= nd
)
1521 nd
= display
->d_next
;
1524 flayer
= D_forecv
->c_layer
;
1528 debug1("AT display %s\n", D_usertty
);
1529 DoCommand(args
+ 1, argl
+ 1);
1531 Msg(0, "command from %s: %s %s",
1532 s
, args
[1], args
[2] ? args
[2] : "");
1539 case '%': /* display */
1543 debug1("at display matching '%s'\n", args
[0]);
1544 for (display
= displays
; display
; display
= nd
)
1546 nd
= display
->d_next
;
1550 flayer
= D_forecv
->c_layer
;
1551 if (strncmp(args
[0], D_usertty
, n
) &&
1552 (strncmp("/dev/", D_usertty
, 5) ||
1553 strncmp(args
[0], D_usertty
+ 5, n
)) &&
1554 (strncmp("/dev/tty", D_usertty
, 8) ||
1555 strncmp(args
[0], D_usertty
+ 8, n
)))
1557 debug1("AT display %s\n", D_usertty
);
1558 DoCommand(args
+ 1, argl
+ 1);
1560 Msg(0, "command from %s: %s %s",
1561 s
, args
[1], args
[2] ? args
[2] : "");
1568 case '#': /* window */
1579 if (!*args
[0] || (i
= WindowByNumber(args
[0])) < 0)
1581 args
[0][n
] = ch
; /* must restore string in case of bind */
1582 /* try looping over titles */
1583 for (fore
= windows
; fore
; fore
= nw
)
1586 if (strncmp(args
[0], fore
->w_title
, n
))
1588 debug2("AT window %d(%s)\n", fore
->w_number
, fore
->w_title
);
1590 * consider this a bug or a feature:
1591 * while looping through windows, we have fore AND
1592 * display context. This will confuse users who try to
1593 * set up loops inside of loops, but often allows to do
1594 * what you mean, even when you adress your context wrong.
1597 /* XXX: other displays? */
1598 if (fore
->w_layer
.l_cvlist
)
1599 display
= fore
->w_layer
.l_cvlist
->c_display
;
1600 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1601 DoCommand(args
+ 1, argl
+ 1); /* may destroy our display */
1602 if (fore
&& fore
->w_layer
.l_cvlist
)
1604 display
= fore
->w_layer
.l_cvlist
->c_display
;
1605 Msg(0, "command from %s: %s %s",
1606 s
, args
[1], args
[2] ? args
[2] : "");
1612 Msg(0, "%s: at '%s': no such window.\n", rc_name
, args
[0]);
1615 else if (i
< maxwin
&& (fore
= wtab
[i
]))
1617 args
[0][n
] = ch
; /* must restore string in case of bind */
1618 debug2("AT window %d (%s)\n", fore
->w_number
, fore
->w_title
);
1619 if (fore
->w_layer
.l_cvlist
)
1620 display
= fore
->w_layer
.l_cvlist
->c_display
;
1621 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1622 DoCommand(args
+ 1, argl
+ 1);
1623 if (fore
&& fore
->w_layer
.l_cvlist
)
1625 display
= fore
->w_layer
.l_cvlist
->c_display
;
1626 Msg(0, "command from %s: %s %s",
1627 s
, args
[1], args
[2] ? args
[2] : "");
1633 Msg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name
);
1639 EffectiveAclUser
= NULL
;
1646 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1647 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1649 i
= FindEncoding(args
[1]);
1652 Msg(0, "%s: readreg: unknown encoding", rc_name
);
1659 * Without arguments we prompt for a destination register.
1660 * It will receive the copybuffer contents.
1661 * This is not done by RC_PASTE, as we prompt for source
1664 if ((s
= *args
) == NULL
)
1666 Input("Copy to register:", 1, INP_RAW
, copy_reg_fn
, NULL
, 0);
1671 Msg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name
);
1676 * With two arguments we *really* read register contents from file
1682 Msg(0, "%s: readreg: too many arguments", rc_name
);
1685 if ((s
= ReadFile(args
[1], &n
)))
1687 struct plop
*pp
= plop_tab
+ (int)(unsigned char)ch
;
1700 * with one argument we copy the copybuffer into a specified register
1701 * This could be done with RC_PASTE too, but is here to be consistent
1702 * with the zero argument call.
1704 copy_reg_fn(&ch
, 0, NULL
);
1709 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1710 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1712 i
= FindEncoding(args
[1]);
1715 Msg(0, "%s: register: unknown encoding", rc_name
);
1724 Msg(0, "%s: register: illegal number of arguments.", rc_name
);
1729 Msg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name
);
1736 if (user
->u_plop
.buf
!= NULL
)
1737 UserFreeCopyBuffer(user
);
1738 if (args
[1] && args
[1][0])
1740 user
->u_plop
.buf
= SaveStrn(args
[1], argl
[1]);
1741 user
->u_plop
.len
= argl
[1];
1743 user
->u_plop
.enc
= i
;
1750 struct plop
*plp
= plop_tab
+ (int)(unsigned char)ch
;
1754 plp
->buf
= SaveStrn(args
[1], argl
[1]);
1762 if ((s
= *args
) == NULL
)
1764 Input("Process register:", 1, INP_RAW
, process_fn
, NULL
, 0);
1769 Msg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name
);
1773 process_fn(&ch
, 0, NULL
);
1779 Input("Stuff:", 100, INP_COOKED
, StuffFin
, NULL
, 0);
1785 if (strcmp(s
, "-k"))
1787 Msg(0, "%s: stuff: invalid option %s", rc_name
, s
);
1791 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
1792 if (strcmp(term
[i
].tcname
, s
) == 0)
1796 Msg(0, "%s: stuff: unknown key '%s'", rc_name
, s
);
1800 if (StuffKey(i
- T_CAPS
) == 0)
1803 s
= display
? D_tcs
[i
].str
: 0;
1818 Msg(0, "screen %s", version
);
1823 timestring
= SaveStr(*args
);
1826 Msg(0, "%s", MakeWinMsg(timestring
, fore
, '%'));
1836 struct action
*ktabp
= ktab
;
1837 if (argc
== 2 && !strcmp(*args
, "-c"))
1839 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
1841 Msg(0, "Unknown command class '%s'", args
[1]);
1845 if (D_ESCseen
!= ktab
|| ktabp
!= ktab
)
1855 SwitchWindow(display
&& D_other
? D_other
->w_number
: NextWindow());
1858 if (user
->u_Esc
== -1)
1877 case RC_DEFBREAKTYPE
:
1880 static char *types
[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL
};
1881 extern int breaktype
;
1885 if (ParseNum(act
, &n
))
1886 for (n
= 0; n
< (int)(sizeof(types
)/sizeof(*types
)); n
++)
1888 for (i
= 0; i
< 4; i
++)
1891 if (ch
>= 'a' && ch
<= 'z')
1893 if (ch
!= types
[n
][i
] && (ch
+ ('a' - 'A')) != types
[n
][i
])
1899 if (n
< 0 || n
>= (int)(sizeof(types
)/sizeof(*types
)))
1900 Msg(0, "%s invalid, chose one of %s, %s or %s", *args
, types
[0], types
[1], types
[2]);
1904 Msg(0, "breaktype set to (%d) %s", n
, types
[n
]);
1908 Msg(0, "breaktype is (%d) %s", breaktype
, types
[breaktype
]);
1914 if (*args
&& ParseNum(act
, &n
))
1916 SendBreak(fore
, n
, nr
== RC_POW_BREAK
);
1930 if (*args
&& !strcmp(*args
, "-w"))
1932 else if (*args
&& !strcmp(*args
, "-d"))
1936 if (what
== 0 && flayer
&& !display
)
1942 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1945 w
= flayer
->l_width
;
1946 h
= flayer
->l_height
;
1952 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1958 if (*args
&& args
[0][0] == '-')
1960 Msg(0, "%s: %s: unknown option %s", rc_name
, comms
[nr
].name
, *args
);
1963 if (nr
== RC_HEIGHT
)
1971 else if (h
== H1height
)
1973 else if (h
> (H0height
+ H1height
) / 2)
1991 else if (w
== Z1width
)
1993 else if (w
> (Z0width
+ Z1width
) / 2)
2005 if (*args
&& args
[1] && args
[2])
2007 Msg(0, "%s: %s: too many arguments", rc_name
, comms
[nr
].name
);
2012 Msg(0, "Illegal width");
2017 Msg(0, "Illegal height");
2022 if (flayer
->l_width
== w
&& flayer
->l_height
== h
)
2024 ResizeLayer(flayer
, w
, h
, (struct display
*)0);
2027 if (D_width
== w
&& D_height
== h
)
2031 ChangeScreenSize(w
, h
, 1);
2035 if (ResizeDisplay(w
, h
) == 0)
2037 Activate(D_fore
? D_fore
->w_norefresh
: 0);
2039 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
2043 Msg(0, "Your termcap does not specify how to change the terminal's width to %d.", w
);
2044 else if (w
== D_width
)
2045 Msg(0, "Your termcap does not specify how to change the terminal's height to %d.", h
);
2047 Msg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w
, h
);
2055 Msg(0, "%s", fore
->w_title
);
2062 ChangeAKA(fore
, *args
, strlen(*args
));
2065 Input(":", 100, INP_EVERY
, Colonfin
, NULL
, 0);
2066 if (*args
&& **args
)
2074 if (D_status_lastmsg
)
2075 Msg(0, "%s", D_status_lastmsg
);
2078 DoScreen("key", args
);
2081 if (ParseSwitch(act
, &fore
->w_wrap
) == 0 && msgok
)
2082 Msg(0, "%cwrap", fore
->w_wrap
? '+' : '-');
2087 if (args
[0][0] == 'a')
2089 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) ? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
2093 if (ParseOnOff(act
, &n
))
2095 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | n
;
2100 if (fore
->w_flow
& FLOW_AUTOFLAG
)
2101 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | FLOW_NOW
;
2102 else if (fore
->w_flow
& FLOW_NOW
)
2103 fore
->w_flow
&= ~FLOW_NOW
;
2105 fore
->w_flow
= fore
->w_flow
? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
2107 SetFlow(fore
->w_flow
& FLOW_NOW
);
2109 Msg(0, "%cflow%s", (fore
->w_flow
& FLOW_NOW
) ? '+' : '-',
2110 (fore
->w_flow
& FLOW_AUTOFLAG
) ? "(auto)" : "");
2113 case RC_DEFWRITELOCK
:
2114 if (args
[0][0] == 'a')
2115 nwin_default
.wlock
= WLOCK_AUTO
;
2118 if (ParseOnOff(act
, &n
))
2120 nwin_default
.wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2126 if (args
[0][0] == 'a')
2128 fore
->w_wlock
= WLOCK_AUTO
;
2132 if (ParseOnOff(act
, &n
))
2134 fore
->w_wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2137 * user may have permission to change the writelock setting,
2138 * but he may never aquire the lock himself without write permission
2140 if (!AclCheckPermWin(D_user
, ACL_WRITE
, fore
))
2141 fore
->w_wlockuser
= D_user
;
2143 Msg(0, "writelock %s", (fore
->w_wlock
== WLOCK_AUTO
) ? "auto" :
2144 ((fore
->w_wlock
== WLOCK_OFF
) ? "off" : "on"));
2148 ResetAnsiState(fore
);
2149 WriteString(fore
, "\033[H\033[J", 6);
2152 ResetAnsiState(fore
);
2154 if (fore
->w_zdisplay
)
2155 zmodem_abort(fore
, fore
->w_zdisplay
);
2157 WriteString(fore
, "\033c", 2);
2160 n
= fore
->w_monitor
!= MON_OFF
;
2163 n
= n
&& (ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
));
2165 if (ParseSwitch(act
, &n
))
2170 if (display
) /* we tell only this user */
2171 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2173 for (i
= 0; i
< maxusercount
; i
++)
2174 ACLBYTE(fore
->w_mon_notify
, i
) |= ACLBIT(i
);
2176 if (fore
->w_monitor
== MON_OFF
)
2177 fore
->w_monitor
= MON_ON
;
2178 Msg(0, "Window %d (%s) is now being monitored for all activity.", fore
->w_number
, fore
->w_title
);
2183 if (display
) /* we remove only this user */
2184 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
)
2185 &= ~ACLBIT(D_user
->u_id
);
2187 for (i
= 0; i
< maxusercount
; i
++)
2188 ACLBYTE(fore
->w_mon_notify
, i
) &= ~ACLBIT(i
);
2189 for (i
= maxusercount
- 1; i
>= 0; i
--)
2190 if (ACLBYTE(fore
->w_mon_notify
, i
))
2194 fore
->w_monitor
= MON_OFF
;
2195 Msg(0, "Window %d (%s) is no longer being monitored for activity.", fore
->w_number
, fore
->w_title
);
2205 display_wlist(0, WLIST_NUM
, (struct win
*)0);
2206 else if (!strcmp(*args
, "string"))
2212 wliststr
= SaveStr(args
[1]);
2215 Msg(0, "windowlist string is '%s'", wliststr
);
2217 else if (!strcmp(*args
, "title"))
2223 wlisttit
= SaveStr(args
[1]);
2226 Msg(0, "windowlist title is '%s'", wlisttit
);
2232 for (i
= 0; i
< argc
; i
++)
2235 else if (!strcmp(args
[i
], "-m"))
2237 else if (!strcmp(args
[i
], "-b"))
2239 else if (!strcmp(args
[i
], "-g"))
2240 flag
|= WLIST_NESTED
;
2243 Msg(0, "usage: windowlist [-b] [-g] [-m] [string [string] | title [title]]");
2247 display_wlist(blank
, flag
, (struct win
*)0);
2251 if (argc
== 2 && !strcmp(*args
, "-c"))
2253 struct action
*ktabp
;
2254 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
2256 Msg(0, "Unknown command class '%s'", args
[1]);
2259 display_help(args
[1], ktabp
);
2262 display_help((char *)0, ktab
);
2265 display_copyright();
2269 if (flayer
->l_layfn
!= &WinLf
)
2271 Msg(0, "Must be on a window layer");
2275 WindowChanged(fore
, 'P');
2279 static char *pasteargs
[] = {".", 0};
2280 static int pasteargl
[] = {1};
2282 if (flayer
->l_layfn
!= &WinLf
)
2284 Msg(0, "Must be on a window layer");
2287 if (GetHistory() == 0)
2289 if (user
->u_plop
.buf
== NULL
)
2297 char *ss
, *dbuf
, dch
;
2304 * without args we prompt for one(!) register to be pasted in the window
2306 if ((s
= *args
) == NULL
)
2308 Input("Paste from register:", 1, INP_RAW
, ins_reg_fn
, NULL
, 0);
2311 if (args
[1] == 0 && !fore
) /* no window? */
2314 * with two arguments we paste into a destination register
2315 * (no window needed here).
2317 if (args
[1] && argl
[1] != 1)
2319 Msg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
2325 enc
= fore
->w_encoding
;
2329 * measure length of needed buffer
2331 for (ss
= s
= *args
; (ch
= *ss
); ss
++)
2337 enc
= user
->u_plop
.enc
;
2338 if (enc
!= user
->u_plop
.enc
)
2339 l
+= RecodeBuf((unsigned char *)user
->u_plop
.buf
, user
->u_plop
.len
, user
->u_plop
.enc
, enc
, (unsigned char *)0);
2342 l
+= user
->u_plop
.len
;
2348 enc
= plop_tab
[(int)(unsigned char)ch
].enc
;
2349 if (enc
!= plop_tab
[(int)(unsigned char)ch
].enc
)
2350 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);
2353 l
+= plop_tab
[(int)(unsigned char)ch
].len
;
2358 Msg(0, "empty buffer");
2363 * if there is only one source and the destination is a window, then
2364 * pass a pointer rather than duplicating the buffer.
2366 if (s
[1] == 0 && args
[1] == 0)
2368 if (enc
== (*s
== '.' ? user
->u_plop
.enc
: plop_tab
[(int)(unsigned char)*s
].enc
))
2371 MakePaster(&fore
->w_paster
, *s
== '.' ? user
->u_plop
.buf
: plop_tab
[(int)(unsigned char)*s
].buf
, l
, 0);
2375 * if no shortcut, we construct a buffer
2377 if ((dbuf
= (char *)malloc(l
)) == 0)
2384 * concatenate all sources into our own buffer, copy buffer is
2385 * special and is skipped if no display exists.
2387 for (ss
= s
; (ch
= *ss
); ss
++)
2389 struct plop
*pp
= (ch
== '.' ? &user
->u_plop
: &plop_tab
[(int)(unsigned char)ch
]);
2393 l
+= RecodeBuf((unsigned char *)pp
->buf
, pp
->len
, pp
->enc
, enc
, (unsigned char *)dbuf
+ l
);
2397 bcopy(pp
->buf
, dbuf
+ l
, pp
->len
);
2401 * when called with one argument we paste our buffer into the window
2405 MakePaster(&fore
->w_paster
, dbuf
, l
, 1);
2410 * we have two arguments, the second is already in dch.
2411 * use this as destination rather than the window.
2416 if (user
->u_plop
.buf
!= NULL
)
2417 UserFreeCopyBuffer(user
);
2418 user
->u_plop
.buf
= dbuf
;
2419 user
->u_plop
.len
= l
;
2421 user
->u_plop
.enc
= enc
;
2426 struct plop
*pp
= plop_tab
+ (int)(unsigned char)dch
;
2439 if (!user
->u_plop
.buf
)
2441 Msg(0, "empty buffer");
2446 struct plop oldplop
;
2448 oldplop
= user
->u_plop
;
2449 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2454 enc
= FindEncoding(args
[1]);
2457 Msg(0, "%s: writebuf: unknown encoding", rc_name
);
2460 if (enc
!= oldplop
.enc
)
2462 l
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)0);
2463 newbuf
= malloc(l
+ 1);
2469 user
->u_plop
.len
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)newbuf
);
2470 user
->u_plop
.buf
= newbuf
;
2471 user
->u_plop
.enc
= enc
;
2476 if (args
[0] && args
[1])
2477 Msg(0, "%s: writebuf: too many arguments", rc_name
);
2479 WriteFile(user
, args
[0], DUMP_EXCHANGE
);
2481 if (user
->u_plop
.buf
!= oldplop
.buf
)
2482 free(user
->u_plop
.buf
);
2483 user
->u_plop
= oldplop
;
2489 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
2490 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2492 i
= FindEncoding(args
[1]);
2495 Msg(0, "%s: readbuf: unknown encoding", rc_name
);
2501 if (args
[0] && args
[1])
2503 Msg(0, "%s: readbuf: too many arguments", rc_name
);
2506 if ((s
= ReadFile(args
[0] ? args
[0] : BufferFile
, &n
)))
2508 if (user
->u_plop
.buf
)
2509 UserFreeCopyBuffer(user
);
2510 user
->u_plop
.len
= n
;
2511 user
->u_plop
.buf
= s
;
2513 user
->u_plop
.enc
= i
;
2521 (void)ParseSwitch(act
, &search_ic
);
2523 Msg(0, "Will %signore case in searches", search_ic
? "" : "not ");
2525 #endif /* COPY_PASTE */
2528 SetEscape(user
, -1, -1);
2529 else if (*argl
== 2)
2530 SetEscape(user
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2533 Msg(0, "%s: two characters required after escape.", rc_name
);
2536 /* Change defescape if master user. This is because we only
2539 if (display
&& user
!= users
)
2544 SetEscape(NULL
, -1, -1);
2545 else if (*argl
== 2)
2546 SetEscape(NULL
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2549 Msg(0, "%s: two characters required after defescape.", rc_name
);
2557 s
= *args
? *args
: home
;
2559 Msg(errno
, "%s", s
);
2563 if (ParseSaveStr(act
, &ShellProg
) == 0)
2564 ShellArgs
[0] = ShellProg
;
2566 case RC_HARDCOPYDIR
:
2568 (void)ParseSaveStr(act
, &hardcopydir
);
2570 Msg(0, "hardcopydir is %s\n", hardcopydir
&& *hardcopydir
? hardcopydir
: "<cwd>");
2575 if (args
[1] && !(strcmp(*args
, "flush")))
2577 log_flush
= atoi(args
[1]);
2579 Msg(0, "log flush timeout set to %ds\n", log_flush
);
2582 if (ParseSaveStr(act
, &screenlogfile
) || !msgok
)
2585 Msg(0, "logfile is '%s'", screenlogfile
);
2588 if (!*args
|| !strcmp(*args
, "on") || !strcmp(*args
, "off"))
2590 if (ParseSwitch(act
, &logtstamp_on
) == 0 && msgok
)
2591 Msg(0, "timestamps turned %s", logtstamp_on
? "on" : "off");
2593 else if (!strcmp(*args
, "string"))
2597 if (logtstamp_string
)
2598 free(logtstamp_string
);
2599 logtstamp_string
= SaveStr(args
[1]);
2602 Msg(0, "logfile timestamp is '%s'", logtstamp_string
);
2604 else if (!strcmp(*args
, "after"))
2608 logtstamp_after
= atoi(args
[1]);
2612 Msg(0, "timestamp printed after %ds\n", logtstamp_after
);
2615 Msg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
2618 (void)ParseSaveStr(act
, &nwin_default
.aka
);
2621 case RC_TERMCAPINFO
:
2623 if (!rc_name
|| !*rc_name
)
2624 Msg(0, "Sorry, too late now. Place that in your .screenrc file.");
2627 break; /* Already handled */
2630 if (ParseSaveStr(act
, &s
))
2632 if (strlen(s
) >= 20)
2634 Msg(0, "%s: term: argument too long ( < 20)", rc_name
);
2638 strcpy(screenterm
, s
);
2640 debug1("screenterm set to %s\n", screenterm
);
2641 MakeTermcap((display
== 0));
2642 debug("new termcap made\n");
2645 if (!msgok
&& (!rc_name
|| strcmp(rc_name
, "-X")))
2648 * user typed ^A:echo... well, echo isn't FinishRc's job,
2649 * but as he wanted to test us, we show good will
2651 if (argc
> 1 && !strcmp(*args
, "-n"))
2657 if (argc
> 1 && !strcmp(*args
, "-p"))
2663 s
= MakeWinMsg(s
, fore
, '%');
2669 Msg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name
);
2678 AddXChars(buf
, sizeof(buf
), BellString
);
2679 Msg(0, "bell_msg is '%s'", buf
);
2682 (void)ParseSaveStr(act
, &BellString
);
2687 BufferFile
= SaveStr(DEFAULT_BUFFERFILE
);
2688 else if (ParseSaveStr(act
, &BufferFile
))
2691 Msg(0, "Bufferfile is now '%s'", BufferFile
);
2695 (void)ParseSaveStr(act
, &ActivityString
);
2697 #if defined(DETACH) && defined(POW_DETACH)
2698 case RC_POW_DETACH_MSG
:
2702 AddXChars(buf
, sizeof(buf
), PowDetachString
);
2703 Msg(0, "pow_detach_msg is '%s'", buf
);
2706 (void)ParseSaveStr(act
, &PowDetachString
);
2709 #if defined(UTMPOK) && defined(LOGOUTOK)
2711 n
= fore
->w_slot
!= (slot_t
)-1;
2712 if (*args
&& !strcmp(*args
, "always"))
2719 if (*args
&& !strcmp(*args
, "attached"))
2726 if (ParseSwitch(act
, &n
) == 0)
2730 if (!strcmp(*args
, "always"))
2731 nwin_default
.lflag
|= 2;
2732 else if (!strcmp(*args
, "attached"))
2733 nwin_default
.lflag
&= ~2;
2735 (void)ParseOnOff(act
, &nwin_default
.lflag
);
2739 if (args
[0] && args
[1] && args
[1][0] == 'i')
2742 for (display
= displays
; display
; display
= display
->d_next
)
2746 #if defined(TERMIO) || defined(POSIX)
2747 D_NewMode
.tio
.c_cc
[VINTR
] = D_OldMode
.tio
.c_cc
[VINTR
];
2748 D_NewMode
.tio
.c_lflag
|= ISIG
;
2749 #else /* TERMIO || POSIX */
2750 D_NewMode
.m_tchars
.t_intrc
= D_OldMode
.m_tchars
.t_intrc
;
2751 #endif /* TERMIO || POSIX */
2752 SetTTY(D_userfd
, &D_NewMode
);
2755 if (args
[0] && args
[0][0] == 'a')
2756 nwin_default
.flowflag
= FLOW_AUTOFLAG
;
2758 (void)ParseOnOff(act
, &nwin_default
.flowflag
);
2761 (void)ParseOnOff(act
, &nwin_default
.wrap
);
2764 (void)ParseOnOff(act
, &nwin_default
.c1
);
2768 (void)ParseOnOff(act
, &nwin_default
.bce
);
2772 (void)ParseOnOff(act
, &nwin_default
.gr
);
2775 if (ParseOnOff(act
, &n
) == 0)
2776 nwin_default
.monitor
= (n
== 0) ? MON_OFF
: MON_ON
;
2778 case RC_DEFMOUSETRACK
:
2779 if (ParseOnOff(act
, &n
) == 0)
2780 defmousetrack
= (n
== 0) ? 0 : 1000;
2785 Msg(0, "Mouse tracking for this display is turned %s", D_mousetrack
? "on" : "off");
2787 else if (ParseOnOff(act
, &n
) == 0)
2789 D_mousetrack
= n
== 0 ? 0 : 1000;
2791 MouseMode(D_fore
->w_mouse
);
2795 if (ParseOnOff(act
, &n
) == 0)
2796 nwin_default
.silence
= (n
== 0) ? SILENCE_OFF
: SILENCE_ON
;
2800 Msg(0, "W%s echo command when creating windows.",
2801 VerboseCreate
? "ill" : "on't");
2802 else if (ParseOnOff(act
, &n
) == 0)
2808 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
2811 if (args
[0] && strcmp(args
[0], "on") && strcmp(args
[0], "off"))
2813 struct display
*olddisplay
= display
;
2814 int old_use
, new_use
= -1;
2817 if (!strncmp(s
, "always", 6))
2819 if (!strcmp(s
, "lastline"))
2820 new_use
= HSTATUS_LASTLINE
;
2821 else if (!strcmp(s
, "ignore"))
2822 new_use
= HSTATUS_IGNORE
;
2823 else if (!strcmp(s
, "message"))
2824 new_use
= HSTATUS_MESSAGE
;
2825 else if (!strcmp(args
[0], "string"))
2830 AddXChars(buf
, sizeof(buf
), hstatusstring
);
2831 Msg(0, "hardstatus string is '%s'", buf
);
2837 Msg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name
);
2842 hardstatusemu
= new_use
| (s
== args
[0] ? 0 : HSTATUS_ALWAYS
);
2843 for (display
= displays
; display
; display
= display
->d_next
)
2846 new_use
= hardstatusemu
& ~HSTATUS_ALWAYS
;
2847 if (D_HS
&& s
== args
[0])
2848 new_use
= HSTATUS_HS
;
2849 ShowHStatus((char *)0);
2850 old_use
= D_has_hstatus
;
2851 D_has_hstatus
= new_use
;
2852 if ((new_use
== HSTATUS_LASTLINE
&& old_use
!= HSTATUS_LASTLINE
) || (new_use
!= HSTATUS_LASTLINE
&& old_use
== HSTATUS_LASTLINE
))
2853 ChangeScreenSize(D_width
, D_height
, 1);
2860 free(hstatusstring
);
2861 hstatusstring
= SaveStr(args
[1]);
2862 for (display
= displays
; display
; display
= display
->d_next
)
2865 display
= olddisplay
;
2868 (void)ParseSwitch(act
, &use_hardstatus
);
2870 Msg(0, "messages displayed on %s", use_hardstatus
? "hardstatus line" : "window");
2873 if (strcmp(args
[0], "always") == 0 || strcmp(args
[0], "splitonly") == 0)
2875 struct display
*olddisplay
= display
;
2877 captionalways
= args
[0][0] == 'a';
2878 for (display
= displays
; display
; display
= display
->d_next
)
2879 ChangeScreenSize(D_width
, D_height
, 1);
2880 display
= olddisplay
;
2882 else if (strcmp(args
[0], "string") == 0)
2887 AddXChars(buf
, sizeof(buf
), captionstring
);
2888 Msg(0, "caption string is '%s'", buf
);
2894 Msg(0, "%s: usage: caption always|splitonly|string <string>", rc_name
);
2900 free(captionstring
);
2901 captionstring
= SaveStr(args
[1]);
2902 RedisplayDisplays(0);
2905 n
= (console_window
!= 0);
2906 if (ParseSwitch(act
, &n
))
2908 if (TtyGrabConsole(fore
->w_ptyfd
, n
, rc_name
))
2911 Msg(0, "%s: releasing console %s", rc_name
, HostName
);
2912 else if (console_window
)
2913 Msg(0, "%s: stealing console %s from window %d (%s)", rc_name
,
2914 HostName
, console_window
->w_number
, console_window
->w_title
);
2916 Msg(0, "%s: grabbing console %s", rc_name
, HostName
);
2917 console_window
= n
? fore
: 0;
2920 if (ParseOnOff(act
, &all_norefresh
))
2922 if (!all_norefresh
&& fore
)
2925 Msg(0, all_norefresh
? "No refresh on window change!\n" :
2926 "Window specific refresh\n");
2929 (void)ParseSwitch(act
, &n
);
2930 fore
->w_norefresh
= n
;
2933 if (ParseSwitch(act
, &visual_bell
) || !msgok
)
2935 if (visual_bell
== 0)
2936 Msg(0, "switched to audible bell.");
2938 Msg(0, "switched to visual bell.");
2941 if (ParseNum1000(act
, &VBellWait
) == 0 && msgok
)
2942 Msg(0, "vbellwait set to %.10g seconds", VBellWait
/1000.);
2945 if (ParseNum1000(act
, &MsgWait
) == 0 && msgok
)
2946 Msg(0, "msgwait set to %.10g seconds", MsgWait
/1000.);
2949 if (ParseNum1000(act
, &MsgMinWait
) == 0 && msgok
)
2950 Msg(0, "msgminwait set to %.10g seconds", MsgMinWait
/1000.);
2952 case RC_SILENCEWAIT
:
2953 if (ParseNum(act
, &SilenceWait
))
2955 if (SilenceWait
< 1)
2957 for (p
= windows
; p
; p
= p
->w_next
)
2958 p
->w_silencewait
= SilenceWait
;
2960 Msg(0, "silencewait set to %d seconds", SilenceWait
);
2964 Msg(0, queryflag
>= 0 ? "%d (%s)" : "This is window %d (%s).", fore
->w_number
, fore
->w_title
);
2967 int old
= fore
->w_number
;
2969 if (args
[0][0] == '+')
2971 else if (args
[0][0] == '-')
2975 parse
= ParseNum(act
, &n
);
2984 if (n
< 0 || n
>= maxwin
)
2986 Msg(0, "Given window position is invalid.");
2997 /* exchange the acls for these windows. */
3001 /* exchange the utmp-slots for these windows */
3002 if ((fore
->w_slot
!= (slot_t
) -1) && (fore
->w_slot
!= (slot_t
) 0))
3007 if (p
&& (p
->w_slot
!= (slot_t
) -1) && (p
->w_slot
!= (slot_t
) 0))
3009 /* XXX: first display wins? */
3010 display
= fore
->w_layer
.l_cvlist
? fore
->w_layer
.l_cvlist
->c_display
: 0;
3016 WindowChanged(fore
, 'n');
3017 WindowChanged((struct win
*)0, 'w');
3018 WindowChanged((struct win
*)0, 'W');
3019 WindowChanged((struct win
*)0, 0);
3023 n
= fore
->w_silence
!= 0;
3024 i
= fore
->w_silencewait
;
3025 if (args
[0] && (args
[0][0] == '-' || (args
[0][0] >= '0' && args
[0][0] <= '9')))
3027 if (ParseNum(act
, &i
))
3031 else if (ParseSwitch(act
, &n
))
3036 if (display
) /* we tell only this user */
3037 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
3039 for (n
= 0; n
< maxusercount
; n
++)
3040 ACLBYTE(fore
->w_lio_notify
, n
) |= ACLBIT(n
);
3042 fore
->w_silencewait
= i
;
3043 fore
->w_silence
= SILENCE_ON
;
3044 SetTimeout(&fore
->w_silenceev
, fore
->w_silencewait
* 1000);
3045 evenq(&fore
->w_silenceev
);
3049 Msg(0, "The window is now being monitored for %d sec. silence.", fore
->w_silencewait
);
3054 if (display
) /* we remove only this user */
3055 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
)
3056 &= ~ACLBIT(D_user
->u_id
);
3058 for (n
= 0; n
< maxusercount
; n
++)
3059 ACLBYTE(fore
->w_lio_notify
, n
) &= ~ACLBIT(n
);
3060 for (i
= maxusercount
- 1; i
>= 0; i
--)
3061 if (ACLBYTE(fore
->w_lio_notify
, i
))
3066 fore
->w_silence
= SILENCE_OFF
;
3067 evdeq(&fore
->w_silenceev
);
3071 Msg(0, "The window is no longer being monitored for silence.");
3075 case RC_DEFSCROLLBACK
:
3076 (void)ParseNum(act
, &nwin_default
.histheight
);
3079 if (flayer
->l_layfn
== &MarkLf
)
3081 Msg(0, "Cannot resize scrollback buffer in copy/scrollback mode.");
3084 (void)ParseNum(act
, &n
);
3085 ChangeWindowSize(fore
, fore
->w_width
, fore
->w_height
, n
);
3087 Msg(0, "scrollback set to %d", fore
->w_histheight
);
3090 case RC_SESSIONNAME
:
3092 Msg(0, "This session is named '%s'\n", SockName
);
3095 char buf
[MAXPATHLEN
];
3098 if (ParseSaveStr(act
, &s
))
3100 if (!*s
|| strlen(s
) + (SockName
- SockPath
) > MAXPATHLEN
- 13 || index(s
, '/'))
3102 Msg(0, "%s: bad session name '%s'\n", rc_name
, s
);
3106 strncpy(buf
, SockPath
, SockName
- SockPath
);
3107 sprintf(buf
+ (SockName
- SockPath
), "%d.%s", (int)getpid(), s
);
3109 if ((access(buf
, F_OK
) == 0) || (errno
!= ENOENT
))
3111 Msg(0, "%s: inappropriate path: '%s'.", rc_name
, buf
);
3114 if (rename(SockPath
, buf
))
3116 Msg(errno
, "%s: failed to rename(%s, %s)", rc_name
, SockPath
, buf
);
3119 debug2("rename(%s, %s) done\n", SockPath
, buf
);
3120 strcpy(SockPath
, buf
);
3122 WindowChanged((struct win
*)0, 'S');
3126 if (!args
[0] || !args
[1])
3128 debug1("RC_SETENV arguments missing: %s\n", args
[0] ? args
[0] : "");
3129 InputSetenv(args
[0]);
3133 xsetenv(args
[0], args
[1]);
3142 case RC_DEFSLOWPASTE
:
3143 (void)ParseNum(act
, &nwin_default
.slow
);
3147 Msg(0, fore
->w_slowpaste
?
3148 "Slowpaste in window %d is %d milliseconds." :
3149 "Slowpaste in window %d is unset.",
3150 fore
->w_number
, fore
->w_slowpaste
);
3151 else if (ParseNum(act
, &fore
->w_slowpaste
) == 0 && msgok
)
3152 Msg(0, fore
->w_slowpaste
?
3153 "Slowpaste in window %d set to %d milliseconds." :
3154 "Slowpaste in window %d now unset.",
3155 fore
->w_number
, fore
->w_slowpaste
);
3158 if (CompileKeys(*args
, *argl
, mark_key_tab
))
3160 Msg(0, "%s: markkeys: syntax error.", rc_name
);
3163 debug1("markkeys %s\n", *args
);
3167 if (ParseSwitch(act
, &pastefont
) == 0 && msgok
)
3168 Msg(0, "Will %spaste font settings", pastefont
? "" : "not ");
3172 (void)ParseSwitch(act
, &join_with_cr
);
3174 case RC_COMPACTHIST
:
3175 if (ParseSwitch(act
, &compacthist
) == 0 && msgok
)
3176 Msg(0, "%scompacting history lines", compacthist
? "" : "not ");
3181 (void)ParseOnOff(act
, &nethackflag
);
3184 case RC_HARDCOPY_APPEND
:
3185 (void)ParseOnOff(act
, &hardcopy_append
);
3191 AddXChars(buf
, sizeof(buf
), VisualBellString
);
3192 Msg(0, "vbell_msg is '%s'", buf
);
3195 (void)ParseSaveStr(act
, &VisualBellString
);
3196 debug1(" new vbellstr '%s'\n", VisualBellString
);
3199 if (ParseBase(act
, *args
, &n
, 8, "octal"))
3201 if (n
< 0 || n
> 0777)
3203 Msg(0, "%s: mode: Invalid tty mode %o", rc_name
, n
);
3208 Msg(0, "Ttymode set to %03o", TtyMode
);
3211 (void)ParseOnOff(act
, &auto_detach
);
3213 case RC_STARTUP_MESSAGE
:
3214 (void)ParseOnOff(act
, &default_startup
);
3220 n
= (*user
->u_password
) ? 1 : 0;
3221 if (user
->u_password
!= NullStr
) free((char *)user
->u_password
);
3222 user
->u_password
= SaveStr(*args
);
3223 if (!strcmp(user
->u_password
, "none"))
3226 Msg(0, "Password checking disabled");
3227 free(user
->u_password
);
3228 user
->u_password
= NullStr
;
3235 Msg(0, "%s: password: window required", rc_name
);
3238 Input("New screen password:", 100, INP_NOECHO
, pass1
, display
? (char *)D_user
: (char *)users
, 0);
3241 #endif /* PASSWORD */
3244 struct action
*ktabp
= ktab
;
3249 if (argc
> 2 && !strcmp(*args
, "-c"))
3251 ktabp
= FindKtab(args
[1], 1);
3258 else if (argc
> 1 && !strcmp(*args
, "-k"))
3271 for (n
= 0; n
< KMAP_KEYS
; n
++)
3272 if (strcmp(term
[n
+ T_CAPS
].tcname
, *args
) == 0)
3276 Msg(0, "%s: bind: unknown key '%s'", rc_name
, *args
);
3285 Msg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name
);
3289 n
= (unsigned char)args
[0][0];
3293 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3295 Msg(0, "%s: bind: unknown command '%s'", rc_name
, args
[1]);
3298 if (CheckArgNum(i
, args
+ 2) < 0)
3300 ClearAction(&ktabp
[n
]);
3301 SaveAction(ktabp
+ n
, i
, args
+ 2, argl
+ 2);
3304 ClearAction(&ktabp
[n
]);
3310 struct action
*newact
;
3311 int newnr
, fl
= 0, kf
= 0, af
= 0, df
= 0, mf
= 0;
3312 struct display
*odisp
= display
;
3314 struct kmap_ext
*kme
;
3316 for (; *args
&& **args
== '-'; args
++, argl
++)
3318 if (strcmp(*args
, "-t") == 0)
3319 fl
= KMAP_NOTIMEOUT
;
3320 else if (strcmp(*args
, "-k") == 0)
3322 else if (strcmp(*args
, "-a") == 0)
3324 else if (strcmp(*args
, "-d") == 0)
3326 else if (strcmp(*args
, "-m") == 0)
3328 else if (strcmp(*args
, "--") == 0)
3336 Msg(0, "%s: bindkey: invalid option %s", rc_name
, *args
);
3342 Msg(0, "%s: bindkey: -d does not work with -m", rc_name
);
3348 display_bindkey("Edit mode", mmtab
);
3350 display_bindkey("Default", dmtab
);
3352 display_bindkey("User", umtab
);
3359 Msg(0, "%s: bindkey: -a only works with -k", rc_name
);
3364 Msg(0, "%s: bindkey: empty string makes no sense", rc_name
);
3367 for (i
= 0, kme
= kmap_exts
; i
< kmap_extn
; i
++, kme
++)
3374 if (*argl
== (kme
->fl
& ~KMAP_NOTIMEOUT
) && bcmp(kme
->str
, *args
, *argl
) == 0)
3380 Msg(0, "%s: bindkey: keybinding not found", rc_name
);
3384 kmap_exts
= (struct kmap_ext
*)xrealloc((char *)kmap_exts
, kmap_extn
* sizeof(*kmap_exts
));
3385 kme
= kmap_exts
+ i
;
3386 bzero((char *)kme
, 8 * sizeof(*kmap_exts
));
3387 for (; i
< kmap_extn
; i
++, kme
++)
3390 kme
->dm
.nr
= kme
->mm
.nr
= kme
->um
.nr
= RC_ILLEGAL
;
3391 kme
->dm
.args
= kme
->mm
.args
= kme
->um
.args
= noargs
;
3392 kme
->dm
.argl
= kme
->mm
.argl
= kme
->um
.argl
= 0;
3397 if (df
== 0 && kme
->dm
.nr
!= RC_ILLEGAL
)
3399 if (mf
== 0 && kme
->mm
.nr
!= RC_ILLEGAL
)
3401 if ((df
|| mf
) && kme
->um
.nr
!= RC_ILLEGAL
)
3403 i
+= KMAP_KEYS
+ KMAP_AKEYS
;
3404 newact
= df
? &kme
->dm
: mf
? &kme
->mm
: &kme
->um
;
3408 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
3409 if (strcmp(term
[i
].tcname
, *args
) == 0)
3413 Msg(0, "%s: bindkey: unknown key '%s'", rc_name
, *args
);
3416 if (af
&& i
>= T_CURSOR
&& i
< T_OCAPS
)
3417 i
-= T_CURSOR
- KMAP_KEYS
;
3420 newact
= df
? &dmtab
[i
] : mf
? &mmtab
[i
] : &umtab
[i
];
3424 if ((newnr
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3426 Msg(0, "%s: bindkey: unknown command '%s'", rc_name
, args
[1]);
3429 if (CheckArgNum(newnr
, args
+ 2) < 0)
3431 ClearAction(newact
);
3432 SaveAction(newact
, newnr
, args
+ 2, argl
+ 2);
3433 if (kf
== 0 && args
[1])
3437 kme
->str
= SaveStrn(*args
, *argl
);
3438 kme
->fl
= fl
| *argl
;
3442 ClearAction(newact
);
3443 for (display
= displays
; display
; display
= display
->d_next
)
3444 remap(i
, args
[1] ? 1 : 0);
3445 if (kf
== 0 && !args
[1])
3447 if (!used
&& kme
->str
)
3460 if (ParseNum(act
, &n
))
3464 Msg(0, "%s: maptimeout: illegal time %d", rc_name
, n
);
3469 if (*args
== 0 || msgok
)
3470 Msg(0, "maptimeout is %dms", maptimeout
);
3484 UsersAcl(NULL
, argc
, args
);
3487 if (UserDel(args
[0], NULL
))
3490 Msg(0, "%s removed from acl database", args
[0]);
3494 * modify a user to gain or lose rights granted to a group.
3495 * This group is actually a normal user whose rights were defined
3496 * with chacl in the usual way.
3500 if (strcmp(args
[1], "none")) /* link a user to another user */
3502 if (AclLinkUser(args
[0], args
[1]))
3505 Msg(0, "User %s joined acl-group %s", args
[0], args
[1]);
3507 else /* remove all groups from user */
3510 struct aclusergroup
*g
;
3512 if (!(u
= *FindUserPtr(args
[0])))
3514 while ((g
= u
->u_group
))
3516 u
->u_group
= g
->next
;
3521 else /* show all groups of user */
3523 char buf
[256], *p
= buf
;
3526 struct aclusergroup
*g
;
3528 if (!(u
= *FindUserPtr(args
[0])))
3531 Msg(0, "User %s does not exist.", args
[0]);
3538 sprintf(p
, "%s ", g
->u
->u_name
);
3546 Msg(0, "%s's group%s: %s.", args
[0], (ngroups
== 1) ? "" : "s",
3547 (ngroups
== 0) ? "none" : buf
);
3552 while ((s
= *args
++))
3556 if (AclUmask(display
? D_user
: users
, s
, &err
))
3557 Msg(0, "umask: %s\n", err
);
3561 if (ParseOnOff(act
, &n
))
3566 Msg(0, "Multiuser mode %s", multi
? "enabled" : "disabled");
3568 #endif /* MULTIUSER */
3576 i
= D_nonblock
>= 0;
3577 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3579 if (ParseNum1000(act
, &i
))
3582 else if (!ParseSwitch(act
, &i
))
3583 i
= i
== 0 ? -1 : 1000;
3586 if (msgok
&& i
== -1)
3587 Msg(0, "display set to blocking mode");
3588 else if (msgok
&& i
== 0)
3589 Msg(0, "display set to nonblocking mode, no timeout");
3591 Msg(0, "display set to nonblocking mode, %.10gs timeout", i
/1000.);
3593 if (D_nonblock
<= 0)
3594 evdeq(&D_blockedev
);
3596 case RC_DEFNONBLOCK
:
3597 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3599 if (ParseNum1000(act
, &defnonblock
))
3602 else if (!ParseOnOff(act
, &defnonblock
))
3603 defnonblock
= defnonblock
== 0 ? -1 : 1000;
3606 if (display
&& *rc_name
)
3608 D_nonblock
= defnonblock
;
3609 if (D_nonblock
<= 0)
3610 evdeq(&D_blockedev
);
3616 if (fore
->w_gr
== 2)
3619 if (ParseSwitch(act
, &fore
->w_gr
) == 0 && msgok
)
3620 Msg(0, "Will %suse GR", fore
->w_gr
? "" : "not ");
3622 if (fore
->w_gr
== 0 && fore
->w_FontE
)
3627 if (ParseSwitch(act
, &fore
->w_c1
) == 0 && msgok
)
3628 Msg(0, "Will %suse C1", fore
->w_c1
? "" : "not ");
3632 if (ParseSwitch(act
, &fore
->w_bce
) == 0 && msgok
)
3633 Msg(0, "Will %serase with background color", fore
->w_bce
? "" : "not ");
3640 if (*args
&& !strcmp(args
[0], "-d"))
3643 Msg(0, "encodings directory is %s", screenencodings
? screenencodings
: "<unset>");
3646 free(screenencodings
);
3647 screenencodings
= SaveStr(args
[1]);
3651 if (*args
&& !strcmp(args
[0], "-l"))
3654 Msg(0, "encoding: -l: argument required");
3655 else if (LoadFontTranslation(-1, args
[1]))
3656 Msg(0, "encoding: could not load utf8 encoding file");
3658 Msg(0, "encoding: utf8 encoding file loaded");
3662 if (*args
&& (!strcmp(args
[0], "-l") || !strcmp(args
[0], "-d")))
3665 Msg(0, "encoding: screen is not compiled for UTF-8.");
3669 for (i
= 0; i
< 2; i
++)
3673 if (!strcmp(args
[i
], "."))
3675 n
= FindEncoding(args
[i
]);
3678 Msg(0, "encoding: unknown encoding '%s'", args
[i
]);
3683 WinSwitchEncoding(fore
, n
);
3684 ResetCharsets(fore
);
3686 else if (i
&& display
)
3691 case RC_DEFENCODING
:
3692 n
= FindEncoding(*args
);
3695 Msg(0, "defencoding: unknown encoding '%s'", *args
);
3698 nwin_default
.encoding
= n
;
3704 n
= nwin_default
.encoding
== UTF8
;
3705 if (ParseSwitch(act
, &n
) == 0)
3707 nwin_default
.encoding
= n
? UTF8
: 0;
3709 Msg(0, "Will %suse UTF-8 encoding for new windows", n
? "" : "not ");
3713 for (i
= 0; i
< 2; i
++)
3715 if (i
&& args
[i
] == 0)
3718 n
= fore
->w_encoding
!= UTF8
;
3719 else if (strcmp(args
[i
], "off") == 0)
3721 else if (strcmp(args
[i
], "on") == 0)
3725 Msg(0, "utf8: illegal argument (%s)", args
[i
]);
3730 WinSwitchEncoding(fore
, n
? UTF8
: 0);
3732 Msg(0, "Will %suse UTF-8 encoding", n
? "" : "not ");
3735 D_encoding
= n
? UTF8
: 0;
3749 printcmd
= SaveStr(*args
);
3751 if (*args
== 0 || msgok
)
3754 Msg(0, "using '%s' as print command", printcmd
);
3756 Msg(0, "using termcap entries for printing");
3762 if (argl
&& argl
[0] > 0 && argl
[1] > 0)
3766 Msg(0, "Two characters expected to define a digraph");
3769 i
= digraph_find(args
[0]);
3770 digraphs
[i
].d
[0] = args
[0][0];
3771 digraphs
[i
].d
[1] = args
[0][1];
3772 if (!parse_input_int(args
[1], argl
[1], &digraphs
[i
].value
))
3774 if (!(digraphs
[i
].value
= atoi(args
[1])))
3777 digraphs
[i
].value
= (int)args
[1][0];
3782 unsigned char *s
= args
[1];
3783 digraphs
[i
].value
= 0;
3786 t
= FromUtf8(*s
++, &digraphs
[i
].value
);
3790 digraphs
[i
].value
= 0;
3792 digraphs
[i
].value
= t
;
3801 Input("Enter digraph: ", 10, INP_EVERY
, digraph_fn
, NULL
, 0);
3802 if (*args
&& **args
)
3815 if (nwin_default
.hstatus
)
3816 AddXChars(buf
, sizeof(buf
), nwin_default
.hstatus
);
3817 Msg(0, "default hstatus is '%s'", buf
);
3820 (void)ParseSaveStr(act
, &nwin_default
.hstatus
);
3821 if (*nwin_default
.hstatus
== 0)
3823 free(nwin_default
.hstatus
);
3824 nwin_default
.hstatus
= 0;
3828 (void)ParseSaveStr(act
, &fore
->w_hstatus
);
3829 if (*fore
->w_hstatus
== 0)
3831 free(fore
->w_hstatus
);
3832 fore
->w_hstatus
= 0;
3834 WindowChanged(fore
, 'h');
3844 if (nwin_default
.charset
)
3845 AddXChars(buf
, sizeof(buf
), nwin_default
.charset
);
3846 Msg(0, "default charset is '%s'", buf
);
3850 if (n
== 0 || n
> 6)
3852 Msg(0, "%s: %s: string has illegal size.", rc_name
, comms
[nr
].name
);
3856 ((args
[0][4] < '0' || args
[0][4] > '3') && args
[0][4] != '.') ||
3857 ((args
[0][5] < '0' || args
[0][5] > '3') && args
[0][5] && args
[0][5] != '.')))
3859 Msg(0, "%s: %s: illegal mapping number.", rc_name
, comms
[nr
].name
);
3862 if (nr
== RC_CHARSET
)
3864 SetCharsets(fore
, *args
);
3867 if (nwin_default
.charset
)
3868 free(nwin_default
.charset
);
3869 nwin_default
.charset
= SaveStr(*args
);
3875 if (*s
>= '0' && *s
<= '9')
3878 for (i
= 0; i
< 8; i
++)
3879 if (*s
== "dubrsBiI"[i
])
3883 if (*s
&& s
[1] && !s
[2])
3885 if (*s
== 'd' && s
[1] == 'd')
3887 else if (*s
== '.' && s
[1] == 'd')
3889 else if (*s
== 'd' && s
[1] == '.')
3891 else if (*s
!= '.' || s
[1] != '.')
3895 if (*s
|| i
< 0 || i
>= 8)
3897 Msg(0, "%s: attrcolor: unknown attribute '%s'.", rc_name
, args
[0]);
3902 n
= ParseAttrColor(args
[1], args
[2], 1);
3905 attr2color
[i
][nr
] = n
;
3907 for (i
= 0; i
< 8; i
++)
3908 if (attr2color
[i
][0] || attr2color
[i
][1] || attr2color
[i
][2] || attr2color
[i
][3])
3915 if (strcmp(args
[0], "bell") == 0)
3919 else if (strcmp(args
[0], "monitor") == 0)
3923 else if (strcmp(args
[0], "so") != 0)
3925 Msg(0, "Invalid option '%s' for rendition", args
[0]);
3934 renditions
[i
] = ParseAttrColor(args
[0], args
[1], 1);
3935 WindowChanged((struct win
*)0, 'w');
3936 WindowChanged((struct win
*)0, 'W');
3937 WindowChanged((struct win
*)0, 0);
3941 /* We are here, means we want to set the sorendition. */
3943 case RC_SORENDITION
:
3947 i
= ParseAttrColor(*args
, args
[1], 1);
3950 ApplyAttrColor(i
, &mchar_so
);
3951 WindowChanged((struct win
*)0, 0);
3952 debug2("--> %x %x\n", mchar_so
.attr
, mchar_so
.color
);
3956 Msg(0, "Standout attributes 0x%02x color 0x%02x", (unsigned char)mchar_so
.attr
, 0x99 ^ (unsigned char)mchar_so
.color
);
3958 Msg(0, "Standout attributes 0x%02x ", (unsigned char)mchar_so
.attr
);
3971 Msg(0, "%s:%s screen login", HostName
, SockPath
);
3972 InputSu(D_fore
, &D_user
, NULL
);
3975 InputSu(D_fore
, &D_user
, args
[0]);
3977 s
= DoSu(&D_user
, args
[0], args
[1], "\377");
3979 s
= DoSu(&D_user
, args
[0], args
[1], args
[2]);
3983 #endif /* MULTIUSER */
3986 if (s
&& !strcmp(s
, "-v"))
3987 AddCanvas(SLICE_HORI
);
3989 AddCanvas(SLICE_VERT
);
4001 D_forecv
->c_xoff
= D_forecv
->c_xs
;
4002 D_forecv
->c_yoff
= D_forecv
->c_ys
;
4003 RethinkViewportOffsets(D_forecv
);
4004 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
4005 flayer
= D_forecv
->c_layer
;
4010 struct canvas
*cv
= 0;
4011 if (!*args
|| !strcmp(*args
, "next"))
4012 cv
= D_forecv
->c_next
? D_forecv
->c_next
: D_cvlist
;
4013 else if (!strcmp(*args
, "prev"))
4015 for (cv
= D_cvlist
; cv
->c_next
&& cv
->c_next
!= D_forecv
; cv
= cv
->c_next
)
4018 else if (!strcmp(*args
, "top"))
4020 else if (!strcmp(*args
, "bottom"))
4022 for (cv
= D_cvlist
; cv
->c_next
; cv
= cv
->c_next
)
4025 else if (!strcmp(*args
, "up"))
4026 cv
= FindCanvas(D_forecv
->c_xs
, D_forecv
->c_ys
- 1);
4027 else if (!strcmp(*args
, "down"))
4028 cv
= FindCanvas(D_forecv
->c_xs
, D_forecv
->c_ye
+ 2);
4029 else if (!strcmp(*args
, "left"))
4030 cv
= FindCanvas(D_forecv
->c_xs
- 1, D_forecv
->c_ys
);
4031 else if (!strcmp(*args
, "right"))
4032 cv
= FindCanvas(D_forecv
->c_xe
+ 1, D_forecv
->c_ys
);
4035 Msg(0, "%s: usage: focus [next|prev|up|down|left|right|top|bottom]", rc_name
);
4038 SetForeCanvas(display
, cv
);
4043 if (D_forecv
->c_slorient
== SLICE_UNKN
)
4045 Msg(0, "resize: need more than one region");
4048 for (; *args
; args
++)
4050 if (!strcmp(*args
, "-h"))
4052 else if (!strcmp(*args
, "-v"))
4054 else if (!strcmp(*args
, "-b"))
4055 i
|= RESIZE_FLAG_H
| RESIZE_FLAG_V
;
4056 else if (!strcmp(*args
, "-p"))
4057 i
|= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
4058 else if (!strcmp(*args
, "-l"))
4063 if (*args
&& args
[1])
4065 Msg(0, "%s: usage: resize [-h] [-v] [-l] [num]\n", rc_name
);
4069 ResizeRegions(*args
, i
);
4071 Input(resizeprompts
[i
], 20, INP_EVERY
, ResizeFin
, (char*)0, i
);
4074 (void)ParseSwitch(act
, &separate_sids
);
4077 args
= SaveArgs(args
);
4078 for (i
= 0; args
[i
]; i
++)
4081 Colonfin(args
[i
], strlen(args
[i
]), (char *)0);
4087 (void)ParseSwitch(act
, &use_altscreen
);
4089 Msg(0, "Will %sdo alternate screen switching", use_altscreen
? "" : "not ");
4094 Msg(0, "maximum windows allowed: %d", maxwin
);
4097 if (ParseNum(act
, &n
))
4100 Msg(0, "illegal maxwin number specified");
4102 Msg(0, "maximum 2048 windows allowed");
4103 else if (n
> maxwin
&& windows
)
4104 Msg(0, "may increase maxwin only when there's no window");
4108 wtab
= realloc(wtab
, n
* sizeof(struct win
));
4113 if (ParseBase(act
, *args
, &n
, 10, "decimal"))
4116 setbacktick(n
, 0, 0, (char **)0);
4122 Msg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name
);
4125 if (ParseBase(act
, args
[1], &lifespan
, 10, "decimal"))
4127 if (ParseBase(act
, args
[2], &tick
, 10, "decimal"))
4129 setbacktick(n
, lifespan
, tick
, SaveArgs(args
+ 3));
4131 WindowChanged(0, '`');
4137 RunBlanker(blankerprg
);
4142 CursorVisibility(-1);
4151 char path
[MAXPATHLEN
];
4152 char *p
= path
, **pp
;
4153 for (pp
= blankerprg
; *pp
; pp
++)
4154 p
+= snprintf(p
, sizeof(path
) - (p
- path
) - 1, "%s ", *pp
);
4156 Msg(0, "blankerprg: %s", path
);
4159 Msg(0, "No blankerprg set.");
4165 for (pp
= blankerprg
; *pp
; pp
++)
4171 blankerprg
= SaveArgs(args
);
4177 struct display
*olddisplay
= display
;
4178 if (!strcmp(*args
, "off"))
4180 else if (args
[0][0])
4181 idletimo
= atoi(*args
) * 1000;
4184 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
4186 Msg(0, "%s: idle: unknown command '%s'", rc_name
, args
[1]);
4189 if (CheckArgNum(i
, args
+ 2) < 0)
4191 ClearAction(&idleaction
);
4192 SaveAction(&idleaction
, i
, args
+ 2, argl
+ 2);
4194 for (display
= displays
; display
; display
= display
->d_next
)
4196 display
= olddisplay
;
4201 Msg(0, "idle timeout %ds, %s", idletimo
/ 1000, comms
[idleaction
.nr
].name
);
4206 case RC_FOCUSMINSIZE
:
4207 for (i
= 0; i
< 2 && args
[i
]; i
++)
4209 if (!strcmp(args
[i
], "max") || !strcmp(args
[i
], "_"))
4221 for (i
= 0; i
< 2; i
++)
4223 n
= i
== 0 ? focusminwidth
: focusminheight
;
4225 strcpy(b
[i
], "max");
4227 sprintf(b
[i
], "%d", n
);
4229 Msg(0, "focus min size is %s %s\n", b
[0], b
[1]);
4238 fore
->w_group
= WindowByName(*args
);
4239 if (fore
->w_group
&& fore
->w_group
->w_type
!= W_TYPE_GROUP
)
4242 WindowChanged((struct win
*)0, 'w');
4243 WindowChanged((struct win
*)0, 'W');
4244 WindowChanged((struct win
*)0, 0);
4249 Msg(0, "window group is %d (%s)\n", fore
->w_group
->w_number
, fore
->w_group
->w_title
);
4251 Msg(0, "window belongs to no group");
4255 if (!strcmp(args
[0], "title"))
4259 Msg(0, "not on a layout");
4264 Msg(0, "current layout is %d (%s)", D_layout
->lay_number
, D_layout
->lay_title
);
4267 free(D_layout
->lay_title
);
4268 D_layout
->lay_title
= SaveStr(args
[1]);
4270 else if (!strcmp(args
[0], "number"))
4276 Msg(0, "not on a layout");
4281 Msg(0, "This is layout %d (%s).\n", D_layout
->lay_number
, D_layout
->lay_title
);
4284 old
= D_layout
->lay_number
;
4286 if (n
< 0 || n
>= MAXLAY
)
4289 laytab
[n
] = D_layout
;
4290 D_layout
->lay_number
= n
;
4293 lay
->lay_number
= old
;
4296 else if (!strcmp(args
[0], "autosave"))
4300 Msg(0, "not on a layout");
4305 if (!strcmp(args
[1], "on"))
4306 D_layout
->lay_autosave
= 1;
4307 else if (!strcmp(args
[1], "off"))
4308 D_layout
->lay_autosave
= 0;
4311 Msg(0, "invalid argument. Give 'on' or 'off");
4316 Msg(0, "autosave is %s", D_layout
->lay_autosave
? "on" : "off");
4318 else if (!strcmp(args
[0], "new"))
4324 while (*t
>= '0' && *t
<= '9')
4326 if (t
!= args
[1] && (!*t
|| *t
== ':'))
4340 else if (!strcmp(args
[0], "save"))
4344 Msg(0, "usage: layout save <name>");
4347 SaveLayout(args
[1], &D_canvas
);
4349 else if (!strcmp(args
[0], "select"))
4353 Input("Switch to layout: ", 20, INP_COOKED
, SelectLayoutFin
, NULL
, 0);
4356 SelectLayoutFin(args
[1], strlen(args
[1]), (char *)0);
4358 else if (!strcmp(args
[0], "next"))
4360 struct layout
*lay
= D_layout
;
4362 lay
= lay
->lay_next
? lay
->lay_next
: layouts
;
4367 Msg(0, "no layout defined");
4370 if (lay
== D_layout
)
4372 LoadLayout(lay
, &D_canvas
);
4375 else if (!strcmp(args
[0], "prev"))
4377 struct layout
*lay
= D_layout
;
4380 for (lay
= layouts
; lay
->lay_next
&& lay
->lay_next
!= D_layout
; lay
= lay
->lay_next
)
4387 Msg(0, "no layout defined");
4390 if (lay
== D_layout
)
4392 LoadLayout(lay
, &D_canvas
);
4395 else if (!strcmp(args
[0], "attach"))
4400 Msg(0, "no attach layout set");
4401 else if (layout_attach
== &layout_last_marker
)
4402 Msg(0, "will attach to last layout");
4404 Msg(0, "will attach to layout %d (%s)", layout_attach
->lay_number
, layout_attach
->lay_title
);
4407 if (!strcmp(args
[1], ":last"))
4408 layout_attach
= &layout_last_marker
;
4409 else if (!args
[1][0])
4414 lay
= FindLayout(args
[1]);
4417 Msg(0, "unknown layout '%s'", args
[1]);
4420 layout_attach
= lay
;
4423 else if (!strcmp(args
[0], "show"))
4427 else if (!strcmp(args
[0], "remove"))
4429 struct layout
*lay
= display
? D_layout
: layouts
;
4432 lay
= layouts
? FindLayout(args
[1]) : (struct layout
*)0;
4435 Msg(0, "unknown layout '%s'", args
[1]);
4442 else if (!strcmp(args
[0], "dump"))
4445 Msg(0, "Must have a display for 'layout dump'.");
4446 else if (!LayoutDumpCanvas(&D_canvas
, args
[1] ? args
[1] : "layout-dump"))
4447 Msg(errno
, "Error dumping layout.");
4449 Msg(0, "Layout dumped to \"%s\"", args
[1] ? args
[1] : "layout-dump");
4452 Msg(0, "unknown layout subcommand");
4456 if(ParseSwitch(act
, &cjkwidth
) == 0)
4459 Msg(0, "Treat ambiguous width characters as %s width", cjkwidth
? "full" : "half");
4465 /* key == -2: input from braille keybord, msgok always 0 */
4466 DoBrailleAction(act
, key
== -2 ? 0 : msgok
);
4470 if (display
!= odisplay
)
4472 for (display
= displays
; display
; display
= display
->d_next
)
4473 if (display
== odisplay
)
4479 DoCommand(argv
, argl
)
4484 const char *cmd
= *argv
;
4487 if (*cmd
== '@') /* Suppress error */
4492 if (*cmd
== '-') /* Suppress normal message */
4498 if ((act
.nr
= FindCommnr(cmd
)) == RC_ILLEGAL
)
4500 Msg(0, "%s: unknown command '%s'", rc_name
, cmd
);
4503 act
.args
= argv
+ 1;
4504 act
.argl
= argl
+ 1;
4509 SaveAction(act
, nr
, args
, argl
)
4515 register int argc
= 0;
4529 if ((pp
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4531 if ((lp
= (int *)malloc((unsigned)(argc
) * sizeof(int *))) == 0)
4538 *lp
= argl
? *argl
++ : (int)strlen(*args
);
4539 *pp
++ = SaveStrn(*args
++, *lp
++);
4548 register char **ap
, **pp
;
4549 register int argc
= 0;
4553 if ((pp
= ap
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4556 *pp
++ = SaveStr(*args
++);
4563 * buf is split into argument vector args.
4564 * leading whitespace is removed.
4565 * @!| abbreviations are expanded.
4566 * the end of buffer is recognized by '\0' or an un-escaped '#'.
4567 * " and ' are interpreted.
4572 Parse(buf
, bufl
, args
, argl
)
4576 register char *p
= buf
, **ap
= args
, *pp
;
4577 register int delim
, argc
;
4580 debug2("Parse %d %s\n", bufl
, buf
);
4587 while (*p
&& (*p
== ' ' || *p
== '\t'))
4590 if (argc
== 0 && *p
== '!')
4599 if (*p
== '\0' || *p
== '#' || *p
== '\n')
4602 for (delim
= 0; delim
< argc
; delim
++)
4603 debug1("-- %s\n", args
[delim
]);
4607 if (++argc
>= MAXARGS
)
4609 Msg(0, "%s: too many tokens.", rc_name
);
4614 debug1("- new arg %s\n", p
);
4619 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')))
4622 if (*p
>= '0' && *p
<= '7')
4625 if (p
[1] >= '0' && p
[1] <= '7')
4628 *pp
= (*pp
<< 3) | (*p
- '0');
4629 if (p
[1] >= '0' && p
[1] <= '7')
4632 *pp
= (*pp
<< 3) | (*p
- '0');
4641 case 'n': *pp
= '\n'; break;
4642 case 'r': *pp
= '\r'; break;
4643 case 't': *pp
= '\t'; break;
4644 default: *pp
= *p
; break;
4649 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] == '_'))
4652 char *ps
, *pe
, op
, *v
, xbuf
[11];
4656 debug1("- var %s\n", ps
);
4660 if (*ps
== '{' && *p
== '}')
4662 if (*ps
== ':' && *p
== ':')
4664 if (*ps
!= '{' && *ps
!= ':' && (*p
< 'a' || *p
> 'z') && (*p
< 'A' || *p
> 'Z') && (*p
< '0' || *p
> '9') && *p
!= '_')
4669 if (*ps
== '{' || *ps
== ':')
4673 Msg(0, "%s: bad variable name.", rc_name
);
4680 debug1("- var is '%s'\n", ps
);
4682 v
= gettermcapstring(ps
+ 1);
4688 if (!strcmp(ps
, "TERM"))
4689 v
= display
? D_termname
: "unknown";
4690 else if (!strcmp(ps
, "COLUMNS"))
4691 sprintf(xbuf
, "%d", display
? D_width
: -1);
4692 else if (!strcmp(ps
, "LINES"))
4693 sprintf(xbuf
, "%d", display
? D_height
: -1);
4694 else if (!strcmp(ps
, "PID"))
4695 sprintf(xbuf
, "%d", getpid());
4696 else if (!strcmp(ps
, "STY"))
4702 vl
= v
? strlen(v
) : 0;
4705 debug1("- sub is '%s'\n", v
);
4708 int right
= buf
+ bufl
- (p
+ strlen(p
) + 1);
4711 bcopy(p
, p
+ right
, strlen(p
) + 1);
4717 Msg(0, "%s: no space left for variable expansion.", rc_name
);
4725 else if (delim
!= '\'' && *p
== '^' && p
[1])
4728 *pp
++ = *p
== '?' ? '\177' : *p
& 0x1f;
4730 else if (delim
== 0 && (*p
== '\'' || *p
== '"'))
4732 else if (delim
== 0 && (*p
== ' ' || *p
== '\t' || *p
== '\n'))
4740 Msg(0, "%s: Missing %c quote.", rc_name
, delim
);
4746 debug2("- arg done, '%s' rest %s\n", ap
[-1], p
);
4747 *lp
++ = pp
- ap
[-1];
4766 if (DefaultEsc
>= 0)
4767 ClearAction(&ktab
[DefaultEsc
]);
4768 if (DefaultMetaEsc
>= 0)
4769 ClearAction(&ktab
[DefaultMetaEsc
]);
4772 DefaultMetaEsc
= me
;
4775 if (DefaultEsc
>= 0)
4777 ClearAction(&ktab
[DefaultEsc
]);
4778 ktab
[DefaultEsc
].nr
= RC_OTHER
;
4780 if (DefaultMetaEsc
>= 0)
4782 ClearAction(&ktab
[DefaultMetaEsc
]);
4783 ktab
[DefaultMetaEsc
].nr
= RC_META
;
4790 ParseSwitch(act
, var
)
4794 if (*act
->args
== 0)
4799 return ParseOnOff(act
, var
);
4803 ParseOnOff(act
, var
)
4807 register int num
= -1;
4808 char **args
= act
->args
;
4812 if (strcmp(args
[0], "on") == 0)
4814 else if (strcmp(args
[0], "off") == 0)
4819 Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name
, comms
[act
->nr
].name
);
4827 ParseSaveStr(act
, var
)
4831 char **args
= act
->args
;
4832 if (*args
== 0 || args
[1])
4834 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4839 *var
= SaveStr(*args
);
4849 char *p
, **args
= act
->args
;
4852 if (p
== 0 || *p
== 0 || args
[1])
4854 Msg(0, "%s: %s: invalid argument. Give one argument.",
4855 rc_name
, comms
[act
->nr
].name
);
4861 if (*p
>= '0' && *p
<= '9')
4862 i
= 10 * i
+ (*p
- '0');
4865 Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4866 rc_name
, comms
[act
->nr
].name
);
4871 debug1("ParseNum got %d\n", i
);
4877 ParseNum1000(act
, var
)
4882 char *p
, **args
= act
->args
;
4886 if (p
== 0 || *p
== 0 || args
[1])
4888 Msg(0, "%s: %s: invalid argument. Give one argument.",
4889 rc_name
, comms
[act
->nr
].name
);
4895 if (*p
>= '0' && *p
<= '9')
4898 i
= 10 * i
+ (*p
- '0');
4899 else if (dig
== 4 && *p
>= '5')
4904 else if (*p
== '.' && !dig
)
4908 Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4909 rc_name
, comms
[act
->nr
].name
);
4920 i
= (int)((unsigned int)~0 >> 1);
4921 debug1("ParseNum1000 got %d\n", i
);
4932 for (p
= windows
; p
; p
= p
->w_next
)
4933 if (!strcmp(p
->w_title
, s
))
4935 for (p
= windows
; p
; p
= p
->w_next
)
4936 if (!strncmp(p
->w_title
, s
, strlen(s
)))
4948 for (i
= 0, s
= str
; *s
; s
++)
4950 if (*s
< '0' || *s
> '9')
4952 i
= i
* 10 + (*s
- '0');
4958 * Get window number from Name or Number string.
4959 * Numbers are tried first, then names, a prefix match suffices.
4960 * Be careful when assigning numeric strings as WindowTitles.
4969 if ((i
= WindowByNumber(str
)) < 0 || i
>= maxwin
)
4971 if ((p
= WindowByName(str
)))
4979 ParseWinNum(act
, var
)
4983 char **args
= act
->args
;
4986 if (*args
== 0 || args
[1])
4988 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4992 i
= WindowByNoN(*args
);
4995 Msg(0, "%s: %s: invalid argument. Give window number or name.",
4996 rc_name
, comms
[act
->nr
].name
);
4999 debug1("ParseWinNum got %d\n", i
);
5005 ParseBase(act
, p
, var
, base
, bname
)
5017 Msg(0, "%s: %s: empty argument.", rc_name
, comms
[act
->nr
].name
);
5022 if (c
>= 'a' && c
<= 'z')
5024 if (c
>= 'A' && c
<= 'Z')
5025 c
-= 'A' - ('0' + 10);
5027 if (c
< 0 || c
>= base
)
5029 Msg(0, "%s: %s: argument is not %s.", rc_name
, comms
[act
->nr
].name
, bname
);
5034 debug1("ParseBase got %d\n", i
);
5044 for (base
+= '0'; *s
; ++s
)
5045 if (*s
< '0' || *s
> base
)
5051 IsNumColon(s
, base
, p
, psize
)
5056 if ((q
= rindex(s
, ':')) != 0)
5058 strncpy(p
, q
+ 1, psize
- 1);
5059 p
[psize
- 1] = '\0';
5064 return IsNum(s
, base
);
5073 debug1("SwitchWindow %d\n", n
);
5074 if (n
< 0 || n
>= maxwin
)
5079 if ((p
= wtab
[n
]) == 0)
5091 Msg(0, "This IS window %d (%s).", n
, p
->w_title
);
5095 if (AclCheckPermWin(D_user
, ACL_READ
, p
))
5097 Msg(0, "Access to window %d denied.", p
->w_number
);
5102 Activate(fore
->w_norefresh
);
5106 * SetForeWindow changes the window in the input focus of the display.
5107 * Puts window wi in canvas display->d_forecv.
5119 p
= Layer2Window(D_forecv
->c_layer
);
5120 SetCanvasWindow(D_forecv
, wi
);
5122 WindowChanged(p
, 'u');
5124 WindowChanged(wi
, 'u');
5125 flayer
= D_forecv
->c_layer
;
5126 /* Activate called afterwards, so no RefreshHStatus needed */
5130 /*****************************************************************/
5133 * Activate - make fore window active
5134 * norefresh = -1 forces a refresh, disregard all_norefresh then.
5140 debug1("Activate(%d)\n", norefresh
);
5145 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
5149 if (MayResizeLayer(D_forecv
->c_layer
))
5150 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, display
);
5156 if (fore
->w_monitor
!= MON_OFF
)
5157 fore
->w_monitor
= MON_ON
;
5158 fore
->w_bell
= BELL_ON
;
5159 WindowChanged(fore
, 'f');
5162 if (ResizeDisplay(fore
->w_width
, fore
->w_height
))
5164 debug2("Cannot resize from (%d,%d)", D_width
, D_height
);
5165 debug2(" to (%d,%d) -> resize window\n", fore
->w_width
, fore
->w_height
);
5166 DoResize(D_width
, D_height
);
5170 Redisplay(norefresh
+ all_norefresh
);
5177 register struct win
**pp
;
5178 int n
= fore
? fore
->w_number
: maxwin
;
5179 struct win
*group
= fore
? fore
->w_group
: 0;
5181 for (pp
= fore
? wtab
+ n
+ 1 : wtab
; pp
!= wtab
+ n
; pp
++)
5183 if (pp
== wtab
+ maxwin
)
5187 if (!fore
|| group
== (*pp
)->w_group
)
5199 register struct win
**pp
;
5200 int n
= fore
? fore
->w_number
: -1;
5201 struct win
*group
= fore
? fore
->w_group
: 0;
5203 for (pp
= wtab
+ n
- 1; pp
!= wtab
+ n
; pp
--)
5206 pp
= wtab
+ maxwin
- 1;
5209 if (!fore
|| group
== (*pp
)->w_group
)
5221 char *m
= "No other window.";
5222 if (windows
&& (fore
== 0 || windows
->w_next
))
5226 Msg(0, "No window available");
5229 Msg(0, m
, fore
->w_number
); /* other arg for nethack */
5237 struct win
**pp
, *p
;
5243 * Remove window from linked list.
5245 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5251 wtab
[wi
->w_number
] = 0;
5260 * switch to different window on all canvases
5262 for (display
= displays
; display
; display
= display
->d_next
)
5265 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5267 if (Layer2Window(cv
->c_layer
) != wi
)
5269 /* switch to other window */
5270 SetCanvasWindow(cv
, FindNiceWindow(D_other
, 0));
5276 if (wi
->w_zdisplay
== display
)
5279 D_readev
.condpos
= D_readev
.condneg
= 0;
5286 /* do the same for the layouts */
5287 for (lay
= layouts
; lay
; lay
= lay
->lay_next
)
5288 UpdateLayoutCanvas(&lay
->lay_canvas
, wi
);
5291 WindowChanged((struct win
*)0, 'w');
5292 WindowChanged((struct win
*)0, 'W');
5293 WindowChanged((struct win
*)0, 0);
5302 if ((fore
->w_log
!= 0) == on
)
5304 if (display
&& !*rc_name
)
5305 Msg(0, "You are %s logging.", on
? "already" : "not");
5308 if (fore
->w_log
!= 0)
5310 Msg(0, "Logfile \"%s\" closed.", fore
->w_log
->name
);
5311 logfclose(fore
->w_log
);
5313 WindowChanged(fore
, 'f');
5316 if (DoStartLog(fore
, buf
, sizeof(buf
)))
5318 Msg(errno
, "Error opening logfile \"%s\"", buf
);
5321 if (ftell(fore
->w_log
->fp
) == 0)
5322 Msg(0, "Creating logfile \"%s\".", fore
->w_log
->name
);
5324 Msg(0, "Appending to logfile \"%s\".", fore
->w_log
->name
);
5325 WindowChanged(fore
, 'f');
5329 AddWindows(buf
, len
, flags
, where
)
5335 register char *s
, *ss
;
5336 register struct win
**pp
, *p
;
5341 if ((flags
& 8) && where
< 0)
5346 for (pp
= ((flags
& 4) && where
>= 0) ? wtab
+ where
+ 1: wtab
; pp
< wtab
+ maxwin
; pp
++)
5349 if (pp
- wtab
== where
&& ss
== buf
)
5353 if ((flags
& 1) && display
&& p
== D_fore
)
5355 if (display
&& D_fore
&& D_fore
->w_group
!= p
->w_group
)
5362 if (s
- buf
+ l
> len
- 24)
5364 if (s
> buf
|| (flags
& 4))
5369 if (p
->w_number
== where
)
5375 if (!(flags
& 4) || where
< 0 || ((flags
& 4) && where
< p
->w_number
))
5377 if (p
->w_monitor
== MON_DONE
&& renditions
[REND_MONITOR
] != -1)
5378 rend
= renditions
[REND_MONITOR
];
5379 else if ((p
->w_bell
== BELL_DONE
|| p
->w_bell
== BELL_FOUND
) && renditions
[REND_BELL
] != -1)
5380 rend
= renditions
[REND_BELL
];
5383 AddWinMsgRend(s
, rend
);
5384 sprintf(s
, "%d", p
->w_number
);
5386 if (display
&& p
== D_fore
)
5390 if (display
&& p
== D_other
)
5392 s
= AddWindowFlags(s
, len
, p
);
5398 AddWinMsgRend(s
, -1);
5405 AddWindowFlags(buf
, len
, p
)
5411 if (p
== 0 || len
< 12)
5417 if (display
&& p
== D_fore
)
5419 if (display
&& p
== D_other
)
5422 if (p
->w_layer
.l_cvlist
&& p
->w_layer
.l_cvlist
->c_lnext
)
5424 if (p
->w_monitor
== MON_DONE
5426 && (ACLBYTE(p
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5430 if (p
->w_bell
== BELL_DONE
)
5433 if (p
->w_slot
!= (slot_t
) 0 && p
->w_slot
!= (slot_t
) -1)
5441 if (p
->w_ptyfd
< 0 && p
->w_type
!= W_TYPE_GROUP
)
5448 AddOtherUsers(buf
, len
, p
)
5453 struct display
*d
, *olddisplay
= display
;
5459 for (display
= displays
; display
; display
= display
->d_next
)
5461 if (olddisplay
&& D_user
== olddisplay
->d_user
)
5463 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5464 if (Layer2Window(cv
->c_layer
) == p
)
5468 for (d
= displays
; d
&& d
!= display
; d
= d
->d_next
)
5469 if (D_user
== d
->d_user
)
5471 if (d
&& d
!= display
)
5473 if (len
> 1 && s
!= buf
)
5478 l
= strlen(D_user
->u_name
);
5481 strcpy(s
, D_user
->u_name
);
5486 display
= olddisplay
;
5497 if (display
&& where
== -1 && D_fore
)
5498 where
= D_fore
->w_number
;
5499 ss
= AddWindows(buf
, sizeof(buf
), 0, where
);
5500 s
= buf
+ strlen(buf
);
5501 if (display
&& ss
- buf
> D_width
/ 2)
5504 if (s
- ss
< D_width
)
5520 register struct win
*wp
= fore
;
5525 Msg(0, "(%d,%d)/(%d,%d) no window", D_x
+ 1, D_y
+ 1, D_width
, D_height
);
5529 if (buf
< (p
+= GetAnsiStatus(wp
, p
)))
5531 sprintf(p
, "(%d,%d)/(%d,%d)",
5532 wp
->w_x
+ 1, wp
->w_y
+ 1, wp
->w_width
, wp
->w_height
);
5534 sprintf(p
+= strlen(p
), "+%d", wp
->w_histheight
);
5536 sprintf(p
+= strlen(p
), " %c%sflow",
5537 (wp
->w_flow
& FLOW_NOW
) ? '+' : '-',
5538 (wp
->w_flow
& FLOW_AUTOFLAG
) ? "" :
5539 ((wp
->w_flow
& FLOW_AUTO
) ? "(+)" : "(-)"));
5540 if (!wp
->w_wrap
) sprintf(p
+= strlen(p
), " -wrap");
5541 if (wp
->w_insert
) sprintf(p
+= strlen(p
), " ins");
5542 if (wp
->w_origin
) sprintf(p
+= strlen(p
), " org");
5543 if (wp
->w_keypad
) sprintf(p
+= strlen(p
), " app");
5544 if (wp
->w_log
) sprintf(p
+= strlen(p
), " log");
5545 if (wp
->w_monitor
!= MON_OFF
5547 && (ACLBYTE(wp
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5550 sprintf(p
+= strlen(p
), " mon");
5551 if (wp
->w_mouse
) sprintf(p
+= strlen(p
), " mouse");
5553 if (wp
->w_bce
) sprintf(p
+= strlen(p
), " bce");
5555 if (!wp
->w_c1
) sprintf(p
+= strlen(p
), " -c1");
5556 if (wp
->w_norefresh
) sprintf(p
+= strlen(p
), " nored");
5561 if (wp
->w_encoding
&& (display
== 0 || D_encoding
!= wp
->w_encoding
|| EncodingDefFont(wp
->w_encoding
) <= 0))
5564 strcpy(p
, EncodingName(wp
->w_encoding
));
5568 if (wp
->w_encoding
!= UTF8
)
5571 if (D_CC0
|| (D_CS0
&& *D_CS0
))
5575 sprintf(p
, " G%c", wp
->w_Charset
+ '0');
5576 if (wp
->w_FontE
>= ' ')
5581 p
[4] = wp
->w_FontE
^ 0x40;
5588 sprintf(p
++, " G%c%c[", wp
->w_Charset
+ '0', wp
->w_CharsetR
+ '0');
5590 sprintf(p
, " G%c[", wp
->w_Charset
+ '0');
5592 for (i
= 0; i
< 4; i
++)
5594 if (wp
->w_charsets
[i
] == ASCII
)
5596 else if (wp
->w_charsets
[i
] >= ' ')
5597 *p
++ = wp
->w_charsets
[i
];
5601 *p
++ = wp
->w_charsets
[i
] ^ 0x40;
5609 if (wp
->w_type
== W_TYPE_PLAIN
)
5611 /* add info about modem control lines */
5613 TtyGetModemStatus(wp
->w_ptyfd
, p
);
5615 #ifdef BUILTIN_TELNET
5616 else if (wp
->w_type
== W_TYPE_TELNET
)
5619 TelStatus(wp
, p
, sizeof(buf
) - 1 - (p
- buf
));
5622 Msg(0, "%s %d(%s)", buf
, wp
->w_number
, wp
->w_title
);
5632 sprintf(p
, "(%d,%d)", D_width
, D_height
),
5638 strcpy(p
, EncodingName(D_encoding
));
5644 strcpy(p
, " xterm");
5650 strcpy(p
, " color");
5657 strcpy(p
, " iso2022");
5660 else if (D_CS0
&& *D_CS0
)
5662 strcpy(p
, " altchar");
5670 AKAfin(buf
, len
, data
)
5673 char *data
; /* dummy */
5677 ChangeAKA(fore
, buf
, strlen(buf
));
5685 Input("Set window's title to: ", sizeof(fore
->w_akabuf
) - 1, INP_COOKED
, AKAfin
, NULL
, 0);
5691 if ((*(unsigned char *)s
& 0x7f) < 0x20 || *s
== 0x7f)
5695 LayProcess(&ss
, &n
);
5700 Colonfin(buf
, len
, data
)
5703 char *data
; /* dummy */
5708 if (buf
[len
] == '\t')
5711 int l
= 0, r
= RC_LAST
;
5712 int showmessage
= 0;
5715 while (*s
&& s
- buf
< len
)
5719 /* Showing a message when there's no hardstatus or caption cancels the input */
5721 (captionalways
|| D_has_hstatus
== HSTATUS_LASTLINE
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
)))
5727 x
= strncmp(buf
, comms
[m
].name
, len
);
5735 for (l
= m
- 1; l
>= 0 && strncmp(buf
, comms
[l
].name
, len
) == 0; l
--)
5737 for (m
= ++l
; m
<= r
&& strncmp(buf
, comms
[m
].name
, len
) == 0 && s
- mbuf
< sizeof(mbuf
); m
++)
5738 s
+= snprintf(s
, sizeof(mbuf
) - (s
- mbuf
), " %s", comms
[m
].name
);
5742 Msg(0, "Possible commands:%s", mbuf
);
5747 len
= snprintf(mbuf
, sizeof(mbuf
), "%s \t", comms
[l
].name
+ len
);
5748 if (len
> 0 && len
< sizeof(mbuf
))
5749 LayProcess(&s
, &len
);
5754 if (l
> r
&& showmessage
)
5755 Msg(0, "No commands matching '%*s'", len
, buf
);
5759 if (!len
|| buf
[len
])
5762 len
= strlen(buf
) + 1;
5763 if (len
> (int)sizeof(mbuf
))
5767 bcopy(buf
, mbuf
, len
);
5768 RcLine(mbuf
, sizeof mbuf
);
5773 SelectFin(buf
, len
, data
)
5776 char *data
; /* dummy */
5780 if (!len
|| !display
)
5782 if (len
== 1 && *buf
== '-')
5784 SetForeWindow((struct win
*)0);
5788 if ((n
= WindowByNoN(buf
)) < 0)
5794 SelectLayoutFin(buf
, len
, data
)
5797 char *data
; /* dummy */
5801 if (!len
|| !display
)
5803 if (len
== 1 && *buf
== '-')
5805 LoadLayout((struct layout
*)0, (struct canvas
*)0);
5809 lay
= FindLayout(buf
);
5811 Msg(0, "No such layout\n");
5812 else if (lay
== D_layout
)
5813 Msg(0, "This IS layout %d (%s).\n", lay
->lay_number
, lay
->lay_title
);
5816 LoadLayout(lay
, &D_canvas
);
5825 Input("Switch to window: ", 20, INP_COOKED
, SelectFin
, NULL
, 0);
5828 static char setenv_var
[31];
5832 SetenvFin1(buf
, len
, data
)
5835 char *data
; /* dummy */
5837 if (!len
|| !display
)
5843 SetenvFin2(buf
, len
, data
)
5846 char *data
; /* dummy */
5848 if (!len
|| !display
)
5850 debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var
, buf
);
5851 xsetenv(setenv_var
, buf
);
5859 static char setenv_buf
[50 + sizeof(setenv_var
)]; /* need to be static here, cannot be freed */
5863 strncpy(setenv_var
, arg
, sizeof(setenv_var
) - 1);
5864 sprintf(setenv_buf
, "Enter value for %s: ", setenv_var
);
5865 Input(setenv_buf
, 30, INP_COOKED
, SetenvFin2
, NULL
, 0);
5868 Input("Setenv: Enter variable name: ", 30, INP_COOKED
, SetenvFin1
, NULL
, 0);
5872 * the following options are understood by this parser:
5873 * -f, -f0, -f1, -fy, -fa
5874 * -t title, -T terminal-type, -h height-of-scrollback,
5875 * -ln, -l0, -ly, -l1, -l
5882 struct NewWindow nwin
;
5887 while (av
&& *av
&& av
[0][0] == '-')
5889 if (av
[0][1] == '-')
5901 nwin
.flowflag
= FLOW_NOW
* 0;
5906 nwin
.flowflag
= FLOW_NOW
* 1;
5909 nwin
.flowflag
= FLOW_AUTOFLAG
;
5915 case 't': /* no more -k */
5917 nwin
.aka
= &av
[0][2];
5925 nwin
.term
= &av
[0][2];
5933 nwin
.histheight
= atoi(av
[0] + 2);
5935 nwin
.histheight
= atoi(*av
);
5964 nwin
.monitor
= MON_ON
;
5970 Msg(0, "%s: screen: invalid option -%c.", fn
, av
[0][1]);
5976 if (av
&& *av
&& IsNumColon(*av
, 10, buf
, sizeof(buf
)))
5981 if (num
< 0 || num
> maxwin
- 1)
5983 Msg(0, "%s: illegal screen number %d.", fn
, num
);
5993 nwin
.aka
= Filename(*av
);
6000 * CompileKeys must be called before Markroutine is first used.
6001 * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
6003 * s is an ascii string in a termcap-like syntax. It looks like
6004 * "j=u:k=d:l=r:h=l: =.:" and so on...
6005 * this example rebinds the cursormovement to the keys u (up), d (down),
6006 * l (left), r (right). placing a mark will now be done with ".".
6009 CompileKeys(s
, sl
, array
)
6012 unsigned char *array
;
6015 unsigned char key
, value
;
6019 for (i
= 0; i
< 256; i
++)
6023 debug1("CompileKeys: '%s'\n", s
);
6026 key
= *(unsigned char *)s
++;
6027 if (*s
!= '=' || sl
< 3)
6034 value
= *(unsigned char *)s
++;
6037 while (*s
== '=' && sl
>= 2);
6046 #endif /* COPY_PASTE */
6049 * Asynchronous input functions
6052 #if defined(DETACH) && defined(POW_DETACH)
6054 pow_detach_fn(buf
, len
, data
)
6057 char *data
; /* dummy */
6059 debug("pow_detach_fn called\n");
6065 if (ktab
[(int)(unsigned char)*buf
].nr
!= RC_POW_DETACH
)
6068 write(D_userfd
, "\007", 1);
6069 Msg(0, "Detach aborted.");
6074 #endif /* POW_DETACH */
6078 copy_reg_fn(buf
, len
, data
)
6081 char *data
; /* dummy */
6083 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6094 if (D_user
->u_plop
.len
)
6096 if ((pp
->buf
= (char *)malloc(D_user
->u_plop
.len
)) == NULL
)
6101 bcopy(D_user
->u_plop
.buf
, pp
->buf
, D_user
->u_plop
.len
);
6103 pp
->len
= D_user
->u_plop
.len
;
6105 pp
->enc
= D_user
->u_plop
.enc
;
6107 Msg(0, "Copied %d characters into register %c", D_user
->u_plop
.len
, *buf
);
6111 ins_reg_fn(buf
, len
, data
)
6114 char *data
; /* dummy */
6116 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6124 return; /* Input() should not call us w/o fore, but you never know... */
6126 Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
6129 MakePaster(&fore
->w_paster
, pp
->buf
, pp
->len
, 0);
6132 Msg(0, "Empty register.");
6134 #endif /* COPY_PASTE */
6137 process_fn(buf
, len
, data
)
6140 char *data
; /* dummy */
6142 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6151 ProcessInput(pp
->buf
, pp
->len
);
6154 Msg(0, "Empty register.");
6158 confirm_fn(buf
, len
, data
)
6165 if (len
|| (*buf
!= 'y' && *buf
!= 'Y'))
6170 act
.nr
= *(int *)data
;
6180 struct acluser
**up
;
6182 char pw1
[130]; /* FreeBSD crypts to 128 bytes */
6187 su_fin(buf
, len
, data
)
6192 struct inputsu
*i
= (struct inputsu
*)data
;
6197 { p
= i
->name
; l
= sizeof(i
->name
) - 1; }
6199 { strcpy(p
= i
->pw1
, "\377"); l
= sizeof(i
->pw1
) - 1; }
6201 { strcpy(p
= i
->pw2
, "\377"); l
= sizeof(i
->pw2
) - 1; }
6203 strncpy(p
, buf
, 1 + (l
< len
) ? l
: len
);
6205 Input("Screen User: ", sizeof(i
->name
) - 1, INP_COOKED
, su_fin
, (char *)i
, 0);
6207 Input("User's UNIX Password: ", sizeof(i
->pw1
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6209 Input("User's Screen Password: ", sizeof(i
->pw2
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6212 if ((p
= DoSu(i
->up
, i
->name
, i
->pw2
, i
->pw1
)))
6219 InputSu(w
, up
, name
)
6221 struct acluser
**up
;
6226 if (!(i
= (struct inputsu
*)calloc(1, sizeof(struct inputsu
))))
6231 su_fin(name
, (int)strlen(name
), (char *)i
); /* can also initialise stuff */
6233 su_fin((char *)0, 0, (char *)i
);
6236 #endif /* MULTIUSER */
6241 pass1(buf
, len
, data
)
6246 struct acluser
*u
= (struct acluser
*)data
;
6251 if (u
->u_password
!= NullStr
)
6252 free((char *)u
->u_password
);
6253 u
->u_password
= SaveStr(buf
);
6254 bzero(buf
, strlen(buf
));
6255 Input("Retype new password:", 100, INP_NOECHO
, pass2
, data
, 0);
6259 pass2(buf
, len
, data
)
6266 struct acluser
*u
= (struct acluser
*)data
;
6269 if (!buf
|| strcmp(u
->u_password
, buf
))
6271 Msg(0, "[ Passwords don't match - checking turned off ]");
6272 if (u
->u_password
!= NullStr
)
6274 bzero(u
->u_password
, strlen(u
->u_password
));
6275 free((char *)u
->u_password
);
6277 u
->u_password
= NullStr
;
6279 else if (u
->u_password
[0] == '\0')
6281 Msg(0, "[ No password - no secure ]");
6283 bzero(buf
, strlen(buf
));
6286 if (u
->u_password
!= NullStr
)
6288 for (st
= 0; st
< 2; st
++)
6289 salt
[st
] = 'A' + (int)((time(0) >> 6 * st
) % 26);
6291 buf
= crypt(u
->u_password
, salt
);
6292 bzero(u
->u_password
, strlen(u
->u_password
));
6293 free((char *)u
->u_password
);
6294 u
->u_password
= SaveStr(buf
);
6295 bzero(buf
, strlen(buf
));
6298 UserFreeCopyBuffer(u
);
6299 u
->u_plop
.len
= strlen(u
->u_password
);
6303 if (!(u
->u_plop
.buf
= SaveStr(u
->u_password
)))
6306 D_user
->u_plop
.len
= 0;
6309 Msg(0, "[ Password moved into copybuffer ]");
6310 #else /* COPY_PASTE */
6311 Msg(0, "[ Crypted password is \"%s\" ]", u
->u_password
);
6312 #endif /* COPY_PASTE */
6315 #endif /* PASSWORD */
6322 for (i
= 0; i
< MAX_DIGRAPH
&& digraphs
[i
].d
[0]; i
++)
6323 if ((digraphs
[i
].d
[0] == (unsigned char)buf
[0] && digraphs
[i
].d
[1] == (unsigned char)buf
[1]) ||
6324 (digraphs
[i
].d
[0] == (unsigned char)buf
[1] && digraphs
[i
].d
[1] == (unsigned char)buf
[0]))
6330 digraph_fn(buf
, len
, data
)
6333 char *data
; /* dummy */
6340 buf
[len
+ 1] = ch
; /* so we can restore it later */
6341 if (ch
< ' ' || ch
== '\177')
6343 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6347 if ((ch
< '0' || ch
> '9') && (ch
< 'a' || ch
> 'f') && (ch
< 'A' || ch
> 'F'))
6349 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6352 if (len
== (*buf
== 'U' ? 5 : 3))
6356 if (len
&& *buf
== '0')
6358 if (ch
< '0' || ch
> '7')
6360 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6375 buf
[len
] = buf
[len
+ 1]; /* stored above */
6380 if (!parse_input_int(buf
, len
, &x
))
6382 i
= digraph_find(buf
);
6383 if ((x
= digraphs
[i
].value
) <= 0)
6385 Msg(0, "Unknown digraph");
6392 if (flayer
->l_encoding
== UTF8
)
6393 i
= ToUtf8(buf
, x
); /* buf is big enough for all UTF-8 codes */
6396 LayProcess(&buf
, &i
);
6407 debug1("StuffKey #%d", i
);
6410 debug1(" - %s", term
[i
+ T_CAPS
].tcname
);
6413 if (i
< KMAP_KEYS
&& D_ESCseen
)
6415 struct action
*act
= &D_ESCseen
[i
+ 256];
6416 if (act
->nr
!= RC_ILLEGAL
)
6419 DoAction(act
, i
+ 256);
6425 if (i
>= T_CURSOR
- T_CAPS
&& i
< T_KEYPAD
- T_CAPS
&& D_cursorkeys
)
6426 i
+= T_OCAPS
- T_CURSOR
;
6427 else if (i
>= T_KEYPAD
- T_CAPS
&& i
< T_OCAPS
- T_CAPS
&& D_keypad
)
6428 i
+= T_OCAPS
- T_CURSOR
;
6429 debug1(" - action %d\n", i
);
6430 flayer
= D_forecv
->c_layer
;
6434 if (flayer
&& flayer
->l_mode
== 1)
6435 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &mmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].mm
;
6437 if ((!act
|| act
->nr
== RC_ILLEGAL
) && !D_mapdefault
)
6438 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &umtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].um
;
6439 if (!act
|| act
->nr
== RC_ILLEGAL
)
6440 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &dmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].dm
;
6442 if (discard
&& (!act
|| act
->nr
!= RC_COMMAND
))
6449 if (act
== 0 || act
->nr
== RC_ILLEGAL
)
6463 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6464 if (Layer2Window(cv
->c_layer
) == wi
)
6470 FindNiceWindow(wi
, presel
)
6476 debug2("FindNiceWindow %d %s\n", wi
? wi
->w_number
: -1 , presel
? presel
: "NULL");
6479 i
= WindowByNoN(presel
);
6486 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6489 if (!wi
|| (IsOnDisplay(wi
) && !presel
))
6491 /* try to get another window */
6494 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6495 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6498 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6499 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6502 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6503 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6506 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6507 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6511 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6512 if (!wi
->w_layer
.l_cvlist
)
6515 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6516 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
))
6520 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6528 /* sorted list of all commands */
6529 static struct comm
**commtab
;
6530 static int ncommtab
;
6535 void (*hand
) __P((struct comm
*, char **, int));
6538 for (n
= 0; cos
[n
].name
; n
++)
6543 commtab
= (struct commt
*)realloc(commtab
, sizeof(*commtab
) * (ncommtab
+ n
));
6545 commtab
= (struct commt
*)malloc(sizeof(*commtab
) * (ncommtab
+ n
));
6548 for (i
= 0; i
< n
; i
++)
6550 for (j
= 0; j
< ncommtab
; j
++)
6552 r
= strcmp(cos
[i
].name
, commtab
[j
]->name
);
6554 Panic(0, "Duplicate command: %s\n", cos
[i
].name
);
6558 for (r
= ncommtab
; r
> j
; r
--)
6559 commtab
[r
] = commtab
[r
- 1];
6560 commtab
[j
] = cos
+ i
;
6561 cos
[i
].handler
= hand
;
6562 bzero(cos
[i
].userbits
, sizeof(cos
[i
].userbits
));
6571 int x
, m
, l
= 0, r
= ncommtab
- 1;
6575 x
= strcmp(str
, commtab
[m
]->name
);
6589 CalcSlicePercent(cv
, percent
)
6594 if (!cv
|| !cv
->c_slback
)
6596 up
= CalcSlicePercent(cv
->c_slback
->c_slback
, percent
);
6598 for (cv
= cv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6599 wsum
+= cv
->c_slweight
;
6602 return (up
* w
) / wsum
;
6606 ChangeCanvasSize(fcv
, abs
, diff
, gflag
, percent
)
6607 struct canvas
*fcv
; /* make this canvas bigger */
6608 int abs
; /* mode: 0:rel 1:abs 2:max */
6609 int diff
; /* change this much */
6610 int gflag
; /* go up if neccessary */
6614 int done
, have
, m
, dir
;
6616 debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs
, diff
, percent
);
6617 if (abs
== 0 && diff
== 0)
6622 fcv
->c_slweight
= 0;
6625 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6627 fcv
->c_slweight
= 1;
6628 cv
= fcv
->c_slback
->c_slback
;
6629 if (gflag
&& cv
&& cv
->c_slback
)
6630 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6638 if (percent
&& diff
> percent
)
6644 for (cv
= fcv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6645 wsum
+= cv
->c_slweight
;
6648 up
= gflag
? CalcSlicePercent(fcv
->c_slback
->c_slback
, percent
) : percent
;
6649 debug3("up=%d, wsum=%d percent=%d\n", up
, wsum
, percent
);
6652 int scale
= wsum
< 10 ? 1000 : 100;
6653 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6654 cv
->c_slweight
*= scale
;
6656 debug1("scaled wsum to %d\n", wsum
);
6658 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6662 cv
->c_slweight
= (cv
->c_slweight
* up
) / percent
;
6663 if (cv
->c_slweight
== 0)
6666 debug1(" - weight %d\n", cv
->c_slweight
);
6668 diff
= (diff
* wsum
) / percent
;
6674 if (abs
&& diff
== (fcv
->c_slorient
== SLICE_VERT
? fcv
->c_ye
- fcv
->c_ys
+ 2 : fcv
->c_xe
- fcv
->c_xs
+ 2))
6676 /* fix weights to real size (can't be helped, sorry) */
6677 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6679 cv
->c_slweight
= cv
->c_slorient
== SLICE_VERT
? cv
->c_ye
- cv
->c_ys
+ 2 : cv
->c_xe
- cv
->c_xs
+ 2;
6680 debug1(" - weight %d\n", cv
->c_slweight
);
6684 diff
= diff
- fcv
->c_slweight
;
6685 debug1("diff = %d\n", diff
);
6690 cv
= fcv
->c_slnext
? fcv
->c_slnext
: fcv
->c_slprev
;
6691 fcv
->c_slweight
+= diff
;
6692 cv
->c_slweight
-= diff
;
6697 for (cv
= fcv
->c_slnext
; diff
> 0; cv
= dir
> 0 ? cv
->c_slnext
: cv
->c_slprev
)
6701 debug1("reached end, dir is %d\n", dir
);
6711 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 : 2;
6712 debug2("min is %d, have %d\n", m
, cv
->c_slweight
);
6713 if (cv
->c_slweight
> m
)
6715 have
= cv
->c_slweight
- m
;
6718 debug1("subtract %d\n", have
);
6719 cv
->c_slweight
-= have
;
6726 /* need more room! */
6727 cv
= fcv
->c_slback
->c_slback
;
6728 if (cv
&& cv
->c_slback
)
6729 done
+= ChangeCanvasSize(fcv
->c_slback
->c_slback
, 0, diff
, gflag
, percent
);
6731 fcv
->c_slweight
+= done
;
6732 debug1("ChangeCanvasSize returns %d\n", done
);
6737 ResizeRegions(arg
, flags
)
6743 int gflag
= 0, abs
= 0, percent
= 0;
6749 if (D_forecv
->c_slorient
== SLICE_UNKN
)
6751 Msg(0, "resize: need more than one region");
6754 gflag
= flags
& RESIZE_FLAG_L
? 0 : 1;
6755 orient
|= flags
& RESIZE_FLAG_H
? SLICE_HORI
: 0;
6756 orient
|= flags
& RESIZE_FLAG_V
? SLICE_VERT
: 0;
6758 orient
= D_forecv
->c_slorient
;
6762 /* make all regions the same height */
6763 struct canvas
*cv
= gflag
? &D_canvas
: D_forecv
->c_slback
;
6764 if (cv
->c_slperp
->c_slorient
& orient
)
6765 EqualizeCanvas(cv
->c_slperp
, gflag
);
6766 /* can't use cv->c_slorient directly as it can be D_canvas */
6767 if ((cv
->c_slperp
->c_slorient
^ (SLICE_HORI
^ SLICE_VERT
)) & orient
)
6772 EqualizeCanvas(cv
->c_slperp
, gflag
);
6775 EqualizeCanvas(cv
, gflag
);
6778 RecreateCanvasChain();
6779 RethinkDisplayViewports();
6780 ResizeLayersToCanvases();
6783 if (!strcmp(arg
, "min") || !strcmp(arg
, "0"))
6788 else if (!strcmp(arg
, "max") || !strcmp(arg
, "_"))
6795 if (l
> 0 && arg
[l
- 1] == '%')
6798 diff
= atoi(arg
+ 1);
6799 else if (*arg
== '-')
6800 diff
= -atoi(arg
+ 1);
6803 diff
= atoi(arg
); /* +1 because of caption line */
6806 abs
= diff
== 0 ? 2 : 1;
6812 diff
= diff
* percent
/ 100;
6814 if (cv
->c_slorient
& orient
)
6815 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6816 if (cv
->c_slback
->c_slorient
& orient
)
6817 ChangeCanvasSize(cv
->c_slback
, abs
, diff
, gflag
, percent
);
6819 ResizeCanvas(&D_canvas
);
6820 RecreateCanvasChain();
6821 RethinkDisplayViewports();
6822 ResizeLayersToCanvases();
6829 if (siz
+ diff
> dsize
- (nreg
- 1) * 2 - 1)
6830 diff
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6831 if (diff
== 0 || siz
+ diff
< 1)
6836 if (D_forecv
->c_next
)
6838 D_forecv
->c_ye
+= diff
;
6839 D_forecv
->c_next
->c_ys
+= diff
;
6840 D_forecv
->c_next
->c_yoff
+= diff
;
6844 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6845 if (cv
->c_next
== D_forecv
)
6849 D_forecv
->c_ys
-= diff
;
6850 D_forecv
->c_yoff
-= diff
;
6855 int s
, i
= 0, found
= 0, di
= diff
, d2
;
6856 s
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6857 for (cv
= D_cvlist
; cv
; i
= cv
->c_ye
+ 2, cv
= cv
->c_next
)
6861 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) + diff
;
6862 cv
->c_yoff
-= cv
->c_ys
- i
;
6867 s
-= cv
->c_ye
- cv
->c_ys
;
6875 d2
= di
> cv
->c_ye
- cv
->c_ys
? cv
->c_ye
- cv
->c_ys
: di
;
6877 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) - d2
;
6878 cv
->c_yoff
-= cv
->c_ys
- i
;
6882 RethinkDisplayViewports();
6883 ResizeLayersToCanvases();
6888 ResizeFin(buf
, len
, data
)
6894 int flags
= *(int *)data
;
6895 ch
= ((unsigned char *)buf
)[len
];
6898 ResizeRegions(buf
, flags
);
6902 flags
^= RESIZE_FLAG_H
;
6904 flags
^= RESIZE_FLAG_V
;
6906 flags
|= RESIZE_FLAG_H
|RESIZE_FLAG_V
;
6908 flags
^= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
6910 flags
^= RESIZE_FLAG_L
;
6913 inp_setprompt(resizeprompts
[flags
], NULL
);
6914 *(int *)data
= flags
;
6919 SetForeCanvas(d
, cv
)
6923 struct display
*odisplay
= display
;
6924 if (d
->d_forecv
== cv
)
6929 if ((focusminwidth
&& (focusminwidth
< 0 || D_forecv
->c_xe
- D_forecv
->c_xs
+ 1 < focusminwidth
)) ||
6930 (focusminheight
&& (focusminheight
< 0 || D_forecv
->c_ye
- D_forecv
->c_ys
+ 1 < focusminheight
)))
6932 ResizeCanvas(&D_canvas
);
6933 RecreateCanvasChain();
6934 RethinkDisplayViewports();
6935 ResizeLayersToCanvases(); /* redisplays */
6937 fore
= D_fore
= Layer2Window(D_forecv
->c_layer
);
6938 if (D_other
== fore
)
6940 flayer
= D_forecv
->c_layer
;
6942 if (D_xtermosc
[2] || D_xtermosc
[3])
6953 flayer
= D_forecv
->c_layer
;
6954 CV_CALL(D_forecv
, LayRestore();LaySetCursor());
6955 WindowChanged(0, 'F');
6968 p
= Layer2Window(D_forecv
->c_layer
);
6969 for (i
= 3; i
>=0; i
--)
6970 SetXtermOSC(i
, p
? p
->w_xtermosc
[i
] : 0);
6975 ParseAttrColor(s1
, s2
, msgok
)
6987 while (*ss
&& *ss
!= ' ')
6991 if (*s
&& (s2
|| *ss
|| !((*s
>= 'a' && *s
<= 'z') || (*s
>= 'A' && *s
<= 'Z') || *s
== '.')))
6993 int mode
= 0, n
= 0;
7011 if (*s
>= '0' && *s
<= '9')
7014 if (*s
>= '0' && *s
<= '9')
7015 n
= n
* 16 + (*s
++ - '0');
7016 else if (*s
>= 'a' && *s
<= 'f')
7017 n
= n
* 16 + (*s
++ - ('a' - 10));
7018 else if (*s
>= 'A' && *s
<= 'F')
7019 n
= n
* 16 + (*s
++ - ('A' - 10));
7020 else if (*s
&& *s
!= ' ')
7023 Msg(0, "Illegal attribute hexchar '%c'", *s
);
7029 while (*s
&& *s
!= ' ')
7046 Msg(0, "Illegal attribute specifier '%c'", *s
);
7052 if (*s
&& *s
!= ' ')
7055 Msg(0, "junk after attribute description: '%c'", *s
);
7067 while (*s
&& *s
== ' ')
7075 Msg(0, "junk after description: '%c'", *s
);
7079 while (*s
&& *s
== ' ')
7086 static char costr
[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
7096 for (j
= 0; j
< 2 && *s
&& *s
!= ' '; j
++)
7098 for (i
= 0; costr
[i
]; i
++)
7104 Msg(0, "illegal color descriptor: '%c'", *s
);
7108 n
= n
<< 4 | (i
& 15);
7111 n
= (n
& 0x20ff) | 0x200;
7115 if ((n
& 0xf00) == 0xf00)
7116 n
^= 0xf00; /* clear superflous bits */
7119 n
^= 0x2400; /* shift bit into right position */
7122 n
|= 0xf0; /* don't change bg color */
7123 if (numco
!= 2 && n
!= 0xff)
7124 n
|= 0x100; /* special invert mode */
7125 if (*s
&& *s
!= ' ')
7128 Msg(0, "junk after color description: '%c'", *s
);
7136 while (*s
&& *s
== ' ')
7141 Msg(0, "junk after description: '%c'", *s
);
7144 debug1("ParseAttrColor %06x\n", r
);
7152 * e just set intensity
7153 * f don't change anything
7154 * Intensity is encoded into bits 17(fg) and 18(bg).
7157 ApplyAttrColor(i
, mc
)
7161 debug1("ApplyAttrColor %06x\n", i
);
7162 mc
->attr
|= i
>> 8 & 255;
7163 mc
->attr
^= i
& 255;
7165 i
= (i
>> 16) ^ 0xff;
7166 if ((i
& 0x100) != 0)
7169 if (mc
->attr
& (A_SO
|A_RV
))
7171 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4) | ((i
& 0x200) << 1) | ((i
& 0x400) >> 1);
7173 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4);
7177 if ((i
& 0x0f) != 0x0f)
7178 mc
->attr
= (mc
->attr
& 0xbf) | ((i
>> 3) & 0x40);
7179 if ((i
& 0xf0) != 0xf0)
7180 mc
->attr
= (mc
->attr
& 0x7f) | ((i
>> 3) & 0x80);
7182 mc
->color
= 0x99 ^ mc
->color
;
7183 if ((i
& 0x0e) == 0x0e)
7184 i
= (i
& 0xf0) | (mc
->color
& 0x0f);
7185 if ((i
& 0xe0) == 0xe0)
7186 i
= (i
& 0x0f) | (mc
->color
& 0xf0);
7187 mc
->color
= 0x99 ^ i
;
7188 debug2("ApplyAttrColor - %02x %02x\n", mc
->attr
, i
);