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" : "");
1063 char **args
= act
->args
;
1064 int *argl
= act
->argl
;
1066 int argc
, i
, n
, msgok
;
1069 struct display
*odisplay
= display
;
1070 struct acluser
*user
;
1072 user
= display
? D_user
: users
;
1073 if (nr
== RC_ILLEGAL
)
1075 debug1("key '%c': No action\n", key
);
1078 n
= comms
[nr
].flags
;
1079 if ((n
& NEED_DISPLAY
) && display
== 0)
1081 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1084 if ((n
& NEED_FORE
) && fore
== 0)
1086 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1089 if ((n
& NEED_LAYER
) && flayer
== 0)
1091 Msg(0, "%s: %s: display or window required", rc_name
, comms
[nr
].name
);
1094 if ((argc
= CheckArgNum(nr
, args
)) < 0)
1099 if (AclCheckPermCmd(D_user
, ACL_EXEC
, &comms
[nr
]))
1101 Msg(0, "%s: %s: permission denied (user %s)",
1102 rc_name
, comms
[nr
].name
, (EffectiveAclUser
? EffectiveAclUser
: D_user
)->u_name
);
1106 #endif /* MULTIUSER */
1108 msgok
= display
&& !*rc_name
;
1114 else if (args
[0][0] == '-' && !args
[0][1])
1116 SetForeWindow((struct win
*)0);
1119 else if (args
[0][0] == '.' && !args
[0][1])
1122 Msg(0, "select . needs a window");
1125 SetForeWindow(fore
);
1129 else if (ParseWinNum(act
, &n
) == 0)
1133 case RC_DEFAUTONUKE
:
1134 if (ParseOnOff(act
, &defautonuke
) == 0 && msgok
)
1135 Msg(0, "Default autonuke turned %s", defautonuke
? "on" : "off");
1136 if (display
&& *rc_name
)
1137 D_auto_nuke
= defautonuke
;
1140 if (ParseOnOff(act
, &D_auto_nuke
) == 0 && msgok
)
1141 Msg(0, "Autonuke turned %s", D_auto_nuke
? "on" : "off");
1144 case RC_DEFOBUFLIMIT
:
1145 if (ParseNum(act
, &defobuflimit
) == 0 && msgok
)
1146 Msg(0, "Default limit set to %d", defobuflimit
);
1147 if (display
&& *rc_name
)
1149 D_obufmax
= defobuflimit
;
1150 D_obuflenmax
= D_obuflen
- D_obufmax
;
1155 Msg(0, "Limit is %d, current buffer size is %d", D_obufmax
, D_obuflen
);
1156 else if (ParseNum(act
, &D_obufmax
) == 0 && msgok
)
1157 Msg(0, "Limit set to %d", D_obufmax
);
1158 D_obuflenmax
= D_obuflen
- D_obufmax
;
1160 case RC_DUMPTERMCAP
:
1161 WriteFile(user
, (char *)0, DUMP_TERMCAP
);
1165 int mode
= DUMP_HARDCOPY
;
1167 if (argc
> 1 && !strcmp(*args
, "-h"))
1169 mode
= DUMP_SCROLLBACK
;
1173 if (*args
&& args
[1])
1175 Msg(0, "%s: hardcopy: too many arguments", rc_name
);
1178 if (fore
== 0 && *args
== 0)
1179 Msg(0, "%s: hardcopy: window required", rc_name
);
1181 WriteFile(user
, *args
, mode
);
1185 (void)ParseOnOff(act
, &nwin_default
.Lflag
);
1188 n
= fore
->w_log
? 1 : 0;
1189 ParseSwitch(act
, &n
);
1199 SwitchWindow(NextWindow());
1203 SwitchWindow(PreviousWindow());
1212 Input(fore
->w_pwin
? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1214 Input("Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1222 FreePseudowin(fore
);
1223 Msg(0, "Filter removed.");
1227 name
= SaveStr(fore
->w_title
);
1229 Msg(0, "Window %d (%s) killed.", n
, name
);
1237 Input("Really quit and kill all your windows [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_QUIT
);
1244 if (*args
&& !strcmp(*args
, "-h"))
1256 Input(buf
, 1, INP_RAW
, pow_detach_fn
, NULL
, 0);
1259 Detach(D_POWER
); /* detach and kill Attacher's parent */
1268 Msg(0, "debugging info is written to %s/", DEBUGDIR
);
1270 Msg(0, "debugging is currently off. Use 'debug on' to enable.");
1275 debug("debug: closing debug file.\n");
1280 if (strcmp("off", *args
))
1284 kill(D_userpid
, SIG_NODEBUG
); /* a one shot item, but hey... */
1285 # endif /* SIG_NODEBUG */
1287 if (*args
== 0 || strcmp("off", *args
))
1288 Msg(0, "Sorry, screen was compiled without -DDEBUG option.");
1293 if (*args
&& !strcmp(*args
, "sendcmd"))
1297 free(zmodem_sendcmd
);
1298 zmodem_sendcmd
= SaveStr(args
[1]);
1301 Msg(0, "zmodem sendcmd: %s", zmodem_sendcmd
);
1304 if (*args
&& !strcmp(*args
, "recvcmd"))
1308 free(zmodem_recvcmd
);
1309 zmodem_recvcmd
= SaveStr(args
[1]);
1312 Msg(0, "zmodem recvcmd: %s", zmodem_recvcmd
);
1317 for (i
= 0; i
< 4; i
++)
1318 if (!strcmp(zmodes
[i
], *args
))
1320 if (i
== 4 && !strcmp(*args
, "on"))
1324 Msg(0, "usage: zmodem off|auto|catch|pass");
1330 Msg(0, "zmodem mode is %s", zmodes
[zmodem_mode
]);
1337 ZombieKey_destroy
= 0;
1340 if (*argl
== 0 || *argl
> 2)
1342 Msg(0, "%s:zombie: one or two characters expected.", rc_name
);
1347 if (!strcmp(args
[1], "onerror"))
1349 ZombieKey_onerror
= 1;
1351 Msg(0, "usage: zombie [keys [onerror]]");
1355 ZombieKey_onerror
= 0;
1356 ZombieKey_destroy
= args
[0][0];
1357 ZombieKey_resurrect
= *argl
== 2 ? args
[0][1] : 0;
1367 struct display
*olddisplay
= display
;
1368 display
= 0; /* no display will cause a broadcast */
1369 Msg(0, "%s: %s", s
, *args
);
1370 display
= olddisplay
;
1374 /* where this AT command comes from: */
1376 s
= SaveStr(D_user
->u_name
);
1377 /* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
1378 EffectiveAclUser
= D_user
;
1380 s
= SaveStr(D_usertty
);
1382 n
= strlen(args
[0]);
1385 * the windows/displays loops are quite dangerous here, take extra
1386 * care not to trigger landmines. Things may appear/disappear while
1387 * we are walking along.
1391 case '*': /* user */
1399 for (u
= users
; u
; u
= u
->u_next
)
1401 debug3("strncmp('%s', '%s', %d)\n", *args
, u
->u_name
, n
);
1402 if (!strncmp(*args
, u
->u_name
, n
))
1405 debug1("at all displays of user %s\n", u
->u_name
);
1406 for (display
= displays
; display
; display
= nd
)
1408 nd
= display
->d_next
;
1411 flayer
= D_forecv
->c_layer
;
1415 debug1("AT display %s\n", D_usertty
);
1416 DoCommand(args
+ 1, argl
+ 1);
1418 Msg(0, "command from %s: %s %s",
1419 s
, args
[1], args
[2] ? args
[2] : "");
1426 case '%': /* display */
1430 debug1("at display matching '%s'\n", args
[0]);
1431 for (display
= displays
; display
; display
= nd
)
1433 nd
= display
->d_next
;
1437 flayer
= D_forecv
->c_layer
;
1438 if (strncmp(args
[0], D_usertty
, n
) &&
1439 (strncmp("/dev/", D_usertty
, 5) ||
1440 strncmp(args
[0], D_usertty
+ 5, n
)) &&
1441 (strncmp("/dev/tty", D_usertty
, 8) ||
1442 strncmp(args
[0], D_usertty
+ 8, n
)))
1444 debug1("AT display %s\n", D_usertty
);
1445 DoCommand(args
+ 1, argl
+ 1);
1447 Msg(0, "command from %s: %s %s",
1448 s
, args
[1], args
[2] ? args
[2] : "");
1455 case '#': /* window */
1466 if (!*args
[0] || (i
= WindowByNumber(args
[0])) < 0)
1468 args
[0][n
] = ch
; /* must restore string in case of bind */
1469 /* try looping over titles */
1470 for (fore
= windows
; fore
; fore
= nw
)
1473 if (strncmp(args
[0], fore
->w_title
, n
))
1475 debug2("AT window %d(%s)\n", fore
->w_number
, fore
->w_title
);
1477 * consider this a bug or a feature:
1478 * while looping through windows, we have fore AND
1479 * display context. This will confuse users who try to
1480 * set up loops inside of loops, but often allows to do
1481 * what you mean, even when you adress your context wrong.
1484 /* XXX: other displays? */
1485 if (fore
->w_layer
.l_cvlist
)
1486 display
= fore
->w_layer
.l_cvlist
->c_display
;
1487 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1488 DoCommand(args
+ 1, argl
+ 1); /* may destroy our display */
1489 if (fore
&& fore
->w_layer
.l_cvlist
)
1491 display
= fore
->w_layer
.l_cvlist
->c_display
;
1492 Msg(0, "command from %s: %s %s",
1493 s
, args
[1], args
[2] ? args
[2] : "");
1499 Msg(0, "%s: at '%s': no such window.\n", rc_name
, args
[0]);
1502 else if (i
< MAXWIN
&& (fore
= wtab
[i
]))
1504 args
[0][n
] = ch
; /* must restore string in case of bind */
1505 debug2("AT window %d (%s)\n", fore
->w_number
, fore
->w_title
);
1506 if (fore
->w_layer
.l_cvlist
)
1507 display
= fore
->w_layer
.l_cvlist
->c_display
;
1508 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1509 DoCommand(args
+ 1, argl
+ 1);
1510 if (fore
&& fore
->w_layer
.l_cvlist
)
1512 display
= fore
->w_layer
.l_cvlist
->c_display
;
1513 Msg(0, "command from %s: %s %s",
1514 s
, args
[1], args
[2] ? args
[2] : "");
1520 Msg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name
);
1526 EffectiveAclUser
= NULL
;
1533 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1534 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1536 i
= FindEncoding(args
[1]);
1539 Msg(0, "%s: readreg: unknown encoding", rc_name
);
1546 * Without arguments we prompt for a destination register.
1547 * It will receive the copybuffer contents.
1548 * This is not done by RC_PASTE, as we prompt for source
1551 if ((s
= *args
) == NULL
)
1553 Input("Copy to register:", 1, INP_RAW
, copy_reg_fn
, NULL
, 0);
1558 Msg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name
);
1563 * With two arguments we *really* read register contents from file
1569 Msg(0, "%s: readreg: too many arguments", rc_name
);
1572 if ((s
= ReadFile(args
[1], &n
)))
1574 struct plop
*pp
= plop_tab
+ (int)(unsigned char)ch
;
1587 * with one argument we copy the copybuffer into a specified register
1588 * This could be done with RC_PASTE too, but is here to be consistent
1589 * with the zero argument call.
1591 copy_reg_fn(&ch
, 0, NULL
);
1596 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1597 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1599 i
= FindEncoding(args
[1]);
1602 Msg(0, "%s: register: unknown encoding", rc_name
);
1611 Msg(0, "%s: register: illegal number of arguments.", rc_name
);
1616 Msg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name
);
1623 if (user
->u_plop
.buf
!= NULL
)
1624 UserFreeCopyBuffer(user
);
1625 if (args
[1] && args
[1][0])
1627 user
->u_plop
.buf
= SaveStrn(args
[1], argl
[1]);
1628 user
->u_plop
.len
= argl
[1];
1630 user
->u_plop
.enc
= i
;
1637 struct plop
*plp
= plop_tab
+ (int)(unsigned char)ch
;
1641 plp
->buf
= SaveStrn(args
[1], argl
[1]);
1649 if ((s
= *args
) == NULL
)
1651 Input("Process register:", 1, INP_RAW
, process_fn
, NULL
, 0);
1656 Msg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name
);
1660 process_fn(&ch
, 0, NULL
);
1667 if (strcmp(s
, "-k"))
1669 Msg(0, "%s: stuff: invalid option %s", rc_name
, s
);
1673 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
1674 if (strcmp(term
[i
].tcname
, s
) == 0)
1678 Msg(0, "%s: stuff: unknown key '%s'", rc_name
, s
);
1682 if (StuffKey(i
- T_CAPS
) == 0)
1685 s
= display
? D_tcs
[i
].str
: 0;
1700 Msg(0, "screen %s", version
);
1705 timestring
= SaveStr(*args
);
1708 Msg(0, "%s", MakeWinMsg(timestring
, fore
, '%'));
1718 struct action
*ktabp
= ktab
;
1719 if (argc
== 2 && !strcmp(*args
, "-c"))
1721 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
1723 Msg(0, "Unknown command class '%s'", args
[1]);
1727 if (D_ESCseen
!= ktab
|| ktabp
!= ktab
)
1737 SwitchWindow(display
&& D_other
? D_other
->w_number
: NextWindow());
1740 if (user
->u_Esc
== -1)
1759 case RC_DEFBREAKTYPE
:
1762 static char *types
[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL
};
1763 extern int breaktype
;
1767 if (ParseNum(act
, &n
))
1768 for (n
= 0; n
< (int)(sizeof(types
)/sizeof(*types
)); n
++)
1770 for (i
= 0; i
< 4; i
++)
1773 if (ch
>= 'a' && ch
<= 'z')
1775 if (ch
!= types
[n
][i
] && (ch
+ ('a' - 'A')) != types
[n
][i
])
1781 if (n
< 0 || n
>= (int)(sizeof(types
)/sizeof(*types
)))
1782 Msg(0, "%s invalid, chose one of %s, %s or %s", *args
, types
[0], types
[1], types
[2]);
1786 Msg(0, "breaktype set to (%d) %s", n
, types
[n
]);
1790 Msg(0, "breaktype is (%d) %s", breaktype
, types
[breaktype
]);
1796 if (*args
&& ParseNum(act
, &n
))
1798 SendBreak(fore
, n
, nr
== RC_POW_BREAK
);
1812 if (*args
&& !strcmp(*args
, "-w"))
1814 else if (*args
&& !strcmp(*args
, "-d"))
1818 if (what
== 0 && flayer
&& !display
)
1824 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1827 w
= flayer
->l_width
;
1828 h
= flayer
->l_height
;
1834 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1840 if (*args
&& args
[0][0] == '-')
1842 Msg(0, "%s: %s: unknown option %s", rc_name
, comms
[nr
].name
, *args
);
1845 if (nr
== RC_HEIGHT
)
1853 else if (h
== H1height
)
1855 else if (h
> (H0height
+ H1height
) / 2)
1873 else if (w
== Z1width
)
1875 else if (w
> (Z0width
+ Z1width
) / 2)
1887 if (*args
&& args
[1] && args
[2])
1889 Msg(0, "%s: %s: too many arguments", rc_name
, comms
[nr
].name
);
1894 Msg(0, "Illegal width");
1899 Msg(0, "Illegal height");
1904 if (flayer
->l_width
== w
&& flayer
->l_height
== h
)
1906 ResizeLayer(flayer
, w
, h
, (struct display
*)0);
1909 if (D_width
== w
&& D_height
== h
)
1913 ChangeScreenSize(w
, h
, 1);
1917 if (ResizeDisplay(w
, h
) == 0)
1919 Activate(D_fore
? D_fore
->w_norefresh
: 0);
1921 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
1925 Msg(0, "Your termcap does not specify how to change the terminal's width to %d.", w
);
1926 else if (w
== D_width
)
1927 Msg(0, "Your termcap does not specify how to change the terminal's height to %d.", h
);
1929 Msg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w
, h
);
1937 ChangeAKA(fore
, *args
, strlen(*args
));
1940 Input(":", 100, INP_EVERY
, Colonfin
, NULL
, 0);
1941 if (*args
&& **args
)
1949 if (D_status_lastmsg
)
1950 Msg(0, "%s", D_status_lastmsg
);
1953 DoScreen("key", args
);
1956 if (ParseSwitch(act
, &fore
->w_wrap
) == 0 && msgok
)
1957 Msg(0, "%cwrap", fore
->w_wrap
? '+' : '-');
1962 if (args
[0][0] == 'a')
1964 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) ? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
1968 if (ParseOnOff(act
, &n
))
1970 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | n
;
1975 if (fore
->w_flow
& FLOW_AUTOFLAG
)
1976 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | FLOW_NOW
;
1977 else if (fore
->w_flow
& FLOW_NOW
)
1978 fore
->w_flow
&= ~FLOW_NOW
;
1980 fore
->w_flow
= fore
->w_flow
? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
1982 SetFlow(fore
->w_flow
& FLOW_NOW
);
1984 Msg(0, "%cflow%s", (fore
->w_flow
& FLOW_NOW
) ? '+' : '-',
1985 (fore
->w_flow
& FLOW_AUTOFLAG
) ? "(auto)" : "");
1988 case RC_DEFWRITELOCK
:
1989 if (args
[0][0] == 'a')
1990 nwin_default
.wlock
= WLOCK_AUTO
;
1993 if (ParseOnOff(act
, &n
))
1995 nwin_default
.wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2001 if (args
[0][0] == 'a')
2003 fore
->w_wlock
= WLOCK_AUTO
;
2007 if (ParseOnOff(act
, &n
))
2009 fore
->w_wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2012 * user may have permission to change the writelock setting,
2013 * but he may never aquire the lock himself without write permission
2015 if (!AclCheckPermWin(D_user
, ACL_WRITE
, fore
))
2016 fore
->w_wlockuser
= D_user
;
2018 Msg(0, "writelock %s", (fore
->w_wlock
== WLOCK_AUTO
) ? "auto" :
2019 ((fore
->w_wlock
== WLOCK_OFF
) ? "off" : "on"));
2023 ResetAnsiState(fore
);
2024 WriteString(fore
, "\033[H\033[J", 6);
2027 ResetAnsiState(fore
);
2029 if (fore
->w_zdisplay
)
2030 zmodem_abort(fore
, fore
->w_zdisplay
);
2032 WriteString(fore
, "\033c", 2);
2035 n
= fore
->w_monitor
!= MON_OFF
;
2038 n
= n
&& (ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
));
2040 if (ParseSwitch(act
, &n
))
2045 if (display
) /* we tell only this user */
2046 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2048 for (i
= 0; i
< maxusercount
; i
++)
2049 ACLBYTE(fore
->w_mon_notify
, i
) |= ACLBIT(i
);
2051 if (fore
->w_monitor
== MON_OFF
)
2052 fore
->w_monitor
= MON_ON
;
2053 Msg(0, "Window %d (%s) is now being monitored for all activity.", fore
->w_number
, fore
->w_title
);
2058 if (display
) /* we remove only this user */
2059 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
)
2060 &= ~ACLBIT(D_user
->u_id
);
2062 for (i
= 0; i
< maxusercount
; i
++)
2063 ACLBYTE(fore
->w_mon_notify
, i
) &= ~ACLBIT(i
);
2064 for (i
= maxusercount
- 1; i
>= 0; i
--)
2065 if (ACLBYTE(fore
->w_mon_notify
, i
))
2069 fore
->w_monitor
= MON_OFF
;
2070 Msg(0, "Window %d (%s) is no longer being monitored for activity.", fore
->w_number
, fore
->w_title
);
2080 display_wlist(0, WLIST_NUM
, (struct win
*)0);
2081 else if (!strcmp(*args
, "-m") && !args
[1])
2082 display_wlist(0, WLIST_MRU
, (struct win
*)0);
2083 else if (!strcmp(*args
, "-b") && !args
[1])
2084 display_wlist(1, WLIST_NUM
, (struct win
*)0);
2085 else if (!strcmp(*args
, "-b") && !strcmp(args
[1], "-m") && !args
[2])
2086 display_wlist(1, WLIST_MRU
, (struct win
*)0);
2087 else if (!strcmp(*args
, "-m") && !strcmp(args
[1], "-b") && !args
[2])
2088 display_wlist(1, WLIST_MRU
, (struct win
*)0);
2089 else if (!strcmp(*args
, "string"))
2095 wliststr
= SaveStr(args
[1]);
2098 Msg(0, "windowlist string is '%s'", wliststr
);
2100 else if (!strcmp(*args
, "title"))
2106 wlisttit
= SaveStr(args
[1]);
2109 Msg(0, "windowlist title is '%s'", wlisttit
);
2112 Msg(0, "usage: windowlist [-b] [string [string] | title [title]]");
2115 if (argc
== 2 && !strcmp(*args
, "-c"))
2117 struct action
*ktabp
;
2118 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
2120 Msg(0, "Unknown command class '%s'", args
[1]);
2123 display_help(args
[1], ktabp
);
2126 display_help((char *)0, ktab
);
2129 display_copyright();
2133 if (flayer
->l_layfn
!= &WinLf
)
2135 Msg(0, "Must be on a window layer");
2142 static char *pasteargs
[] = {".", 0};
2143 static int pasteargl
[] = {1};
2145 if (flayer
->l_layfn
!= &WinLf
)
2147 Msg(0, "Must be on a window layer");
2150 if (GetHistory() == 0)
2152 if (user
->u_plop
.buf
== NULL
)
2160 char *ss
, *dbuf
, dch
;
2167 * without args we prompt for one(!) register to be pasted in the window
2169 if ((s
= *args
) == NULL
)
2171 Input("Paste from register:", 1, INP_RAW
, ins_reg_fn
, NULL
, 0);
2174 if (args
[1] == 0 && !fore
) /* no window? */
2177 * with two arguments we paste into a destination register
2178 * (no window needed here).
2180 if (args
[1] && argl
[1] != 1)
2182 Msg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
2188 enc
= fore
->w_encoding
;
2192 * measure length of needed buffer
2194 for (ss
= s
= *args
; (ch
= *ss
); ss
++)
2200 enc
= user
->u_plop
.enc
;
2201 if (enc
!= user
->u_plop
.enc
)
2202 l
+= RecodeBuf((unsigned char *)user
->u_plop
.buf
, user
->u_plop
.len
, user
->u_plop
.enc
, enc
, (unsigned char *)0);
2205 l
+= user
->u_plop
.len
;
2211 enc
= plop_tab
[(int)(unsigned char)ch
].enc
;
2212 if (enc
!= plop_tab
[(int)(unsigned char)ch
].enc
)
2213 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);
2216 l
+= plop_tab
[(int)(unsigned char)ch
].len
;
2221 Msg(0, "empty buffer");
2226 * if there is only one source and the destination is a window, then
2227 * pass a pointer rather than duplicating the buffer.
2229 if (s
[1] == 0 && args
[1] == 0)
2231 if (enc
== (*s
== '.' ? user
->u_plop
.enc
: plop_tab
[(int)(unsigned char)*s
].enc
))
2234 MakePaster(&fore
->w_paster
, *s
== '.' ? user
->u_plop
.buf
: plop_tab
[(int)(unsigned char)*s
].buf
, l
, 0);
2238 * if no shortcut, we construct a buffer
2240 if ((dbuf
= (char *)malloc(l
)) == 0)
2247 * concatenate all sources into our own buffer, copy buffer is
2248 * special and is skipped if no display exists.
2250 for (ss
= s
; (ch
= *ss
); ss
++)
2252 struct plop
*pp
= (ch
== '.' ? &user
->u_plop
: &plop_tab
[(int)(unsigned char)ch
]);
2256 l
+= RecodeBuf((unsigned char *)pp
->buf
, pp
->len
, pp
->enc
, enc
, (unsigned char *)dbuf
+ l
);
2260 bcopy(pp
->buf
, dbuf
+ l
, pp
->len
);
2264 * when called with one argument we paste our buffer into the window
2268 MakePaster(&fore
->w_paster
, dbuf
, l
, 1);
2273 * we have two arguments, the second is already in dch.
2274 * use this as destination rather than the window.
2279 if (user
->u_plop
.buf
!= NULL
)
2280 UserFreeCopyBuffer(user
);
2281 user
->u_plop
.buf
= dbuf
;
2282 user
->u_plop
.len
= l
;
2284 user
->u_plop
.enc
= enc
;
2289 struct plop
*pp
= plop_tab
+ (int)(unsigned char)dch
;
2302 if (!user
->u_plop
.buf
)
2304 Msg(0, "empty buffer");
2309 struct plop oldplop
;
2311 oldplop
= user
->u_plop
;
2312 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2317 enc
= FindEncoding(args
[1]);
2320 Msg(0, "%s: writebuf: unknown encoding", rc_name
);
2323 if (enc
!= oldplop
.enc
)
2325 l
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)0);
2326 newbuf
= malloc(l
+ 1);
2332 user
->u_plop
.len
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)newbuf
);
2333 user
->u_plop
.buf
= newbuf
;
2334 user
->u_plop
.enc
= enc
;
2339 if (args
[0] && args
[1])
2340 Msg(0, "%s: writebuf: too many arguments", rc_name
);
2342 WriteFile(user
, args
[0], DUMP_EXCHANGE
);
2344 if (user
->u_plop
.buf
!= oldplop
.buf
)
2345 free(user
->u_plop
.buf
);
2346 user
->u_plop
= oldplop
;
2352 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
2353 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2355 i
= FindEncoding(args
[1]);
2358 Msg(0, "%s: readbuf: unknown encoding", rc_name
);
2364 if (args
[0] && args
[1])
2366 Msg(0, "%s: readbuf: too many arguments", rc_name
);
2369 if ((s
= ReadFile(args
[0] ? args
[0] : BufferFile
, &n
)))
2371 if (user
->u_plop
.buf
)
2372 UserFreeCopyBuffer(user
);
2373 user
->u_plop
.len
= n
;
2374 user
->u_plop
.buf
= s
;
2376 user
->u_plop
.enc
= i
;
2384 (void)ParseSwitch(act
, &search_ic
);
2386 Msg(0, "Will %signore case in searches", search_ic
? "" : "not ");
2388 #endif /* COPY_PASTE */
2391 SetEscape(user
, -1, -1);
2392 else if (*argl
== 2)
2393 SetEscape(user
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2396 Msg(0, "%s: two characters required after escape.", rc_name
);
2399 /* Change defescape if master user. This is because we only
2402 if (display
&& user
!= users
)
2407 SetEscape(NULL
, -1, -1);
2408 else if (*argl
== 2)
2409 SetEscape(NULL
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2412 Msg(0, "%s: two characters required after defescape.", rc_name
);
2420 s
= *args
? *args
: home
;
2422 Msg(errno
, "%s", s
);
2426 if (ParseSaveStr(act
, &ShellProg
) == 0)
2427 ShellArgs
[0] = ShellProg
;
2429 case RC_HARDCOPYDIR
:
2431 (void)ParseSaveStr(act
, &hardcopydir
);
2433 Msg(0, "hardcopydir is %s\n", hardcopydir
&& *hardcopydir
? hardcopydir
: "<cwd>");
2438 if (args
[1] && !(strcmp(*args
, "flush")))
2440 log_flush
= atoi(args
[1]);
2442 Msg(0, "log flush timeout set to %ds\n", log_flush
);
2445 if (ParseSaveStr(act
, &screenlogfile
) || !msgok
)
2448 Msg(0, "logfile is '%s'", screenlogfile
);
2451 if (!*args
|| !strcmp(*args
, "on") || !strcmp(*args
, "off"))
2453 if (ParseSwitch(act
, &logtstamp_on
) == 0 && msgok
)
2454 Msg(0, "timestamps turned %s", logtstamp_on
? "on" : "off");
2456 else if (!strcmp(*args
, "string"))
2460 if (logtstamp_string
)
2461 free(logtstamp_string
);
2462 logtstamp_string
= SaveStr(args
[1]);
2465 Msg(0, "logfile timestamp is '%s'", logtstamp_string
);
2467 else if (!strcmp(*args
, "after"))
2471 logtstamp_after
= atoi(args
[1]);
2475 Msg(0, "timestamp printed after %ds\n", logtstamp_after
);
2478 Msg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
2481 (void)ParseSaveStr(act
, &nwin_default
.aka
);
2484 case RC_TERMCAPINFO
:
2486 if (!rc_name
|| !*rc_name
)
2487 Msg(0, "Sorry, too late now. Place that in your .screenrc file.");
2490 break; /* Already handled */
2493 if (ParseSaveStr(act
, &s
))
2495 if (strlen(s
) >= 20)
2497 Msg(0, "%s: term: argument too long ( < 20)", rc_name
);
2501 strcpy(screenterm
, s
);
2503 debug1("screenterm set to %s\n", screenterm
);
2504 MakeTermcap((display
== 0));
2505 debug("new termcap made\n");
2508 if (!msgok
&& (!rc_name
|| strcmp(rc_name
, "-X")))
2511 * user typed ^A:echo... well, echo isn't FinishRc's job,
2512 * but as he wanted to test us, we show good will
2514 if (argc
> 1 && !strcmp(*args
, "-n"))
2520 if (argc
> 1 && !strcmp(*args
, "-p"))
2526 s
= MakeWinMsg(s
, fore
, '%');
2531 Msg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name
);
2538 AddXChars(buf
, sizeof(buf
), BellString
);
2539 Msg(0, "bell_msg is '%s'", buf
);
2542 (void)ParseSaveStr(act
, &BellString
);
2547 BufferFile
= SaveStr(DEFAULT_BUFFERFILE
);
2548 else if (ParseSaveStr(act
, &BufferFile
))
2551 Msg(0, "Bufferfile is now '%s'", BufferFile
);
2555 (void)ParseSaveStr(act
, &ActivityString
);
2557 #if defined(DETACH) && defined(POW_DETACH)
2558 case RC_POW_DETACH_MSG
:
2562 AddXChars(buf
, sizeof(buf
), PowDetachString
);
2563 Msg(0, "pow_detach_msg is '%s'", buf
);
2566 (void)ParseSaveStr(act
, &PowDetachString
);
2569 #if defined(UTMPOK) && defined(LOGOUTOK)
2571 n
= fore
->w_slot
!= (slot_t
)-1;
2572 if (*args
&& !strcmp(*args
, "always"))
2579 if (*args
&& !strcmp(*args
, "attached"))
2586 if (ParseSwitch(act
, &n
) == 0)
2590 if (!strcmp(*args
, "always"))
2591 nwin_default
.lflag
|= 2;
2592 else if (!strcmp(*args
, "attached"))
2593 nwin_default
.lflag
&= ~2;
2595 (void)ParseOnOff(act
, &nwin_default
.lflag
);
2599 if (args
[0] && args
[1] && args
[1][0] == 'i')
2602 for (display
= displays
; display
; display
= display
->d_next
)
2606 #if defined(TERMIO) || defined(POSIX)
2607 D_NewMode
.tio
.c_cc
[VINTR
] = D_OldMode
.tio
.c_cc
[VINTR
];
2608 D_NewMode
.tio
.c_lflag
|= ISIG
;
2609 #else /* TERMIO || POSIX */
2610 D_NewMode
.m_tchars
.t_intrc
= D_OldMode
.m_tchars
.t_intrc
;
2611 #endif /* TERMIO || POSIX */
2612 SetTTY(D_userfd
, &D_NewMode
);
2615 if (args
[0] && args
[0][0] == 'a')
2616 nwin_default
.flowflag
= FLOW_AUTOFLAG
;
2618 (void)ParseOnOff(act
, &nwin_default
.flowflag
);
2621 (void)ParseOnOff(act
, &nwin_default
.wrap
);
2624 (void)ParseOnOff(act
, &nwin_default
.c1
);
2628 (void)ParseOnOff(act
, &nwin_default
.bce
);
2632 (void)ParseOnOff(act
, &nwin_default
.gr
);
2635 if (ParseOnOff(act
, &n
) == 0)
2636 nwin_default
.monitor
= (n
== 0) ? MON_OFF
: MON_ON
;
2639 if (ParseOnOff(act
, &n
) == 0)
2640 nwin_default
.silence
= (n
== 0) ? SILENCE_OFF
: SILENCE_ON
;
2644 Msg(0, "W%s echo command when creating windows.",
2645 VerboseCreate
? "ill" : "on't");
2646 else if (ParseOnOff(act
, &n
) == 0)
2652 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
2655 if (args
[0] && strcmp(args
[0], "on") && strcmp(args
[0], "off"))
2657 struct display
*olddisplay
= display
;
2658 int old_use
, new_use
= -1;
2661 if (!strncmp(s
, "always", 6))
2663 if (!strcmp(s
, "lastline"))
2664 new_use
= HSTATUS_LASTLINE
;
2665 else if (!strcmp(s
, "ignore"))
2666 new_use
= HSTATUS_IGNORE
;
2667 else if (!strcmp(s
, "message"))
2668 new_use
= HSTATUS_MESSAGE
;
2669 else if (!strcmp(args
[0], "string"))
2674 AddXChars(buf
, sizeof(buf
), hstatusstring
);
2675 Msg(0, "hardstatus string is '%s'", buf
);
2681 Msg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name
);
2686 hardstatusemu
= new_use
| (s
== args
[0] ? 0 : HSTATUS_ALWAYS
);
2687 for (display
= displays
; display
; display
= display
->d_next
)
2690 new_use
= hardstatusemu
& ~HSTATUS_ALWAYS
;
2691 if (D_HS
&& s
== args
[0])
2692 new_use
= HSTATUS_HS
;
2693 ShowHStatus((char *)0);
2694 old_use
= D_has_hstatus
;
2695 D_has_hstatus
= new_use
;
2696 if ((new_use
== HSTATUS_LASTLINE
&& old_use
!= HSTATUS_LASTLINE
) || (new_use
!= HSTATUS_LASTLINE
&& old_use
== HSTATUS_LASTLINE
))
2697 ChangeScreenSize(D_width
, D_height
, 1);
2704 free(hstatusstring
);
2705 hstatusstring
= SaveStr(args
[1]);
2706 for (display
= displays
; display
; display
= display
->d_next
)
2709 display
= olddisplay
;
2712 (void)ParseSwitch(act
, &use_hardstatus
);
2714 Msg(0, "messages displayed on %s", use_hardstatus
? "hardstatus line" : "window");
2717 if (strcmp(args
[0], "always") == 0 || strcmp(args
[0], "splitonly") == 0)
2719 struct display
*olddisplay
= display
;
2721 captionalways
= args
[0][0] == 'a';
2722 for (display
= displays
; display
; display
= display
->d_next
)
2723 ChangeScreenSize(D_width
, D_height
, 1);
2724 display
= olddisplay
;
2726 else if (strcmp(args
[0], "string") == 0)
2731 AddXChars(buf
, sizeof(buf
), captionstring
);
2732 Msg(0, "caption string is '%s'", buf
);
2738 Msg(0, "%s: usage: caption always|splitonly|string <string>", rc_name
);
2744 free(captionstring
);
2745 captionstring
= SaveStr(args
[1]);
2746 RedisplayDisplays(0);
2749 n
= (console_window
!= 0);
2750 if (ParseSwitch(act
, &n
))
2752 if (TtyGrabConsole(fore
->w_ptyfd
, n
, rc_name
))
2755 Msg(0, "%s: releasing console %s", rc_name
, HostName
);
2756 else if (console_window
)
2757 Msg(0, "%s: stealing console %s from window %d (%s)", rc_name
,
2758 HostName
, console_window
->w_number
, console_window
->w_title
);
2760 Msg(0, "%s: grabbing console %s", rc_name
, HostName
);
2761 console_window
= n
? fore
: 0;
2764 if (ParseOnOff(act
, &all_norefresh
))
2766 if (!all_norefresh
&& fore
)
2769 Msg(0, all_norefresh
? "No refresh on window change!\n" :
2770 "Window specific refresh\n");
2773 (void)ParseSwitch(act
, &n
);
2774 fore
->w_norefresh
= n
;
2777 if (ParseSwitch(act
, &visual_bell
) || !msgok
)
2779 if (visual_bell
== 0)
2780 Msg(0, "switched to audible bell.");
2782 Msg(0, "switched to visual bell.");
2785 if (ParseNum1000(act
, &VBellWait
) == 0 && msgok
)
2786 Msg(0, "vbellwait set to %.10g seconds", VBellWait
/1000.);
2789 if (ParseNum1000(act
, &MsgWait
) == 0 && msgok
)
2790 Msg(0, "msgwait set to %.10g seconds", MsgWait
/1000.);
2793 if (ParseNum1000(act
, &MsgMinWait
) == 0 && msgok
)
2794 Msg(0, "msgminwait set to %.10g seconds", MsgMinWait
/1000.);
2796 case RC_SILENCEWAIT
:
2797 if (ParseNum(act
, &SilenceWait
))
2799 if (SilenceWait
< 1)
2801 for (p
= windows
; p
; p
= p
->w_next
)
2802 p
->w_silencewait
= SilenceWait
;
2804 Msg(0, "silencewait set to %d seconds", SilenceWait
);
2808 Msg(0, "This is window %d (%s).\n", fore
->w_number
, fore
->w_title
);
2811 int old
= fore
->w_number
;
2813 if (args
[0][0] == '+')
2815 else if (args
[0][0] == '-')
2819 parse
= ParseNum(act
, &n
);
2828 if (n
< 0 || n
>= maxwin
)
2830 Msg(0, "Given window position is invalid.");
2840 /* exchange the acls for these windows. */
2844 /* exchange the utmp-slots for these windows */
2845 if ((fore
->w_slot
!= (slot_t
) -1) && (fore
->w_slot
!= (slot_t
) 0))
2850 if (p
&& (p
->w_slot
!= (slot_t
) -1) && (p
->w_slot
!= (slot_t
) 0))
2852 /* XXX: first display wins? */
2853 display
= fore
->w_layer
.l_cvlist
? fore
->w_layer
.l_cvlist
->c_display
: 0;
2859 WindowChanged(fore
, 'n');
2860 WindowChanged((struct win
*)0, 'w');
2861 WindowChanged((struct win
*)0, 'W');
2862 WindowChanged((struct win
*)0, 0);
2866 n
= fore
->w_silence
!= 0;
2867 i
= fore
->w_silencewait
;
2868 if (args
[0] && (args
[0][0] == '-' || (args
[0][0] >= '0' && args
[0][0] <= '9')))
2870 if (ParseNum(act
, &i
))
2874 else if (ParseSwitch(act
, &n
))
2879 if (display
) /* we tell only this user */
2880 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2882 for (n
= 0; n
< maxusercount
; n
++)
2883 ACLBYTE(fore
->w_lio_notify
, n
) |= ACLBIT(n
);
2885 fore
->w_silencewait
= i
;
2886 fore
->w_silence
= SILENCE_ON
;
2887 SetTimeout(&fore
->w_silenceev
, fore
->w_silencewait
* 1000);
2888 evenq(&fore
->w_silenceev
);
2892 Msg(0, "The window is now being monitored for %d sec. silence.", fore
->w_silencewait
);
2897 if (display
) /* we remove only this user */
2898 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
)
2899 &= ~ACLBIT(D_user
->u_id
);
2901 for (n
= 0; n
< maxusercount
; n
++)
2902 ACLBYTE(fore
->w_lio_notify
, n
) &= ~ACLBIT(n
);
2903 for (i
= maxusercount
- 1; i
>= 0; i
--)
2904 if (ACLBYTE(fore
->w_lio_notify
, i
))
2909 fore
->w_silence
= SILENCE_OFF
;
2910 evdeq(&fore
->w_silenceev
);
2914 Msg(0, "The window is no longer being monitored for silence.");
2918 case RC_DEFSCROLLBACK
:
2919 (void)ParseNum(act
, &nwin_default
.histheight
);
2922 if (flayer
->l_layfn
== &MarkLf
)
2924 Msg(0, "Cannot resize scrollback buffer in copy/scrollback mode.");
2927 (void)ParseNum(act
, &n
);
2928 ChangeWindowSize(fore
, fore
->w_width
, fore
->w_height
, n
);
2930 Msg(0, "scrollback set to %d", fore
->w_histheight
);
2933 case RC_SESSIONNAME
:
2935 Msg(0, "This session is named '%s'\n", SockName
);
2938 char buf
[MAXPATHLEN
];
2941 if (ParseSaveStr(act
, &s
))
2943 if (!*s
|| strlen(s
) + (SockName
- SockPath
) > MAXPATHLEN
- 13 || index(s
, '/'))
2945 Msg(0, "%s: bad session name '%s'\n", rc_name
, s
);
2949 strncpy(buf
, SockPath
, SockName
- SockPath
);
2950 sprintf(buf
+ (SockName
- SockPath
), "%d.%s", (int)getpid(), s
);
2952 if ((access(buf
, F_OK
) == 0) || (errno
!= ENOENT
))
2954 Msg(0, "%s: inappropriate path: '%s'.", rc_name
, buf
);
2957 if (rename(SockPath
, buf
))
2959 Msg(errno
, "%s: failed to rename(%s, %s)", rc_name
, SockPath
, buf
);
2962 debug2("rename(%s, %s) done\n", SockPath
, buf
);
2963 strcpy(SockPath
, buf
);
2968 if (!args
[0] || !args
[1])
2970 debug1("RC_SETENV arguments missing: %s\n", args
[0] ? args
[0] : "");
2971 InputSetenv(args
[0]);
2975 xsetenv(args
[0], args
[1]);
2984 case RC_DEFSLOWPASTE
:
2985 (void)ParseNum(act
, &nwin_default
.slow
);
2989 Msg(0, fore
->w_slowpaste
?
2990 "Slowpaste in window %d is %d milliseconds." :
2991 "Slowpaste in window %d is unset.",
2992 fore
->w_number
, fore
->w_slowpaste
);
2993 else if (ParseNum(act
, &fore
->w_slowpaste
) == 0 && msgok
)
2994 Msg(0, fore
->w_slowpaste
?
2995 "Slowpaste in window %d set to %d milliseconds." :
2996 "Slowpaste in window %d now unset.",
2997 fore
->w_number
, fore
->w_slowpaste
);
3000 if (CompileKeys(*args
, *argl
, mark_key_tab
))
3002 Msg(0, "%s: markkeys: syntax error.", rc_name
);
3005 debug1("markkeys %s\n", *args
);
3009 if (ParseSwitch(act
, &pastefont
) == 0 && msgok
)
3010 Msg(0, "Will %spaste font settings", pastefont
? "" : "not ");
3014 (void)ParseSwitch(act
, &join_with_cr
);
3016 case RC_COMPACTHIST
:
3017 if (ParseSwitch(act
, &compacthist
) == 0 && msgok
)
3018 Msg(0, "%scompacting history lines", compacthist
? "" : "not ");
3023 (void)ParseOnOff(act
, &nethackflag
);
3026 case RC_HARDCOPY_APPEND
:
3027 (void)ParseOnOff(act
, &hardcopy_append
);
3033 AddXChars(buf
, sizeof(buf
), VisualBellString
);
3034 Msg(0, "vbell_msg is '%s'", buf
);
3037 (void)ParseSaveStr(act
, &VisualBellString
);
3038 debug1(" new vbellstr '%s'\n", VisualBellString
);
3041 if (ParseBase(act
, *args
, &n
, 8, "octal"))
3043 if (n
< 0 || n
> 0777)
3045 Msg(0, "%s: mode: Invalid tty mode %o", rc_name
, n
);
3050 Msg(0, "Ttymode set to %03o", TtyMode
);
3053 (void)ParseOnOff(act
, &auto_detach
);
3055 case RC_STARTUP_MESSAGE
:
3056 (void)ParseOnOff(act
, &default_startup
);
3062 n
= (*user
->u_password
) ? 1 : 0;
3063 if (user
->u_password
!= NullStr
) free((char *)user
->u_password
);
3064 user
->u_password
= SaveStr(*args
);
3065 if (!strcmp(user
->u_password
, "none"))
3068 Msg(0, "Password checking disabled");
3069 free(user
->u_password
);
3070 user
->u_password
= NullStr
;
3077 Msg(0, "%s: password: window required", rc_name
);
3080 Input("New screen password:", 100, INP_NOECHO
, pass1
, display
? (char *)D_user
: (char *)users
, 0);
3083 #endif /* PASSWORD */
3086 struct action
*ktabp
= ktab
;
3091 if (argc
> 2 && !strcmp(*args
, "-c"))
3093 ktabp
= FindKtab(args
[1], 1);
3100 else if (argc
> 1 && !strcmp(*args
, "-k"))
3113 for (n
= 0; n
< KMAP_KEYS
; n
++)
3114 if (strcmp(term
[n
+ T_CAPS
].tcname
, *args
) == 0)
3118 Msg(0, "%s: bind: unknown key '%s'", rc_name
, *args
);
3127 Msg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name
);
3131 n
= (unsigned char)args
[0][0];
3135 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3137 Msg(0, "%s: bind: unknown command '%s'", rc_name
, args
[1]);
3140 if (CheckArgNum(i
, args
+ 2) < 0)
3142 ClearAction(&ktabp
[n
]);
3143 SaveAction(ktabp
+ n
, i
, args
+ 2, argl
+ 2);
3146 ClearAction(&ktabp
[n
]);
3152 struct action
*newact
;
3153 int newnr
, fl
= 0, kf
= 0, af
= 0, df
= 0, mf
= 0;
3154 struct display
*odisp
= display
;
3156 struct kmap_ext
*kme
;
3158 for (; *args
&& **args
== '-'; args
++, argl
++)
3160 if (strcmp(*args
, "-t") == 0)
3161 fl
= KMAP_NOTIMEOUT
;
3162 else if (strcmp(*args
, "-k") == 0)
3164 else if (strcmp(*args
, "-a") == 0)
3166 else if (strcmp(*args
, "-d") == 0)
3168 else if (strcmp(*args
, "-m") == 0)
3170 else if (strcmp(*args
, "--") == 0)
3178 Msg(0, "%s: bindkey: invalid option %s", rc_name
, *args
);
3184 Msg(0, "%s: bindkey: -d does not work with -m", rc_name
);
3190 display_bindkey("Edit mode", mmtab
);
3192 display_bindkey("Default", dmtab
);
3194 display_bindkey("User", umtab
);
3201 Msg(0, "%s: bindkey: -a only works with -k", rc_name
);
3206 Msg(0, "%s: bindkey: empty string makes no sense", rc_name
);
3209 for (i
= 0, kme
= kmap_exts
; i
< kmap_extn
; i
++, kme
++)
3216 if (*argl
== (kme
->fl
& ~KMAP_NOTIMEOUT
) && bcmp(kme
->str
, *args
, *argl
) == 0)
3222 Msg(0, "%s: bindkey: keybinding not found", rc_name
);
3226 kmap_exts
= (struct kmap_ext
*)xrealloc((char *)kmap_exts
, kmap_extn
* sizeof(*kmap_exts
));
3227 kme
= kmap_exts
+ i
;
3228 bzero((char *)kme
, 8 * sizeof(*kmap_exts
));
3229 for (; i
< kmap_extn
; i
++, kme
++)
3232 kme
->dm
.nr
= kme
->mm
.nr
= kme
->um
.nr
= RC_ILLEGAL
;
3233 kme
->dm
.args
= kme
->mm
.args
= kme
->um
.args
= noargs
;
3238 if (df
== 0 && kme
->dm
.nr
!= RC_ILLEGAL
)
3240 if (mf
== 0 && kme
->mm
.nr
!= RC_ILLEGAL
)
3242 if ((df
|| mf
) && kme
->um
.nr
!= RC_ILLEGAL
)
3244 i
+= KMAP_KEYS
+ KMAP_AKEYS
;
3245 newact
= df
? &kme
->dm
: mf
? &kme
->mm
: &kme
->um
;
3249 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
3250 if (strcmp(term
[i
].tcname
, *args
) == 0)
3254 Msg(0, "%s: bindkey: unknown key '%s'", rc_name
, *args
);
3257 if (af
&& i
>= T_CURSOR
&& i
< T_OCAPS
)
3258 i
-= T_CURSOR
- KMAP_KEYS
;
3261 newact
= df
? &dmtab
[i
] : mf
? &mmtab
[i
] : &umtab
[i
];
3265 if ((newnr
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3267 Msg(0, "%s: bindkey: unknown command '%s'", rc_name
, args
[1]);
3270 if (CheckArgNum(newnr
, args
+ 2) < 0)
3272 ClearAction(newact
);
3273 SaveAction(newact
, newnr
, args
+ 2, argl
+ 2);
3274 if (kf
== 0 && args
[1])
3278 kme
->str
= SaveStrn(*args
, *argl
);
3279 kme
->fl
= fl
| *argl
;
3283 ClearAction(newact
);
3284 for (display
= displays
; display
; display
= display
->d_next
)
3285 remap(i
, args
[1] ? 1 : 0);
3286 if (kf
== 0 && !args
[1])
3288 if (!used
&& kme
->str
)
3301 if (ParseNum(act
, &n
))
3305 Msg(0, "%s: maptimeout: illegal time %d", rc_name
, n
);
3310 if (*args
== 0 || msgok
)
3311 Msg(0, "maptimeout is %dms", maptimeout
);
3325 UsersAcl(NULL
, argc
, args
);
3328 if (UserDel(args
[0], NULL
))
3331 Msg(0, "%s removed from acl database", args
[0]);
3335 * modify a user to gain or lose rights granted to a group.
3336 * This group is actually a normal user whose rights were defined
3337 * with chacl in the usual way.
3341 if (strcmp(args
[1], "none")) /* link a user to another user */
3343 if (AclLinkUser(args
[0], args
[1]))
3346 Msg(0, "User %s joined acl-group %s", args
[0], args
[1]);
3348 else /* remove all groups from user */
3351 struct aclusergroup
*g
;
3353 if (!(u
= *FindUserPtr(args
[0])))
3355 while ((g
= u
->u_group
))
3357 u
->u_group
= g
->next
;
3362 else /* show all groups of user */
3364 char buf
[256], *p
= buf
;
3367 struct aclusergroup
*g
;
3369 if (!(u
= *FindUserPtr(args
[0])))
3372 Msg(0, "User %s does not exist.", args
[0]);
3379 sprintf(p
, "%s ", g
->u
->u_name
);
3387 Msg(0, "%s's group%s: %s.", args
[0], (ngroups
== 1) ? "" : "s",
3388 (ngroups
== 0) ? "none" : buf
);
3393 while ((s
= *args
++))
3397 if (AclUmask(display
? D_user
: users
, s
, &err
))
3398 Msg(0, "umask: %s\n", err
);
3402 if (ParseOnOff(act
, &n
))
3407 Msg(0, "Multiuser mode %s", multi
? "enabled" : "disabled");
3409 #endif /* MULTIUSER */
3417 i
= D_nonblock
>= 0;
3418 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3420 if (ParseNum1000(act
, &i
))
3423 else if (!ParseSwitch(act
, &i
))
3424 i
= i
== 0 ? -1 : 1000;
3427 if (msgok
&& i
== -1)
3428 Msg(0, "display set to blocking mode");
3429 else if (msgok
&& i
== 0)
3430 Msg(0, "display set to nonblocking mode, no timeout");
3432 Msg(0, "display set to nonblocking mode, %.10gs timeout", i
/1000.);
3434 if (D_nonblock
<= 0)
3435 evdeq(&D_blockedev
);
3437 case RC_DEFNONBLOCK
:
3438 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3440 if (ParseNum1000(act
, &defnonblock
))
3443 else if (!ParseOnOff(act
, &defnonblock
))
3444 defnonblock
= defnonblock
== 0 ? -1 : 1000;
3447 if (display
&& *rc_name
)
3449 D_nonblock
= defnonblock
;
3450 if (D_nonblock
<= 0)
3451 evdeq(&D_blockedev
);
3457 if (fore
->w_gr
== 2)
3460 if (ParseSwitch(act
, &fore
->w_gr
) == 0 && msgok
)
3461 Msg(0, "Will %suse GR", fore
->w_gr
? "" : "not ");
3463 if (fore
->w_gr
== 0 && fore
->w_FontE
)
3468 if (ParseSwitch(act
, &fore
->w_c1
) == 0 && msgok
)
3469 Msg(0, "Will %suse C1", fore
->w_c1
? "" : "not ");
3473 if (ParseSwitch(act
, &fore
->w_bce
) == 0 && msgok
)
3474 Msg(0, "Will %serase with background color", fore
->w_bce
? "" : "not ");
3481 if (*args
&& !strcmp(args
[0], "-d"))
3484 Msg(0, "encodings directory is %s", screenencodings
? screenencodings
: "<unset>");
3487 free(screenencodings
);
3488 screenencodings
= SaveStr(args
[1]);
3492 if (*args
&& !strcmp(args
[0], "-l"))
3495 Msg(0, "encoding: -l: argument required");
3496 else if (LoadFontTranslation(-1, args
[1]))
3497 Msg(0, "encoding: could not load utf8 encoding file");
3499 Msg(0, "encoding: utf8 encoding file loaded");
3503 if (*args
&& (!strcmp(args
[0], "-l") || !strcmp(args
[0], "-d")))
3506 Msg(0, "encoding: screen is not compiled for UTF-8.");
3510 for (i
= 0; i
< 2; i
++)
3514 if (!strcmp(args
[i
], "."))
3516 n
= FindEncoding(args
[i
]);
3519 Msg(0, "encoding: unknown encoding '%s'", args
[i
]);
3524 WinSwitchEncoding(fore
, n
);
3525 ResetCharsets(fore
);
3527 else if (i
&& display
)
3532 case RC_DEFENCODING
:
3533 n
= FindEncoding(*args
);
3536 Msg(0, "defencoding: unknown encoding '%s'", *args
);
3539 nwin_default
.encoding
= n
;
3545 n
= nwin_default
.encoding
== UTF8
;
3546 if (ParseSwitch(act
, &n
) == 0)
3548 nwin_default
.encoding
= n
? UTF8
: 0;
3550 Msg(0, "Will %suse UTF-8 encoding for new windows", n
? "" : "not ");
3554 for (i
= 0; i
< 2; i
++)
3556 if (i
&& args
[i
] == 0)
3559 n
= fore
->w_encoding
!= UTF8
;
3560 else if (strcmp(args
[i
], "off") == 0)
3562 else if (strcmp(args
[i
], "on") == 0)
3566 Msg(0, "utf8: illegal argument (%s)", args
[i
]);
3571 WinSwitchEncoding(fore
, n
? UTF8
: 0);
3573 Msg(0, "Will %suse UTF-8 encoding", n
? "" : "not ");
3576 D_encoding
= n
? UTF8
: 0;
3590 printcmd
= SaveStr(*args
);
3592 if (*args
== 0 || msgok
)
3595 Msg(0, "using '%s' as print command", printcmd
);
3597 Msg(0, "using termcap entries for printing");
3603 Input("Enter digraph: ", 10, INP_EVERY
, digraph_fn
, NULL
, 0);
3604 if (*args
&& **args
)
3617 if (nwin_default
.hstatus
)
3618 AddXChars(buf
, sizeof(buf
), nwin_default
.hstatus
);
3619 Msg(0, "default hstatus is '%s'", buf
);
3622 (void)ParseSaveStr(act
, &nwin_default
.hstatus
);
3623 if (*nwin_default
.hstatus
== 0)
3625 free(nwin_default
.hstatus
);
3626 nwin_default
.hstatus
= 0;
3630 (void)ParseSaveStr(act
, &fore
->w_hstatus
);
3631 if (*fore
->w_hstatus
== 0)
3633 free(fore
->w_hstatus
);
3634 fore
->w_hstatus
= 0;
3636 WindowChanged(fore
, 'h');
3646 if (nwin_default
.charset
)
3647 AddXChars(buf
, sizeof(buf
), nwin_default
.charset
);
3648 Msg(0, "default charset is '%s'", buf
);
3652 if (n
== 0 || n
> 6)
3654 Msg(0, "%s: %s: string has illegal size.", rc_name
, comms
[nr
].name
);
3658 ((args
[0][4] < '0' || args
[0][4] > '3') && args
[0][4] != '.') ||
3659 ((args
[0][5] < '0' || args
[0][5] > '3') && args
[0][5] && args
[0][5] != '.')))
3661 Msg(0, "%s: %s: illegal mapping number.", rc_name
, comms
[nr
].name
);
3664 if (nr
== RC_CHARSET
)
3666 SetCharsets(fore
, *args
);
3669 if (nwin_default
.charset
)
3670 free(nwin_default
.charset
);
3671 nwin_default
.charset
= SaveStr(*args
);
3677 if (*s
>= '0' && *s
<= '9')
3680 for (i
= 0; i
< 8; i
++)
3681 if (*s
== "dubrsBiI"[i
])
3685 if (*s
&& s
[1] && !s
[2])
3687 if (*s
== 'd' && s
[1] == 'd')
3689 else if (*s
== '.' && s
[1] == 'd')
3691 else if (*s
== 'd' && s
[1] == '.')
3693 else if (*s
!= '.' || s
[1] != '.')
3697 if (*s
|| i
< 0 || i
>= 8)
3699 Msg(0, "%s: attrcolor: unknown attribute '%s'.", rc_name
, args
[0]);
3704 n
= ParseAttrColor(args
[1], args
[2], 1);
3707 attr2color
[i
][nr
] = n
;
3709 for (i
= 0; i
< 8; i
++)
3710 if (attr2color
[i
][0] || attr2color
[i
][1] || attr2color
[i
][2] || attr2color
[i
][3])
3715 case RC_SORENDITION
:
3719 i
= ParseAttrColor(*args
, args
[1], 1);
3722 ApplyAttrColor(i
, &mchar_so
);
3723 debug2("--> %x %x\n", mchar_so
.attr
, mchar_so
.color
);
3727 Msg(0, "Standout attributes 0x%02x color 0x%02x", (unsigned char)mchar_so
.attr
, 0x99 ^ (unsigned char)mchar_so
.color
);
3729 Msg(0, "Standout attributes 0x%02x ", (unsigned char)mchar_so
.attr
);
3742 Msg(0, "%s:%s screen login", HostName
, SockPath
);
3743 InputSu(D_fore
, &D_user
, NULL
);
3746 InputSu(D_fore
, &D_user
, args
[0]);
3748 s
= DoSu(&D_user
, args
[0], args
[1], "\377");
3750 s
= DoSu(&D_user
, args
[0], args
[1], args
[2]);
3754 #endif /* MULTIUSER */
3757 if (s
&& !strcmp(s
, "-v"))
3758 AddCanvas(SLICE_HORI
);
3760 AddCanvas(SLICE_VERT
);
3772 D_forecv
->c_xoff
= D_forecv
->c_xs
;
3773 D_forecv
->c_yoff
= D_forecv
->c_ys
;
3774 RethinkViewportOffsets(D_forecv
);
3775 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
3776 flayer
= D_forecv
->c_layer
;
3780 if (!*args
|| !strcmp(*args
, "down"))
3781 D_forecv
= D_forecv
->c_next
? D_forecv
->c_next
: D_cvlist
;
3782 else if (!strcmp(*args
, "up"))
3785 for (cv
= D_cvlist
; cv
->c_next
&& cv
->c_next
!= D_forecv
; cv
= cv
->c_next
)
3789 else if (!strcmp(*args
, "top"))
3790 D_forecv
= D_cvlist
;
3791 else if (!strcmp(*args
, "bottom"))
3794 for (cv
= D_cvlist
; cv
->c_next
; cv
= cv
->c_next
)
3800 Msg(0, "%s: usage: focus [up|down|top|bottom]", rc_name
);
3803 if ((focusminwidth
&& (focusminwidth
< 0 || D_forecv
->c_xe
- D_forecv
->c_xs
+ 1 < focusminwidth
)) ||
3804 (focusminheight
&& (focusminheight
< 0 || D_forecv
->c_ye
- D_forecv
->c_ys
+ 1 < focusminheight
)))
3806 ResizeCanvas(&D_canvas
);
3807 RecreateCanvasChain();
3808 RethinkDisplayViewports();
3809 ResizeLayersToCanvases(); /* redisplays */
3811 fore
= D_fore
= Layer2Window(D_forecv
->c_layer
);
3812 flayer
= D_forecv
->c_layer
;
3814 if (D_xtermosc
[2] || D_xtermosc
[3])
3824 flayer
= D_forecv
->c_layer
;
3825 CV_CALL(D_forecv
, LayRestore();LaySetCursor());
3826 WindowChanged(0, 'F');
3830 if (D_forecv
->c_slorient
== SLICE_UNKN
)
3832 Msg(0, "resize: need more than one region");
3835 for (; *args
; args
++)
3837 if (!strcmp(*args
, "-h"))
3839 else if (!strcmp(*args
, "-v"))
3841 else if (!strcmp(*args
, "-b"))
3842 i
|= RESIZE_FLAG_H
| RESIZE_FLAG_V
;
3843 else if (!strcmp(*args
, "-p"))
3844 i
|= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
3845 else if (!strcmp(*args
, "-l"))
3850 if (*args
&& args
[1])
3852 Msg(0, "%s: usage: resize [-h] [-v] [-l] [num]\n", rc_name
);
3856 ResizeRegions(*args
, i
);
3858 Input(resizeprompts
[i
], 20, INP_EVERY
, ResizeFin
, (char*)0, i
);
3861 (void)ParseSwitch(act
, &separate_sids
);
3864 args
= SaveArgs(args
);
3865 for (i
= 0; args
[i
]; i
++)
3868 Colonfin(args
[i
], strlen(args
[i
]), (char *)0);
3874 (void)ParseSwitch(act
, &use_altscreen
);
3876 Msg(0, "Will %sdo alternate screen switching", use_altscreen
? "" : "not ");
3879 if (ParseNum(act
, &n
))
3882 Msg(0, "illegal maxwin number specified");
3883 else if (n
> maxwin
)
3884 Msg(0, "may only decrease maxwin number");
3889 if (ParseBase(act
, *args
, &n
, 10, "decimal"))
3892 setbacktick(n
, 0, 0, (char **)0);
3898 Msg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name
);
3901 if (ParseBase(act
, args
[1], &lifespan
, 10, "decimal"))
3903 if (ParseBase(act
, args
[2], &tick
, 10, "decimal"))
3905 setbacktick(n
, lifespan
, tick
, SaveArgs(args
+ 3));
3907 WindowChanged(0, '`');
3913 RunBlanker(blankerprg
);
3918 CursorVisibility(-1);
3926 for (pp
= blankerprg
; *pp
; pp
++)
3932 blankerprg
= SaveArgs(args
);
3938 struct display
*olddisplay
= display
;
3939 if (!strcmp(*args
, "off"))
3941 else if (args
[0][0])
3942 idletimo
= atoi(*args
) * 1000;
3945 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3947 Msg(0, "%s: idle: unknown command '%s'", rc_name
, args
[1]);
3950 if (CheckArgNum(i
, args
+ 2) < 0)
3952 ClearAction(&idleaction
);
3953 SaveAction(&idleaction
, i
, args
+ 2, argl
+ 2);
3955 for (display
= displays
; display
; display
= display
->d_next
)
3957 display
= olddisplay
;
3962 Msg(0, "idle timeout %ds, %s", idletimo
/ 1000, comms
[idleaction
.nr
].name
);
3967 case RC_FOCUSMINSIZE
:
3968 for (i
= 0; i
< 2 && args
[i
]; i
++)
3970 if (!strcmp(args
[i
], "max") || !strcmp(args
[i
], "_"))
3982 for (i
= 0; i
< 2; i
++)
3984 n
= i
== 0 ? focusminwidth
: focusminheight
;
3986 strcpy(b
[i
], "max");
3988 sprintf(b
[i
], "%d", n
);
3990 Msg(0, "focus min size is %s %s\n", b
[0], b
[1]);
3999 fore
->w_group
= WindowByName(*args
);
4000 if (fore
->w_group
&& fore
->w_group
->w_type
!= W_TYPE_GROUP
)
4003 WindowChanged((struct win
*)0, 'w');
4004 WindowChanged((struct win
*)0, 'W');
4005 WindowChanged((struct win
*)0, 0);
4010 Msg(0, "window group is %d (%s)\n", fore
->w_group
->w_number
, fore
->w_group
->w_title
);
4012 Msg(0, "window belongs to no group");
4016 if (!strcmp(args
[0], "title"))
4020 Msg(0, "not on a layout");
4025 Msg(0, "current layout is %d (%s)", D_layout
->lay_number
, D_layout
->lay_title
);
4028 free(D_layout
->lay_title
);
4029 D_layout
->lay_title
= SaveStr(args
[1]);
4031 else if (!strcmp(args
[0], "number"))
4037 Msg(0, "This is layout %d (%s).\n", D_layout
->lay_number
, D_layout
->lay_title
);
4040 old
= D_layout
->lay_number
;
4042 if (n
< 0 || n
>= MAXLAY
)
4045 laytab
[n
] = D_layout
;
4046 D_layout
->lay_number
= n
;
4049 lay
->lay_number
= old
;
4052 else if (!strcmp(args
[0], "autosave"))
4056 Msg(0, "not on a layout");
4061 if (!strcmp(args
[1], "on"))
4062 D_layout
->lay_autosave
= 1;
4063 else if (!strcmp(args
[1], "off"))
4064 D_layout
->lay_autosave
= 0;
4067 Msg(0, "invalid argument. Give 'on' or 'off");
4072 Msg(0, "autosave is %s", D_layout
->lay_autosave
? "on" : "off");
4074 else if (!strcmp(args
[0], "new"))
4080 while (*t
>= '0' && *t
<= '9')
4082 if (t
!= args
[1] && (!*t
|| *t
== ':'))
4096 else if (!strcmp(args
[0], "save"))
4100 Msg(0, "usage: layout save <name>");
4103 SaveLayout(args
[1], &D_canvas
);
4105 else if (!strcmp(args
[0], "select"))
4110 Input("Switch to layout: ", 20, INP_COOKED
, SelectLayoutFin
, NULL
, 0);
4113 SelectLayoutFin(args
[1], strlen(args
[1]), (char *)0);
4115 else if (!strcmp(args
[0], "next"))
4117 struct layout
*lay
= D_layout
;
4119 lay
= lay
->lay_next
? lay
->lay_next
: layouts
;
4124 Msg(0, "no layout defined");
4127 if (lay
== D_layout
)
4129 LoadLayout(lay
, &D_canvas
);
4132 else if (!strcmp(args
[0], "prev"))
4134 struct layout
*lay
= D_layout
;
4137 for (lay
= layouts
; lay
->lay_next
&& lay
->lay_next
!= D_layout
; lay
= lay
->lay_next
)
4144 Msg(0, "no layout defined");
4147 if (lay
== D_layout
)
4149 LoadLayout(lay
, &D_canvas
);
4152 else if (!strcmp(args
[0], "attach"))
4157 Msg(0, "no attach layout set");
4158 else if (layout_attach
== &layout_last_marker
)
4159 Msg(0, "will attach to last layout");
4161 Msg(0, "will attach to layout %d (%s)", layout_attach
->lay_number
, layout_attach
->lay_title
);
4164 if (!strcmp(args
[1], ":last"))
4165 layout_attach
= &layout_last_marker
;
4166 else if (!args
[1][0])
4171 lay
= FindLayout(args
[1]);
4174 Msg(0, "unknown layout '%s'", args
[1]);
4177 layout_attach
= lay
;
4180 else if (!strcmp(args
[0], "show"))
4185 Msg(0, "unknown layout subcommand");
4189 if(ParseSwitch(act
, &cjkwidth
) == 0)
4192 Msg(0, "Treat ambiguous width characters as %s width", cjkwidth
? "full" : "half");
4198 /* key == -2: input from braille keybord, msgok always 0 */
4199 DoBrailleAction(act
, key
== -2 ? 0 : msgok
);
4203 if (display
!= odisplay
)
4205 for (display
= displays
; display
; display
= display
->d_next
)
4206 if (display
== odisplay
)
4212 DoCommand(argv
, argl
)
4218 if ((act
.nr
= FindCommnr(*argv
)) == RC_ILLEGAL
)
4220 Msg(0, "%s: unknown command '%s'", rc_name
, *argv
);
4223 act
.args
= argv
+ 1;
4224 act
.argl
= argl
+ 1;
4229 SaveAction(act
, nr
, args
, argl
)
4235 register int argc
= 0;
4249 if ((pp
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4251 if ((lp
= (int *)malloc((unsigned)(argc
) * sizeof(int *))) == 0)
4258 *lp
= argl
? *argl
++ : (int)strlen(*args
);
4259 *pp
++ = SaveStrn(*args
++, *lp
++);
4268 register char **ap
, **pp
;
4269 register int argc
= 0;
4273 if ((pp
= ap
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4276 *pp
++ = SaveStr(*args
++);
4283 * buf is split into argument vector args.
4284 * leading whitespace is removed.
4285 * @!| abbreviations are expanded.
4286 * the end of buffer is recognized by '\0' or an un-escaped '#'.
4287 * " and ' are interpreted.
4292 Parse(buf
, bufl
, args
, argl
)
4296 register char *p
= buf
, **ap
= args
, *pp
;
4297 register int delim
, argc
;
4300 debug2("Parse %d %s\n", bufl
, buf
);
4306 while (*p
&& (*p
== ' ' || *p
== '\t'))
4309 if (argc
== 0 && *p
== '!')
4318 if (*p
== '\0' || *p
== '#' || *p
== '\n')
4321 for (delim
= 0; delim
< argc
; delim
++)
4322 debug1("-- %s\n", args
[delim
]);
4326 if (++argc
>= MAXARGS
)
4328 Msg(0, "%s: too many tokens.", rc_name
);
4333 debug1("- new arg %s\n", p
);
4338 else if (delim
!= '\'' && *p
== '\\' && (p
[1] == '\'' || p
[1] == '"' || p
[1] == '\\' || p
[1] == '$' || p
[1] == '#' || p
[1] == '^' || (p
[1] >= '0' && p
[1] <= '7')))
4341 if (*p
>= '0' && *p
<= '7')
4344 if (p
[1] >= '0' && p
[1] <= '7')
4347 *pp
= (*pp
<< 3) | (*p
- '0');
4348 if (p
[1] >= '0' && p
[1] <= '7')
4351 *pp
= (*pp
<< 3) | (*p
- '0');
4359 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] == '_'))
4362 char *ps
, *pe
, op
, *v
, xbuf
[11];
4366 debug1("- var %s\n", ps
);
4370 if (*ps
== '{' && *p
== '}')
4372 if (*ps
== ':' && *p
== ':')
4374 if (*ps
!= '{' && *ps
!= ':' && (*p
< 'a' || *p
> 'z') && (*p
< 'A' || *p
> 'Z') && (*p
< '0' || *p
> '9') && *p
!= '_')
4379 if (*ps
== '{' || *ps
== ':')
4383 Msg(0, "%s: bad variable name.", rc_name
);
4390 debug1("- var is '%s'\n", ps
);
4392 v
= gettermcapstring(ps
+ 1);
4398 if (!strcmp(ps
, "TERM"))
4399 v
= display
? D_termname
: "unknown";
4400 else if (!strcmp(ps
, "COLUMNS"))
4401 sprintf(xbuf
, "%d", display
? D_width
: -1);
4402 else if (!strcmp(ps
, "LINES"))
4403 sprintf(xbuf
, "%d", display
? D_height
: -1);
4408 vl
= v
? strlen(v
) : 0;
4411 debug1("- sub is '%s'\n", v
);
4414 int right
= buf
+ bufl
- (p
+ strlen(p
) + 1);
4417 bcopy(p
, p
+ right
, strlen(p
) + 1);
4423 Msg(0, "%s: no space left for variable expansion.", rc_name
);
4431 else if (delim
!= '\'' && *p
== '^' && p
[1])
4434 *pp
++ = *p
== '?' ? '\177' : *p
& 0x1f;
4436 else if (delim
== 0 && (*p
== '\'' || *p
== '"'))
4438 else if (delim
== 0 && (*p
== ' ' || *p
== '\t' || *p
== '\n'))
4446 Msg(0, "%s: Missing %c quote.", rc_name
, delim
);
4452 debug2("- arg done, '%s' rest %s\n", ap
[-1], p
);
4453 *lp
++ = pp
- ap
[-1];
4472 if (DefaultEsc
>= 0)
4473 ClearAction(&ktab
[DefaultEsc
]);
4474 if (DefaultMetaEsc
>= 0)
4475 ClearAction(&ktab
[DefaultMetaEsc
]);
4478 DefaultMetaEsc
= me
;
4481 if (DefaultEsc
>= 0)
4483 ClearAction(&ktab
[DefaultEsc
]);
4484 ktab
[DefaultEsc
].nr
= RC_OTHER
;
4486 if (DefaultMetaEsc
>= 0)
4488 ClearAction(&ktab
[DefaultMetaEsc
]);
4489 ktab
[DefaultMetaEsc
].nr
= RC_META
;
4496 ParseSwitch(act
, var
)
4500 if (*act
->args
== 0)
4505 return ParseOnOff(act
, var
);
4509 ParseOnOff(act
, var
)
4513 register int num
= -1;
4514 char **args
= act
->args
;
4518 if (strcmp(args
[0], "on") == 0)
4520 else if (strcmp(args
[0], "off") == 0)
4525 Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name
, comms
[act
->nr
].name
);
4533 ParseSaveStr(act
, var
)
4537 char **args
= act
->args
;
4538 if (*args
== 0 || args
[1])
4540 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4545 *var
= SaveStr(*args
);
4555 char *p
, **args
= act
->args
;
4558 if (p
== 0 || *p
== 0 || args
[1])
4560 Msg(0, "%s: %s: invalid argument. Give one argument.",
4561 rc_name
, comms
[act
->nr
].name
);
4567 if (*p
>= '0' && *p
<= '9')
4568 i
= 10 * i
+ (*p
- '0');
4571 Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4572 rc_name
, comms
[act
->nr
].name
);
4577 debug1("ParseNum got %d\n", i
);
4583 ParseNum1000(act
, var
)
4588 char *p
, **args
= act
->args
;
4592 if (p
== 0 || *p
== 0 || args
[1])
4594 Msg(0, "%s: %s: invalid argument. Give one argument.",
4595 rc_name
, comms
[act
->nr
].name
);
4601 if (*p
>= '0' && *p
<= '9')
4604 i
= 10 * i
+ (*p
- '0');
4605 else if (dig
== 4 && *p
>= '5')
4610 else if (*p
== '.' && !dig
)
4614 Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4615 rc_name
, comms
[act
->nr
].name
);
4626 i
= (int)((unsigned int)~0 >> 1);
4627 debug1("ParseNum1000 got %d\n", i
);
4638 for (p
= windows
; p
; p
= p
->w_next
)
4639 if (!strcmp(p
->w_title
, s
))
4641 for (p
= windows
; p
; p
= p
->w_next
)
4642 if (!strncmp(p
->w_title
, s
, strlen(s
)))
4654 for (i
= 0, s
= str
; *s
; s
++)
4656 if (*s
< '0' || *s
> '9')
4658 i
= i
* 10 + (*s
- '0');
4664 * Get window number from Name or Number string.
4665 * Numbers are tried first, then names, a prefix match suffices.
4666 * Be careful when assigning numeric strings as WindowTitles.
4675 if ((i
= WindowByNumber(str
)) < 0 || i
>= MAXWIN
)
4677 if ((p
= WindowByName(str
)))
4685 ParseWinNum(act
, var
)
4689 char **args
= act
->args
;
4692 if (*args
== 0 || args
[1])
4694 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4698 i
= WindowByNoN(*args
);
4701 Msg(0, "%s: %s: invalid argument. Give window number or name.",
4702 rc_name
, comms
[act
->nr
].name
);
4705 debug1("ParseWinNum got %d\n", i
);
4711 ParseBase(act
, p
, var
, base
, bname
)
4723 Msg(0, "%s: %s: empty argument.", rc_name
, comms
[act
->nr
].name
);
4728 if (c
>= 'a' && c
<= 'z')
4730 if (c
>= 'A' && c
<= 'Z')
4731 c
-= 'A' - ('0' + 10);
4733 if (c
< 0 || c
>= base
)
4735 Msg(0, "%s: %s: argument is not %s.", rc_name
, comms
[act
->nr
].name
, bname
);
4740 debug1("ParseBase got %d\n", i
);
4750 for (base
+= '0'; *s
; ++s
)
4751 if (*s
< '0' || *s
> base
)
4757 IsNumColon(s
, base
, p
, psize
)
4762 if ((q
= rindex(s
, ':')) != 0)
4764 strncpy(p
, q
+ 1, psize
- 1);
4765 p
[psize
- 1] = '\0';
4770 return IsNum(s
, base
);
4779 debug1("SwitchWindow %d\n", n
);
4780 if (n
< 0 || n
>= MAXWIN
)
4785 if ((p
= wtab
[n
]) == 0)
4797 Msg(0, "This IS window %d (%s).", n
, p
->w_title
);
4801 if (AclCheckPermWin(D_user
, ACL_READ
, p
))
4803 Msg(0, "Access to window %d denied.", p
->w_number
);
4808 Activate(fore
->w_norefresh
);
4813 SetCanvasWindow(cv
, wi
)
4817 struct win
*p
= 0, **pp
;
4819 struct canvas
*cvp
, **cvpp
;
4822 display
= cv
->c_display
;
4826 /* remove old layer */
4827 for (cvpp
= &l
->l_cvlist
; (cvp
= *cvpp
); cvpp
= &cvp
->c_lnext
)
4831 *cvpp
= cvp
->c_lnext
;
4833 p
= Layer2Window(l
);
4837 if (p
&& cv
== D_forecv
)
4840 ReleaseAutoWritelock(display
, p
);
4844 SetTimeout(&p
->w_silenceev
, p
->w_silencewait
* 1000);
4845 evenq(&p
->w_silenceev
);
4850 if (l
->l_cvlist
== 0 && (p
== 0 || l
!= p
->w_savelayer
))
4854 /* find right layer to display on canvas */
4855 if (wi
&& wi
->w_type
!= W_TYPE_GROUP
)
4858 if (wi
->w_savelayer
&& (wi
->w_blocked
|| wi
->w_savelayer
->l_cvlist
== 0))
4859 l
= wi
->w_savelayer
;
4865 l
->l_data
= (char *)wi
;
4870 /* add our canvas to the layer's canvaslist */
4871 ASSERT(l
->l_cvlist
!= cv
);
4872 cv
->c_lnext
= l
->l_cvlist
;
4875 cv
->c_xoff
= cv
->c_xs
;
4876 cv
->c_yoff
= cv
->c_ys
;
4877 RethinkViewportOffsets(cv
);
4882 if (wi
&& wi
->w_type
== W_TYPE_GROUP
)
4884 /* auto-start windowlist on groups */
4885 struct display
*d
= display
;
4886 struct layer
*oldflayer
= flayer
;
4888 display_wlist(0, 0, wi
);
4893 if (wi
&& D_other
== wi
)
4894 D_other
= wi
->w_next
; /* Might be 0, but that's OK. */
4898 fore
= D_fore
; /* XXX ? */
4902 ObtainAutoWritelock(display
, wi
);
4905 * Place the window at the head of the most-recently-used list
4909 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
4914 p
->w_next
= windows
;
4924 * SetForeWindow changes the window in the input focus of the display.
4925 * Puts window wi in canvas display->d_forecv.
4937 p
= Layer2Window(D_forecv
->c_layer
);
4938 SetCanvasWindow(D_forecv
, wi
);
4940 WindowChanged(p
, 'u');
4942 WindowChanged(wi
, 'u');
4943 flayer
= D_forecv
->c_layer
;
4944 /* Activate called afterwards, so no RefreshHStatus needed */
4948 /*****************************************************************/
4951 * Activate - make fore window active
4952 * norefresh = -1 forces a refresh, disregard all_norefresh then.
4958 debug1("Activate(%d)\n", norefresh
);
4963 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
4967 if (MayResizeLayer(D_forecv
->c_layer
))
4968 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, display
);
4974 if (fore
->w_monitor
!= MON_OFF
)
4975 fore
->w_monitor
= MON_ON
;
4976 fore
->w_bell
= BELL_ON
;
4977 WindowChanged(fore
, 'f');
4980 if (ResizeDisplay(fore
->w_width
, fore
->w_height
))
4982 debug2("Cannot resize from (%d,%d)", D_width
, D_height
);
4983 debug2(" to (%d,%d) -> resize window\n", fore
->w_width
, fore
->w_height
);
4984 DoResize(D_width
, D_height
);
4988 Redisplay(norefresh
+ all_norefresh
);
4995 register struct win
**pp
;
4996 int n
= fore
? fore
->w_number
: MAXWIN
;
4997 struct win
*group
= fore
? fore
->w_group
: 0;
4999 for (pp
= fore
? wtab
+ n
+ 1 : wtab
; pp
!= wtab
+ n
; pp
++)
5001 if (pp
== wtab
+ MAXWIN
)
5005 if (!fore
|| group
== (*pp
)->w_group
)
5017 register struct win
**pp
;
5018 int n
= fore
? fore
->w_number
: -1;
5019 struct win
*group
= fore
? fore
->w_group
: 0;
5021 for (pp
= wtab
+ n
- 1; pp
!= wtab
+ n
; pp
--)
5024 pp
= wtab
+ MAXWIN
- 1;
5027 if (!fore
|| group
== (*pp
)->w_group
)
5039 char *m
= "No other window.";
5040 if (windows
&& (fore
== 0 || windows
->w_next
))
5044 Msg(0, "No window available");
5047 Msg(0, m
, fore
->w_number
); /* other arg for nethack */
5055 struct win
**pp
, *p
;
5060 * Remove window from linked list.
5062 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5068 wtab
[wi
->w_number
] = 0;
5077 * switch to different window on all canvases
5079 for (display
= displays
; display
; display
= display
->d_next
)
5082 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5084 if (Layer2Window(cv
->c_layer
) != wi
)
5086 /* switch to other window */
5087 SetCanvasWindow(cv
, FindNiceWindow(D_other
, 0));
5093 if (wi
->w_zdisplay
== display
)
5096 D_readev
.condpos
= D_readev
.condneg
= 0;
5103 WindowChanged((struct win
*)0, 'w');
5104 WindowChanged((struct win
*)0, 'W');
5105 WindowChanged((struct win
*)0, 0);
5114 if ((fore
->w_log
!= 0) == on
)
5116 if (display
&& !*rc_name
)
5117 Msg(0, "You are %s logging.", on
? "already" : "not");
5120 if (fore
->w_log
!= 0)
5122 Msg(0, "Logfile \"%s\" closed.", fore
->w_log
->name
);
5123 logfclose(fore
->w_log
);
5125 WindowChanged(fore
, 'f');
5128 if (DoStartLog(fore
, buf
, sizeof(buf
)))
5130 Msg(errno
, "Error opening logfile \"%s\"", buf
);
5133 if (ftell(fore
->w_log
->fp
) == 0)
5134 Msg(0, "Creating logfile \"%s\".", fore
->w_log
->name
);
5136 Msg(0, "Appending to logfile \"%s\".", fore
->w_log
->name
);
5137 WindowChanged(fore
, 'f');
5141 AddWindows(buf
, len
, flags
, where
)
5147 register char *s
, *ss
;
5148 register struct win
**pp
, *p
;
5153 for (pp
= ((flags
& 4) && where
>= 0) ? wtab
+ where
+ 1: wtab
; pp
< wtab
+ MAXWIN
; pp
++)
5155 if (pp
- wtab
== where
&& ss
== buf
)
5159 if ((flags
& 1) && display
&& p
== D_fore
)
5161 if (D_fore
&& D_fore
->w_group
!= p
->w_group
)
5168 if (s
- buf
+ l
> len
- 24)
5170 if (s
> buf
|| (flags
& 4))
5175 sprintf(s
, "%d", p
->w_number
);
5176 if (p
->w_number
== where
)
5179 if (display
&& p
== D_fore
)
5183 if (display
&& p
== D_other
)
5185 s
= AddWindowFlags(s
, len
, p
);
5196 AddWindowFlags(buf
, len
, p
)
5202 if (p
== 0 || len
< 12)
5208 if (display
&& p
== D_fore
)
5210 if (display
&& p
== D_other
)
5213 if (p
->w_layer
.l_cvlist
&& p
->w_layer
.l_cvlist
->c_lnext
)
5215 if (p
->w_monitor
== MON_DONE
5217 && (ACLBYTE(p
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5221 if (p
->w_bell
== BELL_DONE
)
5224 if (p
->w_slot
!= (slot_t
) 0 && p
->w_slot
!= (slot_t
) -1)
5232 if (p
->w_ptyfd
< 0 && p
->w_type
!= W_TYPE_GROUP
)
5239 AddOtherUsers(buf
, len
, p
)
5244 struct display
*d
, *olddisplay
= display
;
5250 for (display
= displays
; display
; display
= display
->d_next
)
5252 if (olddisplay
&& D_user
== olddisplay
->d_user
)
5254 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5255 if (Layer2Window(cv
->c_layer
) == p
)
5259 for (d
= displays
; d
&& d
!= display
; d
= d
->d_next
)
5260 if (D_user
== d
->d_user
)
5262 if (d
&& d
!= display
)
5264 if (len
> 1 && s
!= buf
)
5269 l
= strlen(D_user
->u_name
);
5272 strcpy(s
, D_user
->u_name
);
5277 display
= olddisplay
;
5290 if (where
== -1 && D_fore
)
5291 where
= D_fore
->w_number
;
5292 ss
= AddWindows(buf
, sizeof(buf
), 0, where
);
5293 s
= buf
+ strlen(buf
);
5294 if (ss
- buf
> D_width
/ 2)
5297 if (s
- ss
< D_width
)
5313 register struct win
*wp
= fore
;
5318 Msg(0, "(%d,%d)/(%d,%d) no window", D_x
+ 1, D_y
+ 1, D_width
, D_height
);
5322 if (buf
< (p
+= GetAnsiStatus(wp
, p
)))
5324 sprintf(p
, "(%d,%d)/(%d,%d)",
5325 wp
->w_x
+ 1, wp
->w_y
+ 1, wp
->w_width
, wp
->w_height
);
5327 sprintf(p
+= strlen(p
), "+%d", wp
->w_histheight
);
5329 sprintf(p
+= strlen(p
), " %c%sflow",
5330 (wp
->w_flow
& FLOW_NOW
) ? '+' : '-',
5331 (wp
->w_flow
& FLOW_AUTOFLAG
) ? "" :
5332 ((wp
->w_flow
& FLOW_AUTO
) ? "(+)" : "(-)"));
5333 if (!wp
->w_wrap
) sprintf(p
+= strlen(p
), " -wrap");
5334 if (wp
->w_insert
) sprintf(p
+= strlen(p
), " ins");
5335 if (wp
->w_origin
) sprintf(p
+= strlen(p
), " org");
5336 if (wp
->w_keypad
) sprintf(p
+= strlen(p
), " app");
5337 if (wp
->w_log
) sprintf(p
+= strlen(p
), " log");
5338 if (wp
->w_monitor
!= MON_OFF
5340 && (ACLBYTE(wp
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5343 sprintf(p
+= strlen(p
), " mon");
5344 if (wp
->w_mouse
) sprintf(p
+= strlen(p
), " mouse");
5346 if (wp
->w_bce
) sprintf(p
+= strlen(p
), " bce");
5348 if (!wp
->w_c1
) sprintf(p
+= strlen(p
), " -c1");
5349 if (wp
->w_norefresh
) sprintf(p
+= strlen(p
), " nored");
5354 if (wp
->w_encoding
&& (display
== 0 || D_encoding
!= wp
->w_encoding
|| EncodingDefFont(wp
->w_encoding
) <= 0))
5357 strcpy(p
, EncodingName(wp
->w_encoding
));
5361 if (wp
->w_encoding
!= UTF8
)
5364 if (D_CC0
|| (D_CS0
&& *D_CS0
))
5368 sprintf(p
, " G%c", wp
->w_Charset
+ '0');
5369 if (wp
->w_FontE
>= ' ')
5374 p
[4] = wp
->w_FontE
^ 0x40;
5381 sprintf(p
++, " G%c%c[", wp
->w_Charset
+ '0', wp
->w_CharsetR
+ '0');
5383 sprintf(p
, " G%c[", wp
->w_Charset
+ '0');
5385 for (i
= 0; i
< 4; i
++)
5387 if (wp
->w_charsets
[i
] == ASCII
)
5389 else if (wp
->w_charsets
[i
] >= ' ')
5390 *p
++ = wp
->w_charsets
[i
];
5394 *p
++ = wp
->w_charsets
[i
] ^ 0x40;
5402 if (wp
->w_type
== W_TYPE_PLAIN
)
5404 /* add info about modem control lines */
5406 TtyGetModemStatus(wp
->w_ptyfd
, p
);
5408 #ifdef BUILTIN_TELNET
5409 else if (wp
->w_type
== W_TYPE_TELNET
)
5412 TelStatus(wp
, p
, sizeof(buf
) - 1 - (p
- buf
));
5415 Msg(0, "%s %d(%s)", buf
, wp
->w_number
, wp
->w_title
);
5425 sprintf(p
, "(%d,%d)", D_width
, D_height
),
5431 strcpy(p
, EncodingName(D_encoding
));
5437 strcpy(p
, " xterm");
5443 strcpy(p
, " color");
5450 strcpy(p
, " iso2022");
5453 else if (D_CS0
&& *D_CS0
)
5455 strcpy(p
, " altchar");
5463 AKAfin(buf
, len
, data
)
5466 char *data
; /* dummy */
5470 ChangeAKA(fore
, buf
, strlen(buf
));
5478 Input("Set window's title to: ", sizeof(fore
->w_akabuf
) - 1, INP_COOKED
, AKAfin
, NULL
, 0);
5484 if ((*(unsigned char *)s
& 0x7f) < 0x20 || *s
== 0x7f)
5488 LayProcess(&ss
, &n
);
5493 Colonfin(buf
, len
, data
)
5496 char *data
; /* dummy */
5501 if (buf
[len
] == '\t')
5504 int l
= 0, r
= RC_LAST
;
5505 int showmessage
= 0;
5508 while (*s
&& s
- buf
< len
)
5512 /* Showing a message when there's no hardstatus or caption cancels the input */
5514 (captionalways
|| D_has_hstatus
== HSTATUS_LASTLINE
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
)))
5520 x
= strncmp(buf
, comms
[m
].name
, len
);
5528 for (l
= m
- 1; l
>= 0 && strncmp(buf
, comms
[l
].name
, len
) == 0; l
--)
5530 for (m
= ++l
; m
<= r
&& strncmp(buf
, comms
[m
].name
, len
) == 0 && s
- mbuf
< sizeof(mbuf
); m
++)
5531 s
+= snprintf(s
, sizeof(mbuf
) - (s
- mbuf
), " %s", comms
[m
].name
);
5535 Msg(0, "Possible commands:%s", mbuf
);
5540 len
= snprintf(mbuf
, sizeof(mbuf
), "%s \t", comms
[l
].name
+ len
);
5541 if (len
> 0 && len
< sizeof(mbuf
))
5542 LayProcess(&s
, &len
);
5547 if (l
> r
&& showmessage
)
5548 Msg(0, "No commands matching '%*s'", len
, buf
);
5552 if (!len
|| buf
[len
])
5555 len
= strlen(buf
) + 1;
5556 if (len
> (int)sizeof(mbuf
))
5560 bcopy(buf
, mbuf
, len
);
5561 RcLine(mbuf
, sizeof mbuf
);
5566 SelectFin(buf
, len
, data
)
5569 char *data
; /* dummy */
5573 if (!len
|| !display
)
5575 if (len
== 1 && *buf
== '-')
5577 SetForeWindow((struct win
*)0);
5581 if ((n
= WindowByNoN(buf
)) < 0)
5587 SelectLayoutFin(buf
, len
, data
)
5590 char *data
; /* dummy */
5595 if (!len
|| !display
)
5597 if (len
== 1 && *buf
== '-')
5599 LoadLayout((struct layout
*)0);
5603 lay
= FindLayout(buf
);
5605 Msg(0, "No such layout\n");
5606 else if (lay
== D_layout
)
5607 Msg(0, "This IS layout %d (%s).\n", lay
->lay_number
, lay
->lay_title
);
5610 LoadLayout(lay
, &D_canvas
);
5619 Input("Switch to window: ", 20, INP_COOKED
, SelectFin
, NULL
, 0);
5622 static char setenv_var
[31];
5626 SetenvFin1(buf
, len
, data
)
5629 char *data
; /* dummy */
5631 if (!len
|| !display
)
5637 SetenvFin2(buf
, len
, data
)
5640 char *data
; /* dummy */
5642 if (!len
|| !display
)
5644 debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var
, buf
);
5645 xsetenv(setenv_var
, buf
);
5653 static char setenv_buf
[50 + sizeof(setenv_var
)]; /* need to be static here, cannot be freed */
5657 strncpy(setenv_var
, arg
, sizeof(setenv_var
) - 1);
5658 sprintf(setenv_buf
, "Enter value for %s: ", setenv_var
);
5659 Input(setenv_buf
, 30, INP_COOKED
, SetenvFin2
, NULL
, 0);
5662 Input("Setenv: Enter variable name: ", 30, INP_COOKED
, SetenvFin1
, NULL
, 0);
5666 * the following options are understood by this parser:
5667 * -f, -f0, -f1, -fy, -fa
5668 * -t title, -T terminal-type, -h height-of-scrollback,
5669 * -ln, -l0, -ly, -l1, -l
5676 struct NewWindow nwin
;
5681 while (av
&& *av
&& av
[0][0] == '-')
5683 if (av
[0][1] == '-')
5695 nwin
.flowflag
= FLOW_NOW
* 0;
5700 nwin
.flowflag
= FLOW_NOW
* 1;
5703 nwin
.flowflag
= FLOW_AUTOFLAG
;
5709 case 't': /* no more -k */
5711 nwin
.aka
= &av
[0][2];
5719 nwin
.term
= &av
[0][2];
5727 nwin
.histheight
= atoi(av
[0] + 2);
5729 nwin
.histheight
= atoi(*av
);
5758 nwin
.monitor
= MON_ON
;
5764 Msg(0, "%s: screen: invalid option -%c.", fn
, av
[0][1]);
5770 if (av
&& *av
&& IsNumColon(*av
, 10, buf
, sizeof(buf
)))
5775 if (num
< 0 || num
> MAXWIN
- 1)
5777 Msg(0, "%s: illegal screen number %d.", fn
, num
);
5787 nwin
.aka
= Filename(*av
);
5794 * CompileKeys must be called before Markroutine is first used.
5795 * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
5797 * s is an ascii string in a termcap-like syntax. It looks like
5798 * "j=u:k=d:l=r:h=l: =.:" and so on...
5799 * this example rebinds the cursormovement to the keys u (up), d (down),
5800 * l (left), r (right). placing a mark will now be done with ".".
5803 CompileKeys(s
, sl
, array
)
5806 unsigned char *array
;
5809 unsigned char key
, value
;
5813 for (i
= 0; i
< 256; i
++)
5817 debug1("CompileKeys: '%s'\n", s
);
5820 key
= *(unsigned char *)s
++;
5821 if (*s
!= '=' || sl
< 3)
5828 value
= *(unsigned char *)s
++;
5831 while (*s
== '=' && sl
>= 2);
5840 #endif /* COPY_PASTE */
5843 * Asynchronous input functions
5846 #if defined(DETACH) && defined(POW_DETACH)
5848 pow_detach_fn(buf
, len
, data
)
5851 char *data
; /* dummy */
5853 debug("pow_detach_fn called\n");
5859 if (ktab
[(int)(unsigned char)*buf
].nr
!= RC_POW_DETACH
)
5862 write(D_userfd
, "\007", 1);
5863 Msg(0, "Detach aborted.");
5868 #endif /* POW_DETACH */
5872 copy_reg_fn(buf
, len
, data
)
5875 char *data
; /* dummy */
5877 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
5888 if (D_user
->u_plop
.len
)
5890 if ((pp
->buf
= (char *)malloc(D_user
->u_plop
.len
)) == NULL
)
5895 bcopy(D_user
->u_plop
.buf
, pp
->buf
, D_user
->u_plop
.len
);
5897 pp
->len
= D_user
->u_plop
.len
;
5899 pp
->enc
= D_user
->u_plop
.enc
;
5901 Msg(0, "Copied %d characters into register %c", D_user
->u_plop
.len
, *buf
);
5905 ins_reg_fn(buf
, len
, data
)
5908 char *data
; /* dummy */
5910 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
5918 return; /* Input() should not call us w/o fore, but you never know... */
5920 Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
5923 MakePaster(&fore
->w_paster
, pp
->buf
, pp
->len
, 0);
5926 Msg(0, "Empty register.");
5928 #endif /* COPY_PASTE */
5931 process_fn(buf
, len
, data
)
5934 char *data
; /* dummy */
5936 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
5945 ProcessInput(pp
->buf
, pp
->len
);
5948 Msg(0, "Empty register.");
5952 confirm_fn(buf
, len
, data
)
5959 if (len
|| (*buf
!= 'y' && *buf
!= 'Y'))
5964 act
.nr
= *(int *)data
;
5973 struct acluser
**up
;
5975 char pw1
[130]; /* FreeBSD crypts to 128 bytes */
5980 su_fin(buf
, len
, data
)
5985 struct inputsu
*i
= (struct inputsu
*)data
;
5990 { p
= i
->name
; l
= sizeof(i
->name
) - 1; }
5992 { strcpy(p
= i
->pw1
, "\377"); l
= sizeof(i
->pw1
) - 1; }
5994 { strcpy(p
= i
->pw2
, "\377"); l
= sizeof(i
->pw2
) - 1; }
5996 strncpy(p
, buf
, 1 + (l
< len
) ? l
: len
);
5998 Input("Screen User: ", sizeof(i
->name
) - 1, INP_COOKED
, su_fin
, (char *)i
, 0);
6000 Input("User's UNIX Password: ", sizeof(i
->pw1
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6002 Input("User's Screen Password: ", sizeof(i
->pw2
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6005 if ((p
= DoSu(i
->up
, i
->name
, i
->pw2
, i
->pw1
)))
6012 InputSu(w
, up
, name
)
6014 struct acluser
**up
;
6019 if (!(i
= (struct inputsu
*)calloc(1, sizeof(struct inputsu
))))
6024 su_fin(name
, (int)strlen(name
), (char *)i
); /* can also initialise stuff */
6026 su_fin((char *)0, 0, (char *)i
);
6029 #endif /* MULTIUSER */
6034 pass1(buf
, len
, data
)
6039 struct acluser
*u
= (struct acluser
*)data
;
6044 if (u
->u_password
!= NullStr
)
6045 free((char *)u
->u_password
);
6046 u
->u_password
= SaveStr(buf
);
6047 bzero(buf
, strlen(buf
));
6048 Input("Retype new password:", 100, INP_NOECHO
, pass2
, data
, 0);
6052 pass2(buf
, len
, data
)
6059 struct acluser
*u
= (struct acluser
*)data
;
6062 if (!buf
|| strcmp(u
->u_password
, buf
))
6064 Msg(0, "[ Passwords don't match - checking turned off ]");
6065 if (u
->u_password
!= NullStr
)
6067 bzero(u
->u_password
, strlen(u
->u_password
));
6068 free((char *)u
->u_password
);
6070 u
->u_password
= NullStr
;
6072 else if (u
->u_password
[0] == '\0')
6074 Msg(0, "[ No password - no secure ]");
6076 bzero(buf
, strlen(buf
));
6079 if (u
->u_password
!= NullStr
)
6081 for (st
= 0; st
< 2; st
++)
6082 salt
[st
] = 'A' + (int)((time(0) >> 6 * st
) % 26);
6084 buf
= crypt(u
->u_password
, salt
);
6085 bzero(u
->u_password
, strlen(u
->u_password
));
6086 free((char *)u
->u_password
);
6087 u
->u_password
= SaveStr(buf
);
6088 bzero(buf
, strlen(buf
));
6091 UserFreeCopyBuffer(u
);
6092 u
->u_plop
.len
= strlen(u
->u_password
);
6096 if (!(u
->u_plop
.buf
= SaveStr(u
->u_password
)))
6099 D_user
->u_plop
.len
= 0;
6102 Msg(0, "[ Password moved into copybuffer ]");
6103 #else /* COPY_PASTE */
6104 Msg(0, "[ Crypted password is \"%s\" ]", u
->u_password
);
6105 #endif /* COPY_PASTE */
6108 #endif /* PASSWORD */
6111 digraph_fn(buf
, len
, data
)
6114 char *data
; /* dummy */
6121 buf
[len
+ 1] = ch
; /* so we can restore it later */
6122 if (ch
< ' ' || ch
== '\177')
6124 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6128 if ((ch
< '0' || ch
> '9') && (ch
< 'a' || ch
> 'f') && (ch
< 'A' || ch
> 'F'))
6130 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6133 if (len
== (*buf
== 'U' ? 5 : 3))
6137 if (len
&& *buf
== '0')
6139 if (ch
< '0' || ch
> '7')
6141 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6156 buf
[len
] = buf
[len
+ 1]; /* stored above */
6161 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6164 for (i
= 2; i
< len
; i
++)
6166 if (buf
[i
] >= '0' && buf
[i
] <= '9')
6167 x
= x
* 16 | (buf
[i
] - '0');
6168 else if (buf
[i
] >= 'a' && buf
[i
] <= 'f')
6169 x
= x
* 16 | (buf
[i
] - ('a' - 10));
6170 else if (buf
[i
] >= 'A' && buf
[i
] <= 'F')
6171 x
= x
* 16 | (buf
[i
] - ('A' - 10));
6176 else if (buf
[0] == '0')
6179 for (i
= 1; i
< len
; i
++)
6181 if (buf
[i
] < '0' || buf
[i
] > '7')
6183 x
= x
* 8 | (buf
[i
] - '0');
6188 for (i
= 0; i
< (int)(sizeof(digraphs
)/sizeof(*digraphs
)); i
++)
6189 if ((digraphs
[i
][0] == (unsigned char)buf
[0] && digraphs
[i
][1] == (unsigned char)buf
[1]) ||
6190 (digraphs
[i
][0] == (unsigned char)buf
[1] && digraphs
[i
][1] == (unsigned char)buf
[0]))
6192 if (i
== (int)(sizeof(digraphs
)/sizeof(*digraphs
)))
6194 Msg(0, "Unknown digraph");
6202 if (flayer
->l_encoding
== UTF8
)
6203 i
= ToUtf8(buf
, x
); /* buf is big enough for all UTF-8 codes */
6206 LayProcess(&buf
, &i
);
6217 debug1("StuffKey #%d", i
);
6220 debug1(" - %s", term
[i
+ T_CAPS
].tcname
);
6223 if (i
< KMAP_KEYS
&& D_ESCseen
)
6225 struct action
*act
= &D_ESCseen
[i
+ 256];
6226 if (act
->nr
!= RC_ILLEGAL
)
6229 DoAction(act
, i
+ 256);
6235 if (i
>= T_CURSOR
- T_CAPS
&& i
< T_KEYPAD
- T_CAPS
&& D_cursorkeys
)
6236 i
+= T_OCAPS
- T_CURSOR
;
6237 else if (i
>= T_KEYPAD
- T_CAPS
&& i
< T_OCAPS
- T_CAPS
&& D_keypad
)
6238 i
+= T_OCAPS
- T_CURSOR
;
6239 debug1(" - action %d\n", i
);
6240 flayer
= D_forecv
->c_layer
;
6244 if (InMark() || InInput() || InWList())
6245 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &mmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].mm
;
6247 if ((!act
|| act
->nr
== RC_ILLEGAL
) && !D_mapdefault
)
6248 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &umtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].um
;
6249 if (!act
|| act
->nr
== RC_ILLEGAL
)
6250 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &dmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].dm
;
6252 if (discard
&& (!act
|| act
->nr
!= RC_COMMAND
))
6259 if (act
== 0 || act
->nr
== RC_ILLEGAL
)
6273 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6274 if (Layer2Window(cv
->c_layer
) == wi
)
6280 FindNiceWindow(wi
, presel
)
6286 debug2("FindNiceWindow %d %s\n", wi
? wi
->w_number
: -1 , presel
? presel
: "NULL");
6289 i
= WindowByNoN(presel
);
6296 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6299 if (!wi
|| (IsOnDisplay(wi
) && !presel
))
6301 /* try to get another window */
6304 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6305 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6308 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6309 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6312 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6313 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6316 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6317 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6321 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6322 if (!wi
->w_layer
.l_cvlist
)
6325 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6326 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
))
6330 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6338 /* sorted list of all commands */
6339 static struct comm
**commtab
;
6340 static int ncommtab
;
6345 void (*hand
) __P((struct comm
*, char **, int));
6348 for (n
= 0; cos
[n
].name
; n
++)
6353 commtab
= (struct commt
*)realloc(commtab
, sizeof(*commtab
) * (ncommtab
+ n
));
6355 commtab
= (struct commt
*)malloc(sizeof(*commtab
) * (ncommtab
+ n
));
6358 for (i
= 0; i
< n
; i
++)
6360 for (j
= 0; j
< ncommtab
; j
++)
6362 r
= strcmp(cos
[i
].name
, commtab
[j
]->name
);
6364 Panic(0, "Duplicate command: %s\n", cos
[i
].name
);
6368 for (r
= ncommtab
; r
> j
; r
--)
6369 commtab
[r
] = commtab
[r
- 1];
6370 commtab
[j
] = cos
+ i
;
6371 cos
[i
].handler
= hand
;
6372 bzero(cos
[i
].userbits
, sizeof(cos
[i
].userbits
));
6381 int x
, m
, l
= 0, r
= ncommtab
- 1;
6385 x
= strcmp(str
, commtab
[m
]->name
);
6399 CalcSlicePercent(cv
, percent
)
6404 if (!cv
|| !cv
->c_slback
)
6406 up
= CalcSlicePercent(cv
->c_slback
->c_slback
, percent
);
6408 for (cv
= cv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6409 wsum
+= cv
->c_slweight
;
6412 return (up
* w
) / wsum
;
6416 ChangeCanvasSize(fcv
, abs
, diff
, gflag
, percent
)
6417 struct canvas
*fcv
; /* make this canvas bigger */
6418 int abs
; /* mode: 0:rel 1:abs 2:max */
6419 int diff
; /* change this much */
6420 int gflag
; /* go up if neccessary */
6424 int done
, have
, m
, dir
;
6426 debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs
, diff
, percent
);
6427 if (abs
== 0 && diff
== 0)
6432 fcv
->c_slweight
= 0;
6435 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6437 fcv
->c_slweight
= 1;
6438 cv
= fcv
->c_slback
->c_slback
;
6439 if (gflag
&& cv
&& cv
->c_slback
)
6440 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6448 if (percent
&& diff
> percent
)
6454 for (cv
= fcv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6455 wsum
+= cv
->c_slweight
;
6458 up
= gflag
? CalcSlicePercent(fcv
->c_slback
->c_slback
, percent
) : percent
;
6459 debug3("up=%d, wsum=%d percent=%d\n", up
, wsum
, percent
);
6462 int scale
= wsum
< 10 ? 1000 : 100;
6463 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6464 cv
->c_slweight
*= scale
;
6466 debug1("scaled wsum to %d\n", wsum
);
6468 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6472 cv
->c_slweight
= (cv
->c_slweight
* up
) / percent
;
6473 if (cv
->c_slweight
== 0)
6476 debug1(" - weight %d\n", cv
->c_slweight
);
6478 diff
= (diff
* wsum
) / percent
;
6484 if (abs
&& diff
== (fcv
->c_slorient
== SLICE_VERT
? fcv
->c_ye
- fcv
->c_ys
+ 2 : fcv
->c_xe
- fcv
->c_xs
+ 2))
6486 /* fix weights to real size (can't be helped, sorry) */
6487 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6489 cv
->c_slweight
= cv
->c_slorient
== SLICE_VERT
? cv
->c_ye
- cv
->c_ys
+ 2 : cv
->c_xe
- cv
->c_xs
+ 2;
6490 debug1(" - weight %d\n", cv
->c_slweight
);
6494 diff
= diff
- fcv
->c_slweight
;
6495 debug1("diff = %d\n", diff
);
6500 cv
= fcv
->c_slnext
? fcv
->c_slnext
: fcv
->c_slprev
;
6501 fcv
->c_slweight
+= diff
;
6502 cv
->c_slweight
-= diff
;
6507 for (cv
= fcv
->c_slnext
; diff
> 0; cv
= dir
> 0 ? cv
->c_slnext
: cv
->c_slprev
)
6511 debug1("reached end, dir is %d\n", dir
);
6521 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 : 2;
6522 debug2("min is %d, have %d\n", m
, cv
->c_slweight
);
6523 if (cv
->c_slweight
> m
)
6525 have
= cv
->c_slweight
- m
;
6528 debug1("subtract %d\n", have
);
6529 cv
->c_slweight
-= have
;
6536 /* need more room! */
6537 cv
= fcv
->c_slback
->c_slback
;
6538 if (cv
&& cv
->c_slback
)
6539 done
+= ChangeCanvasSize(fcv
->c_slback
->c_slback
, 0, diff
, gflag
, percent
);
6541 fcv
->c_slweight
+= done
;
6542 debug1("ChangeCanvasSize returns %d\n", done
);
6547 ResizeRegions(arg
, flags
)
6552 int nreg
, dsize
, diff
, siz
, nsiz
, l
, done
;
6553 int gflag
= 0, abs
= 0, percent
= 0;
6557 if (D_forecv
->c_slorient
== SLICE_UNKN
)
6559 Msg(0, "resize: need more than one region");
6562 gflag
= flags
& RESIZE_FLAG_L
? 0 : 1;
6563 orient
|= flags
& RESIZE_FLAG_H
? SLICE_HORI
: 0;
6564 orient
|= flags
& RESIZE_FLAG_V
? SLICE_VERT
: 0;
6566 orient
= D_forecv
->c_slorient
;
6570 /* make all regions the same height */
6571 struct canvas
*cv
= gflag
? &D_canvas
: D_forecv
->c_slback
;
6572 if (cv
->c_slperp
->c_slorient
& orient
)
6573 EqualizeCanvas(cv
->c_slperp
, gflag
);
6574 /* can't use cv->c_slorient directly as it can be D_canvas */
6575 if ((cv
->c_slperp
->c_slorient
^ (SLICE_HORI
^ SLICE_VERT
)) & orient
)
6580 EqualizeCanvas(cv
->c_slperp
, gflag
);
6583 EqualizeCanvas(cv
, gflag
);
6586 RecreateCanvasChain();
6587 RethinkDisplayViewports();
6588 ResizeLayersToCanvases();
6591 if (!strcmp(arg
, "min") || !strcmp(arg
, "0"))
6596 else if (!strcmp(arg
, "max") || !strcmp(arg
, "_"))
6603 if (l
> 0 && arg
[l
- 1] == '%')
6606 diff
= atoi(arg
+ 1);
6607 else if (*arg
== '-')
6608 diff
= -atoi(arg
+ 1);
6611 diff
= atoi(arg
); /* +1 because of caption line */
6614 abs
= diff
== 0 ? 2 : 1;
6620 diff
= diff
* percent
/ 100;
6622 if (cv
->c_slorient
& orient
)
6623 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6624 if (cv
->c_slback
->c_slorient
& orient
)
6625 ChangeCanvasSize(cv
->c_slback
, abs
, diff
, gflag
, percent
);
6627 ResizeCanvas(&D_canvas
);
6628 RecreateCanvasChain();
6629 RethinkDisplayViewports();
6630 ResizeLayersToCanvases();
6637 if (siz
+ diff
> dsize
- (nreg
- 1) * 2 - 1)
6638 diff
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6639 if (diff
== 0 || siz
+ diff
< 1)
6644 if (D_forecv
->c_next
)
6646 D_forecv
->c_ye
+= diff
;
6647 D_forecv
->c_next
->c_ys
+= diff
;
6648 D_forecv
->c_next
->c_yoff
+= diff
;
6652 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6653 if (cv
->c_next
== D_forecv
)
6657 D_forecv
->c_ys
-= diff
;
6658 D_forecv
->c_yoff
-= diff
;
6663 int s
, i
= 0, found
= 0, di
= diff
, d2
;
6664 s
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6665 for (cv
= D_cvlist
; cv
; i
= cv
->c_ye
+ 2, cv
= cv
->c_next
)
6669 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) + diff
;
6670 cv
->c_yoff
-= cv
->c_ys
- i
;
6675 s
-= cv
->c_ye
- cv
->c_ys
;
6683 d2
= di
> cv
->c_ye
- cv
->c_ys
? cv
->c_ye
- cv
->c_ys
: di
;
6685 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) - d2
;
6686 cv
->c_yoff
-= cv
->c_ys
- i
;
6690 RethinkDisplayViewports();
6691 ResizeLayersToCanvases();
6696 ResizeFin(buf
, len
, data
)
6702 int flags
= *(int *)data
;
6703 ch
= ((unsigned char *)buf
)[len
];
6706 ResizeRegions(buf
, flags
);
6710 flags
^= RESIZE_FLAG_H
;
6712 flags
^= RESIZE_FLAG_V
;
6714 flags
|= RESIZE_FLAG_H
|RESIZE_FLAG_V
;
6716 flags
^= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
6718 flags
^= RESIZE_FLAG_L
;
6721 inp_setprompt(resizeprompts
[flags
], NULL
);
6722 *(int *)data
= flags
;
6733 p
= Layer2Window(D_forecv
->c_layer
);
6734 for (i
= 3; i
>=0; i
--)
6735 SetXtermOSC(i
, p
? p
->w_xtermosc
[i
] : 0);
6740 ParseAttrColor(s1
, s2
, msgok
)
6752 while (*ss
&& *ss
!= ' ')
6756 if (*s
&& (s2
|| *ss
|| !((*s
>= 'a' && *s
<= 'z') || (*s
>= 'A' && *s
<= 'Z') || *s
== '.')))
6758 int mode
= 0, n
= 0;
6776 if (*s
>= '0' && *s
<= '9')
6779 if (*s
>= '0' && *s
<= '9')
6780 n
= n
* 16 + (*s
++ - '0');
6781 else if (*s
>= 'a' && *s
<= 'f')
6782 n
= n
* 16 + (*s
++ - ('a' - 10));
6783 else if (*s
>= 'A' && *s
<= 'F')
6784 n
= n
* 16 + (*s
++ - ('A' - 10));
6785 else if (*s
&& *s
!= ' ')
6788 Msg(0, "Illegal attribute hexchar '%c'", *s
);
6794 while (*s
&& *s
!= ' ')
6811 Msg(0, "Illegal attribute specifier '%c'", *s
);
6817 if (*s
&& *s
!= ' ')
6820 Msg(0, "junk after attribute description: '%c'", *s
);
6832 while (*s
&& *s
== ' ')
6840 Msg(0, "junk after description: '%c'", *s
);
6844 while (*s
&& *s
== ' ')
6851 static char costr
[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
6861 for (j
= 0; j
< 2 && *s
&& *s
!= ' '; j
++)
6863 for (i
= 0; costr
[i
]; i
++)
6869 Msg(0, "illegal color descriptor: '%c'", *s
);
6873 n
= n
<< 4 | (i
& 15);
6876 n
= (n
& 0x20ff) | 0x200;
6880 if ((n
& 0xf00) == 0xf00)
6881 n
^= 0xf00; /* clear superflous bits */
6884 n
^= 0x2400; /* shift bit into right position */
6887 n
|= 0xf0; /* don't change bg color */
6888 if (numco
!= 2 && n
!= 0xff)
6889 n
|= 0x100; /* special invert mode */
6890 if (*s
&& *s
!= ' ')
6893 Msg(0, "junk after color description: '%c'", *s
);
6901 while (*s
&& *s
== ' ')
6906 Msg(0, "junk after description: '%c'", *s
);
6909 debug1("ParseAttrColor %06x\n", r
);
6917 * e just set intensity
6918 * f don't change anything
6919 * Intensity is encoded into bits 17(fg) and 18(bg).
6922 ApplyAttrColor(i
, mc
)
6926 debug1("ApplyAttrColor %06x\n", i
);
6927 mc
->attr
|= i
>> 8 & 255;
6928 mc
->attr
^= i
& 255;
6930 i
= (i
>> 16) ^ 0xff;
6931 if ((i
& 0x100) != 0)
6934 if (mc
->attr
& (A_SO
|A_RV
))
6936 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4) | ((i
& 0x200) << 1) | ((i
& 0x400) >> 1);
6938 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4);
6942 if ((i
& 0x0f) != 0x0f)
6943 mc
->attr
= (mc
->attr
& 0xbf) | ((i
>> 3) & 0x40);
6944 if ((i
& 0xf0) != 0xf0)
6945 mc
->attr
= (mc
->attr
& 0x7f) | ((i
>> 3) & 0x80);
6947 mc
->color
= 0x99 ^ mc
->color
;
6948 if ((i
& 0x0e) == 0x0e)
6949 i
= (i
& 0xf0) | (mc
->color
& 0x0f);
6950 if ((i
& 0xe0) == 0xe0)
6951 i
= (i
& 0x0f) | (mc
->color
& 0xf0);
6952 mc
->color
= 0x99 ^ i
;
6953 debug2("ApplyAttrColor - %02x %02x\n", mc
->attr
, i
);