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
;
109 static int CheckArgNum
__P((int, char **));
110 static void ClearAction
__P((struct action
*));
111 static void SaveAction
__P((struct action
*, int, char **, int *));
112 static int NextWindow
__P((void));
113 static int PreviousWindow
__P((void));
114 static int MoreWindows
__P((void));
115 static void LogToggle
__P((int));
116 static void ShowInfo
__P((void));
117 static void ShowDInfo
__P((void));
118 static struct win
*WindowByName
__P((char *));
119 static int WindowByNumber
__P((char *));
120 static int ParseOnOff
__P((struct action
*, int *));
121 static int ParseWinNum
__P((struct action
*, int *));
122 static int ParseBase
__P((struct action
*, char *, int *, int, char *));
123 static int ParseNum1000
__P((struct action
*, int *));
124 static char **SaveArgs
__P((char **));
125 static int IsNum
__P((char *, int));
126 static void Colonfin
__P((char *, int, char *));
127 static void InputSelect
__P((void));
128 static void InputSetenv
__P((char *));
129 static void InputAKA
__P((void));
131 static int InputSu
__P((struct win
*, struct acluser
**, char *));
132 static void su_fin
__P((char *, int, char *));
134 static void AKAfin
__P((char *, int, char *));
136 static void copy_reg_fn
__P((char *, int, char *));
137 static void ins_reg_fn
__P((char *, int, char *));
139 static void process_fn
__P((char *, int, char *));
141 static void pass1
__P((char *, int, char *));
142 static void pass2
__P((char *, int, char *));
145 static void pow_detach_fn
__P((char *, int, char *));
147 static void digraph_fn
__P((char *, int, char *));
148 static void confirm_fn
__P((char *, int, char *));
149 static int IsOnDisplay
__P((struct win
*));
150 static void ResizeRegions
__P((char *, int));
151 static void ResizeFin
__P((char *, int, char *));
152 static struct action
*FindKtab
__P((char *, int));
153 static void SelectFin
__P((char *, int, char *));
154 static void SelectLayoutFin
__P((char *, int, char *));
157 extern struct layer
*flayer
;
158 extern struct display
*display
, *displays
;
159 extern struct win
*fore
, *console_window
, *windows
;
160 extern struct acluser
*users
;
161 extern struct layout
*layouts
, *layout_attach
, layout_last_marker
;
162 extern struct layout
*laytab
[];
164 extern char screenterm
[], HostName
[], version
[];
165 extern struct NewWindow nwin_undef
, nwin_default
;
166 extern struct LayFuncs WinLf
, MarkLf
;
168 extern int Z0width
, Z1width
;
169 extern int real_uid
, real_gid
;
172 extern int nethackflag
;
176 struct win
*wtab
[MAXWIN
]; /* window table, should be dynamic */
180 extern int maxusercount
;
184 struct plop plop_tab
[MAX_PLOP_DEFS
];
187 # define PTYMODE 0622
190 int TtyMode
= PTYMODE
;
191 int hardcopy_append
= 0;
192 int all_norefresh
= 0;
195 char *zmodem_sendcmd
;
196 char *zmodem_recvcmd
;
197 static char *zmodes
[4] = {"off", "auto", "catch", "pass"};
201 struct action idleaction
;
206 struct action ktab
[256 + KMAP_KEYS
]; /* command key translation table */
210 struct action ktab
[256 + KMAP_KEYS
];
212 struct kclass
*kclasses
;
215 struct action umtab
[KMAP_KEYS
+KMAP_AKEYS
];
216 struct action dmtab
[KMAP_KEYS
+KMAP_AKEYS
];
217 struct action mmtab
[KMAP_KEYS
+KMAP_AKEYS
];
218 struct kmap_ext
*kmap_exts
;
220 static int maptimeout
= 300;
224 /* digraph table taken from old vim and rfc1345 */
225 static const unsigned char digraphs
[][3] = {
226 {' ', ' ', 160}, /* */
227 {'N', 'S', 160}, /* */
228 {'~', '!', 161}, /* ¡ */
229 {'!', '!', 161}, /* ¡ */
230 {'!', 'I', 161}, /* ¡ */
231 {'c', '|', 162}, /* ¢ */
232 {'c', 't', 162}, /* ¢ */
233 {'$', '$', 163}, /* £ */
234 {'P', 'd', 163}, /* £ */
235 {'o', 'x', 164}, /* ¤ */
236 {'C', 'u', 164}, /* ¤ */
237 {'C', 'u', 164}, /* ¤ */
238 {'E', 'u', 164}, /* ¤ */
239 {'Y', '-', 165}, /* ¥ */
240 {'Y', 'e', 165}, /* ¥ */
241 {'|', '|', 166}, /* ¦ */
242 {'B', 'B', 166}, /* ¦ */
243 {'p', 'a', 167}, /* § */
244 {'S', 'E', 167}, /* § */
245 {'"', '"', 168}, /* ¨ */
246 {'\'', ':', 168}, /* ¨ */
247 {'c', 'O', 169}, /* © */
248 {'C', 'o', 169}, /* © */
249 {'a', '-', 170}, /* ª */
250 {'<', '<', 171}, /* « */
251 {'-', ',', 172}, /* ¬ */
252 {'N', 'O', 172}, /* ¬ */
253 {'-', '-', 173}, /* */
254 {'r', 'O', 174}, /* ® */
255 {'R', 'g', 174}, /* ® */
256 {'-', '=', 175}, /* ¯ */
257 {'\'', 'm', 175}, /* ¯ */
258 {'~', 'o', 176}, /* ° */
259 {'D', 'G', 176}, /* ° */
260 {'+', '-', 177}, /* ± */
261 {'2', '2', 178}, /* ² */
262 {'2', 'S', 178}, /* ² */
263 {'3', '3', 179}, /* ³ */
264 {'3', 'S', 179}, /* ³ */
265 {'\'', '\'', 180}, /* ´ */
266 {'j', 'u', 181}, /* µ */
267 {'M', 'y', 181}, /* µ */
268 {'p', 'p', 182}, /* ¶ */
269 {'P', 'I', 182}, /* ¶ */
270 {'~', '.', 183}, /* · */
271 {'.', 'M', 183}, /* · */
272 {',', ',', 184}, /* ¸ */
273 {'\'', ',', 184}, /* ¸ */
274 {'1', '1', 185}, /* ¹ */
275 {'1', 'S', 185}, /* ¹ */
276 {'o', '-', 186}, /* º */
277 {'>', '>', 187}, /* » */
278 {'1', '4', 188}, /* ¼ */
279 {'1', '2', 189}, /* ½ */
280 {'3', '4', 190}, /* ¾ */
281 {'~', '?', 191}, /* ¿ */
282 {'?', '?', 191}, /* ¿ */
283 {'?', 'I', 191}, /* ¿ */
284 {'A', '`', 192}, /* À */
285 {'A', '!', 192}, /* À */
286 {'A', '\'', 193}, /* Á */
287 {'A', '^', 194}, /* Â */
288 {'A', '>', 194}, /* Â */
289 {'A', '~', 195}, /* Ã */
290 {'A', '?', 195}, /* Ã */
291 {'A', '"', 196}, /* Ä */
292 {'A', ':', 196}, /* Ä */
293 {'A', '@', 197}, /* Å */
294 {'A', 'A', 197}, /* Å */
295 {'A', 'E', 198}, /* Æ */
296 {'C', ',', 199}, /* Ç */
297 {'E', '`', 200}, /* È */
298 {'E', '!', 200}, /* È */
299 {'E', '\'', 201}, /* É */
300 {'E', '^', 202}, /* Ê */
301 {'E', '>', 202}, /* Ê */
302 {'E', '"', 203}, /* Ë */
303 {'E', ':', 203}, /* Ë */
304 {'I', '`', 204}, /* Ì */
305 {'I', '!', 204}, /* Ì */
306 {'I', '\'', 205}, /* Í */
307 {'I', '^', 206}, /* Î */
308 {'I', '>', 206}, /* Î */
309 {'I', '"', 207}, /* Ï */
310 {'I', ':', 207}, /* Ï */
311 {'D', '-', 208}, /* Ð */
312 {'N', '~', 209}, /* Ñ */
313 {'N', '?', 209}, /* Ñ */
314 {'O', '`', 210}, /* Ò */
315 {'O', '!', 210}, /* Ò */
316 {'O', '\'', 211}, /* Ó */
317 {'O', '^', 212}, /* Ô */
318 {'O', '>', 212}, /* Ô */
319 {'O', '~', 213}, /* Õ */
320 {'O', '?', 213}, /* Õ */
321 {'O', '"', 214}, /* Ö */
322 {'O', ':', 214}, /* Ö */
323 {'/', '\\', 215}, /* × */
324 {'*', 'x', 215}, /* × */
325 {'O', '/', 216}, /* Ø */
326 {'U', '`', 217}, /* Ù */
327 {'U', '!', 217}, /* Ù */
328 {'U', '\'', 218}, /* Ú */
329 {'U', '^', 219}, /* Û */
330 {'U', '>', 219}, /* Û */
331 {'U', '"', 220}, /* Ü */
332 {'U', ':', 220}, /* Ü */
333 {'Y', '\'', 221}, /* Ý */
334 {'I', 'p', 222}, /* Þ */
335 {'T', 'H', 222}, /* Þ */
336 {'s', 's', 223}, /* ß */
337 {'s', '"', 223}, /* ß */
338 {'a', '`', 224}, /* à */
339 {'a', '!', 224}, /* à */
340 {'a', '\'', 225}, /* á */
341 {'a', '^', 226}, /* â */
342 {'a', '>', 226}, /* â */
343 {'a', '~', 227}, /* ã */
344 {'a', '?', 227}, /* ã */
345 {'a', '"', 228}, /* ä */
346 {'a', ':', 228}, /* ä */
347 {'a', 'a', 229}, /* å */
348 {'a', 'e', 230}, /* æ */
349 {'c', ',', 231}, /* ç */
350 {'e', '`', 232}, /* è */
351 {'e', '!', 232}, /* è */
352 {'e', '\'', 233}, /* é */
353 {'e', '^', 234}, /* ê */
354 {'e', '>', 234}, /* ê */
355 {'e', '"', 235}, /* ë */
356 {'e', ':', 235}, /* ë */
357 {'i', '`', 236}, /* ì */
358 {'i', '!', 236}, /* ì */
359 {'i', '\'', 237}, /* í */
360 {'i', '^', 238}, /* î */
361 {'i', '>', 238}, /* î */
362 {'i', '"', 239}, /* ï */
363 {'i', ':', 239}, /* ï */
364 {'d', '-', 240}, /* ð */
365 {'n', '~', 241}, /* ñ */
366 {'n', '?', 241}, /* ñ */
367 {'o', '`', 242}, /* ò */
368 {'o', '!', 242}, /* ò */
369 {'o', '\'', 243}, /* ó */
370 {'o', '^', 244}, /* ô */
371 {'o', '>', 244}, /* ô */
372 {'o', '~', 245}, /* õ */
373 {'o', '?', 245}, /* õ */
374 {'o', '"', 246}, /* ö */
375 {'o', ':', 246}, /* ö */
376 {':', '-', 247}, /* ÷ */
377 {'o', '/', 248}, /* ø */
378 {'u', '`', 249}, /* ù */
379 {'u', '!', 249}, /* ù */
380 {'u', '\'', 250}, /* ú */
381 {'u', '^', 251}, /* û */
382 {'u', '>', 251}, /* û */
383 {'u', '"', 252}, /* ü */
384 {'u', ':', 252}, /* ü */
385 {'y', '\'', 253}, /* ý */
386 {'i', 'p', 254}, /* þ */
387 {'t', 'h', 254}, /* þ */
388 {'y', '"', 255}, /* ÿ */
389 {'y', ':', 255}, /* ÿ */
390 {'"', '[', 196}, /* Ä */
391 {'"', '\\', 214}, /* Ö */
392 {'"', ']', 220}, /* Ü */
393 {'"', '{', 228}, /* ä */
394 {'"', '|', 246}, /* ö */
395 {'"', '}', 252}, /* ü */
396 {'"', '~', 223} /* ß */
399 #define RESIZE_FLAG_H 1
400 #define RESIZE_FLAG_V 2
401 #define RESIZE_FLAG_L 4
403 static char *resizeprompts
[] = {
405 "resize -h # lines: ",
406 "resize -v # lines: ",
407 "resize -b # lines: ",
408 "resize -l # lines: ",
409 "resize -l -h # lines: ",
410 "resize -l -v # lines: ",
411 "resize -l -b # lines: ",
419 register unsigned int i
;
424 for (i
= 0; i
< sizeof(ktab
)/sizeof(*ktab
); i
++)
426 ktab
[i
].nr
= RC_ILLEGAL
;
427 ktab
[i
].args
= noargs
;
431 for (i
= 0; i
< KMAP_KEYS
+KMAP_AKEYS
; i
++)
433 umtab
[i
].nr
= RC_ILLEGAL
;
434 umtab
[i
].args
= noargs
;
436 dmtab
[i
].nr
= RC_ILLEGAL
;
437 dmtab
[i
].args
= noargs
;
439 mmtab
[i
].nr
= RC_ILLEGAL
;
440 mmtab
[i
].args
= noargs
;
444 for (i
= 0; i
< NKMAPDEF
; i
++)
446 if (i
+ KMAPDEFSTART
< T_CAPS
)
448 if (i
+ KMAPDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
452 argarr
[0] = kmapdef
[i
];
453 SaveAction(dmtab
+ i
+ (KMAPDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
455 for (i
= 0; i
< NKMAPADEF
; i
++)
457 if (i
+ KMAPADEFSTART
< T_CURSOR
)
459 if (i
+ KMAPADEFSTART
>= T_CURSOR
+ KMAP_AKEYS
)
461 if (kmapadef
[i
] == 0)
463 argarr
[0] = kmapadef
[i
];
464 SaveAction(dmtab
+ i
+ (KMAPADEFSTART
- T_CURSOR
+ KMAP_KEYS
), RC_STUFF
, argarr
, 0);
466 for (i
= 0; i
< NKMAPMDEF
; i
++)
468 if (i
+ KMAPMDEFSTART
< T_CAPS
)
470 if (i
+ KMAPMDEFSTART
>= T_CAPS
+ KMAP_KEYS
)
472 if (kmapmdef
[i
] == 0)
474 argarr
[0] = kmapmdef
[i
];
476 SaveAction(mmtab
+ i
+ (KMAPMDEFSTART
- T_CAPS
), RC_STUFF
, argarr
, 0);
480 ktab
['h'].nr
= RC_HARDCOPY
;
482 ktab
['z'].nr
= ktab
[Ctrl('z')].nr
= RC_SUSPEND
;
484 ktab
['c'].nr
= ktab
[Ctrl('c')].nr
= RC_SCREEN
;
485 ktab
[' '].nr
= ktab
[Ctrl(' ')].nr
=
486 ktab
['n'].nr
= ktab
[Ctrl('n')].nr
= RC_NEXT
;
487 ktab
['N'].nr
= RC_NUMBER
;
488 ktab
[Ctrl('h')].nr
= ktab
[0177].nr
= ktab
['p'].nr
= ktab
[Ctrl('p')].nr
= RC_PREV
;
489 ktab
['k'].nr
= ktab
[Ctrl('k')].nr
= RC_KILL
;
490 ktab
['l'].nr
= ktab
[Ctrl('l')].nr
= RC_REDISPLAY
;
491 ktab
['w'].nr
= ktab
[Ctrl('w')].nr
= RC_WINDOWS
;
492 ktab
['v'].nr
= RC_VERSION
;
493 ktab
[Ctrl('v')].nr
= RC_DIGRAPH
;
494 ktab
['q'].nr
= ktab
[Ctrl('q')].nr
= RC_XON
;
495 ktab
['s'].nr
= ktab
[Ctrl('s')].nr
= RC_XOFF
;
496 ktab
['t'].nr
= ktab
[Ctrl('t')].nr
= RC_TIME
;
497 ktab
['i'].nr
= ktab
[Ctrl('i')].nr
= RC_INFO
;
498 ktab
['m'].nr
= ktab
[Ctrl('m')].nr
= RC_LASTMSG
;
499 ktab
['A'].nr
= RC_TITLE
;
500 #if defined(UTMPOK) && defined(LOGOUTOK)
501 ktab
['L'].nr
= RC_LOGIN
;
503 ktab
[','].nr
= RC_LICENSE
;
504 ktab
['W'].nr
= RC_WIDTH
;
505 ktab
['.'].nr
= RC_DUMPTERMCAP
;
506 ktab
[Ctrl('\\')].nr
= RC_QUIT
;
508 ktab
['d'].nr
= ktab
[Ctrl('d')].nr
= RC_DETACH
;
510 ktab
['D'].nr
= RC_POW_DETACH
;
513 ktab
['r'].nr
= ktab
[Ctrl('r')].nr
= RC_WRAP
;
514 ktab
['f'].nr
= ktab
[Ctrl('f')].nr
= RC_FLOW
;
515 ktab
['C'].nr
= RC_CLEAR
;
516 ktab
['Z'].nr
= RC_RESET
;
517 ktab
['H'].nr
= RC_LOG
;
518 ktab
['M'].nr
= RC_MONITOR
;
519 ktab
['?'].nr
= RC_HELP
;
521 ktab
['*'].nr
= RC_DISPLAYS
;
527 SaveAction(ktab
+ '-', RC_SELECT
, args
, 0);
529 for (i
= 0; i
< ((MAXWIN
< 10) ? MAXWIN
: 10); i
++)
531 char *args
[2], arg1
[10];
534 sprintf(arg1
, "%d", i
);
535 SaveAction(ktab
+ '0' + i
, RC_SELECT
, args
, 0);
537 ktab
['\''].nr
= RC_SELECT
; /* calling a window by name */
542 SaveAction(ktab
+ '"', RC_WINDOWLIST
, args
, 0);
544 ktab
[Ctrl('G')].nr
= RC_VBELL
;
545 ktab
[':'].nr
= RC_COLON
;
547 ktab
['['].nr
= ktab
[Ctrl('[')].nr
= RC_COPY
;
552 SaveAction(ktab
+ ']', RC_PASTE
, args
, 0);
553 SaveAction(ktab
+ Ctrl(']'), RC_PASTE
, args
, 0);
555 ktab
['{'].nr
= RC_HISTORY
;
556 ktab
['}'].nr
= RC_HISTORY
;
557 ktab
['>'].nr
= RC_WRITEBUF
;
558 ktab
['<'].nr
= RC_READBUF
;
559 ktab
['='].nr
= RC_REMOVEBUF
;
562 ktab
['D'].nr
= RC_POW_DETACH
;
565 ktab
['x'].nr
= ktab
[Ctrl('x')].nr
= RC_LOCKSCREEN
;
567 ktab
['b'].nr
= ktab
[Ctrl('b')].nr
= RC_BREAK
;
568 ktab
['B'].nr
= RC_POW_BREAK
;
569 ktab
['_'].nr
= RC_SILENCE
;
570 ktab
['S'].nr
= RC_SPLIT
;
571 ktab
['Q'].nr
= RC_ONLY
;
572 ktab
['X'].nr
= RC_REMOVE
;
573 ktab
['F'].nr
= RC_FIT
;
574 ktab
['\t'].nr
= RC_FOCUS
;
579 SaveAction(ktab
+ T_BACKTAB
- T_CAPS
+ 256, RC_FOCUS
, args
, 0);
585 SaveAction(ktab
+ '|', RC_SPLIT
, args
, 0);
587 /* These come last; they may want overwrite others: */
590 ClearAction(&ktab
[DefaultEsc
]);
591 ktab
[DefaultEsc
].nr
= RC_OTHER
;
593 if (DefaultMetaEsc
>= 0)
595 ClearAction(&ktab
[DefaultMetaEsc
]);
596 ktab
[DefaultMetaEsc
].nr
= RC_META
;
599 idleaction
.nr
= RC_BLANKER
;
600 idleaction
.args
= noargs
;
604 static struct action
*
605 FindKtab(class, create
)
609 struct kclass
*kp
, **kpp
;
614 for (kpp
= &kclasses
; (kp
= *kpp
) != 0; kpp
= &kp
->next
)
615 if (!strcmp(kp
->name
, class))
621 if (strlen(class) > 80)
623 Msg(0, "Command class name too long.");
626 kp
= malloc(sizeof(*kp
));
632 kp
->name
= SaveStr(class);
633 for (i
= 0; i
< (int)(sizeof(kp
->ktab
)/sizeof(*kp
->ktab
)); i
++)
635 kp
->ktab
[i
].nr
= RC_ILLEGAL
;
636 kp
->ktab
[i
].args
= noargs
;
650 if (act
->nr
== RC_ILLEGAL
)
652 act
->nr
= RC_ILLEGAL
;
653 if (act
->args
== noargs
)
655 for (p
= act
->args
; *p
; p
++)
657 free((char *)act
->args
);
663 * ProcessInput: process input from display and feed it into
664 * the layer on canvas D_forecv.
670 * This ProcessInput just does the keybindings and passes
671 * everything else on to ProcessInput2.
675 ProcessInput(ibuf
, ilen
)
680 unsigned char *s
, *q
;
684 debug1("ProcessInput: %d bytes\n", ilen
);
685 if (display
== 0 || ilen
== 0)
690 s
= (unsigned char *)ibuf
;
694 if (D_dontmap
|| !D_nseqs
)
701 debug3("cmp %c %c[%d]\n", ch
, *D_seqp
, D_seqp
- D_kmaps
);
704 l
= D_seqp
[D_seqp
[-D_seql
-1] + 1];
708 debug1("miss %d\n", D_seqp
- D_kmaps
);
711 debug("complete miss\n");
714 p
= (char *)D_seqp
- l
;
716 D_seqp
= D_kmaps
+ 3;
719 if ((q
= D_seqh
) != 0)
722 i
= q
[0] << 8 | q
[1];
723 i
&= ~KMAP_NOTIMEOUT
;
724 debug1("Mapping former hit #%d - ", i
);
725 debug2("%d(%s) - ", q
[2], q
+ 3);
727 ProcessInput2((char *)q
+ 3, q
[2]);
735 debug1("flush old %d\n", l
);
744 /* Finish old stuff */
746 debug1("finish old %d\n", slen
);
748 ProcessInput2(ibuf
, slen
);
757 debug2("length am %d, want %d\n", l
, D_seqp
[-l
- 1]);
758 if (l
== D_seqp
[-l
- 1])
763 if (D_kmaps
+ D_nseqs
> q
&& q
[2] > l
&& !bcmp(D_seqp
- l
, q
+ 3, l
))
765 debug1("have another mapping (%s), delay execution\n", q
+ 3);
766 D_seqh
= D_seqp
- 3 - l
;
771 i
= D_seqp
[-l
- 3] << 8 | D_seqp
[-l
- 2];
772 i
&= ~KMAP_NOTIMEOUT
;
773 debug1("Mapping #%d - ", i
);
774 p
= (char *)D_seqp
- l
;
775 debug2("%d(%s) - ", l
, p
);
777 D_seqp
= D_kmaps
+ 3;
789 debug("am in sequence -> check for timeout\n");
791 for (s
= D_seqp
; ; s
+= i
* 2 + 4)
793 if (s
[-l
-3] & KMAP_NOTIMEOUT
>> 8)
795 if ((i
= s
[s
[-l
-1] + 1]) == 0)
797 SetTimeout(&D_mapev
, maptimeout
);
803 ProcessInput2(ibuf
, slen
);
807 # define ProcessInput2 ProcessInput
812 * Here only the screen escape commands are handled.
816 ProcessInput2(ibuf
, ilen
)
822 struct action
*ktabp
;
824 debug1("ProcessInput2: %d bytes\n", ilen
);
825 while (ilen
&& display
)
827 debug1(" - ilen now %d bytes\n", ilen
);
828 flayer
= D_forecv
->c_layer
;
836 if ((unsigned char)*s
++ == D_user
->u_Esc
)
842 DoProcess(fore
, &ibuf
, &slen
, 0);
848 ktabp
= D_ESCseen
? D_ESCseen
: ktab
;
850 ch
= (unsigned char)*s
;
853 * As users have different esc characters, but a common ktab[],
854 * we fold back the users esc and meta-esc key to the Default keys
855 * that can be looked up in the ktab[]. grmbl. jw.
856 * XXX: make ktab[] a per user thing.
858 if (ch
== D_user
->u_Esc
)
860 else if (ch
== D_user
->u_MetaEsc
)
864 DoAction(&ktabp
[ch
], ch
);
865 ibuf
= (char *)(s
+ 1);
871 DoProcess(p
, bufp
, lenp
, pa
)
878 struct display
*d
= display
;
881 /* XXX -> PasteStart */
882 if (pa
&& *lenp
> 1 && p
&& p
->w_slowpaste
)
884 /* schedule slowpaste event */
885 SetTimeout(&p
->w_paster
.pa_slowev
, p
->w_slowpaste
);
886 evenq(&p
->w_paster
.pa_slowev
);
890 while (flayer
&& *lenp
)
893 if (!pa
&& p
&& p
->w_paster
.pa_pastelen
&& flayer
== p
->w_paster
.pa_pastelayer
)
895 debug("layer is busy - beep!\n");
896 WBell(p
, visual_bell
);
904 LayProcess(bufp
, lenp
);
906 if (pa
&& !pa
->pa_pastelayer
)
907 break; /* flush rest of paste */
916 /* We're full, let's beep */
917 debug("layer is full - beep!\n");
918 WBell(p
, visual_bell
);
926 if (pa
&& pa
->pa_pastelen
== 0)
935 int x
, m
, l
= 0, r
= RC_LAST
;
939 x
= strcmp(str
, comms
[m
].name
);
951 CheckArgNum(nr
, args
)
956 static char *argss
[] = {"no", "one", "two", "three", "four", "OOPS"};
957 static char *orformat
[] =
959 "%s: %s: %s argument%s required",
960 "%s: %s: %s or %s argument%s required",
961 "%s: %s: %s, %s or %s argument%s required",
962 "%s: %s: %s, %s, %s or %s argument%s required"
965 n
= comms
[nr
].flags
& ARGS_MASK
;
966 for (i
= 0; args
[i
]; i
++)
968 if (comms
[nr
].flags
& ARGS_ORMORE
)
972 Msg(0, "%s: %s: at least %s argument%s required",
973 rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
977 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
978 (comms
[nr
].flags
& ARGS_PLUS2
) &&
979 (comms
[nr
].flags
& ARGS_PLUS3
))
981 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2 && i
!= n
+ 3)
983 Msg(0, orformat
[3], rc_name
, comms
[nr
].name
, argss
[n
],
984 argss
[n
+ 1], argss
[n
+ 2], argss
[n
+ 3], "");
988 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
989 (comms
[nr
].flags
& ARGS_PLUS2
))
991 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 2)
993 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
994 argss
[n
+ 1], argss
[n
+ 2], "");
998 else if ((comms
[nr
].flags
& ARGS_PLUS1
) &&
999 (comms
[nr
].flags
& ARGS_PLUS3
))
1001 if (i
!= n
&& i
!= n
+ 1 && i
!= n
+ 3)
1003 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1004 argss
[n
+ 1], argss
[n
+ 3], "");
1008 else if ((comms
[nr
].flags
& ARGS_PLUS2
) &&
1009 (comms
[nr
].flags
& ARGS_PLUS3
))
1011 if (i
!= n
&& i
!= n
+ 2 && i
!= n
+ 3)
1013 Msg(0, orformat
[2], rc_name
, comms
[nr
].name
, argss
[n
],
1014 argss
[n
+ 2], argss
[n
+ 3], "");
1018 else if (comms
[nr
].flags
& ARGS_PLUS1
)
1020 if (i
!= n
&& i
!= n
+ 1)
1022 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1023 argss
[n
+ 1], n
!= 0 ? "s" : "");
1027 else if (comms
[nr
].flags
& ARGS_PLUS2
)
1029 if (i
!= n
&& i
!= n
+ 2)
1031 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1036 else if (comms
[nr
].flags
& ARGS_PLUS3
)
1038 if (i
!= n
&& i
!= n
+ 3)
1040 Msg(0, orformat
[1], rc_name
, comms
[nr
].name
, argss
[n
],
1047 Msg(0, orformat
[0], rc_name
, comms
[nr
].name
, argss
[n
], n
!= 1 ? "s" : "");
1060 char **args
= act
->args
;
1061 int *argl
= act
->argl
;
1063 int argc
, i
, n
, msgok
;
1066 struct display
*odisplay
= display
;
1067 struct acluser
*user
;
1069 user
= display
? D_user
: users
;
1070 if (nr
== RC_ILLEGAL
)
1072 debug1("key '%c': No action\n", key
);
1075 n
= comms
[nr
].flags
;
1076 if ((n
& NEED_DISPLAY
) && display
== 0)
1078 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1081 if ((n
& NEED_FORE
) && fore
== 0)
1083 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1086 if ((n
& NEED_LAYER
) && flayer
== 0)
1088 Msg(0, "%s: %s: display or window required", rc_name
, comms
[nr
].name
);
1091 if ((argc
= CheckArgNum(nr
, args
)) < 0)
1096 if (AclCheckPermCmd(D_user
, ACL_EXEC
, &comms
[nr
]))
1098 Msg(0, "%s: %s: permission denied (user %s)",
1099 rc_name
, comms
[nr
].name
, (EffectiveAclUser
? EffectiveAclUser
: D_user
)->u_name
);
1103 #endif /* MULTIUSER */
1105 msgok
= display
&& !*rc_name
;
1111 else if (args
[0][0] == '-' && !args
[0][1])
1113 SetForeWindow((struct win
*)0);
1116 else if (args
[0][0] == '.' && !args
[0][1])
1119 Msg(0, "select . needs a window");
1122 SetForeWindow(fore
);
1126 else if (ParseWinNum(act
, &n
) == 0)
1130 case RC_DEFAUTONUKE
:
1131 if (ParseOnOff(act
, &defautonuke
) == 0 && msgok
)
1132 Msg(0, "Default autonuke turned %s", defautonuke
? "on" : "off");
1133 if (display
&& *rc_name
)
1134 D_auto_nuke
= defautonuke
;
1137 if (ParseOnOff(act
, &D_auto_nuke
) == 0 && msgok
)
1138 Msg(0, "Autonuke turned %s", D_auto_nuke
? "on" : "off");
1141 case RC_DEFOBUFLIMIT
:
1142 if (ParseNum(act
, &defobuflimit
) == 0 && msgok
)
1143 Msg(0, "Default limit set to %d", defobuflimit
);
1144 if (display
&& *rc_name
)
1146 D_obufmax
= defobuflimit
;
1147 D_obuflenmax
= D_obuflen
- D_obufmax
;
1152 Msg(0, "Limit is %d, current buffer size is %d", D_obufmax
, D_obuflen
);
1153 else if (ParseNum(act
, &D_obufmax
) == 0 && msgok
)
1154 Msg(0, "Limit set to %d", D_obufmax
);
1155 D_obuflenmax
= D_obuflen
- D_obufmax
;
1157 case RC_DUMPTERMCAP
:
1158 WriteFile(user
, (char *)0, DUMP_TERMCAP
);
1162 int mode
= DUMP_HARDCOPY
;
1164 if (argc
> 1 && !strcmp(*args
, "-h"))
1166 mode
= DUMP_SCROLLBACK
;
1170 if (*args
&& args
[1])
1172 Msg(0, "%s: hardcopy: too many arguments", rc_name
);
1175 if (fore
== 0 && *args
== 0)
1176 Msg(0, "%s: hardcopy: window required", rc_name
);
1178 WriteFile(user
, *args
, mode
);
1182 (void)ParseOnOff(act
, &nwin_default
.Lflag
);
1185 n
= fore
->w_log
? 1 : 0;
1186 ParseSwitch(act
, &n
);
1196 SwitchWindow(NextWindow());
1200 SwitchWindow(PreviousWindow());
1209 Input(fore
->w_pwin
? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1211 Input("Really kill this window [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_KILL
);
1219 FreePseudowin(fore
);
1220 Msg(0, "Filter removed.");
1224 name
= SaveStr(fore
->w_title
);
1226 Msg(0, "Window %d (%s) killed.", n
, name
);
1234 Input("Really quit and kill all your windows [y/n]", 1, INP_RAW
, confirm_fn
, NULL
, RC_QUIT
);
1241 if (*args
&& !strcmp(*args
, "-h"))
1253 Input(buf
, 1, INP_RAW
, pow_detach_fn
, NULL
, 0);
1256 Detach(D_POWER
); /* detach and kill Attacher's parent */
1265 Msg(0, "debugging info is written to %s/", DEBUGDIR
);
1267 Msg(0, "debugging is currently off. Use 'debug on' to enable.");
1272 debug("debug: closing debug file.\n");
1277 if (strcmp("off", *args
))
1281 kill(D_userpid
, SIG_NODEBUG
); /* a one shot item, but hey... */
1282 # endif /* SIG_NODEBUG */
1284 if (*args
== 0 || strcmp("off", *args
))
1285 Msg(0, "Sorry, screen was compiled without -DDEBUG option.");
1290 if (*args
&& !strcmp(*args
, "sendcmd"))
1294 free(zmodem_sendcmd
);
1295 zmodem_sendcmd
= SaveStr(args
[1]);
1298 Msg(0, "zmodem sendcmd: %s", zmodem_sendcmd
);
1301 if (*args
&& !strcmp(*args
, "recvcmd"))
1305 free(zmodem_recvcmd
);
1306 zmodem_recvcmd
= SaveStr(args
[1]);
1309 Msg(0, "zmodem recvcmd: %s", zmodem_recvcmd
);
1314 for (i
= 0; i
< 4; i
++)
1315 if (!strcmp(zmodes
[i
], *args
))
1317 if (i
== 4 && !strcmp(*args
, "on"))
1321 Msg(0, "usage: zmodem off|auto|catch|pass");
1327 Msg(0, "zmodem mode is %s", zmodes
[zmodem_mode
]);
1334 ZombieKey_destroy
= 0;
1337 if (*argl
== 0 || *argl
> 2)
1339 Msg(0, "%s:zombie: one or two characters expected.", rc_name
);
1344 if (!strcmp(args
[1], "onerror"))
1346 ZombieKey_onerror
= 1;
1348 Msg(0, "usage: zombie [keys [onerror]]");
1352 ZombieKey_onerror
= 0;
1353 ZombieKey_destroy
= args
[0][0];
1354 ZombieKey_resurrect
= *argl
== 2 ? args
[0][1] : 0;
1364 struct display
*olddisplay
= display
;
1365 display
= 0; /* no display will cause a broadcast */
1366 Msg(0, "%s: %s", s
, *args
);
1367 display
= olddisplay
;
1371 /* where this AT command comes from: */
1373 s
= SaveStr(D_user
->u_name
);
1374 /* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
1375 EffectiveAclUser
= D_user
;
1377 s
= SaveStr(D_usertty
);
1379 n
= strlen(args
[0]);
1382 * the windows/displays loops are quite dangerous here, take extra
1383 * care not to trigger landmines. Things may appear/disappear while
1384 * we are walking along.
1388 case '*': /* user */
1396 for (u
= users
; u
; u
= u
->u_next
)
1398 debug3("strncmp('%s', '%s', %d)\n", *args
, u
->u_name
, n
);
1399 if (!strncmp(*args
, u
->u_name
, n
))
1402 debug1("at all displays of user %s\n", u
->u_name
);
1403 for (display
= displays
; display
; display
= nd
)
1405 nd
= display
->d_next
;
1408 flayer
= D_forecv
->c_layer
;
1412 debug1("AT display %s\n", D_usertty
);
1413 DoCommand(args
+ 1, argl
+ 1);
1415 Msg(0, "command from %s: %s %s",
1416 s
, args
[1], args
[2] ? args
[2] : "");
1423 case '%': /* display */
1427 debug1("at display matching '%s'\n", args
[0]);
1428 for (display
= displays
; display
; display
= nd
)
1430 nd
= display
->d_next
;
1434 flayer
= D_forecv
->c_layer
;
1435 if (strncmp(args
[0], D_usertty
, n
) &&
1436 (strncmp("/dev/", D_usertty
, 5) ||
1437 strncmp(args
[0], D_usertty
+ 5, n
)) &&
1438 (strncmp("/dev/tty", D_usertty
, 8) ||
1439 strncmp(args
[0], D_usertty
+ 8, n
)))
1441 debug1("AT display %s\n", D_usertty
);
1442 DoCommand(args
+ 1, argl
+ 1);
1444 Msg(0, "command from %s: %s %s",
1445 s
, args
[1], args
[2] ? args
[2] : "");
1452 case '#': /* window */
1463 if (!*args
[0] || (i
= WindowByNumber(args
[0])) < 0)
1465 args
[0][n
] = ch
; /* must restore string in case of bind */
1466 /* try looping over titles */
1467 for (fore
= windows
; fore
; fore
= nw
)
1470 if (strncmp(args
[0], fore
->w_title
, n
))
1472 debug2("AT window %d(%s)\n", fore
->w_number
, fore
->w_title
);
1474 * consider this a bug or a feature:
1475 * while looping through windows, we have fore AND
1476 * display context. This will confuse users who try to
1477 * set up loops inside of loops, but often allows to do
1478 * what you mean, even when you adress your context wrong.
1481 /* XXX: other displays? */
1482 if (fore
->w_layer
.l_cvlist
)
1483 display
= fore
->w_layer
.l_cvlist
->c_display
;
1484 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1485 DoCommand(args
+ 1, argl
+ 1); /* may destroy our display */
1486 if (fore
&& fore
->w_layer
.l_cvlist
)
1488 display
= fore
->w_layer
.l_cvlist
->c_display
;
1489 Msg(0, "command from %s: %s %s",
1490 s
, args
[1], args
[2] ? args
[2] : "");
1496 Msg(0, "%s: at '%s': no such window.\n", rc_name
, args
[0]);
1499 else if (i
< MAXWIN
&& (fore
= wtab
[i
]))
1501 args
[0][n
] = ch
; /* must restore string in case of bind */
1502 debug2("AT window %d (%s)\n", fore
->w_number
, fore
->w_title
);
1503 if (fore
->w_layer
.l_cvlist
)
1504 display
= fore
->w_layer
.l_cvlist
->c_display
;
1505 flayer
= fore
->w_savelayer
? fore
->w_savelayer
: &fore
->w_layer
;
1506 DoCommand(args
+ 1, argl
+ 1);
1507 if (fore
&& fore
->w_layer
.l_cvlist
)
1509 display
= fore
->w_layer
.l_cvlist
->c_display
;
1510 Msg(0, "command from %s: %s %s",
1511 s
, args
[1], args
[2] ? args
[2] : "");
1517 Msg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name
);
1523 EffectiveAclUser
= NULL
;
1530 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1531 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1533 i
= FindEncoding(args
[1]);
1536 Msg(0, "%s: readreg: unknown encoding", rc_name
);
1543 * Without arguments we prompt for a destination register.
1544 * It will receive the copybuffer contents.
1545 * This is not done by RC_PASTE, as we prompt for source
1548 if ((s
= *args
) == NULL
)
1550 Input("Copy to register:", 1, INP_RAW
, copy_reg_fn
, NULL
, 0);
1555 Msg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name
);
1560 * With two arguments we *really* read register contents from file
1566 Msg(0, "%s: readreg: too many arguments", rc_name
);
1569 if ((s
= ReadFile(args
[1], &n
)))
1571 struct plop
*pp
= plop_tab
+ (int)(unsigned char)ch
;
1584 * with one argument we copy the copybuffer into a specified register
1585 * This could be done with RC_PASTE too, but is here to be consistent
1586 * with the zero argument call.
1588 copy_reg_fn(&ch
, 0, NULL
);
1593 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
1594 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
1596 i
= FindEncoding(args
[1]);
1599 Msg(0, "%s: register: unknown encoding", rc_name
);
1608 Msg(0, "%s: register: illegal number of arguments.", rc_name
);
1613 Msg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name
);
1620 if (user
->u_plop
.buf
!= NULL
)
1621 UserFreeCopyBuffer(user
);
1622 if (args
[1] && args
[1][0])
1624 user
->u_plop
.buf
= SaveStrn(args
[1], argl
[1]);
1625 user
->u_plop
.len
= argl
[1];
1627 user
->u_plop
.enc
= i
;
1634 struct plop
*plp
= plop_tab
+ (int)(unsigned char)ch
;
1638 plp
->buf
= SaveStrn(args
[1], argl
[1]);
1646 if ((s
= *args
) == NULL
)
1648 Input("Process register:", 1, INP_RAW
, process_fn
, NULL
, 0);
1653 Msg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name
);
1657 process_fn(&ch
, 0, NULL
);
1664 if (strcmp(s
, "-k"))
1666 Msg(0, "%s: stuff: invalid option %s", rc_name
, s
);
1670 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
1671 if (strcmp(term
[i
].tcname
, s
) == 0)
1675 Msg(0, "%s: stuff: unknown key '%s'", rc_name
, s
);
1679 if (StuffKey(i
- T_CAPS
) == 0)
1682 s
= display
? D_tcs
[i
].str
: 0;
1697 Msg(0, "screen %s", version
);
1702 timestring
= SaveStr(*args
);
1705 Msg(0, "%s", MakeWinMsg(timestring
, fore
, '%'));
1715 struct action
*ktabp
= ktab
;
1716 if (argc
== 2 && !strcmp(*args
, "-c"))
1718 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
1720 Msg(0, "Unknown command class '%s'", args
[1]);
1724 if (D_ESCseen
!= ktab
|| ktabp
!= ktab
)
1734 SwitchWindow(display
&& D_other
? D_other
->w_number
: NextWindow());
1737 if (user
->u_Esc
== -1)
1756 case RC_DEFBREAKTYPE
:
1759 static char *types
[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL
};
1760 extern int breaktype
;
1764 if (ParseNum(act
, &n
))
1765 for (n
= 0; n
< (int)(sizeof(types
)/sizeof(*types
)); n
++)
1767 for (i
= 0; i
< 4; i
++)
1770 if (ch
>= 'a' && ch
<= 'z')
1772 if (ch
!= types
[n
][i
] && (ch
+ ('a' - 'A')) != types
[n
][i
])
1778 if (n
< 0 || n
>= (int)(sizeof(types
)/sizeof(*types
)))
1779 Msg(0, "%s invalid, chose one of %s, %s or %s", *args
, types
[0], types
[1], types
[2]);
1783 Msg(0, "breaktype set to (%d) %s", n
, types
[n
]);
1787 Msg(0, "breaktype is (%d) %s", breaktype
, types
[breaktype
]);
1793 if (*args
&& ParseNum(act
, &n
))
1795 SendBreak(fore
, n
, nr
== RC_POW_BREAK
);
1809 if (*args
&& !strcmp(*args
, "-w"))
1811 else if (*args
&& !strcmp(*args
, "-d"))
1815 if (what
== 0 && flayer
&& !display
)
1821 Msg(0, "%s: %s: window required", rc_name
, comms
[nr
].name
);
1824 w
= flayer
->l_width
;
1825 h
= flayer
->l_height
;
1831 Msg(0, "%s: %s: display required", rc_name
, comms
[nr
].name
);
1837 if (*args
&& args
[0][0] == '-')
1839 Msg(0, "%s: %s: unknown option %s", rc_name
, comms
[nr
].name
, *args
);
1842 if (nr
== RC_HEIGHT
)
1850 else if (h
== H1height
)
1852 else if (h
> (H0height
+ H1height
) / 2)
1870 else if (w
== Z1width
)
1872 else if (w
> (Z0width
+ Z1width
) / 2)
1884 if (*args
&& args
[1] && args
[2])
1886 Msg(0, "%s: %s: too many arguments", rc_name
, comms
[nr
].name
);
1891 Msg(0, "Illegal width");
1896 Msg(0, "Illegal height");
1901 if (flayer
->l_width
== w
&& flayer
->l_height
== h
)
1903 ResizeLayer(flayer
, w
, h
, (struct display
*)0);
1906 if (D_width
== w
&& D_height
== h
)
1910 ChangeScreenSize(w
, h
, 1);
1914 if (ResizeDisplay(w
, h
) == 0)
1916 Activate(D_fore
? D_fore
->w_norefresh
: 0);
1918 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
1922 Msg(0, "Your termcap does not specify how to change the terminal's width to %d.", w
);
1923 else if (w
== D_width
)
1924 Msg(0, "Your termcap does not specify how to change the terminal's height to %d.", h
);
1926 Msg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w
, h
);
1934 ChangeAKA(fore
, *args
, strlen(*args
));
1937 Input(":", 100, INP_EVERY
, Colonfin
, NULL
, 0);
1938 if (*args
&& **args
)
1946 if (D_status_lastmsg
)
1947 Msg(0, "%s", D_status_lastmsg
);
1950 DoScreen("key", args
);
1953 if (ParseSwitch(act
, &fore
->w_wrap
) == 0 && msgok
)
1954 Msg(0, "%cwrap", fore
->w_wrap
? '+' : '-');
1959 if (args
[0][0] == 'a')
1961 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) ? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
1965 if (ParseOnOff(act
, &n
))
1967 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | n
;
1972 if (fore
->w_flow
& FLOW_AUTOFLAG
)
1973 fore
->w_flow
= (fore
->w_flow
& FLOW_AUTO
) | FLOW_NOW
;
1974 else if (fore
->w_flow
& FLOW_NOW
)
1975 fore
->w_flow
&= ~FLOW_NOW
;
1977 fore
->w_flow
= fore
->w_flow
? FLOW_AUTOFLAG
|FLOW_AUTO
|FLOW_NOW
: FLOW_AUTOFLAG
;
1979 SetFlow(fore
->w_flow
& FLOW_NOW
);
1981 Msg(0, "%cflow%s", (fore
->w_flow
& FLOW_NOW
) ? '+' : '-',
1982 (fore
->w_flow
& FLOW_AUTOFLAG
) ? "(auto)" : "");
1985 case RC_DEFWRITELOCK
:
1986 if (args
[0][0] == 'a')
1987 nwin_default
.wlock
= WLOCK_AUTO
;
1990 if (ParseOnOff(act
, &n
))
1992 nwin_default
.wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
1998 if (args
[0][0] == 'a')
2000 fore
->w_wlock
= WLOCK_AUTO
;
2004 if (ParseOnOff(act
, &n
))
2006 fore
->w_wlock
= n
? WLOCK_ON
: WLOCK_OFF
;
2009 * user may have permission to change the writelock setting,
2010 * but he may never aquire the lock himself without write permission
2012 if (!AclCheckPermWin(D_user
, ACL_WRITE
, fore
))
2013 fore
->w_wlockuser
= D_user
;
2015 Msg(0, "writelock %s", (fore
->w_wlock
== WLOCK_AUTO
) ? "auto" :
2016 ((fore
->w_wlock
== WLOCK_OFF
) ? "off" : "on"));
2020 ResetAnsiState(fore
);
2021 WriteString(fore
, "\033[H\033[J", 6);
2024 ResetAnsiState(fore
);
2026 if (fore
->w_zdisplay
)
2027 zmodem_abort(fore
, fore
->w_zdisplay
);
2029 WriteString(fore
, "\033c", 2);
2032 n
= fore
->w_monitor
!= MON_OFF
;
2035 n
= n
&& (ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
));
2037 if (ParseSwitch(act
, &n
))
2042 if (display
) /* we tell only this user */
2043 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2045 for (i
= 0; i
< maxusercount
; i
++)
2046 ACLBYTE(fore
->w_mon_notify
, i
) |= ACLBIT(i
);
2048 if (fore
->w_monitor
== MON_OFF
)
2049 fore
->w_monitor
= MON_ON
;
2050 Msg(0, "Window %d (%s) is now being monitored for all activity.", fore
->w_number
, fore
->w_title
);
2055 if (display
) /* we remove only this user */
2056 ACLBYTE(fore
->w_mon_notify
, D_user
->u_id
)
2057 &= ~ACLBIT(D_user
->u_id
);
2059 for (i
= 0; i
< maxusercount
; i
++)
2060 ACLBYTE(fore
->w_mon_notify
, i
) &= ~ACLBIT(i
);
2061 for (i
= maxusercount
- 1; i
>= 0; i
--)
2062 if (ACLBYTE(fore
->w_mon_notify
, i
))
2066 fore
->w_monitor
= MON_OFF
;
2067 Msg(0, "Window %d (%s) is no longer being monitored for activity.", fore
->w_number
, fore
->w_title
);
2077 display_wlist(0, WLIST_NUM
, (struct win
*)0);
2078 else if (!strcmp(*args
, "-m") && !args
[1])
2079 display_wlist(0, WLIST_MRU
, (struct win
*)0);
2080 else if (!strcmp(*args
, "-b") && !args
[1])
2081 display_wlist(1, WLIST_NUM
, (struct win
*)0);
2082 else if (!strcmp(*args
, "-b") && !strcmp(args
[1], "-m") && !args
[2])
2083 display_wlist(1, WLIST_MRU
, (struct win
*)0);
2084 else if (!strcmp(*args
, "-m") && !strcmp(args
[1], "-b") && !args
[2])
2085 display_wlist(1, WLIST_MRU
, (struct win
*)0);
2086 else if (!strcmp(*args
, "string"))
2092 wliststr
= SaveStr(args
[1]);
2095 Msg(0, "windowlist string is '%s'", wliststr
);
2097 else if (!strcmp(*args
, "title"))
2103 wlisttit
= SaveStr(args
[1]);
2106 Msg(0, "windowlist title is '%s'", wlisttit
);
2109 Msg(0, "usage: windowlist [-b] [string [string] | title [title]]");
2112 if (argc
== 2 && !strcmp(*args
, "-c"))
2114 struct action
*ktabp
;
2115 if ((ktabp
= FindKtab(args
[1], 0)) == 0)
2117 Msg(0, "Unknown command class '%s'", args
[1]);
2120 display_help(args
[1], ktabp
);
2123 display_help((char *)0, ktab
);
2126 display_copyright();
2130 if (flayer
->l_layfn
!= &WinLf
)
2132 Msg(0, "Must be on a window layer");
2139 static char *pasteargs
[] = {".", 0};
2140 static int pasteargl
[] = {1};
2142 if (flayer
->l_layfn
!= &WinLf
)
2144 Msg(0, "Must be on a window layer");
2147 if (GetHistory() == 0)
2149 if (user
->u_plop
.buf
== NULL
)
2157 char *ss
, *dbuf
, dch
;
2164 * without args we prompt for one(!) register to be pasted in the window
2166 if ((s
= *args
) == NULL
)
2168 Input("Paste from register:", 1, INP_RAW
, ins_reg_fn
, NULL
, 0);
2171 if (args
[1] == 0 && !fore
) /* no window? */
2174 * with two arguments we paste into a destination register
2175 * (no window needed here).
2177 if (args
[1] && argl
[1] != 1)
2179 Msg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
2185 enc
= fore
->w_encoding
;
2189 * measure length of needed buffer
2191 for (ss
= s
= *args
; (ch
= *ss
); ss
++)
2197 enc
= user
->u_plop
.enc
;
2198 if (enc
!= user
->u_plop
.enc
)
2199 l
+= RecodeBuf((unsigned char *)user
->u_plop
.buf
, user
->u_plop
.len
, user
->u_plop
.enc
, enc
, (unsigned char *)0);
2202 l
+= user
->u_plop
.len
;
2208 enc
= plop_tab
[(int)(unsigned char)ch
].enc
;
2209 if (enc
!= plop_tab
[(int)(unsigned char)ch
].enc
)
2210 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);
2213 l
+= plop_tab
[(int)(unsigned char)ch
].len
;
2218 Msg(0, "empty buffer");
2223 * if there is only one source and the destination is a window, then
2224 * pass a pointer rather than duplicating the buffer.
2226 if (s
[1] == 0 && args
[1] == 0)
2228 if (enc
== (*s
== '.' ? user
->u_plop
.enc
: plop_tab
[(int)(unsigned char)*s
].enc
))
2231 MakePaster(&fore
->w_paster
, *s
== '.' ? user
->u_plop
.buf
: plop_tab
[(int)(unsigned char)*s
].buf
, l
, 0);
2235 * if no shortcut, we construct a buffer
2237 if ((dbuf
= (char *)malloc(l
)) == 0)
2244 * concatenate all sources into our own buffer, copy buffer is
2245 * special and is skipped if no display exists.
2247 for (ss
= s
; (ch
= *ss
); ss
++)
2249 struct plop
*pp
= (ch
== '.' ? &user
->u_plop
: &plop_tab
[(int)(unsigned char)ch
]);
2253 l
+= RecodeBuf((unsigned char *)pp
->buf
, pp
->len
, pp
->enc
, enc
, (unsigned char *)dbuf
+ l
);
2257 bcopy(pp
->buf
, dbuf
+ l
, pp
->len
);
2261 * when called with one argument we paste our buffer into the window
2265 MakePaster(&fore
->w_paster
, dbuf
, l
, 1);
2270 * we have two arguments, the second is already in dch.
2271 * use this as destination rather than the window.
2276 if (user
->u_plop
.buf
!= NULL
)
2277 UserFreeCopyBuffer(user
);
2278 user
->u_plop
.buf
= dbuf
;
2279 user
->u_plop
.len
= l
;
2281 user
->u_plop
.enc
= enc
;
2286 struct plop
*pp
= plop_tab
+ (int)(unsigned char)dch
;
2299 if (!user
->u_plop
.buf
)
2301 Msg(0, "empty buffer");
2306 struct plop oldplop
;
2308 oldplop
= user
->u_plop
;
2309 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2314 enc
= FindEncoding(args
[1]);
2317 Msg(0, "%s: writebuf: unknown encoding", rc_name
);
2320 if (enc
!= oldplop
.enc
)
2322 l
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)0);
2323 newbuf
= malloc(l
+ 1);
2329 user
->u_plop
.len
= RecodeBuf((unsigned char *)oldplop
.buf
, oldplop
.len
, oldplop
.enc
, enc
, (unsigned char *)newbuf
);
2330 user
->u_plop
.buf
= newbuf
;
2331 user
->u_plop
.enc
= enc
;
2336 if (args
[0] && args
[1])
2337 Msg(0, "%s: writebuf: too many arguments", rc_name
);
2339 WriteFile(user
, args
[0], DUMP_EXCHANGE
);
2341 if (user
->u_plop
.buf
!= oldplop
.buf
)
2342 free(user
->u_plop
.buf
);
2343 user
->u_plop
= oldplop
;
2349 i
= fore
? fore
->w_encoding
: display
? display
->d_encoding
: 0;
2350 if (args
[0] && args
[1] && !strcmp(args
[0], "-e"))
2352 i
= FindEncoding(args
[1]);
2355 Msg(0, "%s: readbuf: unknown encoding", rc_name
);
2361 if (args
[0] && args
[1])
2363 Msg(0, "%s: readbuf: too many arguments", rc_name
);
2366 if ((s
= ReadFile(args
[0] ? args
[0] : BufferFile
, &n
)))
2368 if (user
->u_plop
.buf
)
2369 UserFreeCopyBuffer(user
);
2370 user
->u_plop
.len
= n
;
2371 user
->u_plop
.buf
= s
;
2373 user
->u_plop
.enc
= i
;
2381 (void)ParseSwitch(act
, &search_ic
);
2383 Msg(0, "Will %signore case in searches", search_ic
? "" : "not ");
2385 #endif /* COPY_PASTE */
2388 SetEscape(user
, -1, -1);
2389 else if (*argl
== 2)
2390 SetEscape(user
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2393 Msg(0, "%s: two characters required after escape.", rc_name
);
2396 /* Change defescape if master user. This is because we only
2399 if (display
&& user
!= users
)
2404 SetEscape(NULL
, -1, -1);
2405 else if (*argl
== 2)
2406 SetEscape(NULL
, (int)(unsigned char)args
[0][0], (int)(unsigned char)args
[0][1]);
2409 Msg(0, "%s: two characters required after defescape.", rc_name
);
2417 s
= *args
? *args
: home
;
2419 Msg(errno
, "%s", s
);
2423 if (ParseSaveStr(act
, &ShellProg
) == 0)
2424 ShellArgs
[0] = ShellProg
;
2426 case RC_HARDCOPYDIR
:
2428 (void)ParseSaveStr(act
, &hardcopydir
);
2430 Msg(0, "hardcopydir is %s\n", hardcopydir
&& *hardcopydir
? hardcopydir
: "<cwd>");
2435 if (args
[1] && !(strcmp(*args
, "flush")))
2437 log_flush
= atoi(args
[1]);
2439 Msg(0, "log flush timeout set to %ds\n", log_flush
);
2442 if (ParseSaveStr(act
, &screenlogfile
) || !msgok
)
2445 Msg(0, "logfile is '%s'", screenlogfile
);
2448 if (!*args
|| !strcmp(*args
, "on") || !strcmp(*args
, "off"))
2450 if (ParseSwitch(act
, &logtstamp_on
) == 0 && msgok
)
2451 Msg(0, "timestamps turned %s", logtstamp_on
? "on" : "off");
2453 else if (!strcmp(*args
, "string"))
2457 if (logtstamp_string
)
2458 free(logtstamp_string
);
2459 logtstamp_string
= SaveStr(args
[1]);
2462 Msg(0, "logfile timestamp is '%s'", logtstamp_string
);
2464 else if (!strcmp(*args
, "after"))
2468 logtstamp_after
= atoi(args
[1]);
2472 Msg(0, "timestamp printed after %ds\n", logtstamp_after
);
2475 Msg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
2478 (void)ParseSaveStr(act
, &nwin_default
.aka
);
2481 case RC_TERMCAPINFO
:
2483 if (!rc_name
|| !*rc_name
)
2484 Msg(0, "Sorry, too late now. Place that in your .screenrc file.");
2487 break; /* Already handled */
2490 if (ParseSaveStr(act
, &s
))
2492 if (strlen(s
) >= 20)
2494 Msg(0, "%s: term: argument too long ( < 20)", rc_name
);
2498 strcpy(screenterm
, s
);
2500 debug1("screenterm set to %s\n", screenterm
);
2501 MakeTermcap((display
== 0));
2502 debug("new termcap made\n");
2505 if (!msgok
&& (!rc_name
|| strcmp(rc_name
, "-X")))
2508 * user typed ^A:echo... well, echo isn't FinishRc's job,
2509 * but as he wanted to test us, we show good will
2511 if (argc
> 1 && !strcmp(*args
, "-n"))
2517 if (argc
> 1 && !strcmp(*args
, "-p"))
2523 s
= MakeWinMsg(s
, fore
, '%');
2528 Msg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name
);
2535 AddXChars(buf
, sizeof(buf
), BellString
);
2536 Msg(0, "bell_msg is '%s'", buf
);
2539 (void)ParseSaveStr(act
, &BellString
);
2544 BufferFile
= SaveStr(DEFAULT_BUFFERFILE
);
2545 else if (ParseSaveStr(act
, &BufferFile
))
2548 Msg(0, "Bufferfile is now '%s'", BufferFile
);
2552 (void)ParseSaveStr(act
, &ActivityString
);
2554 #if defined(DETACH) && defined(POW_DETACH)
2555 case RC_POW_DETACH_MSG
:
2559 AddXChars(buf
, sizeof(buf
), PowDetachString
);
2560 Msg(0, "pow_detach_msg is '%s'", buf
);
2563 (void)ParseSaveStr(act
, &PowDetachString
);
2566 #if defined(UTMPOK) && defined(LOGOUTOK)
2568 n
= fore
->w_slot
!= (slot_t
)-1;
2569 if (*args
&& !strcmp(*args
, "always"))
2576 if (*args
&& !strcmp(*args
, "attached"))
2583 if (ParseSwitch(act
, &n
) == 0)
2587 if (!strcmp(*args
, "always"))
2588 nwin_default
.lflag
|= 2;
2589 else if (!strcmp(*args
, "attached"))
2590 nwin_default
.lflag
&= ~2;
2592 (void)ParseOnOff(act
, &nwin_default
.lflag
);
2596 if (args
[0] && args
[1] && args
[1][0] == 'i')
2599 for (display
= displays
; display
; display
= display
->d_next
)
2603 #if defined(TERMIO) || defined(POSIX)
2604 D_NewMode
.tio
.c_cc
[VINTR
] = D_OldMode
.tio
.c_cc
[VINTR
];
2605 D_NewMode
.tio
.c_lflag
|= ISIG
;
2606 #else /* TERMIO || POSIX */
2607 D_NewMode
.m_tchars
.t_intrc
= D_OldMode
.m_tchars
.t_intrc
;
2608 #endif /* TERMIO || POSIX */
2609 SetTTY(D_userfd
, &D_NewMode
);
2612 if (args
[0] && args
[0][0] == 'a')
2613 nwin_default
.flowflag
= FLOW_AUTOFLAG
;
2615 (void)ParseOnOff(act
, &nwin_default
.flowflag
);
2618 (void)ParseOnOff(act
, &nwin_default
.wrap
);
2621 (void)ParseOnOff(act
, &nwin_default
.c1
);
2625 (void)ParseOnOff(act
, &nwin_default
.bce
);
2629 (void)ParseOnOff(act
, &nwin_default
.gr
);
2632 if (ParseOnOff(act
, &n
) == 0)
2633 nwin_default
.monitor
= (n
== 0) ? MON_OFF
: MON_ON
;
2636 if (ParseOnOff(act
, &n
) == 0)
2637 nwin_default
.silence
= (n
== 0) ? SILENCE_OFF
: SILENCE_ON
;
2641 Msg(0, "W%s echo command when creating windows.",
2642 VerboseCreate
? "ill" : "on't");
2643 else if (ParseOnOff(act
, &n
) == 0)
2649 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
2652 if (args
[0] && strcmp(args
[0], "on") && strcmp(args
[0], "off"))
2654 struct display
*olddisplay
= display
;
2655 int old_use
, new_use
= -1;
2658 if (!strncmp(s
, "always", 6))
2660 if (!strcmp(s
, "lastline"))
2661 new_use
= HSTATUS_LASTLINE
;
2662 else if (!strcmp(s
, "ignore"))
2663 new_use
= HSTATUS_IGNORE
;
2664 else if (!strcmp(s
, "message"))
2665 new_use
= HSTATUS_MESSAGE
;
2666 else if (!strcmp(args
[0], "string"))
2671 AddXChars(buf
, sizeof(buf
), hstatusstring
);
2672 Msg(0, "hardstatus string is '%s'", buf
);
2678 Msg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name
);
2683 hardstatusemu
= new_use
| (s
== args
[0] ? 0 : HSTATUS_ALWAYS
);
2684 for (display
= displays
; display
; display
= display
->d_next
)
2687 new_use
= hardstatusemu
& ~HSTATUS_ALWAYS
;
2688 if (D_HS
&& s
== args
[0])
2689 new_use
= HSTATUS_HS
;
2690 ShowHStatus((char *)0);
2691 old_use
= D_has_hstatus
;
2692 D_has_hstatus
= new_use
;
2693 if ((new_use
== HSTATUS_LASTLINE
&& old_use
!= HSTATUS_LASTLINE
) || (new_use
!= HSTATUS_LASTLINE
&& old_use
== HSTATUS_LASTLINE
))
2694 ChangeScreenSize(D_width
, D_height
, 1);
2701 free(hstatusstring
);
2702 hstatusstring
= SaveStr(args
[1]);
2703 for (display
= displays
; display
; display
= display
->d_next
)
2706 display
= olddisplay
;
2709 (void)ParseSwitch(act
, &use_hardstatus
);
2711 Msg(0, "messages displayed on %s", use_hardstatus
? "hardstatus line" : "window");
2714 if (strcmp(args
[0], "always") == 0 || strcmp(args
[0], "splitonly") == 0)
2716 struct display
*olddisplay
= display
;
2718 captionalways
= args
[0][0] == 'a';
2719 for (display
= displays
; display
; display
= display
->d_next
)
2720 ChangeScreenSize(D_width
, D_height
, 1);
2721 display
= olddisplay
;
2723 else if (strcmp(args
[0], "string") == 0)
2728 AddXChars(buf
, sizeof(buf
), captionstring
);
2729 Msg(0, "caption string is '%s'", buf
);
2735 Msg(0, "%s: usage: caption always|splitonly|string <string>", rc_name
);
2741 free(captionstring
);
2742 captionstring
= SaveStr(args
[1]);
2743 RedisplayDisplays(0);
2746 n
= (console_window
!= 0);
2747 if (ParseSwitch(act
, &n
))
2749 if (TtyGrabConsole(fore
->w_ptyfd
, n
, rc_name
))
2752 Msg(0, "%s: releasing console %s", rc_name
, HostName
);
2753 else if (console_window
)
2754 Msg(0, "%s: stealing console %s from window %d (%s)", rc_name
,
2755 HostName
, console_window
->w_number
, console_window
->w_title
);
2757 Msg(0, "%s: grabbing console %s", rc_name
, HostName
);
2758 console_window
= n
? fore
: 0;
2761 if (ParseOnOff(act
, &all_norefresh
))
2763 if (!all_norefresh
&& fore
)
2766 Msg(0, all_norefresh
? "No refresh on window change!\n" :
2767 "Window specific refresh\n");
2770 (void)ParseSwitch(act
, &n
);
2771 fore
->w_norefresh
= n
;
2774 if (ParseSwitch(act
, &visual_bell
) || !msgok
)
2776 if (visual_bell
== 0)
2777 Msg(0, "switched to audible bell.");
2779 Msg(0, "switched to visual bell.");
2782 if (ParseNum1000(act
, &VBellWait
) == 0 && msgok
)
2783 Msg(0, "vbellwait set to %.10g seconds", VBellWait
/1000.);
2786 if (ParseNum1000(act
, &MsgWait
) == 0 && msgok
)
2787 Msg(0, "msgwait set to %.10g seconds", MsgWait
/1000.);
2790 if (ParseNum1000(act
, &MsgMinWait
) == 0 && msgok
)
2791 Msg(0, "msgminwait set to %.10g seconds", MsgMinWait
/1000.);
2793 case RC_SILENCEWAIT
:
2794 if (ParseNum(act
, &SilenceWait
))
2796 if (SilenceWait
< 1)
2798 for (p
= windows
; p
; p
= p
->w_next
)
2799 p
->w_silencewait
= SilenceWait
;
2801 Msg(0, "silencewait set to %d seconds", SilenceWait
);
2805 Msg(0, "This is window %d (%s).\n", fore
->w_number
, fore
->w_title
);
2808 int old
= fore
->w_number
;
2810 if (args
[0][0] == '+')
2812 else if (args
[0][0] == '-')
2816 parse
= ParseNum(act
, &n
);
2825 if (n
< 0 || n
>= maxwin
)
2827 Msg(0, "Given window position is invalid.");
2837 /* exchange the acls for these windows. */
2841 /* exchange the utmp-slots for these windows */
2842 if ((fore
->w_slot
!= (slot_t
) -1) && (fore
->w_slot
!= (slot_t
) 0))
2847 if (p
&& (p
->w_slot
!= (slot_t
) -1) && (p
->w_slot
!= (slot_t
) 0))
2849 /* XXX: first display wins? */
2850 display
= fore
->w_layer
.l_cvlist
? fore
->w_layer
.l_cvlist
->c_display
: 0;
2856 WindowChanged(fore
, 'n');
2857 WindowChanged((struct win
*)0, 'w');
2858 WindowChanged((struct win
*)0, 'W');
2859 WindowChanged((struct win
*)0, 0);
2863 n
= fore
->w_silence
!= 0;
2864 i
= fore
->w_silencewait
;
2865 if (args
[0] && (args
[0][0] == '-' || (args
[0][0] >= '0' && args
[0][0] <= '9')))
2867 if (ParseNum(act
, &i
))
2871 else if (ParseSwitch(act
, &n
))
2876 if (display
) /* we tell only this user */
2877 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
) |= ACLBIT(D_user
->u_id
);
2879 for (n
= 0; n
< maxusercount
; n
++)
2880 ACLBYTE(fore
->w_lio_notify
, n
) |= ACLBIT(n
);
2882 fore
->w_silencewait
= i
;
2883 fore
->w_silence
= SILENCE_ON
;
2884 SetTimeout(&fore
->w_silenceev
, fore
->w_silencewait
* 1000);
2885 evenq(&fore
->w_silenceev
);
2889 Msg(0, "The window is now being monitored for %d sec. silence.", fore
->w_silencewait
);
2894 if (display
) /* we remove only this user */
2895 ACLBYTE(fore
->w_lio_notify
, D_user
->u_id
)
2896 &= ~ACLBIT(D_user
->u_id
);
2898 for (n
= 0; n
< maxusercount
; n
++)
2899 ACLBYTE(fore
->w_lio_notify
, n
) &= ~ACLBIT(n
);
2900 for (i
= maxusercount
- 1; i
>= 0; i
--)
2901 if (ACLBYTE(fore
->w_lio_notify
, i
))
2906 fore
->w_silence
= SILENCE_OFF
;
2907 evdeq(&fore
->w_silenceev
);
2911 Msg(0, "The window is no longer being monitored for silence.");
2915 case RC_DEFSCROLLBACK
:
2916 (void)ParseNum(act
, &nwin_default
.histheight
);
2919 if (flayer
->l_layfn
== &MarkLf
)
2921 Msg(0, "Cannot resize scrollback buffer in copy/scrollback mode.");
2924 (void)ParseNum(act
, &n
);
2925 ChangeWindowSize(fore
, fore
->w_width
, fore
->w_height
, n
);
2927 Msg(0, "scrollback set to %d", fore
->w_histheight
);
2930 case RC_SESSIONNAME
:
2932 Msg(0, "This session is named '%s'\n", SockName
);
2935 char buf
[MAXPATHLEN
];
2938 if (ParseSaveStr(act
, &s
))
2940 if (!*s
|| strlen(s
) + (SockName
- SockPath
) > MAXPATHLEN
- 13 || index(s
, '/'))
2942 Msg(0, "%s: bad session name '%s'\n", rc_name
, s
);
2946 strncpy(buf
, SockPath
, SockName
- SockPath
);
2947 sprintf(buf
+ (SockName
- SockPath
), "%d.%s", (int)getpid(), s
);
2949 if ((access(buf
, F_OK
) == 0) || (errno
!= ENOENT
))
2951 Msg(0, "%s: inappropriate path: '%s'.", rc_name
, buf
);
2954 if (rename(SockPath
, buf
))
2956 Msg(errno
, "%s: failed to rename(%s, %s)", rc_name
, SockPath
, buf
);
2959 debug2("rename(%s, %s) done\n", SockPath
, buf
);
2960 strcpy(SockPath
, buf
);
2965 if (!args
[0] || !args
[1])
2967 debug1("RC_SETENV arguments missing: %s\n", args
[0] ? args
[0] : "");
2968 InputSetenv(args
[0]);
2972 xsetenv(args
[0], args
[1]);
2981 case RC_DEFSLOWPASTE
:
2982 (void)ParseNum(act
, &nwin_default
.slow
);
2986 Msg(0, fore
->w_slowpaste
?
2987 "Slowpaste in window %d is %d milliseconds." :
2988 "Slowpaste in window %d is unset.",
2989 fore
->w_number
, fore
->w_slowpaste
);
2990 else if (ParseNum(act
, &fore
->w_slowpaste
) == 0 && msgok
)
2991 Msg(0, fore
->w_slowpaste
?
2992 "Slowpaste in window %d set to %d milliseconds." :
2993 "Slowpaste in window %d now unset.",
2994 fore
->w_number
, fore
->w_slowpaste
);
2997 if (CompileKeys(*args
, *argl
, mark_key_tab
))
2999 Msg(0, "%s: markkeys: syntax error.", rc_name
);
3002 debug1("markkeys %s\n", *args
);
3006 if (ParseSwitch(act
, &pastefont
) == 0 && msgok
)
3007 Msg(0, "Will %spaste font settings", pastefont
? "" : "not ");
3011 (void)ParseSwitch(act
, &join_with_cr
);
3013 case RC_COMPACTHIST
:
3014 if (ParseSwitch(act
, &compacthist
) == 0 && msgok
)
3015 Msg(0, "%scompacting history lines", compacthist
? "" : "not ");
3020 (void)ParseOnOff(act
, &nethackflag
);
3023 case RC_HARDCOPY_APPEND
:
3024 (void)ParseOnOff(act
, &hardcopy_append
);
3030 AddXChars(buf
, sizeof(buf
), VisualBellString
);
3031 Msg(0, "vbell_msg is '%s'", buf
);
3034 (void)ParseSaveStr(act
, &VisualBellString
);
3035 debug1(" new vbellstr '%s'\n", VisualBellString
);
3038 if (ParseBase(act
, *args
, &n
, 8, "octal"))
3040 if (n
< 0 || n
> 0777)
3042 Msg(0, "%s: mode: Invalid tty mode %o", rc_name
, n
);
3047 Msg(0, "Ttymode set to %03o", TtyMode
);
3050 (void)ParseOnOff(act
, &auto_detach
);
3052 case RC_STARTUP_MESSAGE
:
3053 (void)ParseOnOff(act
, &default_startup
);
3059 n
= (*user
->u_password
) ? 1 : 0;
3060 if (user
->u_password
!= NullStr
) free((char *)user
->u_password
);
3061 user
->u_password
= SaveStr(*args
);
3062 if (!strcmp(user
->u_password
, "none"))
3065 Msg(0, "Password checking disabled");
3066 free(user
->u_password
);
3067 user
->u_password
= NullStr
;
3074 Msg(0, "%s: password: window required", rc_name
);
3077 Input("New screen password:", 100, INP_NOECHO
, pass1
, display
? (char *)D_user
: (char *)users
, 0);
3080 #endif /* PASSWORD */
3083 struct action
*ktabp
= ktab
;
3088 if (argc
> 2 && !strcmp(*args
, "-c"))
3090 ktabp
= FindKtab(args
[1], 1);
3097 else if (argc
> 1 && !strcmp(*args
, "-k"))
3110 for (n
= 0; n
< KMAP_KEYS
; n
++)
3111 if (strcmp(term
[n
+ T_CAPS
].tcname
, *args
) == 0)
3115 Msg(0, "%s: bind: unknown key '%s'", rc_name
, *args
);
3124 Msg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name
);
3128 n
= (unsigned char)args
[0][0];
3132 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3134 Msg(0, "%s: bind: unknown command '%s'", rc_name
, args
[1]);
3137 if (CheckArgNum(i
, args
+ 2) < 0)
3139 ClearAction(&ktabp
[n
]);
3140 SaveAction(ktabp
+ n
, i
, args
+ 2, argl
+ 2);
3143 ClearAction(&ktabp
[n
]);
3149 struct action
*newact
;
3150 int newnr
, fl
= 0, kf
= 0, af
= 0, df
= 0, mf
= 0;
3151 struct display
*odisp
= display
;
3153 struct kmap_ext
*kme
;
3155 for (; *args
&& **args
== '-'; args
++, argl
++)
3157 if (strcmp(*args
, "-t") == 0)
3158 fl
= KMAP_NOTIMEOUT
;
3159 else if (strcmp(*args
, "-k") == 0)
3161 else if (strcmp(*args
, "-a") == 0)
3163 else if (strcmp(*args
, "-d") == 0)
3165 else if (strcmp(*args
, "-m") == 0)
3167 else if (strcmp(*args
, "--") == 0)
3175 Msg(0, "%s: bindkey: invalid option %s", rc_name
, *args
);
3181 Msg(0, "%s: bindkey: -d does not work with -m", rc_name
);
3187 display_bindkey("Edit mode", mmtab
);
3189 display_bindkey("Default", dmtab
);
3191 display_bindkey("User", umtab
);
3198 Msg(0, "%s: bindkey: -a only works with -k", rc_name
);
3203 Msg(0, "%s: bindkey: empty string makes no sense", rc_name
);
3206 for (i
= 0, kme
= kmap_exts
; i
< kmap_extn
; i
++, kme
++)
3213 if (*argl
== (kme
->fl
& ~KMAP_NOTIMEOUT
) && bcmp(kme
->str
, *args
, *argl
) == 0)
3219 Msg(0, "%s: bindkey: keybinding not found", rc_name
);
3223 kmap_exts
= (struct kmap_ext
*)xrealloc((char *)kmap_exts
, kmap_extn
* sizeof(*kmap_exts
));
3224 kme
= kmap_exts
+ i
;
3225 bzero((char *)kme
, 8 * sizeof(*kmap_exts
));
3226 for (; i
< kmap_extn
; i
++, kme
++)
3229 kme
->dm
.nr
= kme
->mm
.nr
= kme
->um
.nr
= RC_ILLEGAL
;
3230 kme
->dm
.args
= kme
->mm
.args
= kme
->um
.args
= noargs
;
3235 if (df
== 0 && kme
->dm
.nr
!= RC_ILLEGAL
)
3237 if (mf
== 0 && kme
->mm
.nr
!= RC_ILLEGAL
)
3239 if ((df
|| mf
) && kme
->um
.nr
!= RC_ILLEGAL
)
3241 i
+= KMAP_KEYS
+ KMAP_AKEYS
;
3242 newact
= df
? &kme
->dm
: mf
? &kme
->mm
: &kme
->um
;
3246 for (i
= T_CAPS
; i
< T_OCAPS
; i
++)
3247 if (strcmp(term
[i
].tcname
, *args
) == 0)
3251 Msg(0, "%s: bindkey: unknown key '%s'", rc_name
, *args
);
3254 if (af
&& i
>= T_CURSOR
&& i
< T_OCAPS
)
3255 i
-= T_CURSOR
- KMAP_KEYS
;
3258 newact
= df
? &dmtab
[i
] : mf
? &mmtab
[i
] : &umtab
[i
];
3262 if ((newnr
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3264 Msg(0, "%s: bindkey: unknown command '%s'", rc_name
, args
[1]);
3267 if (CheckArgNum(newnr
, args
+ 2) < 0)
3269 ClearAction(newact
);
3270 SaveAction(newact
, newnr
, args
+ 2, argl
+ 2);
3271 if (kf
== 0 && args
[1])
3275 kme
->str
= SaveStrn(*args
, *argl
);
3276 kme
->fl
= fl
| *argl
;
3280 ClearAction(newact
);
3281 for (display
= displays
; display
; display
= display
->d_next
)
3282 remap(i
, args
[1] ? 1 : 0);
3283 if (kf
== 0 && !args
[1])
3285 if (!used
&& kme
->str
)
3298 if (ParseNum(act
, &n
))
3302 Msg(0, "%s: maptimeout: illegal time %d", rc_name
, n
);
3307 if (*args
== 0 || msgok
)
3308 Msg(0, "maptimeout is %dms", maptimeout
);
3322 UsersAcl(NULL
, argc
, args
);
3325 if (UserDel(args
[0], NULL
))
3328 Msg(0, "%s removed from acl database", args
[0]);
3332 * modify a user to gain or lose rights granted to a group.
3333 * This group is actually a normal user whose rights were defined
3334 * with chacl in the usual way.
3338 if (strcmp(args
[1], "none")) /* link a user to another user */
3340 if (AclLinkUser(args
[0], args
[1]))
3343 Msg(0, "User %s joined acl-group %s", args
[0], args
[1]);
3345 else /* remove all groups from user */
3348 struct aclusergroup
*g
;
3350 if (!(u
= *FindUserPtr(args
[0])))
3352 while ((g
= u
->u_group
))
3354 u
->u_group
= g
->next
;
3359 else /* show all groups of user */
3361 char buf
[256], *p
= buf
;
3364 struct aclusergroup
*g
;
3366 if (!(u
= *FindUserPtr(args
[0])))
3369 Msg(0, "User %s does not exist.", args
[0]);
3376 sprintf(p
, "%s ", g
->u
->u_name
);
3384 Msg(0, "%s's group%s: %s.", args
[0], (ngroups
== 1) ? "" : "s",
3385 (ngroups
== 0) ? "none" : buf
);
3390 while ((s
= *args
++))
3394 if (AclUmask(display
? D_user
: users
, s
, &err
))
3395 Msg(0, "umask: %s\n", err
);
3399 if (ParseOnOff(act
, &n
))
3404 Msg(0, "Multiuser mode %s", multi
? "enabled" : "disabled");
3406 #endif /* MULTIUSER */
3414 i
= D_nonblock
>= 0;
3415 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3417 if (ParseNum1000(act
, &i
))
3420 else if (!ParseSwitch(act
, &i
))
3421 i
= i
== 0 ? -1 : 1000;
3424 if (msgok
&& i
== -1)
3425 Msg(0, "display set to blocking mode");
3426 else if (msgok
&& i
== 0)
3427 Msg(0, "display set to nonblocking mode, no timeout");
3429 Msg(0, "display set to nonblocking mode, %.10gs timeout", i
/1000.);
3431 if (D_nonblock
<= 0)
3432 evdeq(&D_blockedev
);
3434 case RC_DEFNONBLOCK
:
3435 if (*args
&& ((args
[0][0] >= '0' && args
[0][0] <= '9') || args
[0][0] == '.'))
3437 if (ParseNum1000(act
, &defnonblock
))
3440 else if (!ParseOnOff(act
, &defnonblock
))
3441 defnonblock
= defnonblock
== 0 ? -1 : 1000;
3444 if (display
&& *rc_name
)
3446 D_nonblock
= defnonblock
;
3447 if (D_nonblock
<= 0)
3448 evdeq(&D_blockedev
);
3454 if (fore
->w_gr
== 2)
3457 if (ParseSwitch(act
, &fore
->w_gr
) == 0 && msgok
)
3458 Msg(0, "Will %suse GR", fore
->w_gr
? "" : "not ");
3460 if (fore
->w_gr
== 0 && fore
->w_FontE
)
3465 if (ParseSwitch(act
, &fore
->w_c1
) == 0 && msgok
)
3466 Msg(0, "Will %suse C1", fore
->w_c1
? "" : "not ");
3470 if (ParseSwitch(act
, &fore
->w_bce
) == 0 && msgok
)
3471 Msg(0, "Will %serase with background color", fore
->w_bce
? "" : "not ");
3478 if (*args
&& !strcmp(args
[0], "-d"))
3481 Msg(0, "encodings directory is %s", screenencodings
? screenencodings
: "<unset>");
3484 free(screenencodings
);
3485 screenencodings
= SaveStr(args
[1]);
3489 if (*args
&& !strcmp(args
[0], "-l"))
3492 Msg(0, "encoding: -l: argument required");
3493 else if (LoadFontTranslation(-1, args
[1]))
3494 Msg(0, "encoding: could not load utf8 encoding file");
3496 Msg(0, "encoding: utf8 encoding file loaded");
3500 if (*args
&& (!strcmp(args
[0], "-l") || !strcmp(args
[0], "-d")))
3503 Msg(0, "encoding: screen is not compiled for UTF-8.");
3507 for (i
= 0; i
< 2; i
++)
3511 if (!strcmp(args
[i
], "."))
3513 n
= FindEncoding(args
[i
]);
3516 Msg(0, "encoding: unknown encoding '%s'", args
[i
]);
3521 WinSwitchEncoding(fore
, n
);
3522 ResetCharsets(fore
);
3524 else if (i
&& display
)
3529 case RC_DEFENCODING
:
3530 n
= FindEncoding(*args
);
3533 Msg(0, "defencoding: unknown encoding '%s'", *args
);
3536 nwin_default
.encoding
= n
;
3542 n
= nwin_default
.encoding
== UTF8
;
3543 if (ParseSwitch(act
, &n
) == 0)
3545 nwin_default
.encoding
= n
? UTF8
: 0;
3547 Msg(0, "Will %suse UTF-8 encoding for new windows", n
? "" : "not ");
3551 for (i
= 0; i
< 2; i
++)
3553 if (i
&& args
[i
] == 0)
3556 n
= fore
->w_encoding
!= UTF8
;
3557 else if (strcmp(args
[i
], "off") == 0)
3559 else if (strcmp(args
[i
], "on") == 0)
3563 Msg(0, "utf8: illegal argument (%s)", args
[i
]);
3568 WinSwitchEncoding(fore
, n
? UTF8
: 0);
3570 Msg(0, "Will %suse UTF-8 encoding", n
? "" : "not ");
3573 D_encoding
= n
? UTF8
: 0;
3587 printcmd
= SaveStr(*args
);
3589 if (*args
== 0 || msgok
)
3592 Msg(0, "using '%s' as print command", printcmd
);
3594 Msg(0, "using termcap entries for printing");
3600 Input("Enter digraph: ", 10, INP_EVERY
, digraph_fn
, NULL
, 0);
3601 if (*args
&& **args
)
3614 if (nwin_default
.hstatus
)
3615 AddXChars(buf
, sizeof(buf
), nwin_default
.hstatus
);
3616 Msg(0, "default hstatus is '%s'", buf
);
3619 (void)ParseSaveStr(act
, &nwin_default
.hstatus
);
3620 if (*nwin_default
.hstatus
== 0)
3622 free(nwin_default
.hstatus
);
3623 nwin_default
.hstatus
= 0;
3627 (void)ParseSaveStr(act
, &fore
->w_hstatus
);
3628 if (*fore
->w_hstatus
== 0)
3630 free(fore
->w_hstatus
);
3631 fore
->w_hstatus
= 0;
3633 WindowChanged(fore
, 'h');
3643 if (nwin_default
.charset
)
3644 AddXChars(buf
, sizeof(buf
), nwin_default
.charset
);
3645 Msg(0, "default charset is '%s'", buf
);
3649 if (n
== 0 || n
> 6)
3651 Msg(0, "%s: %s: string has illegal size.", rc_name
, comms
[nr
].name
);
3655 ((args
[0][4] < '0' || args
[0][4] > '3') && args
[0][4] != '.') ||
3656 ((args
[0][5] < '0' || args
[0][5] > '3') && args
[0][5] && args
[0][5] != '.')))
3658 Msg(0, "%s: %s: illegal mapping number.", rc_name
, comms
[nr
].name
);
3661 if (nr
== RC_CHARSET
)
3663 SetCharsets(fore
, *args
);
3666 if (nwin_default
.charset
)
3667 free(nwin_default
.charset
);
3668 nwin_default
.charset
= SaveStr(*args
);
3674 if (*s
>= '0' && *s
<= '9')
3677 for (i
= 0; i
< 8; i
++)
3678 if (*s
== "dubrsBiI"[i
])
3682 if (*s
&& s
[1] && !s
[2])
3684 if (*s
== 'd' && s
[1] == 'd')
3686 else if (*s
== '.' && s
[1] == 'd')
3688 else if (*s
== 'd' && s
[1] == '.')
3690 else if (*s
!= '.' || s
[1] != '.')
3694 if (*s
|| i
< 0 || i
>= 8)
3696 Msg(0, "%s: attrcolor: unknown attribute '%s'.", rc_name
, args
[0]);
3701 n
= ParseAttrColor(args
[1], args
[2], 1);
3704 attr2color
[i
][nr
] = n
;
3706 for (i
= 0; i
< 8; i
++)
3707 if (attr2color
[i
][0] || attr2color
[i
][1] || attr2color
[i
][2] || attr2color
[i
][3])
3712 case RC_SORENDITION
:
3716 i
= ParseAttrColor(*args
, args
[1], 1);
3719 ApplyAttrColor(i
, &mchar_so
);
3720 debug2("--> %x %x\n", mchar_so
.attr
, mchar_so
.color
);
3724 Msg(0, "Standout attributes 0x%02x color 0x%02x", (unsigned char)mchar_so
.attr
, 0x99 ^ (unsigned char)mchar_so
.color
);
3726 Msg(0, "Standout attributes 0x%02x ", (unsigned char)mchar_so
.attr
);
3739 ScriptSource(*args
);
3747 Msg(0, "%s:%s screen login", HostName
, SockPath
);
3748 InputSu(D_fore
, &D_user
, NULL
);
3751 InputSu(D_fore
, &D_user
, args
[0]);
3753 s
= DoSu(&D_user
, args
[0], args
[1], "\377");
3755 s
= DoSu(&D_user
, args
[0], args
[1], args
[2]);
3759 #endif /* MULTIUSER */
3762 if (s
&& !strcmp(s
, "-v"))
3763 AddCanvas(SLICE_HORI
);
3765 AddCanvas(SLICE_VERT
);
3777 D_forecv
->c_xoff
= D_forecv
->c_xs
;
3778 D_forecv
->c_yoff
= D_forecv
->c_ys
;
3779 RethinkViewportOffsets(D_forecv
);
3780 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, 0);
3781 flayer
= D_forecv
->c_layer
;
3785 if (!*args
|| !strcmp(*args
, "down"))
3786 D_forecv
= D_forecv
->c_next
? D_forecv
->c_next
: D_cvlist
;
3787 else if (!strcmp(*args
, "up"))
3790 for (cv
= D_cvlist
; cv
->c_next
&& cv
->c_next
!= D_forecv
; cv
= cv
->c_next
)
3794 else if (!strcmp(*args
, "top"))
3795 D_forecv
= D_cvlist
;
3796 else if (!strcmp(*args
, "bottom"))
3799 for (cv
= D_cvlist
; cv
->c_next
; cv
= cv
->c_next
)
3805 Msg(0, "%s: usage: focus [up|down|top|bottom]", rc_name
);
3808 if ((focusminwidth
&& (focusminwidth
< 0 || D_forecv
->c_xe
- D_forecv
->c_xs
+ 1 < focusminwidth
)) ||
3809 (focusminheight
&& (focusminheight
< 0 || D_forecv
->c_ye
- D_forecv
->c_ys
+ 1 < focusminheight
)))
3811 ResizeCanvas(&D_canvas
);
3812 RecreateCanvasChain();
3813 RethinkDisplayViewports();
3814 ResizeLayersToCanvases(); /* redisplays */
3816 fore
= D_fore
= Layer2Window(D_forecv
->c_layer
);
3817 flayer
= D_forecv
->c_layer
;
3819 if (D_xtermosc
[2] || D_xtermosc
[3])
3829 flayer
= D_forecv
->c_layer
;
3830 CV_CALL(D_forecv
, LayRestore();LaySetCursor());
3831 WindowChanged(0, 'F');
3835 if (D_forecv
->c_slorient
== SLICE_UNKN
)
3837 Msg(0, "resize: need more than one region");
3840 for (; *args
; args
++)
3842 if (!strcmp(*args
, "-h"))
3844 else if (!strcmp(*args
, "-v"))
3846 else if (!strcmp(*args
, "-b"))
3847 i
|= RESIZE_FLAG_H
| RESIZE_FLAG_V
;
3848 else if (!strcmp(*args
, "-p"))
3849 i
|= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
3850 else if (!strcmp(*args
, "-l"))
3855 if (*args
&& args
[1])
3857 Msg(0, "%s: usage: resize [-h] [-v] [-l] [num]\n", rc_name
);
3861 ResizeRegions(*args
, i
);
3863 Input(resizeprompts
[i
], 20, INP_EVERY
, ResizeFin
, (char*)0, i
);
3866 (void)ParseSwitch(act
, &separate_sids
);
3869 args
= SaveArgs(args
);
3870 for (i
= 0; args
[i
]; i
++)
3873 Colonfin(args
[i
], strlen(args
[i
]), (char *)0);
3879 (void)ParseSwitch(act
, &use_altscreen
);
3881 Msg(0, "Will %sdo alternate screen switching", use_altscreen
? "" : "not ");
3884 if (ParseNum(act
, &n
))
3887 Msg(0, "illegal maxwin number specified");
3888 else if (n
> maxwin
)
3889 Msg(0, "may only decrease maxwin number");
3894 if (ParseBase(act
, *args
, &n
, 10, "decimal"))
3897 setbacktick(n
, 0, 0, (char **)0);
3903 Msg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name
);
3906 if (ParseBase(act
, args
[1], &lifespan
, 10, "decimal"))
3908 if (ParseBase(act
, args
[2], &tick
, 10, "decimal"))
3910 setbacktick(n
, lifespan
, tick
, SaveArgs(args
+ 3));
3912 WindowChanged(0, '`');
3918 RunBlanker(blankerprg
);
3923 CursorVisibility(-1);
3931 for (pp
= blankerprg
; *pp
; pp
++)
3937 blankerprg
= SaveArgs(args
);
3943 struct display
*olddisplay
= display
;
3944 if (!strcmp(*args
, "off"))
3946 else if (args
[0][0])
3947 idletimo
= atoi(*args
) * 1000;
3950 if ((i
= FindCommnr(args
[1])) == RC_ILLEGAL
)
3952 Msg(0, "%s: idle: unknown command '%s'", rc_name
, args
[1]);
3955 if (CheckArgNum(i
, args
+ 2) < 0)
3957 ClearAction(&idleaction
);
3958 SaveAction(&idleaction
, i
, args
+ 2, argl
+ 2);
3960 for (display
= displays
; display
; display
= display
->d_next
)
3962 display
= olddisplay
;
3967 Msg(0, "idle timeout %ds, %s", idletimo
/ 1000, comms
[idleaction
.nr
].name
);
3972 case RC_FOCUSMINSIZE
:
3973 for (i
= 0; i
< 2 && args
[i
]; i
++)
3975 if (!strcmp(args
[i
], "max") || !strcmp(args
[i
], "_"))
3987 for (i
= 0; i
< 2; i
++)
3989 n
= i
== 0 ? focusminwidth
: focusminheight
;
3991 strcpy(b
[i
], "max");
3993 sprintf(b
[i
], "%d", n
);
3995 Msg(0, "focus min size is %s %s\n", b
[0], b
[1]);
4004 fore
->w_group
= WindowByName(*args
);
4005 if (fore
->w_group
&& fore
->w_group
->w_type
!= W_TYPE_GROUP
)
4008 WindowChanged((struct win
*)0, 'w');
4009 WindowChanged((struct win
*)0, 'W');
4010 WindowChanged((struct win
*)0, 0);
4015 Msg(0, "window group is %d (%s)\n", fore
->w_group
->w_number
, fore
->w_group
->w_title
);
4017 Msg(0, "window belongs to no group");
4021 if (!strcmp(args
[0], "title"))
4025 Msg(0, "not on a layout");
4030 Msg(0, "current layout is %d (%s)", D_layout
->lay_number
, D_layout
->lay_title
);
4033 free(D_layout
->lay_title
);
4034 D_layout
->lay_title
= SaveStr(args
[1]);
4036 else if (!strcmp(args
[0], "number"))
4042 Msg(0, "This is layout %d (%s).\n", D_layout
->lay_number
, D_layout
->lay_title
);
4045 old
= D_layout
->lay_number
;
4047 if (n
< 0 || n
>= MAXLAY
)
4050 laytab
[n
] = D_layout
;
4051 D_layout
->lay_number
= n
;
4054 lay
->lay_number
= old
;
4057 else if (!strcmp(args
[0], "autosave"))
4061 Msg(0, "not on a layout");
4066 if (!strcmp(args
[1], "on"))
4067 D_layout
->lay_autosave
= 1;
4068 else if (!strcmp(args
[1], "off"))
4069 D_layout
->lay_autosave
= 0;
4072 Msg(0, "invalid argument. Give 'on' or 'off");
4077 Msg(0, "autosave is %s", D_layout
->lay_autosave
? "on" : "off");
4079 else if (!strcmp(args
[0], "new"))
4085 while (*t
>= '0' && *t
<= '9')
4087 if (t
!= args
[1] && (!*t
|| *t
== ':'))
4101 else if (!strcmp(args
[0], "save"))
4105 Msg(0, "usage: layout save <name>");
4108 SaveLayout(args
[1], &D_canvas
);
4110 else if (!strcmp(args
[0], "select"))
4115 Input("Switch to layout: ", 20, INP_COOKED
, SelectLayoutFin
, NULL
, 0);
4118 SelectLayoutFin(args
[1], strlen(args
[1]), (char *)0);
4120 else if (!strcmp(args
[0], "next"))
4122 struct layout
*lay
= D_layout
;
4124 lay
= lay
->lay_next
? lay
->lay_next
: layouts
;
4129 Msg(0, "no layout defined");
4132 if (lay
== D_layout
)
4134 LoadLayout(lay
, &D_canvas
);
4137 else if (!strcmp(args
[0], "prev"))
4139 struct layout
*lay
= D_layout
;
4142 for (lay
= layouts
; lay
->lay_next
&& lay
->lay_next
!= D_layout
; lay
= lay
->lay_next
)
4149 Msg(0, "no layout defined");
4152 if (lay
== D_layout
)
4154 LoadLayout(lay
, &D_canvas
);
4157 else if (!strcmp(args
[0], "attach"))
4162 Msg(0, "no attach layout set");
4163 else if (layout_attach
== &layout_last_marker
)
4164 Msg(0, "will attach to last layout");
4166 Msg(0, "will attach to layout %d (%s)", layout_attach
->lay_number
, layout_attach
->lay_title
);
4169 if (!strcmp(args
[1], ":last"))
4170 layout_attach
= &layout_last_marker
;
4171 else if (!args
[1][0])
4176 lay
= FindLayout(args
[1]);
4179 Msg(0, "unknown layout '%s'", args
[1]);
4182 layout_attach
= lay
;
4185 else if (!strcmp(args
[0], "show"))
4190 Msg(0, "unknown layout subcommand");
4194 /* key == -2: input from braille keybord, msgok always 0 */
4195 DoBrailleAction(act
, key
== -2 ? 0 : msgok
);
4199 if (display
!= odisplay
)
4201 for (display
= displays
; display
; display
= display
->d_next
)
4202 if (display
== odisplay
)
4208 DoCommand(argv
, argl
)
4214 if ((act
.nr
= FindCommnr(*argv
)) == RC_ILLEGAL
)
4216 Msg(0, "%s: unknown command '%s'", rc_name
, *argv
);
4219 act
.args
= argv
+ 1;
4220 act
.argl
= argl
+ 1;
4225 SaveAction(act
, nr
, args
, argl
)
4231 register int argc
= 0;
4245 if ((pp
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4247 if ((lp
= (int *)malloc((unsigned)(argc
) * sizeof(int *))) == 0)
4254 *lp
= argl
? *argl
++ : (int)strlen(*args
);
4255 *pp
++ = SaveStrn(*args
++, *lp
++);
4264 register char **ap
, **pp
;
4265 register int argc
= 0;
4269 if ((pp
= ap
= (char **)malloc((unsigned)(argc
+ 1) * sizeof(char **))) == 0)
4272 *pp
++ = SaveStr(*args
++);
4279 * buf is split into argument vector args.
4280 * leading whitespace is removed.
4281 * @!| abbreviations are expanded.
4282 * the end of buffer is recognized by '\0' or an un-escaped '#'.
4283 * " and ' are interpreted.
4288 Parse(buf
, bufl
, args
, argl
)
4292 register char *p
= buf
, **ap
= args
, *pp
;
4293 register int delim
, argc
;
4296 debug2("Parse %d %s\n", bufl
, buf
);
4302 while (*p
&& (*p
== ' ' || *p
== '\t'))
4305 if (argc
== 0 && *p
== '!')
4314 if (*p
== '\0' || *p
== '#' || *p
== '\n')
4317 for (delim
= 0; delim
< argc
; delim
++)
4318 debug1("-- %s\n", args
[delim
]);
4322 if (++argc
>= MAXARGS
)
4324 Msg(0, "%s: too many tokens.", rc_name
);
4329 debug1("- new arg %s\n", p
);
4334 else if (delim
!= '\'' && *p
== '\\' && (p
[1] == '\'' || p
[1] == '"' || p
[1] == '\\' || p
[1] == '$' || p
[1] == '#' || p
[1] == '^' || (p
[1] >= '0' && p
[1] <= '7')))
4337 if (*p
>= '0' && *p
<= '7')
4340 if (p
[1] >= '0' && p
[1] <= '7')
4343 *pp
= (*pp
<< 3) | (*p
- '0');
4344 if (p
[1] >= '0' && p
[1] <= '7')
4347 *pp
= (*pp
<< 3) | (*p
- '0');
4355 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] == '_'))
4358 char *ps
, *pe
, op
, *v
, xbuf
[11];
4362 debug1("- var %s\n", ps
);
4366 if (*ps
== '{' && *p
== '}')
4368 if (*ps
== ':' && *p
== ':')
4370 if (*ps
!= '{' && *ps
!= ':' && (*p
< 'a' || *p
> 'z') && (*p
< 'A' || *p
> 'Z') && (*p
< '0' || *p
> '9') && *p
!= '_')
4375 if (*ps
== '{' || *ps
== ':')
4379 Msg(0, "%s: bad variable name.", rc_name
);
4386 debug1("- var is '%s'\n", ps
);
4388 v
= gettermcapstring(ps
+ 1);
4394 if (!strcmp(ps
, "TERM"))
4395 v
= display
? D_termname
: "unknown";
4396 else if (!strcmp(ps
, "COLUMNS"))
4397 sprintf(xbuf
, "%d", display
? D_width
: -1);
4398 else if (!strcmp(ps
, "LINES"))
4399 sprintf(xbuf
, "%d", display
? D_height
: -1);
4404 vl
= v
? strlen(v
) : 0;
4407 debug1("- sub is '%s'\n", v
);
4410 int right
= buf
+ bufl
- (p
+ strlen(p
) + 1);
4413 bcopy(p
, p
+ right
, strlen(p
) + 1);
4419 Msg(0, "%s: no space left for variable expansion.", rc_name
);
4427 else if (delim
!= '\'' && *p
== '^' && p
[1])
4430 *pp
++ = *p
== '?' ? '\177' : *p
& 0x1f;
4432 else if (delim
== 0 && (*p
== '\'' || *p
== '"'))
4434 else if (delim
== 0 && (*p
== ' ' || *p
== '\t' || *p
== '\n'))
4442 Msg(0, "%s: Missing %c quote.", rc_name
, delim
);
4448 debug2("- arg done, '%s' rest %s\n", ap
[-1], p
);
4449 *lp
++ = pp
- ap
[-1];
4468 if (DefaultEsc
>= 0)
4469 ClearAction(&ktab
[DefaultEsc
]);
4470 if (DefaultMetaEsc
>= 0)
4471 ClearAction(&ktab
[DefaultMetaEsc
]);
4474 DefaultMetaEsc
= me
;
4477 if (DefaultEsc
>= 0)
4479 ClearAction(&ktab
[DefaultEsc
]);
4480 ktab
[DefaultEsc
].nr
= RC_OTHER
;
4482 if (DefaultMetaEsc
>= 0)
4484 ClearAction(&ktab
[DefaultMetaEsc
]);
4485 ktab
[DefaultMetaEsc
].nr
= RC_META
;
4492 ParseSwitch(act
, var
)
4496 if (*act
->args
== 0)
4501 return ParseOnOff(act
, var
);
4505 ParseOnOff(act
, var
)
4509 register int num
= -1;
4510 char **args
= act
->args
;
4514 if (strcmp(args
[0], "on") == 0)
4516 else if (strcmp(args
[0], "off") == 0)
4521 Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name
, comms
[act
->nr
].name
);
4529 ParseSaveStr(act
, var
)
4533 char **args
= act
->args
;
4534 if (*args
== 0 || args
[1])
4536 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4541 *var
= SaveStr(*args
);
4551 char *p
, **args
= act
->args
;
4554 if (p
== 0 || *p
== 0 || args
[1])
4556 Msg(0, "%s: %s: invalid argument. Give one argument.",
4557 rc_name
, comms
[act
->nr
].name
);
4563 if (*p
>= '0' && *p
<= '9')
4564 i
= 10 * i
+ (*p
- '0');
4567 Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4568 rc_name
, comms
[act
->nr
].name
);
4573 debug1("ParseNum got %d\n", i
);
4579 ParseNum1000(act
, var
)
4584 char *p
, **args
= act
->args
;
4588 if (p
== 0 || *p
== 0 || args
[1])
4590 Msg(0, "%s: %s: invalid argument. Give one argument.",
4591 rc_name
, comms
[act
->nr
].name
);
4597 if (*p
>= '0' && *p
<= '9')
4600 i
= 10 * i
+ (*p
- '0');
4601 else if (dig
== 4 && *p
>= '5')
4606 else if (*p
== '.' && !dig
)
4610 Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4611 rc_name
, comms
[act
->nr
].name
);
4622 i
= (int)((unsigned int)~0 >> 1);
4623 debug1("ParseNum1000 got %d\n", i
);
4634 for (p
= windows
; p
; p
= p
->w_next
)
4635 if (!strcmp(p
->w_title
, s
))
4637 for (p
= windows
; p
; p
= p
->w_next
)
4638 if (!strncmp(p
->w_title
, s
, strlen(s
)))
4650 for (i
= 0, s
= str
; *s
; s
++)
4652 if (*s
< '0' || *s
> '9')
4654 i
= i
* 10 + (*s
- '0');
4660 * Get window number from Name or Number string.
4661 * Numbers are tried first, then names, a prefix match suffices.
4662 * Be careful when assigning numeric strings as WindowTitles.
4671 if ((i
= WindowByNumber(str
)) < 0 || i
>= MAXWIN
)
4673 if ((p
= WindowByName(str
)))
4681 ParseWinNum(act
, var
)
4685 char **args
= act
->args
;
4688 if (*args
== 0 || args
[1])
4690 Msg(0, "%s: %s: one argument required.", rc_name
, comms
[act
->nr
].name
);
4694 i
= WindowByNoN(*args
);
4697 Msg(0, "%s: %s: invalid argument. Give window number or name.",
4698 rc_name
, comms
[act
->nr
].name
);
4701 debug1("ParseWinNum got %d\n", i
);
4707 ParseBase(act
, p
, var
, base
, bname
)
4719 Msg(0, "%s: %s: empty argument.", rc_name
, comms
[act
->nr
].name
);
4724 if (c
>= 'a' && c
<= 'z')
4726 if (c
>= 'A' && c
<= 'Z')
4727 c
-= 'A' - ('0' + 10);
4729 if (c
< 0 || c
>= base
)
4731 Msg(0, "%s: %s: argument is not %s.", rc_name
, comms
[act
->nr
].name
, bname
);
4736 debug1("ParseBase got %d\n", i
);
4746 for (base
+= '0'; *s
; ++s
)
4747 if (*s
< '0' || *s
> base
)
4753 IsNumColon(s
, base
, p
, psize
)
4758 if ((q
= rindex(s
, ':')) != 0)
4760 strncpy(p
, q
+ 1, psize
- 1);
4761 p
[psize
- 1] = '\0';
4766 return IsNum(s
, base
);
4775 debug1("SwitchWindow %d\n", n
);
4776 if (n
< 0 || n
>= MAXWIN
)
4781 if ((p
= wtab
[n
]) == 0)
4793 Msg(0, "This IS window %d (%s).", n
, p
->w_title
);
4797 if (AclCheckPermWin(D_user
, ACL_READ
, p
))
4799 Msg(0, "Access to window %d denied.", p
->w_number
);
4804 Activate(fore
->w_norefresh
);
4809 SetCanvasWindow(cv
, wi
)
4813 struct win
*p
= 0, **pp
;
4815 struct canvas
*cvp
, **cvpp
;
4818 display
= cv
->c_display
;
4822 /* remove old layer */
4823 for (cvpp
= &l
->l_cvlist
; (cvp
= *cvpp
); cvpp
= &cvp
->c_lnext
)
4827 *cvpp
= cvp
->c_lnext
;
4829 p
= Layer2Window(l
);
4833 if (p
&& cv
== D_forecv
)
4836 ReleaseAutoWritelock(display
, p
);
4840 SetTimeout(&p
->w_silenceev
, p
->w_silencewait
* 1000);
4841 evenq(&p
->w_silenceev
);
4846 if (l
->l_cvlist
== 0 && (p
== 0 || l
!= p
->w_savelayer
))
4850 /* find right layer to display on canvas */
4851 if (wi
&& wi
->w_type
!= W_TYPE_GROUP
)
4854 if (wi
->w_savelayer
&& (wi
->w_blocked
|| wi
->w_savelayer
->l_cvlist
== 0))
4855 l
= wi
->w_savelayer
;
4861 l
->l_data
= (char *)wi
;
4866 /* add our canvas to the layer's canvaslist */
4867 ASSERT(l
->l_cvlist
!= cv
);
4868 cv
->c_lnext
= l
->l_cvlist
;
4871 cv
->c_xoff
= cv
->c_xs
;
4872 cv
->c_yoff
= cv
->c_ys
;
4873 RethinkViewportOffsets(cv
);
4878 if (wi
&& wi
->w_type
== W_TYPE_GROUP
)
4880 /* auto-start windowlist on groups */
4881 struct display
*d
= display
;
4882 struct layer
*oldflayer
= flayer
;
4884 display_wlist(0, 0, wi
);
4889 if (wi
&& D_other
== wi
)
4890 D_other
= wi
->w_next
; /* Might be 0, but that's OK. */
4894 fore
= D_fore
; /* XXX ? */
4898 ObtainAutoWritelock(display
, wi
);
4901 * Place the window at the head of the most-recently-used list
4905 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
4910 p
->w_next
= windows
;
4920 * SetForeWindow changes the window in the input focus of the display.
4921 * Puts window wi in canvas display->d_forecv.
4933 p
= Layer2Window(D_forecv
->c_layer
);
4934 SetCanvasWindow(D_forecv
, wi
);
4936 WindowChanged(p
, 'u');
4938 WindowChanged(wi
, 'u');
4939 flayer
= D_forecv
->c_layer
;
4940 ScriptForeWindowChanged();
4941 /* Activate called afterwards, so no RefreshHStatus needed */
4945 /*****************************************************************/
4948 * Activate - make fore window active
4949 * norefresh = -1 forces a refresh, disregard all_norefresh then.
4955 debug1("Activate(%d)\n", norefresh
);
4960 Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
4964 if (MayResizeLayer(D_forecv
->c_layer
))
4965 ResizeLayer(D_forecv
->c_layer
, D_forecv
->c_xe
- D_forecv
->c_xs
+ 1, D_forecv
->c_ye
- D_forecv
->c_ys
+ 1, display
);
4971 if (fore
->w_monitor
!= MON_OFF
)
4972 fore
->w_monitor
= MON_ON
;
4973 fore
->w_bell
= BELL_ON
;
4974 WindowChanged(fore
, 'f');
4977 if (ResizeDisplay(fore
->w_width
, fore
->w_height
))
4979 debug2("Cannot resize from (%d,%d)", D_width
, D_height
);
4980 debug2(" to (%d,%d) -> resize window\n", fore
->w_width
, fore
->w_height
);
4981 DoResize(D_width
, D_height
);
4985 Redisplay(norefresh
+ all_norefresh
);
4992 register struct win
**pp
;
4993 int n
= fore
? fore
->w_number
: MAXWIN
;
4994 struct win
*group
= fore
? fore
->w_group
: 0;
4996 for (pp
= fore
? wtab
+ n
+ 1 : wtab
; pp
!= wtab
+ n
; pp
++)
4998 if (pp
== wtab
+ MAXWIN
)
5002 if (!fore
|| group
== (*pp
)->w_group
)
5014 register struct win
**pp
;
5015 int n
= fore
? fore
->w_number
: -1;
5016 struct win
*group
= fore
? fore
->w_group
: 0;
5018 for (pp
= wtab
+ n
- 1; pp
!= wtab
+ n
; pp
--)
5021 pp
= wtab
+ MAXWIN
- 1;
5024 if (!fore
|| group
== (*pp
)->w_group
)
5036 char *m
= "No other window.";
5037 if (windows
&& (fore
== 0 || windows
->w_next
))
5041 Msg(0, "No window available");
5044 Msg(0, m
, fore
->w_number
); /* other arg for nethack */
5052 struct win
**pp
, *p
;
5057 * Remove window from linked list.
5059 for (pp
= &windows
; (p
= *pp
); pp
= &p
->w_next
)
5065 wtab
[wi
->w_number
] = 0;
5074 * switch to different window on all canvases
5076 for (display
= displays
; display
; display
= display
->d_next
)
5079 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5081 if (Layer2Window(cv
->c_layer
) != wi
)
5083 /* switch to other window */
5084 SetCanvasWindow(cv
, FindNiceWindow(D_other
, 0));
5090 if (wi
->w_zdisplay
== display
)
5093 D_readev
.condpos
= D_readev
.condneg
= 0;
5100 WindowChanged((struct win
*)0, 'w');
5101 WindowChanged((struct win
*)0, 'W');
5102 WindowChanged((struct win
*)0, 0);
5111 if ((fore
->w_log
!= 0) == on
)
5113 if (display
&& !*rc_name
)
5114 Msg(0, "You are %s logging.", on
? "already" : "not");
5117 if (fore
->w_log
!= 0)
5119 Msg(0, "Logfile \"%s\" closed.", fore
->w_log
->name
);
5120 logfclose(fore
->w_log
);
5122 WindowChanged(fore
, 'f');
5125 if (DoStartLog(fore
, buf
, sizeof(buf
)))
5127 Msg(errno
, "Error opening logfile \"%s\"", buf
);
5130 if (ftell(fore
->w_log
->fp
) == 0)
5131 Msg(0, "Creating logfile \"%s\".", fore
->w_log
->name
);
5133 Msg(0, "Appending to logfile \"%s\".", fore
->w_log
->name
);
5134 WindowChanged(fore
, 'f');
5138 AddWindows(buf
, len
, flags
, where
)
5144 register char *s
, *ss
;
5145 register struct win
**pp
, *p
;
5150 for (pp
= ((flags
& 4) && where
>= 0) ? wtab
+ where
+ 1: wtab
; pp
< wtab
+ MAXWIN
; pp
++)
5152 if (pp
- wtab
== where
&& ss
== buf
)
5156 if ((flags
& 1) && display
&& p
== D_fore
)
5158 if (D_fore
&& D_fore
->w_group
!= p
->w_group
)
5165 if (s
- buf
+ l
> len
- 24)
5167 if (s
> buf
|| (flags
& 4))
5172 sprintf(s
, "%d", p
->w_number
);
5173 if (p
->w_number
== where
)
5176 if (display
&& p
== D_fore
)
5180 if (display
&& p
== D_other
)
5182 s
= AddWindowFlags(s
, len
, p
);
5193 AddWindowFlags(buf
, len
, p
)
5199 if (p
== 0 || len
< 12)
5205 if (display
&& p
== D_fore
)
5207 if (display
&& p
== D_other
)
5210 if (p
->w_layer
.l_cvlist
&& p
->w_layer
.l_cvlist
->c_lnext
)
5212 if (p
->w_monitor
== MON_DONE
5214 && (ACLBYTE(p
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5218 if (p
->w_bell
== BELL_DONE
)
5221 if (p
->w_slot
!= (slot_t
) 0 && p
->w_slot
!= (slot_t
) -1)
5229 if (p
->w_ptyfd
< 0 && p
->w_type
!= W_TYPE_GROUP
)
5236 AddOtherUsers(buf
, len
, p
)
5241 struct display
*d
, *olddisplay
= display
;
5247 for (display
= displays
; display
; display
= display
->d_next
)
5249 if (olddisplay
&& D_user
== olddisplay
->d_user
)
5251 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
5252 if (Layer2Window(cv
->c_layer
) == p
)
5256 for (d
= displays
; d
&& d
!= display
; d
= d
->d_next
)
5257 if (D_user
== d
->d_user
)
5259 if (d
&& d
!= display
)
5261 if (len
> 1 && s
!= buf
)
5266 l
= strlen(D_user
->u_name
);
5269 strcpy(s
, D_user
->u_name
);
5274 display
= olddisplay
;
5287 if (where
== -1 && D_fore
)
5288 where
= D_fore
->w_number
;
5289 ss
= AddWindows(buf
, sizeof(buf
), 0, where
);
5290 s
= buf
+ strlen(buf
);
5291 if (ss
- buf
> D_width
/ 2)
5294 if (s
- ss
< D_width
)
5310 register struct win
*wp
= fore
;
5315 Msg(0, "(%d,%d)/(%d,%d) no window", D_x
+ 1, D_y
+ 1, D_width
, D_height
);
5319 if (buf
< (p
+= GetAnsiStatus(wp
, p
)))
5321 sprintf(p
, "(%d,%d)/(%d,%d)",
5322 wp
->w_x
+ 1, wp
->w_y
+ 1, wp
->w_width
, wp
->w_height
);
5324 sprintf(p
+= strlen(p
), "+%d", wp
->w_histheight
);
5326 sprintf(p
+= strlen(p
), " %c%sflow",
5327 (wp
->w_flow
& FLOW_NOW
) ? '+' : '-',
5328 (wp
->w_flow
& FLOW_AUTOFLAG
) ? "" :
5329 ((wp
->w_flow
& FLOW_AUTO
) ? "(+)" : "(-)"));
5330 if (!wp
->w_wrap
) sprintf(p
+= strlen(p
), " -wrap");
5331 if (wp
->w_insert
) sprintf(p
+= strlen(p
), " ins");
5332 if (wp
->w_origin
) sprintf(p
+= strlen(p
), " org");
5333 if (wp
->w_keypad
) sprintf(p
+= strlen(p
), " app");
5334 if (wp
->w_log
) sprintf(p
+= strlen(p
), " log");
5335 if (wp
->w_monitor
!= MON_OFF
5337 && (ACLBYTE(wp
->w_mon_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
))
5340 sprintf(p
+= strlen(p
), " mon");
5341 if (wp
->w_mouse
) sprintf(p
+= strlen(p
), " mouse");
5343 if (wp
->w_bce
) sprintf(p
+= strlen(p
), " bce");
5345 if (!wp
->w_c1
) sprintf(p
+= strlen(p
), " -c1");
5346 if (wp
->w_norefresh
) sprintf(p
+= strlen(p
), " nored");
5351 if (wp
->w_encoding
&& (display
== 0 || D_encoding
!= wp
->w_encoding
|| EncodingDefFont(wp
->w_encoding
) <= 0))
5354 strcpy(p
, EncodingName(wp
->w_encoding
));
5358 if (wp
->w_encoding
!= UTF8
)
5361 if (D_CC0
|| (D_CS0
&& *D_CS0
))
5365 sprintf(p
, " G%c", wp
->w_Charset
+ '0');
5366 if (wp
->w_FontE
>= ' ')
5371 p
[4] = wp
->w_FontE
^ 0x40;
5378 sprintf(p
++, " G%c%c[", wp
->w_Charset
+ '0', wp
->w_CharsetR
+ '0');
5380 sprintf(p
, " G%c[", wp
->w_Charset
+ '0');
5382 for (i
= 0; i
< 4; i
++)
5384 if (wp
->w_charsets
[i
] == ASCII
)
5386 else if (wp
->w_charsets
[i
] >= ' ')
5387 *p
++ = wp
->w_charsets
[i
];
5391 *p
++ = wp
->w_charsets
[i
] ^ 0x40;
5399 if (wp
->w_type
== W_TYPE_PLAIN
)
5401 /* add info about modem control lines */
5403 TtyGetModemStatus(wp
->w_ptyfd
, p
);
5405 #ifdef BUILTIN_TELNET
5406 else if (wp
->w_type
== W_TYPE_TELNET
)
5409 TelStatus(wp
, p
, sizeof(buf
) - 1 - (p
- buf
));
5412 Msg(0, "%s %d(%s)", buf
, wp
->w_number
, wp
->w_title
);
5422 sprintf(p
, "(%d,%d)", D_width
, D_height
),
5428 strcpy(p
, EncodingName(D_encoding
));
5434 strcpy(p
, " xterm");
5440 strcpy(p
, " color");
5447 strcpy(p
, " iso2022");
5450 else if (D_CS0
&& *D_CS0
)
5452 strcpy(p
, " altchar");
5460 AKAfin(buf
, len
, data
)
5463 char *data
; /* dummy */
5467 ChangeAKA(fore
, buf
, strlen(buf
));
5475 Input("Set window's title to: ", sizeof(fore
->w_akabuf
) - 1, INP_COOKED
, AKAfin
, NULL
, 0);
5481 if ((*(unsigned char *)s
& 0x7f) < 0x20 || *s
== 0x7f)
5485 LayProcess(&ss
, &n
);
5490 Colonfin(buf
, len
, data
)
5493 char *data
; /* dummy */
5498 if (buf
[len
] == '\t')
5501 int l
= 0, r
= RC_LAST
;
5502 int showmessage
= 0;
5505 while (*s
&& s
- buf
< len
)
5509 /* Showing a message when there's no hardstatus or caption cancels the input */
5511 (captionalways
|| D_has_hstatus
== HSTATUS_LASTLINE
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
)))
5517 x
= strncmp(buf
, comms
[m
].name
, len
);
5525 for (l
= m
- 1; l
>= 0 && strncmp(buf
, comms
[l
].name
, len
) == 0; l
--)
5527 for (m
= ++l
; m
<= r
&& strncmp(buf
, comms
[m
].name
, len
) == 0 && s
- mbuf
< sizeof(mbuf
); m
++)
5528 s
+= snprintf(s
, sizeof(mbuf
) - (s
- mbuf
), " %s", comms
[m
].name
);
5532 Msg(0, "Possible commands:%s", mbuf
);
5537 len
= snprintf(mbuf
, sizeof(mbuf
), "%s \t", comms
[l
].name
+ len
);
5538 if (len
> 0 && len
< sizeof(mbuf
))
5539 LayProcess(&s
, &len
);
5544 if (l
> r
&& showmessage
)
5545 Msg(0, "No commands matching '%*s'", len
, buf
);
5549 if (!len
|| buf
[len
])
5552 len
= strlen(buf
) + 1;
5553 if (len
> (int)sizeof(mbuf
))
5557 bcopy(buf
, mbuf
, len
);
5558 RcLine(mbuf
, sizeof mbuf
);
5563 SelectFin(buf
, len
, data
)
5566 char *data
; /* dummy */
5570 if (!len
|| !display
)
5572 if (len
== 1 && *buf
== '-')
5574 SetForeWindow((struct win
*)0);
5578 if ((n
= WindowByNoN(buf
)) < 0)
5584 SelectLayoutFin(buf
, len
, data
)
5587 char *data
; /* dummy */
5592 if (!len
|| !display
)
5594 if (len
== 1 && *buf
== '-')
5596 LoadLayout((struct layout
*)0);
5600 lay
= FindLayout(buf
);
5602 Msg(0, "No such layout\n");
5603 else if (lay
== D_layout
)
5604 Msg(0, "This IS layout %d (%s).\n", lay
->lay_number
, lay
->lay_title
);
5607 LoadLayout(lay
, &D_canvas
);
5616 Input("Switch to window: ", 20, INP_COOKED
, SelectFin
, NULL
, 0);
5619 static char setenv_var
[31];
5623 SetenvFin1(buf
, len
, data
)
5626 char *data
; /* dummy */
5628 if (!len
|| !display
)
5634 SetenvFin2(buf
, len
, data
)
5637 char *data
; /* dummy */
5639 if (!len
|| !display
)
5641 debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var
, buf
);
5642 xsetenv(setenv_var
, buf
);
5650 static char setenv_buf
[50 + sizeof(setenv_var
)]; /* need to be static here, cannot be freed */
5654 strncpy(setenv_var
, arg
, sizeof(setenv_var
) - 1);
5655 sprintf(setenv_buf
, "Enter value for %s: ", setenv_var
);
5656 Input(setenv_buf
, 30, INP_COOKED
, SetenvFin2
, NULL
, 0);
5659 Input("Setenv: Enter variable name: ", 30, INP_COOKED
, SetenvFin1
, NULL
, 0);
5663 * the following options are understood by this parser:
5664 * -f, -f0, -f1, -fy, -fa
5665 * -t title, -T terminal-type, -h height-of-scrollback,
5666 * -ln, -l0, -ly, -l1, -l
5673 struct NewWindow nwin
;
5678 while (av
&& *av
&& av
[0][0] == '-')
5680 if (av
[0][1] == '-')
5692 nwin
.flowflag
= FLOW_NOW
* 0;
5697 nwin
.flowflag
= FLOW_NOW
* 1;
5700 nwin
.flowflag
= FLOW_AUTOFLAG
;
5706 case 't': /* no more -k */
5708 nwin
.aka
= &av
[0][2];
5716 nwin
.term
= &av
[0][2];
5724 nwin
.histheight
= atoi(av
[0] + 2);
5726 nwin
.histheight
= atoi(*av
);
5755 nwin
.monitor
= MON_ON
;
5761 Msg(0, "%s: screen: invalid option -%c.", fn
, av
[0][1]);
5767 if (av
&& *av
&& IsNumColon(*av
, 10, buf
, sizeof(buf
)))
5772 if (num
< 0 || num
> MAXWIN
- 1)
5774 Msg(0, "%s: illegal screen number %d.", fn
, num
);
5784 nwin
.aka
= Filename(*av
);
5791 * CompileKeys must be called before Markroutine is first used.
5792 * to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
5794 * s is an ascii string in a termcap-like syntax. It looks like
5795 * "j=u:k=d:l=r:h=l: =.:" and so on...
5796 * this example rebinds the cursormovement to the keys u (up), d (down),
5797 * l (left), r (right). placing a mark will now be done with ".".
5800 CompileKeys(s
, sl
, array
)
5803 unsigned char *array
;
5806 unsigned char key
, value
;
5810 for (i
= 0; i
< 256; i
++)
5814 debug1("CompileKeys: '%s'\n", s
);
5817 key
= *(unsigned char *)s
++;
5818 if (*s
!= '=' || sl
< 3)
5825 value
= *(unsigned char *)s
++;
5828 while (*s
== '=' && sl
>= 2);
5837 #endif /* COPY_PASTE */
5840 * Asynchronous input functions
5843 #if defined(DETACH) && defined(POW_DETACH)
5845 pow_detach_fn(buf
, len
, data
)
5848 char *data
; /* dummy */
5850 debug("pow_detach_fn called\n");
5856 if (ktab
[(int)(unsigned char)*buf
].nr
!= RC_POW_DETACH
)
5859 write(D_userfd
, "\007", 1);
5860 Msg(0, "Detach aborted.");
5865 #endif /* POW_DETACH */
5869 copy_reg_fn(buf
, len
, data
)
5872 char *data
; /* dummy */
5874 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
5885 if (D_user
->u_plop
.len
)
5887 if ((pp
->buf
= (char *)malloc(D_user
->u_plop
.len
)) == NULL
)
5892 bcopy(D_user
->u_plop
.buf
, pp
->buf
, D_user
->u_plop
.len
);
5894 pp
->len
= D_user
->u_plop
.len
;
5896 pp
->enc
= D_user
->u_plop
.enc
;
5898 Msg(0, "Copied %d characters into register %c", D_user
->u_plop
.len
, *buf
);
5902 ins_reg_fn(buf
, len
, data
)
5905 char *data
; /* dummy */
5907 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
5915 return; /* Input() should not call us w/o fore, but you never know... */
5917 Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
5920 MakePaster(&fore
->w_paster
, pp
->buf
, pp
->len
, 0);
5923 Msg(0, "Empty register.");
5925 #endif /* COPY_PASTE */
5928 process_fn(buf
, len
, data
)
5931 char *data
; /* dummy */
5933 struct plop
*pp
= plop_tab
+ (int)(unsigned char)*buf
;
5942 ProcessInput(pp
->buf
, pp
->len
);
5945 Msg(0, "Empty register.");
5949 confirm_fn(buf
, len
, data
)
5956 if (len
|| (*buf
!= 'y' && *buf
!= 'Y'))
5961 act
.nr
= *(int *)data
;
5970 struct acluser
**up
;
5972 char pw1
[130]; /* FreeBSD crypts to 128 bytes */
5977 su_fin(buf
, len
, data
)
5982 struct inputsu
*i
= (struct inputsu
*)data
;
5987 { p
= i
->name
; l
= sizeof(i
->name
) - 1; }
5989 { strcpy(p
= i
->pw1
, "\377"); l
= sizeof(i
->pw1
) - 1; }
5991 { strcpy(p
= i
->pw2
, "\377"); l
= sizeof(i
->pw2
) - 1; }
5993 strncpy(p
, buf
, 1 + (l
< len
) ? l
: len
);
5995 Input("Screen User: ", sizeof(i
->name
) - 1, INP_COOKED
, su_fin
, (char *)i
, 0);
5997 Input("User's UNIX Password: ", sizeof(i
->pw1
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
5999 Input("User's Screen Password: ", sizeof(i
->pw2
)-1, INP_COOKED
|INP_NOECHO
, su_fin
, (char *)i
, 0);
6002 if ((p
= DoSu(i
->up
, i
->name
, i
->pw2
, i
->pw1
)))
6009 InputSu(w
, up
, name
)
6011 struct acluser
**up
;
6016 if (!(i
= (struct inputsu
*)calloc(1, sizeof(struct inputsu
))))
6021 su_fin(name
, (int)strlen(name
), (char *)i
); /* can also initialise stuff */
6023 su_fin((char *)0, 0, (char *)i
);
6026 #endif /* MULTIUSER */
6031 pass1(buf
, len
, data
)
6036 struct acluser
*u
= (struct acluser
*)data
;
6041 if (u
->u_password
!= NullStr
)
6042 free((char *)u
->u_password
);
6043 u
->u_password
= SaveStr(buf
);
6044 bzero(buf
, strlen(buf
));
6045 Input("Retype new password:", 100, INP_NOECHO
, pass2
, data
, 0);
6049 pass2(buf
, len
, data
)
6056 struct acluser
*u
= (struct acluser
*)data
;
6059 if (!buf
|| strcmp(u
->u_password
, buf
))
6061 Msg(0, "[ Passwords don't match - checking turned off ]");
6062 if (u
->u_password
!= NullStr
)
6064 bzero(u
->u_password
, strlen(u
->u_password
));
6065 free((char *)u
->u_password
);
6067 u
->u_password
= NullStr
;
6069 else if (u
->u_password
[0] == '\0')
6071 Msg(0, "[ No password - no secure ]");
6073 bzero(buf
, strlen(buf
));
6076 if (u
->u_password
!= NullStr
)
6078 for (st
= 0; st
< 2; st
++)
6079 salt
[st
] = 'A' + (int)((time(0) >> 6 * st
) % 26);
6081 buf
= crypt(u
->u_password
, salt
);
6082 bzero(u
->u_password
, strlen(u
->u_password
));
6083 free((char *)u
->u_password
);
6084 u
->u_password
= SaveStr(buf
);
6085 bzero(buf
, strlen(buf
));
6088 UserFreeCopyBuffer(u
);
6089 u
->u_plop
.len
= strlen(u
->u_password
);
6093 if (!(u
->u_plop
.buf
= SaveStr(u
->u_password
)))
6096 D_user
->u_plop
.len
= 0;
6099 Msg(0, "[ Password moved into copybuffer ]");
6100 #else /* COPY_PASTE */
6101 Msg(0, "[ Crypted password is \"%s\" ]", u
->u_password
);
6102 #endif /* COPY_PASTE */
6105 #endif /* PASSWORD */
6108 digraph_fn(buf
, len
, data
)
6111 char *data
; /* dummy */
6118 buf
[len
+ 1] = ch
; /* so we can restore it later */
6119 if (ch
< ' ' || ch
== '\177')
6121 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6125 if ((ch
< '0' || ch
> '9') && (ch
< 'a' || ch
> 'f') && (ch
< 'A' || ch
> 'F'))
6127 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6130 if (len
== (*buf
== 'U' ? 5 : 3))
6134 if (len
&& *buf
== '0')
6136 if (ch
< '0' || ch
> '7')
6138 buf
[len
] = '\034'; /* ^] is ignored by Input() */
6153 buf
[len
] = buf
[len
+ 1]; /* stored above */
6158 if (len
>= 1 && ((*buf
== 'U' && buf
[1] == '+') || (*buf
== '0' && (buf
[1] == 'x' || buf
[1] == 'X'))))
6161 for (i
= 2; i
< len
; i
++)
6163 if (buf
[i
] >= '0' && buf
[i
] <= '9')
6164 x
= x
* 16 | (buf
[i
] - '0');
6165 else if (buf
[i
] >= 'a' && buf
[i
] <= 'f')
6166 x
= x
* 16 | (buf
[i
] - ('a' - 10));
6167 else if (buf
[i
] >= 'A' && buf
[i
] <= 'F')
6168 x
= x
* 16 | (buf
[i
] - ('A' - 10));
6173 else if (buf
[0] == '0')
6176 for (i
= 1; i
< len
; i
++)
6178 if (buf
[i
] < '0' || buf
[i
] > '7')
6180 x
= x
* 8 | (buf
[i
] - '0');
6185 for (i
= 0; i
< (int)(sizeof(digraphs
)/sizeof(*digraphs
)); i
++)
6186 if ((digraphs
[i
][0] == (unsigned char)buf
[0] && digraphs
[i
][1] == (unsigned char)buf
[1]) ||
6187 (digraphs
[i
][0] == (unsigned char)buf
[1] && digraphs
[i
][1] == (unsigned char)buf
[0]))
6189 if (i
== (int)(sizeof(digraphs
)/sizeof(*digraphs
)))
6191 Msg(0, "Unknown digraph");
6199 if (flayer
->l_encoding
== UTF8
)
6200 i
= ToUtf8(buf
, x
); /* buf is big enough for all UTF-8 codes */
6203 LayProcess(&buf
, &i
);
6214 debug1("StuffKey #%d", i
);
6217 debug1(" - %s", term
[i
+ T_CAPS
].tcname
);
6220 if (i
< KMAP_KEYS
&& D_ESCseen
)
6222 struct action
*act
= &D_ESCseen
[i
+ 256];
6223 if (act
->nr
!= RC_ILLEGAL
)
6226 DoAction(act
, i
+ 256);
6232 if (i
>= T_CURSOR
- T_CAPS
&& i
< T_KEYPAD
- T_CAPS
&& D_cursorkeys
)
6233 i
+= T_OCAPS
- T_CURSOR
;
6234 else if (i
>= T_KEYPAD
- T_CAPS
&& i
< T_OCAPS
- T_CAPS
&& D_keypad
)
6235 i
+= T_OCAPS
- T_CURSOR
;
6236 debug1(" - action %d\n", i
);
6237 flayer
= D_forecv
->c_layer
;
6241 if (InMark() || InInput() || InWList())
6242 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &mmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].mm
;
6244 if ((!act
|| act
->nr
== RC_ILLEGAL
) && !D_mapdefault
)
6245 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &umtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].um
;
6246 if (!act
|| act
->nr
== RC_ILLEGAL
)
6247 act
= i
< KMAP_KEYS
+KMAP_AKEYS
? &dmtab
[i
] : &kmap_exts
[i
- (KMAP_KEYS
+KMAP_AKEYS
)].dm
;
6249 if (discard
&& (!act
|| act
->nr
!= RC_COMMAND
))
6256 if (act
== 0 || act
->nr
== RC_ILLEGAL
)
6270 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6271 if (Layer2Window(cv
->c_layer
) == wi
)
6277 FindNiceWindow(wi
, presel
)
6283 debug2("FindNiceWindow %d %s\n", wi
? wi
->w_number
: -1 , presel
? presel
: "NULL");
6286 i
= WindowByNoN(presel
);
6293 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6296 if (!wi
|| (IsOnDisplay(wi
) && !presel
))
6298 /* try to get another window */
6301 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6302 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6305 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6306 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_WRITE
, wi
))
6309 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6310 if (!wi
->w_layer
.l_cvlist
&& !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6313 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6314 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
) && !AclCheckPermWin(D_user
, ACL_READ
, wi
))
6318 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6319 if (!wi
->w_layer
.l_cvlist
)
6322 for (wi
= windows
; wi
; wi
= wi
->w_next
)
6323 if (wi
->w_layer
.l_cvlist
&& !IsOnDisplay(wi
))
6327 if (wi
&& AclCheckPermWin(D_user
, ACL_READ
, wi
))
6335 /* sorted list of all commands */
6336 static struct comm
**commtab
;
6337 static int ncommtab
;
6342 void (*hand
) __P((struct comm
*, char **, int));
6345 for (n
= 0; cos
[n
].name
; n
++)
6350 commtab
= (struct commt
*)realloc(commtab
, sizeof(*commtab
) * (ncommtab
+ n
));
6352 commtab
= (struct commt
*)malloc(sizeof(*commtab
) * (ncommtab
+ n
));
6355 for (i
= 0; i
< n
; i
++)
6357 for (j
= 0; j
< ncommtab
; j
++)
6359 r
= strcmp(cos
[i
].name
, commtab
[j
]->name
);
6361 Panic(0, "Duplicate command: %s\n", cos
[i
].name
);
6365 for (r
= ncommtab
; r
> j
; r
--)
6366 commtab
[r
] = commtab
[r
- 1];
6367 commtab
[j
] = cos
+ i
;
6368 cos
[i
].handler
= hand
;
6369 bzero(cos
[i
].userbits
, sizeof(cos
[i
].userbits
));
6378 int x
, m
, l
= 0, r
= ncommtab
- 1;
6382 x
= strcmp(str
, commtab
[m
]->name
);
6396 CalcSlicePercent(cv
, percent
)
6401 if (!cv
|| !cv
->c_slback
)
6403 up
= CalcSlicePercent(cv
->c_slback
->c_slback
, percent
);
6405 for (cv
= cv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6406 wsum
+= cv
->c_slweight
;
6409 return (up
* w
) / wsum
;
6413 ChangeCanvasSize(fcv
, abs
, diff
, gflag
, percent
)
6414 struct canvas
*fcv
; /* make this canvas bigger */
6415 int abs
; /* mode: 0:rel 1:abs 2:max */
6416 int diff
; /* change this much */
6417 int gflag
; /* go up if neccessary */
6421 int done
, have
, m
, dir
;
6423 debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs
, diff
, percent
);
6424 if (abs
== 0 && diff
== 0)
6429 fcv
->c_slweight
= 0;
6432 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6434 fcv
->c_slweight
= 1;
6435 cv
= fcv
->c_slback
->c_slback
;
6436 if (gflag
&& cv
&& cv
->c_slback
)
6437 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6445 if (percent
&& diff
> percent
)
6451 for (cv
= fcv
->c_slback
->c_slperp
, wsum
= 0; cv
; cv
= cv
->c_slnext
)
6452 wsum
+= cv
->c_slweight
;
6455 up
= gflag
? CalcSlicePercent(fcv
->c_slback
->c_slback
, percent
) : percent
;
6456 debug3("up=%d, wsum=%d percent=%d\n", up
, wsum
, percent
);
6459 int scale
= wsum
< 10 ? 1000 : 100;
6460 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6461 cv
->c_slweight
*= scale
;
6463 debug1("scaled wsum to %d\n", wsum
);
6465 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6469 cv
->c_slweight
= (cv
->c_slweight
* up
) / percent
;
6470 if (cv
->c_slweight
== 0)
6473 debug1(" - weight %d\n", cv
->c_slweight
);
6475 diff
= (diff
* wsum
) / percent
;
6481 if (abs
&& diff
== (fcv
->c_slorient
== SLICE_VERT
? fcv
->c_ye
- fcv
->c_ys
+ 2 : fcv
->c_xe
- fcv
->c_xs
+ 2))
6483 /* fix weights to real size (can't be helped, sorry) */
6484 for (cv
= fcv
->c_slback
->c_slperp
; cv
; cv
= cv
->c_slnext
)
6486 cv
->c_slweight
= cv
->c_slorient
== SLICE_VERT
? cv
->c_ye
- cv
->c_ys
+ 2 : cv
->c_xe
- cv
->c_xs
+ 2;
6487 debug1(" - weight %d\n", cv
->c_slweight
);
6491 diff
= diff
- fcv
->c_slweight
;
6492 debug1("diff = %d\n", diff
);
6497 cv
= fcv
->c_slnext
? fcv
->c_slnext
: fcv
->c_slprev
;
6498 fcv
->c_slweight
+= diff
;
6499 cv
->c_slweight
-= diff
;
6504 for (cv
= fcv
->c_slnext
; diff
> 0; cv
= dir
> 0 ? cv
->c_slnext
: cv
->c_slprev
)
6508 debug1("reached end, dir is %d\n", dir
);
6518 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 : 2;
6519 debug2("min is %d, have %d\n", m
, cv
->c_slweight
);
6520 if (cv
->c_slweight
> m
)
6522 have
= cv
->c_slweight
- m
;
6525 debug1("subtract %d\n", have
);
6526 cv
->c_slweight
-= have
;
6533 /* need more room! */
6534 cv
= fcv
->c_slback
->c_slback
;
6535 if (cv
&& cv
->c_slback
)
6536 done
+= ChangeCanvasSize(fcv
->c_slback
->c_slback
, 0, diff
, gflag
, percent
);
6538 fcv
->c_slweight
+= done
;
6539 debug1("ChangeCanvasSize returns %d\n", done
);
6544 ResizeRegions(arg
, flags
)
6549 int nreg
, dsize
, diff
, siz
, nsiz
, l
, done
;
6550 int gflag
= 0, abs
= 0, percent
= 0;
6554 if (D_forecv
->c_slorient
== SLICE_UNKN
)
6556 Msg(0, "resize: need more than one region");
6559 gflag
= flags
& RESIZE_FLAG_L
? 0 : 1;
6560 orient
|= flags
& RESIZE_FLAG_H
? SLICE_HORI
: 0;
6561 orient
|= flags
& RESIZE_FLAG_V
? SLICE_VERT
: 0;
6563 orient
= D_forecv
->c_slorient
;
6567 /* make all regions the same height */
6568 struct canvas
*cv
= gflag
? &D_canvas
: D_forecv
->c_slback
;
6569 if (cv
->c_slperp
->c_slorient
& orient
)
6570 EqualizeCanvas(cv
->c_slperp
, gflag
);
6571 /* can't use cv->c_slorient directly as it can be D_canvas */
6572 if ((cv
->c_slperp
->c_slorient
^ (SLICE_HORI
^ SLICE_VERT
)) & orient
)
6577 EqualizeCanvas(cv
->c_slperp
, gflag
);
6580 EqualizeCanvas(cv
, gflag
);
6583 RecreateCanvasChain();
6584 RethinkDisplayViewports();
6585 ResizeLayersToCanvases();
6588 if (!strcmp(arg
, "min") || !strcmp(arg
, "0"))
6593 else if (!strcmp(arg
, "max") || !strcmp(arg
, "_"))
6600 if (l
> 0 && arg
[l
- 1] == '%')
6603 diff
= atoi(arg
+ 1);
6604 else if (*arg
== '-')
6605 diff
= -atoi(arg
+ 1);
6608 diff
= atoi(arg
); /* +1 because of caption line */
6611 abs
= diff
== 0 ? 2 : 1;
6617 diff
= diff
* percent
/ 100;
6619 if (cv
->c_slorient
& orient
)
6620 ChangeCanvasSize(cv
, abs
, diff
, gflag
, percent
);
6621 if (cv
->c_slback
->c_slorient
& orient
)
6622 ChangeCanvasSize(cv
->c_slback
, abs
, diff
, gflag
, percent
);
6624 ResizeCanvas(&D_canvas
);
6625 RecreateCanvasChain();
6626 RethinkDisplayViewports();
6627 ResizeLayersToCanvases();
6634 if (siz
+ diff
> dsize
- (nreg
- 1) * 2 - 1)
6635 diff
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6636 if (diff
== 0 || siz
+ diff
< 1)
6641 if (D_forecv
->c_next
)
6643 D_forecv
->c_ye
+= diff
;
6644 D_forecv
->c_next
->c_ys
+= diff
;
6645 D_forecv
->c_next
->c_yoff
+= diff
;
6649 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
6650 if (cv
->c_next
== D_forecv
)
6654 D_forecv
->c_ys
-= diff
;
6655 D_forecv
->c_yoff
-= diff
;
6660 int s
, i
= 0, found
= 0, di
= diff
, d2
;
6661 s
= dsize
- (nreg
- 1) * 2 - 1 - siz
;
6662 for (cv
= D_cvlist
; cv
; i
= cv
->c_ye
+ 2, cv
= cv
->c_next
)
6666 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) + diff
;
6667 cv
->c_yoff
-= cv
->c_ys
- i
;
6672 s
-= cv
->c_ye
- cv
->c_ys
;
6680 d2
= di
> cv
->c_ye
- cv
->c_ys
? cv
->c_ye
- cv
->c_ys
: di
;
6682 cv
->c_ye
= i
+ (cv
->c_ye
- cv
->c_ys
) - d2
;
6683 cv
->c_yoff
-= cv
->c_ys
- i
;
6687 RethinkDisplayViewports();
6688 ResizeLayersToCanvases();
6693 ResizeFin(buf
, len
, data
)
6699 int flags
= *(int *)data
;
6700 ch
= ((unsigned char *)buf
)[len
];
6703 ResizeRegions(buf
, flags
);
6707 flags
^= RESIZE_FLAG_H
;
6709 flags
^= RESIZE_FLAG_V
;
6711 flags
|= RESIZE_FLAG_H
|RESIZE_FLAG_V
;
6713 flags
^= D_forecv
->c_slorient
== SLICE_VERT
? RESIZE_FLAG_H
: RESIZE_FLAG_V
;
6715 flags
^= RESIZE_FLAG_L
;
6718 inp_setprompt(resizeprompts
[flags
], NULL
);
6719 *(int *)data
= flags
;
6730 p
= Layer2Window(D_forecv
->c_layer
);
6731 for (i
= 3; i
>=0; i
--)
6732 SetXtermOSC(i
, p
? p
->w_xtermosc
[i
] : 0);
6737 ParseAttrColor(s1
, s2
, msgok
)
6749 while (*ss
&& *ss
!= ' ')
6753 if (*s
&& (s2
|| *ss
|| !((*s
>= 'a' && *s
<= 'z') || (*s
>= 'A' && *s
<= 'Z') || *s
== '.')))
6755 int mode
= 0, n
= 0;
6773 if (*s
>= '0' && *s
<= '9')
6776 if (*s
>= '0' && *s
<= '9')
6777 n
= n
* 16 + (*s
++ - '0');
6778 else if (*s
>= 'a' && *s
<= 'f')
6779 n
= n
* 16 + (*s
++ - ('a' - 10));
6780 else if (*s
>= 'A' && *s
<= 'F')
6781 n
= n
* 16 + (*s
++ - ('A' - 10));
6782 else if (*s
&& *s
!= ' ')
6785 Msg(0, "Illegal attribute hexchar '%c'", *s
);
6791 while (*s
&& *s
!= ' ')
6808 Msg(0, "Illegal attribute specifier '%c'", *s
);
6814 if (*s
&& *s
!= ' ')
6817 Msg(0, "junk after attribute description: '%c'", *s
);
6829 while (*s
&& *s
== ' ')
6837 Msg(0, "junk after description: '%c'", *s
);
6841 while (*s
&& *s
== ' ')
6848 static char costr
[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
6858 for (j
= 0; j
< 2 && *s
&& *s
!= ' '; j
++)
6860 for (i
= 0; costr
[i
]; i
++)
6866 Msg(0, "illegal color descriptor: '%c'", *s
);
6870 n
= n
<< 4 | (i
& 15);
6873 n
= (n
& 0x20ff) | 0x200;
6877 if ((n
& 0xf00) == 0xf00)
6878 n
^= 0xf00; /* clear superflous bits */
6881 n
^= 0x2400; /* shift bit into right position */
6884 n
|= 0xf0; /* don't change bg color */
6885 if (numco
!= 2 && n
!= 0xff)
6886 n
|= 0x100; /* special invert mode */
6887 if (*s
&& *s
!= ' ')
6890 Msg(0, "junk after color description: '%c'", *s
);
6898 while (*s
&& *s
== ' ')
6903 Msg(0, "junk after description: '%c'", *s
);
6906 debug1("ParseAttrColor %06x\n", r
);
6914 * e just set intensity
6915 * f don't change anything
6916 * Intensity is encoded into bits 17(fg) and 18(bg).
6919 ApplyAttrColor(i
, mc
)
6923 debug1("ApplyAttrColor %06x\n", i
);
6924 mc
->attr
|= i
>> 8 & 255;
6925 mc
->attr
^= i
& 255;
6927 i
= (i
>> 16) ^ 0xff;
6928 if ((i
& 0x100) != 0)
6931 if (mc
->attr
& (A_SO
|A_RV
))
6933 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4) | ((i
& 0x200) << 1) | ((i
& 0x400) >> 1);
6935 i
= ((i
& 0x0f) << 4) | ((i
& 0xf0) >> 4);
6939 if ((i
& 0x0f) != 0x0f)
6940 mc
->attr
= (mc
->attr
& 0xbf) | ((i
>> 3) & 0x40);
6941 if ((i
& 0xf0) != 0xf0)
6942 mc
->attr
= (mc
->attr
& 0x7f) | ((i
>> 3) & 0x80);
6944 mc
->color
= 0x99 ^ mc
->color
;
6945 if ((i
& 0x0e) == 0x0e)
6946 i
= (i
& 0xf0) | (mc
->color
& 0x0f);
6947 if ((i
& 0xe0) == 0xe0)
6948 i
= (i
& 0x0f) | (mc
->color
& 0xf0);
6949 mc
->color
= 0x99 ^ i
;
6950 debug2("ApplyAttrColor - %02x %02x\n", mc
->attr
, i
);