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 static void AddAlias
__P((const char *name
, const char *val
, char **args
, int *argl
, int count
));
166 static struct alias
* FindAlias
__P((const char *name
));
167 static struct alias
* FindAliasnr
__P((int));
168 static void DelAlias
__P((const char *name
));
169 static int DoAlias
__P((char **, int *));
171 extern struct layer
*flayer
;
172 extern struct display
*display
, *displays
;
173 extern struct win
*fore
, *console_window
, *windows
;
174 extern struct acluser
*users
;
175 extern struct layout
*layouts
, *layout_attach
, layout_last_marker
;
176 extern struct layout
*laytab
[];
178 extern char screenterm
[], HostName
[], version
[];
179 extern struct NewWindow nwin_undef
, nwin_default
;
180 extern struct LayFuncs WinLf
, MarkLf
;
182 extern int Z0width
, Z1width
;
183 extern int real_uid
, real_gid
;
186 extern int nethackflag
;
190 struct win
*wtab
[MAXWIN
]; /* window table, should be dynamic */
194 extern int maxusercount
;
198 struct plop plop_tab
[MAX_PLOP_DEFS
];
201 # define PTYMODE 0622
204 int TtyMode
= PTYMODE
;
205 int hardcopy_append
= 0;
206 int all_norefresh
= 0;
209 char *zmodem_sendcmd
;
210 char *zmodem_recvcmd
;
211 static char *zmodes
[4] = {"off", "auto", "catch", "pass"};
215 struct action idleaction
;
220 struct action ktab
[256 + KMAP_KEYS
]; /* command key translation table */
224 struct action ktab
[256 + KMAP_KEYS
];
226 struct kclass
*kclasses
;
229 struct action umtab
[KMAP_KEYS
+KMAP_AKEYS
];
230 struct action dmtab
[KMAP_KEYS
+KMAP_AKEYS
];
231 struct action mmtab
[KMAP_KEYS
+KMAP_AKEYS
];
232 struct kmap_ext
*kmap_exts
;
234 static int maptimeout
= 300;
243 char *name
; /* Name of the alias */
244 int cmdnr
; /* Number of the command this is alias for */
245 char **args
; /* The argument list for the command */
249 struct alias
*g_aliases_list
= NULL
;
252 /* digraph table taken from old vim and rfc1345 */
253 static const unsigned char digraphs
[][3] = {
254 {' ', ' ', 160}, /* */
255 {'N', 'S', 160}, /* */
256 {'~', '!', 161}, /* ¡ */
257 {'!', '!', 161}, /* ¡ */
258 {'!', 'I', 161}, /* ¡ */
259 {'c', '|', 162}, /* ¢ */
260 {'c', 't', 162}, /* ¢ */
261 {'$', '$', 163}, /* £ */
262 {'P', 'd', 163}, /* £ */
263 {'o', 'x', 164}, /* ¤ */
264 {'C', 'u', 164}, /* ¤ */
265 {'C', 'u', 164}, /* ¤ */
266 {'E', 'u', 164}, /* ¤ */
267 {'Y', '-', 165}, /* ¥ */
268 {'Y', 'e', 165}, /* ¥ */
269 {'|', '|', 166}, /* ¦ */
270 {'B', 'B', 166}, /* ¦ */
271 {'p', 'a', 167}, /* § */
272 {'S', 'E', 167}, /* § */
273 {'"', '"', 168}, /* ¨ */
274 {'\'', ':', 168}, /* ¨ */
275 {'c', 'O', 169}, /* © */
276 {'C', 'o', 169}, /* © */
277 {'a', '-', 170}, /* ª */
278 {'<', '<', 171}, /* « */
279 {'-', ',', 172}, /* ¬ */
280 {'N', 'O', 172}, /* ¬ */
281 {'-', '-', 173}, /* */
282 {'r', 'O', 174}, /* ® */
283 {'R', 'g', 174}, /* ® */
284 {'-', '=', 175}, /* ¯ */
285 {'\'', 'm', 175}, /* ¯ */
286 {'~', 'o', 176}, /* ° */
287 {'D', 'G', 176}, /* ° */
288 {'+', '-', 177}, /* ± */
289 {'2', '2', 178}, /* ² */
290 {'2', 'S', 178}, /* ² */
291 {'3', '3', 179}, /* ³ */
292 {'3', 'S', 179}, /* ³ */
293 {'\'', '\'', 180}, /* ´ */
294 {'j', 'u', 181}, /* µ */
295 {'M', 'y', 181}, /* µ */
296 {'p', 'p', 182}, /* ¶ */
297 {'P', 'I', 182}, /* ¶ */
298 {'~', '.', 183}, /* · */
299 {'.', 'M', 183}, /* · */
300 {',', ',', 184}, /* ¸ */
301 {'\'', ',', 184}, /* ¸ */
302 {'1', '1', 185}, /* ¹ */
303 {'1', 'S', 185}, /* ¹ */
304 {'o', '-', 186}, /* º */
305 {'>', '>', 187}, /* » */
306 {'1', '4', 188}, /* ¼ */
307 {'1', '2', 189}, /* ½ */
308 {'3', '4', 190}, /* ¾ */
309 {'~', '?', 191}, /* ¿ */
310 {'?', '?', 191}, /* ¿ */
311 {'?', 'I', 191}, /* ¿ */
312 {'A', '`', 192}, /* À */
313 {'A', '!', 192}, /* À */
314 {'A', '\'', 193}, /* Á */
315 {'A', '^', 194}, /* Â */
316 {'A', '>', 194}, /* Â */
317 {'A', '~', 195}, /* Ã */
318 {'A', '?', 195}, /* Ã */
319 {'A', '"', 196}, /* Ä */
320 {'A', ':', 196}, /* Ä */
321 {'A', '@', 197}, /* Å */
322 {'A', 'A', 197}, /* Å */
323 {'A', 'E', 198}, /* Æ */
324 {'C', ',', 199}, /* Ç */
325 {'E', '`', 200}, /* È */
326 {'E', '!', 200}, /* È */
327 {'E', '\'', 201}, /* É */
328 {'E', '^', 202}, /* Ê */
329 {'E', '>', 202}, /* Ê */
330 {'E', '"', 203}, /* Ë */
331 {'E', ':', 203}, /* Ë */
332 {'I', '`', 204}, /* Ì */
333 {'I', '!', 204}, /* Ì */
334 {'I', '\'', 205}, /* Í */
335 {'I', '^', 206}, /* Î */
336 {'I', '>', 206}, /* Î */
337 {'I', '"', 207}, /* Ï */
338 {'I', ':', 207}, /* Ï */
339 {'D', '-', 208}, /* Ð */
340 {'N', '~', 209}, /* Ñ */
341 {'N', '?', 209}, /* Ñ */
342 {'O', '`', 210}, /* Ò */
343 {'O', '!', 210}, /* Ò */
344 {'O', '\'', 211}, /* Ó */
345 {'O', '^', 212}, /* Ô */
346 {'O', '>', 212}, /* Ô */
347 {'O', '~', 213}, /* Õ */
348 {'O', '?', 213}, /* Õ */
349 {'O', '"', 214}, /* Ö */
350 {'O', ':', 214}, /* Ö */
351 {'/', '\\', 215}, /* × */
352 {'*', 'x', 215}, /* × */
353 {'O', '/', 216}, /* Ø */
354 {'U', '`', 217}, /* Ù */
355 {'U', '!', 217}, /* Ù */
356 {'U', '\'', 218}, /* Ú */
357 {'U', '^', 219}, /* Û */
358 {'U', '>', 219}, /* Û */
359 {'U', '"', 220}, /* Ü */
360 {'U', ':', 220}, /* Ü */
361 {'Y', '\'', 221}, /* Ý */
362 {'I', 'p', 222}, /* Þ */
363 {'T', 'H', 222}, /* Þ */
364 {'s', 's', 223}, /* ß */
365 {'s', '"', 223}, /* ß */
366 {'a', '`', 224}, /* à */
367 {'a', '!', 224}, /* à */
368 {'a', '\'', 225}, /* á */
369 {'a', '^', 226}, /* â */
370 {'a', '>', 226}, /* â */
371 {'a', '~', 227}, /* ã */
372 {'a', '?', 227}, /* ã */
373 {'a', '"', 228}, /* ä */
374 {'a', ':', 228}, /* ä */
375 {'a', 'a', 229}, /* å */
376 {'a', 'e', 230}, /* æ */
377 {'c', ',', 231}, /* ç */
378 {'e', '`', 232}, /* è */
379 {'e', '!', 232}, /* è */
380 {'e', '\'', 233}, /* é */
381 {'e', '^', 234}, /* ê */
382 {'e', '>', 234}, /* ê */
383 {'e', '"', 235}, /* ë */
384 {'e', ':', 235}, /* ë */
385 {'i', '`', 236}, /* ì */
386 {'i', '!', 236}, /* ì */
387 {'i', '\'', 237}, /* í */
388 {'i', '^', 238}, /* î */
389 {'i', '>', 238}, /* î */
390 {'i', '"', 239}, /* ï */
391 {'i', ':', 239}, /* ï */
392 {'d', '-', 240}, /* ð */
393 {'n', '~', 241}, /* ñ */
394 {'n', '?', 241}, /* ñ */
395 {'o', '`', 242}, /* ò */
396 {'o', '!', 242}, /* ò */
397 {'o', '\'', 243}, /* ó */
398 {'o', '^', 244}, /* ô */
399 {'o', '>', 244}, /* ô */
400 {'o', '~', 245}, /* õ */
401 {'o', '?', 245}, /* õ */
402 {'o', '"', 246}, /* ö */
403 {'o', ':', 246}, /* ö */
404 {':', '-', 247}, /* ÷ */
405 {'o', '/', 248}, /* ø */
406 {'u', '`', 249}, /* ù */
407 {'u', '!', 249}, /* ù */
408 {'u', '\'', 250}, /* ú */
409 {'u', '^', 251}, /* û */
410 {'u', '>', 251}, /* û */
411 {'u', '"', 252}, /* ü */
412 {'u', ':', 252}, /* ü */
413 {'y', '\'', 253}, /* ý */
414 {'i', 'p', 254}, /* þ */
415 {'t', 'h', 254}, /* þ */
416 {'y', '"', 255}, /* ÿ */
417 {'y', ':', 255}, /* ÿ */
418 {'"', '[', 196}, /* Ä */
419 {'"', '\\', 214}, /* Ö */
420 {'"', ']', 220}, /* Ü */
421 {'"', '{', 228}, /* ä */
422 {'"', '|', 246}, /* ö */
423 {'"', '}', 252}, /* ü */
424 {'"', '~', 223} /* ß */
427 #define RESIZE_FLAG_H 1
428 #define RESIZE_FLAG_V 2
429 #define RESIZE_FLAG_L 4
431 static char *resizeprompts
[] = {
433 "resize -h # lines: ",
434 "resize -v # lines: ",
435 "resize -b # lines: ",
436 "resize -l # lines: ",
437 "resize -l -h # lines: ",
438 "resize -l -v # lines: ",
439 "resize -l -b # lines: ",
447 register unsigned int i
;
452 for (i
= 0; i
< sizeof(ktab
)/sizeof(*ktab
); i
++)
454 ktab
[i
].nr
= RC_ILLEGAL
;
455 ktab
[i
].args
= noargs
;
459 for (i
= 0; i
< KMAP_KEYS
+KMAP_AKEYS
; i
++)
461 umtab
[i
].nr
= RC_ILLEGAL
;
462 umtab
[i
].args
= noargs
;
464 dmtab
[i
].nr
= RC_ILLEGAL
;
465 dmtab
[i
].args
= noargs
;
467 mmtab
[i
].nr
= RC_ILLEGAL
;
468 mmtab
[i
].args
= noargs
;
472 for (i
= 0; i
< NKMAPDEF
; i
++)
474 if (i
+ KMAPDEFSTART
< T_CAPS
)
476 if (i
+ KMAPDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
480 argarr
[0] = kmapdef
[i
];
481 SaveAction(dmtab
+ i
+ (KMAPDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
483 for (i
= 0; i
< NKMAPADEF
; i
++)
485 if (i
+ KMAPADEFSTART
< T_CURSOR
)
487 if (i
+ KMAPADEFSTART
>= T_CURSOR
+ KMAP_AKEYS
)
489 if (kmapadef
[i
] == 0)
491 argarr
[0] = kmapadef
[i
];
492 SaveAction(dmtab
+ i
+ (KMAPADEFSTART
- T_CURSOR
+ KMAP_KEYS
), RC_STUFF
, argarr
, 0);
494 for (i
= 0; i
< NKMAPMDEF
; i
++)
496 if (i
+ KMAPMDEFSTART
< T_CAPS
)
498 if (i
+ KMAPMDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
500 if (kmapmdef
[i
] == 0)
502 argarr
[0] = kmapmdef
[i
];
504 SaveAction(mmtab
+ i
+ (KMAPMDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
508 ktab
['h'].nr
= RC_HARDCOPY
;
510 ktab
['z'].nr
= ktab
[Ctrl('z')].nr
= RC_SUSPEND
;
512 ktab
['c'].nr
= ktab
[Ctrl('c')].nr
= RC_SCREEN
;
513 ktab
[' '].nr
= ktab
[Ctrl(' ')].nr
=
514 ktab
['n'].nr
= ktab
[Ctrl('n')].nr
= RC_NEXT
;
515 ktab
['N'].nr
= RC_NUMBER
;
516 ktab
[Ctrl('h')].nr
= ktab
[0177].nr
= ktab
['p'].nr
= ktab
[Ctrl('p')].nr
= RC_PREV
;
517 ktab
['k'].nr
= ktab
[Ctrl('k')].nr
= RC_KILL
;
518 ktab
['l'].nr
= ktab
[Ctrl('l')].nr
= RC_REDISPLAY
;
519 ktab
['w'].nr
= ktab
[Ctrl('w')].nr
= RC_WINDOWS
;
520 ktab
['v'].nr
= RC_VERSION
;
521 ktab
[Ctrl('v')].nr
= RC_DIGRAPH
;
522 ktab
['q'].nr
= ktab
[Ctrl('q')].nr
= RC_XON
;
523 ktab
['s'].nr
= ktab
[Ctrl('s')].nr
= RC_XOFF
;
524 ktab
['t'].nr
= ktab
[Ctrl('t')].nr
= RC_TIME
;
525 ktab
['i'].nr
= ktab
[Ctrl('i')].nr
= RC_INFO
;
526 ktab
['m'].nr
= ktab
[Ctrl('m')].nr
= RC_LASTMSG
;
527 ktab
['A'].nr
= RC_TITLE
;
528 #if defined(UTMPOK) && defined(LOGOUTOK)
529 ktab
['L'].nr
= RC_LOGIN
;
531 ktab
[','].nr
= RC_LICENSE
;
532 ktab
['W'].nr
= RC_WIDTH
;
533 ktab
['.'].nr
= RC_DUMPTERMCAP
;
534 ktab
[Ctrl('\\')].nr
= RC_QUIT
;
536 ktab
['d'].nr
= ktab
[Ctrl('d')].nr
= RC_DETACH
;
538 ktab
['D'].nr
= RC_POW_DETACH
;
541 ktab
['r'].nr
= ktab
[Ctrl('r')].nr
= RC_WRAP
;
542 ktab
['f'].nr
= ktab
[Ctrl('f')].nr
= RC_FLOW
;
543 ktab
['C'].nr
= RC_CLEAR
;
544 ktab
['Z'].nr
= RC_RESET
;
545 ktab
['H'].nr
= RC_LOG
;
546 ktab
['M'].nr
= RC_MONITOR
;
547 ktab
['?'].nr
= RC_HELP
;
549 ktab
['*'].nr
= RC_DISPLAYS
;
555 SaveAction(ktab
+ '-', RC_SELECT
, args
, 0);
557 for (i
= 0; i
< ((MAXWIN
< 10) ? MAXWIN
: 10); i
++)
559 char *args
[2], arg1
[10];
562 sprintf(arg1
, "%d", i
);
563 SaveAction(ktab
+ '0' + i
, RC_SELECT
, args
, 0);
565 ktab
['\''].nr
= RC_SELECT
; /* calling a window by name */
570 SaveAction(ktab
+ '"', RC_WINDOWLIST
, args
, 0);
572 ktab
[Ctrl('G')].nr
= RC_VBELL
;
573 ktab
[':'].nr
= RC_COLON
;
575 ktab
['['].nr
= ktab
[Ctrl('[')].nr
= RC_COPY
;
580 SaveAction(ktab
+ ']', RC_PASTE
, args
, 0);
581 SaveAction(ktab
+ Ctrl(']'), RC_PASTE
, args
, 0);
583 ktab
['{'].nr
= RC_HISTORY
;
584 ktab
['}'].nr
= RC_HISTORY
;
585 ktab
['>'].nr
= RC_WRITEBUF
;
586 ktab
['<'].nr
= RC_READBUF
;
587 ktab
['='].nr
= RC_REMOVEBUF
;
590 ktab
['D'].nr
= RC_POW_DETACH
;
593 ktab
['x'].nr
= ktab
[Ctrl('x')].nr
= RC_LOCKSCREEN
;
595 ktab
['b'].nr
= ktab
[Ctrl('b')].nr
= RC_BREAK
;
596 ktab
['B'].nr
= RC_POW_BREAK
;
597 ktab
['_'].nr
= RC_SILENCE
;
598 ktab
['S'].nr
= RC_SPLIT
;
599 ktab
['Q'].nr
= RC_ONLY
;
600 ktab
['X'].nr
= RC_REMOVE
;
601 ktab
['F'].nr
= RC_FIT
;
602 ktab
['\t'].nr
= RC_FOCUS
;
607 SaveAction(ktab
+ T_BACKTAB
- T_CAPS
+ 256, RC_FOCUS
, args
, 0);
613 SaveAction(ktab
+ '|', RC_SPLIT
, args
, 0);
615 /* These come last; they may want overwrite others: */
618 ClearAction(&ktab
[DefaultEsc
]);
619 ktab
[DefaultEsc
].nr
= RC_OTHER
;
621 if (DefaultMetaEsc
>= 0)
623 ClearAction(&ktab
[DefaultMetaEsc
]);
624 ktab
[DefaultMetaEsc
].nr
= RC_META
;
627 idleaction
.nr
= RC_BLANKER
;
628 idleaction
.args
= noargs
;
632 static struct action
*
633 FindKtab(class, create
)
637 struct kclass
*kp
, **kpp
;
642 for (kpp
= &kclasses
; (kp
= *kpp
) != 0; kpp
= &kp
->next
)
643 if (!strcmp(kp
->name
, class))
649 if (strlen(class) > 80)
651 Msg(0, "Command class name too long.");
654 kp
= malloc(sizeof(*kp
));
660 kp
->name
= SaveStr(class);
661 for (i
= 0; i
< (int)(sizeof(kp
->ktab
)/sizeof(*kp
->ktab
)); i
++)
663 kp
->ktab
[i
].nr
= RC_ILLEGAL
;
664 kp
->ktab
[i
].args
= noargs
;
678 if (act
->nr
== RC_ILLEGAL
)
680 act
->nr
= RC_ILLEGAL
;
681 if (act
->args
== noargs
)
683 for (p
= act
->args
; *p
; p
++)
685 free((char *)act
->args
);
691 * ProcessInput: process input from display and feed it into
692 * the layer on canvas D_forecv.
698 * This ProcessInput just does the keybindings and passes
699 * everything else on to ProcessInput2.
703 ProcessInput(ibuf
, ilen
)
708 unsigned char *s
, *q
;
712 debug1("ProcessInput: %d bytes\n", ilen
);
713 if (display
== 0 || ilen
== 0)
718 s
= (unsigned char *)ibuf
;
722 if (D_dontmap
|| !D_nseqs
)
729 debug3("cmp %c %c[%d]\n", ch
, *D_seqp
, D_seqp
- D_kmaps
);
732 l
= D_seqp
[D_seqp
[-D_seql
-1] + 1];
736 debug1("miss %d\n", D_seqp
- D_kmaps
);
739 debug("complete miss\n");
742 p
= (char *)D_seqp
- l
;
744 D_seqp
= D_kmaps
+ 3;
747 if ((q
= D_seqh
) != 0)
750 i
= q
[0] << 8 | q
[1];
751 i
&= ~KMAP_NOTIMEOUT
;
752 debug1("Mapping former hit #%d - ", i
);
753 debug2("%d(%s) - ", q
[2], q
+ 3);
755 ProcessInput2((char *)q
+ 3, q
[2]);
763 debug1("flush old %d\n", l
);
772 /* Finish old stuff */
774 debug1("finish old %d\n", slen
);
776 ProcessInput2(ibuf
, slen
);
785 debug2("length am %d, want %d\n", l
, D_seqp
[-l
- 1]);
786 if (l
== D_seqp
[-l
- 1])
791 if (D_kmaps
+ D_nseqs
> q
&& q
[2] > l
&& !bcmp(D_seqp
- l
, q
+ 3, l
))
793 debug1("have another mapping (%s), delay execution\n", q
+ 3);
794 D_seqh
= D_seqp
- 3 - l
;
799 i
= D_seqp
[-l
- 3] << 8 | D_seqp
[-l
- 2];
800 i
&= ~KMAP_NOTIMEOUT
;
801 debug1("Mapping #%d - ", i
);
802 p
= (char *)D_seqp
- l
;
803 debug2("%d(%s) - ", l
, p
);
805 D_seqp
= D_kmaps
+ 3;
817 debug("am in sequence -> check for timeout\n");
819 for (s
= D_seqp
; ; s
+= i
* 2 + 4)
821 if (s
[-l
-3] & KMAP_NOTIMEOUT
>> 8)
823 if ((i
= s
[s
[-l
-1] + 1]) == 0)
825 SetTimeout(&D_mapev
, maptimeout
);
831 ProcessInput2(ibuf
, slen
);
835 # define ProcessInput2 ProcessInput
840 * Here only the screen escape commands are handled.
844 ProcessInput2(ibuf
, ilen
)
850 struct action
*ktabp
;
852 debug1("ProcessInput2: %d bytes\n", ilen
);
853 while (ilen
&& display
)
855 debug1(" - ilen now %d bytes\n", ilen
);
856 flayer
= D_forecv
->c_layer
;
864 if ((unsigned char)*s
++ == D_user
->u_Esc
)
870 DoProcess(fore
, &ibuf
, &slen
, 0);
876 ktabp
= D_ESCseen
? D_ESCseen
: ktab
;
878 ch
= (unsigned char)*s
;
881 * As users have different esc characters, but a common ktab[],
882 * we fold back the users esc and meta-esc key to the Default keys
883 * that can be looked up in the ktab[]. grmbl. jw.
884 * XXX: make ktab[] a per user thing.
886 if (ch
== D_user
->u_Esc
)
888 else if (ch
== D_user
->u_MetaEsc
)
892 DoAction(&ktabp
[ch
], ch
);
893 ibuf
= (char *)(s
+ 1);
899 DoProcess(p
, bufp
, lenp
, pa
)
906 struct display
*d
= display
;
909 /* XXX -> PasteStart */
910 if (pa
&& *lenp
> 1 && p
&& p
->w_slowpaste
)
912 /* schedule slowpaste event */
913 SetTimeout(&p
->w_paster
.pa_slowev
, p
->w_slowpaste
);
914 evenq(&p
->w_paster
.pa_slowev
);
918 while (flayer
&& *lenp
)
921 if (!pa
&& p
&& p
->w_paster
.pa_pastelen
&& flayer
== p
->w_paster
.pa_pastelayer
)
923 debug("layer is busy - beep!\n");
924 WBell(p
, visual_bell
);
932 LayProcess(bufp
, lenp
);
934 if (pa
&& !pa
->pa_pastelayer
)
935 break; /* flush rest of paste */
944 /* We're full, let's beep */
945 debug("layer is full - beep!\n");
946 WBell(p
, visual_bell
);
954 if (pa
&& pa
->pa_pastelen
== 0)
963 int x
, m
, l
= 0, r
= RC_LAST
;
967 x
= strcmp(str
, comms
[m
].name
);
979 CheckArgNum(nr
, args
)
984 static char *argss
[] = {"no", "one", "two", "three", "four", "OOPS"};
985 static char *orformat
[] =
987 "%s: %s: %s argument%s required",
988 "%s: %s: %s or %s argument%s required",
989 "%s: %s: %s, %s or %s argument%s required",
990 "%s: %s: %s, %s, %s or %s argument%s required"
993 n
= comms
[nr
].flags
& ARGS_MASK
;
994 for (i
= 0; args
[i
]; i
++)
996 if (comms
[nr
].flags
& ARGS_ORMORE
)
1000 Msg(0, "%s: %s: at least %s argument%s required",
1001 rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1005 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1006 (comms
[nr
].flags
& ARGS_PLUS2
) &&
1007 (comms
[nr
].flags
& ARGS_PLUS3
))
1009 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2 && i
!= n
+ 3)
1011 Msg(0, orformat
[3], rc_name
, comms
[nr
].name
, argss
[n
],
1012 argss
[n
+ 1], argss
[n
+ 2], argss
[n
+ 3], "");
1016 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1017 (comms
[nr
].flags
& ARGS_PLUS2
))
1019 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2)
1021 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1022 argss
[n
+ 1], argss
[n
+ 2], "");
1026 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1027 (comms
[nr
].flags
& ARGS_PLUS3
))
1029 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 3)
1031 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1032 argss
[n
+ 1], argss
[n
+ 3], "");
1036 else if ((comms
[nr
].flags
& ARGS_PLUS2
) &&
1037 (comms
[nr
].flags
& ARGS_PLUS3
))
1039 if (i
!= n
&& i
!= n
+ 2 && i
!= n
+ 3)
1041 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1042 argss
[n
+ 2], argss
[n
+ 3], "");
1046 else if (comms
[nr
].flags
& ARGS_PLUS1
)
1048 if (i
!= n
&& i
!= n
+ 1)
1050 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1051 argss
[n
+ 1], n
!= 0 ? "s" : "");
1055 else if (comms
[nr
].flags
& ARGS_PLUS2
)
1057 if (i
!= n
&& i
!= n
+ 2)
1059 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1064 else if (comms
[nr
].flags
& ARGS_PLUS3
)
1066 if (i
!= n
&& i
!= n
+ 3)
1068 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1075 Msg(0, orformat
[0], rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1082 StuffFin(buf
, len
, data
)
1090 LayProcess(&buf
, &len
);
1100 char **args
= act
->args
;
1101 int *argl
= act
->argl
;
1103 int argc
, i
, n
, msgok
;
1106 struct display
*odisplay
= display
;
1107 struct acluser
*user
;
1109 user
= display
? D_user
: users
;
1113 struct alias
*alias
= FindAliasnr(nr
);
1116 DoAlias(&alias
->name
, NULL
);
1122 if (nr
== RC_ILLEGAL
)
1124 debug1("key '%c': No action\n", key
);
1128 n
= comms
[nr
].flags
;
1129 if ((n
& NEED_DISPLAY
) && display
== 0)
1131 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1134 if ((n
& NEED_FORE
) && fore
== 0)
1136 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1139 if ((n
& NEED_LAYER
) && flayer
== 0)
1141 Msg(0, "%s: %s: display or window required", rc_name
, comms
[nr
].name
);
1144 if ((argc
= CheckArgNum(nr
, args
)) < 0)
1149 if (AclCheckPermCmd(D_user
, ACL_EXEC
, &comms
[nr
]))
1151 Msg(0, "%s: %s: permission denied (user %s)",
1152 rc_name
, comms
[nr
].name
, (EffectiveAclUser
? EffectiveAclUser
: D_user
)->u_name
);
1156 #endif /* MULTIUSER */
1158 msgok
= display
&& !*rc_name
;
1164 else if (args
[0][0] == '-' && !args
[0][1])
1166 SetForeWindow((struct win
*)0);
1169 else if (args
[0][0] == '.' && !args
[0][1])
1172 Msg(0, "select . needs a window");
1175 SetForeWindow(fore
);
1179 else if (ParseWinNum(act
, &n
) == 0)
1183 case RC_DEFAUTONUKE
:
1184 if (ParseOnOff(act
, &defautonuke
) == 0 && msgok
)
1185 Msg(0, "Default autonuke turned %s", defautonuke
? "on" : "off");
1186 if (display
&& *rc_name
)
1187 D_auto_nuke
= defautonuke
;
1190 if (ParseOnOff(act
, &D_auto_nuke
) == 0 && msgok
)
1191 Msg(0, "Autonuke turned %s", D_auto_nuke
? "on" : "off");
1194 case RC_DEFOBUFLIMIT
:
1195 if (ParseNum(act
, &defobuflimit
) == 0 && msgok
)
1196 Msg(0, "Default limit set to %d", defobuflimit
);
1197 if (display
&& *rc_name
)
1199 D_obufmax
= defobuflimit
;
1200 D_obuflenmax
= D_obuflen
- D_obufmax
;
1205 Msg(0, "Limit is %d, current buffer size is %d", D_obufmax
, D_obuflen
);
1206 else if (ParseNum(act
, &D_obufmax
) == 0 && msgok
)
1207 Msg(0, "Limit set to %d", D_obufmax
);
1208 D_obuflenmax
= D_obuflen
- D_obufmax
;
1210 case RC_DUMPTERMCAP
:
1211 WriteFile(user
, (char *)0, DUMP_TERMCAP
);
1215 int mode
= DUMP_HARDCOPY
;
1217 if (argc
> 1 && !strcmp(*args
, "-h"))
1219 mode
= DUMP_SCROLLBACK
;
1223 if (*args
&& args
[1])
1225 Msg(0, "%s: hardcopy: too many arguments", rc_name
);
1228 if (fore
== 0 && *args
== 0)
1229 Msg(0, "%s: hardcopy: window required", rc_name
);
1231 WriteFile(user
, *args
, mode
);
1235 (void)ParseOnOff(act
, &nwin_default
.Lflag
);
1238 n
= fore
->w_log
? 1 : 0;
1239 ParseSwitch(act
, &n
);
1249 SwitchWindow(NextWindow());
1253 SwitchWindow(PreviousWindow());
1262 Input(fore
->w_pwin
? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1264 Input("Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1272 FreePseudowin(fore
);
1273 Msg(0, "Filter removed.");
1277 name
= SaveStr(fore
->w_title
);
1279 Msg(0, "Window %d (%s) killed.", n
, name
);
1287 Input("Really quit and kill all your windows [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_QUIT
);
1294 if (*args
&& !strcmp(*args
, "-h"))
1306 Input(buf
, 1, INP_RAW
, pow_detach_fn
, NULL
, 0);
1309 Detach(D_POWER
); /* detach and kill Attacher's parent */
1318 Msg(0, "debugging info is written to %s/", DEBUGDIR
);
1320 Msg(0, "debugging is currently off. Use 'debug on' to enable.");
1325 debug("debug: closing debug file.\n");
1330 if (strcmp("off", *args
))
1334 kill(D_userpid
, SIG_NODEBUG
); /* a one shot item, but hey... */
1335 # endif /* SIG_NODEBUG */
1337 if (*args
== 0 || strcmp("off", *args
))
1338 Msg(0, "Sorry, screen was compiled without -DDEBUG option.");
1343 if (*args
&& !strcmp(*args
, "sendcmd"))
1347 free(zmodem_sendcmd
);
1348 zmodem_sendcmd
= SaveStr(args
[1]);
1351 Msg(0, "zmodem sendcmd: %s", zmodem_sendcmd
);
1354 if (*args
&& !strcmp(*args
, "recvcmd"))
1358 free(zmodem_recvcmd
);
1359 zmodem_recvcmd
= SaveStr(args
[1]);
1362 Msg(0, "zmodem recvcmd: %s", zmodem_recvcmd
);
1367 for (i
= 0; i
< 4; i
++)
1368 if (!strcmp(zmodes
[i
], *args
))
1370 if (i
== 4 && !strcmp(*args
, "on"))
1374 Msg(0, "usage: zmodem off|auto|catch|pass");
1380 Msg(0, "zmodem mode is %s", zmodes
[zmodem_mode
]);
1387 ZombieKey_destroy
= 0;
1390 if (*argl
== 0 || *argl
> 2)
1392 Msg(0, "%s:zombie: one or two characters expected.", rc_name
);
1397 if (!strcmp(args
[1], "onerror"))
1399 ZombieKey_onerror
= 1;
1401 Msg(0, "usage: zombie [keys [onerror]]");
1405 ZombieKey_onerror
= 0;
1406 ZombieKey_destroy
= args
[0][0];
1407 ZombieKey_resurrect
= *argl
== 2 ? args
[0][1] : 0;
1417 struct display
*olddisplay
= display
;
1418 display
= 0; /* no display will cause a broadcast */
1419 Msg(0, "%s: %s", s
, *args
);
1420 display
= olddisplay
;
1424 /* where this AT command comes from: */
1426 s
= SaveStr(D_user
->u_name
);
1427 /* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
1428 EffectiveAclUser
= D_user
;
1430 s
= SaveStr(D_usertty
);
1432 n
= strlen(args
[0]);
1435 * the windows/displays loops are quite dangerous here, take extra
1436 * care not to trigger landmines. Things may appear/disappear while
1437 * we are walking along.
1441 case '*': /* user */
1449 for (u
= users
; u
; u
= u
->u_next
)
1451 debug3("strncmp('%s', '%s', %d)\n", *args
, u
->u_name
, n
);
1452 if (!strncmp(*args
, u
->u_name
, n
))
1455 debug1("at all displays of user %s\n", u
->u_name
);
1456 for (display
= displays
; display
; display
= nd
)
1458 nd
= display
->d_next
;
1461 flayer
= D_forecv
->c_layer
;
1465 debug1("AT display %s\n", D_usertty
);
1466 DoCommand(args
+ 1, argl
+ 1);
1468 Msg(0, "command from %s: %s %s",
1469 s
, args
[1], args
[2] ? args
[2] : "");
1476 case '%': /* display */
1480 debug1("at display matching '%s'\n", args
[0]);
1481 for (display
= displays
; display
; display
= nd
)
1483 nd
= display
->d_next
;
1487 flayer
= D_forecv
->c_layer
;
1488 if (strncmp(args
[0], D_usertty
, n
) &&
1489 (strncmp("/dev/", D_usertty
, 5) ||
1490 strncmp(args
[0], D_usertty
+ 5, n
)) &&
1491 (strncmp("/dev/tty", D_usertty
, 8) ||
1492 strncmp(args
[0], D_usertty
+ 8, n
)))
1494 debug1("AT display %s\n", D_usertty
);
1495 DoCommand(args
+ 1, argl
+ 1);
1497 Msg(0, "command from %s: %s %s",
1498 s
, args
[1], args
[2] ? args
[2] : "");
1505 case '#': /* window */
1516 if (!*args
[0] || (i
= WindowByNumber(args
[0])) < 0)
1518 args
[0][n
] = ch
; /* must restore string in case of bind */
1519 /* try looping over titles */
1520 for (fore
= windows
; fore
; fore
= nw
)
1523 if (strncmp(args
[0], fore
->w_title
, n
))
1525 debug2("AT window %d(%s)\n", fore
->w_number
, fore
->w_title
);
1527 * consider this a bug or a feature:
1528 * while looping through windows, we have fore AND
1529 * display context. This will confuse users who try to
1530 * set up loops inside of loops, but often allows to do
1531 * what you mean, even when you adress your context wrong.
1534 /* XXX: other displays? */
1535 if (fore
->w_layer
.l_cvlist
)
1536 display
= fore
->w_layer
.l_cvlist
->c_display
;
1537 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1538 DoCommand(args
+ 1, argl
+ 1); /* may destroy our display */
1539 if (fore
&& fore
->w_layer
.l_cvlist
)
1541 display
= fore
->w_layer
.l_cvlist
->c_display
;
1542 Msg(0, "command from %s: %s %s",
1543 s
, args
[1], args
[2] ? args
[2] : "");
1549 Msg(0, "%s: at '%s': no such window.\n", rc_name
, args
[0]);
1552 else if (i
< MAXWIN
&& (fore
= wtab
[i
]))
1554 args
[0][n
] = ch
; /* must restore string in case of bind */
1555 debug2("AT window %d (%s)\n", fore
->w_number
, fore
->w_title
);
1556 if (fore
->w_layer
.l_cvlist
)
1557 display
= fore
->w_layer
.l_cvlist
->c_display
;
1558 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1559 DoCommand(args
+ 1, argl
+ 1);
1560 if (fore
&& fore
->w_layer
.l_cvlist
)
1562 display
= fore
->w_layer
.l_cvlist
->c_display
;
1563 Msg(0, "command from %s: %s %s",
1564 s
, args
[1], args
[2] ? args
[2] : "");
1570 Msg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name
);
1576 EffectiveAclUser
= NULL
;
1583 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1584 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1586 i
= FindEncoding(args
[1]);
1589 Msg(0, "%s: readreg: unknown encoding", rc_name
);
1596 * Without arguments we prompt for a destination register.
1597 * It will receive the copybuffer contents.
1598 * This is not done by RC_PASTE, as we prompt for source
1601 if ((s
= *args
) == NULL
)
1603 Input("Copy to register:", 1, INP_RAW
, copy_reg_fn
, NULL
, 0);
1608 Msg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name
);
1613 * With two arguments we *really* read register contents from file
1619 Msg(0, "%s: readreg: too many arguments", rc_name
);
1622 if ((s
= ReadFile(args
[1], &n
)))
1624 struct plop
*pp
= plop_tab
+ (int)(unsigned char)ch
;
1637 * with one argument we copy the copybuffer into a specified register
1638 * This could be done with RC_PASTE too, but is here to be consistent
1639 * with the zero argument call.
1641 copy_reg_fn(&ch
, 0, NULL
);
1646 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1647 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1649 i
= FindEncoding(args
[1]);
1652 Msg(0, "%s: register: unknown encoding", rc_name
);
1661 Msg(0, "%s: register: illegal number of arguments.", rc_name
);
1666 Msg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name
);
1673 if (user
->u_plop
.buf
!= NULL
)
1674 UserFreeCopyBuffer(user
);
1675 if (args
[1] && args
[1][0])
1677 user
->u_plop
.buf
= SaveStrn(args
[1], argl
[1]);
1678 user
->u_plop
.len
= argl
[1];
1680 user
->u_plop
.enc
= i
;
1687 struct plop
*plp
= plop_tab
+ (int)(unsigned char)ch
;
1691 plp
->buf
= SaveStrn(args
[1], argl
[1]);
1699 if ((s
= *args
) == NULL
)
1701 Input("Process register:", 1, INP_RAW
, process_fn
, NULL
, 0);
1706 Msg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name
);
1710 process_fn(&ch
, 0, NULL
);
1716 Input("Stuff:", 100, INP_COOKED
, StuffFin
, NULL
, 0);
1722 if (strcmp(s
, "-k"))
1724 Msg(0, "%s: stuff: invalid option %s", rc_name
, s
);
1728 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
1729 if (strcmp(term
[i
].tcname
, s
) == 0)
1733 Msg(0, "%s: stuff: unknown key '%s'", rc_name
, s
);
1737 if (StuffKey(i
- T_CAPS
) == 0)
1740 s
= display
? D_tcs
[i
].str
: 0;
1755 Msg(0, "screen %s", version
);
1760 timestring
= SaveStr(*args
);
1763 Msg(0, "%s", MakeWinMsg(timestring
, fore
, '%'));
1773 struct action
*ktabp
= ktab
;
1774 if (argc
== 2 && !strcmp(*args
, "-c"))
1776 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
1778 Msg(0, "Unknown command class '%s'", args
[1]);
1782 if (D_ESCseen
!= ktab
|| ktabp
!= ktab
)
1792 SwitchWindow(display
&& D_other
? D_other
->w_number
: NextWindow());
1795 if (user
->u_Esc
== -1)
1814 case RC_DEFBREAKTYPE
:
1817 static char *types
[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL
};
1818 extern int breaktype
;
1822 if (ParseNum(act
, &n
))
1823 for (n
= 0; n
< (int)(sizeof(types
)/sizeof(*types
)); n
++)
1825 for (i
= 0; i
< 4; i
++)
1828 if (ch
>= 'a' && ch
<= 'z')
1830 if (ch
!= types
[n
][i
] && (ch
+ ('a' - 'A')) != types
[n
][i
])
1836 if (n
< 0 || n
>= (int)(sizeof(types
)/sizeof(*types
)))
1837 Msg(0, "%s invalid, chose one of %s, %s or %s", *args
, types
[0], types
[1], types
[2]);
1841 Msg(0, "breaktype set to (%d) %s", n
, types
[n
]);
1845 Msg(0, "breaktype is (%d) %s", breaktype
, types
[breaktype
]);
1851 if (*args
&& ParseNum(act
, &n
))
1853 SendBreak(fore
, n
, nr
== RC_POW_BREAK
);
1867 if (*args
&& !strcmp(*args
, "-w"))
1869 else if (*args
&& !strcmp(*args
, "-d"))
1873 if (what
== 0 && flayer
&& !display
)
1879 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1882 w
= flayer
->l_width
;
1883 h
= flayer
->l_height
;
1889 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1895 if (*args
&& args
[0][0] == '-')
1897 Msg(0, "%s: %s: unknown option %s", rc_name
, comms
[nr
].name
, *args
);
1900 if (nr
== RC_HEIGHT
)
1908 else if (h
== H1height
)
1910 else if (h
> (H0height
+ H1height
) / 2)
1928 else if (w
== Z1width
)
1930 else if (w
> (Z0width
+ Z1width
) / 2)
1942 if (*args
&& args
[1] && args
[2])
1944 Msg(0, "%s: %s: too many arguments", rc_name
, comms
[nr
].name
);
1949 Msg(0, "Illegal width");
1954 Msg(0, "Illegal height");
1959 if (flayer
->l_width
== w
&& flayer
->l_height
== h
)
1961 ResizeLayer(flayer
, w
, h
, (struct display
*)0);
1964 if (D_width
== w
&& D_height
== h
)
1968 ChangeScreenSize(w
, h
, 1);
1972 if (ResizeDisplay(w
, h
) == 0)
1974 Activate(D_fore
? D_fore
->w_norefresh
: 0);
1976 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
1980 Msg(0, "Your termcap does not specify how to change the terminal's width to %d.", w
);
1981 else if (w
== D_width
)
1982 Msg(0, "Your termcap does not specify how to change the terminal's height to %d.", h
);
1984 Msg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w
, h
);
1992 ChangeAKA(fore
, *args
, strlen(*args
));
1995 Input(":", 100, INP_EVERY
, Colonfin
, NULL
, 0);
1996 if (*args
&& **args
)
2004 if (D_status_lastmsg
)
2005 Msg(0, "%s", D_status_lastmsg
);
2008 DoScreen("key", args
);
2011 if (ParseSwitch(act
, &fore
->w_wrap
) == 0 && msgok
)
2012 Msg(0, "%cwrap", fore
->w_wrap
? '+' : '-');
2017 if (args
[0][0] == 'a')
2019 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) ? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
2023 if (ParseOnOff(act
, &n
))
2025 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | n
;
2030 if (fore
->w_flow
& FLOW_AUTOFLAG
)
2031 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | FLOW_NOW
;
2032 else if (fore
->w_flow
& FLOW_NOW
)
2033 fore
->w_flow
&= ~FLOW_NOW
;
2035 fore
->w_flow
= fore
->w_flow
? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
2037 SetFlow(fore
->w_flow
& FLOW_NOW
);
2039 Msg(0, "%cflow%s", (fore
->w_flow
& FLOW_NOW
) ? '+' : '-',
2040 (fore
->w_flow
& FLOW_AUTOFLAG
) ? "(auto)" : "");
2043 case RC_DEFWRITELOCK
:
2044 if (args
[0][0] == 'a')
2045 nwin_default
.wlock
= WLOCK_AUTO
;
2048 if (ParseOnOff(act
, &n
))
2050 nwin_default
.wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2056 if (args
[0][0] == 'a')
2058 fore
->w_wlock
= WLOCK_AUTO
;
2062 if (ParseOnOff(act
, &n
))
2064 fore
->w_wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2067 * user may have permission to change the writelock setting,
2068 * but he may never aquire the lock himself without write permission
2070 if (!AclCheckPermWin(D_user
, ACL_WRITE
, fore
))
2071 fore
->w_wlockuser
= D_user
;
2073 Msg(0, "writelock %s", (fore
->w_wlock
== WLOCK_AUTO
) ? "auto" :
2074 ((fore
->w_wlock
== WLOCK_OFF
) ? "off" : "on"));
2078 ResetAnsiState(fore
);
2079 WriteString(fore
, "\033[H\033[J", 6);
2082 ResetAnsiState(fore
);
2084 if (fore
->w_zdisplay
)
2085 zmodem_abort(fore
, fore
->w_zdisplay
);
2087 WriteString(fore
, "\033c", 2);
2090 n
= fore
->w_monitor
!= MON_OFF
;
2093 n
= n
&& (ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
));
2095 if (ParseSwitch(act
, &n
))
2100 if (display
) /* we tell only this user */
2101 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2103 for (i
= 0; i
< maxusercount
; i
++)
2104 ACLBYTE(fore
->w_mon_notify
, i
) |= ACLBIT(i
);
2106 if (fore
->w_monitor
== MON_OFF
)
2107 fore
->w_monitor
= MON_ON
;
2108 Msg(0, "Window %d (%s) is now being monitored for all activity.", fore
->w_number
, fore
->w_title
);
2113 if (display
) /* we remove only this user */
2114 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
)
2115 &= ~ACLBIT(D_user
->u_id
);
2117 for (i
= 0; i
< maxusercount
; i
++)
2118 ACLBYTE(fore
->w_mon_notify
, i
) &= ~ACLBIT(i
);
2119 for (i
= maxusercount
- 1; i
>= 0; i
--)
2120 if (ACLBYTE(fore
->w_mon_notify
, i
))
2124 fore
->w_monitor
= MON_OFF
;
2125 Msg(0, "Window %d (%s) is no longer being monitored for activity.", fore
->w_number
, fore
->w_title
);
2135 display_wlist(0, WLIST_NUM
, (struct win
*)0);
2136 else if (!strcmp(*args
, "string"))
2142 wliststr
= SaveStr(args
[1]);
2145 Msg(0, "windowlist string is '%s'", wliststr
);
2147 else if (!strcmp(*args
, "title"))
2153 wlisttit
= SaveStr(args
[1]);
2156 Msg(0, "windowlist title is '%s'", wlisttit
);
2162 for (i
= 0; i
< argc
; i
++)
2165 else if (!strcmp(args
[i
], "-m"))
2167 else if (!strcmp(args
[i
], "-b"))
2169 else if (!strcmp(args
[i
], "-g"))
2170 flag
|= WLIST_NESTED
;
2173 Msg(0, "usage: windowlist [-b] [-g] [-m] [string [string] | title [title]]");
2177 display_wlist(blank
, flag
, (struct win
*)0);
2181 if (argc
== 2 && !strcmp(*args
, "-c"))
2183 struct action
*ktabp
;
2184 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
2186 Msg(0, "Unknown command class '%s'", args
[1]);
2189 display_help(args
[1], ktabp
);
2192 display_help((char *)0, ktab
);
2195 display_copyright();
2199 if (flayer
->l_layfn
!= &WinLf
)
2201 Msg(0, "Must be on a window layer");
2208 static char *pasteargs
[] = {".", 0};
2209 static int pasteargl
[] = {1};
2211 if (flayer
->l_layfn
!= &WinLf
)
2213 Msg(0, "Must be on a window layer");
2216 if (GetHistory() == 0)
2218 if (user
->u_plop
.buf
== NULL
)
2226 char *ss
, *dbuf
, dch
;
2233 * without args we prompt for one(!) register to be pasted in the window
2235 if ((s
= *args
) == NULL
)
2237 Input("Paste from register:", 1, INP_RAW
, ins_reg_fn
, NULL
, 0);
2240 if (args
[1] == 0 && !fore
) /* no window? */
2243 * with two arguments we paste into a destination register
2244 * (no window needed here).
2246 if (args
[1] && argl
[1] != 1)
2248 Msg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
2254 enc
= fore
->w_encoding
;
2258 * measure length of needed buffer
2260 for (ss
= s
= *args
; (ch
= *ss
); ss
++)
2266 enc
= user
->u_plop
.enc
;
2267 if (enc
!= user
->u_plop
.enc
)
2268 l
+= RecodeBuf((unsigned char *)user
->u_plop
.buf
, user
->u_plop
.len
, user
->u_plop
.enc
, enc
, (unsigned char *)0);
2271 l
+= user
->u_plop
.len
;
2277 enc
= plop_tab
[(int)(unsigned char)ch
].enc
;
2278 if (enc
!= plop_tab
[(int)(unsigned char)ch
].enc
)
2279 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);
2282 l
+= plop_tab
[(int)(unsigned char)ch
].len
;
2287 Msg(0, "empty buffer");
2292 * if there is only one source and the destination is a window, then
2293 * pass a pointer rather than duplicating the buffer.
2295 if (s
[1] == 0 && args
[1] == 0)
2297 if (enc
== (*s
== '.' ? user
->u_plop
.enc
: plop_tab
[(int)(unsigned char)*s
].enc
))
2300 MakePaster(&fore
->w_paster
, *s
== '.' ? user
->u_plop
.buf
: plop_tab
[(int)(unsigned char)*s
].buf
, l
, 0);
2304 * if no shortcut, we construct a buffer
2306 if ((dbuf
= (char *)malloc(l
)) == 0)
2313 * concatenate all sources into our own buffer, copy buffer is
2314 * special and is skipped if no display exists.
2316 for (ss
= s
; (ch
= *ss
); ss
++)
2318 struct plop
*pp
= (ch
== '.' ? &user
->u_plop
: &plop_tab
[(int)(unsigned char)ch
]);
2322 l
+= RecodeBuf((unsigned char *)pp
->buf
, pp
->len
, pp
->enc
, enc
, (unsigned char *)dbuf
+ l
);
2326 bcopy(pp
->buf
, dbuf
+ l
, pp
->len
);
2330 * when called with one argument we paste our buffer into the window
2334 MakePaster(&fore
->w_paster
, dbuf
, l
, 1);
2339 * we have two arguments, the second is already in dch.
2340 * use this as destination rather than the window.
2345 if (user
->u_plop
.buf
!= NULL
)
2346 UserFreeCopyBuffer(user
);
2347 user
->u_plop
.buf
= dbuf
;
2348 user
->u_plop
.len
= l
;
2350 user
->u_plop
.enc
= enc
;
2355 struct plop
*pp
= plop_tab
+ (int)(unsigned char)dch
;
2368 if (!user
->u_plop
.buf
)
2370 Msg(0, "empty buffer");
2375 struct plop oldplop
;
2377 oldplop
= user
->u_plop
;
2378 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2383 enc
= FindEncoding(args
[1]);
2386 Msg(0, "%s: writebuf: unknown encoding", rc_name
);
2389 if (enc
!= oldplop
.enc
)
2391 l
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)0);
2392 newbuf
= malloc(l
+ 1);
2398 user
->u_plop
.len
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)newbuf
);
2399 user
->u_plop
.buf
= newbuf
;
2400 user
->u_plop
.enc
= enc
;
2405 if (args
[0] && args
[1])
2406 Msg(0, "%s: writebuf: too many arguments", rc_name
);
2408 WriteFile(user
, args
[0], DUMP_EXCHANGE
);
2410 if (user
->u_plop
.buf
!= oldplop
.buf
)
2411 free(user
->u_plop
.buf
);
2412 user
->u_plop
= oldplop
;
2418 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
2419 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2421 i
= FindEncoding(args
[1]);
2424 Msg(0, "%s: readbuf: unknown encoding", rc_name
);
2430 if (args
[0] && args
[1])
2432 Msg(0, "%s: readbuf: too many arguments", rc_name
);
2435 if ((s
= ReadFile(args
[0] ? args
[0] : BufferFile
, &n
)))
2437 if (user
->u_plop
.buf
)
2438 UserFreeCopyBuffer(user
);
2439 user
->u_plop
.len
= n
;
2440 user
->u_plop
.buf
= s
;
2442 user
->u_plop
.enc
= i
;
2450 (void)ParseSwitch(act
, &search_ic
);
2452 Msg(0, "Will %signore case in searches", search_ic
? "" : "not ");
2454 #endif /* COPY_PASTE */
2457 SetEscape(user
, -1, -1);
2458 else if (*argl
== 2)
2459 SetEscape(user
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2462 Msg(0, "%s: two characters required after escape.", rc_name
);
2465 /* Change defescape if master user. This is because we only
2468 if (display
&& user
!= users
)
2473 SetEscape(NULL
, -1, -1);
2474 else if (*argl
== 2)
2475 SetEscape(NULL
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2478 Msg(0, "%s: two characters required after defescape.", rc_name
);
2486 s
= *args
? *args
: home
;
2488 Msg(errno
, "%s", s
);
2492 if (ParseSaveStr(act
, &ShellProg
) == 0)
2493 ShellArgs
[0] = ShellProg
;
2495 case RC_HARDCOPYDIR
:
2497 (void)ParseSaveStr(act
, &hardcopydir
);
2499 Msg(0, "hardcopydir is %s\n", hardcopydir
&& *hardcopydir
? hardcopydir
: "<cwd>");
2504 if (args
[1] && !(strcmp(*args
, "flush")))
2506 log_flush
= atoi(args
[1]);
2508 Msg(0, "log flush timeout set to %ds\n", log_flush
);
2511 if (ParseSaveStr(act
, &screenlogfile
) || !msgok
)
2514 Msg(0, "logfile is '%s'", screenlogfile
);
2517 if (!*args
|| !strcmp(*args
, "on") || !strcmp(*args
, "off"))
2519 if (ParseSwitch(act
, &logtstamp_on
) == 0 && msgok
)
2520 Msg(0, "timestamps turned %s", logtstamp_on
? "on" : "off");
2522 else if (!strcmp(*args
, "string"))
2526 if (logtstamp_string
)
2527 free(logtstamp_string
);
2528 logtstamp_string
= SaveStr(args
[1]);
2531 Msg(0, "logfile timestamp is '%s'", logtstamp_string
);
2533 else if (!strcmp(*args
, "after"))
2537 logtstamp_after
= atoi(args
[1]);
2541 Msg(0, "timestamp printed after %ds\n", logtstamp_after
);
2544 Msg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
2547 (void)ParseSaveStr(act
, &nwin_default
.aka
);
2550 case RC_TERMCAPINFO
:
2552 if (!rc_name
|| !*rc_name
)
2553 Msg(0, "Sorry, too late now. Place that in your .screenrc file.");
2556 break; /* Already handled */
2561 AddAlias(args
[0], args
[1], args
+1, argl
+1, argc
- 1);
2565 if (ParseSaveStr(act
, &s
))
2567 if (strlen(s
) >= 20)
2569 Msg(0, "%s: term: argument too long ( < 20)", rc_name
);
2573 strcpy(screenterm
, s
);
2575 debug1("screenterm set to %s\n", screenterm
);
2576 MakeTermcap((display
== 0));
2577 debug("new termcap made\n");
2580 if (!msgok
&& (!rc_name
|| strcmp(rc_name
, "-X")))
2583 * user typed ^A:echo... well, echo isn't FinishRc's job,
2584 * but as he wanted to test us, we show good will
2586 if (argc
> 1 && !strcmp(*args
, "-n"))
2592 if (argc
> 1 && !strcmp(*args
, "-p"))
2598 s
= MakeWinMsg(s
, fore
, '%');
2603 Msg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name
);
2610 AddXChars(buf
, sizeof(buf
), BellString
);
2611 Msg(0, "bell_msg is '%s'", buf
);
2614 (void)ParseSaveStr(act
, &BellString
);
2619 BufferFile
= SaveStr(DEFAULT_BUFFERFILE
);
2620 else if (ParseSaveStr(act
, &BufferFile
))
2623 Msg(0, "Bufferfile is now '%s'", BufferFile
);
2627 (void)ParseSaveStr(act
, &ActivityString
);
2629 #if defined(DETACH) && defined(POW_DETACH)
2630 case RC_POW_DETACH_MSG
:
2634 AddXChars(buf
, sizeof(buf
), PowDetachString
);
2635 Msg(0, "pow_detach_msg is '%s'", buf
);
2638 (void)ParseSaveStr(act
, &PowDetachString
);
2641 #if defined(UTMPOK) && defined(LOGOUTOK)
2643 n
= fore
->w_slot
!= (slot_t
)-1;
2644 if (*args
&& !strcmp(*args
, "always"))
2651 if (*args
&& !strcmp(*args
, "attached"))
2658 if (ParseSwitch(act
, &n
) == 0)
2662 if (!strcmp(*args
, "always"))
2663 nwin_default
.lflag
|= 2;
2664 else if (!strcmp(*args
, "attached"))
2665 nwin_default
.lflag
&= ~2;
2667 (void)ParseOnOff(act
, &nwin_default
.lflag
);
2671 if (args
[0] && args
[1] && args
[1][0] == 'i')
2674 for (display
= displays
; display
; display
= display
->d_next
)
2678 #if defined(TERMIO) || defined(POSIX)
2679 D_NewMode
.tio
.c_cc
[VINTR
] = D_OldMode
.tio
.c_cc
[VINTR
];
2680 D_NewMode
.tio
.c_lflag
|= ISIG
;
2681 #else /* TERMIO || POSIX */
2682 D_NewMode
.m_tchars
.t_intrc
= D_OldMode
.m_tchars
.t_intrc
;
2683 #endif /* TERMIO || POSIX */
2684 SetTTY(D_userfd
, &D_NewMode
);
2687 if (args
[0] && args
[0][0] == 'a')
2688 nwin_default
.flowflag
= FLOW_AUTOFLAG
;
2690 (void)ParseOnOff(act
, &nwin_default
.flowflag
);
2693 (void)ParseOnOff(act
, &nwin_default
.wrap
);
2696 (void)ParseOnOff(act
, &nwin_default
.c1
);
2700 (void)ParseOnOff(act
, &nwin_default
.bce
);
2704 (void)ParseOnOff(act
, &nwin_default
.gr
);
2707 if (ParseOnOff(act
, &n
) == 0)
2708 nwin_default
.monitor
= (n
== 0) ? MON_OFF
: MON_ON
;
2711 if (ParseOnOff(act
, &n
) == 0)
2712 nwin_default
.silence
= (n
== 0) ? SILENCE_OFF
: SILENCE_ON
;
2716 Msg(0, "W%s echo command when creating windows.",
2717 VerboseCreate
? "ill" : "on't");
2718 else if (ParseOnOff(act
, &n
) == 0)
2724 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
2727 if (args
[0] && strcmp(args
[0], "on") && strcmp(args
[0], "off"))
2729 struct display
*olddisplay
= display
;
2730 int old_use
, new_use
= -1;
2733 if (!strncmp(s
, "always", 6))
2735 if (!strcmp(s
, "lastline"))
2736 new_use
= HSTATUS_LASTLINE
;
2737 else if (!strcmp(s
, "ignore"))
2738 new_use
= HSTATUS_IGNORE
;
2739 else if (!strcmp(s
, "message"))
2740 new_use
= HSTATUS_MESSAGE
;
2741 else if (!strcmp(args
[0], "string"))
2746 AddXChars(buf
, sizeof(buf
), hstatusstring
);
2747 Msg(0, "hardstatus string is '%s'", buf
);
2753 Msg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name
);
2758 hardstatusemu
= new_use
| (s
== args
[0] ? 0 : HSTATUS_ALWAYS
);
2759 for (display
= displays
; display
; display
= display
->d_next
)
2762 new_use
= hardstatusemu
& ~HSTATUS_ALWAYS
;
2763 if (D_HS
&& s
== args
[0])
2764 new_use
= HSTATUS_HS
;
2765 ShowHStatus((char *)0);
2766 old_use
= D_has_hstatus
;
2767 D_has_hstatus
= new_use
;
2768 if ((new_use
== HSTATUS_LASTLINE
&& old_use
!= HSTATUS_LASTLINE
) || (new_use
!= HSTATUS_LASTLINE
&& old_use
== HSTATUS_LASTLINE
))
2769 ChangeScreenSize(D_width
, D_height
, 1);
2776 free(hstatusstring
);
2777 hstatusstring
= SaveStr(args
[1]);
2778 for (display
= displays
; display
; display
= display
->d_next
)
2781 display
= olddisplay
;
2784 (void)ParseSwitch(act
, &use_hardstatus
);
2786 Msg(0, "messages displayed on %s", use_hardstatus
? "hardstatus line" : "window");
2789 if (strcmp(args
[0], "always") == 0 || strcmp(args
[0], "splitonly") == 0)
2791 struct display
*olddisplay
= display
;
2793 captionalways
= args
[0][0] == 'a';
2794 for (display
= displays
; display
; display
= display
->d_next
)
2795 ChangeScreenSize(D_width
, D_height
, 1);
2796 display
= olddisplay
;
2798 else if (strcmp(args
[0], "string") == 0)
2803 AddXChars(buf
, sizeof(buf
), captionstring
);
2804 Msg(0, "caption string is '%s'", buf
);
2810 Msg(0, "%s: usage: caption always|splitonly|string <string>", rc_name
);
2816 free(captionstring
);
2817 captionstring
= SaveStr(args
[1]);
2818 RedisplayDisplays(0);
2821 n
= (console_window
!= 0);
2822 if (ParseSwitch(act
, &n
))
2824 if (TtyGrabConsole(fore
->w_ptyfd
, n
, rc_name
))
2827 Msg(0, "%s: releasing console %s", rc_name
, HostName
);
2828 else if (console_window
)
2829 Msg(0, "%s: stealing console %s from window %d (%s)", rc_name
,
2830 HostName
, console_window
->w_number
, console_window
->w_title
);
2832 Msg(0, "%s: grabbing console %s", rc_name
, HostName
);
2833 console_window
= n
? fore
: 0;
2836 if (ParseOnOff(act
, &all_norefresh
))
2838 if (!all_norefresh
&& fore
)
2841 Msg(0, all_norefresh
? "No refresh on window change!\n" :
2842 "Window specific refresh\n");
2845 (void)ParseSwitch(act
, &n
);
2846 fore
->w_norefresh
= n
;
2849 if (ParseSwitch(act
, &visual_bell
) || !msgok
)
2851 if (visual_bell
== 0)
2852 Msg(0, "switched to audible bell.");
2854 Msg(0, "switched to visual bell.");
2857 if (ParseNum1000(act
, &VBellWait
) == 0 && msgok
)
2858 Msg(0, "vbellwait set to %.10g seconds", VBellWait
/1000.);
2861 if (ParseNum1000(act
, &MsgWait
) == 0 && msgok
)
2862 Msg(0, "msgwait set to %.10g seconds", MsgWait
/1000.);
2865 if (ParseNum1000(act
, &MsgMinWait
) == 0 && msgok
)
2866 Msg(0, "msgminwait set to %.10g seconds", MsgMinWait
/1000.);
2868 case RC_SILENCEWAIT
:
2869 if (ParseNum(act
, &SilenceWait
))
2871 if (SilenceWait
< 1)
2873 for (p
= windows
; p
; p
= p
->w_next
)
2874 p
->w_silencewait
= SilenceWait
;
2876 Msg(0, "silencewait set to %d seconds", SilenceWait
);
2880 Msg(0, "This is window %d (%s).\n", fore
->w_number
, fore
->w_title
);
2883 int old
= fore
->w_number
;
2885 if (args
[0][0] == '+')
2887 else if (args
[0][0] == '-')
2891 parse
= ParseNum(act
, &n
);
2900 if (n
< 0 || n
>= maxwin
)
2902 Msg(0, "Given window position is invalid.");
2912 /* exchange the acls for these windows. */
2916 /* exchange the utmp-slots for these windows */
2917 if ((fore
->w_slot
!= (slot_t
) -1) && (fore
->w_slot
!= (slot_t
) 0))
2922 if (p
&& (p
->w_slot
!= (slot_t
) -1) && (p
->w_slot
!= (slot_t
) 0))
2924 /* XXX: first display wins? */
2925 display
= fore
->w_layer
.l_cvlist
? fore
->w_layer
.l_cvlist
->c_display
: 0;
2931 WindowChanged(fore
, 'n');
2932 WindowChanged((struct win
*)0, 'w');
2933 WindowChanged((struct win
*)0, 'W');
2934 WindowChanged((struct win
*)0, 0);
2938 n
= fore
->w_silence
!= 0;
2939 i
= fore
->w_silencewait
;
2940 if (args
[0] && (args
[0][0] == '-' || (args
[0][0] >= '0' && args
[0][0] <= '9')))
2942 if (ParseNum(act
, &i
))
2946 else if (ParseSwitch(act
, &n
))
2951 if (display
) /* we tell only this user */
2952 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2954 for (n
= 0; n
< maxusercount
; n
++)
2955 ACLBYTE(fore
->w_lio_notify
, n
) |= ACLBIT(n
);
2957 fore
->w_silencewait
= i
;
2958 fore
->w_silence
= SILENCE_ON
;
2959 SetTimeout(&fore
->w_silenceev
, fore
->w_silencewait
* 1000);
2960 evenq(&fore
->w_silenceev
);
2964 Msg(0, "The window is now being monitored for %d sec. silence.", fore
->w_silencewait
);
2969 if (display
) /* we remove only this user */
2970 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
)
2971 &= ~ACLBIT(D_user
->u_id
);
2973 for (n
= 0; n
< maxusercount
; n
++)
2974 ACLBYTE(fore
->w_lio_notify
, n
) &= ~ACLBIT(n
);
2975 for (i
= maxusercount
- 1; i
>= 0; i
--)
2976 if (ACLBYTE(fore
->w_lio_notify
, i
))
2981 fore
->w_silence
= SILENCE_OFF
;
2982 evdeq(&fore
->w_silenceev
);
2986 Msg(0, "The window is no longer being monitored for silence.");
2990 case RC_DEFSCROLLBACK
:
2991 (void)ParseNum(act
, &nwin_default
.histheight
);
2994 if (flayer
->l_layfn
== &MarkLf
)
2996 Msg(0, "Cannot resize scrollback buffer in copy/scrollback mode.");
2999 (void)ParseNum(act
, &n
);
3000 ChangeWindowSize(fore
, fore
->w_width
, fore
->w_height
, n
);
3002 Msg(0, "scrollback set to %d", fore
->w_histheight
);
3005 case RC_SESSIONNAME
:
3007 Msg(0, "This session is named '%s'\n", SockName
);
3010 char buf
[MAXPATHLEN
];
3013 if (ParseSaveStr(act
, &s
))
3015 if (!*s
|| strlen(s
) + (SockName
- SockPath
) > MAXPATHLEN
- 13 || index(s
, '/'))
3017 Msg(0, "%s: bad session name '%s'\n", rc_name
, s
);
3021 strncpy(buf
, SockPath
, SockName
- SockPath
);
3022 sprintf(buf
+ (SockName
- SockPath
), "%d.%s", (int)getpid(), s
);
3024 if ((access(buf
, F_OK
) == 0) || (errno
!= ENOENT
))
3026 Msg(0, "%s: inappropriate path: '%s'.", rc_name
, buf
);
3029 if (rename(SockPath
, buf
))
3031 Msg(errno
, "%s: failed to rename(%s, %s)", rc_name
, SockPath
, buf
);
3034 debug2("rename(%s, %s) done\n", SockPath
, buf
);
3035 strcpy(SockPath
, buf
);
3037 WindowChanged((struct win
*)0, 'S');
3041 if (!args
[0] || !args
[1])
3043 debug1("RC_SETENV arguments missing: %s\n", args
[0] ? args
[0] : "");
3044 InputSetenv(args
[0]);
3048 xsetenv(args
[0], args
[1]);
3057 case RC_DEFSLOWPASTE
:
3058 (void)ParseNum(act
, &nwin_default
.slow
);
3062 Msg(0, fore
->w_slowpaste
?
3063 "Slowpaste in window %d is %d milliseconds." :
3064 "Slowpaste in window %d is unset.",
3065 fore
->w_number
, fore
->w_slowpaste
);
3066 else if (ParseNum(act
, &fore
->w_slowpaste
) == 0 && msgok
)
3067 Msg(0, fore
->w_slowpaste
?
3068 "Slowpaste in window %d set to %d milliseconds." :
3069 "Slowpaste in window %d now unset.",
3070 fore
->w_number
, fore
->w_slowpaste
);
3073 if (CompileKeys(*args
, *argl
, mark_key_tab
))
3075 Msg(0, "%s: markkeys: syntax error.", rc_name
);
3078 debug1("markkeys %s\n", *args
);
3082 if (ParseSwitch(act
, &pastefont
) == 0 && msgok
)
3083 Msg(0, "Will %spaste font settings", pastefont
? "" : "not ");
3087 (void)ParseSwitch(act
, &join_with_cr
);
3089 case RC_COMPACTHIST
:
3090 if (ParseSwitch(act
, &compacthist
) == 0 && msgok
)
3091 Msg(0, "%scompacting history lines", compacthist
? "" : "not ");
3096 (void)ParseOnOff(act
, &nethackflag
);
3099 case RC_HARDCOPY_APPEND
:
3100 (void)ParseOnOff(act
, &hardcopy_append
);
3106 AddXChars(buf
, sizeof(buf
), VisualBellString
);
3107 Msg(0, "vbell_msg is '%s'", buf
);
3110 (void)ParseSaveStr(act
, &VisualBellString
);
3111 debug1(" new vbellstr '%s'\n", VisualBellString
);
3114 if (ParseBase(act
, *args
, &n
, 8, "octal"))
3116 if (n
< 0 || n
> 0777)
3118 Msg(0, "%s: mode: Invalid tty mode %o", rc_name
, n
);
3123 Msg(0, "Ttymode set to %03o", TtyMode
);
3126 (void)ParseOnOff(act
, &auto_detach
);
3128 case RC_STARTUP_MESSAGE
:
3129 (void)ParseOnOff(act
, &default_startup
);
3135 n
= (*user
->u_password
) ? 1 : 0;
3136 if (user
->u_password
!= NullStr
) free((char *)user
->u_password
);
3137 user
->u_password
= SaveStr(*args
);
3138 if (!strcmp(user
->u_password
, "none"))
3141 Msg(0, "Password checking disabled");
3142 free(user
->u_password
);
3143 user
->u_password
= NullStr
;
3150 Msg(0, "%s: password: window required", rc_name
);
3153 Input("New screen password:", 100, INP_NOECHO
, pass1
, display
? (char *)D_user
: (char *)users
, 0);
3156 #endif /* PASSWORD */
3159 struct action
*ktabp
= ktab
;
3164 if (argc
> 2 && !strcmp(*args
, "-c"))
3166 ktabp
= FindKtab(args
[1], 1);
3173 else if (argc
> 1 && !strcmp(*args
, "-k"))
3186 for (n
= 0; n
< KMAP_KEYS
; n
++)
3187 if (strcmp(term
[n
+ T_CAPS
].tcname
, *args
) == 0)
3191 Msg(0, "%s: bind: unknown key '%s'", rc_name
, *args
);
3200 Msg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name
);
3204 n
= (unsigned char)args
[0][0];
3208 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3210 struct alias
*alias
= FindAlias(args
[1]);
3213 Msg(0, "%s: bind: unknown command '%s'", rc_name
, args
[1]);
3218 if (i
<= RC_LAST
&& CheckArgNum(i
, args
+ 2) < 0)
3220 ClearAction(&ktabp
[n
]);
3221 SaveAction(ktabp
+ n
, i
, args
+ 2, argl
+ 2);
3224 ClearAction(&ktabp
[n
]);
3230 struct action
*newact
;
3231 int newnr
, fl
= 0, kf
= 0, af
= 0, df
= 0, mf
= 0;
3232 struct display
*odisp
= display
;
3234 struct kmap_ext
*kme
;
3236 for (; *args
&& **args
== '-'; args
++, argl
++)
3238 if (strcmp(*args
, "-t") == 0)
3239 fl
= KMAP_NOTIMEOUT
;
3240 else if (strcmp(*args
, "-k") == 0)
3242 else if (strcmp(*args
, "-a") == 0)
3244 else if (strcmp(*args
, "-d") == 0)
3246 else if (strcmp(*args
, "-m") == 0)
3248 else if (strcmp(*args
, "--") == 0)
3256 Msg(0, "%s: bindkey: invalid option %s", rc_name
, *args
);
3262 Msg(0, "%s: bindkey: -d does not work with -m", rc_name
);
3268 display_bindkey("Edit mode", mmtab
);
3270 display_bindkey("Default", dmtab
);
3272 display_bindkey("User", umtab
);
3279 Msg(0, "%s: bindkey: -a only works with -k", rc_name
);
3284 Msg(0, "%s: bindkey: empty string makes no sense", rc_name
);
3287 for (i
= 0, kme
= kmap_exts
; i
< kmap_extn
; i
++, kme
++)
3294 if (*argl
== (kme
->fl
& ~KMAP_NOTIMEOUT
) && bcmp(kme
->str
, *args
, *argl
) == 0)
3300 Msg(0, "%s: bindkey: keybinding not found", rc_name
);
3304 kmap_exts
= (struct kmap_ext
*)xrealloc((char *)kmap_exts
, kmap_extn
* sizeof(*kmap_exts
));
3305 kme
= kmap_exts
+ i
;
3306 bzero((char *)kme
, 8 * sizeof(*kmap_exts
));
3307 for (; i
< kmap_extn
; i
++, kme
++)
3310 kme
->dm
.nr
= kme
->mm
.nr
= kme
->um
.nr
= RC_ILLEGAL
;
3311 kme
->dm
.args
= kme
->mm
.args
= kme
->um
.args
= noargs
;
3316 if (df
== 0 && kme
->dm
.nr
!= RC_ILLEGAL
)
3318 if (mf
== 0 && kme
->mm
.nr
!= RC_ILLEGAL
)
3320 if ((df
|| mf
) && kme
->um
.nr
!= RC_ILLEGAL
)
3322 i
+= KMAP_KEYS
+ KMAP_AKEYS
;
3323 newact
= df
? &kme
->dm
: mf
? &kme
->mm
: &kme
->um
;
3327 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
3328 if (strcmp(term
[i
].tcname
, *args
) == 0)
3332 Msg(0, "%s: bindkey: unknown key '%s'", rc_name
, *args
);
3335 if (af
&& i
>= T_CURSOR
&& i
< T_OCAPS
)
3336 i
-= T_CURSOR
- KMAP_KEYS
;
3339 newact
= df
? &dmtab
[i
] : mf
? &mmtab
[i
] : &umtab
[i
];
3343 if ((newnr
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3345 struct alias
*alias
= FindAlias(args
[1]);
3348 Msg(0, "%s: bindkey: unknown command '%s'", rc_name
, args
[1]);
3353 if (newnr
<= RC_LAST
&& CheckArgNum(newnr
, args
+ 2) < 0)
3355 ClearAction(newact
);
3356 SaveAction(newact
, newnr
, args
+ 2, argl
+ 2);
3357 if (kf
== 0 && args
[1])
3361 kme
->str
= SaveStrn(*args
, *argl
);
3362 kme
->fl
= fl
| *argl
;
3366 ClearAction(newact
);
3367 for (display
= displays
; display
; display
= display
->d_next
)
3368 remap(i
, args
[1] ? 1 : 0);
3369 if (kf
== 0 && !args
[1])
3371 if (!used
&& kme
->str
)
3384 if (ParseNum(act
, &n
))
3388 Msg(0, "%s: maptimeout: illegal time %d", rc_name
, n
);
3393 if (*args
== 0 || msgok
)
3394 Msg(0, "maptimeout is %dms", maptimeout
);
3408 UsersAcl(NULL
, argc
, args
);
3411 if (UserDel(args
[0], NULL
))
3414 Msg(0, "%s removed from acl database", args
[0]);
3418 * modify a user to gain or lose rights granted to a group.
3419 * This group is actually a normal user whose rights were defined
3420 * with chacl in the usual way.
3424 if (strcmp(args
[1], "none")) /* link a user to another user */
3426 if (AclLinkUser(args
[0], args
[1]))
3429 Msg(0, "User %s joined acl-group %s", args
[0], args
[1]);
3431 else /* remove all groups from user */
3434 struct aclusergroup
*g
;
3436 if (!(u
= *FindUserPtr(args
[0])))
3438 while ((g
= u
->u_group
))
3440 u
->u_group
= g
->next
;
3445 else /* show all groups of user */
3447 char buf
[256], *p
= buf
;
3450 struct aclusergroup
*g
;
3452 if (!(u
= *FindUserPtr(args
[0])))
3455 Msg(0, "User %s does not exist.", args
[0]);
3462 sprintf(p
, "%s ", g
->u
->u_name
);
3470 Msg(0, "%s's group%s: %s.", args
[0], (ngroups
== 1) ? "" : "s",
3471 (ngroups
== 0) ? "none" : buf
);
3476 while ((s
= *args
++))
3480 if (AclUmask(display
? D_user
: users
, s
, &err
))
3481 Msg(0, "umask: %s\n", err
);
3485 if (ParseOnOff(act
, &n
))
3490 Msg(0, "Multiuser mode %s", multi
? "enabled" : "disabled");
3492 #endif /* MULTIUSER */
3500 i
= D_nonblock
>= 0;
3501 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3503 if (ParseNum1000(act
, &i
))
3506 else if (!ParseSwitch(act
, &i
))
3507 i
= i
== 0 ? -1 : 1000;
3510 if (msgok
&& i
== -1)
3511 Msg(0, "display set to blocking mode");
3512 else if (msgok
&& i
== 0)
3513 Msg(0, "display set to nonblocking mode, no timeout");
3515 Msg(0, "display set to nonblocking mode, %.10gs timeout", i
/1000.);
3517 if (D_nonblock
<= 0)
3518 evdeq(&D_blockedev
);
3520 case RC_DEFNONBLOCK
:
3521 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3523 if (ParseNum1000(act
, &defnonblock
))
3526 else if (!ParseOnOff(act
, &defnonblock
))
3527 defnonblock
= defnonblock
== 0 ? -1 : 1000;
3530 if (display
&& *rc_name
)
3532 D_nonblock
= defnonblock
;
3533 if (D_nonblock
<= 0)
3534 evdeq(&D_blockedev
);
3540 if (fore
->w_gr
== 2)
3543 if (ParseSwitch(act
, &fore
->w_gr
) == 0 && msgok
)
3544 Msg(0, "Will %suse GR", fore
->w_gr
? "" : "not ");
3546 if (fore
->w_gr
== 0 && fore
->w_FontE
)
3551 if (ParseSwitch(act
, &fore
->w_c1
) == 0 && msgok
)
3552 Msg(0, "Will %suse C1", fore
->w_c1
? "" : "not ");
3556 if (ParseSwitch(act
, &fore
->w_bce
) == 0 && msgok
)
3557 Msg(0, "Will %serase with background color", fore
->w_bce
? "" : "not ");
3564 if (*args
&& !strcmp(args
[0], "-d"))
3567 Msg(0, "encodings directory is %s", screenencodings
? screenencodings
: "<unset>");
3570 free(screenencodings
);
3571 screenencodings
= SaveStr(args
[1]);
3575 if (*args
&& !strcmp(args
[0], "-l"))
3578 Msg(0, "encoding: -l: argument required");
3579 else if (LoadFontTranslation(-1, args
[1]))
3580 Msg(0, "encoding: could not load utf8 encoding file");
3582 Msg(0, "encoding: utf8 encoding file loaded");
3586 if (*args
&& (!strcmp(args
[0], "-l") || !strcmp(args
[0], "-d")))
3589 Msg(0, "encoding: screen is not compiled for UTF-8.");
3593 for (i
= 0; i
< 2; i
++)
3597 if (!strcmp(args
[i
], "."))
3599 n
= FindEncoding(args
[i
]);
3602 Msg(0, "encoding: unknown encoding '%s'", args
[i
]);
3607 WinSwitchEncoding(fore
, n
);
3608 ResetCharsets(fore
);
3610 else if (i
&& display
)
3615 case RC_DEFENCODING
:
3616 n
= FindEncoding(*args
);
3619 Msg(0, "defencoding: unknown encoding '%s'", *args
);
3622 nwin_default
.encoding
= n
;
3628 n
= nwin_default
.encoding
== UTF8
;
3629 if (ParseSwitch(act
, &n
) == 0)
3631 nwin_default
.encoding
= n
? UTF8
: 0;
3633 Msg(0, "Will %suse UTF-8 encoding for new windows", n
? "" : "not ");
3637 for (i
= 0; i
< 2; i
++)
3639 if (i
&& args
[i
] == 0)
3642 n
= fore
->w_encoding
!= UTF8
;
3643 else if (strcmp(args
[i
], "off") == 0)
3645 else if (strcmp(args
[i
], "on") == 0)
3649 Msg(0, "utf8: illegal argument (%s)", args
[i
]);
3654 WinSwitchEncoding(fore
, n
? UTF8
: 0);
3656 Msg(0, "Will %suse UTF-8 encoding", n
? "" : "not ");
3659 D_encoding
= n
? UTF8
: 0;
3673 printcmd
= SaveStr(*args
);
3675 if (*args
== 0 || msgok
)
3678 Msg(0, "using '%s' as print command", printcmd
);
3680 Msg(0, "using termcap entries for printing");
3686 Input("Enter digraph: ", 10, INP_EVERY
, digraph_fn
, NULL
, 0);
3687 if (*args
&& **args
)
3700 if (nwin_default
.hstatus
)
3701 AddXChars(buf
, sizeof(buf
), nwin_default
.hstatus
);
3702 Msg(0, "default hstatus is '%s'", buf
);
3705 (void)ParseSaveStr(act
, &nwin_default
.hstatus
);
3706 if (*nwin_default
.hstatus
== 0)
3708 free(nwin_default
.hstatus
);
3709 nwin_default
.hstatus
= 0;
3713 (void)ParseSaveStr(act
, &fore
->w_hstatus
);
3714 if (*fore
->w_hstatus
== 0)
3716 free(fore
->w_hstatus
);
3717 fore
->w_hstatus
= 0;
3719 WindowChanged(fore
, 'h');
3729 if (nwin_default
.charset
)
3730 AddXChars(buf
, sizeof(buf
), nwin_default
.charset
);
3731 Msg(0, "default charset is '%s'", buf
);
3735 if (n
== 0 || n
> 6)
3737 Msg(0, "%s: %s: string has illegal size.", rc_name
, comms
[nr
].name
);
3741 ((args
[0][4] < '0' || args
[0][4] > '3') && args
[0][4] != '.') ||
3742 ((args
[0][5] < '0' || args
[0][5] > '3') && args
[0][5] && args
[0][5] != '.')))
3744 Msg(0, "%s: %s: illegal mapping number.", rc_name
, comms
[nr
].name
);
3747 if (nr
== RC_CHARSET
)
3749 SetCharsets(fore
, *args
);
3752 if (nwin_default
.charset
)
3753 free(nwin_default
.charset
);
3754 nwin_default
.charset
= SaveStr(*args
);
3760 if (*s
>= '0' && *s
<= '9')
3763 for (i
= 0; i
< 8; i
++)
3764 if (*s
== "dubrsBiI"[i
])
3768 if (*s
&& s
[1] && !s
[2])
3770 if (*s
== 'd' && s
[1] == 'd')
3772 else if (*s
== '.' && s
[1] == 'd')
3774 else if (*s
== 'd' && s
[1] == '.')
3776 else if (*s
!= '.' || s
[1] != '.')
3780 if (*s
|| i
< 0 || i
>= 8)
3782 Msg(0, "%s: attrcolor: unknown attribute '%s'.", rc_name
, args
[0]);
3787 n
= ParseAttrColor(args
[1], args
[2], 1);
3790 attr2color
[i
][nr
] = n
;
3792 for (i
= 0; i
< 8; i
++)
3793 if (attr2color
[i
][0] || attr2color
[i
][1] || attr2color
[i
][2] || attr2color
[i
][3])
3798 case RC_SORENDITION
:
3802 i
= ParseAttrColor(*args
, args
[1], 1);
3805 ApplyAttrColor(i
, &mchar_so
);
3806 debug2("--> %x %x\n", mchar_so
.attr
, mchar_so
.color
);
3810 Msg(0, "Standout attributes 0x%02x color 0x%02x", (unsigned char)mchar_so
.attr
, 0x99 ^ (unsigned char)mchar_so
.color
);
3812 Msg(0, "Standout attributes 0x%02x ", (unsigned char)mchar_so
.attr
);
3825 Msg(0, "%s:%s screen login", HostName
, SockPath
);
3826 InputSu(D_fore
, &D_user
, NULL
);
3829 InputSu(D_fore
, &D_user
, args
[0]);
3831 s
= DoSu(&D_user
, args
[0], args
[1], "\377");
3833 s
= DoSu(&D_user
, args
[0], args
[1], args
[2]);
3837 #endif /* MULTIUSER */
3840 if (s
&& !strcmp(s
, "-v"))
3841 AddCanvas(SLICE_HORI
);
3843 AddCanvas(SLICE_VERT
);
3855 D_forecv
->c_xoff
= D_forecv
->c_xs
;
3856 D_forecv
->c_yoff
= D_forecv
->c_ys
;
3857 RethinkViewportOffsets(D_forecv
);
3858 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
3859 flayer
= D_forecv
->c_layer
;
3863 if (!*args
|| !strcmp(*args
, "down"))
3864 D_forecv
= D_forecv
->c_next
? D_forecv
->c_next
: D_cvlist
;
3865 else if (!strcmp(*args
, "up"))
3868 for (cv
= D_cvlist
; cv
->c_next
&& cv
->c_next
!= D_forecv
; cv
= cv
->c_next
)
3872 else if (!strcmp(*args
, "top"))
3873 D_forecv
= D_cvlist
;
3874 else if (!strcmp(*args
, "bottom"))
3877 for (cv
= D_cvlist
; cv
->c_next
; cv
= cv
->c_next
)
3883 Msg(0, "%s: usage: focus [up|down|top|bottom]", rc_name
);
3886 if ((focusminwidth
&& (focusminwidth
< 0 || D_forecv
->c_xe
- D_forecv
->c_xs
+ 1 < focusminwidth
)) ||
3887 (focusminheight
&& (focusminheight
< 0 || D_forecv
->c_ye
- D_forecv
->c_ys
+ 1 < focusminheight
)))
3889 ResizeCanvas(&D_canvas
);
3890 RecreateCanvasChain();
3891 RethinkDisplayViewports();
3892 ResizeLayersToCanvases(); /* redisplays */
3894 fore
= D_fore
= Layer2Window(D_forecv
->c_layer
);
3895 if (D_other
== fore
)
3897 flayer
= D_forecv
->c_layer
;
3899 if (D_xtermosc
[2] || D_xtermosc
[3])
3909 flayer
= D_forecv
->c_layer
;
3910 CV_CALL(D_forecv
, LayRestore();LaySetCursor());
3911 WindowChanged(0, 'F');
3915 if (D_forecv
->c_slorient
== SLICE_UNKN
)
3917 Msg(0, "resize: need more than one region");
3920 for (; *args
; args
++)
3922 if (!strcmp(*args
, "-h"))
3924 else if (!strcmp(*args
, "-v"))
3926 else if (!strcmp(*args
, "-b"))
3927 i
|= RESIZE_FLAG_H
| RESIZE_FLAG_V
;
3928 else if (!strcmp(*args
, "-p"))
3929 i
|= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
3930 else if (!strcmp(*args
, "-l"))
3935 if (*args
&& args
[1])
3937 Msg(0, "%s: usage: resize [-h] [-v] [-l] [num]\n", rc_name
);
3941 ResizeRegions(*args
, i
);
3943 Input(resizeprompts
[i
], 20, INP_EVERY
, ResizeFin
, (char*)0, i
);
3946 (void)ParseSwitch(act
, &separate_sids
);
3949 args
= SaveArgs(args
);
3950 for (i
= 0; args
[i
]; i
++)
3953 Colonfin(args
[i
], strlen(args
[i
]), (char *)0);
3959 (void)ParseSwitch(act
, &use_altscreen
);
3961 Msg(0, "Will %sdo alternate screen switching", use_altscreen
? "" : "not ");
3964 if (ParseNum(act
, &n
))
3967 Msg(0, "illegal maxwin number specified");
3968 else if (n
> maxwin
)
3969 Msg(0, "may only decrease maxwin number");
3974 if (ParseBase(act
, *args
, &n
, 10, "decimal"))
3977 setbacktick(n
, 0, 0, (char **)0);
3983 Msg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name
);
3986 if (ParseBase(act
, args
[1], &lifespan
, 10, "decimal"))
3988 if (ParseBase(act
, args
[2], &tick
, 10, "decimal"))
3990 setbacktick(n
, lifespan
, tick
, SaveArgs(args
+ 3));
3992 WindowChanged(0, '`');
3998 RunBlanker(blankerprg
);
4003 CursorVisibility(-1);
4011 for (pp
= blankerprg
; *pp
; pp
++)
4017 blankerprg
= SaveArgs(args
);
4023 struct display
*olddisplay
= display
;
4024 if (!strcmp(*args
, "off"))
4026 else if (args
[0][0])
4027 idletimo
= atoi(*args
) * 1000;
4030 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
4032 Msg(0, "%s: idle: unknown command '%s'", rc_name
, args
[1]);
4035 if (CheckArgNum(i
, args
+ 2) < 0)
4037 ClearAction(&idleaction
);
4038 SaveAction(&idleaction
, i
, args
+ 2, argl
+ 2);
4040 for (display
= displays
; display
; display
= display
->d_next
)
4042 display
= olddisplay
;
4047 Msg(0, "idle timeout %ds, %s", idletimo
/ 1000, comms
[idleaction
.nr
].name
);
4052 case RC_FOCUSMINSIZE
:
4053 for (i
= 0; i
< 2 && args
[i
]; i
++)
4055 if (!strcmp(args
[i
], "max") || !strcmp(args
[i
], "_"))
4067 for (i
= 0; i
< 2; i
++)
4069 n
= i
== 0 ? focusminwidth
: focusminheight
;
4071 strcpy(b
[i
], "max");
4073 sprintf(b
[i
], "%d", n
);
4075 Msg(0, "focus min size is %s %s\n", b
[0], b
[1]);
4084 fore
->w_group
= WindowByName(*args
);
4085 if (fore
->w_group
&& fore
->w_group
->w_type
!= W_TYPE_GROUP
)
4088 WindowChanged((struct win
*)0, 'w');
4089 WindowChanged((struct win
*)0, 'W');
4090 WindowChanged((struct win
*)0, 0);
4095 Msg(0, "window group is %d (%s)\n", fore
->w_group
->w_number
, fore
->w_group
->w_title
);
4097 Msg(0, "window belongs to no group");
4101 if (!strcmp(args
[0], "title"))
4105 Msg(0, "not on a layout");
4110 Msg(0, "current layout is %d (%s)", D_layout
->lay_number
, D_layout
->lay_title
);
4113 free(D_layout
->lay_title
);
4114 D_layout
->lay_title
= SaveStr(args
[1]);
4116 else if (!strcmp(args
[0], "number"))
4122 Msg(0, "This is layout %d (%s).\n", D_layout
->lay_number
, D_layout
->lay_title
);
4125 old
= D_layout
->lay_number
;
4127 if (n
< 0 || n
>= MAXLAY
)
4130 laytab
[n
] = D_layout
;
4131 D_layout
->lay_number
= n
;
4134 lay
->lay_number
= old
;
4137 else if (!strcmp(args
[0], "autosave"))
4141 Msg(0, "not on a layout");
4146 if (!strcmp(args
[1], "on"))
4147 D_layout
->lay_autosave
= 1;
4148 else if (!strcmp(args
[1], "off"))
4149 D_layout
->lay_autosave
= 0;
4152 Msg(0, "invalid argument. Give 'on' or 'off");
4157 Msg(0, "autosave is %s", D_layout
->lay_autosave
? "on" : "off");
4159 else if (!strcmp(args
[0], "new"))
4165 while (*t
>= '0' && *t
<= '9')
4167 if (t
!= args
[1] && (!*t
|| *t
== ':'))
4181 else if (!strcmp(args
[0], "save"))
4185 Msg(0, "usage: layout save <name>");
4188 SaveLayout(args
[1], &D_canvas
);
4190 else if (!strcmp(args
[0], "select"))
4194 Input("Switch to layout: ", 20, INP_COOKED
, SelectLayoutFin
, NULL
, 0);
4197 SelectLayoutFin(args
[1], strlen(args
[1]), (char *)0);
4199 else if (!strcmp(args
[0], "next"))
4201 struct layout
*lay
= D_layout
;
4203 lay
= lay
->lay_next
? lay
->lay_next
: layouts
;
4208 Msg(0, "no layout defined");
4211 if (lay
== D_layout
)
4213 LoadLayout(lay
, &D_canvas
);
4216 else if (!strcmp(args
[0], "prev"))
4218 struct layout
*lay
= D_layout
;
4221 for (lay
= layouts
; lay
->lay_next
&& lay
->lay_next
!= D_layout
; lay
= lay
->lay_next
)
4228 Msg(0, "no layout defined");
4231 if (lay
== D_layout
)
4233 LoadLayout(lay
, &D_canvas
);
4236 else if (!strcmp(args
[0], "attach"))
4241 Msg(0, "no attach layout set");
4242 else if (layout_attach
== &layout_last_marker
)
4243 Msg(0, "will attach to last layout");
4245 Msg(0, "will attach to layout %d (%s)", layout_attach
->lay_number
, layout_attach
->lay_title
);
4248 if (!strcmp(args
[1], ":last"))
4249 layout_attach
= &layout_last_marker
;
4250 else if (!args
[1][0])
4255 lay
= FindLayout(args
[1]);
4258 Msg(0, "unknown layout '%s'", args
[1]);
4261 layout_attach
= lay
;
4264 else if (!strcmp(args
[0], "show"))
4268 else if (!strcmp(args
[0], "remove"))
4270 struct layout
*lay
= display
? D_layout
: layouts
;
4273 lay
= layouts
? FindLayout(args
[1]) : (struct layout
*)0;
4276 Msg(0, "unknown layout '%s'", args
[1]);
4284 Msg(0, "unknown layout subcommand");
4288 if(ParseSwitch(act
, &cjkwidth
) == 0)
4291 Msg(0, "Treat ambiguous width characters as %s width", cjkwidth
? "full" : "half");
4297 /* key == -2: input from braille keybord, msgok always 0 */
4298 DoBrailleAction(act
, key
== -2 ? 0 : msgok
);
4302 if (display
!= odisplay
)
4304 for (display
= displays
; display
; display
= display
->d_next
)
4305 if (display
== odisplay
)
4310 /* Right now, aliased commands cannot really take parameters.
4311 * So argv and argl are pretty much ununsed (except *argv, of course, which is the
4312 * name of the alias itself).
4319 /* Find the alias */
4320 struct alias
*alias
= FindAlias(*argv
);
4324 DoCommand(alias
->args
, alias
->argl
);
4329 DoCommand(argv
, argl
)
4336 if (DoAlias(argv
, argl
))
4339 if ((act
.nr
= FindCommnr(*argv
)) == RC_ILLEGAL
)
4341 Msg(0, "%s: unknown command '%s'", rc_name
, *argv
);
4344 act
.args
= argv
+ 1;
4345 act
.argl
= argl
+ 1;
4350 SaveAction(act
, nr
, args
, argl
)
4356 register int argc
= 0;
4370 if ((pp
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4372 if ((lp
= (int *)malloc((unsigned)(argc
) * sizeof(int *))) == 0)
4379 *lp
= argl
? *argl
++ : (int)strlen(*args
);
4380 *pp
++ = SaveStrn(*args
++, *lp
++);
4389 register char **ap
, **pp
;
4390 register int argc
= 0;
4394 if ((pp
= ap
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4397 *pp
++ = SaveStr(*args
++);
4404 * buf is split into argument vector args.
4405 * leading whitespace is removed.
4406 * @!| abbreviations are expanded.
4407 * the end of buffer is recognized by '\0' or an un-escaped '#'.
4408 * " and ' are interpreted.
4413 Parse(buf
, bufl
, args
, argl
)
4417 register char *p
= buf
, **ap
= args
, *pp
;
4418 register int delim
, argc
;
4421 debug2("Parse %d %s\n", bufl
, buf
);
4427 while (*p
&& (*p
== ' ' || *p
== '\t'))
4430 if (argc
== 0 && *p
== '!')
4439 if (*p
== '\0' || *p
== '#' || *p
== '\n')
4442 for (delim
= 0; delim
< argc
; delim
++)
4443 debug1("-- %s\n", args
[delim
]);
4447 if (++argc
>= MAXARGS
)
4449 Msg(0, "%s: too many tokens.", rc_name
);
4454 debug1("- new arg %s\n", p
);
4459 else if (delim
!= '\'' && *p
== '\\' && (p
[1] == '\'' || p
[1] == '"' || p
[1] == '\\' || p
[1] == '$' || p
[1] == '#' || p
[1] == '^' || (p
[1] >= '0' && p
[1] <= '7')))
4462 if (*p
>= '0' && *p
<= '7')
4465 if (p
[1] >= '0' && p
[1] <= '7')
4468 *pp
= (*pp
<< 3) | (*p
- '0');
4469 if (p
[1] >= '0' && p
[1] <= '7')
4472 *pp
= (*pp
<< 3) | (*p
- '0');
4480 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] == '_'))
4483 char *ps
, *pe
, op
, *v
, xbuf
[11];
4487 debug1("- var %s\n", ps
);
4491 if (*ps
== '{' && *p
== '}')
4493 if (*ps
== ':' && *p
== ':')
4495 if (*ps
!= '{' && *ps
!= ':' && (*p
< 'a' || *p
> 'z') && (*p
< 'A' || *p
> 'Z') && (*p
< '0' || *p
> '9') && *p
!= '_')
4500 if (*ps
== '{' || *ps
== ':')
4504 Msg(0, "%s: bad variable name.", rc_name
);
4511 debug1("- var is '%s'\n", ps
);
4513 v
= gettermcapstring(ps
+ 1);
4519 if (!strcmp(ps
, "TERM"))
4520 v
= display
? D_termname
: "unknown";
4521 else if (!strcmp(ps
, "COLUMNS"))
4522 sprintf(xbuf
, "%d", display
? D_width
: -1);
4523 else if (!strcmp(ps
, "LINES"))
4524 sprintf(xbuf
, "%d", display
? D_height
: -1);
4529 vl
= v
? strlen(v
) : 0;
4532 debug1("- sub is '%s'\n", v
);
4535 int right
= buf
+ bufl
- (p
+ strlen(p
) + 1);
4538 bcopy(p
, p
+ right
, strlen(p
) + 1);
4544 Msg(0, "%s: no space left for variable expansion.", rc_name
);
4552 else if (delim
!= '\'' && *p
== '^' && p
[1])
4555 *pp
++ = *p
== '?' ? '\177' : *p
& 0x1f;
4557 else if (delim
== 0 && (*p
== '\'' || *p
== '"'))
4559 else if (delim
== 0 && (*p
== ' ' || *p
== '\t' || *p
== '\n'))
4567 Msg(0, "%s: Missing %c quote.", rc_name
, delim
);
4573 debug2("- arg done, '%s' rest %s\n", ap
[-1], p
);
4574 *lp
++ = pp
- ap
[-1];
4593 if (DefaultEsc
>= 0)
4594 ClearAction(&ktab
[DefaultEsc
]);
4595 if (DefaultMetaEsc
>= 0)
4596 ClearAction(&ktab
[DefaultMetaEsc
]);
4599 DefaultMetaEsc
= me
;
4602 if (DefaultEsc
>= 0)
4604 ClearAction(&ktab
[DefaultEsc
]);
4605 ktab
[DefaultEsc
].nr
= RC_OTHER
;
4607 if (DefaultMetaEsc
>= 0)
4609 ClearAction(&ktab
[DefaultMetaEsc
]);
4610 ktab
[DefaultMetaEsc
].nr
= RC_META
;
4617 ParseSwitch(act
, var
)
4621 if (*act
->args
== 0)
4626 return ParseOnOff(act
, var
);
4630 ParseOnOff(act
, var
)
4634 register int num
= -1;
4635 char **args
= act
->args
;
4639 if (strcmp(args
[0], "on") == 0)
4641 else if (strcmp(args
[0], "off") == 0)
4646 Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name
, comms
[act
->nr
].name
);
4654 ParseSaveStr(act
, var
)
4658 char **args
= act
->args
;
4659 if (*args
== 0 || args
[1])
4661 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4666 *var
= SaveStr(*args
);
4676 char *p
, **args
= act
->args
;
4679 if (p
== 0 || *p
== 0 || args
[1])
4681 Msg(0, "%s: %s: invalid argument. Give one argument.",
4682 rc_name
, comms
[act
->nr
].name
);
4688 if (*p
>= '0' && *p
<= '9')
4689 i
= 10 * i
+ (*p
- '0');
4692 Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4693 rc_name
, comms
[act
->nr
].name
);
4698 debug1("ParseNum got %d\n", i
);
4704 ParseNum1000(act
, var
)
4709 char *p
, **args
= act
->args
;
4713 if (p
== 0 || *p
== 0 || args
[1])
4715 Msg(0, "%s: %s: invalid argument. Give one argument.",
4716 rc_name
, comms
[act
->nr
].name
);
4722 if (*p
>= '0' && *p
<= '9')
4725 i
= 10 * i
+ (*p
- '0');
4726 else if (dig
== 4 && *p
>= '5')
4731 else if (*p
== '.' && !dig
)
4735 Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4736 rc_name
, comms
[act
->nr
].name
);
4747 i
= (int)((unsigned int)~0 >> 1);
4748 debug1("ParseNum1000 got %d\n", i
);
4759 for (p
= windows
; p
; p
= p
->w_next
)
4760 if (!strcmp(p
->w_title
, s
))
4762 for (p
= windows
; p
; p
= p
->w_next
)
4763 if (!strncmp(p
->w_title
, s
, strlen(s
)))
4775 for (i
= 0, s
= str
; *s
; s
++)
4777 if (*s
< '0' || *s
> '9')
4779 i
= i
* 10 + (*s
- '0');
4785 * Get window number from Name or Number string.
4786 * Numbers are tried first, then names, a prefix match suffices.
4787 * Be careful when assigning numeric strings as WindowTitles.
4796 if ((i
= WindowByNumber(str
)) < 0 || i
>= MAXWIN
)
4798 if ((p
= WindowByName(str
)))
4806 ParseWinNum(act
, var
)
4810 char **args
= act
->args
;
4813 if (*args
== 0 || args
[1])
4815 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4819 i
= WindowByNoN(*args
);
4822 Msg(0, "%s: %s: invalid argument. Give window number or name.",
4823 rc_name
, comms
[act
->nr
].name
);
4826 debug1("ParseWinNum got %d\n", i
);
4832 ParseBase(act
, p
, var
, base
, bname
)
4844 Msg(0, "%s: %s: empty argument.", rc_name
, comms
[act
->nr
].name
);
4849 if (c
>= 'a' && c
<= 'z')
4851 if (c
>= 'A' && c
<= 'Z')
4852 c
-= 'A' - ('0' + 10);
4854 if (c
< 0 || c
>= base
)
4856 Msg(0, "%s: %s: argument is not %s.", rc_name
, comms
[act
->nr
].name
, bname
);
4861 debug1("ParseBase got %d\n", i
);
4871 for (base
+= '0'; *s
; ++s
)
4872 if (*s
< '0' || *s
> base
)
4878 IsNumColon(s
, base
, p
, psize
)
4883 if ((q
= rindex(s
, ':')) != 0)
4885 strncpy(p
, q
+ 1, psize
- 1);
4886 p
[psize
- 1] = '\0';
4891 return IsNum(s
, base
);
4900 debug1("SwitchWindow %d\n", n
);
4901 if (n
< 0 || n
>= MAXWIN
)
4906 if ((p
= wtab
[n
]) == 0)
4918 Msg(0, "This IS window %d (%s).", n
, p
->w_title
);
4922 if (AclCheckPermWin(D_user
, ACL_READ
, p
))
4924 Msg(0, "Access to window %d denied.", p
->w_number
);
4929 Activate(fore
->w_norefresh
);
4934 SetCanvasWindow(cv
, wi
)
4938 struct win
*p
= 0, **pp
;
4940 struct canvas
*cvp
, **cvpp
;
4943 display
= cv
->c_display
;
4947 /* remove old layer */
4948 for (cvpp
= &l
->l_cvlist
; (cvp
= *cvpp
); cvpp
= &cvp
->c_lnext
)
4952 *cvpp
= cvp
->c_lnext
;
4954 p
= Layer2Window(l
);
4958 if (p
&& cv
== D_forecv
)
4961 ReleaseAutoWritelock(display
, p
);
4965 SetTimeout(&p
->w_silenceev
, p
->w_silencewait
* 1000);
4966 evenq(&p
->w_silenceev
);
4971 if (l
->l_cvlist
== 0 && (p
== 0 || l
!= p
->w_savelayer
))
4975 /* find right layer to display on canvas */
4976 if (wi
&& wi
->w_type
!= W_TYPE_GROUP
)
4979 if (wi
->w_savelayer
&& (wi
->w_blocked
|| wi
->w_savelayer
->l_cvlist
== 0))
4980 l
= wi
->w_savelayer
;
4986 l
->l_data
= (char *)wi
;
4991 /* add our canvas to the layer's canvaslist */
4992 ASSERT(l
->l_cvlist
!= cv
);
4993 cv
->c_lnext
= l
->l_cvlist
;
4996 cv
->c_xoff
= cv
->c_xs
;
4997 cv
->c_yoff
= cv
->c_ys
;
4998 RethinkViewportOffsets(cv
);
5003 if (wi
&& wi
->w_type
== W_TYPE_GROUP
)
5005 /* auto-start windowlist on groups */
5006 struct display
*d
= display
;
5007 struct layer
*oldflayer
= flayer
;
5009 display_wlist(0, 0, wi
);
5014 if (wi
&& D_other
== wi
)
5015 D_other
= wi
->w_next
; /* Might be 0, but that's OK. */
5019 fore
= D_fore
; /* XXX ? */
5023 ObtainAutoWritelock(display
, wi
);
5026 * Place the window at the head of the most-recently-used list
5030 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5035 p
->w_next
= windows
;
5045 * SetForeWindow changes the window in the input focus of the display.
5046 * Puts window wi in canvas display->d_forecv.
5058 p
= Layer2Window(D_forecv
->c_layer
);
5059 SetCanvasWindow(D_forecv
, wi
);
5061 WindowChanged(p
, 'u');
5063 WindowChanged(wi
, 'u');
5064 flayer
= D_forecv
->c_layer
;
5065 /* Activate called afterwards, so no RefreshHStatus needed */
5069 /*****************************************************************/
5072 * Activate - make fore window active
5073 * norefresh = -1 forces a refresh, disregard all_norefresh then.
5079 debug1("Activate(%d)\n", norefresh
);
5084 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
5088 if (MayResizeLayer(D_forecv
->c_layer
))
5089 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, display
);
5095 if (fore
->w_monitor
!= MON_OFF
)
5096 fore
->w_monitor
= MON_ON
;
5097 fore
->w_bell
= BELL_ON
;
5098 WindowChanged(fore
, 'f');
5101 if (ResizeDisplay(fore
->w_width
, fore
->w_height
))
5103 debug2("Cannot resize from (%d,%d)", D_width
, D_height
);
5104 debug2(" to (%d,%d) -> resize window\n", fore
->w_width
, fore
->w_height
);
5105 DoResize(D_width
, D_height
);
5109 Redisplay(norefresh
+ all_norefresh
);
5116 register struct win
**pp
;
5117 int n
= fore
? fore
->w_number
: MAXWIN
;
5118 struct win
*group
= fore
? fore
->w_group
: 0;
5120 for (pp
= fore
? wtab
+ n
+ 1 : wtab
; pp
!= wtab
+ n
; pp
++)
5122 if (pp
== wtab
+ MAXWIN
)
5126 if (!fore
|| group
== (*pp
)->w_group
)
5138 register struct win
**pp
;
5139 int n
= fore
? fore
->w_number
: -1;
5140 struct win
*group
= fore
? fore
->w_group
: 0;
5142 for (pp
= wtab
+ n
- 1; pp
!= wtab
+ n
; pp
--)
5145 pp
= wtab
+ MAXWIN
- 1;
5148 if (!fore
|| group
== (*pp
)->w_group
)
5160 char *m
= "No other window.";
5161 if (windows
&& (fore
== 0 || windows
->w_next
))
5165 Msg(0, "No window available");
5168 Msg(0, m
, fore
->w_number
); /* other arg for nethack */
5173 UpdateLayoutCanvas(cv
, wi
)
5177 for (; cv
; cv
= cv
->c_slnext
)
5179 if (cv
->c_layer
&& Layer2Window(cv
->c_layer
) == wi
)
5181 /* A simplistic version of SetCanvasWindow(cv, 0) */
5182 struct layer
*l
= cv
->c_layer
;
5184 if (l
->l_cvlist
== 0 && (wi
== 0 || l
!= wi
->w_savelayer
))
5188 if (l
->l_cvlist
!= cv
)
5190 cv
->c_lnext
= l
->l_cvlist
;
5194 /* Do not end here. Multiple canvases can have the same window */
5198 UpdateLayoutCanvas(cv
->c_slperp
, wi
);
5206 struct win
**pp
, *p
;
5212 * Remove window from linked list.
5214 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5220 wtab
[wi
->w_number
] = 0;
5229 * switch to different window on all canvases
5231 for (display
= displays
; display
; display
= display
->d_next
)
5234 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5236 if (Layer2Window(cv
->c_layer
) != wi
)
5238 /* switch to other window */
5239 SetCanvasWindow(cv
, FindNiceWindow(D_other
, 0));
5245 if (wi
->w_zdisplay
== display
)
5248 D_readev
.condpos
= D_readev
.condneg
= 0;
5255 /* do the same for the layouts */
5256 for (lay
= layouts
; lay
; lay
= lay
->lay_next
)
5257 UpdateLayoutCanvas(&lay
->lay_canvas
, wi
);
5260 WindowChanged((struct win
*)0, 'w');
5261 WindowChanged((struct win
*)0, 'W');
5262 WindowChanged((struct win
*)0, 0);
5271 if ((fore
->w_log
!= 0) == on
)
5273 if (display
&& !*rc_name
)
5274 Msg(0, "You are %s logging.", on
? "already" : "not");
5277 if (fore
->w_log
!= 0)
5279 Msg(0, "Logfile \"%s\" closed.", fore
->w_log
->name
);
5280 logfclose(fore
->w_log
);
5282 WindowChanged(fore
, 'f');
5285 if (DoStartLog(fore
, buf
, sizeof(buf
)))
5287 Msg(errno
, "Error opening logfile \"%s\"", buf
);
5290 if (ftell(fore
->w_log
->fp
) == 0)
5291 Msg(0, "Creating logfile \"%s\".", fore
->w_log
->name
);
5293 Msg(0, "Appending to logfile \"%s\".", fore
->w_log
->name
);
5294 WindowChanged(fore
, 'f');
5298 AddWindows(buf
, len
, flags
, where
)
5304 register char *s
, *ss
;
5305 register struct win
**pp
, *p
;
5310 for (pp
= ((flags
& 4) && where
>= 0) ? wtab
+ where
+ 1: wtab
; pp
< wtab
+ MAXWIN
; pp
++)
5312 if (pp
- wtab
== where
&& ss
== buf
)
5316 if ((flags
& 1) && display
&& p
== D_fore
)
5318 if (D_fore
&& D_fore
->w_group
!= p
->w_group
)
5325 if (s
- buf
+ l
> len
- 24)
5327 if (s
> buf
|| (flags
& 4))
5332 sprintf(s
, "%d", p
->w_number
);
5333 if (p
->w_number
== where
)
5336 if (display
&& p
== D_fore
)
5340 if (display
&& p
== D_other
)
5342 s
= AddWindowFlags(s
, len
, p
);
5353 AddWindowFlags(buf
, len
, p
)
5359 if (p
== 0 || len
< 12)
5365 if (display
&& p
== D_fore
)
5367 if (display
&& p
== D_other
)
5370 if (p
->w_layer
.l_cvlist
&& p
->w_layer
.l_cvlist
->c_lnext
)
5372 if (p
->w_monitor
== MON_DONE
5374 && (ACLBYTE(p
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5378 if (p
->w_bell
== BELL_DONE
)
5381 if (p
->w_slot
!= (slot_t
) 0 && p
->w_slot
!= (slot_t
) -1)
5389 if (p
->w_ptyfd
< 0 && p
->w_type
!= W_TYPE_GROUP
)
5396 AddOtherUsers(buf
, len
, p
)
5401 struct display
*d
, *olddisplay
= display
;
5407 for (display
= displays
; display
; display
= display
->d_next
)
5409 if (olddisplay
&& D_user
== olddisplay
->d_user
)
5411 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5412 if (Layer2Window(cv
->c_layer
) == p
)
5416 for (d
= displays
; d
&& d
!= display
; d
= d
->d_next
)
5417 if (D_user
== d
->d_user
)
5419 if (d
&& d
!= display
)
5421 if (len
> 1 && s
!= buf
)
5426 l
= strlen(D_user
->u_name
);
5429 strcpy(s
, D_user
->u_name
);
5434 display
= olddisplay
;
5447 if (where
== -1 && D_fore
)
5448 where
= D_fore
->w_number
;
5449 ss
= AddWindows(buf
, sizeof(buf
), 0, where
);
5450 s
= buf
+ strlen(buf
);
5451 if (ss
- buf
> D_width
/ 2)
5454 if (s
- ss
< D_width
)
5470 register struct win
*wp
= fore
;
5475 Msg(0, "(%d,%d)/(%d,%d) no window", D_x
+ 1, D_y
+ 1, D_width
, D_height
);
5479 if (buf
< (p
+= GetAnsiStatus(wp
, p
)))
5481 sprintf(p
, "(%d,%d)/(%d,%d)",
5482 wp
->w_x
+ 1, wp
->w_y
+ 1, wp
->w_width
, wp
->w_height
);
5484 sprintf(p
+= strlen(p
), "+%d", wp
->w_histheight
);
5486 sprintf(p
+= strlen(p
), " %c%sflow",
5487 (wp
->w_flow
& FLOW_NOW
) ? '+' : '-',
5488 (wp
->w_flow
& FLOW_AUTOFLAG
) ? "" :
5489 ((wp
->w_flow
& FLOW_AUTO
) ? "(+)" : "(-)"));
5490 if (!wp
->w_wrap
) sprintf(p
+= strlen(p
), " -wrap");
5491 if (wp
->w_insert
) sprintf(p
+= strlen(p
), " ins");
5492 if (wp
->w_origin
) sprintf(p
+= strlen(p
), " org");
5493 if (wp
->w_keypad
) sprintf(p
+= strlen(p
), " app");
5494 if (wp
->w_log
) sprintf(p
+= strlen(p
), " log");
5495 if (wp
->w_monitor
!= MON_OFF
5497 && (ACLBYTE(wp
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5500 sprintf(p
+= strlen(p
), " mon");
5501 if (wp
->w_mouse
) sprintf(p
+= strlen(p
), " mouse");
5503 if (wp
->w_bce
) sprintf(p
+= strlen(p
), " bce");
5505 if (!wp
->w_c1
) sprintf(p
+= strlen(p
), " -c1");
5506 if (wp
->w_norefresh
) sprintf(p
+= strlen(p
), " nored");
5511 if (wp
->w_encoding
&& (display
== 0 || D_encoding
!= wp
->w_encoding
|| EncodingDefFont(wp
->w_encoding
) <= 0))
5514 strcpy(p
, EncodingName(wp
->w_encoding
));
5518 if (wp
->w_encoding
!= UTF8
)
5521 if (D_CC0
|| (D_CS0
&& *D_CS0
))
5525 sprintf(p
, " G%c", wp
->w_Charset
+ '0');
5526 if (wp
->w_FontE
>= ' ')
5531 p
[4] = wp
->w_FontE
^ 0x40;
5538 sprintf(p
++, " G%c%c[", wp
->w_Charset
+ '0', wp
->w_CharsetR
+ '0');
5540 sprintf(p
, " G%c[", wp
->w_Charset
+ '0');
5542 for (i
= 0; i
< 4; i
++)
5544 if (wp
->w_charsets
[i
] == ASCII
)
5546 else if (wp
->w_charsets
[i
] >= ' ')
5547 *p
++ = wp
->w_charsets
[i
];
5551 *p
++ = wp
->w_charsets
[i
] ^ 0x40;
5559 if (wp
->w_type
== W_TYPE_PLAIN
)
5561 /* add info about modem control lines */
5563 TtyGetModemStatus(wp
->w_ptyfd
, p
);
5565 #ifdef BUILTIN_TELNET
5566 else if (wp
->w_type
== W_TYPE_TELNET
)
5569 TelStatus(wp
, p
, sizeof(buf
) - 1 - (p
- buf
));
5572 Msg(0, "%s %d(%s)", buf
, wp
->w_number
, wp
->w_title
);
5582 sprintf(p
, "(%d,%d)", D_width
, D_height
),
5588 strcpy(p
, EncodingName(D_encoding
));
5594 strcpy(p
, " xterm");
5600 strcpy(p
, " color");
5607 strcpy(p
, " iso2022");
5610 else if (D_CS0
&& *D_CS0
)
5612 strcpy(p
, " altchar");
5620 AKAfin(buf
, len
, data
)
5623 char *data
; /* dummy */
5627 ChangeAKA(fore
, buf
, strlen(buf
));
5635 Input("Set window's title to: ", sizeof(fore
->w_akabuf
) - 1, INP_COOKED
, AKAfin
, NULL
, 0);
5641 if ((*(unsigned char *)s
& 0x7f) < 0x20 || *s
== 0x7f)
5645 LayProcess(&ss
, &n
);
5650 Colonfin(buf
, len
, data
)
5653 char *data
; /* dummy */
5658 if (buf
[len
] == '\t')
5661 int l
= 0, r
= RC_LAST
;
5662 int showmessage
= 0;
5665 while (*s
&& s
- buf
< len
)
5669 /* Showing a message when there's no hardstatus or caption cancels the input */
5671 (captionalways
|| D_has_hstatus
== HSTATUS_LASTLINE
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
)))
5677 x
= strncmp(buf
, comms
[m
].name
, len
);
5685 for (l
= m
- 1; l
>= 0 && strncmp(buf
, comms
[l
].name
, len
) == 0; l
--)
5687 for (m
= ++l
; m
<= r
&& strncmp(buf
, comms
[m
].name
, len
) == 0 && s
- mbuf
< sizeof(mbuf
); m
++)
5688 s
+= snprintf(s
, sizeof(mbuf
) - (s
- mbuf
), " %s", comms
[m
].name
);
5692 Msg(0, "Possible commands:%s", mbuf
);
5697 len
= snprintf(mbuf
, sizeof(mbuf
), "%s \t", comms
[l
].name
+ len
);
5698 if (len
> 0 && len
< sizeof(mbuf
))
5699 LayProcess(&s
, &len
);
5704 if (l
> r
&& showmessage
)
5705 Msg(0, "No commands matching '%*s'", len
, buf
);
5709 if (!len
|| buf
[len
])
5712 len
= strlen(buf
) + 1;
5713 if (len
> (int)sizeof(mbuf
))
5717 bcopy(buf
, mbuf
, len
);
5718 RcLine(mbuf
, sizeof mbuf
);
5723 SelectFin(buf
, len
, data
)
5726 char *data
; /* dummy */
5730 if (!len
|| !display
)
5732 if (len
== 1 && *buf
== '-')
5734 SetForeWindow((struct win
*)0);
5738 if ((n
= WindowByNoN(buf
)) < 0)
5744 SelectLayoutFin(buf
, len
, data
)
5747 char *data
; /* dummy */
5751 if (!len
|| !display
)
5753 if (len
== 1 && *buf
== '-')
5755 LoadLayout((struct layout
*)0, (struct canvas
*)0);
5759 lay
= FindLayout(buf
);
5761 Msg(0, "No such layout\n");
5762 else if (lay
== D_layout
)
5763 Msg(0, "This IS layout %d (%s).\n", lay
->lay_number
, lay
->lay_title
);
5766 LoadLayout(lay
, &D_canvas
);
5775 Input("Switch to window: ", 20, INP_COOKED
, SelectFin
, NULL
, 0);
5778 static char setenv_var
[31];
5782 SetenvFin1(buf
, len
, data
)
5785 char *data
; /* dummy */
5787 if (!len
|| !display
)
5793 SetenvFin2(buf
, len
, data
)
5796 char *data
; /* dummy */
5798 if (!len
|| !display
)
5800 debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var
, buf
);
5801 xsetenv(setenv_var
, buf
);
5809 static char setenv_buf
[50 + sizeof(setenv_var
)]; /* need to be static here, cannot be freed */
5813 strncpy(setenv_var
, arg
, sizeof(setenv_var
) - 1);
5814 sprintf(setenv_buf
, "Enter value for %s: ", setenv_var
);
5815 Input(setenv_buf
, 30, INP_COOKED
, SetenvFin2
, NULL
, 0);
5818 Input("Setenv: Enter variable name: ", 30, INP_COOKED
, SetenvFin1
, NULL
, 0);
5822 * the following options are understood by this parser:
5823 * -f, -f0, -f1, -fy, -fa
5824 * -t title, -T terminal-type, -h height-of-scrollback,
5825 * -ln, -l0, -ly, -l1, -l
5832 struct NewWindow nwin
;
5837 while (av
&& *av
&& av
[0][0] == '-')
5839 if (av
[0][1] == '-')
5851 nwin
.flowflag
= FLOW_NOW
* 0;
5856 nwin
.flowflag
= FLOW_NOW
* 1;
5859 nwin
.flowflag
= FLOW_AUTOFLAG
;
5865 case 't': /* no more -k */
5867 nwin
.aka
= &av
[0][2];
5875 nwin
.term
= &av
[0][2];
5883 nwin
.histheight
= atoi(av
[0] + 2);
5885 nwin
.histheight
= atoi(*av
);
5914 nwin
.monitor
= MON_ON
;
5920 Msg(0, "%s: screen: invalid option -%c.", fn
, av
[0][1]);
5926 if (av
&& *av
&& IsNumColon(*av
, 10, buf
, sizeof(buf
)))
5931 if (num
< 0 || num
> MAXWIN
- 1)
5933 Msg(0, "%s: illegal screen number %d.", fn
, num
);
5943 nwin
.aka
= Filename(*av
);
5950 * CompileKeys must be called before Markroutine is first used.
5951 * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
5953 * s is an ascii string in a termcap-like syntax. It looks like
5954 * "j=u:k=d:l=r:h=l: =.:" and so on...
5955 * this example rebinds the cursormovement to the keys u (up), d (down),
5956 * l (left), r (right). placing a mark will now be done with ".".
5959 CompileKeys(s
, sl
, array
)
5962 unsigned char *array
;
5965 unsigned char key
, value
;
5969 for (i
= 0; i
< 256; i
++)
5973 debug1("CompileKeys: '%s'\n", s
);
5976 key
= *(unsigned char *)s
++;
5977 if (*s
!= '=' || sl
< 3)
5984 value
= *(unsigned char *)s
++;
5987 while (*s
== '=' && sl
>= 2);
5996 #endif /* COPY_PASTE */
5999 * Asynchronous input functions
6002 #if defined(DETACH) && defined(POW_DETACH)
6004 pow_detach_fn(buf
, len
, data
)
6007 char *data
; /* dummy */
6009 debug("pow_detach_fn called\n");
6015 if (ktab
[(int)(unsigned char)*buf
].nr
!= RC_POW_DETACH
)
6018 write(D_userfd
, "\007", 1);
6019 Msg(0, "Detach aborted.");
6024 #endif /* POW_DETACH */
6028 copy_reg_fn(buf
, len
, data
)
6031 char *data
; /* dummy */
6033 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6044 if (D_user
->u_plop
.len
)
6046 if ((pp
->buf
= (char *)malloc(D_user
->u_plop
.len
)) == NULL
)
6051 bcopy(D_user
->u_plop
.buf
, pp
->buf
, D_user
->u_plop
.len
);
6053 pp
->len
= D_user
->u_plop
.len
;
6055 pp
->enc
= D_user
->u_plop
.enc
;
6057 Msg(0, "Copied %d characters into register %c", D_user
->u_plop
.len
, *buf
);
6061 ins_reg_fn(buf
, len
, data
)
6064 char *data
; /* dummy */
6066 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6074 return; /* Input() should not call us w/o fore, but you never know... */
6076 Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
6079 MakePaster(&fore
->w_paster
, pp
->buf
, pp
->len
, 0);
6082 Msg(0, "Empty register.");
6084 #endif /* COPY_PASTE */
6087 process_fn(buf
, len
, data
)
6090 char *data
; /* dummy */
6092 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6101 ProcessInput(pp
->buf
, pp
->len
);
6104 Msg(0, "Empty register.");
6108 confirm_fn(buf
, len
, data
)
6115 if (len
|| (*buf
!= 'y' && *buf
!= 'Y'))
6120 act
.nr
= *(int *)data
;
6129 struct acluser
**up
;
6131 char pw1
[130]; /* FreeBSD crypts to 128 bytes */
6136 su_fin(buf
, len
, data
)
6141 struct inputsu
*i
= (struct inputsu
*)data
;
6146 { p
= i
->name
; l
= sizeof(i
->name
) - 1; }
6148 { strcpy(p
= i
->pw1
, "\377"); l
= sizeof(i
->pw1
) - 1; }
6150 { strcpy(p
= i
->pw2
, "\377"); l
= sizeof(i
->pw2
) - 1; }
6152 strncpy(p
, buf
, 1 + (l
< len
) ? l
: len
);
6154 Input("Screen User: ", sizeof(i
->name
) - 1, INP_COOKED
, su_fin
, (char *)i
, 0);
6156 Input("User's UNIX Password: ", sizeof(i
->pw1
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6158 Input("User's Screen Password: ", sizeof(i
->pw2
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6161 if ((p
= DoSu(i
->up
, i
->name
, i
->pw2
, i
->pw1
)))
6168 InputSu(w
, up
, name
)
6170 struct acluser
**up
;
6175 if (!(i
= (struct inputsu
*)calloc(1, sizeof(struct inputsu
))))
6180 su_fin(name
, (int)strlen(name
), (char *)i
); /* can also initialise stuff */
6182 su_fin((char *)0, 0, (char *)i
);
6185 #endif /* MULTIUSER */
6190 pass1(buf
, len
, data
)
6195 struct acluser
*u
= (struct acluser
*)data
;
6200 if (u
->u_password
!= NullStr
)
6201 free((char *)u
->u_password
);
6202 u
->u_password
= SaveStr(buf
);
6203 bzero(buf
, strlen(buf
));
6204 Input("Retype new password:", 100, INP_NOECHO
, pass2
, data
, 0);
6208 pass2(buf
, len
, data
)
6215 struct acluser
*u
= (struct acluser
*)data
;
6218 if (!buf
|| strcmp(u
->u_password
, buf
))
6220 Msg(0, "[ Passwords don't match - checking turned off ]");
6221 if (u
->u_password
!= NullStr
)
6223 bzero(u
->u_password
, strlen(u
->u_password
));
6224 free((char *)u
->u_password
);
6226 u
->u_password
= NullStr
;
6228 else if (u
->u_password
[0] == '\0')
6230 Msg(0, "[ No password - no secure ]");
6232 bzero(buf
, strlen(buf
));
6235 if (u
->u_password
!= NullStr
)
6237 for (st
= 0; st
< 2; st
++)
6238 salt
[st
] = 'A' + (int)((time(0) >> 6 * st
) % 26);
6240 buf
= crypt(u
->u_password
, salt
);
6241 bzero(u
->u_password
, strlen(u
->u_password
));
6242 free((char *)u
->u_password
);
6243 u
->u_password
= SaveStr(buf
);
6244 bzero(buf
, strlen(buf
));
6247 UserFreeCopyBuffer(u
);
6248 u
->u_plop
.len
= strlen(u
->u_password
);
6252 if (!(u
->u_plop
.buf
= SaveStr(u
->u_password
)))
6255 D_user
->u_plop
.len
= 0;
6258 Msg(0, "[ Password moved into copybuffer ]");
6259 #else /* COPY_PASTE */
6260 Msg(0, "[ Crypted password is \"%s\" ]", u
->u_password
);
6261 #endif /* COPY_PASTE */
6264 #endif /* PASSWORD */
6267 digraph_fn(buf
, len
, data
)
6270 char *data
; /* dummy */
6277 buf
[len
+ 1] = ch
; /* so we can restore it later */
6278 if (ch
< ' ' || ch
== '\177')
6280 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6284 if ((ch
< '0' || ch
> '9') && (ch
< 'a' || ch
> 'f') && (ch
< 'A' || ch
> 'F'))
6286 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6289 if (len
== (*buf
== 'U' ? 5 : 3))
6293 if (len
&& *buf
== '0')
6295 if (ch
< '0' || ch
> '7')
6297 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6312 buf
[len
] = buf
[len
+ 1]; /* stored above */
6317 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6320 for (i
= 2; i
< len
; i
++)
6322 if (buf
[i
] >= '0' && buf
[i
] <= '9')
6323 x
= x
* 16 | (buf
[i
] - '0');
6324 else if (buf
[i
] >= 'a' && buf
[i
] <= 'f')
6325 x
= x
* 16 | (buf
[i
] - ('a' - 10));
6326 else if (buf
[i
] >= 'A' && buf
[i
] <= 'F')
6327 x
= x
* 16 | (buf
[i
] - ('A' - 10));
6332 else if (buf
[0] == '0')
6335 for (i
= 1; i
< len
; i
++)
6337 if (buf
[i
] < '0' || buf
[i
] > '7')
6339 x
= x
* 8 | (buf
[i
] - '0');
6344 for (i
= 0; i
< (int)(sizeof(digraphs
)/sizeof(*digraphs
)); i
++)
6345 if ((digraphs
[i
][0] == (unsigned char)buf
[0] && digraphs
[i
][1] == (unsigned char)buf
[1]) ||
6346 (digraphs
[i
][0] == (unsigned char)buf
[1] && digraphs
[i
][1] == (unsigned char)buf
[0]))
6348 if (i
== (int)(sizeof(digraphs
)/sizeof(*digraphs
)))
6350 Msg(0, "Unknown digraph");
6358 if (flayer
->l_encoding
== UTF8
)
6359 i
= ToUtf8(buf
, x
); /* buf is big enough for all UTF-8 codes */
6362 LayProcess(&buf
, &i
);
6373 debug1("StuffKey #%d", i
);
6376 debug1(" - %s", term
[i
+ T_CAPS
].tcname
);
6379 if (i
< KMAP_KEYS
&& D_ESCseen
)
6381 struct action
*act
= &D_ESCseen
[i
+ 256];
6382 if (act
->nr
!= RC_ILLEGAL
)
6385 DoAction(act
, i
+ 256);
6391 if (i
>= T_CURSOR
- T_CAPS
&& i
< T_KEYPAD
- T_CAPS
&& D_cursorkeys
)
6392 i
+= T_OCAPS
- T_CURSOR
;
6393 else if (i
>= T_KEYPAD
- T_CAPS
&& i
< T_OCAPS
- T_CAPS
&& D_keypad
)
6394 i
+= T_OCAPS
- T_CURSOR
;
6395 debug1(" - action %d\n", i
);
6396 flayer
= D_forecv
->c_layer
;
6400 if (InMark() || InInput() || InWList())
6401 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &mmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].mm
;
6403 if ((!act
|| act
->nr
== RC_ILLEGAL
) && !D_mapdefault
)
6404 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &umtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].um
;
6405 if (!act
|| act
->nr
== RC_ILLEGAL
)
6406 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &dmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].dm
;
6408 if (discard
&& (!act
|| act
->nr
!= RC_COMMAND
))
6415 if (act
== 0 || act
->nr
== RC_ILLEGAL
)
6429 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6430 if (Layer2Window(cv
->c_layer
) == wi
)
6436 FindNiceWindow(wi
, presel
)
6442 debug2("FindNiceWindow %d %s\n", wi
? wi
->w_number
: -1 , presel
? presel
: "NULL");
6445 i
= WindowByNoN(presel
);
6452 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6455 if (!wi
|| (IsOnDisplay(wi
) && !presel
))
6457 /* try to get another window */
6460 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6461 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6464 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6465 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6468 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6469 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6472 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6473 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6477 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6478 if (!wi
->w_layer
.l_cvlist
)
6481 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6482 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
))
6486 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6496 AddAlias(name
, value
, args
, argl
, count
)
6503 struct alias
*nalias
= NULL
;
6504 static next_command
= RC_LAST
;
6507 /* Make sure we don't already have this alias name defined. */
6508 if (FindAlias(name
) != NULL
)
6510 Msg(0, "alias already defined: %s", name
);
6514 /* Make sure the alias maps to something */
6515 if ((nr
= FindCommnr((char *)value
)) == RC_ILLEGAL
)
6517 struct alias
*alias
= FindAlias(value
);
6520 Msg(0, "%s: could not find command or alias '%s'", rc_name
, value
);
6526 nalias
= (struct alias
*)calloc(1, sizeof(struct alias
));
6529 nalias
->next
= NULL
;
6530 nalias
->name
= SaveStr(name
);
6534 nalias
->args
= SaveArgs(args
);
6535 nalias
->argl
= calloc(count
+ 1, sizeof(int));
6537 nalias
->argl
[count
] = argl
[count
];
6539 nalias
->nr
= ++next_command
;
6542 nalias
->next
= g_aliases_list
;
6543 g_aliases_list
= nalias
;
6548 * Find an alias by name.
6550 static struct alias
*
6554 struct alias
*t
= g_aliases_list
;
6558 if ((t
->name
!= NULL
) &&
6559 (strcmp(t
->name
, name
) == 0))
6569 * Find an alias by number.
6571 static struct alias
*
6576 for (t
= g_aliases_list
; t
; t
= t
->next
)
6592 /* Find the previous alias */
6593 struct alias
*cur
= g_aliases_list
;
6594 struct alias
**pcur
= &g_aliases_list
;
6598 if ((cur
->name
!= NULL
) &&
6599 (strcmp(cur
->name
, name
) == 0))
6601 struct alias
*found
= cur
;
6604 /* remove this one from the chain. */
6605 *pcur
= found
->next
;
6610 for (c
= 0; found
->args
[c
]; c
++)
6611 free(found
->args
[c
]);
6617 Msg(0, "alias %s removed", name
);
6624 Msg(0, "alias %s not found", name
);
6629 /* sorted list of all commands */
6630 static struct comm
**commtab
;
6631 static int ncommtab
;
6636 void (*hand
) __P((struct comm
*, char **, int));
6639 for (n
= 0; cos
[n
].name
; n
++)
6644 commtab
= (struct commt
*)realloc(commtab
, sizeof(*commtab
) * (ncommtab
+ n
));
6646 commtab
= (struct commt
*)malloc(sizeof(*commtab
) * (ncommtab
+ n
));
6649 for (i
= 0; i
< n
; i
++)
6651 for (j
= 0; j
< ncommtab
; j
++)
6653 r
= strcmp(cos
[i
].name
, commtab
[j
]->name
);
6655 Panic(0, "Duplicate command: %s\n", cos
[i
].name
);
6659 for (r
= ncommtab
; r
> j
; r
--)
6660 commtab
[r
] = commtab
[r
- 1];
6661 commtab
[j
] = cos
+ i
;
6662 cos
[i
].handler
= hand
;
6663 bzero(cos
[i
].userbits
, sizeof(cos
[i
].userbits
));
6672 int x
, m
, l
= 0, r
= ncommtab
- 1;
6676 x
= strcmp(str
, commtab
[m
]->name
);
6690 CalcSlicePercent(cv
, percent
)
6695 if (!cv
|| !cv
->c_slback
)
6697 up
= CalcSlicePercent(cv
->c_slback
->c_slback
, percent
);
6699 for (cv
= cv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6700 wsum
+= cv
->c_slweight
;
6703 return (up
* w
) / wsum
;
6707 ChangeCanvasSize(fcv
, abs
, diff
, gflag
, percent
)
6708 struct canvas
*fcv
; /* make this canvas bigger */
6709 int abs
; /* mode: 0:rel 1:abs 2:max */
6710 int diff
; /* change this much */
6711 int gflag
; /* go up if neccessary */
6715 int done
, have
, m
, dir
;
6717 debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs
, diff
, percent
);
6718 if (abs
== 0 && diff
== 0)
6723 fcv
->c_slweight
= 0;
6726 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6728 fcv
->c_slweight
= 1;
6729 cv
= fcv
->c_slback
->c_slback
;
6730 if (gflag
&& cv
&& cv
->c_slback
)
6731 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6739 if (percent
&& diff
> percent
)
6745 for (cv
= fcv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6746 wsum
+= cv
->c_slweight
;
6749 up
= gflag
? CalcSlicePercent(fcv
->c_slback
->c_slback
, percent
) : percent
;
6750 debug3("up=%d, wsum=%d percent=%d\n", up
, wsum
, percent
);
6753 int scale
= wsum
< 10 ? 1000 : 100;
6754 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6755 cv
->c_slweight
*= scale
;
6757 debug1("scaled wsum to %d\n", wsum
);
6759 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6763 cv
->c_slweight
= (cv
->c_slweight
* up
) / percent
;
6764 if (cv
->c_slweight
== 0)
6767 debug1(" - weight %d\n", cv
->c_slweight
);
6769 diff
= (diff
* wsum
) / percent
;
6775 if (abs
&& diff
== (fcv
->c_slorient
== SLICE_VERT
? fcv
->c_ye
- fcv
->c_ys
+ 2 : fcv
->c_xe
- fcv
->c_xs
+ 2))
6777 /* fix weights to real size (can't be helped, sorry) */
6778 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6780 cv
->c_slweight
= cv
->c_slorient
== SLICE_VERT
? cv
->c_ye
- cv
->c_ys
+ 2 : cv
->c_xe
- cv
->c_xs
+ 2;
6781 debug1(" - weight %d\n", cv
->c_slweight
);
6785 diff
= diff
- fcv
->c_slweight
;
6786 debug1("diff = %d\n", diff
);
6791 cv
= fcv
->c_slnext
? fcv
->c_slnext
: fcv
->c_slprev
;
6792 fcv
->c_slweight
+= diff
;
6793 cv
->c_slweight
-= diff
;
6798 for (cv
= fcv
->c_slnext
; diff
> 0; cv
= dir
> 0 ? cv
->c_slnext
: cv
->c_slprev
)
6802 debug1("reached end, dir is %d\n", dir
);
6812 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 : 2;
6813 debug2("min is %d, have %d\n", m
, cv
->c_slweight
);
6814 if (cv
->c_slweight
> m
)
6816 have
= cv
->c_slweight
- m
;
6819 debug1("subtract %d\n", have
);
6820 cv
->c_slweight
-= have
;
6827 /* need more room! */
6828 cv
= fcv
->c_slback
->c_slback
;
6829 if (cv
&& cv
->c_slback
)
6830 done
+= ChangeCanvasSize(fcv
->c_slback
->c_slback
, 0, diff
, gflag
, percent
);
6832 fcv
->c_slweight
+= done
;
6833 debug1("ChangeCanvasSize returns %d\n", done
);
6838 ResizeRegions(arg
, flags
)
6844 int gflag
= 0, abs
= 0, percent
= 0;
6850 if (D_forecv
->c_slorient
== SLICE_UNKN
)
6852 Msg(0, "resize: need more than one region");
6855 gflag
= flags
& RESIZE_FLAG_L
? 0 : 1;
6856 orient
|= flags
& RESIZE_FLAG_H
? SLICE_HORI
: 0;
6857 orient
|= flags
& RESIZE_FLAG_V
? SLICE_VERT
: 0;
6859 orient
= D_forecv
->c_slorient
;
6863 /* make all regions the same height */
6864 struct canvas
*cv
= gflag
? &D_canvas
: D_forecv
->c_slback
;
6865 if (cv
->c_slperp
->c_slorient
& orient
)
6866 EqualizeCanvas(cv
->c_slperp
, gflag
);
6867 /* can't use cv->c_slorient directly as it can be D_canvas */
6868 if ((cv
->c_slperp
->c_slorient
^ (SLICE_HORI
^ SLICE_VERT
)) & orient
)
6873 EqualizeCanvas(cv
->c_slperp
, gflag
);
6876 EqualizeCanvas(cv
, gflag
);
6879 RecreateCanvasChain();
6880 RethinkDisplayViewports();
6881 ResizeLayersToCanvases();
6884 if (!strcmp(arg
, "min") || !strcmp(arg
, "0"))
6889 else if (!strcmp(arg
, "max") || !strcmp(arg
, "_"))
6896 if (l
> 0 && arg
[l
- 1] == '%')
6899 diff
= atoi(arg
+ 1);
6900 else if (*arg
== '-')
6901 diff
= -atoi(arg
+ 1);
6904 diff
= atoi(arg
); /* +1 because of caption line */
6907 abs
= diff
== 0 ? 2 : 1;
6913 diff
= diff
* percent
/ 100;
6915 if (cv
->c_slorient
& orient
)
6916 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6917 if (cv
->c_slback
->c_slorient
& orient
)
6918 ChangeCanvasSize(cv
->c_slback
, abs
, diff
, gflag
, percent
);
6920 ResizeCanvas(&D_canvas
);
6921 RecreateCanvasChain();
6922 RethinkDisplayViewports();
6923 ResizeLayersToCanvases();
6930 if (siz
+ diff
> dsize
- (nreg
- 1) * 2 - 1)
6931 diff
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6932 if (diff
== 0 || siz
+ diff
< 1)
6937 if (D_forecv
->c_next
)
6939 D_forecv
->c_ye
+= diff
;
6940 D_forecv
->c_next
->c_ys
+= diff
;
6941 D_forecv
->c_next
->c_yoff
+= diff
;
6945 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6946 if (cv
->c_next
== D_forecv
)
6950 D_forecv
->c_ys
-= diff
;
6951 D_forecv
->c_yoff
-= diff
;
6956 int s
, i
= 0, found
= 0, di
= diff
, d2
;
6957 s
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6958 for (cv
= D_cvlist
; cv
; i
= cv
->c_ye
+ 2, cv
= cv
->c_next
)
6962 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) + diff
;
6963 cv
->c_yoff
-= cv
->c_ys
- i
;
6968 s
-= cv
->c_ye
- cv
->c_ys
;
6976 d2
= di
> cv
->c_ye
- cv
->c_ys
? cv
->c_ye
- cv
->c_ys
: di
;
6978 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) - d2
;
6979 cv
->c_yoff
-= cv
->c_ys
- i
;
6983 RethinkDisplayViewports();
6984 ResizeLayersToCanvases();
6989 ResizeFin(buf
, len
, data
)
6995 int flags
= *(int *)data
;
6996 ch
= ((unsigned char *)buf
)[len
];
6999 ResizeRegions(buf
, flags
);
7003 flags
^= RESIZE_FLAG_H
;
7005 flags
^= RESIZE_FLAG_V
;
7007 flags
|= RESIZE_FLAG_H
|RESIZE_FLAG_V
;
7009 flags
^= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
7011 flags
^= RESIZE_FLAG_L
;
7014 inp_setprompt(resizeprompts
[flags
], NULL
);
7015 *(int *)data
= flags
;
7026 p
= Layer2Window(D_forecv
->c_layer
);
7027 for (i
= 3; i
>=0; i
--)
7028 SetXtermOSC(i
, p
? p
->w_xtermosc
[i
] : 0);
7033 ParseAttrColor(s1
, s2
, msgok
)
7045 while (*ss
&& *ss
!= ' ')
7049 if (*s
&& (s2
|| *ss
|| !((*s
>= 'a' && *s
<= 'z') || (*s
>= 'A' && *s
<= 'Z') || *s
== '.')))
7051 int mode
= 0, n
= 0;
7069 if (*s
>= '0' && *s
<= '9')
7072 if (*s
>= '0' && *s
<= '9')
7073 n
= n
* 16 + (*s
++ - '0');
7074 else if (*s
>= 'a' && *s
<= 'f')
7075 n
= n
* 16 + (*s
++ - ('a' - 10));
7076 else if (*s
>= 'A' && *s
<= 'F')
7077 n
= n
* 16 + (*s
++ - ('A' - 10));
7078 else if (*s
&& *s
!= ' ')
7081 Msg(0, "Illegal attribute hexchar '%c'", *s
);
7087 while (*s
&& *s
!= ' ')
7104 Msg(0, "Illegal attribute specifier '%c'", *s
);
7110 if (*s
&& *s
!= ' ')
7113 Msg(0, "junk after attribute description: '%c'", *s
);
7125 while (*s
&& *s
== ' ')
7133 Msg(0, "junk after description: '%c'", *s
);
7137 while (*s
&& *s
== ' ')
7144 static char costr
[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
7154 for (j
= 0; j
< 2 && *s
&& *s
!= ' '; j
++)
7156 for (i
= 0; costr
[i
]; i
++)
7162 Msg(0, "illegal color descriptor: '%c'", *s
);
7166 n
= n
<< 4 | (i
& 15);
7169 n
= (n
& 0x20ff) | 0x200;
7173 if ((n
& 0xf00) == 0xf00)
7174 n
^= 0xf00; /* clear superflous bits */
7177 n
^= 0x2400; /* shift bit into right position */
7180 n
|= 0xf0; /* don't change bg color */
7181 if (numco
!= 2 && n
!= 0xff)
7182 n
|= 0x100; /* special invert mode */
7183 if (*s
&& *s
!= ' ')
7186 Msg(0, "junk after color description: '%c'", *s
);
7194 while (*s
&& *s
== ' ')
7199 Msg(0, "junk after description: '%c'", *s
);
7202 debug1("ParseAttrColor %06x\n", r
);
7210 * e just set intensity
7211 * f don't change anything
7212 * Intensity is encoded into bits 17(fg) and 18(bg).
7215 ApplyAttrColor(i
, mc
)
7219 debug1("ApplyAttrColor %06x\n", i
);
7220 mc
->attr
|= i
>> 8 & 255;
7221 mc
->attr
^= i
& 255;
7223 i
= (i
>> 16) ^ 0xff;
7224 if ((i
& 0x100) != 0)
7227 if (mc
->attr
& (A_SO
|A_RV
))
7229 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4) | ((i
& 0x200) << 1) | ((i
& 0x400) >> 1);
7231 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4);
7235 if ((i
& 0x0f) != 0x0f)
7236 mc
->attr
= (mc
->attr
& 0xbf) | ((i
>> 3) & 0x40);
7237 if ((i
& 0xf0) != 0xf0)
7238 mc
->attr
= (mc
->attr
& 0x7f) | ((i
>> 3) & 0x80);
7240 mc
->color
= 0x99 ^ mc
->color
;
7241 if ((i
& 0x0e) == 0x0e)
7242 i
= (i
& 0xf0) | (mc
->color
& 0x0f);
7243 if ((i
& 0xe0) == 0xe0)
7244 i
= (i
& 0x0f) | (mc
->color
& 0xf0);
7245 mc
->color
= 0x99 ^ i
;
7246 debug2("ApplyAttrColor - %02x %02x\n", mc
->attr
, i
);