1 /* Copyright (c) 1993-2002
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Copyright (c) 1987 Oliver Laumann
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program (see the file COPYING); if not, write to the
18 * Free Software Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 ****************************************************************
24 #include <sys/types.h>
28 #if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
33 #include <sys/ioctl.h>
39 /* for solaris 2.1, Unixware (SVR4.2) and possibly others: */
41 # include <sys/stropts.h>
48 extern struct comm comms
[];
50 extern char *RcFileName
, *home
;
51 extern char *BellString
, *ActivityString
, *ShellProg
, *ShellArgs
[];
52 extern char *hstatusstring
, *captionstring
, *timestring
;
53 extern char *wliststr
, *wlisttit
;
54 extern int captionalways
;
55 extern char *hardcopydir
, *screenlogfile
, *logtstamp_string
;
56 extern int log_flush
, logtstamp_on
, logtstamp_after
;
57 extern char *VisualBellString
;
58 extern int VBellWait
, MsgWait
, MsgMinWait
, SilenceWait
;
59 extern char SockPath
[], *SockName
;
60 extern int TtyMode
, auto_detach
, use_altscreen
;
61 extern int iflag
, maxwin
;
62 extern int focusminwidth
, focusminheight
;
63 extern int use_hardstatus
, visual_bell
;
65 extern int attr2color
[][4];
66 extern int nattr2color
;
68 extern int hardstatusemu
;
69 extern char *printcmd
;
70 extern int default_startup
;
71 extern int defobuflimit
;
72 extern int defnonblock
;
73 extern int ZombieKey_destroy
;
74 extern int ZombieKey_resurrect
;
75 extern int ZombieKey_onerror
;
77 extern int defautonuke
;
79 extern int separate_sids
;
80 extern struct NewWindow nwin_default
, nwin_undef
;
82 extern int join_with_cr
;
83 extern int compacthist
;
88 extern unsigned char mark_key_tab
[];
89 extern char *BufferFile
;
92 extern char *BufferFile
, *PowDetachString
;
95 extern struct acluser
*EffectiveAclUser
; /* acl.c */
97 extern struct term term
[]; /* terminal capabilities */
99 extern char *kmapdef
[];
100 extern char *kmapadef
[];
101 extern char *kmapmdef
[];
103 extern struct mchar mchar_so
, mchar_null
;
104 extern int VerboseCreate
;
106 extern char *screenencodings
;
112 static int CheckArgNum
__P((int, char **));
113 static void ClearAction
__P((struct action
*));
114 static void SaveAction
__P((struct action
*, int, char **, int *));
115 static int NextWindow
__P((void));
116 static int PreviousWindow
__P((void));
117 static int MoreWindows
__P((void));
118 static void LogToggle
__P((int));
119 static void ShowInfo
__P((void));
120 static void ShowDInfo
__P((void));
121 static struct win
*WindowByName
__P((char *));
122 static int WindowByNumber
__P((char *));
123 static int ParseOnOff
__P((struct action
*, int *));
124 static int ParseWinNum
__P((struct action
*, int *));
125 static int ParseBase
__P((struct action
*, char *, int *, int, char *));
126 static int ParseNum1000
__P((struct action
*, int *));
127 static char **SaveArgs
__P((char **));
128 static int IsNum
__P((char *, int));
129 static void Colonfin
__P((char *, int, char *));
130 static void InputSelect
__P((void));
131 static void InputSetenv
__P((char *));
132 static void InputAKA
__P((void));
134 static int InputSu
__P((struct win
*, struct acluser
**, char *));
135 static void su_fin
__P((char *, int, char *));
137 static void AKAfin
__P((char *, int, char *));
139 static void copy_reg_fn
__P((char *, int, char *));
140 static void ins_reg_fn
__P((char *, int, char *));
142 static void process_fn
__P((char *, int, char *));
144 static void pass1
__P((char *, int, char *));
145 static void pass2
__P((char *, int, char *));
148 static void pow_detach_fn
__P((char *, int, char *));
150 static void digraph_fn
__P((char *, int, char *));
151 static void confirm_fn
__P((char *, int, char *));
152 static int IsOnDisplay
__P((struct win
*));
153 static void ResizeRegions
__P((char *, int));
154 static void ResizeFin
__P((char *, int, char *));
155 static struct action
*FindKtab
__P((char *, int));
156 static void SelectFin
__P((char *, int, char *));
157 static void SelectLayoutFin
__P((char *, int, char *));
160 extern struct layer
*flayer
;
161 extern struct display
*display
, *displays
;
162 extern struct win
*fore
, *console_window
, *windows
;
163 extern struct acluser
*users
;
164 extern struct layout
*layouts
, *layout_attach
, layout_last_marker
;
165 extern struct layout
*laytab
[];
167 extern char screenterm
[], HostName
[], version
[];
168 extern struct NewWindow nwin_undef
, nwin_default
;
169 extern struct LayFuncs WinLf
, MarkLf
;
171 extern int Z0width
, Z1width
;
172 extern int real_uid
, real_gid
;
175 extern int nethackflag
;
179 struct win
*wtab
[MAXWIN
]; /* window table, should be dynamic */
183 extern int maxusercount
;
187 struct plop plop_tab
[MAX_PLOP_DEFS
];
190 # define PTYMODE 0622
193 int TtyMode
= PTYMODE
;
194 int hardcopy_append
= 0;
195 int all_norefresh
= 0;
198 char *zmodem_sendcmd
;
199 char *zmodem_recvcmd
;
200 static char *zmodes
[4] = {"off", "auto", "catch", "pass"};
204 struct action idleaction
;
209 struct action ktab
[256 + KMAP_KEYS
]; /* command key translation table */
213 struct action ktab
[256 + KMAP_KEYS
];
215 struct kclass
*kclasses
;
218 struct action umtab
[KMAP_KEYS
+KMAP_AKEYS
];
219 struct action dmtab
[KMAP_KEYS
+KMAP_AKEYS
];
220 struct action mmtab
[KMAP_KEYS
+KMAP_AKEYS
];
221 struct kmap_ext
*kmap_exts
;
223 static int maptimeout
= 300;
227 /* digraph table taken from old vim and rfc1345 */
228 static const unsigned char digraphs
[][3] = {
229 {' ', ' ', 160}, /* */
230 {'N', 'S', 160}, /* */
231 {'~', '!', 161}, /* ¡ */
232 {'!', '!', 161}, /* ¡ */
233 {'!', 'I', 161}, /* ¡ */
234 {'c', '|', 162}, /* ¢ */
235 {'c', 't', 162}, /* ¢ */
236 {'$', '$', 163}, /* £ */
237 {'P', 'd', 163}, /* £ */
238 {'o', 'x', 164}, /* ¤ */
239 {'C', 'u', 164}, /* ¤ */
240 {'C', 'u', 164}, /* ¤ */
241 {'E', 'u', 164}, /* ¤ */
242 {'Y', '-', 165}, /* ¥ */
243 {'Y', 'e', 165}, /* ¥ */
244 {'|', '|', 166}, /* ¦ */
245 {'B', 'B', 166}, /* ¦ */
246 {'p', 'a', 167}, /* § */
247 {'S', 'E', 167}, /* § */
248 {'"', '"', 168}, /* ¨ */
249 {'\'', ':', 168}, /* ¨ */
250 {'c', 'O', 169}, /* © */
251 {'C', 'o', 169}, /* © */
252 {'a', '-', 170}, /* ª */
253 {'<', '<', 171}, /* « */
254 {'-', ',', 172}, /* ¬ */
255 {'N', 'O', 172}, /* ¬ */
256 {'-', '-', 173}, /* */
257 {'r', 'O', 174}, /* ® */
258 {'R', 'g', 174}, /* ® */
259 {'-', '=', 175}, /* ¯ */
260 {'\'', 'm', 175}, /* ¯ */
261 {'~', 'o', 176}, /* ° */
262 {'D', 'G', 176}, /* ° */
263 {'+', '-', 177}, /* ± */
264 {'2', '2', 178}, /* ² */
265 {'2', 'S', 178}, /* ² */
266 {'3', '3', 179}, /* ³ */
267 {'3', 'S', 179}, /* ³ */
268 {'\'', '\'', 180}, /* ´ */
269 {'j', 'u', 181}, /* µ */
270 {'M', 'y', 181}, /* µ */
271 {'p', 'p', 182}, /* ¶ */
272 {'P', 'I', 182}, /* ¶ */
273 {'~', '.', 183}, /* · */
274 {'.', 'M', 183}, /* · */
275 {',', ',', 184}, /* ¸ */
276 {'\'', ',', 184}, /* ¸ */
277 {'1', '1', 185}, /* ¹ */
278 {'1', 'S', 185}, /* ¹ */
279 {'o', '-', 186}, /* º */
280 {'>', '>', 187}, /* » */
281 {'1', '4', 188}, /* ¼ */
282 {'1', '2', 189}, /* ½ */
283 {'3', '4', 190}, /* ¾ */
284 {'~', '?', 191}, /* ¿ */
285 {'?', '?', 191}, /* ¿ */
286 {'?', 'I', 191}, /* ¿ */
287 {'A', '`', 192}, /* À */
288 {'A', '!', 192}, /* À */
289 {'A', '\'', 193}, /* Á */
290 {'A', '^', 194}, /* Â */
291 {'A', '>', 194}, /* Â */
292 {'A', '~', 195}, /* Ã */
293 {'A', '?', 195}, /* Ã */
294 {'A', '"', 196}, /* Ä */
295 {'A', ':', 196}, /* Ä */
296 {'A', '@', 197}, /* Å */
297 {'A', 'A', 197}, /* Å */
298 {'A', 'E', 198}, /* Æ */
299 {'C', ',', 199}, /* Ç */
300 {'E', '`', 200}, /* È */
301 {'E', '!', 200}, /* È */
302 {'E', '\'', 201}, /* É */
303 {'E', '^', 202}, /* Ê */
304 {'E', '>', 202}, /* Ê */
305 {'E', '"', 203}, /* Ë */
306 {'E', ':', 203}, /* Ë */
307 {'I', '`', 204}, /* Ì */
308 {'I', '!', 204}, /* Ì */
309 {'I', '\'', 205}, /* Í */
310 {'I', '^', 206}, /* Î */
311 {'I', '>', 206}, /* Î */
312 {'I', '"', 207}, /* Ï */
313 {'I', ':', 207}, /* Ï */
314 {'D', '-', 208}, /* Ð */
315 {'N', '~', 209}, /* Ñ */
316 {'N', '?', 209}, /* Ñ */
317 {'O', '`', 210}, /* Ò */
318 {'O', '!', 210}, /* Ò */
319 {'O', '\'', 211}, /* Ó */
320 {'O', '^', 212}, /* Ô */
321 {'O', '>', 212}, /* Ô */
322 {'O', '~', 213}, /* Õ */
323 {'O', '?', 213}, /* Õ */
324 {'O', '"', 214}, /* Ö */
325 {'O', ':', 214}, /* Ö */
326 {'/', '\\', 215}, /* × */
327 {'*', 'x', 215}, /* × */
328 {'O', '/', 216}, /* Ø */
329 {'U', '`', 217}, /* Ù */
330 {'U', '!', 217}, /* Ù */
331 {'U', '\'', 218}, /* Ú */
332 {'U', '^', 219}, /* Û */
333 {'U', '>', 219}, /* Û */
334 {'U', '"', 220}, /* Ü */
335 {'U', ':', 220}, /* Ü */
336 {'Y', '\'', 221}, /* Ý */
337 {'I', 'p', 222}, /* Þ */
338 {'T', 'H', 222}, /* Þ */
339 {'s', 's', 223}, /* ß */
340 {'s', '"', 223}, /* ß */
341 {'a', '`', 224}, /* à */
342 {'a', '!', 224}, /* à */
343 {'a', '\'', 225}, /* á */
344 {'a', '^', 226}, /* â */
345 {'a', '>', 226}, /* â */
346 {'a', '~', 227}, /* ã */
347 {'a', '?', 227}, /* ã */
348 {'a', '"', 228}, /* ä */
349 {'a', ':', 228}, /* ä */
350 {'a', 'a', 229}, /* å */
351 {'a', 'e', 230}, /* æ */
352 {'c', ',', 231}, /* ç */
353 {'e', '`', 232}, /* è */
354 {'e', '!', 232}, /* è */
355 {'e', '\'', 233}, /* é */
356 {'e', '^', 234}, /* ê */
357 {'e', '>', 234}, /* ê */
358 {'e', '"', 235}, /* ë */
359 {'e', ':', 235}, /* ë */
360 {'i', '`', 236}, /* ì */
361 {'i', '!', 236}, /* ì */
362 {'i', '\'', 237}, /* í */
363 {'i', '^', 238}, /* î */
364 {'i', '>', 238}, /* î */
365 {'i', '"', 239}, /* ï */
366 {'i', ':', 239}, /* ï */
367 {'d', '-', 240}, /* ð */
368 {'n', '~', 241}, /* ñ */
369 {'n', '?', 241}, /* ñ */
370 {'o', '`', 242}, /* ò */
371 {'o', '!', 242}, /* ò */
372 {'o', '\'', 243}, /* ó */
373 {'o', '^', 244}, /* ô */
374 {'o', '>', 244}, /* ô */
375 {'o', '~', 245}, /* õ */
376 {'o', '?', 245}, /* õ */
377 {'o', '"', 246}, /* ö */
378 {'o', ':', 246}, /* ö */
379 {':', '-', 247}, /* ÷ */
380 {'o', '/', 248}, /* ø */
381 {'u', '`', 249}, /* ù */
382 {'u', '!', 249}, /* ù */
383 {'u', '\'', 250}, /* ú */
384 {'u', '^', 251}, /* û */
385 {'u', '>', 251}, /* û */
386 {'u', '"', 252}, /* ü */
387 {'u', ':', 252}, /* ü */
388 {'y', '\'', 253}, /* ý */
389 {'i', 'p', 254}, /* þ */
390 {'t', 'h', 254}, /* þ */
391 {'y', '"', 255}, /* ÿ */
392 {'y', ':', 255}, /* ÿ */
393 {'"', '[', 196}, /* Ä */
394 {'"', '\\', 214}, /* Ö */
395 {'"', ']', 220}, /* Ü */
396 {'"', '{', 228}, /* ä */
397 {'"', '|', 246}, /* ö */
398 {'"', '}', 252}, /* ü */
399 {'"', '~', 223} /* ß */
402 #define RESIZE_FLAG_H 1
403 #define RESIZE_FLAG_V 2
404 #define RESIZE_FLAG_L 4
406 static char *resizeprompts
[] = {
408 "resize -h # lines: ",
409 "resize -v # lines: ",
410 "resize -b # lines: ",
411 "resize -l # lines: ",
412 "resize -l -h # lines: ",
413 "resize -l -v # lines: ",
414 "resize -l -b # lines: ",
422 register unsigned int i
;
427 for (i
= 0; i
< sizeof(ktab
)/sizeof(*ktab
); i
++)
429 ktab
[i
].nr
= RC_ILLEGAL
;
430 ktab
[i
].args
= noargs
;
434 for (i
= 0; i
< KMAP_KEYS
+KMAP_AKEYS
; i
++)
436 umtab
[i
].nr
= RC_ILLEGAL
;
437 umtab
[i
].args
= noargs
;
439 dmtab
[i
].nr
= RC_ILLEGAL
;
440 dmtab
[i
].args
= noargs
;
442 mmtab
[i
].nr
= RC_ILLEGAL
;
443 mmtab
[i
].args
= noargs
;
447 for (i
= 0; i
< NKMAPDEF
; i
++)
449 if (i
+ KMAPDEFSTART
< T_CAPS
)
451 if (i
+ KMAPDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
455 argarr
[0] = kmapdef
[i
];
456 SaveAction(dmtab
+ i
+ (KMAPDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
458 for (i
= 0; i
< NKMAPADEF
; i
++)
460 if (i
+ KMAPADEFSTART
< T_CURSOR
)
462 if (i
+ KMAPADEFSTART
>= T_CURSOR
+ KMAP_AKEYS
)
464 if (kmapadef
[i
] == 0)
466 argarr
[0] = kmapadef
[i
];
467 SaveAction(dmtab
+ i
+ (KMAPADEFSTART
- T_CURSOR
+ KMAP_KEYS
), RC_STUFF
, argarr
, 0);
469 for (i
= 0; i
< NKMAPMDEF
; i
++)
471 if (i
+ KMAPMDEFSTART
< T_CAPS
)
473 if (i
+ KMAPMDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
475 if (kmapmdef
[i
] == 0)
477 argarr
[0] = kmapmdef
[i
];
479 SaveAction(mmtab
+ i
+ (KMAPMDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
483 ktab
['h'].nr
= RC_HARDCOPY
;
485 ktab
['z'].nr
= ktab
[Ctrl('z')].nr
= RC_SUSPEND
;
487 ktab
['c'].nr
= ktab
[Ctrl('c')].nr
= RC_SCREEN
;
488 ktab
[' '].nr
= ktab
[Ctrl(' ')].nr
=
489 ktab
['n'].nr
= ktab
[Ctrl('n')].nr
= RC_NEXT
;
490 ktab
['N'].nr
= RC_NUMBER
;
491 ktab
[Ctrl('h')].nr
= ktab
[0177].nr
= ktab
['p'].nr
= ktab
[Ctrl('p')].nr
= RC_PREV
;
492 ktab
['k'].nr
= ktab
[Ctrl('k')].nr
= RC_KILL
;
493 ktab
['l'].nr
= ktab
[Ctrl('l')].nr
= RC_REDISPLAY
;
494 ktab
['w'].nr
= ktab
[Ctrl('w')].nr
= RC_WINDOWS
;
495 ktab
['v'].nr
= RC_VERSION
;
496 ktab
[Ctrl('v')].nr
= RC_DIGRAPH
;
497 ktab
['q'].nr
= ktab
[Ctrl('q')].nr
= RC_XON
;
498 ktab
['s'].nr
= ktab
[Ctrl('s')].nr
= RC_XOFF
;
499 ktab
['t'].nr
= ktab
[Ctrl('t')].nr
= RC_TIME
;
500 ktab
['i'].nr
= ktab
[Ctrl('i')].nr
= RC_INFO
;
501 ktab
['m'].nr
= ktab
[Ctrl('m')].nr
= RC_LASTMSG
;
502 ktab
['A'].nr
= RC_TITLE
;
503 #if defined(UTMPOK) && defined(LOGOUTOK)
504 ktab
['L'].nr
= RC_LOGIN
;
506 ktab
[','].nr
= RC_LICENSE
;
507 ktab
['W'].nr
= RC_WIDTH
;
508 ktab
['.'].nr
= RC_DUMPTERMCAP
;
509 ktab
[Ctrl('\\')].nr
= RC_QUIT
;
511 ktab
['d'].nr
= ktab
[Ctrl('d')].nr
= RC_DETACH
;
513 ktab
['D'].nr
= RC_POW_DETACH
;
516 ktab
['r'].nr
= ktab
[Ctrl('r')].nr
= RC_WRAP
;
517 ktab
['f'].nr
= ktab
[Ctrl('f')].nr
= RC_FLOW
;
518 ktab
['C'].nr
= RC_CLEAR
;
519 ktab
['Z'].nr
= RC_RESET
;
520 ktab
['H'].nr
= RC_LOG
;
521 ktab
['M'].nr
= RC_MONITOR
;
522 ktab
['?'].nr
= RC_HELP
;
524 ktab
['*'].nr
= RC_DISPLAYS
;
530 SaveAction(ktab
+ '-', RC_SELECT
, args
, 0);
532 for (i
= 0; i
< ((MAXWIN
< 10) ? MAXWIN
: 10); i
++)
534 char *args
[2], arg1
[10];
537 sprintf(arg1
, "%d", i
);
538 SaveAction(ktab
+ '0' + i
, RC_SELECT
, args
, 0);
540 ktab
['\''].nr
= RC_SELECT
; /* calling a window by name */
545 SaveAction(ktab
+ '"', RC_WINDOWLIST
, args
, 0);
547 ktab
[Ctrl('G')].nr
= RC_VBELL
;
548 ktab
[':'].nr
= RC_COLON
;
550 ktab
['['].nr
= ktab
[Ctrl('[')].nr
= RC_COPY
;
555 SaveAction(ktab
+ ']', RC_PASTE
, args
, 0);
556 SaveAction(ktab
+ Ctrl(']'), RC_PASTE
, args
, 0);
558 ktab
['{'].nr
= RC_HISTORY
;
559 ktab
['}'].nr
= RC_HISTORY
;
560 ktab
['>'].nr
= RC_WRITEBUF
;
561 ktab
['<'].nr
= RC_READBUF
;
562 ktab
['='].nr
= RC_REMOVEBUF
;
565 ktab
['D'].nr
= RC_POW_DETACH
;
568 ktab
['x'].nr
= ktab
[Ctrl('x')].nr
= RC_LOCKSCREEN
;
570 ktab
['b'].nr
= ktab
[Ctrl('b')].nr
= RC_BREAK
;
571 ktab
['B'].nr
= RC_POW_BREAK
;
572 ktab
['_'].nr
= RC_SILENCE
;
573 ktab
['S'].nr
= RC_SPLIT
;
574 ktab
['Q'].nr
= RC_ONLY
;
575 ktab
['X'].nr
= RC_REMOVE
;
576 ktab
['F'].nr
= RC_FIT
;
577 ktab
['\t'].nr
= RC_FOCUS
;
582 SaveAction(ktab
+ T_BACKTAB
- T_CAPS
+ 256, RC_FOCUS
, args
, 0);
588 SaveAction(ktab
+ '|', RC_SPLIT
, args
, 0);
590 /* These come last; they may want overwrite others: */
593 ClearAction(&ktab
[DefaultEsc
]);
594 ktab
[DefaultEsc
].nr
= RC_OTHER
;
596 if (DefaultMetaEsc
>= 0)
598 ClearAction(&ktab
[DefaultMetaEsc
]);
599 ktab
[DefaultMetaEsc
].nr
= RC_META
;
602 idleaction
.nr
= RC_BLANKER
;
603 idleaction
.args
= noargs
;
607 static struct action
*
608 FindKtab(class, create
)
612 struct kclass
*kp
, **kpp
;
617 for (kpp
= &kclasses
; (kp
= *kpp
) != 0; kpp
= &kp
->next
)
618 if (!strcmp(kp
->name
, class))
624 if (strlen(class) > 80)
626 Msg(0, "Command class name too long.");
629 kp
= malloc(sizeof(*kp
));
635 kp
->name
= SaveStr(class);
636 for (i
= 0; i
< (int)(sizeof(kp
->ktab
)/sizeof(*kp
->ktab
)); i
++)
638 kp
->ktab
[i
].nr
= RC_ILLEGAL
;
639 kp
->ktab
[i
].args
= noargs
;
653 if (act
->nr
== RC_ILLEGAL
)
655 act
->nr
= RC_ILLEGAL
;
656 if (act
->args
== noargs
)
658 for (p
= act
->args
; *p
; p
++)
660 free((char *)act
->args
);
666 * ProcessInput: process input from display and feed it into
667 * the layer on canvas D_forecv.
673 * This ProcessInput just does the keybindings and passes
674 * everything else on to ProcessInput2.
678 ProcessInput(ibuf
, ilen
)
683 unsigned char *s
, *q
;
687 debug1("ProcessInput: %d bytes\n", ilen
);
688 if (display
== 0 || ilen
== 0)
693 s
= (unsigned char *)ibuf
;
697 if (D_dontmap
|| !D_nseqs
)
704 debug3("cmp %c %c[%d]\n", ch
, *D_seqp
, D_seqp
- D_kmaps
);
707 l
= D_seqp
[D_seqp
[-D_seql
-1] + 1];
711 debug1("miss %d\n", D_seqp
- D_kmaps
);
714 debug("complete miss\n");
717 p
= (char *)D_seqp
- l
;
719 D_seqp
= D_kmaps
+ 3;
722 if ((q
= D_seqh
) != 0)
725 i
= q
[0] << 8 | q
[1];
726 i
&= ~KMAP_NOTIMEOUT
;
727 debug1("Mapping former hit #%d - ", i
);
728 debug2("%d(%s) - ", q
[2], q
+ 3);
730 ProcessInput2((char *)q
+ 3, q
[2]);
738 debug1("flush old %d\n", l
);
747 /* Finish old stuff */
749 debug1("finish old %d\n", slen
);
751 ProcessInput2(ibuf
, slen
);
760 debug2("length am %d, want %d\n", l
, D_seqp
[-l
- 1]);
761 if (l
== D_seqp
[-l
- 1])
766 if (D_kmaps
+ D_nseqs
> q
&& q
[2] > l
&& !bcmp(D_seqp
- l
, q
+ 3, l
))
768 debug1("have another mapping (%s), delay execution\n", q
+ 3);
769 D_seqh
= D_seqp
- 3 - l
;
774 i
= D_seqp
[-l
- 3] << 8 | D_seqp
[-l
- 2];
775 i
&= ~KMAP_NOTIMEOUT
;
776 debug1("Mapping #%d - ", i
);
777 p
= (char *)D_seqp
- l
;
778 debug2("%d(%s) - ", l
, p
);
780 D_seqp
= D_kmaps
+ 3;
792 debug("am in sequence -> check for timeout\n");
794 for (s
= D_seqp
; ; s
+= i
* 2 + 4)
796 if (s
[-l
-3] & KMAP_NOTIMEOUT
>> 8)
798 if ((i
= s
[s
[-l
-1] + 1]) == 0)
800 SetTimeout(&D_mapev
, maptimeout
);
806 ProcessInput2(ibuf
, slen
);
810 # define ProcessInput2 ProcessInput
815 * Here only the screen escape commands are handled.
819 ProcessInput2(ibuf
, ilen
)
825 struct action
*ktabp
;
827 debug1("ProcessInput2: %d bytes\n", ilen
);
828 while (ilen
&& display
)
830 debug1(" - ilen now %d bytes\n", ilen
);
831 flayer
= D_forecv
->c_layer
;
839 if ((unsigned char)*s
++ == D_user
->u_Esc
)
845 DoProcess(fore
, &ibuf
, &slen
, 0);
851 ktabp
= D_ESCseen
? D_ESCseen
: ktab
;
853 ch
= (unsigned char)*s
;
856 * As users have different esc characters, but a common ktab[],
857 * we fold back the users esc and meta-esc key to the Default keys
858 * that can be looked up in the ktab[]. grmbl. jw.
859 * XXX: make ktab[] a per user thing.
861 if (ch
== D_user
->u_Esc
)
863 else if (ch
== D_user
->u_MetaEsc
)
867 DoAction(&ktabp
[ch
], ch
);
868 ibuf
= (char *)(s
+ 1);
874 DoProcess(p
, bufp
, lenp
, pa
)
881 struct display
*d
= display
;
884 /* XXX -> PasteStart */
885 if (pa
&& *lenp
> 1 && p
&& p
->w_slowpaste
)
887 /* schedule slowpaste event */
888 SetTimeout(&p
->w_paster
.pa_slowev
, p
->w_slowpaste
);
889 evenq(&p
->w_paster
.pa_slowev
);
893 while (flayer
&& *lenp
)
896 if (!pa
&& p
&& p
->w_paster
.pa_pastelen
&& flayer
== p
->w_paster
.pa_pastelayer
)
898 debug("layer is busy - beep!\n");
899 WBell(p
, visual_bell
);
907 LayProcess(bufp
, lenp
);
909 if (pa
&& !pa
->pa_pastelayer
)
910 break; /* flush rest of paste */
919 /* We're full, let's beep */
920 debug("layer is full - beep!\n");
921 WBell(p
, visual_bell
);
929 if (pa
&& pa
->pa_pastelen
== 0)
938 int x
, m
, l
= 0, r
= RC_LAST
;
942 x
= strcmp(str
, comms
[m
].name
);
954 CheckArgNum(nr
, args
)
959 static char *argss
[] = {"no", "one", "two", "three", "four", "OOPS"};
960 static char *orformat
[] =
962 "%s: %s: %s argument%s required",
963 "%s: %s: %s or %s argument%s required",
964 "%s: %s: %s, %s or %s argument%s required",
965 "%s: %s: %s, %s, %s or %s argument%s required"
968 n
= comms
[nr
].flags
& ARGS_MASK
;
969 for (i
= 0; args
[i
]; i
++)
971 if (comms
[nr
].flags
& ARGS_ORMORE
)
975 Msg(0, "%s: %s: at least %s argument%s required",
976 rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
980 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
981 (comms
[nr
].flags
& ARGS_PLUS2
) &&
982 (comms
[nr
].flags
& ARGS_PLUS3
))
984 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2 && i
!= n
+ 3)
986 Msg(0, orformat
[3], rc_name
, comms
[nr
].name
, argss
[n
],
987 argss
[n
+ 1], argss
[n
+ 2], argss
[n
+ 3], "");
991 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
992 (comms
[nr
].flags
& ARGS_PLUS2
))
994 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2)
996 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
997 argss
[n
+ 1], argss
[n
+ 2], "");
1001 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
1002 (comms
[nr
].flags
& ARGS_PLUS3
))
1004 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 3)
1006 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1007 argss
[n
+ 1], argss
[n
+ 3], "");
1011 else if ((comms
[nr
].flags
& ARGS_PLUS2
) &&
1012 (comms
[nr
].flags
& ARGS_PLUS3
))
1014 if (i
!= n
&& i
!= n
+ 2 && i
!= n
+ 3)
1016 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1017 argss
[n
+ 2], argss
[n
+ 3], "");
1021 else if (comms
[nr
].flags
& ARGS_PLUS1
)
1023 if (i
!= n
&& i
!= n
+ 1)
1025 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1026 argss
[n
+ 1], n
!= 0 ? "s" : "");
1030 else if (comms
[nr
].flags
& ARGS_PLUS2
)
1032 if (i
!= n
&& i
!= n
+ 2)
1034 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1039 else if (comms
[nr
].flags
& ARGS_PLUS3
)
1041 if (i
!= n
&& i
!= n
+ 3)
1043 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1050 Msg(0, orformat
[0], rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1057 StuffFin(buf
, len
, data
)
1065 LayProcess(&buf
, &len
);
1075 char **args
= act
->args
;
1076 int *argl
= act
->argl
;
1078 int argc
, i
, n
, msgok
;
1081 struct display
*odisplay
= display
;
1082 struct acluser
*user
;
1084 user
= display
? D_user
: users
;
1085 if (nr
== RC_ILLEGAL
)
1087 debug1("key '%c': No action\n", key
);
1090 n
= comms
[nr
].flags
;
1091 if ((n
& NEED_DISPLAY
) && display
== 0)
1093 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1096 if ((n
& NEED_FORE
) && fore
== 0)
1098 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1101 if ((n
& NEED_LAYER
) && flayer
== 0)
1103 Msg(0, "%s: %s: display or window required", rc_name
, comms
[nr
].name
);
1106 if ((argc
= CheckArgNum(nr
, args
)) < 0)
1111 if (AclCheckPermCmd(D_user
, ACL_EXEC
, &comms
[nr
]))
1113 Msg(0, "%s: %s: permission denied (user %s)",
1114 rc_name
, comms
[nr
].name
, (EffectiveAclUser
? EffectiveAclUser
: D_user
)->u_name
);
1118 #endif /* MULTIUSER */
1120 msgok
= display
&& !*rc_name
;
1126 else if (args
[0][0] == '-' && !args
[0][1])
1128 SetForeWindow((struct win
*)0);
1131 else if (args
[0][0] == '.' && !args
[0][1])
1134 Msg(0, "select . needs a window");
1137 SetForeWindow(fore
);
1141 else if (ParseWinNum(act
, &n
) == 0)
1145 case RC_DEFAUTONUKE
:
1146 if (ParseOnOff(act
, &defautonuke
) == 0 && msgok
)
1147 Msg(0, "Default autonuke turned %s", defautonuke
? "on" : "off");
1148 if (display
&& *rc_name
)
1149 D_auto_nuke
= defautonuke
;
1152 if (ParseOnOff(act
, &D_auto_nuke
) == 0 && msgok
)
1153 Msg(0, "Autonuke turned %s", D_auto_nuke
? "on" : "off");
1156 case RC_DEFOBUFLIMIT
:
1157 if (ParseNum(act
, &defobuflimit
) == 0 && msgok
)
1158 Msg(0, "Default limit set to %d", defobuflimit
);
1159 if (display
&& *rc_name
)
1161 D_obufmax
= defobuflimit
;
1162 D_obuflenmax
= D_obuflen
- D_obufmax
;
1167 Msg(0, "Limit is %d, current buffer size is %d", D_obufmax
, D_obuflen
);
1168 else if (ParseNum(act
, &D_obufmax
) == 0 && msgok
)
1169 Msg(0, "Limit set to %d", D_obufmax
);
1170 D_obuflenmax
= D_obuflen
- D_obufmax
;
1172 case RC_DUMPTERMCAP
:
1173 WriteFile(user
, (char *)0, DUMP_TERMCAP
);
1177 int mode
= DUMP_HARDCOPY
;
1179 if (argc
> 1 && !strcmp(*args
, "-h"))
1181 mode
= DUMP_SCROLLBACK
;
1185 if (*args
&& args
[1])
1187 Msg(0, "%s: hardcopy: too many arguments", rc_name
);
1190 if (fore
== 0 && *args
== 0)
1191 Msg(0, "%s: hardcopy: window required", rc_name
);
1193 WriteFile(user
, *args
, mode
);
1197 (void)ParseOnOff(act
, &nwin_default
.Lflag
);
1200 n
= fore
->w_log
? 1 : 0;
1201 ParseSwitch(act
, &n
);
1211 SwitchWindow(NextWindow());
1215 SwitchWindow(PreviousWindow());
1224 Input(fore
->w_pwin
? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1226 Input("Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1234 FreePseudowin(fore
);
1235 Msg(0, "Filter removed.");
1239 name
= SaveStr(fore
->w_title
);
1241 Msg(0, "Window %d (%s) killed.", n
, name
);
1249 Input("Really quit and kill all your windows [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_QUIT
);
1256 if (*args
&& !strcmp(*args
, "-h"))
1268 Input(buf
, 1, INP_RAW
, pow_detach_fn
, NULL
, 0);
1271 Detach(D_POWER
); /* detach and kill Attacher's parent */
1280 Msg(0, "debugging info is written to %s/", DEBUGDIR
);
1282 Msg(0, "debugging is currently off. Use 'debug on' to enable.");
1287 debug("debug: closing debug file.\n");
1292 if (strcmp("off", *args
))
1296 kill(D_userpid
, SIG_NODEBUG
); /* a one shot item, but hey... */
1297 # endif /* SIG_NODEBUG */
1299 if (*args
== 0 || strcmp("off", *args
))
1300 Msg(0, "Sorry, screen was compiled without -DDEBUG option.");
1305 if (*args
&& !strcmp(*args
, "sendcmd"))
1309 free(zmodem_sendcmd
);
1310 zmodem_sendcmd
= SaveStr(args
[1]);
1313 Msg(0, "zmodem sendcmd: %s", zmodem_sendcmd
);
1316 if (*args
&& !strcmp(*args
, "recvcmd"))
1320 free(zmodem_recvcmd
);
1321 zmodem_recvcmd
= SaveStr(args
[1]);
1324 Msg(0, "zmodem recvcmd: %s", zmodem_recvcmd
);
1329 for (i
= 0; i
< 4; i
++)
1330 if (!strcmp(zmodes
[i
], *args
))
1332 if (i
== 4 && !strcmp(*args
, "on"))
1336 Msg(0, "usage: zmodem off|auto|catch|pass");
1342 Msg(0, "zmodem mode is %s", zmodes
[zmodem_mode
]);
1349 ZombieKey_destroy
= 0;
1352 if (*argl
== 0 || *argl
> 2)
1354 Msg(0, "%s:zombie: one or two characters expected.", rc_name
);
1359 if (!strcmp(args
[1], "onerror"))
1361 ZombieKey_onerror
= 1;
1363 Msg(0, "usage: zombie [keys [onerror]]");
1367 ZombieKey_onerror
= 0;
1368 ZombieKey_destroy
= args
[0][0];
1369 ZombieKey_resurrect
= *argl
== 2 ? args
[0][1] : 0;
1379 struct display
*olddisplay
= display
;
1380 display
= 0; /* no display will cause a broadcast */
1381 Msg(0, "%s: %s", s
, *args
);
1382 display
= olddisplay
;
1386 /* where this AT command comes from: */
1388 s
= SaveStr(D_user
->u_name
);
1389 /* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
1390 EffectiveAclUser
= D_user
;
1392 s
= SaveStr(D_usertty
);
1394 n
= strlen(args
[0]);
1397 * the windows/displays loops are quite dangerous here, take extra
1398 * care not to trigger landmines. Things may appear/disappear while
1399 * we are walking along.
1403 case '*': /* user */
1411 for (u
= users
; u
; u
= u
->u_next
)
1413 debug3("strncmp('%s', '%s', %d)\n", *args
, u
->u_name
, n
);
1414 if (!strncmp(*args
, u
->u_name
, n
))
1417 debug1("at all displays of user %s\n", u
->u_name
);
1418 for (display
= displays
; display
; display
= nd
)
1420 nd
= display
->d_next
;
1423 flayer
= D_forecv
->c_layer
;
1427 debug1("AT display %s\n", D_usertty
);
1428 DoCommand(args
+ 1, argl
+ 1);
1430 Msg(0, "command from %s: %s %s",
1431 s
, args
[1], args
[2] ? args
[2] : "");
1438 case '%': /* display */
1442 debug1("at display matching '%s'\n", args
[0]);
1443 for (display
= displays
; display
; display
= nd
)
1445 nd
= display
->d_next
;
1449 flayer
= D_forecv
->c_layer
;
1450 if (strncmp(args
[0], D_usertty
, n
) &&
1451 (strncmp("/dev/", D_usertty
, 5) ||
1452 strncmp(args
[0], D_usertty
+ 5, n
)) &&
1453 (strncmp("/dev/tty", D_usertty
, 8) ||
1454 strncmp(args
[0], D_usertty
+ 8, n
)))
1456 debug1("AT display %s\n", D_usertty
);
1457 DoCommand(args
+ 1, argl
+ 1);
1459 Msg(0, "command from %s: %s %s",
1460 s
, args
[1], args
[2] ? args
[2] : "");
1467 case '#': /* window */
1478 if (!*args
[0] || (i
= WindowByNumber(args
[0])) < 0)
1480 args
[0][n
] = ch
; /* must restore string in case of bind */
1481 /* try looping over titles */
1482 for (fore
= windows
; fore
; fore
= nw
)
1485 if (strncmp(args
[0], fore
->w_title
, n
))
1487 debug2("AT window %d(%s)\n", fore
->w_number
, fore
->w_title
);
1489 * consider this a bug or a feature:
1490 * while looping through windows, we have fore AND
1491 * display context. This will confuse users who try to
1492 * set up loops inside of loops, but often allows to do
1493 * what you mean, even when you adress your context wrong.
1496 /* XXX: other displays? */
1497 if (fore
->w_layer
.l_cvlist
)
1498 display
= fore
->w_layer
.l_cvlist
->c_display
;
1499 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1500 DoCommand(args
+ 1, argl
+ 1); /* may destroy our display */
1501 if (fore
&& fore
->w_layer
.l_cvlist
)
1503 display
= fore
->w_layer
.l_cvlist
->c_display
;
1504 Msg(0, "command from %s: %s %s",
1505 s
, args
[1], args
[2] ? args
[2] : "");
1511 Msg(0, "%s: at '%s': no such window.\n", rc_name
, args
[0]);
1514 else if (i
< MAXWIN
&& (fore
= wtab
[i
]))
1516 args
[0][n
] = ch
; /* must restore string in case of bind */
1517 debug2("AT window %d (%s)\n", fore
->w_number
, fore
->w_title
);
1518 if (fore
->w_layer
.l_cvlist
)
1519 display
= fore
->w_layer
.l_cvlist
->c_display
;
1520 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1521 DoCommand(args
+ 1, argl
+ 1);
1522 if (fore
&& fore
->w_layer
.l_cvlist
)
1524 display
= fore
->w_layer
.l_cvlist
->c_display
;
1525 Msg(0, "command from %s: %s %s",
1526 s
, args
[1], args
[2] ? args
[2] : "");
1532 Msg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name
);
1538 EffectiveAclUser
= NULL
;
1545 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1546 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1548 i
= FindEncoding(args
[1]);
1551 Msg(0, "%s: readreg: unknown encoding", rc_name
);
1558 * Without arguments we prompt for a destination register.
1559 * It will receive the copybuffer contents.
1560 * This is not done by RC_PASTE, as we prompt for source
1563 if ((s
= *args
) == NULL
)
1565 Input("Copy to register:", 1, INP_RAW
, copy_reg_fn
, NULL
, 0);
1570 Msg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name
);
1575 * With two arguments we *really* read register contents from file
1581 Msg(0, "%s: readreg: too many arguments", rc_name
);
1584 if ((s
= ReadFile(args
[1], &n
)))
1586 struct plop
*pp
= plop_tab
+ (int)(unsigned char)ch
;
1599 * with one argument we copy the copybuffer into a specified register
1600 * This could be done with RC_PASTE too, but is here to be consistent
1601 * with the zero argument call.
1603 copy_reg_fn(&ch
, 0, NULL
);
1608 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1609 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1611 i
= FindEncoding(args
[1]);
1614 Msg(0, "%s: register: unknown encoding", rc_name
);
1623 Msg(0, "%s: register: illegal number of arguments.", rc_name
);
1628 Msg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name
);
1635 if (user
->u_plop
.buf
!= NULL
)
1636 UserFreeCopyBuffer(user
);
1637 if (args
[1] && args
[1][0])
1639 user
->u_plop
.buf
= SaveStrn(args
[1], argl
[1]);
1640 user
->u_plop
.len
= argl
[1];
1642 user
->u_plop
.enc
= i
;
1649 struct plop
*plp
= plop_tab
+ (int)(unsigned char)ch
;
1653 plp
->buf
= SaveStrn(args
[1], argl
[1]);
1661 if ((s
= *args
) == NULL
)
1663 Input("Process register:", 1, INP_RAW
, process_fn
, NULL
, 0);
1668 Msg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name
);
1672 process_fn(&ch
, 0, NULL
);
1678 Input("Stuff:", 100, INP_COOKED
, StuffFin
, NULL
, 0);
1684 if (strcmp(s
, "-k"))
1686 Msg(0, "%s: stuff: invalid option %s", rc_name
, s
);
1690 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
1691 if (strcmp(term
[i
].tcname
, s
) == 0)
1695 Msg(0, "%s: stuff: unknown key '%s'", rc_name
, s
);
1699 if (StuffKey(i
- T_CAPS
) == 0)
1702 s
= display
? D_tcs
[i
].str
: 0;
1717 Msg(0, "screen %s", version
);
1722 timestring
= SaveStr(*args
);
1725 Msg(0, "%s", MakeWinMsg(timestring
, fore
, '%'));
1735 struct action
*ktabp
= ktab
;
1736 if (argc
== 2 && !strcmp(*args
, "-c"))
1738 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
1740 Msg(0, "Unknown command class '%s'", args
[1]);
1744 if (D_ESCseen
!= ktab
|| ktabp
!= ktab
)
1754 SwitchWindow(display
&& D_other
? D_other
->w_number
: NextWindow());
1757 if (user
->u_Esc
== -1)
1776 case RC_DEFBREAKTYPE
:
1779 static char *types
[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL
};
1780 extern int breaktype
;
1784 if (ParseNum(act
, &n
))
1785 for (n
= 0; n
< (int)(sizeof(types
)/sizeof(*types
)); n
++)
1787 for (i
= 0; i
< 4; i
++)
1790 if (ch
>= 'a' && ch
<= 'z')
1792 if (ch
!= types
[n
][i
] && (ch
+ ('a' - 'A')) != types
[n
][i
])
1798 if (n
< 0 || n
>= (int)(sizeof(types
)/sizeof(*types
)))
1799 Msg(0, "%s invalid, chose one of %s, %s or %s", *args
, types
[0], types
[1], types
[2]);
1803 Msg(0, "breaktype set to (%d) %s", n
, types
[n
]);
1807 Msg(0, "breaktype is (%d) %s", breaktype
, types
[breaktype
]);
1813 if (*args
&& ParseNum(act
, &n
))
1815 SendBreak(fore
, n
, nr
== RC_POW_BREAK
);
1829 if (*args
&& !strcmp(*args
, "-w"))
1831 else if (*args
&& !strcmp(*args
, "-d"))
1835 if (what
== 0 && flayer
&& !display
)
1841 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1844 w
= flayer
->l_width
;
1845 h
= flayer
->l_height
;
1851 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1857 if (*args
&& args
[0][0] == '-')
1859 Msg(0, "%s: %s: unknown option %s", rc_name
, comms
[nr
].name
, *args
);
1862 if (nr
== RC_HEIGHT
)
1870 else if (h
== H1height
)
1872 else if (h
> (H0height
+ H1height
) / 2)
1890 else if (w
== Z1width
)
1892 else if (w
> (Z0width
+ Z1width
) / 2)
1904 if (*args
&& args
[1] && args
[2])
1906 Msg(0, "%s: %s: too many arguments", rc_name
, comms
[nr
].name
);
1911 Msg(0, "Illegal width");
1916 Msg(0, "Illegal height");
1921 if (flayer
->l_width
== w
&& flayer
->l_height
== h
)
1923 ResizeLayer(flayer
, w
, h
, (struct display
*)0);
1926 if (D_width
== w
&& D_height
== h
)
1930 ChangeScreenSize(w
, h
, 1);
1934 if (ResizeDisplay(w
, h
) == 0)
1936 Activate(D_fore
? D_fore
->w_norefresh
: 0);
1938 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
1942 Msg(0, "Your termcap does not specify how to change the terminal's width to %d.", w
);
1943 else if (w
== D_width
)
1944 Msg(0, "Your termcap does not specify how to change the terminal's height to %d.", h
);
1946 Msg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w
, h
);
1954 ChangeAKA(fore
, *args
, strlen(*args
));
1957 Input(":", 100, INP_EVERY
, Colonfin
, NULL
, 0);
1958 if (*args
&& **args
)
1966 if (D_status_lastmsg
)
1967 Msg(0, "%s", D_status_lastmsg
);
1970 DoScreen("key", args
);
1973 if (ParseSwitch(act
, &fore
->w_wrap
) == 0 && msgok
)
1974 Msg(0, "%cwrap", fore
->w_wrap
? '+' : '-');
1979 if (args
[0][0] == 'a')
1981 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) ? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
1985 if (ParseOnOff(act
, &n
))
1987 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | n
;
1992 if (fore
->w_flow
& FLOW_AUTOFLAG
)
1993 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | FLOW_NOW
;
1994 else if (fore
->w_flow
& FLOW_NOW
)
1995 fore
->w_flow
&= ~FLOW_NOW
;
1997 fore
->w_flow
= fore
->w_flow
? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
1999 SetFlow(fore
->w_flow
& FLOW_NOW
);
2001 Msg(0, "%cflow%s", (fore
->w_flow
& FLOW_NOW
) ? '+' : '-',
2002 (fore
->w_flow
& FLOW_AUTOFLAG
) ? "(auto)" : "");
2005 case RC_DEFWRITELOCK
:
2006 if (args
[0][0] == 'a')
2007 nwin_default
.wlock
= WLOCK_AUTO
;
2010 if (ParseOnOff(act
, &n
))
2012 nwin_default
.wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2018 if (args
[0][0] == 'a')
2020 fore
->w_wlock
= WLOCK_AUTO
;
2024 if (ParseOnOff(act
, &n
))
2026 fore
->w_wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2029 * user may have permission to change the writelock setting,
2030 * but he may never aquire the lock himself without write permission
2032 if (!AclCheckPermWin(D_user
, ACL_WRITE
, fore
))
2033 fore
->w_wlockuser
= D_user
;
2035 Msg(0, "writelock %s", (fore
->w_wlock
== WLOCK_AUTO
) ? "auto" :
2036 ((fore
->w_wlock
== WLOCK_OFF
) ? "off" : "on"));
2040 ResetAnsiState(fore
);
2041 WriteString(fore
, "\033[H\033[J", 6);
2044 ResetAnsiState(fore
);
2046 if (fore
->w_zdisplay
)
2047 zmodem_abort(fore
, fore
->w_zdisplay
);
2049 WriteString(fore
, "\033c", 2);
2052 n
= fore
->w_monitor
!= MON_OFF
;
2055 n
= n
&& (ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
));
2057 if (ParseSwitch(act
, &n
))
2062 if (display
) /* we tell only this user */
2063 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2065 for (i
= 0; i
< maxusercount
; i
++)
2066 ACLBYTE(fore
->w_mon_notify
, i
) |= ACLBIT(i
);
2068 if (fore
->w_monitor
== MON_OFF
)
2069 fore
->w_monitor
= MON_ON
;
2070 Msg(0, "Window %d (%s) is now being monitored for all activity.", fore
->w_number
, fore
->w_title
);
2075 if (display
) /* we remove only this user */
2076 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
)
2077 &= ~ACLBIT(D_user
->u_id
);
2079 for (i
= 0; i
< maxusercount
; i
++)
2080 ACLBYTE(fore
->w_mon_notify
, i
) &= ~ACLBIT(i
);
2081 for (i
= maxusercount
- 1; i
>= 0; i
--)
2082 if (ACLBYTE(fore
->w_mon_notify
, i
))
2086 fore
->w_monitor
= MON_OFF
;
2087 Msg(0, "Window %d (%s) is no longer being monitored for activity.", fore
->w_number
, fore
->w_title
);
2097 display_wlist(0, WLIST_NUM
, (struct win
*)0);
2098 else if (!strcmp(*args
, "string"))
2104 wliststr
= SaveStr(args
[1]);
2107 Msg(0, "windowlist string is '%s'", wliststr
);
2109 else if (!strcmp(*args
, "title"))
2115 wlisttit
= SaveStr(args
[1]);
2118 Msg(0, "windowlist title is '%s'", wlisttit
);
2124 for (i
= 0; i
< argc
; i
++)
2127 else if (!strcmp(args
[i
], "-m"))
2129 else if (!strcmp(args
[i
], "-b"))
2131 else if (!strcmp(args
[i
], "-g"))
2132 flag
|= WLIST_NESTED
;
2135 Msg(0, "usage: windowlist [-b] [-g] [-m] [string [string] | title [title]]");
2139 display_wlist(blank
, flag
, (struct win
*)0);
2143 if (argc
== 2 && !strcmp(*args
, "-c"))
2145 struct action
*ktabp
;
2146 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
2148 Msg(0, "Unknown command class '%s'", args
[1]);
2151 display_help(args
[1], ktabp
);
2154 display_help((char *)0, ktab
);
2157 display_copyright();
2161 if (flayer
->l_layfn
!= &WinLf
)
2163 Msg(0, "Must be on a window layer");
2170 static char *pasteargs
[] = {".", 0};
2171 static int pasteargl
[] = {1};
2173 if (flayer
->l_layfn
!= &WinLf
)
2175 Msg(0, "Must be on a window layer");
2178 if (GetHistory() == 0)
2180 if (user
->u_plop
.buf
== NULL
)
2188 char *ss
, *dbuf
, dch
;
2195 * without args we prompt for one(!) register to be pasted in the window
2197 if ((s
= *args
) == NULL
)
2199 Input("Paste from register:", 1, INP_RAW
, ins_reg_fn
, NULL
, 0);
2202 if (args
[1] == 0 && !fore
) /* no window? */
2205 * with two arguments we paste into a destination register
2206 * (no window needed here).
2208 if (args
[1] && argl
[1] != 1)
2210 Msg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
2216 enc
= fore
->w_encoding
;
2220 * measure length of needed buffer
2222 for (ss
= s
= *args
; (ch
= *ss
); ss
++)
2228 enc
= user
->u_plop
.enc
;
2229 if (enc
!= user
->u_plop
.enc
)
2230 l
+= RecodeBuf((unsigned char *)user
->u_plop
.buf
, user
->u_plop
.len
, user
->u_plop
.enc
, enc
, (unsigned char *)0);
2233 l
+= user
->u_plop
.len
;
2239 enc
= plop_tab
[(int)(unsigned char)ch
].enc
;
2240 if (enc
!= plop_tab
[(int)(unsigned char)ch
].enc
)
2241 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);
2244 l
+= plop_tab
[(int)(unsigned char)ch
].len
;
2249 Msg(0, "empty buffer");
2254 * if there is only one source and the destination is a window, then
2255 * pass a pointer rather than duplicating the buffer.
2257 if (s
[1] == 0 && args
[1] == 0)
2259 if (enc
== (*s
== '.' ? user
->u_plop
.enc
: plop_tab
[(int)(unsigned char)*s
].enc
))
2262 MakePaster(&fore
->w_paster
, *s
== '.' ? user
->u_plop
.buf
: plop_tab
[(int)(unsigned char)*s
].buf
, l
, 0);
2266 * if no shortcut, we construct a buffer
2268 if ((dbuf
= (char *)malloc(l
)) == 0)
2275 * concatenate all sources into our own buffer, copy buffer is
2276 * special and is skipped if no display exists.
2278 for (ss
= s
; (ch
= *ss
); ss
++)
2280 struct plop
*pp
= (ch
== '.' ? &user
->u_plop
: &plop_tab
[(int)(unsigned char)ch
]);
2284 l
+= RecodeBuf((unsigned char *)pp
->buf
, pp
->len
, pp
->enc
, enc
, (unsigned char *)dbuf
+ l
);
2288 bcopy(pp
->buf
, dbuf
+ l
, pp
->len
);
2292 * when called with one argument we paste our buffer into the window
2296 MakePaster(&fore
->w_paster
, dbuf
, l
, 1);
2301 * we have two arguments, the second is already in dch.
2302 * use this as destination rather than the window.
2307 if (user
->u_plop
.buf
!= NULL
)
2308 UserFreeCopyBuffer(user
);
2309 user
->u_plop
.buf
= dbuf
;
2310 user
->u_plop
.len
= l
;
2312 user
->u_plop
.enc
= enc
;
2317 struct plop
*pp
= plop_tab
+ (int)(unsigned char)dch
;
2330 if (!user
->u_plop
.buf
)
2332 Msg(0, "empty buffer");
2337 struct plop oldplop
;
2339 oldplop
= user
->u_plop
;
2340 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2345 enc
= FindEncoding(args
[1]);
2348 Msg(0, "%s: writebuf: unknown encoding", rc_name
);
2351 if (enc
!= oldplop
.enc
)
2353 l
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)0);
2354 newbuf
= malloc(l
+ 1);
2360 user
->u_plop
.len
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)newbuf
);
2361 user
->u_plop
.buf
= newbuf
;
2362 user
->u_plop
.enc
= enc
;
2367 if (args
[0] && args
[1])
2368 Msg(0, "%s: writebuf: too many arguments", rc_name
);
2370 WriteFile(user
, args
[0], DUMP_EXCHANGE
);
2372 if (user
->u_plop
.buf
!= oldplop
.buf
)
2373 free(user
->u_plop
.buf
);
2374 user
->u_plop
= oldplop
;
2380 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
2381 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2383 i
= FindEncoding(args
[1]);
2386 Msg(0, "%s: readbuf: unknown encoding", rc_name
);
2392 if (args
[0] && args
[1])
2394 Msg(0, "%s: readbuf: too many arguments", rc_name
);
2397 if ((s
= ReadFile(args
[0] ? args
[0] : BufferFile
, &n
)))
2399 if (user
->u_plop
.buf
)
2400 UserFreeCopyBuffer(user
);
2401 user
->u_plop
.len
= n
;
2402 user
->u_plop
.buf
= s
;
2404 user
->u_plop
.enc
= i
;
2412 (void)ParseSwitch(act
, &search_ic
);
2414 Msg(0, "Will %signore case in searches", search_ic
? "" : "not ");
2416 #endif /* COPY_PASTE */
2419 SetEscape(user
, -1, -1);
2420 else if (*argl
== 2)
2421 SetEscape(user
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2424 Msg(0, "%s: two characters required after escape.", rc_name
);
2427 /* Change defescape if master user. This is because we only
2430 if (display
&& user
!= users
)
2435 SetEscape(NULL
, -1, -1);
2436 else if (*argl
== 2)
2437 SetEscape(NULL
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2440 Msg(0, "%s: two characters required after defescape.", rc_name
);
2448 s
= *args
? *args
: home
;
2450 Msg(errno
, "%s", s
);
2454 if (ParseSaveStr(act
, &ShellProg
) == 0)
2455 ShellArgs
[0] = ShellProg
;
2457 case RC_HARDCOPYDIR
:
2459 (void)ParseSaveStr(act
, &hardcopydir
);
2461 Msg(0, "hardcopydir is %s\n", hardcopydir
&& *hardcopydir
? hardcopydir
: "<cwd>");
2466 if (args
[1] && !(strcmp(*args
, "flush")))
2468 log_flush
= atoi(args
[1]);
2470 Msg(0, "log flush timeout set to %ds\n", log_flush
);
2473 if (ParseSaveStr(act
, &screenlogfile
) || !msgok
)
2476 Msg(0, "logfile is '%s'", screenlogfile
);
2479 if (!*args
|| !strcmp(*args
, "on") || !strcmp(*args
, "off"))
2481 if (ParseSwitch(act
, &logtstamp_on
) == 0 && msgok
)
2482 Msg(0, "timestamps turned %s", logtstamp_on
? "on" : "off");
2484 else if (!strcmp(*args
, "string"))
2488 if (logtstamp_string
)
2489 free(logtstamp_string
);
2490 logtstamp_string
= SaveStr(args
[1]);
2493 Msg(0, "logfile timestamp is '%s'", logtstamp_string
);
2495 else if (!strcmp(*args
, "after"))
2499 logtstamp_after
= atoi(args
[1]);
2503 Msg(0, "timestamp printed after %ds\n", logtstamp_after
);
2506 Msg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
2509 (void)ParseSaveStr(act
, &nwin_default
.aka
);
2512 case RC_TERMCAPINFO
:
2514 if (!rc_name
|| !*rc_name
)
2515 Msg(0, "Sorry, too late now. Place that in your .screenrc file.");
2518 break; /* Already handled */
2521 if (ParseSaveStr(act
, &s
))
2523 if (strlen(s
) >= 20)
2525 Msg(0, "%s: term: argument too long ( < 20)", rc_name
);
2529 strcpy(screenterm
, s
);
2531 debug1("screenterm set to %s\n", screenterm
);
2532 MakeTermcap((display
== 0));
2533 debug("new termcap made\n");
2536 if (!msgok
&& (!rc_name
|| strcmp(rc_name
, "-X")))
2539 * user typed ^A:echo... well, echo isn't FinishRc's job,
2540 * but as he wanted to test us, we show good will
2542 if (argc
> 1 && !strcmp(*args
, "-n"))
2548 if (argc
> 1 && !strcmp(*args
, "-p"))
2554 s
= MakeWinMsg(s
, fore
, '%');
2559 Msg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name
);
2566 AddXChars(buf
, sizeof(buf
), BellString
);
2567 Msg(0, "bell_msg is '%s'", buf
);
2570 (void)ParseSaveStr(act
, &BellString
);
2575 BufferFile
= SaveStr(DEFAULT_BUFFERFILE
);
2576 else if (ParseSaveStr(act
, &BufferFile
))
2579 Msg(0, "Bufferfile is now '%s'", BufferFile
);
2583 (void)ParseSaveStr(act
, &ActivityString
);
2585 #if defined(DETACH) && defined(POW_DETACH)
2586 case RC_POW_DETACH_MSG
:
2590 AddXChars(buf
, sizeof(buf
), PowDetachString
);
2591 Msg(0, "pow_detach_msg is '%s'", buf
);
2594 (void)ParseSaveStr(act
, &PowDetachString
);
2597 #if defined(UTMPOK) && defined(LOGOUTOK)
2599 n
= fore
->w_slot
!= (slot_t
)-1;
2600 if (*args
&& !strcmp(*args
, "always"))
2607 if (*args
&& !strcmp(*args
, "attached"))
2614 if (ParseSwitch(act
, &n
) == 0)
2618 if (!strcmp(*args
, "always"))
2619 nwin_default
.lflag
|= 2;
2620 else if (!strcmp(*args
, "attached"))
2621 nwin_default
.lflag
&= ~2;
2623 (void)ParseOnOff(act
, &nwin_default
.lflag
);
2627 if (args
[0] && args
[1] && args
[1][0] == 'i')
2630 for (display
= displays
; display
; display
= display
->d_next
)
2634 #if defined(TERMIO) || defined(POSIX)
2635 D_NewMode
.tio
.c_cc
[VINTR
] = D_OldMode
.tio
.c_cc
[VINTR
];
2636 D_NewMode
.tio
.c_lflag
|= ISIG
;
2637 #else /* TERMIO || POSIX */
2638 D_NewMode
.m_tchars
.t_intrc
= D_OldMode
.m_tchars
.t_intrc
;
2639 #endif /* TERMIO || POSIX */
2640 SetTTY(D_userfd
, &D_NewMode
);
2643 if (args
[0] && args
[0][0] == 'a')
2644 nwin_default
.flowflag
= FLOW_AUTOFLAG
;
2646 (void)ParseOnOff(act
, &nwin_default
.flowflag
);
2649 (void)ParseOnOff(act
, &nwin_default
.wrap
);
2652 (void)ParseOnOff(act
, &nwin_default
.c1
);
2656 (void)ParseOnOff(act
, &nwin_default
.bce
);
2660 (void)ParseOnOff(act
, &nwin_default
.gr
);
2663 if (ParseOnOff(act
, &n
) == 0)
2664 nwin_default
.monitor
= (n
== 0) ? MON_OFF
: MON_ON
;
2667 if (ParseOnOff(act
, &n
) == 0)
2668 nwin_default
.silence
= (n
== 0) ? SILENCE_OFF
: SILENCE_ON
;
2672 Msg(0, "W%s echo command when creating windows.",
2673 VerboseCreate
? "ill" : "on't");
2674 else if (ParseOnOff(act
, &n
) == 0)
2680 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
2683 if (args
[0] && strcmp(args
[0], "on") && strcmp(args
[0], "off"))
2685 struct display
*olddisplay
= display
;
2686 int old_use
, new_use
= -1;
2689 if (!strncmp(s
, "always", 6))
2691 if (!strcmp(s
, "lastline"))
2692 new_use
= HSTATUS_LASTLINE
;
2693 else if (!strcmp(s
, "ignore"))
2694 new_use
= HSTATUS_IGNORE
;
2695 else if (!strcmp(s
, "message"))
2696 new_use
= HSTATUS_MESSAGE
;
2697 else if (!strcmp(args
[0], "string"))
2702 AddXChars(buf
, sizeof(buf
), hstatusstring
);
2703 Msg(0, "hardstatus string is '%s'", buf
);
2709 Msg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name
);
2714 hardstatusemu
= new_use
| (s
== args
[0] ? 0 : HSTATUS_ALWAYS
);
2715 for (display
= displays
; display
; display
= display
->d_next
)
2718 new_use
= hardstatusemu
& ~HSTATUS_ALWAYS
;
2719 if (D_HS
&& s
== args
[0])
2720 new_use
= HSTATUS_HS
;
2721 ShowHStatus((char *)0);
2722 old_use
= D_has_hstatus
;
2723 D_has_hstatus
= new_use
;
2724 if ((new_use
== HSTATUS_LASTLINE
&& old_use
!= HSTATUS_LASTLINE
) || (new_use
!= HSTATUS_LASTLINE
&& old_use
== HSTATUS_LASTLINE
))
2725 ChangeScreenSize(D_width
, D_height
, 1);
2732 free(hstatusstring
);
2733 hstatusstring
= SaveStr(args
[1]);
2734 for (display
= displays
; display
; display
= display
->d_next
)
2737 display
= olddisplay
;
2740 (void)ParseSwitch(act
, &use_hardstatus
);
2742 Msg(0, "messages displayed on %s", use_hardstatus
? "hardstatus line" : "window");
2745 if (strcmp(args
[0], "always") == 0 || strcmp(args
[0], "splitonly") == 0)
2747 struct display
*olddisplay
= display
;
2749 captionalways
= args
[0][0] == 'a';
2750 for (display
= displays
; display
; display
= display
->d_next
)
2751 ChangeScreenSize(D_width
, D_height
, 1);
2752 display
= olddisplay
;
2754 else if (strcmp(args
[0], "string") == 0)
2759 AddXChars(buf
, sizeof(buf
), captionstring
);
2760 Msg(0, "caption string is '%s'", buf
);
2766 Msg(0, "%s: usage: caption always|splitonly|string <string>", rc_name
);
2772 free(captionstring
);
2773 captionstring
= SaveStr(args
[1]);
2774 RedisplayDisplays(0);
2777 n
= (console_window
!= 0);
2778 if (ParseSwitch(act
, &n
))
2780 if (TtyGrabConsole(fore
->w_ptyfd
, n
, rc_name
))
2783 Msg(0, "%s: releasing console %s", rc_name
, HostName
);
2784 else if (console_window
)
2785 Msg(0, "%s: stealing console %s from window %d (%s)", rc_name
,
2786 HostName
, console_window
->w_number
, console_window
->w_title
);
2788 Msg(0, "%s: grabbing console %s", rc_name
, HostName
);
2789 console_window
= n
? fore
: 0;
2792 if (ParseOnOff(act
, &all_norefresh
))
2794 if (!all_norefresh
&& fore
)
2797 Msg(0, all_norefresh
? "No refresh on window change!\n" :
2798 "Window specific refresh\n");
2801 (void)ParseSwitch(act
, &n
);
2802 fore
->w_norefresh
= n
;
2805 if (ParseSwitch(act
, &visual_bell
) || !msgok
)
2807 if (visual_bell
== 0)
2808 Msg(0, "switched to audible bell.");
2810 Msg(0, "switched to visual bell.");
2813 if (ParseNum1000(act
, &VBellWait
) == 0 && msgok
)
2814 Msg(0, "vbellwait set to %.10g seconds", VBellWait
/1000.);
2817 if (ParseNum1000(act
, &MsgWait
) == 0 && msgok
)
2818 Msg(0, "msgwait set to %.10g seconds", MsgWait
/1000.);
2821 if (ParseNum1000(act
, &MsgMinWait
) == 0 && msgok
)
2822 Msg(0, "msgminwait set to %.10g seconds", MsgMinWait
/1000.);
2824 case RC_SILENCEWAIT
:
2825 if (ParseNum(act
, &SilenceWait
))
2827 if (SilenceWait
< 1)
2829 for (p
= windows
; p
; p
= p
->w_next
)
2830 p
->w_silencewait
= SilenceWait
;
2832 Msg(0, "silencewait set to %d seconds", SilenceWait
);
2836 Msg(0, "This is window %d (%s).\n", fore
->w_number
, fore
->w_title
);
2839 int old
= fore
->w_number
;
2841 if (args
[0][0] == '+')
2843 else if (args
[0][0] == '-')
2847 parse
= ParseNum(act
, &n
);
2856 if (n
< 0 || n
>= maxwin
)
2858 Msg(0, "Given window position is invalid.");
2868 /* exchange the acls for these windows. */
2872 /* exchange the utmp-slots for these windows */
2873 if ((fore
->w_slot
!= (slot_t
) -1) && (fore
->w_slot
!= (slot_t
) 0))
2878 if (p
&& (p
->w_slot
!= (slot_t
) -1) && (p
->w_slot
!= (slot_t
) 0))
2880 /* XXX: first display wins? */
2881 display
= fore
->w_layer
.l_cvlist
? fore
->w_layer
.l_cvlist
->c_display
: 0;
2887 WindowChanged(fore
, 'n');
2888 WindowChanged((struct win
*)0, 'w');
2889 WindowChanged((struct win
*)0, 'W');
2890 WindowChanged((struct win
*)0, 0);
2894 n
= fore
->w_silence
!= 0;
2895 i
= fore
->w_silencewait
;
2896 if (args
[0] && (args
[0][0] == '-' || (args
[0][0] >= '0' && args
[0][0] <= '9')))
2898 if (ParseNum(act
, &i
))
2902 else if (ParseSwitch(act
, &n
))
2907 if (display
) /* we tell only this user */
2908 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2910 for (n
= 0; n
< maxusercount
; n
++)
2911 ACLBYTE(fore
->w_lio_notify
, n
) |= ACLBIT(n
);
2913 fore
->w_silencewait
= i
;
2914 fore
->w_silence
= SILENCE_ON
;
2915 SetTimeout(&fore
->w_silenceev
, fore
->w_silencewait
* 1000);
2916 evenq(&fore
->w_silenceev
);
2920 Msg(0, "The window is now being monitored for %d sec. silence.", fore
->w_silencewait
);
2925 if (display
) /* we remove only this user */
2926 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
)
2927 &= ~ACLBIT(D_user
->u_id
);
2929 for (n
= 0; n
< maxusercount
; n
++)
2930 ACLBYTE(fore
->w_lio_notify
, n
) &= ~ACLBIT(n
);
2931 for (i
= maxusercount
- 1; i
>= 0; i
--)
2932 if (ACLBYTE(fore
->w_lio_notify
, i
))
2937 fore
->w_silence
= SILENCE_OFF
;
2938 evdeq(&fore
->w_silenceev
);
2942 Msg(0, "The window is no longer being monitored for silence.");
2946 case RC_DEFSCROLLBACK
:
2947 (void)ParseNum(act
, &nwin_default
.histheight
);
2950 if (flayer
->l_layfn
== &MarkLf
)
2952 Msg(0, "Cannot resize scrollback buffer in copy/scrollback mode.");
2955 (void)ParseNum(act
, &n
);
2956 ChangeWindowSize(fore
, fore
->w_width
, fore
->w_height
, n
);
2958 Msg(0, "scrollback set to %d", fore
->w_histheight
);
2961 case RC_SESSIONNAME
:
2963 Msg(0, "This session is named '%s'\n", SockName
);
2966 char buf
[MAXPATHLEN
];
2969 if (ParseSaveStr(act
, &s
))
2971 if (!*s
|| strlen(s
) + (SockName
- SockPath
) > MAXPATHLEN
- 13 || index(s
, '/'))
2973 Msg(0, "%s: bad session name '%s'\n", rc_name
, s
);
2977 strncpy(buf
, SockPath
, SockName
- SockPath
);
2978 sprintf(buf
+ (SockName
- SockPath
), "%d.%s", (int)getpid(), s
);
2980 if ((access(buf
, F_OK
) == 0) || (errno
!= ENOENT
))
2982 Msg(0, "%s: inappropriate path: '%s'.", rc_name
, buf
);
2985 if (rename(SockPath
, buf
))
2987 Msg(errno
, "%s: failed to rename(%s, %s)", rc_name
, SockPath
, buf
);
2990 debug2("rename(%s, %s) done\n", SockPath
, buf
);
2991 strcpy(SockPath
, buf
);
2993 WindowChanged((struct win
*)0, 'S');
2997 if (!args
[0] || !args
[1])
2999 debug1("RC_SETENV arguments missing: %s\n", args
[0] ? args
[0] : "");
3000 InputSetenv(args
[0]);
3004 xsetenv(args
[0], args
[1]);
3013 case RC_DEFSLOWPASTE
:
3014 (void)ParseNum(act
, &nwin_default
.slow
);
3018 Msg(0, fore
->w_slowpaste
?
3019 "Slowpaste in window %d is %d milliseconds." :
3020 "Slowpaste in window %d is unset.",
3021 fore
->w_number
, fore
->w_slowpaste
);
3022 else if (ParseNum(act
, &fore
->w_slowpaste
) == 0 && msgok
)
3023 Msg(0, fore
->w_slowpaste
?
3024 "Slowpaste in window %d set to %d milliseconds." :
3025 "Slowpaste in window %d now unset.",
3026 fore
->w_number
, fore
->w_slowpaste
);
3029 if (CompileKeys(*args
, *argl
, mark_key_tab
))
3031 Msg(0, "%s: markkeys: syntax error.", rc_name
);
3034 debug1("markkeys %s\n", *args
);
3038 if (ParseSwitch(act
, &pastefont
) == 0 && msgok
)
3039 Msg(0, "Will %spaste font settings", pastefont
? "" : "not ");
3043 (void)ParseSwitch(act
, &join_with_cr
);
3045 case RC_COMPACTHIST
:
3046 if (ParseSwitch(act
, &compacthist
) == 0 && msgok
)
3047 Msg(0, "%scompacting history lines", compacthist
? "" : "not ");
3052 (void)ParseOnOff(act
, &nethackflag
);
3055 case RC_HARDCOPY_APPEND
:
3056 (void)ParseOnOff(act
, &hardcopy_append
);
3062 AddXChars(buf
, sizeof(buf
), VisualBellString
);
3063 Msg(0, "vbell_msg is '%s'", buf
);
3066 (void)ParseSaveStr(act
, &VisualBellString
);
3067 debug1(" new vbellstr '%s'\n", VisualBellString
);
3070 if (ParseBase(act
, *args
, &n
, 8, "octal"))
3072 if (n
< 0 || n
> 0777)
3074 Msg(0, "%s: mode: Invalid tty mode %o", rc_name
, n
);
3079 Msg(0, "Ttymode set to %03o", TtyMode
);
3082 (void)ParseOnOff(act
, &auto_detach
);
3084 case RC_STARTUP_MESSAGE
:
3085 (void)ParseOnOff(act
, &default_startup
);
3091 n
= (*user
->u_password
) ? 1 : 0;
3092 if (user
->u_password
!= NullStr
) free((char *)user
->u_password
);
3093 user
->u_password
= SaveStr(*args
);
3094 if (!strcmp(user
->u_password
, "none"))
3097 Msg(0, "Password checking disabled");
3098 free(user
->u_password
);
3099 user
->u_password
= NullStr
;
3106 Msg(0, "%s: password: window required", rc_name
);
3109 Input("New screen password:", 100, INP_NOECHO
, pass1
, display
? (char *)D_user
: (char *)users
, 0);
3112 #endif /* PASSWORD */
3115 struct action
*ktabp
= ktab
;
3120 if (argc
> 2 && !strcmp(*args
, "-c"))
3122 ktabp
= FindKtab(args
[1], 1);
3129 else if (argc
> 1 && !strcmp(*args
, "-k"))
3142 for (n
= 0; n
< KMAP_KEYS
; n
++)
3143 if (strcmp(term
[n
+ T_CAPS
].tcname
, *args
) == 0)
3147 Msg(0, "%s: bind: unknown key '%s'", rc_name
, *args
);
3156 Msg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name
);
3160 n
= (unsigned char)args
[0][0];
3164 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3166 Msg(0, "%s: bind: unknown command '%s'", rc_name
, args
[1]);
3169 if (CheckArgNum(i
, args
+ 2) < 0)
3171 ClearAction(&ktabp
[n
]);
3172 SaveAction(ktabp
+ n
, i
, args
+ 2, argl
+ 2);
3175 ClearAction(&ktabp
[n
]);
3181 struct action
*newact
;
3182 int newnr
, fl
= 0, kf
= 0, af
= 0, df
= 0, mf
= 0;
3183 struct display
*odisp
= display
;
3185 struct kmap_ext
*kme
;
3187 for (; *args
&& **args
== '-'; args
++, argl
++)
3189 if (strcmp(*args
, "-t") == 0)
3190 fl
= KMAP_NOTIMEOUT
;
3191 else if (strcmp(*args
, "-k") == 0)
3193 else if (strcmp(*args
, "-a") == 0)
3195 else if (strcmp(*args
, "-d") == 0)
3197 else if (strcmp(*args
, "-m") == 0)
3199 else if (strcmp(*args
, "--") == 0)
3207 Msg(0, "%s: bindkey: invalid option %s", rc_name
, *args
);
3213 Msg(0, "%s: bindkey: -d does not work with -m", rc_name
);
3219 display_bindkey("Edit mode", mmtab
);
3221 display_bindkey("Default", dmtab
);
3223 display_bindkey("User", umtab
);
3230 Msg(0, "%s: bindkey: -a only works with -k", rc_name
);
3235 Msg(0, "%s: bindkey: empty string makes no sense", rc_name
);
3238 for (i
= 0, kme
= kmap_exts
; i
< kmap_extn
; i
++, kme
++)
3245 if (*argl
== (kme
->fl
& ~KMAP_NOTIMEOUT
) && bcmp(kme
->str
, *args
, *argl
) == 0)
3251 Msg(0, "%s: bindkey: keybinding not found", rc_name
);
3255 kmap_exts
= (struct kmap_ext
*)xrealloc((char *)kmap_exts
, kmap_extn
* sizeof(*kmap_exts
));
3256 kme
= kmap_exts
+ i
;
3257 bzero((char *)kme
, 8 * sizeof(*kmap_exts
));
3258 for (; i
< kmap_extn
; i
++, kme
++)
3261 kme
->dm
.nr
= kme
->mm
.nr
= kme
->um
.nr
= RC_ILLEGAL
;
3262 kme
->dm
.args
= kme
->mm
.args
= kme
->um
.args
= noargs
;
3267 if (df
== 0 && kme
->dm
.nr
!= RC_ILLEGAL
)
3269 if (mf
== 0 && kme
->mm
.nr
!= RC_ILLEGAL
)
3271 if ((df
|| mf
) && kme
->um
.nr
!= RC_ILLEGAL
)
3273 i
+= KMAP_KEYS
+ KMAP_AKEYS
;
3274 newact
= df
? &kme
->dm
: mf
? &kme
->mm
: &kme
->um
;
3278 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
3279 if (strcmp(term
[i
].tcname
, *args
) == 0)
3283 Msg(0, "%s: bindkey: unknown key '%s'", rc_name
, *args
);
3286 if (af
&& i
>= T_CURSOR
&& i
< T_OCAPS
)
3287 i
-= T_CURSOR
- KMAP_KEYS
;
3290 newact
= df
? &dmtab
[i
] : mf
? &mmtab
[i
] : &umtab
[i
];
3294 if ((newnr
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3296 Msg(0, "%s: bindkey: unknown command '%s'", rc_name
, args
[1]);
3299 if (CheckArgNum(newnr
, args
+ 2) < 0)
3301 ClearAction(newact
);
3302 SaveAction(newact
, newnr
, args
+ 2, argl
+ 2);
3303 if (kf
== 0 && args
[1])
3307 kme
->str
= SaveStrn(*args
, *argl
);
3308 kme
->fl
= fl
| *argl
;
3312 ClearAction(newact
);
3313 for (display
= displays
; display
; display
= display
->d_next
)
3314 remap(i
, args
[1] ? 1 : 0);
3315 if (kf
== 0 && !args
[1])
3317 if (!used
&& kme
->str
)
3330 if (ParseNum(act
, &n
))
3334 Msg(0, "%s: maptimeout: illegal time %d", rc_name
, n
);
3339 if (*args
== 0 || msgok
)
3340 Msg(0, "maptimeout is %dms", maptimeout
);
3354 UsersAcl(NULL
, argc
, args
);
3357 if (UserDel(args
[0], NULL
))
3360 Msg(0, "%s removed from acl database", args
[0]);
3364 * modify a user to gain or lose rights granted to a group.
3365 * This group is actually a normal user whose rights were defined
3366 * with chacl in the usual way.
3370 if (strcmp(args
[1], "none")) /* link a user to another user */
3372 if (AclLinkUser(args
[0], args
[1]))
3375 Msg(0, "User %s joined acl-group %s", args
[0], args
[1]);
3377 else /* remove all groups from user */
3380 struct aclusergroup
*g
;
3382 if (!(u
= *FindUserPtr(args
[0])))
3384 while ((g
= u
->u_group
))
3386 u
->u_group
= g
->next
;
3391 else /* show all groups of user */
3393 char buf
[256], *p
= buf
;
3396 struct aclusergroup
*g
;
3398 if (!(u
= *FindUserPtr(args
[0])))
3401 Msg(0, "User %s does not exist.", args
[0]);
3408 sprintf(p
, "%s ", g
->u
->u_name
);
3416 Msg(0, "%s's group%s: %s.", args
[0], (ngroups
== 1) ? "" : "s",
3417 (ngroups
== 0) ? "none" : buf
);
3422 while ((s
= *args
++))
3426 if (AclUmask(display
? D_user
: users
, s
, &err
))
3427 Msg(0, "umask: %s\n", err
);
3431 if (ParseOnOff(act
, &n
))
3436 Msg(0, "Multiuser mode %s", multi
? "enabled" : "disabled");
3438 #endif /* MULTIUSER */
3446 i
= D_nonblock
>= 0;
3447 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3449 if (ParseNum1000(act
, &i
))
3452 else if (!ParseSwitch(act
, &i
))
3453 i
= i
== 0 ? -1 : 1000;
3456 if (msgok
&& i
== -1)
3457 Msg(0, "display set to blocking mode");
3458 else if (msgok
&& i
== 0)
3459 Msg(0, "display set to nonblocking mode, no timeout");
3461 Msg(0, "display set to nonblocking mode, %.10gs timeout", i
/1000.);
3463 if (D_nonblock
<= 0)
3464 evdeq(&D_blockedev
);
3466 case RC_DEFNONBLOCK
:
3467 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3469 if (ParseNum1000(act
, &defnonblock
))
3472 else if (!ParseOnOff(act
, &defnonblock
))
3473 defnonblock
= defnonblock
== 0 ? -1 : 1000;
3476 if (display
&& *rc_name
)
3478 D_nonblock
= defnonblock
;
3479 if (D_nonblock
<= 0)
3480 evdeq(&D_blockedev
);
3486 if (fore
->w_gr
== 2)
3489 if (ParseSwitch(act
, &fore
->w_gr
) == 0 && msgok
)
3490 Msg(0, "Will %suse GR", fore
->w_gr
? "" : "not ");
3492 if (fore
->w_gr
== 0 && fore
->w_FontE
)
3497 if (ParseSwitch(act
, &fore
->w_c1
) == 0 && msgok
)
3498 Msg(0, "Will %suse C1", fore
->w_c1
? "" : "not ");
3502 if (ParseSwitch(act
, &fore
->w_bce
) == 0 && msgok
)
3503 Msg(0, "Will %serase with background color", fore
->w_bce
? "" : "not ");
3510 if (*args
&& !strcmp(args
[0], "-d"))
3513 Msg(0, "encodings directory is %s", screenencodings
? screenencodings
: "<unset>");
3516 free(screenencodings
);
3517 screenencodings
= SaveStr(args
[1]);
3521 if (*args
&& !strcmp(args
[0], "-l"))
3524 Msg(0, "encoding: -l: argument required");
3525 else if (LoadFontTranslation(-1, args
[1]))
3526 Msg(0, "encoding: could not load utf8 encoding file");
3528 Msg(0, "encoding: utf8 encoding file loaded");
3532 if (*args
&& (!strcmp(args
[0], "-l") || !strcmp(args
[0], "-d")))
3535 Msg(0, "encoding: screen is not compiled for UTF-8.");
3539 for (i
= 0; i
< 2; i
++)
3543 if (!strcmp(args
[i
], "."))
3545 n
= FindEncoding(args
[i
]);
3548 Msg(0, "encoding: unknown encoding '%s'", args
[i
]);
3553 WinSwitchEncoding(fore
, n
);
3554 ResetCharsets(fore
);
3556 else if (i
&& display
)
3561 case RC_DEFENCODING
:
3562 n
= FindEncoding(*args
);
3565 Msg(0, "defencoding: unknown encoding '%s'", *args
);
3568 nwin_default
.encoding
= n
;
3574 n
= nwin_default
.encoding
== UTF8
;
3575 if (ParseSwitch(act
, &n
) == 0)
3577 nwin_default
.encoding
= n
? UTF8
: 0;
3579 Msg(0, "Will %suse UTF-8 encoding for new windows", n
? "" : "not ");
3583 for (i
= 0; i
< 2; i
++)
3585 if (i
&& args
[i
] == 0)
3588 n
= fore
->w_encoding
!= UTF8
;
3589 else if (strcmp(args
[i
], "off") == 0)
3591 else if (strcmp(args
[i
], "on") == 0)
3595 Msg(0, "utf8: illegal argument (%s)", args
[i
]);
3600 WinSwitchEncoding(fore
, n
? UTF8
: 0);
3602 Msg(0, "Will %suse UTF-8 encoding", n
? "" : "not ");
3605 D_encoding
= n
? UTF8
: 0;
3619 printcmd
= SaveStr(*args
);
3621 if (*args
== 0 || msgok
)
3624 Msg(0, "using '%s' as print command", printcmd
);
3626 Msg(0, "using termcap entries for printing");
3632 Input("Enter digraph: ", 10, INP_EVERY
, digraph_fn
, NULL
, 0);
3633 if (*args
&& **args
)
3646 if (nwin_default
.hstatus
)
3647 AddXChars(buf
, sizeof(buf
), nwin_default
.hstatus
);
3648 Msg(0, "default hstatus is '%s'", buf
);
3651 (void)ParseSaveStr(act
, &nwin_default
.hstatus
);
3652 if (*nwin_default
.hstatus
== 0)
3654 free(nwin_default
.hstatus
);
3655 nwin_default
.hstatus
= 0;
3659 (void)ParseSaveStr(act
, &fore
->w_hstatus
);
3660 if (*fore
->w_hstatus
== 0)
3662 free(fore
->w_hstatus
);
3663 fore
->w_hstatus
= 0;
3665 WindowChanged(fore
, 'h');
3675 if (nwin_default
.charset
)
3676 AddXChars(buf
, sizeof(buf
), nwin_default
.charset
);
3677 Msg(0, "default charset is '%s'", buf
);
3681 if (n
== 0 || n
> 6)
3683 Msg(0, "%s: %s: string has illegal size.", rc_name
, comms
[nr
].name
);
3687 ((args
[0][4] < '0' || args
[0][4] > '3') && args
[0][4] != '.') ||
3688 ((args
[0][5] < '0' || args
[0][5] > '3') && args
[0][5] && args
[0][5] != '.')))
3690 Msg(0, "%s: %s: illegal mapping number.", rc_name
, comms
[nr
].name
);
3693 if (nr
== RC_CHARSET
)
3695 SetCharsets(fore
, *args
);
3698 if (nwin_default
.charset
)
3699 free(nwin_default
.charset
);
3700 nwin_default
.charset
= SaveStr(*args
);
3706 if (*s
>= '0' && *s
<= '9')
3709 for (i
= 0; i
< 8; i
++)
3710 if (*s
== "dubrsBiI"[i
])
3714 if (*s
&& s
[1] && !s
[2])
3716 if (*s
== 'd' && s
[1] == 'd')
3718 else if (*s
== '.' && s
[1] == 'd')
3720 else if (*s
== 'd' && s
[1] == '.')
3722 else if (*s
!= '.' || s
[1] != '.')
3726 if (*s
|| i
< 0 || i
>= 8)
3728 Msg(0, "%s: attrcolor: unknown attribute '%s'.", rc_name
, args
[0]);
3733 n
= ParseAttrColor(args
[1], args
[2], 1);
3736 attr2color
[i
][nr
] = n
;
3738 for (i
= 0; i
< 8; i
++)
3739 if (attr2color
[i
][0] || attr2color
[i
][1] || attr2color
[i
][2] || attr2color
[i
][3])
3744 case RC_SORENDITION
:
3748 i
= ParseAttrColor(*args
, args
[1], 1);
3751 ApplyAttrColor(i
, &mchar_so
);
3752 debug2("--> %x %x\n", mchar_so
.attr
, mchar_so
.color
);
3756 Msg(0, "Standout attributes 0x%02x color 0x%02x", (unsigned char)mchar_so
.attr
, 0x99 ^ (unsigned char)mchar_so
.color
);
3758 Msg(0, "Standout attributes 0x%02x ", (unsigned char)mchar_so
.attr
);
3771 Msg(0, "%s:%s screen login", HostName
, SockPath
);
3772 InputSu(D_fore
, &D_user
, NULL
);
3775 InputSu(D_fore
, &D_user
, args
[0]);
3777 s
= DoSu(&D_user
, args
[0], args
[1], "\377");
3779 s
= DoSu(&D_user
, args
[0], args
[1], args
[2]);
3783 #endif /* MULTIUSER */
3786 if (s
&& !strcmp(s
, "-v"))
3787 AddCanvas(SLICE_HORI
);
3789 AddCanvas(SLICE_VERT
);
3801 D_forecv
->c_xoff
= D_forecv
->c_xs
;
3802 D_forecv
->c_yoff
= D_forecv
->c_ys
;
3803 RethinkViewportOffsets(D_forecv
);
3804 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
3805 flayer
= D_forecv
->c_layer
;
3809 if (!*args
|| !strcmp(*args
, "down"))
3810 D_forecv
= D_forecv
->c_next
? D_forecv
->c_next
: D_cvlist
;
3811 else if (!strcmp(*args
, "up"))
3814 for (cv
= D_cvlist
; cv
->c_next
&& cv
->c_next
!= D_forecv
; cv
= cv
->c_next
)
3818 else if (!strcmp(*args
, "top"))
3819 D_forecv
= D_cvlist
;
3820 else if (!strcmp(*args
, "bottom"))
3823 for (cv
= D_cvlist
; cv
->c_next
; cv
= cv
->c_next
)
3829 Msg(0, "%s: usage: focus [up|down|top|bottom]", rc_name
);
3832 if ((focusminwidth
&& (focusminwidth
< 0 || D_forecv
->c_xe
- D_forecv
->c_xs
+ 1 < focusminwidth
)) ||
3833 (focusminheight
&& (focusminheight
< 0 || D_forecv
->c_ye
- D_forecv
->c_ys
+ 1 < focusminheight
)))
3835 ResizeCanvas(&D_canvas
);
3836 RecreateCanvasChain();
3837 RethinkDisplayViewports();
3838 ResizeLayersToCanvases(); /* redisplays */
3840 fore
= D_fore
= Layer2Window(D_forecv
->c_layer
);
3841 flayer
= D_forecv
->c_layer
;
3843 if (D_xtermosc
[2] || D_xtermosc
[3])
3853 flayer
= D_forecv
->c_layer
;
3854 CV_CALL(D_forecv
, LayRestore();LaySetCursor());
3855 WindowChanged(0, 'F');
3859 if (D_forecv
->c_slorient
== SLICE_UNKN
)
3861 Msg(0, "resize: need more than one region");
3864 for (; *args
; args
++)
3866 if (!strcmp(*args
, "-h"))
3868 else if (!strcmp(*args
, "-v"))
3870 else if (!strcmp(*args
, "-b"))
3871 i
|= RESIZE_FLAG_H
| RESIZE_FLAG_V
;
3872 else if (!strcmp(*args
, "-p"))
3873 i
|= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
3874 else if (!strcmp(*args
, "-l"))
3879 if (*args
&& args
[1])
3881 Msg(0, "%s: usage: resize [-h] [-v] [-l] [num]\n", rc_name
);
3885 ResizeRegions(*args
, i
);
3887 Input(resizeprompts
[i
], 20, INP_EVERY
, ResizeFin
, (char*)0, i
);
3890 (void)ParseSwitch(act
, &separate_sids
);
3893 args
= SaveArgs(args
);
3894 for (i
= 0; args
[i
]; i
++)
3897 Colonfin(args
[i
], strlen(args
[i
]), (char *)0);
3903 (void)ParseSwitch(act
, &use_altscreen
);
3905 Msg(0, "Will %sdo alternate screen switching", use_altscreen
? "" : "not ");
3908 if (ParseNum(act
, &n
))
3911 Msg(0, "illegal maxwin number specified");
3912 else if (n
> maxwin
)
3913 Msg(0, "may only decrease maxwin number");
3918 if (ParseBase(act
, *args
, &n
, 10, "decimal"))
3921 setbacktick(n
, 0, 0, (char **)0);
3927 Msg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name
);
3930 if (ParseBase(act
, args
[1], &lifespan
, 10, "decimal"))
3932 if (ParseBase(act
, args
[2], &tick
, 10, "decimal"))
3934 setbacktick(n
, lifespan
, tick
, SaveArgs(args
+ 3));
3936 WindowChanged(0, '`');
3942 RunBlanker(blankerprg
);
3947 CursorVisibility(-1);
3955 for (pp
= blankerprg
; *pp
; pp
++)
3961 blankerprg
= SaveArgs(args
);
3967 struct display
*olddisplay
= display
;
3968 if (!strcmp(*args
, "off"))
3970 else if (args
[0][0])
3971 idletimo
= atoi(*args
) * 1000;
3974 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3976 Msg(0, "%s: idle: unknown command '%s'", rc_name
, args
[1]);
3979 if (CheckArgNum(i
, args
+ 2) < 0)
3981 ClearAction(&idleaction
);
3982 SaveAction(&idleaction
, i
, args
+ 2, argl
+ 2);
3984 for (display
= displays
; display
; display
= display
->d_next
)
3986 display
= olddisplay
;
3991 Msg(0, "idle timeout %ds, %s", idletimo
/ 1000, comms
[idleaction
.nr
].name
);
3996 case RC_FOCUSMINSIZE
:
3997 for (i
= 0; i
< 2 && args
[i
]; i
++)
3999 if (!strcmp(args
[i
], "max") || !strcmp(args
[i
], "_"))
4011 for (i
= 0; i
< 2; i
++)
4013 n
= i
== 0 ? focusminwidth
: focusminheight
;
4015 strcpy(b
[i
], "max");
4017 sprintf(b
[i
], "%d", n
);
4019 Msg(0, "focus min size is %s %s\n", b
[0], b
[1]);
4028 fore
->w_group
= WindowByName(*args
);
4029 if (fore
->w_group
&& fore
->w_group
->w_type
!= W_TYPE_GROUP
)
4032 WindowChanged((struct win
*)0, 'w');
4033 WindowChanged((struct win
*)0, 'W');
4034 WindowChanged((struct win
*)0, 0);
4039 Msg(0, "window group is %d (%s)\n", fore
->w_group
->w_number
, fore
->w_group
->w_title
);
4041 Msg(0, "window belongs to no group");
4045 if (!strcmp(args
[0], "title"))
4049 Msg(0, "not on a layout");
4054 Msg(0, "current layout is %d (%s)", D_layout
->lay_number
, D_layout
->lay_title
);
4057 free(D_layout
->lay_title
);
4058 D_layout
->lay_title
= SaveStr(args
[1]);
4060 else if (!strcmp(args
[0], "number"))
4066 Msg(0, "This is layout %d (%s).\n", D_layout
->lay_number
, D_layout
->lay_title
);
4069 old
= D_layout
->lay_number
;
4071 if (n
< 0 || n
>= MAXLAY
)
4074 laytab
[n
] = D_layout
;
4075 D_layout
->lay_number
= n
;
4078 lay
->lay_number
= old
;
4081 else if (!strcmp(args
[0], "autosave"))
4085 Msg(0, "not on a layout");
4090 if (!strcmp(args
[1], "on"))
4091 D_layout
->lay_autosave
= 1;
4092 else if (!strcmp(args
[1], "off"))
4093 D_layout
->lay_autosave
= 0;
4096 Msg(0, "invalid argument. Give 'on' or 'off");
4101 Msg(0, "autosave is %s", D_layout
->lay_autosave
? "on" : "off");
4103 else if (!strcmp(args
[0], "new"))
4109 while (*t
>= '0' && *t
<= '9')
4111 if (t
!= args
[1] && (!*t
|| *t
== ':'))
4125 else if (!strcmp(args
[0], "save"))
4129 Msg(0, "usage: layout save <name>");
4132 SaveLayout(args
[1], &D_canvas
);
4134 else if (!strcmp(args
[0], "select"))
4138 Input("Switch to layout: ", 20, INP_COOKED
, SelectLayoutFin
, NULL
, 0);
4141 SelectLayoutFin(args
[1], strlen(args
[1]), (char *)0);
4143 else if (!strcmp(args
[0], "next"))
4145 struct layout
*lay
= D_layout
;
4147 lay
= lay
->lay_next
? lay
->lay_next
: layouts
;
4152 Msg(0, "no layout defined");
4155 if (lay
== D_layout
)
4157 LoadLayout(lay
, &D_canvas
);
4160 else if (!strcmp(args
[0], "prev"))
4162 struct layout
*lay
= D_layout
;
4165 for (lay
= layouts
; lay
->lay_next
&& lay
->lay_next
!= D_layout
; lay
= lay
->lay_next
)
4172 Msg(0, "no layout defined");
4175 if (lay
== D_layout
)
4177 LoadLayout(lay
, &D_canvas
);
4180 else if (!strcmp(args
[0], "attach"))
4185 Msg(0, "no attach layout set");
4186 else if (layout_attach
== &layout_last_marker
)
4187 Msg(0, "will attach to last layout");
4189 Msg(0, "will attach to layout %d (%s)", layout_attach
->lay_number
, layout_attach
->lay_title
);
4192 if (!strcmp(args
[1], ":last"))
4193 layout_attach
= &layout_last_marker
;
4194 else if (!args
[1][0])
4199 lay
= FindLayout(args
[1]);
4202 Msg(0, "unknown layout '%s'", args
[1]);
4205 layout_attach
= lay
;
4208 else if (!strcmp(args
[0], "show"))
4213 Msg(0, "unknown layout subcommand");
4217 if(ParseSwitch(act
, &cjkwidth
) == 0)
4220 Msg(0, "Treat ambiguous width characters as %s width", cjkwidth
? "full" : "half");
4226 /* key == -2: input from braille keybord, msgok always 0 */
4227 DoBrailleAction(act
, key
== -2 ? 0 : msgok
);
4231 if (display
!= odisplay
)
4233 for (display
= displays
; display
; display
= display
->d_next
)
4234 if (display
== odisplay
)
4240 DoCommand(argv
, argl
)
4246 if ((act
.nr
= FindCommnr(*argv
)) == RC_ILLEGAL
)
4248 Msg(0, "%s: unknown command '%s'", rc_name
, *argv
);
4251 act
.args
= argv
+ 1;
4252 act
.argl
= argl
+ 1;
4257 SaveAction(act
, nr
, args
, argl
)
4263 register int argc
= 0;
4277 if ((pp
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4279 if ((lp
= (int *)malloc((unsigned)(argc
) * sizeof(int *))) == 0)
4286 *lp
= argl
? *argl
++ : (int)strlen(*args
);
4287 *pp
++ = SaveStrn(*args
++, *lp
++);
4296 register char **ap
, **pp
;
4297 register int argc
= 0;
4301 if ((pp
= ap
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4304 *pp
++ = SaveStr(*args
++);
4311 * buf is split into argument vector args.
4312 * leading whitespace is removed.
4313 * @!| abbreviations are expanded.
4314 * the end of buffer is recognized by '\0' or an un-escaped '#'.
4315 * " and ' are interpreted.
4320 Parse(buf
, bufl
, args
, argl
)
4324 register char *p
= buf
, **ap
= args
, *pp
;
4325 register int delim
, argc
;
4328 debug2("Parse %d %s\n", bufl
, buf
);
4334 while (*p
&& (*p
== ' ' || *p
== '\t'))
4337 if (argc
== 0 && *p
== '!')
4346 if (*p
== '\0' || *p
== '#' || *p
== '\n')
4349 for (delim
= 0; delim
< argc
; delim
++)
4350 debug1("-- %s\n", args
[delim
]);
4354 if (++argc
>= MAXARGS
)
4356 Msg(0, "%s: too many tokens.", rc_name
);
4361 debug1("- new arg %s\n", p
);
4366 else if (delim
!= '\'' && *p
== '\\' && (p
[1] == '\'' || p
[1] == '"' || p
[1] == '\\' || p
[1] == '$' || p
[1] == '#' || p
[1] == '^' || (p
[1] >= '0' && p
[1] <= '7')))
4369 if (*p
>= '0' && *p
<= '7')
4372 if (p
[1] >= '0' && p
[1] <= '7')
4375 *pp
= (*pp
<< 3) | (*p
- '0');
4376 if (p
[1] >= '0' && p
[1] <= '7')
4379 *pp
= (*pp
<< 3) | (*p
- '0');
4387 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] == '_'))
4390 char *ps
, *pe
, op
, *v
, xbuf
[11];
4394 debug1("- var %s\n", ps
);
4398 if (*ps
== '{' && *p
== '}')
4400 if (*ps
== ':' && *p
== ':')
4402 if (*ps
!= '{' && *ps
!= ':' && (*p
< 'a' || *p
> 'z') && (*p
< 'A' || *p
> 'Z') && (*p
< '0' || *p
> '9') && *p
!= '_')
4407 if (*ps
== '{' || *ps
== ':')
4411 Msg(0, "%s: bad variable name.", rc_name
);
4418 debug1("- var is '%s'\n", ps
);
4420 v
= gettermcapstring(ps
+ 1);
4426 if (!strcmp(ps
, "TERM"))
4427 v
= display
? D_termname
: "unknown";
4428 else if (!strcmp(ps
, "COLUMNS"))
4429 sprintf(xbuf
, "%d", display
? D_width
: -1);
4430 else if (!strcmp(ps
, "LINES"))
4431 sprintf(xbuf
, "%d", display
? D_height
: -1);
4436 vl
= v
? strlen(v
) : 0;
4439 debug1("- sub is '%s'\n", v
);
4442 int right
= buf
+ bufl
- (p
+ strlen(p
) + 1);
4445 bcopy(p
, p
+ right
, strlen(p
) + 1);
4451 Msg(0, "%s: no space left for variable expansion.", rc_name
);
4459 else if (delim
!= '\'' && *p
== '^' && p
[1])
4462 *pp
++ = *p
== '?' ? '\177' : *p
& 0x1f;
4464 else if (delim
== 0 && (*p
== '\'' || *p
== '"'))
4466 else if (delim
== 0 && (*p
== ' ' || *p
== '\t' || *p
== '\n'))
4474 Msg(0, "%s: Missing %c quote.", rc_name
, delim
);
4480 debug2("- arg done, '%s' rest %s\n", ap
[-1], p
);
4481 *lp
++ = pp
- ap
[-1];
4500 if (DefaultEsc
>= 0)
4501 ClearAction(&ktab
[DefaultEsc
]);
4502 if (DefaultMetaEsc
>= 0)
4503 ClearAction(&ktab
[DefaultMetaEsc
]);
4506 DefaultMetaEsc
= me
;
4509 if (DefaultEsc
>= 0)
4511 ClearAction(&ktab
[DefaultEsc
]);
4512 ktab
[DefaultEsc
].nr
= RC_OTHER
;
4514 if (DefaultMetaEsc
>= 0)
4516 ClearAction(&ktab
[DefaultMetaEsc
]);
4517 ktab
[DefaultMetaEsc
].nr
= RC_META
;
4524 ParseSwitch(act
, var
)
4528 if (*act
->args
== 0)
4533 return ParseOnOff(act
, var
);
4537 ParseOnOff(act
, var
)
4541 register int num
= -1;
4542 char **args
= act
->args
;
4546 if (strcmp(args
[0], "on") == 0)
4548 else if (strcmp(args
[0], "off") == 0)
4553 Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name
, comms
[act
->nr
].name
);
4561 ParseSaveStr(act
, var
)
4565 char **args
= act
->args
;
4566 if (*args
== 0 || args
[1])
4568 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4573 *var
= SaveStr(*args
);
4583 char *p
, **args
= act
->args
;
4586 if (p
== 0 || *p
== 0 || args
[1])
4588 Msg(0, "%s: %s: invalid argument. Give one argument.",
4589 rc_name
, comms
[act
->nr
].name
);
4595 if (*p
>= '0' && *p
<= '9')
4596 i
= 10 * i
+ (*p
- '0');
4599 Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4600 rc_name
, comms
[act
->nr
].name
);
4605 debug1("ParseNum got %d\n", i
);
4611 ParseNum1000(act
, var
)
4616 char *p
, **args
= act
->args
;
4620 if (p
== 0 || *p
== 0 || args
[1])
4622 Msg(0, "%s: %s: invalid argument. Give one argument.",
4623 rc_name
, comms
[act
->nr
].name
);
4629 if (*p
>= '0' && *p
<= '9')
4632 i
= 10 * i
+ (*p
- '0');
4633 else if (dig
== 4 && *p
>= '5')
4638 else if (*p
== '.' && !dig
)
4642 Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4643 rc_name
, comms
[act
->nr
].name
);
4654 i
= (int)((unsigned int)~0 >> 1);
4655 debug1("ParseNum1000 got %d\n", i
);
4666 for (p
= windows
; p
; p
= p
->w_next
)
4667 if (!strcmp(p
->w_title
, s
))
4669 for (p
= windows
; p
; p
= p
->w_next
)
4670 if (!strncmp(p
->w_title
, s
, strlen(s
)))
4682 for (i
= 0, s
= str
; *s
; s
++)
4684 if (*s
< '0' || *s
> '9')
4686 i
= i
* 10 + (*s
- '0');
4692 * Get window number from Name or Number string.
4693 * Numbers are tried first, then names, a prefix match suffices.
4694 * Be careful when assigning numeric strings as WindowTitles.
4703 if ((i
= WindowByNumber(str
)) < 0 || i
>= MAXWIN
)
4705 if ((p
= WindowByName(str
)))
4713 ParseWinNum(act
, var
)
4717 char **args
= act
->args
;
4720 if (*args
== 0 || args
[1])
4722 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4726 i
= WindowByNoN(*args
);
4729 Msg(0, "%s: %s: invalid argument. Give window number or name.",
4730 rc_name
, comms
[act
->nr
].name
);
4733 debug1("ParseWinNum got %d\n", i
);
4739 ParseBase(act
, p
, var
, base
, bname
)
4751 Msg(0, "%s: %s: empty argument.", rc_name
, comms
[act
->nr
].name
);
4756 if (c
>= 'a' && c
<= 'z')
4758 if (c
>= 'A' && c
<= 'Z')
4759 c
-= 'A' - ('0' + 10);
4761 if (c
< 0 || c
>= base
)
4763 Msg(0, "%s: %s: argument is not %s.", rc_name
, comms
[act
->nr
].name
, bname
);
4768 debug1("ParseBase got %d\n", i
);
4778 for (base
+= '0'; *s
; ++s
)
4779 if (*s
< '0' || *s
> base
)
4785 IsNumColon(s
, base
, p
, psize
)
4790 if ((q
= rindex(s
, ':')) != 0)
4792 strncpy(p
, q
+ 1, psize
- 1);
4793 p
[psize
- 1] = '\0';
4798 return IsNum(s
, base
);
4807 debug1("SwitchWindow %d\n", n
);
4808 if (n
< 0 || n
>= MAXWIN
)
4813 if ((p
= wtab
[n
]) == 0)
4825 Msg(0, "This IS window %d (%s).", n
, p
->w_title
);
4829 if (AclCheckPermWin(D_user
, ACL_READ
, p
))
4831 Msg(0, "Access to window %d denied.", p
->w_number
);
4836 Activate(fore
->w_norefresh
);
4841 SetCanvasWindow(cv
, wi
)
4845 struct win
*p
= 0, **pp
;
4847 struct canvas
*cvp
, **cvpp
;
4850 display
= cv
->c_display
;
4854 /* remove old layer */
4855 for (cvpp
= &l
->l_cvlist
; (cvp
= *cvpp
); cvpp
= &cvp
->c_lnext
)
4859 *cvpp
= cvp
->c_lnext
;
4861 p
= Layer2Window(l
);
4865 if (p
&& cv
== D_forecv
)
4868 ReleaseAutoWritelock(display
, p
);
4872 SetTimeout(&p
->w_silenceev
, p
->w_silencewait
* 1000);
4873 evenq(&p
->w_silenceev
);
4878 if (l
->l_cvlist
== 0 && (p
== 0 || l
!= p
->w_savelayer
))
4882 /* find right layer to display on canvas */
4883 if (wi
&& wi
->w_type
!= W_TYPE_GROUP
)
4886 if (wi
->w_savelayer
&& (wi
->w_blocked
|| wi
->w_savelayer
->l_cvlist
== 0))
4887 l
= wi
->w_savelayer
;
4893 l
->l_data
= (char *)wi
;
4898 /* add our canvas to the layer's canvaslist */
4899 ASSERT(l
->l_cvlist
!= cv
);
4900 cv
->c_lnext
= l
->l_cvlist
;
4903 cv
->c_xoff
= cv
->c_xs
;
4904 cv
->c_yoff
= cv
->c_ys
;
4905 RethinkViewportOffsets(cv
);
4910 if (wi
&& wi
->w_type
== W_TYPE_GROUP
)
4912 /* auto-start windowlist on groups */
4913 struct display
*d
= display
;
4914 struct layer
*oldflayer
= flayer
;
4916 display_wlist(0, 0, wi
);
4921 if (wi
&& D_other
== wi
)
4922 D_other
= wi
->w_next
; /* Might be 0, but that's OK. */
4926 fore
= D_fore
; /* XXX ? */
4930 ObtainAutoWritelock(display
, wi
);
4933 * Place the window at the head of the most-recently-used list
4937 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
4942 p
->w_next
= windows
;
4952 * SetForeWindow changes the window in the input focus of the display.
4953 * Puts window wi in canvas display->d_forecv.
4965 p
= Layer2Window(D_forecv
->c_layer
);
4966 SetCanvasWindow(D_forecv
, wi
);
4968 WindowChanged(p
, 'u');
4970 WindowChanged(wi
, 'u');
4971 flayer
= D_forecv
->c_layer
;
4972 /* Activate called afterwards, so no RefreshHStatus needed */
4976 /*****************************************************************/
4979 * Activate - make fore window active
4980 * norefresh = -1 forces a refresh, disregard all_norefresh then.
4986 debug1("Activate(%d)\n", norefresh
);
4991 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
4995 if (MayResizeLayer(D_forecv
->c_layer
))
4996 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, display
);
5002 if (fore
->w_monitor
!= MON_OFF
)
5003 fore
->w_monitor
= MON_ON
;
5004 fore
->w_bell
= BELL_ON
;
5005 WindowChanged(fore
, 'f');
5008 if (ResizeDisplay(fore
->w_width
, fore
->w_height
))
5010 debug2("Cannot resize from (%d,%d)", D_width
, D_height
);
5011 debug2(" to (%d,%d) -> resize window\n", fore
->w_width
, fore
->w_height
);
5012 DoResize(D_width
, D_height
);
5016 Redisplay(norefresh
+ all_norefresh
);
5023 register struct win
**pp
;
5024 int n
= fore
? fore
->w_number
: MAXWIN
;
5025 struct win
*group
= fore
? fore
->w_group
: 0;
5027 for (pp
= fore
? wtab
+ n
+ 1 : wtab
; pp
!= wtab
+ n
; pp
++)
5029 if (pp
== wtab
+ MAXWIN
)
5033 if (!fore
|| group
== (*pp
)->w_group
)
5045 register struct win
**pp
;
5046 int n
= fore
? fore
->w_number
: -1;
5047 struct win
*group
= fore
? fore
->w_group
: 0;
5049 for (pp
= wtab
+ n
- 1; pp
!= wtab
+ n
; pp
--)
5052 pp
= wtab
+ MAXWIN
- 1;
5055 if (!fore
|| group
== (*pp
)->w_group
)
5067 char *m
= "No other window.";
5068 if (windows
&& (fore
== 0 || windows
->w_next
))
5072 Msg(0, "No window available");
5075 Msg(0, m
, fore
->w_number
); /* other arg for nethack */
5080 UpdateLayoutCanvas(cv
, wi
)
5084 for (; cv
; cv
= cv
->c_slnext
)
5086 if (cv
->c_layer
&& Layer2Window(cv
->c_layer
) == wi
)
5088 /* A simplistic version of SetCanvasWindow(cv, 0) */
5089 struct layer
*l
= cv
->c_layer
;
5091 if (l
->l_cvlist
== 0 && (wi
== 0 || l
!= wi
->w_savelayer
))
5095 if (l
->l_cvlist
!= cv
)
5097 cv
->c_lnext
= l
->l_cvlist
;
5101 /* Do not end here. Multiple canvases can have the same window */
5105 UpdateLayoutCanvas(cv
->c_slperp
, wi
);
5113 struct win
**pp
, *p
;
5119 * Remove window from linked list.
5121 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5127 wtab
[wi
->w_number
] = 0;
5136 * switch to different window on all canvases
5138 for (display
= displays
; display
; display
= display
->d_next
)
5141 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5143 if (Layer2Window(cv
->c_layer
) != wi
)
5145 /* switch to other window */
5146 SetCanvasWindow(cv
, FindNiceWindow(D_other
, 0));
5152 if (wi
->w_zdisplay
== display
)
5155 D_readev
.condpos
= D_readev
.condneg
= 0;
5162 /* do the same for the layouts */
5163 for (lay
= layouts
; lay
; lay
= lay
->lay_next
)
5164 UpdateLayoutCanvas(&lay
->lay_canvas
, wi
);
5167 WindowChanged((struct win
*)0, 'w');
5168 WindowChanged((struct win
*)0, 'W');
5169 WindowChanged((struct win
*)0, 0);
5178 if ((fore
->w_log
!= 0) == on
)
5180 if (display
&& !*rc_name
)
5181 Msg(0, "You are %s logging.", on
? "already" : "not");
5184 if (fore
->w_log
!= 0)
5186 Msg(0, "Logfile \"%s\" closed.", fore
->w_log
->name
);
5187 logfclose(fore
->w_log
);
5189 WindowChanged(fore
, 'f');
5192 if (DoStartLog(fore
, buf
, sizeof(buf
)))
5194 Msg(errno
, "Error opening logfile \"%s\"", buf
);
5197 if (ftell(fore
->w_log
->fp
) == 0)
5198 Msg(0, "Creating logfile \"%s\".", fore
->w_log
->name
);
5200 Msg(0, "Appending to logfile \"%s\".", fore
->w_log
->name
);
5201 WindowChanged(fore
, 'f');
5205 AddWindows(buf
, len
, flags
, where
)
5211 register char *s
, *ss
;
5212 register struct win
**pp
, *p
;
5217 for (pp
= ((flags
& 4) && where
>= 0) ? wtab
+ where
+ 1: wtab
; pp
< wtab
+ MAXWIN
; pp
++)
5219 if (pp
- wtab
== where
&& ss
== buf
)
5223 if ((flags
& 1) && display
&& p
== D_fore
)
5225 if (D_fore
&& D_fore
->w_group
!= p
->w_group
)
5232 if (s
- buf
+ l
> len
- 24)
5234 if (s
> buf
|| (flags
& 4))
5239 sprintf(s
, "%d", p
->w_number
);
5240 if (p
->w_number
== where
)
5243 if (display
&& p
== D_fore
)
5247 if (display
&& p
== D_other
)
5249 s
= AddWindowFlags(s
, len
, p
);
5260 AddWindowFlags(buf
, len
, p
)
5266 if (p
== 0 || len
< 12)
5272 if (display
&& p
== D_fore
)
5274 if (display
&& p
== D_other
)
5277 if (p
->w_layer
.l_cvlist
&& p
->w_layer
.l_cvlist
->c_lnext
)
5279 if (p
->w_monitor
== MON_DONE
5281 && (ACLBYTE(p
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5285 if (p
->w_bell
== BELL_DONE
)
5288 if (p
->w_slot
!= (slot_t
) 0 && p
->w_slot
!= (slot_t
) -1)
5296 if (p
->w_ptyfd
< 0 && p
->w_type
!= W_TYPE_GROUP
)
5303 AddOtherUsers(buf
, len
, p
)
5308 struct display
*d
, *olddisplay
= display
;
5314 for (display
= displays
; display
; display
= display
->d_next
)
5316 if (olddisplay
&& D_user
== olddisplay
->d_user
)
5318 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5319 if (Layer2Window(cv
->c_layer
) == p
)
5323 for (d
= displays
; d
&& d
!= display
; d
= d
->d_next
)
5324 if (D_user
== d
->d_user
)
5326 if (d
&& d
!= display
)
5328 if (len
> 1 && s
!= buf
)
5333 l
= strlen(D_user
->u_name
);
5336 strcpy(s
, D_user
->u_name
);
5341 display
= olddisplay
;
5354 if (where
== -1 && D_fore
)
5355 where
= D_fore
->w_number
;
5356 ss
= AddWindows(buf
, sizeof(buf
), 0, where
);
5357 s
= buf
+ strlen(buf
);
5358 if (ss
- buf
> D_width
/ 2)
5361 if (s
- ss
< D_width
)
5377 register struct win
*wp
= fore
;
5382 Msg(0, "(%d,%d)/(%d,%d) no window", D_x
+ 1, D_y
+ 1, D_width
, D_height
);
5386 if (buf
< (p
+= GetAnsiStatus(wp
, p
)))
5388 sprintf(p
, "(%d,%d)/(%d,%d)",
5389 wp
->w_x
+ 1, wp
->w_y
+ 1, wp
->w_width
, wp
->w_height
);
5391 sprintf(p
+= strlen(p
), "+%d", wp
->w_histheight
);
5393 sprintf(p
+= strlen(p
), " %c%sflow",
5394 (wp
->w_flow
& FLOW_NOW
) ? '+' : '-',
5395 (wp
->w_flow
& FLOW_AUTOFLAG
) ? "" :
5396 ((wp
->w_flow
& FLOW_AUTO
) ? "(+)" : "(-)"));
5397 if (!wp
->w_wrap
) sprintf(p
+= strlen(p
), " -wrap");
5398 if (wp
->w_insert
) sprintf(p
+= strlen(p
), " ins");
5399 if (wp
->w_origin
) sprintf(p
+= strlen(p
), " org");
5400 if (wp
->w_keypad
) sprintf(p
+= strlen(p
), " app");
5401 if (wp
->w_log
) sprintf(p
+= strlen(p
), " log");
5402 if (wp
->w_monitor
!= MON_OFF
5404 && (ACLBYTE(wp
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5407 sprintf(p
+= strlen(p
), " mon");
5408 if (wp
->w_mouse
) sprintf(p
+= strlen(p
), " mouse");
5410 if (wp
->w_bce
) sprintf(p
+= strlen(p
), " bce");
5412 if (!wp
->w_c1
) sprintf(p
+= strlen(p
), " -c1");
5413 if (wp
->w_norefresh
) sprintf(p
+= strlen(p
), " nored");
5418 if (wp
->w_encoding
&& (display
== 0 || D_encoding
!= wp
->w_encoding
|| EncodingDefFont(wp
->w_encoding
) <= 0))
5421 strcpy(p
, EncodingName(wp
->w_encoding
));
5425 if (wp
->w_encoding
!= UTF8
)
5428 if (D_CC0
|| (D_CS0
&& *D_CS0
))
5432 sprintf(p
, " G%c", wp
->w_Charset
+ '0');
5433 if (wp
->w_FontE
>= ' ')
5438 p
[4] = wp
->w_FontE
^ 0x40;
5445 sprintf(p
++, " G%c%c[", wp
->w_Charset
+ '0', wp
->w_CharsetR
+ '0');
5447 sprintf(p
, " G%c[", wp
->w_Charset
+ '0');
5449 for (i
= 0; i
< 4; i
++)
5451 if (wp
->w_charsets
[i
] == ASCII
)
5453 else if (wp
->w_charsets
[i
] >= ' ')
5454 *p
++ = wp
->w_charsets
[i
];
5458 *p
++ = wp
->w_charsets
[i
] ^ 0x40;
5466 if (wp
->w_type
== W_TYPE_PLAIN
)
5468 /* add info about modem control lines */
5470 TtyGetModemStatus(wp
->w_ptyfd
, p
);
5472 #ifdef BUILTIN_TELNET
5473 else if (wp
->w_type
== W_TYPE_TELNET
)
5476 TelStatus(wp
, p
, sizeof(buf
) - 1 - (p
- buf
));
5479 Msg(0, "%s %d(%s)", buf
, wp
->w_number
, wp
->w_title
);
5489 sprintf(p
, "(%d,%d)", D_width
, D_height
),
5495 strcpy(p
, EncodingName(D_encoding
));
5501 strcpy(p
, " xterm");
5507 strcpy(p
, " color");
5514 strcpy(p
, " iso2022");
5517 else if (D_CS0
&& *D_CS0
)
5519 strcpy(p
, " altchar");
5527 AKAfin(buf
, len
, data
)
5530 char *data
; /* dummy */
5534 ChangeAKA(fore
, buf
, strlen(buf
));
5542 Input("Set window's title to: ", sizeof(fore
->w_akabuf
) - 1, INP_COOKED
, AKAfin
, NULL
, 0);
5548 if ((*(unsigned char *)s
& 0x7f) < 0x20 || *s
== 0x7f)
5552 LayProcess(&ss
, &n
);
5557 Colonfin(buf
, len
, data
)
5560 char *data
; /* dummy */
5565 if (buf
[len
] == '\t')
5568 int l
= 0, r
= RC_LAST
;
5569 int showmessage
= 0;
5572 while (*s
&& s
- buf
< len
)
5576 /* Showing a message when there's no hardstatus or caption cancels the input */
5578 (captionalways
|| D_has_hstatus
== HSTATUS_LASTLINE
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
)))
5584 x
= strncmp(buf
, comms
[m
].name
, len
);
5592 for (l
= m
- 1; l
>= 0 && strncmp(buf
, comms
[l
].name
, len
) == 0; l
--)
5594 for (m
= ++l
; m
<= r
&& strncmp(buf
, comms
[m
].name
, len
) == 0 && s
- mbuf
< sizeof(mbuf
); m
++)
5595 s
+= snprintf(s
, sizeof(mbuf
) - (s
- mbuf
), " %s", comms
[m
].name
);
5599 Msg(0, "Possible commands:%s", mbuf
);
5604 len
= snprintf(mbuf
, sizeof(mbuf
), "%s \t", comms
[l
].name
+ len
);
5605 if (len
> 0 && len
< sizeof(mbuf
))
5606 LayProcess(&s
, &len
);
5611 if (l
> r
&& showmessage
)
5612 Msg(0, "No commands matching '%*s'", len
, buf
);
5616 if (!len
|| buf
[len
])
5619 len
= strlen(buf
) + 1;
5620 if (len
> (int)sizeof(mbuf
))
5624 bcopy(buf
, mbuf
, len
);
5625 RcLine(mbuf
, sizeof mbuf
);
5630 SelectFin(buf
, len
, data
)
5633 char *data
; /* dummy */
5637 if (!len
|| !display
)
5639 if (len
== 1 && *buf
== '-')
5641 SetForeWindow((struct win
*)0);
5645 if ((n
= WindowByNoN(buf
)) < 0)
5651 SelectLayoutFin(buf
, len
, data
)
5654 char *data
; /* dummy */
5658 if (!len
|| !display
)
5660 if (len
== 1 && *buf
== '-')
5662 LoadLayout((struct layout
*)0, (struct canvas
*)0);
5666 lay
= FindLayout(buf
);
5668 Msg(0, "No such layout\n");
5669 else if (lay
== D_layout
)
5670 Msg(0, "This IS layout %d (%s).\n", lay
->lay_number
, lay
->lay_title
);
5673 LoadLayout(lay
, &D_canvas
);
5682 Input("Switch to window: ", 20, INP_COOKED
, SelectFin
, NULL
, 0);
5685 static char setenv_var
[31];
5689 SetenvFin1(buf
, len
, data
)
5692 char *data
; /* dummy */
5694 if (!len
|| !display
)
5700 SetenvFin2(buf
, len
, data
)
5703 char *data
; /* dummy */
5705 if (!len
|| !display
)
5707 debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var
, buf
);
5708 xsetenv(setenv_var
, buf
);
5716 static char setenv_buf
[50 + sizeof(setenv_var
)]; /* need to be static here, cannot be freed */
5720 strncpy(setenv_var
, arg
, sizeof(setenv_var
) - 1);
5721 sprintf(setenv_buf
, "Enter value for %s: ", setenv_var
);
5722 Input(setenv_buf
, 30, INP_COOKED
, SetenvFin2
, NULL
, 0);
5725 Input("Setenv: Enter variable name: ", 30, INP_COOKED
, SetenvFin1
, NULL
, 0);
5729 * the following options are understood by this parser:
5730 * -f, -f0, -f1, -fy, -fa
5731 * -t title, -T terminal-type, -h height-of-scrollback,
5732 * -ln, -l0, -ly, -l1, -l
5739 struct NewWindow nwin
;
5744 while (av
&& *av
&& av
[0][0] == '-')
5746 if (av
[0][1] == '-')
5758 nwin
.flowflag
= FLOW_NOW
* 0;
5763 nwin
.flowflag
= FLOW_NOW
* 1;
5766 nwin
.flowflag
= FLOW_AUTOFLAG
;
5772 case 't': /* no more -k */
5774 nwin
.aka
= &av
[0][2];
5782 nwin
.term
= &av
[0][2];
5790 nwin
.histheight
= atoi(av
[0] + 2);
5792 nwin
.histheight
= atoi(*av
);
5821 nwin
.monitor
= MON_ON
;
5827 Msg(0, "%s: screen: invalid option -%c.", fn
, av
[0][1]);
5833 if (av
&& *av
&& IsNumColon(*av
, 10, buf
, sizeof(buf
)))
5838 if (num
< 0 || num
> MAXWIN
- 1)
5840 Msg(0, "%s: illegal screen number %d.", fn
, num
);
5850 nwin
.aka
= Filename(*av
);
5857 * CompileKeys must be called before Markroutine is first used.
5858 * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
5860 * s is an ascii string in a termcap-like syntax. It looks like
5861 * "j=u:k=d:l=r:h=l: =.:" and so on...
5862 * this example rebinds the cursormovement to the keys u (up), d (down),
5863 * l (left), r (right). placing a mark will now be done with ".".
5866 CompileKeys(s
, sl
, array
)
5869 unsigned char *array
;
5872 unsigned char key
, value
;
5876 for (i
= 0; i
< 256; i
++)
5880 debug1("CompileKeys: '%s'\n", s
);
5883 key
= *(unsigned char *)s
++;
5884 if (*s
!= '=' || sl
< 3)
5891 value
= *(unsigned char *)s
++;
5894 while (*s
== '=' && sl
>= 2);
5903 #endif /* COPY_PASTE */
5906 * Asynchronous input functions
5909 #if defined(DETACH) && defined(POW_DETACH)
5911 pow_detach_fn(buf
, len
, data
)
5914 char *data
; /* dummy */
5916 debug("pow_detach_fn called\n");
5922 if (ktab
[(int)(unsigned char)*buf
].nr
!= RC_POW_DETACH
)
5925 write(D_userfd
, "\007", 1);
5926 Msg(0, "Detach aborted.");
5931 #endif /* POW_DETACH */
5935 copy_reg_fn(buf
, len
, data
)
5938 char *data
; /* dummy */
5940 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
5951 if (D_user
->u_plop
.len
)
5953 if ((pp
->buf
= (char *)malloc(D_user
->u_plop
.len
)) == NULL
)
5958 bcopy(D_user
->u_plop
.buf
, pp
->buf
, D_user
->u_plop
.len
);
5960 pp
->len
= D_user
->u_plop
.len
;
5962 pp
->enc
= D_user
->u_plop
.enc
;
5964 Msg(0, "Copied %d characters into register %c", D_user
->u_plop
.len
, *buf
);
5968 ins_reg_fn(buf
, len
, data
)
5971 char *data
; /* dummy */
5973 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
5981 return; /* Input() should not call us w/o fore, but you never know... */
5983 Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
5986 MakePaster(&fore
->w_paster
, pp
->buf
, pp
->len
, 0);
5989 Msg(0, "Empty register.");
5991 #endif /* COPY_PASTE */
5994 process_fn(buf
, len
, data
)
5997 char *data
; /* dummy */
5999 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6008 ProcessInput(pp
->buf
, pp
->len
);
6011 Msg(0, "Empty register.");
6015 confirm_fn(buf
, len
, data
)
6022 if (len
|| (*buf
!= 'y' && *buf
!= 'Y'))
6027 act
.nr
= *(int *)data
;
6036 struct acluser
**up
;
6038 char pw1
[130]; /* FreeBSD crypts to 128 bytes */
6043 su_fin(buf
, len
, data
)
6048 struct inputsu
*i
= (struct inputsu
*)data
;
6053 { p
= i
->name
; l
= sizeof(i
->name
) - 1; }
6055 { strcpy(p
= i
->pw1
, "\377"); l
= sizeof(i
->pw1
) - 1; }
6057 { strcpy(p
= i
->pw2
, "\377"); l
= sizeof(i
->pw2
) - 1; }
6059 strncpy(p
, buf
, 1 + (l
< len
) ? l
: len
);
6061 Input("Screen User: ", sizeof(i
->name
) - 1, INP_COOKED
, su_fin
, (char *)i
, 0);
6063 Input("User's UNIX Password: ", sizeof(i
->pw1
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6065 Input("User's Screen Password: ", sizeof(i
->pw2
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6068 if ((p
= DoSu(i
->up
, i
->name
, i
->pw2
, i
->pw1
)))
6075 InputSu(w
, up
, name
)
6077 struct acluser
**up
;
6082 if (!(i
= (struct inputsu
*)calloc(1, sizeof(struct inputsu
))))
6087 su_fin(name
, (int)strlen(name
), (char *)i
); /* can also initialise stuff */
6089 su_fin((char *)0, 0, (char *)i
);
6092 #endif /* MULTIUSER */
6097 pass1(buf
, len
, data
)
6102 struct acluser
*u
= (struct acluser
*)data
;
6107 if (u
->u_password
!= NullStr
)
6108 free((char *)u
->u_password
);
6109 u
->u_password
= SaveStr(buf
);
6110 bzero(buf
, strlen(buf
));
6111 Input("Retype new password:", 100, INP_NOECHO
, pass2
, data
, 0);
6115 pass2(buf
, len
, data
)
6122 struct acluser
*u
= (struct acluser
*)data
;
6125 if (!buf
|| strcmp(u
->u_password
, buf
))
6127 Msg(0, "[ Passwords don't match - checking turned off ]");
6128 if (u
->u_password
!= NullStr
)
6130 bzero(u
->u_password
, strlen(u
->u_password
));
6131 free((char *)u
->u_password
);
6133 u
->u_password
= NullStr
;
6135 else if (u
->u_password
[0] == '\0')
6137 Msg(0, "[ No password - no secure ]");
6139 bzero(buf
, strlen(buf
));
6142 if (u
->u_password
!= NullStr
)
6144 for (st
= 0; st
< 2; st
++)
6145 salt
[st
] = 'A' + (int)((time(0) >> 6 * st
) % 26);
6147 buf
= crypt(u
->u_password
, salt
);
6148 bzero(u
->u_password
, strlen(u
->u_password
));
6149 free((char *)u
->u_password
);
6150 u
->u_password
= SaveStr(buf
);
6151 bzero(buf
, strlen(buf
));
6154 UserFreeCopyBuffer(u
);
6155 u
->u_plop
.len
= strlen(u
->u_password
);
6159 if (!(u
->u_plop
.buf
= SaveStr(u
->u_password
)))
6162 D_user
->u_plop
.len
= 0;
6165 Msg(0, "[ Password moved into copybuffer ]");
6166 #else /* COPY_PASTE */
6167 Msg(0, "[ Crypted password is \"%s\" ]", u
->u_password
);
6168 #endif /* COPY_PASTE */
6171 #endif /* PASSWORD */
6174 digraph_fn(buf
, len
, data
)
6177 char *data
; /* dummy */
6184 buf
[len
+ 1] = ch
; /* so we can restore it later */
6185 if (ch
< ' ' || ch
== '\177')
6187 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6191 if ((ch
< '0' || ch
> '9') && (ch
< 'a' || ch
> 'f') && (ch
< 'A' || ch
> 'F'))
6193 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6196 if (len
== (*buf
== 'U' ? 5 : 3))
6200 if (len
&& *buf
== '0')
6202 if (ch
< '0' || ch
> '7')
6204 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6219 buf
[len
] = buf
[len
+ 1]; /* stored above */
6224 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6227 for (i
= 2; i
< len
; i
++)
6229 if (buf
[i
] >= '0' && buf
[i
] <= '9')
6230 x
= x
* 16 | (buf
[i
] - '0');
6231 else if (buf
[i
] >= 'a' && buf
[i
] <= 'f')
6232 x
= x
* 16 | (buf
[i
] - ('a' - 10));
6233 else if (buf
[i
] >= 'A' && buf
[i
] <= 'F')
6234 x
= x
* 16 | (buf
[i
] - ('A' - 10));
6239 else if (buf
[0] == '0')
6242 for (i
= 1; i
< len
; i
++)
6244 if (buf
[i
] < '0' || buf
[i
] > '7')
6246 x
= x
* 8 | (buf
[i
] - '0');
6251 for (i
= 0; i
< (int)(sizeof(digraphs
)/sizeof(*digraphs
)); i
++)
6252 if ((digraphs
[i
][0] == (unsigned char)buf
[0] && digraphs
[i
][1] == (unsigned char)buf
[1]) ||
6253 (digraphs
[i
][0] == (unsigned char)buf
[1] && digraphs
[i
][1] == (unsigned char)buf
[0]))
6255 if (i
== (int)(sizeof(digraphs
)/sizeof(*digraphs
)))
6257 Msg(0, "Unknown digraph");
6265 if (flayer
->l_encoding
== UTF8
)
6266 i
= ToUtf8(buf
, x
); /* buf is big enough for all UTF-8 codes */
6269 LayProcess(&buf
, &i
);
6280 debug1("StuffKey #%d", i
);
6283 debug1(" - %s", term
[i
+ T_CAPS
].tcname
);
6286 if (i
< KMAP_KEYS
&& D_ESCseen
)
6288 struct action
*act
= &D_ESCseen
[i
+ 256];
6289 if (act
->nr
!= RC_ILLEGAL
)
6292 DoAction(act
, i
+ 256);
6298 if (i
>= T_CURSOR
- T_CAPS
&& i
< T_KEYPAD
- T_CAPS
&& D_cursorkeys
)
6299 i
+= T_OCAPS
- T_CURSOR
;
6300 else if (i
>= T_KEYPAD
- T_CAPS
&& i
< T_OCAPS
- T_CAPS
&& D_keypad
)
6301 i
+= T_OCAPS
- T_CURSOR
;
6302 debug1(" - action %d\n", i
);
6303 flayer
= D_forecv
->c_layer
;
6307 if (InMark() || InInput() || InWList())
6308 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &mmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].mm
;
6310 if ((!act
|| act
->nr
== RC_ILLEGAL
) && !D_mapdefault
)
6311 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &umtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].um
;
6312 if (!act
|| act
->nr
== RC_ILLEGAL
)
6313 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &dmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].dm
;
6315 if (discard
&& (!act
|| act
->nr
!= RC_COMMAND
))
6322 if (act
== 0 || act
->nr
== RC_ILLEGAL
)
6336 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6337 if (Layer2Window(cv
->c_layer
) == wi
)
6343 FindNiceWindow(wi
, presel
)
6349 debug2("FindNiceWindow %d %s\n", wi
? wi
->w_number
: -1 , presel
? presel
: "NULL");
6352 i
= WindowByNoN(presel
);
6359 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6362 if (!wi
|| (IsOnDisplay(wi
) && !presel
))
6364 /* try to get another window */
6367 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6368 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6371 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6372 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6375 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6376 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6379 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6380 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6384 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6385 if (!wi
->w_layer
.l_cvlist
)
6388 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6389 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
))
6393 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6401 /* sorted list of all commands */
6402 static struct comm
**commtab
;
6403 static int ncommtab
;
6408 void (*hand
) __P((struct comm
*, char **, int));
6411 for (n
= 0; cos
[n
].name
; n
++)
6416 commtab
= (struct commt
*)realloc(commtab
, sizeof(*commtab
) * (ncommtab
+ n
));
6418 commtab
= (struct commt
*)malloc(sizeof(*commtab
) * (ncommtab
+ n
));
6421 for (i
= 0; i
< n
; i
++)
6423 for (j
= 0; j
< ncommtab
; j
++)
6425 r
= strcmp(cos
[i
].name
, commtab
[j
]->name
);
6427 Panic(0, "Duplicate command: %s\n", cos
[i
].name
);
6431 for (r
= ncommtab
; r
> j
; r
--)
6432 commtab
[r
] = commtab
[r
- 1];
6433 commtab
[j
] = cos
+ i
;
6434 cos
[i
].handler
= hand
;
6435 bzero(cos
[i
].userbits
, sizeof(cos
[i
].userbits
));
6444 int x
, m
, l
= 0, r
= ncommtab
- 1;
6448 x
= strcmp(str
, commtab
[m
]->name
);
6462 CalcSlicePercent(cv
, percent
)
6467 if (!cv
|| !cv
->c_slback
)
6469 up
= CalcSlicePercent(cv
->c_slback
->c_slback
, percent
);
6471 for (cv
= cv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6472 wsum
+= cv
->c_slweight
;
6475 return (up
* w
) / wsum
;
6479 ChangeCanvasSize(fcv
, abs
, diff
, gflag
, percent
)
6480 struct canvas
*fcv
; /* make this canvas bigger */
6481 int abs
; /* mode: 0:rel 1:abs 2:max */
6482 int diff
; /* change this much */
6483 int gflag
; /* go up if neccessary */
6487 int done
, have
, m
, dir
;
6489 debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs
, diff
, percent
);
6490 if (abs
== 0 && diff
== 0)
6495 fcv
->c_slweight
= 0;
6498 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6500 fcv
->c_slweight
= 1;
6501 cv
= fcv
->c_slback
->c_slback
;
6502 if (gflag
&& cv
&& cv
->c_slback
)
6503 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6511 if (percent
&& diff
> percent
)
6517 for (cv
= fcv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6518 wsum
+= cv
->c_slweight
;
6521 up
= gflag
? CalcSlicePercent(fcv
->c_slback
->c_slback
, percent
) : percent
;
6522 debug3("up=%d, wsum=%d percent=%d\n", up
, wsum
, percent
);
6525 int scale
= wsum
< 10 ? 1000 : 100;
6526 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6527 cv
->c_slweight
*= scale
;
6529 debug1("scaled wsum to %d\n", wsum
);
6531 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6535 cv
->c_slweight
= (cv
->c_slweight
* up
) / percent
;
6536 if (cv
->c_slweight
== 0)
6539 debug1(" - weight %d\n", cv
->c_slweight
);
6541 diff
= (diff
* wsum
) / percent
;
6547 if (abs
&& diff
== (fcv
->c_slorient
== SLICE_VERT
? fcv
->c_ye
- fcv
->c_ys
+ 2 : fcv
->c_xe
- fcv
->c_xs
+ 2))
6549 /* fix weights to real size (can't be helped, sorry) */
6550 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6552 cv
->c_slweight
= cv
->c_slorient
== SLICE_VERT
? cv
->c_ye
- cv
->c_ys
+ 2 : cv
->c_xe
- cv
->c_xs
+ 2;
6553 debug1(" - weight %d\n", cv
->c_slweight
);
6557 diff
= diff
- fcv
->c_slweight
;
6558 debug1("diff = %d\n", diff
);
6563 cv
= fcv
->c_slnext
? fcv
->c_slnext
: fcv
->c_slprev
;
6564 fcv
->c_slweight
+= diff
;
6565 cv
->c_slweight
-= diff
;
6570 for (cv
= fcv
->c_slnext
; diff
> 0; cv
= dir
> 0 ? cv
->c_slnext
: cv
->c_slprev
)
6574 debug1("reached end, dir is %d\n", dir
);
6584 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 : 2;
6585 debug2("min is %d, have %d\n", m
, cv
->c_slweight
);
6586 if (cv
->c_slweight
> m
)
6588 have
= cv
->c_slweight
- m
;
6591 debug1("subtract %d\n", have
);
6592 cv
->c_slweight
-= have
;
6599 /* need more room! */
6600 cv
= fcv
->c_slback
->c_slback
;
6601 if (cv
&& cv
->c_slback
)
6602 done
+= ChangeCanvasSize(fcv
->c_slback
->c_slback
, 0, diff
, gflag
, percent
);
6604 fcv
->c_slweight
+= done
;
6605 debug1("ChangeCanvasSize returns %d\n", done
);
6610 ResizeRegions(arg
, flags
)
6616 int gflag
= 0, abs
= 0, percent
= 0;
6622 if (D_forecv
->c_slorient
== SLICE_UNKN
)
6624 Msg(0, "resize: need more than one region");
6627 gflag
= flags
& RESIZE_FLAG_L
? 0 : 1;
6628 orient
|= flags
& RESIZE_FLAG_H
? SLICE_HORI
: 0;
6629 orient
|= flags
& RESIZE_FLAG_V
? SLICE_VERT
: 0;
6631 orient
= D_forecv
->c_slorient
;
6635 /* make all regions the same height */
6636 struct canvas
*cv
= gflag
? &D_canvas
: D_forecv
->c_slback
;
6637 if (cv
->c_slperp
->c_slorient
& orient
)
6638 EqualizeCanvas(cv
->c_slperp
, gflag
);
6639 /* can't use cv->c_slorient directly as it can be D_canvas */
6640 if ((cv
->c_slperp
->c_slorient
^ (SLICE_HORI
^ SLICE_VERT
)) & orient
)
6645 EqualizeCanvas(cv
->c_slperp
, gflag
);
6648 EqualizeCanvas(cv
, gflag
);
6651 RecreateCanvasChain();
6652 RethinkDisplayViewports();
6653 ResizeLayersToCanvases();
6656 if (!strcmp(arg
, "min") || !strcmp(arg
, "0"))
6661 else if (!strcmp(arg
, "max") || !strcmp(arg
, "_"))
6668 if (l
> 0 && arg
[l
- 1] == '%')
6671 diff
= atoi(arg
+ 1);
6672 else if (*arg
== '-')
6673 diff
= -atoi(arg
+ 1);
6676 diff
= atoi(arg
); /* +1 because of caption line */
6679 abs
= diff
== 0 ? 2 : 1;
6685 diff
= diff
* percent
/ 100;
6687 if (cv
->c_slorient
& orient
)
6688 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6689 if (cv
->c_slback
->c_slorient
& orient
)
6690 ChangeCanvasSize(cv
->c_slback
, abs
, diff
, gflag
, percent
);
6692 ResizeCanvas(&D_canvas
);
6693 RecreateCanvasChain();
6694 RethinkDisplayViewports();
6695 ResizeLayersToCanvases();
6702 if (siz
+ diff
> dsize
- (nreg
- 1) * 2 - 1)
6703 diff
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6704 if (diff
== 0 || siz
+ diff
< 1)
6709 if (D_forecv
->c_next
)
6711 D_forecv
->c_ye
+= diff
;
6712 D_forecv
->c_next
->c_ys
+= diff
;
6713 D_forecv
->c_next
->c_yoff
+= diff
;
6717 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6718 if (cv
->c_next
== D_forecv
)
6722 D_forecv
->c_ys
-= diff
;
6723 D_forecv
->c_yoff
-= diff
;
6728 int s
, i
= 0, found
= 0, di
= diff
, d2
;
6729 s
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6730 for (cv
= D_cvlist
; cv
; i
= cv
->c_ye
+ 2, cv
= cv
->c_next
)
6734 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) + diff
;
6735 cv
->c_yoff
-= cv
->c_ys
- i
;
6740 s
-= cv
->c_ye
- cv
->c_ys
;
6748 d2
= di
> cv
->c_ye
- cv
->c_ys
? cv
->c_ye
- cv
->c_ys
: di
;
6750 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) - d2
;
6751 cv
->c_yoff
-= cv
->c_ys
- i
;
6755 RethinkDisplayViewports();
6756 ResizeLayersToCanvases();
6761 ResizeFin(buf
, len
, data
)
6767 int flags
= *(int *)data
;
6768 ch
= ((unsigned char *)buf
)[len
];
6771 ResizeRegions(buf
, flags
);
6775 flags
^= RESIZE_FLAG_H
;
6777 flags
^= RESIZE_FLAG_V
;
6779 flags
|= RESIZE_FLAG_H
|RESIZE_FLAG_V
;
6781 flags
^= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
6783 flags
^= RESIZE_FLAG_L
;
6786 inp_setprompt(resizeprompts
[flags
], NULL
);
6787 *(int *)data
= flags
;
6798 p
= Layer2Window(D_forecv
->c_layer
);
6799 for (i
= 3; i
>=0; i
--)
6800 SetXtermOSC(i
, p
? p
->w_xtermosc
[i
] : 0);
6805 ParseAttrColor(s1
, s2
, msgok
)
6817 while (*ss
&& *ss
!= ' ')
6821 if (*s
&& (s2
|| *ss
|| !((*s
>= 'a' && *s
<= 'z') || (*s
>= 'A' && *s
<= 'Z') || *s
== '.')))
6823 int mode
= 0, n
= 0;
6841 if (*s
>= '0' && *s
<= '9')
6844 if (*s
>= '0' && *s
<= '9')
6845 n
= n
* 16 + (*s
++ - '0');
6846 else if (*s
>= 'a' && *s
<= 'f')
6847 n
= n
* 16 + (*s
++ - ('a' - 10));
6848 else if (*s
>= 'A' && *s
<= 'F')
6849 n
= n
* 16 + (*s
++ - ('A' - 10));
6850 else if (*s
&& *s
!= ' ')
6853 Msg(0, "Illegal attribute hexchar '%c'", *s
);
6859 while (*s
&& *s
!= ' ')
6876 Msg(0, "Illegal attribute specifier '%c'", *s
);
6882 if (*s
&& *s
!= ' ')
6885 Msg(0, "junk after attribute description: '%c'", *s
);
6897 while (*s
&& *s
== ' ')
6905 Msg(0, "junk after description: '%c'", *s
);
6909 while (*s
&& *s
== ' ')
6916 static char costr
[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
6926 for (j
= 0; j
< 2 && *s
&& *s
!= ' '; j
++)
6928 for (i
= 0; costr
[i
]; i
++)
6934 Msg(0, "illegal color descriptor: '%c'", *s
);
6938 n
= n
<< 4 | (i
& 15);
6941 n
= (n
& 0x20ff) | 0x200;
6945 if ((n
& 0xf00) == 0xf00)
6946 n
^= 0xf00; /* clear superflous bits */
6949 n
^= 0x2400; /* shift bit into right position */
6952 n
|= 0xf0; /* don't change bg color */
6953 if (numco
!= 2 && n
!= 0xff)
6954 n
|= 0x100; /* special invert mode */
6955 if (*s
&& *s
!= ' ')
6958 Msg(0, "junk after color description: '%c'", *s
);
6966 while (*s
&& *s
== ' ')
6971 Msg(0, "junk after description: '%c'", *s
);
6974 debug1("ParseAttrColor %06x\n", r
);
6982 * e just set intensity
6983 * f don't change anything
6984 * Intensity is encoded into bits 17(fg) and 18(bg).
6987 ApplyAttrColor(i
, mc
)
6991 debug1("ApplyAttrColor %06x\n", i
);
6992 mc
->attr
|= i
>> 8 & 255;
6993 mc
->attr
^= i
& 255;
6995 i
= (i
>> 16) ^ 0xff;
6996 if ((i
& 0x100) != 0)
6999 if (mc
->attr
& (A_SO
|A_RV
))
7001 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4) | ((i
& 0x200) << 1) | ((i
& 0x400) >> 1);
7003 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4);
7007 if ((i
& 0x0f) != 0x0f)
7008 mc
->attr
= (mc
->attr
& 0xbf) | ((i
>> 3) & 0x40);
7009 if ((i
& 0xf0) != 0xf0)
7010 mc
->attr
= (mc
->attr
& 0x7f) | ((i
>> 3) & 0x80);
7012 mc
->color
= 0x99 ^ mc
->color
;
7013 if ((i
& 0x0e) == 0x0e)
7014 i
= (i
& 0xf0) | (mc
->color
& 0x0f);
7015 if ((i
& 0xe0) == 0xe0)
7016 i
= (i
& 0x0f) | (mc
->color
& 0xf0);
7017 mc
->color
= 0x99 ^ i
;
7018 debug2("ApplyAttrColor - %02x %02x\n", mc
->attr
, i
);