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"))
4212 else if (!strcmp(args
[0], "remove"))
4214 struct layout
*lay
= display
? D_layout
: layouts
;
4217 lay
= layouts
? FindLayout(args
[1]) : (struct layout
*)0;
4220 Msg(0, "unknown layout '%s'", args
[1]);
4228 Msg(0, "unknown layout subcommand");
4232 if(ParseSwitch(act
, &cjkwidth
) == 0)
4235 Msg(0, "Treat ambiguous width characters as %s width", cjkwidth
? "full" : "half");
4241 /* key == -2: input from braille keybord, msgok always 0 */
4242 DoBrailleAction(act
, key
== -2 ? 0 : msgok
);
4246 if (display
!= odisplay
)
4248 for (display
= displays
; display
; display
= display
->d_next
)
4249 if (display
== odisplay
)
4255 DoCommand(argv
, argl
)
4261 if ((act
.nr
= FindCommnr(*argv
)) == RC_ILLEGAL
)
4263 Msg(0, "%s: unknown command '%s'", rc_name
, *argv
);
4266 act
.args
= argv
+ 1;
4267 act
.argl
= argl
+ 1;
4272 SaveAction(act
, nr
, args
, argl
)
4278 register int argc
= 0;
4292 if ((pp
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4294 if ((lp
= (int *)malloc((unsigned)(argc
) * sizeof(int *))) == 0)
4301 *lp
= argl
? *argl
++ : (int)strlen(*args
);
4302 *pp
++ = SaveStrn(*args
++, *lp
++);
4311 register char **ap
, **pp
;
4312 register int argc
= 0;
4316 if ((pp
= ap
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4319 *pp
++ = SaveStr(*args
++);
4326 * buf is split into argument vector args.
4327 * leading whitespace is removed.
4328 * @!| abbreviations are expanded.
4329 * the end of buffer is recognized by '\0' or an un-escaped '#'.
4330 * " and ' are interpreted.
4335 Parse(buf
, bufl
, args
, argl
)
4339 register char *p
= buf
, **ap
= args
, *pp
;
4340 register int delim
, argc
;
4343 debug2("Parse %d %s\n", bufl
, buf
);
4349 while (*p
&& (*p
== ' ' || *p
== '\t'))
4352 if (argc
== 0 && *p
== '!')
4361 if (*p
== '\0' || *p
== '#' || *p
== '\n')
4364 for (delim
= 0; delim
< argc
; delim
++)
4365 debug1("-- %s\n", args
[delim
]);
4369 if (++argc
>= MAXARGS
)
4371 Msg(0, "%s: too many tokens.", rc_name
);
4376 debug1("- new arg %s\n", p
);
4381 else if (delim
!= '\'' && *p
== '\\' && (p
[1] == '\'' || p
[1] == '"' || p
[1] == '\\' || p
[1] == '$' || p
[1] == '#' || p
[1] == '^' || (p
[1] >= '0' && p
[1] <= '7')))
4384 if (*p
>= '0' && *p
<= '7')
4387 if (p
[1] >= '0' && p
[1] <= '7')
4390 *pp
= (*pp
<< 3) | (*p
- '0');
4391 if (p
[1] >= '0' && p
[1] <= '7')
4394 *pp
= (*pp
<< 3) | (*p
- '0');
4402 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] == '_'))
4405 char *ps
, *pe
, op
, *v
, xbuf
[11];
4409 debug1("- var %s\n", ps
);
4413 if (*ps
== '{' && *p
== '}')
4415 if (*ps
== ':' && *p
== ':')
4417 if (*ps
!= '{' && *ps
!= ':' && (*p
< 'a' || *p
> 'z') && (*p
< 'A' || *p
> 'Z') && (*p
< '0' || *p
> '9') && *p
!= '_')
4422 if (*ps
== '{' || *ps
== ':')
4426 Msg(0, "%s: bad variable name.", rc_name
);
4433 debug1("- var is '%s'\n", ps
);
4435 v
= gettermcapstring(ps
+ 1);
4441 if (!strcmp(ps
, "TERM"))
4442 v
= display
? D_termname
: "unknown";
4443 else if (!strcmp(ps
, "COLUMNS"))
4444 sprintf(xbuf
, "%d", display
? D_width
: -1);
4445 else if (!strcmp(ps
, "LINES"))
4446 sprintf(xbuf
, "%d", display
? D_height
: -1);
4451 vl
= v
? strlen(v
) : 0;
4454 debug1("- sub is '%s'\n", v
);
4457 int right
= buf
+ bufl
- (p
+ strlen(p
) + 1);
4460 bcopy(p
, p
+ right
, strlen(p
) + 1);
4466 Msg(0, "%s: no space left for variable expansion.", rc_name
);
4474 else if (delim
!= '\'' && *p
== '^' && p
[1])
4477 *pp
++ = *p
== '?' ? '\177' : *p
& 0x1f;
4479 else if (delim
== 0 && (*p
== '\'' || *p
== '"'))
4481 else if (delim
== 0 && (*p
== ' ' || *p
== '\t' || *p
== '\n'))
4489 Msg(0, "%s: Missing %c quote.", rc_name
, delim
);
4495 debug2("- arg done, '%s' rest %s\n", ap
[-1], p
);
4496 *lp
++ = pp
- ap
[-1];
4515 if (DefaultEsc
>= 0)
4516 ClearAction(&ktab
[DefaultEsc
]);
4517 if (DefaultMetaEsc
>= 0)
4518 ClearAction(&ktab
[DefaultMetaEsc
]);
4521 DefaultMetaEsc
= me
;
4524 if (DefaultEsc
>= 0)
4526 ClearAction(&ktab
[DefaultEsc
]);
4527 ktab
[DefaultEsc
].nr
= RC_OTHER
;
4529 if (DefaultMetaEsc
>= 0)
4531 ClearAction(&ktab
[DefaultMetaEsc
]);
4532 ktab
[DefaultMetaEsc
].nr
= RC_META
;
4539 ParseSwitch(act
, var
)
4543 if (*act
->args
== 0)
4548 return ParseOnOff(act
, var
);
4552 ParseOnOff(act
, var
)
4556 register int num
= -1;
4557 char **args
= act
->args
;
4561 if (strcmp(args
[0], "on") == 0)
4563 else if (strcmp(args
[0], "off") == 0)
4568 Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name
, comms
[act
->nr
].name
);
4576 ParseSaveStr(act
, var
)
4580 char **args
= act
->args
;
4581 if (*args
== 0 || args
[1])
4583 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4588 *var
= SaveStr(*args
);
4598 char *p
, **args
= act
->args
;
4601 if (p
== 0 || *p
== 0 || args
[1])
4603 Msg(0, "%s: %s: invalid argument. Give one argument.",
4604 rc_name
, comms
[act
->nr
].name
);
4610 if (*p
>= '0' && *p
<= '9')
4611 i
= 10 * i
+ (*p
- '0');
4614 Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4615 rc_name
, comms
[act
->nr
].name
);
4620 debug1("ParseNum got %d\n", i
);
4626 ParseNum1000(act
, var
)
4631 char *p
, **args
= act
->args
;
4635 if (p
== 0 || *p
== 0 || args
[1])
4637 Msg(0, "%s: %s: invalid argument. Give one argument.",
4638 rc_name
, comms
[act
->nr
].name
);
4644 if (*p
>= '0' && *p
<= '9')
4647 i
= 10 * i
+ (*p
- '0');
4648 else if (dig
== 4 && *p
>= '5')
4653 else if (*p
== '.' && !dig
)
4657 Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4658 rc_name
, comms
[act
->nr
].name
);
4669 i
= (int)((unsigned int)~0 >> 1);
4670 debug1("ParseNum1000 got %d\n", i
);
4681 for (p
= windows
; p
; p
= p
->w_next
)
4682 if (!strcmp(p
->w_title
, s
))
4684 for (p
= windows
; p
; p
= p
->w_next
)
4685 if (!strncmp(p
->w_title
, s
, strlen(s
)))
4697 for (i
= 0, s
= str
; *s
; s
++)
4699 if (*s
< '0' || *s
> '9')
4701 i
= i
* 10 + (*s
- '0');
4707 * Get window number from Name or Number string.
4708 * Numbers are tried first, then names, a prefix match suffices.
4709 * Be careful when assigning numeric strings as WindowTitles.
4718 if ((i
= WindowByNumber(str
)) < 0 || i
>= MAXWIN
)
4720 if ((p
= WindowByName(str
)))
4728 ParseWinNum(act
, var
)
4732 char **args
= act
->args
;
4735 if (*args
== 0 || args
[1])
4737 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4741 i
= WindowByNoN(*args
);
4744 Msg(0, "%s: %s: invalid argument. Give window number or name.",
4745 rc_name
, comms
[act
->nr
].name
);
4748 debug1("ParseWinNum got %d\n", i
);
4754 ParseBase(act
, p
, var
, base
, bname
)
4766 Msg(0, "%s: %s: empty argument.", rc_name
, comms
[act
->nr
].name
);
4771 if (c
>= 'a' && c
<= 'z')
4773 if (c
>= 'A' && c
<= 'Z')
4774 c
-= 'A' - ('0' + 10);
4776 if (c
< 0 || c
>= base
)
4778 Msg(0, "%s: %s: argument is not %s.", rc_name
, comms
[act
->nr
].name
, bname
);
4783 debug1("ParseBase got %d\n", i
);
4793 for (base
+= '0'; *s
; ++s
)
4794 if (*s
< '0' || *s
> base
)
4800 IsNumColon(s
, base
, p
, psize
)
4805 if ((q
= rindex(s
, ':')) != 0)
4807 strncpy(p
, q
+ 1, psize
- 1);
4808 p
[psize
- 1] = '\0';
4813 return IsNum(s
, base
);
4822 debug1("SwitchWindow %d\n", n
);
4823 if (n
< 0 || n
>= MAXWIN
)
4828 if ((p
= wtab
[n
]) == 0)
4840 Msg(0, "This IS window %d (%s).", n
, p
->w_title
);
4844 if (AclCheckPermWin(D_user
, ACL_READ
, p
))
4846 Msg(0, "Access to window %d denied.", p
->w_number
);
4851 Activate(fore
->w_norefresh
);
4856 SetCanvasWindow(cv
, wi
)
4860 struct win
*p
= 0, **pp
;
4862 struct canvas
*cvp
, **cvpp
;
4865 display
= cv
->c_display
;
4869 /* remove old layer */
4870 for (cvpp
= &l
->l_cvlist
; (cvp
= *cvpp
); cvpp
= &cvp
->c_lnext
)
4874 *cvpp
= cvp
->c_lnext
;
4876 p
= Layer2Window(l
);
4880 if (p
&& cv
== D_forecv
)
4883 ReleaseAutoWritelock(display
, p
);
4887 SetTimeout(&p
->w_silenceev
, p
->w_silencewait
* 1000);
4888 evenq(&p
->w_silenceev
);
4893 if (l
->l_cvlist
== 0 && (p
== 0 || l
!= p
->w_savelayer
))
4897 /* find right layer to display on canvas */
4898 if (wi
&& wi
->w_type
!= W_TYPE_GROUP
)
4901 if (wi
->w_savelayer
&& (wi
->w_blocked
|| wi
->w_savelayer
->l_cvlist
== 0))
4902 l
= wi
->w_savelayer
;
4908 l
->l_data
= (char *)wi
;
4913 /* add our canvas to the layer's canvaslist */
4914 ASSERT(l
->l_cvlist
!= cv
);
4915 cv
->c_lnext
= l
->l_cvlist
;
4918 cv
->c_xoff
= cv
->c_xs
;
4919 cv
->c_yoff
= cv
->c_ys
;
4920 RethinkViewportOffsets(cv
);
4925 if (wi
&& wi
->w_type
== W_TYPE_GROUP
)
4927 /* auto-start windowlist on groups */
4928 struct display
*d
= display
;
4929 struct layer
*oldflayer
= flayer
;
4931 display_wlist(0, 0, wi
);
4936 if (wi
&& D_other
== wi
)
4937 D_other
= wi
->w_next
; /* Might be 0, but that's OK. */
4941 fore
= D_fore
; /* XXX ? */
4945 ObtainAutoWritelock(display
, wi
);
4948 * Place the window at the head of the most-recently-used list
4952 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
4957 p
->w_next
= windows
;
4967 * SetForeWindow changes the window in the input focus of the display.
4968 * Puts window wi in canvas display->d_forecv.
4980 p
= Layer2Window(D_forecv
->c_layer
);
4981 SetCanvasWindow(D_forecv
, wi
);
4983 WindowChanged(p
, 'u');
4985 WindowChanged(wi
, 'u');
4986 flayer
= D_forecv
->c_layer
;
4987 /* Activate called afterwards, so no RefreshHStatus needed */
4991 /*****************************************************************/
4994 * Activate - make fore window active
4995 * norefresh = -1 forces a refresh, disregard all_norefresh then.
5001 debug1("Activate(%d)\n", norefresh
);
5006 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
5010 if (MayResizeLayer(D_forecv
->c_layer
))
5011 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, display
);
5017 if (fore
->w_monitor
!= MON_OFF
)
5018 fore
->w_monitor
= MON_ON
;
5019 fore
->w_bell
= BELL_ON
;
5020 WindowChanged(fore
, 'f');
5023 if (ResizeDisplay(fore
->w_width
, fore
->w_height
))
5025 debug2("Cannot resize from (%d,%d)", D_width
, D_height
);
5026 debug2(" to (%d,%d) -> resize window\n", fore
->w_width
, fore
->w_height
);
5027 DoResize(D_width
, D_height
);
5031 Redisplay(norefresh
+ all_norefresh
);
5038 register struct win
**pp
;
5039 int n
= fore
? fore
->w_number
: MAXWIN
;
5040 struct win
*group
= fore
? fore
->w_group
: 0;
5042 for (pp
= fore
? wtab
+ n
+ 1 : wtab
; pp
!= wtab
+ n
; pp
++)
5044 if (pp
== wtab
+ MAXWIN
)
5048 if (!fore
|| group
== (*pp
)->w_group
)
5060 register struct win
**pp
;
5061 int n
= fore
? fore
->w_number
: -1;
5062 struct win
*group
= fore
? fore
->w_group
: 0;
5064 for (pp
= wtab
+ n
- 1; pp
!= wtab
+ n
; pp
--)
5067 pp
= wtab
+ MAXWIN
- 1;
5070 if (!fore
|| group
== (*pp
)->w_group
)
5082 char *m
= "No other window.";
5083 if (windows
&& (fore
== 0 || windows
->w_next
))
5087 Msg(0, "No window available");
5090 Msg(0, m
, fore
->w_number
); /* other arg for nethack */
5095 UpdateLayoutCanvas(cv
, wi
)
5099 for (; cv
; cv
= cv
->c_slnext
)
5101 if (cv
->c_layer
&& Layer2Window(cv
->c_layer
) == wi
)
5103 /* A simplistic version of SetCanvasWindow(cv, 0) */
5104 struct layer
*l
= cv
->c_layer
;
5106 if (l
->l_cvlist
== 0 && (wi
== 0 || l
!= wi
->w_savelayer
))
5110 if (l
->l_cvlist
!= cv
)
5112 cv
->c_lnext
= l
->l_cvlist
;
5116 /* Do not end here. Multiple canvases can have the same window */
5120 UpdateLayoutCanvas(cv
->c_slperp
, wi
);
5128 struct win
**pp
, *p
;
5134 * Remove window from linked list.
5136 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5142 wtab
[wi
->w_number
] = 0;
5151 * switch to different window on all canvases
5153 for (display
= displays
; display
; display
= display
->d_next
)
5156 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5158 if (Layer2Window(cv
->c_layer
) != wi
)
5160 /* switch to other window */
5161 SetCanvasWindow(cv
, FindNiceWindow(D_other
, 0));
5167 if (wi
->w_zdisplay
== display
)
5170 D_readev
.condpos
= D_readev
.condneg
= 0;
5177 /* do the same for the layouts */
5178 for (lay
= layouts
; lay
; lay
= lay
->lay_next
)
5179 UpdateLayoutCanvas(&lay
->lay_canvas
, wi
);
5182 WindowChanged((struct win
*)0, 'w');
5183 WindowChanged((struct win
*)0, 'W');
5184 WindowChanged((struct win
*)0, 0);
5193 if ((fore
->w_log
!= 0) == on
)
5195 if (display
&& !*rc_name
)
5196 Msg(0, "You are %s logging.", on
? "already" : "not");
5199 if (fore
->w_log
!= 0)
5201 Msg(0, "Logfile \"%s\" closed.", fore
->w_log
->name
);
5202 logfclose(fore
->w_log
);
5204 WindowChanged(fore
, 'f');
5207 if (DoStartLog(fore
, buf
, sizeof(buf
)))
5209 Msg(errno
, "Error opening logfile \"%s\"", buf
);
5212 if (ftell(fore
->w_log
->fp
) == 0)
5213 Msg(0, "Creating logfile \"%s\".", fore
->w_log
->name
);
5215 Msg(0, "Appending to logfile \"%s\".", fore
->w_log
->name
);
5216 WindowChanged(fore
, 'f');
5220 AddWindows(buf
, len
, flags
, where
)
5226 register char *s
, *ss
;
5227 register struct win
**pp
, *p
;
5232 for (pp
= ((flags
& 4) && where
>= 0) ? wtab
+ where
+ 1: wtab
; pp
< wtab
+ MAXWIN
; pp
++)
5234 if (pp
- wtab
== where
&& ss
== buf
)
5238 if ((flags
& 1) && display
&& p
== D_fore
)
5240 if (D_fore
&& D_fore
->w_group
!= p
->w_group
)
5247 if (s
- buf
+ l
> len
- 24)
5249 if (s
> buf
|| (flags
& 4))
5254 sprintf(s
, "%d", p
->w_number
);
5255 if (p
->w_number
== where
)
5258 if (display
&& p
== D_fore
)
5262 if (display
&& p
== D_other
)
5264 s
= AddWindowFlags(s
, len
, p
);
5275 AddWindowFlags(buf
, len
, p
)
5281 if (p
== 0 || len
< 12)
5287 if (display
&& p
== D_fore
)
5289 if (display
&& p
== D_other
)
5292 if (p
->w_layer
.l_cvlist
&& p
->w_layer
.l_cvlist
->c_lnext
)
5294 if (p
->w_monitor
== MON_DONE
5296 && (ACLBYTE(p
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5300 if (p
->w_bell
== BELL_DONE
)
5303 if (p
->w_slot
!= (slot_t
) 0 && p
->w_slot
!= (slot_t
) -1)
5311 if (p
->w_ptyfd
< 0 && p
->w_type
!= W_TYPE_GROUP
)
5318 AddOtherUsers(buf
, len
, p
)
5323 struct display
*d
, *olddisplay
= display
;
5329 for (display
= displays
; display
; display
= display
->d_next
)
5331 if (olddisplay
&& D_user
== olddisplay
->d_user
)
5333 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5334 if (Layer2Window(cv
->c_layer
) == p
)
5338 for (d
= displays
; d
&& d
!= display
; d
= d
->d_next
)
5339 if (D_user
== d
->d_user
)
5341 if (d
&& d
!= display
)
5343 if (len
> 1 && s
!= buf
)
5348 l
= strlen(D_user
->u_name
);
5351 strcpy(s
, D_user
->u_name
);
5356 display
= olddisplay
;
5369 if (where
== -1 && D_fore
)
5370 where
= D_fore
->w_number
;
5371 ss
= AddWindows(buf
, sizeof(buf
), 0, where
);
5372 s
= buf
+ strlen(buf
);
5373 if (ss
- buf
> D_width
/ 2)
5376 if (s
- ss
< D_width
)
5392 register struct win
*wp
= fore
;
5397 Msg(0, "(%d,%d)/(%d,%d) no window", D_x
+ 1, D_y
+ 1, D_width
, D_height
);
5401 if (buf
< (p
+= GetAnsiStatus(wp
, p
)))
5403 sprintf(p
, "(%d,%d)/(%d,%d)",
5404 wp
->w_x
+ 1, wp
->w_y
+ 1, wp
->w_width
, wp
->w_height
);
5406 sprintf(p
+= strlen(p
), "+%d", wp
->w_histheight
);
5408 sprintf(p
+= strlen(p
), " %c%sflow",
5409 (wp
->w_flow
& FLOW_NOW
) ? '+' : '-',
5410 (wp
->w_flow
& FLOW_AUTOFLAG
) ? "" :
5411 ((wp
->w_flow
& FLOW_AUTO
) ? "(+)" : "(-)"));
5412 if (!wp
->w_wrap
) sprintf(p
+= strlen(p
), " -wrap");
5413 if (wp
->w_insert
) sprintf(p
+= strlen(p
), " ins");
5414 if (wp
->w_origin
) sprintf(p
+= strlen(p
), " org");
5415 if (wp
->w_keypad
) sprintf(p
+= strlen(p
), " app");
5416 if (wp
->w_log
) sprintf(p
+= strlen(p
), " log");
5417 if (wp
->w_monitor
!= MON_OFF
5419 && (ACLBYTE(wp
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5422 sprintf(p
+= strlen(p
), " mon");
5423 if (wp
->w_mouse
) sprintf(p
+= strlen(p
), " mouse");
5425 if (wp
->w_bce
) sprintf(p
+= strlen(p
), " bce");
5427 if (!wp
->w_c1
) sprintf(p
+= strlen(p
), " -c1");
5428 if (wp
->w_norefresh
) sprintf(p
+= strlen(p
), " nored");
5433 if (wp
->w_encoding
&& (display
== 0 || D_encoding
!= wp
->w_encoding
|| EncodingDefFont(wp
->w_encoding
) <= 0))
5436 strcpy(p
, EncodingName(wp
->w_encoding
));
5440 if (wp
->w_encoding
!= UTF8
)
5443 if (D_CC0
|| (D_CS0
&& *D_CS0
))
5447 sprintf(p
, " G%c", wp
->w_Charset
+ '0');
5448 if (wp
->w_FontE
>= ' ')
5453 p
[4] = wp
->w_FontE
^ 0x40;
5460 sprintf(p
++, " G%c%c[", wp
->w_Charset
+ '0', wp
->w_CharsetR
+ '0');
5462 sprintf(p
, " G%c[", wp
->w_Charset
+ '0');
5464 for (i
= 0; i
< 4; i
++)
5466 if (wp
->w_charsets
[i
] == ASCII
)
5468 else if (wp
->w_charsets
[i
] >= ' ')
5469 *p
++ = wp
->w_charsets
[i
];
5473 *p
++ = wp
->w_charsets
[i
] ^ 0x40;
5481 if (wp
->w_type
== W_TYPE_PLAIN
)
5483 /* add info about modem control lines */
5485 TtyGetModemStatus(wp
->w_ptyfd
, p
);
5487 #ifdef BUILTIN_TELNET
5488 else if (wp
->w_type
== W_TYPE_TELNET
)
5491 TelStatus(wp
, p
, sizeof(buf
) - 1 - (p
- buf
));
5494 Msg(0, "%s %d(%s)", buf
, wp
->w_number
, wp
->w_title
);
5504 sprintf(p
, "(%d,%d)", D_width
, D_height
),
5510 strcpy(p
, EncodingName(D_encoding
));
5516 strcpy(p
, " xterm");
5522 strcpy(p
, " color");
5529 strcpy(p
, " iso2022");
5532 else if (D_CS0
&& *D_CS0
)
5534 strcpy(p
, " altchar");
5542 AKAfin(buf
, len
, data
)
5545 char *data
; /* dummy */
5549 ChangeAKA(fore
, buf
, strlen(buf
));
5557 Input("Set window's title to: ", sizeof(fore
->w_akabuf
) - 1, INP_COOKED
, AKAfin
, NULL
, 0);
5563 if ((*(unsigned char *)s
& 0x7f) < 0x20 || *s
== 0x7f)
5567 LayProcess(&ss
, &n
);
5572 Colonfin(buf
, len
, data
)
5575 char *data
; /* dummy */
5580 if (buf
[len
] == '\t')
5583 int l
= 0, r
= RC_LAST
;
5584 int showmessage
= 0;
5587 while (*s
&& s
- buf
< len
)
5591 /* Showing a message when there's no hardstatus or caption cancels the input */
5593 (captionalways
|| D_has_hstatus
== HSTATUS_LASTLINE
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
)))
5599 x
= strncmp(buf
, comms
[m
].name
, len
);
5607 for (l
= m
- 1; l
>= 0 && strncmp(buf
, comms
[l
].name
, len
) == 0; l
--)
5609 for (m
= ++l
; m
<= r
&& strncmp(buf
, comms
[m
].name
, len
) == 0 && s
- mbuf
< sizeof(mbuf
); m
++)
5610 s
+= snprintf(s
, sizeof(mbuf
) - (s
- mbuf
), " %s", comms
[m
].name
);
5614 Msg(0, "Possible commands:%s", mbuf
);
5619 len
= snprintf(mbuf
, sizeof(mbuf
), "%s \t", comms
[l
].name
+ len
);
5620 if (len
> 0 && len
< sizeof(mbuf
))
5621 LayProcess(&s
, &len
);
5626 if (l
> r
&& showmessage
)
5627 Msg(0, "No commands matching '%*s'", len
, buf
);
5631 if (!len
|| buf
[len
])
5634 len
= strlen(buf
) + 1;
5635 if (len
> (int)sizeof(mbuf
))
5639 bcopy(buf
, mbuf
, len
);
5640 RcLine(mbuf
, sizeof mbuf
);
5645 SelectFin(buf
, len
, data
)
5648 char *data
; /* dummy */
5652 if (!len
|| !display
)
5654 if (len
== 1 && *buf
== '-')
5656 SetForeWindow((struct win
*)0);
5660 if ((n
= WindowByNoN(buf
)) < 0)
5666 SelectLayoutFin(buf
, len
, data
)
5669 char *data
; /* dummy */
5673 if (!len
|| !display
)
5675 if (len
== 1 && *buf
== '-')
5677 LoadLayout((struct layout
*)0, (struct canvas
*)0);
5681 lay
= FindLayout(buf
);
5683 Msg(0, "No such layout\n");
5684 else if (lay
== D_layout
)
5685 Msg(0, "This IS layout %d (%s).\n", lay
->lay_number
, lay
->lay_title
);
5688 LoadLayout(lay
, &D_canvas
);
5697 Input("Switch to window: ", 20, INP_COOKED
, SelectFin
, NULL
, 0);
5700 static char setenv_var
[31];
5704 SetenvFin1(buf
, len
, data
)
5707 char *data
; /* dummy */
5709 if (!len
|| !display
)
5715 SetenvFin2(buf
, len
, data
)
5718 char *data
; /* dummy */
5720 if (!len
|| !display
)
5722 debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var
, buf
);
5723 xsetenv(setenv_var
, buf
);
5731 static char setenv_buf
[50 + sizeof(setenv_var
)]; /* need to be static here, cannot be freed */
5735 strncpy(setenv_var
, arg
, sizeof(setenv_var
) - 1);
5736 sprintf(setenv_buf
, "Enter value for %s: ", setenv_var
);
5737 Input(setenv_buf
, 30, INP_COOKED
, SetenvFin2
, NULL
, 0);
5740 Input("Setenv: Enter variable name: ", 30, INP_COOKED
, SetenvFin1
, NULL
, 0);
5744 * the following options are understood by this parser:
5745 * -f, -f0, -f1, -fy, -fa
5746 * -t title, -T terminal-type, -h height-of-scrollback,
5747 * -ln, -l0, -ly, -l1, -l
5754 struct NewWindow nwin
;
5759 while (av
&& *av
&& av
[0][0] == '-')
5761 if (av
[0][1] == '-')
5773 nwin
.flowflag
= FLOW_NOW
* 0;
5778 nwin
.flowflag
= FLOW_NOW
* 1;
5781 nwin
.flowflag
= FLOW_AUTOFLAG
;
5787 case 't': /* no more -k */
5789 nwin
.aka
= &av
[0][2];
5797 nwin
.term
= &av
[0][2];
5805 nwin
.histheight
= atoi(av
[0] + 2);
5807 nwin
.histheight
= atoi(*av
);
5836 nwin
.monitor
= MON_ON
;
5842 Msg(0, "%s: screen: invalid option -%c.", fn
, av
[0][1]);
5848 if (av
&& *av
&& IsNumColon(*av
, 10, buf
, sizeof(buf
)))
5853 if (num
< 0 || num
> MAXWIN
- 1)
5855 Msg(0, "%s: illegal screen number %d.", fn
, num
);
5865 nwin
.aka
= Filename(*av
);
5872 * CompileKeys must be called before Markroutine is first used.
5873 * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
5875 * s is an ascii string in a termcap-like syntax. It looks like
5876 * "j=u:k=d:l=r:h=l: =.:" and so on...
5877 * this example rebinds the cursormovement to the keys u (up), d (down),
5878 * l (left), r (right). placing a mark will now be done with ".".
5881 CompileKeys(s
, sl
, array
)
5884 unsigned char *array
;
5887 unsigned char key
, value
;
5891 for (i
= 0; i
< 256; i
++)
5895 debug1("CompileKeys: '%s'\n", s
);
5898 key
= *(unsigned char *)s
++;
5899 if (*s
!= '=' || sl
< 3)
5906 value
= *(unsigned char *)s
++;
5909 while (*s
== '=' && sl
>= 2);
5918 #endif /* COPY_PASTE */
5921 * Asynchronous input functions
5924 #if defined(DETACH) && defined(POW_DETACH)
5926 pow_detach_fn(buf
, len
, data
)
5929 char *data
; /* dummy */
5931 debug("pow_detach_fn called\n");
5937 if (ktab
[(int)(unsigned char)*buf
].nr
!= RC_POW_DETACH
)
5940 write(D_userfd
, "\007", 1);
5941 Msg(0, "Detach aborted.");
5946 #endif /* POW_DETACH */
5950 copy_reg_fn(buf
, len
, data
)
5953 char *data
; /* dummy */
5955 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
5966 if (D_user
->u_plop
.len
)
5968 if ((pp
->buf
= (char *)malloc(D_user
->u_plop
.len
)) == NULL
)
5973 bcopy(D_user
->u_plop
.buf
, pp
->buf
, D_user
->u_plop
.len
);
5975 pp
->len
= D_user
->u_plop
.len
;
5977 pp
->enc
= D_user
->u_plop
.enc
;
5979 Msg(0, "Copied %d characters into register %c", D_user
->u_plop
.len
, *buf
);
5983 ins_reg_fn(buf
, len
, data
)
5986 char *data
; /* dummy */
5988 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
5996 return; /* Input() should not call us w/o fore, but you never know... */
5998 Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
6001 MakePaster(&fore
->w_paster
, pp
->buf
, pp
->len
, 0);
6004 Msg(0, "Empty register.");
6006 #endif /* COPY_PASTE */
6009 process_fn(buf
, len
, data
)
6012 char *data
; /* dummy */
6014 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
6023 ProcessInput(pp
->buf
, pp
->len
);
6026 Msg(0, "Empty register.");
6030 confirm_fn(buf
, len
, data
)
6037 if (len
|| (*buf
!= 'y' && *buf
!= 'Y'))
6042 act
.nr
= *(int *)data
;
6051 struct acluser
**up
;
6053 char pw1
[130]; /* FreeBSD crypts to 128 bytes */
6058 su_fin(buf
, len
, data
)
6063 struct inputsu
*i
= (struct inputsu
*)data
;
6068 { p
= i
->name
; l
= sizeof(i
->name
) - 1; }
6070 { strcpy(p
= i
->pw1
, "\377"); l
= sizeof(i
->pw1
) - 1; }
6072 { strcpy(p
= i
->pw2
, "\377"); l
= sizeof(i
->pw2
) - 1; }
6074 strncpy(p
, buf
, 1 + (l
< len
) ? l
: len
);
6076 Input("Screen User: ", sizeof(i
->name
) - 1, INP_COOKED
, su_fin
, (char *)i
, 0);
6078 Input("User's UNIX Password: ", sizeof(i
->pw1
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6080 Input("User's Screen Password: ", sizeof(i
->pw2
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6083 if ((p
= DoSu(i
->up
, i
->name
, i
->pw2
, i
->pw1
)))
6090 InputSu(w
, up
, name
)
6092 struct acluser
**up
;
6097 if (!(i
= (struct inputsu
*)calloc(1, sizeof(struct inputsu
))))
6102 su_fin(name
, (int)strlen(name
), (char *)i
); /* can also initialise stuff */
6104 su_fin((char *)0, 0, (char *)i
);
6107 #endif /* MULTIUSER */
6112 pass1(buf
, len
, data
)
6117 struct acluser
*u
= (struct acluser
*)data
;
6122 if (u
->u_password
!= NullStr
)
6123 free((char *)u
->u_password
);
6124 u
->u_password
= SaveStr(buf
);
6125 bzero(buf
, strlen(buf
));
6126 Input("Retype new password:", 100, INP_NOECHO
, pass2
, data
, 0);
6130 pass2(buf
, len
, data
)
6137 struct acluser
*u
= (struct acluser
*)data
;
6140 if (!buf
|| strcmp(u
->u_password
, buf
))
6142 Msg(0, "[ Passwords don't match - checking turned off ]");
6143 if (u
->u_password
!= NullStr
)
6145 bzero(u
->u_password
, strlen(u
->u_password
));
6146 free((char *)u
->u_password
);
6148 u
->u_password
= NullStr
;
6150 else if (u
->u_password
[0] == '\0')
6152 Msg(0, "[ No password - no secure ]");
6154 bzero(buf
, strlen(buf
));
6157 if (u
->u_password
!= NullStr
)
6159 for (st
= 0; st
< 2; st
++)
6160 salt
[st
] = 'A' + (int)((time(0) >> 6 * st
) % 26);
6162 buf
= crypt(u
->u_password
, salt
);
6163 bzero(u
->u_password
, strlen(u
->u_password
));
6164 free((char *)u
->u_password
);
6165 u
->u_password
= SaveStr(buf
);
6166 bzero(buf
, strlen(buf
));
6169 UserFreeCopyBuffer(u
);
6170 u
->u_plop
.len
= strlen(u
->u_password
);
6174 if (!(u
->u_plop
.buf
= SaveStr(u
->u_password
)))
6177 D_user
->u_plop
.len
= 0;
6180 Msg(0, "[ Password moved into copybuffer ]");
6181 #else /* COPY_PASTE */
6182 Msg(0, "[ Crypted password is \"%s\" ]", u
->u_password
);
6183 #endif /* COPY_PASTE */
6186 #endif /* PASSWORD */
6189 digraph_fn(buf
, len
, data
)
6192 char *data
; /* dummy */
6199 buf
[len
+ 1] = ch
; /* so we can restore it later */
6200 if (ch
< ' ' || ch
== '\177')
6202 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6206 if ((ch
< '0' || ch
> '9') && (ch
< 'a' || ch
> 'f') && (ch
< 'A' || ch
> 'F'))
6208 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6211 if (len
== (*buf
== 'U' ? 5 : 3))
6215 if (len
&& *buf
== '0')
6217 if (ch
< '0' || ch
> '7')
6219 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6234 buf
[len
] = buf
[len
+ 1]; /* stored above */
6239 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6242 for (i
= 2; i
< len
; i
++)
6244 if (buf
[i
] >= '0' && buf
[i
] <= '9')
6245 x
= x
* 16 | (buf
[i
] - '0');
6246 else if (buf
[i
] >= 'a' && buf
[i
] <= 'f')
6247 x
= x
* 16 | (buf
[i
] - ('a' - 10));
6248 else if (buf
[i
] >= 'A' && buf
[i
] <= 'F')
6249 x
= x
* 16 | (buf
[i
] - ('A' - 10));
6254 else if (buf
[0] == '0')
6257 for (i
= 1; i
< len
; i
++)
6259 if (buf
[i
] < '0' || buf
[i
] > '7')
6261 x
= x
* 8 | (buf
[i
] - '0');
6266 for (i
= 0; i
< (int)(sizeof(digraphs
)/sizeof(*digraphs
)); i
++)
6267 if ((digraphs
[i
][0] == (unsigned char)buf
[0] && digraphs
[i
][1] == (unsigned char)buf
[1]) ||
6268 (digraphs
[i
][0] == (unsigned char)buf
[1] && digraphs
[i
][1] == (unsigned char)buf
[0]))
6270 if (i
== (int)(sizeof(digraphs
)/sizeof(*digraphs
)))
6272 Msg(0, "Unknown digraph");
6280 if (flayer
->l_encoding
== UTF8
)
6281 i
= ToUtf8(buf
, x
); /* buf is big enough for all UTF-8 codes */
6284 LayProcess(&buf
, &i
);
6295 debug1("StuffKey #%d", i
);
6298 debug1(" - %s", term
[i
+ T_CAPS
].tcname
);
6301 if (i
< KMAP_KEYS
&& D_ESCseen
)
6303 struct action
*act
= &D_ESCseen
[i
+ 256];
6304 if (act
->nr
!= RC_ILLEGAL
)
6307 DoAction(act
, i
+ 256);
6313 if (i
>= T_CURSOR
- T_CAPS
&& i
< T_KEYPAD
- T_CAPS
&& D_cursorkeys
)
6314 i
+= T_OCAPS
- T_CURSOR
;
6315 else if (i
>= T_KEYPAD
- T_CAPS
&& i
< T_OCAPS
- T_CAPS
&& D_keypad
)
6316 i
+= T_OCAPS
- T_CURSOR
;
6317 debug1(" - action %d\n", i
);
6318 flayer
= D_forecv
->c_layer
;
6322 if (InMark() || InInput() || InWList())
6323 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &mmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].mm
;
6325 if ((!act
|| act
->nr
== RC_ILLEGAL
) && !D_mapdefault
)
6326 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &umtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].um
;
6327 if (!act
|| act
->nr
== RC_ILLEGAL
)
6328 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &dmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].dm
;
6330 if (discard
&& (!act
|| act
->nr
!= RC_COMMAND
))
6337 if (act
== 0 || act
->nr
== RC_ILLEGAL
)
6351 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6352 if (Layer2Window(cv
->c_layer
) == wi
)
6358 FindNiceWindow(wi
, presel
)
6364 debug2("FindNiceWindow %d %s\n", wi
? wi
->w_number
: -1 , presel
? presel
: "NULL");
6367 i
= WindowByNoN(presel
);
6374 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6377 if (!wi
|| (IsOnDisplay(wi
) && !presel
))
6379 /* try to get another window */
6382 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6383 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6386 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6387 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6390 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6391 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6394 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6395 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6399 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6400 if (!wi
->w_layer
.l_cvlist
)
6403 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6404 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
))
6408 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6416 /* sorted list of all commands */
6417 static struct comm
**commtab
;
6418 static int ncommtab
;
6423 void (*hand
) __P((struct comm
*, char **, int));
6426 for (n
= 0; cos
[n
].name
; n
++)
6431 commtab
= (struct commt
*)realloc(commtab
, sizeof(*commtab
) * (ncommtab
+ n
));
6433 commtab
= (struct commt
*)malloc(sizeof(*commtab
) * (ncommtab
+ n
));
6436 for (i
= 0; i
< n
; i
++)
6438 for (j
= 0; j
< ncommtab
; j
++)
6440 r
= strcmp(cos
[i
].name
, commtab
[j
]->name
);
6442 Panic(0, "Duplicate command: %s\n", cos
[i
].name
);
6446 for (r
= ncommtab
; r
> j
; r
--)
6447 commtab
[r
] = commtab
[r
- 1];
6448 commtab
[j
] = cos
+ i
;
6449 cos
[i
].handler
= hand
;
6450 bzero(cos
[i
].userbits
, sizeof(cos
[i
].userbits
));
6459 int x
, m
, l
= 0, r
= ncommtab
- 1;
6463 x
= strcmp(str
, commtab
[m
]->name
);
6477 CalcSlicePercent(cv
, percent
)
6482 if (!cv
|| !cv
->c_slback
)
6484 up
= CalcSlicePercent(cv
->c_slback
->c_slback
, percent
);
6486 for (cv
= cv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6487 wsum
+= cv
->c_slweight
;
6490 return (up
* w
) / wsum
;
6494 ChangeCanvasSize(fcv
, abs
, diff
, gflag
, percent
)
6495 struct canvas
*fcv
; /* make this canvas bigger */
6496 int abs
; /* mode: 0:rel 1:abs 2:max */
6497 int diff
; /* change this much */
6498 int gflag
; /* go up if neccessary */
6502 int done
, have
, m
, dir
;
6504 debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs
, diff
, percent
);
6505 if (abs
== 0 && diff
== 0)
6510 fcv
->c_slweight
= 0;
6513 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6515 fcv
->c_slweight
= 1;
6516 cv
= fcv
->c_slback
->c_slback
;
6517 if (gflag
&& cv
&& cv
->c_slback
)
6518 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6526 if (percent
&& diff
> percent
)
6532 for (cv
= fcv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6533 wsum
+= cv
->c_slweight
;
6536 up
= gflag
? CalcSlicePercent(fcv
->c_slback
->c_slback
, percent
) : percent
;
6537 debug3("up=%d, wsum=%d percent=%d\n", up
, wsum
, percent
);
6540 int scale
= wsum
< 10 ? 1000 : 100;
6541 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6542 cv
->c_slweight
*= scale
;
6544 debug1("scaled wsum to %d\n", wsum
);
6546 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6550 cv
->c_slweight
= (cv
->c_slweight
* up
) / percent
;
6551 if (cv
->c_slweight
== 0)
6554 debug1(" - weight %d\n", cv
->c_slweight
);
6556 diff
= (diff
* wsum
) / percent
;
6562 if (abs
&& diff
== (fcv
->c_slorient
== SLICE_VERT
? fcv
->c_ye
- fcv
->c_ys
+ 2 : fcv
->c_xe
- fcv
->c_xs
+ 2))
6564 /* fix weights to real size (can't be helped, sorry) */
6565 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6567 cv
->c_slweight
= cv
->c_slorient
== SLICE_VERT
? cv
->c_ye
- cv
->c_ys
+ 2 : cv
->c_xe
- cv
->c_xs
+ 2;
6568 debug1(" - weight %d\n", cv
->c_slweight
);
6572 diff
= diff
- fcv
->c_slweight
;
6573 debug1("diff = %d\n", diff
);
6578 cv
= fcv
->c_slnext
? fcv
->c_slnext
: fcv
->c_slprev
;
6579 fcv
->c_slweight
+= diff
;
6580 cv
->c_slweight
-= diff
;
6585 for (cv
= fcv
->c_slnext
; diff
> 0; cv
= dir
> 0 ? cv
->c_slnext
: cv
->c_slprev
)
6589 debug1("reached end, dir is %d\n", dir
);
6599 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 : 2;
6600 debug2("min is %d, have %d\n", m
, cv
->c_slweight
);
6601 if (cv
->c_slweight
> m
)
6603 have
= cv
->c_slweight
- m
;
6606 debug1("subtract %d\n", have
);
6607 cv
->c_slweight
-= have
;
6614 /* need more room! */
6615 cv
= fcv
->c_slback
->c_slback
;
6616 if (cv
&& cv
->c_slback
)
6617 done
+= ChangeCanvasSize(fcv
->c_slback
->c_slback
, 0, diff
, gflag
, percent
);
6619 fcv
->c_slweight
+= done
;
6620 debug1("ChangeCanvasSize returns %d\n", done
);
6625 ResizeRegions(arg
, flags
)
6631 int gflag
= 0, abs
= 0, percent
= 0;
6637 if (D_forecv
->c_slorient
== SLICE_UNKN
)
6639 Msg(0, "resize: need more than one region");
6642 gflag
= flags
& RESIZE_FLAG_L
? 0 : 1;
6643 orient
|= flags
& RESIZE_FLAG_H
? SLICE_HORI
: 0;
6644 orient
|= flags
& RESIZE_FLAG_V
? SLICE_VERT
: 0;
6646 orient
= D_forecv
->c_slorient
;
6650 /* make all regions the same height */
6651 struct canvas
*cv
= gflag
? &D_canvas
: D_forecv
->c_slback
;
6652 if (cv
->c_slperp
->c_slorient
& orient
)
6653 EqualizeCanvas(cv
->c_slperp
, gflag
);
6654 /* can't use cv->c_slorient directly as it can be D_canvas */
6655 if ((cv
->c_slperp
->c_slorient
^ (SLICE_HORI
^ SLICE_VERT
)) & orient
)
6660 EqualizeCanvas(cv
->c_slperp
, gflag
);
6663 EqualizeCanvas(cv
, gflag
);
6666 RecreateCanvasChain();
6667 RethinkDisplayViewports();
6668 ResizeLayersToCanvases();
6671 if (!strcmp(arg
, "min") || !strcmp(arg
, "0"))
6676 else if (!strcmp(arg
, "max") || !strcmp(arg
, "_"))
6683 if (l
> 0 && arg
[l
- 1] == '%')
6686 diff
= atoi(arg
+ 1);
6687 else if (*arg
== '-')
6688 diff
= -atoi(arg
+ 1);
6691 diff
= atoi(arg
); /* +1 because of caption line */
6694 abs
= diff
== 0 ? 2 : 1;
6700 diff
= diff
* percent
/ 100;
6702 if (cv
->c_slorient
& orient
)
6703 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6704 if (cv
->c_slback
->c_slorient
& orient
)
6705 ChangeCanvasSize(cv
->c_slback
, abs
, diff
, gflag
, percent
);
6707 ResizeCanvas(&D_canvas
);
6708 RecreateCanvasChain();
6709 RethinkDisplayViewports();
6710 ResizeLayersToCanvases();
6717 if (siz
+ diff
> dsize
- (nreg
- 1) * 2 - 1)
6718 diff
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6719 if (diff
== 0 || siz
+ diff
< 1)
6724 if (D_forecv
->c_next
)
6726 D_forecv
->c_ye
+= diff
;
6727 D_forecv
->c_next
->c_ys
+= diff
;
6728 D_forecv
->c_next
->c_yoff
+= diff
;
6732 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6733 if (cv
->c_next
== D_forecv
)
6737 D_forecv
->c_ys
-= diff
;
6738 D_forecv
->c_yoff
-= diff
;
6743 int s
, i
= 0, found
= 0, di
= diff
, d2
;
6744 s
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6745 for (cv
= D_cvlist
; cv
; i
= cv
->c_ye
+ 2, cv
= cv
->c_next
)
6749 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) + diff
;
6750 cv
->c_yoff
-= cv
->c_ys
- i
;
6755 s
-= cv
->c_ye
- cv
->c_ys
;
6763 d2
= di
> cv
->c_ye
- cv
->c_ys
? cv
->c_ye
- cv
->c_ys
: di
;
6765 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) - d2
;
6766 cv
->c_yoff
-= cv
->c_ys
- i
;
6770 RethinkDisplayViewports();
6771 ResizeLayersToCanvases();
6776 ResizeFin(buf
, len
, data
)
6782 int flags
= *(int *)data
;
6783 ch
= ((unsigned char *)buf
)[len
];
6786 ResizeRegions(buf
, flags
);
6790 flags
^= RESIZE_FLAG_H
;
6792 flags
^= RESIZE_FLAG_V
;
6794 flags
|= RESIZE_FLAG_H
|RESIZE_FLAG_V
;
6796 flags
^= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
6798 flags
^= RESIZE_FLAG_L
;
6801 inp_setprompt(resizeprompts
[flags
], NULL
);
6802 *(int *)data
= flags
;
6813 p
= Layer2Window(D_forecv
->c_layer
);
6814 for (i
= 3; i
>=0; i
--)
6815 SetXtermOSC(i
, p
? p
->w_xtermosc
[i
] : 0);
6820 ParseAttrColor(s1
, s2
, msgok
)
6832 while (*ss
&& *ss
!= ' ')
6836 if (*s
&& (s2
|| *ss
|| !((*s
>= 'a' && *s
<= 'z') || (*s
>= 'A' && *s
<= 'Z') || *s
== '.')))
6838 int mode
= 0, n
= 0;
6856 if (*s
>= '0' && *s
<= '9')
6859 if (*s
>= '0' && *s
<= '9')
6860 n
= n
* 16 + (*s
++ - '0');
6861 else if (*s
>= 'a' && *s
<= 'f')
6862 n
= n
* 16 + (*s
++ - ('a' - 10));
6863 else if (*s
>= 'A' && *s
<= 'F')
6864 n
= n
* 16 + (*s
++ - ('A' - 10));
6865 else if (*s
&& *s
!= ' ')
6868 Msg(0, "Illegal attribute hexchar '%c'", *s
);
6874 while (*s
&& *s
!= ' ')
6891 Msg(0, "Illegal attribute specifier '%c'", *s
);
6897 if (*s
&& *s
!= ' ')
6900 Msg(0, "junk after attribute description: '%c'", *s
);
6912 while (*s
&& *s
== ' ')
6920 Msg(0, "junk after description: '%c'", *s
);
6924 while (*s
&& *s
== ' ')
6931 static char costr
[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
6941 for (j
= 0; j
< 2 && *s
&& *s
!= ' '; j
++)
6943 for (i
= 0; costr
[i
]; i
++)
6949 Msg(0, "illegal color descriptor: '%c'", *s
);
6953 n
= n
<< 4 | (i
& 15);
6956 n
= (n
& 0x20ff) | 0x200;
6960 if ((n
& 0xf00) == 0xf00)
6961 n
^= 0xf00; /* clear superflous bits */
6964 n
^= 0x2400; /* shift bit into right position */
6967 n
|= 0xf0; /* don't change bg color */
6968 if (numco
!= 2 && n
!= 0xff)
6969 n
|= 0x100; /* special invert mode */
6970 if (*s
&& *s
!= ' ')
6973 Msg(0, "junk after color description: '%c'", *s
);
6981 while (*s
&& *s
== ' ')
6986 Msg(0, "junk after description: '%c'", *s
);
6989 debug1("ParseAttrColor %06x\n", r
);
6997 * e just set intensity
6998 * f don't change anything
6999 * Intensity is encoded into bits 17(fg) and 18(bg).
7002 ApplyAttrColor(i
, mc
)
7006 debug1("ApplyAttrColor %06x\n", i
);
7007 mc
->attr
|= i
>> 8 & 255;
7008 mc
->attr
^= i
& 255;
7010 i
= (i
>> 16) ^ 0xff;
7011 if ((i
& 0x100) != 0)
7014 if (mc
->attr
& (A_SO
|A_RV
))
7016 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4) | ((i
& 0x200) << 1) | ((i
& 0x400) >> 1);
7018 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4);
7022 if ((i
& 0x0f) != 0x0f)
7023 mc
->attr
= (mc
->attr
& 0xbf) | ((i
>> 3) & 0x40);
7024 if ((i
& 0xf0) != 0xf0)
7025 mc
->attr
= (mc
->attr
& 0x7f) | ((i
>> 3) & 0x80);
7027 mc
->color
= 0x99 ^ mc
->color
;
7028 if ((i
& 0x0e) == 0x0e)
7029 i
= (i
& 0xf0) | (mc
->color
& 0x0f);
7030 if ((i
& 0xe0) == 0xe0)
7031 i
= (i
& 0x0f) | (mc
->color
& 0xf0);
7032 mc
->color
= 0x99 ^ i
;
7033 debug2("ApplyAttrColor - %02x %02x\n", mc
->attr
, i
);