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((const char *, 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
, act
->args
, act
->argl
);
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 or alias '%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 or alias '%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 struct alias
*alias
= FindAlias(args
[1]);
4035 Msg(0, "%s: idle: unknown command or alias '%s'", rc_name
, args
[1]);
4040 if (i
<= RC_LAST
&& CheckArgNum(i
, args
+ 2) < 0)
4042 ClearAction(&idleaction
);
4043 SaveAction(&idleaction
, i
, args
+ 2, argl
+ 2);
4045 for (display
= displays
; display
; display
= display
->d_next
)
4047 display
= olddisplay
;
4052 Msg(0, "idle timeout %ds, %s", idletimo
/ 1000, comms
[idleaction
.nr
].name
);
4057 case RC_FOCUSMINSIZE
:
4058 for (i
= 0; i
< 2 && args
[i
]; i
++)
4060 if (!strcmp(args
[i
], "max") || !strcmp(args
[i
], "_"))
4072 for (i
= 0; i
< 2; i
++)
4074 n
= i
== 0 ? focusminwidth
: focusminheight
;
4076 strcpy(b
[i
], "max");
4078 sprintf(b
[i
], "%d", n
);
4080 Msg(0, "focus min size is %s %s\n", b
[0], b
[1]);
4089 fore
->w_group
= WindowByName(*args
);
4090 if (fore
->w_group
&& fore
->w_group
->w_type
!= W_TYPE_GROUP
)
4093 WindowChanged((struct win
*)0, 'w');
4094 WindowChanged((struct win
*)0, 'W');
4095 WindowChanged((struct win
*)0, 0);
4100 Msg(0, "window group is %d (%s)\n", fore
->w_group
->w_number
, fore
->w_group
->w_title
);
4102 Msg(0, "window belongs to no group");
4106 if (!strcmp(args
[0], "title"))
4110 Msg(0, "not on a layout");
4115 Msg(0, "current layout is %d (%s)", D_layout
->lay_number
, D_layout
->lay_title
);
4118 free(D_layout
->lay_title
);
4119 D_layout
->lay_title
= SaveStr(args
[1]);
4121 else if (!strcmp(args
[0], "number"))
4127 Msg(0, "This is layout %d (%s).\n", D_layout
->lay_number
, D_layout
->lay_title
);
4130 old
= D_layout
->lay_number
;
4132 if (n
< 0 || n
>= MAXLAY
)
4135 laytab
[n
] = D_layout
;
4136 D_layout
->lay_number
= n
;
4139 lay
->lay_number
= old
;
4142 else if (!strcmp(args
[0], "autosave"))
4146 Msg(0, "not on a layout");
4151 if (!strcmp(args
[1], "on"))
4152 D_layout
->lay_autosave
= 1;
4153 else if (!strcmp(args
[1], "off"))
4154 D_layout
->lay_autosave
= 0;
4157 Msg(0, "invalid argument. Give 'on' or 'off");
4162 Msg(0, "autosave is %s", D_layout
->lay_autosave
? "on" : "off");
4164 else if (!strcmp(args
[0], "new"))
4170 while (*t
>= '0' && *t
<= '9')
4172 if (t
!= args
[1] && (!*t
|| *t
== ':'))
4186 else if (!strcmp(args
[0], "save"))
4190 Msg(0, "usage: layout save <name>");
4193 SaveLayout(args
[1], &D_canvas
);
4195 else if (!strcmp(args
[0], "select"))
4199 Input("Switch to layout: ", 20, INP_COOKED
, SelectLayoutFin
, NULL
, 0);
4202 SelectLayoutFin(args
[1], strlen(args
[1]), (char *)0);
4204 else if (!strcmp(args
[0], "next"))
4206 struct layout
*lay
= D_layout
;
4208 lay
= lay
->lay_next
? lay
->lay_next
: layouts
;
4213 Msg(0, "no layout defined");
4216 if (lay
== D_layout
)
4218 LoadLayout(lay
, &D_canvas
);
4221 else if (!strcmp(args
[0], "prev"))
4223 struct layout
*lay
= D_layout
;
4226 for (lay
= layouts
; lay
->lay_next
&& lay
->lay_next
!= D_layout
; lay
= lay
->lay_next
)
4233 Msg(0, "no layout defined");
4236 if (lay
== D_layout
)
4238 LoadLayout(lay
, &D_canvas
);
4241 else if (!strcmp(args
[0], "attach"))
4246 Msg(0, "no attach layout set");
4247 else if (layout_attach
== &layout_last_marker
)
4248 Msg(0, "will attach to last layout");
4250 Msg(0, "will attach to layout %d (%s)", layout_attach
->lay_number
, layout_attach
->lay_title
);
4253 if (!strcmp(args
[1], ":last"))
4254 layout_attach
= &layout_last_marker
;
4255 else if (!args
[1][0])
4260 lay
= FindLayout(args
[1]);
4263 Msg(0, "unknown layout '%s'", args
[1]);
4266 layout_attach
= lay
;
4269 else if (!strcmp(args
[0], "show"))
4273 else if (!strcmp(args
[0], "remove"))
4275 struct layout
*lay
= display
? D_layout
: layouts
;
4278 lay
= layouts
? FindLayout(args
[1]) : (struct layout
*)0;
4281 Msg(0, "unknown layout '%s'", args
[1]);
4289 Msg(0, "unknown layout subcommand");
4293 if(ParseSwitch(act
, &cjkwidth
) == 0)
4296 Msg(0, "Treat ambiguous width characters as %s width", cjkwidth
? "full" : "half");
4302 /* key == -2: input from braille keybord, msgok always 0 */
4303 DoBrailleAction(act
, key
== -2 ? 0 : msgok
);
4307 if (display
!= odisplay
)
4309 for (display
= displays
; display
; display
= display
->d_next
)
4310 if (display
== odisplay
)
4316 DoAlias(name
, args
, argl
)
4324 struct alias
*alias
= FindAlias(name
);
4330 for (; args
&& args
[count
]; count
++)
4332 for (i
= 0; alias
->args
&& alias
->args
[i
]; i
++, count
++)
4336 if ((mergeds
= malloc(count
* sizeof(char *))) == 0)
4338 if ((mergedl
= malloc(count
* sizeof(int))) == 0)
4343 for (count
= 0; alias
->args
&& alias
->args
[count
]; count
++)
4345 mergeds
[count
] = alias
->args
[count
];
4346 mergedl
[count
] = alias
->argl
[count
];
4348 for (i
= 0; args
&& args
[i
]; i
++, count
++)
4350 mergeds
[count
] = args
[i
];
4351 mergedl
[count
] = argl
[i
];
4354 mergedl
[count
] = 0 ;
4356 DoCommand(mergeds
, mergedl
);
4364 DoCommand(argv
, argl
)
4371 if (DoAlias(*argv
, argv
+ 1, argl
+ 1))
4374 if ((act
.nr
= FindCommnr(*argv
)) == RC_ILLEGAL
)
4376 Msg(0, "%s: unknown command '%s'", rc_name
, *argv
);
4379 act
.args
= argv
+ 1;
4380 act
.argl
= argl
+ 1;
4385 SaveAction(act
, nr
, args
, argl
)
4391 register int argc
= 0;
4405 if ((pp
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4407 if ((lp
= (int *)malloc((unsigned)(argc
) * sizeof(int *))) == 0)
4414 *lp
= argl
? *argl
++ : (int)strlen(*args
);
4415 *pp
++ = SaveStrn(*args
++, *lp
++);
4424 register char **ap
, **pp
;
4425 register int argc
= 0;
4429 if ((pp
= ap
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4432 *pp
++ = SaveStr(*args
++);
4439 * buf is split into argument vector args.
4440 * leading whitespace is removed.
4441 * @!| abbreviations are expanded.
4442 * the end of buffer is recognized by '\0' or an un-escaped '#'.
4443 * " and ' are interpreted.
4448 Parse(buf
, bufl
, args
, argl
)
4452 register char *p
= buf
, **ap
= args
, *pp
;
4453 register int delim
, argc
;
4456 debug2("Parse %d %s\n", bufl
, buf
);
4462 while (*p
&& (*p
== ' ' || *p
== '\t'))
4465 if (argc
== 0 && *p
== '!')
4474 if (*p
== '\0' || *p
== '#' || *p
== '\n')
4477 for (delim
= 0; delim
< argc
; delim
++)
4478 debug1("-- %s\n", args
[delim
]);
4482 if (++argc
>= MAXARGS
)
4484 Msg(0, "%s: too many tokens.", rc_name
);
4489 debug1("- new arg %s\n", p
);
4494 else if (delim
!= '\'' && *p
== '\\' && (p
[1] == '\'' || p
[1] == '"' || p
[1] == '\\' || p
[1] == '$' || p
[1] == '#' || p
[1] == '^' || (p
[1] >= '0' && p
[1] <= '7')))
4497 if (*p
>= '0' && *p
<= '7')
4500 if (p
[1] >= '0' && p
[1] <= '7')
4503 *pp
= (*pp
<< 3) | (*p
- '0');
4504 if (p
[1] >= '0' && p
[1] <= '7')
4507 *pp
= (*pp
<< 3) | (*p
- '0');
4515 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] == '_'))
4518 char *ps
, *pe
, op
, *v
, xbuf
[11];
4522 debug1("- var %s\n", ps
);
4526 if (*ps
== '{' && *p
== '}')
4528 if (*ps
== ':' && *p
== ':')
4530 if (*ps
!= '{' && *ps
!= ':' && (*p
< 'a' || *p
> 'z') && (*p
< 'A' || *p
> 'Z') && (*p
< '0' || *p
> '9') && *p
!= '_')
4535 if (*ps
== '{' || *ps
== ':')
4539 Msg(0, "%s: bad variable name.", rc_name
);
4546 debug1("- var is '%s'\n", ps
);
4548 v
= gettermcapstring(ps
+ 1);
4554 if (!strcmp(ps
, "TERM"))
4555 v
= display
? D_termname
: "unknown";
4556 else if (!strcmp(ps
, "COLUMNS"))
4557 sprintf(xbuf
, "%d", display
? D_width
: -1);
4558 else if (!strcmp(ps
, "LINES"))
4559 sprintf(xbuf
, "%d", display
? D_height
: -1);
4564 vl
= v
? strlen(v
) : 0;
4567 debug1("- sub is '%s'\n", v
);
4570 int right
= buf
+ bufl
- (p
+ strlen(p
) + 1);
4573 bcopy(p
, p
+ right
, strlen(p
) + 1);
4579 Msg(0, "%s: no space left for variable expansion.", rc_name
);
4587 else if (delim
!= '\'' && *p
== '^' && p
[1])
4590 *pp
++ = *p
== '?' ? '\177' : *p
& 0x1f;
4592 else if (delim
== 0 && (*p
== '\'' || *p
== '"'))
4594 else if (delim
== 0 && (*p
== ' ' || *p
== '\t' || *p
== '\n'))
4602 Msg(0, "%s: Missing %c quote.", rc_name
, delim
);
4608 debug2("- arg done, '%s' rest %s\n", ap
[-1], p
);
4609 *lp
++ = pp
- ap
[-1];
4628 if (DefaultEsc
>= 0)
4629 ClearAction(&ktab
[DefaultEsc
]);
4630 if (DefaultMetaEsc
>= 0)
4631 ClearAction(&ktab
[DefaultMetaEsc
]);
4634 DefaultMetaEsc
= me
;
4637 if (DefaultEsc
>= 0)
4639 ClearAction(&ktab
[DefaultEsc
]);
4640 ktab
[DefaultEsc
].nr
= RC_OTHER
;
4642 if (DefaultMetaEsc
>= 0)
4644 ClearAction(&ktab
[DefaultMetaEsc
]);
4645 ktab
[DefaultMetaEsc
].nr
= RC_META
;
4652 ParseSwitch(act
, var
)
4656 if (*act
->args
== 0)
4661 return ParseOnOff(act
, var
);
4665 ParseOnOff(act
, var
)
4669 register int num
= -1;
4670 char **args
= act
->args
;
4674 if (strcmp(args
[0], "on") == 0)
4676 else if (strcmp(args
[0], "off") == 0)
4681 Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name
, comms
[act
->nr
].name
);
4689 ParseSaveStr(act
, var
)
4693 char **args
= act
->args
;
4694 if (*args
== 0 || args
[1])
4696 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4701 *var
= SaveStr(*args
);
4711 char *p
, **args
= act
->args
;
4714 if (p
== 0 || *p
== 0 || args
[1])
4716 Msg(0, "%s: %s: invalid argument. Give one argument.",
4717 rc_name
, comms
[act
->nr
].name
);
4723 if (*p
>= '0' && *p
<= '9')
4724 i
= 10 * i
+ (*p
- '0');
4727 Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4728 rc_name
, comms
[act
->nr
].name
);
4733 debug1("ParseNum got %d\n", i
);
4739 ParseNum1000(act
, var
)
4744 char *p
, **args
= act
->args
;
4748 if (p
== 0 || *p
== 0 || args
[1])
4750 Msg(0, "%s: %s: invalid argument. Give one argument.",
4751 rc_name
, comms
[act
->nr
].name
);
4757 if (*p
>= '0' && *p
<= '9')
4760 i
= 10 * i
+ (*p
- '0');
4761 else if (dig
== 4 && *p
>= '5')
4766 else if (*p
== '.' && !dig
)
4770 Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4771 rc_name
, comms
[act
->nr
].name
);
4782 i
= (int)((unsigned int)~0 >> 1);
4783 debug1("ParseNum1000 got %d\n", i
);
4794 for (p
= windows
; p
; p
= p
->w_next
)
4795 if (!strcmp(p
->w_title
, s
))
4797 for (p
= windows
; p
; p
= p
->w_next
)
4798 if (!strncmp(p
->w_title
, s
, strlen(s
)))
4810 for (i
= 0, s
= str
; *s
; s
++)
4812 if (*s
< '0' || *s
> '9')
4814 i
= i
* 10 + (*s
- '0');
4820 * Get window number from Name or Number string.
4821 * Numbers are tried first, then names, a prefix match suffices.
4822 * Be careful when assigning numeric strings as WindowTitles.
4831 if ((i
= WindowByNumber(str
)) < 0 || i
>= MAXWIN
)
4833 if ((p
= WindowByName(str
)))
4841 ParseWinNum(act
, var
)
4845 char **args
= act
->args
;
4848 if (*args
== 0 || args
[1])
4850 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4854 i
= WindowByNoN(*args
);
4857 Msg(0, "%s: %s: invalid argument. Give window number or name.",
4858 rc_name
, comms
[act
->nr
].name
);
4861 debug1("ParseWinNum got %d\n", i
);
4867 ParseBase(act
, p
, var
, base
, bname
)
4879 Msg(0, "%s: %s: empty argument.", rc_name
, comms
[act
->nr
].name
);
4884 if (c
>= 'a' && c
<= 'z')
4886 if (c
>= 'A' && c
<= 'Z')
4887 c
-= 'A' - ('0' + 10);
4889 if (c
< 0 || c
>= base
)
4891 Msg(0, "%s: %s: argument is not %s.", rc_name
, comms
[act
->nr
].name
, bname
);
4896 debug1("ParseBase got %d\n", i
);
4906 for (base
+= '0'; *s
; ++s
)
4907 if (*s
< '0' || *s
> base
)
4913 IsNumColon(s
, base
, p
, psize
)
4918 if ((q
= rindex(s
, ':')) != 0)
4920 strncpy(p
, q
+ 1, psize
- 1);
4921 p
[psize
- 1] = '\0';
4926 return IsNum(s
, base
);
4935 debug1("SwitchWindow %d\n", n
);
4936 if (n
< 0 || n
>= MAXWIN
)
4941 if ((p
= wtab
[n
]) == 0)
4953 Msg(0, "This IS window %d (%s).", n
, p
->w_title
);
4957 if (AclCheckPermWin(D_user
, ACL_READ
, p
))
4959 Msg(0, "Access to window %d denied.", p
->w_number
);
4964 Activate(fore
->w_norefresh
);
4969 SetCanvasWindow(cv
, wi
)
4973 struct win
*p
= 0, **pp
;
4975 struct canvas
*cvp
, **cvpp
;
4978 display
= cv
->c_display
;
4982 /* remove old layer */
4983 for (cvpp
= &l
->l_cvlist
; (cvp
= *cvpp
); cvpp
= &cvp
->c_lnext
)
4987 *cvpp
= cvp
->c_lnext
;
4989 p
= Layer2Window(l
);
4993 if (p
&& cv
== D_forecv
)
4996 ReleaseAutoWritelock(display
, p
);
5000 SetTimeout(&p
->w_silenceev
, p
->w_silencewait
* 1000);
5001 evenq(&p
->w_silenceev
);
5006 if (l
->l_cvlist
== 0 && (p
== 0 || l
!= p
->w_savelayer
))
5010 /* find right layer to display on canvas */
5011 if (wi
&& wi
->w_type
!= W_TYPE_GROUP
)
5014 if (wi
->w_savelayer
&& (wi
->w_blocked
|| wi
->w_savelayer
->l_cvlist
== 0))
5015 l
= wi
->w_savelayer
;
5021 l
->l_data
= (char *)wi
;
5026 /* add our canvas to the layer's canvaslist */
5027 ASSERT(l
->l_cvlist
!= cv
);
5028 cv
->c_lnext
= l
->l_cvlist
;
5031 cv
->c_xoff
= cv
->c_xs
;
5032 cv
->c_yoff
= cv
->c_ys
;
5033 RethinkViewportOffsets(cv
);
5038 if (wi
&& wi
->w_type
== W_TYPE_GROUP
)
5040 /* auto-start windowlist on groups */
5041 struct display
*d
= display
;
5042 struct layer
*oldflayer
= flayer
;
5044 display_wlist(0, 0, wi
);
5049 if (wi
&& D_other
== wi
)
5050 D_other
= wi
->w_next
; /* Might be 0, but that's OK. */
5054 fore
= D_fore
; /* XXX ? */
5058 ObtainAutoWritelock(display
, wi
);
5061 * Place the window at the head of the most-recently-used list
5065 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5070 p
->w_next
= windows
;
5080 * SetForeWindow changes the window in the input focus of the display.
5081 * Puts window wi in canvas display->d_forecv.
5093 p
= Layer2Window(D_forecv
->c_layer
);
5094 SetCanvasWindow(D_forecv
, wi
);
5096 WindowChanged(p
, 'u');
5098 WindowChanged(wi
, 'u');
5099 flayer
= D_forecv
->c_layer
;
5100 /* Activate called afterwards, so no RefreshHStatus needed */
5104 /*****************************************************************/
5107 * Activate - make fore window active
5108 * norefresh = -1 forces a refresh, disregard all_norefresh then.
5114 debug1("Activate(%d)\n", norefresh
);
5119 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
5123 if (MayResizeLayer(D_forecv
->c_layer
))
5124 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, display
);
5130 if (fore
->w_monitor
!= MON_OFF
)
5131 fore
->w_monitor
= MON_ON
;
5132 fore
->w_bell
= BELL_ON
;
5133 WindowChanged(fore
, 'f');
5136 if (ResizeDisplay(fore
->w_width
, fore
->w_height
))
5138 debug2("Cannot resize from (%d,%d)", D_width
, D_height
);
5139 debug2(" to (%d,%d) -> resize window\n", fore
->w_width
, fore
->w_height
);
5140 DoResize(D_width
, D_height
);
5144 Redisplay(norefresh
+ all_norefresh
);
5151 register struct win
**pp
;
5152 int n
= fore
? fore
->w_number
: MAXWIN
;
5153 struct win
*group
= fore
? fore
->w_group
: 0;
5155 for (pp
= fore
? wtab
+ n
+ 1 : wtab
; pp
!= wtab
+ n
; pp
++)
5157 if (pp
== wtab
+ MAXWIN
)
5161 if (!fore
|| group
== (*pp
)->w_group
)
5173 register struct win
**pp
;
5174 int n
= fore
? fore
->w_number
: -1;
5175 struct win
*group
= fore
? fore
->w_group
: 0;
5177 for (pp
= wtab
+ n
- 1; pp
!= wtab
+ n
; pp
--)
5180 pp
= wtab
+ MAXWIN
- 1;
5183 if (!fore
|| group
== (*pp
)->w_group
)
5195 char *m
= "No other window.";
5196 if (windows
&& (fore
== 0 || windows
->w_next
))
5200 Msg(0, "No window available");
5203 Msg(0, m
, fore
->w_number
); /* other arg for nethack */
5208 UpdateLayoutCanvas(cv
, wi
)
5212 for (; cv
; cv
= cv
->c_slnext
)
5214 if (cv
->c_layer
&& Layer2Window(cv
->c_layer
) == wi
)
5216 /* A simplistic version of SetCanvasWindow(cv, 0) */
5217 struct layer
*l
= cv
->c_layer
;
5219 if (l
->l_cvlist
== 0 && (wi
== 0 || l
!= wi
->w_savelayer
))
5223 if (l
->l_cvlist
!= cv
)
5225 cv
->c_lnext
= l
->l_cvlist
;
5229 /* Do not end here. Multiple canvases can have the same window */
5233 UpdateLayoutCanvas(cv
->c_slperp
, wi
);
5241 struct win
**pp
, *p
;
5247 * Remove window from linked list.
5249 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5255 wtab
[wi
->w_number
] = 0;
5264 * switch to different window on all canvases
5266 for (display
= displays
; display
; display
= display
->d_next
)
5269 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5271 if (Layer2Window(cv
->c_layer
) != wi
)
5273 /* switch to other window */
5274 SetCanvasWindow(cv
, FindNiceWindow(D_other
, 0));
5280 if (wi
->w_zdisplay
== display
)
5283 D_readev
.condpos
= D_readev
.condneg
= 0;
5290 /* do the same for the layouts */
5291 for (lay
= layouts
; lay
; lay
= lay
->lay_next
)
5292 UpdateLayoutCanvas(&lay
->lay_canvas
, wi
);
5295 WindowChanged((struct win
*)0, 'w');
5296 WindowChanged((struct win
*)0, 'W');
5297 WindowChanged((struct win
*)0, 0);
5306 if ((fore
->w_log
!= 0) == on
)
5308 if (display
&& !*rc_name
)
5309 Msg(0, "You are %s logging.", on
? "already" : "not");
5312 if (fore
->w_log
!= 0)
5314 Msg(0, "Logfile \"%s\" closed.", fore
->w_log
->name
);
5315 logfclose(fore
->w_log
);
5317 WindowChanged(fore
, 'f');
5320 if (DoStartLog(fore
, buf
, sizeof(buf
)))
5322 Msg(errno
, "Error opening logfile \"%s\"", buf
);
5325 if (ftell(fore
->w_log
->fp
) == 0)
5326 Msg(0, "Creating logfile \"%s\".", fore
->w_log
->name
);
5328 Msg(0, "Appending to logfile \"%s\".", fore
->w_log
->name
);
5329 WindowChanged(fore
, 'f');
5333 AddWindows(buf
, len
, flags
, where
)
5339 register char *s
, *ss
;
5340 register struct win
**pp
, *p
;
5345 for (pp
= ((flags
& 4) && where
>= 0) ? wtab
+ where
+ 1: wtab
; pp
< wtab
+ MAXWIN
; pp
++)
5347 if (pp
- wtab
== where
&& ss
== buf
)
5351 if ((flags
& 1) && display
&& p
== D_fore
)
5353 if (D_fore
&& D_fore
->w_group
!= p
->w_group
)
5360 if (s
- buf
+ l
> len
- 24)
5362 if (s
> buf
|| (flags
& 4))
5367 sprintf(s
, "%d", p
->w_number
);
5368 if (p
->w_number
== where
)
5371 if (display
&& p
== D_fore
)
5375 if (display
&& p
== D_other
)
5377 s
= AddWindowFlags(s
, len
, p
);
5388 AddWindowFlags(buf
, len
, p
)
5394 if (p
== 0 || len
< 12)
5400 if (display
&& p
== D_fore
)
5402 if (display
&& p
== D_other
)
5405 if (p
->w_layer
.l_cvlist
&& p
->w_layer
.l_cvlist
->c_lnext
)
5407 if (p
->w_monitor
== MON_DONE
5409 && (ACLBYTE(p
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5413 if (p
->w_bell
== BELL_DONE
)
5416 if (p
->w_slot
!= (slot_t
) 0 && p
->w_slot
!= (slot_t
) -1)
5424 if (p
->w_ptyfd
< 0 && p
->w_type
!= W_TYPE_GROUP
)
5431 AddOtherUsers(buf
, len
, p
)
5436 struct display
*d
, *olddisplay
= display
;
5442 for (display
= displays
; display
; display
= display
->d_next
)
5444 if (olddisplay
&& D_user
== olddisplay
->d_user
)
5446 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5447 if (Layer2Window(cv
->c_layer
) == p
)
5451 for (d
= displays
; d
&& d
!= display
; d
= d
->d_next
)
5452 if (D_user
== d
->d_user
)
5454 if (d
&& d
!= display
)
5456 if (len
> 1 && s
!= buf
)
5461 l
= strlen(D_user
->u_name
);
5464 strcpy(s
, D_user
->u_name
);
5469 display
= olddisplay
;
5482 if (where
== -1 && D_fore
)
5483 where
= D_fore
->w_number
;
5484 ss
= AddWindows(buf
, sizeof(buf
), 0, where
);
5485 s
= buf
+ strlen(buf
);
5486 if (ss
- buf
> D_width
/ 2)
5489 if (s
- ss
< D_width
)
5505 register struct win
*wp
= fore
;
5510 Msg(0, "(%d,%d)/(%d,%d) no window", D_x
+ 1, D_y
+ 1, D_width
, D_height
);
5514 if (buf
< (p
+= GetAnsiStatus(wp
, p
)))
5516 sprintf(p
, "(%d,%d)/(%d,%d)",
5517 wp
->w_x
+ 1, wp
->w_y
+ 1, wp
->w_width
, wp
->w_height
);
5519 sprintf(p
+= strlen(p
), "+%d", wp
->w_histheight
);
5521 sprintf(p
+= strlen(p
), " %c%sflow",
5522 (wp
->w_flow
& FLOW_NOW
) ? '+' : '-',
5523 (wp
->w_flow
& FLOW_AUTOFLAG
) ? "" :
5524 ((wp
->w_flow
& FLOW_AUTO
) ? "(+)" : "(-)"));
5525 if (!wp
->w_wrap
) sprintf(p
+= strlen(p
), " -wrap");
5526 if (wp
->w_insert
) sprintf(p
+= strlen(p
), " ins");
5527 if (wp
->w_origin
) sprintf(p
+= strlen(p
), " org");
5528 if (wp
->w_keypad
) sprintf(p
+= strlen(p
), " app");
5529 if (wp
->w_log
) sprintf(p
+= strlen(p
), " log");
5530 if (wp
->w_monitor
!= MON_OFF
5532 && (ACLBYTE(wp
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5535 sprintf(p
+= strlen(p
), " mon");
5536 if (wp
->w_mouse
) sprintf(p
+= strlen(p
), " mouse");
5538 if (wp
->w_bce
) sprintf(p
+= strlen(p
), " bce");
5540 if (!wp
->w_c1
) sprintf(p
+= strlen(p
), " -c1");
5541 if (wp
->w_norefresh
) sprintf(p
+= strlen(p
), " nored");
5546 if (wp
->w_encoding
&& (display
== 0 || D_encoding
!= wp
->w_encoding
|| EncodingDefFont(wp
->w_encoding
) <= 0))
5549 strcpy(p
, EncodingName(wp
->w_encoding
));
5553 if (wp
->w_encoding
!= UTF8
)
5556 if (D_CC0
|| (D_CS0
&& *D_CS0
))
5560 sprintf(p
, " G%c", wp
->w_Charset
+ '0');
5561 if (wp
->w_FontE
>= ' ')
5566 p
[4] = wp
->w_FontE
^ 0x40;
5573 sprintf(p
++, " G%c%c[", wp
->w_Charset
+ '0', wp
->w_CharsetR
+ '0');
5575 sprintf(p
, " G%c[", wp
->w_Charset
+ '0');
5577 for (i
= 0; i
< 4; i
++)
5579 if (wp
->w_charsets
[i
] == ASCII
)
5581 else if (wp
->w_charsets
[i
] >= ' ')
5582 *p
++ = wp
->w_charsets
[i
];
5586 *p
++ = wp
->w_charsets
[i
] ^ 0x40;
5594 if (wp
->w_type
== W_TYPE_PLAIN
)
5596 /* add info about modem control lines */
5598 TtyGetModemStatus(wp
->w_ptyfd
, p
);
5600 #ifdef BUILTIN_TELNET
5601 else if (wp
->w_type
== W_TYPE_TELNET
)
5604 TelStatus(wp
, p
, sizeof(buf
) - 1 - (p
- buf
));
5607 Msg(0, "%s %d(%s)", buf
, wp
->w_number
, wp
->w_title
);
5617 sprintf(p
, "(%d,%d)", D_width
, D_height
),
5623 strcpy(p
, EncodingName(D_encoding
));
5629 strcpy(p
, " xterm");
5635 strcpy(p
, " color");
5642 strcpy(p
, " iso2022");
5645 else if (D_CS0
&& *D_CS0
)
5647 strcpy(p
, " altchar");
5655 AKAfin(buf
, len
, data
)
5658 char *data
; /* dummy */
5662 ChangeAKA(fore
, buf
, strlen(buf
));
5670 Input("Set window's title to: ", sizeof(fore
->w_akabuf
) - 1, INP_COOKED
, AKAfin
, NULL
, 0);
5676 if ((*(unsigned char *)s
& 0x7f) < 0x20 || *s
== 0x7f)
5680 LayProcess(&ss
, &n
);
5685 Colonfin(buf
, len
, data
)
5688 char *data
; /* dummy */
5693 if (buf
[len
] == '\t')
5696 int l
= 0, r
= RC_LAST
;
5697 int showmessage
= 0;
5700 while (*s
&& s
- buf
< len
)
5704 /* Showing a message when there's no hardstatus or caption cancels the input */
5706 (captionalways
|| D_has_hstatus
== HSTATUS_LASTLINE
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
)))
5712 x
= strncmp(buf
, comms
[m
].name
, len
);
5720 for (l
= m
- 1; l
>= 0 && strncmp(buf
, comms
[l
].name
, len
) == 0; l
--)
5722 for (m
= ++l
; m
<= r
&& strncmp(buf
, comms
[m
].name
, len
) == 0 && s
- mbuf
< sizeof(mbuf
); m
++)
5723 s
+= snprintf(s
, sizeof(mbuf
) - (s
- mbuf
), " %s", comms
[m
].name
);
5727 Msg(0, "Possible commands:%s", mbuf
);
5732 len
= snprintf(mbuf
, sizeof(mbuf
), "%s \t", comms
[l
].name
+ len
);
5733 if (len
> 0 && len
< sizeof(mbuf
))
5734 LayProcess(&s
, &len
);
5739 if (l
> r
&& showmessage
)
5740 Msg(0, "No commands matching '%*s'", len
, buf
);
5744 if (!len
|| buf
[len
])
5747 len
= strlen(buf
) + 1;
5748 if (len
> (int)sizeof(mbuf
))
5752 bcopy(buf
, mbuf
, len
);
5753 RcLine(mbuf
, sizeof mbuf
);
5758 SelectFin(buf
, len
, data
)
5761 char *data
; /* dummy */
5765 if (!len
|| !display
)
5767 if (len
== 1 && *buf
== '-')
5769 SetForeWindow((struct win
*)0);
5773 if ((n
= WindowByNoN(buf
)) < 0)
5779 SelectLayoutFin(buf
, len
, data
)
5782 char *data
; /* dummy */
5786 if (!len
|| !display
)
5788 if (len
== 1 && *buf
== '-')
5790 LoadLayout((struct layout
*)0, (struct canvas
*)0);
5794 lay
= FindLayout(buf
);
5796 Msg(0, "No such layout\n");
5797 else if (lay
== D_layout
)
5798 Msg(0, "This IS layout %d (%s).\n", lay
->lay_number
, lay
->lay_title
);
5801 LoadLayout(lay
, &D_canvas
);
5810 Input("Switch to window: ", 20, INP_COOKED
, SelectFin
, NULL
, 0);
5813 static char setenv_var
[31];
5817 SetenvFin1(buf
, len
, data
)
5820 char *data
; /* dummy */
5822 if (!len
|| !display
)
5828 SetenvFin2(buf
, len
, data
)
5831 char *data
; /* dummy */
5833 if (!len
|| !display
)
5835 debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var
, buf
);
5836 xsetenv(setenv_var
, buf
);
5844 static char setenv_buf
[50 + sizeof(setenv_var
)]; /* need to be static here, cannot be freed */
5848 strncpy(setenv_var
, arg
, sizeof(setenv_var
) - 1);
5849 sprintf(setenv_buf
, "Enter value for %s: ", setenv_var
);
5850 Input(setenv_buf
, 30, INP_COOKED
, SetenvFin2
, NULL
, 0);
5853 Input("Setenv: Enter variable name: ", 30, INP_COOKED
, SetenvFin1
, NULL
, 0);
5857 * the following options are understood by this parser:
5858 * -f, -f0, -f1, -fy, -fa
5859 * -t title, -T terminal-type, -h height-of-scrollback,
5860 * -ln, -l0, -ly, -l1, -l
5867 struct NewWindow nwin
;
5872 while (av
&& *av
&& av
[0][0] == '-')
5874 if (av
[0][1] == '-')
5886 nwin
.flowflag
= FLOW_NOW
* 0;
5891 nwin
.flowflag
= FLOW_NOW
* 1;
5894 nwin
.flowflag
= FLOW_AUTOFLAG
;
5900 case 't': /* no more -k */
5902 nwin
.aka
= &av
[0][2];
5910 nwin
.term
= &av
[0][2];
5918 nwin
.histheight
= atoi(av
[0] + 2);
5920 nwin
.histheight
= atoi(*av
);
5949 nwin
.monitor
= MON_ON
;
5955 Msg(0, "%s: screen: invalid option -%c.", fn
, av
[0][1]);
5961 if (av
&& *av
&& IsNumColon(*av
, 10, buf
, sizeof(buf
)))
5966 if (num
< 0 || num
> MAXWIN
- 1)
5968 Msg(0, "%s: illegal screen number %d.", fn
, num
);
5978 nwin
.aka
= Filename(*av
);
5985 * CompileKeys must be called before Markroutine is first used.
5986 * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
5988 * s is an ascii string in a termcap-like syntax. It looks like
5989 * "j=u:k=d:l=r:h=l: =.:" and so on...
5990 * this example rebinds the cursormovement to the keys u (up), d (down),
5991 * l (left), r (right). placing a mark will now be done with ".".
5994 CompileKeys(s
, sl
, array
)
5997 unsigned char *array
;
6000 unsigned char key
, value
;
6004 for (i
= 0; i
< 256; i
++)
6008 debug1("CompileKeys: '%s'\n", s
);
6011 key
= *(unsigned char *)s
++;
6012 if (*s
!= '=' || sl
< 3)
6019 value
= *(unsigned char *)s
++;
6022 while (*s
== '=' && sl
>= 2);
6031 #endif /* COPY_PASTE */
6034 * Asynchronous input functions
6037 #if defined(DETACH) && defined(POW_DETACH)
6039 pow_detach_fn(buf
, len
, data
)
6042 char *data
; /* dummy */
6044 debug("pow_detach_fn called\n");
6050 if (ktab
[(int)(unsigned char)*buf
].nr
!= RC_POW_DETACH
)
6053 write(D_userfd
, "\007", 1);
6054 Msg(0, "Detach aborted.");
6059 #endif /* POW_DETACH */
6063 copy_reg_fn(buf
, len
, data
)
6066 char *data
; /* dummy */
6068 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6079 if (D_user
->u_plop
.len
)
6081 if ((pp
->buf
= (char *)malloc(D_user
->u_plop
.len
)) == NULL
)
6086 bcopy(D_user
->u_plop
.buf
, pp
->buf
, D_user
->u_plop
.len
);
6088 pp
->len
= D_user
->u_plop
.len
;
6090 pp
->enc
= D_user
->u_plop
.enc
;
6092 Msg(0, "Copied %d characters into register %c", D_user
->u_plop
.len
, *buf
);
6096 ins_reg_fn(buf
, len
, data
)
6099 char *data
; /* dummy */
6101 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6109 return; /* Input() should not call us w/o fore, but you never know... */
6111 Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
6114 MakePaster(&fore
->w_paster
, pp
->buf
, pp
->len
, 0);
6117 Msg(0, "Empty register.");
6119 #endif /* COPY_PASTE */
6122 process_fn(buf
, len
, data
)
6125 char *data
; /* dummy */
6127 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6136 ProcessInput(pp
->buf
, pp
->len
);
6139 Msg(0, "Empty register.");
6143 confirm_fn(buf
, len
, data
)
6150 if (len
|| (*buf
!= 'y' && *buf
!= 'Y'))
6155 act
.nr
= *(int *)data
;
6164 struct acluser
**up
;
6166 char pw1
[130]; /* FreeBSD crypts to 128 bytes */
6171 su_fin(buf
, len
, data
)
6176 struct inputsu
*i
= (struct inputsu
*)data
;
6181 { p
= i
->name
; l
= sizeof(i
->name
) - 1; }
6183 { strcpy(p
= i
->pw1
, "\377"); l
= sizeof(i
->pw1
) - 1; }
6185 { strcpy(p
= i
->pw2
, "\377"); l
= sizeof(i
->pw2
) - 1; }
6187 strncpy(p
, buf
, 1 + (l
< len
) ? l
: len
);
6189 Input("Screen User: ", sizeof(i
->name
) - 1, INP_COOKED
, su_fin
, (char *)i
, 0);
6191 Input("User's UNIX Password: ", sizeof(i
->pw1
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6193 Input("User's Screen Password: ", sizeof(i
->pw2
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6196 if ((p
= DoSu(i
->up
, i
->name
, i
->pw2
, i
->pw1
)))
6203 InputSu(w
, up
, name
)
6205 struct acluser
**up
;
6210 if (!(i
= (struct inputsu
*)calloc(1, sizeof(struct inputsu
))))
6215 su_fin(name
, (int)strlen(name
), (char *)i
); /* can also initialise stuff */
6217 su_fin((char *)0, 0, (char *)i
);
6220 #endif /* MULTIUSER */
6225 pass1(buf
, len
, data
)
6230 struct acluser
*u
= (struct acluser
*)data
;
6235 if (u
->u_password
!= NullStr
)
6236 free((char *)u
->u_password
);
6237 u
->u_password
= SaveStr(buf
);
6238 bzero(buf
, strlen(buf
));
6239 Input("Retype new password:", 100, INP_NOECHO
, pass2
, data
, 0);
6243 pass2(buf
, len
, data
)
6250 struct acluser
*u
= (struct acluser
*)data
;
6253 if (!buf
|| strcmp(u
->u_password
, buf
))
6255 Msg(0, "[ Passwords don't match - checking turned off ]");
6256 if (u
->u_password
!= NullStr
)
6258 bzero(u
->u_password
, strlen(u
->u_password
));
6259 free((char *)u
->u_password
);
6261 u
->u_password
= NullStr
;
6263 else if (u
->u_password
[0] == '\0')
6265 Msg(0, "[ No password - no secure ]");
6267 bzero(buf
, strlen(buf
));
6270 if (u
->u_password
!= NullStr
)
6272 for (st
= 0; st
< 2; st
++)
6273 salt
[st
] = 'A' + (int)((time(0) >> 6 * st
) % 26);
6275 buf
= crypt(u
->u_password
, salt
);
6276 bzero(u
->u_password
, strlen(u
->u_password
));
6277 free((char *)u
->u_password
);
6278 u
->u_password
= SaveStr(buf
);
6279 bzero(buf
, strlen(buf
));
6282 UserFreeCopyBuffer(u
);
6283 u
->u_plop
.len
= strlen(u
->u_password
);
6287 if (!(u
->u_plop
.buf
= SaveStr(u
->u_password
)))
6290 D_user
->u_plop
.len
= 0;
6293 Msg(0, "[ Password moved into copybuffer ]");
6294 #else /* COPY_PASTE */
6295 Msg(0, "[ Crypted password is \"%s\" ]", u
->u_password
);
6296 #endif /* COPY_PASTE */
6299 #endif /* PASSWORD */
6302 digraph_fn(buf
, len
, data
)
6305 char *data
; /* dummy */
6312 buf
[len
+ 1] = ch
; /* so we can restore it later */
6313 if (ch
< ' ' || ch
== '\177')
6315 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6319 if ((ch
< '0' || ch
> '9') && (ch
< 'a' || ch
> 'f') && (ch
< 'A' || ch
> 'F'))
6321 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6324 if (len
== (*buf
== 'U' ? 5 : 3))
6328 if (len
&& *buf
== '0')
6330 if (ch
< '0' || ch
> '7')
6332 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6347 buf
[len
] = buf
[len
+ 1]; /* stored above */
6352 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6355 for (i
= 2; i
< len
; i
++)
6357 if (buf
[i
] >= '0' && buf
[i
] <= '9')
6358 x
= x
* 16 | (buf
[i
] - '0');
6359 else if (buf
[i
] >= 'a' && buf
[i
] <= 'f')
6360 x
= x
* 16 | (buf
[i
] - ('a' - 10));
6361 else if (buf
[i
] >= 'A' && buf
[i
] <= 'F')
6362 x
= x
* 16 | (buf
[i
] - ('A' - 10));
6367 else if (buf
[0] == '0')
6370 for (i
= 1; i
< len
; i
++)
6372 if (buf
[i
] < '0' || buf
[i
] > '7')
6374 x
= x
* 8 | (buf
[i
] - '0');
6379 for (i
= 0; i
< (int)(sizeof(digraphs
)/sizeof(*digraphs
)); i
++)
6380 if ((digraphs
[i
][0] == (unsigned char)buf
[0] && digraphs
[i
][1] == (unsigned char)buf
[1]) ||
6381 (digraphs
[i
][0] == (unsigned char)buf
[1] && digraphs
[i
][1] == (unsigned char)buf
[0]))
6383 if (i
== (int)(sizeof(digraphs
)/sizeof(*digraphs
)))
6385 Msg(0, "Unknown digraph");
6393 if (flayer
->l_encoding
== UTF8
)
6394 i
= ToUtf8(buf
, x
); /* buf is big enough for all UTF-8 codes */
6397 LayProcess(&buf
, &i
);
6408 debug1("StuffKey #%d", i
);
6411 debug1(" - %s", term
[i
+ T_CAPS
].tcname
);
6414 if (i
< KMAP_KEYS
&& D_ESCseen
)
6416 struct action
*act
= &D_ESCseen
[i
+ 256];
6417 if (act
->nr
!= RC_ILLEGAL
)
6420 DoAction(act
, i
+ 256);
6426 if (i
>= T_CURSOR
- T_CAPS
&& i
< T_KEYPAD
- T_CAPS
&& D_cursorkeys
)
6427 i
+= T_OCAPS
- T_CURSOR
;
6428 else if (i
>= T_KEYPAD
- T_CAPS
&& i
< T_OCAPS
- T_CAPS
&& D_keypad
)
6429 i
+= T_OCAPS
- T_CURSOR
;
6430 debug1(" - action %d\n", i
);
6431 flayer
= D_forecv
->c_layer
;
6435 if (InMark() || InInput() || InWList())
6436 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &mmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].mm
;
6438 if ((!act
|| act
->nr
== RC_ILLEGAL
) && !D_mapdefault
)
6439 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &umtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].um
;
6440 if (!act
|| act
->nr
== RC_ILLEGAL
)
6441 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &dmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].dm
;
6443 if (discard
&& (!act
|| act
->nr
!= RC_COMMAND
))
6450 if (act
== 0 || act
->nr
== RC_ILLEGAL
)
6464 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6465 if (Layer2Window(cv
->c_layer
) == wi
)
6471 FindNiceWindow(wi
, presel
)
6477 debug2("FindNiceWindow %d %s\n", wi
? wi
->w_number
: -1 , presel
? presel
: "NULL");
6480 i
= WindowByNoN(presel
);
6487 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6490 if (!wi
|| (IsOnDisplay(wi
) && !presel
))
6492 /* try to get another window */
6495 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6496 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6499 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6500 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6503 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6504 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6507 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6508 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6512 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6513 if (!wi
->w_layer
.l_cvlist
)
6516 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6517 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
))
6521 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6531 AddAlias(name
, value
, args
, argl
, count
)
6538 struct alias
*nalias
= NULL
;
6539 static next_command
= RC_LAST
;
6542 /* Make sure we don't already have this alias name defined. */
6543 if (FindAlias(name
) != NULL
)
6545 Msg(0, "alias already defined: %s", name
);
6549 /* Make sure the alias maps to something */
6550 if ((nr
= FindCommnr((char *)value
)) == RC_ILLEGAL
)
6552 struct alias
*alias
= FindAlias(value
);
6555 Msg(0, "%s: could not find command or alias '%s'", rc_name
, value
);
6561 nalias
= (struct alias
*)calloc(1, sizeof(struct alias
));
6564 nalias
->next
= NULL
;
6565 nalias
->name
= SaveStr(name
);
6569 nalias
->args
= SaveArgs(args
);
6570 nalias
->argl
= calloc(count
+ 1, sizeof(int));
6572 nalias
->argl
[count
] = argl
[count
];
6574 nalias
->nr
= ++next_command
;
6577 nalias
->next
= g_aliases_list
;
6578 g_aliases_list
= nalias
;
6583 * Find an alias by name.
6585 static struct alias
*
6589 struct alias
*t
= g_aliases_list
;
6593 if ((t
->name
!= NULL
) &&
6594 (strcmp(t
->name
, name
) == 0))
6604 * Find an alias by number.
6606 static struct alias
*
6611 for (t
= g_aliases_list
; t
; t
= t
->next
)
6627 /* Find the previous alias */
6628 struct alias
*cur
= g_aliases_list
;
6629 struct alias
**pcur
= &g_aliases_list
;
6633 if ((cur
->name
!= NULL
) &&
6634 (strcmp(cur
->name
, name
) == 0))
6636 struct alias
*found
= cur
;
6639 /* remove this one from the chain. */
6640 *pcur
= found
->next
;
6645 for (c
= 0; found
->args
[c
]; c
++)
6646 free(found
->args
[c
]);
6652 Msg(0, "alias %s removed", name
);
6659 Msg(0, "alias %s not found", name
);
6664 /* sorted list of all commands */
6665 static struct comm
**commtab
;
6666 static int ncommtab
;
6671 void (*hand
) __P((struct comm
*, char **, int));
6674 for (n
= 0; cos
[n
].name
; n
++)
6679 commtab
= (struct commt
*)realloc(commtab
, sizeof(*commtab
) * (ncommtab
+ n
));
6681 commtab
= (struct commt
*)malloc(sizeof(*commtab
) * (ncommtab
+ n
));
6684 for (i
= 0; i
< n
; i
++)
6686 for (j
= 0; j
< ncommtab
; j
++)
6688 r
= strcmp(cos
[i
].name
, commtab
[j
]->name
);
6690 Panic(0, "Duplicate command: %s\n", cos
[i
].name
);
6694 for (r
= ncommtab
; r
> j
; r
--)
6695 commtab
[r
] = commtab
[r
- 1];
6696 commtab
[j
] = cos
+ i
;
6697 cos
[i
].handler
= hand
;
6698 bzero(cos
[i
].userbits
, sizeof(cos
[i
].userbits
));
6707 int x
, m
, l
= 0, r
= ncommtab
- 1;
6711 x
= strcmp(str
, commtab
[m
]->name
);
6725 CalcSlicePercent(cv
, percent
)
6730 if (!cv
|| !cv
->c_slback
)
6732 up
= CalcSlicePercent(cv
->c_slback
->c_slback
, percent
);
6734 for (cv
= cv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6735 wsum
+= cv
->c_slweight
;
6738 return (up
* w
) / wsum
;
6742 ChangeCanvasSize(fcv
, abs
, diff
, gflag
, percent
)
6743 struct canvas
*fcv
; /* make this canvas bigger */
6744 int abs
; /* mode: 0:rel 1:abs 2:max */
6745 int diff
; /* change this much */
6746 int gflag
; /* go up if neccessary */
6750 int done
, have
, m
, dir
;
6752 debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs
, diff
, percent
);
6753 if (abs
== 0 && diff
== 0)
6758 fcv
->c_slweight
= 0;
6761 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6763 fcv
->c_slweight
= 1;
6764 cv
= fcv
->c_slback
->c_slback
;
6765 if (gflag
&& cv
&& cv
->c_slback
)
6766 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6774 if (percent
&& diff
> percent
)
6780 for (cv
= fcv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6781 wsum
+= cv
->c_slweight
;
6784 up
= gflag
? CalcSlicePercent(fcv
->c_slback
->c_slback
, percent
) : percent
;
6785 debug3("up=%d, wsum=%d percent=%d\n", up
, wsum
, percent
);
6788 int scale
= wsum
< 10 ? 1000 : 100;
6789 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6790 cv
->c_slweight
*= scale
;
6792 debug1("scaled wsum to %d\n", wsum
);
6794 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6798 cv
->c_slweight
= (cv
->c_slweight
* up
) / percent
;
6799 if (cv
->c_slweight
== 0)
6802 debug1(" - weight %d\n", cv
->c_slweight
);
6804 diff
= (diff
* wsum
) / percent
;
6810 if (abs
&& diff
== (fcv
->c_slorient
== SLICE_VERT
? fcv
->c_ye
- fcv
->c_ys
+ 2 : fcv
->c_xe
- fcv
->c_xs
+ 2))
6812 /* fix weights to real size (can't be helped, sorry) */
6813 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6815 cv
->c_slweight
= cv
->c_slorient
== SLICE_VERT
? cv
->c_ye
- cv
->c_ys
+ 2 : cv
->c_xe
- cv
->c_xs
+ 2;
6816 debug1(" - weight %d\n", cv
->c_slweight
);
6820 diff
= diff
- fcv
->c_slweight
;
6821 debug1("diff = %d\n", diff
);
6826 cv
= fcv
->c_slnext
? fcv
->c_slnext
: fcv
->c_slprev
;
6827 fcv
->c_slweight
+= diff
;
6828 cv
->c_slweight
-= diff
;
6833 for (cv
= fcv
->c_slnext
; diff
> 0; cv
= dir
> 0 ? cv
->c_slnext
: cv
->c_slprev
)
6837 debug1("reached end, dir is %d\n", dir
);
6847 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 : 2;
6848 debug2("min is %d, have %d\n", m
, cv
->c_slweight
);
6849 if (cv
->c_slweight
> m
)
6851 have
= cv
->c_slweight
- m
;
6854 debug1("subtract %d\n", have
);
6855 cv
->c_slweight
-= have
;
6862 /* need more room! */
6863 cv
= fcv
->c_slback
->c_slback
;
6864 if (cv
&& cv
->c_slback
)
6865 done
+= ChangeCanvasSize(fcv
->c_slback
->c_slback
, 0, diff
, gflag
, percent
);
6867 fcv
->c_slweight
+= done
;
6868 debug1("ChangeCanvasSize returns %d\n", done
);
6873 ResizeRegions(arg
, flags
)
6879 int gflag
= 0, abs
= 0, percent
= 0;
6885 if (D_forecv
->c_slorient
== SLICE_UNKN
)
6887 Msg(0, "resize: need more than one region");
6890 gflag
= flags
& RESIZE_FLAG_L
? 0 : 1;
6891 orient
|= flags
& RESIZE_FLAG_H
? SLICE_HORI
: 0;
6892 orient
|= flags
& RESIZE_FLAG_V
? SLICE_VERT
: 0;
6894 orient
= D_forecv
->c_slorient
;
6898 /* make all regions the same height */
6899 struct canvas
*cv
= gflag
? &D_canvas
: D_forecv
->c_slback
;
6900 if (cv
->c_slperp
->c_slorient
& orient
)
6901 EqualizeCanvas(cv
->c_slperp
, gflag
);
6902 /* can't use cv->c_slorient directly as it can be D_canvas */
6903 if ((cv
->c_slperp
->c_slorient
^ (SLICE_HORI
^ SLICE_VERT
)) & orient
)
6908 EqualizeCanvas(cv
->c_slperp
, gflag
);
6911 EqualizeCanvas(cv
, gflag
);
6914 RecreateCanvasChain();
6915 RethinkDisplayViewports();
6916 ResizeLayersToCanvases();
6919 if (!strcmp(arg
, "min") || !strcmp(arg
, "0"))
6924 else if (!strcmp(arg
, "max") || !strcmp(arg
, "_"))
6931 if (l
> 0 && arg
[l
- 1] == '%')
6934 diff
= atoi(arg
+ 1);
6935 else if (*arg
== '-')
6936 diff
= -atoi(arg
+ 1);
6939 diff
= atoi(arg
); /* +1 because of caption line */
6942 abs
= diff
== 0 ? 2 : 1;
6948 diff
= diff
* percent
/ 100;
6950 if (cv
->c_slorient
& orient
)
6951 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6952 if (cv
->c_slback
->c_slorient
& orient
)
6953 ChangeCanvasSize(cv
->c_slback
, abs
, diff
, gflag
, percent
);
6955 ResizeCanvas(&D_canvas
);
6956 RecreateCanvasChain();
6957 RethinkDisplayViewports();
6958 ResizeLayersToCanvases();
6965 if (siz
+ diff
> dsize
- (nreg
- 1) * 2 - 1)
6966 diff
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6967 if (diff
== 0 || siz
+ diff
< 1)
6972 if (D_forecv
->c_next
)
6974 D_forecv
->c_ye
+= diff
;
6975 D_forecv
->c_next
->c_ys
+= diff
;
6976 D_forecv
->c_next
->c_yoff
+= diff
;
6980 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6981 if (cv
->c_next
== D_forecv
)
6985 D_forecv
->c_ys
-= diff
;
6986 D_forecv
->c_yoff
-= diff
;
6991 int s
, i
= 0, found
= 0, di
= diff
, d2
;
6992 s
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6993 for (cv
= D_cvlist
; cv
; i
= cv
->c_ye
+ 2, cv
= cv
->c_next
)
6997 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) + diff
;
6998 cv
->c_yoff
-= cv
->c_ys
- i
;
7003 s
-= cv
->c_ye
- cv
->c_ys
;
7011 d2
= di
> cv
->c_ye
- cv
->c_ys
? cv
->c_ye
- cv
->c_ys
: di
;
7013 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) - d2
;
7014 cv
->c_yoff
-= cv
->c_ys
- i
;
7018 RethinkDisplayViewports();
7019 ResizeLayersToCanvases();
7024 ResizeFin(buf
, len
, data
)
7030 int flags
= *(int *)data
;
7031 ch
= ((unsigned char *)buf
)[len
];
7034 ResizeRegions(buf
, flags
);
7038 flags
^= RESIZE_FLAG_H
;
7040 flags
^= RESIZE_FLAG_V
;
7042 flags
|= RESIZE_FLAG_H
|RESIZE_FLAG_V
;
7044 flags
^= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
7046 flags
^= RESIZE_FLAG_L
;
7049 inp_setprompt(resizeprompts
[flags
], NULL
);
7050 *(int *)data
= flags
;
7061 p
= Layer2Window(D_forecv
->c_layer
);
7062 for (i
= 3; i
>=0; i
--)
7063 SetXtermOSC(i
, p
? p
->w_xtermosc
[i
] : 0);
7068 ParseAttrColor(s1
, s2
, msgok
)
7080 while (*ss
&& *ss
!= ' ')
7084 if (*s
&& (s2
|| *ss
|| !((*s
>= 'a' && *s
<= 'z') || (*s
>= 'A' && *s
<= 'Z') || *s
== '.')))
7086 int mode
= 0, n
= 0;
7104 if (*s
>= '0' && *s
<= '9')
7107 if (*s
>= '0' && *s
<= '9')
7108 n
= n
* 16 + (*s
++ - '0');
7109 else if (*s
>= 'a' && *s
<= 'f')
7110 n
= n
* 16 + (*s
++ - ('a' - 10));
7111 else if (*s
>= 'A' && *s
<= 'F')
7112 n
= n
* 16 + (*s
++ - ('A' - 10));
7113 else if (*s
&& *s
!= ' ')
7116 Msg(0, "Illegal attribute hexchar '%c'", *s
);
7122 while (*s
&& *s
!= ' ')
7139 Msg(0, "Illegal attribute specifier '%c'", *s
);
7145 if (*s
&& *s
!= ' ')
7148 Msg(0, "junk after attribute description: '%c'", *s
);
7160 while (*s
&& *s
== ' ')
7168 Msg(0, "junk after description: '%c'", *s
);
7172 while (*s
&& *s
== ' ')
7179 static char costr
[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
7189 for (j
= 0; j
< 2 && *s
&& *s
!= ' '; j
++)
7191 for (i
= 0; costr
[i
]; i
++)
7197 Msg(0, "illegal color descriptor: '%c'", *s
);
7201 n
= n
<< 4 | (i
& 15);
7204 n
= (n
& 0x20ff) | 0x200;
7208 if ((n
& 0xf00) == 0xf00)
7209 n
^= 0xf00; /* clear superflous bits */
7212 n
^= 0x2400; /* shift bit into right position */
7215 n
|= 0xf0; /* don't change bg color */
7216 if (numco
!= 2 && n
!= 0xff)
7217 n
|= 0x100; /* special invert mode */
7218 if (*s
&& *s
!= ' ')
7221 Msg(0, "junk after color description: '%c'", *s
);
7229 while (*s
&& *s
== ' ')
7234 Msg(0, "junk after description: '%c'", *s
);
7237 debug1("ParseAttrColor %06x\n", r
);
7245 * e just set intensity
7246 * f don't change anything
7247 * Intensity is encoded into bits 17(fg) and 18(bg).
7250 ApplyAttrColor(i
, mc
)
7254 debug1("ApplyAttrColor %06x\n", i
);
7255 mc
->attr
|= i
>> 8 & 255;
7256 mc
->attr
^= i
& 255;
7258 i
= (i
>> 16) ^ 0xff;
7259 if ((i
& 0x100) != 0)
7262 if (mc
->attr
& (A_SO
|A_RV
))
7264 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4) | ((i
& 0x200) << 1) | ((i
& 0x400) >> 1);
7266 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4);
7270 if ((i
& 0x0f) != 0x0f)
7271 mc
->attr
= (mc
->attr
& 0xbf) | ((i
>> 3) & 0x40);
7272 if ((i
& 0xf0) != 0xf0)
7273 mc
->attr
= (mc
->attr
& 0x7f) | ((i
>> 3) & 0x80);
7275 mc
->color
= 0x99 ^ mc
->color
;
7276 if ((i
& 0x0e) == 0x0e)
7277 i
= (i
& 0xf0) | (mc
->color
& 0x0f);
7278 if ((i
& 0xe0) == 0xe0)
7279 i
= (i
& 0x0f) | (mc
->color
& 0xf0);
7280 mc
->color
= 0x99 ^ i
;
7281 debug2("ApplyAttrColor - %02x %02x\n", mc
->attr
, i
);