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 ****************************************************************
29 #include <sys/types.h>
33 #if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
38 #include <sys/ioctl.h>
44 /* for solaris 2.1, Unixware (SVR4.2) and possibly others: */
46 # include <sys/stropts.h>
53 extern struct comm comms
[];
55 extern char *RcFileName
, *home
;
56 extern char *BellString
, *ActivityString
, *ShellProg
, *ShellArgs
[];
57 extern char *hstatusstring
, *captionstring
, *timestring
;
58 extern char *wliststr
, *wlisttit
;
59 extern int captionalways
;
60 extern char *hardcopydir
, *screenlogfile
, *logtstamp_string
;
61 extern int log_flush
, logtstamp_on
, logtstamp_after
;
62 extern char *VisualBellString
;
63 extern int VBellWait
, MsgWait
, MsgMinWait
, SilenceWait
;
64 extern char SockPath
[], *SockName
;
65 extern int TtyMode
, auto_detach
, use_altscreen
;
66 extern int iflag
, maxwin
;
67 extern int focusminwidth
, focusminheight
;
68 extern int use_hardstatus
, visual_bell
;
70 extern int attr2color
[][4];
71 extern int nattr2color
;
73 extern int hardstatusemu
;
74 extern char *printcmd
;
75 extern int default_startup
;
76 extern int defobuflimit
;
77 extern int defnonblock
;
78 extern int defmousetrack
;
79 extern int ZombieKey_destroy
;
80 extern int ZombieKey_resurrect
;
81 extern int ZombieKey_onerror
;
83 extern int defautonuke
;
85 extern int separate_sids
;
86 extern struct NewWindow nwin_default
, nwin_undef
;
88 extern int join_with_cr
;
89 extern int compacthist
;
94 extern unsigned char mark_key_tab
[];
95 extern char *BufferFile
;
98 extern char *BufferFile
, *PowDetachString
;
101 extern struct acluser
*EffectiveAclUser
; /* acl.c */
103 extern struct term term
[]; /* terminal capabilities */
105 extern char *kmapdef
[];
106 extern char *kmapadef
[];
107 extern char *kmapmdef
[];
109 extern struct mchar mchar_so
, mchar_null
;
110 extern int renditions
[];
111 extern int VerboseCreate
;
113 extern char *screenencodings
;
119 static int CheckArgNum
__P((int, char **));
120 static void ClearAction
__P((struct action
*));
121 static void SaveAction
__P((struct action
*, int, char **, int *));
122 static int NextWindow
__P((void));
123 static int PreviousWindow
__P((void));
124 static int MoreWindows
__P((void));
125 static void LogToggle
__P((int));
126 static void ShowInfo
__P((void));
127 static void ShowDInfo
__P((void));
128 static struct win
*WindowByName
__P((char *));
129 static int WindowByNumber
__P((char *));
130 static int ParseOnOff
__P((struct action
*, int *));
131 static int ParseWinNum
__P((struct action
*, int *));
132 static int ParseBase
__P((struct action
*, char *, int *, int, char *));
133 static int ParseNum1000
__P((struct action
*, int *));
134 static char **SaveArgs
__P((char **));
135 static int IsNum
__P((char *, int));
136 static void Colonfin
__P((char *, int, char *));
137 static void InputSelect
__P((void));
138 static void InputSetenv
__P((char *));
139 static void InputAKA
__P((void));
141 static int InputSu
__P((struct win
*, struct acluser
**, char *));
142 static void su_fin
__P((char *, int, char *));
144 static void AKAfin
__P((char *, int, char *));
146 static void copy_reg_fn
__P((char *, int, char *));
147 static void ins_reg_fn
__P((char *, int, char *));
149 static void process_fn
__P((char *, int, char *));
151 static void pass1
__P((char *, int, char *));
152 static void pass2
__P((char *, int, char *));
155 static void pow_detach_fn
__P((char *, int, char *));
157 static void digraph_fn
__P((char *, int, char *));
158 static int digraph_find
__P((const char *buf
));
159 static void confirm_fn
__P((char *, int, char *));
160 static int IsOnDisplay
__P((struct win
*));
161 static void ResizeRegions
__P((char *, int));
162 static void ResizeFin
__P((char *, int, char *));
163 static struct action
*FindKtab
__P((char *, int));
164 static void SelectFin
__P((char *, int, char *));
165 static void SelectLayoutFin
__P((char *, int, char *));
168 extern struct layer
*flayer
;
169 extern struct display
*display
, *displays
;
170 extern struct win
*fore
, *console_window
, *windows
;
171 extern struct acluser
*users
;
172 extern struct layout
*layouts
, *layout_attach
, layout_last_marker
;
173 extern struct layout
*laytab
[];
175 extern char screenterm
[], HostName
[], version
[];
176 extern struct NewWindow nwin_undef
, nwin_default
;
177 extern struct LayFuncs WinLf
, MarkLf
;
179 extern int Z0width
, Z1width
;
180 extern int real_uid
, real_gid
;
183 extern int nethackflag
;
187 struct win
*wtab
[MAXWIN
]; /* window table, should be dynamic */
191 extern int maxusercount
;
195 struct plop plop_tab
[MAX_PLOP_DEFS
];
198 # define PTYMODE 0622
201 int TtyMode
= PTYMODE
;
202 int hardcopy_append
= 0;
203 int all_norefresh
= 0;
206 char *zmodem_sendcmd
;
207 char *zmodem_recvcmd
;
208 static char *zmodes
[4] = {"off", "auto", "catch", "pass"};
212 struct action idleaction
;
217 struct action ktab
[256 + KMAP_KEYS
]; /* command key translation table */
221 struct action ktab
[256 + KMAP_KEYS
];
223 struct kclass
*kclasses
;
226 struct action umtab
[KMAP_KEYS
+KMAP_AKEYS
];
227 struct action dmtab
[KMAP_KEYS
+KMAP_AKEYS
];
228 struct action mmtab
[KMAP_KEYS
+KMAP_AKEYS
];
229 struct kmap_ext
*kmap_exts
;
231 static int maptimeout
= 300;
235 #define MAX_DIGRAPH 512
244 /* digraph table taken from old vim and rfc1345 */
245 static struct digraph digraphs
[MAX_DIGRAPH
+ 1] = {
246 {' ', ' ', 160}, /* */
247 {'N', 'S', 160}, /* */
248 {'~', '!', 161}, /* ¡ */
249 {'!', '!', 161}, /* ¡ */
250 {'!', 'I', 161}, /* ¡ */
251 {'c', '|', 162}, /* ¢ */
252 {'c', 't', 162}, /* ¢ */
253 {'$', '$', 163}, /* £ */
254 {'P', 'd', 163}, /* £ */
255 {'o', 'x', 164}, /* ¤ */
256 {'C', 'u', 164}, /* ¤ */
257 {'C', 'u', 164}, /* ¤ */
258 {'E', 'u', 164}, /* ¤ */
259 {'Y', '-', 165}, /* ¥ */
260 {'Y', 'e', 165}, /* ¥ */
261 {'|', '|', 166}, /* ¦ */
262 {'B', 'B', 166}, /* ¦ */
263 {'p', 'a', 167}, /* § */
264 {'S', 'E', 167}, /* § */
265 {'"', '"', 168}, /* ¨ */
266 {'\'', ':', 168}, /* ¨ */
267 {'c', 'O', 169}, /* © */
268 {'C', 'o', 169}, /* © */
269 {'a', '-', 170}, /* ª */
270 {'<', '<', 171}, /* « */
271 {'-', ',', 172}, /* ¬ */
272 {'N', 'O', 172}, /* ¬ */
273 {'-', '-', 173}, /* */
274 {'r', 'O', 174}, /* ® */
275 {'R', 'g', 174}, /* ® */
276 {'-', '=', 175}, /* ¯ */
277 {'\'', 'm', 175}, /* ¯ */
278 {'~', 'o', 176}, /* ° */
279 {'D', 'G', 176}, /* ° */
280 {'+', '-', 177}, /* ± */
281 {'2', '2', 178}, /* ² */
282 {'2', 'S', 178}, /* ² */
283 {'3', '3', 179}, /* ³ */
284 {'3', 'S', 179}, /* ³ */
285 {'\'', '\'', 180}, /* ´ */
286 {'j', 'u', 181}, /* µ */
287 {'M', 'y', 181}, /* µ */
288 {'p', 'p', 182}, /* ¶ */
289 {'P', 'I', 182}, /* ¶ */
290 {'~', '.', 183}, /* · */
291 {'.', 'M', 183}, /* · */
292 {',', ',', 184}, /* ¸ */
293 {'\'', ',', 184}, /* ¸ */
294 {'1', '1', 185}, /* ¹ */
295 {'1', 'S', 185}, /* ¹ */
296 {'o', '-', 186}, /* º */
297 {'>', '>', 187}, /* » */
298 {'1', '4', 188}, /* ¼ */
299 {'1', '2', 189}, /* ½ */
300 {'3', '4', 190}, /* ¾ */
301 {'~', '?', 191}, /* ¿ */
302 {'?', '?', 191}, /* ¿ */
303 {'?', 'I', 191}, /* ¿ */
304 {'A', '`', 192}, /* À */
305 {'A', '!', 192}, /* À */
306 {'A', '\'', 193}, /* Á */
307 {'A', '^', 194}, /* Â */
308 {'A', '>', 194}, /* Â */
309 {'A', '~', 195}, /* Ã */
310 {'A', '?', 195}, /* Ã */
311 {'A', '"', 196}, /* Ä */
312 {'A', ':', 196}, /* Ä */
313 {'A', '@', 197}, /* Å */
314 {'A', 'A', 197}, /* Å */
315 {'A', 'E', 198}, /* Æ */
316 {'C', ',', 199}, /* Ç */
317 {'E', '`', 200}, /* È */
318 {'E', '!', 200}, /* È */
319 {'E', '\'', 201}, /* É */
320 {'E', '^', 202}, /* Ê */
321 {'E', '>', 202}, /* Ê */
322 {'E', '"', 203}, /* Ë */
323 {'E', ':', 203}, /* Ë */
324 {'I', '`', 204}, /* Ì */
325 {'I', '!', 204}, /* Ì */
326 {'I', '\'', 205}, /* Í */
327 {'I', '^', 206}, /* Î */
328 {'I', '>', 206}, /* Î */
329 {'I', '"', 207}, /* Ï */
330 {'I', ':', 207}, /* Ï */
331 {'D', '-', 208}, /* Ð */
332 {'N', '~', 209}, /* Ñ */
333 {'N', '?', 209}, /* Ñ */
334 {'O', '`', 210}, /* Ò */
335 {'O', '!', 210}, /* Ò */
336 {'O', '\'', 211}, /* Ó */
337 {'O', '^', 212}, /* Ô */
338 {'O', '>', 212}, /* Ô */
339 {'O', '~', 213}, /* Õ */
340 {'O', '?', 213}, /* Õ */
341 {'O', '"', 214}, /* Ö */
342 {'O', ':', 214}, /* Ö */
343 {'/', '\\', 215}, /* × */
344 {'*', 'x', 215}, /* × */
345 {'O', '/', 216}, /* Ø */
346 {'U', '`', 217}, /* Ù */
347 {'U', '!', 217}, /* Ù */
348 {'U', '\'', 218}, /* Ú */
349 {'U', '^', 219}, /* Û */
350 {'U', '>', 219}, /* Û */
351 {'U', '"', 220}, /* Ü */
352 {'U', ':', 220}, /* Ü */
353 {'Y', '\'', 221}, /* Ý */
354 {'I', 'p', 222}, /* Þ */
355 {'T', 'H', 222}, /* Þ */
356 {'s', 's', 223}, /* ß */
357 {'s', '"', 223}, /* ß */
358 {'a', '`', 224}, /* à */
359 {'a', '!', 224}, /* à */
360 {'a', '\'', 225}, /* á */
361 {'a', '^', 226}, /* â */
362 {'a', '>', 226}, /* â */
363 {'a', '~', 227}, /* ã */
364 {'a', '?', 227}, /* ã */
365 {'a', '"', 228}, /* ä */
366 {'a', ':', 228}, /* ä */
367 {'a', 'a', 229}, /* å */
368 {'a', 'e', 230}, /* æ */
369 {'c', ',', 231}, /* ç */
370 {'e', '`', 232}, /* è */
371 {'e', '!', 232}, /* è */
372 {'e', '\'', 233}, /* é */
373 {'e', '^', 234}, /* ê */
374 {'e', '>', 234}, /* ê */
375 {'e', '"', 235}, /* ë */
376 {'e', ':', 235}, /* ë */
377 {'i', '`', 236}, /* ì */
378 {'i', '!', 236}, /* ì */
379 {'i', '\'', 237}, /* í */
380 {'i', '^', 238}, /* î */
381 {'i', '>', 238}, /* î */
382 {'i', '"', 239}, /* ï */
383 {'i', ':', 239}, /* ï */
384 {'d', '-', 240}, /* ð */
385 {'n', '~', 241}, /* ñ */
386 {'n', '?', 241}, /* ñ */
387 {'o', '`', 242}, /* ò */
388 {'o', '!', 242}, /* ò */
389 {'o', '\'', 243}, /* ó */
390 {'o', '^', 244}, /* ô */
391 {'o', '>', 244}, /* ô */
392 {'o', '~', 245}, /* õ */
393 {'o', '?', 245}, /* õ */
394 {'o', '"', 246}, /* ö */
395 {'o', ':', 246}, /* ö */
396 {':', '-', 247}, /* ÷ */
397 {'o', '/', 248}, /* ø */
398 {'u', '`', 249}, /* ù */
399 {'u', '!', 249}, /* ù */
400 {'u', '\'', 250}, /* ú */
401 {'u', '^', 251}, /* û */
402 {'u', '>', 251}, /* û */
403 {'u', '"', 252}, /* ü */
404 {'u', ':', 252}, /* ü */
405 {'y', '\'', 253}, /* ý */
406 {'i', 'p', 254}, /* þ */
407 {'t', 'h', 254}, /* þ */
408 {'y', '"', 255}, /* ÿ */
409 {'y', ':', 255}, /* ÿ */
410 {'"', '[', 196}, /* Ä */
411 {'"', '\\', 214}, /* Ö */
412 {'"', ']', 220}, /* Ü */
413 {'"', '{', 228}, /* ä */
414 {'"', '|', 246}, /* ö */
415 {'"', '}', 252}, /* ü */
416 {'"', '~', 223} /* ß */
419 #define RESIZE_FLAG_H 1
420 #define RESIZE_FLAG_V 2
421 #define RESIZE_FLAG_L 4
423 static char *resizeprompts
[] = {
425 "resize -h # lines: ",
426 "resize -v # lines: ",
427 "resize -b # lines: ",
428 "resize -l # lines: ",
429 "resize -l -h # lines: ",
430 "resize -l -v # lines: ",
431 "resize -l -b # lines: ",
435 parse_input_int(buf
, len
, val
)
441 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
444 for (i
= 2; i
< len
; i
++)
446 if (buf
[i
] >= '0' && buf
[i
] <= '9')
447 x
= x
* 16 | (buf
[i
] - '0');
448 else if (buf
[i
] >= 'a' && buf
[i
] <= 'f')
449 x
= x
* 16 | (buf
[i
] - ('a' - 10));
450 else if (buf
[i
] >= 'A' && buf
[i
] <= 'F')
451 x
= x
* 16 | (buf
[i
] - ('A' - 10));
456 else if (buf
[0] == '0')
459 for (i
= 1; i
< len
; i
++)
461 if (buf
[i
] < '0' || buf
[i
] > '7')
463 x
= x
* 8 | (buf
[i
] - '0');
477 register unsigned int i
;
482 for (i
= 0; i
< sizeof(ktab
)/sizeof(*ktab
); i
++)
484 ktab
[i
].nr
= RC_ILLEGAL
;
485 ktab
[i
].args
= noargs
;
489 for (i
= 0; i
< KMAP_KEYS
+KMAP_AKEYS
; i
++)
491 umtab
[i
].nr
= RC_ILLEGAL
;
492 umtab
[i
].args
= noargs
;
494 dmtab
[i
].nr
= RC_ILLEGAL
;
495 dmtab
[i
].args
= noargs
;
497 mmtab
[i
].nr
= RC_ILLEGAL
;
498 mmtab
[i
].args
= noargs
;
502 for (i
= 0; i
< NKMAPDEF
; i
++)
504 if (i
+ KMAPDEFSTART
< T_CAPS
)
506 if (i
+ KMAPDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
510 argarr
[0] = kmapdef
[i
];
511 SaveAction(dmtab
+ i
+ (KMAPDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
513 for (i
= 0; i
< NKMAPADEF
; i
++)
515 if (i
+ KMAPADEFSTART
< T_CURSOR
)
517 if (i
+ KMAPADEFSTART
>= T_CURSOR
+ KMAP_AKEYS
)
519 if (kmapadef
[i
] == 0)
521 argarr
[0] = kmapadef
[i
];
522 SaveAction(dmtab
+ i
+ (KMAPADEFSTART
- T_CURSOR
+ KMAP_KEYS
), RC_STUFF
, argarr
, 0);
524 for (i
= 0; i
< NKMAPMDEF
; i
++)
526 if (i
+ KMAPMDEFSTART
< T_CAPS
)
528 if (i
+ KMAPMDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
530 if (kmapmdef
[i
] == 0)
532 argarr
[0] = kmapmdef
[i
];
534 SaveAction(mmtab
+ i
+ (KMAPMDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
538 ktab
['h'].nr
= RC_HARDCOPY
;
540 ktab
['z'].nr
= ktab
[Ctrl('z')].nr
= RC_SUSPEND
;
542 ktab
['c'].nr
= ktab
[Ctrl('c')].nr
= RC_SCREEN
;
543 ktab
[' '].nr
= ktab
[Ctrl(' ')].nr
=
544 ktab
['n'].nr
= ktab
[Ctrl('n')].nr
= RC_NEXT
;
545 ktab
['N'].nr
= RC_NUMBER
;
546 ktab
[Ctrl('h')].nr
= ktab
[0177].nr
= ktab
['p'].nr
= ktab
[Ctrl('p')].nr
= RC_PREV
;
547 ktab
['k'].nr
= ktab
[Ctrl('k')].nr
= RC_KILL
;
548 ktab
['l'].nr
= ktab
[Ctrl('l')].nr
= RC_REDISPLAY
;
549 ktab
['w'].nr
= ktab
[Ctrl('w')].nr
= RC_WINDOWS
;
550 ktab
['v'].nr
= RC_VERSION
;
551 ktab
[Ctrl('v')].nr
= RC_DIGRAPH
;
552 ktab
['q'].nr
= ktab
[Ctrl('q')].nr
= RC_XON
;
553 ktab
['s'].nr
= ktab
[Ctrl('s')].nr
= RC_XOFF
;
554 ktab
['t'].nr
= ktab
[Ctrl('t')].nr
= RC_TIME
;
555 ktab
['i'].nr
= ktab
[Ctrl('i')].nr
= RC_INFO
;
556 ktab
['m'].nr
= ktab
[Ctrl('m')].nr
= RC_LASTMSG
;
557 ktab
['A'].nr
= RC_TITLE
;
558 #if defined(UTMPOK) && defined(LOGOUTOK)
559 ktab
['L'].nr
= RC_LOGIN
;
561 ktab
[','].nr
= RC_LICENSE
;
562 ktab
['W'].nr
= RC_WIDTH
;
563 ktab
['.'].nr
= RC_DUMPTERMCAP
;
564 ktab
[Ctrl('\\')].nr
= RC_QUIT
;
566 ktab
['d'].nr
= ktab
[Ctrl('d')].nr
= RC_DETACH
;
568 ktab
['D'].nr
= RC_POW_DETACH
;
571 ktab
['r'].nr
= ktab
[Ctrl('r')].nr
= RC_WRAP
;
572 ktab
['f'].nr
= ktab
[Ctrl('f')].nr
= RC_FLOW
;
573 ktab
['C'].nr
= RC_CLEAR
;
574 ktab
['Z'].nr
= RC_RESET
;
575 ktab
['H'].nr
= RC_LOG
;
576 ktab
['M'].nr
= RC_MONITOR
;
577 ktab
['?'].nr
= RC_HELP
;
579 ktab
['*'].nr
= RC_DISPLAYS
;
585 SaveAction(ktab
+ '-', RC_SELECT
, args
, 0);
587 for (i
= 0; i
< ((MAXWIN
< 10) ? MAXWIN
: 10); i
++)
589 char *args
[2], arg1
[10];
592 sprintf(arg1
, "%d", i
);
593 SaveAction(ktab
+ '0' + i
, RC_SELECT
, args
, 0);
595 ktab
['\''].nr
= RC_SELECT
; /* calling a window by name */
600 SaveAction(ktab
+ '"', RC_WINDOWLIST
, args
, 0);
602 ktab
[Ctrl('G')].nr
= RC_VBELL
;
603 ktab
[':'].nr
= RC_COLON
;
605 ktab
['['].nr
= ktab
[Ctrl('[')].nr
= RC_COPY
;
610 SaveAction(ktab
+ ']', RC_PASTE
, args
, 0);
611 SaveAction(ktab
+ Ctrl(']'), RC_PASTE
, args
, 0);
613 ktab
['{'].nr
= RC_HISTORY
;
614 ktab
['}'].nr
= RC_HISTORY
;
615 ktab
['>'].nr
= RC_WRITEBUF
;
616 ktab
['<'].nr
= RC_READBUF
;
617 ktab
['='].nr
= RC_REMOVEBUF
;
620 ktab
['D'].nr
= RC_POW_DETACH
;
623 ktab
['x'].nr
= ktab
[Ctrl('x')].nr
= RC_LOCKSCREEN
;
625 ktab
['b'].nr
= ktab
[Ctrl('b')].nr
= RC_BREAK
;
626 ktab
['B'].nr
= RC_POW_BREAK
;
627 ktab
['_'].nr
= RC_SILENCE
;
628 ktab
['S'].nr
= RC_SPLIT
;
629 ktab
['Q'].nr
= RC_ONLY
;
630 ktab
['X'].nr
= RC_REMOVE
;
631 ktab
['F'].nr
= RC_FIT
;
632 ktab
['\t'].nr
= RC_FOCUS
;
637 SaveAction(ktab
+ T_BACKTAB
- T_CAPS
+ 256, RC_FOCUS
, args
, 0);
643 SaveAction(ktab
+ '|', RC_SPLIT
, args
, 0);
645 /* These come last; they may want overwrite others: */
648 ClearAction(&ktab
[DefaultEsc
]);
649 ktab
[DefaultEsc
].nr
= RC_OTHER
;
651 if (DefaultMetaEsc
>= 0)
653 ClearAction(&ktab
[DefaultMetaEsc
]);
654 ktab
[DefaultMetaEsc
].nr
= RC_META
;
657 idleaction
.nr
= RC_BLANKER
;
658 idleaction
.args
= noargs
;
662 static struct action
*
663 FindKtab(class, create
)
667 struct kclass
*kp
, **kpp
;
672 for (kpp
= &kclasses
; (kp
= *kpp
) != 0; kpp
= &kp
->next
)
673 if (!strcmp(kp
->name
, class))
679 if (strlen(class) > 80)
681 Msg(0, "Command class name too long.");
684 kp
= malloc(sizeof(*kp
));
690 kp
->name
= SaveStr(class);
691 for (i
= 0; i
< (int)(sizeof(kp
->ktab
)/sizeof(*kp
->ktab
)); i
++)
693 kp
->ktab
[i
].nr
= RC_ILLEGAL
;
694 kp
->ktab
[i
].args
= noargs
;
695 kp
->ktab
[i
].argl
= 0;
709 if (act
->nr
== RC_ILLEGAL
)
711 act
->nr
= RC_ILLEGAL
;
712 if (act
->args
== noargs
)
714 for (p
= act
->args
; *p
; p
++)
716 free((char *)act
->args
);
722 * ProcessInput: process input from display and feed it into
723 * the layer on canvas D_forecv.
729 * This ProcessInput just does the keybindings and passes
730 * everything else on to ProcessInput2.
734 ProcessInput(ibuf
, ilen
)
739 unsigned char *s
, *q
;
743 debug1("ProcessInput: %d bytes\n", ilen
);
744 if (display
== 0 || ilen
== 0)
749 s
= (unsigned char *)ibuf
;
753 if (D_dontmap
|| !D_nseqs
)
760 debug3("cmp %c %c[%d]\n", ch
, *D_seqp
, D_seqp
- D_kmaps
);
763 l
= D_seqp
[D_seqp
[-D_seql
-1] + 1];
767 debug1("miss %d\n", D_seqp
- D_kmaps
);
770 debug("complete miss\n");
773 p
= (char *)D_seqp
- l
;
775 D_seqp
= D_kmaps
+ 3;
778 if ((q
= D_seqh
) != 0)
781 i
= q
[0] << 8 | q
[1];
782 i
&= ~KMAP_NOTIMEOUT
;
783 debug1("Mapping former hit #%d - ", i
);
784 debug2("%d(%s) - ", q
[2], q
+ 3);
786 ProcessInput2((char *)q
+ 3, q
[2]);
794 debug1("flush old %d\n", l
);
803 /* Finish old stuff */
805 debug1("finish old %d\n", slen
);
807 ProcessInput2(ibuf
, slen
);
816 debug2("length am %d, want %d\n", l
, D_seqp
[-l
- 1]);
817 if (l
== D_seqp
[-l
- 1])
822 if (D_kmaps
+ D_nseqs
> q
&& q
[2] > l
&& !bcmp(D_seqp
- l
, q
+ 3, l
))
824 debug1("have another mapping (%s), delay execution\n", q
+ 3);
825 D_seqh
= D_seqp
- 3 - l
;
830 i
= D_seqp
[-l
- 3] << 8 | D_seqp
[-l
- 2];
831 i
&= ~KMAP_NOTIMEOUT
;
832 debug1("Mapping #%d - ", i
);
833 p
= (char *)D_seqp
- l
;
834 debug2("%d(%s) - ", l
, p
);
836 D_seqp
= D_kmaps
+ 3;
848 debug("am in sequence -> check for timeout\n");
850 for (s
= D_seqp
; ; s
+= i
* 2 + 4)
852 if (s
[-l
-3] & KMAP_NOTIMEOUT
>> 8)
854 if ((i
= s
[s
[-l
-1] + 1]) == 0)
856 SetTimeout(&D_mapev
, maptimeout
);
862 ProcessInput2(ibuf
, slen
);
866 # define ProcessInput2 ProcessInput
871 * Here only the screen escape commands are handled.
875 ProcessInput2(ibuf
, ilen
)
881 struct action
*ktabp
;
883 debug1("ProcessInput2: %d bytes\n", ilen
);
884 while (ilen
&& display
)
886 debug1(" - ilen now %d bytes\n", ilen
);
887 flayer
= D_forecv
->c_layer
;
895 if ((unsigned char)*s
++ == D_user
->u_Esc
)
901 DoProcess(fore
, &ibuf
, &slen
, 0);
907 ktabp
= D_ESCseen
? D_ESCseen
: ktab
;
909 ch
= (unsigned char)*s
;
912 * As users have different esc characters, but a common ktab[],
913 * we fold back the users esc and meta-esc key to the Default keys
914 * that can be looked up in the ktab[]. grmbl. jw.
915 * XXX: make ktab[] a per user thing.
917 if (ch
== D_user
->u_Esc
)
919 else if (ch
== D_user
->u_MetaEsc
)
923 DoAction(&ktabp
[ch
], ch
);
924 ibuf
= (char *)(s
+ 1);
930 DoProcess(p
, bufp
, lenp
, pa
)
937 struct display
*d
= display
;
940 /* XXX -> PasteStart */
941 if (pa
&& *lenp
> 1 && p
&& p
->w_slowpaste
)
943 /* schedule slowpaste event */
944 SetTimeout(&p
->w_paster
.pa_slowev
, p
->w_slowpaste
);
945 evenq(&p
->w_paster
.pa_slowev
);
949 while (flayer
&& *lenp
)
952 if (!pa
&& p
&& p
->w_paster
.pa_pastelen
&& flayer
== p
->w_paster
.pa_pastelayer
)
954 debug("layer is busy - beep!\n");
955 WBell(p
, visual_bell
);
963 LayProcess(bufp
, lenp
);
965 if (pa
&& !pa
->pa_pastelayer
)
966 break; /* flush rest of paste */
975 /* We're full, let's beep */
976 debug("layer is full - beep!\n");
977 WBell(p
, visual_bell
);
985 if (pa
&& pa
->pa_pastelen
== 0)
994 int x
, m
, l
= 0, r
= RC_LAST
;
998 x
= strcmp(str
, comms
[m
].name
);
1010 CheckArgNum(nr
, args
)
1015 static char *argss
[] = {"no", "one", "two", "three", "four", "OOPS"};
1016 static char *orformat
[] =
1018 "%s: %s: %s argument%s required",
1019 "%s: %s: %s or %s argument%s required",
1020 "%s: %s: %s, %s or %s argument%s required",
1021 "%s: %s: %s, %s, %s or %s argument%s required"
1024 n
= comms
[nr
].flags
& ARGS_MASK
;
1025 for (i
= 0; args
[i
]; i
++)
1027 if (comms
[nr
].flags
& ARGS_ORMORE
)
1031 Msg(0, "%s: %s: at least %s argument%s required",
1032 rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1036 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1037 (comms
[nr
].flags
& ARGS_PLUS2
) &&
1038 (comms
[nr
].flags
& ARGS_PLUS3
))
1040 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2 && i
!= n
+ 3)
1042 Msg(0, orformat
[3], rc_name
, comms
[nr
].name
, argss
[n
],
1043 argss
[n
+ 1], argss
[n
+ 2], argss
[n
+ 3], "");
1047 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1048 (comms
[nr
].flags
& ARGS_PLUS2
))
1050 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2)
1052 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1053 argss
[n
+ 1], argss
[n
+ 2], "");
1057 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1058 (comms
[nr
].flags
& ARGS_PLUS3
))
1060 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 3)
1062 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1063 argss
[n
+ 1], argss
[n
+ 3], "");
1067 else if ((comms
[nr
].flags
& ARGS_PLUS2
) &&
1068 (comms
[nr
].flags
& ARGS_PLUS3
))
1070 if (i
!= n
&& i
!= n
+ 2 && i
!= n
+ 3)
1072 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1073 argss
[n
+ 2], argss
[n
+ 3], "");
1077 else if (comms
[nr
].flags
& ARGS_PLUS1
)
1079 if (i
!= n
&& i
!= n
+ 1)
1081 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1082 argss
[n
+ 1], n
!= 0 ? "s" : "");
1086 else if (comms
[nr
].flags
& ARGS_PLUS2
)
1088 if (i
!= n
&& i
!= n
+ 2)
1090 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1095 else if (comms
[nr
].flags
& ARGS_PLUS3
)
1097 if (i
!= n
&& i
!= n
+ 3)
1099 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1106 Msg(0, orformat
[0], rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1113 StuffFin(buf
, len
, data
)
1121 LayProcess(&buf
, &len
);
1131 char **args
= act
->args
;
1132 int *argl
= act
->argl
;
1134 int argc
, i
, n
, msgok
;
1137 struct display
*odisplay
= display
;
1138 struct acluser
*user
;
1140 user
= display
? D_user
: users
;
1141 if (nr
== RC_ILLEGAL
)
1143 debug1("key '%c': No action\n", key
);
1146 n
= comms
[nr
].flags
;
1147 if ((n
& NEED_DISPLAY
) && display
== 0)
1149 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1152 if ((n
& NEED_FORE
) && fore
== 0)
1154 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1157 if ((n
& NEED_LAYER
) && flayer
== 0)
1159 Msg(0, "%s: %s: display or window required", rc_name
, comms
[nr
].name
);
1162 if ((argc
= CheckArgNum(nr
, args
)) < 0)
1167 if (AclCheckPermCmd(D_user
, ACL_EXEC
, &comms
[nr
]))
1169 Msg(0, "%s: %s: permission denied (user %s)",
1170 rc_name
, comms
[nr
].name
, (EffectiveAclUser
? EffectiveAclUser
: D_user
)->u_name
);
1174 #endif /* MULTIUSER */
1176 msgok
= display
&& !*rc_name
;
1182 else if (args
[0][0] == '-' && !args
[0][1])
1184 SetForeWindow((struct win
*)0);
1187 else if (args
[0][0] == '.' && !args
[0][1])
1190 Msg(0, "select . needs a window");
1193 SetForeWindow(fore
);
1197 else if (ParseWinNum(act
, &n
) == 0)
1201 case RC_DEFAUTONUKE
:
1202 if (ParseOnOff(act
, &defautonuke
) == 0 && msgok
)
1203 Msg(0, "Default autonuke turned %s", defautonuke
? "on" : "off");
1204 if (display
&& *rc_name
)
1205 D_auto_nuke
= defautonuke
;
1208 if (ParseOnOff(act
, &D_auto_nuke
) == 0 && msgok
)
1209 Msg(0, "Autonuke turned %s", D_auto_nuke
? "on" : "off");
1212 case RC_DEFOBUFLIMIT
:
1213 if (ParseNum(act
, &defobuflimit
) == 0 && msgok
)
1214 Msg(0, "Default limit set to %d", defobuflimit
);
1215 if (display
&& *rc_name
)
1217 D_obufmax
= defobuflimit
;
1218 D_obuflenmax
= D_obuflen
- D_obufmax
;
1223 Msg(0, "Limit is %d, current buffer size is %d", D_obufmax
, D_obuflen
);
1224 else if (ParseNum(act
, &D_obufmax
) == 0 && msgok
)
1225 Msg(0, "Limit set to %d", D_obufmax
);
1226 D_obuflenmax
= D_obuflen
- D_obufmax
;
1228 case RC_DUMPTERMCAP
:
1229 WriteFile(user
, (char *)0, DUMP_TERMCAP
);
1233 int mode
= DUMP_HARDCOPY
;
1235 if (argc
> 1 && !strcmp(*args
, "-h"))
1237 mode
= DUMP_SCROLLBACK
;
1241 if (*args
&& args
[1])
1243 Msg(0, "%s: hardcopy: too many arguments", rc_name
);
1246 if (fore
== 0 && *args
== 0)
1247 Msg(0, "%s: hardcopy: window required", rc_name
);
1249 WriteFile(user
, *args
, mode
);
1253 (void)ParseOnOff(act
, &nwin_default
.Lflag
);
1256 n
= fore
->w_log
? 1 : 0;
1257 ParseSwitch(act
, &n
);
1267 SwitchWindow(NextWindow());
1271 SwitchWindow(PreviousWindow());
1280 Input(fore
->w_pwin
? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1282 Input("Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1290 FreePseudowin(fore
);
1291 Msg(0, "Filter removed.");
1295 name
= SaveStr(fore
->w_title
);
1297 Msg(0, "Window %d (%s) killed.", n
, name
);
1305 Input("Really quit and kill all your windows [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_QUIT
);
1312 if (*args
&& !strcmp(*args
, "-h"))
1324 Input(buf
, 1, INP_RAW
, pow_detach_fn
, NULL
, 0);
1327 Detach(D_POWER
); /* detach and kill Attacher's parent */
1336 Msg(0, "debugging info is written to %s/", DEBUGDIR
);
1338 Msg(0, "debugging is currently off. Use 'debug on' to enable.");
1343 debug("debug: closing debug file.\n");
1348 if (strcmp("off", *args
))
1352 kill(D_userpid
, SIG_NODEBUG
); /* a one shot item, but hey... */
1353 # endif /* SIG_NODEBUG */
1355 if (*args
== 0 || strcmp("off", *args
))
1356 Msg(0, "Sorry, screen was compiled without -DDEBUG option.");
1361 if (*args
&& !strcmp(*args
, "sendcmd"))
1365 free(zmodem_sendcmd
);
1366 zmodem_sendcmd
= SaveStr(args
[1]);
1369 Msg(0, "zmodem sendcmd: %s", zmodem_sendcmd
);
1372 if (*args
&& !strcmp(*args
, "recvcmd"))
1376 free(zmodem_recvcmd
);
1377 zmodem_recvcmd
= SaveStr(args
[1]);
1380 Msg(0, "zmodem recvcmd: %s", zmodem_recvcmd
);
1385 for (i
= 0; i
< 4; i
++)
1386 if (!strcmp(zmodes
[i
], *args
))
1388 if (i
== 4 && !strcmp(*args
, "on"))
1392 Msg(0, "usage: zmodem off|auto|catch|pass");
1398 Msg(0, "zmodem mode is %s", zmodes
[zmodem_mode
]);
1403 register unsigned int i
;
1405 for (i
= 0; i
< sizeof(ktab
)/sizeof(*ktab
); i
++)
1406 ClearAction(&ktab
[i
]);
1407 Msg(0, "Unbound all keys." );
1414 ZombieKey_destroy
= 0;
1417 if (*argl
== 0 || *argl
> 2)
1419 Msg(0, "%s:zombie: one or two characters expected.", rc_name
);
1424 if (!strcmp(args
[1], "onerror"))
1426 ZombieKey_onerror
= 1;
1428 Msg(0, "usage: zombie [keys [onerror]]");
1432 ZombieKey_onerror
= 0;
1433 ZombieKey_destroy
= args
[0][0];
1434 ZombieKey_resurrect
= *argl
== 2 ? args
[0][1] : 0;
1444 struct display
*olddisplay
= display
;
1445 display
= 0; /* no display will cause a broadcast */
1446 Msg(0, "%s: %s", s
, *args
);
1447 display
= olddisplay
;
1451 /* where this AT command comes from: */
1453 s
= SaveStr(D_user
->u_name
);
1454 /* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
1455 EffectiveAclUser
= D_user
;
1457 s
= SaveStr(D_usertty
);
1459 n
= strlen(args
[0]);
1462 * the windows/displays loops are quite dangerous here, take extra
1463 * care not to trigger landmines. Things may appear/disappear while
1464 * we are walking along.
1468 case '*': /* user */
1476 for (u
= users
; u
; u
= u
->u_next
)
1478 debug3("strncmp('%s', '%s', %d)\n", *args
, u
->u_name
, n
);
1479 if (!strncmp(*args
, u
->u_name
, n
))
1482 debug1("at all displays of user %s\n", u
->u_name
);
1483 for (display
= displays
; display
; display
= nd
)
1485 nd
= display
->d_next
;
1488 flayer
= D_forecv
->c_layer
;
1492 debug1("AT display %s\n", D_usertty
);
1493 DoCommand(args
+ 1, argl
+ 1);
1495 Msg(0, "command from %s: %s %s",
1496 s
, args
[1], args
[2] ? args
[2] : "");
1503 case '%': /* display */
1507 debug1("at display matching '%s'\n", args
[0]);
1508 for (display
= displays
; display
; display
= nd
)
1510 nd
= display
->d_next
;
1514 flayer
= D_forecv
->c_layer
;
1515 if (strncmp(args
[0], D_usertty
, n
) &&
1516 (strncmp("/dev/", D_usertty
, 5) ||
1517 strncmp(args
[0], D_usertty
+ 5, n
)) &&
1518 (strncmp("/dev/tty", D_usertty
, 8) ||
1519 strncmp(args
[0], D_usertty
+ 8, n
)))
1521 debug1("AT display %s\n", D_usertty
);
1522 DoCommand(args
+ 1, argl
+ 1);
1524 Msg(0, "command from %s: %s %s",
1525 s
, args
[1], args
[2] ? args
[2] : "");
1532 case '#': /* window */
1543 if (!*args
[0] || (i
= WindowByNumber(args
[0])) < 0)
1545 args
[0][n
] = ch
; /* must restore string in case of bind */
1546 /* try looping over titles */
1547 for (fore
= windows
; fore
; fore
= nw
)
1550 if (strncmp(args
[0], fore
->w_title
, n
))
1552 debug2("AT window %d(%s)\n", fore
->w_number
, fore
->w_title
);
1554 * consider this a bug or a feature:
1555 * while looping through windows, we have fore AND
1556 * display context. This will confuse users who try to
1557 * set up loops inside of loops, but often allows to do
1558 * what you mean, even when you adress your context wrong.
1561 /* XXX: other displays? */
1562 if (fore
->w_layer
.l_cvlist
)
1563 display
= fore
->w_layer
.l_cvlist
->c_display
;
1564 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1565 DoCommand(args
+ 1, argl
+ 1); /* may destroy our display */
1566 if (fore
&& fore
->w_layer
.l_cvlist
)
1568 display
= fore
->w_layer
.l_cvlist
->c_display
;
1569 Msg(0, "command from %s: %s %s",
1570 s
, args
[1], args
[2] ? args
[2] : "");
1576 Msg(0, "%s: at '%s': no such window.\n", rc_name
, args
[0]);
1579 else if (i
< MAXWIN
&& (fore
= wtab
[i
]))
1581 args
[0][n
] = ch
; /* must restore string in case of bind */
1582 debug2("AT window %d (%s)\n", fore
->w_number
, fore
->w_title
);
1583 if (fore
->w_layer
.l_cvlist
)
1584 display
= fore
->w_layer
.l_cvlist
->c_display
;
1585 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1586 DoCommand(args
+ 1, argl
+ 1);
1587 if (fore
&& fore
->w_layer
.l_cvlist
)
1589 display
= fore
->w_layer
.l_cvlist
->c_display
;
1590 Msg(0, "command from %s: %s %s",
1591 s
, args
[1], args
[2] ? args
[2] : "");
1597 Msg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name
);
1603 EffectiveAclUser
= NULL
;
1610 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1611 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1613 i
= FindEncoding(args
[1]);
1616 Msg(0, "%s: readreg: unknown encoding", rc_name
);
1623 * Without arguments we prompt for a destination register.
1624 * It will receive the copybuffer contents.
1625 * This is not done by RC_PASTE, as we prompt for source
1628 if ((s
= *args
) == NULL
)
1630 Input("Copy to register:", 1, INP_RAW
, copy_reg_fn
, NULL
, 0);
1635 Msg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name
);
1640 * With two arguments we *really* read register contents from file
1646 Msg(0, "%s: readreg: too many arguments", rc_name
);
1649 if ((s
= ReadFile(args
[1], &n
)))
1651 struct plop
*pp
= plop_tab
+ (int)(unsigned char)ch
;
1664 * with one argument we copy the copybuffer into a specified register
1665 * This could be done with RC_PASTE too, but is here to be consistent
1666 * with the zero argument call.
1668 copy_reg_fn(&ch
, 0, NULL
);
1673 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1674 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1676 i
= FindEncoding(args
[1]);
1679 Msg(0, "%s: register: unknown encoding", rc_name
);
1688 Msg(0, "%s: register: illegal number of arguments.", rc_name
);
1693 Msg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name
);
1700 if (user
->u_plop
.buf
!= NULL
)
1701 UserFreeCopyBuffer(user
);
1702 if (args
[1] && args
[1][0])
1704 user
->u_plop
.buf
= SaveStrn(args
[1], argl
[1]);
1705 user
->u_plop
.len
= argl
[1];
1707 user
->u_plop
.enc
= i
;
1714 struct plop
*plp
= plop_tab
+ (int)(unsigned char)ch
;
1718 plp
->buf
= SaveStrn(args
[1], argl
[1]);
1726 if ((s
= *args
) == NULL
)
1728 Input("Process register:", 1, INP_RAW
, process_fn
, NULL
, 0);
1733 Msg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name
);
1737 process_fn(&ch
, 0, NULL
);
1743 Input("Stuff:", 100, INP_COOKED
, StuffFin
, NULL
, 0);
1749 if (strcmp(s
, "-k"))
1751 Msg(0, "%s: stuff: invalid option %s", rc_name
, s
);
1755 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
1756 if (strcmp(term
[i
].tcname
, s
) == 0)
1760 Msg(0, "%s: stuff: unknown key '%s'", rc_name
, s
);
1764 if (StuffKey(i
- T_CAPS
) == 0)
1767 s
= display
? D_tcs
[i
].str
: 0;
1782 Msg(0, "screen %s", version
);
1787 timestring
= SaveStr(*args
);
1790 Msg(0, "%s", MakeWinMsg(timestring
, fore
, '%'));
1800 struct action
*ktabp
= ktab
;
1801 if (argc
== 2 && !strcmp(*args
, "-c"))
1803 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
1805 Msg(0, "Unknown command class '%s'", args
[1]);
1809 if (D_ESCseen
!= ktab
|| ktabp
!= ktab
)
1819 SwitchWindow(display
&& D_other
? D_other
->w_number
: NextWindow());
1822 if (user
->u_Esc
== -1)
1841 case RC_DEFBREAKTYPE
:
1844 static char *types
[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL
};
1845 extern int breaktype
;
1849 if (ParseNum(act
, &n
))
1850 for (n
= 0; n
< (int)(sizeof(types
)/sizeof(*types
)); n
++)
1852 for (i
= 0; i
< 4; i
++)
1855 if (ch
>= 'a' && ch
<= 'z')
1857 if (ch
!= types
[n
][i
] && (ch
+ ('a' - 'A')) != types
[n
][i
])
1863 if (n
< 0 || n
>= (int)(sizeof(types
)/sizeof(*types
)))
1864 Msg(0, "%s invalid, chose one of %s, %s or %s", *args
, types
[0], types
[1], types
[2]);
1868 Msg(0, "breaktype set to (%d) %s", n
, types
[n
]);
1872 Msg(0, "breaktype is (%d) %s", breaktype
, types
[breaktype
]);
1878 if (*args
&& ParseNum(act
, &n
))
1880 SendBreak(fore
, n
, nr
== RC_POW_BREAK
);
1894 if (*args
&& !strcmp(*args
, "-w"))
1896 else if (*args
&& !strcmp(*args
, "-d"))
1900 if (what
== 0 && flayer
&& !display
)
1906 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1909 w
= flayer
->l_width
;
1910 h
= flayer
->l_height
;
1916 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1922 if (*args
&& args
[0][0] == '-')
1924 Msg(0, "%s: %s: unknown option %s", rc_name
, comms
[nr
].name
, *args
);
1927 if (nr
== RC_HEIGHT
)
1935 else if (h
== H1height
)
1937 else if (h
> (H0height
+ H1height
) / 2)
1955 else if (w
== Z1width
)
1957 else if (w
> (Z0width
+ Z1width
) / 2)
1969 if (*args
&& args
[1] && args
[2])
1971 Msg(0, "%s: %s: too many arguments", rc_name
, comms
[nr
].name
);
1976 Msg(0, "Illegal width");
1981 Msg(0, "Illegal height");
1986 if (flayer
->l_width
== w
&& flayer
->l_height
== h
)
1988 ResizeLayer(flayer
, w
, h
, (struct display
*)0);
1991 if (D_width
== w
&& D_height
== h
)
1995 ChangeScreenSize(w
, h
, 1);
1999 if (ResizeDisplay(w
, h
) == 0)
2001 Activate(D_fore
? D_fore
->w_norefresh
: 0);
2003 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
2007 Msg(0, "Your termcap does not specify how to change the terminal's width to %d.", w
);
2008 else if (w
== D_width
)
2009 Msg(0, "Your termcap does not specify how to change the terminal's height to %d.", h
);
2011 Msg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w
, h
);
2019 ChangeAKA(fore
, *args
, strlen(*args
));
2022 Input(":", 100, INP_EVERY
, Colonfin
, NULL
, 0);
2023 if (*args
&& **args
)
2031 if (D_status_lastmsg
)
2032 Msg(0, "%s", D_status_lastmsg
);
2035 DoScreen("key", args
);
2038 if (ParseSwitch(act
, &fore
->w_wrap
) == 0 && msgok
)
2039 Msg(0, "%cwrap", fore
->w_wrap
? '+' : '-');
2044 if (args
[0][0] == 'a')
2046 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) ? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
2050 if (ParseOnOff(act
, &n
))
2052 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | n
;
2057 if (fore
->w_flow
& FLOW_AUTOFLAG
)
2058 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | FLOW_NOW
;
2059 else if (fore
->w_flow
& FLOW_NOW
)
2060 fore
->w_flow
&= ~FLOW_NOW
;
2062 fore
->w_flow
= fore
->w_flow
? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
2064 SetFlow(fore
->w_flow
& FLOW_NOW
);
2066 Msg(0, "%cflow%s", (fore
->w_flow
& FLOW_NOW
) ? '+' : '-',
2067 (fore
->w_flow
& FLOW_AUTOFLAG
) ? "(auto)" : "");
2070 case RC_DEFWRITELOCK
:
2071 if (args
[0][0] == 'a')
2072 nwin_default
.wlock
= WLOCK_AUTO
;
2075 if (ParseOnOff(act
, &n
))
2077 nwin_default
.wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2083 if (args
[0][0] == 'a')
2085 fore
->w_wlock
= WLOCK_AUTO
;
2089 if (ParseOnOff(act
, &n
))
2091 fore
->w_wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2094 * user may have permission to change the writelock setting,
2095 * but he may never aquire the lock himself without write permission
2097 if (!AclCheckPermWin(D_user
, ACL_WRITE
, fore
))
2098 fore
->w_wlockuser
= D_user
;
2100 Msg(0, "writelock %s", (fore
->w_wlock
== WLOCK_AUTO
) ? "auto" :
2101 ((fore
->w_wlock
== WLOCK_OFF
) ? "off" : "on"));
2105 ResetAnsiState(fore
);
2106 WriteString(fore
, "\033[H\033[J", 6);
2109 ResetAnsiState(fore
);
2111 if (fore
->w_zdisplay
)
2112 zmodem_abort(fore
, fore
->w_zdisplay
);
2114 WriteString(fore
, "\033c", 2);
2117 n
= fore
->w_monitor
!= MON_OFF
;
2120 n
= n
&& (ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
));
2122 if (ParseSwitch(act
, &n
))
2127 if (display
) /* we tell only this user */
2128 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2130 for (i
= 0; i
< maxusercount
; i
++)
2131 ACLBYTE(fore
->w_mon_notify
, i
) |= ACLBIT(i
);
2133 if (fore
->w_monitor
== MON_OFF
)
2134 fore
->w_monitor
= MON_ON
;
2135 Msg(0, "Window %d (%s) is now being monitored for all activity.", fore
->w_number
, fore
->w_title
);
2140 if (display
) /* we remove only this user */
2141 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
)
2142 &= ~ACLBIT(D_user
->u_id
);
2144 for (i
= 0; i
< maxusercount
; i
++)
2145 ACLBYTE(fore
->w_mon_notify
, i
) &= ~ACLBIT(i
);
2146 for (i
= maxusercount
- 1; i
>= 0; i
--)
2147 if (ACLBYTE(fore
->w_mon_notify
, i
))
2151 fore
->w_monitor
= MON_OFF
;
2152 Msg(0, "Window %d (%s) is no longer being monitored for activity.", fore
->w_number
, fore
->w_title
);
2162 display_wlist(0, WLIST_NUM
, (struct win
*)0);
2163 else if (!strcmp(*args
, "string"))
2169 wliststr
= SaveStr(args
[1]);
2172 Msg(0, "windowlist string is '%s'", wliststr
);
2174 else if (!strcmp(*args
, "title"))
2180 wlisttit
= SaveStr(args
[1]);
2183 Msg(0, "windowlist title is '%s'", wlisttit
);
2189 for (i
= 0; i
< argc
; i
++)
2192 else if (!strcmp(args
[i
], "-m"))
2194 else if (!strcmp(args
[i
], "-b"))
2196 else if (!strcmp(args
[i
], "-g"))
2197 flag
|= WLIST_NESTED
;
2200 Msg(0, "usage: windowlist [-b] [-g] [-m] [string [string] | title [title]]");
2204 display_wlist(blank
, flag
, (struct win
*)0);
2208 if (argc
== 2 && !strcmp(*args
, "-c"))
2210 struct action
*ktabp
;
2211 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
2213 Msg(0, "Unknown command class '%s'", args
[1]);
2216 display_help(args
[1], ktabp
);
2219 display_help((char *)0, ktab
);
2222 display_copyright();
2226 if (flayer
->l_layfn
!= &WinLf
)
2228 Msg(0, "Must be on a window layer");
2235 static char *pasteargs
[] = {".", 0};
2236 static int pasteargl
[] = {1};
2238 if (flayer
->l_layfn
!= &WinLf
)
2240 Msg(0, "Must be on a window layer");
2243 if (GetHistory() == 0)
2245 if (user
->u_plop
.buf
== NULL
)
2253 char *ss
, *dbuf
, dch
;
2260 * without args we prompt for one(!) register to be pasted in the window
2262 if ((s
= *args
) == NULL
)
2264 Input("Paste from register:", 1, INP_RAW
, ins_reg_fn
, NULL
, 0);
2267 if (args
[1] == 0 && !fore
) /* no window? */
2270 * with two arguments we paste into a destination register
2271 * (no window needed here).
2273 if (args
[1] && argl
[1] != 1)
2275 Msg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
2281 enc
= fore
->w_encoding
;
2285 * measure length of needed buffer
2287 for (ss
= s
= *args
; (ch
= *ss
); ss
++)
2293 enc
= user
->u_plop
.enc
;
2294 if (enc
!= user
->u_plop
.enc
)
2295 l
+= RecodeBuf((unsigned char *)user
->u_plop
.buf
, user
->u_plop
.len
, user
->u_plop
.enc
, enc
, (unsigned char *)0);
2298 l
+= user
->u_plop
.len
;
2304 enc
= plop_tab
[(int)(unsigned char)ch
].enc
;
2305 if (enc
!= plop_tab
[(int)(unsigned char)ch
].enc
)
2306 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);
2309 l
+= plop_tab
[(int)(unsigned char)ch
].len
;
2314 Msg(0, "empty buffer");
2319 * if there is only one source and the destination is a window, then
2320 * pass a pointer rather than duplicating the buffer.
2322 if (s
[1] == 0 && args
[1] == 0)
2324 if (enc
== (*s
== '.' ? user
->u_plop
.enc
: plop_tab
[(int)(unsigned char)*s
].enc
))
2327 MakePaster(&fore
->w_paster
, *s
== '.' ? user
->u_plop
.buf
: plop_tab
[(int)(unsigned char)*s
].buf
, l
, 0);
2331 * if no shortcut, we construct a buffer
2333 if ((dbuf
= (char *)malloc(l
)) == 0)
2340 * concatenate all sources into our own buffer, copy buffer is
2341 * special and is skipped if no display exists.
2343 for (ss
= s
; (ch
= *ss
); ss
++)
2345 struct plop
*pp
= (ch
== '.' ? &user
->u_plop
: &plop_tab
[(int)(unsigned char)ch
]);
2349 l
+= RecodeBuf((unsigned char *)pp
->buf
, pp
->len
, pp
->enc
, enc
, (unsigned char *)dbuf
+ l
);
2353 bcopy(pp
->buf
, dbuf
+ l
, pp
->len
);
2357 * when called with one argument we paste our buffer into the window
2361 MakePaster(&fore
->w_paster
, dbuf
, l
, 1);
2366 * we have two arguments, the second is already in dch.
2367 * use this as destination rather than the window.
2372 if (user
->u_plop
.buf
!= NULL
)
2373 UserFreeCopyBuffer(user
);
2374 user
->u_plop
.buf
= dbuf
;
2375 user
->u_plop
.len
= l
;
2377 user
->u_plop
.enc
= enc
;
2382 struct plop
*pp
= plop_tab
+ (int)(unsigned char)dch
;
2395 if (!user
->u_plop
.buf
)
2397 Msg(0, "empty buffer");
2402 struct plop oldplop
;
2404 oldplop
= user
->u_plop
;
2405 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2410 enc
= FindEncoding(args
[1]);
2413 Msg(0, "%s: writebuf: unknown encoding", rc_name
);
2416 if (enc
!= oldplop
.enc
)
2418 l
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)0);
2419 newbuf
= malloc(l
+ 1);
2425 user
->u_plop
.len
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)newbuf
);
2426 user
->u_plop
.buf
= newbuf
;
2427 user
->u_plop
.enc
= enc
;
2432 if (args
[0] && args
[1])
2433 Msg(0, "%s: writebuf: too many arguments", rc_name
);
2435 WriteFile(user
, args
[0], DUMP_EXCHANGE
);
2437 if (user
->u_plop
.buf
!= oldplop
.buf
)
2438 free(user
->u_plop
.buf
);
2439 user
->u_plop
= oldplop
;
2445 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
2446 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2448 i
= FindEncoding(args
[1]);
2451 Msg(0, "%s: readbuf: unknown encoding", rc_name
);
2457 if (args
[0] && args
[1])
2459 Msg(0, "%s: readbuf: too many arguments", rc_name
);
2462 if ((s
= ReadFile(args
[0] ? args
[0] : BufferFile
, &n
)))
2464 if (user
->u_plop
.buf
)
2465 UserFreeCopyBuffer(user
);
2466 user
->u_plop
.len
= n
;
2467 user
->u_plop
.buf
= s
;
2469 user
->u_plop
.enc
= i
;
2477 (void)ParseSwitch(act
, &search_ic
);
2479 Msg(0, "Will %signore case in searches", search_ic
? "" : "not ");
2481 #endif /* COPY_PASTE */
2484 SetEscape(user
, -1, -1);
2485 else if (*argl
== 2)
2486 SetEscape(user
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2489 Msg(0, "%s: two characters required after escape.", rc_name
);
2492 /* Change defescape if master user. This is because we only
2495 if (display
&& user
!= users
)
2500 SetEscape(NULL
, -1, -1);
2501 else if (*argl
== 2)
2502 SetEscape(NULL
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2505 Msg(0, "%s: two characters required after defescape.", rc_name
);
2513 s
= *args
? *args
: home
;
2515 Msg(errno
, "%s", s
);
2519 if (ParseSaveStr(act
, &ShellProg
) == 0)
2520 ShellArgs
[0] = ShellProg
;
2522 case RC_HARDCOPYDIR
:
2524 (void)ParseSaveStr(act
, &hardcopydir
);
2526 Msg(0, "hardcopydir is %s\n", hardcopydir
&& *hardcopydir
? hardcopydir
: "<cwd>");
2531 if (args
[1] && !(strcmp(*args
, "flush")))
2533 log_flush
= atoi(args
[1]);
2535 Msg(0, "log flush timeout set to %ds\n", log_flush
);
2538 if (ParseSaveStr(act
, &screenlogfile
) || !msgok
)
2541 Msg(0, "logfile is '%s'", screenlogfile
);
2544 if (!*args
|| !strcmp(*args
, "on") || !strcmp(*args
, "off"))
2546 if (ParseSwitch(act
, &logtstamp_on
) == 0 && msgok
)
2547 Msg(0, "timestamps turned %s", logtstamp_on
? "on" : "off");
2549 else if (!strcmp(*args
, "string"))
2553 if (logtstamp_string
)
2554 free(logtstamp_string
);
2555 logtstamp_string
= SaveStr(args
[1]);
2558 Msg(0, "logfile timestamp is '%s'", logtstamp_string
);
2560 else if (!strcmp(*args
, "after"))
2564 logtstamp_after
= atoi(args
[1]);
2568 Msg(0, "timestamp printed after %ds\n", logtstamp_after
);
2571 Msg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
2574 (void)ParseSaveStr(act
, &nwin_default
.aka
);
2577 case RC_TERMCAPINFO
:
2579 if (!rc_name
|| !*rc_name
)
2580 Msg(0, "Sorry, too late now. Place that in your .screenrc file.");
2583 break; /* Already handled */
2586 if (ParseSaveStr(act
, &s
))
2588 if (strlen(s
) >= 20)
2590 Msg(0, "%s: term: argument too long ( < 20)", rc_name
);
2594 strcpy(screenterm
, s
);
2596 debug1("screenterm set to %s\n", screenterm
);
2597 MakeTermcap((display
== 0));
2598 debug("new termcap made\n");
2601 if (!msgok
&& (!rc_name
|| strcmp(rc_name
, "-X")))
2604 * user typed ^A:echo... well, echo isn't FinishRc's job,
2605 * but as he wanted to test us, we show good will
2607 if (argc
> 1 && !strcmp(*args
, "-n"))
2613 if (argc
> 1 && !strcmp(*args
, "-p"))
2619 s
= MakeWinMsg(s
, fore
, '%');
2624 Msg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name
);
2631 AddXChars(buf
, sizeof(buf
), BellString
);
2632 Msg(0, "bell_msg is '%s'", buf
);
2635 (void)ParseSaveStr(act
, &BellString
);
2640 BufferFile
= SaveStr(DEFAULT_BUFFERFILE
);
2641 else if (ParseSaveStr(act
, &BufferFile
))
2644 Msg(0, "Bufferfile is now '%s'", BufferFile
);
2648 (void)ParseSaveStr(act
, &ActivityString
);
2650 #if defined(DETACH) && defined(POW_DETACH)
2651 case RC_POW_DETACH_MSG
:
2655 AddXChars(buf
, sizeof(buf
), PowDetachString
);
2656 Msg(0, "pow_detach_msg is '%s'", buf
);
2659 (void)ParseSaveStr(act
, &PowDetachString
);
2662 #if defined(UTMPOK) && defined(LOGOUTOK)
2664 n
= fore
->w_slot
!= (slot_t
)-1;
2665 if (*args
&& !strcmp(*args
, "always"))
2672 if (*args
&& !strcmp(*args
, "attached"))
2679 if (ParseSwitch(act
, &n
) == 0)
2683 if (!strcmp(*args
, "always"))
2684 nwin_default
.lflag
|= 2;
2685 else if (!strcmp(*args
, "attached"))
2686 nwin_default
.lflag
&= ~2;
2688 (void)ParseOnOff(act
, &nwin_default
.lflag
);
2692 if (args
[0] && args
[1] && args
[1][0] == 'i')
2695 for (display
= displays
; display
; display
= display
->d_next
)
2699 #if defined(TERMIO) || defined(POSIX)
2700 D_NewMode
.tio
.c_cc
[VINTR
] = D_OldMode
.tio
.c_cc
[VINTR
];
2701 D_NewMode
.tio
.c_lflag
|= ISIG
;
2702 #else /* TERMIO || POSIX */
2703 D_NewMode
.m_tchars
.t_intrc
= D_OldMode
.m_tchars
.t_intrc
;
2704 #endif /* TERMIO || POSIX */
2705 SetTTY(D_userfd
, &D_NewMode
);
2708 if (args
[0] && args
[0][0] == 'a')
2709 nwin_default
.flowflag
= FLOW_AUTOFLAG
;
2711 (void)ParseOnOff(act
, &nwin_default
.flowflag
);
2714 (void)ParseOnOff(act
, &nwin_default
.wrap
);
2717 (void)ParseOnOff(act
, &nwin_default
.c1
);
2721 (void)ParseOnOff(act
, &nwin_default
.bce
);
2725 (void)ParseOnOff(act
, &nwin_default
.gr
);
2728 if (ParseOnOff(act
, &n
) == 0)
2729 nwin_default
.monitor
= (n
== 0) ? MON_OFF
: MON_ON
;
2731 case RC_DEFMOUSETRACK
:
2732 if (ParseOnOff(act
, &n
) == 0)
2733 defmousetrack
= (n
== 0) ? 0 : 1000;
2738 Msg(0, "Mouse tracking for this display is turned %s", D_mousetrack
? "on" : "off");
2740 else if (ParseOnOff(act
, &n
) == 0)
2742 D_mousetrack
= n
== 0 ? 0 : 1000;
2744 MouseMode(D_fore
->w_mouse
);
2748 if (ParseOnOff(act
, &n
) == 0)
2749 nwin_default
.silence
= (n
== 0) ? SILENCE_OFF
: SILENCE_ON
;
2753 Msg(0, "W%s echo command when creating windows.",
2754 VerboseCreate
? "ill" : "on't");
2755 else if (ParseOnOff(act
, &n
) == 0)
2761 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
2764 if (args
[0] && strcmp(args
[0], "on") && strcmp(args
[0], "off"))
2766 struct display
*olddisplay
= display
;
2767 int old_use
, new_use
= -1;
2770 if (!strncmp(s
, "always", 6))
2772 if (!strcmp(s
, "lastline"))
2773 new_use
= HSTATUS_LASTLINE
;
2774 else if (!strcmp(s
, "ignore"))
2775 new_use
= HSTATUS_IGNORE
;
2776 else if (!strcmp(s
, "message"))
2777 new_use
= HSTATUS_MESSAGE
;
2778 else if (!strcmp(args
[0], "string"))
2783 AddXChars(buf
, sizeof(buf
), hstatusstring
);
2784 Msg(0, "hardstatus string is '%s'", buf
);
2790 Msg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name
);
2795 hardstatusemu
= new_use
| (s
== args
[0] ? 0 : HSTATUS_ALWAYS
);
2796 for (display
= displays
; display
; display
= display
->d_next
)
2799 new_use
= hardstatusemu
& ~HSTATUS_ALWAYS
;
2800 if (D_HS
&& s
== args
[0])
2801 new_use
= HSTATUS_HS
;
2802 ShowHStatus((char *)0);
2803 old_use
= D_has_hstatus
;
2804 D_has_hstatus
= new_use
;
2805 if ((new_use
== HSTATUS_LASTLINE
&& old_use
!= HSTATUS_LASTLINE
) || (new_use
!= HSTATUS_LASTLINE
&& old_use
== HSTATUS_LASTLINE
))
2806 ChangeScreenSize(D_width
, D_height
, 1);
2813 free(hstatusstring
);
2814 hstatusstring
= SaveStr(args
[1]);
2815 for (display
= displays
; display
; display
= display
->d_next
)
2818 display
= olddisplay
;
2821 (void)ParseSwitch(act
, &use_hardstatus
);
2823 Msg(0, "messages displayed on %s", use_hardstatus
? "hardstatus line" : "window");
2826 if (strcmp(args
[0], "always") == 0 || strcmp(args
[0], "splitonly") == 0)
2828 struct display
*olddisplay
= display
;
2830 captionalways
= args
[0][0] == 'a';
2831 for (display
= displays
; display
; display
= display
->d_next
)
2832 ChangeScreenSize(D_width
, D_height
, 1);
2833 display
= olddisplay
;
2835 else if (strcmp(args
[0], "string") == 0)
2840 AddXChars(buf
, sizeof(buf
), captionstring
);
2841 Msg(0, "caption string is '%s'", buf
);
2847 Msg(0, "%s: usage: caption always|splitonly|string <string>", rc_name
);
2853 free(captionstring
);
2854 captionstring
= SaveStr(args
[1]);
2855 RedisplayDisplays(0);
2858 n
= (console_window
!= 0);
2859 if (ParseSwitch(act
, &n
))
2861 if (TtyGrabConsole(fore
->w_ptyfd
, n
, rc_name
))
2864 Msg(0, "%s: releasing console %s", rc_name
, HostName
);
2865 else if (console_window
)
2866 Msg(0, "%s: stealing console %s from window %d (%s)", rc_name
,
2867 HostName
, console_window
->w_number
, console_window
->w_title
);
2869 Msg(0, "%s: grabbing console %s", rc_name
, HostName
);
2870 console_window
= n
? fore
: 0;
2873 if (ParseOnOff(act
, &all_norefresh
))
2875 if (!all_norefresh
&& fore
)
2878 Msg(0, all_norefresh
? "No refresh on window change!\n" :
2879 "Window specific refresh\n");
2882 (void)ParseSwitch(act
, &n
);
2883 fore
->w_norefresh
= n
;
2886 if (ParseSwitch(act
, &visual_bell
) || !msgok
)
2888 if (visual_bell
== 0)
2889 Msg(0, "switched to audible bell.");
2891 Msg(0, "switched to visual bell.");
2894 if (ParseNum1000(act
, &VBellWait
) == 0 && msgok
)
2895 Msg(0, "vbellwait set to %.10g seconds", VBellWait
/1000.);
2898 if (ParseNum1000(act
, &MsgWait
) == 0 && msgok
)
2899 Msg(0, "msgwait set to %.10g seconds", MsgWait
/1000.);
2902 if (ParseNum1000(act
, &MsgMinWait
) == 0 && msgok
)
2903 Msg(0, "msgminwait set to %.10g seconds", MsgMinWait
/1000.);
2905 case RC_SILENCEWAIT
:
2906 if (ParseNum(act
, &SilenceWait
))
2908 if (SilenceWait
< 1)
2910 for (p
= windows
; p
; p
= p
->w_next
)
2911 p
->w_silencewait
= SilenceWait
;
2913 Msg(0, "silencewait set to %d seconds", SilenceWait
);
2917 Msg(0, "This is window %d (%s).\n", fore
->w_number
, fore
->w_title
);
2920 int old
= fore
->w_number
;
2922 if (args
[0][0] == '+')
2924 else if (args
[0][0] == '-')
2928 parse
= ParseNum(act
, &n
);
2937 if (n
< 0 || n
>= maxwin
)
2939 Msg(0, "Given window position is invalid.");
2949 /* exchange the acls for these windows. */
2953 /* exchange the utmp-slots for these windows */
2954 if ((fore
->w_slot
!= (slot_t
) -1) && (fore
->w_slot
!= (slot_t
) 0))
2959 if (p
&& (p
->w_slot
!= (slot_t
) -1) && (p
->w_slot
!= (slot_t
) 0))
2961 /* XXX: first display wins? */
2962 display
= fore
->w_layer
.l_cvlist
? fore
->w_layer
.l_cvlist
->c_display
: 0;
2968 WindowChanged(fore
, 'n');
2969 WindowChanged((struct win
*)0, 'w');
2970 WindowChanged((struct win
*)0, 'W');
2971 WindowChanged((struct win
*)0, 0);
2975 n
= fore
->w_silence
!= 0;
2976 i
= fore
->w_silencewait
;
2977 if (args
[0] && (args
[0][0] == '-' || (args
[0][0] >= '0' && args
[0][0] <= '9')))
2979 if (ParseNum(act
, &i
))
2983 else if (ParseSwitch(act
, &n
))
2988 if (display
) /* we tell only this user */
2989 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2991 for (n
= 0; n
< maxusercount
; n
++)
2992 ACLBYTE(fore
->w_lio_notify
, n
) |= ACLBIT(n
);
2994 fore
->w_silencewait
= i
;
2995 fore
->w_silence
= SILENCE_ON
;
2996 SetTimeout(&fore
->w_silenceev
, fore
->w_silencewait
* 1000);
2997 evenq(&fore
->w_silenceev
);
3001 Msg(0, "The window is now being monitored for %d sec. silence.", fore
->w_silencewait
);
3006 if (display
) /* we remove only this user */
3007 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
)
3008 &= ~ACLBIT(D_user
->u_id
);
3010 for (n
= 0; n
< maxusercount
; n
++)
3011 ACLBYTE(fore
->w_lio_notify
, n
) &= ~ACLBIT(n
);
3012 for (i
= maxusercount
- 1; i
>= 0; i
--)
3013 if (ACLBYTE(fore
->w_lio_notify
, i
))
3018 fore
->w_silence
= SILENCE_OFF
;
3019 evdeq(&fore
->w_silenceev
);
3023 Msg(0, "The window is no longer being monitored for silence.");
3027 case RC_DEFSCROLLBACK
:
3028 (void)ParseNum(act
, &nwin_default
.histheight
);
3031 if (flayer
->l_layfn
== &MarkLf
)
3033 Msg(0, "Cannot resize scrollback buffer in copy/scrollback mode.");
3036 (void)ParseNum(act
, &n
);
3037 ChangeWindowSize(fore
, fore
->w_width
, fore
->w_height
, n
);
3039 Msg(0, "scrollback set to %d", fore
->w_histheight
);
3042 case RC_SESSIONNAME
:
3044 Msg(0, "This session is named '%s'\n", SockName
);
3047 char buf
[MAXPATHLEN
];
3050 if (ParseSaveStr(act
, &s
))
3052 if (!*s
|| strlen(s
) + (SockName
- SockPath
) > MAXPATHLEN
- 13 || index(s
, '/'))
3054 Msg(0, "%s: bad session name '%s'\n", rc_name
, s
);
3058 strncpy(buf
, SockPath
, SockName
- SockPath
);
3059 sprintf(buf
+ (SockName
- SockPath
), "%d.%s", (int)getpid(), s
);
3061 if ((access(buf
, F_OK
) == 0) || (errno
!= ENOENT
))
3063 Msg(0, "%s: inappropriate path: '%s'.", rc_name
, buf
);
3066 if (rename(SockPath
, buf
))
3068 Msg(errno
, "%s: failed to rename(%s, %s)", rc_name
, SockPath
, buf
);
3071 debug2("rename(%s, %s) done\n", SockPath
, buf
);
3072 strcpy(SockPath
, buf
);
3074 WindowChanged((struct win
*)0, 'S');
3078 if (!args
[0] || !args
[1])
3080 debug1("RC_SETENV arguments missing: %s\n", args
[0] ? args
[0] : "");
3081 InputSetenv(args
[0]);
3085 xsetenv(args
[0], args
[1]);
3094 case RC_DEFSLOWPASTE
:
3095 (void)ParseNum(act
, &nwin_default
.slow
);
3099 Msg(0, fore
->w_slowpaste
?
3100 "Slowpaste in window %d is %d milliseconds." :
3101 "Slowpaste in window %d is unset.",
3102 fore
->w_number
, fore
->w_slowpaste
);
3103 else if (ParseNum(act
, &fore
->w_slowpaste
) == 0 && msgok
)
3104 Msg(0, fore
->w_slowpaste
?
3105 "Slowpaste in window %d set to %d milliseconds." :
3106 "Slowpaste in window %d now unset.",
3107 fore
->w_number
, fore
->w_slowpaste
);
3110 if (CompileKeys(*args
, *argl
, mark_key_tab
))
3112 Msg(0, "%s: markkeys: syntax error.", rc_name
);
3115 debug1("markkeys %s\n", *args
);
3119 if (ParseSwitch(act
, &pastefont
) == 0 && msgok
)
3120 Msg(0, "Will %spaste font settings", pastefont
? "" : "not ");
3124 (void)ParseSwitch(act
, &join_with_cr
);
3126 case RC_COMPACTHIST
:
3127 if (ParseSwitch(act
, &compacthist
) == 0 && msgok
)
3128 Msg(0, "%scompacting history lines", compacthist
? "" : "not ");
3133 (void)ParseOnOff(act
, &nethackflag
);
3136 case RC_HARDCOPY_APPEND
:
3137 (void)ParseOnOff(act
, &hardcopy_append
);
3143 AddXChars(buf
, sizeof(buf
), VisualBellString
);
3144 Msg(0, "vbell_msg is '%s'", buf
);
3147 (void)ParseSaveStr(act
, &VisualBellString
);
3148 debug1(" new vbellstr '%s'\n", VisualBellString
);
3151 if (ParseBase(act
, *args
, &n
, 8, "octal"))
3153 if (n
< 0 || n
> 0777)
3155 Msg(0, "%s: mode: Invalid tty mode %o", rc_name
, n
);
3160 Msg(0, "Ttymode set to %03o", TtyMode
);
3163 (void)ParseOnOff(act
, &auto_detach
);
3165 case RC_STARTUP_MESSAGE
:
3166 (void)ParseOnOff(act
, &default_startup
);
3172 n
= (*user
->u_password
) ? 1 : 0;
3173 if (user
->u_password
!= NullStr
) free((char *)user
->u_password
);
3174 user
->u_password
= SaveStr(*args
);
3175 if (!strcmp(user
->u_password
, "none"))
3178 Msg(0, "Password checking disabled");
3179 free(user
->u_password
);
3180 user
->u_password
= NullStr
;
3187 Msg(0, "%s: password: window required", rc_name
);
3190 Input("New screen password:", 100, INP_NOECHO
, pass1
, display
? (char *)D_user
: (char *)users
, 0);
3193 #endif /* PASSWORD */
3196 struct action
*ktabp
= ktab
;
3201 if (argc
> 2 && !strcmp(*args
, "-c"))
3203 ktabp
= FindKtab(args
[1], 1);
3210 else if (argc
> 1 && !strcmp(*args
, "-k"))
3223 for (n
= 0; n
< KMAP_KEYS
; n
++)
3224 if (strcmp(term
[n
+ T_CAPS
].tcname
, *args
) == 0)
3228 Msg(0, "%s: bind: unknown key '%s'", rc_name
, *args
);
3237 Msg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name
);
3241 n
= (unsigned char)args
[0][0];
3245 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3247 Msg(0, "%s: bind: unknown command '%s'", rc_name
, args
[1]);
3250 if (CheckArgNum(i
, args
+ 2) < 0)
3252 ClearAction(&ktabp
[n
]);
3253 SaveAction(ktabp
+ n
, i
, args
+ 2, argl
+ 2);
3256 ClearAction(&ktabp
[n
]);
3262 struct action
*newact
;
3263 int newnr
, fl
= 0, kf
= 0, af
= 0, df
= 0, mf
= 0;
3264 struct display
*odisp
= display
;
3266 struct kmap_ext
*kme
;
3268 for (; *args
&& **args
== '-'; args
++, argl
++)
3270 if (strcmp(*args
, "-t") == 0)
3271 fl
= KMAP_NOTIMEOUT
;
3272 else if (strcmp(*args
, "-k") == 0)
3274 else if (strcmp(*args
, "-a") == 0)
3276 else if (strcmp(*args
, "-d") == 0)
3278 else if (strcmp(*args
, "-m") == 0)
3280 else if (strcmp(*args
, "--") == 0)
3288 Msg(0, "%s: bindkey: invalid option %s", rc_name
, *args
);
3294 Msg(0, "%s: bindkey: -d does not work with -m", rc_name
);
3300 display_bindkey("Edit mode", mmtab
);
3302 display_bindkey("Default", dmtab
);
3304 display_bindkey("User", umtab
);
3311 Msg(0, "%s: bindkey: -a only works with -k", rc_name
);
3316 Msg(0, "%s: bindkey: empty string makes no sense", rc_name
);
3319 for (i
= 0, kme
= kmap_exts
; i
< kmap_extn
; i
++, kme
++)
3326 if (*argl
== (kme
->fl
& ~KMAP_NOTIMEOUT
) && bcmp(kme
->str
, *args
, *argl
) == 0)
3332 Msg(0, "%s: bindkey: keybinding not found", rc_name
);
3336 kmap_exts
= (struct kmap_ext
*)xrealloc((char *)kmap_exts
, kmap_extn
* sizeof(*kmap_exts
));
3337 kme
= kmap_exts
+ i
;
3338 bzero((char *)kme
, 8 * sizeof(*kmap_exts
));
3339 for (; i
< kmap_extn
; i
++, kme
++)
3342 kme
->dm
.nr
= kme
->mm
.nr
= kme
->um
.nr
= RC_ILLEGAL
;
3343 kme
->dm
.args
= kme
->mm
.args
= kme
->um
.args
= noargs
;
3344 kme
->dm
.argl
= kme
->mm
.argl
= kme
->um
.argl
= 0;
3349 if (df
== 0 && kme
->dm
.nr
!= RC_ILLEGAL
)
3351 if (mf
== 0 && kme
->mm
.nr
!= RC_ILLEGAL
)
3353 if ((df
|| mf
) && kme
->um
.nr
!= RC_ILLEGAL
)
3355 i
+= KMAP_KEYS
+ KMAP_AKEYS
;
3356 newact
= df
? &kme
->dm
: mf
? &kme
->mm
: &kme
->um
;
3360 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
3361 if (strcmp(term
[i
].tcname
, *args
) == 0)
3365 Msg(0, "%s: bindkey: unknown key '%s'", rc_name
, *args
);
3368 if (af
&& i
>= T_CURSOR
&& i
< T_OCAPS
)
3369 i
-= T_CURSOR
- KMAP_KEYS
;
3372 newact
= df
? &dmtab
[i
] : mf
? &mmtab
[i
] : &umtab
[i
];
3376 if ((newnr
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3378 Msg(0, "%s: bindkey: unknown command '%s'", rc_name
, args
[1]);
3381 if (CheckArgNum(newnr
, args
+ 2) < 0)
3383 ClearAction(newact
);
3384 SaveAction(newact
, newnr
, args
+ 2, argl
+ 2);
3385 if (kf
== 0 && args
[1])
3389 kme
->str
= SaveStrn(*args
, *argl
);
3390 kme
->fl
= fl
| *argl
;
3394 ClearAction(newact
);
3395 for (display
= displays
; display
; display
= display
->d_next
)
3396 remap(i
, args
[1] ? 1 : 0);
3397 if (kf
== 0 && !args
[1])
3399 if (!used
&& kme
->str
)
3412 if (ParseNum(act
, &n
))
3416 Msg(0, "%s: maptimeout: illegal time %d", rc_name
, n
);
3421 if (*args
== 0 || msgok
)
3422 Msg(0, "maptimeout is %dms", maptimeout
);
3436 UsersAcl(NULL
, argc
, args
);
3439 if (UserDel(args
[0], NULL
))
3442 Msg(0, "%s removed from acl database", args
[0]);
3446 * modify a user to gain or lose rights granted to a group.
3447 * This group is actually a normal user whose rights were defined
3448 * with chacl in the usual way.
3452 if (strcmp(args
[1], "none")) /* link a user to another user */
3454 if (AclLinkUser(args
[0], args
[1]))
3457 Msg(0, "User %s joined acl-group %s", args
[0], args
[1]);
3459 else /* remove all groups from user */
3462 struct aclusergroup
*g
;
3464 if (!(u
= *FindUserPtr(args
[0])))
3466 while ((g
= u
->u_group
))
3468 u
->u_group
= g
->next
;
3473 else /* show all groups of user */
3475 char buf
[256], *p
= buf
;
3478 struct aclusergroup
*g
;
3480 if (!(u
= *FindUserPtr(args
[0])))
3483 Msg(0, "User %s does not exist.", args
[0]);
3490 sprintf(p
, "%s ", g
->u
->u_name
);
3498 Msg(0, "%s's group%s: %s.", args
[0], (ngroups
== 1) ? "" : "s",
3499 (ngroups
== 0) ? "none" : buf
);
3504 while ((s
= *args
++))
3508 if (AclUmask(display
? D_user
: users
, s
, &err
))
3509 Msg(0, "umask: %s\n", err
);
3513 if (ParseOnOff(act
, &n
))
3518 Msg(0, "Multiuser mode %s", multi
? "enabled" : "disabled");
3520 #endif /* MULTIUSER */
3528 i
= D_nonblock
>= 0;
3529 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3531 if (ParseNum1000(act
, &i
))
3534 else if (!ParseSwitch(act
, &i
))
3535 i
= i
== 0 ? -1 : 1000;
3538 if (msgok
&& i
== -1)
3539 Msg(0, "display set to blocking mode");
3540 else if (msgok
&& i
== 0)
3541 Msg(0, "display set to nonblocking mode, no timeout");
3543 Msg(0, "display set to nonblocking mode, %.10gs timeout", i
/1000.);
3545 if (D_nonblock
<= 0)
3546 evdeq(&D_blockedev
);
3548 case RC_DEFNONBLOCK
:
3549 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3551 if (ParseNum1000(act
, &defnonblock
))
3554 else if (!ParseOnOff(act
, &defnonblock
))
3555 defnonblock
= defnonblock
== 0 ? -1 : 1000;
3558 if (display
&& *rc_name
)
3560 D_nonblock
= defnonblock
;
3561 if (D_nonblock
<= 0)
3562 evdeq(&D_blockedev
);
3568 if (fore
->w_gr
== 2)
3571 if (ParseSwitch(act
, &fore
->w_gr
) == 0 && msgok
)
3572 Msg(0, "Will %suse GR", fore
->w_gr
? "" : "not ");
3574 if (fore
->w_gr
== 0 && fore
->w_FontE
)
3579 if (ParseSwitch(act
, &fore
->w_c1
) == 0 && msgok
)
3580 Msg(0, "Will %suse C1", fore
->w_c1
? "" : "not ");
3584 if (ParseSwitch(act
, &fore
->w_bce
) == 0 && msgok
)
3585 Msg(0, "Will %serase with background color", fore
->w_bce
? "" : "not ");
3592 if (*args
&& !strcmp(args
[0], "-d"))
3595 Msg(0, "encodings directory is %s", screenencodings
? screenencodings
: "<unset>");
3598 free(screenencodings
);
3599 screenencodings
= SaveStr(args
[1]);
3603 if (*args
&& !strcmp(args
[0], "-l"))
3606 Msg(0, "encoding: -l: argument required");
3607 else if (LoadFontTranslation(-1, args
[1]))
3608 Msg(0, "encoding: could not load utf8 encoding file");
3610 Msg(0, "encoding: utf8 encoding file loaded");
3614 if (*args
&& (!strcmp(args
[0], "-l") || !strcmp(args
[0], "-d")))
3617 Msg(0, "encoding: screen is not compiled for UTF-8.");
3621 for (i
= 0; i
< 2; i
++)
3625 if (!strcmp(args
[i
], "."))
3627 n
= FindEncoding(args
[i
]);
3630 Msg(0, "encoding: unknown encoding '%s'", args
[i
]);
3635 WinSwitchEncoding(fore
, n
);
3636 ResetCharsets(fore
);
3638 else if (i
&& display
)
3643 case RC_DEFENCODING
:
3644 n
= FindEncoding(*args
);
3647 Msg(0, "defencoding: unknown encoding '%s'", *args
);
3650 nwin_default
.encoding
= n
;
3656 n
= nwin_default
.encoding
== UTF8
;
3657 if (ParseSwitch(act
, &n
) == 0)
3659 nwin_default
.encoding
= n
? UTF8
: 0;
3661 Msg(0, "Will %suse UTF-8 encoding for new windows", n
? "" : "not ");
3665 for (i
= 0; i
< 2; i
++)
3667 if (i
&& args
[i
] == 0)
3670 n
= fore
->w_encoding
!= UTF8
;
3671 else if (strcmp(args
[i
], "off") == 0)
3673 else if (strcmp(args
[i
], "on") == 0)
3677 Msg(0, "utf8: illegal argument (%s)", args
[i
]);
3682 WinSwitchEncoding(fore
, n
? UTF8
: 0);
3684 Msg(0, "Will %suse UTF-8 encoding", n
? "" : "not ");
3687 D_encoding
= n
? UTF8
: 0;
3701 printcmd
= SaveStr(*args
);
3703 if (*args
== 0 || msgok
)
3706 Msg(0, "using '%s' as print command", printcmd
);
3708 Msg(0, "using termcap entries for printing");
3714 if (argl
&& argl
[0] > 0 && argl
[1] > 0)
3718 Msg(0, "Two characters expected to define a digraph");
3721 i
= digraph_find(args
[0]);
3722 digraphs
[i
].d
[0] = args
[0][0];
3723 digraphs
[i
].d
[1] = args
[0][1];
3724 if (!parse_input_int(args
[1], argl
[1], &digraphs
[i
].value
))
3726 if (!(digraphs
[i
].value
= atoi(args
[1])))
3729 digraphs
[i
].value
= (int)args
[1][0];
3734 unsigned char *s
= args
[1];
3735 digraphs
[i
].value
= 0;
3738 t
= FromUtf8(*s
++, &digraphs
[i
].value
);
3742 digraphs
[i
].value
= 0;
3744 digraphs
[i
].value
= t
;
3753 Input("Enter digraph: ", 10, INP_EVERY
, digraph_fn
, NULL
, 0);
3754 if (*args
&& **args
)
3767 if (nwin_default
.hstatus
)
3768 AddXChars(buf
, sizeof(buf
), nwin_default
.hstatus
);
3769 Msg(0, "default hstatus is '%s'", buf
);
3772 (void)ParseSaveStr(act
, &nwin_default
.hstatus
);
3773 if (*nwin_default
.hstatus
== 0)
3775 free(nwin_default
.hstatus
);
3776 nwin_default
.hstatus
= 0;
3780 (void)ParseSaveStr(act
, &fore
->w_hstatus
);
3781 if (*fore
->w_hstatus
== 0)
3783 free(fore
->w_hstatus
);
3784 fore
->w_hstatus
= 0;
3786 WindowChanged(fore
, 'h');
3796 if (nwin_default
.charset
)
3797 AddXChars(buf
, sizeof(buf
), nwin_default
.charset
);
3798 Msg(0, "default charset is '%s'", buf
);
3802 if (n
== 0 || n
> 6)
3804 Msg(0, "%s: %s: string has illegal size.", rc_name
, comms
[nr
].name
);
3808 ((args
[0][4] < '0' || args
[0][4] > '3') && args
[0][4] != '.') ||
3809 ((args
[0][5] < '0' || args
[0][5] > '3') && args
[0][5] && args
[0][5] != '.')))
3811 Msg(0, "%s: %s: illegal mapping number.", rc_name
, comms
[nr
].name
);
3814 if (nr
== RC_CHARSET
)
3816 SetCharsets(fore
, *args
);
3819 if (nwin_default
.charset
)
3820 free(nwin_default
.charset
);
3821 nwin_default
.charset
= SaveStr(*args
);
3827 if (*s
>= '0' && *s
<= '9')
3830 for (i
= 0; i
< 8; i
++)
3831 if (*s
== "dubrsBiI"[i
])
3835 if (*s
&& s
[1] && !s
[2])
3837 if (*s
== 'd' && s
[1] == 'd')
3839 else if (*s
== '.' && s
[1] == 'd')
3841 else if (*s
== 'd' && s
[1] == '.')
3843 else if (*s
!= '.' || s
[1] != '.')
3847 if (*s
|| i
< 0 || i
>= 8)
3849 Msg(0, "%s: attrcolor: unknown attribute '%s'.", rc_name
, args
[0]);
3854 n
= ParseAttrColor(args
[1], args
[2], 1);
3857 attr2color
[i
][nr
] = n
;
3859 for (i
= 0; i
< 8; i
++)
3860 if (attr2color
[i
][0] || attr2color
[i
][1] || attr2color
[i
][2] || attr2color
[i
][3])
3867 if (strcmp(args
[0], "bell") == 0)
3871 else if (strcmp(args
[0], "monitor") == 0)
3875 else if (strcmp(args
[0], "so") != 0)
3877 Msg(0, "Invalid option '%s' for rendition", args
[0]);
3886 renditions
[i
] = ParseAttrColor(args
[0], args
[1], 1);
3887 WindowChanged((struct win
*)0, 'w');
3888 WindowChanged((struct win
*)0, 'W');
3889 WindowChanged((struct win
*)0, 0);
3893 /* We are here, means we want to set the sorendition. */
3895 case RC_SORENDITION
:
3899 i
= ParseAttrColor(*args
, args
[1], 1);
3902 ApplyAttrColor(i
, &mchar_so
);
3903 WindowChanged((struct win
*)0, 0);
3904 debug2("--> %x %x\n", mchar_so
.attr
, mchar_so
.color
);
3908 Msg(0, "Standout attributes 0x%02x color 0x%02x", (unsigned char)mchar_so
.attr
, 0x99 ^ (unsigned char)mchar_so
.color
);
3910 Msg(0, "Standout attributes 0x%02x ", (unsigned char)mchar_so
.attr
);
3923 Msg(0, "%s:%s screen login", HostName
, SockPath
);
3924 InputSu(D_fore
, &D_user
, NULL
);
3927 InputSu(D_fore
, &D_user
, args
[0]);
3929 s
= DoSu(&D_user
, args
[0], args
[1], "\377");
3931 s
= DoSu(&D_user
, args
[0], args
[1], args
[2]);
3935 #endif /* MULTIUSER */
3938 if (s
&& !strcmp(s
, "-v"))
3939 AddCanvas(SLICE_HORI
);
3941 AddCanvas(SLICE_VERT
);
3953 D_forecv
->c_xoff
= D_forecv
->c_xs
;
3954 D_forecv
->c_yoff
= D_forecv
->c_ys
;
3955 RethinkViewportOffsets(D_forecv
);
3956 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
3957 flayer
= D_forecv
->c_layer
;
3962 struct canvas
*cv
= 0;
3963 if (!*args
|| !strcmp(*args
, "next"))
3964 cv
= D_forecv
->c_next
? D_forecv
->c_next
: D_cvlist
;
3965 else if (!strcmp(*args
, "prev"))
3967 for (cv
= D_cvlist
; cv
->c_next
&& cv
->c_next
!= D_forecv
; cv
= cv
->c_next
)
3970 else if (!strcmp(*args
, "top"))
3972 else if (!strcmp(*args
, "bottom"))
3974 for (cv
= D_cvlist
; cv
->c_next
; cv
= cv
->c_next
)
3977 else if (!strcmp(*args
, "up"))
3978 cv
= FindCanvas(D_forecv
->c_xs
, D_forecv
->c_ys
- 1);
3979 else if (!strcmp(*args
, "down"))
3980 cv
= FindCanvas(D_forecv
->c_xs
, D_forecv
->c_ye
+ 2);
3981 else if (!strcmp(*args
, "left"))
3982 cv
= FindCanvas(D_forecv
->c_xs
- 1, D_forecv
->c_ys
);
3983 else if (!strcmp(*args
, "right"))
3984 cv
= FindCanvas(D_forecv
->c_xe
+ 1, D_forecv
->c_ys
);
3987 Msg(0, "%s: usage: focus [next|prev|up|down|left|right|top|bottom]", rc_name
);
3990 SetForeCanvas(display
, cv
);
3995 if (D_forecv
->c_slorient
== SLICE_UNKN
)
3997 Msg(0, "resize: need more than one region");
4000 for (; *args
; args
++)
4002 if (!strcmp(*args
, "-h"))
4004 else if (!strcmp(*args
, "-v"))
4006 else if (!strcmp(*args
, "-b"))
4007 i
|= RESIZE_FLAG_H
| RESIZE_FLAG_V
;
4008 else if (!strcmp(*args
, "-p"))
4009 i
|= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
4010 else if (!strcmp(*args
, "-l"))
4015 if (*args
&& args
[1])
4017 Msg(0, "%s: usage: resize [-h] [-v] [-l] [num]\n", rc_name
);
4021 ResizeRegions(*args
, i
);
4023 Input(resizeprompts
[i
], 20, INP_EVERY
, ResizeFin
, (char*)0, i
);
4026 (void)ParseSwitch(act
, &separate_sids
);
4029 args
= SaveArgs(args
);
4030 for (i
= 0; args
[i
]; i
++)
4033 Colonfin(args
[i
], strlen(args
[i
]), (char *)0);
4039 (void)ParseSwitch(act
, &use_altscreen
);
4041 Msg(0, "Will %sdo alternate screen switching", use_altscreen
? "" : "not ");
4044 if (ParseNum(act
, &n
))
4047 Msg(0, "illegal maxwin number specified");
4048 else if (n
> maxwin
)
4049 Msg(0, "may only decrease maxwin number");
4054 if (ParseBase(act
, *args
, &n
, 10, "decimal"))
4057 setbacktick(n
, 0, 0, (char **)0);
4063 Msg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name
);
4066 if (ParseBase(act
, args
[1], &lifespan
, 10, "decimal"))
4068 if (ParseBase(act
, args
[2], &tick
, 10, "decimal"))
4070 setbacktick(n
, lifespan
, tick
, SaveArgs(args
+ 3));
4072 WindowChanged(0, '`');
4078 RunBlanker(blankerprg
);
4083 CursorVisibility(-1);
4091 for (pp
= blankerprg
; *pp
; pp
++)
4097 blankerprg
= SaveArgs(args
);
4103 struct display
*olddisplay
= display
;
4104 if (!strcmp(*args
, "off"))
4106 else if (args
[0][0])
4107 idletimo
= atoi(*args
) * 1000;
4110 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
4112 Msg(0, "%s: idle: unknown command '%s'", rc_name
, args
[1]);
4115 if (CheckArgNum(i
, args
+ 2) < 0)
4117 ClearAction(&idleaction
);
4118 SaveAction(&idleaction
, i
, args
+ 2, argl
+ 2);
4120 for (display
= displays
; display
; display
= display
->d_next
)
4122 display
= olddisplay
;
4127 Msg(0, "idle timeout %ds, %s", idletimo
/ 1000, comms
[idleaction
.nr
].name
);
4132 case RC_FOCUSMINSIZE
:
4133 for (i
= 0; i
< 2 && args
[i
]; i
++)
4135 if (!strcmp(args
[i
], "max") || !strcmp(args
[i
], "_"))
4147 for (i
= 0; i
< 2; i
++)
4149 n
= i
== 0 ? focusminwidth
: focusminheight
;
4151 strcpy(b
[i
], "max");
4153 sprintf(b
[i
], "%d", n
);
4155 Msg(0, "focus min size is %s %s\n", b
[0], b
[1]);
4164 fore
->w_group
= WindowByName(*args
);
4165 if (fore
->w_group
&& fore
->w_group
->w_type
!= W_TYPE_GROUP
)
4168 WindowChanged((struct win
*)0, 'w');
4169 WindowChanged((struct win
*)0, 'W');
4170 WindowChanged((struct win
*)0, 0);
4175 Msg(0, "window group is %d (%s)\n", fore
->w_group
->w_number
, fore
->w_group
->w_title
);
4177 Msg(0, "window belongs to no group");
4181 if (!strcmp(args
[0], "title"))
4185 Msg(0, "not on a layout");
4190 Msg(0, "current layout is %d (%s)", D_layout
->lay_number
, D_layout
->lay_title
);
4193 free(D_layout
->lay_title
);
4194 D_layout
->lay_title
= SaveStr(args
[1]);
4196 else if (!strcmp(args
[0], "number"))
4202 Msg(0, "not on a layout");
4207 Msg(0, "This is layout %d (%s).\n", D_layout
->lay_number
, D_layout
->lay_title
);
4210 old
= D_layout
->lay_number
;
4212 if (n
< 0 || n
>= MAXLAY
)
4215 laytab
[n
] = D_layout
;
4216 D_layout
->lay_number
= n
;
4219 lay
->lay_number
= old
;
4222 else if (!strcmp(args
[0], "autosave"))
4226 Msg(0, "not on a layout");
4231 if (!strcmp(args
[1], "on"))
4232 D_layout
->lay_autosave
= 1;
4233 else if (!strcmp(args
[1], "off"))
4234 D_layout
->lay_autosave
= 0;
4237 Msg(0, "invalid argument. Give 'on' or 'off");
4242 Msg(0, "autosave is %s", D_layout
->lay_autosave
? "on" : "off");
4244 else if (!strcmp(args
[0], "new"))
4250 while (*t
>= '0' && *t
<= '9')
4252 if (t
!= args
[1] && (!*t
|| *t
== ':'))
4266 else if (!strcmp(args
[0], "save"))
4270 Msg(0, "usage: layout save <name>");
4273 SaveLayout(args
[1], &D_canvas
);
4275 else if (!strcmp(args
[0], "select"))
4279 Input("Switch to layout: ", 20, INP_COOKED
, SelectLayoutFin
, NULL
, 0);
4282 SelectLayoutFin(args
[1], strlen(args
[1]), (char *)0);
4284 else if (!strcmp(args
[0], "next"))
4286 struct layout
*lay
= D_layout
;
4288 lay
= lay
->lay_next
? lay
->lay_next
: layouts
;
4293 Msg(0, "no layout defined");
4296 if (lay
== D_layout
)
4298 LoadLayout(lay
, &D_canvas
);
4301 else if (!strcmp(args
[0], "prev"))
4303 struct layout
*lay
= D_layout
;
4306 for (lay
= layouts
; lay
->lay_next
&& lay
->lay_next
!= D_layout
; lay
= lay
->lay_next
)
4313 Msg(0, "no layout defined");
4316 if (lay
== D_layout
)
4318 LoadLayout(lay
, &D_canvas
);
4321 else if (!strcmp(args
[0], "attach"))
4326 Msg(0, "no attach layout set");
4327 else if (layout_attach
== &layout_last_marker
)
4328 Msg(0, "will attach to last layout");
4330 Msg(0, "will attach to layout %d (%s)", layout_attach
->lay_number
, layout_attach
->lay_title
);
4333 if (!strcmp(args
[1], ":last"))
4334 layout_attach
= &layout_last_marker
;
4335 else if (!args
[1][0])
4340 lay
= FindLayout(args
[1]);
4343 Msg(0, "unknown layout '%s'", args
[1]);
4346 layout_attach
= lay
;
4349 else if (!strcmp(args
[0], "show"))
4353 else if (!strcmp(args
[0], "remove"))
4355 struct layout
*lay
= display
? D_layout
: layouts
;
4358 lay
= layouts
? FindLayout(args
[1]) : (struct layout
*)0;
4361 Msg(0, "unknown layout '%s'", args
[1]);
4369 Msg(0, "unknown layout subcommand");
4373 if(ParseSwitch(act
, &cjkwidth
) == 0)
4376 Msg(0, "Treat ambiguous width characters as %s width", cjkwidth
? "full" : "half");
4382 /* key == -2: input from braille keybord, msgok always 0 */
4383 DoBrailleAction(act
, key
== -2 ? 0 : msgok
);
4387 if (display
!= odisplay
)
4389 for (display
= displays
; display
; display
= display
->d_next
)
4390 if (display
== odisplay
)
4396 DoCommand(argv
, argl
)
4402 if ((act
.nr
= FindCommnr(*argv
)) == RC_ILLEGAL
)
4404 Msg(0, "%s: unknown command '%s'", rc_name
, *argv
);
4407 act
.args
= argv
+ 1;
4408 act
.argl
= argl
+ 1;
4413 SaveAction(act
, nr
, args
, argl
)
4419 register int argc
= 0;
4433 if ((pp
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4435 if ((lp
= (int *)malloc((unsigned)(argc
) * sizeof(int *))) == 0)
4442 *lp
= argl
? *argl
++ : (int)strlen(*args
);
4443 *pp
++ = SaveStrn(*args
++, *lp
++);
4452 register char **ap
, **pp
;
4453 register int argc
= 0;
4457 if ((pp
= ap
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4460 *pp
++ = SaveStr(*args
++);
4467 * buf is split into argument vector args.
4468 * leading whitespace is removed.
4469 * @!| abbreviations are expanded.
4470 * the end of buffer is recognized by '\0' or an un-escaped '#'.
4471 * " and ' are interpreted.
4476 Parse(buf
, bufl
, args
, argl
)
4480 register char *p
= buf
, **ap
= args
, *pp
;
4481 register int delim
, argc
;
4484 debug2("Parse %d %s\n", bufl
, buf
);
4491 while (*p
&& (*p
== ' ' || *p
== '\t'))
4494 if (argc
== 0 && *p
== '!')
4503 if (*p
== '\0' || *p
== '#' || *p
== '\n')
4506 for (delim
= 0; delim
< argc
; delim
++)
4507 debug1("-- %s\n", args
[delim
]);
4511 if (++argc
>= MAXARGS
)
4513 Msg(0, "%s: too many tokens.", rc_name
);
4518 debug1("- new arg %s\n", p
);
4523 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')))
4526 if (*p
>= '0' && *p
<= '7')
4529 if (p
[1] >= '0' && p
[1] <= '7')
4532 *pp
= (*pp
<< 3) | (*p
- '0');
4533 if (p
[1] >= '0' && p
[1] <= '7')
4536 *pp
= (*pp
<< 3) | (*p
- '0');
4545 case 'n': *pp
= '\n'; break;
4546 case 'r': *pp
= '\r'; break;
4547 case 't': *pp
= '\t'; break;
4548 default: *pp
= *p
; break;
4553 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] == '_'))
4556 char *ps
, *pe
, op
, *v
, xbuf
[11];
4560 debug1("- var %s\n", ps
);
4564 if (*ps
== '{' && *p
== '}')
4566 if (*ps
== ':' && *p
== ':')
4568 if (*ps
!= '{' && *ps
!= ':' && (*p
< 'a' || *p
> 'z') && (*p
< 'A' || *p
> 'Z') && (*p
< '0' || *p
> '9') && *p
!= '_')
4573 if (*ps
== '{' || *ps
== ':')
4577 Msg(0, "%s: bad variable name.", rc_name
);
4584 debug1("- var is '%s'\n", ps
);
4586 v
= gettermcapstring(ps
+ 1);
4592 if (!strcmp(ps
, "TERM"))
4593 v
= display
? D_termname
: "unknown";
4594 else if (!strcmp(ps
, "COLUMNS"))
4595 sprintf(xbuf
, "%d", display
? D_width
: -1);
4596 else if (!strcmp(ps
, "LINES"))
4597 sprintf(xbuf
, "%d", display
? D_height
: -1);
4598 else if (!strcmp(ps
, "PID"))
4599 sprintf(xbuf
, "%d", getpid());
4600 else if (!strcmp(ps
, "STY"))
4606 vl
= v
? strlen(v
) : 0;
4609 debug1("- sub is '%s'\n", v
);
4612 int right
= buf
+ bufl
- (p
+ strlen(p
) + 1);
4615 bcopy(p
, p
+ right
, strlen(p
) + 1);
4621 Msg(0, "%s: no space left for variable expansion.", rc_name
);
4629 else if (delim
!= '\'' && *p
== '^' && p
[1])
4632 *pp
++ = *p
== '?' ? '\177' : *p
& 0x1f;
4634 else if (delim
== 0 && (*p
== '\'' || *p
== '"'))
4636 else if (delim
== 0 && (*p
== ' ' || *p
== '\t' || *p
== '\n'))
4644 Msg(0, "%s: Missing %c quote.", rc_name
, delim
);
4650 debug2("- arg done, '%s' rest %s\n", ap
[-1], p
);
4651 *lp
++ = pp
- ap
[-1];
4670 if (DefaultEsc
>= 0)
4671 ClearAction(&ktab
[DefaultEsc
]);
4672 if (DefaultMetaEsc
>= 0)
4673 ClearAction(&ktab
[DefaultMetaEsc
]);
4676 DefaultMetaEsc
= me
;
4679 if (DefaultEsc
>= 0)
4681 ClearAction(&ktab
[DefaultEsc
]);
4682 ktab
[DefaultEsc
].nr
= RC_OTHER
;
4684 if (DefaultMetaEsc
>= 0)
4686 ClearAction(&ktab
[DefaultMetaEsc
]);
4687 ktab
[DefaultMetaEsc
].nr
= RC_META
;
4694 ParseSwitch(act
, var
)
4698 if (*act
->args
== 0)
4703 return ParseOnOff(act
, var
);
4707 ParseOnOff(act
, var
)
4711 register int num
= -1;
4712 char **args
= act
->args
;
4716 if (strcmp(args
[0], "on") == 0)
4718 else if (strcmp(args
[0], "off") == 0)
4723 Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name
, comms
[act
->nr
].name
);
4731 ParseSaveStr(act
, var
)
4735 char **args
= act
->args
;
4736 if (*args
== 0 || args
[1])
4738 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4743 *var
= SaveStr(*args
);
4753 char *p
, **args
= act
->args
;
4756 if (p
== 0 || *p
== 0 || args
[1])
4758 Msg(0, "%s: %s: invalid argument. Give one argument.",
4759 rc_name
, comms
[act
->nr
].name
);
4765 if (*p
>= '0' && *p
<= '9')
4766 i
= 10 * i
+ (*p
- '0');
4769 Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4770 rc_name
, comms
[act
->nr
].name
);
4775 debug1("ParseNum got %d\n", i
);
4781 ParseNum1000(act
, var
)
4786 char *p
, **args
= act
->args
;
4790 if (p
== 0 || *p
== 0 || args
[1])
4792 Msg(0, "%s: %s: invalid argument. Give one argument.",
4793 rc_name
, comms
[act
->nr
].name
);
4799 if (*p
>= '0' && *p
<= '9')
4802 i
= 10 * i
+ (*p
- '0');
4803 else if (dig
== 4 && *p
>= '5')
4808 else if (*p
== '.' && !dig
)
4812 Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4813 rc_name
, comms
[act
->nr
].name
);
4824 i
= (int)((unsigned int)~0 >> 1);
4825 debug1("ParseNum1000 got %d\n", i
);
4836 for (p
= windows
; p
; p
= p
->w_next
)
4837 if (!strcmp(p
->w_title
, s
))
4839 for (p
= windows
; p
; p
= p
->w_next
)
4840 if (!strncmp(p
->w_title
, s
, strlen(s
)))
4852 for (i
= 0, s
= str
; *s
; s
++)
4854 if (*s
< '0' || *s
> '9')
4856 i
= i
* 10 + (*s
- '0');
4862 * Get window number from Name or Number string.
4863 * Numbers are tried first, then names, a prefix match suffices.
4864 * Be careful when assigning numeric strings as WindowTitles.
4873 if ((i
= WindowByNumber(str
)) < 0 || i
>= MAXWIN
)
4875 if ((p
= WindowByName(str
)))
4883 ParseWinNum(act
, var
)
4887 char **args
= act
->args
;
4890 if (*args
== 0 || args
[1])
4892 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4896 i
= WindowByNoN(*args
);
4899 Msg(0, "%s: %s: invalid argument. Give window number or name.",
4900 rc_name
, comms
[act
->nr
].name
);
4903 debug1("ParseWinNum got %d\n", i
);
4909 ParseBase(act
, p
, var
, base
, bname
)
4921 Msg(0, "%s: %s: empty argument.", rc_name
, comms
[act
->nr
].name
);
4926 if (c
>= 'a' && c
<= 'z')
4928 if (c
>= 'A' && c
<= 'Z')
4929 c
-= 'A' - ('0' + 10);
4931 if (c
< 0 || c
>= base
)
4933 Msg(0, "%s: %s: argument is not %s.", rc_name
, comms
[act
->nr
].name
, bname
);
4938 debug1("ParseBase got %d\n", i
);
4948 for (base
+= '0'; *s
; ++s
)
4949 if (*s
< '0' || *s
> base
)
4955 IsNumColon(s
, base
, p
, psize
)
4960 if ((q
= rindex(s
, ':')) != 0)
4962 strncpy(p
, q
+ 1, psize
- 1);
4963 p
[psize
- 1] = '\0';
4968 return IsNum(s
, base
);
4977 debug1("SwitchWindow %d\n", n
);
4978 if (n
< 0 || n
>= MAXWIN
)
4983 if ((p
= wtab
[n
]) == 0)
4995 Msg(0, "This IS window %d (%s).", n
, p
->w_title
);
4999 if (AclCheckPermWin(D_user
, ACL_READ
, p
))
5001 Msg(0, "Access to window %d denied.", p
->w_number
);
5006 Activate(fore
->w_norefresh
);
5011 SetCanvasWindow(cv
, wi
)
5015 struct win
*p
= 0, **pp
;
5017 struct canvas
*cvp
, **cvpp
;
5020 display
= cv
->c_display
;
5024 /* remove old layer */
5025 for (cvpp
= &l
->l_cvlist
; (cvp
= *cvpp
); cvpp
= &cvp
->c_lnext
)
5029 *cvpp
= cvp
->c_lnext
;
5031 p
= Layer2Window(l
);
5035 if (p
&& cv
== D_forecv
)
5038 ReleaseAutoWritelock(display
, p
);
5042 SetTimeout(&p
->w_silenceev
, p
->w_silencewait
* 1000);
5043 evenq(&p
->w_silenceev
);
5048 if (l
->l_cvlist
== 0 && (p
== 0 || l
!= p
->w_savelayer
))
5052 /* find right layer to display on canvas */
5053 if (wi
&& wi
->w_type
!= W_TYPE_GROUP
)
5056 if (wi
->w_savelayer
&& (wi
->w_blocked
|| wi
->w_savelayer
->l_cvlist
== 0))
5057 l
= wi
->w_savelayer
;
5063 l
->l_data
= (char *)wi
;
5068 /* add our canvas to the layer's canvaslist */
5069 ASSERT(l
->l_cvlist
!= cv
);
5070 cv
->c_lnext
= l
->l_cvlist
;
5073 cv
->c_xoff
= cv
->c_xs
;
5074 cv
->c_yoff
= cv
->c_ys
;
5075 RethinkViewportOffsets(cv
);
5080 if (wi
&& wi
->w_type
== W_TYPE_GROUP
)
5082 /* auto-start windowlist on groups */
5083 struct display
*d
= display
;
5084 struct layer
*oldflayer
= flayer
;
5086 display_wlist(0, 0, wi
);
5091 if (wi
&& D_other
== wi
)
5092 D_other
= wi
->w_next
; /* Might be 0, but that's OK. */
5096 fore
= D_fore
; /* XXX ? */
5100 ObtainAutoWritelock(display
, wi
);
5103 * Place the window at the head of the most-recently-used list
5107 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5112 p
->w_next
= windows
;
5122 * SetForeWindow changes the window in the input focus of the display.
5123 * Puts window wi in canvas display->d_forecv.
5135 p
= Layer2Window(D_forecv
->c_layer
);
5136 SetCanvasWindow(D_forecv
, wi
);
5138 WindowChanged(p
, 'u');
5140 WindowChanged(wi
, 'u');
5141 flayer
= D_forecv
->c_layer
;
5142 /* Activate called afterwards, so no RefreshHStatus needed */
5146 /*****************************************************************/
5149 * Activate - make fore window active
5150 * norefresh = -1 forces a refresh, disregard all_norefresh then.
5156 debug1("Activate(%d)\n", norefresh
);
5161 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
5165 if (MayResizeLayer(D_forecv
->c_layer
))
5166 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, display
);
5172 if (fore
->w_monitor
!= MON_OFF
)
5173 fore
->w_monitor
= MON_ON
;
5174 fore
->w_bell
= BELL_ON
;
5175 WindowChanged(fore
, 'f');
5178 if (ResizeDisplay(fore
->w_width
, fore
->w_height
))
5180 debug2("Cannot resize from (%d,%d)", D_width
, D_height
);
5181 debug2(" to (%d,%d) -> resize window\n", fore
->w_width
, fore
->w_height
);
5182 DoResize(D_width
, D_height
);
5186 Redisplay(norefresh
+ all_norefresh
);
5193 register struct win
**pp
;
5194 int n
= fore
? fore
->w_number
: MAXWIN
;
5195 struct win
*group
= fore
? fore
->w_group
: 0;
5197 for (pp
= fore
? wtab
+ n
+ 1 : wtab
; pp
!= wtab
+ n
; pp
++)
5199 if (pp
== wtab
+ MAXWIN
)
5203 if (!fore
|| group
== (*pp
)->w_group
)
5215 register struct win
**pp
;
5216 int n
= fore
? fore
->w_number
: -1;
5217 struct win
*group
= fore
? fore
->w_group
: 0;
5219 for (pp
= wtab
+ n
- 1; pp
!= wtab
+ n
; pp
--)
5222 pp
= wtab
+ MAXWIN
- 1;
5225 if (!fore
|| group
== (*pp
)->w_group
)
5237 char *m
= "No other window.";
5238 if (windows
&& (fore
== 0 || windows
->w_next
))
5242 Msg(0, "No window available");
5245 Msg(0, m
, fore
->w_number
); /* other arg for nethack */
5250 UpdateLayoutCanvas(cv
, wi
)
5254 for (; cv
; cv
= cv
->c_slnext
)
5256 if (cv
->c_layer
&& Layer2Window(cv
->c_layer
) == wi
)
5258 /* A simplistic version of SetCanvasWindow(cv, 0) */
5259 struct layer
*l
= cv
->c_layer
;
5261 if (l
->l_cvlist
== 0 && (wi
== 0 || l
!= wi
->w_savelayer
))
5265 if (l
->l_cvlist
!= cv
)
5267 cv
->c_lnext
= l
->l_cvlist
;
5271 /* Do not end here. Multiple canvases can have the same window */
5275 UpdateLayoutCanvas(cv
->c_slperp
, wi
);
5283 struct win
**pp
, *p
;
5289 * Remove window from linked list.
5291 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5297 wtab
[wi
->w_number
] = 0;
5306 * switch to different window on all canvases
5308 for (display
= displays
; display
; display
= display
->d_next
)
5311 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5313 if (Layer2Window(cv
->c_layer
) != wi
)
5315 /* switch to other window */
5316 SetCanvasWindow(cv
, FindNiceWindow(D_other
, 0));
5322 if (wi
->w_zdisplay
== display
)
5325 D_readev
.condpos
= D_readev
.condneg
= 0;
5332 /* do the same for the layouts */
5333 for (lay
= layouts
; lay
; lay
= lay
->lay_next
)
5334 UpdateLayoutCanvas(&lay
->lay_canvas
, wi
);
5337 WindowChanged((struct win
*)0, 'w');
5338 WindowChanged((struct win
*)0, 'W');
5339 WindowChanged((struct win
*)0, 0);
5348 if ((fore
->w_log
!= 0) == on
)
5350 if (display
&& !*rc_name
)
5351 Msg(0, "You are %s logging.", on
? "already" : "not");
5354 if (fore
->w_log
!= 0)
5356 Msg(0, "Logfile \"%s\" closed.", fore
->w_log
->name
);
5357 logfclose(fore
->w_log
);
5359 WindowChanged(fore
, 'f');
5362 if (DoStartLog(fore
, buf
, sizeof(buf
)))
5364 Msg(errno
, "Error opening logfile \"%s\"", buf
);
5367 if (ftell(fore
->w_log
->fp
) == 0)
5368 Msg(0, "Creating logfile \"%s\".", fore
->w_log
->name
);
5370 Msg(0, "Appending to logfile \"%s\".", fore
->w_log
->name
);
5371 WindowChanged(fore
, 'f');
5375 AddWindows(buf
, len
, flags
, where
)
5381 register char *s
, *ss
;
5382 register struct win
**pp
, *p
;
5387 if ((flags
& 8) && where
< 0)
5392 for (pp
= ((flags
& 4) && where
>= 0) ? wtab
+ where
+ 1: wtab
; pp
< wtab
+ MAXWIN
; pp
++)
5395 if (pp
- wtab
== where
&& ss
== buf
)
5399 if ((flags
& 1) && display
&& p
== D_fore
)
5401 if (D_fore
&& D_fore
->w_group
!= p
->w_group
)
5408 if (s
- buf
+ l
> len
- 24)
5410 if (s
> buf
|| (flags
& 4))
5415 if (p
->w_number
== where
)
5421 if (!(flags
& 4) || where
< 0 || ((flags
& 4) && where
< p
->w_number
))
5423 if (p
->w_monitor
== MON_DONE
&& renditions
[REND_MONITOR
] != -1)
5424 rend
= renditions
[REND_MONITOR
];
5425 else if ((p
->w_bell
== BELL_DONE
|| p
->w_bell
== BELL_FOUND
) && renditions
[REND_BELL
] != -1)
5426 rend
= renditions
[REND_BELL
];
5429 AddWinMsgRend(s
, rend
);
5430 sprintf(s
, "%d", p
->w_number
);
5432 if (display
&& p
== D_fore
)
5436 if (display
&& p
== D_other
)
5438 s
= AddWindowFlags(s
, len
, p
);
5444 AddWinMsgRend(s
, -1);
5451 AddWindowFlags(buf
, len
, p
)
5457 if (p
== 0 || len
< 12)
5463 if (display
&& p
== D_fore
)
5465 if (display
&& p
== D_other
)
5468 if (p
->w_layer
.l_cvlist
&& p
->w_layer
.l_cvlist
->c_lnext
)
5470 if (p
->w_monitor
== MON_DONE
5472 && (ACLBYTE(p
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5476 if (p
->w_bell
== BELL_DONE
)
5479 if (p
->w_slot
!= (slot_t
) 0 && p
->w_slot
!= (slot_t
) -1)
5487 if (p
->w_ptyfd
< 0 && p
->w_type
!= W_TYPE_GROUP
)
5494 AddOtherUsers(buf
, len
, p
)
5499 struct display
*d
, *olddisplay
= display
;
5505 for (display
= displays
; display
; display
= display
->d_next
)
5507 if (olddisplay
&& D_user
== olddisplay
->d_user
)
5509 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5510 if (Layer2Window(cv
->c_layer
) == p
)
5514 for (d
= displays
; d
&& d
!= display
; d
= d
->d_next
)
5515 if (D_user
== d
->d_user
)
5517 if (d
&& d
!= display
)
5519 if (len
> 1 && s
!= buf
)
5524 l
= strlen(D_user
->u_name
);
5527 strcpy(s
, D_user
->u_name
);
5532 display
= olddisplay
;
5545 if (where
== -1 && D_fore
)
5546 where
= D_fore
->w_number
;
5547 ss
= AddWindows(buf
, sizeof(buf
), 0, where
);
5548 s
= buf
+ strlen(buf
);
5549 if (ss
- buf
> D_width
/ 2)
5552 if (s
- ss
< D_width
)
5568 register struct win
*wp
= fore
;
5573 Msg(0, "(%d,%d)/(%d,%d) no window", D_x
+ 1, D_y
+ 1, D_width
, D_height
);
5577 if (buf
< (p
+= GetAnsiStatus(wp
, p
)))
5579 sprintf(p
, "(%d,%d)/(%d,%d)",
5580 wp
->w_x
+ 1, wp
->w_y
+ 1, wp
->w_width
, wp
->w_height
);
5582 sprintf(p
+= strlen(p
), "+%d", wp
->w_histheight
);
5584 sprintf(p
+= strlen(p
), " %c%sflow",
5585 (wp
->w_flow
& FLOW_NOW
) ? '+' : '-',
5586 (wp
->w_flow
& FLOW_AUTOFLAG
) ? "" :
5587 ((wp
->w_flow
& FLOW_AUTO
) ? "(+)" : "(-)"));
5588 if (!wp
->w_wrap
) sprintf(p
+= strlen(p
), " -wrap");
5589 if (wp
->w_insert
) sprintf(p
+= strlen(p
), " ins");
5590 if (wp
->w_origin
) sprintf(p
+= strlen(p
), " org");
5591 if (wp
->w_keypad
) sprintf(p
+= strlen(p
), " app");
5592 if (wp
->w_log
) sprintf(p
+= strlen(p
), " log");
5593 if (wp
->w_monitor
!= MON_OFF
5595 && (ACLBYTE(wp
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5598 sprintf(p
+= strlen(p
), " mon");
5599 if (wp
->w_mouse
) sprintf(p
+= strlen(p
), " mouse");
5601 if (wp
->w_bce
) sprintf(p
+= strlen(p
), " bce");
5603 if (!wp
->w_c1
) sprintf(p
+= strlen(p
), " -c1");
5604 if (wp
->w_norefresh
) sprintf(p
+= strlen(p
), " nored");
5609 if (wp
->w_encoding
&& (display
== 0 || D_encoding
!= wp
->w_encoding
|| EncodingDefFont(wp
->w_encoding
) <= 0))
5612 strcpy(p
, EncodingName(wp
->w_encoding
));
5616 if (wp
->w_encoding
!= UTF8
)
5619 if (D_CC0
|| (D_CS0
&& *D_CS0
))
5623 sprintf(p
, " G%c", wp
->w_Charset
+ '0');
5624 if (wp
->w_FontE
>= ' ')
5629 p
[4] = wp
->w_FontE
^ 0x40;
5636 sprintf(p
++, " G%c%c[", wp
->w_Charset
+ '0', wp
->w_CharsetR
+ '0');
5638 sprintf(p
, " G%c[", wp
->w_Charset
+ '0');
5640 for (i
= 0; i
< 4; i
++)
5642 if (wp
->w_charsets
[i
] == ASCII
)
5644 else if (wp
->w_charsets
[i
] >= ' ')
5645 *p
++ = wp
->w_charsets
[i
];
5649 *p
++ = wp
->w_charsets
[i
] ^ 0x40;
5657 if (wp
->w_type
== W_TYPE_PLAIN
)
5659 /* add info about modem control lines */
5661 TtyGetModemStatus(wp
->w_ptyfd
, p
);
5663 #ifdef BUILTIN_TELNET
5664 else if (wp
->w_type
== W_TYPE_TELNET
)
5667 TelStatus(wp
, p
, sizeof(buf
) - 1 - (p
- buf
));
5670 Msg(0, "%s %d(%s)", buf
, wp
->w_number
, wp
->w_title
);
5680 sprintf(p
, "(%d,%d)", D_width
, D_height
),
5686 strcpy(p
, EncodingName(D_encoding
));
5692 strcpy(p
, " xterm");
5698 strcpy(p
, " color");
5705 strcpy(p
, " iso2022");
5708 else if (D_CS0
&& *D_CS0
)
5710 strcpy(p
, " altchar");
5718 AKAfin(buf
, len
, data
)
5721 char *data
; /* dummy */
5725 ChangeAKA(fore
, buf
, strlen(buf
));
5733 Input("Set window's title to: ", sizeof(fore
->w_akabuf
) - 1, INP_COOKED
, AKAfin
, NULL
, 0);
5739 if ((*(unsigned char *)s
& 0x7f) < 0x20 || *s
== 0x7f)
5743 LayProcess(&ss
, &n
);
5748 Colonfin(buf
, len
, data
)
5751 char *data
; /* dummy */
5756 if (buf
[len
] == '\t')
5759 int l
= 0, r
= RC_LAST
;
5760 int showmessage
= 0;
5763 while (*s
&& s
- buf
< len
)
5767 /* Showing a message when there's no hardstatus or caption cancels the input */
5769 (captionalways
|| D_has_hstatus
== HSTATUS_LASTLINE
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
)))
5775 x
= strncmp(buf
, comms
[m
].name
, len
);
5783 for (l
= m
- 1; l
>= 0 && strncmp(buf
, comms
[l
].name
, len
) == 0; l
--)
5785 for (m
= ++l
; m
<= r
&& strncmp(buf
, comms
[m
].name
, len
) == 0 && s
- mbuf
< sizeof(mbuf
); m
++)
5786 s
+= snprintf(s
, sizeof(mbuf
) - (s
- mbuf
), " %s", comms
[m
].name
);
5790 Msg(0, "Possible commands:%s", mbuf
);
5795 len
= snprintf(mbuf
, sizeof(mbuf
), "%s \t", comms
[l
].name
+ len
);
5796 if (len
> 0 && len
< sizeof(mbuf
))
5797 LayProcess(&s
, &len
);
5802 if (l
> r
&& showmessage
)
5803 Msg(0, "No commands matching '%*s'", len
, buf
);
5807 if (!len
|| buf
[len
])
5810 len
= strlen(buf
) + 1;
5811 if (len
> (int)sizeof(mbuf
))
5815 bcopy(buf
, mbuf
, len
);
5816 RcLine(mbuf
, sizeof mbuf
);
5821 SelectFin(buf
, len
, data
)
5824 char *data
; /* dummy */
5828 if (!len
|| !display
)
5830 if (len
== 1 && *buf
== '-')
5832 SetForeWindow((struct win
*)0);
5836 if ((n
= WindowByNoN(buf
)) < 0)
5842 SelectLayoutFin(buf
, len
, data
)
5845 char *data
; /* dummy */
5849 if (!len
|| !display
)
5851 if (len
== 1 && *buf
== '-')
5853 LoadLayout((struct layout
*)0, (struct canvas
*)0);
5857 lay
= FindLayout(buf
);
5859 Msg(0, "No such layout\n");
5860 else if (lay
== D_layout
)
5861 Msg(0, "This IS layout %d (%s).\n", lay
->lay_number
, lay
->lay_title
);
5864 LoadLayout(lay
, &D_canvas
);
5873 Input("Switch to window: ", 20, INP_COOKED
, SelectFin
, NULL
, 0);
5876 static char setenv_var
[31];
5880 SetenvFin1(buf
, len
, data
)
5883 char *data
; /* dummy */
5885 if (!len
|| !display
)
5891 SetenvFin2(buf
, len
, data
)
5894 char *data
; /* dummy */
5896 if (!len
|| !display
)
5898 debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var
, buf
);
5899 xsetenv(setenv_var
, buf
);
5907 static char setenv_buf
[50 + sizeof(setenv_var
)]; /* need to be static here, cannot be freed */
5911 strncpy(setenv_var
, arg
, sizeof(setenv_var
) - 1);
5912 sprintf(setenv_buf
, "Enter value for %s: ", setenv_var
);
5913 Input(setenv_buf
, 30, INP_COOKED
, SetenvFin2
, NULL
, 0);
5916 Input("Setenv: Enter variable name: ", 30, INP_COOKED
, SetenvFin1
, NULL
, 0);
5920 * the following options are understood by this parser:
5921 * -f, -f0, -f1, -fy, -fa
5922 * -t title, -T terminal-type, -h height-of-scrollback,
5923 * -ln, -l0, -ly, -l1, -l
5930 struct NewWindow nwin
;
5935 while (av
&& *av
&& av
[0][0] == '-')
5937 if (av
[0][1] == '-')
5949 nwin
.flowflag
= FLOW_NOW
* 0;
5954 nwin
.flowflag
= FLOW_NOW
* 1;
5957 nwin
.flowflag
= FLOW_AUTOFLAG
;
5963 case 't': /* no more -k */
5965 nwin
.aka
= &av
[0][2];
5973 nwin
.term
= &av
[0][2];
5981 nwin
.histheight
= atoi(av
[0] + 2);
5983 nwin
.histheight
= atoi(*av
);
6012 nwin
.monitor
= MON_ON
;
6018 Msg(0, "%s: screen: invalid option -%c.", fn
, av
[0][1]);
6024 if (av
&& *av
&& IsNumColon(*av
, 10, buf
, sizeof(buf
)))
6029 if (num
< 0 || num
> MAXWIN
- 1)
6031 Msg(0, "%s: illegal screen number %d.", fn
, num
);
6041 nwin
.aka
= Filename(*av
);
6048 * CompileKeys must be called before Markroutine is first used.
6049 * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
6051 * s is an ascii string in a termcap-like syntax. It looks like
6052 * "j=u:k=d:l=r:h=l: =.:" and so on...
6053 * this example rebinds the cursormovement to the keys u (up), d (down),
6054 * l (left), r (right). placing a mark will now be done with ".".
6057 CompileKeys(s
, sl
, array
)
6060 unsigned char *array
;
6063 unsigned char key
, value
;
6067 for (i
= 0; i
< 256; i
++)
6071 debug1("CompileKeys: '%s'\n", s
);
6074 key
= *(unsigned char *)s
++;
6075 if (*s
!= '=' || sl
< 3)
6082 value
= *(unsigned char *)s
++;
6085 while (*s
== '=' && sl
>= 2);
6094 #endif /* COPY_PASTE */
6097 * Asynchronous input functions
6100 #if defined(DETACH) && defined(POW_DETACH)
6102 pow_detach_fn(buf
, len
, data
)
6105 char *data
; /* dummy */
6107 debug("pow_detach_fn called\n");
6113 if (ktab
[(int)(unsigned char)*buf
].nr
!= RC_POW_DETACH
)
6116 write(D_userfd
, "\007", 1);
6117 Msg(0, "Detach aborted.");
6122 #endif /* POW_DETACH */
6126 copy_reg_fn(buf
, len
, data
)
6129 char *data
; /* dummy */
6131 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6142 if (D_user
->u_plop
.len
)
6144 if ((pp
->buf
= (char *)malloc(D_user
->u_plop
.len
)) == NULL
)
6149 bcopy(D_user
->u_plop
.buf
, pp
->buf
, D_user
->u_plop
.len
);
6151 pp
->len
= D_user
->u_plop
.len
;
6153 pp
->enc
= D_user
->u_plop
.enc
;
6155 Msg(0, "Copied %d characters into register %c", D_user
->u_plop
.len
, *buf
);
6159 ins_reg_fn(buf
, len
, data
)
6162 char *data
; /* dummy */
6164 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6172 return; /* Input() should not call us w/o fore, but you never know... */
6174 Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
6177 MakePaster(&fore
->w_paster
, pp
->buf
, pp
->len
, 0);
6180 Msg(0, "Empty register.");
6182 #endif /* COPY_PASTE */
6185 process_fn(buf
, len
, data
)
6188 char *data
; /* dummy */
6190 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6199 ProcessInput(pp
->buf
, pp
->len
);
6202 Msg(0, "Empty register.");
6206 confirm_fn(buf
, len
, data
)
6213 if (len
|| (*buf
!= 'y' && *buf
!= 'Y'))
6218 act
.nr
= *(int *)data
;
6227 struct acluser
**up
;
6229 char pw1
[130]; /* FreeBSD crypts to 128 bytes */
6234 su_fin(buf
, len
, data
)
6239 struct inputsu
*i
= (struct inputsu
*)data
;
6244 { p
= i
->name
; l
= sizeof(i
->name
) - 1; }
6246 { strcpy(p
= i
->pw1
, "\377"); l
= sizeof(i
->pw1
) - 1; }
6248 { strcpy(p
= i
->pw2
, "\377"); l
= sizeof(i
->pw2
) - 1; }
6250 strncpy(p
, buf
, 1 + (l
< len
) ? l
: len
);
6252 Input("Screen User: ", sizeof(i
->name
) - 1, INP_COOKED
, su_fin
, (char *)i
, 0);
6254 Input("User's UNIX Password: ", sizeof(i
->pw1
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6256 Input("User's Screen Password: ", sizeof(i
->pw2
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6259 if ((p
= DoSu(i
->up
, i
->name
, i
->pw2
, i
->pw1
)))
6266 InputSu(w
, up
, name
)
6268 struct acluser
**up
;
6273 if (!(i
= (struct inputsu
*)calloc(1, sizeof(struct inputsu
))))
6278 su_fin(name
, (int)strlen(name
), (char *)i
); /* can also initialise stuff */
6280 su_fin((char *)0, 0, (char *)i
);
6283 #endif /* MULTIUSER */
6288 pass1(buf
, len
, data
)
6293 struct acluser
*u
= (struct acluser
*)data
;
6298 if (u
->u_password
!= NullStr
)
6299 free((char *)u
->u_password
);
6300 u
->u_password
= SaveStr(buf
);
6301 bzero(buf
, strlen(buf
));
6302 Input("Retype new password:", 100, INP_NOECHO
, pass2
, data
, 0);
6306 pass2(buf
, len
, data
)
6313 struct acluser
*u
= (struct acluser
*)data
;
6316 if (!buf
|| strcmp(u
->u_password
, buf
))
6318 Msg(0, "[ Passwords don't match - checking turned off ]");
6319 if (u
->u_password
!= NullStr
)
6321 bzero(u
->u_password
, strlen(u
->u_password
));
6322 free((char *)u
->u_password
);
6324 u
->u_password
= NullStr
;
6326 else if (u
->u_password
[0] == '\0')
6328 Msg(0, "[ No password - no secure ]");
6330 bzero(buf
, strlen(buf
));
6333 if (u
->u_password
!= NullStr
)
6335 for (st
= 0; st
< 2; st
++)
6336 salt
[st
] = 'A' + (int)((time(0) >> 6 * st
) % 26);
6338 buf
= crypt(u
->u_password
, salt
);
6339 bzero(u
->u_password
, strlen(u
->u_password
));
6340 free((char *)u
->u_password
);
6341 u
->u_password
= SaveStr(buf
);
6342 bzero(buf
, strlen(buf
));
6345 UserFreeCopyBuffer(u
);
6346 u
->u_plop
.len
= strlen(u
->u_password
);
6350 if (!(u
->u_plop
.buf
= SaveStr(u
->u_password
)))
6353 D_user
->u_plop
.len
= 0;
6356 Msg(0, "[ Password moved into copybuffer ]");
6357 #else /* COPY_PASTE */
6358 Msg(0, "[ Crypted password is \"%s\" ]", u
->u_password
);
6359 #endif /* COPY_PASTE */
6362 #endif /* PASSWORD */
6369 for (i
= 0; i
< MAX_DIGRAPH
&& digraphs
[i
].d
[0]; i
++)
6370 if ((digraphs
[i
].d
[0] == (unsigned char)buf
[0] && digraphs
[i
].d
[1] == (unsigned char)buf
[1]) ||
6371 (digraphs
[i
].d
[0] == (unsigned char)buf
[1] && digraphs
[i
].d
[1] == (unsigned char)buf
[0]))
6377 digraph_fn(buf
, len
, data
)
6380 char *data
; /* dummy */
6387 buf
[len
+ 1] = ch
; /* so we can restore it later */
6388 if (ch
< ' ' || ch
== '\177')
6390 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6394 if ((ch
< '0' || ch
> '9') && (ch
< 'a' || ch
> 'f') && (ch
< 'A' || ch
> 'F'))
6396 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6399 if (len
== (*buf
== 'U' ? 5 : 3))
6403 if (len
&& *buf
== '0')
6405 if (ch
< '0' || ch
> '7')
6407 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6422 buf
[len
] = buf
[len
+ 1]; /* stored above */
6427 if (!parse_input_int(buf
, len
, &x
))
6429 i
= digraph_find(buf
);
6430 if ((x
= digraphs
[i
].value
) <= 0)
6432 Msg(0, "Unknown digraph");
6439 if (flayer
->l_encoding
== UTF8
)
6440 i
= ToUtf8(buf
, x
); /* buf is big enough for all UTF-8 codes */
6443 LayProcess(&buf
, &i
);
6454 debug1("StuffKey #%d", i
);
6457 debug1(" - %s", term
[i
+ T_CAPS
].tcname
);
6460 if (i
< KMAP_KEYS
&& D_ESCseen
)
6462 struct action
*act
= &D_ESCseen
[i
+ 256];
6463 if (act
->nr
!= RC_ILLEGAL
)
6466 DoAction(act
, i
+ 256);
6472 if (i
>= T_CURSOR
- T_CAPS
&& i
< T_KEYPAD
- T_CAPS
&& D_cursorkeys
)
6473 i
+= T_OCAPS
- T_CURSOR
;
6474 else if (i
>= T_KEYPAD
- T_CAPS
&& i
< T_OCAPS
- T_CAPS
&& D_keypad
)
6475 i
+= T_OCAPS
- T_CURSOR
;
6476 debug1(" - action %d\n", i
);
6477 flayer
= D_forecv
->c_layer
;
6481 if (InMark() || InInput() || InWList())
6482 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &mmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].mm
;
6484 if ((!act
|| act
->nr
== RC_ILLEGAL
) && !D_mapdefault
)
6485 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &umtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].um
;
6486 if (!act
|| act
->nr
== RC_ILLEGAL
)
6487 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &dmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].dm
;
6489 if (discard
&& (!act
|| act
->nr
!= RC_COMMAND
))
6496 if (act
== 0 || act
->nr
== RC_ILLEGAL
)
6510 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6511 if (Layer2Window(cv
->c_layer
) == wi
)
6517 FindNiceWindow(wi
, presel
)
6523 debug2("FindNiceWindow %d %s\n", wi
? wi
->w_number
: -1 , presel
? presel
: "NULL");
6526 i
= WindowByNoN(presel
);
6533 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6536 if (!wi
|| (IsOnDisplay(wi
) && !presel
))
6538 /* try to get another window */
6541 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6542 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6545 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6546 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6549 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6550 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6553 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6554 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6558 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6559 if (!wi
->w_layer
.l_cvlist
)
6562 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6563 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
))
6567 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6575 /* sorted list of all commands */
6576 static struct comm
**commtab
;
6577 static int ncommtab
;
6582 void (*hand
) __P((struct comm
*, char **, int));
6585 for (n
= 0; cos
[n
].name
; n
++)
6590 commtab
= (struct commt
*)realloc(commtab
, sizeof(*commtab
) * (ncommtab
+ n
));
6592 commtab
= (struct commt
*)malloc(sizeof(*commtab
) * (ncommtab
+ n
));
6595 for (i
= 0; i
< n
; i
++)
6597 for (j
= 0; j
< ncommtab
; j
++)
6599 r
= strcmp(cos
[i
].name
, commtab
[j
]->name
);
6601 Panic(0, "Duplicate command: %s\n", cos
[i
].name
);
6605 for (r
= ncommtab
; r
> j
; r
--)
6606 commtab
[r
] = commtab
[r
- 1];
6607 commtab
[j
] = cos
+ i
;
6608 cos
[i
].handler
= hand
;
6609 bzero(cos
[i
].userbits
, sizeof(cos
[i
].userbits
));
6618 int x
, m
, l
= 0, r
= ncommtab
- 1;
6622 x
= strcmp(str
, commtab
[m
]->name
);
6636 CalcSlicePercent(cv
, percent
)
6641 if (!cv
|| !cv
->c_slback
)
6643 up
= CalcSlicePercent(cv
->c_slback
->c_slback
, percent
);
6645 for (cv
= cv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6646 wsum
+= cv
->c_slweight
;
6649 return (up
* w
) / wsum
;
6653 ChangeCanvasSize(fcv
, abs
, diff
, gflag
, percent
)
6654 struct canvas
*fcv
; /* make this canvas bigger */
6655 int abs
; /* mode: 0:rel 1:abs 2:max */
6656 int diff
; /* change this much */
6657 int gflag
; /* go up if neccessary */
6661 int done
, have
, m
, dir
;
6663 debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs
, diff
, percent
);
6664 if (abs
== 0 && diff
== 0)
6669 fcv
->c_slweight
= 0;
6672 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6674 fcv
->c_slweight
= 1;
6675 cv
= fcv
->c_slback
->c_slback
;
6676 if (gflag
&& cv
&& cv
->c_slback
)
6677 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6685 if (percent
&& diff
> percent
)
6691 for (cv
= fcv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6692 wsum
+= cv
->c_slweight
;
6695 up
= gflag
? CalcSlicePercent(fcv
->c_slback
->c_slback
, percent
) : percent
;
6696 debug3("up=%d, wsum=%d percent=%d\n", up
, wsum
, percent
);
6699 int scale
= wsum
< 10 ? 1000 : 100;
6700 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6701 cv
->c_slweight
*= scale
;
6703 debug1("scaled wsum to %d\n", wsum
);
6705 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6709 cv
->c_slweight
= (cv
->c_slweight
* up
) / percent
;
6710 if (cv
->c_slweight
== 0)
6713 debug1(" - weight %d\n", cv
->c_slweight
);
6715 diff
= (diff
* wsum
) / percent
;
6721 if (abs
&& diff
== (fcv
->c_slorient
== SLICE_VERT
? fcv
->c_ye
- fcv
->c_ys
+ 2 : fcv
->c_xe
- fcv
->c_xs
+ 2))
6723 /* fix weights to real size (can't be helped, sorry) */
6724 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6726 cv
->c_slweight
= cv
->c_slorient
== SLICE_VERT
? cv
->c_ye
- cv
->c_ys
+ 2 : cv
->c_xe
- cv
->c_xs
+ 2;
6727 debug1(" - weight %d\n", cv
->c_slweight
);
6731 diff
= diff
- fcv
->c_slweight
;
6732 debug1("diff = %d\n", diff
);
6737 cv
= fcv
->c_slnext
? fcv
->c_slnext
: fcv
->c_slprev
;
6738 fcv
->c_slweight
+= diff
;
6739 cv
->c_slweight
-= diff
;
6744 for (cv
= fcv
->c_slnext
; diff
> 0; cv
= dir
> 0 ? cv
->c_slnext
: cv
->c_slprev
)
6748 debug1("reached end, dir is %d\n", dir
);
6758 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 : 2;
6759 debug2("min is %d, have %d\n", m
, cv
->c_slweight
);
6760 if (cv
->c_slweight
> m
)
6762 have
= cv
->c_slweight
- m
;
6765 debug1("subtract %d\n", have
);
6766 cv
->c_slweight
-= have
;
6773 /* need more room! */
6774 cv
= fcv
->c_slback
->c_slback
;
6775 if (cv
&& cv
->c_slback
)
6776 done
+= ChangeCanvasSize(fcv
->c_slback
->c_slback
, 0, diff
, gflag
, percent
);
6778 fcv
->c_slweight
+= done
;
6779 debug1("ChangeCanvasSize returns %d\n", done
);
6787 struct canvas
*cv
, *mcv
= 0;
6790 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6792 /* ye + 1 because of caption line */
6793 if (x
>= cv
->c_xs
&& x
<= cv
->c_xe
&& y
>= cv
->c_ys
&& y
<= cv
->c_ye
+ 1)
6798 if (x
>= D_forecv
->c_xs
&& x
<= D_forecv
->c_xe
)
6800 if (x
< cv
->c_xs
|| x
> cv
->c_xe
)
6802 if (y
< D_forecv
->c_ys
&& y
< cv
->c_ys
)
6804 if (y
> D_forecv
->c_ye
+ 1 && y
> cv
->c_ye
+ 1)
6808 if (y
> cv
->c_ye
+ 1)
6809 m
= y
- (cv
->c_ye
+ 1);
6811 if (y
>= D_forecv
->c_ys
&& y
<= D_forecv
->c_ye
+ 1)
6813 if (y
< cv
->c_ys
|| y
> cv
->c_ye
+ 1)
6815 if (x
< D_forecv
->c_xs
&& x
< cv
->c_xs
)
6817 if (x
> D_forecv
->c_xe
&& x
> cv
->c_xe
)
6824 if (m
&& (!mm
|| m
< mm
))
6830 return mcv
? mcv
: D_forecv
;
6834 ResizeRegions(arg
, flags
)
6840 int gflag
= 0, abs
= 0, percent
= 0;
6846 if (D_forecv
->c_slorient
== SLICE_UNKN
)
6848 Msg(0, "resize: need more than one region");
6851 gflag
= flags
& RESIZE_FLAG_L
? 0 : 1;
6852 orient
|= flags
& RESIZE_FLAG_H
? SLICE_HORI
: 0;
6853 orient
|= flags
& RESIZE_FLAG_V
? SLICE_VERT
: 0;
6855 orient
= D_forecv
->c_slorient
;
6859 /* make all regions the same height */
6860 struct canvas
*cv
= gflag
? &D_canvas
: D_forecv
->c_slback
;
6861 if (cv
->c_slperp
->c_slorient
& orient
)
6862 EqualizeCanvas(cv
->c_slperp
, gflag
);
6863 /* can't use cv->c_slorient directly as it can be D_canvas */
6864 if ((cv
->c_slperp
->c_slorient
^ (SLICE_HORI
^ SLICE_VERT
)) & orient
)
6869 EqualizeCanvas(cv
->c_slperp
, gflag
);
6872 EqualizeCanvas(cv
, gflag
);
6875 RecreateCanvasChain();
6876 RethinkDisplayViewports();
6877 ResizeLayersToCanvases();
6880 if (!strcmp(arg
, "min") || !strcmp(arg
, "0"))
6885 else if (!strcmp(arg
, "max") || !strcmp(arg
, "_"))
6892 if (l
> 0 && arg
[l
- 1] == '%')
6895 diff
= atoi(arg
+ 1);
6896 else if (*arg
== '-')
6897 diff
= -atoi(arg
+ 1);
6900 diff
= atoi(arg
); /* +1 because of caption line */
6903 abs
= diff
== 0 ? 2 : 1;
6909 diff
= diff
* percent
/ 100;
6911 if (cv
->c_slorient
& orient
)
6912 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6913 if (cv
->c_slback
->c_slorient
& orient
)
6914 ChangeCanvasSize(cv
->c_slback
, abs
, diff
, gflag
, percent
);
6916 ResizeCanvas(&D_canvas
);
6917 RecreateCanvasChain();
6918 RethinkDisplayViewports();
6919 ResizeLayersToCanvases();
6926 if (siz
+ diff
> dsize
- (nreg
- 1) * 2 - 1)
6927 diff
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6928 if (diff
== 0 || siz
+ diff
< 1)
6933 if (D_forecv
->c_next
)
6935 D_forecv
->c_ye
+= diff
;
6936 D_forecv
->c_next
->c_ys
+= diff
;
6937 D_forecv
->c_next
->c_yoff
+= diff
;
6941 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6942 if (cv
->c_next
== D_forecv
)
6946 D_forecv
->c_ys
-= diff
;
6947 D_forecv
->c_yoff
-= diff
;
6952 int s
, i
= 0, found
= 0, di
= diff
, d2
;
6953 s
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6954 for (cv
= D_cvlist
; cv
; i
= cv
->c_ye
+ 2, cv
= cv
->c_next
)
6958 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) + diff
;
6959 cv
->c_yoff
-= cv
->c_ys
- i
;
6964 s
-= cv
->c_ye
- cv
->c_ys
;
6972 d2
= di
> cv
->c_ye
- cv
->c_ys
? cv
->c_ye
- cv
->c_ys
: di
;
6974 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) - d2
;
6975 cv
->c_yoff
-= cv
->c_ys
- i
;
6979 RethinkDisplayViewports();
6980 ResizeLayersToCanvases();
6985 ResizeFin(buf
, len
, data
)
6991 int flags
= *(int *)data
;
6992 ch
= ((unsigned char *)buf
)[len
];
6995 ResizeRegions(buf
, flags
);
6999 flags
^= RESIZE_FLAG_H
;
7001 flags
^= RESIZE_FLAG_V
;
7003 flags
|= RESIZE_FLAG_H
|RESIZE_FLAG_V
;
7005 flags
^= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
7007 flags
^= RESIZE_FLAG_L
;
7010 inp_setprompt(resizeprompts
[flags
], NULL
);
7011 *(int *)data
= flags
;
7016 SetForeCanvas(d
, cv
)
7020 struct display
*odisplay
= display
;
7021 if (d
->d_forecv
== cv
)
7026 if ((focusminwidth
&& (focusminwidth
< 0 || D_forecv
->c_xe
- D_forecv
->c_xs
+ 1 < focusminwidth
)) ||
7027 (focusminheight
&& (focusminheight
< 0 || D_forecv
->c_ye
- D_forecv
->c_ys
+ 1 < focusminheight
)))
7029 ResizeCanvas(&D_canvas
);
7030 RecreateCanvasChain();
7031 RethinkDisplayViewports();
7032 ResizeLayersToCanvases(); /* redisplays */
7034 fore
= D_fore
= Layer2Window(D_forecv
->c_layer
);
7035 if (D_other
== fore
)
7037 flayer
= D_forecv
->c_layer
;
7039 if (D_xtermosc
[2] || D_xtermosc
[3])
7050 flayer
= D_forecv
->c_layer
;
7051 CV_CALL(D_forecv
, LayRestore();LaySetCursor());
7052 WindowChanged(0, 'F');
7065 p
= Layer2Window(D_forecv
->c_layer
);
7066 for (i
= 3; i
>=0; i
--)
7067 SetXtermOSC(i
, p
? p
->w_xtermosc
[i
] : 0);
7072 ParseAttrColor(s1
, s2
, msgok
)
7084 while (*ss
&& *ss
!= ' ')
7088 if (*s
&& (s2
|| *ss
|| !((*s
>= 'a' && *s
<= 'z') || (*s
>= 'A' && *s
<= 'Z') || *s
== '.')))
7090 int mode
= 0, n
= 0;
7108 if (*s
>= '0' && *s
<= '9')
7111 if (*s
>= '0' && *s
<= '9')
7112 n
= n
* 16 + (*s
++ - '0');
7113 else if (*s
>= 'a' && *s
<= 'f')
7114 n
= n
* 16 + (*s
++ - ('a' - 10));
7115 else if (*s
>= 'A' && *s
<= 'F')
7116 n
= n
* 16 + (*s
++ - ('A' - 10));
7117 else if (*s
&& *s
!= ' ')
7120 Msg(0, "Illegal attribute hexchar '%c'", *s
);
7126 while (*s
&& *s
!= ' ')
7143 Msg(0, "Illegal attribute specifier '%c'", *s
);
7149 if (*s
&& *s
!= ' ')
7152 Msg(0, "junk after attribute description: '%c'", *s
);
7164 while (*s
&& *s
== ' ')
7172 Msg(0, "junk after description: '%c'", *s
);
7176 while (*s
&& *s
== ' ')
7183 static char costr
[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
7193 for (j
= 0; j
< 2 && *s
&& *s
!= ' '; j
++)
7195 for (i
= 0; costr
[i
]; i
++)
7201 Msg(0, "illegal color descriptor: '%c'", *s
);
7205 n
= n
<< 4 | (i
& 15);
7208 n
= (n
& 0x20ff) | 0x200;
7212 if ((n
& 0xf00) == 0xf00)
7213 n
^= 0xf00; /* clear superflous bits */
7216 n
^= 0x2400; /* shift bit into right position */
7219 n
|= 0xf0; /* don't change bg color */
7220 if (numco
!= 2 && n
!= 0xff)
7221 n
|= 0x100; /* special invert mode */
7222 if (*s
&& *s
!= ' ')
7225 Msg(0, "junk after color description: '%c'", *s
);
7233 while (*s
&& *s
== ' ')
7238 Msg(0, "junk after description: '%c'", *s
);
7241 debug1("ParseAttrColor %06x\n", r
);
7249 * e just set intensity
7250 * f don't change anything
7251 * Intensity is encoded into bits 17(fg) and 18(bg).
7254 ApplyAttrColor(i
, mc
)
7258 debug1("ApplyAttrColor %06x\n", i
);
7259 mc
->attr
|= i
>> 8 & 255;
7260 mc
->attr
^= i
& 255;
7262 i
= (i
>> 16) ^ 0xff;
7263 if ((i
& 0x100) != 0)
7266 if (mc
->attr
& (A_SO
|A_RV
))
7268 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4) | ((i
& 0x200) << 1) | ((i
& 0x400) >> 1);
7270 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4);
7274 if ((i
& 0x0f) != 0x0f)
7275 mc
->attr
= (mc
->attr
& 0xbf) | ((i
>> 3) & 0x40);
7276 if ((i
& 0xf0) != 0xf0)
7277 mc
->attr
= (mc
->attr
& 0x7f) | ((i
>> 3) & 0x80);
7279 mc
->color
= 0x99 ^ mc
->color
;
7280 if ((i
& 0x0e) == 0x0e)
7281 i
= (i
& 0xf0) | (mc
->color
& 0x0f);
7282 if ((i
& 0xe0) == 0xe0)
7283 i
= (i
& 0x0f) | (mc
->color
& 0xf0);
7284 mc
->color
= 0x99 ^ i
;
7285 debug2("ApplyAttrColor - %02x %02x\n", mc
->attr
, i
);