1 /* Copyright (c) 2008, 2009
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Micah Cowan (micah@cowan.name)
5 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
6 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
7 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
8 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
9 * Copyright (c) 1987 Oliver Laumann
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3, or (at your option)
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 ****************************************************************
31 #include <sys/types.h>
35 #if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
40 #include <sys/ioctl.h>
44 /* for solaris 2.1, Unixware (SVR4.2) and possibly others: */
46 # include <sys/stropts.h>
55 extern struct comm comms
[];
57 extern char *RcFileName
, *home
;
58 extern char *BellString
, *ActivityString
, *ShellProg
, *ShellArgs
[];
59 extern char *hstatusstring
, *captionstring
, *timestring
;
60 extern char *wliststr
, *wlisttit
;
61 extern int captionalways
;
62 extern char *hardcopydir
, *screenlogfile
, *logtstamp_string
;
63 extern int log_flush
, logtstamp_on
, logtstamp_after
;
64 extern char *VisualBellString
;
65 extern int VBellWait
, MsgWait
, MsgMinWait
, SilenceWait
;
66 extern char SockPath
[], *SockName
;
67 extern int TtyMode
, auto_detach
, use_altscreen
;
68 extern int iflag
, maxwin
;
69 extern int focusminwidth
, focusminheight
;
70 extern int use_hardstatus
, visual_bell
;
72 extern int attr2color
[][4];
73 extern int nattr2color
;
75 extern int hardstatusemu
;
76 extern char *printcmd
;
77 extern int default_startup
;
78 extern int defobuflimit
;
79 extern int defnonblock
;
80 extern int defmousetrack
;
81 extern int ZombieKey_destroy
;
82 extern int ZombieKey_resurrect
;
83 extern int ZombieKey_onerror
;
85 extern int defautonuke
;
87 extern int separate_sids
;
88 extern struct NewWindow nwin_default
, nwin_undef
;
90 extern int join_with_cr
;
91 extern int compacthist
;
96 extern unsigned char mark_key_tab
[];
97 extern char *BufferFile
;
100 extern char *BufferFile
, *PowDetachString
;
103 extern struct acluser
*EffectiveAclUser
; /* acl.c */
105 extern struct term term
[]; /* terminal capabilities */
107 extern char *kmapdef
[];
108 extern char *kmapadef
[];
109 extern char *kmapmdef
[];
111 extern struct mchar mchar_so
, mchar_null
;
112 extern int renditions
[];
113 extern int VerboseCreate
;
115 extern char *screenencodings
;
121 static int CheckArgNum
__P((int, char **));
122 static void ClearAction
__P((struct action
*));
123 static void SaveAction
__P((struct action
*, int, char **, int *));
124 static int NextWindow
__P((void));
125 static int PreviousWindow
__P((void));
126 static int MoreWindows
__P((void));
127 static void LogToggle
__P((int));
128 static void ShowInfo
__P((void));
129 static void ShowDInfo
__P((void));
130 static struct win
*WindowByName
__P((char *));
131 static int WindowByNumber
__P((char *));
132 static int ParseOnOff
__P((struct action
*, int *));
133 static int ParseWinNum
__P((struct action
*, int *));
134 static int ParseBase
__P((struct action
*, char *, int *, int, char *));
135 static int ParseNum1000
__P((struct action
*, int *));
136 static char **SaveArgs
__P((char **));
137 static int IsNum
__P((char *, int));
138 static void Colonfin
__P((char *, int, char *));
139 static void InputSelect
__P((void));
140 static void InputSetenv
__P((char *));
141 static void InputAKA
__P((void));
143 static int InputSu
__P((struct win
*, struct acluser
**, char *));
144 static void su_fin
__P((char *, int, char *));
146 static void AKAfin
__P((char *, int, char *));
148 static void copy_reg_fn
__P((char *, int, char *));
149 static void ins_reg_fn
__P((char *, int, char *));
151 static void process_fn
__P((char *, int, char *));
153 static void pass1
__P((char *, int, char *));
154 static void pass2
__P((char *, int, char *));
157 static void pow_detach_fn
__P((char *, int, char *));
159 static void digraph_fn
__P((char *, int, char *));
160 static int digraph_find
__P((const char *buf
));
161 static void confirm_fn
__P((char *, int, char *));
162 static int IsOnDisplay
__P((struct win
*));
163 static void ResizeRegions
__P((char *, int));
164 static void ResizeFin
__P((char *, int, char *));
165 static struct action
*FindKtab
__P((char *, int));
166 static void SelectFin
__P((char *, int, char *));
167 static void SelectLayoutFin
__P((char *, int, char *));
170 extern struct layer
*flayer
;
171 extern struct display
*display
, *displays
;
172 extern struct win
*fore
, *console_window
, *windows
;
173 extern struct acluser
*users
;
174 extern struct layout
*layouts
, *layout_attach
, layout_last_marker
;
175 extern struct layout
*laytab
[];
177 extern char screenterm
[], HostName
[], version
[];
178 extern struct NewWindow nwin_undef
, nwin_default
;
179 extern struct LayFuncs WinLf
, MarkLf
;
181 extern int Z0width
, Z1width
;
182 extern int real_uid
, real_gid
;
185 extern int nethackflag
;
189 extern struct win
**wtab
;
193 extern int maxusercount
;
197 struct plop plop_tab
[MAX_PLOP_DEFS
];
200 # define PTYMODE 0622
203 int TtyMode
= PTYMODE
;
204 int hardcopy_append
= 0;
205 int all_norefresh
= 0;
208 char *zmodem_sendcmd
;
209 char *zmodem_recvcmd
;
210 static char *zmodes
[4] = {"off", "auto", "catch", "pass"};
214 struct action idleaction
;
219 struct action ktab
[256 + KMAP_KEYS
]; /* command key translation table */
223 struct action ktab
[256 + KMAP_KEYS
];
225 struct kclass
*kclasses
;
228 struct action umtab
[KMAP_KEYS
+KMAP_AKEYS
];
229 struct action dmtab
[KMAP_KEYS
+KMAP_AKEYS
];
230 struct action mmtab
[KMAP_KEYS
+KMAP_AKEYS
];
231 struct kmap_ext
*kmap_exts
;
233 static int maptimeout
= 300;
237 #define MAX_DIGRAPH 512
246 /* digraph table taken from old vim and rfc1345 */
247 static struct digraph digraphs
[MAX_DIGRAPH
+ 1] = {
248 {' ', ' ', 160}, /* */
249 {'N', 'S', 160}, /* */
250 {'~', '!', 161}, /* ¡ */
251 {'!', '!', 161}, /* ¡ */
252 {'!', 'I', 161}, /* ¡ */
253 {'c', '|', 162}, /* ¢ */
254 {'c', 't', 162}, /* ¢ */
255 {'$', '$', 163}, /* £ */
256 {'P', 'd', 163}, /* £ */
257 {'o', 'x', 164}, /* ¤ */
258 {'C', 'u', 164}, /* ¤ */
259 {'C', 'u', 164}, /* ¤ */
260 {'E', 'u', 164}, /* ¤ */
261 {'Y', '-', 165}, /* ¥ */
262 {'Y', 'e', 165}, /* ¥ */
263 {'|', '|', 166}, /* ¦ */
264 {'B', 'B', 166}, /* ¦ */
265 {'p', 'a', 167}, /* § */
266 {'S', 'E', 167}, /* § */
267 {'"', '"', 168}, /* ¨ */
268 {'\'', ':', 168}, /* ¨ */
269 {'c', 'O', 169}, /* © */
270 {'C', 'o', 169}, /* © */
271 {'a', '-', 170}, /* ª */
272 {'<', '<', 171}, /* « */
273 {'-', ',', 172}, /* ¬ */
274 {'N', 'O', 172}, /* ¬ */
275 {'-', '-', 173}, /* */
276 {'r', 'O', 174}, /* ® */
277 {'R', 'g', 174}, /* ® */
278 {'-', '=', 175}, /* ¯ */
279 {'\'', 'm', 175}, /* ¯ */
280 {'~', 'o', 176}, /* ° */
281 {'D', 'G', 176}, /* ° */
282 {'+', '-', 177}, /* ± */
283 {'2', '2', 178}, /* ² */
284 {'2', 'S', 178}, /* ² */
285 {'3', '3', 179}, /* ³ */
286 {'3', 'S', 179}, /* ³ */
287 {'\'', '\'', 180}, /* ´ */
288 {'j', 'u', 181}, /* µ */
289 {'M', 'y', 181}, /* µ */
290 {'p', 'p', 182}, /* ¶ */
291 {'P', 'I', 182}, /* ¶ */
292 {'~', '.', 183}, /* · */
293 {'.', 'M', 183}, /* · */
294 {',', ',', 184}, /* ¸ */
295 {'\'', ',', 184}, /* ¸ */
296 {'1', '1', 185}, /* ¹ */
297 {'1', 'S', 185}, /* ¹ */
298 {'o', '-', 186}, /* º */
299 {'>', '>', 187}, /* » */
300 {'1', '4', 188}, /* ¼ */
301 {'1', '2', 189}, /* ½ */
302 {'3', '4', 190}, /* ¾ */
303 {'~', '?', 191}, /* ¿ */
304 {'?', '?', 191}, /* ¿ */
305 {'?', 'I', 191}, /* ¿ */
306 {'A', '`', 192}, /* À */
307 {'A', '!', 192}, /* À */
308 {'A', '\'', 193}, /* Á */
309 {'A', '^', 194}, /* Â */
310 {'A', '>', 194}, /* Â */
311 {'A', '~', 195}, /* Ã */
312 {'A', '?', 195}, /* Ã */
313 {'A', '"', 196}, /* Ä */
314 {'A', ':', 196}, /* Ä */
315 {'A', '@', 197}, /* Å */
316 {'A', 'A', 197}, /* Å */
317 {'A', 'E', 198}, /* Æ */
318 {'C', ',', 199}, /* Ç */
319 {'E', '`', 200}, /* È */
320 {'E', '!', 200}, /* È */
321 {'E', '\'', 201}, /* É */
322 {'E', '^', 202}, /* Ê */
323 {'E', '>', 202}, /* Ê */
324 {'E', '"', 203}, /* Ë */
325 {'E', ':', 203}, /* Ë */
326 {'I', '`', 204}, /* Ì */
327 {'I', '!', 204}, /* Ì */
328 {'I', '\'', 205}, /* Í */
329 {'I', '^', 206}, /* Î */
330 {'I', '>', 206}, /* Î */
331 {'I', '"', 207}, /* Ï */
332 {'I', ':', 207}, /* Ï */
333 {'D', '-', 208}, /* Ð */
334 {'N', '~', 209}, /* Ñ */
335 {'N', '?', 209}, /* Ñ */
336 {'O', '`', 210}, /* Ò */
337 {'O', '!', 210}, /* Ò */
338 {'O', '\'', 211}, /* Ó */
339 {'O', '^', 212}, /* Ô */
340 {'O', '>', 212}, /* Ô */
341 {'O', '~', 213}, /* Õ */
342 {'O', '?', 213}, /* Õ */
343 {'O', '"', 214}, /* Ö */
344 {'O', ':', 214}, /* Ö */
345 {'/', '\\', 215}, /* × */
346 {'*', 'x', 215}, /* × */
347 {'O', '/', 216}, /* Ø */
348 {'U', '`', 217}, /* Ù */
349 {'U', '!', 217}, /* Ù */
350 {'U', '\'', 218}, /* Ú */
351 {'U', '^', 219}, /* Û */
352 {'U', '>', 219}, /* Û */
353 {'U', '"', 220}, /* Ü */
354 {'U', ':', 220}, /* Ü */
355 {'Y', '\'', 221}, /* Ý */
356 {'I', 'p', 222}, /* Þ */
357 {'T', 'H', 222}, /* Þ */
358 {'s', 's', 223}, /* ß */
359 {'s', '"', 223}, /* ß */
360 {'a', '`', 224}, /* à */
361 {'a', '!', 224}, /* à */
362 {'a', '\'', 225}, /* á */
363 {'a', '^', 226}, /* â */
364 {'a', '>', 226}, /* â */
365 {'a', '~', 227}, /* ã */
366 {'a', '?', 227}, /* ã */
367 {'a', '"', 228}, /* ä */
368 {'a', ':', 228}, /* ä */
369 {'a', 'a', 229}, /* å */
370 {'a', 'e', 230}, /* æ */
371 {'c', ',', 231}, /* ç */
372 {'e', '`', 232}, /* è */
373 {'e', '!', 232}, /* è */
374 {'e', '\'', 233}, /* é */
375 {'e', '^', 234}, /* ê */
376 {'e', '>', 234}, /* ê */
377 {'e', '"', 235}, /* ë */
378 {'e', ':', 235}, /* ë */
379 {'i', '`', 236}, /* ì */
380 {'i', '!', 236}, /* ì */
381 {'i', '\'', 237}, /* í */
382 {'i', '^', 238}, /* î */
383 {'i', '>', 238}, /* î */
384 {'i', '"', 239}, /* ï */
385 {'i', ':', 239}, /* ï */
386 {'d', '-', 240}, /* ð */
387 {'n', '~', 241}, /* ñ */
388 {'n', '?', 241}, /* ñ */
389 {'o', '`', 242}, /* ò */
390 {'o', '!', 242}, /* ò */
391 {'o', '\'', 243}, /* ó */
392 {'o', '^', 244}, /* ô */
393 {'o', '>', 244}, /* ô */
394 {'o', '~', 245}, /* õ */
395 {'o', '?', 245}, /* õ */
396 {'o', '"', 246}, /* ö */
397 {'o', ':', 246}, /* ö */
398 {':', '-', 247}, /* ÷ */
399 {'o', '/', 248}, /* ø */
400 {'u', '`', 249}, /* ù */
401 {'u', '!', 249}, /* ù */
402 {'u', '\'', 250}, /* ú */
403 {'u', '^', 251}, /* û */
404 {'u', '>', 251}, /* û */
405 {'u', '"', 252}, /* ü */
406 {'u', ':', 252}, /* ü */
407 {'y', '\'', 253}, /* ý */
408 {'i', 'p', 254}, /* þ */
409 {'t', 'h', 254}, /* þ */
410 {'y', '"', 255}, /* ÿ */
411 {'y', ':', 255}, /* ÿ */
412 {'"', '[', 196}, /* Ä */
413 {'"', '\\', 214}, /* Ö */
414 {'"', ']', 220}, /* Ü */
415 {'"', '{', 228}, /* ä */
416 {'"', '|', 246}, /* ö */
417 {'"', '}', 252}, /* ü */
418 {'"', '~', 223} /* ß */
421 #define RESIZE_FLAG_H 1
422 #define RESIZE_FLAG_V 2
423 #define RESIZE_FLAG_L 4
425 static char *resizeprompts
[] = {
427 "resize -h # lines: ",
428 "resize -v # lines: ",
429 "resize -b # lines: ",
430 "resize -l # lines: ",
431 "resize -l -h # lines: ",
432 "resize -l -v # lines: ",
433 "resize -l -b # lines: ",
437 parse_input_int(buf
, len
, val
)
443 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
446 for (i
= 2; i
< len
; i
++)
448 if (buf
[i
] >= '0' && buf
[i
] <= '9')
449 x
= x
* 16 | (buf
[i
] - '0');
450 else if (buf
[i
] >= 'a' && buf
[i
] <= 'f')
451 x
= x
* 16 | (buf
[i
] - ('a' - 10));
452 else if (buf
[i
] >= 'A' && buf
[i
] <= 'F')
453 x
= x
* 16 | (buf
[i
] - ('A' - 10));
458 else if (buf
[0] == '0')
461 for (i
= 1; i
< len
; i
++)
463 if (buf
[i
] < '0' || buf
[i
] > '7')
465 x
= x
* 8 | (buf
[i
] - '0');
479 register unsigned int i
;
484 for (i
= 0; i
< sizeof(ktab
)/sizeof(*ktab
); i
++)
486 ktab
[i
].nr
= RC_ILLEGAL
;
487 ktab
[i
].args
= noargs
;
491 for (i
= 0; i
< KMAP_KEYS
+KMAP_AKEYS
; i
++)
493 umtab
[i
].nr
= RC_ILLEGAL
;
494 umtab
[i
].args
= noargs
;
496 dmtab
[i
].nr
= RC_ILLEGAL
;
497 dmtab
[i
].args
= noargs
;
499 mmtab
[i
].nr
= RC_ILLEGAL
;
500 mmtab
[i
].args
= noargs
;
504 for (i
= 0; i
< NKMAPDEF
; i
++)
506 if (i
+ KMAPDEFSTART
< T_CAPS
)
508 if (i
+ KMAPDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
512 argarr
[0] = kmapdef
[i
];
513 SaveAction(dmtab
+ i
+ (KMAPDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
515 for (i
= 0; i
< NKMAPADEF
; i
++)
517 if (i
+ KMAPADEFSTART
< T_CURSOR
)
519 if (i
+ KMAPADEFSTART
>= T_CURSOR
+ KMAP_AKEYS
)
521 if (kmapadef
[i
] == 0)
523 argarr
[0] = kmapadef
[i
];
524 SaveAction(dmtab
+ i
+ (KMAPADEFSTART
- T_CURSOR
+ KMAP_KEYS
), RC_STUFF
, argarr
, 0);
526 for (i
= 0; i
< NKMAPMDEF
; i
++)
528 if (i
+ KMAPMDEFSTART
< T_CAPS
)
530 if (i
+ KMAPMDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
532 if (kmapmdef
[i
] == 0)
534 argarr
[0] = kmapmdef
[i
];
536 SaveAction(mmtab
+ i
+ (KMAPMDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
540 ktab
['h'].nr
= RC_HARDCOPY
;
542 ktab
['z'].nr
= ktab
[Ctrl('z')].nr
= RC_SUSPEND
;
544 ktab
['c'].nr
= ktab
[Ctrl('c')].nr
= RC_SCREEN
;
545 ktab
[' '].nr
= ktab
[Ctrl(' ')].nr
=
546 ktab
['n'].nr
= ktab
[Ctrl('n')].nr
= RC_NEXT
;
547 ktab
['N'].nr
= RC_NUMBER
;
548 ktab
[Ctrl('h')].nr
= ktab
[0177].nr
= ktab
['p'].nr
= ktab
[Ctrl('p')].nr
= RC_PREV
;
549 ktab
['k'].nr
= ktab
[Ctrl('k')].nr
= RC_KILL
;
550 ktab
['l'].nr
= ktab
[Ctrl('l')].nr
= RC_REDISPLAY
;
551 ktab
['w'].nr
= ktab
[Ctrl('w')].nr
= RC_WINDOWS
;
552 ktab
['v'].nr
= RC_VERSION
;
553 ktab
[Ctrl('v')].nr
= RC_DIGRAPH
;
554 ktab
['q'].nr
= ktab
[Ctrl('q')].nr
= RC_XON
;
555 ktab
['s'].nr
= ktab
[Ctrl('s')].nr
= RC_XOFF
;
556 ktab
['t'].nr
= ktab
[Ctrl('t')].nr
= RC_TIME
;
557 ktab
['i'].nr
= ktab
[Ctrl('i')].nr
= RC_INFO
;
558 ktab
['m'].nr
= ktab
[Ctrl('m')].nr
= RC_LASTMSG
;
559 ktab
['A'].nr
= RC_TITLE
;
560 #if defined(UTMPOK) && defined(LOGOUTOK)
561 ktab
['L'].nr
= RC_LOGIN
;
563 ktab
[','].nr
= RC_LICENSE
;
564 ktab
['W'].nr
= RC_WIDTH
;
565 ktab
['.'].nr
= RC_DUMPTERMCAP
;
566 ktab
[Ctrl('\\')].nr
= RC_QUIT
;
568 ktab
['d'].nr
= ktab
[Ctrl('d')].nr
= RC_DETACH
;
570 ktab
['D'].nr
= RC_POW_DETACH
;
573 ktab
['r'].nr
= ktab
[Ctrl('r')].nr
= RC_WRAP
;
574 ktab
['f'].nr
= ktab
[Ctrl('f')].nr
= RC_FLOW
;
575 ktab
['C'].nr
= RC_CLEAR
;
576 ktab
['Z'].nr
= RC_RESET
;
577 ktab
['H'].nr
= RC_LOG
;
578 ktab
['M'].nr
= RC_MONITOR
;
579 ktab
['?'].nr
= RC_HELP
;
581 ktab
['*'].nr
= RC_DISPLAYS
;
587 SaveAction(ktab
+ '-', RC_SELECT
, args
, 0);
589 for (i
= 0; i
< ((maxwin
&& maxwin
< 10) ? maxwin
: 10); i
++)
591 char *args
[2], arg1
[10];
594 sprintf(arg1
, "%d", i
);
595 SaveAction(ktab
+ '0' + i
, RC_SELECT
, args
, 0);
597 ktab
['\''].nr
= RC_SELECT
; /* calling a window by name */
602 SaveAction(ktab
+ '"', RC_WINDOWLIST
, args
, 0);
604 ktab
[Ctrl('G')].nr
= RC_VBELL
;
605 ktab
[':'].nr
= RC_COLON
;
607 ktab
['['].nr
= ktab
[Ctrl('[')].nr
= RC_COPY
;
612 SaveAction(ktab
+ ']', RC_PASTE
, args
, 0);
613 SaveAction(ktab
+ Ctrl(']'), RC_PASTE
, args
, 0);
615 ktab
['{'].nr
= RC_HISTORY
;
616 ktab
['}'].nr
= RC_HISTORY
;
617 ktab
['>'].nr
= RC_WRITEBUF
;
618 ktab
['<'].nr
= RC_READBUF
;
619 ktab
['='].nr
= RC_REMOVEBUF
;
622 ktab
['D'].nr
= RC_POW_DETACH
;
625 ktab
['x'].nr
= ktab
[Ctrl('x')].nr
= RC_LOCKSCREEN
;
627 ktab
['b'].nr
= ktab
[Ctrl('b')].nr
= RC_BREAK
;
628 ktab
['B'].nr
= RC_POW_BREAK
;
629 ktab
['_'].nr
= RC_SILENCE
;
630 ktab
['S'].nr
= RC_SPLIT
;
631 ktab
['Q'].nr
= RC_ONLY
;
632 ktab
['X'].nr
= RC_REMOVE
;
633 ktab
['F'].nr
= RC_FIT
;
634 ktab
['\t'].nr
= RC_FOCUS
;
639 SaveAction(ktab
+ T_BACKTAB
- T_CAPS
+ 256, RC_FOCUS
, args
, 0);
645 SaveAction(ktab
+ '|', RC_SPLIT
, args
, 0);
647 /* These come last; they may want overwrite others: */
650 ClearAction(&ktab
[DefaultEsc
]);
651 ktab
[DefaultEsc
].nr
= RC_OTHER
;
653 if (DefaultMetaEsc
>= 0)
655 ClearAction(&ktab
[DefaultMetaEsc
]);
656 ktab
[DefaultMetaEsc
].nr
= RC_META
;
659 idleaction
.nr
= RC_BLANKER
;
660 idleaction
.args
= noargs
;
664 static struct action
*
665 FindKtab(class, create
)
669 struct kclass
*kp
, **kpp
;
674 for (kpp
= &kclasses
; (kp
= *kpp
) != 0; kpp
= &kp
->next
)
675 if (!strcmp(kp
->name
, class))
681 if (strlen(class) > 80)
683 Msg(0, "Command class name too long.");
686 kp
= malloc(sizeof(*kp
));
692 kp
->name
= SaveStr(class);
693 for (i
= 0; i
< (int)(sizeof(kp
->ktab
)/sizeof(*kp
->ktab
)); i
++)
695 kp
->ktab
[i
].nr
= RC_ILLEGAL
;
696 kp
->ktab
[i
].args
= noargs
;
697 kp
->ktab
[i
].argl
= 0;
698 kp
->ktab
[i
].quiet
= 0;
712 if (act
->nr
== RC_ILLEGAL
)
714 act
->nr
= RC_ILLEGAL
;
715 if (act
->args
== noargs
)
717 for (p
= act
->args
; *p
; p
++)
719 free((char *)act
->args
);
725 * ProcessInput: process input from display and feed it into
726 * the layer on canvas D_forecv.
732 * This ProcessInput just does the keybindings and passes
733 * everything else on to ProcessInput2.
737 ProcessInput(ibuf
, ilen
)
742 unsigned char *s
, *q
;
746 debug1("ProcessInput: %d bytes\n", ilen
);
747 if (display
== 0 || ilen
== 0)
752 s
= (unsigned char *)ibuf
;
756 if (D_dontmap
|| !D_nseqs
)
763 debug3("cmp %c %c[%d]\n", ch
, *D_seqp
, D_seqp
- D_kmaps
);
766 l
= D_seqp
[D_seqp
[-D_seql
-1] + 1];
770 debug1("miss %d\n", D_seqp
- D_kmaps
);
773 debug("complete miss\n");
776 p
= (char *)D_seqp
- l
;
778 D_seqp
= D_kmaps
+ 3;
781 if ((q
= D_seqh
) != 0)
784 i
= q
[0] << 8 | q
[1];
785 i
&= ~KMAP_NOTIMEOUT
;
786 debug1("Mapping former hit #%d - ", i
);
787 debug2("%d(%s) - ", q
[2], q
+ 3);
789 ProcessInput2((char *)q
+ 3, q
[2]);
797 debug1("flush old %d\n", l
);
806 /* Finish old stuff */
808 debug1("finish old %d\n", slen
);
810 ProcessInput2(ibuf
, slen
);
819 debug2("length am %d, want %d\n", l
, D_seqp
[-l
- 1]);
820 if (l
== D_seqp
[-l
- 1])
825 if (D_kmaps
+ D_nseqs
> q
&& q
[2] > l
&& !bcmp(D_seqp
- l
, q
+ 3, l
))
827 debug1("have another mapping (%s), delay execution\n", q
+ 3);
828 D_seqh
= D_seqp
- 3 - l
;
833 i
= D_seqp
[-l
- 3] << 8 | D_seqp
[-l
- 2];
834 i
&= ~KMAP_NOTIMEOUT
;
835 debug1("Mapping #%d - ", i
);
836 p
= (char *)D_seqp
- l
;
837 debug2("%d(%s) - ", l
, p
);
839 D_seqp
= D_kmaps
+ 3;
851 debug("am in sequence -> check for timeout\n");
853 for (s
= D_seqp
; ; s
+= i
* 2 + 4)
855 if (s
[-l
-3] & KMAP_NOTIMEOUT
>> 8)
857 if ((i
= s
[s
[-l
-1] + 1]) == 0)
859 SetTimeout(&D_mapev
, maptimeout
);
865 ProcessInput2(ibuf
, slen
);
869 # define ProcessInput2 ProcessInput
874 * Here only the screen escape commands are handled.
878 ProcessInput2(ibuf
, ilen
)
884 struct action
*ktabp
;
886 debug1("ProcessInput2: %d bytes\n", ilen
);
887 while (ilen
&& display
)
889 debug1(" - ilen now %d bytes\n", ilen
);
890 flayer
= D_forecv
->c_layer
;
898 if ((unsigned char)*s
++ == D_user
->u_Esc
)
904 DoProcess(fore
, &ibuf
, &slen
, 0);
910 ktabp
= D_ESCseen
? D_ESCseen
: ktab
;
912 ch
= (unsigned char)*s
;
915 * As users have different esc characters, but a common ktab[],
916 * we fold back the users esc and meta-esc key to the Default keys
917 * that can be looked up in the ktab[]. grmbl. jw.
918 * XXX: make ktab[] a per user thing.
920 if (ch
== D_user
->u_Esc
)
922 else if (ch
== D_user
->u_MetaEsc
)
926 DoAction(&ktabp
[ch
], ch
);
927 ibuf
= (char *)(s
+ 1);
933 DoProcess(p
, bufp
, lenp
, pa
)
940 struct display
*d
= display
;
943 /* XXX -> PasteStart */
944 if (pa
&& *lenp
> 1 && p
&& p
->w_slowpaste
)
946 /* schedule slowpaste event */
947 SetTimeout(&p
->w_paster
.pa_slowev
, p
->w_slowpaste
);
948 evenq(&p
->w_paster
.pa_slowev
);
952 while (flayer
&& *lenp
)
955 if (!pa
&& p
&& p
->w_paster
.pa_pastelen
&& flayer
== p
->w_paster
.pa_pastelayer
)
957 debug("layer is busy - beep!\n");
958 WBell(p
, visual_bell
);
966 LayProcess(bufp
, lenp
);
968 if (pa
&& !pa
->pa_pastelayer
)
969 break; /* flush rest of paste */
978 /* We're full, let's beep */
979 debug("layer is full - beep!\n");
980 WBell(p
, visual_bell
);
988 if (pa
&& pa
->pa_pastelen
== 0)
997 int x
, m
, l
= 0, r
= RC_LAST
;
1001 x
= strcmp(str
, comms
[m
].name
);
1013 CheckArgNum(nr
, args
)
1018 static char *argss
[] = {"no", "one", "two", "three", "four", "OOPS"};
1019 static char *orformat
[] =
1021 "%s: %s: %s argument%s required",
1022 "%s: %s: %s or %s argument%s required",
1023 "%s: %s: %s, %s or %s argument%s required",
1024 "%s: %s: %s, %s, %s or %s argument%s required"
1027 n
= comms
[nr
].flags
& ARGS_MASK
;
1028 for (i
= 0; args
[i
]; i
++)
1030 if (comms
[nr
].flags
& ARGS_ORMORE
)
1034 Msg(0, "%s: %s: at least %s argument%s required",
1035 rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1039 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1040 (comms
[nr
].flags
& ARGS_PLUS2
) &&
1041 (comms
[nr
].flags
& ARGS_PLUS3
))
1043 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2 && i
!= n
+ 3)
1045 Msg(0, orformat
[3], rc_name
, comms
[nr
].name
, argss
[n
],
1046 argss
[n
+ 1], argss
[n
+ 2], argss
[n
+ 3], "");
1050 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1051 (comms
[nr
].flags
& ARGS_PLUS2
))
1053 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2)
1055 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1056 argss
[n
+ 1], argss
[n
+ 2], "");
1060 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1061 (comms
[nr
].flags
& ARGS_PLUS3
))
1063 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 3)
1065 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1066 argss
[n
+ 1], argss
[n
+ 3], "");
1070 else if ((comms
[nr
].flags
& ARGS_PLUS2
) &&
1071 (comms
[nr
].flags
& ARGS_PLUS3
))
1073 if (i
!= n
&& i
!= n
+ 2 && i
!= n
+ 3)
1075 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1076 argss
[n
+ 2], argss
[n
+ 3], "");
1080 else if (comms
[nr
].flags
& ARGS_PLUS1
)
1082 if (i
!= n
&& i
!= n
+ 1)
1084 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1085 argss
[n
+ 1], n
!= 0 ? "s" : "");
1089 else if (comms
[nr
].flags
& ARGS_PLUS2
)
1091 if (i
!= n
&& i
!= n
+ 2)
1093 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1098 else if (comms
[nr
].flags
& ARGS_PLUS3
)
1100 if (i
!= n
&& i
!= n
+ 3)
1102 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1109 Msg(0, orformat
[0], rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1116 StuffFin(buf
, len
, data
)
1124 LayProcess(&buf
, &len
);
1134 char **args
= act
->args
;
1135 int *argl
= act
->argl
;
1137 int argc
, i
, n
, msgok
;
1140 struct display
*odisplay
= display
;
1141 struct acluser
*user
;
1143 user
= display
? D_user
: users
;
1144 if (nr
== RC_ILLEGAL
)
1146 debug1("key '%c': No action\n", key
);
1149 n
= comms
[nr
].flags
;
1150 if ((n
& NEED_DISPLAY
) && display
== 0)
1152 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1155 if ((n
& NEED_FORE
) && fore
== 0)
1157 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1160 if ((n
& NEED_LAYER
) && flayer
== 0)
1162 Msg(0, "%s: %s: display or window required", rc_name
, comms
[nr
].name
);
1165 if ((argc
= CheckArgNum(nr
, args
)) < 0)
1170 if (AclCheckPermCmd(D_user
, ACL_EXEC
, &comms
[nr
]))
1172 Msg(0, "%s: %s: permission denied (user %s)",
1173 rc_name
, comms
[nr
].name
, (EffectiveAclUser
? EffectiveAclUser
: D_user
)->u_name
);
1177 #endif /* MULTIUSER */
1179 msgok
= display
&& !*rc_name
;
1185 else if (args
[0][0] == '-' && !args
[0][1])
1187 SetForeWindow((struct win
*)0);
1190 else if (args
[0][0] == '.' && !args
[0][1])
1193 Msg(0, "select . needs a window");
1196 SetForeWindow(fore
);
1200 else if (ParseWinNum(act
, &n
) == 0)
1204 case RC_DEFAUTONUKE
:
1205 if (ParseOnOff(act
, &defautonuke
) == 0 && msgok
)
1206 Msg(0, "Default autonuke turned %s", defautonuke
? "on" : "off");
1207 if (display
&& *rc_name
)
1208 D_auto_nuke
= defautonuke
;
1211 if (ParseOnOff(act
, &D_auto_nuke
) == 0 && msgok
)
1212 Msg(0, "Autonuke turned %s", D_auto_nuke
? "on" : "off");
1215 case RC_DEFOBUFLIMIT
:
1216 if (ParseNum(act
, &defobuflimit
) == 0 && msgok
)
1217 Msg(0, "Default limit set to %d", defobuflimit
);
1218 if (display
&& *rc_name
)
1220 D_obufmax
= defobuflimit
;
1221 D_obuflenmax
= D_obuflen
- D_obufmax
;
1226 Msg(0, "Limit is %d, current buffer size is %d", D_obufmax
, D_obuflen
);
1227 else if (ParseNum(act
, &D_obufmax
) == 0 && msgok
)
1228 Msg(0, "Limit set to %d", D_obufmax
);
1229 D_obuflenmax
= D_obuflen
- D_obufmax
;
1231 case RC_DUMPTERMCAP
:
1232 WriteFile(user
, (char *)0, DUMP_TERMCAP
);
1236 int mode
= DUMP_HARDCOPY
;
1238 if (argc
> 1 && !strcmp(*args
, "-h"))
1240 mode
= DUMP_SCROLLBACK
;
1244 if (*args
&& args
[1])
1246 Msg(0, "%s: hardcopy: too many arguments", rc_name
);
1249 if (fore
== 0 && *args
== 0)
1250 Msg(0, "%s: hardcopy: window required", rc_name
);
1252 WriteFile(user
, *args
, mode
);
1256 (void)ParseOnOff(act
, &nwin_default
.Lflag
);
1259 n
= fore
->w_log
? 1 : 0;
1260 ParseSwitch(act
, &n
);
1270 SwitchWindow(NextWindow());
1274 SwitchWindow(PreviousWindow());
1283 Input(fore
->w_pwin
? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1285 Input("Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1293 FreePseudowin(fore
);
1294 Msg(0, "Filter removed.");
1298 name
= SaveStr(fore
->w_title
);
1300 Msg(0, "Window %d (%s) killed.", n
, name
);
1308 Input("Really quit and kill all your windows [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_QUIT
);
1315 if (*args
&& !strcmp(*args
, "-h"))
1327 Input(buf
, 1, INP_RAW
, pow_detach_fn
, NULL
, 0);
1330 Detach(D_POWER
); /* detach and kill Attacher's parent */
1339 Msg(0, "debugging info is written to %s/", DEBUGDIR
);
1341 Msg(0, "debugging is currently off. Use 'debug on' to enable.");
1346 debug("debug: closing debug file.\n");
1351 if (strcmp("off", *args
))
1355 kill(D_userpid
, SIG_NODEBUG
); /* a one shot item, but hey... */
1356 # endif /* SIG_NODEBUG */
1358 if (*args
== 0 || strcmp("off", *args
))
1359 Msg(0, "Sorry, screen was compiled without -DDEBUG option.");
1364 if (*args
&& !strcmp(*args
, "sendcmd"))
1368 free(zmodem_sendcmd
);
1369 zmodem_sendcmd
= SaveStr(args
[1]);
1372 Msg(0, "zmodem sendcmd: %s", zmodem_sendcmd
);
1375 if (*args
&& !strcmp(*args
, "recvcmd"))
1379 free(zmodem_recvcmd
);
1380 zmodem_recvcmd
= SaveStr(args
[1]);
1383 Msg(0, "zmodem recvcmd: %s", zmodem_recvcmd
);
1388 for (i
= 0; i
< 4; i
++)
1389 if (!strcmp(zmodes
[i
], *args
))
1391 if (i
== 4 && !strcmp(*args
, "on"))
1395 Msg(0, "usage: zmodem off|auto|catch|pass");
1401 Msg(0, "zmodem mode is %s", zmodes
[zmodem_mode
]);
1406 register unsigned int i
;
1408 for (i
= 0; i
< sizeof(ktab
)/sizeof(*ktab
); i
++)
1409 ClearAction(&ktab
[i
]);
1410 Msg(0, "Unbound all keys." );
1417 ZombieKey_destroy
= 0;
1420 if (*argl
== 0 || *argl
> 2)
1422 Msg(0, "%s:zombie: one or two characters expected.", rc_name
);
1427 if (!strcmp(args
[1], "onerror"))
1429 ZombieKey_onerror
= 1;
1431 Msg(0, "usage: zombie [keys [onerror]]");
1435 ZombieKey_onerror
= 0;
1436 ZombieKey_destroy
= args
[0][0];
1437 ZombieKey_resurrect
= *argl
== 2 ? args
[0][1] : 0;
1447 struct display
*olddisplay
= display
;
1448 display
= 0; /* no display will cause a broadcast */
1449 Msg(0, "%s: %s", s
, *args
);
1450 display
= olddisplay
;
1454 /* where this AT command comes from: */
1458 s
= SaveStr(user
->u_name
);
1459 /* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
1460 EffectiveAclUser
= user
;
1462 s
= SaveStr(display
? D_usertty
: user
->u_name
);
1464 n
= strlen(args
[0]);
1467 * the windows/displays loops are quite dangerous here, take extra
1468 * care not to trigger landmines. Things may appear/disappear while
1469 * we are walking along.
1473 case '*': /* user */
1482 for (u
= users
; u
; u
= u
->u_next
)
1484 debug3("strncmp('%s', '%s', %d)\n", *args
, u
->u_name
, n
);
1485 if (!strncmp(*args
, u
->u_name
, n
))
1491 Msg(0, "Did not find any user matching '%s'", args
[0]);
1495 debug1("at all displays of user %s\n", u
->u_name
);
1496 for (display
= displays
; display
; display
= nd
)
1498 nd
= display
->d_next
;
1501 flayer
= D_forecv
->c_layer
;
1505 debug1("AT display %s\n", D_usertty
);
1506 DoCommand(args
+ 1, argl
+ 1);
1508 Msg(0, "command from %s: %s %s",
1509 s
, args
[1], args
[2] ? args
[2] : "");
1516 case '%': /* display */
1520 debug1("at display matching '%s'\n", args
[0]);
1521 for (display
= displays
; display
; display
= nd
)
1523 nd
= display
->d_next
;
1527 flayer
= D_forecv
->c_layer
;
1528 if (strncmp(args
[0], D_usertty
, n
) &&
1529 (strncmp("/dev/", D_usertty
, 5) ||
1530 strncmp(args
[0], D_usertty
+ 5, n
)) &&
1531 (strncmp("/dev/tty", D_usertty
, 8) ||
1532 strncmp(args
[0], D_usertty
+ 8, n
)))
1534 debug1("AT display %s\n", D_usertty
);
1535 DoCommand(args
+ 1, argl
+ 1);
1537 Msg(0, "command from %s: %s %s",
1538 s
, args
[1], args
[2] ? args
[2] : "");
1545 case '#': /* window */
1556 if (!*args
[0] || (i
= WindowByNumber(args
[0])) < 0)
1558 args
[0][n
] = ch
; /* must restore string in case of bind */
1559 /* try looping over titles */
1560 for (fore
= windows
; fore
; fore
= nw
)
1563 if (strncmp(args
[0], fore
->w_title
, n
))
1565 debug2("AT window %d(%s)\n", fore
->w_number
, fore
->w_title
);
1567 * consider this a bug or a feature:
1568 * while looping through windows, we have fore AND
1569 * display context. This will confuse users who try to
1570 * set up loops inside of loops, but often allows to do
1571 * what you mean, even when you adress your context wrong.
1574 /* XXX: other displays? */
1575 if (fore
->w_layer
.l_cvlist
)
1576 display
= fore
->w_layer
.l_cvlist
->c_display
;
1577 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1578 DoCommand(args
+ 1, argl
+ 1); /* may destroy our display */
1579 if (fore
&& fore
->w_layer
.l_cvlist
)
1581 display
= fore
->w_layer
.l_cvlist
->c_display
;
1582 Msg(0, "command from %s: %s %s",
1583 s
, args
[1], args
[2] ? args
[2] : "");
1589 Msg(0, "%s: at '%s': no such window.\n", rc_name
, args
[0]);
1592 else if (i
< maxwin
&& (fore
= wtab
[i
]))
1594 args
[0][n
] = ch
; /* must restore string in case of bind */
1595 debug2("AT window %d (%s)\n", fore
->w_number
, fore
->w_title
);
1596 if (fore
->w_layer
.l_cvlist
)
1597 display
= fore
->w_layer
.l_cvlist
->c_display
;
1598 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1599 DoCommand(args
+ 1, argl
+ 1);
1600 if (fore
&& fore
->w_layer
.l_cvlist
)
1602 display
= fore
->w_layer
.l_cvlist
->c_display
;
1603 Msg(0, "command from %s: %s %s",
1604 s
, args
[1], args
[2] ? args
[2] : "");
1610 Msg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name
);
1616 EffectiveAclUser
= NULL
;
1623 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1624 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1626 i
= FindEncoding(args
[1]);
1629 Msg(0, "%s: readreg: unknown encoding", rc_name
);
1636 * Without arguments we prompt for a destination register.
1637 * It will receive the copybuffer contents.
1638 * This is not done by RC_PASTE, as we prompt for source
1641 if ((s
= *args
) == NULL
)
1643 Input("Copy to register:", 1, INP_RAW
, copy_reg_fn
, NULL
, 0);
1648 Msg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name
);
1653 * With two arguments we *really* read register contents from file
1659 Msg(0, "%s: readreg: too many arguments", rc_name
);
1662 if ((s
= ReadFile(args
[1], &n
)))
1664 struct plop
*pp
= plop_tab
+ (int)(unsigned char)ch
;
1677 * with one argument we copy the copybuffer into a specified register
1678 * This could be done with RC_PASTE too, but is here to be consistent
1679 * with the zero argument call.
1681 copy_reg_fn(&ch
, 0, NULL
);
1686 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1687 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1689 i
= FindEncoding(args
[1]);
1692 Msg(0, "%s: register: unknown encoding", rc_name
);
1701 Msg(0, "%s: register: illegal number of arguments.", rc_name
);
1706 Msg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name
);
1713 if (user
->u_plop
.buf
!= NULL
)
1714 UserFreeCopyBuffer(user
);
1715 if (args
[1] && args
[1][0])
1717 user
->u_plop
.buf
= SaveStrn(args
[1], argl
[1]);
1718 user
->u_plop
.len
= argl
[1];
1720 user
->u_plop
.enc
= i
;
1727 struct plop
*plp
= plop_tab
+ (int)(unsigned char)ch
;
1731 plp
->buf
= SaveStrn(args
[1], argl
[1]);
1739 if ((s
= *args
) == NULL
)
1741 Input("Process register:", 1, INP_RAW
, process_fn
, NULL
, 0);
1746 Msg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name
);
1750 process_fn(&ch
, 0, NULL
);
1756 Input("Stuff:", 100, INP_COOKED
, StuffFin
, NULL
, 0);
1762 if (strcmp(s
, "-k"))
1764 Msg(0, "%s: stuff: invalid option %s", rc_name
, s
);
1768 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
1769 if (strcmp(term
[i
].tcname
, s
) == 0)
1773 Msg(0, "%s: stuff: unknown key '%s'", rc_name
, s
);
1777 if (StuffKey(i
- T_CAPS
) == 0)
1780 s
= display
? D_tcs
[i
].str
: 0;
1795 Msg(0, "screen %s", version
);
1800 timestring
= SaveStr(*args
);
1803 Msg(0, "%s", MakeWinMsg(timestring
, fore
, '%'));
1813 struct action
*ktabp
= ktab
;
1814 if (argc
== 2 && !strcmp(*args
, "-c"))
1816 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
1818 Msg(0, "Unknown command class '%s'", args
[1]);
1822 if (D_ESCseen
!= ktab
|| ktabp
!= ktab
)
1832 SwitchWindow(display
&& D_other
? D_other
->w_number
: NextWindow());
1835 if (user
->u_Esc
== -1)
1854 case RC_DEFBREAKTYPE
:
1857 static char *types
[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL
};
1858 extern int breaktype
;
1862 if (ParseNum(act
, &n
))
1863 for (n
= 0; n
< (int)(sizeof(types
)/sizeof(*types
)); n
++)
1865 for (i
= 0; i
< 4; i
++)
1868 if (ch
>= 'a' && ch
<= 'z')
1870 if (ch
!= types
[n
][i
] && (ch
+ ('a' - 'A')) != types
[n
][i
])
1876 if (n
< 0 || n
>= (int)(sizeof(types
)/sizeof(*types
)))
1877 Msg(0, "%s invalid, chose one of %s, %s or %s", *args
, types
[0], types
[1], types
[2]);
1881 Msg(0, "breaktype set to (%d) %s", n
, types
[n
]);
1885 Msg(0, "breaktype is (%d) %s", breaktype
, types
[breaktype
]);
1891 if (*args
&& ParseNum(act
, &n
))
1893 SendBreak(fore
, n
, nr
== RC_POW_BREAK
);
1907 if (*args
&& !strcmp(*args
, "-w"))
1909 else if (*args
&& !strcmp(*args
, "-d"))
1913 if (what
== 0 && flayer
&& !display
)
1919 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1922 w
= flayer
->l_width
;
1923 h
= flayer
->l_height
;
1929 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1935 if (*args
&& args
[0][0] == '-')
1937 Msg(0, "%s: %s: unknown option %s", rc_name
, comms
[nr
].name
, *args
);
1940 if (nr
== RC_HEIGHT
)
1948 else if (h
== H1height
)
1950 else if (h
> (H0height
+ H1height
) / 2)
1968 else if (w
== Z1width
)
1970 else if (w
> (Z0width
+ Z1width
) / 2)
1982 if (*args
&& args
[1] && args
[2])
1984 Msg(0, "%s: %s: too many arguments", rc_name
, comms
[nr
].name
);
1989 Msg(0, "Illegal width");
1994 Msg(0, "Illegal height");
1999 if (flayer
->l_width
== w
&& flayer
->l_height
== h
)
2001 ResizeLayer(flayer
, w
, h
, (struct display
*)0);
2004 if (D_width
== w
&& D_height
== h
)
2008 ChangeScreenSize(w
, h
, 1);
2012 if (ResizeDisplay(w
, h
) == 0)
2014 Activate(D_fore
? D_fore
->w_norefresh
: 0);
2016 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
2020 Msg(0, "Your termcap does not specify how to change the terminal's width to %d.", w
);
2021 else if (w
== D_width
)
2022 Msg(0, "Your termcap does not specify how to change the terminal's height to %d.", h
);
2024 Msg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w
, h
);
2032 ChangeAKA(fore
, *args
, strlen(*args
));
2035 Input(":", 100, INP_EVERY
, Colonfin
, NULL
, 0);
2036 if (*args
&& **args
)
2044 if (D_status_lastmsg
)
2045 Msg(0, "%s", D_status_lastmsg
);
2048 DoScreen("key", args
);
2051 if (ParseSwitch(act
, &fore
->w_wrap
) == 0 && msgok
)
2052 Msg(0, "%cwrap", fore
->w_wrap
? '+' : '-');
2057 if (args
[0][0] == 'a')
2059 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) ? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
2063 if (ParseOnOff(act
, &n
))
2065 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | n
;
2070 if (fore
->w_flow
& FLOW_AUTOFLAG
)
2071 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | FLOW_NOW
;
2072 else if (fore
->w_flow
& FLOW_NOW
)
2073 fore
->w_flow
&= ~FLOW_NOW
;
2075 fore
->w_flow
= fore
->w_flow
? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
2077 SetFlow(fore
->w_flow
& FLOW_NOW
);
2079 Msg(0, "%cflow%s", (fore
->w_flow
& FLOW_NOW
) ? '+' : '-',
2080 (fore
->w_flow
& FLOW_AUTOFLAG
) ? "(auto)" : "");
2083 case RC_DEFWRITELOCK
:
2084 if (args
[0][0] == 'a')
2085 nwin_default
.wlock
= WLOCK_AUTO
;
2088 if (ParseOnOff(act
, &n
))
2090 nwin_default
.wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2096 if (args
[0][0] == 'a')
2098 fore
->w_wlock
= WLOCK_AUTO
;
2102 if (ParseOnOff(act
, &n
))
2104 fore
->w_wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2107 * user may have permission to change the writelock setting,
2108 * but he may never aquire the lock himself without write permission
2110 if (!AclCheckPermWin(D_user
, ACL_WRITE
, fore
))
2111 fore
->w_wlockuser
= D_user
;
2113 Msg(0, "writelock %s", (fore
->w_wlock
== WLOCK_AUTO
) ? "auto" :
2114 ((fore
->w_wlock
== WLOCK_OFF
) ? "off" : "on"));
2118 ResetAnsiState(fore
);
2119 WriteString(fore
, "\033[H\033[J", 6);
2122 ResetAnsiState(fore
);
2124 if (fore
->w_zdisplay
)
2125 zmodem_abort(fore
, fore
->w_zdisplay
);
2127 WriteString(fore
, "\033c", 2);
2130 n
= fore
->w_monitor
!= MON_OFF
;
2133 n
= n
&& (ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
));
2135 if (ParseSwitch(act
, &n
))
2140 if (display
) /* we tell only this user */
2141 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2143 for (i
= 0; i
< maxusercount
; i
++)
2144 ACLBYTE(fore
->w_mon_notify
, i
) |= ACLBIT(i
);
2146 if (fore
->w_monitor
== MON_OFF
)
2147 fore
->w_monitor
= MON_ON
;
2148 Msg(0, "Window %d (%s) is now being monitored for all activity.", fore
->w_number
, fore
->w_title
);
2153 if (display
) /* we remove only this user */
2154 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
)
2155 &= ~ACLBIT(D_user
->u_id
);
2157 for (i
= 0; i
< maxusercount
; i
++)
2158 ACLBYTE(fore
->w_mon_notify
, i
) &= ~ACLBIT(i
);
2159 for (i
= maxusercount
- 1; i
>= 0; i
--)
2160 if (ACLBYTE(fore
->w_mon_notify
, i
))
2164 fore
->w_monitor
= MON_OFF
;
2165 Msg(0, "Window %d (%s) is no longer being monitored for activity.", fore
->w_number
, fore
->w_title
);
2175 display_wlist(0, WLIST_NUM
, (struct win
*)0);
2176 else if (!strcmp(*args
, "string"))
2182 wliststr
= SaveStr(args
[1]);
2185 Msg(0, "windowlist string is '%s'", wliststr
);
2187 else if (!strcmp(*args
, "title"))
2193 wlisttit
= SaveStr(args
[1]);
2196 Msg(0, "windowlist title is '%s'", wlisttit
);
2202 for (i
= 0; i
< argc
; i
++)
2205 else if (!strcmp(args
[i
], "-m"))
2207 else if (!strcmp(args
[i
], "-b"))
2209 else if (!strcmp(args
[i
], "-g"))
2210 flag
|= WLIST_NESTED
;
2213 Msg(0, "usage: windowlist [-b] [-g] [-m] [string [string] | title [title]]");
2217 display_wlist(blank
, flag
, (struct win
*)0);
2221 if (argc
== 2 && !strcmp(*args
, "-c"))
2223 struct action
*ktabp
;
2224 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
2226 Msg(0, "Unknown command class '%s'", args
[1]);
2229 display_help(args
[1], ktabp
);
2232 display_help((char *)0, ktab
);
2235 display_copyright();
2239 if (flayer
->l_layfn
!= &WinLf
)
2241 Msg(0, "Must be on a window layer");
2245 WindowChanged(fore
, 'P');
2249 static char *pasteargs
[] = {".", 0};
2250 static int pasteargl
[] = {1};
2252 if (flayer
->l_layfn
!= &WinLf
)
2254 Msg(0, "Must be on a window layer");
2257 if (GetHistory() == 0)
2259 if (user
->u_plop
.buf
== NULL
)
2267 char *ss
, *dbuf
, dch
;
2274 * without args we prompt for one(!) register to be pasted in the window
2276 if ((s
= *args
) == NULL
)
2278 Input("Paste from register:", 1, INP_RAW
, ins_reg_fn
, NULL
, 0);
2281 if (args
[1] == 0 && !fore
) /* no window? */
2284 * with two arguments we paste into a destination register
2285 * (no window needed here).
2287 if (args
[1] && argl
[1] != 1)
2289 Msg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
2295 enc
= fore
->w_encoding
;
2299 * measure length of needed buffer
2301 for (ss
= s
= *args
; (ch
= *ss
); ss
++)
2307 enc
= user
->u_plop
.enc
;
2308 if (enc
!= user
->u_plop
.enc
)
2309 l
+= RecodeBuf((unsigned char *)user
->u_plop
.buf
, user
->u_plop
.len
, user
->u_plop
.enc
, enc
, (unsigned char *)0);
2312 l
+= user
->u_plop
.len
;
2318 enc
= plop_tab
[(int)(unsigned char)ch
].enc
;
2319 if (enc
!= plop_tab
[(int)(unsigned char)ch
].enc
)
2320 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);
2323 l
+= plop_tab
[(int)(unsigned char)ch
].len
;
2328 Msg(0, "empty buffer");
2333 * if there is only one source and the destination is a window, then
2334 * pass a pointer rather than duplicating the buffer.
2336 if (s
[1] == 0 && args
[1] == 0)
2338 if (enc
== (*s
== '.' ? user
->u_plop
.enc
: plop_tab
[(int)(unsigned char)*s
].enc
))
2341 MakePaster(&fore
->w_paster
, *s
== '.' ? user
->u_plop
.buf
: plop_tab
[(int)(unsigned char)*s
].buf
, l
, 0);
2345 * if no shortcut, we construct a buffer
2347 if ((dbuf
= (char *)malloc(l
)) == 0)
2354 * concatenate all sources into our own buffer, copy buffer is
2355 * special and is skipped if no display exists.
2357 for (ss
= s
; (ch
= *ss
); ss
++)
2359 struct plop
*pp
= (ch
== '.' ? &user
->u_plop
: &plop_tab
[(int)(unsigned char)ch
]);
2363 l
+= RecodeBuf((unsigned char *)pp
->buf
, pp
->len
, pp
->enc
, enc
, (unsigned char *)dbuf
+ l
);
2367 bcopy(pp
->buf
, dbuf
+ l
, pp
->len
);
2371 * when called with one argument we paste our buffer into the window
2375 MakePaster(&fore
->w_paster
, dbuf
, l
, 1);
2380 * we have two arguments, the second is already in dch.
2381 * use this as destination rather than the window.
2386 if (user
->u_plop
.buf
!= NULL
)
2387 UserFreeCopyBuffer(user
);
2388 user
->u_plop
.buf
= dbuf
;
2389 user
->u_plop
.len
= l
;
2391 user
->u_plop
.enc
= enc
;
2396 struct plop
*pp
= plop_tab
+ (int)(unsigned char)dch
;
2409 if (!user
->u_plop
.buf
)
2411 Msg(0, "empty buffer");
2416 struct plop oldplop
;
2418 oldplop
= user
->u_plop
;
2419 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2424 enc
= FindEncoding(args
[1]);
2427 Msg(0, "%s: writebuf: unknown encoding", rc_name
);
2430 if (enc
!= oldplop
.enc
)
2432 l
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)0);
2433 newbuf
= malloc(l
+ 1);
2439 user
->u_plop
.len
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)newbuf
);
2440 user
->u_plop
.buf
= newbuf
;
2441 user
->u_plop
.enc
= enc
;
2446 if (args
[0] && args
[1])
2447 Msg(0, "%s: writebuf: too many arguments", rc_name
);
2449 WriteFile(user
, args
[0], DUMP_EXCHANGE
);
2451 if (user
->u_plop
.buf
!= oldplop
.buf
)
2452 free(user
->u_plop
.buf
);
2453 user
->u_plop
= oldplop
;
2459 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
2460 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2462 i
= FindEncoding(args
[1]);
2465 Msg(0, "%s: readbuf: unknown encoding", rc_name
);
2471 if (args
[0] && args
[1])
2473 Msg(0, "%s: readbuf: too many arguments", rc_name
);
2476 if ((s
= ReadFile(args
[0] ? args
[0] : BufferFile
, &n
)))
2478 if (user
->u_plop
.buf
)
2479 UserFreeCopyBuffer(user
);
2480 user
->u_plop
.len
= n
;
2481 user
->u_plop
.buf
= s
;
2483 user
->u_plop
.enc
= i
;
2491 (void)ParseSwitch(act
, &search_ic
);
2493 Msg(0, "Will %signore case in searches", search_ic
? "" : "not ");
2495 #endif /* COPY_PASTE */
2498 SetEscape(user
, -1, -1);
2499 else if (*argl
== 2)
2500 SetEscape(user
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2503 Msg(0, "%s: two characters required after escape.", rc_name
);
2506 /* Change defescape if master user. This is because we only
2509 if (display
&& user
!= users
)
2514 SetEscape(NULL
, -1, -1);
2515 else if (*argl
== 2)
2516 SetEscape(NULL
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2519 Msg(0, "%s: two characters required after defescape.", rc_name
);
2527 s
= *args
? *args
: home
;
2529 Msg(errno
, "%s", s
);
2533 if (ParseSaveStr(act
, &ShellProg
) == 0)
2534 ShellArgs
[0] = ShellProg
;
2536 case RC_HARDCOPYDIR
:
2538 (void)ParseSaveStr(act
, &hardcopydir
);
2540 Msg(0, "hardcopydir is %s\n", hardcopydir
&& *hardcopydir
? hardcopydir
: "<cwd>");
2545 if (args
[1] && !(strcmp(*args
, "flush")))
2547 log_flush
= atoi(args
[1]);
2549 Msg(0, "log flush timeout set to %ds\n", log_flush
);
2552 if (ParseSaveStr(act
, &screenlogfile
) || !msgok
)
2555 Msg(0, "logfile is '%s'", screenlogfile
);
2558 if (!*args
|| !strcmp(*args
, "on") || !strcmp(*args
, "off"))
2560 if (ParseSwitch(act
, &logtstamp_on
) == 0 && msgok
)
2561 Msg(0, "timestamps turned %s", logtstamp_on
? "on" : "off");
2563 else if (!strcmp(*args
, "string"))
2567 if (logtstamp_string
)
2568 free(logtstamp_string
);
2569 logtstamp_string
= SaveStr(args
[1]);
2572 Msg(0, "logfile timestamp is '%s'", logtstamp_string
);
2574 else if (!strcmp(*args
, "after"))
2578 logtstamp_after
= atoi(args
[1]);
2582 Msg(0, "timestamp printed after %ds\n", logtstamp_after
);
2585 Msg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
2588 (void)ParseSaveStr(act
, &nwin_default
.aka
);
2591 case RC_TERMCAPINFO
:
2593 if (!rc_name
|| !*rc_name
)
2594 Msg(0, "Sorry, too late now. Place that in your .screenrc file.");
2597 break; /* Already handled */
2600 if (ParseSaveStr(act
, &s
))
2602 if (strlen(s
) >= 20)
2604 Msg(0, "%s: term: argument too long ( < 20)", rc_name
);
2608 strcpy(screenterm
, s
);
2610 debug1("screenterm set to %s\n", screenterm
);
2611 MakeTermcap((display
== 0));
2612 debug("new termcap made\n");
2615 if (!msgok
&& (!rc_name
|| strcmp(rc_name
, "-X")))
2618 * user typed ^A:echo... well, echo isn't FinishRc's job,
2619 * but as he wanted to test us, we show good will
2621 if (argc
> 1 && !strcmp(*args
, "-n"))
2627 if (argc
> 1 && !strcmp(*args
, "-p"))
2633 s
= MakeWinMsg(s
, fore
, '%');
2638 Msg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name
);
2645 AddXChars(buf
, sizeof(buf
), BellString
);
2646 Msg(0, "bell_msg is '%s'", buf
);
2649 (void)ParseSaveStr(act
, &BellString
);
2654 BufferFile
= SaveStr(DEFAULT_BUFFERFILE
);
2655 else if (ParseSaveStr(act
, &BufferFile
))
2658 Msg(0, "Bufferfile is now '%s'", BufferFile
);
2662 (void)ParseSaveStr(act
, &ActivityString
);
2664 #if defined(DETACH) && defined(POW_DETACH)
2665 case RC_POW_DETACH_MSG
:
2669 AddXChars(buf
, sizeof(buf
), PowDetachString
);
2670 Msg(0, "pow_detach_msg is '%s'", buf
);
2673 (void)ParseSaveStr(act
, &PowDetachString
);
2676 #if defined(UTMPOK) && defined(LOGOUTOK)
2678 n
= fore
->w_slot
!= (slot_t
)-1;
2679 if (*args
&& !strcmp(*args
, "always"))
2686 if (*args
&& !strcmp(*args
, "attached"))
2693 if (ParseSwitch(act
, &n
) == 0)
2697 if (!strcmp(*args
, "always"))
2698 nwin_default
.lflag
|= 2;
2699 else if (!strcmp(*args
, "attached"))
2700 nwin_default
.lflag
&= ~2;
2702 (void)ParseOnOff(act
, &nwin_default
.lflag
);
2706 if (args
[0] && args
[1] && args
[1][0] == 'i')
2709 for (display
= displays
; display
; display
= display
->d_next
)
2713 #if defined(TERMIO) || defined(POSIX)
2714 D_NewMode
.tio
.c_cc
[VINTR
] = D_OldMode
.tio
.c_cc
[VINTR
];
2715 D_NewMode
.tio
.c_lflag
|= ISIG
;
2716 #else /* TERMIO || POSIX */
2717 D_NewMode
.m_tchars
.t_intrc
= D_OldMode
.m_tchars
.t_intrc
;
2718 #endif /* TERMIO || POSIX */
2719 SetTTY(D_userfd
, &D_NewMode
);
2722 if (args
[0] && args
[0][0] == 'a')
2723 nwin_default
.flowflag
= FLOW_AUTOFLAG
;
2725 (void)ParseOnOff(act
, &nwin_default
.flowflag
);
2728 (void)ParseOnOff(act
, &nwin_default
.wrap
);
2731 (void)ParseOnOff(act
, &nwin_default
.c1
);
2735 (void)ParseOnOff(act
, &nwin_default
.bce
);
2739 (void)ParseOnOff(act
, &nwin_default
.gr
);
2742 if (ParseOnOff(act
, &n
) == 0)
2743 nwin_default
.monitor
= (n
== 0) ? MON_OFF
: MON_ON
;
2745 case RC_DEFMOUSETRACK
:
2746 if (ParseOnOff(act
, &n
) == 0)
2747 defmousetrack
= (n
== 0) ? 0 : 1000;
2752 Msg(0, "Mouse tracking for this display is turned %s", D_mousetrack
? "on" : "off");
2754 else if (ParseOnOff(act
, &n
) == 0)
2756 D_mousetrack
= n
== 0 ? 0 : 1000;
2758 MouseMode(D_fore
->w_mouse
);
2762 if (ParseOnOff(act
, &n
) == 0)
2763 nwin_default
.silence
= (n
== 0) ? SILENCE_OFF
: SILENCE_ON
;
2767 Msg(0, "W%s echo command when creating windows.",
2768 VerboseCreate
? "ill" : "on't");
2769 else if (ParseOnOff(act
, &n
) == 0)
2775 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
2778 if (args
[0] && strcmp(args
[0], "on") && strcmp(args
[0], "off"))
2780 struct display
*olddisplay
= display
;
2781 int old_use
, new_use
= -1;
2784 if (!strncmp(s
, "always", 6))
2786 if (!strcmp(s
, "lastline"))
2787 new_use
= HSTATUS_LASTLINE
;
2788 else if (!strcmp(s
, "ignore"))
2789 new_use
= HSTATUS_IGNORE
;
2790 else if (!strcmp(s
, "message"))
2791 new_use
= HSTATUS_MESSAGE
;
2792 else if (!strcmp(args
[0], "string"))
2797 AddXChars(buf
, sizeof(buf
), hstatusstring
);
2798 Msg(0, "hardstatus string is '%s'", buf
);
2804 Msg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name
);
2809 hardstatusemu
= new_use
| (s
== args
[0] ? 0 : HSTATUS_ALWAYS
);
2810 for (display
= displays
; display
; display
= display
->d_next
)
2813 new_use
= hardstatusemu
& ~HSTATUS_ALWAYS
;
2814 if (D_HS
&& s
== args
[0])
2815 new_use
= HSTATUS_HS
;
2816 ShowHStatus((char *)0);
2817 old_use
= D_has_hstatus
;
2818 D_has_hstatus
= new_use
;
2819 if ((new_use
== HSTATUS_LASTLINE
&& old_use
!= HSTATUS_LASTLINE
) || (new_use
!= HSTATUS_LASTLINE
&& old_use
== HSTATUS_LASTLINE
))
2820 ChangeScreenSize(D_width
, D_height
, 1);
2827 free(hstatusstring
);
2828 hstatusstring
= SaveStr(args
[1]);
2829 for (display
= displays
; display
; display
= display
->d_next
)
2832 display
= olddisplay
;
2835 (void)ParseSwitch(act
, &use_hardstatus
);
2837 Msg(0, "messages displayed on %s", use_hardstatus
? "hardstatus line" : "window");
2840 if (strcmp(args
[0], "always") == 0 || strcmp(args
[0], "splitonly") == 0)
2842 struct display
*olddisplay
= display
;
2844 captionalways
= args
[0][0] == 'a';
2845 for (display
= displays
; display
; display
= display
->d_next
)
2846 ChangeScreenSize(D_width
, D_height
, 1);
2847 display
= olddisplay
;
2849 else if (strcmp(args
[0], "string") == 0)
2854 AddXChars(buf
, sizeof(buf
), captionstring
);
2855 Msg(0, "caption string is '%s'", buf
);
2861 Msg(0, "%s: usage: caption always|splitonly|string <string>", rc_name
);
2867 free(captionstring
);
2868 captionstring
= SaveStr(args
[1]);
2869 RedisplayDisplays(0);
2872 n
= (console_window
!= 0);
2873 if (ParseSwitch(act
, &n
))
2875 if (TtyGrabConsole(fore
->w_ptyfd
, n
, rc_name
))
2878 Msg(0, "%s: releasing console %s", rc_name
, HostName
);
2879 else if (console_window
)
2880 Msg(0, "%s: stealing console %s from window %d (%s)", rc_name
,
2881 HostName
, console_window
->w_number
, console_window
->w_title
);
2883 Msg(0, "%s: grabbing console %s", rc_name
, HostName
);
2884 console_window
= n
? fore
: 0;
2887 if (ParseOnOff(act
, &all_norefresh
))
2889 if (!all_norefresh
&& fore
)
2892 Msg(0, all_norefresh
? "No refresh on window change!\n" :
2893 "Window specific refresh\n");
2896 (void)ParseSwitch(act
, &n
);
2897 fore
->w_norefresh
= n
;
2900 if (ParseSwitch(act
, &visual_bell
) || !msgok
)
2902 if (visual_bell
== 0)
2903 Msg(0, "switched to audible bell.");
2905 Msg(0, "switched to visual bell.");
2908 if (ParseNum1000(act
, &VBellWait
) == 0 && msgok
)
2909 Msg(0, "vbellwait set to %.10g seconds", VBellWait
/1000.);
2912 if (ParseNum1000(act
, &MsgWait
) == 0 && msgok
)
2913 Msg(0, "msgwait set to %.10g seconds", MsgWait
/1000.);
2916 if (ParseNum1000(act
, &MsgMinWait
) == 0 && msgok
)
2917 Msg(0, "msgminwait set to %.10g seconds", MsgMinWait
/1000.);
2919 case RC_SILENCEWAIT
:
2920 if (ParseNum(act
, &SilenceWait
))
2922 if (SilenceWait
< 1)
2924 for (p
= windows
; p
; p
= p
->w_next
)
2925 p
->w_silencewait
= SilenceWait
;
2927 Msg(0, "silencewait set to %d seconds", SilenceWait
);
2931 Msg(0, "This is window %d (%s).\n", fore
->w_number
, fore
->w_title
);
2934 int old
= fore
->w_number
;
2936 if (args
[0][0] == '+')
2938 else if (args
[0][0] == '-')
2942 parse
= ParseNum(act
, &n
);
2951 if (n
< 0 || n
>= maxwin
)
2953 Msg(0, "Given window position is invalid.");
2963 /* exchange the acls for these windows. */
2967 /* exchange the utmp-slots for these windows */
2968 if ((fore
->w_slot
!= (slot_t
) -1) && (fore
->w_slot
!= (slot_t
) 0))
2973 if (p
&& (p
->w_slot
!= (slot_t
) -1) && (p
->w_slot
!= (slot_t
) 0))
2975 /* XXX: first display wins? */
2976 display
= fore
->w_layer
.l_cvlist
? fore
->w_layer
.l_cvlist
->c_display
: 0;
2982 WindowChanged(fore
, 'n');
2983 WindowChanged((struct win
*)0, 'w');
2984 WindowChanged((struct win
*)0, 'W');
2985 WindowChanged((struct win
*)0, 0);
2989 n
= fore
->w_silence
!= 0;
2990 i
= fore
->w_silencewait
;
2991 if (args
[0] && (args
[0][0] == '-' || (args
[0][0] >= '0' && args
[0][0] <= '9')))
2993 if (ParseNum(act
, &i
))
2997 else if (ParseSwitch(act
, &n
))
3002 if (display
) /* we tell only this user */
3003 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
3005 for (n
= 0; n
< maxusercount
; n
++)
3006 ACLBYTE(fore
->w_lio_notify
, n
) |= ACLBIT(n
);
3008 fore
->w_silencewait
= i
;
3009 fore
->w_silence
= SILENCE_ON
;
3010 SetTimeout(&fore
->w_silenceev
, fore
->w_silencewait
* 1000);
3011 evenq(&fore
->w_silenceev
);
3015 Msg(0, "The window is now being monitored for %d sec. silence.", fore
->w_silencewait
);
3020 if (display
) /* we remove only this user */
3021 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
)
3022 &= ~ACLBIT(D_user
->u_id
);
3024 for (n
= 0; n
< maxusercount
; n
++)
3025 ACLBYTE(fore
->w_lio_notify
, n
) &= ~ACLBIT(n
);
3026 for (i
= maxusercount
- 1; i
>= 0; i
--)
3027 if (ACLBYTE(fore
->w_lio_notify
, i
))
3032 fore
->w_silence
= SILENCE_OFF
;
3033 evdeq(&fore
->w_silenceev
);
3037 Msg(0, "The window is no longer being monitored for silence.");
3041 case RC_DEFSCROLLBACK
:
3042 (void)ParseNum(act
, &nwin_default
.histheight
);
3045 if (flayer
->l_layfn
== &MarkLf
)
3047 Msg(0, "Cannot resize scrollback buffer in copy/scrollback mode.");
3050 (void)ParseNum(act
, &n
);
3051 ChangeWindowSize(fore
, fore
->w_width
, fore
->w_height
, n
);
3053 Msg(0, "scrollback set to %d", fore
->w_histheight
);
3056 case RC_SESSIONNAME
:
3058 Msg(0, "This session is named '%s'\n", SockName
);
3061 char buf
[MAXPATHLEN
];
3064 if (ParseSaveStr(act
, &s
))
3066 if (!*s
|| strlen(s
) + (SockName
- SockPath
) > MAXPATHLEN
- 13 || index(s
, '/'))
3068 Msg(0, "%s: bad session name '%s'\n", rc_name
, s
);
3072 strncpy(buf
, SockPath
, SockName
- SockPath
);
3073 sprintf(buf
+ (SockName
- SockPath
), "%d.%s", (int)getpid(), s
);
3075 if ((access(buf
, F_OK
) == 0) || (errno
!= ENOENT
))
3077 Msg(0, "%s: inappropriate path: '%s'.", rc_name
, buf
);
3080 if (rename(SockPath
, buf
))
3082 Msg(errno
, "%s: failed to rename(%s, %s)", rc_name
, SockPath
, buf
);
3085 debug2("rename(%s, %s) done\n", SockPath
, buf
);
3086 strcpy(SockPath
, buf
);
3088 WindowChanged((struct win
*)0, 'S');
3092 if (!args
[0] || !args
[1])
3094 debug1("RC_SETENV arguments missing: %s\n", args
[0] ? args
[0] : "");
3095 InputSetenv(args
[0]);
3099 xsetenv(args
[0], args
[1]);
3108 case RC_DEFSLOWPASTE
:
3109 (void)ParseNum(act
, &nwin_default
.slow
);
3113 Msg(0, fore
->w_slowpaste
?
3114 "Slowpaste in window %d is %d milliseconds." :
3115 "Slowpaste in window %d is unset.",
3116 fore
->w_number
, fore
->w_slowpaste
);
3117 else if (ParseNum(act
, &fore
->w_slowpaste
) == 0 && msgok
)
3118 Msg(0, fore
->w_slowpaste
?
3119 "Slowpaste in window %d set to %d milliseconds." :
3120 "Slowpaste in window %d now unset.",
3121 fore
->w_number
, fore
->w_slowpaste
);
3124 if (CompileKeys(*args
, *argl
, mark_key_tab
))
3126 Msg(0, "%s: markkeys: syntax error.", rc_name
);
3129 debug1("markkeys %s\n", *args
);
3133 if (ParseSwitch(act
, &pastefont
) == 0 && msgok
)
3134 Msg(0, "Will %spaste font settings", pastefont
? "" : "not ");
3138 (void)ParseSwitch(act
, &join_with_cr
);
3140 case RC_COMPACTHIST
:
3141 if (ParseSwitch(act
, &compacthist
) == 0 && msgok
)
3142 Msg(0, "%scompacting history lines", compacthist
? "" : "not ");
3147 (void)ParseOnOff(act
, &nethackflag
);
3150 case RC_HARDCOPY_APPEND
:
3151 (void)ParseOnOff(act
, &hardcopy_append
);
3157 AddXChars(buf
, sizeof(buf
), VisualBellString
);
3158 Msg(0, "vbell_msg is '%s'", buf
);
3161 (void)ParseSaveStr(act
, &VisualBellString
);
3162 debug1(" new vbellstr '%s'\n", VisualBellString
);
3165 if (ParseBase(act
, *args
, &n
, 8, "octal"))
3167 if (n
< 0 || n
> 0777)
3169 Msg(0, "%s: mode: Invalid tty mode %o", rc_name
, n
);
3174 Msg(0, "Ttymode set to %03o", TtyMode
);
3177 (void)ParseOnOff(act
, &auto_detach
);
3179 case RC_STARTUP_MESSAGE
:
3180 (void)ParseOnOff(act
, &default_startup
);
3186 n
= (*user
->u_password
) ? 1 : 0;
3187 if (user
->u_password
!= NullStr
) free((char *)user
->u_password
);
3188 user
->u_password
= SaveStr(*args
);
3189 if (!strcmp(user
->u_password
, "none"))
3192 Msg(0, "Password checking disabled");
3193 free(user
->u_password
);
3194 user
->u_password
= NullStr
;
3201 Msg(0, "%s: password: window required", rc_name
);
3204 Input("New screen password:", 100, INP_NOECHO
, pass1
, display
? (char *)D_user
: (char *)users
, 0);
3207 #endif /* PASSWORD */
3210 struct action
*ktabp
= ktab
;
3215 if (argc
> 2 && !strcmp(*args
, "-c"))
3217 ktabp
= FindKtab(args
[1], 1);
3224 else if (argc
> 1 && !strcmp(*args
, "-k"))
3237 for (n
= 0; n
< KMAP_KEYS
; n
++)
3238 if (strcmp(term
[n
+ T_CAPS
].tcname
, *args
) == 0)
3242 Msg(0, "%s: bind: unknown key '%s'", rc_name
, *args
);
3251 Msg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name
);
3255 n
= (unsigned char)args
[0][0];
3259 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3261 Msg(0, "%s: bind: unknown command '%s'", rc_name
, args
[1]);
3264 if (CheckArgNum(i
, args
+ 2) < 0)
3266 ClearAction(&ktabp
[n
]);
3267 SaveAction(ktabp
+ n
, i
, args
+ 2, argl
+ 2);
3270 ClearAction(&ktabp
[n
]);
3276 struct action
*newact
;
3277 int newnr
, fl
= 0, kf
= 0, af
= 0, df
= 0, mf
= 0;
3278 struct display
*odisp
= display
;
3280 struct kmap_ext
*kme
;
3282 for (; *args
&& **args
== '-'; args
++, argl
++)
3284 if (strcmp(*args
, "-t") == 0)
3285 fl
= KMAP_NOTIMEOUT
;
3286 else if (strcmp(*args
, "-k") == 0)
3288 else if (strcmp(*args
, "-a") == 0)
3290 else if (strcmp(*args
, "-d") == 0)
3292 else if (strcmp(*args
, "-m") == 0)
3294 else if (strcmp(*args
, "--") == 0)
3302 Msg(0, "%s: bindkey: invalid option %s", rc_name
, *args
);
3308 Msg(0, "%s: bindkey: -d does not work with -m", rc_name
);
3314 display_bindkey("Edit mode", mmtab
);
3316 display_bindkey("Default", dmtab
);
3318 display_bindkey("User", umtab
);
3325 Msg(0, "%s: bindkey: -a only works with -k", rc_name
);
3330 Msg(0, "%s: bindkey: empty string makes no sense", rc_name
);
3333 for (i
= 0, kme
= kmap_exts
; i
< kmap_extn
; i
++, kme
++)
3340 if (*argl
== (kme
->fl
& ~KMAP_NOTIMEOUT
) && bcmp(kme
->str
, *args
, *argl
) == 0)
3346 Msg(0, "%s: bindkey: keybinding not found", rc_name
);
3350 kmap_exts
= (struct kmap_ext
*)xrealloc((char *)kmap_exts
, kmap_extn
* sizeof(*kmap_exts
));
3351 kme
= kmap_exts
+ i
;
3352 bzero((char *)kme
, 8 * sizeof(*kmap_exts
));
3353 for (; i
< kmap_extn
; i
++, kme
++)
3356 kme
->dm
.nr
= kme
->mm
.nr
= kme
->um
.nr
= RC_ILLEGAL
;
3357 kme
->dm
.args
= kme
->mm
.args
= kme
->um
.args
= noargs
;
3358 kme
->dm
.argl
= kme
->mm
.argl
= kme
->um
.argl
= 0;
3363 if (df
== 0 && kme
->dm
.nr
!= RC_ILLEGAL
)
3365 if (mf
== 0 && kme
->mm
.nr
!= RC_ILLEGAL
)
3367 if ((df
|| mf
) && kme
->um
.nr
!= RC_ILLEGAL
)
3369 i
+= KMAP_KEYS
+ KMAP_AKEYS
;
3370 newact
= df
? &kme
->dm
: mf
? &kme
->mm
: &kme
->um
;
3374 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
3375 if (strcmp(term
[i
].tcname
, *args
) == 0)
3379 Msg(0, "%s: bindkey: unknown key '%s'", rc_name
, *args
);
3382 if (af
&& i
>= T_CURSOR
&& i
< T_OCAPS
)
3383 i
-= T_CURSOR
- KMAP_KEYS
;
3386 newact
= df
? &dmtab
[i
] : mf
? &mmtab
[i
] : &umtab
[i
];
3390 if ((newnr
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3392 Msg(0, "%s: bindkey: unknown command '%s'", rc_name
, args
[1]);
3395 if (CheckArgNum(newnr
, args
+ 2) < 0)
3397 ClearAction(newact
);
3398 SaveAction(newact
, newnr
, args
+ 2, argl
+ 2);
3399 if (kf
== 0 && args
[1])
3403 kme
->str
= SaveStrn(*args
, *argl
);
3404 kme
->fl
= fl
| *argl
;
3408 ClearAction(newact
);
3409 for (display
= displays
; display
; display
= display
->d_next
)
3410 remap(i
, args
[1] ? 1 : 0);
3411 if (kf
== 0 && !args
[1])
3413 if (!used
&& kme
->str
)
3426 if (ParseNum(act
, &n
))
3430 Msg(0, "%s: maptimeout: illegal time %d", rc_name
, n
);
3435 if (*args
== 0 || msgok
)
3436 Msg(0, "maptimeout is %dms", maptimeout
);
3450 UsersAcl(NULL
, argc
, args
);
3453 if (UserDel(args
[0], NULL
))
3456 Msg(0, "%s removed from acl database", args
[0]);
3460 * modify a user to gain or lose rights granted to a group.
3461 * This group is actually a normal user whose rights were defined
3462 * with chacl in the usual way.
3466 if (strcmp(args
[1], "none")) /* link a user to another user */
3468 if (AclLinkUser(args
[0], args
[1]))
3471 Msg(0, "User %s joined acl-group %s", args
[0], args
[1]);
3473 else /* remove all groups from user */
3476 struct aclusergroup
*g
;
3478 if (!(u
= *FindUserPtr(args
[0])))
3480 while ((g
= u
->u_group
))
3482 u
->u_group
= g
->next
;
3487 else /* show all groups of user */
3489 char buf
[256], *p
= buf
;
3492 struct aclusergroup
*g
;
3494 if (!(u
= *FindUserPtr(args
[0])))
3497 Msg(0, "User %s does not exist.", args
[0]);
3504 sprintf(p
, "%s ", g
->u
->u_name
);
3512 Msg(0, "%s's group%s: %s.", args
[0], (ngroups
== 1) ? "" : "s",
3513 (ngroups
== 0) ? "none" : buf
);
3518 while ((s
= *args
++))
3522 if (AclUmask(display
? D_user
: users
, s
, &err
))
3523 Msg(0, "umask: %s\n", err
);
3527 if (ParseOnOff(act
, &n
))
3532 Msg(0, "Multiuser mode %s", multi
? "enabled" : "disabled");
3534 #endif /* MULTIUSER */
3542 i
= D_nonblock
>= 0;
3543 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3545 if (ParseNum1000(act
, &i
))
3548 else if (!ParseSwitch(act
, &i
))
3549 i
= i
== 0 ? -1 : 1000;
3552 if (msgok
&& i
== -1)
3553 Msg(0, "display set to blocking mode");
3554 else if (msgok
&& i
== 0)
3555 Msg(0, "display set to nonblocking mode, no timeout");
3557 Msg(0, "display set to nonblocking mode, %.10gs timeout", i
/1000.);
3559 if (D_nonblock
<= 0)
3560 evdeq(&D_blockedev
);
3562 case RC_DEFNONBLOCK
:
3563 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3565 if (ParseNum1000(act
, &defnonblock
))
3568 else if (!ParseOnOff(act
, &defnonblock
))
3569 defnonblock
= defnonblock
== 0 ? -1 : 1000;
3572 if (display
&& *rc_name
)
3574 D_nonblock
= defnonblock
;
3575 if (D_nonblock
<= 0)
3576 evdeq(&D_blockedev
);
3582 if (fore
->w_gr
== 2)
3585 if (ParseSwitch(act
, &fore
->w_gr
) == 0 && msgok
)
3586 Msg(0, "Will %suse GR", fore
->w_gr
? "" : "not ");
3588 if (fore
->w_gr
== 0 && fore
->w_FontE
)
3593 if (ParseSwitch(act
, &fore
->w_c1
) == 0 && msgok
)
3594 Msg(0, "Will %suse C1", fore
->w_c1
? "" : "not ");
3598 if (ParseSwitch(act
, &fore
->w_bce
) == 0 && msgok
)
3599 Msg(0, "Will %serase with background color", fore
->w_bce
? "" : "not ");
3606 if (*args
&& !strcmp(args
[0], "-d"))
3609 Msg(0, "encodings directory is %s", screenencodings
? screenencodings
: "<unset>");
3612 free(screenencodings
);
3613 screenencodings
= SaveStr(args
[1]);
3617 if (*args
&& !strcmp(args
[0], "-l"))
3620 Msg(0, "encoding: -l: argument required");
3621 else if (LoadFontTranslation(-1, args
[1]))
3622 Msg(0, "encoding: could not load utf8 encoding file");
3624 Msg(0, "encoding: utf8 encoding file loaded");
3628 if (*args
&& (!strcmp(args
[0], "-l") || !strcmp(args
[0], "-d")))
3631 Msg(0, "encoding: screen is not compiled for UTF-8.");
3635 for (i
= 0; i
< 2; i
++)
3639 if (!strcmp(args
[i
], "."))
3641 n
= FindEncoding(args
[i
]);
3644 Msg(0, "encoding: unknown encoding '%s'", args
[i
]);
3649 WinSwitchEncoding(fore
, n
);
3650 ResetCharsets(fore
);
3652 else if (i
&& display
)
3657 case RC_DEFENCODING
:
3658 n
= FindEncoding(*args
);
3661 Msg(0, "defencoding: unknown encoding '%s'", *args
);
3664 nwin_default
.encoding
= n
;
3670 n
= nwin_default
.encoding
== UTF8
;
3671 if (ParseSwitch(act
, &n
) == 0)
3673 nwin_default
.encoding
= n
? UTF8
: 0;
3675 Msg(0, "Will %suse UTF-8 encoding for new windows", n
? "" : "not ");
3679 for (i
= 0; i
< 2; i
++)
3681 if (i
&& args
[i
] == 0)
3684 n
= fore
->w_encoding
!= UTF8
;
3685 else if (strcmp(args
[i
], "off") == 0)
3687 else if (strcmp(args
[i
], "on") == 0)
3691 Msg(0, "utf8: illegal argument (%s)", args
[i
]);
3696 WinSwitchEncoding(fore
, n
? UTF8
: 0);
3698 Msg(0, "Will %suse UTF-8 encoding", n
? "" : "not ");
3701 D_encoding
= n
? UTF8
: 0;
3715 printcmd
= SaveStr(*args
);
3717 if (*args
== 0 || msgok
)
3720 Msg(0, "using '%s' as print command", printcmd
);
3722 Msg(0, "using termcap entries for printing");
3728 if (argl
&& argl
[0] > 0 && argl
[1] > 0)
3732 Msg(0, "Two characters expected to define a digraph");
3735 i
= digraph_find(args
[0]);
3736 digraphs
[i
].d
[0] = args
[0][0];
3737 digraphs
[i
].d
[1] = args
[0][1];
3738 if (!parse_input_int(args
[1], argl
[1], &digraphs
[i
].value
))
3740 if (!(digraphs
[i
].value
= atoi(args
[1])))
3743 digraphs
[i
].value
= (int)args
[1][0];
3748 unsigned char *s
= args
[1];
3749 digraphs
[i
].value
= 0;
3752 t
= FromUtf8(*s
++, &digraphs
[i
].value
);
3756 digraphs
[i
].value
= 0;
3758 digraphs
[i
].value
= t
;
3767 Input("Enter digraph: ", 10, INP_EVERY
, digraph_fn
, NULL
, 0);
3768 if (*args
&& **args
)
3781 if (nwin_default
.hstatus
)
3782 AddXChars(buf
, sizeof(buf
), nwin_default
.hstatus
);
3783 Msg(0, "default hstatus is '%s'", buf
);
3786 (void)ParseSaveStr(act
, &nwin_default
.hstatus
);
3787 if (*nwin_default
.hstatus
== 0)
3789 free(nwin_default
.hstatus
);
3790 nwin_default
.hstatus
= 0;
3794 (void)ParseSaveStr(act
, &fore
->w_hstatus
);
3795 if (*fore
->w_hstatus
== 0)
3797 free(fore
->w_hstatus
);
3798 fore
->w_hstatus
= 0;
3800 WindowChanged(fore
, 'h');
3810 if (nwin_default
.charset
)
3811 AddXChars(buf
, sizeof(buf
), nwin_default
.charset
);
3812 Msg(0, "default charset is '%s'", buf
);
3816 if (n
== 0 || n
> 6)
3818 Msg(0, "%s: %s: string has illegal size.", rc_name
, comms
[nr
].name
);
3822 ((args
[0][4] < '0' || args
[0][4] > '3') && args
[0][4] != '.') ||
3823 ((args
[0][5] < '0' || args
[0][5] > '3') && args
[0][5] && args
[0][5] != '.')))
3825 Msg(0, "%s: %s: illegal mapping number.", rc_name
, comms
[nr
].name
);
3828 if (nr
== RC_CHARSET
)
3830 SetCharsets(fore
, *args
);
3833 if (nwin_default
.charset
)
3834 free(nwin_default
.charset
);
3835 nwin_default
.charset
= SaveStr(*args
);
3841 if (*s
>= '0' && *s
<= '9')
3844 for (i
= 0; i
< 8; i
++)
3845 if (*s
== "dubrsBiI"[i
])
3849 if (*s
&& s
[1] && !s
[2])
3851 if (*s
== 'd' && s
[1] == 'd')
3853 else if (*s
== '.' && s
[1] == 'd')
3855 else if (*s
== 'd' && s
[1] == '.')
3857 else if (*s
!= '.' || s
[1] != '.')
3861 if (*s
|| i
< 0 || i
>= 8)
3863 Msg(0, "%s: attrcolor: unknown attribute '%s'.", rc_name
, args
[0]);
3868 n
= ParseAttrColor(args
[1], args
[2], 1);
3871 attr2color
[i
][nr
] = n
;
3873 for (i
= 0; i
< 8; i
++)
3874 if (attr2color
[i
][0] || attr2color
[i
][1] || attr2color
[i
][2] || attr2color
[i
][3])
3881 if (strcmp(args
[0], "bell") == 0)
3885 else if (strcmp(args
[0], "monitor") == 0)
3889 else if (strcmp(args
[0], "so") != 0)
3891 Msg(0, "Invalid option '%s' for rendition", args
[0]);
3900 renditions
[i
] = ParseAttrColor(args
[0], args
[1], 1);
3901 WindowChanged((struct win
*)0, 'w');
3902 WindowChanged((struct win
*)0, 'W');
3903 WindowChanged((struct win
*)0, 0);
3907 /* We are here, means we want to set the sorendition. */
3909 case RC_SORENDITION
:
3913 i
= ParseAttrColor(*args
, args
[1], 1);
3916 ApplyAttrColor(i
, &mchar_so
);
3917 WindowChanged((struct win
*)0, 0);
3918 debug2("--> %x %x\n", mchar_so
.attr
, mchar_so
.color
);
3922 Msg(0, "Standout attributes 0x%02x color 0x%02x", (unsigned char)mchar_so
.attr
, 0x99 ^ (unsigned char)mchar_so
.color
);
3924 Msg(0, "Standout attributes 0x%02x ", (unsigned char)mchar_so
.attr
);
3937 Msg(0, "%s:%s screen login", HostName
, SockPath
);
3938 InputSu(D_fore
, &D_user
, NULL
);
3941 InputSu(D_fore
, &D_user
, args
[0]);
3943 s
= DoSu(&D_user
, args
[0], args
[1], "\377");
3945 s
= DoSu(&D_user
, args
[0], args
[1], args
[2]);
3949 #endif /* MULTIUSER */
3952 if (s
&& !strcmp(s
, "-v"))
3953 AddCanvas(SLICE_HORI
);
3955 AddCanvas(SLICE_VERT
);
3967 D_forecv
->c_xoff
= D_forecv
->c_xs
;
3968 D_forecv
->c_yoff
= D_forecv
->c_ys
;
3969 RethinkViewportOffsets(D_forecv
);
3970 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
3971 flayer
= D_forecv
->c_layer
;
3976 struct canvas
*cv
= 0;
3977 if (!*args
|| !strcmp(*args
, "next"))
3978 cv
= D_forecv
->c_next
? D_forecv
->c_next
: D_cvlist
;
3979 else if (!strcmp(*args
, "prev"))
3981 for (cv
= D_cvlist
; cv
->c_next
&& cv
->c_next
!= D_forecv
; cv
= cv
->c_next
)
3984 else if (!strcmp(*args
, "top"))
3986 else if (!strcmp(*args
, "bottom"))
3988 for (cv
= D_cvlist
; cv
->c_next
; cv
= cv
->c_next
)
3991 else if (!strcmp(*args
, "up"))
3992 cv
= FindCanvas(D_forecv
->c_xs
, D_forecv
->c_ys
- 1);
3993 else if (!strcmp(*args
, "down"))
3994 cv
= FindCanvas(D_forecv
->c_xs
, D_forecv
->c_ye
+ 2);
3995 else if (!strcmp(*args
, "left"))
3996 cv
= FindCanvas(D_forecv
->c_xs
- 1, D_forecv
->c_ys
);
3997 else if (!strcmp(*args
, "right"))
3998 cv
= FindCanvas(D_forecv
->c_xe
+ 1, D_forecv
->c_ys
);
4001 Msg(0, "%s: usage: focus [next|prev|up|down|left|right|top|bottom]", rc_name
);
4004 SetForeCanvas(display
, cv
);
4009 if (D_forecv
->c_slorient
== SLICE_UNKN
)
4011 Msg(0, "resize: need more than one region");
4014 for (; *args
; args
++)
4016 if (!strcmp(*args
, "-h"))
4018 else if (!strcmp(*args
, "-v"))
4020 else if (!strcmp(*args
, "-b"))
4021 i
|= RESIZE_FLAG_H
| RESIZE_FLAG_V
;
4022 else if (!strcmp(*args
, "-p"))
4023 i
|= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
4024 else if (!strcmp(*args
, "-l"))
4029 if (*args
&& args
[1])
4031 Msg(0, "%s: usage: resize [-h] [-v] [-l] [num]\n", rc_name
);
4035 ResizeRegions(*args
, i
);
4037 Input(resizeprompts
[i
], 20, INP_EVERY
, ResizeFin
, (char*)0, i
);
4040 (void)ParseSwitch(act
, &separate_sids
);
4043 args
= SaveArgs(args
);
4044 for (i
= 0; args
[i
]; i
++)
4047 Colonfin(args
[i
], strlen(args
[i
]), (char *)0);
4053 (void)ParseSwitch(act
, &use_altscreen
);
4055 Msg(0, "Will %sdo alternate screen switching", use_altscreen
? "" : "not ");
4060 Msg(0, "maximum windows allowed: %d", maxwin
);
4063 if (ParseNum(act
, &n
))
4066 Msg(0, "illegal maxwin number specified");
4068 Msg(0, "maximum 2048 windows allowed");
4069 else if (n
> maxwin
&& windows
)
4070 Msg(0, "may increase maxwin only when there's no window");
4074 wtab
= realloc(wtab
, n
* sizeof(struct win
));
4079 if (ParseBase(act
, *args
, &n
, 10, "decimal"))
4082 setbacktick(n
, 0, 0, (char **)0);
4088 Msg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name
);
4091 if (ParseBase(act
, args
[1], &lifespan
, 10, "decimal"))
4093 if (ParseBase(act
, args
[2], &tick
, 10, "decimal"))
4095 setbacktick(n
, lifespan
, tick
, SaveArgs(args
+ 3));
4097 WindowChanged(0, '`');
4103 RunBlanker(blankerprg
);
4108 CursorVisibility(-1);
4117 char path
[MAXPATHLEN
];
4118 char *p
= path
, **pp
;
4119 for (pp
= blankerprg
; *pp
; pp
++)
4120 p
+= snprintf(p
, sizeof(path
) - (p
- path
) - 1, "%s ", *pp
);
4122 Msg(0, "blankerprg: %s", path
);
4125 Msg(0, "No blankerprg set.");
4131 for (pp
= blankerprg
; *pp
; pp
++)
4137 blankerprg
= SaveArgs(args
);
4143 struct display
*olddisplay
= display
;
4144 if (!strcmp(*args
, "off"))
4146 else if (args
[0][0])
4147 idletimo
= atoi(*args
) * 1000;
4150 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
4152 Msg(0, "%s: idle: unknown command '%s'", rc_name
, args
[1]);
4155 if (CheckArgNum(i
, args
+ 2) < 0)
4157 ClearAction(&idleaction
);
4158 SaveAction(&idleaction
, i
, args
+ 2, argl
+ 2);
4160 for (display
= displays
; display
; display
= display
->d_next
)
4162 display
= olddisplay
;
4167 Msg(0, "idle timeout %ds, %s", idletimo
/ 1000, comms
[idleaction
.nr
].name
);
4172 case RC_FOCUSMINSIZE
:
4173 for (i
= 0; i
< 2 && args
[i
]; i
++)
4175 if (!strcmp(args
[i
], "max") || !strcmp(args
[i
], "_"))
4187 for (i
= 0; i
< 2; i
++)
4189 n
= i
== 0 ? focusminwidth
: focusminheight
;
4191 strcpy(b
[i
], "max");
4193 sprintf(b
[i
], "%d", n
);
4195 Msg(0, "focus min size is %s %s\n", b
[0], b
[1]);
4204 fore
->w_group
= WindowByName(*args
);
4205 if (fore
->w_group
&& fore
->w_group
->w_type
!= W_TYPE_GROUP
)
4208 WindowChanged((struct win
*)0, 'w');
4209 WindowChanged((struct win
*)0, 'W');
4210 WindowChanged((struct win
*)0, 0);
4215 Msg(0, "window group is %d (%s)\n", fore
->w_group
->w_number
, fore
->w_group
->w_title
);
4217 Msg(0, "window belongs to no group");
4221 if (!strcmp(args
[0], "title"))
4225 Msg(0, "not on a layout");
4230 Msg(0, "current layout is %d (%s)", D_layout
->lay_number
, D_layout
->lay_title
);
4233 free(D_layout
->lay_title
);
4234 D_layout
->lay_title
= SaveStr(args
[1]);
4236 else if (!strcmp(args
[0], "number"))
4242 Msg(0, "not on a layout");
4247 Msg(0, "This is layout %d (%s).\n", D_layout
->lay_number
, D_layout
->lay_title
);
4250 old
= D_layout
->lay_number
;
4252 if (n
< 0 || n
>= MAXLAY
)
4255 laytab
[n
] = D_layout
;
4256 D_layout
->lay_number
= n
;
4259 lay
->lay_number
= old
;
4262 else if (!strcmp(args
[0], "autosave"))
4266 Msg(0, "not on a layout");
4271 if (!strcmp(args
[1], "on"))
4272 D_layout
->lay_autosave
= 1;
4273 else if (!strcmp(args
[1], "off"))
4274 D_layout
->lay_autosave
= 0;
4277 Msg(0, "invalid argument. Give 'on' or 'off");
4282 Msg(0, "autosave is %s", D_layout
->lay_autosave
? "on" : "off");
4284 else if (!strcmp(args
[0], "new"))
4290 while (*t
>= '0' && *t
<= '9')
4292 if (t
!= args
[1] && (!*t
|| *t
== ':'))
4306 else if (!strcmp(args
[0], "save"))
4310 Msg(0, "usage: layout save <name>");
4313 SaveLayout(args
[1], &D_canvas
);
4315 else if (!strcmp(args
[0], "select"))
4319 Input("Switch to layout: ", 20, INP_COOKED
, SelectLayoutFin
, NULL
, 0);
4322 SelectLayoutFin(args
[1], strlen(args
[1]), (char *)0);
4324 else if (!strcmp(args
[0], "next"))
4326 struct layout
*lay
= D_layout
;
4328 lay
= lay
->lay_next
? lay
->lay_next
: layouts
;
4333 Msg(0, "no layout defined");
4336 if (lay
== D_layout
)
4338 LoadLayout(lay
, &D_canvas
);
4341 else if (!strcmp(args
[0], "prev"))
4343 struct layout
*lay
= D_layout
;
4346 for (lay
= layouts
; lay
->lay_next
&& lay
->lay_next
!= D_layout
; lay
= lay
->lay_next
)
4353 Msg(0, "no layout defined");
4356 if (lay
== D_layout
)
4358 LoadLayout(lay
, &D_canvas
);
4361 else if (!strcmp(args
[0], "attach"))
4366 Msg(0, "no attach layout set");
4367 else if (layout_attach
== &layout_last_marker
)
4368 Msg(0, "will attach to last layout");
4370 Msg(0, "will attach to layout %d (%s)", layout_attach
->lay_number
, layout_attach
->lay_title
);
4373 if (!strcmp(args
[1], ":last"))
4374 layout_attach
= &layout_last_marker
;
4375 else if (!args
[1][0])
4380 lay
= FindLayout(args
[1]);
4383 Msg(0, "unknown layout '%s'", args
[1]);
4386 layout_attach
= lay
;
4389 else if (!strcmp(args
[0], "show"))
4393 else if (!strcmp(args
[0], "remove"))
4395 struct layout
*lay
= display
? D_layout
: layouts
;
4398 lay
= layouts
? FindLayout(args
[1]) : (struct layout
*)0;
4401 Msg(0, "unknown layout '%s'", args
[1]);
4408 else if (!strcmp(args
[0], "dump"))
4411 Msg(0, "Must have a display for 'layout dump'.");
4412 else if (!LayoutDumpCanvas(&D_canvas
, args
[1] ? args
[1] : "layout-dump"))
4413 Msg(errno
, "Error dumping layout.");
4415 Msg(0, "Layout dumped to \"%s\"", args
[1] ? args
[1] : "layout-dump");
4418 Msg(0, "unknown layout subcommand");
4422 if(ParseSwitch(act
, &cjkwidth
) == 0)
4425 Msg(0, "Treat ambiguous width characters as %s width", cjkwidth
? "full" : "half");
4431 /* key == -2: input from braille keybord, msgok always 0 */
4432 DoBrailleAction(act
, key
== -2 ? 0 : msgok
);
4436 if (display
!= odisplay
)
4438 for (display
= displays
; display
; display
= display
->d_next
)
4439 if (display
== odisplay
)
4445 DoCommand(argv
, argl
)
4450 const char *cmd
= *argv
;
4453 if (*cmd
== '@') /* Suppress error */
4458 if (*cmd
== '-') /* Suppress normal message */
4464 if ((act
.nr
= FindCommnr(cmd
)) == RC_ILLEGAL
)
4466 Msg(0, "%s: unknown command '%s'", rc_name
, cmd
);
4469 act
.args
= argv
+ 1;
4470 act
.argl
= argl
+ 1;
4475 SaveAction(act
, nr
, args
, argl
)
4481 register int argc
= 0;
4495 if ((pp
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4497 if ((lp
= (int *)malloc((unsigned)(argc
) * sizeof(int *))) == 0)
4504 *lp
= argl
? *argl
++ : (int)strlen(*args
);
4505 *pp
++ = SaveStrn(*args
++, *lp
++);
4514 register char **ap
, **pp
;
4515 register int argc
= 0;
4519 if ((pp
= ap
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4522 *pp
++ = SaveStr(*args
++);
4529 * buf is split into argument vector args.
4530 * leading whitespace is removed.
4531 * @!| abbreviations are expanded.
4532 * the end of buffer is recognized by '\0' or an un-escaped '#'.
4533 * " and ' are interpreted.
4538 Parse(buf
, bufl
, args
, argl
)
4542 register char *p
= buf
, **ap
= args
, *pp
;
4543 register int delim
, argc
;
4546 debug2("Parse %d %s\n", bufl
, buf
);
4553 while (*p
&& (*p
== ' ' || *p
== '\t'))
4556 if (argc
== 0 && *p
== '!')
4565 if (*p
== '\0' || *p
== '#' || *p
== '\n')
4568 for (delim
= 0; delim
< argc
; delim
++)
4569 debug1("-- %s\n", args
[delim
]);
4573 if (++argc
>= MAXARGS
)
4575 Msg(0, "%s: too many tokens.", rc_name
);
4580 debug1("- new arg %s\n", p
);
4585 else if (delim
!= '\'' && *p
== '\\' && (p
[1] == 'n' || p
[1] == 'r' || p
[1] == 't' || p
[1] == '\'' || p
[1] == '"' || p
[1] == '\\' || p
[1] == '$' || p
[1] == '#' || p
[1] == '^' || (p
[1] >= '0' && p
[1] <= '7')))
4588 if (*p
>= '0' && *p
<= '7')
4591 if (p
[1] >= '0' && p
[1] <= '7')
4594 *pp
= (*pp
<< 3) | (*p
- '0');
4595 if (p
[1] >= '0' && p
[1] <= '7')
4598 *pp
= (*pp
<< 3) | (*p
- '0');
4607 case 'n': *pp
= '\n'; break;
4608 case 'r': *pp
= '\r'; break;
4609 case 't': *pp
= '\t'; break;
4610 default: *pp
= *p
; break;
4615 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] == '_'))
4618 char *ps
, *pe
, op
, *v
, xbuf
[11];
4622 debug1("- var %s\n", ps
);
4626 if (*ps
== '{' && *p
== '}')
4628 if (*ps
== ':' && *p
== ':')
4630 if (*ps
!= '{' && *ps
!= ':' && (*p
< 'a' || *p
> 'z') && (*p
< 'A' || *p
> 'Z') && (*p
< '0' || *p
> '9') && *p
!= '_')
4635 if (*ps
== '{' || *ps
== ':')
4639 Msg(0, "%s: bad variable name.", rc_name
);
4646 debug1("- var is '%s'\n", ps
);
4648 v
= gettermcapstring(ps
+ 1);
4654 if (!strcmp(ps
, "TERM"))
4655 v
= display
? D_termname
: "unknown";
4656 else if (!strcmp(ps
, "COLUMNS"))
4657 sprintf(xbuf
, "%d", display
? D_width
: -1);
4658 else if (!strcmp(ps
, "LINES"))
4659 sprintf(xbuf
, "%d", display
? D_height
: -1);
4660 else if (!strcmp(ps
, "PID"))
4661 sprintf(xbuf
, "%d", getpid());
4662 else if (!strcmp(ps
, "STY"))
4668 vl
= v
? strlen(v
) : 0;
4671 debug1("- sub is '%s'\n", v
);
4674 int right
= buf
+ bufl
- (p
+ strlen(p
) + 1);
4677 bcopy(p
, p
+ right
, strlen(p
) + 1);
4683 Msg(0, "%s: no space left for variable expansion.", rc_name
);
4691 else if (delim
!= '\'' && *p
== '^' && p
[1])
4694 *pp
++ = *p
== '?' ? '\177' : *p
& 0x1f;
4696 else if (delim
== 0 && (*p
== '\'' || *p
== '"'))
4698 else if (delim
== 0 && (*p
== ' ' || *p
== '\t' || *p
== '\n'))
4706 Msg(0, "%s: Missing %c quote.", rc_name
, delim
);
4712 debug2("- arg done, '%s' rest %s\n", ap
[-1], p
);
4713 *lp
++ = pp
- ap
[-1];
4732 if (DefaultEsc
>= 0)
4733 ClearAction(&ktab
[DefaultEsc
]);
4734 if (DefaultMetaEsc
>= 0)
4735 ClearAction(&ktab
[DefaultMetaEsc
]);
4738 DefaultMetaEsc
= me
;
4741 if (DefaultEsc
>= 0)
4743 ClearAction(&ktab
[DefaultEsc
]);
4744 ktab
[DefaultEsc
].nr
= RC_OTHER
;
4746 if (DefaultMetaEsc
>= 0)
4748 ClearAction(&ktab
[DefaultMetaEsc
]);
4749 ktab
[DefaultMetaEsc
].nr
= RC_META
;
4756 ParseSwitch(act
, var
)
4760 if (*act
->args
== 0)
4765 return ParseOnOff(act
, var
);
4769 ParseOnOff(act
, var
)
4773 register int num
= -1;
4774 char **args
= act
->args
;
4778 if (strcmp(args
[0], "on") == 0)
4780 else if (strcmp(args
[0], "off") == 0)
4785 Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name
, comms
[act
->nr
].name
);
4793 ParseSaveStr(act
, var
)
4797 char **args
= act
->args
;
4798 if (*args
== 0 || args
[1])
4800 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4805 *var
= SaveStr(*args
);
4815 char *p
, **args
= act
->args
;
4818 if (p
== 0 || *p
== 0 || args
[1])
4820 Msg(0, "%s: %s: invalid argument. Give one argument.",
4821 rc_name
, comms
[act
->nr
].name
);
4827 if (*p
>= '0' && *p
<= '9')
4828 i
= 10 * i
+ (*p
- '0');
4831 Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4832 rc_name
, comms
[act
->nr
].name
);
4837 debug1("ParseNum got %d\n", i
);
4843 ParseNum1000(act
, var
)
4848 char *p
, **args
= act
->args
;
4852 if (p
== 0 || *p
== 0 || args
[1])
4854 Msg(0, "%s: %s: invalid argument. Give one argument.",
4855 rc_name
, comms
[act
->nr
].name
);
4861 if (*p
>= '0' && *p
<= '9')
4864 i
= 10 * i
+ (*p
- '0');
4865 else if (dig
== 4 && *p
>= '5')
4870 else if (*p
== '.' && !dig
)
4874 Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4875 rc_name
, comms
[act
->nr
].name
);
4886 i
= (int)((unsigned int)~0 >> 1);
4887 debug1("ParseNum1000 got %d\n", i
);
4898 for (p
= windows
; p
; p
= p
->w_next
)
4899 if (!strcmp(p
->w_title
, s
))
4901 for (p
= windows
; p
; p
= p
->w_next
)
4902 if (!strncmp(p
->w_title
, s
, strlen(s
)))
4914 for (i
= 0, s
= str
; *s
; s
++)
4916 if (*s
< '0' || *s
> '9')
4918 i
= i
* 10 + (*s
- '0');
4924 * Get window number from Name or Number string.
4925 * Numbers are tried first, then names, a prefix match suffices.
4926 * Be careful when assigning numeric strings as WindowTitles.
4935 if ((i
= WindowByNumber(str
)) < 0 || i
>= maxwin
)
4937 if ((p
= WindowByName(str
)))
4945 ParseWinNum(act
, var
)
4949 char **args
= act
->args
;
4952 if (*args
== 0 || args
[1])
4954 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4958 i
= WindowByNoN(*args
);
4961 Msg(0, "%s: %s: invalid argument. Give window number or name.",
4962 rc_name
, comms
[act
->nr
].name
);
4965 debug1("ParseWinNum got %d\n", i
);
4971 ParseBase(act
, p
, var
, base
, bname
)
4983 Msg(0, "%s: %s: empty argument.", rc_name
, comms
[act
->nr
].name
);
4988 if (c
>= 'a' && c
<= 'z')
4990 if (c
>= 'A' && c
<= 'Z')
4991 c
-= 'A' - ('0' + 10);
4993 if (c
< 0 || c
>= base
)
4995 Msg(0, "%s: %s: argument is not %s.", rc_name
, comms
[act
->nr
].name
, bname
);
5000 debug1("ParseBase got %d\n", i
);
5010 for (base
+= '0'; *s
; ++s
)
5011 if (*s
< '0' || *s
> base
)
5017 IsNumColon(s
, base
, p
, psize
)
5022 if ((q
= rindex(s
, ':')) != 0)
5024 strncpy(p
, q
+ 1, psize
- 1);
5025 p
[psize
- 1] = '\0';
5030 return IsNum(s
, base
);
5039 debug1("SwitchWindow %d\n", n
);
5040 if (n
< 0 || n
>= maxwin
)
5045 if ((p
= wtab
[n
]) == 0)
5057 Msg(0, "This IS window %d (%s).", n
, p
->w_title
);
5061 if (AclCheckPermWin(D_user
, ACL_READ
, p
))
5063 Msg(0, "Access to window %d denied.", p
->w_number
);
5068 Activate(fore
->w_norefresh
);
5072 * SetForeWindow changes the window in the input focus of the display.
5073 * Puts window wi in canvas display->d_forecv.
5085 p
= Layer2Window(D_forecv
->c_layer
);
5086 SetCanvasWindow(D_forecv
, wi
);
5088 WindowChanged(p
, 'u');
5090 WindowChanged(wi
, 'u');
5091 flayer
= D_forecv
->c_layer
;
5092 /* Activate called afterwards, so no RefreshHStatus needed */
5096 /*****************************************************************/
5099 * Activate - make fore window active
5100 * norefresh = -1 forces a refresh, disregard all_norefresh then.
5106 debug1("Activate(%d)\n", norefresh
);
5111 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
5115 if (MayResizeLayer(D_forecv
->c_layer
))
5116 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, display
);
5122 if (fore
->w_monitor
!= MON_OFF
)
5123 fore
->w_monitor
= MON_ON
;
5124 fore
->w_bell
= BELL_ON
;
5125 WindowChanged(fore
, 'f');
5128 if (ResizeDisplay(fore
->w_width
, fore
->w_height
))
5130 debug2("Cannot resize from (%d,%d)", D_width
, D_height
);
5131 debug2(" to (%d,%d) -> resize window\n", fore
->w_width
, fore
->w_height
);
5132 DoResize(D_width
, D_height
);
5136 Redisplay(norefresh
+ all_norefresh
);
5143 register struct win
**pp
;
5144 int n
= fore
? fore
->w_number
: maxwin
;
5145 struct win
*group
= fore
? fore
->w_group
: 0;
5147 for (pp
= fore
? wtab
+ n
+ 1 : wtab
; pp
!= wtab
+ n
; pp
++)
5149 if (pp
== wtab
+ maxwin
)
5153 if (!fore
|| group
== (*pp
)->w_group
)
5165 register struct win
**pp
;
5166 int n
= fore
? fore
->w_number
: -1;
5167 struct win
*group
= fore
? fore
->w_group
: 0;
5169 for (pp
= wtab
+ n
- 1; pp
!= wtab
+ n
; pp
--)
5172 pp
= wtab
+ maxwin
- 1;
5175 if (!fore
|| group
== (*pp
)->w_group
)
5187 char *m
= "No other window.";
5188 if (windows
&& (fore
== 0 || windows
->w_next
))
5192 Msg(0, "No window available");
5195 Msg(0, m
, fore
->w_number
); /* other arg for nethack */
5203 struct win
**pp
, *p
;
5209 * Remove window from linked list.
5211 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5217 wtab
[wi
->w_number
] = 0;
5226 * switch to different window on all canvases
5228 for (display
= displays
; display
; display
= display
->d_next
)
5231 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5233 if (Layer2Window(cv
->c_layer
) != wi
)
5235 /* switch to other window */
5236 SetCanvasWindow(cv
, FindNiceWindow(D_other
, 0));
5242 if (wi
->w_zdisplay
== display
)
5245 D_readev
.condpos
= D_readev
.condneg
= 0;
5252 /* do the same for the layouts */
5253 for (lay
= layouts
; lay
; lay
= lay
->lay_next
)
5254 UpdateLayoutCanvas(&lay
->lay_canvas
, wi
);
5257 WindowChanged((struct win
*)0, 'w');
5258 WindowChanged((struct win
*)0, 'W');
5259 WindowChanged((struct win
*)0, 0);
5268 if ((fore
->w_log
!= 0) == on
)
5270 if (display
&& !*rc_name
)
5271 Msg(0, "You are %s logging.", on
? "already" : "not");
5274 if (fore
->w_log
!= 0)
5276 Msg(0, "Logfile \"%s\" closed.", fore
->w_log
->name
);
5277 logfclose(fore
->w_log
);
5279 WindowChanged(fore
, 'f');
5282 if (DoStartLog(fore
, buf
, sizeof(buf
)))
5284 Msg(errno
, "Error opening logfile \"%s\"", buf
);
5287 if (ftell(fore
->w_log
->fp
) == 0)
5288 Msg(0, "Creating logfile \"%s\".", fore
->w_log
->name
);
5290 Msg(0, "Appending to logfile \"%s\".", fore
->w_log
->name
);
5291 WindowChanged(fore
, 'f');
5295 AddWindows(buf
, len
, flags
, where
)
5301 register char *s
, *ss
;
5302 register struct win
**pp
, *p
;
5307 if ((flags
& 8) && where
< 0)
5312 for (pp
= ((flags
& 4) && where
>= 0) ? wtab
+ where
+ 1: wtab
; pp
< wtab
+ maxwin
; pp
++)
5315 if (pp
- wtab
== where
&& ss
== buf
)
5319 if ((flags
& 1) && display
&& p
== D_fore
)
5321 if (D_fore
&& D_fore
->w_group
!= p
->w_group
)
5328 if (s
- buf
+ l
> len
- 24)
5330 if (s
> buf
|| (flags
& 4))
5335 if (p
->w_number
== where
)
5341 if (!(flags
& 4) || where
< 0 || ((flags
& 4) && where
< p
->w_number
))
5343 if (p
->w_monitor
== MON_DONE
&& renditions
[REND_MONITOR
] != -1)
5344 rend
= renditions
[REND_MONITOR
];
5345 else if ((p
->w_bell
== BELL_DONE
|| p
->w_bell
== BELL_FOUND
) && renditions
[REND_BELL
] != -1)
5346 rend
= renditions
[REND_BELL
];
5349 AddWinMsgRend(s
, rend
);
5350 sprintf(s
, "%d", p
->w_number
);
5352 if (display
&& p
== D_fore
)
5356 if (display
&& p
== D_other
)
5358 s
= AddWindowFlags(s
, len
, p
);
5364 AddWinMsgRend(s
, -1);
5371 AddWindowFlags(buf
, len
, p
)
5377 if (p
== 0 || len
< 12)
5383 if (display
&& p
== D_fore
)
5385 if (display
&& p
== D_other
)
5388 if (p
->w_layer
.l_cvlist
&& p
->w_layer
.l_cvlist
->c_lnext
)
5390 if (p
->w_monitor
== MON_DONE
5392 && (ACLBYTE(p
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5396 if (p
->w_bell
== BELL_DONE
)
5399 if (p
->w_slot
!= (slot_t
) 0 && p
->w_slot
!= (slot_t
) -1)
5407 if (p
->w_ptyfd
< 0 && p
->w_type
!= W_TYPE_GROUP
)
5414 AddOtherUsers(buf
, len
, p
)
5419 struct display
*d
, *olddisplay
= display
;
5425 for (display
= displays
; display
; display
= display
->d_next
)
5427 if (olddisplay
&& D_user
== olddisplay
->d_user
)
5429 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5430 if (Layer2Window(cv
->c_layer
) == p
)
5434 for (d
= displays
; d
&& d
!= display
; d
= d
->d_next
)
5435 if (D_user
== d
->d_user
)
5437 if (d
&& d
!= display
)
5439 if (len
> 1 && s
!= buf
)
5444 l
= strlen(D_user
->u_name
);
5447 strcpy(s
, D_user
->u_name
);
5452 display
= olddisplay
;
5465 if (where
== -1 && D_fore
)
5466 where
= D_fore
->w_number
;
5467 ss
= AddWindows(buf
, sizeof(buf
), 0, where
);
5468 s
= buf
+ strlen(buf
);
5469 if (ss
- buf
> D_width
/ 2)
5472 if (s
- ss
< D_width
)
5488 register struct win
*wp
= fore
;
5493 Msg(0, "(%d,%d)/(%d,%d) no window", D_x
+ 1, D_y
+ 1, D_width
, D_height
);
5497 if (buf
< (p
+= GetAnsiStatus(wp
, p
)))
5499 sprintf(p
, "(%d,%d)/(%d,%d)",
5500 wp
->w_x
+ 1, wp
->w_y
+ 1, wp
->w_width
, wp
->w_height
);
5502 sprintf(p
+= strlen(p
), "+%d", wp
->w_histheight
);
5504 sprintf(p
+= strlen(p
), " %c%sflow",
5505 (wp
->w_flow
& FLOW_NOW
) ? '+' : '-',
5506 (wp
->w_flow
& FLOW_AUTOFLAG
) ? "" :
5507 ((wp
->w_flow
& FLOW_AUTO
) ? "(+)" : "(-)"));
5508 if (!wp
->w_wrap
) sprintf(p
+= strlen(p
), " -wrap");
5509 if (wp
->w_insert
) sprintf(p
+= strlen(p
), " ins");
5510 if (wp
->w_origin
) sprintf(p
+= strlen(p
), " org");
5511 if (wp
->w_keypad
) sprintf(p
+= strlen(p
), " app");
5512 if (wp
->w_log
) sprintf(p
+= strlen(p
), " log");
5513 if (wp
->w_monitor
!= MON_OFF
5515 && (ACLBYTE(wp
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5518 sprintf(p
+= strlen(p
), " mon");
5519 if (wp
->w_mouse
) sprintf(p
+= strlen(p
), " mouse");
5521 if (wp
->w_bce
) sprintf(p
+= strlen(p
), " bce");
5523 if (!wp
->w_c1
) sprintf(p
+= strlen(p
), " -c1");
5524 if (wp
->w_norefresh
) sprintf(p
+= strlen(p
), " nored");
5529 if (wp
->w_encoding
&& (display
== 0 || D_encoding
!= wp
->w_encoding
|| EncodingDefFont(wp
->w_encoding
) <= 0))
5532 strcpy(p
, EncodingName(wp
->w_encoding
));
5536 if (wp
->w_encoding
!= UTF8
)
5539 if (D_CC0
|| (D_CS0
&& *D_CS0
))
5543 sprintf(p
, " G%c", wp
->w_Charset
+ '0');
5544 if (wp
->w_FontE
>= ' ')
5549 p
[4] = wp
->w_FontE
^ 0x40;
5556 sprintf(p
++, " G%c%c[", wp
->w_Charset
+ '0', wp
->w_CharsetR
+ '0');
5558 sprintf(p
, " G%c[", wp
->w_Charset
+ '0');
5560 for (i
= 0; i
< 4; i
++)
5562 if (wp
->w_charsets
[i
] == ASCII
)
5564 else if (wp
->w_charsets
[i
] >= ' ')
5565 *p
++ = wp
->w_charsets
[i
];
5569 *p
++ = wp
->w_charsets
[i
] ^ 0x40;
5577 if (wp
->w_type
== W_TYPE_PLAIN
)
5579 /* add info about modem control lines */
5581 TtyGetModemStatus(wp
->w_ptyfd
, p
);
5583 #ifdef BUILTIN_TELNET
5584 else if (wp
->w_type
== W_TYPE_TELNET
)
5587 TelStatus(wp
, p
, sizeof(buf
) - 1 - (p
- buf
));
5590 Msg(0, "%s %d(%s)", buf
, wp
->w_number
, wp
->w_title
);
5600 sprintf(p
, "(%d,%d)", D_width
, D_height
),
5606 strcpy(p
, EncodingName(D_encoding
));
5612 strcpy(p
, " xterm");
5618 strcpy(p
, " color");
5625 strcpy(p
, " iso2022");
5628 else if (D_CS0
&& *D_CS0
)
5630 strcpy(p
, " altchar");
5638 AKAfin(buf
, len
, data
)
5641 char *data
; /* dummy */
5645 ChangeAKA(fore
, buf
, strlen(buf
));
5653 Input("Set window's title to: ", sizeof(fore
->w_akabuf
) - 1, INP_COOKED
, AKAfin
, NULL
, 0);
5659 if ((*(unsigned char *)s
& 0x7f) < 0x20 || *s
== 0x7f)
5663 LayProcess(&ss
, &n
);
5668 Colonfin(buf
, len
, data
)
5671 char *data
; /* dummy */
5676 if (buf
[len
] == '\t')
5679 int l
= 0, r
= RC_LAST
;
5680 int showmessage
= 0;
5683 while (*s
&& s
- buf
< len
)
5687 /* Showing a message when there's no hardstatus or caption cancels the input */
5689 (captionalways
|| D_has_hstatus
== HSTATUS_LASTLINE
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
)))
5695 x
= strncmp(buf
, comms
[m
].name
, len
);
5703 for (l
= m
- 1; l
>= 0 && strncmp(buf
, comms
[l
].name
, len
) == 0; l
--)
5705 for (m
= ++l
; m
<= r
&& strncmp(buf
, comms
[m
].name
, len
) == 0 && s
- mbuf
< sizeof(mbuf
); m
++)
5706 s
+= snprintf(s
, sizeof(mbuf
) - (s
- mbuf
), " %s", comms
[m
].name
);
5710 Msg(0, "Possible commands:%s", mbuf
);
5715 len
= snprintf(mbuf
, sizeof(mbuf
), "%s \t", comms
[l
].name
+ len
);
5716 if (len
> 0 && len
< sizeof(mbuf
))
5717 LayProcess(&s
, &len
);
5722 if (l
> r
&& showmessage
)
5723 Msg(0, "No commands matching '%*s'", len
, buf
);
5727 if (!len
|| buf
[len
])
5730 len
= strlen(buf
) + 1;
5731 if (len
> (int)sizeof(mbuf
))
5735 bcopy(buf
, mbuf
, len
);
5736 RcLine(mbuf
, sizeof mbuf
);
5741 SelectFin(buf
, len
, data
)
5744 char *data
; /* dummy */
5748 if (!len
|| !display
)
5750 if (len
== 1 && *buf
== '-')
5752 SetForeWindow((struct win
*)0);
5756 if ((n
= WindowByNoN(buf
)) < 0)
5762 SelectLayoutFin(buf
, len
, data
)
5765 char *data
; /* dummy */
5769 if (!len
|| !display
)
5771 if (len
== 1 && *buf
== '-')
5773 LoadLayout((struct layout
*)0, (struct canvas
*)0);
5777 lay
= FindLayout(buf
);
5779 Msg(0, "No such layout\n");
5780 else if (lay
== D_layout
)
5781 Msg(0, "This IS layout %d (%s).\n", lay
->lay_number
, lay
->lay_title
);
5784 LoadLayout(lay
, &D_canvas
);
5793 Input("Switch to window: ", 20, INP_COOKED
, SelectFin
, NULL
, 0);
5796 static char setenv_var
[31];
5800 SetenvFin1(buf
, len
, data
)
5803 char *data
; /* dummy */
5805 if (!len
|| !display
)
5811 SetenvFin2(buf
, len
, data
)
5814 char *data
; /* dummy */
5816 if (!len
|| !display
)
5818 debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var
, buf
);
5819 xsetenv(setenv_var
, buf
);
5827 static char setenv_buf
[50 + sizeof(setenv_var
)]; /* need to be static here, cannot be freed */
5831 strncpy(setenv_var
, arg
, sizeof(setenv_var
) - 1);
5832 sprintf(setenv_buf
, "Enter value for %s: ", setenv_var
);
5833 Input(setenv_buf
, 30, INP_COOKED
, SetenvFin2
, NULL
, 0);
5836 Input("Setenv: Enter variable name: ", 30, INP_COOKED
, SetenvFin1
, NULL
, 0);
5840 * the following options are understood by this parser:
5841 * -f, -f0, -f1, -fy, -fa
5842 * -t title, -T terminal-type, -h height-of-scrollback,
5843 * -ln, -l0, -ly, -l1, -l
5850 struct NewWindow nwin
;
5855 while (av
&& *av
&& av
[0][0] == '-')
5857 if (av
[0][1] == '-')
5869 nwin
.flowflag
= FLOW_NOW
* 0;
5874 nwin
.flowflag
= FLOW_NOW
* 1;
5877 nwin
.flowflag
= FLOW_AUTOFLAG
;
5883 case 't': /* no more -k */
5885 nwin
.aka
= &av
[0][2];
5893 nwin
.term
= &av
[0][2];
5901 nwin
.histheight
= atoi(av
[0] + 2);
5903 nwin
.histheight
= atoi(*av
);
5932 nwin
.monitor
= MON_ON
;
5938 Msg(0, "%s: screen: invalid option -%c.", fn
, av
[0][1]);
5944 if (av
&& *av
&& IsNumColon(*av
, 10, buf
, sizeof(buf
)))
5949 if (num
< 0 || num
> maxwin
- 1)
5951 Msg(0, "%s: illegal screen number %d.", fn
, num
);
5961 nwin
.aka
= Filename(*av
);
5968 * CompileKeys must be called before Markroutine is first used.
5969 * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
5971 * s is an ascii string in a termcap-like syntax. It looks like
5972 * "j=u:k=d:l=r:h=l: =.:" and so on...
5973 * this example rebinds the cursormovement to the keys u (up), d (down),
5974 * l (left), r (right). placing a mark will now be done with ".".
5977 CompileKeys(s
, sl
, array
)
5980 unsigned char *array
;
5983 unsigned char key
, value
;
5987 for (i
= 0; i
< 256; i
++)
5991 debug1("CompileKeys: '%s'\n", s
);
5994 key
= *(unsigned char *)s
++;
5995 if (*s
!= '=' || sl
< 3)
6002 value
= *(unsigned char *)s
++;
6005 while (*s
== '=' && sl
>= 2);
6014 #endif /* COPY_PASTE */
6017 * Asynchronous input functions
6020 #if defined(DETACH) && defined(POW_DETACH)
6022 pow_detach_fn(buf
, len
, data
)
6025 char *data
; /* dummy */
6027 debug("pow_detach_fn called\n");
6033 if (ktab
[(int)(unsigned char)*buf
].nr
!= RC_POW_DETACH
)
6036 write(D_userfd
, "\007", 1);
6037 Msg(0, "Detach aborted.");
6042 #endif /* POW_DETACH */
6046 copy_reg_fn(buf
, len
, data
)
6049 char *data
; /* dummy */
6051 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6062 if (D_user
->u_plop
.len
)
6064 if ((pp
->buf
= (char *)malloc(D_user
->u_plop
.len
)) == NULL
)
6069 bcopy(D_user
->u_plop
.buf
, pp
->buf
, D_user
->u_plop
.len
);
6071 pp
->len
= D_user
->u_plop
.len
;
6073 pp
->enc
= D_user
->u_plop
.enc
;
6075 Msg(0, "Copied %d characters into register %c", D_user
->u_plop
.len
, *buf
);
6079 ins_reg_fn(buf
, len
, data
)
6082 char *data
; /* dummy */
6084 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6092 return; /* Input() should not call us w/o fore, but you never know... */
6094 Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
6097 MakePaster(&fore
->w_paster
, pp
->buf
, pp
->len
, 0);
6100 Msg(0, "Empty register.");
6102 #endif /* COPY_PASTE */
6105 process_fn(buf
, len
, data
)
6108 char *data
; /* dummy */
6110 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6119 ProcessInput(pp
->buf
, pp
->len
);
6122 Msg(0, "Empty register.");
6126 confirm_fn(buf
, len
, data
)
6133 if (len
|| (*buf
!= 'y' && *buf
!= 'Y'))
6138 act
.nr
= *(int *)data
;
6148 struct acluser
**up
;
6150 char pw1
[130]; /* FreeBSD crypts to 128 bytes */
6155 su_fin(buf
, len
, data
)
6160 struct inputsu
*i
= (struct inputsu
*)data
;
6165 { p
= i
->name
; l
= sizeof(i
->name
) - 1; }
6167 { strcpy(p
= i
->pw1
, "\377"); l
= sizeof(i
->pw1
) - 1; }
6169 { strcpy(p
= i
->pw2
, "\377"); l
= sizeof(i
->pw2
) - 1; }
6171 strncpy(p
, buf
, 1 + (l
< len
) ? l
: len
);
6173 Input("Screen User: ", sizeof(i
->name
) - 1, INP_COOKED
, su_fin
, (char *)i
, 0);
6175 Input("User's UNIX Password: ", sizeof(i
->pw1
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6177 Input("User's Screen Password: ", sizeof(i
->pw2
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6180 if ((p
= DoSu(i
->up
, i
->name
, i
->pw2
, i
->pw1
)))
6187 InputSu(w
, up
, name
)
6189 struct acluser
**up
;
6194 if (!(i
= (struct inputsu
*)calloc(1, sizeof(struct inputsu
))))
6199 su_fin(name
, (int)strlen(name
), (char *)i
); /* can also initialise stuff */
6201 su_fin((char *)0, 0, (char *)i
);
6204 #endif /* MULTIUSER */
6209 pass1(buf
, len
, data
)
6214 struct acluser
*u
= (struct acluser
*)data
;
6219 if (u
->u_password
!= NullStr
)
6220 free((char *)u
->u_password
);
6221 u
->u_password
= SaveStr(buf
);
6222 bzero(buf
, strlen(buf
));
6223 Input("Retype new password:", 100, INP_NOECHO
, pass2
, data
, 0);
6227 pass2(buf
, len
, data
)
6234 struct acluser
*u
= (struct acluser
*)data
;
6237 if (!buf
|| strcmp(u
->u_password
, buf
))
6239 Msg(0, "[ Passwords don't match - checking turned off ]");
6240 if (u
->u_password
!= NullStr
)
6242 bzero(u
->u_password
, strlen(u
->u_password
));
6243 free((char *)u
->u_password
);
6245 u
->u_password
= NullStr
;
6247 else if (u
->u_password
[0] == '\0')
6249 Msg(0, "[ No password - no secure ]");
6251 bzero(buf
, strlen(buf
));
6254 if (u
->u_password
!= NullStr
)
6256 for (st
= 0; st
< 2; st
++)
6257 salt
[st
] = 'A' + (int)((time(0) >> 6 * st
) % 26);
6259 buf
= crypt(u
->u_password
, salt
);
6260 bzero(u
->u_password
, strlen(u
->u_password
));
6261 free((char *)u
->u_password
);
6262 u
->u_password
= SaveStr(buf
);
6263 bzero(buf
, strlen(buf
));
6266 UserFreeCopyBuffer(u
);
6267 u
->u_plop
.len
= strlen(u
->u_password
);
6271 if (!(u
->u_plop
.buf
= SaveStr(u
->u_password
)))
6274 D_user
->u_plop
.len
= 0;
6277 Msg(0, "[ Password moved into copybuffer ]");
6278 #else /* COPY_PASTE */
6279 Msg(0, "[ Crypted password is \"%s\" ]", u
->u_password
);
6280 #endif /* COPY_PASTE */
6283 #endif /* PASSWORD */
6290 for (i
= 0; i
< MAX_DIGRAPH
&& digraphs
[i
].d
[0]; i
++)
6291 if ((digraphs
[i
].d
[0] == (unsigned char)buf
[0] && digraphs
[i
].d
[1] == (unsigned char)buf
[1]) ||
6292 (digraphs
[i
].d
[0] == (unsigned char)buf
[1] && digraphs
[i
].d
[1] == (unsigned char)buf
[0]))
6298 digraph_fn(buf
, len
, data
)
6301 char *data
; /* dummy */
6308 buf
[len
+ 1] = ch
; /* so we can restore it later */
6309 if (ch
< ' ' || ch
== '\177')
6311 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6315 if ((ch
< '0' || ch
> '9') && (ch
< 'a' || ch
> 'f') && (ch
< 'A' || ch
> 'F'))
6317 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6320 if (len
== (*buf
== 'U' ? 5 : 3))
6324 if (len
&& *buf
== '0')
6326 if (ch
< '0' || ch
> '7')
6328 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6343 buf
[len
] = buf
[len
+ 1]; /* stored above */
6348 if (!parse_input_int(buf
, len
, &x
))
6350 i
= digraph_find(buf
);
6351 if ((x
= digraphs
[i
].value
) <= 0)
6353 Msg(0, "Unknown digraph");
6360 if (flayer
->l_encoding
== UTF8
)
6361 i
= ToUtf8(buf
, x
); /* buf is big enough for all UTF-8 codes */
6364 LayProcess(&buf
, &i
);
6375 debug1("StuffKey #%d", i
);
6378 debug1(" - %s", term
[i
+ T_CAPS
].tcname
);
6381 if (i
< KMAP_KEYS
&& D_ESCseen
)
6383 struct action
*act
= &D_ESCseen
[i
+ 256];
6384 if (act
->nr
!= RC_ILLEGAL
)
6387 DoAction(act
, i
+ 256);
6393 if (i
>= T_CURSOR
- T_CAPS
&& i
< T_KEYPAD
- T_CAPS
&& D_cursorkeys
)
6394 i
+= T_OCAPS
- T_CURSOR
;
6395 else if (i
>= T_KEYPAD
- T_CAPS
&& i
< T_OCAPS
- T_CAPS
&& D_keypad
)
6396 i
+= T_OCAPS
- T_CURSOR
;
6397 debug1(" - action %d\n", i
);
6398 flayer
= D_forecv
->c_layer
;
6402 if (flayer
&& flayer
->l_mode
== 1)
6403 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &mmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].mm
;
6405 if ((!act
|| act
->nr
== RC_ILLEGAL
) && !D_mapdefault
)
6406 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &umtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].um
;
6407 if (!act
|| act
->nr
== RC_ILLEGAL
)
6408 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &dmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].dm
;
6410 if (discard
&& (!act
|| act
->nr
!= RC_COMMAND
))
6417 if (act
== 0 || act
->nr
== RC_ILLEGAL
)
6431 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6432 if (Layer2Window(cv
->c_layer
) == wi
)
6438 FindNiceWindow(wi
, presel
)
6444 debug2("FindNiceWindow %d %s\n", wi
? wi
->w_number
: -1 , presel
? presel
: "NULL");
6447 i
= WindowByNoN(presel
);
6454 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6457 if (!wi
|| (IsOnDisplay(wi
) && !presel
))
6459 /* try to get another window */
6462 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6463 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6466 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6467 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6470 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6471 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6474 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6475 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6479 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6480 if (!wi
->w_layer
.l_cvlist
)
6483 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6484 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
))
6488 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6496 /* sorted list of all commands */
6497 static struct comm
**commtab
;
6498 static int ncommtab
;
6503 void (*hand
) __P((struct comm
*, char **, int));
6506 for (n
= 0; cos
[n
].name
; n
++)
6511 commtab
= (struct commt
*)realloc(commtab
, sizeof(*commtab
) * (ncommtab
+ n
));
6513 commtab
= (struct commt
*)malloc(sizeof(*commtab
) * (ncommtab
+ n
));
6516 for (i
= 0; i
< n
; i
++)
6518 for (j
= 0; j
< ncommtab
; j
++)
6520 r
= strcmp(cos
[i
].name
, commtab
[j
]->name
);
6522 Panic(0, "Duplicate command: %s\n", cos
[i
].name
);
6526 for (r
= ncommtab
; r
> j
; r
--)
6527 commtab
[r
] = commtab
[r
- 1];
6528 commtab
[j
] = cos
+ i
;
6529 cos
[i
].handler
= hand
;
6530 bzero(cos
[i
].userbits
, sizeof(cos
[i
].userbits
));
6539 int x
, m
, l
= 0, r
= ncommtab
- 1;
6543 x
= strcmp(str
, commtab
[m
]->name
);
6557 CalcSlicePercent(cv
, percent
)
6562 if (!cv
|| !cv
->c_slback
)
6564 up
= CalcSlicePercent(cv
->c_slback
->c_slback
, percent
);
6566 for (cv
= cv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6567 wsum
+= cv
->c_slweight
;
6570 return (up
* w
) / wsum
;
6574 ChangeCanvasSize(fcv
, abs
, diff
, gflag
, percent
)
6575 struct canvas
*fcv
; /* make this canvas bigger */
6576 int abs
; /* mode: 0:rel 1:abs 2:max */
6577 int diff
; /* change this much */
6578 int gflag
; /* go up if neccessary */
6582 int done
, have
, m
, dir
;
6584 debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs
, diff
, percent
);
6585 if (abs
== 0 && diff
== 0)
6590 fcv
->c_slweight
= 0;
6593 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6595 fcv
->c_slweight
= 1;
6596 cv
= fcv
->c_slback
->c_slback
;
6597 if (gflag
&& cv
&& cv
->c_slback
)
6598 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6606 if (percent
&& diff
> percent
)
6612 for (cv
= fcv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6613 wsum
+= cv
->c_slweight
;
6616 up
= gflag
? CalcSlicePercent(fcv
->c_slback
->c_slback
, percent
) : percent
;
6617 debug3("up=%d, wsum=%d percent=%d\n", up
, wsum
, percent
);
6620 int scale
= wsum
< 10 ? 1000 : 100;
6621 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6622 cv
->c_slweight
*= scale
;
6624 debug1("scaled wsum to %d\n", wsum
);
6626 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6630 cv
->c_slweight
= (cv
->c_slweight
* up
) / percent
;
6631 if (cv
->c_slweight
== 0)
6634 debug1(" - weight %d\n", cv
->c_slweight
);
6636 diff
= (diff
* wsum
) / percent
;
6642 if (abs
&& diff
== (fcv
->c_slorient
== SLICE_VERT
? fcv
->c_ye
- fcv
->c_ys
+ 2 : fcv
->c_xe
- fcv
->c_xs
+ 2))
6644 /* fix weights to real size (can't be helped, sorry) */
6645 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6647 cv
->c_slweight
= cv
->c_slorient
== SLICE_VERT
? cv
->c_ye
- cv
->c_ys
+ 2 : cv
->c_xe
- cv
->c_xs
+ 2;
6648 debug1(" - weight %d\n", cv
->c_slweight
);
6652 diff
= diff
- fcv
->c_slweight
;
6653 debug1("diff = %d\n", diff
);
6658 cv
= fcv
->c_slnext
? fcv
->c_slnext
: fcv
->c_slprev
;
6659 fcv
->c_slweight
+= diff
;
6660 cv
->c_slweight
-= diff
;
6665 for (cv
= fcv
->c_slnext
; diff
> 0; cv
= dir
> 0 ? cv
->c_slnext
: cv
->c_slprev
)
6669 debug1("reached end, dir is %d\n", dir
);
6679 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 : 2;
6680 debug2("min is %d, have %d\n", m
, cv
->c_slweight
);
6681 if (cv
->c_slweight
> m
)
6683 have
= cv
->c_slweight
- m
;
6686 debug1("subtract %d\n", have
);
6687 cv
->c_slweight
-= have
;
6694 /* need more room! */
6695 cv
= fcv
->c_slback
->c_slback
;
6696 if (cv
&& cv
->c_slback
)
6697 done
+= ChangeCanvasSize(fcv
->c_slback
->c_slback
, 0, diff
, gflag
, percent
);
6699 fcv
->c_slweight
+= done
;
6700 debug1("ChangeCanvasSize returns %d\n", done
);
6705 ResizeRegions(arg
, flags
)
6711 int gflag
= 0, abs
= 0, percent
= 0;
6717 if (D_forecv
->c_slorient
== SLICE_UNKN
)
6719 Msg(0, "resize: need more than one region");
6722 gflag
= flags
& RESIZE_FLAG_L
? 0 : 1;
6723 orient
|= flags
& RESIZE_FLAG_H
? SLICE_HORI
: 0;
6724 orient
|= flags
& RESIZE_FLAG_V
? SLICE_VERT
: 0;
6726 orient
= D_forecv
->c_slorient
;
6730 /* make all regions the same height */
6731 struct canvas
*cv
= gflag
? &D_canvas
: D_forecv
->c_slback
;
6732 if (cv
->c_slperp
->c_slorient
& orient
)
6733 EqualizeCanvas(cv
->c_slperp
, gflag
);
6734 /* can't use cv->c_slorient directly as it can be D_canvas */
6735 if ((cv
->c_slperp
->c_slorient
^ (SLICE_HORI
^ SLICE_VERT
)) & orient
)
6740 EqualizeCanvas(cv
->c_slperp
, gflag
);
6743 EqualizeCanvas(cv
, gflag
);
6746 RecreateCanvasChain();
6747 RethinkDisplayViewports();
6748 ResizeLayersToCanvases();
6751 if (!strcmp(arg
, "min") || !strcmp(arg
, "0"))
6756 else if (!strcmp(arg
, "max") || !strcmp(arg
, "_"))
6763 if (l
> 0 && arg
[l
- 1] == '%')
6766 diff
= atoi(arg
+ 1);
6767 else if (*arg
== '-')
6768 diff
= -atoi(arg
+ 1);
6771 diff
= atoi(arg
); /* +1 because of caption line */
6774 abs
= diff
== 0 ? 2 : 1;
6780 diff
= diff
* percent
/ 100;
6782 if (cv
->c_slorient
& orient
)
6783 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6784 if (cv
->c_slback
->c_slorient
& orient
)
6785 ChangeCanvasSize(cv
->c_slback
, abs
, diff
, gflag
, percent
);
6787 ResizeCanvas(&D_canvas
);
6788 RecreateCanvasChain();
6789 RethinkDisplayViewports();
6790 ResizeLayersToCanvases();
6797 if (siz
+ diff
> dsize
- (nreg
- 1) * 2 - 1)
6798 diff
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6799 if (diff
== 0 || siz
+ diff
< 1)
6804 if (D_forecv
->c_next
)
6806 D_forecv
->c_ye
+= diff
;
6807 D_forecv
->c_next
->c_ys
+= diff
;
6808 D_forecv
->c_next
->c_yoff
+= diff
;
6812 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6813 if (cv
->c_next
== D_forecv
)
6817 D_forecv
->c_ys
-= diff
;
6818 D_forecv
->c_yoff
-= diff
;
6823 int s
, i
= 0, found
= 0, di
= diff
, d2
;
6824 s
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6825 for (cv
= D_cvlist
; cv
; i
= cv
->c_ye
+ 2, cv
= cv
->c_next
)
6829 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) + diff
;
6830 cv
->c_yoff
-= cv
->c_ys
- i
;
6835 s
-= cv
->c_ye
- cv
->c_ys
;
6843 d2
= di
> cv
->c_ye
- cv
->c_ys
? cv
->c_ye
- cv
->c_ys
: di
;
6845 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) - d2
;
6846 cv
->c_yoff
-= cv
->c_ys
- i
;
6850 RethinkDisplayViewports();
6851 ResizeLayersToCanvases();
6856 ResizeFin(buf
, len
, data
)
6862 int flags
= *(int *)data
;
6863 ch
= ((unsigned char *)buf
)[len
];
6866 ResizeRegions(buf
, flags
);
6870 flags
^= RESIZE_FLAG_H
;
6872 flags
^= RESIZE_FLAG_V
;
6874 flags
|= RESIZE_FLAG_H
|RESIZE_FLAG_V
;
6876 flags
^= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
6878 flags
^= RESIZE_FLAG_L
;
6881 inp_setprompt(resizeprompts
[flags
], NULL
);
6882 *(int *)data
= flags
;
6887 SetForeCanvas(d
, cv
)
6891 struct display
*odisplay
= display
;
6892 if (d
->d_forecv
== cv
)
6897 if ((focusminwidth
&& (focusminwidth
< 0 || D_forecv
->c_xe
- D_forecv
->c_xs
+ 1 < focusminwidth
)) ||
6898 (focusminheight
&& (focusminheight
< 0 || D_forecv
->c_ye
- D_forecv
->c_ys
+ 1 < focusminheight
)))
6900 ResizeCanvas(&D_canvas
);
6901 RecreateCanvasChain();
6902 RethinkDisplayViewports();
6903 ResizeLayersToCanvases(); /* redisplays */
6905 fore
= D_fore
= Layer2Window(D_forecv
->c_layer
);
6906 if (D_other
== fore
)
6908 flayer
= D_forecv
->c_layer
;
6910 if (D_xtermosc
[2] || D_xtermosc
[3])
6921 flayer
= D_forecv
->c_layer
;
6922 CV_CALL(D_forecv
, LayRestore();LaySetCursor());
6923 WindowChanged(0, 'F');
6936 p
= Layer2Window(D_forecv
->c_layer
);
6937 for (i
= 3; i
>=0; i
--)
6938 SetXtermOSC(i
, p
? p
->w_xtermosc
[i
] : 0);
6943 ParseAttrColor(s1
, s2
, msgok
)
6955 while (*ss
&& *ss
!= ' ')
6959 if (*s
&& (s2
|| *ss
|| !((*s
>= 'a' && *s
<= 'z') || (*s
>= 'A' && *s
<= 'Z') || *s
== '.')))
6961 int mode
= 0, n
= 0;
6979 if (*s
>= '0' && *s
<= '9')
6982 if (*s
>= '0' && *s
<= '9')
6983 n
= n
* 16 + (*s
++ - '0');
6984 else if (*s
>= 'a' && *s
<= 'f')
6985 n
= n
* 16 + (*s
++ - ('a' - 10));
6986 else if (*s
>= 'A' && *s
<= 'F')
6987 n
= n
* 16 + (*s
++ - ('A' - 10));
6988 else if (*s
&& *s
!= ' ')
6991 Msg(0, "Illegal attribute hexchar '%c'", *s
);
6997 while (*s
&& *s
!= ' ')
7014 Msg(0, "Illegal attribute specifier '%c'", *s
);
7020 if (*s
&& *s
!= ' ')
7023 Msg(0, "junk after attribute description: '%c'", *s
);
7035 while (*s
&& *s
== ' ')
7043 Msg(0, "junk after description: '%c'", *s
);
7047 while (*s
&& *s
== ' ')
7054 static char costr
[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
7064 for (j
= 0; j
< 2 && *s
&& *s
!= ' '; j
++)
7066 for (i
= 0; costr
[i
]; i
++)
7072 Msg(0, "illegal color descriptor: '%c'", *s
);
7076 n
= n
<< 4 | (i
& 15);
7079 n
= (n
& 0x20ff) | 0x200;
7083 if ((n
& 0xf00) == 0xf00)
7084 n
^= 0xf00; /* clear superflous bits */
7087 n
^= 0x2400; /* shift bit into right position */
7090 n
|= 0xf0; /* don't change bg color */
7091 if (numco
!= 2 && n
!= 0xff)
7092 n
|= 0x100; /* special invert mode */
7093 if (*s
&& *s
!= ' ')
7096 Msg(0, "junk after color description: '%c'", *s
);
7104 while (*s
&& *s
== ' ')
7109 Msg(0, "junk after description: '%c'", *s
);
7112 debug1("ParseAttrColor %06x\n", r
);
7120 * e just set intensity
7121 * f don't change anything
7122 * Intensity is encoded into bits 17(fg) and 18(bg).
7125 ApplyAttrColor(i
, mc
)
7129 debug1("ApplyAttrColor %06x\n", i
);
7130 mc
->attr
|= i
>> 8 & 255;
7131 mc
->attr
^= i
& 255;
7133 i
= (i
>> 16) ^ 0xff;
7134 if ((i
& 0x100) != 0)
7137 if (mc
->attr
& (A_SO
|A_RV
))
7139 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4) | ((i
& 0x200) << 1) | ((i
& 0x400) >> 1);
7141 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4);
7145 if ((i
& 0x0f) != 0x0f)
7146 mc
->attr
= (mc
->attr
& 0xbf) | ((i
>> 3) & 0x40);
7147 if ((i
& 0xf0) != 0xf0)
7148 mc
->attr
= (mc
->attr
& 0x7f) | ((i
>> 3) & 0x80);
7150 mc
->color
= 0x99 ^ mc
->color
;
7151 if ((i
& 0x0e) == 0x0e)
7152 i
= (i
& 0xf0) | (mc
->color
& 0x0f);
7153 if ((i
& 0xe0) == 0xe0)
7154 i
= (i
& 0x0f) | (mc
->color
& 0xf0);
7155 mc
->color
= 0x99 ^ i
;
7156 debug2("ApplyAttrColor - %02x %02x\n", mc
->attr
, i
);