Add some window events.
[screen-lua.git] / src / process.c
blob6bd76fcb0f25f32b62e847d6f74a915d8e5ff7f0
1 /* Copyright (c) 2008, 2009
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Micah Cowan (micah@cowan.name)
5 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
6 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
7 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
8 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
9 * Copyright (c) 1987 Oliver Laumann
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3, or (at your option)
14 * any later version.
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>
30 #include <sys/stat.h>
31 #include <signal.h>
32 #include <fcntl.h>
33 #if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
34 # include <time.h>
35 #endif
36 #include <sys/time.h>
37 #ifndef sun
38 #include <sys/ioctl.h>
39 #endif
42 #include "config.h"
44 /* for solaris 2.1, Unixware (SVR4.2) and possibly others: */
45 #ifdef HAVE_STROPTS_H
46 # include <sys/stropts.h>
47 #endif
49 #include "screen.h"
50 #include "extern.h"
51 #include "logfile.h"
53 extern struct comm comms[];
54 extern char *rc_name;
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;
69 #ifdef COLOR
70 extern int attr2color[][4];
71 extern int nattr2color;
72 #endif
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;
81 #ifdef AUTO_NUKE
82 extern int defautonuke;
83 #endif
84 extern int separate_sids;
85 extern struct NewWindow nwin_default, nwin_undef;
86 #ifdef COPY_PASTE
87 extern int join_with_cr;
88 extern int compacthist;
89 extern int search_ic;
90 # ifdef FONT
91 extern int pastefont;
92 # endif
93 extern unsigned char mark_key_tab[];
94 extern char *BufferFile;
95 #endif
96 #ifdef POW_DETACH
97 extern char *BufferFile, *PowDetachString;
98 #endif
99 #ifdef MULTIUSER
100 extern struct acluser *EffectiveAclUser; /* acl.c */
101 #endif
102 extern struct term term[]; /* terminal capabilities */
103 #ifdef MAPKEYS
104 extern char *kmapdef[];
105 extern char *kmapadef[];
106 extern char *kmapmdef[];
107 #endif
108 extern struct mchar mchar_so, mchar_null;
109 extern int renditions[];
110 extern int VerboseCreate;
111 #ifdef UTF8
112 extern char *screenencodings;
113 #endif
114 #ifdef DW_CHARS
115 extern int cjkwidth;
116 #endif
118 static int CheckArgNum __P((int, char **));
119 static void ClearAction __P((struct action *));
120 static void SaveAction __P((struct action *, int, char **, int *));
121 static int NextWindow __P((void));
122 static int PreviousWindow __P((void));
123 static int MoreWindows __P((void));
124 static void LogToggle __P((int));
125 static void ShowInfo __P((void));
126 static void ShowDInfo __P((void));
127 static struct win *WindowByName __P((char *));
128 static int WindowByNumber __P((char *));
129 static int ParseOnOff __P((struct action *, int *));
130 static int ParseWinNum __P((struct action *, int *));
131 static int ParseBase __P((struct action *, char *, int *, int, char *));
132 static int ParseNum1000 __P((struct action *, int *));
133 static char **SaveArgs __P((char **));
134 static int IsNum __P((char *, int));
135 static void Colonfin __P((char *, int, char *));
136 static void InputSelect __P((void));
137 static void InputSetenv __P((char *));
138 static void InputAKA __P((void));
139 #ifdef MULTIUSER
140 static int InputSu __P((struct win *, struct acluser **, char *));
141 static void su_fin __P((char *, int, char *));
142 #endif
143 static void AKAfin __P((char *, int, char *));
144 #ifdef COPY_PASTE
145 static void copy_reg_fn __P((char *, int, char *));
146 static void ins_reg_fn __P((char *, int, char *));
147 #endif
148 static void process_fn __P((char *, int, char *));
149 #ifdef PASSWORD
150 static void pass1 __P((char *, int, char *));
151 static void pass2 __P((char *, int, char *));
152 #endif
153 #ifdef POW_DETACH
154 static void pow_detach_fn __P((char *, int, char *));
155 #endif
156 static void digraph_fn __P((char *, int, char *));
157 static int digraph_find __P((const char *buf));
158 static void confirm_fn __P((char *, int, char *));
159 static int IsOnDisplay __P((struct win *));
160 static void ResizeRegions __P((char *, int));
161 static void ResizeFin __P((char *, int, char *));
162 static struct action *FindKtab __P((char *, int));
163 static void SelectFin __P((char *, int, char *));
164 static void SelectLayoutFin __P((char *, int, char *));
166 /* Alias */
167 static void AddAlias __P((const char *name, const char *val , char **args, int *argl, int count));
168 static struct alias * FindAlias __P((const char *name));
169 static struct alias * FindAliasnr __P((int));
170 static void DelAlias __P((const char *name));
171 static int DoAlias __P((const char *, char **, int *));
173 extern struct layer *flayer;
174 extern struct display *display, *displays;
175 extern struct win *fore, *console_window, *windows;
176 extern struct acluser *users;
177 extern struct layout *layouts, *layout_attach, layout_last_marker;
178 extern struct layout *laytab[];
180 extern char screenterm[], HostName[], version[];
181 extern struct NewWindow nwin_undef, nwin_default;
182 extern struct LayFuncs WinLf, MarkLf;
184 extern int Z0width, Z1width;
185 extern int real_uid, real_gid;
187 #ifdef NETHACK
188 extern int nethackflag;
189 #endif
192 struct win *wtab[MAXWIN]; /* window table, should be dynamic */
194 #ifdef MULTIUSER
195 extern char *multi;
196 extern int maxusercount;
197 #endif
198 char NullStr[] = "";
200 struct plop plop_tab[MAX_PLOP_DEFS];
202 #ifndef PTYMODE
203 # define PTYMODE 0622
204 #endif
206 int TtyMode = PTYMODE;
207 int hardcopy_append = 0;
208 int all_norefresh = 0;
209 #ifdef ZMODEM
210 int zmodem_mode = 0;
211 char *zmodem_sendcmd;
212 char *zmodem_recvcmd;
213 static char *zmodes[4] = {"off", "auto", "catch", "pass"};
214 #endif
216 int idletimo;
217 struct action idleaction;
218 #ifdef BLANKER_PRG
219 char **blankerprg;
220 #endif
222 struct action ktab[256 + KMAP_KEYS]; /* command key translation table */
223 struct kclass {
224 struct kclass *next;
225 char *name;
226 struct action ktab[256 + KMAP_KEYS];
228 struct kclass *kclasses;
230 #ifdef MAPKEYS
231 struct action umtab[KMAP_KEYS+KMAP_AKEYS];
232 struct action dmtab[KMAP_KEYS+KMAP_AKEYS];
233 struct action mmtab[KMAP_KEYS+KMAP_AKEYS];
234 struct kmap_ext *kmap_exts;
235 int kmap_extn;
236 static int maptimeout = 300;
237 #endif
239 #ifndef MAX_DIGRAPH
240 #define MAX_DIGRAPH 512
241 #endif
243 struct digraph
245 unsigned char d[2];
246 int value;
250 * Command aliases.
252 struct alias {
253 int nr;
254 char *name; /* Name of the alias */
255 int cmdnr; /* Number of the command this is alias for */
256 char **args; /* The argument list for the command */
257 int *argl;
258 struct alias *next;
260 struct alias *g_aliases_list = NULL;
263 /* digraph table taken from old vim and rfc1345 */
264 static struct digraph digraphs[MAX_DIGRAPH + 1] = {
265 {' ', ' ', 160}, /*   */
266 {'N', 'S', 160}, /*   */
267 {'~', '!', 161}, /* ¡ */
268 {'!', '!', 161}, /* ¡ */
269 {'!', 'I', 161}, /* ¡ */
270 {'c', '|', 162}, /* ¢ */
271 {'c', 't', 162}, /* ¢ */
272 {'$', '$', 163}, /* £ */
273 {'P', 'd', 163}, /* £ */
274 {'o', 'x', 164}, /* ¤ */
275 {'C', 'u', 164}, /* ¤ */
276 {'C', 'u', 164}, /* ¤ */
277 {'E', 'u', 164}, /* ¤ */
278 {'Y', '-', 165}, /* ¥ */
279 {'Y', 'e', 165}, /* ¥ */
280 {'|', '|', 166}, /* ¦ */
281 {'B', 'B', 166}, /* ¦ */
282 {'p', 'a', 167}, /* § */
283 {'S', 'E', 167}, /* § */
284 {'"', '"', 168}, /* ¨ */
285 {'\'', ':', 168}, /* ¨ */
286 {'c', 'O', 169}, /* © */
287 {'C', 'o', 169}, /* © */
288 {'a', '-', 170}, /* ª */
289 {'<', '<', 171}, /* « */
290 {'-', ',', 172}, /* ¬ */
291 {'N', 'O', 172}, /* ¬ */
292 {'-', '-', 173}, /* ­ */
293 {'r', 'O', 174}, /* ® */
294 {'R', 'g', 174}, /* ® */
295 {'-', '=', 175}, /* ¯ */
296 {'\'', 'm', 175}, /* ¯ */
297 {'~', 'o', 176}, /* ° */
298 {'D', 'G', 176}, /* ° */
299 {'+', '-', 177}, /* ± */
300 {'2', '2', 178}, /* ² */
301 {'2', 'S', 178}, /* ² */
302 {'3', '3', 179}, /* ³ */
303 {'3', 'S', 179}, /* ³ */
304 {'\'', '\'', 180}, /* ´ */
305 {'j', 'u', 181}, /* µ */
306 {'M', 'y', 181}, /* µ */
307 {'p', 'p', 182}, /* ¶ */
308 {'P', 'I', 182}, /* ¶ */
309 {'~', '.', 183}, /* · */
310 {'.', 'M', 183}, /* · */
311 {',', ',', 184}, /* ¸ */
312 {'\'', ',', 184}, /* ¸ */
313 {'1', '1', 185}, /* ¹ */
314 {'1', 'S', 185}, /* ¹ */
315 {'o', '-', 186}, /* º */
316 {'>', '>', 187}, /* » */
317 {'1', '4', 188}, /* ¼ */
318 {'1', '2', 189}, /* ½ */
319 {'3', '4', 190}, /* ¾ */
320 {'~', '?', 191}, /* ¿ */
321 {'?', '?', 191}, /* ¿ */
322 {'?', 'I', 191}, /* ¿ */
323 {'A', '`', 192}, /* À */
324 {'A', '!', 192}, /* À */
325 {'A', '\'', 193}, /* Á */
326 {'A', '^', 194}, /* Â */
327 {'A', '>', 194}, /* Â */
328 {'A', '~', 195}, /* Ã */
329 {'A', '?', 195}, /* Ã */
330 {'A', '"', 196}, /* Ä */
331 {'A', ':', 196}, /* Ä */
332 {'A', '@', 197}, /* Å */
333 {'A', 'A', 197}, /* Å */
334 {'A', 'E', 198}, /* Æ */
335 {'C', ',', 199}, /* Ç */
336 {'E', '`', 200}, /* È */
337 {'E', '!', 200}, /* È */
338 {'E', '\'', 201}, /* É */
339 {'E', '^', 202}, /* Ê */
340 {'E', '>', 202}, /* Ê */
341 {'E', '"', 203}, /* Ë */
342 {'E', ':', 203}, /* Ë */
343 {'I', '`', 204}, /* Ì */
344 {'I', '!', 204}, /* Ì */
345 {'I', '\'', 205}, /* Í */
346 {'I', '^', 206}, /* Î */
347 {'I', '>', 206}, /* Î */
348 {'I', '"', 207}, /* Ï */
349 {'I', ':', 207}, /* Ï */
350 {'D', '-', 208}, /* Ð */
351 {'N', '~', 209}, /* Ñ */
352 {'N', '?', 209}, /* Ñ */
353 {'O', '`', 210}, /* Ò */
354 {'O', '!', 210}, /* Ò */
355 {'O', '\'', 211}, /* Ó */
356 {'O', '^', 212}, /* Ô */
357 {'O', '>', 212}, /* Ô */
358 {'O', '~', 213}, /* Õ */
359 {'O', '?', 213}, /* Õ */
360 {'O', '"', 214}, /* Ö */
361 {'O', ':', 214}, /* Ö */
362 {'/', '\\', 215}, /* × */
363 {'*', 'x', 215}, /* × */
364 {'O', '/', 216}, /* Ø */
365 {'U', '`', 217}, /* Ù */
366 {'U', '!', 217}, /* Ù */
367 {'U', '\'', 218}, /* Ú */
368 {'U', '^', 219}, /* Û */
369 {'U', '>', 219}, /* Û */
370 {'U', '"', 220}, /* Ü */
371 {'U', ':', 220}, /* Ü */
372 {'Y', '\'', 221}, /* Ý */
373 {'I', 'p', 222}, /* Þ */
374 {'T', 'H', 222}, /* Þ */
375 {'s', 's', 223}, /* ß */
376 {'s', '"', 223}, /* ß */
377 {'a', '`', 224}, /* à */
378 {'a', '!', 224}, /* à */
379 {'a', '\'', 225}, /* á */
380 {'a', '^', 226}, /* â */
381 {'a', '>', 226}, /* â */
382 {'a', '~', 227}, /* ã */
383 {'a', '?', 227}, /* ã */
384 {'a', '"', 228}, /* ä */
385 {'a', ':', 228}, /* ä */
386 {'a', 'a', 229}, /* å */
387 {'a', 'e', 230}, /* æ */
388 {'c', ',', 231}, /* ç */
389 {'e', '`', 232}, /* è */
390 {'e', '!', 232}, /* è */
391 {'e', '\'', 233}, /* é */
392 {'e', '^', 234}, /* ê */
393 {'e', '>', 234}, /* ê */
394 {'e', '"', 235}, /* ë */
395 {'e', ':', 235}, /* ë */
396 {'i', '`', 236}, /* ì */
397 {'i', '!', 236}, /* ì */
398 {'i', '\'', 237}, /* í */
399 {'i', '^', 238}, /* î */
400 {'i', '>', 238}, /* î */
401 {'i', '"', 239}, /* ï */
402 {'i', ':', 239}, /* ï */
403 {'d', '-', 240}, /* ð */
404 {'n', '~', 241}, /* ñ */
405 {'n', '?', 241}, /* ñ */
406 {'o', '`', 242}, /* ò */
407 {'o', '!', 242}, /* ò */
408 {'o', '\'', 243}, /* ó */
409 {'o', '^', 244}, /* ô */
410 {'o', '>', 244}, /* ô */
411 {'o', '~', 245}, /* õ */
412 {'o', '?', 245}, /* õ */
413 {'o', '"', 246}, /* ö */
414 {'o', ':', 246}, /* ö */
415 {':', '-', 247}, /* ÷ */
416 {'o', '/', 248}, /* ø */
417 {'u', '`', 249}, /* ù */
418 {'u', '!', 249}, /* ù */
419 {'u', '\'', 250}, /* ú */
420 {'u', '^', 251}, /* û */
421 {'u', '>', 251}, /* û */
422 {'u', '"', 252}, /* ü */
423 {'u', ':', 252}, /* ü */
424 {'y', '\'', 253}, /* ý */
425 {'i', 'p', 254}, /* þ */
426 {'t', 'h', 254}, /* þ */
427 {'y', '"', 255}, /* ÿ */
428 {'y', ':', 255}, /* ÿ */
429 {'"', '[', 196}, /* Ä */
430 {'"', '\\', 214}, /* Ö */
431 {'"', ']', 220}, /* Ü */
432 {'"', '{', 228}, /* ä */
433 {'"', '|', 246}, /* ö */
434 {'"', '}', 252}, /* ü */
435 {'"', '~', 223} /* ß */
438 #define RESIZE_FLAG_H 1
439 #define RESIZE_FLAG_V 2
440 #define RESIZE_FLAG_L 4
442 static char *resizeprompts[] = {
443 "resize # lines: ",
444 "resize -h # lines: ",
445 "resize -v # lines: ",
446 "resize -b # lines: ",
447 "resize -l # lines: ",
448 "resize -l -h # lines: ",
449 "resize -l -v # lines: ",
450 "resize -l -b # lines: ",
453 static int
454 parse_input_int(buf, len, val)
455 const char *buf;
456 int len;
457 int *val;
459 int x = 0, i;
460 if (len >= 1 && ((*buf == 'U' && buf[1] == '+') || (*buf == '0' && (buf[1] == 'x' || buf[1] == 'X'))))
462 x = 0;
463 for (i = 2; i < len; i++)
465 if (buf[i] >= '0' && buf[i] <= '9')
466 x = x * 16 | (buf[i] - '0');
467 else if (buf[i] >= 'a' && buf[i] <= 'f')
468 x = x * 16 | (buf[i] - ('a' - 10));
469 else if (buf[i] >= 'A' && buf[i] <= 'F')
470 x = x * 16 | (buf[i] - ('A' - 10));
471 else
472 return 0;
475 else if (buf[0] == '0')
477 x = 0;
478 for (i = 1; i < len; i++)
480 if (buf[i] < '0' || buf[i] > '7')
481 return 0;
482 x = x * 8 | (buf[i] - '0');
485 else
486 return 0;
487 *val = x;
488 return 1;
491 char *noargs[1];
493 void
494 InitKeytab()
496 register unsigned int i;
497 #ifdef MAPKEYS
498 char *argarr[2];
499 #endif
501 for (i = 0; i < sizeof(ktab)/sizeof(*ktab); i++)
503 ktab[i].nr = RC_ILLEGAL;
504 ktab[i].args = noargs;
505 ktab[i].argl = 0;
507 #ifdef MAPKEYS
508 for (i = 0; i < KMAP_KEYS+KMAP_AKEYS; i++)
510 umtab[i].nr = RC_ILLEGAL;
511 umtab[i].args = noargs;
512 umtab[i].argl = 0;
513 dmtab[i].nr = RC_ILLEGAL;
514 dmtab[i].args = noargs;
515 dmtab[i].argl = 0;
516 mmtab[i].nr = RC_ILLEGAL;
517 mmtab[i].args = noargs;
518 mmtab[i].argl = 0;
520 argarr[1] = 0;
521 for (i = 0; i < NKMAPDEF; i++)
523 if (i + KMAPDEFSTART < T_CAPS)
524 continue;
525 if (i + KMAPDEFSTART >= T_CAPS + KMAP_KEYS)
526 continue;
527 if (kmapdef[i] == 0)
528 continue;
529 argarr[0] = kmapdef[i];
530 SaveAction(dmtab + i + (KMAPDEFSTART - T_CAPS), RC_STUFF, argarr, 0);
532 for (i = 0; i < NKMAPADEF; i++)
534 if (i + KMAPADEFSTART < T_CURSOR)
535 continue;
536 if (i + KMAPADEFSTART >= T_CURSOR + KMAP_AKEYS)
537 continue;
538 if (kmapadef[i] == 0)
539 continue;
540 argarr[0] = kmapadef[i];
541 SaveAction(dmtab + i + (KMAPADEFSTART - T_CURSOR + KMAP_KEYS), RC_STUFF, argarr, 0);
543 for (i = 0; i < NKMAPMDEF; i++)
545 if (i + KMAPMDEFSTART < T_CAPS)
546 continue;
547 if (i + KMAPMDEFSTART >= T_CAPS + KMAP_KEYS)
548 continue;
549 if (kmapmdef[i] == 0)
550 continue;
551 argarr[0] = kmapmdef[i];
552 argarr[1] = 0;
553 SaveAction(mmtab + i + (KMAPMDEFSTART - T_CAPS), RC_STUFF, argarr, 0);
555 #endif
557 ktab['h'].nr = RC_HARDCOPY;
558 #ifdef BSDJOBS
559 ktab['z'].nr = ktab[Ctrl('z')].nr = RC_SUSPEND;
560 #endif
561 ktab['c'].nr = ktab[Ctrl('c')].nr = RC_SCREEN;
562 ktab[' '].nr = ktab[Ctrl(' ')].nr =
563 ktab['n'].nr = ktab[Ctrl('n')].nr = RC_NEXT;
564 ktab['N'].nr = RC_NUMBER;
565 ktab[Ctrl('h')].nr = ktab[0177].nr = ktab['p'].nr = ktab[Ctrl('p')].nr = RC_PREV;
566 ktab['k'].nr = ktab[Ctrl('k')].nr = RC_KILL;
567 ktab['l'].nr = ktab[Ctrl('l')].nr = RC_REDISPLAY;
568 ktab['w'].nr = ktab[Ctrl('w')].nr = RC_WINDOWS;
569 ktab['v'].nr = RC_VERSION;
570 ktab[Ctrl('v')].nr = RC_DIGRAPH;
571 ktab['q'].nr = ktab[Ctrl('q')].nr = RC_XON;
572 ktab['s'].nr = ktab[Ctrl('s')].nr = RC_XOFF;
573 ktab['t'].nr = ktab[Ctrl('t')].nr = RC_TIME;
574 ktab['i'].nr = ktab[Ctrl('i')].nr = RC_INFO;
575 ktab['m'].nr = ktab[Ctrl('m')].nr = RC_LASTMSG;
576 ktab['A'].nr = RC_TITLE;
577 #if defined(UTMPOK) && defined(LOGOUTOK)
578 ktab['L'].nr = RC_LOGIN;
579 #endif
580 ktab[','].nr = RC_LICENSE;
581 ktab['W'].nr = RC_WIDTH;
582 ktab['.'].nr = RC_DUMPTERMCAP;
583 ktab[Ctrl('\\')].nr = RC_QUIT;
584 #ifdef DETACH
585 ktab['d'].nr = ktab[Ctrl('d')].nr = RC_DETACH;
586 # ifdef POW_DETACH
587 ktab['D'].nr = RC_POW_DETACH;
588 # endif
589 #endif
590 ktab['r'].nr = ktab[Ctrl('r')].nr = RC_WRAP;
591 ktab['f'].nr = ktab[Ctrl('f')].nr = RC_FLOW;
592 ktab['C'].nr = RC_CLEAR;
593 ktab['Z'].nr = RC_RESET;
594 ktab['H'].nr = RC_LOG;
595 ktab['M'].nr = RC_MONITOR;
596 ktab['?'].nr = RC_HELP;
597 #ifdef MULTI
598 ktab['*'].nr = RC_DISPLAYS;
599 #endif
601 char *args[2];
602 args[0] = "-";
603 args[1] = NULL;
604 SaveAction(ktab + '-', RC_SELECT, args, 0);
606 for (i = 0; i < ((MAXWIN < 10) ? MAXWIN : 10); i++)
608 char *args[2], arg1[10];
609 args[0] = arg1;
610 args[1] = 0;
611 sprintf(arg1, "%d", i);
612 SaveAction(ktab + '0' + i, RC_SELECT, args, 0);
614 ktab['\''].nr = RC_SELECT; /* calling a window by name */
616 char *args[2];
617 args[0] = "-b";
618 args[1] = 0;
619 SaveAction(ktab + '"', RC_WINDOWLIST, args, 0);
621 ktab[Ctrl('G')].nr = RC_VBELL;
622 ktab[':'].nr = RC_COLON;
623 #ifdef COPY_PASTE
624 ktab['['].nr = ktab[Ctrl('[')].nr = RC_COPY;
626 char *args[2];
627 args[0] = ".";
628 args[1] = 0;
629 SaveAction(ktab + ']', RC_PASTE, args, 0);
630 SaveAction(ktab + Ctrl(']'), RC_PASTE, args, 0);
632 ktab['{'].nr = RC_HISTORY;
633 ktab['}'].nr = RC_HISTORY;
634 ktab['>'].nr = RC_WRITEBUF;
635 ktab['<'].nr = RC_READBUF;
636 ktab['='].nr = RC_REMOVEBUF;
637 #endif
638 #ifdef POW_DETACH
639 ktab['D'].nr = RC_POW_DETACH;
640 #endif
641 #ifdef LOCK
642 ktab['x'].nr = ktab[Ctrl('x')].nr = RC_LOCKSCREEN;
643 #endif
644 ktab['b'].nr = ktab[Ctrl('b')].nr = RC_BREAK;
645 ktab['B'].nr = RC_POW_BREAK;
646 ktab['_'].nr = RC_SILENCE;
647 ktab['S'].nr = RC_SPLIT;
648 ktab['Q'].nr = RC_ONLY;
649 ktab['X'].nr = RC_REMOVE;
650 ktab['F'].nr = RC_FIT;
651 ktab['\t'].nr = RC_FOCUS;
653 char *args[2];
654 args[0] = "up";
655 args[1] = 0;
656 SaveAction(ktab + T_BACKTAB - T_CAPS + 256, RC_FOCUS, args, 0);
659 char *args[2];
660 args[0] = "-v";
661 args[1] = 0;
662 SaveAction(ktab + '|', RC_SPLIT, args, 0);
664 /* These come last; they may want overwrite others: */
665 if (DefaultEsc >= 0)
667 ClearAction(&ktab[DefaultEsc]);
668 ktab[DefaultEsc].nr = RC_OTHER;
670 if (DefaultMetaEsc >= 0)
672 ClearAction(&ktab[DefaultMetaEsc]);
673 ktab[DefaultMetaEsc].nr = RC_META;
676 idleaction.nr = RC_BLANKER;
677 idleaction.args = noargs;
678 idleaction.argl = 0;
681 static struct action *
682 FindKtab(class, create)
683 char *class;
684 int create;
686 struct kclass *kp, **kpp;
687 int i;
689 if (class == 0)
690 return ktab;
691 for (kpp = &kclasses; (kp = *kpp) != 0; kpp = &kp->next)
692 if (!strcmp(kp->name, class))
693 break;
694 if (kp == 0)
696 if (!create)
697 return 0;
698 if (strlen(class) > 80)
700 Msg(0, "Command class name too long.");
701 return 0;
703 kp = malloc(sizeof(*kp));
704 if (kp == 0)
706 Msg(0, strnomem);
707 return 0;
709 kp->name = SaveStr(class);
710 for (i = 0; i < (int)(sizeof(kp->ktab)/sizeof(*kp->ktab)); i++)
712 kp->ktab[i].nr = RC_ILLEGAL;
713 kp->ktab[i].args = noargs;
715 kp->next = 0;
716 *kpp = kp;
718 return kp->ktab;
721 static void
722 ClearAction(act)
723 struct action *act;
725 char **p;
727 if (act->nr == RC_ILLEGAL)
728 return;
729 act->nr = RC_ILLEGAL;
730 if (act->args == noargs)
731 return;
732 for (p = act->args; *p; p++)
733 free(*p);
734 free((char *)act->args);
735 act->args = noargs;
736 act->argl = 0;
740 * ProcessInput: process input from display and feed it into
741 * the layer on canvas D_forecv.
744 #ifdef MAPKEYS
747 * This ProcessInput just does the keybindings and passes
748 * everything else on to ProcessInput2.
751 void
752 ProcessInput(ibuf, ilen)
753 char *ibuf;
754 int ilen;
756 int ch, slen;
757 unsigned char *s, *q;
758 int i, l;
759 char *p;
761 debug1("ProcessInput: %d bytes\n", ilen);
762 if (display == 0 || ilen == 0)
763 return;
764 if (D_seql)
765 evdeq(&D_mapev);
766 slen = ilen;
767 s = (unsigned char *)ibuf;
768 while (ilen-- > 0)
770 ch = *s++;
771 if (D_dontmap || !D_nseqs)
773 D_dontmap = 0;
774 continue;
776 for (;;)
778 debug3("cmp %c %c[%d]\n", ch, *D_seqp, D_seqp - D_kmaps);
779 if (*D_seqp != ch)
781 l = D_seqp[D_seqp[-D_seql-1] + 1];
782 if (l)
784 D_seqp += l * 2 + 4;
785 debug1("miss %d\n", D_seqp - D_kmaps);
786 continue;
788 debug("complete miss\n");
789 D_mapdefault = 0;
790 l = D_seql;
791 p = (char *)D_seqp - l;
792 D_seql = 0;
793 D_seqp = D_kmaps + 3;
794 if (l == 0)
795 break;
796 if ((q = D_seqh) != 0)
798 D_seqh = 0;
799 i = q[0] << 8 | q[1];
800 i &= ~KMAP_NOTIMEOUT;
801 debug1("Mapping former hit #%d - ", i);
802 debug2("%d(%s) - ", q[2], q + 3);
803 if (StuffKey(i))
804 ProcessInput2((char *)q + 3, q[2]);
805 if (display == 0)
806 return;
807 l -= q[2];
808 p += q[2];
810 else
811 D_dontmap = 1;
812 debug1("flush old %d\n", l);
813 ProcessInput(p, l);
814 if (display == 0)
815 return;
816 evdeq(&D_mapev);
817 continue;
819 if (D_seql++ == 0)
821 /* Finish old stuff */
822 slen -= ilen + 1;
823 debug1("finish old %d\n", slen);
824 if (slen)
825 ProcessInput2(ibuf, slen);
826 if (display == 0)
827 return;
828 D_seqh = 0;
830 ibuf = (char *)s;
831 slen = ilen;
832 D_seqp++;
833 l = D_seql;
834 debug2("length am %d, want %d\n", l, D_seqp[-l - 1]);
835 if (l == D_seqp[-l - 1])
837 if (D_seqp[l] != l)
839 q = D_seqp + 1 + l;
840 if (D_kmaps + D_nseqs > q && q[2] > l && !bcmp(D_seqp - l, q + 3, l))
842 debug1("have another mapping (%s), delay execution\n", q + 3);
843 D_seqh = D_seqp - 3 - l;
844 D_seqp = q + 3 + l;
845 break;
848 i = D_seqp[-l - 3] << 8 | D_seqp[-l - 2];
849 i &= ~KMAP_NOTIMEOUT;
850 debug1("Mapping #%d - ", i);
851 p = (char *)D_seqp - l;
852 debug2("%d(%s) - ", l, p);
853 D_seql = 0;
854 D_seqp = D_kmaps + 3;
855 D_seqh = 0;
856 if (StuffKey(i))
857 ProcessInput2(p, l);
858 if (display == 0)
859 return;
861 break;
864 if (D_seql)
866 debug("am in sequence -> check for timeout\n");
867 l = D_seql;
868 for (s = D_seqp; ; s += i * 2 + 4)
870 if (s[-l-3] & KMAP_NOTIMEOUT >> 8)
871 break;
872 if ((i = s[s[-l-1] + 1]) == 0)
874 SetTimeout(&D_mapev, maptimeout);
875 evenq(&D_mapev);
876 break;
880 ProcessInput2(ibuf, slen);
883 #else
884 # define ProcessInput2 ProcessInput
885 #endif
889 * Here only the screen escape commands are handled.
892 void
893 ProcessInput2(ibuf, ilen)
894 char *ibuf;
895 int ilen;
897 char *s;
898 int ch, slen;
899 struct action *ktabp;
901 debug1("ProcessInput2: %d bytes\n", ilen);
902 while (ilen && display)
904 debug1(" - ilen now %d bytes\n", ilen);
905 flayer = D_forecv->c_layer;
906 fore = D_fore;
907 slen = ilen;
908 s = ibuf;
909 if (!D_ESCseen)
911 while (ilen > 0)
913 if ((unsigned char)*s++ == D_user->u_Esc)
914 break;
915 ilen--;
917 slen -= ilen;
918 if (slen)
919 DoProcess(fore, &ibuf, &slen, 0);
920 if (--ilen == 0)
921 D_ESCseen = ktab;
923 if (ilen <= 0)
924 return;
925 ktabp = D_ESCseen ? D_ESCseen : ktab;
926 D_ESCseen = 0;
927 ch = (unsigned char)*s;
930 * As users have different esc characters, but a common ktab[],
931 * we fold back the users esc and meta-esc key to the Default keys
932 * that can be looked up in the ktab[]. grmbl. jw.
933 * XXX: make ktab[] a per user thing.
935 if (ch == D_user->u_Esc)
936 ch = DefaultEsc;
937 else if (ch == D_user->u_MetaEsc)
938 ch = DefaultMetaEsc;
940 if (ch >= 0)
941 DoAction(&ktabp[ch], ch);
942 ibuf = (char *)(s + 1);
943 ilen--;
947 void
948 DoProcess(p, bufp, lenp, pa)
949 struct win *p;
950 char **bufp;
951 int *lenp;
952 struct paster *pa;
954 int oldlen;
955 struct display *d = display;
957 #ifdef COPY_PASTE
958 /* XXX -> PasteStart */
959 if (pa && *lenp > 1 && p && p->w_slowpaste)
961 /* schedule slowpaste event */
962 SetTimeout(&p->w_paster.pa_slowev, p->w_slowpaste);
963 evenq(&p->w_paster.pa_slowev);
964 return;
966 #endif
967 while (flayer && *lenp)
969 #ifdef COPY_PASTE
970 if (!pa && p && p->w_paster.pa_pastelen && flayer == p->w_paster.pa_pastelayer)
972 debug("layer is busy - beep!\n");
973 WBell(p, visual_bell);
974 *bufp += *lenp;
975 *lenp = 0;
976 display = d;
977 return;
979 #endif
980 oldlen = *lenp;
981 LayProcess(bufp, lenp);
982 #ifdef COPY_PASTE
983 if (pa && !pa->pa_pastelayer)
984 break; /* flush rest of paste */
985 #endif
986 if (*lenp == oldlen)
988 if (pa)
990 display = d;
991 return;
993 /* We're full, let's beep */
994 debug("layer is full - beep!\n");
995 WBell(p, visual_bell);
996 break;
999 *bufp += *lenp;
1000 *lenp = 0;
1001 display = d;
1002 #ifdef COPY_PASTE
1003 if (pa && pa->pa_pastelen == 0)
1004 FreePaster(pa);
1005 #endif
1009 FindCommnr(str)
1010 char *str;
1012 int x, m, l = 0, r = RC_LAST;
1013 while (l <= r)
1015 m = (l + r) / 2;
1016 x = strcmp(str, comms[m].name);
1017 if (x > 0)
1018 l = m + 1;
1019 else if (x < 0)
1020 r = m - 1;
1021 else
1022 return m;
1024 return RC_ILLEGAL;
1027 static int
1028 CheckArgNum(nr, args)
1029 int nr;
1030 char **args;
1032 int i, n;
1033 static char *argss[] = {"no", "one", "two", "three", "four", "OOPS"};
1034 static char *orformat[] =
1036 "%s: %s: %s argument%s required",
1037 "%s: %s: %s or %s argument%s required",
1038 "%s: %s: %s, %s or %s argument%s required",
1039 "%s: %s: %s, %s, %s or %s argument%s required"
1042 n = comms[nr].flags & ARGS_MASK;
1043 for (i = 0; args[i]; i++)
1045 if (comms[nr].flags & ARGS_ORMORE)
1047 if (i < n)
1049 Msg(0, "%s: %s: at least %s argument%s required",
1050 rc_name, comms[nr].name, argss[n], n != 1 ? "s" : "");
1051 return -1;
1054 else if ((comms[nr].flags & ARGS_PLUS1) &&
1055 (comms[nr].flags & ARGS_PLUS2) &&
1056 (comms[nr].flags & ARGS_PLUS3))
1058 if (i != n && i != n + 1 && i != n + 2 && i != n + 3)
1060 Msg(0, orformat[3], rc_name, comms[nr].name, argss[n],
1061 argss[n + 1], argss[n + 2], argss[n + 3], "");
1062 return -1;
1065 else if ((comms[nr].flags & ARGS_PLUS1) &&
1066 (comms[nr].flags & ARGS_PLUS2))
1068 if (i != n && i != n + 1 && i != n + 2)
1070 Msg(0, orformat[2], rc_name, comms[nr].name, argss[n],
1071 argss[n + 1], argss[n + 2], "");
1072 return -1;
1075 else if ((comms[nr].flags & ARGS_PLUS1) &&
1076 (comms[nr].flags & ARGS_PLUS3))
1078 if (i != n && i != n + 1 && i != n + 3)
1080 Msg(0, orformat[2], rc_name, comms[nr].name, argss[n],
1081 argss[n + 1], argss[n + 3], "");
1082 return -1;
1085 else if ((comms[nr].flags & ARGS_PLUS2) &&
1086 (comms[nr].flags & ARGS_PLUS3))
1088 if (i != n && i != n + 2 && i != n + 3)
1090 Msg(0, orformat[2], rc_name, comms[nr].name, argss[n],
1091 argss[n + 2], argss[n + 3], "");
1092 return -1;
1095 else if (comms[nr].flags & ARGS_PLUS1)
1097 if (i != n && i != n + 1)
1099 Msg(0, orformat[1], rc_name, comms[nr].name, argss[n],
1100 argss[n + 1], n != 0 ? "s" : "");
1101 return -1;
1104 else if (comms[nr].flags & ARGS_PLUS2)
1106 if (i != n && i != n + 2)
1108 Msg(0, orformat[1], rc_name, comms[nr].name, argss[n],
1109 argss[n + 2], "s");
1110 return -1;
1113 else if (comms[nr].flags & ARGS_PLUS3)
1115 if (i != n && i != n + 3)
1117 Msg(0, orformat[1], rc_name, comms[nr].name, argss[n],
1118 argss[n + 3], "");
1119 return -1;
1122 else if (i != n)
1124 Msg(0, orformat[0], rc_name, comms[nr].name, argss[n], n != 1 ? "s" : "");
1125 return -1;
1127 return i;
1130 static void
1131 StuffFin(buf, len, data)
1132 char *buf;
1133 int len;
1134 char *data;
1136 if (!flayer)
1137 return;
1138 while(len)
1139 LayProcess(&buf, &len);
1142 void
1143 ChangeWinNum(old, new)
1144 int old;
1145 int new;
1147 struct win *pnew = wtab[new];
1148 struct win *pold = wtab[old];
1149 if (new < 0 || new >= maxwin)
1151 Msg(0, "Given window position is invalid.");
1152 return;
1154 wtab[new] = pold;
1155 pold->w_number = new;
1156 wtab[old] = pnew;
1157 if (pnew)
1158 pnew->w_number = old;
1159 #ifdef MULTIUSER
1160 /* exchange the acls for these windows. */
1161 AclWinSwap(old, new);
1162 #endif
1163 #ifdef UTMPOK
1164 /* exchange the utmp-slots for these windows */
1165 if ((pold->w_slot != (slot_t) -1) && (pold->w_slot != (slot_t) 0))
1167 RemoveUtmp(pold);
1168 SetUtmp(pold);
1170 if (pnew && (pnew->w_slot != (slot_t) -1) && (pnew->w_slot != (slot_t) 0))
1172 /* XXX: first display wins? */
1173 display = pold->w_layer.l_cvlist ? pold->w_layer.l_cvlist->c_display : 0;
1174 RemoveUtmp(pnew);
1175 SetUtmp(pnew);
1177 #endif
1179 WindowChanged(pold, 'n');
1180 WindowChanged((struct win *)0, 'w');
1181 WindowChanged((struct win *)0, 'W');
1182 WindowChanged((struct win *)0, 0);
1185 /*ARGSUSED*/
1186 void
1187 DoAction(act, key)
1188 struct action *act;
1189 int key;
1191 int nr = act->nr;
1192 char **args = act->args;
1193 int *argl = act->argl;
1194 struct win *p;
1195 int argc, i, n, msgok;
1196 char *s;
1197 char ch;
1198 struct display *odisplay = display;
1199 struct acluser *user;
1201 user = display ? D_user : users;
1203 if (nr > RC_LAST)
1205 struct alias *alias = FindAliasnr(nr);
1206 if (alias)
1208 DoAlias(alias->name, act->args, act->argl);
1209 return;
1211 nr = RC_ILLEGAL;
1214 if (nr == RC_ILLEGAL)
1216 debug1("key '%c': No action\n", key);
1217 return;
1220 n = comms[nr].flags;
1221 if ((n & NEED_DISPLAY) && display == 0)
1223 Msg(0, "%s: %s: display required", rc_name, comms[nr].name);
1224 return;
1226 if ((n & NEED_FORE) && fore == 0)
1228 Msg(0, "%s: %s: window required", rc_name, comms[nr].name);
1229 return;
1231 if ((n & NEED_LAYER) && flayer == 0)
1233 Msg(0, "%s: %s: display or window required", rc_name, comms[nr].name);
1234 return;
1236 if ((argc = CheckArgNum(nr, args)) < 0)
1237 return;
1238 #ifdef MULTIUSER
1239 if (display)
1241 if (AclCheckPermCmd(D_user, ACL_EXEC, &comms[nr]))
1243 Msg(0, "%s: %s: permission denied (user %s)",
1244 rc_name, comms[nr].name, (EffectiveAclUser ? EffectiveAclUser : D_user)->u_name);
1245 return;
1248 #endif /* MULTIUSER */
1250 msgok = display && !*rc_name;
1251 switch(nr)
1253 case RC_SELECT:
1254 if (!*args)
1255 InputSelect();
1256 else if (args[0][0] == '-' && !args[0][1])
1258 SetForeWindow((struct win *)0);
1259 Activate(0);
1261 else if (args[0][0] == '.' && !args[0][1])
1263 if (!fore)
1264 Msg(0, "select . needs a window");
1265 else
1267 SetForeWindow(fore);
1268 Activate(0);
1271 else if (ParseWinNum(act, &n) == 0)
1272 SwitchWindow(n);
1273 break;
1274 #ifdef AUTO_NUKE
1275 case RC_DEFAUTONUKE:
1276 if (ParseOnOff(act, &defautonuke) == 0 && msgok)
1277 Msg(0, "Default autonuke turned %s", defautonuke ? "on" : "off");
1278 if (display && *rc_name)
1279 D_auto_nuke = defautonuke;
1280 break;
1281 case RC_AUTONUKE:
1282 if (ParseOnOff(act, &D_auto_nuke) == 0 && msgok)
1283 Msg(0, "Autonuke turned %s", D_auto_nuke ? "on" : "off");
1284 break;
1285 #endif
1286 case RC_DEFOBUFLIMIT:
1287 if (ParseNum(act, &defobuflimit) == 0 && msgok)
1288 Msg(0, "Default limit set to %d", defobuflimit);
1289 if (display && *rc_name)
1291 D_obufmax = defobuflimit;
1292 D_obuflenmax = D_obuflen - D_obufmax;
1294 break;
1295 case RC_OBUFLIMIT:
1296 if (*args == 0)
1297 Msg(0, "Limit is %d, current buffer size is %d", D_obufmax, D_obuflen);
1298 else if (ParseNum(act, &D_obufmax) == 0 && msgok)
1299 Msg(0, "Limit set to %d", D_obufmax);
1300 D_obuflenmax = D_obuflen - D_obufmax;
1301 break;
1302 case RC_DUMPTERMCAP:
1303 WriteFile(user, (char *)0, DUMP_TERMCAP);
1304 break;
1305 case RC_HARDCOPY:
1307 int mode = DUMP_HARDCOPY;
1309 if (argc > 1 && !strcmp(*args, "-h"))
1311 mode = DUMP_SCROLLBACK;
1312 args++;
1313 argc--;
1315 if (*args && args[1])
1317 Msg(0, "%s: hardcopy: too many arguments", rc_name);
1318 break;
1320 if (fore == 0 && *args == 0)
1321 Msg(0, "%s: hardcopy: window required", rc_name);
1322 else
1323 WriteFile(user, *args, mode);
1325 break;
1326 case RC_DEFLOG:
1327 (void)ParseOnOff(act, &nwin_default.Lflag);
1328 break;
1329 case RC_LOG:
1330 n = fore->w_log ? 1 : 0;
1331 ParseSwitch(act, &n);
1332 LogToggle(n);
1333 break;
1334 #ifdef BSDJOBS
1335 case RC_SUSPEND:
1336 Detach(D_STOP);
1337 break;
1338 #endif
1339 case RC_NEXT:
1340 if (MoreWindows())
1341 SwitchWindow(NextWindow());
1342 break;
1343 case RC_PREV:
1344 if (MoreWindows())
1345 SwitchWindow(PreviousWindow());
1346 break;
1347 case RC_KILL:
1349 char *name;
1351 if (key >= 0)
1353 #ifdef PSEUDOS
1354 Input(fore->w_pwin ? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW, confirm_fn, NULL, RC_KILL);
1355 #else
1356 Input("Really kill this window [y/n]", 1, INP_RAW, confirm_fn, NULL, RC_KILL);
1357 #endif
1358 break;
1360 n = fore->w_number;
1361 #ifdef PSEUDOS
1362 if (fore->w_pwin)
1364 FreePseudowin(fore);
1365 Msg(0, "Filter removed.");
1366 break;
1368 #endif
1369 name = SaveStr(fore->w_title);
1370 KillWindow(fore);
1371 Msg(0, "Window %d (%s) killed.", n, name);
1372 if (name)
1373 free(name);
1374 break;
1376 case RC_QUIT:
1377 if (key >= 0)
1379 Input("Really quit and kill all your windows [y/n]", 1, INP_RAW, confirm_fn, NULL, RC_QUIT);
1380 break;
1382 Finit(0);
1383 /* NOTREACHED */
1384 #ifdef DETACH
1385 case RC_DETACH:
1386 if (*args && !strcmp(*args, "-h"))
1387 Hangup();
1388 else
1389 Detach(D_DETACH);
1390 break;
1391 # ifdef POW_DETACH
1392 case RC_POW_DETACH:
1393 if (key >= 0)
1395 static char buf[2];
1397 buf[0] = key;
1398 Input(buf, 1, INP_RAW, pow_detach_fn, NULL, 0);
1400 else
1401 Detach(D_POWER); /* detach and kill Attacher's parent */
1402 break;
1403 # endif
1404 #endif
1405 case RC_DEBUG:
1406 #ifdef DEBUG
1407 if (!*args)
1409 if (dfp)
1410 Msg(0, "debugging info is written to %s/", DEBUGDIR);
1411 else
1412 Msg(0, "debugging is currently off. Use 'debug on' to enable.");
1413 break;
1415 if (dfp)
1417 debug("debug: closing debug file.\n");
1418 fflush(dfp);
1419 fclose(dfp);
1420 dfp = NULL;
1422 if (strcmp("off", *args))
1423 opendebug(0, 1);
1424 # ifdef SIG_NODEBUG
1425 else if (display)
1426 kill(D_userpid, SIG_NODEBUG); /* a one shot item, but hey... */
1427 # endif /* SIG_NODEBUG */
1428 #else
1429 if (*args == 0 || strcmp("off", *args))
1430 Msg(0, "Sorry, screen was compiled without -DDEBUG option.");
1431 #endif
1432 break;
1433 #ifdef ZMODEM
1434 case RC_ZMODEM:
1435 if (*args && !strcmp(*args, "sendcmd"))
1437 if (args[1])
1439 free(zmodem_sendcmd);
1440 zmodem_sendcmd = SaveStr(args[1]);
1442 if (msgok)
1443 Msg(0, "zmodem sendcmd: %s", zmodem_sendcmd);
1444 break;
1446 if (*args && !strcmp(*args, "recvcmd"))
1448 if (args[1])
1450 free(zmodem_recvcmd);
1451 zmodem_recvcmd = SaveStr(args[1]);
1453 if (msgok)
1454 Msg(0, "zmodem recvcmd: %s", zmodem_recvcmd);
1455 break;
1457 if (*args)
1459 for (i = 0; i < 4; i++)
1460 if (!strcmp(zmodes[i], *args))
1461 break;
1462 if (i == 4 && !strcmp(*args, "on"))
1463 i = 1;
1464 if (i == 4)
1466 Msg(0, "usage: zmodem off|auto|catch|pass");
1467 break;
1469 zmodem_mode = i;
1471 if (msgok)
1472 Msg(0, "zmodem mode is %s", zmodes[zmodem_mode]);
1473 break;
1474 #endif
1475 case RC_ZOMBIE:
1477 if (!(s = *args))
1479 ZombieKey_destroy = 0;
1480 break;
1482 if (*argl == 0 || *argl > 2)
1484 Msg(0, "%s:zombie: one or two characters expected.", rc_name);
1485 break;
1487 if (args[1])
1489 if (!strcmp(args[1], "onerror"))
1491 ZombieKey_onerror = 1;
1492 } else {
1493 Msg(0, "usage: zombie [keys [onerror]]");
1494 break;
1496 } else
1497 ZombieKey_onerror = 0;
1498 ZombieKey_destroy = args[0][0];
1499 ZombieKey_resurrect = *argl == 2 ? args[0][1] : 0;
1501 break;
1502 case RC_WALL:
1503 #ifdef MULTIUSER
1504 s = D_user->u_name;
1505 #else
1506 s = D_usertty;
1507 #endif
1509 struct display *olddisplay = display;
1510 display = 0; /* no display will cause a broadcast */
1511 Msg(0, "%s: %s", s, *args);
1512 display = olddisplay;
1514 break;
1515 case RC_AT:
1516 /* where this AT command comes from: */
1517 #ifdef MULTIUSER
1518 s = SaveStr(D_user->u_name);
1519 /* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
1520 EffectiveAclUser = D_user;
1521 #else
1522 s = SaveStr(D_usertty);
1523 #endif
1524 n = strlen(args[0]);
1525 if (n) n--;
1527 * the windows/displays loops are quite dangerous here, take extra
1528 * care not to trigger landmines. Things may appear/disappear while
1529 * we are walking along.
1531 switch (args[0][n])
1533 case '*': /* user */
1535 struct display *nd;
1536 struct acluser *u;
1538 if (!n)
1539 u = D_user;
1540 else
1541 for (u = users; u; u = u->u_next)
1543 debug3("strncmp('%s', '%s', %d)\n", *args, u->u_name, n);
1544 if (!strncmp(*args, u->u_name, n))
1545 break;
1547 debug1("at all displays of user %s\n", u->u_name);
1548 for (display = displays; display; display = nd)
1550 nd = display->d_next;
1551 if (D_forecv == 0)
1552 continue;
1553 flayer = D_forecv->c_layer;
1554 fore = D_fore;
1555 if (D_user != u)
1556 continue;
1557 debug1("AT display %s\n", D_usertty);
1558 DoCommand(args + 1, argl + 1);
1559 if (display)
1560 Msg(0, "command from %s: %s %s",
1561 s, args[1], args[2] ? args[2] : "");
1562 display = NULL;
1563 flayer = 0;
1564 fore = NULL;
1566 break;
1568 case '%': /* display */
1570 struct display *nd;
1572 debug1("at display matching '%s'\n", args[0]);
1573 for (display = displays; display; display = nd)
1575 nd = display->d_next;
1576 if (D_forecv == 0)
1577 continue;
1578 fore = D_fore;
1579 flayer = D_forecv->c_layer;
1580 if (strncmp(args[0], D_usertty, n) &&
1581 (strncmp("/dev/", D_usertty, 5) ||
1582 strncmp(args[0], D_usertty + 5, n)) &&
1583 (strncmp("/dev/tty", D_usertty, 8) ||
1584 strncmp(args[0], D_usertty + 8, n)))
1585 continue;
1586 debug1("AT display %s\n", D_usertty);
1587 DoCommand(args + 1, argl + 1);
1588 if (display)
1589 Msg(0, "command from %s: %s %s",
1590 s, args[1], args[2] ? args[2] : "");
1591 display = NULL;
1592 fore = NULL;
1593 flayer = 0;
1595 break;
1597 case '#': /* window */
1598 n--;
1599 /* FALLTHROUGH */
1600 default:
1602 struct win *nw;
1603 int ch;
1605 n++;
1606 ch = args[0][n];
1607 args[0][n] = '\0';
1608 if (!*args[0] || (i = WindowByNumber(args[0])) < 0)
1610 args[0][n] = ch; /* must restore string in case of bind */
1611 /* try looping over titles */
1612 for (fore = windows; fore; fore = nw)
1614 nw = fore->w_next;
1615 if (strncmp(args[0], fore->w_title, n))
1616 continue;
1617 debug2("AT window %d(%s)\n", fore->w_number, fore->w_title);
1619 * consider this a bug or a feature:
1620 * while looping through windows, we have fore AND
1621 * display context. This will confuse users who try to
1622 * set up loops inside of loops, but often allows to do
1623 * what you mean, even when you adress your context wrong.
1625 i = 0;
1626 /* XXX: other displays? */
1627 if (fore->w_layer.l_cvlist)
1628 display = fore->w_layer.l_cvlist->c_display;
1629 flayer = fore->w_savelayer ? fore->w_savelayer : &fore->w_layer;
1630 DoCommand(args + 1, argl + 1); /* may destroy our display */
1631 if (fore && fore->w_layer.l_cvlist)
1633 display = fore->w_layer.l_cvlist->c_display;
1634 Msg(0, "command from %s: %s %s",
1635 s, args[1], args[2] ? args[2] : "");
1638 display = NULL;
1639 fore = NULL;
1640 if (i < 0)
1641 Msg(0, "%s: at '%s': no such window.\n", rc_name, args[0]);
1642 break;
1644 else if (i < MAXWIN && (fore = wtab[i]))
1646 args[0][n] = ch; /* must restore string in case of bind */
1647 debug2("AT window %d (%s)\n", fore->w_number, fore->w_title);
1648 if (fore->w_layer.l_cvlist)
1649 display = fore->w_layer.l_cvlist->c_display;
1650 flayer = fore->w_savelayer ? fore->w_savelayer : &fore->w_layer;
1651 DoCommand(args + 1, argl + 1);
1652 if (fore && fore->w_layer.l_cvlist)
1654 display = fore->w_layer.l_cvlist->c_display;
1655 Msg(0, "command from %s: %s %s",
1656 s, args[1], args[2] ? args[2] : "");
1658 display = NULL;
1659 fore = NULL;
1661 else
1662 Msg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name);
1663 break;
1666 free(s);
1667 #ifdef MULTIUSER
1668 EffectiveAclUser = NULL;
1669 #endif
1670 break;
1672 #ifdef COPY_PASTE
1673 case RC_READREG:
1674 #ifdef ENCODINGS
1675 i = fore ? fore->w_encoding : display ? display->d_encoding : 0;
1676 if (args[0] && args[1] && !strcmp(args[0], "-e"))
1678 i = FindEncoding(args[1]);
1679 if (i == -1)
1681 Msg(0, "%s: readreg: unknown encoding", rc_name);
1682 break;
1684 args += 2;
1686 #endif
1688 * Without arguments we prompt for a destination register.
1689 * It will receive the copybuffer contents.
1690 * This is not done by RC_PASTE, as we prompt for source
1691 * (not dest) there.
1693 if ((s = *args) == NULL)
1695 Input("Copy to register:", 1, INP_RAW, copy_reg_fn, NULL, 0);
1696 break;
1698 if (*argl != 1)
1700 Msg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name);
1701 break;
1703 ch = args[0][0];
1705 * With two arguments we *really* read register contents from file
1707 if (args[1])
1709 if (args[2])
1711 Msg(0, "%s: readreg: too many arguments", rc_name);
1712 break;
1714 if ((s = ReadFile(args[1], &n)))
1716 struct plop *pp = plop_tab + (int)(unsigned char)ch;
1718 if (pp->buf)
1719 free(pp->buf);
1720 pp->buf = s;
1721 pp->len = n;
1722 #ifdef ENCODINGS
1723 pp->enc = i;
1724 #endif
1727 else
1729 * with one argument we copy the copybuffer into a specified register
1730 * This could be done with RC_PASTE too, but is here to be consistent
1731 * with the zero argument call.
1733 copy_reg_fn(&ch, 0, NULL);
1734 break;
1735 #endif
1736 case RC_REGISTER:
1737 #ifdef ENCODINGS
1738 i = fore ? fore->w_encoding : display ? display->d_encoding : 0;
1739 if (args[0] && args[1] && !strcmp(args[0], "-e"))
1741 i = FindEncoding(args[1]);
1742 if (i == -1)
1744 Msg(0, "%s: register: unknown encoding", rc_name);
1745 break;
1747 args += 2;
1748 argc -= 2;
1750 #endif
1751 if (argc != 2)
1753 Msg(0, "%s: register: illegal number of arguments.", rc_name);
1754 break;
1756 if (*argl != 1)
1758 Msg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name);
1759 break;
1761 ch = args[0][0];
1762 #ifdef COPY_PASTE
1763 if (ch == '.')
1765 if (user->u_plop.buf != NULL)
1766 UserFreeCopyBuffer(user);
1767 if (args[1] && args[1][0])
1769 user->u_plop.buf = SaveStrn(args[1], argl[1]);
1770 user->u_plop.len = argl[1];
1771 #ifdef ENCODINGS
1772 user->u_plop.enc = i;
1773 #endif
1776 else
1777 #endif
1779 struct plop *plp = plop_tab + (int)(unsigned char)ch;
1781 if (plp->buf)
1782 free(plp->buf);
1783 plp->buf = SaveStrn(args[1], argl[1]);
1784 plp->len = argl[1];
1785 #ifdef ENCODINGS
1786 plp->enc = i;
1787 #endif
1789 break;
1790 case RC_PROCESS:
1791 if ((s = *args) == NULL)
1793 Input("Process register:", 1, INP_RAW, process_fn, NULL, 0);
1794 break;
1796 if (*argl != 1)
1798 Msg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name);
1799 break;
1801 ch = args[0][0];
1802 process_fn(&ch, 0, NULL);
1803 break;
1804 case RC_STUFF:
1805 s = *args;
1806 if (!args[0])
1808 Input("Stuff:", 100, INP_COOKED, StuffFin, NULL, 0);
1809 break;
1811 n = *argl;
1812 if (args[1])
1814 if (strcmp(s, "-k"))
1816 Msg(0, "%s: stuff: invalid option %s", rc_name, s);
1817 break;
1819 s = args[1];
1820 for (i = T_CAPS; i < T_OCAPS; i++)
1821 if (strcmp(term[i].tcname, s) == 0)
1822 break;
1823 if (i == T_OCAPS)
1825 Msg(0, "%s: stuff: unknown key '%s'", rc_name, s);
1826 break;
1828 #ifdef MAPKEYS
1829 if (StuffKey(i - T_CAPS) == 0)
1830 break;
1831 #endif
1832 s = display ? D_tcs[i].str : 0;
1833 if (s == 0)
1834 break;
1835 n = strlen(s);
1837 while(n)
1838 LayProcess(&s, &n);
1839 break;
1840 case RC_REDISPLAY:
1841 Activate(-1);
1842 break;
1843 case RC_WINDOWS:
1844 ShowWindows(-1);
1845 break;
1846 case RC_VERSION:
1847 Msg(0, "screen %s", version);
1848 break;
1849 case RC_TIME:
1850 if (*args)
1852 timestring = SaveStr(*args);
1853 break;
1855 Msg(0, "%s", MakeWinMsg(timestring, fore, '%'));
1856 break;
1857 case RC_INFO:
1858 ShowInfo();
1859 break;
1860 case RC_DINFO:
1861 ShowDInfo();
1862 break;
1863 case RC_COMMAND:
1865 struct action *ktabp = ktab;
1866 if (argc == 2 && !strcmp(*args, "-c"))
1868 if ((ktabp = FindKtab(args[1], 0)) == 0)
1870 Msg(0, "Unknown command class '%s'", args[1]);
1871 break;
1874 if (D_ESCseen != ktab || ktabp != ktab)
1876 D_ESCseen = ktabp;
1877 break;
1879 D_ESCseen = 0;
1881 /* FALLTHROUGH */
1882 case RC_OTHER:
1883 if (MoreWindows())
1884 SwitchWindow(display && D_other ? D_other->w_number : NextWindow());
1885 break;
1886 case RC_META:
1887 if (user->u_Esc == -1)
1888 break;
1889 ch = user->u_Esc;
1890 s = &ch;
1891 n = 1;
1892 LayProcess(&s, &n);
1893 break;
1894 case RC_XON:
1895 ch = Ctrl('q');
1896 s = &ch;
1897 n = 1;
1898 LayProcess(&s, &n);
1899 break;
1900 case RC_XOFF:
1901 ch = Ctrl('s');
1902 s = &ch;
1903 n = 1;
1904 LayProcess(&s, &n);
1905 break;
1906 case RC_DEFBREAKTYPE:
1907 case RC_BREAKTYPE:
1909 static char *types[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL };
1910 extern int breaktype;
1912 if (*args)
1914 if (ParseNum(act, &n))
1915 for (n = 0; n < (int)(sizeof(types)/sizeof(*types)); n++)
1917 for (i = 0; i < 4; i++)
1919 ch = args[0][i];
1920 if (ch >= 'a' && ch <= 'z')
1921 ch -= 'a' - 'A';
1922 if (ch != types[n][i] && (ch + ('a' - 'A')) != types[n][i])
1923 break;
1925 if (i == 4)
1926 break;
1928 if (n < 0 || n >= (int)(sizeof(types)/sizeof(*types)))
1929 Msg(0, "%s invalid, chose one of %s, %s or %s", *args, types[0], types[1], types[2]);
1930 else
1932 breaktype = n;
1933 Msg(0, "breaktype set to (%d) %s", n, types[n]);
1936 else
1937 Msg(0, "breaktype is (%d) %s", breaktype, types[breaktype]);
1939 break;
1940 case RC_POW_BREAK:
1941 case RC_BREAK:
1942 n = 0;
1943 if (*args && ParseNum(act, &n))
1944 break;
1945 SendBreak(fore, n, nr == RC_POW_BREAK);
1946 break;
1947 #ifdef LOCK
1948 case RC_LOCKSCREEN:
1949 Detach(D_LOCK);
1950 break;
1951 #endif
1952 case RC_WIDTH:
1953 case RC_HEIGHT:
1955 int w, h;
1956 int what = 0;
1958 i = 1;
1959 if (*args && !strcmp(*args, "-w"))
1960 what = 1;
1961 else if (*args && !strcmp(*args, "-d"))
1962 what = 2;
1963 if (what)
1964 args++;
1965 if (what == 0 && flayer && !display)
1966 what = 1;
1967 if (what == 1)
1969 if (!flayer)
1971 Msg(0, "%s: %s: window required", rc_name, comms[nr].name);
1972 break;
1974 w = flayer->l_width;
1975 h = flayer->l_height;
1977 else
1979 if (!display)
1981 Msg(0, "%s: %s: display required", rc_name, comms[nr].name);
1982 break;
1984 w = D_width;
1985 h = D_height;
1987 if (*args && args[0][0] == '-')
1989 Msg(0, "%s: %s: unknown option %s", rc_name, comms[nr].name, *args);
1990 break;
1992 if (nr == RC_HEIGHT)
1994 if (!*args)
1996 #define H0height 42
1997 #define H1height 24
1998 if (h == H0height)
1999 h = H1height;
2000 else if (h == H1height)
2001 h = H0height;
2002 else if (h > (H0height + H1height) / 2)
2003 h = H0height;
2004 else
2005 h = H1height;
2007 else
2009 h = atoi(*args);
2010 if (args[1])
2011 w = atoi(args[1]);
2014 else
2016 if (!*args)
2018 if (w == Z0width)
2019 w = Z1width;
2020 else if (w == Z1width)
2021 w = Z0width;
2022 else if (w > (Z0width + Z1width) / 2)
2023 w = Z0width;
2024 else
2025 w = Z1width;
2027 else
2029 w = atoi(*args);
2030 if (args[1])
2031 h = atoi(args[1]);
2034 if (*args && args[1] && args[2])
2036 Msg(0, "%s: %s: too many arguments", rc_name, comms[nr].name);
2037 break;
2039 if (w <= 0)
2041 Msg(0, "Illegal width");
2042 break;
2044 if (h <= 0)
2046 Msg(0, "Illegal height");
2047 break;
2049 if (what == 1)
2051 if (flayer->l_width == w && flayer->l_height == h)
2052 break;
2053 ResizeLayer(flayer, w, h, (struct display *)0);
2054 break;
2056 if (D_width == w && D_height == h)
2057 break;
2058 if (what == 2)
2060 ChangeScreenSize(w, h, 1);
2062 else
2064 if (ResizeDisplay(w, h) == 0)
2066 Activate(D_fore ? D_fore->w_norefresh : 0);
2067 /* autofit */
2068 ResizeLayer(D_forecv->c_layer, D_forecv->c_xe - D_forecv->c_xs + 1, D_forecv->c_ye - D_forecv->c_ys + 1, 0);
2069 break;
2071 if (h == D_height)
2072 Msg(0, "Your termcap does not specify how to change the terminal's width to %d.", w);
2073 else if (w == D_width)
2074 Msg(0, "Your termcap does not specify how to change the terminal's height to %d.", h);
2075 else
2076 Msg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w, h);
2079 break;
2080 case RC_TITLE:
2081 if (*args == 0)
2082 InputAKA();
2083 else
2084 ChangeAKA(fore, *args, strlen(*args));
2085 break;
2086 case RC_COLON:
2087 Input(":", 100, INP_EVERY, Colonfin, NULL, 0);
2088 if (*args && **args)
2090 s = *args;
2091 n = strlen(s);
2092 LayProcess(&s, &n);
2094 break;
2095 case RC_LASTMSG:
2096 if (D_status_lastmsg)
2097 Msg(0, "%s", D_status_lastmsg);
2098 break;
2099 case RC_SCREEN:
2100 DoScreen("key", args);
2101 break;
2102 case RC_WRAP:
2103 if (ParseSwitch(act, &fore->w_wrap) == 0 && msgok)
2104 Msg(0, "%cwrap", fore->w_wrap ? '+' : '-');
2105 break;
2106 case RC_FLOW:
2107 if (*args)
2109 if (args[0][0] == 'a')
2111 fore->w_flow = (fore->w_flow & FLOW_AUTO) ? FLOW_AUTOFLAG |FLOW_AUTO|FLOW_NOW : FLOW_AUTOFLAG;
2113 else
2115 if (ParseOnOff(act, &n))
2116 break;
2117 fore->w_flow = (fore->w_flow & FLOW_AUTO) | n;
2120 else
2122 if (fore->w_flow & FLOW_AUTOFLAG)
2123 fore->w_flow = (fore->w_flow & FLOW_AUTO) | FLOW_NOW;
2124 else if (fore->w_flow & FLOW_NOW)
2125 fore->w_flow &= ~FLOW_NOW;
2126 else
2127 fore->w_flow = fore->w_flow ? FLOW_AUTOFLAG|FLOW_AUTO|FLOW_NOW : FLOW_AUTOFLAG;
2129 SetFlow(fore->w_flow & FLOW_NOW);
2130 if (msgok)
2131 Msg(0, "%cflow%s", (fore->w_flow & FLOW_NOW) ? '+' : '-',
2132 (fore->w_flow & FLOW_AUTOFLAG) ? "(auto)" : "");
2133 break;
2134 #ifdef MULTIUSER
2135 case RC_DEFWRITELOCK:
2136 if (args[0][0] == 'a')
2137 nwin_default.wlock = WLOCK_AUTO;
2138 else
2140 if (ParseOnOff(act, &n))
2141 break;
2142 nwin_default.wlock = n ? WLOCK_ON : WLOCK_OFF;
2144 break;
2145 case RC_WRITELOCK:
2146 if (*args)
2148 if (args[0][0] == 'a')
2150 fore->w_wlock = WLOCK_AUTO;
2152 else
2154 if (ParseOnOff(act, &n))
2155 break;
2156 fore->w_wlock = n ? WLOCK_ON : WLOCK_OFF;
2159 * user may have permission to change the writelock setting,
2160 * but he may never aquire the lock himself without write permission
2162 if (!AclCheckPermWin(D_user, ACL_WRITE, fore))
2163 fore->w_wlockuser = D_user;
2165 Msg(0, "writelock %s", (fore->w_wlock == WLOCK_AUTO) ? "auto" :
2166 ((fore->w_wlock == WLOCK_OFF) ? "off" : "on"));
2167 break;
2168 #endif
2169 case RC_CLEAR:
2170 ResetAnsiState(fore);
2171 WriteString(fore, "\033[H\033[J", 6);
2172 break;
2173 case RC_RESET:
2174 ResetAnsiState(fore);
2175 #ifdef ZMODEM
2176 if (fore->w_zdisplay)
2177 zmodem_abort(fore, fore->w_zdisplay);
2178 #endif
2179 WriteString(fore, "\033c", 2);
2180 break;
2181 case RC_MONITOR:
2182 n = fore->w_monitor != MON_OFF;
2183 #ifdef MULTIUSER
2184 if (display)
2185 n = n && (ACLBYTE(fore->w_mon_notify, D_user->u_id) & ACLBIT(D_user->u_id));
2186 #endif
2187 if (ParseSwitch(act, &n))
2188 break;
2189 if (n)
2191 #ifdef MULTIUSER
2192 if (display) /* we tell only this user */
2193 ACLBYTE(fore->w_mon_notify, D_user->u_id) |= ACLBIT(D_user->u_id);
2194 else
2195 for (i = 0; i < maxusercount; i++)
2196 ACLBYTE(fore->w_mon_notify, i) |= ACLBIT(i);
2197 #endif
2198 if (fore->w_monitor == MON_OFF)
2199 fore->w_monitor = MON_ON;
2200 Msg(0, "Window %d (%s) is now being monitored for all activity.", fore->w_number, fore->w_title);
2202 else
2204 #ifdef MULTIUSER
2205 if (display) /* we remove only this user */
2206 ACLBYTE(fore->w_mon_notify, D_user->u_id)
2207 &= ~ACLBIT(D_user->u_id);
2208 else
2209 for (i = 0; i < maxusercount; i++)
2210 ACLBYTE(fore->w_mon_notify, i) &= ~ACLBIT(i);
2211 for (i = maxusercount - 1; i >= 0; i--)
2212 if (ACLBYTE(fore->w_mon_notify, i))
2213 break;
2214 if (i < 0)
2215 #endif
2216 fore->w_monitor = MON_OFF;
2217 Msg(0, "Window %d (%s) is no longer being monitored for activity.", fore->w_number, fore->w_title);
2219 break;
2220 #ifdef MULTI
2221 case RC_DISPLAYS:
2222 display_displays();
2223 break;
2224 #endif
2225 case RC_WINDOWLIST:
2226 if (!*args)
2227 display_wlist(0, WLIST_NUM, (struct win *)0);
2228 else if (!strcmp(*args, "string"))
2230 if (args[1])
2232 if (wliststr)
2233 free(wliststr);
2234 wliststr = SaveStr(args[1]);
2236 if (msgok)
2237 Msg(0, "windowlist string is '%s'", wliststr);
2239 else if (!strcmp(*args, "title"))
2241 if (args[1])
2243 if (wlisttit)
2244 free(wlisttit);
2245 wlisttit = SaveStr(args[1]);
2247 if (msgok)
2248 Msg(0, "windowlist title is '%s'", wlisttit);
2250 else
2252 int flag = 0;
2253 int blank = 0;
2254 for (i = 0; i < argc; i++)
2255 if (!args[i])
2256 continue;
2257 else if (!strcmp(args[i], "-m"))
2258 flag |= WLIST_MRU;
2259 else if (!strcmp(args[i], "-b"))
2260 blank = 1;
2261 else if (!strcmp(args[i], "-g"))
2262 flag |= WLIST_NESTED;
2263 else
2265 Msg(0, "usage: windowlist [-b] [-g] [-m] [string [string] | title [title]]");
2266 break;
2268 if (i == argc)
2269 display_wlist(blank, flag, (struct win *)0);
2271 break;
2272 case RC_HELP:
2273 if (argc == 2 && !strcmp(*args, "-c"))
2275 struct action *ktabp;
2276 if ((ktabp = FindKtab(args[1], 0)) == 0)
2278 Msg(0, "Unknown command class '%s'", args[1]);
2279 break;
2281 display_help(args[1], ktabp);
2283 else
2284 display_help((char *)0, ktab);
2285 break;
2286 case RC_LICENSE:
2287 display_copyright();
2288 break;
2289 #ifdef COPY_PASTE
2290 case RC_COPY:
2291 if (flayer->l_layfn != &WinLf)
2293 Msg(0, "Must be on a window layer");
2294 break;
2296 MarkRoutine();
2297 break;
2298 case RC_HISTORY:
2300 static char *pasteargs[] = {".", 0};
2301 static int pasteargl[] = {1};
2303 if (flayer->l_layfn != &WinLf)
2305 Msg(0, "Must be on a window layer");
2306 break;
2308 if (GetHistory() == 0)
2309 break;
2310 if (user->u_plop.buf == NULL)
2311 break;
2312 args = pasteargs;
2313 argl = pasteargl;
2315 /*FALLTHROUGH*/
2316 case RC_PASTE:
2318 char *ss, *dbuf, dch;
2319 int l = 0;
2320 # ifdef ENCODINGS
2321 int enc = -1;
2322 # endif
2325 * without args we prompt for one(!) register to be pasted in the window
2327 if ((s = *args) == NULL)
2329 Input("Paste from register:", 1, INP_RAW, ins_reg_fn, NULL, 0);
2330 break;
2332 if (args[1] == 0 && !fore) /* no window? */
2333 break;
2335 * with two arguments we paste into a destination register
2336 * (no window needed here).
2338 if (args[1] && argl[1] != 1)
2340 Msg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
2341 rc_name);
2342 break;
2344 # ifdef ENCODINGS
2345 else if (fore)
2346 enc = fore->w_encoding;
2347 # endif
2350 * measure length of needed buffer
2352 for (ss = s = *args; (ch = *ss); ss++)
2354 if (ch == '.')
2356 # ifdef ENCODINGS
2357 if (enc == -1)
2358 enc = user->u_plop.enc;
2359 if (enc != user->u_plop.enc)
2360 l += RecodeBuf((unsigned char *)user->u_plop.buf, user->u_plop.len, user->u_plop.enc, enc, (unsigned char *)0);
2361 else
2362 # endif
2363 l += user->u_plop.len;
2365 else
2367 # ifdef ENCODINGS
2368 if (enc == -1)
2369 enc = plop_tab[(int)(unsigned char)ch].enc;
2370 if (enc != plop_tab[(int)(unsigned char)ch].enc)
2371 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);
2372 else
2373 # endif
2374 l += plop_tab[(int)(unsigned char)ch].len;
2377 if (l == 0)
2379 Msg(0, "empty buffer");
2380 break;
2383 * shortcut:
2384 * if there is only one source and the destination is a window, then
2385 * pass a pointer rather than duplicating the buffer.
2387 if (s[1] == 0 && args[1] == 0)
2388 # ifdef ENCODINGS
2389 if (enc == (*s == '.' ? user->u_plop.enc : plop_tab[(int)(unsigned char)*s].enc))
2390 # endif
2392 MakePaster(&fore->w_paster, *s == '.' ? user->u_plop.buf : plop_tab[(int)(unsigned char)*s].buf, l, 0);
2393 break;
2396 * if no shortcut, we construct a buffer
2398 if ((dbuf = (char *)malloc(l)) == 0)
2400 Msg(0, strnomem);
2401 break;
2403 l = 0;
2405 * concatenate all sources into our own buffer, copy buffer is
2406 * special and is skipped if no display exists.
2408 for (ss = s; (ch = *ss); ss++)
2410 struct plop *pp = (ch == '.' ? &user->u_plop : &plop_tab[(int)(unsigned char)ch]);
2411 #ifdef ENCODINGS
2412 if (pp->enc != enc)
2414 l += RecodeBuf((unsigned char *)pp->buf, pp->len, pp->enc, enc, (unsigned char *)dbuf + l);
2415 continue;
2417 #endif
2418 bcopy(pp->buf, dbuf + l, pp->len);
2419 l += pp->len;
2422 * when called with one argument we paste our buffer into the window
2424 if (args[1] == 0)
2426 MakePaster(&fore->w_paster, dbuf, l, 1);
2428 else
2431 * we have two arguments, the second is already in dch.
2432 * use this as destination rather than the window.
2434 dch = args[1][0];
2435 if (dch == '.')
2437 if (user->u_plop.buf != NULL)
2438 UserFreeCopyBuffer(user);
2439 user->u_plop.buf = dbuf;
2440 user->u_plop.len = l;
2441 #ifdef ENCODINGS
2442 user->u_plop.enc = enc;
2443 #endif
2445 else
2447 struct plop *pp = plop_tab + (int)(unsigned char)dch;
2448 if (pp->buf)
2449 free(pp->buf);
2450 pp->buf = dbuf;
2451 pp->len = l;
2452 #ifdef ENCODINGS
2453 pp->enc = enc;
2454 #endif
2457 break;
2459 case RC_WRITEBUF:
2460 if (!user->u_plop.buf)
2462 Msg(0, "empty buffer");
2463 break;
2465 #ifdef ENCODINGS
2467 struct plop oldplop;
2469 oldplop = user->u_plop;
2470 if (args[0] && args[1] && !strcmp(args[0], "-e"))
2472 int enc, l;
2473 char *newbuf;
2475 enc = FindEncoding(args[1]);
2476 if (enc == -1)
2478 Msg(0, "%s: writebuf: unknown encoding", rc_name);
2479 break;
2481 if (enc != oldplop.enc)
2483 l = RecodeBuf((unsigned char *)oldplop.buf, oldplop.len, oldplop.enc, enc, (unsigned char *)0);
2484 newbuf = malloc(l + 1);
2485 if (!newbuf)
2487 Msg(0, strnomem);
2488 break;
2490 user->u_plop.len = RecodeBuf((unsigned char *)oldplop.buf, oldplop.len, oldplop.enc, enc, (unsigned char *)newbuf);
2491 user->u_plop.buf = newbuf;
2492 user->u_plop.enc = enc;
2494 args += 2;
2496 #endif
2497 if (args[0] && args[1])
2498 Msg(0, "%s: writebuf: too many arguments", rc_name);
2499 else
2500 WriteFile(user, args[0], DUMP_EXCHANGE);
2501 #ifdef ENCODINGS
2502 if (user->u_plop.buf != oldplop.buf)
2503 free(user->u_plop.buf);
2504 user->u_plop = oldplop;
2506 #endif
2507 break;
2508 case RC_READBUF:
2509 #ifdef ENCODINGS
2510 i = fore ? fore->w_encoding : display ? display->d_encoding : 0;
2511 if (args[0] && args[1] && !strcmp(args[0], "-e"))
2513 i = FindEncoding(args[1]);
2514 if (i == -1)
2516 Msg(0, "%s: readbuf: unknown encoding", rc_name);
2517 break;
2519 args += 2;
2521 #endif
2522 if (args[0] && args[1])
2524 Msg(0, "%s: readbuf: too many arguments", rc_name);
2525 break;
2527 if ((s = ReadFile(args[0] ? args[0] : BufferFile, &n)))
2529 if (user->u_plop.buf)
2530 UserFreeCopyBuffer(user);
2531 user->u_plop.len = n;
2532 user->u_plop.buf = s;
2533 #ifdef ENCODINGS
2534 user->u_plop.enc = i;
2535 #endif
2537 break;
2538 case RC_REMOVEBUF:
2539 KillBuffers();
2540 break;
2541 case RC_IGNORECASE:
2542 (void)ParseSwitch(act, &search_ic);
2543 if (msgok)
2544 Msg(0, "Will %signore case in searches", search_ic ? "" : "not ");
2545 break;
2546 #endif /* COPY_PASTE */
2547 case RC_ESCAPE:
2548 if (*argl == 0)
2549 SetEscape(user, -1, -1);
2550 else if (*argl == 2)
2551 SetEscape(user, (int)(unsigned char)args[0][0], (int)(unsigned char)args[0][1]);
2552 else
2554 Msg(0, "%s: two characters required after escape.", rc_name);
2555 break;
2557 /* Change defescape if master user. This is because we only
2558 * have one ktab.
2560 if (display && user != users)
2561 break;
2562 /* FALLTHROUGH */
2563 case RC_DEFESCAPE:
2564 if (*argl == 0)
2565 SetEscape(NULL, -1, -1);
2566 else if (*argl == 2)
2567 SetEscape(NULL, (int)(unsigned char)args[0][0], (int)(unsigned char)args[0][1]);
2568 else
2570 Msg(0, "%s: two characters required after defescape.", rc_name);
2571 break;
2573 #ifdef MAPKEYS
2574 CheckEscape();
2575 #endif
2576 break;
2577 case RC_CHDIR:
2578 s = *args ? *args : home;
2579 if (chdir(s) == -1)
2580 Msg(errno, "%s", s);
2581 break;
2582 case RC_SHELL:
2583 case RC_DEFSHELL:
2584 if (ParseSaveStr(act, &ShellProg) == 0)
2585 ShellArgs[0] = ShellProg;
2586 break;
2587 case RC_HARDCOPYDIR:
2588 if (*args)
2589 (void)ParseSaveStr(act, &hardcopydir);
2590 if (msgok)
2591 Msg(0, "hardcopydir is %s\n", hardcopydir && *hardcopydir ? hardcopydir : "<cwd>");
2592 break;
2593 case RC_LOGFILE:
2594 if (*args)
2596 if (args[1] && !(strcmp(*args, "flush")))
2598 log_flush = atoi(args[1]);
2599 if (msgok)
2600 Msg(0, "log flush timeout set to %ds\n", log_flush);
2601 break;
2603 if (ParseSaveStr(act, &screenlogfile) || !msgok)
2604 break;
2606 Msg(0, "logfile is '%s'", screenlogfile);
2607 break;
2608 case RC_LOGTSTAMP:
2609 if (!*args || !strcmp(*args, "on") || !strcmp(*args, "off"))
2611 if (ParseSwitch(act, &logtstamp_on) == 0 && msgok)
2612 Msg(0, "timestamps turned %s", logtstamp_on ? "on" : "off");
2614 else if (!strcmp(*args, "string"))
2616 if (args[1])
2618 if (logtstamp_string)
2619 free(logtstamp_string);
2620 logtstamp_string = SaveStr(args[1]);
2622 if (msgok)
2623 Msg(0, "logfile timestamp is '%s'", logtstamp_string);
2625 else if (!strcmp(*args, "after"))
2627 if (args[1])
2629 logtstamp_after = atoi(args[1]);
2630 if (!msgok)
2631 break;
2633 Msg(0, "timestamp printed after %ds\n", logtstamp_after);
2635 else
2636 Msg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
2637 break;
2638 case RC_SHELLTITLE:
2639 (void)ParseSaveStr(act, &nwin_default.aka);
2640 break;
2641 case RC_TERMCAP:
2642 case RC_TERMCAPINFO:
2643 case RC_TERMINFO:
2644 if (!rc_name || !*rc_name)
2645 Msg(0, "Sorry, too late now. Place that in your .screenrc file.");
2646 break;
2647 case RC_SLEEP:
2648 break; /* Already handled */
2649 case RC_ALIAS:
2650 if (argc == 1)
2651 DelAlias(args[0]);
2652 else
2653 AddAlias(args[0], args[1], args+1, argl+1, argc - 1);
2654 break;
2655 case RC_TERM:
2656 s = NULL;
2657 if (ParseSaveStr(act, &s))
2658 break;
2659 if (strlen(s) >= 20)
2661 Msg(0, "%s: term: argument too long ( < 20)", rc_name);
2662 free(s);
2663 break;
2665 strcpy(screenterm, s);
2666 free(s);
2667 debug1("screenterm set to %s\n", screenterm);
2668 MakeTermcap((display == 0));
2669 debug("new termcap made\n");
2670 break;
2671 case RC_ECHO:
2672 if (!msgok && (!rc_name || strcmp(rc_name, "-X")))
2673 break;
2675 * user typed ^A:echo... well, echo isn't FinishRc's job,
2676 * but as he wanted to test us, we show good will
2678 if (argc > 1 && !strcmp(*args, "-n"))
2680 args++;
2681 argc--;
2683 s = *args;
2684 if (argc > 1 && !strcmp(*args, "-p"))
2686 args++;
2687 argc--;
2688 s = *args;
2689 if (s)
2690 s = MakeWinMsg(s, fore, '%');
2692 if (s)
2693 Msg(0, "%s", s);
2694 else
2695 Msg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name);
2696 break;
2697 case RC_BELL:
2698 case RC_BELL_MSG:
2699 if (*args == 0)
2701 char buf[256];
2702 AddXChars(buf, sizeof(buf), BellString);
2703 Msg(0, "bell_msg is '%s'", buf);
2704 break;
2706 (void)ParseSaveStr(act, &BellString);
2707 break;
2708 #ifdef COPY_PASTE
2709 case RC_BUFFERFILE:
2710 if (*args == 0)
2711 BufferFile = SaveStr(DEFAULT_BUFFERFILE);
2712 else if (ParseSaveStr(act, &BufferFile))
2713 break;
2714 if (msgok)
2715 Msg(0, "Bufferfile is now '%s'", BufferFile);
2716 break;
2717 #endif
2718 case RC_ACTIVITY:
2719 (void)ParseSaveStr(act, &ActivityString);
2720 break;
2721 #if defined(DETACH) && defined(POW_DETACH)
2722 case RC_POW_DETACH_MSG:
2723 if (*args == 0)
2725 char buf[256];
2726 AddXChars(buf, sizeof(buf), PowDetachString);
2727 Msg(0, "pow_detach_msg is '%s'", buf);
2728 break;
2730 (void)ParseSaveStr(act, &PowDetachString);
2731 break;
2732 #endif
2733 #if defined(UTMPOK) && defined(LOGOUTOK)
2734 case RC_LOGIN:
2735 n = fore->w_slot != (slot_t)-1;
2736 if (*args && !strcmp(*args, "always"))
2738 fore->w_lflag = 3;
2739 if (!displays && n)
2740 SlotToggle(n);
2741 break;
2743 if (*args && !strcmp(*args, "attached"))
2745 fore->w_lflag = 1;
2746 if (!displays && n)
2747 SlotToggle(0);
2748 break;
2750 if (ParseSwitch(act, &n) == 0)
2751 SlotToggle(n);
2752 break;
2753 case RC_DEFLOGIN:
2754 if (!strcmp(*args, "always"))
2755 nwin_default.lflag |= 2;
2756 else if (!strcmp(*args, "attached"))
2757 nwin_default.lflag &= ~2;
2758 else
2759 (void)ParseOnOff(act, &nwin_default.lflag);
2760 break;
2761 #endif
2762 case RC_DEFFLOW:
2763 if (args[0] && args[1] && args[1][0] == 'i')
2765 iflag = 1;
2766 for (display = displays; display; display = display->d_next)
2768 if (!D_flow)
2769 continue;
2770 #if defined(TERMIO) || defined(POSIX)
2771 D_NewMode.tio.c_cc[VINTR] = D_OldMode.tio.c_cc[VINTR];
2772 D_NewMode.tio.c_lflag |= ISIG;
2773 #else /* TERMIO || POSIX */
2774 D_NewMode.m_tchars.t_intrc = D_OldMode.m_tchars.t_intrc;
2775 #endif /* TERMIO || POSIX */
2776 SetTTY(D_userfd, &D_NewMode);
2779 if (args[0] && args[0][0] == 'a')
2780 nwin_default.flowflag = FLOW_AUTOFLAG;
2781 else
2782 (void)ParseOnOff(act, &nwin_default.flowflag);
2783 break;
2784 case RC_DEFWRAP:
2785 (void)ParseOnOff(act, &nwin_default.wrap);
2786 break;
2787 case RC_DEFC1:
2788 (void)ParseOnOff(act, &nwin_default.c1);
2789 break;
2790 #ifdef COLOR
2791 case RC_DEFBCE:
2792 (void)ParseOnOff(act, &nwin_default.bce);
2793 break;
2794 #endif
2795 case RC_DEFGR:
2796 (void)ParseOnOff(act, &nwin_default.gr);
2797 break;
2798 case RC_DEFMONITOR:
2799 if (ParseOnOff(act, &n) == 0)
2800 nwin_default.monitor = (n == 0) ? MON_OFF : MON_ON;
2801 break;
2802 case RC_DEFSILENCE:
2803 if (ParseOnOff(act, &n) == 0)
2804 nwin_default.silence = (n == 0) ? SILENCE_OFF : SILENCE_ON;
2805 break;
2806 case RC_VERBOSE:
2807 if (!*args)
2808 Msg(0, "W%s echo command when creating windows.",
2809 VerboseCreate ? "ill" : "on't");
2810 else if (ParseOnOff(act, &n) == 0)
2811 VerboseCreate = n;
2812 break;
2813 case RC_HARDSTATUS:
2814 if (display)
2816 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
2817 RemoveStatus();
2819 if (args[0] && strcmp(args[0], "on") && strcmp(args[0], "off"))
2821 struct display *olddisplay = display;
2822 int old_use, new_use = -1;
2824 s = args[0];
2825 if (!strncmp(s, "always", 6))
2826 s += 6;
2827 if (!strcmp(s, "lastline"))
2828 new_use = HSTATUS_LASTLINE;
2829 else if (!strcmp(s, "ignore"))
2830 new_use = HSTATUS_IGNORE;
2831 else if (!strcmp(s, "message"))
2832 new_use = HSTATUS_MESSAGE;
2833 else if (!strcmp(args[0], "string"))
2835 if (!args[1])
2837 char buf[256];
2838 AddXChars(buf, sizeof(buf), hstatusstring);
2839 Msg(0, "hardstatus string is '%s'", buf);
2840 break;
2843 else
2845 Msg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name);
2846 break;
2848 if (new_use != -1)
2850 hardstatusemu = new_use | (s == args[0] ? 0 : HSTATUS_ALWAYS);
2851 for (display = displays; display; display = display->d_next)
2853 RemoveStatus();
2854 new_use = hardstatusemu & ~HSTATUS_ALWAYS;
2855 if (D_HS && s == args[0])
2856 new_use = HSTATUS_HS;
2857 ShowHStatus((char *)0);
2858 old_use = D_has_hstatus;
2859 D_has_hstatus = new_use;
2860 if ((new_use == HSTATUS_LASTLINE && old_use != HSTATUS_LASTLINE) || (new_use != HSTATUS_LASTLINE && old_use == HSTATUS_LASTLINE))
2861 ChangeScreenSize(D_width, D_height, 1);
2862 RefreshHStatus();
2865 if (args[1])
2867 if (hstatusstring)
2868 free(hstatusstring);
2869 hstatusstring = SaveStr(args[1]);
2870 for (display = displays; display; display = display->d_next)
2871 RefreshHStatus();
2873 display = olddisplay;
2874 break;
2876 (void)ParseSwitch(act, &use_hardstatus);
2877 if (msgok)
2878 Msg(0, "messages displayed on %s", use_hardstatus ? "hardstatus line" : "window");
2879 break;
2880 case RC_CAPTION:
2881 if (strcmp(args[0], "always") == 0 || strcmp(args[0], "splitonly") == 0)
2883 struct display *olddisplay = display;
2885 captionalways = args[0][0] == 'a';
2886 for (display = displays; display; display = display->d_next)
2887 ChangeScreenSize(D_width, D_height, 1);
2888 display = olddisplay;
2890 else if (strcmp(args[0], "string") == 0)
2892 if (!args[1])
2894 char buf[256];
2895 AddXChars(buf, sizeof(buf), captionstring);
2896 Msg(0, "caption string is '%s'", buf);
2897 break;
2900 else
2902 Msg(0, "%s: usage: caption always|splitonly|string <string>", rc_name);
2903 break;
2905 if (!args[1])
2906 break;
2907 if (captionstring)
2908 free(captionstring);
2909 captionstring = SaveStr(args[1]);
2910 RedisplayDisplays(0);
2911 break;
2912 case RC_CONSOLE:
2913 n = (console_window != 0);
2914 if (ParseSwitch(act, &n))
2915 break;
2916 if (TtyGrabConsole(fore->w_ptyfd, n, rc_name))
2917 break;
2918 if (n == 0)
2919 Msg(0, "%s: releasing console %s", rc_name, HostName);
2920 else if (console_window)
2921 Msg(0, "%s: stealing console %s from window %d (%s)", rc_name,
2922 HostName, console_window->w_number, console_window->w_title);
2923 else
2924 Msg(0, "%s: grabbing console %s", rc_name, HostName);
2925 console_window = n ? fore : 0;
2926 break;
2927 case RC_ALLPARTIAL:
2928 if (ParseOnOff(act, &all_norefresh))
2929 break;
2930 if (!all_norefresh && fore)
2931 Activate(-1);
2932 if (msgok)
2933 Msg(0, all_norefresh ? "No refresh on window change!\n" :
2934 "Window specific refresh\n");
2935 break;
2936 case RC_PARTIAL:
2937 (void)ParseSwitch(act, &n);
2938 fore->w_norefresh = n;
2939 break;
2940 case RC_VBELL:
2941 if (ParseSwitch(act, &visual_bell) || !msgok)
2942 break;
2943 if (visual_bell == 0)
2944 Msg(0, "switched to audible bell.");
2945 else
2946 Msg(0, "switched to visual bell.");
2947 break;
2948 case RC_VBELLWAIT:
2949 if (ParseNum1000(act, &VBellWait) == 0 && msgok)
2950 Msg(0, "vbellwait set to %.10g seconds", VBellWait/1000.);
2951 break;
2952 case RC_MSGWAIT:
2953 if (ParseNum1000(act, &MsgWait) == 0 && msgok)
2954 Msg(0, "msgwait set to %.10g seconds", MsgWait/1000.);
2955 break;
2956 case RC_MSGMINWAIT:
2957 if (ParseNum1000(act, &MsgMinWait) == 0 && msgok)
2958 Msg(0, "msgminwait set to %.10g seconds", MsgMinWait/1000.);
2959 break;
2960 case RC_SILENCEWAIT:
2961 if (ParseNum(act, &SilenceWait))
2962 break;
2963 if (SilenceWait < 1)
2964 SilenceWait = 1;
2965 for (p = windows; p; p = p->w_next)
2966 p->w_silencewait = SilenceWait;
2967 if (msgok)
2968 Msg(0, "silencewait set to %d seconds", SilenceWait);
2969 break;
2970 case RC_NUMBER:
2971 if (*args == 0)
2972 Msg(0, "This is window %d (%s).\n", fore->w_number, fore->w_title);
2973 else
2975 int old = fore->w_number;
2976 int rel = 0, parse;
2977 if (args[0][0] == '+')
2978 rel = 1;
2979 else if (args[0][0] == '-')
2980 rel = -1;
2981 if (rel)
2982 ++act->args[0];
2983 parse = ParseNum(act, &n);
2984 if (rel)
2985 --act->args[0];
2986 if (parse)
2987 break;
2988 if (rel > 0)
2989 n += old;
2990 else if (rel < 0)
2991 n = old - n;
2992 ChangeWinNum(old, n);
2994 break;
2995 case RC_SILENCE:
2996 n = fore->w_silence != 0;
2997 i = fore->w_silencewait;
2998 if (args[0] && (args[0][0] == '-' || (args[0][0] >= '0' && args[0][0] <= '9')))
3000 if (ParseNum(act, &i))
3001 break;
3002 n = i > 0;
3004 else if (ParseSwitch(act, &n))
3005 break;
3006 if (n)
3008 #ifdef MULTIUSER
3009 if (display) /* we tell only this user */
3010 ACLBYTE(fore->w_lio_notify, D_user->u_id) |= ACLBIT(D_user->u_id);
3011 else
3012 for (n = 0; n < maxusercount; n++)
3013 ACLBYTE(fore->w_lio_notify, n) |= ACLBIT(n);
3014 #endif
3015 fore->w_silencewait = i;
3016 fore->w_silence = SILENCE_ON;
3017 SetTimeout(&fore->w_silenceev, fore->w_silencewait * 1000);
3018 evenq(&fore->w_silenceev);
3020 if (!msgok)
3021 break;
3022 Msg(0, "The window is now being monitored for %d sec. silence.", fore->w_silencewait);
3024 else
3026 #ifdef MULTIUSER
3027 if (display) /* we remove only this user */
3028 ACLBYTE(fore->w_lio_notify, D_user->u_id)
3029 &= ~ACLBIT(D_user->u_id);
3030 else
3031 for (n = 0; n < maxusercount; n++)
3032 ACLBYTE(fore->w_lio_notify, n) &= ~ACLBIT(n);
3033 for (i = maxusercount - 1; i >= 0; i--)
3034 if (ACLBYTE(fore->w_lio_notify, i))
3035 break;
3036 if (i < 0)
3037 #endif
3039 fore->w_silence = SILENCE_OFF;
3040 evdeq(&fore->w_silenceev);
3042 if (!msgok)
3043 break;
3044 Msg(0, "The window is no longer being monitored for silence.");
3046 break;
3047 #ifdef COPY_PASTE
3048 case RC_DEFSCROLLBACK:
3049 (void)ParseNum(act, &nwin_default.histheight);
3050 break;
3051 case RC_SCROLLBACK:
3052 if (flayer->l_layfn == &MarkLf)
3054 Msg(0, "Cannot resize scrollback buffer in copy/scrollback mode.");
3055 break;
3057 (void)ParseNum(act, &n);
3058 ChangeWindowSize(fore, fore->w_width, fore->w_height, n);
3059 if (msgok)
3060 Msg(0, "scrollback set to %d", fore->w_histheight);
3061 break;
3062 #endif
3063 case RC_SESSIONNAME:
3064 if (*args == 0)
3065 Msg(0, "This session is named '%s'\n", SockName);
3066 else
3068 char buf[MAXPATHLEN];
3070 s = 0;
3071 if (ParseSaveStr(act, &s))
3072 break;
3073 if (!*s || strlen(s) + (SockName - SockPath) > MAXPATHLEN - 13 || index(s, '/'))
3075 Msg(0, "%s: bad session name '%s'\n", rc_name, s);
3076 free(s);
3077 break;
3079 strncpy(buf, SockPath, SockName - SockPath);
3080 sprintf(buf + (SockName - SockPath), "%d.%s", (int)getpid(), s);
3081 free(s);
3082 if ((access(buf, F_OK) == 0) || (errno != ENOENT))
3084 Msg(0, "%s: inappropriate path: '%s'.", rc_name, buf);
3085 break;
3087 if (rename(SockPath, buf))
3089 Msg(errno, "%s: failed to rename(%s, %s)", rc_name, SockPath, buf);
3090 break;
3092 debug2("rename(%s, %s) done\n", SockPath, buf);
3093 strcpy(SockPath, buf);
3094 MakeNewEnv();
3095 WindowChanged((struct win *)0, 'S');
3097 break;
3098 case RC_SETENV:
3099 if (!args[0] || !args[1])
3101 debug1("RC_SETENV arguments missing: %s\n", args[0] ? args[0] : "");
3102 InputSetenv(args[0]);
3104 else
3106 xsetenv(args[0], args[1]);
3107 MakeNewEnv();
3109 break;
3110 case RC_UNSETENV:
3111 unsetenv(*args);
3112 MakeNewEnv();
3113 break;
3114 #ifdef COPY_PASTE
3115 case RC_DEFSLOWPASTE:
3116 (void)ParseNum(act, &nwin_default.slow);
3117 break;
3118 case RC_SLOWPASTE:
3119 if (*args == 0)
3120 Msg(0, fore->w_slowpaste ?
3121 "Slowpaste in window %d is %d milliseconds." :
3122 "Slowpaste in window %d is unset.",
3123 fore->w_number, fore->w_slowpaste);
3124 else if (ParseNum(act, &fore->w_slowpaste) == 0 && msgok)
3125 Msg(0, fore->w_slowpaste ?
3126 "Slowpaste in window %d set to %d milliseconds." :
3127 "Slowpaste in window %d now unset.",
3128 fore->w_number, fore->w_slowpaste);
3129 break;
3130 case RC_MARKKEYS:
3131 if (CompileKeys(*args, *argl, mark_key_tab))
3133 Msg(0, "%s: markkeys: syntax error.", rc_name);
3134 break;
3136 debug1("markkeys %s\n", *args);
3137 break;
3138 # ifdef FONT
3139 case RC_PASTEFONT:
3140 if (ParseSwitch(act, &pastefont) == 0 && msgok)
3141 Msg(0, "Will %spaste font settings", pastefont ? "" : "not ");
3142 break;
3143 # endif
3144 case RC_CRLF:
3145 (void)ParseSwitch(act, &join_with_cr);
3146 break;
3147 case RC_COMPACTHIST:
3148 if (ParseSwitch(act, &compacthist) == 0 && msgok)
3149 Msg(0, "%scompacting history lines", compacthist ? "" : "not ");
3150 break;
3151 #endif
3152 #ifdef NETHACK
3153 case RC_NETHACK:
3154 (void)ParseOnOff(act, &nethackflag);
3155 break;
3156 #endif
3157 case RC_HARDCOPY_APPEND:
3158 (void)ParseOnOff(act, &hardcopy_append);
3159 break;
3160 case RC_VBELL_MSG:
3161 if (*args == 0)
3163 char buf[256];
3164 AddXChars(buf, sizeof(buf), VisualBellString);
3165 Msg(0, "vbell_msg is '%s'", buf);
3166 break;
3168 (void)ParseSaveStr(act, &VisualBellString);
3169 debug1(" new vbellstr '%s'\n", VisualBellString);
3170 break;
3171 case RC_DEFMODE:
3172 if (ParseBase(act, *args, &n, 8, "octal"))
3173 break;
3174 if (n < 0 || n > 0777)
3176 Msg(0, "%s: mode: Invalid tty mode %o", rc_name, n);
3177 break;
3179 TtyMode = n;
3180 if (msgok)
3181 Msg(0, "Ttymode set to %03o", TtyMode);
3182 break;
3183 case RC_AUTODETACH:
3184 (void)ParseOnOff(act, &auto_detach);
3185 break;
3186 case RC_STARTUP_MESSAGE:
3187 (void)ParseOnOff(act, &default_startup);
3188 break;
3189 #ifdef PASSWORD
3190 case RC_PASSWORD:
3191 if (*args)
3193 n = (*user->u_password) ? 1 : 0;
3194 if (user->u_password != NullStr) free((char *)user->u_password);
3195 user->u_password = SaveStr(*args);
3196 if (!strcmp(user->u_password, "none"))
3198 if (n)
3199 Msg(0, "Password checking disabled");
3200 free(user->u_password);
3201 user->u_password = NullStr;
3204 else
3206 if (!fore)
3208 Msg(0, "%s: password: window required", rc_name);
3209 break;
3211 Input("New screen password:", 100, INP_NOECHO, pass1, display ? (char *)D_user : (char *)users, 0);
3213 break;
3214 #endif /* PASSWORD */
3215 case RC_BIND:
3217 struct action *ktabp = ktab;
3218 int kflag = 0;
3220 for (;;)
3222 if (argc > 2 && !strcmp(*args, "-c"))
3224 ktabp = FindKtab(args[1], 1);
3225 if (ktabp == 0)
3226 break;
3227 args += 2;
3228 argl += 2;
3229 argc -= 2;
3231 else if (argc > 1 && !strcmp(*args, "-k"))
3233 kflag = 1;
3234 args++;
3235 argl++;
3236 argc--;
3238 else
3239 break;
3241 #ifdef MAPKEYS
3242 if (kflag)
3244 for (n = 0; n < KMAP_KEYS; n++)
3245 if (strcmp(term[n + T_CAPS].tcname, *args) == 0)
3246 break;
3247 if (n == KMAP_KEYS)
3249 Msg(0, "%s: bind: unknown key '%s'", rc_name, *args);
3250 break;
3252 n += 256;
3254 else
3255 #endif
3256 if (*argl != 1)
3258 Msg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name);
3259 break;
3261 else
3262 n = (unsigned char)args[0][0];
3264 if (args[1])
3266 if ((i = FindCommnr(args[1])) == RC_ILLEGAL)
3268 struct alias *alias = FindAlias(args[1]);
3269 if (!alias)
3271 Msg(0, "%s: bind: unknown command or alias '%s'", rc_name, args[1]);
3272 break;
3274 i = alias->nr;
3276 if (i <= RC_LAST && CheckArgNum(i, args + 2) < 0)
3277 break;
3278 ClearAction(&ktabp[n]);
3279 SaveAction(ktabp + n, i, args + 2, argl + 2);
3281 else
3282 ClearAction(&ktabp[n]);
3284 break;
3285 #ifdef MAPKEYS
3286 case RC_BINDKEY:
3288 struct action *newact;
3289 int newnr, fl = 0, kf = 0, af = 0, df = 0, mf = 0;
3290 struct display *odisp = display;
3291 int used = 0;
3292 struct kmap_ext *kme;
3294 for (; *args && **args == '-'; args++, argl++)
3296 if (strcmp(*args, "-t") == 0)
3297 fl = KMAP_NOTIMEOUT;
3298 else if (strcmp(*args, "-k") == 0)
3299 kf = 1;
3300 else if (strcmp(*args, "-a") == 0)
3301 af = 1;
3302 else if (strcmp(*args, "-d") == 0)
3303 df = 1;
3304 else if (strcmp(*args, "-m") == 0)
3305 mf = 1;
3306 else if (strcmp(*args, "--") == 0)
3308 args++;
3309 argl++;
3310 break;
3312 else
3314 Msg(0, "%s: bindkey: invalid option %s", rc_name, *args);
3315 return;
3318 if (df && mf)
3320 Msg(0, "%s: bindkey: -d does not work with -m", rc_name);
3321 break;
3323 if (*args == 0)
3325 if (mf)
3326 display_bindkey("Edit mode", mmtab);
3327 else if (df)
3328 display_bindkey("Default", dmtab);
3329 else
3330 display_bindkey("User", umtab);
3331 break;
3333 if (kf == 0)
3335 if (af)
3337 Msg(0, "%s: bindkey: -a only works with -k", rc_name);
3338 break;
3340 if (*argl == 0)
3342 Msg(0, "%s: bindkey: empty string makes no sense", rc_name);
3343 break;
3345 for (i = 0, kme = kmap_exts; i < kmap_extn; i++, kme++)
3346 if (kme->str == 0)
3348 if (args[1])
3349 break;
3351 else
3352 if (*argl == (kme->fl & ~KMAP_NOTIMEOUT) && bcmp(kme->str, *args, *argl) == 0)
3353 break;
3354 if (i == kmap_extn)
3356 if (!args[1])
3358 Msg(0, "%s: bindkey: keybinding not found", rc_name);
3359 break;
3361 kmap_extn += 8;
3362 kmap_exts = (struct kmap_ext *)xrealloc((char *)kmap_exts, kmap_extn * sizeof(*kmap_exts));
3363 kme = kmap_exts + i;
3364 bzero((char *)kme, 8 * sizeof(*kmap_exts));
3365 for (; i < kmap_extn; i++, kme++)
3367 kme->str = 0;
3368 kme->dm.nr = kme->mm.nr = kme->um.nr = RC_ILLEGAL;
3369 kme->dm.args = kme->mm.args = kme->um.args = noargs;
3371 i -= 8;
3372 kme -= 8;
3374 if (df == 0 && kme->dm.nr != RC_ILLEGAL)
3375 used = 1;
3376 if (mf == 0 && kme->mm.nr != RC_ILLEGAL)
3377 used = 1;
3378 if ((df || mf) && kme->um.nr != RC_ILLEGAL)
3379 used = 1;
3380 i += KMAP_KEYS + KMAP_AKEYS;
3381 newact = df ? &kme->dm : mf ? &kme->mm : &kme->um;
3383 else
3385 for (i = T_CAPS; i < T_OCAPS; i++)
3386 if (strcmp(term[i].tcname, *args) == 0)
3387 break;
3388 if (i == T_OCAPS)
3390 Msg(0, "%s: bindkey: unknown key '%s'", rc_name, *args);
3391 break;
3393 if (af && i >= T_CURSOR && i < T_OCAPS)
3394 i -= T_CURSOR - KMAP_KEYS;
3395 else
3396 i -= T_CAPS;
3397 newact = df ? &dmtab[i] : mf ? &mmtab[i] : &umtab[i];
3399 if (args[1])
3401 if ((newnr = FindCommnr(args[1])) == RC_ILLEGAL)
3403 struct alias *alias = FindAlias(args[1]);
3404 if (!alias)
3406 Msg(0, "%s: bindkey: unknown command or alias '%s'", rc_name, args[1]);
3407 break;
3409 newnr = alias->nr;
3411 if (newnr <= RC_LAST && CheckArgNum(newnr, args + 2) < 0)
3412 break;
3413 ClearAction(newact);
3414 SaveAction(newact, newnr, args + 2, argl + 2);
3415 if (kf == 0 && args[1])
3417 if (kme->str)
3418 free(kme->str);
3419 kme->str = SaveStrn(*args, *argl);
3420 kme->fl = fl | *argl;
3423 else
3424 ClearAction(newact);
3425 for (display = displays; display; display = display->d_next)
3426 remap(i, args[1] ? 1 : 0);
3427 if (kf == 0 && !args[1])
3429 if (!used && kme->str)
3431 free(kme->str);
3432 kme->str = 0;
3433 kme->fl = 0;
3436 display = odisp;
3438 break;
3439 case RC_MAPTIMEOUT:
3440 if (*args)
3442 if (ParseNum(act, &n))
3443 break;
3444 if (n < 0)
3446 Msg(0, "%s: maptimeout: illegal time %d", rc_name, n);
3447 break;
3449 maptimeout = n;
3451 if (*args == 0 || msgok)
3452 Msg(0, "maptimeout is %dms", maptimeout);
3453 break;
3454 case RC_MAPNOTNEXT:
3455 D_dontmap = 1;
3456 break;
3457 case RC_MAPDEFAULT:
3458 D_mapdefault = 1;
3459 break;
3460 #endif
3461 #ifdef MULTIUSER
3462 case RC_ACLCHG:
3463 case RC_ACLADD:
3464 case RC_ADDACL:
3465 case RC_CHACL:
3466 UsersAcl(NULL, argc, args);
3467 break;
3468 case RC_ACLDEL:
3469 if (UserDel(args[0], NULL))
3470 break;
3471 if (msgok)
3472 Msg(0, "%s removed from acl database", args[0]);
3473 break;
3474 case RC_ACLGRP:
3476 * modify a user to gain or lose rights granted to a group.
3477 * This group is actually a normal user whose rights were defined
3478 * with chacl in the usual way.
3480 if (args[1])
3482 if (strcmp(args[1], "none")) /* link a user to another user */
3484 if (AclLinkUser(args[0], args[1]))
3485 break;
3486 if (msgok)
3487 Msg(0, "User %s joined acl-group %s", args[0], args[1]);
3489 else /* remove all groups from user */
3491 struct acluser *u;
3492 struct aclusergroup *g;
3494 if (!(u = *FindUserPtr(args[0])))
3495 break;
3496 while ((g = u->u_group))
3498 u->u_group = g->next;
3499 free((char *)g);
3503 else /* show all groups of user */
3505 char buf[256], *p = buf;
3506 int ngroups = 0;
3507 struct acluser *u;
3508 struct aclusergroup *g;
3510 if (!(u = *FindUserPtr(args[0])))
3512 if (msgok)
3513 Msg(0, "User %s does not exist.", args[0]);
3514 break;
3516 g = u->u_group;
3517 while (g)
3519 ngroups++;
3520 sprintf(p, "%s ", g->u->u_name);
3521 p += strlen(p);
3522 if (p > buf+200)
3523 break;
3524 g = g->next;
3526 if (ngroups)
3527 *(--p) = '\0';
3528 Msg(0, "%s's group%s: %s.", args[0], (ngroups == 1) ? "" : "s",
3529 (ngroups == 0) ? "none" : buf);
3531 break;
3532 case RC_ACLUMASK:
3533 case RC_UMASK:
3534 while ((s = *args++))
3536 char *err = 0;
3538 if (AclUmask(display ? D_user : users, s, &err))
3539 Msg(0, "umask: %s\n", err);
3541 break;
3542 case RC_MULTIUSER:
3543 if (ParseOnOff(act, &n))
3544 break;
3545 multi = n ? "" : 0;
3546 chsock();
3547 if (msgok)
3548 Msg(0, "Multiuser mode %s", multi ? "enabled" : "disabled");
3549 break;
3550 #endif /* MULTIUSER */
3551 #ifdef PSEUDOS
3552 case RC_EXEC:
3553 winexec(args);
3554 break;
3555 #endif
3556 #ifdef MULTI
3557 case RC_NONBLOCK:
3558 i = D_nonblock >= 0;
3559 if (*args && ((args[0][0] >= '0' && args[0][0] <= '9') || args[0][0] == '.'))
3561 if (ParseNum1000(act, &i))
3562 break;
3564 else if (!ParseSwitch(act, &i))
3565 i = i == 0 ? -1 : 1000;
3566 else
3567 break;
3568 if (msgok && i == -1)
3569 Msg(0, "display set to blocking mode");
3570 else if (msgok && i == 0)
3571 Msg(0, "display set to nonblocking mode, no timeout");
3572 else if (msgok)
3573 Msg(0, "display set to nonblocking mode, %.10gs timeout", i/1000.);
3574 D_nonblock = i;
3575 if (D_nonblock <= 0)
3576 evdeq(&D_blockedev);
3577 break;
3578 case RC_DEFNONBLOCK:
3579 if (*args && ((args[0][0] >= '0' && args[0][0] <= '9') || args[0][0] == '.'))
3581 if (ParseNum1000(act, &defnonblock))
3582 break;
3584 else if (!ParseOnOff(act, &defnonblock))
3585 defnonblock = defnonblock == 0 ? -1 : 1000;
3586 else
3587 break;
3588 if (display && *rc_name)
3590 D_nonblock = defnonblock;
3591 if (D_nonblock <= 0)
3592 evdeq(&D_blockedev);
3594 break;
3595 #endif
3596 case RC_GR:
3597 #ifdef ENCODINGS
3598 if (fore->w_gr == 2)
3599 fore->w_gr = 0;
3600 #endif
3601 if (ParseSwitch(act, &fore->w_gr) == 0 && msgok)
3602 Msg(0, "Will %suse GR", fore->w_gr ? "" : "not ");
3603 #ifdef ENCODINGS
3604 if (fore->w_gr == 0 && fore->w_FontE)
3605 fore->w_gr = 2;
3606 #endif
3607 break;
3608 case RC_C1:
3609 if (ParseSwitch(act, &fore->w_c1) == 0 && msgok)
3610 Msg(0, "Will %suse C1", fore->w_c1 ? "" : "not ");
3611 break;
3612 #ifdef COLOR
3613 case RC_BCE:
3614 if (ParseSwitch(act, &fore->w_bce) == 0 && msgok)
3615 Msg(0, "Will %serase with background color", fore->w_bce ? "" : "not ");
3616 break;
3617 #endif
3618 #ifdef ENCODINGS
3619 case RC_KANJI:
3620 case RC_ENCODING:
3621 #ifdef UTF8
3622 if (*args && !strcmp(args[0], "-d"))
3624 if (!args[1])
3625 Msg(0, "encodings directory is %s", screenencodings ? screenencodings : "<unset>");
3626 else