929afba5eea9108eef669d91ad69d04933d47d8f
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Micah Cowan (micah@cowan.name)
5 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
6 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
7 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
8 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
9 * Copyright (c) 1987 Oliver Laumann
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, see
23 * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 ****************************************************************
29 #include <sys/types.h>
33 #if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
38 #include <sys/ioctl.h>
44 /* for solaris 2.1, Unixware (SVR4.2) and possibly others: */
46 # include <sys/stropts.h>
53 extern struct comm comms
[];
55 extern char *RcFileName
, *home
;
56 extern char *BellString
, *ActivityString
, *ShellProg
, *ShellArgs
[];
57 extern char *hstatusstring
, *captionstring
, *timestring
;
58 extern char *wliststr
, *wlisttit
;
59 extern int captionalways
;
60 extern char *hardcopydir
, *screenlogfile
, *logtstamp_string
;
61 extern int log_flush
, logtstamp_on
, logtstamp_after
;
62 extern char *VisualBellString
;
63 extern int VBellWait
, MsgWait
, MsgMinWait
, SilenceWait
;
64 extern char SockPath
[], *SockName
;
65 extern int TtyMode
, auto_detach
, use_altscreen
;
66 extern int iflag
, maxwin
;
67 extern int focusminwidth
, focusminheight
;
68 extern int use_hardstatus
, visual_bell
;
70 extern int attr2color
[][4];
71 extern int nattr2color
;
73 extern int hardstatusemu
;
74 extern char *printcmd
;
75 extern int default_startup
;
76 extern int defobuflimit
;
77 extern int defnonblock
;
78 extern int ZombieKey_destroy
;
79 extern int ZombieKey_resurrect
;
80 extern int ZombieKey_onerror
;
82 extern int defautonuke
;
84 extern int separate_sids
;
85 extern struct NewWindow nwin_default
, nwin_undef
;
87 extern int join_with_cr
;
88 extern int compacthist
;
93 extern unsigned char mark_key_tab
[];
94 extern char *BufferFile
;
97 extern char *BufferFile
, *PowDetachString
;
100 extern struct acluser
*EffectiveAclUser
; /* acl.c */
102 extern struct term term
[]; /* terminal capabilities */
104 extern char *kmapdef
[];
105 extern char *kmapadef
[];
106 extern char *kmapmdef
[];
108 extern struct mchar mchar_so
, mchar_null
;
109 extern int VerboseCreate
;
111 extern char *screenencodings
;
117 static int CheckArgNum
__P((int, char **));
118 static void ClearAction
__P((struct action
*));
119 static void SaveAction
__P((struct action
*, int, char **, int *));
120 static int NextWindow
__P((void));
121 static int PreviousWindow
__P((void));
122 static int MoreWindows
__P((void));
123 static void LogToggle
__P((int));
124 static void ShowInfo
__P((void));
125 static void ShowDInfo
__P((void));
126 static struct win
*WindowByName
__P((char *));
127 static int WindowByNumber
__P((char *));
128 static int ParseOnOff
__P((struct action
*, int *));
129 static int ParseWinNum
__P((struct action
*, int *));
130 static int ParseBase
__P((struct action
*, char *, int *, int, char *));
131 static int ParseNum1000
__P((struct action
*, int *));
132 static char **SaveArgs
__P((char **));
133 static int IsNum
__P((char *, int));
134 static void Colonfin
__P((char *, int, char *));
135 static void InputSelect
__P((void));
136 static void InputSetenv
__P((char *));
137 static void InputAKA
__P((void));
139 static int InputSu
__P((struct win
*, struct acluser
**, char *));
140 static void su_fin
__P((char *, int, char *));
142 static void AKAfin
__P((char *, int, char *));
144 static void copy_reg_fn
__P((char *, int, char *));
145 static void ins_reg_fn
__P((char *, int, char *));
147 static void process_fn
__P((char *, int, char *));
149 static void pass1
__P((char *, int, char *));
150 static void pass2
__P((char *, int, char *));
153 static void pow_detach_fn
__P((char *, int, char *));
155 static void digraph_fn
__P((char *, int, char *));
156 static void confirm_fn
__P((char *, int, char *));
157 static int IsOnDisplay
__P((struct win
*));
158 static void ResizeRegions
__P((char *, int));
159 static void ResizeFin
__P((char *, int, char *));
160 static struct action
*FindKtab
__P((char *, int));
161 static void SelectFin
__P((char *, int, char *));
162 static void SelectLayoutFin
__P((char *, int, char *));
165 extern struct layer
*flayer
;
166 extern struct display
*display
, *displays
;
167 extern struct win
*fore
, *console_window
, *windows
;
168 extern struct acluser
*users
;
169 extern struct layout
*layouts
, *layout_attach
, layout_last_marker
;
170 extern struct layout
*laytab
[];
172 extern char screenterm
[], HostName
[], version
[];
173 extern struct NewWindow nwin_undef
, nwin_default
;
174 extern struct LayFuncs WinLf
, MarkLf
;
176 extern int Z0width
, Z1width
;
177 extern int real_uid
, real_gid
;
180 extern int nethackflag
;
184 struct win
*wtab
[MAXWIN
]; /* window table, should be dynamic */
188 extern int maxusercount
;
192 struct plop plop_tab
[MAX_PLOP_DEFS
];
195 # define PTYMODE 0622
198 int TtyMode
= PTYMODE
;
199 int hardcopy_append
= 0;
200 int all_norefresh
= 0;
203 char *zmodem_sendcmd
;
204 char *zmodem_recvcmd
;
205 static char *zmodes
[4] = {"off", "auto", "catch", "pass"};
209 struct action idleaction
;
214 struct action ktab
[256 + KMAP_KEYS
]; /* command key translation table */
218 struct action ktab
[256 + KMAP_KEYS
];
220 struct kclass
*kclasses
;
223 struct action umtab
[KMAP_KEYS
+KMAP_AKEYS
];
224 struct action dmtab
[KMAP_KEYS
+KMAP_AKEYS
];
225 struct action mmtab
[KMAP_KEYS
+KMAP_AKEYS
];
226 struct kmap_ext
*kmap_exts
;
228 static int maptimeout
= 300;
232 /* digraph table taken from old vim and rfc1345 */
233 static const unsigned char digraphs
[][3] = {
234 {' ', ' ', 160}, /* */
235 {'N', 'S', 160}, /* */
236 {'~', '!', 161}, /* ¡ */
237 {'!', '!', 161}, /* ¡ */
238 {'!', 'I', 161}, /* ¡ */
239 {'c', '|', 162}, /* ¢ */
240 {'c', 't', 162}, /* ¢ */
241 {'$', '$', 163}, /* £ */
242 {'P', 'd', 163}, /* £ */
243 {'o', 'x', 164}, /* ¤ */
244 {'C', 'u', 164}, /* ¤ */
245 {'C', 'u', 164}, /* ¤ */
246 {'E', 'u', 164}, /* ¤ */
247 {'Y', '-', 165}, /* ¥ */
248 {'Y', 'e', 165}, /* ¥ */
249 {'|', '|', 166}, /* ¦ */
250 {'B', 'B', 166}, /* ¦ */
251 {'p', 'a', 167}, /* § */
252 {'S', 'E', 167}, /* § */
253 {'"', '"', 168}, /* ¨ */
254 {'\'', ':', 168}, /* ¨ */
255 {'c', 'O', 169}, /* © */
256 {'C', 'o', 169}, /* © */
257 {'a', '-', 170}, /* ª */
258 {'<', '<', 171}, /* « */
259 {'-', ',', 172}, /* ¬ */
260 {'N', 'O', 172}, /* ¬ */
261 {'-', '-', 173}, /* */
262 {'r', 'O', 174}, /* ® */
263 {'R', 'g', 174}, /* ® */
264 {'-', '=', 175}, /* ¯ */
265 {'\'', 'm', 175}, /* ¯ */
266 {'~', 'o', 176}, /* ° */
267 {'D', 'G', 176}, /* ° */
268 {'+', '-', 177}, /* ± */
269 {'2', '2', 178}, /* ² */
270 {'2', 'S', 178}, /* ² */
271 {'3', '3', 179}, /* ³ */
272 {'3', 'S', 179}, /* ³ */
273 {'\'', '\'', 180}, /* ´ */
274 {'j', 'u', 181}, /* µ */
275 {'M', 'y', 181}, /* µ */
276 {'p', 'p', 182}, /* ¶ */
277 {'P', 'I', 182}, /* ¶ */
278 {'~', '.', 183}, /* · */
279 {'.', 'M', 183}, /* · */
280 {',', ',', 184}, /* ¸ */
281 {'\'', ',', 184}, /* ¸ */
282 {'1', '1', 185}, /* ¹ */
283 {'1', 'S', 185}, /* ¹ */
284 {'o', '-', 186}, /* º */
285 {'>', '>', 187}, /* » */
286 {'1', '4', 188}, /* ¼ */
287 {'1', '2', 189}, /* ½ */
288 {'3', '4', 190}, /* ¾ */
289 {'~', '?', 191}, /* ¿ */
290 {'?', '?', 191}, /* ¿ */
291 {'?', 'I', 191}, /* ¿ */
292 {'A', '`', 192}, /* À */
293 {'A', '!', 192}, /* À */
294 {'A', '\'', 193}, /* Á */
295 {'A', '^', 194}, /* Â */
296 {'A', '>', 194}, /* Â */
297 {'A', '~', 195}, /* Ã */
298 {'A', '?', 195}, /* Ã */
299 {'A', '"', 196}, /* Ä */
300 {'A', ':', 196}, /* Ä */
301 {'A', '@', 197}, /* Å */
302 {'A', 'A', 197}, /* Å */
303 {'A', 'E', 198}, /* Æ */
304 {'C', ',', 199}, /* Ç */
305 {'E', '`', 200}, /* È */
306 {'E', '!', 200}, /* È */
307 {'E', '\'', 201}, /* É */
308 {'E', '^', 202}, /* Ê */
309 {'E', '>', 202}, /* Ê */
310 {'E', '"', 203}, /* Ë */
311 {'E', ':', 203}, /* Ë */
312 {'I', '`', 204}, /* Ì */
313 {'I', '!', 204}, /* Ì */
314 {'I', '\'', 205}, /* Í */
315 {'I', '^', 206}, /* Î */
316 {'I', '>', 206}, /* Î */
317 {'I', '"', 207}, /* Ï */
318 {'I', ':', 207}, /* Ï */
319 {'D', '-', 208}, /* Ð */
320 {'N', '~', 209}, /* Ñ */
321 {'N', '?', 209}, /* Ñ */
322 {'O', '`', 210}, /* Ò */
323 {'O', '!', 210}, /* Ò */
324 {'O', '\'', 211}, /* Ó */
325 {'O', '^', 212}, /* Ô */
326 {'O', '>', 212}, /* Ô */
327 {'O', '~', 213}, /* Õ */
328 {'O', '?', 213}, /* Õ */
329 {'O', '"', 214}, /* Ö */
330 {'O', ':', 214}, /* Ö */
331 {'/', '\\', 215}, /* × */
332 {'*', 'x', 215}, /* × */
333 {'O', '/', 216}, /* Ø */
334 {'U', '`', 217}, /* Ù */
335 {'U', '!', 217}, /* Ù */
336 {'U', '\'', 218}, /* Ú */
337 {'U', '^', 219}, /* Û */
338 {'U', '>', 219}, /* Û */
339 {'U', '"', 220}, /* Ü */
340 {'U', ':', 220}, /* Ü */
341 {'Y', '\'', 221}, /* Ý */
342 {'I', 'p', 222}, /* Þ */
343 {'T', 'H', 222}, /* Þ */
344 {'s', 's', 223}, /* ß */
345 {'s', '"', 223}, /* ß */
346 {'a', '`', 224}, /* à */
347 {'a', '!', 224}, /* à */
348 {'a', '\'', 225}, /* á */
349 {'a', '^', 226}, /* â */
350 {'a', '>', 226}, /* â */
351 {'a', '~', 227}, /* ã */
352 {'a', '?', 227}, /* ã */
353 {'a', '"', 228}, /* ä */
354 {'a', ':', 228}, /* ä */
355 {'a', 'a', 229}, /* å */
356 {'a', 'e', 230}, /* æ */
357 {'c', ',', 231}, /* ç */
358 {'e', '`', 232}, /* è */
359 {'e', '!', 232}, /* è */
360 {'e', '\'', 233}, /* é */
361 {'e', '^', 234}, /* ê */
362 {'e', '>', 234}, /* ê */
363 {'e', '"', 235}, /* ë */
364 {'e', ':', 235}, /* ë */
365 {'i', '`', 236}, /* ì */
366 {'i', '!', 236}, /* ì */
367 {'i', '\'', 237}, /* í */
368 {'i', '^', 238}, /* î */
369 {'i', '>', 238}, /* î */
370 {'i', '"', 239}, /* ï */
371 {'i', ':', 239}, /* ï */
372 {'d', '-', 240}, /* ð */
373 {'n', '~', 241}, /* ñ */
374 {'n', '?', 241}, /* ñ */
375 {'o', '`', 242}, /* ò */
376 {'o', '!', 242}, /* ò */
377 {'o', '\'', 243}, /* ó */
378 {'o', '^', 244}, /* ô */
379 {'o', '>', 244}, /* ô */
380 {'o', '~', 245}, /* õ */
381 {'o', '?', 245}, /* õ */
382 {'o', '"', 246}, /* ö */
383 {'o', ':', 246}, /* ö */
384 {':', '-', 247}, /* ÷ */
385 {'o', '/', 248}, /* ø */
386 {'u', '`', 249}, /* ù */
387 {'u', '!', 249}, /* ù */
388 {'u', '\'', 250}, /* ú */
389 {'u', '^', 251}, /* û */
390 {'u', '>', 251}, /* û */
391 {'u', '"', 252}, /* ü */
392 {'u', ':', 252}, /* ü */
393 {'y', '\'', 253}, /* ý */
394 {'i', 'p', 254}, /* þ */
395 {'t', 'h', 254}, /* þ */
396 {'y', '"', 255}, /* ÿ */
397 {'y', ':', 255}, /* ÿ */
398 {'"', '[', 196}, /* Ä */
399 {'"', '\\', 214}, /* Ö */
400 {'"', ']', 220}, /* Ü */
401 {'"', '{', 228}, /* ä */
402 {'"', '|', 246}, /* ö */
403 {'"', '}', 252}, /* ü */
404 {'"', '~', 223} /* ß */
407 #define RESIZE_FLAG_H 1
408 #define RESIZE_FLAG_V 2
409 #define RESIZE_FLAG_L 4
411 static char *resizeprompts
[] = {
413 "resize -h # lines: ",
414 "resize -v # lines: ",
415 "resize -b # lines: ",
416 "resize -l # lines: ",
417 "resize -l -h # lines: ",
418 "resize -l -v # lines: ",
419 "resize -l -b # lines: ",
427 register unsigned int i
;
432 for (i
= 0; i
< sizeof(ktab
)/sizeof(*ktab
); i
++)
434 ktab
[i
].nr
= RC_ILLEGAL
;
435 ktab
[i
].args
= noargs
;
439 for (i
= 0; i
< KMAP_KEYS
+KMAP_AKEYS
; i
++)
441 umtab
[i
].nr
= RC_ILLEGAL
;
442 umtab
[i
].args
= noargs
;
444 dmtab
[i
].nr
= RC_ILLEGAL
;
445 dmtab
[i
].args
= noargs
;
447 mmtab
[i
].nr
= RC_ILLEGAL
;
448 mmtab
[i
].args
= noargs
;
452 for (i
= 0; i
< NKMAPDEF
; i
++)
454 if (i
+ KMAPDEFSTART
< T_CAPS
)
456 if (i
+ KMAPDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
460 argarr
[0] = kmapdef
[i
];
461 SaveAction(dmtab
+ i
+ (KMAPDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
463 for (i
= 0; i
< NKMAPADEF
; i
++)
465 if (i
+ KMAPADEFSTART
< T_CURSOR
)
467 if (i
+ KMAPADEFSTART
>= T_CURSOR
+ KMAP_AKEYS
)
469 if (kmapadef
[i
] == 0)
471 argarr
[0] = kmapadef
[i
];
472 SaveAction(dmtab
+ i
+ (KMAPADEFSTART
- T_CURSOR
+ KMAP_KEYS
), RC_STUFF
, argarr
, 0);
474 for (i
= 0; i
< NKMAPMDEF
; i
++)
476 if (i
+ KMAPMDEFSTART
< T_CAPS
)
478 if (i
+ KMAPMDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
480 if (kmapmdef
[i
] == 0)
482 argarr
[0] = kmapmdef
[i
];
484 SaveAction(mmtab
+ i
+ (KMAPMDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
488 ktab
['h'].nr
= RC_HARDCOPY
;
490 ktab
['z'].nr
= ktab
[Ctrl('z')].nr
= RC_SUSPEND
;
492 ktab
['c'].nr
= ktab
[Ctrl('c')].nr
= RC_SCREEN
;
493 ktab
[' '].nr
= ktab
[Ctrl(' ')].nr
=
494 ktab
['n'].nr
= ktab
[Ctrl('n')].nr
= RC_NEXT
;
495 ktab
['N'].nr
= RC_NUMBER
;
496 ktab
[Ctrl('h')].nr
= ktab
[0177].nr
= ktab
['p'].nr
= ktab
[Ctrl('p')].nr
= RC_PREV
;
497 ktab
['k'].nr
= ktab
[Ctrl('k')].nr
= RC_KILL
;
498 ktab
['l'].nr
= ktab
[Ctrl('l')].nr
= RC_REDISPLAY
;
499 ktab
['w'].nr
= ktab
[Ctrl('w')].nr
= RC_WINDOWS
;
500 ktab
['v'].nr
= RC_VERSION
;
501 ktab
[Ctrl('v')].nr
= RC_DIGRAPH
;
502 ktab
['q'].nr
= ktab
[Ctrl('q')].nr
= RC_XON
;
503 ktab
['s'].nr
= ktab
[Ctrl('s')].nr
= RC_XOFF
;
504 ktab
['t'].nr
= ktab
[Ctrl('t')].nr
= RC_TIME
;
505 ktab
['i'].nr
= ktab
[Ctrl('i')].nr
= RC_INFO
;
506 ktab
['m'].nr
= ktab
[Ctrl('m')].nr
= RC_LASTMSG
;
507 ktab
['A'].nr
= RC_TITLE
;
508 #if defined(UTMPOK) && defined(LOGOUTOK)
509 ktab
['L'].nr
= RC_LOGIN
;
511 ktab
[','].nr
= RC_LICENSE
;
512 ktab
['W'].nr
= RC_WIDTH
;
513 ktab
['.'].nr
= RC_DUMPTERMCAP
;
514 ktab
[Ctrl('\\')].nr
= RC_QUIT
;
516 ktab
['d'].nr
= ktab
[Ctrl('d')].nr
= RC_DETACH
;
518 ktab
['D'].nr
= RC_POW_DETACH
;
521 ktab
['r'].nr
= ktab
[Ctrl('r')].nr
= RC_WRAP
;
522 ktab
['f'].nr
= ktab
[Ctrl('f')].nr
= RC_FLOW
;
523 ktab
['C'].nr
= RC_CLEAR
;
524 ktab
['Z'].nr
= RC_RESET
;
525 ktab
['H'].nr
= RC_LOG
;
526 ktab
['M'].nr
= RC_MONITOR
;
527 ktab
['?'].nr
= RC_HELP
;
529 ktab
['*'].nr
= RC_DISPLAYS
;
535 SaveAction(ktab
+ '-', RC_SELECT
, args
, 0);
537 for (i
= 0; i
< ((MAXWIN
< 10) ? MAXWIN
: 10); i
++)
539 char *args
[2], arg1
[10];
542 sprintf(arg1
, "%d", i
);
543 SaveAction(ktab
+ '0' + i
, RC_SELECT
, args
, 0);
545 ktab
['\''].nr
= RC_SELECT
; /* calling a window by name */
550 SaveAction(ktab
+ '"', RC_WINDOWLIST
, args
, 0);
552 ktab
[Ctrl('G')].nr
= RC_VBELL
;
553 ktab
[':'].nr
= RC_COLON
;
555 ktab
['['].nr
= ktab
[Ctrl('[')].nr
= RC_COPY
;
560 SaveAction(ktab
+ ']', RC_PASTE
, args
, 0);
561 SaveAction(ktab
+ Ctrl(']'), RC_PASTE
, args
, 0);
563 ktab
['{'].nr
= RC_HISTORY
;
564 ktab
['}'].nr
= RC_HISTORY
;
565 ktab
['>'].nr
= RC_WRITEBUF
;
566 ktab
['<'].nr
= RC_READBUF
;
567 ktab
['='].nr
= RC_REMOVEBUF
;
570 ktab
['D'].nr
= RC_POW_DETACH
;
573 ktab
['x'].nr
= ktab
[Ctrl('x')].nr
= RC_LOCKSCREEN
;
575 ktab
['b'].nr
= ktab
[Ctrl('b')].nr
= RC_BREAK
;
576 ktab
['B'].nr
= RC_POW_BREAK
;
577 ktab
['_'].nr
= RC_SILENCE
;
578 ktab
['S'].nr
= RC_SPLIT
;
579 ktab
['Q'].nr
= RC_ONLY
;
580 ktab
['X'].nr
= RC_REMOVE
;
581 ktab
['F'].nr
= RC_FIT
;
582 ktab
['\t'].nr
= RC_FOCUS
;
587 SaveAction(ktab
+ T_BACKTAB
- T_CAPS
+ 256, RC_FOCUS
, args
, 0);
593 SaveAction(ktab
+ '|', RC_SPLIT
, args
, 0);
595 /* These come last; they may want overwrite others: */
598 ClearAction(&ktab
[DefaultEsc
]);
599 ktab
[DefaultEsc
].nr
= RC_OTHER
;
601 if (DefaultMetaEsc
>= 0)
603 ClearAction(&ktab
[DefaultMetaEsc
]);
604 ktab
[DefaultMetaEsc
].nr
= RC_META
;
607 idleaction
.nr
= RC_BLANKER
;
608 idleaction
.args
= noargs
;
612 static struct action
*
613 FindKtab(class, create
)
617 struct kclass
*kp
, **kpp
;
622 for (kpp
= &kclasses
; (kp
= *kpp
) != 0; kpp
= &kp
->next
)
623 if (!strcmp(kp
->name
, class))
629 if (strlen(class) > 80)
631 Msg(0, "Command class name too long.");
634 kp
= malloc(sizeof(*kp
));
640 kp
->name
= SaveStr(class);
641 for (i
= 0; i
< (int)(sizeof(kp
->ktab
)/sizeof(*kp
->ktab
)); i
++)
643 kp
->ktab
[i
].nr
= RC_ILLEGAL
;
644 kp
->ktab
[i
].args
= noargs
;
658 if (act
->nr
== RC_ILLEGAL
)
660 act
->nr
= RC_ILLEGAL
;
661 if (act
->args
== noargs
)
663 for (p
= act
->args
; *p
; p
++)
665 free((char *)act
->args
);
671 * ProcessInput: process input from display and feed it into
672 * the layer on canvas D_forecv.
678 * This ProcessInput just does the keybindings and passes
679 * everything else on to ProcessInput2.
683 ProcessInput(ibuf
, ilen
)
688 unsigned char *s
, *q
;
692 debug1("ProcessInput: %d bytes\n", ilen
);
693 if (display
== 0 || ilen
== 0)
698 s
= (unsigned char *)ibuf
;
702 if (D_dontmap
|| !D_nseqs
)
709 debug3("cmp %c %c[%d]\n", ch
, *D_seqp
, D_seqp
- D_kmaps
);
712 l
= D_seqp
[D_seqp
[-D_seql
-1] + 1];
716 debug1("miss %d\n", D_seqp
- D_kmaps
);
719 debug("complete miss\n");
722 p
= (char *)D_seqp
- l
;
724 D_seqp
= D_kmaps
+ 3;
727 if ((q
= D_seqh
) != 0)
730 i
= q
[0] << 8 | q
[1];
731 i
&= ~KMAP_NOTIMEOUT
;
732 debug1("Mapping former hit #%d - ", i
);
733 debug2("%d(%s) - ", q
[2], q
+ 3);
735 ProcessInput2((char *)q
+ 3, q
[2]);
743 debug1("flush old %d\n", l
);
752 /* Finish old stuff */
754 debug1("finish old %d\n", slen
);
756 ProcessInput2(ibuf
, slen
);
765 debug2("length am %d, want %d\n", l
, D_seqp
[-l
- 1]);
766 if (l
== D_seqp
[-l
- 1])
771 if (D_kmaps
+ D_nseqs
> q
&& q
[2] > l
&& !bcmp(D_seqp
- l
, q
+ 3, l
))
773 debug1("have another mapping (%s), delay execution\n", q
+ 3);
774 D_seqh
= D_seqp
- 3 - l
;
779 i
= D_seqp
[-l
- 3] << 8 | D_seqp
[-l
- 2];
780 i
&= ~KMAP_NOTIMEOUT
;
781 debug1("Mapping #%d - ", i
);
782 p
= (char *)D_seqp
- l
;
783 debug2("%d(%s) - ", l
, p
);
785 D_seqp
= D_kmaps
+ 3;
797 debug("am in sequence -> check for timeout\n");
799 for (s
= D_seqp
; ; s
+= i
* 2 + 4)
801 if (s
[-l
-3] & KMAP_NOTIMEOUT
>> 8)
803 if ((i
= s
[s
[-l
-1] + 1]) == 0)
805 SetTimeout(&D_mapev
, maptimeout
);
811 ProcessInput2(ibuf
, slen
);
815 # define ProcessInput2 ProcessInput
820 * Here only the screen escape commands are handled.
824 ProcessInput2(ibuf
, ilen
)
830 struct action
*ktabp
;
832 debug1("ProcessInput2: %d bytes\n", ilen
);
833 while (ilen
&& display
)
835 debug1(" - ilen now %d bytes\n", ilen
);
836 flayer
= D_forecv
->c_layer
;
844 if ((unsigned char)*s
++ == D_user
->u_Esc
)
850 DoProcess(fore
, &ibuf
, &slen
, 0);
856 ktabp
= D_ESCseen
? D_ESCseen
: ktab
;
858 ch
= (unsigned char)*s
;
861 * As users have different esc characters, but a common ktab[],
862 * we fold back the users esc and meta-esc key to the Default keys
863 * that can be looked up in the ktab[]. grmbl. jw.
864 * XXX: make ktab[] a per user thing.
866 if (ch
== D_user
->u_Esc
)
868 else if (ch
== D_user
->u_MetaEsc
)
872 DoAction(&ktabp
[ch
], ch
);
873 ibuf
= (char *)(s
+ 1);
879 DoProcess(p
, bufp
, lenp
, pa
)
886 struct display
*d
= display
;
889 /* XXX -> PasteStart */
890 if (pa
&& *lenp
> 1 && p
&& p
->w_slowpaste
)
892 /* schedule slowpaste event */
893 SetTimeout(&p
->w_paster
.pa_slowev
, p
->w_slowpaste
);
894 evenq(&p
->w_paster
.pa_slowev
);
898 while (flayer
&& *lenp
)
901 if (!pa
&& p
&& p
->w_paster
.pa_pastelen
&& flayer
== p
->w_paster
.pa_pastelayer
)
903 debug("layer is busy - beep!\n");
904 WBell(p
, visual_bell
);
912 LayProcess(bufp
, lenp
);
914 if (pa
&& !pa
->pa_pastelayer
)
915 break; /* flush rest of paste */
924 /* We're full, let's beep */
925 debug("layer is full - beep!\n");
926 WBell(p
, visual_bell
);
934 if (pa
&& pa
->pa_pastelen
== 0)
943 int x
, m
, l
= 0, r
= RC_LAST
;
947 x
= strcmp(str
, comms
[m
].name
);
959 CheckArgNum(nr
, args
)
964 static char *argss
[] = {"no", "one", "two", "three", "four", "OOPS"};
965 static char *orformat
[] =
967 "%s: %s: %s argument%s required",
968 "%s: %s: %s or %s argument%s required",
969 "%s: %s: %s, %s or %s argument%s required",
970 "%s: %s: %s, %s, %s or %s argument%s required"
973 n
= comms
[nr
].flags
& ARGS_MASK
;
974 for (i
= 0; args
[i
]; i
++)
976 if (comms
[nr
].flags
& ARGS_ORMORE
)
980 Msg(0, "%s: %s: at least %s argument%s required",
981 rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
985 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
986 (comms
[nr
].flags
& ARGS_PLUS2
) &&
987 (comms
[nr
].flags
& ARGS_PLUS3
))
989 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2 && i
!= n
+ 3)
991 Msg(0, orformat
[3], rc_name
, comms
[nr
].name
, argss
[n
],
992 argss
[n
+ 1], argss
[n
+ 2], argss
[n
+ 3], "");
996 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
997 (comms
[nr
].flags
& ARGS_PLUS2
))
999 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2)
1001 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1002 argss
[n
+ 1], argss
[n
+ 2], "");
1006 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1007 (comms
[nr
].flags
& ARGS_PLUS3
))
1009 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 3)
1011 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1012 argss
[n
+ 1], argss
[n
+ 3], "");
1016 else if ((comms
[nr
].flags
& ARGS_PLUS2
) &&
1017 (comms
[nr
].flags
& ARGS_PLUS3
))
1019 if (i
!= n
&& i
!= n
+ 2 && i
!= n
+ 3)
1021 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1022 argss
[n
+ 2], argss
[n
+ 3], "");
1026 else if (comms
[nr
].flags
& ARGS_PLUS1
)
1028 if (i
!= n
&& i
!= n
+ 1)
1030 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1031 argss
[n
+ 1], n
!= 0 ? "s" : "");
1035 else if (comms
[nr
].flags
& ARGS_PLUS2
)
1037 if (i
!= n
&& i
!= n
+ 2)
1039 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1044 else if (comms
[nr
].flags
& ARGS_PLUS3
)
1046 if (i
!= n
&& i
!= n
+ 3)
1048 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1055 Msg(0, orformat
[0], rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1062 StuffFin(buf
, len
, data
)
1070 LayProcess(&buf
, &len
);
1080 char **args
= act
->args
;
1081 int *argl
= act
->argl
;
1083 int argc
, i
, n
, msgok
;
1086 struct display
*odisplay
= display
;
1087 struct acluser
*user
;
1089 user
= display
? D_user
: users
;
1090 if (nr
== RC_ILLEGAL
)
1092 debug1("key '%c': No action\n", key
);
1095 n
= comms
[nr
].flags
;
1096 if ((n
& NEED_DISPLAY
) && display
== 0)
1098 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1101 if ((n
& NEED_FORE
) && fore
== 0)
1103 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1106 if ((n
& NEED_LAYER
) && flayer
== 0)
1108 Msg(0, "%s: %s: display or window required", rc_name
, comms
[nr
].name
);
1111 if ((argc
= CheckArgNum(nr
, args
)) < 0)
1116 if (AclCheckPermCmd(D_user
, ACL_EXEC
, &comms
[nr
]))
1118 Msg(0, "%s: %s: permission denied (user %s)",
1119 rc_name
, comms
[nr
].name
, (EffectiveAclUser
? EffectiveAclUser
: D_user
)->u_name
);
1123 #endif /* MULTIUSER */
1125 msgok
= display
&& !*rc_name
;
1131 else if (args
[0][0] == '-' && !args
[0][1])
1133 SetForeWindow((struct win
*)0);
1136 else if (args
[0][0] == '.' && !args
[0][1])
1139 Msg(0, "select . needs a window");
1142 SetForeWindow(fore
);
1146 else if (ParseWinNum(act
, &n
) == 0)
1150 case RC_DEFAUTONUKE
:
1151 if (ParseOnOff(act
, &defautonuke
) == 0 && msgok
)
1152 Msg(0, "Default autonuke turned %s", defautonuke
? "on" : "off");
1153 if (display
&& *rc_name
)
1154 D_auto_nuke
= defautonuke
;
1157 if (ParseOnOff(act
, &D_auto_nuke
) == 0 && msgok
)
1158 Msg(0, "Autonuke turned %s", D_auto_nuke
? "on" : "off");
1161 case RC_DEFOBUFLIMIT
:
1162 if (ParseNum(act
, &defobuflimit
) == 0 && msgok
)
1163 Msg(0, "Default limit set to %d", defobuflimit
);
1164 if (display
&& *rc_name
)
1166 D_obufmax
= defobuflimit
;
1167 D_obuflenmax
= D_obuflen
- D_obufmax
;
1172 Msg(0, "Limit is %d, current buffer size is %d", D_obufmax
, D_obuflen
);
1173 else if (ParseNum(act
, &D_obufmax
) == 0 && msgok
)
1174 Msg(0, "Limit set to %d", D_obufmax
);
1175 D_obuflenmax
= D_obuflen
- D_obufmax
;
1177 case RC_DUMPTERMCAP
:
1178 WriteFile(user
, (char *)0, DUMP_TERMCAP
);
1182 int mode
= DUMP_HARDCOPY
;
1184 if (argc
> 1 && !strcmp(*args
, "-h"))
1186 mode
= DUMP_SCROLLBACK
;
1190 if (*args
&& args
[1])
1192 Msg(0, "%s: hardcopy: too many arguments", rc_name
);
1195 if (fore
== 0 && *args
== 0)
1196 Msg(0, "%s: hardcopy: window required", rc_name
);
1198 WriteFile(user
, *args
, mode
);
1202 (void)ParseOnOff(act
, &nwin_default
.Lflag
);
1205 n
= fore
->w_log
? 1 : 0;
1206 ParseSwitch(act
, &n
);
1216 SwitchWindow(NextWindow());
1220 SwitchWindow(PreviousWindow());
1229 Input(fore
->w_pwin
? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1231 Input("Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1239 FreePseudowin(fore
);
1240 Msg(0, "Filter removed.");
1244 name
= SaveStr(fore
->w_title
);
1246 Msg(0, "Window %d (%s) killed.", n
, name
);
1254 Input("Really quit and kill all your windows [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_QUIT
);
1261 if (*args
&& !strcmp(*args
, "-h"))
1273 Input(buf
, 1, INP_RAW
, pow_detach_fn
, NULL
, 0);
1276 Detach(D_POWER
); /* detach and kill Attacher's parent */
1285 Msg(0, "debugging info is written to %s/", DEBUGDIR
);
1287 Msg(0, "debugging is currently off. Use 'debug on' to enable.");
1292 debug("debug: closing debug file.\n");
1297 if (strcmp("off", *args
))
1301 kill(D_userpid
, SIG_NODEBUG
); /* a one shot item, but hey... */
1302 # endif /* SIG_NODEBUG */
1304 if (*args
== 0 || strcmp("off", *args
))
1305 Msg(0, "Sorry, screen was compiled without -DDEBUG option.");
1310 if (*args
&& !strcmp(*args
, "sendcmd"))
1314 free(zmodem_sendcmd
);
1315 zmodem_sendcmd
= SaveStr(args
[1]);
1318 Msg(0, "zmodem sendcmd: %s", zmodem_sendcmd
);
1321 if (*args
&& !strcmp(*args
, "recvcmd"))
1325 free(zmodem_recvcmd
);
1326 zmodem_recvcmd
= SaveStr(args
[1]);
1329 Msg(0, "zmodem recvcmd: %s", zmodem_recvcmd
);
1334 for (i
= 0; i
< 4; i
++)
1335 if (!strcmp(zmodes
[i
], *args
))
1337 if (i
== 4 && !strcmp(*args
, "on"))
1341 Msg(0, "usage: zmodem off|auto|catch|pass");
1347 Msg(0, "zmodem mode is %s", zmodes
[zmodem_mode
]);
1354 ZombieKey_destroy
= 0;
1357 if (*argl
== 0 || *argl
> 2)
1359 Msg(0, "%s:zombie: one or two characters expected.", rc_name
);
1364 if (!strcmp(args
[1], "onerror"))
1366 ZombieKey_onerror
= 1;
1368 Msg(0, "usage: zombie [keys [onerror]]");
1372 ZombieKey_onerror
= 0;
1373 ZombieKey_destroy
= args
[0][0];
1374 ZombieKey_resurrect
= *argl
== 2 ? args
[0][1] : 0;
1384 struct display
*olddisplay
= display
;
1385 display
= 0; /* no display will cause a broadcast */
1386 Msg(0, "%s: %s", s
, *args
);
1387 display
= olddisplay
;
1391 /* where this AT command comes from: */
1393 s
= SaveStr(D_user
->u_name
);
1394 /* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
1395 EffectiveAclUser
= D_user
;
1397 s
= SaveStr(D_usertty
);
1399 n
= strlen(args
[0]);
1402 * the windows/displays loops are quite dangerous here, take extra
1403 * care not to trigger landmines. Things may appear/disappear while
1404 * we are walking along.
1408 case '*': /* user */
1416 for (u
= users
; u
; u
= u
->u_next
)
1418 debug3("strncmp('%s', '%s', %d)\n", *args
, u
->u_name
, n
);
1419 if (!strncmp(*args
, u
->u_name
, n
))
1422 debug1("at all displays of user %s\n", u
->u_name
);
1423 for (display
= displays
; display
; display
= nd
)
1425 nd
= display
->d_next
;
1428 flayer
= D_forecv
->c_layer
;
1432 debug1("AT display %s\n", D_usertty
);
1433 DoCommand(args
+ 1, argl
+ 1);
1435 Msg(0, "command from %s: %s %s",
1436 s
, args
[1], args
[2] ? args
[2] : "");
1443 case '%': /* display */
1447 debug1("at display matching '%s'\n", args
[0]);
1448 for (display
= displays
; display
; display
= nd
)
1450 nd
= display
->d_next
;
1454 flayer
= D_forecv
->c_layer
;
1455 if (strncmp(args
[0], D_usertty
, n
) &&
1456 (strncmp("/dev/", D_usertty
, 5) ||
1457 strncmp(args
[0], D_usertty
+ 5, n
)) &&
1458 (strncmp("/dev/tty", D_usertty
, 8) ||
1459 strncmp(args
[0], D_usertty
+ 8, n
)))
1461 debug1("AT display %s\n", D_usertty
);
1462 DoCommand(args
+ 1, argl
+ 1);
1464 Msg(0, "command from %s: %s %s",
1465 s
, args
[1], args
[2] ? args
[2] : "");
1472 case '#': /* window */
1483 if (!*args
[0] || (i
= WindowByNumber(args
[0])) < 0)
1485 args
[0][n
] = ch
; /* must restore string in case of bind */
1486 /* try looping over titles */
1487 for (fore
= windows
; fore
; fore
= nw
)
1490 if (strncmp(args
[0], fore
->w_title
, n
))
1492 debug2("AT window %d(%s)\n", fore
->w_number
, fore
->w_title
);
1494 * consider this a bug or a feature:
1495 * while looping through windows, we have fore AND
1496 * display context. This will confuse users who try to
1497 * set up loops inside of loops, but often allows to do
1498 * what you mean, even when you adress your context wrong.
1501 /* XXX: other displays? */
1502 if (fore
->w_layer
.l_cvlist
)
1503 display
= fore
->w_layer
.l_cvlist
->c_display
;
1504 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1505 DoCommand(args
+ 1, argl
+ 1); /* may destroy our display */
1506 if (fore
&& fore
->w_layer
.l_cvlist
)
1508 display
= fore
->w_layer
.l_cvlist
->c_display
;
1509 Msg(0, "command from %s: %s %s",
1510 s
, args
[1], args
[2] ? args
[2] : "");
1516 Msg(0, "%s: at '%s': no such window.\n", rc_name
, args
[0]);
1519 else if (i
< MAXWIN
&& (fore
= wtab
[i
]))
1521 args
[0][n
] = ch
; /* must restore string in case of bind */
1522 debug2("AT window %d (%s)\n", fore
->w_number
, fore
->w_title
);
1523 if (fore
->w_layer
.l_cvlist
)
1524 display
= fore
->w_layer
.l_cvlist
->c_display
;
1525 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1526 DoCommand(args
+ 1, argl
+ 1);
1527 if (fore
&& fore
->w_layer
.l_cvlist
)
1529 display
= fore
->w_layer
.l_cvlist
->c_display
;
1530 Msg(0, "command from %s: %s %s",
1531 s
, args
[1], args
[2] ? args
[2] : "");
1537 Msg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name
);
1543 EffectiveAclUser
= NULL
;
1550 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1551 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1553 i
= FindEncoding(args
[1]);
1556 Msg(0, "%s: readreg: unknown encoding", rc_name
);
1563 * Without arguments we prompt for a destination register.
1564 * It will receive the copybuffer contents.
1565 * This is not done by RC_PASTE, as we prompt for source
1568 if ((s
= *args
) == NULL
)
1570 Input("Copy to register:", 1, INP_RAW
, copy_reg_fn
, NULL
, 0);
1575 Msg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name
);
1580 * With two arguments we *really* read register contents from file
1586 Msg(0, "%s: readreg: too many arguments", rc_name
);
1589 if ((s
= ReadFile(args
[1], &n
)))
1591 struct plop
*pp
= plop_tab
+ (int)(unsigned char)ch
;
1604 * with one argument we copy the copybuffer into a specified register
1605 * This could be done with RC_PASTE too, but is here to be consistent
1606 * with the zero argument call.
1608 copy_reg_fn(&ch
, 0, NULL
);
1613 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1614 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1616 i
= FindEncoding(args
[1]);
1619 Msg(0, "%s: register: unknown encoding", rc_name
);
1628 Msg(0, "%s: register: illegal number of arguments.", rc_name
);
1633 Msg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name
);
1640 if (user
->u_plop
.buf
!= NULL
)
1641 UserFreeCopyBuffer(user
);
1642 if (args
[1] && args
[1][0])
1644 user
->u_plop
.buf
= SaveStrn(args
[1], argl
[1]);
1645 user
->u_plop
.len
= argl
[1];
1647 user
->u_plop
.enc
= i
;
1654 struct plop
*plp
= plop_tab
+ (int)(unsigned char)ch
;
1658 plp
->buf
= SaveStrn(args
[1], argl
[1]);
1666 if ((s
= *args
) == NULL
)
1668 Input("Process register:", 1, INP_RAW
, process_fn
, NULL
, 0);
1673 Msg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name
);
1677 process_fn(&ch
, 0, NULL
);
1683 Input("Stuff:", 100, INP_COOKED
, StuffFin
, NULL
, 0);
1689 if (strcmp(s
, "-k"))
1691 Msg(0, "%s: stuff: invalid option %s", rc_name
, s
);
1695 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
1696 if (strcmp(term
[i
].tcname
, s
) == 0)
1700 Msg(0, "%s: stuff: unknown key '%s'", rc_name
, s
);
1704 if (StuffKey(i
- T_CAPS
) == 0)
1707 s
= display
? D_tcs
[i
].str
: 0;
1722 Msg(0, "screen %s", version
);
1727 timestring
= SaveStr(*args
);
1730 Msg(0, "%s", MakeWinMsg(timestring
, fore
, '%'));
1740 struct action
*ktabp
= ktab
;
1741 if (argc
== 2 && !strcmp(*args
, "-c"))
1743 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
1745 Msg(0, "Unknown command class '%s'", args
[1]);
1749 if (D_ESCseen
!= ktab
|| ktabp
!= ktab
)
1759 SwitchWindow(display
&& D_other
? D_other
->w_number
: NextWindow());
1762 if (user
->u_Esc
== -1)
1781 case RC_DEFBREAKTYPE
:
1784 static char *types
[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL
};
1785 extern int breaktype
;
1789 if (ParseNum(act
, &n
))
1790 for (n
= 0; n
< (int)(sizeof(types
)/sizeof(*types
)); n
++)
1792 for (i
= 0; i
< 4; i
++)
1795 if (ch
>= 'a' && ch
<= 'z')
1797 if (ch
!= types
[n
][i
] && (ch
+ ('a' - 'A')) != types
[n
][i
])
1803 if (n
< 0 || n
>= (int)(sizeof(types
)/sizeof(*types
)))
1804 Msg(0, "%s invalid, chose one of %s, %s or %s", *args
, types
[0], types
[1], types
[2]);
1808 Msg(0, "breaktype set to (%d) %s", n
, types
[n
]);
1812 Msg(0, "breaktype is (%d) %s", breaktype
, types
[breaktype
]);
1818 if (*args
&& ParseNum(act
, &n
))
1820 SendBreak(fore
, n
, nr
== RC_POW_BREAK
);
1834 if (*args
&& !strcmp(*args
, "-w"))
1836 else if (*args
&& !strcmp(*args
, "-d"))
1840 if (what
== 0 && flayer
&& !display
)
1846 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1849 w
= flayer
->l_width
;
1850 h
= flayer
->l_height
;
1856 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1862 if (*args
&& args
[0][0] == '-')
1864 Msg(0, "%s: %s: unknown option %s", rc_name
, comms
[nr
].name
, *args
);
1867 if (nr
== RC_HEIGHT
)
1875 else if (h
== H1height
)
1877 else if (h
> (H0height
+ H1height
) / 2)
1895 else if (w
== Z1width
)
1897 else if (w
> (Z0width
+ Z1width
) / 2)
1909 if (*args
&& args
[1] && args
[2])
1911 Msg(0, "%s: %s: too many arguments", rc_name
, comms
[nr
].name
);
1916 Msg(0, "Illegal width");
1921 Msg(0, "Illegal height");
1926 if (flayer
->l_width
== w
&& flayer
->l_height
== h
)
1928 ResizeLayer(flayer
, w
, h
, (struct display
*)0);
1931 if (D_width
== w
&& D_height
== h
)
1935 ChangeScreenSize(w
, h
, 1);
1939 if (ResizeDisplay(w
, h
) == 0)
1941 Activate(D_fore
? D_fore
->w_norefresh
: 0);
1943 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
1947 Msg(0, "Your termcap does not specify how to change the terminal's width to %d.", w
);
1948 else if (w
== D_width
)
1949 Msg(0, "Your termcap does not specify how to change the terminal's height to %d.", h
);
1951 Msg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w
, h
);
1959 ChangeAKA(fore
, *args
, strlen(*args
));
1962 Input(":", 100, INP_EVERY
, Colonfin
, NULL
, 0);
1963 if (*args
&& **args
)
1971 if (D_status_lastmsg
)
1972 Msg(0, "%s", D_status_lastmsg
);
1975 DoScreen("key", args
);
1978 if (ParseSwitch(act
, &fore
->w_wrap
) == 0 && msgok
)
1979 Msg(0, "%cwrap", fore
->w_wrap
? '+' : '-');
1984 if (args
[0][0] == 'a')
1986 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) ? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
1990 if (ParseOnOff(act
, &n
))
1992 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | n
;
1997 if (fore
->w_flow
& FLOW_AUTOFLAG
)
1998 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | FLOW_NOW
;
1999 else if (fore
->w_flow
& FLOW_NOW
)
2000 fore
->w_flow
&= ~FLOW_NOW
;
2002 fore
->w_flow
= fore
->w_flow
? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
2004 SetFlow(fore
->w_flow
& FLOW_NOW
);
2006 Msg(0, "%cflow%s", (fore
->w_flow
& FLOW_NOW
) ? '+' : '-',
2007 (fore
->w_flow
& FLOW_AUTOFLAG
) ? "(auto)" : "");
2010 case RC_DEFWRITELOCK
:
2011 if (args
[0][0] == 'a')
2012 nwin_default
.wlock
= WLOCK_AUTO
;
2015 if (ParseOnOff(act
, &n
))
2017 nwin_default
.wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2023 if (args
[0][0] == 'a')
2025 fore
->w_wlock
= WLOCK_AUTO
;
2029 if (ParseOnOff(act
, &n
))
2031 fore
->w_wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2034 * user may have permission to change the writelock setting,
2035 * but he may never aquire the lock himself without write permission
2037 if (!AclCheckPermWin(D_user
, ACL_WRITE
, fore
))
2038 fore
->w_wlockuser
= D_user
;
2040 Msg(0, "writelock %s", (fore
->w_wlock
== WLOCK_AUTO
) ? "auto" :
2041 ((fore
->w_wlock
== WLOCK_OFF
) ? "off" : "on"));
2045 ResetAnsiState(fore
);
2046 WriteString(fore
, "\033[H\033[J", 6);
2049 ResetAnsiState(fore
);
2051 if (fore
->w_zdisplay
)
2052 zmodem_abort(fore
, fore
->w_zdisplay
);
2054 WriteString(fore
, "\033c", 2);
2057 n
= fore
->w_monitor
!= MON_OFF
;
2060 n
= n
&& (ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
));
2062 if (ParseSwitch(act
, &n
))
2067 if (display
) /* we tell only this user */
2068 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2070 for (i
= 0; i
< maxusercount
; i
++)
2071 ACLBYTE(fore
->w_mon_notify
, i
) |= ACLBIT(i
);
2073 if (fore
->w_monitor
== MON_OFF
)
2074 fore
->w_monitor
= MON_ON
;
2075 Msg(0, "Window %d (%s) is now being monitored for all activity.", fore
->w_number
, fore
->w_title
);
2080 if (display
) /* we remove only this user */
2081 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
)
2082 &= ~ACLBIT(D_user
->u_id
);
2084 for (i
= 0; i
< maxusercount
; i
++)
2085 ACLBYTE(fore
->w_mon_notify
, i
) &= ~ACLBIT(i
);
2086 for (i
= maxusercount
- 1; i
>= 0; i
--)
2087 if (ACLBYTE(fore
->w_mon_notify
, i
))
2091 fore
->w_monitor
= MON_OFF
;
2092 Msg(0, "Window %d (%s) is no longer being monitored for activity.", fore
->w_number
, fore
->w_title
);
2102 display_wlist(0, WLIST_NUM
, (struct win
*)0);
2103 else if (!strcmp(*args
, "string"))
2109 wliststr
= SaveStr(args
[1]);
2112 Msg(0, "windowlist string is '%s'", wliststr
);
2114 else if (!strcmp(*args
, "title"))
2120 wlisttit
= SaveStr(args
[1]);
2123 Msg(0, "windowlist title is '%s'", wlisttit
);
2129 for (i
= 0; i
< argc
; i
++)
2132 else if (!strcmp(args
[i
], "-m"))
2134 else if (!strcmp(args
[i
], "-b"))
2136 else if (!strcmp(args
[i
], "-g"))
2137 flag
|= WLIST_NESTED
;
2140 Msg(0, "usage: windowlist [-b] [-g] [-m] [string [string] | title [title]]");
2144 display_wlist(blank
, flag
, (struct win
*)0);
2148 if (argc
== 2 && !strcmp(*args
, "-c"))
2150 struct action
*ktabp
;
2151 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
2153 Msg(0, "Unknown command class '%s'", args
[1]);
2156 display_help(args
[1], ktabp
);
2159 display_help((char *)0, ktab
);
2162 display_copyright();
2166 if (flayer
->l_layfn
!= &WinLf
)
2168 Msg(0, "Must be on a window layer");
2175 static char *pasteargs
[] = {".", 0};
2176 static int pasteargl
[] = {1};
2178 if (flayer
->l_layfn
!= &WinLf
)
2180 Msg(0, "Must be on a window layer");
2183 if (GetHistory() == 0)
2185 if (user
->u_plop
.buf
== NULL
)
2193 char *ss
, *dbuf
, dch
;
2200 * without args we prompt for one(!) register to be pasted in the window
2202 if ((s
= *args
) == NULL
)
2204 Input("Paste from register:", 1, INP_RAW
, ins_reg_fn
, NULL
, 0);
2207 if (args
[1] == 0 && !fore
) /* no window? */
2210 * with two arguments we paste into a destination register
2211 * (no window needed here).
2213 if (args
[1] && argl
[1] != 1)
2215 Msg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
2221 enc
= fore
->w_encoding
;
2225 * measure length of needed buffer
2227 for (ss
= s
= *args
; (ch
= *ss
); ss
++)
2233 enc
= user
->u_plop
.enc
;
2234 if (enc
!= user
->u_plop
.enc
)
2235 l
+= RecodeBuf((unsigned char *)user
->u_plop
.buf
, user
->u_plop
.len
, user
->u_plop
.enc
, enc
, (unsigned char *)0);
2238 l
+= user
->u_plop
.len
;
2244 enc
= plop_tab
[(int)(unsigned char)ch
].enc
;
2245 if (enc
!= plop_tab
[(int)(unsigned char)ch
].enc
)
2246 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);
2249 l
+= plop_tab
[(int)(unsigned char)ch
].len
;
2254 Msg(0, "empty buffer");
2259 * if there is only one source and the destination is a window, then
2260 * pass a pointer rather than duplicating the buffer.
2262 if (s
[1] == 0 && args
[1] == 0)
2264 if (enc
== (*s
== '.' ? user
->u_plop
.enc
: plop_tab
[(int)(unsigned char)*s
].enc
))
2267 MakePaster(&fore
->w_paster
, *s
== '.' ? user
->u_plop
.buf
: plop_tab
[(int)(unsigned char)*s
].buf
, l
, 0);
2271 * if no shortcut, we construct a buffer
2273 if ((dbuf
= (char *)malloc(l
)) == 0)
2280 * concatenate all sources into our own buffer, copy buffer is
2281 * special and is skipped if no display exists.
2283 for (ss
= s
; (ch
= *ss
); ss
++)
2285 struct plop
*pp
= (ch
== '.' ? &user
->u_plop
: &plop_tab
[(int)(unsigned char)ch
]);
2289 l
+= RecodeBuf((unsigned char *)pp
->buf
, pp
->len
, pp
->enc
, enc
, (unsigned char *)dbuf
+ l
);
2293 bcopy(pp
->buf
, dbuf
+ l
, pp
->len
);
2297 * when called with one argument we paste our buffer into the window
2301 MakePaster(&fore
->w_paster
, dbuf
, l
, 1);
2306 * we have two arguments, the second is already in dch.
2307 * use this as destination rather than the window.
2312 if (user
->u_plop
.buf
!= NULL
)
2313 UserFreeCopyBuffer(user
);
2314 user
->u_plop
.buf
= dbuf
;
2315 user
->u_plop
.len
= l
;
2317 user
->u_plop
.enc
= enc
;
2322 struct plop
*pp
= plop_tab
+ (int)(unsigned char)dch
;
2335 if (!user
->u_plop
.buf
)
2337 Msg(0, "empty buffer");
2342 struct plop oldplop
;
2344 oldplop
= user
->u_plop
;
2345 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2350 enc
= FindEncoding(args
[1]);
2353 Msg(0, "%s: writebuf: unknown encoding", rc_name
);
2356 if (enc
!= oldplop
.enc
)
2358 l
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)0);
2359 newbuf
= malloc(l
+ 1);
2365 user
->u_plop
.len
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)newbuf
);
2366 user
->u_plop
.buf
= newbuf
;
2367 user
->u_plop
.enc
= enc
;
2372 if (args
[0] && args
[1])
2373 Msg(0, "%s: writebuf: too many arguments", rc_name
);
2375 WriteFile(user
, args
[0], DUMP_EXCHANGE
);
2377 if (user
->u_plop
.buf
!= oldplop
.buf
)
2378 free(user
->u_plop
.buf
);
2379 user
->u_plop
= oldplop
;
2385 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
2386 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2388 i
= FindEncoding(args
[1]);
2391 Msg(0, "%s: readbuf: unknown encoding", rc_name
);
2397 if (args
[0] && args
[1])
2399 Msg(0, "%s: readbuf: too many arguments", rc_name
);
2402 if ((s
= ReadFile(args
[0] ? args
[0] : BufferFile
, &n
)))
2404 if (user
->u_plop
.buf
)
2405 UserFreeCopyBuffer(user
);
2406 user
->u_plop
.len
= n
;
2407 user
->u_plop
.buf
= s
;
2409 user
->u_plop
.enc
= i
;
2417 (void)ParseSwitch(act
, &search_ic
);
2419 Msg(0, "Will %signore case in searches", search_ic
? "" : "not ");
2421 #endif /* COPY_PASTE */
2424 SetEscape(user
, -1, -1);
2425 else if (*argl
== 2)
2426 SetEscape(user
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2429 Msg(0, "%s: two characters required after escape.", rc_name
);
2432 /* Change defescape if master user. This is because we only
2435 if (display
&& user
!= users
)
2440 SetEscape(NULL
, -1, -1);
2441 else if (*argl
== 2)
2442 SetEscape(NULL
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2445 Msg(0, "%s: two characters required after defescape.", rc_name
);
2453 s
= *args
? *args
: home
;
2455 Msg(errno
, "%s", s
);
2459 if (ParseSaveStr(act
, &ShellProg
) == 0)
2460 ShellArgs
[0] = ShellProg
;
2462 case RC_HARDCOPYDIR
:
2464 (void)ParseSaveStr(act
, &hardcopydir
);
2466 Msg(0, "hardcopydir is %s\n", hardcopydir
&& *hardcopydir
? hardcopydir
: "<cwd>");
2471 if (args
[1] && !(strcmp(*args
, "flush")))
2473 log_flush
= atoi(args
[1]);
2475 Msg(0, "log flush timeout set to %ds\n", log_flush
);
2478 if (ParseSaveStr(act
, &screenlogfile
) || !msgok
)
2481 Msg(0, "logfile is '%s'", screenlogfile
);
2484 if (!*args
|| !strcmp(*args
, "on") || !strcmp(*args
, "off"))
2486 if (ParseSwitch(act
, &logtstamp_on
) == 0 && msgok
)
2487 Msg(0, "timestamps turned %s", logtstamp_on
? "on" : "off");
2489 else if (!strcmp(*args
, "string"))
2493 if (logtstamp_string
)
2494 free(logtstamp_string
);
2495 logtstamp_string
= SaveStr(args
[1]);
2498 Msg(0, "logfile timestamp is '%s'", logtstamp_string
);
2500 else if (!strcmp(*args
, "after"))
2504 logtstamp_after
= atoi(args
[1]);
2508 Msg(0, "timestamp printed after %ds\n", logtstamp_after
);
2511 Msg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
2514 (void)ParseSaveStr(act
, &nwin_default
.aka
);
2517 case RC_TERMCAPINFO
:
2519 if (!rc_name
|| !*rc_name
)
2520 Msg(0, "Sorry, too late now. Place that in your .screenrc file.");
2523 break; /* Already handled */
2526 if (ParseSaveStr(act
, &s
))
2528 if (strlen(s
) >= 20)
2530 Msg(0, "%s: term: argument too long ( < 20)", rc_name
);
2534 strcpy(screenterm
, s
);
2536 debug1("screenterm set to %s\n", screenterm
);
2537 MakeTermcap((display
== 0));
2538 debug("new termcap made\n");
2541 if (!msgok
&& (!rc_name
|| strcmp(rc_name
, "-X")))
2544 * user typed ^A:echo... well, echo isn't FinishRc's job,
2545 * but as he wanted to test us, we show good will
2547 if (argc
> 1 && !strcmp(*args
, "-n"))
2553 if (argc
> 1 && !strcmp(*args
, "-p"))
2559 s
= MakeWinMsg(s
, fore
, '%');
2564 Msg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name
);
2571 AddXChars(buf
, sizeof(buf
), BellString
);
2572 Msg(0, "bell_msg is '%s'", buf
);
2575 (void)ParseSaveStr(act
, &BellString
);
2580 BufferFile
= SaveStr(DEFAULT_BUFFERFILE
);
2581 else if (ParseSaveStr(act
, &BufferFile
))
2584 Msg(0, "Bufferfile is now '%s'", BufferFile
);
2588 (void)ParseSaveStr(act
, &ActivityString
);
2590 #if defined(DETACH) && defined(POW_DETACH)
2591 case RC_POW_DETACH_MSG
:
2595 AddXChars(buf
, sizeof(buf
), PowDetachString
);
2596 Msg(0, "pow_detach_msg is '%s'", buf
);
2599 (void)ParseSaveStr(act
, &PowDetachString
);
2602 #if defined(UTMPOK) && defined(LOGOUTOK)
2604 n
= fore
->w_slot
!= (slot_t
)-1;
2605 if (*args
&& !strcmp(*args
, "always"))
2612 if (*args
&& !strcmp(*args
, "attached"))
2619 if (ParseSwitch(act
, &n
) == 0)
2623 if (!strcmp(*args
, "always"))
2624 nwin_default
.lflag
|= 2;
2625 else if (!strcmp(*args
, "attached"))
2626 nwin_default
.lflag
&= ~2;
2628 (void)ParseOnOff(act
, &nwin_default
.lflag
);
2632 if (args
[0] && args
[1] && args
[1][0] == 'i')
2635 for (display
= displays
; display
; display
= display
->d_next
)
2639 #if defined(TERMIO) || defined(POSIX)
2640 D_NewMode
.tio
.c_cc
[VINTR
] = D_OldMode
.tio
.c_cc
[VINTR
];
2641 D_NewMode
.tio
.c_lflag
|= ISIG
;
2642 #else /* TERMIO || POSIX */
2643 D_NewMode
.m_tchars
.t_intrc
= D_OldMode
.m_tchars
.t_intrc
;
2644 #endif /* TERMIO || POSIX */
2645 SetTTY(D_userfd
, &D_NewMode
);
2648 if (args
[0] && args
[0][0] == 'a')
2649 nwin_default
.flowflag
= FLOW_AUTOFLAG
;
2651 (void)ParseOnOff(act
, &nwin_default
.flowflag
);
2654 (void)ParseOnOff(act
, &nwin_default
.wrap
);
2657 (void)ParseOnOff(act
, &nwin_default
.c1
);
2661 (void)ParseOnOff(act
, &nwin_default
.bce
);
2665 (void)ParseOnOff(act
, &nwin_default
.gr
);
2668 if (ParseOnOff(act
, &n
) == 0)
2669 nwin_default
.monitor
= (n
== 0) ? MON_OFF
: MON_ON
;
2672 if (ParseOnOff(act
, &n
) == 0)
2673 nwin_default
.silence
= (n
== 0) ? SILENCE_OFF
: SILENCE_ON
;
2677 Msg(0, "W%s echo command when creating windows.",
2678 VerboseCreate
? "ill" : "on't");
2679 else if (ParseOnOff(act
, &n
) == 0)
2685 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
2688 if (args
[0] && strcmp(args
[0], "on") && strcmp(args
[0], "off"))
2690 struct display
*olddisplay
= display
;
2691 int old_use
, new_use
= -1;
2694 if (!strncmp(s
, "always", 6))
2696 if (!strcmp(s
, "lastline"))
2697 new_use
= HSTATUS_LASTLINE
;
2698 else if (!strcmp(s
, "ignore"))
2699 new_use
= HSTATUS_IGNORE
;
2700 else if (!strcmp(s
, "message"))
2701 new_use
= HSTATUS_MESSAGE
;
2702 else if (!strcmp(args
[0], "string"))
2707 AddXChars(buf
, sizeof(buf
), hstatusstring
);
2708 Msg(0, "hardstatus string is '%s'", buf
);
2714 Msg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name
);
2719 hardstatusemu
= new_use
| (s
== args
[0] ? 0 : HSTATUS_ALWAYS
);
2720 for (display
= displays
; display
; display
= display
->d_next
)
2723 new_use
= hardstatusemu
& ~HSTATUS_ALWAYS
;
2724 if (D_HS
&& s
== args
[0])
2725 new_use
= HSTATUS_HS
;
2726 ShowHStatus((char *)0);
2727 old_use
= D_has_hstatus
;
2728 D_has_hstatus
= new_use
;
2729 if ((new_use
== HSTATUS_LASTLINE
&& old_use
!= HSTATUS_LASTLINE
) || (new_use
!= HSTATUS_LASTLINE
&& old_use
== HSTATUS_LASTLINE
))
2730 ChangeScreenSize(D_width
, D_height
, 1);
2737 free(hstatusstring
);
2738 hstatusstring
= SaveStr(args
[1]);
2739 for (display
= displays
; display
; display
= display
->d_next
)
2742 display
= olddisplay
;
2745 (void)ParseSwitch(act
, &use_hardstatus
);
2747 Msg(0, "messages displayed on %s", use_hardstatus
? "hardstatus line" : "window");
2750 if (strcmp(args
[0], "always") == 0 || strcmp(args
[0], "splitonly") == 0)
2752 struct display
*olddisplay
= display
;
2754 captionalways
= args
[0][0] == 'a';
2755 for (display
= displays
; display
; display
= display
->d_next
)
2756 ChangeScreenSize(D_width
, D_height
, 1);
2757 display
= olddisplay
;
2759 else if (strcmp(args
[0], "string") == 0)
2764 AddXChars(buf
, sizeof(buf
), captionstring
);
2765 Msg(0, "caption string is '%s'", buf
);
2771 Msg(0, "%s: usage: caption always|splitonly|string <string>", rc_name
);
2777 free(captionstring
);
2778 captionstring
= SaveStr(args
[1]);
2779 RedisplayDisplays(0);
2782 n
= (console_window
!= 0);
2783 if (ParseSwitch(act
, &n
))
2785 if (TtyGrabConsole(fore
->w_ptyfd
, n
, rc_name
))
2788 Msg(0, "%s: releasing console %s", rc_name
, HostName
);
2789 else if (console_window
)
2790 Msg(0, "%s: stealing console %s from window %d (%s)", rc_name
,
2791 HostName
, console_window
->w_number
, console_window
->w_title
);
2793 Msg(0, "%s: grabbing console %s", rc_name
, HostName
);
2794 console_window
= n
? fore
: 0;
2797 if (ParseOnOff(act
, &all_norefresh
))
2799 if (!all_norefresh
&& fore
)
2802 Msg(0, all_norefresh
? "No refresh on window change!\n" :
2803 "Window specific refresh\n");
2806 (void)ParseSwitch(act
, &n
);
2807 fore
->w_norefresh
= n
;
2810 if (ParseSwitch(act
, &visual_bell
) || !msgok
)
2812 if (visual_bell
== 0)
2813 Msg(0, "switched to audible bell.");
2815 Msg(0, "switched to visual bell.");
2818 if (ParseNum1000(act
, &VBellWait
) == 0 && msgok
)
2819 Msg(0, "vbellwait set to %.10g seconds", VBellWait
/1000.);
2822 if (ParseNum1000(act
, &MsgWait
) == 0 && msgok
)
2823 Msg(0, "msgwait set to %.10g seconds", MsgWait
/1000.);
2826 if (ParseNum1000(act
, &MsgMinWait
) == 0 && msgok
)
2827 Msg(0, "msgminwait set to %.10g seconds", MsgMinWait
/1000.);
2829 case RC_SILENCEWAIT
:
2830 if (ParseNum(act
, &SilenceWait
))
2832 if (SilenceWait
< 1)
2834 for (p
= windows
; p
; p
= p
->w_next
)
2835 p
->w_silencewait
= SilenceWait
;
2837 Msg(0, "silencewait set to %d seconds", SilenceWait
);
2841 Msg(0, "This is window %d (%s).\n", fore
->w_number
, fore
->w_title
);
2844 int old
= fore
->w_number
;
2846 if (args
[0][0] == '+')
2848 else if (args
[0][0] == '-')
2852 parse
= ParseNum(act
, &n
);
2861 if (n
< 0 || n
>= maxwin
)
2863 Msg(0, "Given window position is invalid.");
2873 /* exchange the acls for these windows. */
2877 /* exchange the utmp-slots for these windows */
2878 if ((fore
->w_slot
!= (slot_t
) -1) && (fore
->w_slot
!= (slot_t
) 0))
2883 if (p
&& (p
->w_slot
!= (slot_t
) -1) && (p
->w_slot
!= (slot_t
) 0))
2885 /* XXX: first display wins? */
2886 display
= fore
->w_layer
.l_cvlist
? fore
->w_layer
.l_cvlist
->c_display
: 0;
2892 WindowChanged(fore
, 'n');
2893 WindowChanged((struct win
*)0, 'w');
2894 WindowChanged((struct win
*)0, 'W');
2895 WindowChanged((struct win
*)0, 0);
2899 n
= fore
->w_silence
!= 0;
2900 i
= fore
->w_silencewait
;
2901 if (args
[0] && (args
[0][0] == '-' || (args
[0][0] >= '0' && args
[0][0] <= '9')))
2903 if (ParseNum(act
, &i
))
2907 else if (ParseSwitch(act
, &n
))
2912 if (display
) /* we tell only this user */
2913 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2915 for (n
= 0; n
< maxusercount
; n
++)
2916 ACLBYTE(fore
->w_lio_notify
, n
) |= ACLBIT(n
);
2918 fore
->w_silencewait
= i
;
2919 fore
->w_silence
= SILENCE_ON
;
2920 SetTimeout(&fore
->w_silenceev
, fore
->w_silencewait
* 1000);
2921 evenq(&fore
->w_silenceev
);
2925 Msg(0, "The window is now being monitored for %d sec. silence.", fore
->w_silencewait
);
2930 if (display
) /* we remove only this user */
2931 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
)
2932 &= ~ACLBIT(D_user
->u_id
);
2934 for (n
= 0; n
< maxusercount
; n
++)
2935 ACLBYTE(fore
->w_lio_notify
, n
) &= ~ACLBIT(n
);
2936 for (i
= maxusercount
- 1; i
>= 0; i
--)
2937 if (ACLBYTE(fore
->w_lio_notify
, i
))
2942 fore
->w_silence
= SILENCE_OFF
;
2943 evdeq(&fore
->w_silenceev
);
2947 Msg(0, "The window is no longer being monitored for silence.");
2951 case RC_DEFSCROLLBACK
:
2952 (void)ParseNum(act
, &nwin_default
.histheight
);
2955 if (flayer
->l_layfn
== &MarkLf
)
2957 Msg(0, "Cannot resize scrollback buffer in copy/scrollback mode.");
2960 (void)ParseNum(act
, &n
);
2961 ChangeWindowSize(fore
, fore
->w_width
, fore
->w_height
, n
);
2963 Msg(0, "scrollback set to %d", fore
->w_histheight
);
2966 case RC_SESSIONNAME
:
2968 Msg(0, "This session is named '%s'\n", SockName
);
2971 char buf
[MAXPATHLEN
];
2974 if (ParseSaveStr(act
, &s
))
2976 if (!*s
|| strlen(s
) + (SockName
- SockPath
) > MAXPATHLEN
- 13 || index(s
, '/'))
2978 Msg(0, "%s: bad session name '%s'\n", rc_name
, s
);
2982 strncpy(buf
, SockPath
, SockName
- SockPath
);
2983 sprintf(buf
+ (SockName
- SockPath
), "%d.%s", (int)getpid(), s
);
2985 if ((access(buf
, F_OK
) == 0) || (errno
!= ENOENT
))
2987 Msg(0, "%s: inappropriate path: '%s'.", rc_name
, buf
);
2990 if (rename(SockPath
, buf
))
2992 Msg(errno
, "%s: failed to rename(%s, %s)", rc_name
, SockPath
, buf
);
2995 debug2("rename(%s, %s) done\n", SockPath
, buf
);
2996 strcpy(SockPath
, buf
);
2998 WindowChanged((struct win
*)0, 'S');
3002 if (!args
[0] || !args
[1])
3004 debug1("RC_SETENV arguments missing: %s\n", args
[0] ? args
[0] : "");
3005 InputSetenv(args
[0]);
3009 xsetenv(args
[0], args
[1]);
3018 case RC_DEFSLOWPASTE
:
3019 (void)ParseNum(act
, &nwin_default
.slow
);
3023 Msg(0, fore
->w_slowpaste
?
3024 "Slowpaste in window %d is %d milliseconds." :
3025 "Slowpaste in window %d is unset.",
3026 fore
->w_number
, fore
->w_slowpaste
);
3027 else if (ParseNum(act
, &fore
->w_slowpaste
) == 0 && msgok
)
3028 Msg(0, fore
->w_slowpaste
?
3029 "Slowpaste in window %d set to %d milliseconds." :
3030 "Slowpaste in window %d now unset.",
3031 fore
->w_number
, fore
->w_slowpaste
);
3034 if (CompileKeys(*args
, *argl
, mark_key_tab
))
3036 Msg(0, "%s: markkeys: syntax error.", rc_name
);
3039 debug1("markkeys %s\n", *args
);
3043 if (ParseSwitch(act
, &pastefont
) == 0 && msgok
)
3044 Msg(0, "Will %spaste font settings", pastefont
? "" : "not ");
3048 (void)ParseSwitch(act
, &join_with_cr
);
3050 case RC_COMPACTHIST
:
3051 if (ParseSwitch(act
, &compacthist
) == 0 && msgok
)
3052 Msg(0, "%scompacting history lines", compacthist
? "" : "not ");
3057 (void)ParseOnOff(act
, &nethackflag
);
3060 case RC_HARDCOPY_APPEND
:
3061 (void)ParseOnOff(act
, &hardcopy_append
);
3067 AddXChars(buf
, sizeof(buf
), VisualBellString
);
3068 Msg(0, "vbell_msg is '%s'", buf
);
3071 (void)ParseSaveStr(act
, &VisualBellString
);
3072 debug1(" new vbellstr '%s'\n", VisualBellString
);
3075 if (ParseBase(act
, *args
, &n
, 8, "octal"))
3077 if (n
< 0 || n
> 0777)
3079 Msg(0, "%s: mode: Invalid tty mode %o", rc_name
, n
);
3084 Msg(0, "Ttymode set to %03o", TtyMode
);
3087 (void)ParseOnOff(act
, &auto_detach
);
3089 case RC_STARTUP_MESSAGE
:
3090 (void)ParseOnOff(act
, &default_startup
);
3096 n
= (*user
->u_password
) ? 1 : 0;
3097 if (user
->u_password
!= NullStr
) free((char *)user
->u_password
);
3098 user
->u_password
= SaveStr(*args
);
3099 if (!strcmp(user
->u_password
, "none"))
3102 Msg(0, "Password checking disabled");
3103 free(user
->u_password
);
3104 user
->u_password
= NullStr
;
3111 Msg(0, "%s: password: window required", rc_name
);
3114 Input("New screen password:", 100, INP_NOECHO
, pass1
, display
? (char *)D_user
: (char *)users
, 0);
3117 #endif /* PASSWORD */
3120 struct action
*ktabp
= ktab
;
3125 if (argc
> 2 && !strcmp(*args
, "-c"))
3127 ktabp
= FindKtab(args
[1], 1);
3134 else if (argc
> 1 && !strcmp(*args
, "-k"))
3147 for (n
= 0; n
< KMAP_KEYS
; n
++)
3148 if (strcmp(term
[n
+ T_CAPS
].tcname
, *args
) == 0)
3152 Msg(0, "%s: bind: unknown key '%s'", rc_name
, *args
);
3161 Msg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name
);
3165 n
= (unsigned char)args
[0][0];
3169 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3171 Msg(0, "%s: bind: unknown command '%s'", rc_name
, args
[1]);
3174 if (CheckArgNum(i
, args
+ 2) < 0)
3176 ClearAction(&ktabp
[n
]);
3177 SaveAction(ktabp
+ n
, i
, args
+ 2, argl
+ 2);
3180 ClearAction(&ktabp
[n
]);
3186 struct action
*newact
;
3187 int newnr
, fl
= 0, kf
= 0, af
= 0, df
= 0, mf
= 0;
3188 struct display
*odisp
= display
;
3190 struct kmap_ext
*kme
;
3192 for (; *args
&& **args
== '-'; args
++, argl
++)
3194 if (strcmp(*args
, "-t") == 0)
3195 fl
= KMAP_NOTIMEOUT
;
3196 else if (strcmp(*args
, "-k") == 0)
3198 else if (strcmp(*args
, "-a") == 0)
3200 else if (strcmp(*args
, "-d") == 0)
3202 else if (strcmp(*args
, "-m") == 0)
3204 else if (strcmp(*args
, "--") == 0)
3212 Msg(0, "%s: bindkey: invalid option %s", rc_name
, *args
);
3218 Msg(0, "%s: bindkey: -d does not work with -m", rc_name
);
3224 display_bindkey("Edit mode", mmtab
);
3226 display_bindkey("Default", dmtab
);
3228 display_bindkey("User", umtab
);
3235 Msg(0, "%s: bindkey: -a only works with -k", rc_name
);
3240 Msg(0, "%s: bindkey: empty string makes no sense", rc_name
);
3243 for (i
= 0, kme
= kmap_exts
; i
< kmap_extn
; i
++, kme
++)
3250 if (*argl
== (kme
->fl
& ~KMAP_NOTIMEOUT
) && bcmp(kme
->str
, *args
, *argl
) == 0)
3256 Msg(0, "%s: bindkey: keybinding not found", rc_name
);
3260 kmap_exts
= (struct kmap_ext
*)xrealloc((char *)kmap_exts
, kmap_extn
* sizeof(*kmap_exts
));
3261 kme
= kmap_exts
+ i
;
3262 bzero((char *)kme
, 8 * sizeof(*kmap_exts
));
3263 for (; i
< kmap_extn
; i
++, kme
++)
3266 kme
->dm
.nr
= kme
->mm
.nr
= kme
->um
.nr
= RC_ILLEGAL
;
3267 kme
->dm
.args
= kme
->mm
.args
= kme
->um
.args
= noargs
;
3272 if (df
== 0 && kme
->dm
.nr
!= RC_ILLEGAL
)
3274 if (mf
== 0 && kme
->mm
.nr
!= RC_ILLEGAL
)
3276 if ((df
|| mf
) && kme
->um
.nr
!= RC_ILLEGAL
)
3278 i
+= KMAP_KEYS
+ KMAP_AKEYS
;
3279 newact
= df
? &kme
->dm
: mf
? &kme
->mm
: &kme
->um
;
3283 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
3284 if (strcmp(term
[i
].tcname
, *args
) == 0)
3288 Msg(0, "%s: bindkey: unknown key '%s'", rc_name
, *args
);
3291 if (af
&& i
>= T_CURSOR
&& i
< T_OCAPS
)
3292 i
-= T_CURSOR
- KMAP_KEYS
;
3295 newact
= df
? &dmtab
[i
] : mf
? &mmtab
[i
] : &umtab
[i
];
3299 if ((newnr
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3301 Msg(0, "%s: bindkey: unknown command '%s'", rc_name
, args
[1]);
3304 if (CheckArgNum(newnr
, args
+ 2) < 0)
3306 ClearAction(newact
);
3307 SaveAction(newact
, newnr
, args
+ 2, argl
+ 2);
3308 if (kf
== 0 && args
[1])
3312 kme
->str
= SaveStrn(*args
, *argl
);
3313 kme
->fl
= fl
| *argl
;
3317 ClearAction(newact
);
3318 for (display
= displays
; display
; display
= display
->d_next
)
3319 remap(i
, args
[1] ? 1 : 0);
3320 if (kf
== 0 && !args
[1])
3322 if (!used
&& kme
->str
)
3335 if (ParseNum(act
, &n
))
3339 Msg(0, "%s: maptimeout: illegal time %d", rc_name
, n
);
3344 if (*args
== 0 || msgok
)
3345 Msg(0, "maptimeout is %dms", maptimeout
);
3359 UsersAcl(NULL
, argc
, args
);
3362 if (UserDel(args
[0], NULL
))
3365 Msg(0, "%s removed from acl database", args
[0]);
3369 * modify a user to gain or lose rights granted to a group.
3370 * This group is actually a normal user whose rights were defined
3371 * with chacl in the usual way.
3375 if (strcmp(args
[1], "none")) /* link a user to another user */
3377 if (AclLinkUser(args
[0], args
[1]))
3380 Msg(0, "User %s joined acl-group %s", args
[0], args
[1]);
3382 else /* remove all groups from user */
3385 struct aclusergroup
*g
;
3387 if (!(u
= *FindUserPtr(args
[0])))
3389 while ((g
= u
->u_group
))
3391 u
->u_group
= g
->next
;
3396 else /* show all groups of user */
3398 char buf
[256], *p
= buf
;
3401 struct aclusergroup
*g
;
3403 if (!(u
= *FindUserPtr(args
[0])))
3406 Msg(0, "User %s does not exist.", args
[0]);
3413 sprintf(p
, "%s ", g
->u
->u_name
);
3421 Msg(0, "%s's group%s: %s.", args
[0], (ngroups
== 1) ? "" : "s",
3422 (ngroups
== 0) ? "none" : buf
);
3427 while ((s
= *args
++))
3431 if (AclUmask(display
? D_user
: users
, s
, &err
))
3432 Msg(0, "umask: %s\n", err
);
3436 if (ParseOnOff(act
, &n
))
3441 Msg(0, "Multiuser mode %s", multi
? "enabled" : "disabled");
3443 #endif /* MULTIUSER */
3451 i
= D_nonblock
>= 0;
3452 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3454 if (ParseNum1000(act
, &i
))
3457 else if (!ParseSwitch(act
, &i
))
3458 i
= i
== 0 ? -1 : 1000;
3461 if (msgok
&& i
== -1)
3462 Msg(0, "display set to blocking mode");
3463 else if (msgok
&& i
== 0)
3464 Msg(0, "display set to nonblocking mode, no timeout");
3466 Msg(0, "display set to nonblocking mode, %.10gs timeout", i
/1000.);
3468 if (D_nonblock
<= 0)
3469 evdeq(&D_blockedev
);
3471 case RC_DEFNONBLOCK
:
3472 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3474 if (ParseNum1000(act
, &defnonblock
))
3477 else if (!ParseOnOff(act
, &defnonblock
))
3478 defnonblock
= defnonblock
== 0 ? -1 : 1000;
3481 if (display
&& *rc_name
)
3483 D_nonblock
= defnonblock
;
3484 if (D_nonblock
<= 0)
3485 evdeq(&D_blockedev
);
3491 if (fore
->w_gr
== 2)
3494 if (ParseSwitch(act
, &fore
->w_gr
) == 0 && msgok
)
3495 Msg(0, "Will %suse GR", fore
->w_gr
? "" : "not ");
3497 if (fore
->w_gr
== 0 && fore
->w_FontE
)
3502 if (ParseSwitch(act
, &fore
->w_c1
) == 0 && msgok
)
3503 Msg(0, "Will %suse C1", fore
->w_c1
? "" : "not ");
3507 if (ParseSwitch(act
, &fore
->w_bce
) == 0 && msgok
)
3508 Msg(0, "Will %serase with background color", fore
->w_bce
? "" : "not ");
3515 if (*args
&& !strcmp(args
[0], "-d"))
3518 Msg(0, "encodings directory is %s", screenencodings
? screenencodings
: "<unset>");
3521 free(screenencodings
);
3522 screenencodings
= SaveStr(args
[1]);
3526 if (*args
&& !strcmp(args
[0], "-l"))
3529 Msg(0, "encoding: -l: argument required");
3530 else if (LoadFontTranslation(-1, args
[1]))
3531 Msg(0, "encoding: could not load utf8 encoding file");
3533 Msg(0, "encoding: utf8 encoding file loaded");
3537 if (*args
&& (!strcmp(args
[0], "-l") || !strcmp(args
[0], "-d")))
3540 Msg(0, "encoding: screen is not compiled for UTF-8.");
3544 for (i
= 0; i
< 2; i
++)
3548 if (!strcmp(args
[i
], "."))
3550 n
= FindEncoding(args
[i
]);
3553 Msg(0, "encoding: unknown encoding '%s'", args
[i
]);
3558 WinSwitchEncoding(fore
, n
);
3559 ResetCharsets(fore
);
3561 else if (i
&& display
)
3566 case RC_DEFENCODING
:
3567 n
= FindEncoding(*args
);
3570 Msg(0, "defencoding: unknown encoding '%s'", *args
);
3573 nwin_default
.encoding
= n
;
3579 n
= nwin_default
.encoding
== UTF8
;
3580 if (ParseSwitch(act
, &n
) == 0)
3582 nwin_default
.encoding
= n
? UTF8
: 0;
3584 Msg(0, "Will %suse UTF-8 encoding for new windows", n
? "" : "not ");
3588 for (i
= 0; i
< 2; i
++)
3590 if (i
&& args
[i
] == 0)
3593 n
= fore
->w_encoding
!= UTF8
;
3594 else if (strcmp(args
[i
], "off") == 0)
3596 else if (strcmp(args
[i
], "on") == 0)
3600 Msg(0, "utf8: illegal argument (%s)", args
[i
]);
3605 WinSwitchEncoding(fore
, n
? UTF8
: 0);
3607 Msg(0, "Will %suse UTF-8 encoding", n
? "" : "not ");
3610 D_encoding
= n
? UTF8
: 0;
3624 printcmd
= SaveStr(*args
);
3626 if (*args
== 0 || msgok
)
3629 Msg(0, "using '%s' as print command", printcmd
);
3631 Msg(0, "using termcap entries for printing");
3637 Input("Enter digraph: ", 10, INP_EVERY
, digraph_fn
, NULL
, 0);
3638 if (*args
&& **args
)
3651 if (nwin_default
.hstatus
)
3652 AddXChars(buf
, sizeof(buf
), nwin_default
.hstatus
);
3653 Msg(0, "default hstatus is '%s'", buf
);
3656 (void)ParseSaveStr(act
, &nwin_default
.hstatus
);
3657 if (*nwin_default
.hstatus
== 0)
3659 free(nwin_default
.hstatus
);
3660 nwin_default
.hstatus
= 0;
3664 (void)ParseSaveStr(act
, &fore
->w_hstatus
);
3665 if (*fore
->w_hstatus
== 0)
3667 free(fore
->w_hstatus
);
3668 fore
->w_hstatus
= 0;
3670 WindowChanged(fore
, 'h');
3680 if (nwin_default
.charset
)
3681 AddXChars(buf
, sizeof(buf
), nwin_default
.charset
);
3682 Msg(0, "default charset is '%s'", buf
);
3686 if (n
== 0 || n
> 6)
3688 Msg(0, "%s: %s: string has illegal size.", rc_name
, comms
[nr
].name
);
3692 ((args
[0][4] < '0' || args
[0][4] > '3') && args
[0][4] != '.') ||
3693 ((args
[0][5] < '0' || args
[0][5] > '3') && args
[0][5] && args
[0][5] != '.')))
3695 Msg(0, "%s: %s: illegal mapping number.", rc_name
, comms
[nr
].name
);
3698 if (nr
== RC_CHARSET
)
3700 SetCharsets(fore
, *args
);
3703 if (nwin_default
.charset
)
3704 free(nwin_default
.charset
);
3705 nwin_default
.charset
= SaveStr(*args
);
3711 if (*s
>= '0' && *s
<= '9')
3714 for (i
= 0; i
< 8; i
++)
3715 if (*s
== "dubrsBiI"[i
])
3719 if (*s
&& s
[1] && !s
[2])
3721 if (*s
== 'd' && s
[1] == 'd')
3723 else if (*s
== '.' && s
[1] == 'd')
3725 else if (*s
== 'd' && s
[1] == '.')
3727 else if (*s
!= '.' || s
[1] != '.')
3731 if (*s
|| i
< 0 || i
>= 8)
3733 Msg(0, "%s: attrcolor: unknown attribute '%s'.", rc_name
, args
[0]);
3738 n
= ParseAttrColor(args
[1], args
[2], 1);
3741 attr2color
[i
][nr
] = n
;
3743 for (i
= 0; i
< 8; i
++)
3744 if (attr2color
[i
][0] || attr2color
[i
][1] || attr2color
[i
][2] || attr2color
[i
][3])
3749 case RC_SORENDITION
:
3753 i
= ParseAttrColor(*args
, args
[1], 1);
3756 ApplyAttrColor(i
, &mchar_so
);
3757 debug2("--> %x %x\n", mchar_so
.attr
, mchar_so
.color
);
3761 Msg(0, "Standout attributes 0x%02x color 0x%02x", (unsigned char)mchar_so
.attr
, 0x99 ^ (unsigned char)mchar_so
.color
);
3763 Msg(0, "Standout attributes 0x%02x ", (unsigned char)mchar_so
.attr
);
3776 Msg(0, "%s:%s screen login", HostName
, SockPath
);
3777 InputSu(D_fore
, &D_user
, NULL
);
3780 InputSu(D_fore
, &D_user
, args
[0]);
3782 s
= DoSu(&D_user
, args
[0], args
[1], "\377");
3784 s
= DoSu(&D_user
, args
[0], args
[1], args
[2]);
3788 #endif /* MULTIUSER */
3791 if (s
&& !strcmp(s
, "-v"))
3792 AddCanvas(SLICE_HORI
);
3794 AddCanvas(SLICE_VERT
);
3806 D_forecv
->c_xoff
= D_forecv
->c_xs
;
3807 D_forecv
->c_yoff
= D_forecv
->c_ys
;
3808 RethinkViewportOffsets(D_forecv
);
3809 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
3810 flayer
= D_forecv
->c_layer
;
3814 if (!*args
|| !strcmp(*args
, "down"))
3815 D_forecv
= D_forecv
->c_next
? D_forecv
->c_next
: D_cvlist
;
3816 else if (!strcmp(*args
, "up"))
3819 for (cv
= D_cvlist
; cv
->c_next
&& cv
->c_next
!= D_forecv
; cv
= cv
->c_next
)
3823 else if (!strcmp(*args
, "top"))
3824 D_forecv
= D_cvlist
;
3825 else if (!strcmp(*args
, "bottom"))
3828 for (cv
= D_cvlist
; cv
->c_next
; cv
= cv
->c_next
)
3834 Msg(0, "%s: usage: focus [up|down|top|bottom]", rc_name
);
3837 if ((focusminwidth
&& (focusminwidth
< 0 || D_forecv
->c_xe
- D_forecv
->c_xs
+ 1 < focusminwidth
)) ||
3838 (focusminheight
&& (focusminheight
< 0 || D_forecv
->c_ye
- D_forecv
->c_ys
+ 1 < focusminheight
)))
3840 ResizeCanvas(&D_canvas
);
3841 RecreateCanvasChain();
3842 RethinkDisplayViewports();
3843 ResizeLayersToCanvases(); /* redisplays */
3845 fore
= D_fore
= Layer2Window(D_forecv
->c_layer
);
3846 if (D_other
== fore
)
3848 flayer
= D_forecv
->c_layer
;
3850 if (D_xtermosc
[2] || D_xtermosc
[3])
3860 flayer
= D_forecv
->c_layer
;
3861 CV_CALL(D_forecv
, LayRestore();LaySetCursor());
3862 WindowChanged(0, 'F');
3866 if (D_forecv
->c_slorient
== SLICE_UNKN
)
3868 Msg(0, "resize: need more than one region");
3871 for (; *args
; args
++)
3873 if (!strcmp(*args
, "-h"))
3875 else if (!strcmp(*args
, "-v"))
3877 else if (!strcmp(*args
, "-b"))
3878 i
|= RESIZE_FLAG_H
| RESIZE_FLAG_V
;
3879 else if (!strcmp(*args
, "-p"))
3880 i
|= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
3881 else if (!strcmp(*args
, "-l"))
3886 if (*args
&& args
[1])
3888 Msg(0, "%s: usage: resize [-h] [-v] [-l] [num]\n", rc_name
);
3892 ResizeRegions(*args
, i
);
3894 Input(resizeprompts
[i
], 20, INP_EVERY
, ResizeFin
, (char*)0, i
);
3897 (void)ParseSwitch(act
, &separate_sids
);
3900 args
= SaveArgs(args
);
3901 for (i
= 0; args
[i
]; i
++)
3904 Colonfin(args
[i
], strlen(args
[i
]), (char *)0);
3910 (void)ParseSwitch(act
, &use_altscreen
);
3912 Msg(0, "Will %sdo alternate screen switching", use_altscreen
? "" : "not ");
3915 if (ParseNum(act
, &n
))
3918 Msg(0, "illegal maxwin number specified");
3919 else if (n
> maxwin
)
3920 Msg(0, "may only decrease maxwin number");
3925 if (ParseBase(act
, *args
, &n
, 10, "decimal"))
3928 setbacktick(n
, 0, 0, (char **)0);
3934 Msg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name
);
3937 if (ParseBase(act
, args
[1], &lifespan
, 10, "decimal"))
3939 if (ParseBase(act
, args
[2], &tick
, 10, "decimal"))
3941 setbacktick(n
, lifespan
, tick
, SaveArgs(args
+ 3));
3943 WindowChanged(0, '`');
3949 RunBlanker(blankerprg
);
3954 CursorVisibility(-1);
3962 for (pp
= blankerprg
; *pp
; pp
++)
3968 blankerprg
= SaveArgs(args
);
3974 struct display
*olddisplay
= display
;
3975 if (!strcmp(*args
, "off"))
3977 else if (args
[0][0])
3978 idletimo
= atoi(*args
) * 1000;
3981 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3983 Msg(0, "%s: idle: unknown command '%s'", rc_name
, args
[1]);
3986 if (CheckArgNum(i
, args
+ 2) < 0)
3988 ClearAction(&idleaction
);
3989 SaveAction(&idleaction
, i
, args
+ 2, argl
+ 2);
3991 for (display
= displays
; display
; display
= display
->d_next
)
3993 display
= olddisplay
;
3998 Msg(0, "idle timeout %ds, %s", idletimo
/ 1000, comms
[idleaction
.nr
].name
);
4003 case RC_FOCUSMINSIZE
:
4004 for (i
= 0; i
< 2 && args
[i
]; i
++)
4006 if (!strcmp(args
[i
], "max") || !strcmp(args
[i
], "_"))
4018 for (i
= 0; i
< 2; i
++)
4020 n
= i
== 0 ? focusminwidth
: focusminheight
;
4022 strcpy(b
[i
], "max");
4024 sprintf(b
[i
], "%d", n
);
4026 Msg(0, "focus min size is %s %s\n", b
[0], b
[1]);
4035 fore
->w_group
= WindowByName(*args
);
4036 if (fore
->w_group
&& fore
->w_group
->w_type
!= W_TYPE_GROUP
)
4039 WindowChanged((struct win
*)0, 'w');
4040 WindowChanged((struct win
*)0, 'W');
4041 WindowChanged((struct win
*)0, 0);
4046 Msg(0, "window group is %d (%s)\n", fore
->w_group
->w_number
, fore
->w_group
->w_title
);
4048 Msg(0, "window belongs to no group");
4052 if (!strcmp(args
[0], "title"))
4056 Msg(0, "not on a layout");
4061 Msg(0, "current layout is %d (%s)", D_layout
->lay_number
, D_layout
->lay_title
);
4064 free(D_layout
->lay_title
);
4065 D_layout
->lay_title
= SaveStr(args
[1]);
4067 else if (!strcmp(args
[0], "number"))
4073 Msg(0, "This is layout %d (%s).\n", D_layout
->lay_number
, D_layout
->lay_title
);
4076 old
= D_layout
->lay_number
;
4078 if (n
< 0 || n
>= MAXLAY
)
4081 laytab
[n
] = D_layout
;
4082 D_layout
->lay_number
= n
;
4085 lay
->lay_number
= old
;
4088 else if (!strcmp(args
[0], "autosave"))
4092 Msg(0, "not on a layout");
4097 if (!strcmp(args
[1], "on"))
4098 D_layout
->lay_autosave
= 1;
4099 else if (!strcmp(args
[1], "off"))
4100 D_layout
->lay_autosave
= 0;
4103 Msg(0, "invalid argument. Give 'on' or 'off");
4108 Msg(0, "autosave is %s", D_layout
->lay_autosave
? "on" : "off");
4110 else if (!strcmp(args
[0], "new"))
4116 while (*t
>= '0' && *t
<= '9')
4118 if (t
!= args
[1] && (!*t
|| *t
== ':'))
4132 else if (!strcmp(args
[0], "save"))
4136 Msg(0, "usage: layout save <name>");
4139 SaveLayout(args
[1], &D_canvas
);
4141 else if (!strcmp(args
[0], "select"))
4145 Input("Switch to layout: ", 20, INP_COOKED
, SelectLayoutFin
, NULL
, 0);
4148 SelectLayoutFin(args
[1], strlen(args
[1]), (char *)0);
4150 else if (!strcmp(args
[0], "next"))
4152 struct layout
*lay
= D_layout
;
4154 lay
= lay
->lay_next
? lay
->lay_next
: layouts
;
4159 Msg(0, "no layout defined");
4162 if (lay
== D_layout
)
4164 LoadLayout(lay
, &D_canvas
);
4167 else if (!strcmp(args
[0], "prev"))
4169 struct layout
*lay
= D_layout
;
4172 for (lay
= layouts
; lay
->lay_next
&& lay
->lay_next
!= D_layout
; lay
= lay
->lay_next
)
4179 Msg(0, "no layout defined");
4182 if (lay
== D_layout
)
4184 LoadLayout(lay
, &D_canvas
);
4187 else if (!strcmp(args
[0], "attach"))
4192 Msg(0, "no attach layout set");
4193 else if (layout_attach
== &layout_last_marker
)
4194 Msg(0, "will attach to last layout");
4196 Msg(0, "will attach to layout %d (%s)", layout_attach
->lay_number
, layout_attach
->lay_title
);
4199 if (!strcmp(args
[1], ":last"))
4200 layout_attach
= &layout_last_marker
;
4201 else if (!args
[1][0])
4206 lay
= FindLayout(args
[1]);
4209 Msg(0, "unknown layout '%s'", args
[1]);
4212 layout_attach
= lay
;
4215 else if (!strcmp(args
[0], "show"))
4219 else if (!strcmp(args
[0], "remove"))
4221 struct layout
*lay
= display
? D_layout
: layouts
;
4224 lay
= layouts
? FindLayout(args
[1]) : (struct layout
*)0;
4227 Msg(0, "unknown layout '%s'", args
[1]);
4235 Msg(0, "unknown layout subcommand");
4239 if(ParseSwitch(act
, &cjkwidth
) == 0)
4242 Msg(0, "Treat ambiguous width characters as %s width", cjkwidth
? "full" : "half");
4248 /* key == -2: input from braille keybord, msgok always 0 */
4249 DoBrailleAction(act
, key
== -2 ? 0 : msgok
);
4253 if (display
!= odisplay
)
4255 for (display
= displays
; display
; display
= display
->d_next
)
4256 if (display
== odisplay
)
4262 DoCommand(argv
, argl
)
4268 if ((act
.nr
= FindCommnr(*argv
)) == RC_ILLEGAL
)
4270 Msg(0, "%s: unknown command '%s'", rc_name
, *argv
);
4273 act
.args
= argv
+ 1;
4274 act
.argl
= argl
+ 1;
4279 SaveAction(act
, nr
, args
, argl
)
4285 register int argc
= 0;
4299 if ((pp
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4301 if ((lp
= (int *)malloc((unsigned)(argc
) * sizeof(int *))) == 0)
4308 *lp
= argl
? *argl
++ : (int)strlen(*args
);
4309 *pp
++ = SaveStrn(*args
++, *lp
++);
4318 register char **ap
, **pp
;
4319 register int argc
= 0;
4323 if ((pp
= ap
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4326 *pp
++ = SaveStr(*args
++);
4333 * buf is split into argument vector args.
4334 * leading whitespace is removed.
4335 * @!| abbreviations are expanded.
4336 * the end of buffer is recognized by '\0' or an un-escaped '#'.
4337 * " and ' are interpreted.
4342 Parse(buf
, bufl
, args
, argl
)
4346 register char *p
= buf
, **ap
= args
, *pp
;
4347 register int delim
, argc
;
4350 debug2("Parse %d %s\n", bufl
, buf
);
4356 while (*p
&& (*p
== ' ' || *p
== '\t'))
4359 if (argc
== 0 && *p
== '!')
4368 if (*p
== '\0' || *p
== '#' || *p
== '\n')
4371 for (delim
= 0; delim
< argc
; delim
++)
4372 debug1("-- %s\n", args
[delim
]);
4376 if (++argc
>= MAXARGS
)
4378 Msg(0, "%s: too many tokens.", rc_name
);
4383 debug1("- new arg %s\n", p
);
4388 else if (delim
!= '\'' && *p
== '\\' && (p
[1] == '\'' || p
[1] == '"' || p
[1] == '\\' || p
[1] == '$' || p
[1] == '#' || p
[1] == '^' || (p
[1] >= '0' && p
[1] <= '7')))
4391 if (*p
>= '0' && *p
<= '7')
4394 if (p
[1] >= '0' && p
[1] <= '7')
4397 *pp
= (*pp
<< 3) | (*p
- '0');
4398 if (p
[1] >= '0' && p
[1] <= '7')
4401 *pp
= (*pp
<< 3) | (*p
- '0');
4409 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] == '_'))
4412 char *ps
, *pe
, op
, *v
, xbuf
[11];
4416 debug1("- var %s\n", ps
);
4420 if (*ps
== '{' && *p
== '}')
4422 if (*ps
== ':' && *p
== ':')
4424 if (*ps
!= '{' && *ps
!= ':' && (*p
< 'a' || *p
> 'z') && (*p
< 'A' || *p
> 'Z') && (*p
< '0' || *p
> '9') && *p
!= '_')
4429 if (*ps
== '{' || *ps
== ':')
4433 Msg(0, "%s: bad variable name.", rc_name
);
4440 debug1("- var is '%s'\n", ps
);
4442 v
= gettermcapstring(ps
+ 1);
4448 if (!strcmp(ps
, "TERM"))
4449 v
= display
? D_termname
: "unknown";
4450 else if (!strcmp(ps
, "COLUMNS"))
4451 sprintf(xbuf
, "%d", display
? D_width
: -1);
4452 else if (!strcmp(ps
, "LINES"))
4453 sprintf(xbuf
, "%d", display
? D_height
: -1);
4458 vl
= v
? strlen(v
) : 0;
4461 debug1("- sub is '%s'\n", v
);
4464 int right
= buf
+ bufl
- (p
+ strlen(p
) + 1);
4467 bcopy(p
, p
+ right
, strlen(p
) + 1);
4473 Msg(0, "%s: no space left for variable expansion.", rc_name
);
4481 else if (delim
!= '\'' && *p
== '^' && p
[1])
4484 *pp
++ = *p
== '?' ? '\177' : *p
& 0x1f;
4486 else if (delim
== 0 && (*p
== '\'' || *p
== '"'))
4488 else if (delim
== 0 && (*p
== ' ' || *p
== '\t' || *p
== '\n'))
4496 Msg(0, "%s: Missing %c quote.", rc_name
, delim
);
4502 debug2("- arg done, '%s' rest %s\n", ap
[-1], p
);
4503 *lp
++ = pp
- ap
[-1];
4522 if (DefaultEsc
>= 0)
4523 ClearAction(&ktab
[DefaultEsc
]);
4524 if (DefaultMetaEsc
>= 0)
4525 ClearAction(&ktab
[DefaultMetaEsc
]);
4528 DefaultMetaEsc
= me
;
4531 if (DefaultEsc
>= 0)
4533 ClearAction(&ktab
[DefaultEsc
]);
4534 ktab
[DefaultEsc
].nr
= RC_OTHER
;
4536 if (DefaultMetaEsc
>= 0)
4538 ClearAction(&ktab
[DefaultMetaEsc
]);
4539 ktab
[DefaultMetaEsc
].nr
= RC_META
;
4546 ParseSwitch(act
, var
)
4550 if (*act
->args
== 0)
4555 return ParseOnOff(act
, var
);
4559 ParseOnOff(act
, var
)
4563 register int num
= -1;
4564 char **args
= act
->args
;
4568 if (strcmp(args
[0], "on") == 0)
4570 else if (strcmp(args
[0], "off") == 0)
4575 Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name
, comms
[act
->nr
].name
);
4583 ParseSaveStr(act
, var
)
4587 char **args
= act
->args
;
4588 if (*args
== 0 || args
[1])
4590 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4595 *var
= SaveStr(*args
);
4605 char *p
, **args
= act
->args
;
4608 if (p
== 0 || *p
== 0 || args
[1])
4610 Msg(0, "%s: %s: invalid argument. Give one argument.",
4611 rc_name
, comms
[act
->nr
].name
);
4617 if (*p
>= '0' && *p
<= '9')
4618 i
= 10 * i
+ (*p
- '0');
4621 Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4622 rc_name
, comms
[act
->nr
].name
);
4627 debug1("ParseNum got %d\n", i
);
4633 ParseNum1000(act
, var
)
4638 char *p
, **args
= act
->args
;
4642 if (p
== 0 || *p
== 0 || args
[1])
4644 Msg(0, "%s: %s: invalid argument. Give one argument.",
4645 rc_name
, comms
[act
->nr
].name
);
4651 if (*p
>= '0' && *p
<= '9')
4654 i
= 10 * i
+ (*p
- '0');
4655 else if (dig
== 4 && *p
>= '5')
4660 else if (*p
== '.' && !dig
)
4664 Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4665 rc_name
, comms
[act
->nr
].name
);
4676 i
= (int)((unsigned int)~0 >> 1);
4677 debug1("ParseNum1000 got %d\n", i
);
4688 for (p
= windows
; p
; p
= p
->w_next
)
4689 if (!strcmp(p
->w_title
, s
))
4691 for (p
= windows
; p
; p
= p
->w_next
)
4692 if (!strncmp(p
->w_title
, s
, strlen(s
)))
4704 for (i
= 0, s
= str
; *s
; s
++)
4706 if (*s
< '0' || *s
> '9')
4708 i
= i
* 10 + (*s
- '0');
4714 * Get window number from Name or Number string.
4715 * Numbers are tried first, then names, a prefix match suffices.
4716 * Be careful when assigning numeric strings as WindowTitles.
4725 if ((i
= WindowByNumber(str
)) < 0 || i
>= MAXWIN
)
4727 if ((p
= WindowByName(str
)))
4735 ParseWinNum(act
, var
)
4739 char **args
= act
->args
;
4742 if (*args
== 0 || args
[1])
4744 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4748 i
= WindowByNoN(*args
);
4751 Msg(0, "%s: %s: invalid argument. Give window number or name.",
4752 rc_name
, comms
[act
->nr
].name
);
4755 debug1("ParseWinNum got %d\n", i
);
4761 ParseBase(act
, p
, var
, base
, bname
)
4773 Msg(0, "%s: %s: empty argument.", rc_name
, comms
[act
->nr
].name
);
4778 if (c
>= 'a' && c
<= 'z')
4780 if (c
>= 'A' && c
<= 'Z')
4781 c
-= 'A' - ('0' + 10);
4783 if (c
< 0 || c
>= base
)
4785 Msg(0, "%s: %s: argument is not %s.", rc_name
, comms
[act
->nr
].name
, bname
);
4790 debug1("ParseBase got %d\n", i
);
4800 for (base
+= '0'; *s
; ++s
)
4801 if (*s
< '0' || *s
> base
)
4807 IsNumColon(s
, base
, p
, psize
)
4812 if ((q
= rindex(s
, ':')) != 0)
4814 strncpy(p
, q
+ 1, psize
- 1);
4815 p
[psize
- 1] = '\0';
4820 return IsNum(s
, base
);
4829 debug1("SwitchWindow %d\n", n
);
4830 if (n
< 0 || n
>= MAXWIN
)
4835 if ((p
= wtab
[n
]) == 0)
4847 Msg(0, "This IS window %d (%s).", n
, p
->w_title
);
4851 if (AclCheckPermWin(D_user
, ACL_READ
, p
))
4853 Msg(0, "Access to window %d denied.", p
->w_number
);
4858 Activate(fore
->w_norefresh
);
4863 SetCanvasWindow(cv
, wi
)
4867 struct win
*p
= 0, **pp
;
4869 struct canvas
*cvp
, **cvpp
;
4872 display
= cv
->c_display
;
4876 /* remove old layer */
4877 for (cvpp
= &l
->l_cvlist
; (cvp
= *cvpp
); cvpp
= &cvp
->c_lnext
)
4881 *cvpp
= cvp
->c_lnext
;
4883 p
= Layer2Window(l
);
4887 if (p
&& cv
== D_forecv
)
4890 ReleaseAutoWritelock(display
, p
);
4894 SetTimeout(&p
->w_silenceev
, p
->w_silencewait
* 1000);
4895 evenq(&p
->w_silenceev
);
4900 if (l
->l_cvlist
== 0 && (p
== 0 || l
!= p
->w_savelayer
))
4904 /* find right layer to display on canvas */
4905 if (wi
&& wi
->w_type
!= W_TYPE_GROUP
)
4908 if (wi
->w_savelayer
&& (wi
->w_blocked
|| wi
->w_savelayer
->l_cvlist
== 0))
4909 l
= wi
->w_savelayer
;
4915 l
->l_data
= (char *)wi
;
4920 /* add our canvas to the layer's canvaslist */
4921 ASSERT(l
->l_cvlist
!= cv
);
4922 cv
->c_lnext
= l
->l_cvlist
;
4925 cv
->c_xoff
= cv
->c_xs
;
4926 cv
->c_yoff
= cv
->c_ys
;
4927 RethinkViewportOffsets(cv
);
4932 if (wi
&& wi
->w_type
== W_TYPE_GROUP
)
4934 /* auto-start windowlist on groups */
4935 struct display
*d
= display
;
4936 struct layer
*oldflayer
= flayer
;
4938 display_wlist(0, 0, wi
);
4943 if (wi
&& D_other
== wi
)
4944 D_other
= wi
->w_next
; /* Might be 0, but that's OK. */
4948 fore
= D_fore
; /* XXX ? */
4952 ObtainAutoWritelock(display
, wi
);
4955 * Place the window at the head of the most-recently-used list
4959 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
4964 p
->w_next
= windows
;
4974 * SetForeWindow changes the window in the input focus of the display.
4975 * Puts window wi in canvas display->d_forecv.
4987 p
= Layer2Window(D_forecv
->c_layer
);
4988 SetCanvasWindow(D_forecv
, wi
);
4990 WindowChanged(p
, 'u');
4992 WindowChanged(wi
, 'u');
4993 flayer
= D_forecv
->c_layer
;
4994 /* Activate called afterwards, so no RefreshHStatus needed */
4998 /*****************************************************************/
5001 * Activate - make fore window active
5002 * norefresh = -1 forces a refresh, disregard all_norefresh then.
5008 debug1("Activate(%d)\n", norefresh
);
5013 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
5017 if (MayResizeLayer(D_forecv
->c_layer
))
5018 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, display
);
5024 if (fore
->w_monitor
!= MON_OFF
)
5025 fore
->w_monitor
= MON_ON
;
5026 fore
->w_bell
= BELL_ON
;
5027 WindowChanged(fore
, 'f');
5030 if (ResizeDisplay(fore
->w_width
, fore
->w_height
))
5032 debug2("Cannot resize from (%d,%d)", D_width
, D_height
);
5033 debug2(" to (%d,%d) -> resize window\n", fore
->w_width
, fore
->w_height
);
5034 DoResize(D_width
, D_height
);
5038 Redisplay(norefresh
+ all_norefresh
);
5045 register struct win
**pp
;
5046 int n
= fore
? fore
->w_number
: MAXWIN
;
5047 struct win
*group
= fore
? fore
->w_group
: 0;
5049 for (pp
= fore
? wtab
+ n
+ 1 : wtab
; pp
!= wtab
+ n
; pp
++)
5051 if (pp
== wtab
+ MAXWIN
)
5055 if (!fore
|| group
== (*pp
)->w_group
)
5067 register struct win
**pp
;
5068 int n
= fore
? fore
->w_number
: -1;
5069 struct win
*group
= fore
? fore
->w_group
: 0;
5071 for (pp
= wtab
+ n
- 1; pp
!= wtab
+ n
; pp
--)
5074 pp
= wtab
+ MAXWIN
- 1;
5077 if (!fore
|| group
== (*pp
)->w_group
)
5089 char *m
= "No other window.";
5090 if (windows
&& (fore
== 0 || windows
->w_next
))
5094 Msg(0, "No window available");
5097 Msg(0, m
, fore
->w_number
); /* other arg for nethack */
5102 UpdateLayoutCanvas(cv
, wi
)
5106 for (; cv
; cv
= cv
->c_slnext
)
5108 if (cv
->c_layer
&& Layer2Window(cv
->c_layer
) == wi
)
5110 /* A simplistic version of SetCanvasWindow(cv, 0) */
5111 struct layer
*l
= cv
->c_layer
;
5113 if (l
->l_cvlist
== 0 && (wi
== 0 || l
!= wi
->w_savelayer
))
5117 if (l
->l_cvlist
!= cv
)
5119 cv
->c_lnext
= l
->l_cvlist
;
5123 /* Do not end here. Multiple canvases can have the same window */
5127 UpdateLayoutCanvas(cv
->c_slperp
, wi
);
5135 struct win
**pp
, *p
;
5141 * Remove window from linked list.
5143 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5149 wtab
[wi
->w_number
] = 0;
5158 * switch to different window on all canvases
5160 for (display
= displays
; display
; display
= display
->d_next
)
5163 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5165 if (Layer2Window(cv
->c_layer
) != wi
)
5167 /* switch to other window */
5168 SetCanvasWindow(cv
, FindNiceWindow(D_other
, 0));
5174 if (wi
->w_zdisplay
== display
)
5177 D_readev
.condpos
= D_readev
.condneg
= 0;
5184 /* do the same for the layouts */
5185 for (lay
= layouts
; lay
; lay
= lay
->lay_next
)
5186 UpdateLayoutCanvas(&lay
->lay_canvas
, wi
);
5189 WindowChanged((struct win
*)0, 'w');
5190 WindowChanged((struct win
*)0, 'W');
5191 WindowChanged((struct win
*)0, 0);
5200 if ((fore
->w_log
!= 0) == on
)
5202 if (display
&& !*rc_name
)
5203 Msg(0, "You are %s logging.", on
? "already" : "not");
5206 if (fore
->w_log
!= 0)
5208 Msg(0, "Logfile \"%s\" closed.", fore
->w_log
->name
);
5209 logfclose(fore
->w_log
);
5211 WindowChanged(fore
, 'f');
5214 if (DoStartLog(fore
, buf
, sizeof(buf
)))
5216 Msg(errno
, "Error opening logfile \"%s\"", buf
);
5219 if (ftell(fore
->w_log
->fp
) == 0)
5220 Msg(0, "Creating logfile \"%s\".", fore
->w_log
->name
);
5222 Msg(0, "Appending to logfile \"%s\".", fore
->w_log
->name
);
5223 WindowChanged(fore
, 'f');
5227 AddWindows(buf
, len
, flags
, where
)
5233 register char *s
, *ss
;
5234 register struct win
**pp
, *p
;
5239 for (pp
= ((flags
& 4) && where
>= 0) ? wtab
+ where
+ 1: wtab
; pp
< wtab
+ MAXWIN
; pp
++)
5241 if (pp
- wtab
== where
&& ss
== buf
)
5245 if ((flags
& 1) && display
&& p
== D_fore
)
5247 if (D_fore
&& D_fore
->w_group
!= p
->w_group
)
5254 if (s
- buf
+ l
> len
- 24)
5256 if (s
> buf
|| (flags
& 4))
5261 sprintf(s
, "%d", p
->w_number
);
5262 if (p
->w_number
== where
)
5265 if (display
&& p
== D_fore
)
5269 if (display
&& p
== D_other
)
5271 s
= AddWindowFlags(s
, len
, p
);
5282 AddWindowFlags(buf
, len
, p
)
5288 if (p
== 0 || len
< 12)
5294 if (display
&& p
== D_fore
)
5296 if (display
&& p
== D_other
)
5299 if (p
->w_layer
.l_cvlist
&& p
->w_layer
.l_cvlist
->c_lnext
)
5301 if (p
->w_monitor
== MON_DONE
5303 && (ACLBYTE(p
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5307 if (p
->w_bell
== BELL_DONE
)
5310 if (p
->w_slot
!= (slot_t
) 0 && p
->w_slot
!= (slot_t
) -1)
5318 if (p
->w_ptyfd
< 0 && p
->w_type
!= W_TYPE_GROUP
)
5325 AddOtherUsers(buf
, len
, p
)
5330 struct display
*d
, *olddisplay
= display
;
5336 for (display
= displays
; display
; display
= display
->d_next
)
5338 if (olddisplay
&& D_user
== olddisplay
->d_user
)
5340 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5341 if (Layer2Window(cv
->c_layer
) == p
)
5345 for (d
= displays
; d
&& d
!= display
; d
= d
->d_next
)
5346 if (D_user
== d
->d_user
)
5348 if (d
&& d
!= display
)
5350 if (len
> 1 && s
!= buf
)
5355 l
= strlen(D_user
->u_name
);
5358 strcpy(s
, D_user
->u_name
);
5363 display
= olddisplay
;
5376 if (where
== -1 && D_fore
)
5377 where
= D_fore
->w_number
;
5378 ss
= AddWindows(buf
, sizeof(buf
), 0, where
);
5379 s
= buf
+ strlen(buf
);
5380 if (ss
- buf
> D_width
/ 2)
5383 if (s
- ss
< D_width
)
5399 register struct win
*wp
= fore
;
5404 Msg(0, "(%d,%d)/(%d,%d) no window", D_x
+ 1, D_y
+ 1, D_width
, D_height
);
5408 if (buf
< (p
+= GetAnsiStatus(wp
, p
)))
5410 sprintf(p
, "(%d,%d)/(%d,%d)",
5411 wp
->w_x
+ 1, wp
->w_y
+ 1, wp
->w_width
, wp
->w_height
);
5413 sprintf(p
+= strlen(p
), "+%d", wp
->w_histheight
);
5415 sprintf(p
+= strlen(p
), " %c%sflow",
5416 (wp
->w_flow
& FLOW_NOW
) ? '+' : '-',
5417 (wp
->w_flow
& FLOW_AUTOFLAG
) ? "" :
5418 ((wp
->w_flow
& FLOW_AUTO
) ? "(+)" : "(-)"));
5419 if (!wp
->w_wrap
) sprintf(p
+= strlen(p
), " -wrap");
5420 if (wp
->w_insert
) sprintf(p
+= strlen(p
), " ins");
5421 if (wp
->w_origin
) sprintf(p
+= strlen(p
), " org");
5422 if (wp
->w_keypad
) sprintf(p
+= strlen(p
), " app");
5423 if (wp
->w_log
) sprintf(p
+= strlen(p
), " log");
5424 if (wp
->w_monitor
!= MON_OFF
5426 && (ACLBYTE(wp
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5429 sprintf(p
+= strlen(p
), " mon");
5430 if (wp
->w_mouse
) sprintf(p
+= strlen(p
), " mouse");
5432 if (wp
->w_bce
) sprintf(p
+= strlen(p
), " bce");
5434 if (!wp
->w_c1
) sprintf(p
+= strlen(p
), " -c1");
5435 if (wp
->w_norefresh
) sprintf(p
+= strlen(p
), " nored");
5440 if (wp
->w_encoding
&& (display
== 0 || D_encoding
!= wp
->w_encoding
|| EncodingDefFont(wp
->w_encoding
) <= 0))
5443 strcpy(p
, EncodingName(wp
->w_encoding
));
5447 if (wp
->w_encoding
!= UTF8
)
5450 if (D_CC0
|| (D_CS0
&& *D_CS0
))
5454 sprintf(p
, " G%c", wp
->w_Charset
+ '0');
5455 if (wp
->w_FontE
>= ' ')
5460 p
[4] = wp
->w_FontE
^ 0x40;
5467 sprintf(p
++, " G%c%c[", wp
->w_Charset
+ '0', wp
->w_CharsetR
+ '0');
5469 sprintf(p
, " G%c[", wp
->w_Charset
+ '0');
5471 for (i
= 0; i
< 4; i
++)
5473 if (wp
->w_charsets
[i
] == ASCII
)
5475 else if (wp
->w_charsets
[i
] >= ' ')
5476 *p
++ = wp
->w_charsets
[i
];
5480 *p
++ = wp
->w_charsets
[i
] ^ 0x40;
5488 if (wp
->w_type
== W_TYPE_PLAIN
)
5490 /* add info about modem control lines */
5492 TtyGetModemStatus(wp
->w_ptyfd
, p
);
5494 #ifdef BUILTIN_TELNET
5495 else if (wp
->w_type
== W_TYPE_TELNET
)
5498 TelStatus(wp
, p
, sizeof(buf
) - 1 - (p
- buf
));
5501 Msg(0, "%s %d(%s)", buf
, wp
->w_number
, wp
->w_title
);
5511 sprintf(p
, "(%d,%d)", D_width
, D_height
),
5517 strcpy(p
, EncodingName(D_encoding
));
5523 strcpy(p
, " xterm");
5529 strcpy(p
, " color");
5536 strcpy(p
, " iso2022");
5539 else if (D_CS0
&& *D_CS0
)
5541 strcpy(p
, " altchar");
5549 AKAfin(buf
, len
, data
)
5552 char *data
; /* dummy */
5556 ChangeAKA(fore
, buf
, strlen(buf
));
5564 Input("Set window's title to: ", sizeof(fore
->w_akabuf
) - 1, INP_COOKED
, AKAfin
, NULL
, 0);
5570 if ((*(unsigned char *)s
& 0x7f) < 0x20 || *s
== 0x7f)
5574 LayProcess(&ss
, &n
);
5579 Colonfin(buf
, len
, data
)
5582 char *data
; /* dummy */
5587 if (buf
[len
] == '\t')
5590 int l
= 0, r
= RC_LAST
;
5591 int showmessage
= 0;
5594 while (*s
&& s
- buf
< len
)
5598 /* Showing a message when there's no hardstatus or caption cancels the input */
5600 (captionalways
|| D_has_hstatus
== HSTATUS_LASTLINE
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
)))
5606 x
= strncmp(buf
, comms
[m
].name
, len
);
5614 for (l
= m
- 1; l
>= 0 && strncmp(buf
, comms
[l
].name
, len
) == 0; l
--)
5616 for (m
= ++l
; m
<= r
&& strncmp(buf
, comms
[m
].name
, len
) == 0 && s
- mbuf
< sizeof(mbuf
); m
++)
5617 s
+= snprintf(s
, sizeof(mbuf
) - (s
- mbuf
), " %s", comms
[m
].name
);
5621 Msg(0, "Possible commands:%s", mbuf
);
5626 len
= snprintf(mbuf
, sizeof(mbuf
), "%s \t", comms
[l
].name
+ len
);
5627 if (len
> 0 && len
< sizeof(mbuf
))
5628 LayProcess(&s
, &len
);
5633 if (l
> r
&& showmessage
)
5634 Msg(0, "No commands matching '%*s'", len
, buf
);
5638 if (!len
|| buf
[len
])
5641 len
= strlen(buf
) + 1;
5642 if (len
> (int)sizeof(mbuf
))
5646 bcopy(buf
, mbuf
, len
);
5647 RcLine(mbuf
, sizeof mbuf
);
5652 SelectFin(buf
, len
, data
)
5655 char *data
; /* dummy */
5659 if (!len
|| !display
)
5661 if (len
== 1 && *buf
== '-')
5663 SetForeWindow((struct win
*)0);
5667 if ((n
= WindowByNoN(buf
)) < 0)
5673 SelectLayoutFin(buf
, len
, data
)
5676 char *data
; /* dummy */
5680 if (!len
|| !display
)
5682 if (len
== 1 && *buf
== '-')
5684 LoadLayout((struct layout
*)0, (struct canvas
*)0);
5688 lay
= FindLayout(buf
);
5690 Msg(0, "No such layout\n");
5691 else if (lay
== D_layout
)
5692 Msg(0, "This IS layout %d (%s).\n", lay
->lay_number
, lay
->lay_title
);
5695 LoadLayout(lay
, &D_canvas
);
5704 Input("Switch to window: ", 20, INP_COOKED
, SelectFin
, NULL
, 0);
5707 static char setenv_var
[31];
5711 SetenvFin1(buf
, len
, data
)
5714 char *data
; /* dummy */
5716 if (!len
|| !display
)
5722 SetenvFin2(buf
, len
, data
)
5725 char *data
; /* dummy */
5727 if (!len
|| !display
)
5729 debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var
, buf
);
5730 xsetenv(setenv_var
, buf
);
5738 static char setenv_buf
[50 + sizeof(setenv_var
)]; /* need to be static here, cannot be freed */
5742 strncpy(setenv_var
, arg
, sizeof(setenv_var
) - 1);
5743 sprintf(setenv_buf
, "Enter value for %s: ", setenv_var
);
5744 Input(setenv_buf
, 30, INP_COOKED
, SetenvFin2
, NULL
, 0);
5747 Input("Setenv: Enter variable name: ", 30, INP_COOKED
, SetenvFin1
, NULL
, 0);
5751 * the following options are understood by this parser:
5752 * -f, -f0, -f1, -fy, -fa
5753 * -t title, -T terminal-type, -h height-of-scrollback,
5754 * -ln, -l0, -ly, -l1, -l
5761 struct NewWindow nwin
;
5766 while (av
&& *av
&& av
[0][0] == '-')
5768 if (av
[0][1] == '-')
5780 nwin
.flowflag
= FLOW_NOW
* 0;
5785 nwin
.flowflag
= FLOW_NOW
* 1;
5788 nwin
.flowflag
= FLOW_AUTOFLAG
;
5794 case 't': /* no more -k */
5796 nwin
.aka
= &av
[0][2];
5804 nwin
.term
= &av
[0][2];
5812 nwin
.histheight
= atoi(av
[0] + 2);
5814 nwin
.histheight
= atoi(*av
);
5843 nwin
.monitor
= MON_ON
;
5849 Msg(0, "%s: screen: invalid option -%c.", fn
, av
[0][1]);
5855 if (av
&& *av
&& IsNumColon(*av
, 10, buf
, sizeof(buf
)))
5860 if (num
< 0 || num
> MAXWIN
- 1)
5862 Msg(0, "%s: illegal screen number %d.", fn
, num
);
5872 nwin
.aka
= Filename(*av
);
5879 * CompileKeys must be called before Markroutine is first used.
5880 * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
5882 * s is an ascii string in a termcap-like syntax. It looks like
5883 * "j=u:k=d:l=r:h=l: =.:" and so on...
5884 * this example rebinds the cursormovement to the keys u (up), d (down),
5885 * l (left), r (right). placing a mark will now be done with ".".
5888 CompileKeys(s
, sl
, array
)
5891 unsigned char *array
;
5894 unsigned char key
, value
;
5898 for (i
= 0; i
< 256; i
++)
5902 debug1("CompileKeys: '%s'\n", s
);
5905 key
= *(unsigned char *)s
++;
5906 if (*s
!= '=' || sl
< 3)
5913 value
= *(unsigned char *)s
++;
5916 while (*s
== '=' && sl
>= 2);
5925 #endif /* COPY_PASTE */
5928 * Asynchronous input functions
5931 #if defined(DETACH) && defined(POW_DETACH)
5933 pow_detach_fn(buf
, len
, data
)
5936 char *data
; /* dummy */
5938 debug("pow_detach_fn called\n");
5944 if (ktab
[(int)(unsigned char)*buf
].nr
!= RC_POW_DETACH
)
5947 write(D_userfd
, "\007", 1);
5948 Msg(0, "Detach aborted.");
5953 #endif /* POW_DETACH */
5957 copy_reg_fn(buf
, len
, data
)
5960 char *data
; /* dummy */
5962 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
5973 if (D_user
->u_plop
.len
)
5975 if ((pp
->buf
= (char *)malloc(D_user
->u_plop
.len
)) == NULL
)
5980 bcopy(D_user
->u_plop
.buf
, pp
->buf
, D_user
->u_plop
.len
);
5982 pp
->len
= D_user
->u_plop
.len
;
5984 pp
->enc
= D_user
->u_plop
.enc
;
5986 Msg(0, "Copied %d characters into register %c", D_user
->u_plop
.len
, *buf
);
5990 ins_reg_fn(buf
, len
, data
)
5993 char *data
; /* dummy */
5995 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6003 return; /* Input() should not call us w/o fore, but you never know... */
6005 Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
6008 MakePaster(&fore
->w_paster
, pp
->buf
, pp
->len
, 0);
6011 Msg(0, "Empty register.");
6013 #endif /* COPY_PASTE */
6016 process_fn(buf
, len
, data
)
6019 char *data
; /* dummy */
6021 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6030 ProcessInput(pp
->buf
, pp
->len
);
6033 Msg(0, "Empty register.");
6037 confirm_fn(buf
, len
, data
)
6044 if (len
|| (*buf
!= 'y' && *buf
!= 'Y'))
6049 act
.nr
= *(int *)data
;
6058 struct acluser
**up
;
6060 char pw1
[130]; /* FreeBSD crypts to 128 bytes */
6065 su_fin(buf
, len
, data
)
6070 struct inputsu
*i
= (struct inputsu
*)data
;
6075 { p
= i
->name
; l
= sizeof(i
->name
) - 1; }
6077 { strcpy(p
= i
->pw1
, "\377"); l
= sizeof(i
->pw1
) - 1; }
6079 { strcpy(p
= i
->pw2
, "\377"); l
= sizeof(i
->pw2
) - 1; }
6081 strncpy(p
, buf
, 1 + (l
< len
) ? l
: len
);
6083 Input("Screen User: ", sizeof(i
->name
) - 1, INP_COOKED
, su_fin
, (char *)i
, 0);
6085 Input("User's UNIX Password: ", sizeof(i
->pw1
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6087 Input("User's Screen Password: ", sizeof(i
->pw2
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6090 if ((p
= DoSu(i
->up
, i
->name
, i
->pw2
, i
->pw1
)))
6097 InputSu(w
, up
, name
)
6099 struct acluser
**up
;
6104 if (!(i
= (struct inputsu
*)calloc(1, sizeof(struct inputsu
))))
6109 su_fin(name
, (int)strlen(name
), (char *)i
); /* can also initialise stuff */
6111 su_fin((char *)0, 0, (char *)i
);
6114 #endif /* MULTIUSER */
6119 pass1(buf
, len
, data
)
6124 struct acluser
*u
= (struct acluser
*)data
;
6129 if (u
->u_password
!= NullStr
)
6130 free((char *)u
->u_password
);
6131 u
->u_password
= SaveStr(buf
);
6132 bzero(buf
, strlen(buf
));
6133 Input("Retype new password:", 100, INP_NOECHO
, pass2
, data
, 0);
6137 pass2(buf
, len
, data
)
6144 struct acluser
*u
= (struct acluser
*)data
;
6147 if (!buf
|| strcmp(u
->u_password
, buf
))
6149 Msg(0, "[ Passwords don't match - checking turned off ]");
6150 if (u
->u_password
!= NullStr
)
6152 bzero(u
->u_password
, strlen(u
->u_password
));
6153 free((char *)u
->u_password
);
6155 u
->u_password
= NullStr
;
6157 else if (u
->u_password
[0] == '\0')
6159 Msg(0, "[ No password - no secure ]");
6161 bzero(buf
, strlen(buf
));
6164 if (u
->u_password
!= NullStr
)
6166 for (st
= 0; st
< 2; st
++)
6167 salt
[st
] = 'A' + (int)((time(0) >> 6 * st
) % 26);
6169 buf
= crypt(u
->u_password
, salt
);
6170 bzero(u
->u_password
, strlen(u
->u_password
));
6171 free((char *)u
->u_password
);
6172 u
->u_password
= SaveStr(buf
);
6173 bzero(buf
, strlen(buf
));
6176 UserFreeCopyBuffer(u
);
6177 u
->u_plop
.len
= strlen(u
->u_password
);
6181 if (!(u
->u_plop
.buf
= SaveStr(u
->u_password
)))
6184 D_user
->u_plop
.len
= 0;
6187 Msg(0, "[ Password moved into copybuffer ]");
6188 #else /* COPY_PASTE */
6189 Msg(0, "[ Crypted password is \"%s\" ]", u
->u_password
);
6190 #endif /* COPY_PASTE */
6193 #endif /* PASSWORD */
6196 digraph_fn(buf
, len
, data
)
6199 char *data
; /* dummy */
6206 buf
[len
+ 1] = ch
; /* so we can restore it later */
6207 if (ch
< ' ' || ch
== '\177')
6209 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6213 if ((ch
< '0' || ch
> '9') && (ch
< 'a' || ch
> 'f') && (ch
< 'A' || ch
> 'F'))
6215 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6218 if (len
== (*buf
== 'U' ? 5 : 3))
6222 if (len
&& *buf
== '0')
6224 if (ch
< '0' || ch
> '7')
6226 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6241 buf
[len
] = buf
[len
+ 1]; /* stored above */
6246 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6249 for (i
= 2; i
< len
; i
++)
6251 if (buf
[i
] >= '0' && buf
[i
] <= '9')
6252 x
= x
* 16 | (buf
[i
] - '0');
6253 else if (buf
[i
] >= 'a' && buf
[i
] <= 'f')
6254 x
= x
* 16 | (buf
[i
] - ('a' - 10));
6255 else if (buf
[i
] >= 'A' && buf
[i
] <= 'F')
6256 x
= x
* 16 | (buf
[i
] - ('A' - 10));
6261 else if (buf
[0] == '0')
6264 for (i
= 1; i
< len
; i
++)
6266 if (buf
[i
] < '0' || buf
[i
] > '7')
6268 x
= x
* 8 | (buf
[i
] - '0');
6273 for (i
= 0; i
< (int)(sizeof(digraphs
)/sizeof(*digraphs
)); i
++)
6274 if ((digraphs
[i
][0] == (unsigned char)buf
[0] && digraphs
[i
][1] == (unsigned char)buf
[1]) ||
6275 (digraphs
[i
][0] == (unsigned char)buf
[1] && digraphs
[i
][1] == (unsigned char)buf
[0]))
6277 if (i
== (int)(sizeof(digraphs
)/sizeof(*digraphs
)))
6279 Msg(0, "Unknown digraph");
6287 if (flayer
->l_encoding
== UTF8
)
6288 i
= ToUtf8(buf
, x
); /* buf is big enough for all UTF-8 codes */
6291 LayProcess(&buf
, &i
);
6302 debug1("StuffKey #%d", i
);
6305 debug1(" - %s", term
[i
+ T_CAPS
].tcname
);
6308 if (i
< KMAP_KEYS
&& D_ESCseen
)
6310 struct action
*act
= &D_ESCseen
[i
+ 256];
6311 if (act
->nr
!= RC_ILLEGAL
)
6314 DoAction(act
, i
+ 256);
6320 if (i
>= T_CURSOR
- T_CAPS
&& i
< T_KEYPAD
- T_CAPS
&& D_cursorkeys
)
6321 i
+= T_OCAPS
- T_CURSOR
;
6322 else if (i
>= T_KEYPAD
- T_CAPS
&& i
< T_OCAPS
- T_CAPS
&& D_keypad
)
6323 i
+= T_OCAPS
- T_CURSOR
;
6324 debug1(" - action %d\n", i
);
6325 flayer
= D_forecv
->c_layer
;
6329 if (InMark() || InInput() || InWList())
6330 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &mmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].mm
;
6332 if ((!act
|| act
->nr
== RC_ILLEGAL
) && !D_mapdefault
)
6333 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &umtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].um
;
6334 if (!act
|| act
->nr
== RC_ILLEGAL
)
6335 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &dmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].dm
;
6337 if (discard
&& (!act
|| act
->nr
!= RC_COMMAND
))
6344 if (act
== 0 || act
->nr
== RC_ILLEGAL
)
6358 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6359 if (Layer2Window(cv
->c_layer
) == wi
)
6365 FindNiceWindow(wi
, presel
)
6371 debug2("FindNiceWindow %d %s\n", wi
? wi
->w_number
: -1 , presel
? presel
: "NULL");
6374 i
= WindowByNoN(presel
);
6381 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6384 if (!wi
|| (IsOnDisplay(wi
) && !presel
))
6386 /* try to get another window */
6389 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6390 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6393 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6394 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6397 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6398 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6401 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6402 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6406 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6407 if (!wi
->w_layer
.l_cvlist
)
6410 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6411 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
))
6415 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6423 /* sorted list of all commands */
6424 static struct comm
**commtab
;
6425 static int ncommtab
;
6430 void (*hand
) __P((struct comm
*, char **, int));
6433 for (n
= 0; cos
[n
].name
; n
++)
6438 commtab
= (struct commt
*)realloc(commtab
, sizeof(*commtab
) * (ncommtab
+ n
));
6440 commtab
= (struct commt
*)malloc(sizeof(*commtab
) * (ncommtab
+ n
));
6443 for (i
= 0; i
< n
; i
++)
6445 for (j
= 0; j
< ncommtab
; j
++)
6447 r
= strcmp(cos
[i
].name
, commtab
[j
]->name
);
6449 Panic(0, "Duplicate command: %s\n", cos
[i
].name
);
6453 for (r
= ncommtab
; r
> j
; r
--)
6454 commtab
[r
] = commtab
[r
- 1];
6455 commtab
[j
] = cos
+ i
;
6456 cos
[i
].handler
= hand
;
6457 bzero(cos
[i
].userbits
, sizeof(cos
[i
].userbits
));
6466 int x
, m
, l
= 0, r
= ncommtab
- 1;
6470 x
= strcmp(str
, commtab
[m
]->name
);
6484 CalcSlicePercent(cv
, percent
)
6489 if (!cv
|| !cv
->c_slback
)
6491 up
= CalcSlicePercent(cv
->c_slback
->c_slback
, percent
);
6493 for (cv
= cv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6494 wsum
+= cv
->c_slweight
;
6497 return (up
* w
) / wsum
;
6501 ChangeCanvasSize(fcv
, abs
, diff
, gflag
, percent
)
6502 struct canvas
*fcv
; /* make this canvas bigger */
6503 int abs
; /* mode: 0:rel 1:abs 2:max */
6504 int diff
; /* change this much */
6505 int gflag
; /* go up if neccessary */
6509 int done
, have
, m
, dir
;
6511 debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs
, diff
, percent
);
6512 if (abs
== 0 && diff
== 0)
6517 fcv
->c_slweight
= 0;
6520 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6522 fcv
->c_slweight
= 1;
6523 cv
= fcv
->c_slback
->c_slback
;
6524 if (gflag
&& cv
&& cv
->c_slback
)
6525 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6533 if (percent
&& diff
> percent
)
6539 for (cv
= fcv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6540 wsum
+= cv
->c_slweight
;
6543 up
= gflag
? CalcSlicePercent(fcv
->c_slback
->c_slback
, percent
) : percent
;
6544 debug3("up=%d, wsum=%d percent=%d\n", up
, wsum
, percent
);
6547 int scale
= wsum
< 10 ? 1000 : 100;
6548 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6549 cv
->c_slweight
*= scale
;
6551 debug1("scaled wsum to %d\n", wsum
);
6553 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6557 cv
->c_slweight
= (cv
->c_slweight
* up
) / percent
;
6558 if (cv
->c_slweight
== 0)
6561 debug1(" - weight %d\n", cv
->c_slweight
);
6563 diff
= (diff
* wsum
) / percent
;
6569 if (abs
&& diff
== (fcv
->c_slorient
== SLICE_VERT
? fcv
->c_ye
- fcv
->c_ys
+ 2 : fcv
->c_xe
- fcv
->c_xs
+ 2))
6571 /* fix weights to real size (can't be helped, sorry) */
6572 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6574 cv
->c_slweight
= cv
->c_slorient
== SLICE_VERT
? cv
->c_ye
- cv
->c_ys
+ 2 : cv
->c_xe
- cv
->c_xs
+ 2;
6575 debug1(" - weight %d\n", cv
->c_slweight
);
6579 diff
= diff
- fcv
->c_slweight
;
6580 debug1("diff = %d\n", diff
);
6585 cv
= fcv
->c_slnext
? fcv
->c_slnext
: fcv
->c_slprev
;
6586 fcv
->c_slweight
+= diff
;
6587 cv
->c_slweight
-= diff
;
6592 for (cv
= fcv
->c_slnext
; diff
> 0; cv
= dir
> 0 ? cv
->c_slnext
: cv
->c_slprev
)
6596 debug1("reached end, dir is %d\n", dir
);
6606 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 : 2;
6607 debug2("min is %d, have %d\n", m
, cv
->c_slweight
);
6608 if (cv
->c_slweight
> m
)
6610 have
= cv
->c_slweight
- m
;
6613 debug1("subtract %d\n", have
);
6614 cv
->c_slweight
-= have
;
6621 /* need more room! */
6622 cv
= fcv
->c_slback
->c_slback
;
6623 if (cv
&& cv
->c_slback
)
6624 done
+= ChangeCanvasSize(fcv
->c_slback
->c_slback
, 0, diff
, gflag
, percent
);
6626 fcv
->c_slweight
+= done
;
6627 debug1("ChangeCanvasSize returns %d\n", done
);
6632 ResizeRegions(arg
, flags
)
6638 int gflag
= 0, abs
= 0, percent
= 0;
6644 if (D_forecv
->c_slorient
== SLICE_UNKN
)
6646 Msg(0, "resize: need more than one region");
6649 gflag
= flags
& RESIZE_FLAG_L
? 0 : 1;
6650 orient
|= flags
& RESIZE_FLAG_H
? SLICE_HORI
: 0;
6651 orient
|= flags
& RESIZE_FLAG_V
? SLICE_VERT
: 0;
6653 orient
= D_forecv
->c_slorient
;
6657 /* make all regions the same height */
6658 struct canvas
*cv
= gflag
? &D_canvas
: D_forecv
->c_slback
;
6659 if (cv
->c_slperp
->c_slorient
& orient
)
6660 EqualizeCanvas(cv
->c_slperp
, gflag
);
6661 /* can't use cv->c_slorient directly as it can be D_canvas */
6662 if ((cv
->c_slperp
->c_slorient
^ (SLICE_HORI
^ SLICE_VERT
)) & orient
)
6667 EqualizeCanvas(cv
->c_slperp
, gflag
);
6670 EqualizeCanvas(cv
, gflag
);
6673 RecreateCanvasChain();
6674 RethinkDisplayViewports();
6675 ResizeLayersToCanvases();
6678 if (!strcmp(arg
, "min") || !strcmp(arg
, "0"))
6683 else if (!strcmp(arg
, "max") || !strcmp(arg
, "_"))
6690 if (l
> 0 && arg
[l
- 1] == '%')
6693 diff
= atoi(arg
+ 1);
6694 else if (*arg
== '-')
6695 diff
= -atoi(arg
+ 1);
6698 diff
= atoi(arg
); /* +1 because of caption line */
6701 abs
= diff
== 0 ? 2 : 1;
6707 diff
= diff
* percent
/ 100;
6709 if (cv
->c_slorient
& orient
)
6710 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6711 if (cv
->c_slback
->c_slorient
& orient
)
6712 ChangeCanvasSize(cv
->c_slback
, abs
, diff
, gflag
, percent
);
6714 ResizeCanvas(&D_canvas
);
6715 RecreateCanvasChain();
6716 RethinkDisplayViewports();
6717 ResizeLayersToCanvases();
6724 if (siz
+ diff
> dsize
- (nreg
- 1) * 2 - 1)
6725 diff
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6726 if (diff
== 0 || siz
+ diff
< 1)
6731 if (D_forecv
->c_next
)
6733 D_forecv
->c_ye
+= diff
;
6734 D_forecv
->c_next
->c_ys
+= diff
;
6735 D_forecv
->c_next
->c_yoff
+= diff
;
6739 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6740 if (cv
->c_next
== D_forecv
)
6744 D_forecv
->c_ys
-= diff
;
6745 D_forecv
->c_yoff
-= diff
;
6750 int s
, i
= 0, found
= 0, di
= diff
, d2
;
6751 s
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6752 for (cv
= D_cvlist
; cv
; i
= cv
->c_ye
+ 2, cv
= cv
->c_next
)
6756 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) + diff
;
6757 cv
->c_yoff
-= cv
->c_ys
- i
;
6762 s
-= cv
->c_ye
- cv
->c_ys
;
6770 d2
= di
> cv
->c_ye
- cv
->c_ys
? cv
->c_ye
- cv
->c_ys
: di
;
6772 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) - d2
;
6773 cv
->c_yoff
-= cv
->c_ys
- i
;
6777 RethinkDisplayViewports();
6778 ResizeLayersToCanvases();
6783 ResizeFin(buf
, len
, data
)
6789 int flags
= *(int *)data
;
6790 ch
= ((unsigned char *)buf
)[len
];
6793 ResizeRegions(buf
, flags
);
6797 flags
^= RESIZE_FLAG_H
;
6799 flags
^= RESIZE_FLAG_V
;
6801 flags
|= RESIZE_FLAG_H
|RESIZE_FLAG_V
;
6803 flags
^= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
6805 flags
^= RESIZE_FLAG_L
;
6808 inp_setprompt(resizeprompts
[flags
], NULL
);
6809 *(int *)data
= flags
;
6820 p
= Layer2Window(D_forecv
->c_layer
);
6821 for (i
= 3; i
>=0; i
--)
6822 SetXtermOSC(i
, p
? p
->w_xtermosc
[i
] : 0);
6827 ParseAttrColor(s1
, s2
, msgok
)
6839 while (*ss
&& *ss
!= ' ')
6843 if (*s
&& (s2
|| *ss
|| !((*s
>= 'a' && *s
<= 'z') || (*s
>= 'A' && *s
<= 'Z') || *s
== '.')))
6845 int mode
= 0, n
= 0;
6863 if (*s
>= '0' && *s
<= '9')
6866 if (*s
>= '0' && *s
<= '9')
6867 n
= n
* 16 + (*s
++ - '0');
6868 else if (*s
>= 'a' && *s
<= 'f')
6869 n
= n
* 16 + (*s
++ - ('a' - 10));
6870 else if (*s
>= 'A' && *s
<= 'F')
6871 n
= n
* 16 + (*s
++ - ('A' - 10));
6872 else if (*s
&& *s
!= ' ')
6875 Msg(0, "Illegal attribute hexchar '%c'", *s
);
6881 while (*s
&& *s
!= ' ')
6898 Msg(0, "Illegal attribute specifier '%c'", *s
);
6904 if (*s
&& *s
!= ' ')
6907 Msg(0, "junk after attribute description: '%c'", *s
);
6919 while (*s
&& *s
== ' ')
6927 Msg(0, "junk after description: '%c'", *s
);
6931 while (*s
&& *s
== ' ')
6938 static char costr
[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
6948 for (j
= 0; j
< 2 && *s
&& *s
!= ' '; j
++)
6950 for (i
= 0; costr
[i
]; i
++)
6956 Msg(0, "illegal color descriptor: '%c'", *s
);
6960 n
= n
<< 4 | (i
& 15);
6963 n
= (n
& 0x20ff) | 0x200;
6967 if ((n
& 0xf00) == 0xf00)
6968 n
^= 0xf00; /* clear superflous bits */
6971 n
^= 0x2400; /* shift bit into right position */
6974 n
|= 0xf0; /* don't change bg color */
6975 if (numco
!= 2 && n
!= 0xff)
6976 n
|= 0x100; /* special invert mode */
6977 if (*s
&& *s
!= ' ')
6980 Msg(0, "junk after color description: '%c'", *s
);
6988 while (*s
&& *s
== ' ')
6993 Msg(0, "junk after description: '%c'", *s
);
6996 debug1("ParseAttrColor %06x\n", r
);
7004 * e just set intensity
7005 * f don't change anything
7006 * Intensity is encoded into bits 17(fg) and 18(bg).
7009 ApplyAttrColor(i
, mc
)
7013 debug1("ApplyAttrColor %06x\n", i
);
7014 mc
->attr
|= i
>> 8 & 255;
7015 mc
->attr
^= i
& 255;
7017 i
= (i
>> 16) ^ 0xff;
7018 if ((i
& 0x100) != 0)
7021 if (mc
->attr
& (A_SO
|A_RV
))
7023 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4) | ((i
& 0x200) << 1) | ((i
& 0x400) >> 1);
7025 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4);
7029 if ((i
& 0x0f) != 0x0f)
7030 mc
->attr
= (mc
->attr
& 0xbf) | ((i
>> 3) & 0x40);
7031 if ((i
& 0xf0) != 0xf0)
7032 mc
->attr
= (mc
->attr
& 0x7f) | ((i
>> 3) & 0x80);
7034 mc
->color
= 0x99 ^ mc
->color
;
7035 if ((i
& 0x0e) == 0x0e)
7036 i
= (i
& 0xf0) | (mc
->color
& 0x0f);
7037 if ((i
& 0xe0) == 0xe0)
7038 i
= (i
& 0x0f) | (mc
->color
& 0xf0);
7039 mc
->color
= 0x99 ^ i
;
7040 debug2("ApplyAttrColor - %02x %02x\n", mc
->attr
, i
);