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 ScriptSource(*args
);
3833 Msg(0, "%s:%s screen login", HostName
, SockPath
);
3834 InputSu(D_fore
, &D_user
, NULL
);
3837 InputSu(D_fore
, &D_user
, args
[0]);
3839 s
= DoSu(&D_user
, args
[0], args
[1], "\377");
3841 s
= DoSu(&D_user
, args
[0], args
[1], args
[2]);
3845 #endif /* MULTIUSER */
3848 if (s
&& !strcmp(s
, "-v"))
3849 AddCanvas(SLICE_HORI
);
3851 AddCanvas(SLICE_VERT
);
3863 D_forecv
->c_xoff
= D_forecv
->c_xs
;
3864 D_forecv
->c_yoff
= D_forecv
->c_ys
;
3865 RethinkViewportOffsets(D_forecv
);
3866 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
3867 flayer
= D_forecv
->c_layer
;
3871 if (!*args
|| !strcmp(*args
, "down"))
3872 D_forecv
= D_forecv
->c_next
? D_forecv
->c_next
: D_cvlist
;
3873 else if (!strcmp(*args
, "up"))
3876 for (cv
= D_cvlist
; cv
->c_next
&& cv
->c_next
!= D_forecv
; cv
= cv
->c_next
)
3880 else if (!strcmp(*args
, "top"))
3881 D_forecv
= D_cvlist
;
3882 else if (!strcmp(*args
, "bottom"))
3885 for (cv
= D_cvlist
; cv
->c_next
; cv
= cv
->c_next
)
3891 Msg(0, "%s: usage: focus [up|down|top|bottom]", rc_name
);
3894 if ((focusminwidth
&& (focusminwidth
< 0 || D_forecv
->c_xe
- D_forecv
->c_xs
+ 1 < focusminwidth
)) ||
3895 (focusminheight
&& (focusminheight
< 0 || D_forecv
->c_ye
- D_forecv
->c_ys
+ 1 < focusminheight
)))
3897 ResizeCanvas(&D_canvas
);
3898 RecreateCanvasChain();
3899 RethinkDisplayViewports();
3900 ResizeLayersToCanvases(); /* redisplays */
3902 fore
= D_fore
= Layer2Window(D_forecv
->c_layer
);
3903 if (D_other
== fore
)
3905 flayer
= D_forecv
->c_layer
;
3907 if (D_xtermosc
[2] || D_xtermosc
[3])
3917 flayer
= D_forecv
->c_layer
;
3918 CV_CALL(D_forecv
, LayRestore();LaySetCursor());
3919 WindowChanged(0, 'F');
3923 if (D_forecv
->c_slorient
== SLICE_UNKN
)
3925 Msg(0, "resize: need more than one region");
3928 for (; *args
; args
++)
3930 if (!strcmp(*args
, "-h"))
3932 else if (!strcmp(*args
, "-v"))
3934 else if (!strcmp(*args
, "-b"))
3935 i
|= RESIZE_FLAG_H
| RESIZE_FLAG_V
;
3936 else if (!strcmp(*args
, "-p"))
3937 i
|= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
3938 else if (!strcmp(*args
, "-l"))
3943 if (*args
&& args
[1])
3945 Msg(0, "%s: usage: resize [-h] [-v] [-l] [num]\n", rc_name
);
3949 ResizeRegions(*args
, i
);
3951 Input(resizeprompts
[i
], 20, INP_EVERY
, ResizeFin
, (char*)0, i
);
3954 (void)ParseSwitch(act
, &separate_sids
);
3957 args
= SaveArgs(args
);
3958 for (i
= 0; args
[i
]; i
++)
3961 Colonfin(args
[i
], strlen(args
[i
]), (char *)0);
3967 (void)ParseSwitch(act
, &use_altscreen
);
3969 Msg(0, "Will %sdo alternate screen switching", use_altscreen
? "" : "not ");
3972 if (ParseNum(act
, &n
))
3975 Msg(0, "illegal maxwin number specified");
3976 else if (n
> maxwin
)
3977 Msg(0, "may only decrease maxwin number");
3982 if (ParseBase(act
, *args
, &n
, 10, "decimal"))
3985 setbacktick(n
, 0, 0, (char **)0);
3991 Msg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name
);
3994 if (ParseBase(act
, args
[1], &lifespan
, 10, "decimal"))
3996 if (ParseBase(act
, args
[2], &tick
, 10, "decimal"))
3998 setbacktick(n
, lifespan
, tick
, SaveArgs(args
+ 3));
4000 WindowChanged(0, '`');
4006 RunBlanker(blankerprg
);
4011 CursorVisibility(-1);
4019 for (pp
= blankerprg
; *pp
; pp
++)
4025 blankerprg
= SaveArgs(args
);
4031 struct display
*olddisplay
= display
;
4032 if (!strcmp(*args
, "off"))
4034 else if (args
[0][0])
4035 idletimo
= atoi(*args
) * 1000;
4038 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
4040 struct alias
*alias
= FindAlias(args
[1]);
4043 Msg(0, "%s: idle: unknown command or alias '%s'", rc_name
, args
[1]);
4048 if (i
<= RC_LAST
&& CheckArgNum(i
, args
+ 2) < 0)
4050 ClearAction(&idleaction
);
4051 SaveAction(&idleaction
, i
, args
+ 2, argl
+ 2);
4053 for (display
= displays
; display
; display
= display
->d_next
)
4055 display
= olddisplay
;
4060 Msg(0, "idle timeout %ds, %s", idletimo
/ 1000, comms
[idleaction
.nr
].name
);
4065 case RC_FOCUSMINSIZE
:
4066 for (i
= 0; i
< 2 && args
[i
]; i
++)
4068 if (!strcmp(args
[i
], "max") || !strcmp(args
[i
], "_"))
4080 for (i
= 0; i
< 2; i
++)
4082 n
= i
== 0 ? focusminwidth
: focusminheight
;
4084 strcpy(b
[i
], "max");
4086 sprintf(b
[i
], "%d", n
);
4088 Msg(0, "focus min size is %s %s\n", b
[0], b
[1]);
4097 fore
->w_group
= WindowByName(*args
);
4098 if (fore
->w_group
&& fore
->w_group
->w_type
!= W_TYPE_GROUP
)
4101 WindowChanged((struct win
*)0, 'w');
4102 WindowChanged((struct win
*)0, 'W');
4103 WindowChanged((struct win
*)0, 0);
4108 Msg(0, "window group is %d (%s)\n", fore
->w_group
->w_number
, fore
->w_group
->w_title
);
4110 Msg(0, "window belongs to no group");
4114 if (!strcmp(args
[0], "title"))
4118 Msg(0, "not on a layout");
4123 Msg(0, "current layout is %d (%s)", D_layout
->lay_number
, D_layout
->lay_title
);
4126 free(D_layout
->lay_title
);
4127 D_layout
->lay_title
= SaveStr(args
[1]);
4129 else if (!strcmp(args
[0], "number"))
4135 Msg(0, "This is layout %d (%s).\n", D_layout
->lay_number
, D_layout
->lay_title
);
4138 old
= D_layout
->lay_number
;
4140 if (n
< 0 || n
>= MAXLAY
)
4143 laytab
[n
] = D_layout
;
4144 D_layout
->lay_number
= n
;
4147 lay
->lay_number
= old
;
4150 else if (!strcmp(args
[0], "autosave"))
4154 Msg(0, "not on a layout");
4159 if (!strcmp(args
[1], "on"))
4160 D_layout
->lay_autosave
= 1;
4161 else if (!strcmp(args
[1], "off"))
4162 D_layout
->lay_autosave
= 0;
4165 Msg(0, "invalid argument. Give 'on' or 'off");
4170 Msg(0, "autosave is %s", D_layout
->lay_autosave
? "on" : "off");
4172 else if (!strcmp(args
[0], "new"))
4178 while (*t
>= '0' && *t
<= '9')
4180 if (t
!= args
[1] && (!*t
|| *t
== ':'))
4194 else if (!strcmp(args
[0], "save"))
4198 Msg(0, "usage: layout save <name>");
4201 SaveLayout(args
[1], &D_canvas
);
4203 else if (!strcmp(args
[0], "select"))
4207 Input("Switch to layout: ", 20, INP_COOKED
, SelectLayoutFin
, NULL
, 0);
4210 SelectLayoutFin(args
[1], strlen(args
[1]), (char *)0);
4212 else if (!strcmp(args
[0], "next"))
4214 struct layout
*lay
= D_layout
;
4216 lay
= lay
->lay_next
? lay
->lay_next
: layouts
;
4221 Msg(0, "no layout defined");
4224 if (lay
== D_layout
)
4226 LoadLayout(lay
, &D_canvas
);
4229 else if (!strcmp(args
[0], "prev"))
4231 struct layout
*lay
= D_layout
;
4234 for (lay
= layouts
; lay
->lay_next
&& lay
->lay_next
!= D_layout
; lay
= lay
->lay_next
)
4241 Msg(0, "no layout defined");
4244 if (lay
== D_layout
)
4246 LoadLayout(lay
, &D_canvas
);
4249 else if (!strcmp(args
[0], "attach"))
4254 Msg(0, "no attach layout set");
4255 else if (layout_attach
== &layout_last_marker
)
4256 Msg(0, "will attach to last layout");
4258 Msg(0, "will attach to layout %d (%s)", layout_attach
->lay_number
, layout_attach
->lay_title
);
4261 if (!strcmp(args
[1], ":last"))
4262 layout_attach
= &layout_last_marker
;
4263 else if (!args
[1][0])
4268 lay
= FindLayout(args
[1]);
4271 Msg(0, "unknown layout '%s'", args
[1]);
4274 layout_attach
= lay
;
4277 else if (!strcmp(args
[0], "show"))
4281 else if (!strcmp(args
[0], "remove"))
4283 struct layout
*lay
= display
? D_layout
: layouts
;
4286 lay
= layouts
? FindLayout(args
[1]) : (struct layout
*)0;
4289 Msg(0, "unknown layout '%s'", args
[1]);
4297 Msg(0, "unknown layout subcommand");
4301 if(ParseSwitch(act
, &cjkwidth
) == 0)
4304 Msg(0, "Treat ambiguous width characters as %s width", cjkwidth
? "full" : "half");
4310 /* key == -2: input from braille keybord, msgok always 0 */
4311 DoBrailleAction(act
, key
== -2 ? 0 : msgok
);
4315 if (display
!= odisplay
)
4317 for (display
= displays
; display
; display
= display
->d_next
)
4318 if (display
== odisplay
)
4324 DoAlias(name
, args
, argl
)
4332 struct alias
*alias
= FindAlias(name
);
4338 for (; args
&& args
[count
]; count
++)
4340 for (i
= 0; alias
->args
&& alias
->args
[i
]; i
++, count
++)
4344 if ((mergeds
= malloc(count
* sizeof(char *))) == 0)
4346 if ((mergedl
= malloc(count
* sizeof(int))) == 0)
4351 for (count
= 0; alias
->args
&& alias
->args
[count
]; count
++)
4353 mergeds
[count
] = alias
->args
[count
];
4354 mergedl
[count
] = alias
->argl
[count
];
4356 for (i
= 0; args
&& args
[i
]; i
++, count
++)
4358 mergeds
[count
] = args
[i
];
4359 mergedl
[count
] = argl
[i
];
4362 mergedl
[count
] = 0 ;
4364 DoCommand(mergeds
, mergedl
);
4372 DoCommand(argv
, argl
)
4379 if (DoAlias(*argv
, argv
+ 1, argl
+ 1))
4382 if ((act
.nr
= FindCommnr(*argv
)) == RC_ILLEGAL
)
4384 Msg(0, "%s: unknown command '%s'", rc_name
, *argv
);
4387 act
.args
= argv
+ 1;
4388 act
.argl
= argl
+ 1;
4393 SaveAction(act
, nr
, args
, argl
)
4399 register int argc
= 0;
4413 if ((pp
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4415 if ((lp
= (int *)malloc((unsigned)(argc
) * sizeof(int *))) == 0)
4422 *lp
= argl
? *argl
++ : (int)strlen(*args
);
4423 *pp
++ = SaveStrn(*args
++, *lp
++);
4432 register char **ap
, **pp
;
4433 register int argc
= 0;
4437 if ((pp
= ap
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4440 *pp
++ = SaveStr(*args
++);
4447 * buf is split into argument vector args.
4448 * leading whitespace is removed.
4449 * @!| abbreviations are expanded.
4450 * the end of buffer is recognized by '\0' or an un-escaped '#'.
4451 * " and ' are interpreted.
4456 Parse(buf
, bufl
, args
, argl
)
4460 register char *p
= buf
, **ap
= args
, *pp
;
4461 register int delim
, argc
;
4464 debug2("Parse %d %s\n", bufl
, buf
);
4470 while (*p
&& (*p
== ' ' || *p
== '\t'))
4473 if (argc
== 0 && *p
== '!')
4482 if (*p
== '\0' || *p
== '#' || *p
== '\n')
4485 for (delim
= 0; delim
< argc
; delim
++)
4486 debug1("-- %s\n", args
[delim
]);
4490 if (++argc
>= MAXARGS
)
4492 Msg(0, "%s: too many tokens.", rc_name
);
4497 debug1("- new arg %s\n", p
);
4502 else if (delim
!= '\'' && *p
== '\\' && (p
[1] == '\'' || p
[1] == '"' || p
[1] == '\\' || p
[1] == '$' || p
[1] == '#' || p
[1] == '^' || (p
[1] >= '0' && p
[1] <= '7')))
4505 if (*p
>= '0' && *p
<= '7')
4508 if (p
[1] >= '0' && p
[1] <= '7')
4511 *pp
= (*pp
<< 3) | (*p
- '0');
4512 if (p
[1] >= '0' && p
[1] <= '7')
4515 *pp
= (*pp
<< 3) | (*p
- '0');
4523 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] == '_'))
4526 char *ps
, *pe
, op
, *v
, xbuf
[11];
4530 debug1("- var %s\n", ps
);
4534 if (*ps
== '{' && *p
== '}')
4536 if (*ps
== ':' && *p
== ':')
4538 if (*ps
!= '{' && *ps
!= ':' && (*p
< 'a' || *p
> 'z') && (*p
< 'A' || *p
> 'Z') && (*p
< '0' || *p
> '9') && *p
!= '_')
4543 if (*ps
== '{' || *ps
== ':')
4547 Msg(0, "%s: bad variable name.", rc_name
);
4554 debug1("- var is '%s'\n", ps
);
4556 v
= gettermcapstring(ps
+ 1);
4562 if (!strcmp(ps
, "TERM"))
4563 v
= display
? D_termname
: "unknown";
4564 else if (!strcmp(ps
, "COLUMNS"))
4565 sprintf(xbuf
, "%d", display
? D_width
: -1);
4566 else if (!strcmp(ps
, "LINES"))
4567 sprintf(xbuf
, "%d", display
? D_height
: -1);
4572 vl
= v
? strlen(v
) : 0;
4575 debug1("- sub is '%s'\n", v
);
4578 int right
= buf
+ bufl
- (p
+ strlen(p
) + 1);
4581 bcopy(p
, p
+ right
, strlen(p
) + 1);
4587 Msg(0, "%s: no space left for variable expansion.", rc_name
);
4595 else if (delim
!= '\'' && *p
== '^' && p
[1])
4598 *pp
++ = *p
== '?' ? '\177' : *p
& 0x1f;
4600 else if (delim
== 0 && (*p
== '\'' || *p
== '"'))
4602 else if (delim
== 0 && (*p
== ' ' || *p
== '\t' || *p
== '\n'))
4610 Msg(0, "%s: Missing %c quote.", rc_name
, delim
);
4616 debug2("- arg done, '%s' rest %s\n", ap
[-1], p
);
4617 *lp
++ = pp
- ap
[-1];
4636 if (DefaultEsc
>= 0)
4637 ClearAction(&ktab
[DefaultEsc
]);
4638 if (DefaultMetaEsc
>= 0)
4639 ClearAction(&ktab
[DefaultMetaEsc
]);
4642 DefaultMetaEsc
= me
;
4645 if (DefaultEsc
>= 0)
4647 ClearAction(&ktab
[DefaultEsc
]);
4648 ktab
[DefaultEsc
].nr
= RC_OTHER
;
4650 if (DefaultMetaEsc
>= 0)
4652 ClearAction(&ktab
[DefaultMetaEsc
]);
4653 ktab
[DefaultMetaEsc
].nr
= RC_META
;
4660 ParseSwitch(act
, var
)
4664 if (*act
->args
== 0)
4669 return ParseOnOff(act
, var
);
4673 ParseOnOff(act
, var
)
4677 register int num
= -1;
4678 char **args
= act
->args
;
4682 if (strcmp(args
[0], "on") == 0)
4684 else if (strcmp(args
[0], "off") == 0)
4689 Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name
, comms
[act
->nr
].name
);
4697 ParseSaveStr(act
, var
)
4701 char **args
= act
->args
;
4702 if (*args
== 0 || args
[1])
4704 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4709 *var
= SaveStr(*args
);
4719 char *p
, **args
= act
->args
;
4722 if (p
== 0 || *p
== 0 || args
[1])
4724 Msg(0, "%s: %s: invalid argument. Give one argument.",
4725 rc_name
, comms
[act
->nr
].name
);
4731 if (*p
>= '0' && *p
<= '9')
4732 i
= 10 * i
+ (*p
- '0');
4735 Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4736 rc_name
, comms
[act
->nr
].name
);
4741 debug1("ParseNum got %d\n", i
);
4747 ParseNum1000(act
, var
)
4752 char *p
, **args
= act
->args
;
4756 if (p
== 0 || *p
== 0 || args
[1])
4758 Msg(0, "%s: %s: invalid argument. Give one argument.",
4759 rc_name
, comms
[act
->nr
].name
);
4765 if (*p
>= '0' && *p
<= '9')
4768 i
= 10 * i
+ (*p
- '0');
4769 else if (dig
== 4 && *p
>= '5')
4774 else if (*p
== '.' && !dig
)
4778 Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4779 rc_name
, comms
[act
->nr
].name
);
4790 i
= (int)((unsigned int)~0 >> 1);
4791 debug1("ParseNum1000 got %d\n", i
);
4802 for (p
= windows
; p
; p
= p
->w_next
)
4803 if (!strcmp(p
->w_title
, s
))
4805 for (p
= windows
; p
; p
= p
->w_next
)
4806 if (!strncmp(p
->w_title
, s
, strlen(s
)))
4818 for (i
= 0, s
= str
; *s
; s
++)
4820 if (*s
< '0' || *s
> '9')
4822 i
= i
* 10 + (*s
- '0');
4828 * Get window number from Name or Number string.
4829 * Numbers are tried first, then names, a prefix match suffices.
4830 * Be careful when assigning numeric strings as WindowTitles.
4839 if ((i
= WindowByNumber(str
)) < 0 || i
>= MAXWIN
)
4841 if ((p
= WindowByName(str
)))
4849 ParseWinNum(act
, var
)
4853 char **args
= act
->args
;
4856 if (*args
== 0 || args
[1])
4858 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4862 i
= WindowByNoN(*args
);
4865 Msg(0, "%s: %s: invalid argument. Give window number or name.",
4866 rc_name
, comms
[act
->nr
].name
);
4869 debug1("ParseWinNum got %d\n", i
);
4875 ParseBase(act
, p
, var
, base
, bname
)
4887 Msg(0, "%s: %s: empty argument.", rc_name
, comms
[act
->nr
].name
);
4892 if (c
>= 'a' && c
<= 'z')
4894 if (c
>= 'A' && c
<= 'Z')
4895 c
-= 'A' - ('0' + 10);
4897 if (c
< 0 || c
>= base
)
4899 Msg(0, "%s: %s: argument is not %s.", rc_name
, comms
[act
->nr
].name
, bname
);
4904 debug1("ParseBase got %d\n", i
);
4914 for (base
+= '0'; *s
; ++s
)
4915 if (*s
< '0' || *s
> base
)
4921 IsNumColon(s
, base
, p
, psize
)
4926 if ((q
= rindex(s
, ':')) != 0)
4928 strncpy(p
, q
+ 1, psize
- 1);
4929 p
[psize
- 1] = '\0';
4934 return IsNum(s
, base
);
4943 debug1("SwitchWindow %d\n", n
);
4944 if (n
< 0 || n
>= MAXWIN
)
4949 if ((p
= wtab
[n
]) == 0)
4961 Msg(0, "This IS window %d (%s).", n
, p
->w_title
);
4965 if (AclCheckPermWin(D_user
, ACL_READ
, p
))
4967 Msg(0, "Access to window %d denied.", p
->w_number
);
4972 Activate(fore
->w_norefresh
);
4977 SetCanvasWindow(cv
, wi
)
4981 struct win
*p
= 0, **pp
;
4983 struct canvas
*cvp
, **cvpp
;
4986 display
= cv
->c_display
;
4990 /* remove old layer */
4991 for (cvpp
= &l
->l_cvlist
; (cvp
= *cvpp
); cvpp
= &cvp
->c_lnext
)
4995 *cvpp
= cvp
->c_lnext
;
4997 p
= Layer2Window(l
);
5001 if (p
&& cv
== D_forecv
)
5004 ReleaseAutoWritelock(display
, p
);
5008 SetTimeout(&p
->w_silenceev
, p
->w_silencewait
* 1000);
5009 evenq(&p
->w_silenceev
);
5014 if (l
->l_cvlist
== 0 && (p
== 0 || l
!= p
->w_savelayer
))
5018 /* find right layer to display on canvas */
5019 if (wi
&& wi
->w_type
!= W_TYPE_GROUP
)
5022 if (wi
->w_savelayer
&& (wi
->w_blocked
|| wi
->w_savelayer
->l_cvlist
== 0))
5023 l
= wi
->w_savelayer
;
5029 l
->l_data
= (char *)wi
;
5034 /* add our canvas to the layer's canvaslist */
5035 ASSERT(l
->l_cvlist
!= cv
);
5036 cv
->c_lnext
= l
->l_cvlist
;
5039 cv
->c_xoff
= cv
->c_xs
;
5040 cv
->c_yoff
= cv
->c_ys
;
5041 RethinkViewportOffsets(cv
);
5046 if (wi
&& wi
->w_type
== W_TYPE_GROUP
)
5048 /* auto-start windowlist on groups */
5049 struct display
*d
= display
;
5050 struct layer
*oldflayer
= flayer
;
5052 display_wlist(0, 0, wi
);
5057 if (wi
&& D_other
== wi
)
5058 D_other
= wi
->w_next
; /* Might be 0, but that's OK. */
5062 fore
= D_fore
; /* XXX ? */
5066 ObtainAutoWritelock(display
, wi
);
5069 * Place the window at the head of the most-recently-used list
5073 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5078 p
->w_next
= windows
;
5088 * SetForeWindow changes the window in the input focus of the display.
5089 * Puts window wi in canvas display->d_forecv.
5101 p
= Layer2Window(D_forecv
->c_layer
);
5102 SetCanvasWindow(D_forecv
, wi
);
5104 WindowChanged(p
, 'u');
5106 WindowChanged(wi
, 'u');
5107 flayer
= D_forecv
->c_layer
;
5108 ScriptForeWindowChanged();
5109 /* Activate called afterwards, so no RefreshHStatus needed */
5113 /*****************************************************************/
5116 * Activate - make fore window active
5117 * norefresh = -1 forces a refresh, disregard all_norefresh then.
5123 debug1("Activate(%d)\n", norefresh
);
5128 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
5132 if (MayResizeLayer(D_forecv
->c_layer
))
5133 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, display
);
5139 if (fore
->w_monitor
!= MON_OFF
)
5140 fore
->w_monitor
= MON_ON
;
5141 fore
->w_bell
= BELL_ON
;
5142 WindowChanged(fore
, 'f');
5145 if (ResizeDisplay(fore
->w_width
, fore
->w_height
))
5147 debug2("Cannot resize from (%d,%d)", D_width
, D_height
);
5148 debug2(" to (%d,%d) -> resize window\n", fore
->w_width
, fore
->w_height
);
5149 DoResize(D_width
, D_height
);
5153 Redisplay(norefresh
+ all_norefresh
);
5160 register struct win
**pp
;
5161 int n
= fore
? fore
->w_number
: MAXWIN
;
5162 struct win
*group
= fore
? fore
->w_group
: 0;
5164 for (pp
= fore
? wtab
+ n
+ 1 : wtab
; pp
!= wtab
+ n
; pp
++)
5166 if (pp
== wtab
+ MAXWIN
)
5170 if (!fore
|| group
== (*pp
)->w_group
)
5182 register struct win
**pp
;
5183 int n
= fore
? fore
->w_number
: -1;
5184 struct win
*group
= fore
? fore
->w_group
: 0;
5186 for (pp
= wtab
+ n
- 1; pp
!= wtab
+ n
; pp
--)
5189 pp
= wtab
+ MAXWIN
- 1;
5192 if (!fore
|| group
== (*pp
)->w_group
)
5204 char *m
= "No other window.";
5205 if (windows
&& (fore
== 0 || windows
->w_next
))
5209 Msg(0, "No window available");
5212 Msg(0, m
, fore
->w_number
); /* other arg for nethack */
5217 UpdateLayoutCanvas(cv
, wi
)
5221 for (; cv
; cv
= cv
->c_slnext
)
5223 if (cv
->c_layer
&& Layer2Window(cv
->c_layer
) == wi
)
5225 /* A simplistic version of SetCanvasWindow(cv, 0) */
5226 struct layer
*l
= cv
->c_layer
;
5228 if (l
->l_cvlist
== 0 && (wi
== 0 || l
!= wi
->w_savelayer
))
5232 if (l
->l_cvlist
!= cv
)
5234 cv
->c_lnext
= l
->l_cvlist
;
5238 /* Do not end here. Multiple canvases can have the same window */
5242 UpdateLayoutCanvas(cv
->c_slperp
, wi
);
5250 struct win
**pp
, *p
;
5256 * Remove window from linked list.
5258 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5264 wtab
[wi
->w_number
] = 0;
5273 * switch to different window on all canvases
5275 for (display
= displays
; display
; display
= display
->d_next
)
5278 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5280 if (Layer2Window(cv
->c_layer
) != wi
)
5282 /* switch to other window */
5283 SetCanvasWindow(cv
, FindNiceWindow(D_other
, 0));
5289 if (wi
->w_zdisplay
== display
)
5292 D_readev
.condpos
= D_readev
.condneg
= 0;
5299 /* do the same for the layouts */
5300 for (lay
= layouts
; lay
; lay
= lay
->lay_next
)
5301 UpdateLayoutCanvas(&lay
->lay_canvas
, wi
);
5304 WindowChanged((struct win
*)0, 'w');
5305 WindowChanged((struct win
*)0, 'W');
5306 WindowChanged((struct win
*)0, 0);
5315 if ((fore
->w_log
!= 0) == on
)
5317 if (display
&& !*rc_name
)
5318 Msg(0, "You are %s logging.", on
? "already" : "not");
5321 if (fore
->w_log
!= 0)
5323 Msg(0, "Logfile \"%s\" closed.", fore
->w_log
->name
);
5324 logfclose(fore
->w_log
);
5326 WindowChanged(fore
, 'f');
5329 if (DoStartLog(fore
, buf
, sizeof(buf
)))
5331 Msg(errno
, "Error opening logfile \"%s\"", buf
);
5334 if (ftell(fore
->w_log
->fp
) == 0)
5335 Msg(0, "Creating logfile \"%s\".", fore
->w_log
->name
);
5337 Msg(0, "Appending to logfile \"%s\".", fore
->w_log
->name
);
5338 WindowChanged(fore
, 'f');
5342 AddWindows(buf
, len
, flags
, where
)
5348 register char *s
, *ss
;
5349 register struct win
**pp
, *p
;
5354 for (pp
= ((flags
& 4) && where
>= 0) ? wtab
+ where
+ 1: wtab
; pp
< wtab
+ MAXWIN
; pp
++)
5356 if (pp
- wtab
== where
&& ss
== buf
)
5360 if ((flags
& 1) && display
&& p
== D_fore
)
5362 if (D_fore
&& D_fore
->w_group
!= p
->w_group
)
5369 if (s
- buf
+ l
> len
- 24)
5371 if (s
> buf
|| (flags
& 4))
5376 sprintf(s
, "%d", p
->w_number
);
5377 if (p
->w_number
== where
)
5380 if (display
&& p
== D_fore
)
5384 if (display
&& p
== D_other
)
5386 s
= AddWindowFlags(s
, len
, p
);
5397 AddWindowFlags(buf
, len
, p
)
5403 if (p
== 0 || len
< 12)
5409 if (display
&& p
== D_fore
)
5411 if (display
&& p
== D_other
)
5414 if (p
->w_layer
.l_cvlist
&& p
->w_layer
.l_cvlist
->c_lnext
)
5416 if (p
->w_monitor
== MON_DONE
5418 && (ACLBYTE(p
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5422 if (p
->w_bell
== BELL_DONE
)
5425 if (p
->w_slot
!= (slot_t
) 0 && p
->w_slot
!= (slot_t
) -1)
5433 if (p
->w_ptyfd
< 0 && p
->w_type
!= W_TYPE_GROUP
)
5440 AddOtherUsers(buf
, len
, p
)
5445 struct display
*d
, *olddisplay
= display
;
5451 for (display
= displays
; display
; display
= display
->d_next
)
5453 if (olddisplay
&& D_user
== olddisplay
->d_user
)
5455 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5456 if (Layer2Window(cv
->c_layer
) == p
)
5460 for (d
= displays
; d
&& d
!= display
; d
= d
->d_next
)
5461 if (D_user
== d
->d_user
)
5463 if (d
&& d
!= display
)
5465 if (len
> 1 && s
!= buf
)
5470 l
= strlen(D_user
->u_name
);
5473 strcpy(s
, D_user
->u_name
);
5478 display
= olddisplay
;
5491 if (where
== -1 && D_fore
)
5492 where
= D_fore
->w_number
;
5493 ss
= AddWindows(buf
, sizeof(buf
), 0, where
);
5494 s
= buf
+ strlen(buf
);
5495 if (ss
- buf
> D_width
/ 2)
5498 if (s
- ss
< D_width
)
5514 register struct win
*wp
= fore
;
5519 Msg(0, "(%d,%d)/(%d,%d) no window", D_x
+ 1, D_y
+ 1, D_width
, D_height
);
5523 if (buf
< (p
+= GetAnsiStatus(wp
, p
)))
5525 sprintf(p
, "(%d,%d)/(%d,%d)",
5526 wp
->w_x
+ 1, wp
->w_y
+ 1, wp
->w_width
, wp
->w_height
);
5528 sprintf(p
+= strlen(p
), "+%d", wp
->w_histheight
);
5530 sprintf(p
+= strlen(p
), " %c%sflow",
5531 (wp
->w_flow
& FLOW_NOW
) ? '+' : '-',
5532 (wp
->w_flow
& FLOW_AUTOFLAG
) ? "" :
5533 ((wp
->w_flow
& FLOW_AUTO
) ? "(+)" : "(-)"));
5534 if (!wp
->w_wrap
) sprintf(p
+= strlen(p
), " -wrap");
5535 if (wp
->w_insert
) sprintf(p
+= strlen(p
), " ins");
5536 if (wp
->w_origin
) sprintf(p
+= strlen(p
), " org");
5537 if (wp
->w_keypad
) sprintf(p
+= strlen(p
), " app");
5538 if (wp
->w_log
) sprintf(p
+= strlen(p
), " log");
5539 if (wp
->w_monitor
!= MON_OFF
5541 && (ACLBYTE(wp
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5544 sprintf(p
+= strlen(p
), " mon");
5545 if (wp
->w_mouse
) sprintf(p
+= strlen(p
), " mouse");
5547 if (wp
->w_bce
) sprintf(p
+= strlen(p
), " bce");
5549 if (!wp
->w_c1
) sprintf(p
+= strlen(p
), " -c1");
5550 if (wp
->w_norefresh
) sprintf(p
+= strlen(p
), " nored");
5555 if (wp
->w_encoding
&& (display
== 0 || D_encoding
!= wp
->w_encoding
|| EncodingDefFont(wp
->w_encoding
) <= 0))
5558 strcpy(p
, EncodingName(wp
->w_encoding
));
5562 if (wp
->w_encoding
!= UTF8
)
5565 if (D_CC0
|| (D_CS0
&& *D_CS0
))
5569 sprintf(p
, " G%c", wp
->w_Charset
+ '0');
5570 if (wp
->w_FontE
>= ' ')
5575 p
[4] = wp
->w_FontE
^ 0x40;
5582 sprintf(p
++, " G%c%c[", wp
->w_Charset
+ '0', wp
->w_CharsetR
+ '0');
5584 sprintf(p
, " G%c[", wp
->w_Charset
+ '0');
5586 for (i
= 0; i
< 4; i
++)
5588 if (wp
->w_charsets
[i
] == ASCII
)
5590 else if (wp
->w_charsets
[i
] >= ' ')
5591 *p
++ = wp
->w_charsets
[i
];
5595 *p
++ = wp
->w_charsets
[i
] ^ 0x40;
5603 if (wp
->w_type
== W_TYPE_PLAIN
)
5605 /* add info about modem control lines */
5607 TtyGetModemStatus(wp
->w_ptyfd
, p
);
5609 #ifdef BUILTIN_TELNET
5610 else if (wp
->w_type
== W_TYPE_TELNET
)
5613 TelStatus(wp
, p
, sizeof(buf
) - 1 - (p
- buf
));
5616 Msg(0, "%s %d(%s)", buf
, wp
->w_number
, wp
->w_title
);
5626 sprintf(p
, "(%d,%d)", D_width
, D_height
),
5632 strcpy(p
, EncodingName(D_encoding
));
5638 strcpy(p
, " xterm");
5644 strcpy(p
, " color");
5651 strcpy(p
, " iso2022");
5654 else if (D_CS0
&& *D_CS0
)
5656 strcpy(p
, " altchar");
5664 AKAfin(buf
, len
, data
)
5667 char *data
; /* dummy */
5671 ChangeAKA(fore
, buf
, strlen(buf
));
5679 Input("Set window's title to: ", sizeof(fore
->w_akabuf
) - 1, INP_COOKED
, AKAfin
, NULL
, 0);
5685 if ((*(unsigned char *)s
& 0x7f) < 0x20 || *s
== 0x7f)
5689 LayProcess(&ss
, &n
);
5694 Colonfin(buf
, len
, data
)
5697 char *data
; /* dummy */
5702 if (buf
[len
] == '\t')
5705 int l
= 0, r
= RC_LAST
;
5706 int showmessage
= 0;
5709 while (*s
&& s
- buf
< len
)
5713 /* Showing a message when there's no hardstatus or caption cancels the input */
5715 (captionalways
|| D_has_hstatus
== HSTATUS_LASTLINE
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
)))
5721 x
= strncmp(buf
, comms
[m
].name
, len
);
5729 for (l
= m
- 1; l
>= 0 && strncmp(buf
, comms
[l
].name
, len
) == 0; l
--)
5731 for (m
= ++l
; m
<= r
&& strncmp(buf
, comms
[m
].name
, len
) == 0 && s
- mbuf
< sizeof(mbuf
); m
++)
5732 s
+= snprintf(s
, sizeof(mbuf
) - (s
- mbuf
), " %s", comms
[m
].name
);
5736 Msg(0, "Possible commands:%s", mbuf
);
5741 len
= snprintf(mbuf
, sizeof(mbuf
), "%s \t", comms
[l
].name
+ len
);
5742 if (len
> 0 && len
< sizeof(mbuf
))
5743 LayProcess(&s
, &len
);
5748 if (l
> r
&& showmessage
)
5749 Msg(0, "No commands matching '%*s'", len
, buf
);
5753 if (!len
|| buf
[len
])
5756 len
= strlen(buf
) + 1;
5757 if (len
> (int)sizeof(mbuf
))
5761 bcopy(buf
, mbuf
, len
);
5762 RcLine(mbuf
, sizeof mbuf
);
5767 SelectFin(buf
, len
, data
)
5770 char *data
; /* dummy */
5774 if (!len
|| !display
)
5776 if (len
== 1 && *buf
== '-')
5778 SetForeWindow((struct win
*)0);
5782 if ((n
= WindowByNoN(buf
)) < 0)
5788 SelectLayoutFin(buf
, len
, data
)
5791 char *data
; /* dummy */
5795 if (!len
|| !display
)
5797 if (len
== 1 && *buf
== '-')
5799 LoadLayout((struct layout
*)0, (struct canvas
*)0);
5803 lay
= FindLayout(buf
);
5805 Msg(0, "No such layout\n");
5806 else if (lay
== D_layout
)
5807 Msg(0, "This IS layout %d (%s).\n", lay
->lay_number
, lay
->lay_title
);
5810 LoadLayout(lay
, &D_canvas
);
5819 Input("Switch to window: ", 20, INP_COOKED
, SelectFin
, NULL
, 0);
5822 static char setenv_var
[31];
5826 SetenvFin1(buf
, len
, data
)
5829 char *data
; /* dummy */
5831 if (!len
|| !display
)
5837 SetenvFin2(buf
, len
, data
)
5840 char *data
; /* dummy */
5842 if (!len
|| !display
)
5844 debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var
, buf
);
5845 xsetenv(setenv_var
, buf
);
5853 static char setenv_buf
[50 + sizeof(setenv_var
)]; /* need to be static here, cannot be freed */
5857 strncpy(setenv_var
, arg
, sizeof(setenv_var
) - 1);
5858 sprintf(setenv_buf
, "Enter value for %s: ", setenv_var
);
5859 Input(setenv_buf
, 30, INP_COOKED
, SetenvFin2
, NULL
, 0);
5862 Input("Setenv: Enter variable name: ", 30, INP_COOKED
, SetenvFin1
, NULL
, 0);
5866 * the following options are understood by this parser:
5867 * -f, -f0, -f1, -fy, -fa
5868 * -t title, -T terminal-type, -h height-of-scrollback,
5869 * -ln, -l0, -ly, -l1, -l
5876 struct NewWindow nwin
;
5881 while (av
&& *av
&& av
[0][0] == '-')
5883 if (av
[0][1] == '-')
5895 nwin
.flowflag
= FLOW_NOW
* 0;
5900 nwin
.flowflag
= FLOW_NOW
* 1;
5903 nwin
.flowflag
= FLOW_AUTOFLAG
;
5909 case 't': /* no more -k */
5911 nwin
.aka
= &av
[0][2];
5919 nwin
.term
= &av
[0][2];
5927 nwin
.histheight
= atoi(av
[0] + 2);
5929 nwin
.histheight
= atoi(*av
);
5958 nwin
.monitor
= MON_ON
;
5964 Msg(0, "%s: screen: invalid option -%c.", fn
, av
[0][1]);
5970 if (av
&& *av
&& IsNumColon(*av
, 10, buf
, sizeof(buf
)))
5975 if (num
< 0 || num
> MAXWIN
- 1)
5977 Msg(0, "%s: illegal screen number %d.", fn
, num
);
5987 nwin
.aka
= Filename(*av
);
5994 * CompileKeys must be called before Markroutine is first used.
5995 * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
5997 * s is an ascii string in a termcap-like syntax. It looks like
5998 * "j=u:k=d:l=r:h=l: =.:" and so on...
5999 * this example rebinds the cursormovement to the keys u (up), d (down),
6000 * l (left), r (right). placing a mark will now be done with ".".
6003 CompileKeys(s
, sl
, array
)
6006 unsigned char *array
;
6009 unsigned char key
, value
;
6013 for (i
= 0; i
< 256; i
++)
6017 debug1("CompileKeys: '%s'\n", s
);
6020 key
= *(unsigned char *)s
++;
6021 if (*s
!= '=' || sl
< 3)
6028 value
= *(unsigned char *)s
++;
6031 while (*s
== '=' && sl
>= 2);
6040 #endif /* COPY_PASTE */
6043 * Asynchronous input functions
6046 #if defined(DETACH) && defined(POW_DETACH)
6048 pow_detach_fn(buf
, len
, data
)
6051 char *data
; /* dummy */
6053 debug("pow_detach_fn called\n");
6059 if (ktab
[(int)(unsigned char)*buf
].nr
!= RC_POW_DETACH
)
6062 write(D_userfd
, "\007", 1);
6063 Msg(0, "Detach aborted.");
6068 #endif /* POW_DETACH */
6072 copy_reg_fn(buf
, len
, data
)
6075 char *data
; /* dummy */
6077 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6088 if (D_user
->u_plop
.len
)
6090 if ((pp
->buf
= (char *)malloc(D_user
->u_plop
.len
)) == NULL
)
6095 bcopy(D_user
->u_plop
.buf
, pp
->buf
, D_user
->u_plop
.len
);
6097 pp
->len
= D_user
->u_plop
.len
;
6099 pp
->enc
= D_user
->u_plop
.enc
;
6101 Msg(0, "Copied %d characters into register %c", D_user
->u_plop
.len
, *buf
);
6105 ins_reg_fn(buf
, len
, data
)
6108 char *data
; /* dummy */
6110 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6118 return; /* Input() should not call us w/o fore, but you never know... */
6120 Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
6123 MakePaster(&fore
->w_paster
, pp
->buf
, pp
->len
, 0);
6126 Msg(0, "Empty register.");
6128 #endif /* COPY_PASTE */
6131 process_fn(buf
, len
, data
)
6134 char *data
; /* dummy */
6136 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6145 ProcessInput(pp
->buf
, pp
->len
);
6148 Msg(0, "Empty register.");
6152 confirm_fn(buf
, len
, data
)
6159 if (len
|| (*buf
!= 'y' && *buf
!= 'Y'))
6164 act
.nr
= *(int *)data
;
6173 struct acluser
**up
;
6175 char pw1
[130]; /* FreeBSD crypts to 128 bytes */
6180 su_fin(buf
, len
, data
)
6185 struct inputsu
*i
= (struct inputsu
*)data
;
6190 { p
= i
->name
; l
= sizeof(i
->name
) - 1; }
6192 { strcpy(p
= i
->pw1
, "\377"); l
= sizeof(i
->pw1
) - 1; }
6194 { strcpy(p
= i
->pw2
, "\377"); l
= sizeof(i
->pw2
) - 1; }
6196 strncpy(p
, buf
, 1 + (l
< len
) ? l
: len
);
6198 Input("Screen User: ", sizeof(i
->name
) - 1, INP_COOKED
, su_fin
, (char *)i
, 0);
6200 Input("User's UNIX Password: ", sizeof(i
->pw1
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6202 Input("User's Screen Password: ", sizeof(i
->pw2
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6205 if ((p
= DoSu(i
->up
, i
->name
, i
->pw2
, i
->pw1
)))
6212 InputSu(w
, up
, name
)
6214 struct acluser
**up
;
6219 if (!(i
= (struct inputsu
*)calloc(1, sizeof(struct inputsu
))))
6224 su_fin(name
, (int)strlen(name
), (char *)i
); /* can also initialise stuff */
6226 su_fin((char *)0, 0, (char *)i
);
6229 #endif /* MULTIUSER */
6234 pass1(buf
, len
, data
)
6239 struct acluser
*u
= (struct acluser
*)data
;
6244 if (u
->u_password
!= NullStr
)
6245 free((char *)u
->u_password
);
6246 u
->u_password
= SaveStr(buf
);
6247 bzero(buf
, strlen(buf
));
6248 Input("Retype new password:", 100, INP_NOECHO
, pass2
, data
, 0);
6252 pass2(buf
, len
, data
)
6259 struct acluser
*u
= (struct acluser
*)data
;
6262 if (!buf
|| strcmp(u
->u_password
, buf
))
6264 Msg(0, "[ Passwords don't match - checking turned off ]");
6265 if (u
->u_password
!= NullStr
)
6267 bzero(u
->u_password
, strlen(u
->u_password
));
6268 free((char *)u
->u_password
);
6270 u
->u_password
= NullStr
;
6272 else if (u
->u_password
[0] == '\0')
6274 Msg(0, "[ No password - no secure ]");
6276 bzero(buf
, strlen(buf
));
6279 if (u
->u_password
!= NullStr
)
6281 for (st
= 0; st
< 2; st
++)
6282 salt
[st
] = 'A' + (int)((time(0) >> 6 * st
) % 26);
6284 buf
= crypt(u
->u_password
, salt
);
6285 bzero(u
->u_password
, strlen(u
->u_password
));
6286 free((char *)u
->u_password
);
6287 u
->u_password
= SaveStr(buf
);
6288 bzero(buf
, strlen(buf
));
6291 UserFreeCopyBuffer(u
);
6292 u
->u_plop
.len
= strlen(u
->u_password
);
6296 if (!(u
->u_plop
.buf
= SaveStr(u
->u_password
)))
6299 D_user
->u_plop
.len
= 0;
6302 Msg(0, "[ Password moved into copybuffer ]");
6303 #else /* COPY_PASTE */
6304 Msg(0, "[ Crypted password is \"%s\" ]", u
->u_password
);
6305 #endif /* COPY_PASTE */
6308 #endif /* PASSWORD */
6311 digraph_fn(buf
, len
, data
)
6314 char *data
; /* dummy */
6321 buf
[len
+ 1] = ch
; /* so we can restore it later */
6322 if (ch
< ' ' || ch
== '\177')
6324 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6328 if ((ch
< '0' || ch
> '9') && (ch
< 'a' || ch
> 'f') && (ch
< 'A' || ch
> 'F'))
6330 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6333 if (len
== (*buf
== 'U' ? 5 : 3))
6337 if (len
&& *buf
== '0')
6339 if (ch
< '0' || ch
> '7')
6341 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6356 buf
[len
] = buf
[len
+ 1]; /* stored above */
6361 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6364 for (i
= 2; i
< len
; i
++)
6366 if (buf
[i
] >= '0' && buf
[i
] <= '9')
6367 x
= x
* 16 | (buf
[i
] - '0');
6368 else if (buf
[i
] >= 'a' && buf
[i
] <= 'f')
6369 x
= x
* 16 | (buf
[i
] - ('a' - 10));
6370 else if (buf
[i
] >= 'A' && buf
[i
] <= 'F')
6371 x
= x
* 16 | (buf
[i
] - ('A' - 10));
6376 else if (buf
[0] == '0')
6379 for (i
= 1; i
< len
; i
++)
6381 if (buf
[i
] < '0' || buf
[i
] > '7')
6383 x
= x
* 8 | (buf
[i
] - '0');
6388 for (i
= 0; i
< (int)(sizeof(digraphs
)/sizeof(*digraphs
)); i
++)
6389 if ((digraphs
[i
][0] == (unsigned char)buf
[0] && digraphs
[i
][1] == (unsigned char)buf
[1]) ||
6390 (digraphs
[i
][0] == (unsigned char)buf
[1] && digraphs
[i
][1] == (unsigned char)buf
[0]))
6392 if (i
== (int)(sizeof(digraphs
)/sizeof(*digraphs
)))
6394 Msg(0, "Unknown digraph");
6402 if (flayer
->l_encoding
== UTF8
)
6403 i
= ToUtf8(buf
, x
); /* buf is big enough for all UTF-8 codes */
6406 LayProcess(&buf
, &i
);
6417 debug1("StuffKey #%d", i
);
6420 debug1(" - %s", term
[i
+ T_CAPS
].tcname
);
6423 if (i
< KMAP_KEYS
&& D_ESCseen
)
6425 struct action
*act
= &D_ESCseen
[i
+ 256];
6426 if (act
->nr
!= RC_ILLEGAL
)
6429 DoAction(act
, i
+ 256);
6435 if (i
>= T_CURSOR
- T_CAPS
&& i
< T_KEYPAD
- T_CAPS
&& D_cursorkeys
)
6436 i
+= T_OCAPS
- T_CURSOR
;
6437 else if (i
>= T_KEYPAD
- T_CAPS
&& i
< T_OCAPS
- T_CAPS
&& D_keypad
)
6438 i
+= T_OCAPS
- T_CURSOR
;
6439 debug1(" - action %d\n", i
);
6440 flayer
= D_forecv
->c_layer
;
6444 if (InMark() || InInput() || InWList())
6445 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &mmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].mm
;
6447 if ((!act
|| act
->nr
== RC_ILLEGAL
) && !D_mapdefault
)
6448 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &umtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].um
;
6449 if (!act
|| act
->nr
== RC_ILLEGAL
)
6450 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &dmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].dm
;
6452 if (discard
&& (!act
|| act
->nr
!= RC_COMMAND
))
6459 if (act
== 0 || act
->nr
== RC_ILLEGAL
)
6473 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6474 if (Layer2Window(cv
->c_layer
) == wi
)
6480 FindNiceWindow(wi
, presel
)
6486 debug2("FindNiceWindow %d %s\n", wi
? wi
->w_number
: -1 , presel
? presel
: "NULL");
6489 i
= WindowByNoN(presel
);
6496 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6499 if (!wi
|| (IsOnDisplay(wi
) && !presel
))
6501 /* try to get another window */
6504 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6505 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6508 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6509 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6512 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6513 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6516 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6517 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6521 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6522 if (!wi
->w_layer
.l_cvlist
)
6525 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6526 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
))
6530 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6540 AddAlias(name
, value
, args
, argl
, count
)
6547 struct alias
*nalias
= NULL
;
6548 static next_command
= RC_LAST
;
6551 /* Make sure we don't already have this alias name defined. */
6552 if (FindAlias(name
) != NULL
)
6554 Msg(0, "alias already defined: %s", name
);
6558 /* Make sure the alias maps to something */
6559 if ((nr
= FindCommnr((char *)value
)) == RC_ILLEGAL
)
6561 struct alias
*alias
= FindAlias(value
);
6564 Msg(0, "%s: could not find command or alias '%s'", rc_name
, value
);
6570 nalias
= (struct alias
*)calloc(1, sizeof(struct alias
));
6573 nalias
->next
= NULL
;
6574 nalias
->name
= SaveStr(name
);
6578 nalias
->args
= SaveArgs(args
);
6579 nalias
->argl
= calloc(count
+ 1, sizeof(int));
6581 nalias
->argl
[count
] = argl
[count
];
6583 nalias
->nr
= ++next_command
;
6586 nalias
->next
= g_aliases_list
;
6587 g_aliases_list
= nalias
;
6592 * Find an alias by name.
6594 static struct alias
*
6598 struct alias
*t
= g_aliases_list
;
6602 if ((t
->name
!= NULL
) &&
6603 (strcmp(t
->name
, name
) == 0))
6613 * Find an alias by number.
6615 static struct alias
*
6620 for (t
= g_aliases_list
; t
; t
= t
->next
)
6636 /* Find the previous alias */
6637 struct alias
*cur
= g_aliases_list
;
6638 struct alias
**pcur
= &g_aliases_list
;
6642 if ((cur
->name
!= NULL
) &&
6643 (strcmp(cur
->name
, name
) == 0))
6645 struct alias
*found
= cur
;
6648 /* remove this one from the chain. */
6649 *pcur
= found
->next
;
6654 for (c
= 0; found
->args
[c
]; c
++)
6655 free(found
->args
[c
]);
6661 Msg(0, "alias %s removed", name
);
6668 Msg(0, "alias %s not found", name
);
6673 /* sorted list of all commands */
6674 static struct comm
**commtab
;
6675 static int ncommtab
;
6680 void (*hand
) __P((struct comm
*, char **, int));
6683 for (n
= 0; cos
[n
].name
; n
++)
6688 commtab
= (struct commt
*)realloc(commtab
, sizeof(*commtab
) * (ncommtab
+ n
));
6690 commtab
= (struct commt
*)malloc(sizeof(*commtab
) * (ncommtab
+ n
));
6693 for (i
= 0; i
< n
; i
++)
6695 for (j
= 0; j
< ncommtab
; j
++)
6697 r
= strcmp(cos
[i
].name
, commtab
[j
]->name
);
6699 Panic(0, "Duplicate command: %s\n", cos
[i
].name
);
6703 for (r
= ncommtab
; r
> j
; r
--)
6704 commtab
[r
] = commtab
[r
- 1];
6705 commtab
[j
] = cos
+ i
;
6706 cos
[i
].handler
= hand
;
6707 bzero(cos
[i
].userbits
, sizeof(cos
[i
].userbits
));
6716 int x
, m
, l
= 0, r
= ncommtab
- 1;
6720 x
= strcmp(str
, commtab
[m
]->name
);
6734 CalcSlicePercent(cv
, percent
)
6739 if (!cv
|| !cv
->c_slback
)
6741 up
= CalcSlicePercent(cv
->c_slback
->c_slback
, percent
);
6743 for (cv
= cv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6744 wsum
+= cv
->c_slweight
;
6747 return (up
* w
) / wsum
;
6751 ChangeCanvasSize(fcv
, abs
, diff
, gflag
, percent
)
6752 struct canvas
*fcv
; /* make this canvas bigger */
6753 int abs
; /* mode: 0:rel 1:abs 2:max */
6754 int diff
; /* change this much */
6755 int gflag
; /* go up if neccessary */
6759 int done
, have
, m
, dir
;
6761 debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs
, diff
, percent
);
6762 if (abs
== 0 && diff
== 0)
6767 fcv
->c_slweight
= 0;
6770 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6772 fcv
->c_slweight
= 1;
6773 cv
= fcv
->c_slback
->c_slback
;
6774 if (gflag
&& cv
&& cv
->c_slback
)
6775 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6783 if (percent
&& diff
> percent
)
6789 for (cv
= fcv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6790 wsum
+= cv
->c_slweight
;
6793 up
= gflag
? CalcSlicePercent(fcv
->c_slback
->c_slback
, percent
) : percent
;
6794 debug3("up=%d, wsum=%d percent=%d\n", up
, wsum
, percent
);
6797 int scale
= wsum
< 10 ? 1000 : 100;
6798 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6799 cv
->c_slweight
*= scale
;
6801 debug1("scaled wsum to %d\n", wsum
);
6803 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6807 cv
->c_slweight
= (cv
->c_slweight
* up
) / percent
;
6808 if (cv
->c_slweight
== 0)
6811 debug1(" - weight %d\n", cv
->c_slweight
);
6813 diff
= (diff
* wsum
) / percent
;
6819 if (abs
&& diff
== (fcv
->c_slorient
== SLICE_VERT
? fcv
->c_ye
- fcv
->c_ys
+ 2 : fcv
->c_xe
- fcv
->c_xs
+ 2))
6821 /* fix weights to real size (can't be helped, sorry) */
6822 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6824 cv
->c_slweight
= cv
->c_slorient
== SLICE_VERT
? cv
->c_ye
- cv
->c_ys
+ 2 : cv
->c_xe
- cv
->c_xs
+ 2;
6825 debug1(" - weight %d\n", cv
->c_slweight
);
6829 diff
= diff
- fcv
->c_slweight
;
6830 debug1("diff = %d\n", diff
);
6835 cv
= fcv
->c_slnext
? fcv
->c_slnext
: fcv
->c_slprev
;
6836 fcv
->c_slweight
+= diff
;
6837 cv
->c_slweight
-= diff
;
6842 for (cv
= fcv
->c_slnext
; diff
> 0; cv
= dir
> 0 ? cv
->c_slnext
: cv
->c_slprev
)
6846 debug1("reached end, dir is %d\n", dir
);
6856 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 : 2;
6857 debug2("min is %d, have %d\n", m
, cv
->c_slweight
);
6858 if (cv
->c_slweight
> m
)
6860 have
= cv
->c_slweight
- m
;
6863 debug1("subtract %d\n", have
);
6864 cv
->c_slweight
-= have
;
6871 /* need more room! */
6872 cv
= fcv
->c_slback
->c_slback
;
6873 if (cv
&& cv
->c_slback
)
6874 done
+= ChangeCanvasSize(fcv
->c_slback
->c_slback
, 0, diff
, gflag
, percent
);
6876 fcv
->c_slweight
+= done
;
6877 debug1("ChangeCanvasSize returns %d\n", done
);
6882 ResizeRegions(arg
, flags
)
6888 int gflag
= 0, abs
= 0, percent
= 0;
6894 if (D_forecv
->c_slorient
== SLICE_UNKN
)
6896 Msg(0, "resize: need more than one region");
6899 gflag
= flags
& RESIZE_FLAG_L
? 0 : 1;
6900 orient
|= flags
& RESIZE_FLAG_H
? SLICE_HORI
: 0;
6901 orient
|= flags
& RESIZE_FLAG_V
? SLICE_VERT
: 0;
6903 orient
= D_forecv
->c_slorient
;
6907 /* make all regions the same height */
6908 struct canvas
*cv
= gflag
? &D_canvas
: D_forecv
->c_slback
;
6909 if (cv
->c_slperp
->c_slorient
& orient
)
6910 EqualizeCanvas(cv
->c_slperp
, gflag
);
6911 /* can't use cv->c_slorient directly as it can be D_canvas */
6912 if ((cv
->c_slperp
->c_slorient
^ (SLICE_HORI
^ SLICE_VERT
)) & orient
)
6917 EqualizeCanvas(cv
->c_slperp
, gflag
);
6920 EqualizeCanvas(cv
, gflag
);
6923 RecreateCanvasChain();
6924 RethinkDisplayViewports();
6925 ResizeLayersToCanvases();
6928 if (!strcmp(arg
, "min") || !strcmp(arg
, "0"))
6933 else if (!strcmp(arg
, "max") || !strcmp(arg
, "_"))
6940 if (l
> 0 && arg
[l
- 1] == '%')
6943 diff
= atoi(arg
+ 1);
6944 else if (*arg
== '-')
6945 diff
= -atoi(arg
+ 1);
6948 diff
= atoi(arg
); /* +1 because of caption line */
6951 abs
= diff
== 0 ? 2 : 1;
6957 diff
= diff
* percent
/ 100;
6959 if (cv
->c_slorient
& orient
)
6960 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6961 if (cv
->c_slback
->c_slorient
& orient
)
6962 ChangeCanvasSize(cv
->c_slback
, abs
, diff
, gflag
, percent
);
6964 ResizeCanvas(&D_canvas
);
6965 RecreateCanvasChain();
6966 RethinkDisplayViewports();
6967 ResizeLayersToCanvases();
6974 if (siz
+ diff
> dsize
- (nreg
- 1) * 2 - 1)
6975 diff
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6976 if (diff
== 0 || siz
+ diff
< 1)
6981 if (D_forecv
->c_next
)
6983 D_forecv
->c_ye
+= diff
;
6984 D_forecv
->c_next
->c_ys
+= diff
;
6985 D_forecv
->c_next
->c_yoff
+= diff
;
6989 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6990 if (cv
->c_next
== D_forecv
)
6994 D_forecv
->c_ys
-= diff
;
6995 D_forecv
->c_yoff
-= diff
;
7000 int s
, i
= 0, found
= 0, di
= diff
, d2
;
7001 s
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
7002 for (cv
= D_cvlist
; cv
; i
= cv
->c_ye
+ 2, cv
= cv
->c_next
)
7006 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) + diff
;
7007 cv
->c_yoff
-= cv
->c_ys
- i
;
7012 s
-= cv
->c_ye
- cv
->c_ys
;
7020 d2
= di
> cv
->c_ye
- cv
->c_ys
? cv
->c_ye
- cv
->c_ys
: di
;
7022 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) - d2
;
7023 cv
->c_yoff
-= cv
->c_ys
- i
;
7027 RethinkDisplayViewports();
7028 ResizeLayersToCanvases();
7033 ResizeFin(buf
, len
, data
)
7039 int flags
= *(int *)data
;
7040 ch
= ((unsigned char *)buf
)[len
];
7043 ResizeRegions(buf
, flags
);
7047 flags
^= RESIZE_FLAG_H
;
7049 flags
^= RESIZE_FLAG_V
;
7051 flags
|= RESIZE_FLAG_H
|RESIZE_FLAG_V
;
7053 flags
^= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
7055 flags
^= RESIZE_FLAG_L
;
7058 inp_setprompt(resizeprompts
[flags
], NULL
);
7059 *(int *)data
= flags
;
7070 p
= Layer2Window(D_forecv
->c_layer
);
7071 for (i
= 3; i
>=0; i
--)
7072 SetXtermOSC(i
, p
? p
->w_xtermosc
[i
] : 0);
7077 ParseAttrColor(s1
, s2
, msgok
)
7089 while (*ss
&& *ss
!= ' ')
7093 if (*s
&& (s2
|| *ss
|| !((*s
>= 'a' && *s
<= 'z') || (*s
>= 'A' && *s
<= 'Z') || *s
== '.')))
7095 int mode
= 0, n
= 0;
7113 if (*s
>= '0' && *s
<= '9')
7116 if (*s
>= '0' && *s
<= '9')
7117 n
= n
* 16 + (*s
++ - '0');
7118 else if (*s
>= 'a' && *s
<= 'f')
7119 n
= n
* 16 + (*s
++ - ('a' - 10));
7120 else if (*s
>= 'A' && *s
<= 'F')
7121 n
= n
* 16 + (*s
++ - ('A' - 10));
7122 else if (*s
&& *s
!= ' ')
7125 Msg(0, "Illegal attribute hexchar '%c'", *s
);
7131 while (*s
&& *s
!= ' ')
7148 Msg(0, "Illegal attribute specifier '%c'", *s
);
7154 if (*s
&& *s
!= ' ')
7157 Msg(0, "junk after attribute description: '%c'", *s
);
7169 while (*s
&& *s
== ' ')
7177 Msg(0, "junk after description: '%c'", *s
);
7181 while (*s
&& *s
== ' ')
7188 static char costr
[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
7198 for (j
= 0; j
< 2 && *s
&& *s
!= ' '; j
++)
7200 for (i
= 0; costr
[i
]; i
++)
7206 Msg(0, "illegal color descriptor: '%c'", *s
);
7210 n
= n
<< 4 | (i
& 15);
7213 n
= (n
& 0x20ff) | 0x200;
7217 if ((n
& 0xf00) == 0xf00)
7218 n
^= 0xf00; /* clear superflous bits */
7221 n
^= 0x2400; /* shift bit into right position */
7224 n
|= 0xf0; /* don't change bg color */
7225 if (numco
!= 2 && n
!= 0xff)
7226 n
|= 0x100; /* special invert mode */
7227 if (*s
&& *s
!= ' ')
7230 Msg(0, "junk after color description: '%c'", *s
);
7238 while (*s
&& *s
== ' ')
7243 Msg(0, "junk after description: '%c'", *s
);
7246 debug1("ParseAttrColor %06x\n", r
);
7254 * e just set intensity
7255 * f don't change anything
7256 * Intensity is encoded into bits 17(fg) and 18(bg).
7259 ApplyAttrColor(i
, mc
)
7263 debug1("ApplyAttrColor %06x\n", i
);
7264 mc
->attr
|= i
>> 8 & 255;
7265 mc
->attr
^= i
& 255;
7267 i
= (i
>> 16) ^ 0xff;
7268 if ((i
& 0x100) != 0)
7271 if (mc
->attr
& (A_SO
|A_RV
))
7273 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4) | ((i
& 0x200) << 1) | ((i
& 0x400) >> 1);
7275 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4);
7279 if ((i
& 0x0f) != 0x0f)
7280 mc
->attr
= (mc
->attr
& 0xbf) | ((i
>> 3) & 0x40);
7281 if ((i
& 0xf0) != 0xf0)
7282 mc
->attr
= (mc
->attr
& 0x7f) | ((i
>> 3) & 0x80);
7284 mc
->color
= 0x99 ^ mc
->color
;
7285 if ((i
& 0x0e) == 0x0e)
7286 i
= (i
& 0xf0) | (mc
->color
& 0x0f);
7287 if ((i
& 0xe0) == 0xe0)
7288 i
= (i
& 0x0f) | (mc
->color
& 0xf0);
7289 mc
->color
= 0x99 ^ i
;
7290 debug2("ApplyAttrColor - %02x %02x\n", mc
->attr
, i
);