2
* Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3
* Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
4
* Copyright (c) 2008, 2009
5
* Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
6
* Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
7
* Micah Cowan (micah@cowan.name)
8
* Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
9
* Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
10
* Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
11
* Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
12
* Copyright (c) 1987 Oliver Laumann
14
* This program is free software; you can redistribute it and/or modify
15
* it under the terms of the GNU General Public License as published by
16
* the Free Software Foundation; either version 3, or (at your option)
19
* This program is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU General Public License for more details.
24
* You should have received a copy of the GNU General Public License
25
* along with this program (see the file COPYING); if not, see
26
* http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
27
* 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
29
****************************************************************
34
#include <sys/types.h>
38
#if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
43
#include <sys/ioctl.h>
47
/* for solaris 2.1, Unixware (SVR4.2) and possibly others: */
49
# include <sys/stropts.h>
57
#include "list_generic.h"
59
extern struct comm comms[];
61
extern char *RcFileName, *home;
62
extern char *BellString, *ActivityString, *ShellProg, *ShellArgs[];
63
extern char *hstatusstring, *captionstring, *timestring;
64
extern char *wliststr, *wlisttit;
65
extern int captionalways;
67
extern char *hardcopydir, *screenlogfile, *logtstamp_string;
68
extern int log_flush, logtstamp_on, logtstamp_after;
69
extern char *VisualBellString;
70
extern int VBellWait, MsgWait, MsgMinWait, SilenceWait;
71
extern char SockPath[], *SockName;
72
extern int TtyMode, auto_detach, use_altscreen;
73
extern int iflag, maxwin;
74
extern int focusminwidth, focusminheight;
75
extern int use_hardstatus, visual_bell;
77
extern int attr2color[][4];
78
extern int nattr2color;
80
extern int hardstatusemu;
81
extern char *printcmd;
82
extern int default_startup;
83
extern int defobuflimit;
84
extern int defnonblock;
85
extern int defmousetrack;
86
extern int ZombieKey_destroy;
87
extern int ZombieKey_resurrect;
88
extern int ZombieKey_onerror;
90
extern int defautonuke;
92
extern int separate_sids;
93
extern struct NewWindow nwin_default, nwin_undef;
95
extern int join_with_cr;
96
extern int compacthist;
101
extern unsigned char mark_key_tab[];
102
extern char *BufferFile;
105
extern char *BufferFile, *PowDetachString;
108
extern struct acluser *EffectiveAclUser; /* acl.c */
110
extern struct term term[]; /* terminal capabilities */
112
extern char *kmapdef[];
113
extern char *kmapadef[];
114
extern char *kmapmdef[];
116
extern struct mchar mchar_so, mchar_null;
117
extern int renditions[];
118
extern int VerboseCreate;
120
extern char *screenencodings;
126
static int CheckArgNum __P((int, char **));
127
static void ClearAction __P((struct action *));
128
static void SaveAction __P((struct action *, int, char **, int *));
129
static int NextWindow __P((void));
130
static int PreviousWindow __P((void));
131
static int MoreWindows __P((void));
132
static void LogToggle __P((int));
133
static void ShowInfo __P((void));
134
static void ShowDInfo __P((void));
135
static struct win *WindowByName __P((char *));
136
static int WindowByNumber __P((char *));
137
static int ParseOnOff __P((struct action *, int *));
138
static int ParseWinNum __P((struct action *, int *));
139
static int ParseBase __P((struct action *, char *, int *, int, char *));
140
static int ParseNum1000 __P((struct action *, int *));
141
static char **SaveArgs __P((char **));
142
static int IsNum __P((char *, int));
143
static void Colonfin __P((char *, int, char *));
144
static void InputSelect __P((void));
145
static void InputSetenv __P((char *));
146
static void InputAKA __P((void));
148
static int InputSu __P((struct win *, struct acluser **, char *));
149
static void su_fin __P((char *, int, char *));
151
static void AKAfin __P((char *, int, char *));
153
static void copy_reg_fn __P((char *, int, char *));
154
static void ins_reg_fn __P((char *, int, char *));
156
static void process_fn __P((char *, int, char *));
158
static void pass1 __P((char *, int, char *));
159
static void pass2 __P((char *, int, char *));
162
static void pow_detach_fn __P((char *, int, char *));
164
static void digraph_fn __P((char *, int, char *));
165
static int digraph_find __P((const char *buf));
166
static void confirm_fn __P((char *, int, char *));
167
static int IsOnDisplay __P((struct win *));
168
static void ResizeRegions __P((char *, int));
169
static void ResizeFin __P((char *, int, char *));
170
static struct action *FindKtab __P((char *, int));
171
static void SelectFin __P((char *, int, char *));
172
static void SelectLayoutFin __P((char *, int, char *));
175
extern struct layer *flayer;
176
extern struct display *display, *displays;
177
extern struct win *fore, *console_window, *windows;
178
extern struct acluser *users;
179
extern struct layout *layouts, *layout_attach, layout_last_marker;
180
extern struct layout *laytab[];
182
extern char screenterm[], HostName[], version[];
183
extern struct NewWindow nwin_undef, nwin_default;
184
extern struct LayFuncs WinLf, MarkLf;
186
extern int Z0width, Z1width;
187
extern int real_uid, real_gid;
190
extern int nethackflag;
194
extern struct win **wtab;
198
extern int maxusercount;
202
struct plop plop_tab[MAX_PLOP_DEFS];
205
# define PTYMODE 0622
208
int TtyMode = PTYMODE;
209
int hardcopy_append = 0;
210
int all_norefresh = 0;
213
char *zmodem_sendcmd;
214
char *zmodem_recvcmd;
215
static char *zmodes[4] = {"off", "auto", "catch", "pass"};
219
struct action idleaction;
224
struct action ktab[256 + KMAP_KEYS]; /* command key translation table */
228
struct action ktab[256 + KMAP_KEYS];
230
struct kclass *kclasses;
233
struct action umtab[KMAP_KEYS+KMAP_AKEYS];
234
struct action dmtab[KMAP_KEYS+KMAP_AKEYS];
235
struct action mmtab[KMAP_KEYS+KMAP_AKEYS];
236
struct kmap_ext *kmap_exts;
238
static int maptimeout = 300;
242
#define MAX_DIGRAPH 512
251
/* digraph table taken from old vim and rfc1345 */
252
static struct digraph digraphs[MAX_DIGRAPH + 1] = {
253
{{' ', ' '}, 0x00a0}, /* NO-BREAK SPACE */
254
{{'N', 'S'}, 0x00a0}, /* NO-BREAK SPACE */
255
{{'~', '!'}, 0x00a1}, /* INVERTED EXCLAMATION MARK */
256
{{'!', '!'}, 0x00a1}, /* INVERTED EXCLAMATION MARK */
257
{{'!', 'I'}, 0x00a1}, /* INVERTED EXCLAMATION MARK */
258
{{'c', '|'}, 0x00a2}, /* CENT SIGN */
259
{{'c', 't'}, 0x00a2}, /* CENT SIGN */
260
{{'$', '$'}, 0x00a3}, /* POUND SIGN */
261
{{'P', 'd'}, 0x00a3}, /* POUND SIGN */
262
{{'o', 'x'}, 0x00a4}, /* CURRENCY SIGN */
263
{{'C', 'u'}, 0x00a4}, /* CURRENCY SIGN */
264
{{'C', 'u'}, 0x00a4}, /* CURRENCY SIGN */
265
{{'E', 'u'}, 0x00a4}, /* CURRENCY SIGN */
266
{{'Y', '-'}, 0x00a5}, /* YEN SIGN */
267
{{'Y', 'e'}, 0x00a5}, /* YEN SIGN */
268
{{'|', '|'}, 0x00a6}, /* BROKEN BAR */
269
{{'B', 'B'}, 0x00a6}, /* BROKEN BAR */
270
{{'p', 'a'}, 0x00a7}, /* SECTION SIGN */
271
{{'S', 'E'}, 0x00a7}, /* SECTION SIGN */
272
{{'"', '"'}, 0x00a8}, /* DIAERESIS */
273
{{'\'', ':'}, 0x00a8}, /* DIAERESIS */
274
{{'c', 'O'}, 0x00a9}, /* COPYRIGHT SIGN */
275
{{'C', 'o'}, 0x00a9}, /* COPYRIGHT SIGN */
276
{{'-', 'a'}, 0x00aa}, /* FEMININE ORDINAL INDICATOR */
277
{{'<', '<'}, 0x00ab}, /* LEFT-POINTING DOUBLE ANGLE QUOTATION MARK */
278
{{'-', ','}, 0x00ac}, /* NOT SIGN */
279
{{'N', 'O'}, 0x00ac}, /* NOT SIGN */
280
{{'-', '-'}, 0x00ad}, /* SOFT HYPHEN */
281
{{'r', 'O'}, 0x00ae}, /* REGISTERED SIGN */
282
{{'R', 'g'}, 0x00ae}, /* REGISTERED SIGN */
283
{{'-', '='}, 0x00af}, /* MACRON */
284
{{'\'', 'm'}, 0x00af}, /* MACRON */
285
{{'~', 'o'}, 0x00b0}, /* DEGREE SIGN */
286
{{'D', 'G'}, 0x00b0}, /* DEGREE SIGN */
287
{{'+', '-'}, 0x00b1}, /* PLUS-MINUS SIGN */
288
{{'2', '2'}, 0x00b2}, /* SUPERSCRIPT TWO */
289
{{'2', 'S'}, 0x00b2}, /* SUPERSCRIPT TWO */
290
{{'3', '3'}, 0x00b3}, /* SUPERSCRIPT THREE */
291
{{'3', 'S'}, 0x00b3}, /* SUPERSCRIPT THREE */
292
{{'\'', '\''}, 0x00b4}, /* ACUTE ACCENT */
293
{{'j', 'u'}, 0x00b5}, /* MICRO SIGN */
294
{{'M', 'y'}, 0x00b5}, /* MICRO SIGN */
295
{{'p', 'p'}, 0x00b6}, /* PILCROW SIGN */
296
{{'P', 'I'}, 0x00b6}, /* PILCROW SIGN */
297
{{'~', '.'}, 0x00b7}, /* MIDDLE DOT */
298
{{'.', 'M'}, 0x00b7}, /* MIDDLE DOT */
299
{{',', ','}, 0x00b8}, /* CEDILLA */
300
{{'\'', ','}, 0x00b8}, /* CEDILLA */
301
{{'1', '1'}, 0x00b9}, /* SUPERSCRIPT ONE */
302
{{'1', 'S'}, 0x00b9}, /* SUPERSCRIPT ONE */
303
{{'-', 'o'}, 0x00ba}, /* MASCULINE ORDINAL INDICATOR */
304
{{'>', '>'}, 0x00bb}, /* RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK */
305
{{'1', '4'}, 0x00bc}, /* VULGAR FRACTION ONE QUARTER */
306
{{'1', '2'}, 0x00bd}, /* VULGAR FRACTION ONE HALF */
307
{{'3', '4'}, 0x00be}, /* VULGAR FRACTION THREE QUARTERS */
308
{{'~', '?'}, 0x00bf}, /* INVERTED QUESTION MARK */
309
{{'?', '?'}, 0x00bf}, /* INVERTED QUESTION MARK */
310
{{'?', 'I'}, 0x00bf}, /* INVERTED QUESTION MARK */
311
{{'A', '`'}, 0x00c0}, /* LATIN CAPITAL LETTER A WITH GRAVE */
312
{{'A', '!'}, 0x00c0}, /* LATIN CAPITAL LETTER A WITH GRAVE */
313
{{'A', '\''}, 0x00c1}, /* LATIN CAPITAL LETTER A WITH ACUTE */
314
{{'A', '^'}, 0x00c2}, /* LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
315
{{'A', '>'}, 0x00c2}, /* LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
316
{{'A', '~'}, 0x00c3}, /* LATIN CAPITAL LETTER A WITH TILDE */
317
{{'A', '?'}, 0x00c3}, /* LATIN CAPITAL LETTER A WITH TILDE */
318
{{'A', '"'}, 0x00c4}, /* LATIN CAPITAL LETTER A WITH DIAERESIS */
319
{{'A', ':'}, 0x00c4}, /* LATIN CAPITAL LETTER A WITH DIAERESIS */
320
{{'A', '@'}, 0x00c5}, /* LATIN CAPITAL LETTER A WITH RING ABOVE */
321
{{'A', 'A'}, 0x00c5}, /* LATIN CAPITAL LETTER A WITH RING ABOVE */
322
{{'A', 'E'}, 0x00c6}, /* LATIN CAPITAL LETTER AE */
323
{{'C', ','}, 0x00c7}, /* LATIN CAPITAL LETTER C WITH CEDILLA */
324
{{'E', '`'}, 0x00c8}, /* LATIN CAPITAL LETTER E WITH GRAVE */
325
{{'E', '!'}, 0x00c8}, /* LATIN CAPITAL LETTER E WITH GRAVE */
326
{{'E', '\''}, 0x00c9}, /* LATIN CAPITAL LETTER E WITH ACUTE */
327
{{'E', '^'}, 0x00ca}, /* LATIN CAPITAL LETTER E WITH CIRCUMFLEX */
328
{{'E', '>'}, 0x00ca}, /* LATIN CAPITAL LETTER E WITH CIRCUMFLEX */
329
{{'E', '"'}, 0x00cb}, /* LATIN CAPITAL LETTER E WITH DIAERESIS */
330
{{'E', ':'}, 0x00cb}, /* LATIN CAPITAL LETTER E WITH DIAERESIS */
331
{{'I', '`'}, 0x00cc}, /* LATIN CAPITAL LETTER I WITH GRAVE */
332
{{'I', '!'}, 0x00cc}, /* LATIN CAPITAL LETTER I WITH GRAVE */
333
{{'I', '\''}, 0x00cd}, /* LATIN CAPITAL LETTER I WITH ACUTE */
334
{{'I', '^'}, 0x00ce}, /* LATIN CAPITAL LETTER I WITH CIRCUMFLEX */
335
{{'I', '>'}, 0x00ce}, /* LATIN CAPITAL LETTER I WITH CIRCUMFLEX */
336
{{'I', '"'}, 0x00cf}, /* LATIN CAPITAL LETTER I WITH DIAERESIS */
337
{{'I', ':'}, 0x00cf}, /* LATIN CAPITAL LETTER I WITH DIAERESIS */
338
{{'D', '-'}, 0x00d0}, /* LATIN CAPITAL LETTER ETH */
339
{{'N', '~'}, 0x00d1}, /* LATIN CAPITAL LETTER N WITH TILDE */
340
{{'N', '?'}, 0x00d1}, /* LATIN CAPITAL LETTER N WITH TILDE */
341
{{'O', '`'}, 0x00d2}, /* LATIN CAPITAL LETTER O WITH GRAVE */
342
{{'O', '!'}, 0x00d2}, /* LATIN CAPITAL LETTER O WITH GRAVE */
343
{{'O', '\''}, 0x00d3}, /* LATIN CAPITAL LETTER O WITH ACUTE */
344
{{'O', '^'}, 0x00d4}, /* LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
345
{{'O', '>'}, 0x00d4}, /* LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
346
{{'O', '~'}, 0x00d5}, /* LATIN CAPITAL LETTER O WITH TILDE */
347
{{'O', '?'}, 0x00d5}, /* LATIN CAPITAL LETTER O WITH TILDE */
348
{{'O', '"'}, 0x00d6}, /* LATIN CAPITAL LETTER O WITH DIAERESIS */
349
{{'O', ':'}, 0x00d6}, /* LATIN CAPITAL LETTER O WITH DIAERESIS */
350
{{'/', '\\'}, 0x00d7}, /* MULTIPLICATION SIGN */
351
{{'*', 'x'}, 0x00d7}, /* MULTIPLICATION SIGN */
352
{{'O', '/'}, 0x00d8}, /* LATIN CAPITAL LETTER O WITH STROKE */
353
{{'U', '`'}, 0x00d9}, /* LATIN CAPITAL LETTER U WITH GRAVE */
354
{{'U', '!'}, 0x00d9}, /* LATIN CAPITAL LETTER U WITH GRAVE */
355
{{'U', '\''}, 0x00da}, /* LATIN CAPITAL LETTER U WITH ACUTE */
356
{{'U', '^'}, 0x00db}, /* LATIN CAPITAL LETTER U WITH CIRCUMFLEX */
357
{{'U', '>'}, 0x00db}, /* LATIN CAPITAL LETTER U WITH CIRCUMFLEX */
358
{{'U', '"'}, 0x00dc}, /* LATIN CAPITAL LETTER U WITH DIAERESIS */
359
{{'U', ':'}, 0x00dc}, /* LATIN CAPITAL LETTER U WITH DIAERESIS */
360
{{'Y', '\''}, 0x00dd}, /* LATIN CAPITAL LETTER Y WITH ACUTE */
361
{{'I', 'p'}, 0x00de}, /* LATIN CAPITAL LETTER THORN */
362
{{'T', 'H'}, 0x00de}, /* LATIN CAPITAL LETTER THORN */
363
{{'s', 's'}, 0x00df}, /* LATIN SMALL LETTER SHARP S */
364
{{'s', '"'}, 0x00df}, /* LATIN SMALL LETTER SHARP S */
365
{{'a', '`'}, 0x00e0}, /* LATIN SMALL LETTER A WITH GRAVE */
366
{{'a', '!'}, 0x00e0}, /* LATIN SMALL LETTER A WITH GRAVE */
367
{{'a', '\''}, 0x00e1}, /* LATIN SMALL LETTER A WITH ACUTE */
368
{{'a', '^'}, 0x00e2}, /* LATIN SMALL LETTER A WITH CIRCUMFLEX */
369
{{'a', '>'}, 0x00e2}, /* LATIN SMALL LETTER A WITH CIRCUMFLEX */
370
{{'a', '~'}, 0x00e3}, /* LATIN SMALL LETTER A WITH TILDE */
371
{{'a', '?'}, 0x00e3}, /* LATIN SMALL LETTER A WITH TILDE */
372
{{'a', '"'}, 0x00e4}, /* LATIN SMALL LETTER A WITH DIAERESIS */
373
{{'a', ':'}, 0x00e4}, /* LATIN SMALL LETTER A WITH DIAERESIS */
374
{{'a', 'a'}, 0x00e5}, /* LATIN SMALL LETTER A WITH RING ABOVE */
375
{{'a', 'e'}, 0x00e6}, /* LATIN SMALL LETTER AE */
376
{{'c', ','}, 0x00e7}, /* LATIN SMALL LETTER C WITH CEDILLA */
377
{{'e', '`'}, 0x00e8}, /* LATIN SMALL LETTER E WITH GRAVE */
378
{{'e', '!'}, 0x00e8}, /* LATIN SMALL LETTER E WITH GRAVE */
379
{{'e', '\''}, 0x00e9}, /* LATIN SMALL LETTER E WITH ACUTE */
380
{{'e', '^'}, 0x00ea}, /* LATIN SMALL LETTER E WITH CIRCUMFLEX */
381
{{'e', '>'}, 0x00ea}, /* LATIN SMALL LETTER E WITH CIRCUMFLEX */
382
{{'e', '"'}, 0x00eb}, /* LATIN SMALL LETTER E WITH DIAERESIS */
383
{{'e', ':'}, 0x00eb}, /* LATIN SMALL LETTER E WITH DIAERESIS */
384
{{'i', '`'}, 0x00ec}, /* LATIN SMALL LETTER I WITH GRAVE */
385
{{'i', '!'}, 0x00ec}, /* LATIN SMALL LETTER I WITH GRAVE */
386
{{'i', '\''}, 0x00ed}, /* LATIN SMALL LETTER I WITH ACUTE */
387
{{'i', '^'}, 0x00ee}, /* LATIN SMALL LETTER I WITH CIRCUMFLEX */
388
{{'i', '>'}, 0x00ee}, /* LATIN SMALL LETTER I WITH CIRCUMFLEX */
389
{{'i', '"'}, 0x00ef}, /* LATIN SMALL LETTER I WITH DIAERESIS */
390
{{'i', ':'}, 0x00ef}, /* LATIN SMALL LETTER I WITH DIAERESIS */
391
{{'d', '-'}, 0x00f0}, /* LATIN SMALL LETTER ETH */
392
{{'n', '~'}, 0x00f1}, /* LATIN SMALL LETTER N WITH TILDE */
393
{{'n', '?'}, 0x00f1}, /* LATIN SMALL LETTER N WITH TILDE */
394
{{'o', '`'}, 0x00f2}, /* LATIN SMALL LETTER O WITH GRAVE */
395
{{'o', '!'}, 0x00f2}, /* LATIN SMALL LETTER O WITH GRAVE */
396
{{'o', '\''}, 0x00f3}, /* LATIN SMALL LETTER O WITH ACUTE */
397
{{'o', '^'}, 0x00f4}, /* LATIN SMALL LETTER O WITH CIRCUMFLEX */
398
{{'o', '>'}, 0x00f4}, /* LATIN SMALL LETTER O WITH CIRCUMFLEX */
399
{{'o', '~'}, 0x00f5}, /* LATIN SMALL LETTER O WITH TILDE */
400
{{'o', '?'}, 0x00f5}, /* LATIN SMALL LETTER O WITH TILDE */
401
{{'o', '"'}, 0x00f6}, /* LATIN SMALL LETTER O WITH DIAERESIS */
402
{{'o', ':'}, 0x00f6}, /* LATIN SMALL LETTER O WITH DIAERESIS */
403
{{'-', ':'}, 0x00f7}, /* DIVISION SIGN */
404
{{'o', '/'}, 0x00f8}, /* LATIN SMALL LETTER O WITH STROKE */
405
{{'u', '`'}, 0x00f9}, /* LATIN SMALL LETTER U WITH GRAVE */
406
{{'u', '!'}, 0x00f9}, /* LATIN SMALL LETTER U WITH GRAVE */
407
{{'u', '\''}, 0x00fa}, /* LATIN SMALL LETTER U WITH ACUTE */
408
{{'u', '^'}, 0x00fb}, /* LATIN SMALL LETTER U WITH CIRCUMFLEX */
409
{{'u', '>'}, 0x00fb}, /* LATIN SMALL LETTER U WITH CIRCUMFLEX */
410
{{'u', '"'}, 0x00fc}, /* LATIN SMALL LETTER U WITH DIAERESIS */
411
{{'u', ':'}, 0x00fc}, /* LATIN SMALL LETTER U WITH DIAERESIS */
412
{{'y', '\''}, 0x00fd}, /* LATIN SMALL LETTER Y WITH ACUTE */
413
{{'i', 'p'}, 0x00fe}, /* LATIN SMALL LETTER THORN */
414
{{'t', 'h'}, 0x00fe}, /* LATIN SMALL LETTER THORN */
415
{{'y', '"'}, 0x00ff}, /* LATIN SMALL LETTER Y WITH DIAERESIS */
416
{{'y', ':'}, 0x00ff}, /* LATIN SMALL LETTER Y WITH DIAERESIS */
417
{{'"', '['}, 0x00c4}, /* LATIN CAPITAL LETTER A WITH DIAERESIS */
418
{{'"', '\\'}, 0x00d6}, /* LATIN CAPITAL LETTER O WITH DIAERESIS */
419
{{'"', ']'}, 0x00dc}, /* LATIN CAPITAL LETTER U WITH DIAERESIS */
420
{{'"', '{'}, 0x00e4}, /* LATIN SMALL LETTER A WITH DIAERESIS */
421
{{'"', '|'}, 0x00f6}, /* LATIN SMALL LETTER O WITH DIAERESIS */
422
{{'"', '}'}, 0x00fc}, /* LATIN SMALL LETTER U WITH DIAERESIS */
423
{{'"', '~'}, 0x00df}, /* LATIN SMALL LETTER SHARP S */
426
#define RESIZE_FLAG_H 1
427
#define RESIZE_FLAG_V 2
428
#define RESIZE_FLAG_L 4
430
static char *resizeprompts[] = {
432
"resize -h # lines: ",
433
"resize -v # lines: ",
434
"resize -b # lines: ",
435
"resize -l # lines: ",
436
"resize -l -h # lines: ",
437
"resize -l -v # lines: ",
438
"resize -l -b # lines: ",
442
parse_input_int(buf, len, val)
448
if (len >= 1 && ((*buf == 'U' && buf[1] == '+') || (*buf == '0' && (buf[1] == 'x' || buf[1] == 'X'))))
451
for (i = 2; i < len; i++)
453
if (buf[i] >= '0' && buf[i] <= '9')
454
x = x * 16 | (buf[i] - '0');
455
else if (buf[i] >= 'a' && buf[i] <= 'f')
456
x = x * 16 | (buf[i] - ('a' - 10));
457
else if (buf[i] >= 'A' && buf[i] <= 'F')
458
x = x * 16 | (buf[i] - ('A' - 10));
463
else if (buf[0] == '0')
466
for (i = 1; i < len; i++)
468
if (buf[i] < '0' || buf[i] > '7')
470
x = x * 8 | (buf[i] - '0');
484
register unsigned int i;
489
for (i = 0; i < sizeof(ktab)/sizeof(*ktab); i++)
491
ktab[i].nr = RC_ILLEGAL;
492
ktab[i].args = noargs;
496
for (i = 0; i < KMAP_KEYS+KMAP_AKEYS; i++)
498
umtab[i].nr = RC_ILLEGAL;
499
umtab[i].args = noargs;
501
dmtab[i].nr = RC_ILLEGAL;
502
dmtab[i].args = noargs;
504
mmtab[i].nr = RC_ILLEGAL;
505
mmtab[i].args = noargs;
509
for (i = 0; i < NKMAPDEF; i++)
511
if (i + KMAPDEFSTART < T_CAPS)
513
if (i + KMAPDEFSTART >= T_CAPS + KMAP_KEYS)
517
argarr[0] = kmapdef[i];
518
SaveAction(dmtab + i + (KMAPDEFSTART - T_CAPS), RC_STUFF, argarr, 0);
520
for (i = 0; i < NKMAPADEF; i++)
522
if (i + KMAPADEFSTART < T_CURSOR)
524
if (i + KMAPADEFSTART >= T_CURSOR + KMAP_AKEYS)
526
if (kmapadef[i] == 0)
528
argarr[0] = kmapadef[i];
529
SaveAction(dmtab + i + (KMAPADEFSTART - T_CURSOR + KMAP_KEYS), RC_STUFF, argarr, 0);
531
for (i = 0; i < NKMAPMDEF; i++)
533
if (i + KMAPMDEFSTART < T_CAPS)
535
if (i + KMAPMDEFSTART >= T_CAPS + KMAP_KEYS)
537
if (kmapmdef[i] == 0)
539
argarr[0] = kmapmdef[i];
541
SaveAction(mmtab + i + (KMAPMDEFSTART - T_CAPS), RC_STUFF, argarr, 0);
545
ktab['h'].nr = RC_HARDCOPY;
547
ktab['z'].nr = ktab[Ctrl('z')].nr = RC_SUSPEND;
549
ktab['c'].nr = ktab[Ctrl('c')].nr = RC_SCREEN;
550
ktab[' '].nr = ktab[Ctrl(' ')].nr =
551
ktab['n'].nr = ktab[Ctrl('n')].nr = RC_NEXT;
552
ktab['N'].nr = RC_NUMBER;
553
ktab[Ctrl('h')].nr = ktab[0177].nr = ktab['p'].nr = ktab[Ctrl('p')].nr = RC_PREV;
554
ktab['k'].nr = ktab[Ctrl('k')].nr = RC_KILL;
555
ktab['l'].nr = ktab[Ctrl('l')].nr = RC_REDISPLAY;
556
ktab['w'].nr = ktab[Ctrl('w')].nr = RC_WINDOWS;
557
ktab['v'].nr = RC_VERSION;
558
ktab[Ctrl('v')].nr = RC_DIGRAPH;
559
ktab['q'].nr = ktab[Ctrl('q')].nr = RC_XON;
560
ktab['s'].nr = ktab[Ctrl('s')].nr = RC_XOFF;
561
ktab['t'].nr = ktab[Ctrl('t')].nr = RC_TIME;
562
ktab['i'].nr = ktab[Ctrl('i')].nr = RC_INFO;
563
ktab['m'].nr = ktab[Ctrl('m')].nr = RC_LASTMSG;
564
ktab['A'].nr = RC_TITLE;
565
#if defined(UTMPOK) && defined(LOGOUTOK)
566
ktab['L'].nr = RC_LOGIN;
568
ktab[','].nr = RC_LICENSE;
569
ktab['W'].nr = RC_WIDTH;
570
ktab['.'].nr = RC_DUMPTERMCAP;
571
ktab[Ctrl('\\')].nr = RC_QUIT;
573
ktab['d'].nr = ktab[Ctrl('d')].nr = RC_DETACH;
575
ktab['D'].nr = RC_POW_DETACH;
578
ktab['r'].nr = ktab[Ctrl('r')].nr = RC_WRAP;
579
ktab['f'].nr = ktab[Ctrl('f')].nr = RC_FLOW;
580
ktab['C'].nr = RC_CLEAR;
581
ktab['Z'].nr = RC_RESET;
582
ktab['H'].nr = RC_LOG;
583
ktab['M'].nr = RC_MONITOR;
584
ktab['?'].nr = RC_HELP;
586
ktab['*'].nr = RC_DISPLAYS;
592
SaveAction(ktab + '-', RC_SELECT, args, 0);
594
for (i = 0; i < ((maxwin && maxwin < 10) ? maxwin : 10); i++)
596
char *args[2], arg1[10];
599
sprintf(arg1, "%d", i);
600
SaveAction(ktab + '0' + i, RC_SELECT, args, 0);
602
ktab['\''].nr = RC_SELECT; /* calling a window by name */
607
SaveAction(ktab + '"', RC_WINDOWLIST, args, 0);
609
ktab[Ctrl('G')].nr = RC_VBELL;
610
ktab[':'].nr = RC_COLON;
612
ktab['['].nr = ktab[Ctrl('[')].nr = RC_COPY;
617
SaveAction(ktab + ']', RC_PASTE, args, 0);
618
SaveAction(ktab + Ctrl(']'), RC_PASTE, args, 0);
620
ktab['{'].nr = RC_HISTORY;
621
ktab['}'].nr = RC_HISTORY;
622
ktab['>'].nr = RC_WRITEBUF;
623
ktab['<'].nr = RC_READBUF;
624
ktab['='].nr = RC_REMOVEBUF;
627
ktab['D'].nr = RC_POW_DETACH;
630
ktab['x'].nr = ktab[Ctrl('x')].nr = RC_LOCKSCREEN;
632
ktab['b'].nr = ktab[Ctrl('b')].nr = RC_BREAK;
633
ktab['B'].nr = RC_POW_BREAK;
634
ktab['_'].nr = RC_SILENCE;
635
ktab['S'].nr = RC_SPLIT;
636
ktab['Q'].nr = RC_ONLY;
637
ktab['X'].nr = RC_REMOVE;
638
ktab['F'].nr = RC_FIT;
639
ktab['\t'].nr = RC_FOCUS;
644
SaveAction(ktab + T_BACKTAB - T_CAPS + 256, RC_FOCUS, args, 0);
650
SaveAction(ktab + '|', RC_SPLIT, args, 0);
652
/* These come last; they may want overwrite others: */
655
ClearAction(&ktab[DefaultEsc]);
656
ktab[DefaultEsc].nr = RC_OTHER;
658
if (DefaultMetaEsc >= 0)
660
ClearAction(&ktab[DefaultMetaEsc]);
661
ktab[DefaultMetaEsc].nr = RC_META;
664
idleaction.nr = RC_BLANKER;
665
idleaction.args = noargs;
669
static struct action *
670
FindKtab(class, create)
674
struct kclass *kp, **kpp;
679
for (kpp = &kclasses; (kp = *kpp) != 0; kpp = &kp->next)
680
if (!strcmp(kp->name, class))
686
if (strlen(class) > 80)
688
Msg(0, "Command class name too long.");
691
kp = malloc(sizeof(*kp));
694
Msg(0, "%s", strnomem);
697
kp->name = SaveStr(class);
698
for (i = 0; i < (int)(sizeof(kp->ktab)/sizeof(*kp->ktab)); i++)
700
kp->ktab[i].nr = RC_ILLEGAL;
701
kp->ktab[i].args = noargs;
702
kp->ktab[i].argl = 0;
703
kp->ktab[i].quiet = 0;
717
if (act->nr == RC_ILLEGAL)
719
act->nr = RC_ILLEGAL;
720
if (act->args == noargs)
722
for (p = act->args; *p; p++)
724
free((char *)act->args);
730
* ProcessInput: process input from display and feed it into
731
* the layer on canvas D_forecv.
737
* This ProcessInput just does the keybindings and passes
738
* everything else on to ProcessInput2.
742
ProcessInput(ibuf, ilen)
747
unsigned char *s, *q;
751
debug1("ProcessInput: %d bytes\n", ilen);
752
if (display == 0 || ilen == 0)
757
s = (unsigned char *)ibuf;
761
if (D_dontmap || !D_nseqs)
768
debug3("cmp %c %c[%d]\n", ch, *D_seqp, D_seqp - D_kmaps);
771
l = D_seqp[D_seqp[-D_seql-1] + 1];
775
debug1("miss %d\n", D_seqp - D_kmaps);
778
debug("complete miss\n");
781
p = (char *)D_seqp - l;
783
D_seqp = D_kmaps + 3;
786
if ((q = D_seqh) != 0)
789
i = q[0] << 8 | q[1];
790
i &= ~KMAP_NOTIMEOUT;
791
debug1("Mapping former hit #%d - ", i);
792
debug2("%d(%s) - ", q[2], q + 3);
794
ProcessInput2((char *)q + 3, q[2]);
802
debug1("flush old %d\n", l);
811
/* Finish old stuff */
813
debug1("finish old %d\n", slen);
815
ProcessInput2(ibuf, slen);
824
debug2("length am %d, want %d\n", l, D_seqp[-l - 1]);
825
if (l == D_seqp[-l - 1])
830
if (D_kmaps + D_nseqs > q && q[2] > l && !bcmp(D_seqp - l, q + 3, l))
832
debug1("have another mapping (%s), delay execution\n", q + 3);
833
D_seqh = D_seqp - 3 - l;
838
i = D_seqp[-l - 3] << 8 | D_seqp[-l - 2];
839
i &= ~KMAP_NOTIMEOUT;
840
debug1("Mapping #%d - ", i);
841
p = (char *)D_seqp - l;
842
debug2("%d(%s) - ", l, p);
844
D_seqp = D_kmaps + 3;
856
debug("am in sequence -> check for timeout\n");
858
for (s = D_seqp; ; s += i * 2 + 4)
860
if (s[-l-3] & KMAP_NOTIMEOUT >> 8)
862
if ((i = s[s[-l-1] + 1]) == 0)
864
SetTimeout(&D_mapev, maptimeout);
870
ProcessInput2(ibuf, slen);
874
# define ProcessInput2 ProcessInput
879
* Here only the screen escape commands are handled.
883
ProcessInput2(ibuf, ilen)
889
struct action *ktabp;
891
debug1("ProcessInput2: %d bytes\n", ilen);
892
while (ilen && display)
894
debug1(" - ilen now %d bytes\n", ilen);
895
flayer = D_forecv->c_layer;
903
if ((unsigned char)*s++ == D_user->u_Esc)
909
DoProcess(fore, &ibuf, &slen, 0);
913
WindowChanged(fore, 'E');
918
ktabp = D_ESCseen ? D_ESCseen : ktab;
922
WindowChanged(fore, 'E');
924
ch = (unsigned char)*s;
927
* As users have different esc characters, but a common ktab[],
928
* we fold back the users esc and meta-esc key to the Default keys
929
* that can be looked up in the ktab[]. grmbl. jw.
930
* XXX: make ktab[] a per user thing.
932
if (ch == D_user->u_Esc)
934
else if (ch == D_user->u_MetaEsc)
938
DoAction(&ktabp[ch], ch);
939
ibuf = (char *)(s + 1);
945
DoProcess(p, bufp, lenp, pa)
952
struct display *d = display;
955
/* XXX -> PasteStart */
956
if (pa && *lenp > 1 && p && p->w_slowpaste)
958
/* schedule slowpaste event */
959
SetTimeout(&p->w_paster.pa_slowev, p->w_slowpaste);
960
evenq(&p->w_paster.pa_slowev);
964
while (flayer && *lenp)
967
if (!pa && p && p->w_paster.pa_pastelen && flayer == p->w_paster.pa_pastelayer)
969
debug("layer is busy - beep!\n");
970
WBell(p, visual_bell);
978
LayProcess(bufp, lenp);
980
if (pa && !pa->pa_pastelayer)
981
break; /* flush rest of paste */
990
/* We're full, let's beep */
991
debug("layer is full - beep!\n");
992
WBell(p, visual_bell);
1000
if (pa && pa->pa_pastelen == 0)
1009
int x, m, l = 0, r = RC_LAST;
1013
x = strcmp(str, comms[m].name);
1025
CheckArgNum(nr, args)
1030
static char *argss[] = {"no", "one", "two", "three", "four", "OOPS"};
1031
static char *orformat[] =
1033
"%s: %s: %s argument%s required",
1034
"%s: %s: %s or %s argument%s required",
1035
"%s: %s: %s, %s or %s argument%s required",
1036
"%s: %s: %s, %s, %s or %s argument%s required"
1039
n = comms[nr].flags & ARGS_MASK;
1040
for (i = 0; args[i]; i++)
1042
if (comms[nr].flags & ARGS_ORMORE)
1046
Msg(0, "%s: %s: at least %s argument%s required",
1047
rc_name, comms[nr].name, argss[n], n != 1 ? "s" : "");
1051
else if ((comms[nr].flags & ARGS_PLUS1) &&
1052
(comms[nr].flags & ARGS_PLUS2) &&
1053
(comms[nr].flags & ARGS_PLUS3))
1055
if (i != n && i != n + 1 && i != n + 2 && i != n + 3)
1057
Msg(0, orformat[3], rc_name, comms[nr].name, argss[n],
1058
argss[n + 1], argss[n + 2], argss[n + 3], "");
1062
else if ((comms[nr].flags & ARGS_PLUS1) &&
1063
(comms[nr].flags & ARGS_PLUS2))
1065
if (i != n && i != n + 1 && i != n + 2)
1067
Msg(0, orformat[2], rc_name, comms[nr].name, argss[n],
1068
argss[n + 1], argss[n + 2], "");
1072
else if ((comms[nr].flags & ARGS_PLUS1) &&
1073
(comms[nr].flags & ARGS_PLUS3))
1075
if (i != n && i != n + 1 && i != n + 3)
1077
Msg(0, orformat[2], rc_name, comms[nr].name, argss[n],
1078
argss[n + 1], argss[n + 3], "");
1082
else if ((comms[nr].flags & ARGS_PLUS2) &&
1083
(comms[nr].flags & ARGS_PLUS3))
1085
if (i != n && i != n + 2 && i != n + 3)
1087
Msg(0, orformat[2], rc_name, comms[nr].name, argss[n],
1088
argss[n + 2], argss[n + 3], "");
1092
else if (comms[nr].flags & ARGS_PLUS1)
1094
if (i != n && i != n + 1)
1096
Msg(0, orformat[1], rc_name, comms[nr].name, argss[n],
1097
argss[n + 1], n != 0 ? "s" : "");
1101
else if (comms[nr].flags & ARGS_PLUS2)
1103
if (i != n && i != n + 2)
1105
Msg(0, orformat[1], rc_name, comms[nr].name, argss[n],
1110
else if (comms[nr].flags & ARGS_PLUS3)
1112
if (i != n && i != n + 3)
1114
Msg(0, orformat[1], rc_name, comms[nr].name, argss[n],
1121
Msg(0, orformat[0], rc_name, comms[nr].name, argss[n], n != 1 ? "s" : "");
1128
StuffFin(buf, len, data)
1136
LayProcess(&buf, &len);
1139
/* If the command is not 'quieted', then use Msg to output the message. If it's a remote
1140
* query, then Msg takes care of also outputting the message to the querying client.
1142
* If we want the command to be quiet, and it's a remote query, then use QueryMsg so that
1143
* the response does go back to the querying client.
1145
* If the command is quieted, and it's not a remote query, then just don't print the message.
1147
#define OutputMsg (!act->quiet ? Msg : queryflag >= 0 ? QueryMsg : Dummy)
1156
char **args = act->args;
1157
int *argl = act->argl;
1159
int argc, i, n, msgok;
1162
struct display *odisplay = display;
1163
struct acluser *user;
1165
user = display ? D_user : users;
1166
if (nr == RC_ILLEGAL)
1168
debug1("key '%c': No action\n", key);
1171
n = comms[nr].flags;
1172
/* Commands will have a CAN_QUERY flag, depending on whether they have
1173
* something to return on a query. For example, 'windows' can return a result,
1174
* but 'other' cannot.
1175
* If some command causes an error, then it should reset queryflag to -1, so that
1176
* the process requesting the query can be notified that an error happened.
1178
if (!(n & CAN_QUERY) && queryflag >= 0)
1180
/* Query flag is set, but this command cannot be queried. */
1181
OutputMsg(0, "%s command cannot be queried.", comms[nr].name);
1185
if ((n & NEED_DISPLAY) && display == 0)
1187
OutputMsg(0, "%s: %s: display required", rc_name, comms[nr].name);
1191
if ((n & NEED_FORE) && fore == 0)
1193
OutputMsg(0, "%s: %s: window required", rc_name, comms[nr].name);
1197
if ((n & NEED_LAYER) && flayer == 0)
1199
OutputMsg(0, "%s: %s: display or window required", rc_name, comms[nr].name);
1203
if ((argc = CheckArgNum(nr, args)) < 0)
1208
if (AclCheckPermCmd(D_user, ACL_EXEC, &comms[nr]))
1210
OutputMsg(0, "%s: %s: permission denied (user %s)",
1211
rc_name, comms[nr].name, (EffectiveAclUser ? EffectiveAclUser : D_user)->u_name);
1216
#endif /* MULTIUSER */
1218
msgok = display && !*rc_name;
1224
else if (args[0][0] == '-' && !args[0][1])
1226
SetForeWindow((struct win *)0);
1229
else if (args[0][0] == '.' && !args[0][1])
1233
OutputMsg(0, "select . needs a window");
1238
SetForeWindow(fore);
1242
else if (ParseWinNum(act, &n) == 0)
1244
else if (queryflag >= 0)
1245
queryflag = -1; /* ParseWinNum already prints out an appropriate error message. */
1248
case RC_DEFAUTONUKE:
1249
if (ParseOnOff(act, &defautonuke) == 0 && msgok)
1250
OutputMsg(0, "Default autonuke turned %s", defautonuke ? "on" : "off");
1251
if (display && *rc_name)
1252
D_auto_nuke = defautonuke;
1255
if (ParseOnOff(act, &D_auto_nuke) == 0 && msgok)
1256
OutputMsg(0, "Autonuke turned %s", D_auto_nuke ? "on" : "off");
1259
case RC_DEFOBUFLIMIT:
1260
if (ParseNum(act, &defobuflimit) == 0 && msgok)
1261
OutputMsg(0, "Default limit set to %d", defobuflimit);
1262
if (display && *rc_name)
1264
D_obufmax = defobuflimit;
1265
D_obuflenmax = D_obuflen - D_obufmax;
1270
OutputMsg(0, "Limit is %d, current buffer size is %d", D_obufmax, D_obuflen);
1271
else if (ParseNum(act, &D_obufmax) == 0 && msgok)
1272
OutputMsg(0, "Limit set to %d", D_obufmax);
1273
D_obuflenmax = D_obuflen - D_obufmax;
1275
case RC_DUMPTERMCAP:
1276
WriteFile(user, (char *)0, DUMP_TERMCAP);
1280
int mode = DUMP_HARDCOPY;
1285
if (!strcmp(*args, "-h"))
1287
mode = DUMP_SCROLLBACK;
1290
else if (!strcmp(*args, "--") && args[1])
1296
if (args[0] && file == args[0] && args[1])
1298
OutputMsg(0, "%s: hardcopy: too many arguments", rc_name);
1301
WriteFile(user, file, mode);
1305
(void)ParseOnOff(act, &nwin_default.Lflag);
1308
n = fore->w_log ? 1 : 0;
1309
ParseSwitch(act, &n);
1319
SwitchWindow(NextWindow());
1323
SwitchWindow(PreviousWindow());
1332
Input(fore->w_pwin ? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW, confirm_fn, NULL, RC_KILL);
1334
Input("Really kill this window [y/n]", 1, INP_RAW, confirm_fn, NULL, RC_KILL);
1342
FreePseudowin(fore);
1343
OutputMsg(0, "Filter removed.");
1347
name = SaveStr(fore->w_title);
1349
OutputMsg(0, "Window %d (%s) killed.", n, name);
1357
Input("Really quit and kill all your windows [y/n]", 1, INP_RAW, confirm_fn, NULL, RC_QUIT);
1364
if (*args && !strcmp(*args, "-h"))
1376
Input(buf, 1, INP_RAW, pow_detach_fn, NULL, 0);
1379
Detach(D_POWER); /* detach and kill Attacher's parent */
1388
OutputMsg(0, "debugging info is written to %s/", DEBUGDIR);
1390
OutputMsg(0, "debugging is currently off. Use 'debug on' to enable.");
1395
debug("debug: closing debug file.\n");
1400
if (strcmp("off", *args))
1404
kill(D_userpid, SIG_NODEBUG); /* a one shot item, but hey... */
1405
# endif /* SIG_NODEBUG */
1407
if (*args == 0 || strcmp("off", *args))
1408
OutputMsg(0, "Sorry, screen was compiled without -DDEBUG option.");
1413
if (*args && !strcmp(*args, "sendcmd"))
1417
free(zmodem_sendcmd);
1418
zmodem_sendcmd = SaveStr(args[1]);
1421
OutputMsg(0, "zmodem sendcmd: %s", zmodem_sendcmd);
1424
if (*args && !strcmp(*args, "recvcmd"))
1428
free(zmodem_recvcmd);
1429
zmodem_recvcmd = SaveStr(args[1]);
1432
OutputMsg(0, "zmodem recvcmd: %s", zmodem_recvcmd);
1437
for (i = 0; i < 4; i++)
1438
if (!strcmp(zmodes[i], *args))
1440
if (i == 4 && !strcmp(*args, "on"))
1444
OutputMsg(0, "usage: zmodem off|auto|catch|pass");
1450
OutputMsg(0, "zmodem mode is %s", zmodes[zmodem_mode]);
1455
register unsigned int i;
1457
for (i = 0; i < sizeof(ktab)/sizeof(*ktab); i++)
1458
ClearAction(&ktab[i]);
1459
OutputMsg(0, "Unbound all keys." );
1466
ZombieKey_destroy = 0;
1469
if (*argl == 0 || *argl > 2)
1471
OutputMsg(0, "%s:zombie: one or two characters expected.", rc_name);
1476
if (!strcmp(args[1], "onerror"))
1478
ZombieKey_onerror = 1;
1480
OutputMsg(0, "usage: zombie [keys [onerror]]");
1484
ZombieKey_onerror = 0;
1485
ZombieKey_destroy = args[0][0];
1486
ZombieKey_resurrect = *argl == 2 ? args[0][1] : 0;
1496
struct display *olddisplay = display;
1497
display = 0; /* no display will cause a broadcast */
1498
OutputMsg(0, "%s: %s", s, *args);
1499
display = olddisplay;
1503
/* where this AT command comes from: */
1507
s = SaveStr(user->u_name);
1508
/* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
1509
EffectiveAclUser = user;
1511
s = SaveStr(display ? D_usertty : user->u_name);
1513
n = strlen(args[0]);
1516
* the windows/displays loops are quite dangerous here, take extra
1517
* care not to trigger landmines. Things may appear/disappear while
1518
* we are walking along.
1522
case '*': /* user */
1531
for (u = users; u; u = u->u_next)
1533
debug3("strncmp('%s', '%s', %d)\n", *args, u->u_name, n);
1534
if (!strncmp(*args, u->u_name, n))
1540
OutputMsg(0, "Did not find any user matching '%s'", args[0]);
1544
debug1("at all displays of user %s\n", u->u_name);
1545
for (display = displays; display; display = nd)
1547
nd = display->d_next;
1550
flayer = D_forecv->c_layer;
1554
debug1("AT display %s\n", D_usertty);
1555
DoCommand(args + 1, argl + 1);
1557
OutputMsg(0, "command from %s: %s %s",
1558
s, args[1], args[2] ? args[2] : "");
1565
case '%': /* display */
1569
debug1("at display matching '%s'\n", args[0]);
1570
for (display = displays; display; display = nd)
1572
nd = display->d_next;
1576
flayer = D_forecv->c_layer;
1577
if (strncmp(args[0], D_usertty, n) &&
1578
(strncmp("/dev/", D_usertty, 5) ||
1579
strncmp(args[0], D_usertty + 5, n)) &&
1580
(strncmp("/dev/tty", D_usertty, 8) ||
1581
strncmp(args[0], D_usertty + 8, n)))
1583
debug1("AT display %s\n", D_usertty);
1584
DoCommand(args + 1, argl + 1);
1586
OutputMsg(0, "command from %s: %s %s",
1587
s, args[1], args[2] ? args[2] : "");
1594
case '#': /* window */
1605
if (!*args[0] || (i = WindowByNumber(args[0])) < 0)
1607
args[0][n] = ch; /* must restore string in case of bind */
1608
/* try looping over titles */
1609
for (fore = windows; fore; fore = nw)
1612
if (strncmp(args[0], fore->w_title, n))
1614
debug2("AT window %d(%s)\n", fore->w_number, fore->w_title);
1616
* consider this a bug or a feature:
1617
* while looping through windows, we have fore AND
1618
* display context. This will confuse users who try to
1619
* set up loops inside of loops, but often allows to do
1620
* what you mean, even when you adress your context wrong.
1623
/* XXX: other displays? */
1624
if (fore->w_layer.l_cvlist)
1625
display = fore->w_layer.l_cvlist->c_display;
1626
flayer = fore->w_savelayer ? fore->w_savelayer : &fore->w_layer;
1627
DoCommand(args + 1, argl + 1); /* may destroy our display */
1628
if (fore && fore->w_layer.l_cvlist)
1630
display = fore->w_layer.l_cvlist->c_display;
1631
OutputMsg(0, "command from %s: %s %s",
1632
s, args[1], args[2] ? args[2] : "");
1638
OutputMsg(0, "%s: at '%s': no such window.\n", rc_name, args[0]);
1641
else if (i < maxwin && (fore = wtab[i]))
1643
args[0][n] = ch; /* must restore string in case of bind */
1644
debug2("AT window %d (%s)\n", fore->w_number, fore->w_title);
1645
if (fore->w_layer.l_cvlist)
1646
display = fore->w_layer.l_cvlist->c_display;
1647
flayer = fore->w_savelayer ? fore->w_savelayer : &fore->w_layer;
1648
DoCommand(args + 1, argl + 1);
1649
if (fore && fore->w_layer.l_cvlist)
1651
display = fore->w_layer.l_cvlist->c_display;
1652
OutputMsg(0, "command from %s: %s %s",
1653
s, args[1], args[2] ? args[2] : "");
1659
OutputMsg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name);
1665
EffectiveAclUser = NULL;
1672
i = fore ? fore->w_encoding : display ? display->d_encoding : 0;
1673
if (args[0] && args[1] && !strcmp(args[0], "-e"))
1675
i = FindEncoding(args[1]);
1678
OutputMsg(0, "%s: readreg: unknown encoding", rc_name);
1685
* Without arguments we prompt for a destination register.
1686
* It will receive the copybuffer contents.
1687
* This is not done by RC_PASTE, as we prompt for source
1690
if ((s = *args) == NULL)
1692
Input("Copy to register:", 1, INP_RAW, copy_reg_fn, NULL, 0);
1697
OutputMsg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name);
1702
* With two arguments we *really* read register contents from file
1708
OutputMsg(0, "%s: readreg: too many arguments", rc_name);
1711
if ((s = ReadFile(args[1], &n)))
1713
struct plop *pp = plop_tab + (int)(unsigned char)ch;
1726
* with one argument we copy the copybuffer into a specified register
1727
* This could be done with RC_PASTE too, but is here to be consistent
1728
* with the zero argument call.
1730
copy_reg_fn(&ch, 0, NULL);
1735
i = fore ? fore->w_encoding : display ? display->d_encoding : 0;
1736
if (args[0] && args[1] && !strcmp(args[0], "-e"))
1738
i = FindEncoding(args[1]);
1741
OutputMsg(0, "%s: register: unknown encoding", rc_name);
1750
OutputMsg(0, "%s: register: illegal number of arguments.", rc_name);
1755
OutputMsg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name);
1762
if (user->u_plop.buf != NULL)
1763
UserFreeCopyBuffer(user);
1764
if (args[1] && args[1][0])
1766
user->u_plop.buf = SaveStrn(args[1], argl[1]);
1767
user->u_plop.len = argl[1];
1769
user->u_plop.enc = i;
1776
struct plop *plp = plop_tab + (int)(unsigned char)ch;
1780
plp->buf = SaveStrn(args[1], argl[1]);
1788
if ((s = *args) == NULL)
1790
Input("Process register:", 1, INP_RAW, process_fn, NULL, 0);
1795
OutputMsg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name);
1799
process_fn(&ch, 0, NULL);
1805
Input("Stuff:", 100, INP_COOKED, StuffFin, NULL, 0);
1811
if (strcmp(s, "-k"))
1813
OutputMsg(0, "%s: stuff: invalid option %s", rc_name, s);
1817
for (i = T_CAPS; i < T_OCAPS; i++)
1818
if (strcmp(term[i].tcname, s) == 0)
1822
OutputMsg(0, "%s: stuff: unknown key '%s'", rc_name, s);
1826
if (StuffKey(i - T_CAPS) == 0)
1829
s = display ? D_tcs[i].str : 0;
1844
OutputMsg(0, "screen %s", version);
1849
timestring = SaveStr(*args);
1852
OutputMsg(0, "%s", MakeWinMsg(timestring, fore, '%'));
1862
struct action *ktabp = ktab;
1863
if (argc == 2 && !strcmp(*args, "-c"))
1865
if ((ktabp = FindKtab(args[1], 0)) == 0)
1867
OutputMsg(0, "Unknown command class '%s'", args[1]);
1871
if (D_ESCseen != ktab || ktabp != ktab)
1873
if (D_ESCseen != ktabp)
1876
WindowChanged(fore, 'E');
1883
WindowChanged(fore, 'E');
1889
SwitchWindow(display && D_other ? D_other->w_number : NextWindow());
1892
if (user->u_Esc == -1)
1911
case RC_DEFBREAKTYPE:
1914
static char *types[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL };
1915
extern int breaktype;
1919
if (ParseNum(act, &n))
1920
for (n = 0; n < (int)(sizeof(types)/sizeof(*types)); n++)
1922
for (i = 0; i < 4; i++)
1925
if (ch >= 'a' && ch <= 'z')
1927
if (ch != types[n][i] && (ch + ('a' - 'A')) != types[n][i])
1933
if (n < 0 || n >= (int)(sizeof(types)/sizeof(*types)))
1934
OutputMsg(0, "%s invalid, chose one of %s, %s or %s", *args, types[0], types[1], types[2]);
1938
OutputMsg(0, "breaktype set to (%d) %s", n, types[n]);
1942
OutputMsg(0, "breaktype is (%d) %s", breaktype, types[breaktype]);
1948
if (*args && ParseNum(act, &n))
1950
SendBreak(fore, n, nr == RC_POW_BREAK);
1964
if (*args && !strcmp(*args, "-w"))
1966
else if (*args && !strcmp(*args, "-d"))
1970
if (what == 0 && flayer && !display)
1976
OutputMsg(0, "%s: %s: window required", rc_name, comms[nr].name);
1979
w = flayer->l_width;
1980
h = flayer->l_height;
1986
OutputMsg(0, "%s: %s: display required", rc_name, comms[nr].name);
1992
if (*args && args[0][0] == '-')
1994
OutputMsg(0, "%s: %s: unknown option %s", rc_name, comms[nr].name, *args);
1997
if (nr == RC_HEIGHT)
2005
else if (h == H1height)
2007
else if (h > (H0height + H1height) / 2)
2025
else if (w == Z1width)
2027
else if (w > (Z0width + Z1width) / 2)
2039
if (*args && args[1] && args[2])
2041
OutputMsg(0, "%s: %s: too many arguments", rc_name, comms[nr].name);
2046
OutputMsg(0, "Illegal width");
2051
OutputMsg(0, "Illegal height");
2056
if (flayer->l_width == w && flayer->l_height == h)
2058
ResizeLayer(flayer, w, h, (struct display *)0);
2061
if (D_width == w && D_height == h)
2065
ChangeScreenSize(w, h, 1);
2069
if (ResizeDisplay(w, h) == 0)
2071
Activate(D_fore ? D_fore->w_norefresh : 0);
2073
ResizeLayer(D_forecv->c_layer, D_forecv->c_xe - D_forecv->c_xs + 1, D_forecv->c_ye - D_forecv->c_ys + 1, 0);
2077
OutputMsg(0, "Your termcap does not specify how to change the terminal's width to %d.", w);
2078
else if (w == D_width)
2079
OutputMsg(0, "Your termcap does not specify how to change the terminal's height to %d.", h);
2081
OutputMsg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w, h);
2089
OutputMsg(0, "%s", fore->w_title);
2097
ChangeAKA(fore, *args, strlen(*args));
2100
Input(":", MAXSTR, INP_EVERY, Colonfin, NULL, 0);
2101
if (*args && **args)
2109
if (D_status_lastmsg)
2110
OutputMsg(0, "%s", D_status_lastmsg);
2113
DoScreen("key", args);
2116
if (ParseSwitch(act, &fore->w_wrap) == 0 && msgok)
2117
OutputMsg(0, "%cwrap", fore->w_wrap ? '+' : '-');
2122
if (args[0][0] == 'a')
2124
fore->w_flow = (fore->w_flow & FLOW_AUTO) ? FLOW_AUTOFLAG |FLOW_AUTO|FLOW_NOW : FLOW_AUTOFLAG;
2128
if (ParseOnOff(act, &n))
2130
fore->w_flow = (fore->w_flow & FLOW_AUTO) | n;
2135
if (fore->w_flow & FLOW_AUTOFLAG)
2136
fore->w_flow = (fore->w_flow & FLOW_AUTO) | FLOW_NOW;
2137
else if (fore->w_flow & FLOW_NOW)
2138
fore->w_flow &= ~FLOW_NOW;
2140
fore->w_flow = fore->w_flow ? FLOW_AUTOFLAG|FLOW_AUTO|FLOW_NOW : FLOW_AUTOFLAG;
2142
SetFlow(fore->w_flow & FLOW_NOW);
2144
OutputMsg(0, "%cflow%s", (fore->w_flow & FLOW_NOW) ? '+' : '-',
2145
(fore->w_flow & FLOW_AUTOFLAG) ? "(auto)" : "");
2148
case RC_DEFWRITELOCK:
2149
if (args[0][0] == 'a')
2150
nwin_default.wlock = WLOCK_AUTO;
2153
if (ParseOnOff(act, &n))
2155
nwin_default.wlock = n ? WLOCK_ON : WLOCK_OFF;
2161
if (args[0][0] == 'a')
2163
fore->w_wlock = WLOCK_AUTO;
2167
if (ParseOnOff(act, &n))
2169
fore->w_wlock = n ? WLOCK_ON : WLOCK_OFF;
2172
* user may have permission to change the writelock setting,
2173
* but he may never aquire the lock himself without write permission
2175
if (!AclCheckPermWin(D_user, ACL_WRITE, fore))
2176
fore->w_wlockuser = D_user;
2178
OutputMsg(0, "writelock %s", (fore->w_wlock == WLOCK_AUTO) ? "auto" :
2179
((fore->w_wlock == WLOCK_OFF) ? "off" : "on"));
2183
ResetAnsiState(fore);
2184
WriteString(fore, "\033[H\033[J", 6);
2187
ResetAnsiState(fore);
2189
if (fore->w_zdisplay)
2190
zmodem_abort(fore, fore->w_zdisplay);
2192
WriteString(fore, "\033c", 2);
2195
n = fore->w_monitor != MON_OFF;
2198
n = n && (ACLBYTE(fore->w_mon_notify, D_user->u_id) & ACLBIT(D_user->u_id));
2200
if (ParseSwitch(act, &n))
2205
if (display) /* we tell only this user */
2206
ACLBYTE(fore->w_mon_notify, D_user->u_id) |= ACLBIT(D_user->u_id);
2208
for (i = 0; i < maxusercount; i++)
2209
ACLBYTE(fore->w_mon_notify, i) |= ACLBIT(i);
2211
if (fore->w_monitor == MON_OFF)
2212
fore->w_monitor = MON_ON;
2213
OutputMsg(0, "Window %d (%s) is now being monitored for all activity.", fore->w_number, fore->w_title);
2218
if (display) /* we remove only this user */
2219
ACLBYTE(fore->w_mon_notify, D_user->u_id)
2220
&= ~ACLBIT(D_user->u_id);
2222
for (i = 0; i < maxusercount; i++)
2223
ACLBYTE(fore->w_mon_notify, i) &= ~ACLBIT(i);
2224
for (i = maxusercount - 1; i >= 0; i--)
2225
if (ACLBYTE(fore->w_mon_notify, i))
2229
fore->w_monitor = MON_OFF;
2230
OutputMsg(0, "Window %d (%s) is no longer being monitored for activity.", fore->w_number, fore->w_title);
2240
display_windows(0, WLIST_NUM, (struct win *)0);
2241
else if (!strcmp(*args, "string"))
2247
wliststr = SaveStr(args[1]);
2250
OutputMsg(0, "windowlist string is '%s'", wliststr);
2252
else if (!strcmp(*args, "title"))
2258
wlisttit = SaveStr(args[1]);
2261
OutputMsg(0, "windowlist title is '%s'", wlisttit);
2267
for (i = 0; i < argc; i++)
2270
else if (!strcmp(args[i], "-m"))
2272
else if (!strcmp(args[i], "-b"))
2274
else if (!strcmp(args[i], "-g"))
2275
flag |= WLIST_NESTED;
2278
OutputMsg(0, "usage: windowlist [-b] [-g] [-m] [string [string] | title [title]]");
2282
display_windows(blank, flag, (struct win *)0);
2286
if (argc == 2 && !strcmp(*args, "-c"))
2288
struct action *ktabp;
2289
if ((ktabp = FindKtab(args[1], 0)) == 0)
2291
OutputMsg(0, "Unknown command class '%s'", args[1]);
2294
display_help(args[1], ktabp);
2297
display_help((char *)0, ktab);
2300
display_copyright();
2304
if (flayer->l_layfn != &WinLf)
2306
OutputMsg(0, "Must be on a window layer");
2310
WindowChanged(fore, 'P');
2314
static char *pasteargs[] = {".", 0};
2315
static int pasteargl[] = {1};
2317
if (flayer->l_layfn != &WinLf)
2319
OutputMsg(0, "Must be on a window layer");
2322
if (GetHistory() == 0)
2324
if (user->u_plop.buf == NULL)
2332
char *ss, *dbuf, dch;
2339
* without args we prompt for one(!) register to be pasted in the window
2341
if ((s = *args) == NULL)
2343
Input("Paste from register:", 1, INP_RAW, ins_reg_fn, NULL, 0);
2346
if (args[1] == 0 && !fore) /* no window? */
2349
* with two arguments we paste into a destination register
2350
* (no window needed here).
2352
if (args[1] && argl[1] != 1)
2354
OutputMsg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
2360
enc = fore->w_encoding;
2364
* measure length of needed buffer
2366
for (ss = s = *args; (ch = *ss); ss++)
2372
enc = user->u_plop.enc;
2373
if (enc != user->u_plop.enc)
2374
l += RecodeBuf((unsigned char *)user->u_plop.buf, user->u_plop.len, user->u_plop.enc, enc, (unsigned char *)0);
2377
l += user->u_plop.len;
2383
enc = plop_tab[(int)(unsigned char)ch].enc;
2384
if (enc != plop_tab[(int)(unsigned char)ch].enc)
2385
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);
2388
l += plop_tab[(int)(unsigned char)ch].len;
2393
OutputMsg(0, "empty buffer");
2398
* if there is only one source and the destination is a window, then
2399
* pass a pointer rather than duplicating the buffer.
2401
if (s[1] == 0 && args[1] == 0)
2403
if (enc == (*s == '.' ? user->u_plop.enc : plop_tab[(int)(unsigned char)*s].enc))
2406
MakePaster(&fore->w_paster, *s == '.' ? user->u_plop.buf : plop_tab[(int)(unsigned char)*s].buf, l, 0);
2410
* if no shortcut, we construct a buffer
2412
if ((dbuf = (char *)malloc(l)) == 0)
2414
OutputMsg(0, "%s", strnomem);
2419
* concatenate all sources into our own buffer, copy buffer is
2420
* special and is skipped if no display exists.
2422
for (ss = s; (ch = *ss); ss++)
2424
struct plop *pp = (ch == '.' ? &user->u_plop : &plop_tab[(int)(unsigned char)ch]);
2428
l += RecodeBuf((unsigned char *)pp->buf, pp->len, pp->enc, enc, (unsigned char *)dbuf + l);
2432
bcopy(pp->buf, dbuf + l, pp->len);
2436
* when called with one argument we paste our buffer into the window
2440
MakePaster(&fore->w_paster, dbuf, l, 1);
2445
* we have two arguments, the second is already in dch.
2446
* use this as destination rather than the window.
2451
if (user->u_plop.buf != NULL)
2452
UserFreeCopyBuffer(user);
2453
user->u_plop.buf = dbuf;
2454
user->u_plop.len = l;
2456
user->u_plop.enc = enc;
2461
struct plop *pp = plop_tab + (int)(unsigned char)dch;
2474
if (!user->u_plop.buf)
2476
OutputMsg(0, "empty buffer");
2481
struct plop oldplop;
2483
oldplop = user->u_plop;
2484
if (args[0] && args[1] && !strcmp(args[0], "-e"))
2489
enc = FindEncoding(args[1]);
2492
OutputMsg(0, "%s: writebuf: unknown encoding", rc_name);
2495
if (enc != oldplop.enc)
2497
l = RecodeBuf((unsigned char *)oldplop.buf, oldplop.len, oldplop.enc, enc, (unsigned char *)0);
2498
newbuf = malloc(l + 1);
2501
OutputMsg(0, "%s", strnomem);
2504
user->u_plop.len = RecodeBuf((unsigned char *)oldplop.buf, oldplop.len, oldplop.enc, enc, (unsigned char *)newbuf);
2505
user->u_plop.buf = newbuf;
2506
user->u_plop.enc = enc;
2511
if (args[0] && args[1])
2512
OutputMsg(0, "%s: writebuf: too many arguments", rc_name);
2514
WriteFile(user, args[0], DUMP_EXCHANGE);
2516
if (user->u_plop.buf != oldplop.buf)
2517
free(user->u_plop.buf);
2518
user->u_plop = oldplop;
2524
i = fore ? fore->w_encoding : display ? display->d_encoding : 0;
2525
if (args[0] && args[1] && !strcmp(args[0], "-e"))
2527
i = FindEncoding(args[1]);
2530
OutputMsg(0, "%s: readbuf: unknown encoding", rc_name);
2536
if (args[0] && args[1])
2538
OutputMsg(0, "%s: readbuf: too many arguments", rc_name);
2541
if ((s = ReadFile(args[0] ? args[0] : BufferFile, &n)))
2543
if (user->u_plop.buf)
2544
UserFreeCopyBuffer(user);
2545
user->u_plop.len = n;
2546
user->u_plop.buf = s;
2548
user->u_plop.enc = i;
2556
(void)ParseSwitch(act, &search_ic);
2558
OutputMsg(0, "Will %signore case in searches", search_ic ? "" : "not ");
2560
#endif /* COPY_PASTE */
2563
SetEscape(user, -1, -1);
2564
else if (*argl == 2)
2565
SetEscape(user, (int)(unsigned char)args[0][0], (int)(unsigned char)args[0][1]);
2568
OutputMsg(0, "%s: two characters required after escape.", rc_name);
2571
/* Change defescape if master user. This is because we only
2574
if (display && user != users)
2579
SetEscape(NULL, -1, -1);
2580
else if (*argl == 2)
2581
SetEscape(NULL, (int)(unsigned char)args[0][0], (int)(unsigned char)args[0][1]);
2584
OutputMsg(0, "%s: two characters required after defescape.", rc_name);
2592
s = *args ? *args : home;
2594
OutputMsg(errno, "%s", s);
2598
if (ParseSaveStr(act, &ShellProg) == 0)
2599
ShellArgs[0] = ShellProg;
2601
case RC_HARDCOPYDIR:
2603
(void)ParseSaveStr(act, &hardcopydir);
2605
OutputMsg(0, "hardcopydir is %s\n", hardcopydir && *hardcopydir ? hardcopydir : "<cwd>");
2610
if (args[1] && !(strcmp(*args, "flush")))
2612
log_flush = atoi(args[1]);
2614
OutputMsg(0, "log flush timeout set to %ds\n", log_flush);
2617
if (ParseSaveStr(act, &screenlogfile) || !msgok)
2620
OutputMsg(0, "logfile is '%s'", screenlogfile);
2623
if (!*args || !strcmp(*args, "on") || !strcmp(*args, "off"))
2625
if (ParseSwitch(act, &logtstamp_on) == 0 && msgok)
2626
OutputMsg(0, "timestamps turned %s", logtstamp_on ? "on" : "off");
2628
else if (!strcmp(*args, "string"))
2632
if (logtstamp_string)
2633
free(logtstamp_string);
2634
logtstamp_string = SaveStr(args[1]);
2637
OutputMsg(0, "logfile timestamp is '%s'", logtstamp_string);
2639
else if (!strcmp(*args, "after"))
2643
logtstamp_after = atoi(args[1]);
2647
OutputMsg(0, "timestamp printed after %ds\n", logtstamp_after);
2650
OutputMsg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
2653
(void)ParseSaveStr(act, &nwin_default.aka);
2656
case RC_TERMCAPINFO:
2658
if (!rc_name || !*rc_name)
2659
OutputMsg(0, "Sorry, too late now. Place that in your .screenrc file.");
2662
break; /* Already handled */
2665
if (ParseSaveStr(act, &s))
2667
if (strlen(s) >= 20)
2669
OutputMsg(0, "%s: term: argument too long ( < 20)", rc_name);
2673
strcpy(screenterm, s);
2675
debug1("screenterm set to %s\n", screenterm);
2676
MakeTermcap((display == 0));
2677
debug("new termcap made\n");
2680
if (!msgok && (!rc_name || strcmp(rc_name, "-X")))
2683
* user typed ^A:echo... well, echo isn't FinishRc's job,
2684
* but as he wanted to test us, we show good will
2686
if (argc > 1 && !strcmp(*args, "-n"))
2692
if (argc > 1 && !strcmp(*args, "-p"))
2698
s = MakeWinMsg(s, fore, '%');
2701
OutputMsg(0, "%s", s);
2704
OutputMsg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name);
2713
AddXChars(buf, sizeof(buf), BellString);
2714
OutputMsg(0, "bell_msg is '%s'", buf);
2717
(void)ParseSaveStr(act, &BellString);
2722
BufferFile = SaveStr(DEFAULT_BUFFERFILE);
2723
else if (ParseSaveStr(act, &BufferFile))
2726
OutputMsg(0, "Bufferfile is now '%s'", BufferFile);
2730
(void)ParseSaveStr(act, &ActivityString);
2732
#if defined(DETACH) && defined(POW_DETACH)
2733
case RC_POW_DETACH_MSG:
2737
AddXChars(buf, sizeof(buf), PowDetachString);
2738
OutputMsg(0, "pow_detach_msg is '%s'", buf);
2741
(void)ParseSaveStr(act, &PowDetachString);
2744
#if defined(UTMPOK) && defined(LOGOUTOK)
2746
n = fore->w_slot != (slot_t)-1;
2747
if (*args && !strcmp(*args, "always"))
2754
if (*args && !strcmp(*args, "attached"))
2761
if (ParseSwitch(act, &n) == 0)
2765
if (!strcmp(*args, "always"))
2766
nwin_default.lflag |= 2;
2767
else if (!strcmp(*args, "attached"))
2768
nwin_default.lflag &= ~2;
2770
(void)ParseOnOff(act, &nwin_default.lflag);
2774
if (args[0] && args[1] && args[1][0] == 'i')
2777
for (display = displays; display; display = display->d_next)
2781
#if defined(TERMIO) || defined(POSIX)
2782
D_NewMode.tio.c_cc[VINTR] = D_OldMode.tio.c_cc[VINTR];
2783
D_NewMode.tio.c_lflag |= ISIG;
2784
#else /* TERMIO || POSIX */
2785
D_NewMode.m_tchars.t_intrc = D_OldMode.m_tchars.t_intrc;
2786
#endif /* TERMIO || POSIX */
2787
SetTTY(D_userfd, &D_NewMode);
2790
if (args[0] && args[0][0] == 'a')
2791
nwin_default.flowflag = FLOW_AUTOFLAG;
2793
(void)ParseOnOff(act, &nwin_default.flowflag);
2796
(void)ParseOnOff(act, &nwin_default.wrap);
2799
(void)ParseOnOff(act, &nwin_default.c1);
2803
(void)ParseOnOff(act, &nwin_default.bce);
2807
(void)ParseOnOff(act, &nwin_default.gr);
2810
if (ParseOnOff(act, &n) == 0)
2811
nwin_default.monitor = (n == 0) ? MON_OFF : MON_ON;
2813
case RC_DEFMOUSETRACK:
2814
if (ParseOnOff(act, &n) == 0)
2815
defmousetrack = (n == 0) ? 0 : 1000;
2820
OutputMsg(0, "Mouse tracking for this display is turned %s", D_mousetrack ? "on" : "off");
2822
else if (ParseOnOff(act, &n) == 0)
2824
D_mousetrack = n == 0 ? 0 : 1000;
2826
MouseMode(D_fore->w_mouse);
2830
if (ParseOnOff(act, &n) == 0)
2831
nwin_default.silence = (n == 0) ? SILENCE_OFF : SILENCE_ON;
2835
OutputMsg(0, "W%s echo command when creating windows.",
2836
VerboseCreate ? "ill" : "on't");
2837
else if (ParseOnOff(act, &n) == 0)
2843
OutputMsg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
2846
if (args[0] && strcmp(args[0], "on") && strcmp(args[0], "off"))
2848
struct display *olddisplay = display;
2849
int old_use, new_use = -1;
2852
if (!strncmp(s, "always", 6))
2854
if (!strcmp(s, "lastline"))
2855
new_use = HSTATUS_LASTLINE;
2856
else if (!strcmp(s, "ignore"))
2857
new_use = HSTATUS_IGNORE;
2858
else if (!strcmp(s, "message"))
2859
new_use = HSTATUS_MESSAGE;
2860
else if (!strcmp(args[0], "string"))
2865
AddXChars(buf, sizeof(buf), hstatusstring);
2866
OutputMsg(0, "hardstatus string is '%s'", buf);
2872
OutputMsg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name);
2877
hardstatusemu = new_use | (s == args[0] ? 0 : HSTATUS_ALWAYS);
2878
for (display = displays; display; display = display->d_next)
2881
new_use = hardstatusemu & ~HSTATUS_ALWAYS;
2882
if (D_HS && s == args[0])
2883
new_use = HSTATUS_HS;
2884
ShowHStatus((char *)0);
2885
old_use = D_has_hstatus;
2886
D_has_hstatus = new_use;
2887
if ((new_use == HSTATUS_LASTLINE && old_use != HSTATUS_LASTLINE) || (new_use != HSTATUS_LASTLINE && old_use == HSTATUS_LASTLINE))
2888
ChangeScreenSize(D_width, D_height, 1);
2895
free(hstatusstring);
2896
hstatusstring = SaveStr(args[1]);
2897
for (display = displays; display; display = display->d_next)
2900
display = olddisplay;
2903
(void)ParseSwitch(act, &use_hardstatus);
2905
OutputMsg(0, "messages displayed on %s", use_hardstatus ? "hardstatus line" : "window");
2908
if (strcmp(args[0], "always") == 0 || strcmp(args[0], "splitonly") == 0)
2910
struct display *olddisplay = display;
2912
captionalways = args[0][0] == 'a';
2913
for (display = displays; display; display = display->d_next)
2914
ChangeScreenSize(D_width, D_height, 1);
2915
display = olddisplay;
2917
else if (strcmp(args[0], "string") == 0)
2922
AddXChars(buf, sizeof(buf), captionstring);
2923
OutputMsg(0, "caption string is '%s'", buf);
2929
OutputMsg(0, "%s: usage: caption always|splitonly|string <string>", rc_name);
2935
free(captionstring);
2936
captionstring = SaveStr(args[1]);
2937
RedisplayDisplays(0);
2940
n = (console_window != 0);
2941
if (ParseSwitch(act, &n))
2943
if (TtyGrabConsole(fore->w_ptyfd, n, rc_name))
2946
OutputMsg(0, "%s: releasing console %s", rc_name, HostName);
2947
else if (console_window)
2948
OutputMsg(0, "%s: stealing console %s from window %d (%s)", rc_name,
2949
HostName, console_window->w_number, console_window->w_title);
2951
OutputMsg(0, "%s: grabbing console %s", rc_name, HostName);
2952
console_window = n ? fore : 0;
2955
if (ParseOnOff(act, &all_norefresh))
2957
if (!all_norefresh && fore)
2960
OutputMsg(0, all_norefresh ? "No refresh on window change!\n" :
2961
"Window specific refresh\n");
2964
(void)ParseSwitch(act, &n);
2965
fore->w_norefresh = n;
2968
if (ParseSwitch(act, &visual_bell) || !msgok)
2970
if (visual_bell == 0)
2971
OutputMsg(0, "switched to audible bell.");
2973
OutputMsg(0, "switched to visual bell.");
2976
if (ParseNum1000(act, &VBellWait) == 0 && msgok)
2977
OutputMsg(0, "vbellwait set to %.10g seconds", VBellWait/1000.);
2980
if (ParseNum1000(act, &MsgWait) == 0 && msgok)
2981
OutputMsg(0, "msgwait set to %.10g seconds", MsgWait/1000.);
2984
if (ParseNum1000(act, &MsgMinWait) == 0 && msgok)
2985
OutputMsg(0, "msgminwait set to %.10g seconds", MsgMinWait/1000.);
2987
case RC_SILENCEWAIT:
2988
if (ParseNum(act, &SilenceWait))
2990
if (SilenceWait < 1)
2992
for (p = windows; p; p = p->w_next)
2993
p->w_silencewait = SilenceWait;
2995
OutputMsg(0, "silencewait set to %d seconds", SilenceWait);
2999
OutputMsg(0, queryflag >= 0 ? "%d (%s)" : "This is window %d (%s).", fore->w_number, fore->w_title);
3002
int old = fore->w_number;
3004
if (args[0][0] == '+')
3006
else if (args[0][0] == '-')
3010
parse = ParseNum(act, &n);
3019
if (!WindowChangeNumber(fore, n))
3021
/* Window number could not be changed. */
3028
n = fore->w_silence != 0;
3029
i = fore->w_silencewait;
3030
if (args[0] && (args[0][0] == '-' || (args[0][0] >= '0' && args[0][0] <= '9')))
3032
if (ParseNum(act, &i))
3036
else if (ParseSwitch(act, &n))
3041
if (display) /* we tell only this user */
3042
ACLBYTE(fore->w_lio_notify, D_user->u_id) |= ACLBIT(D_user->u_id);
3044
for (n = 0; n < maxusercount; n++)
3045
ACLBYTE(fore->w_lio_notify, n) |= ACLBIT(n);
3047
fore->w_silencewait = i;
3048
fore->w_silence = SILENCE_ON;
3049
SetTimeout(&fore->w_silenceev, fore->w_silencewait * 1000);
3050
evenq(&fore->w_silenceev);
3054
OutputMsg(0, "The window is now being monitored for %d sec. silence.", fore->w_silencewait);
3059
if (display) /* we remove only this user */
3060
ACLBYTE(fore->w_lio_notify, D_user->u_id)
3061
&= ~ACLBIT(D_user->u_id);
3063
for (n = 0; n < maxusercount; n++)
3064
ACLBYTE(fore->w_lio_notify, n) &= ~ACLBIT(n);
3065
for (i = maxusercount - 1; i >= 0; i--)
3066
if (ACLBYTE(fore->w_lio_notify, i))
3071
fore->w_silence = SILENCE_OFF;
3072
evdeq(&fore->w_silenceev);
3076
OutputMsg(0, "The window is no longer being monitored for silence.");
3080
case RC_DEFSCROLLBACK:
3081
(void)ParseNum(act, &nwin_default.histheight);
3084
if (flayer->l_layfn == &MarkLf)
3086
OutputMsg(0, "Cannot resize scrollback buffer in copy/scrollback mode.");
3089
(void)ParseNum(act, &n);
3090
ChangeWindowSize(fore, fore->w_width, fore->w_height, n);
3092
OutputMsg(0, "scrollback set to %d", fore->w_histheight);
3095
case RC_SESSIONNAME:
3097
OutputMsg(0, "This session is named '%s'\n", SockName);
3100
char buf[MAXPATHLEN];
3103
if (ParseSaveStr(act, &s))
3105
if (!*s || strlen(s) + (SockName - SockPath) > MAXPATHLEN - 13 || index(s, '/'))
3107
OutputMsg(0, "%s: bad session name '%s'\n", rc_name, s);
3111
strncpy(buf, SockPath, SockName - SockPath);
3112
sprintf(buf + (SockName - SockPath), "%d.%s", (int)getpid(), s);
3114
if ((access(buf, F_OK) == 0) || (errno != ENOENT))
3116
OutputMsg(0, "%s: inappropriate path: '%s'.", rc_name, buf);
3119
if (rename(SockPath, buf))
3121
OutputMsg(errno, "%s: failed to rename(%s, %s)", rc_name, SockPath, buf);
3124
debug2("rename(%s, %s) done\n", SockPath, buf);
3125
strcpy(SockPath, buf);
3127
WindowChanged((struct win *)0, 'S');
3131
if (!args[0] || !args[1])
3133
debug1("RC_SETENV arguments missing: %s\n", args[0] ? args[0] : "");
3134
InputSetenv(args[0]);
3138
xsetenv(args[0], args[1]);
3147
case RC_DEFSLOWPASTE:
3148
(void)ParseNum(act, &nwin_default.slow);
3152
OutputMsg(0, fore->w_slowpaste ?
3153
"Slowpaste in window %d is %d milliseconds." :
3154
"Slowpaste in window %d is unset.",
3155
fore->w_number, fore->w_slowpaste);
3156
else if (ParseNum(act, &fore->w_slowpaste) == 0 && msgok)
3157
OutputMsg(0, fore->w_slowpaste ?
3158
"Slowpaste in window %d set to %d milliseconds." :
3159
"Slowpaste in window %d now unset.",
3160
fore->w_number, fore->w_slowpaste);
3163
if (CompileKeys(*args, *argl, mark_key_tab))
3165
OutputMsg(0, "%s: markkeys: syntax error.", rc_name);
3168
debug1("markkeys %s\n", *args);
3172
if (ParseSwitch(act, &pastefont) == 0 && msgok)
3173
OutputMsg(0, "Will %spaste font settings", pastefont ? "" : "not ");
3177
(void)ParseSwitch(act, &join_with_cr);
3179
case RC_COMPACTHIST:
3180
if (ParseSwitch(act, &compacthist) == 0 && msgok)
3181
OutputMsg(0, "%scompacting history lines", compacthist ? "" : "not ");
3186
(void)ParseOnOff(act, &nethackflag);
3189
case RC_HARDCOPY_APPEND:
3190
(void)ParseOnOff(act, &hardcopy_append);
3196
AddXChars(buf, sizeof(buf), VisualBellString);
3197
OutputMsg(0, "vbell_msg is '%s'", buf);
3200
(void)ParseSaveStr(act, &VisualBellString);
3201
debug1(" new vbellstr '%s'\n", VisualBellString);
3204
if (ParseBase(act, *args, &n, 8, "octal"))
3206
if (n < 0 || n > 0777)
3208
OutputMsg(0, "%s: mode: Invalid tty mode %o", rc_name, n);
3213
OutputMsg(0, "Ttymode set to %03o", TtyMode);
3216
(void)ParseOnOff(act, &auto_detach);
3218
case RC_STARTUP_MESSAGE:
3219
(void)ParseOnOff(act, &default_startup);
3225
n = (*user->u_password) ? 1 : 0;
3226
if (user->u_password != NullStr) free((char *)user->u_password);
3227
user->u_password = SaveStr(*args);
3228
if (!strcmp(user->u_password, "none"))
3231
OutputMsg(0, "Password checking disabled");
3232
free(user->u_password);
3233
user->u_password = NullStr;
3240
OutputMsg(0, "%s: password: window required", rc_name);
3243
Input("New screen password:", 100, INP_NOECHO, pass1, display ? (char *)D_user : (char *)users, 0);
3246
#endif /* PASSWORD */
3249
struct action *ktabp = ktab;
3254
if (argc > 2 && !strcmp(*args, "-c"))
3256
ktabp = FindKtab(args[1], 1);
3263
else if (argc > 1 && !strcmp(*args, "-k"))
3276
for (n = 0; n < KMAP_KEYS; n++)
3277
if (strcmp(term[n + T_CAPS].tcname, *args) == 0)
3281
OutputMsg(0, "%s: bind: unknown key '%s'", rc_name, *args);
3290
OutputMsg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name);
3294
n = (unsigned char)args[0][0];
3298
if ((i = FindCommnr(args[1])) == RC_ILLEGAL)
3300
OutputMsg(0, "%s: bind: unknown command '%s'", rc_name, args[1]);
3303
if (CheckArgNum(i, args + 2) < 0)
3305
ClearAction(&ktabp[n]);
3306
SaveAction(ktabp + n, i, args + 2, argl + 2);
3309
ClearAction(&ktabp[n]);
3315
struct action *newact;
3316
int newnr, fl = 0, kf = 0, af = 0, df = 0, mf = 0;
3317
struct display *odisp = display;
3319
struct kmap_ext *kme = NULL;
3321
for (; *args && **args == '-'; args++, argl++)
3323
if (strcmp(*args, "-t") == 0)
3324
fl = KMAP_NOTIMEOUT;
3325
else if (strcmp(*args, "-k") == 0)
3327
else if (strcmp(*args, "-a") == 0)
3329
else if (strcmp(*args, "-d") == 0)
3331
else if (strcmp(*args, "-m") == 0)
3333
else if (strcmp(*args, "--") == 0)
3341
OutputMsg(0, "%s: bindkey: invalid option %s", rc_name, *args);
3347
OutputMsg(0, "%s: bindkey: -d does not work with -m", rc_name);
3353
display_bindkey("Edit mode", mmtab);
3355
display_bindkey("Default", dmtab);
3357
display_bindkey("User", umtab);
3364
OutputMsg(0, "%s: bindkey: -a only works with -k", rc_name);
3369
OutputMsg(0, "%s: bindkey: empty string makes no sense", rc_name);
3372
for (i = 0, kme = kmap_exts; i < kmap_extn; i++, kme++)
3379
if (*argl == (kme->fl & ~KMAP_NOTIMEOUT) && bcmp(kme->str, *args, *argl) == 0)
3385
OutputMsg(0, "%s: bindkey: keybinding not found", rc_name);
3389
kmap_exts = (struct kmap_ext *)xrealloc((char *)kmap_exts, kmap_extn * sizeof(*kmap_exts));
3390
kme = kmap_exts + i;
3391
bzero((char *)kme, 8 * sizeof(*kmap_exts));
3392
for (; i < kmap_extn; i++, kme++)
3395
kme->dm.nr = kme->mm.nr = kme->um.nr = RC_ILLEGAL;
3396
kme->dm.args = kme->mm.args = kme->um.args = noargs;
3397
kme->dm.argl = kme->mm.argl = kme->um.argl = 0;
3402
if (df == 0 && kme->dm.nr != RC_ILLEGAL)
3404
if (mf == 0 && kme->mm.nr != RC_ILLEGAL)
3406
if ((df || mf) && kme->um.nr != RC_ILLEGAL)
3408
i += KMAP_KEYS + KMAP_AKEYS;
3409
newact = df ? &kme->dm : mf ? &kme->mm : &kme->um;
3413
for (i = T_CAPS; i < T_OCAPS; i++)
3414
if (strcmp(term[i].tcname, *args) == 0)
3418
OutputMsg(0, "%s: bindkey: unknown key '%s'", rc_name, *args);
3421
if (af && i >= T_CURSOR && i < T_OCAPS)
3422
i -= T_CURSOR - KMAP_KEYS;
3425
newact = df ? &dmtab[i] : mf ? &mmtab[i] : &umtab[i];
3429
if ((newnr = FindCommnr(args[1])) == RC_ILLEGAL)
3431
OutputMsg(0, "%s: bindkey: unknown command '%s'", rc_name, args[1]);
3434
if (CheckArgNum(newnr, args + 2) < 0)
3436
ClearAction(newact);
3437
SaveAction(newact, newnr, args + 2, argl + 2);
3438
if (kf == 0 && args[1])
3442
kme->str = SaveStrn(*args, *argl);
3443
kme->fl = fl | *argl;
3447
ClearAction(newact);
3448
for (display = displays; display; display = display->d_next)
3449
remap(i, args[1] ? 1 : 0);
3450
if (kf == 0 && !args[1])
3452
if (!used && kme->str)
3465
if (ParseNum(act, &n))
3469
OutputMsg(0, "%s: maptimeout: illegal time %d", rc_name, n);
3474
if (*args == 0 || msgok)
3475
OutputMsg(0, "maptimeout is %dms", maptimeout);
3489
UsersAcl(NULL, argc, args);
3492
if (UserDel(args[0], NULL))
3495
OutputMsg(0, "%s removed from acl database", args[0]);
3499
* modify a user to gain or lose rights granted to a group.
3500
* This group is actually a normal user whose rights were defined
3501
* with chacl in the usual way.
3505
if (strcmp(args[1], "none")) /* link a user to another user */
3507
if (AclLinkUser(args[0], args[1]))
3510
OutputMsg(0, "User %s joined acl-group %s", args[0], args[1]);
3512
else /* remove all groups from user */
3515
struct aclusergroup *g;
3517
if (!(u = *FindUserPtr(args[0])))
3519
while ((g = u->u_group))
3521
u->u_group = g->next;
3526
else /* show all groups of user */
3528
char buf[256], *p = buf;
3531
struct aclusergroup *g;
3533
if (!(u = *FindUserPtr(args[0])))
3536
OutputMsg(0, "User %s does not exist.", args[0]);
3543
sprintf(p, "%s ", g->u->u_name);
3551
OutputMsg(0, "%s's group%s: %s.", args[0], (ngroups == 1) ? "" : "s",
3552
(ngroups == 0) ? "none" : buf);
3557
while ((s = *args++))
3561
if (AclUmask(display ? D_user : users, s, &err))
3562
OutputMsg(0, "umask: %s\n", err);
3566
if (ParseOnOff(act, &n))
3571
OutputMsg(0, "Multiuser mode %s", multi ? "enabled" : "disabled");
3573
#endif /* MULTIUSER */
3581
i = D_nonblock >= 0;
3582
if (*args && ((args[0][0] >= '0' && args[0][0] <= '9') || args[0][0] == '.'))
3584
if (ParseNum1000(act, &i))
3587
else if (!ParseSwitch(act, &i))
3588
i = i == 0 ? -1 : 1000;
3591
if (msgok && i == -1)
3592
OutputMsg(0, "display set to blocking mode");
3593
else if (msgok && i == 0)
3594
OutputMsg(0, "display set to nonblocking mode, no timeout");
3596
OutputMsg(0, "display set to nonblocking mode, %.10gs timeout", i/1000.);
3598
if (D_nonblock <= 0)
3599
evdeq(&D_blockedev);
3601
case RC_DEFNONBLOCK:
3602
if (*args && ((args[0][0] >= '0' && args[0][0] <= '9') || args[0][0] == '.'))
3604
if (ParseNum1000(act, &defnonblock))
3607
else if (!ParseOnOff(act, &defnonblock))
3608
defnonblock = defnonblock == 0 ? -1 : 1000;
3611
if (display && *rc_name)
3613
D_nonblock = defnonblock;
3614
if (D_nonblock <= 0)
3615
evdeq(&D_blockedev);
3621
if (fore->w_gr == 2)
3624
if (ParseSwitch(act, &fore->w_gr) == 0 && msgok)
3625
OutputMsg(0, "Will %suse GR", fore->w_gr ? "" : "not ");
3627
if (fore->w_gr == 0 && fore->w_FontE)
3632
if (ParseSwitch(act, &fore->w_c1) == 0 && msgok)
3633
OutputMsg(0, "Will %suse C1", fore->w_c1 ? "" : "not ");
3637
if (ParseSwitch(act, &fore->w_bce) == 0 && msgok)
3638
OutputMsg(0, "Will %serase with background color", fore->w_bce ? "" : "not ");
3645
if (*args && !strcmp(args[0], "-d"))
3648
OutputMsg(0, "encodings directory is %s", screenencodings ? screenencodings : "<unset>");
3651
free(screenencodings);
3652
screenencodings = SaveStr(args[1]);
3656
if (*args && !strcmp(args[0], "-l"))
3659
OutputMsg(0, "encoding: -l: argument required");
3660
else if (LoadFontTranslation(-1, args[1]))
3661
OutputMsg(0, "encoding: could not load utf8 encoding file");
3663
OutputMsg(0, "encoding: utf8 encoding file loaded");
3667
if (*args && (!strcmp(args[0], "-l") || !strcmp(args[0], "-d")))
3670
OutputMsg(0, "encoding: screen is not compiled for UTF-8.");
3674
for (i = 0; i < 2; i++)
3678
if (!strcmp(args[i], "."))
3680
n = FindEncoding(args[i]);
3683
OutputMsg(0, "encoding: unknown encoding '%s'", args[i]);
3688
WinSwitchEncoding(fore, n);
3689
ResetCharsets(fore);
3691
else if (i && display)
3696
case RC_DEFENCODING:
3697
n = FindEncoding(*args);
3700
OutputMsg(0, "defencoding: unknown encoding '%s'", *args);
3703
nwin_default.encoding = n;
3709
n = nwin_default.encoding == UTF8;
3710
if (ParseSwitch(act, &n) == 0)
3712
nwin_default.encoding = n ? UTF8 : 0;
3714
OutputMsg(0, "Will %suse UTF-8 encoding for new windows", n ? "" : "not ");
3718
for (i = 0; i < 2; i++)
3720
if (i && args[i] == 0)
3723
n = fore->w_encoding != UTF8;
3724
else if (strcmp(args[i], "off") == 0)
3726
else if (strcmp(args[i], "on") == 0)
3730
OutputMsg(0, "utf8: illegal argument (%s)", args[i]);
3735
WinSwitchEncoding(fore, n ? UTF8 : 0);
3737
OutputMsg(0, "Will %suse UTF-8 encoding", n ? "" : "not ");
3740
D_encoding = n ? UTF8 : 0;
3754
printcmd = SaveStr(*args);
3756
if (*args == 0 || msgok)
3759
OutputMsg(0, "using '%s' as print command", printcmd);
3761
OutputMsg(0, "using termcap entries for printing");
3767
if (argl && argl[0] > 0 && argl[1] > 0)
3771
OutputMsg(0, "Two characters expected to define a digraph");
3774
i = digraph_find(args[0]);
3775
digraphs[i].d[0] = args[0][0];
3776
digraphs[i].d[1] = args[0][1];
3777
if (!parse_input_int(args[1], argl[1], &digraphs[i].value))
3779
if (!(digraphs[i].value = atoi(args[1])))
3782
digraphs[i].value = (int)args[1][0];
3787
unsigned char *s = (unsigned char *)args[1];
3788
digraphs[i].value = 0;
3791
t = FromUtf8(*s++, &digraphs[i].value);
3795
digraphs[i].value = 0;
3797
digraphs[i].value = t;
3806
Input("Enter digraph: ", 10, INP_EVERY, digraph_fn, NULL, 0);
3807
if (*args && **args)
3820
if (nwin_default.hstatus)
3821
AddXChars(buf, sizeof(buf), nwin_default.hstatus);
3822
OutputMsg(0, "default hstatus is '%s'", buf);
3825
(void)ParseSaveStr(act, &nwin_default.hstatus);
3826
if (*nwin_default.hstatus == 0)
3828
free(nwin_default.hstatus);
3829
nwin_default.hstatus = 0;
3833
(void)ParseSaveStr(act, &fore->w_hstatus);
3834
if (*fore->w_hstatus == 0)
3836
free(fore->w_hstatus);
3837
fore->w_hstatus = 0;
3839
WindowChanged(fore, 'h');
3849
if (nwin_default.charset)
3850
AddXChars(buf, sizeof(buf), nwin_default.charset);
3851
OutputMsg(0, "default charset is '%s'", buf);
3855
if (n == 0 || n > 6)
3857
OutputMsg(0, "%s: %s: string has illegal size.", rc_name, comms[nr].name);
3861
((args[0][4] < '0' || args[0][4] > '3') && args[0][4] != '.') ||
3862
((args[0][5] < '0' || args[0][5] > '3') && args[0][5] && args[0][5] != '.')))
3864
OutputMsg(0, "%s: %s: illegal mapping number.", rc_name, comms[nr].name);
3867
if (nr == RC_CHARSET)
3869
SetCharsets(fore, *args);
3872
if (nwin_default.charset)
3873
free(nwin_default.charset);
3874
nwin_default.charset = SaveStr(*args);
3880
if (*s >= '0' && *s <= '9')
3883
for (i = 0; i < 8; i++)
3884
if (*s == "dubrsBiI"[i])
3888
if (*s && s[1] && !s[2])
3890
if (*s == 'd' && s[1] == 'd')
3892
else if (*s == '.' && s[1] == 'd')
3894
else if (*s == 'd' && s[1] == '.')
3896
else if (*s != '.' || s[1] != '.')
3900
if (*s || i < 0 || i >= 8)
3902
OutputMsg(0, "%s: attrcolor: unknown attribute '%s'.", rc_name, args[0]);
3907
n = ParseAttrColor(args[1], args[2], 1);
3910
attr2color[i][nr] = n;
3912
for (i = 0; i < 8; i++)
3913
if (attr2color[i][0] || attr2color[i][1] || attr2color[i][2] || attr2color[i][3])
3920
if (strcmp(args[0], "bell") == 0)
3924
else if (strcmp(args[0], "monitor") == 0)
3928
else if (strcmp(args[0], "silence") == 0)
3932
else if (strcmp(args[0], "so") != 0)
3934
OutputMsg(0, "Invalid option '%s' for rendition", args[0]);
3943
renditions[i] = ParseAttrColor(args[0], args[1], 1);
3944
WindowChanged((struct win *)0, 'w');
3945
WindowChanged((struct win *)0, 'W');
3946
WindowChanged((struct win *)0, 0);
3950
/* We are here, means we want to set the sorendition. */
3952
case RC_SORENDITION:
3956
i = ParseAttrColor(*args, args[1], 1);
3959
ApplyAttrColor(i, &mchar_so);
3960
WindowChanged((struct win *)0, 0);
3961
debug2("--> %x %x\n", mchar_so.attr, mchar_so.color);
3965
OutputMsg(0, "Standout attributes 0x%02x color 0x%02x", (unsigned char)mchar_so.attr, 0x99 ^ (unsigned char)mchar_so.color);
3967
OutputMsg(0, "Standout attributes 0x%02x ", (unsigned char)mchar_so.attr);
3980
OutputMsg(0, "%s:%s screen login", HostName, SockPath);
3981
InputSu(D_fore, &D_user, NULL);
3984
InputSu(D_fore, &D_user, args[0]);
3986
s = DoSu(&D_user, args[0], args[1], "\377");
3988
s = DoSu(&D_user, args[0], args[1], args[2]);
3990
OutputMsg(0, "%s", s);
3992
#endif /* MULTIUSER */
3995
if (s && !strcmp(s, "-v"))
3996
AddCanvas(SLICE_HORI);
3998
AddCanvas(SLICE_VERT);
4010
D_forecv->c_xoff = D_forecv->c_xs;
4011
D_forecv->c_yoff = D_forecv->c_ys;
4012
RethinkViewportOffsets(D_forecv);
4013
ResizeLayer(D_forecv->c_layer, D_forecv->c_xe - D_forecv->c_xs + 1, D_forecv->c_ye - D_forecv->c_ys + 1, 0);
4014
flayer = D_forecv->c_layer;
4019
struct canvas *cv = 0;
4020
if (!*args || !strcmp(*args, "next"))
4021
cv = D_forecv->c_next ? D_forecv->c_next : D_cvlist;
4022
else if (!strcmp(*args, "prev"))
4024
for (cv = D_cvlist; cv->c_next && cv->c_next != D_forecv; cv = cv->c_next)
4027
else if (!strcmp(*args, "top"))
4029
else if (!strcmp(*args, "bottom"))
4031
for (cv = D_cvlist; cv->c_next; cv = cv->c_next)
4034
else if (!strcmp(*args, "up"))
4035
cv = FindCanvas(D_forecv->c_xs, D_forecv->c_ys - 1);
4036
else if (!strcmp(*args, "down"))
4037
cv = FindCanvas(D_forecv->c_xs, D_forecv->c_ye + 2);
4038
else if (!strcmp(*args, "left"))
4039
cv = FindCanvas(D_forecv->c_xs - 1, D_forecv->c_ys);
4040
else if (!strcmp(*args, "right"))
4041
cv = FindCanvas(D_forecv->c_xe + 1, D_forecv->c_ys);
4044
OutputMsg(0, "%s: usage: focus [next|prev|up|down|left|right|top|bottom]", rc_name);
4047
SetForeCanvas(display, cv);
4052
if (D_forecv->c_slorient == SLICE_UNKN)
4054
OutputMsg(0, "resize: need more than one region");
4057
for (; *args; args++)
4059
if (!strcmp(*args, "-h"))
4061
else if (!strcmp(*args, "-v"))
4063
else if (!strcmp(*args, "-b"))
4064
i |= RESIZE_FLAG_H | RESIZE_FLAG_V;
4065
else if (!strcmp(*args, "-p"))
4066
i |= D_forecv->c_slorient == SLICE_VERT ? RESIZE_FLAG_H : RESIZE_FLAG_V;
4067
else if (!strcmp(*args, "-l"))
4072
if (*args && args[1])
4074
OutputMsg(0, "%s: usage: resize [-h] [-v] [-l] [num]\n", rc_name);
4078
ResizeRegions(*args, i);
4080
Input(resizeprompts[i], 20, INP_EVERY, ResizeFin, (char*)0, i);
4083
(void)ParseSwitch(act, &separate_sids);
4086
args = SaveArgs(args);
4087
for (i = 0; args[i]; i++)
4090
Colonfin(args[i], strlen(args[i]), (char *)0);
4096
(void)ParseSwitch(act, &use_altscreen);
4098
OutputMsg(0, "Will %sdo alternate screen switching", use_altscreen ? "" : "not ");
4103
OutputMsg(0, "maximum windows allowed: %d", maxwin);
4106
if (ParseNum(act, &n))
4109
OutputMsg(0, "illegal maxwin number specified");
4111
OutputMsg(0, "maximum 2048 windows allowed");
4112
else if (n > maxwin && windows)
4113
OutputMsg(0, "may increase maxwin only when there's no window");
4117
wtab = realloc(wtab, n * sizeof(struct win *));
4122
if (ParseBase(act, *args, &n, 10, "decimal"))
4125
setbacktick(n, 0, 0, (char **)0);
4131
OutputMsg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name);
4134
if (ParseBase(act, args[1], &lifespan, 10, "decimal"))
4136
if (ParseBase(act, args[2], &tick, 10, "decimal"))
4138
setbacktick(n, lifespan, tick, SaveArgs(args + 3));
4140
WindowChanged(0, '`');
4146
RunBlanker(blankerprg);
4151
CursorVisibility(-1);
4160
char path[MAXPATHLEN];
4161
char *p = path, **pp;
4162
for (pp = blankerprg; *pp; pp++)
4163
p += snprintf(p, sizeof(path) - (p - path) - 1, "%s ", *pp);
4165
OutputMsg(0, "blankerprg: %s", path);
4168
OutputMsg(0, "No blankerprg set.");
4174
for (pp = blankerprg; *pp; pp++)
4180
blankerprg = SaveArgs(args);
4186
struct display *olddisplay = display;
4187
if (!strcmp(*args, "off"))
4189
else if (args[0][0])
4190
idletimo = atoi(*args) * 1000;
4193
if ((i = FindCommnr(args[1])) == RC_ILLEGAL)
4195
OutputMsg(0, "%s: idle: unknown command '%s'", rc_name, args[1]);
4198
if (CheckArgNum(i, args + 2) < 0)
4200
ClearAction(&idleaction);
4201
SaveAction(&idleaction, i, args + 2, argl + 2);
4203
for (display = displays; display; display = display->d_next)
4205
display = olddisplay;
4210
OutputMsg(0, "idle timeout %ds, %s", idletimo / 1000, comms[idleaction.nr].name);
4212
OutputMsg(0, "idle off");
4215
case RC_FOCUSMINSIZE:
4216
for (i = 0; i < 2 && args[i]; i++)
4218
if (!strcmp(args[i], "max") || !strcmp(args[i], "_"))
4230
for (i = 0; i < 2; i++)
4232
n = i == 0 ? focusminwidth : focusminheight;
4234
strcpy(b[i], "max");
4236
sprintf(b[i], "%d", n);
4238
OutputMsg(0, "focus min size is %s %s\n", b[0], b[1]);
4247
fore->w_group = WindowByName(*args);
4248
if (fore->w_group == fore || (fore->w_group && fore->w_group->w_type != W_TYPE_GROUP))
4251
WindowChanged((struct win *)0, 'w');
4252
WindowChanged((struct win *)0, 'W');
4253
WindowChanged((struct win *)0, 0);
4258
OutputMsg(0, "window group is %d (%s)\n", fore->w_group->w_number, fore->w_group->w_title);
4260
OutputMsg(0, "window belongs to no group");
4264
// A number of the subcommands for "layout" are ignored, or not processed correctly when there
4265
// is no attached display.
4267
if (!strcmp(args[0], "title"))
4271
if (!args[1]) // There is no display, and there is no new title. Ignore.
4273
if (!layout_attach || layout_attach == &layout_last_marker)
4274
layout_attach = CreateLayout(args[1], 0);
4276
RenameLayout(layout_attach, args[1]);
4282
OutputMsg(0, "not on a layout");
4287
OutputMsg(0, "current layout is %d (%s)", D_layout->lay_number, D_layout->lay_title);
4290
RenameLayout(D_layout, args[1]);
4292
else if (!strcmp(args[0], "number"))
4296
if (args[1] && layout_attach && layout_attach != &layout_last_marker)
4297
RenumberLayout(layout_attach, atoi(args[1]));
4303
OutputMsg(0, "not on a layout");
4308
OutputMsg(0, "This is layout %d (%s).\n", D_layout->lay_number, D_layout->lay_title);
4311
RenumberLayout(D_layout, atoi(args[1]));
4314
else if (!strcmp(args[0], "autosave"))
4318
if (args[1] && layout_attach && layout_attach != &layout_last_marker)
4320
if (!strcmp(args[1], "on"))
4321
layout_attach->lay_autosave = 1;
4322
else if (!strcmp(args[1], "off"))
4323
layout_attach->lay_autosave = 0;
4330
OutputMsg(0, "not on a layout");
4335
if (!strcmp(args[1], "on"))
4336
D_layout->lay_autosave = 1;
4337
else if (!strcmp(args[1], "off"))
4338
D_layout->lay_autosave = 0;
4341
OutputMsg(0, "invalid argument. Give 'on' or 'off");
4346
OutputMsg(0, "autosave is %s", D_layout->lay_autosave ? "on" : "off");
4348
else if (!strcmp(args[0], "new"))
4354
while (*t >= '0' && *t <= '9')
4356
if (t != args[1] && (!*t || *t == ':'))
4370
else if (!strcmp(args[0], "save"))
4374
OutputMsg(0, "usage: layout save <name>");
4378
SaveLayout(args[1], &D_canvas);
4380
else if (!strcmp(args[0], "select"))
4385
layout_attach = FindLayout(args[1]);
4390
Input("Switch to layout: ", 20, INP_COOKED, SelectLayoutFin, NULL, 0);
4393
SelectLayoutFin(args[1], strlen(args[1]), (char *)0);
4395
else if (!strcmp(args[0], "next"))
4399
if (layout_attach && layout_attach != &layout_last_marker)
4400
layout_attach = layout_attach->lay_next ? layout_attach->lay_next : layouts;;
4403
struct layout *lay = D_layout;
4405
lay = lay->lay_next ? lay->lay_next : layouts;
4410
OutputMsg(0, "no layout defined");
4413
if (lay == D_layout)
4415
LoadLayout(lay, &D_canvas);
4418
else if (!strcmp(args[0], "prev"))
4420
struct layout *lay = display ? D_layout : layout_attach;
4421
struct layout *target = lay;
4424
for (lay = layouts; lay->lay_next && lay->lay_next != target; lay = lay->lay_next)
4432
layout_attach = lay;
4438
OutputMsg(0, "no layout defined");
4441
if (lay == D_layout)
4443
LoadLayout(lay, &D_canvas);
4446
else if (!strcmp(args[0], "attach"))
4451
OutputMsg(0, "no attach layout set");
4452
else if (layout_attach == &layout_last_marker)
4453
OutputMsg(0, "will attach to last layout");
4455
OutputMsg(0, "will attach to layout %d (%s)", layout_attach->lay_number, layout_attach->lay_title);
4458
if (!strcmp(args[1], ":last"))
4459
layout_attach = &layout_last_marker;
4460
else if (!args[1][0])
4465
lay = FindLayout(args[1]);
4468
OutputMsg(0, "unknown layout '%s'", args[1]);
4471
layout_attach = lay;
4474
else if (!strcmp(args[0], "show"))
4478
else if (!strcmp(args[0], "remove"))
4480
struct layout *lay = display ? D_layout : layouts;
4483
lay = layouts ? FindLayout(args[1]) : (struct layout *)0;
4486
OutputMsg(0, "unknown layout '%s'", args[1]);
4493
else if (!strcmp(args[0], "dump"))
4496
OutputMsg(0, "Must have a display for 'layout dump'.");
4497
else if (!LayoutDumpCanvas(&D_canvas, args[1] ? args[1] : "layout-dump"))
4498
OutputMsg(errno, "Error dumping layout.");
4500
OutputMsg(0, "Layout dumped to \"%s\"", args[1] ? args[1] : "layout-dump");
4503
OutputMsg(0, "unknown layout subcommand");
4507
if(ParseSwitch(act, &cjkwidth) == 0)
4510
OutputMsg(0, "Treat ambiguous width characters as %s width", cjkwidth ? "full" : "half");
4516
/* key == -2: input from braille keybord, msgok always 0 */
4517
DoBrailleAction(act, key == -2 ? 0 : msgok);
4521
if (display != odisplay)
4523
for (display = displays; display; display = display->d_next)
4524
if (display == odisplay)
4531
DoCommand(argv, argl)
4536
const char *cmd = *argv;
4539
/* For now, we actually treat both 'supress error' and 'suppress normal message' as the
4540
* same, and ignore all messages on either flag. If we wanted to do otherwise, we would
4541
* need to change the definition of 'OutputMsg' slightly. */
4542
if (*cmd == '@') /* Suppress error */
4547
if (*cmd == '-') /* Suppress normal message */
4553
if ((act.nr = FindCommnr(cmd)) == RC_ILLEGAL)
4555
Msg(0, "%s: unknown command '%s'", rc_name, cmd);
4558
act.args = argv + 1;
4559
act.argl = argl + 1;
4564
SaveAction(act, nr, args, argl)
4570
register int argc = 0;
4584
if ((pp = (char **)malloc((unsigned)(argc + 1) * sizeof(char **))) == 0)
4585
Panic(0, "%s", strnomem);
4586
if ((lp = (int *)malloc((unsigned)(argc) * sizeof(int *))) == 0)
4587
Panic(0, "%s", strnomem);
4593
*lp = argl ? *argl++ : (int)strlen(*args);
4594
*pp++ = SaveStrn(*args++, *lp++);
4603
register char **ap, **pp;
4604
register int argc = 0;
4608
if ((pp = ap = (char **)malloc((unsigned)(argc + 1) * sizeof(char **))) == 0)
4609
Panic(0, "%s", strnomem);
4611
*pp++ = SaveStr(*args++);
4618
* buf is split into argument vector args.
4619
* leading whitespace is removed.
4620
* @!| abbreviations are expanded.
4621
* the end of buffer is recognized by '\0' or an un-escaped '#'.
4622
* " and ' are interpreted.
4627
Parse(buf, bufl, args, argl)
4631
register char *p = buf, **ap = args, *pp;
4632
register int delim, argc;
4635
debug2("Parse %d %s\n", bufl, buf);
4642
while (*p && (*p == ' ' || *p == '\t'))
4645
if (argc == 0 && *p == '!')
4654
if (*p == '\0' || *p == '#' || *p == '\n')
4657
for (delim = 0; delim < argc; delim++)
4658
debug1("-- %s\n", args[delim]);
4662
if (++argc >= MAXARGS)
4664
Msg(0, "%s: too many tokens.", rc_name);
4669
debug1("- new arg %s\n", p);
4674
else if (delim != '\'' && *p == '\\' && (p[1] == 'n' || p[1] == 'r' || p[1] == 't' || p[1] == '\'' || p[1] == '"' || p[1] == '\\' || p[1] == '$' || p[1] == '#' || p[1] == '^' || (p[1] >= '0' && p[1] <= '7')))
4677
if (*p >= '0' && *p <= '7')
4680
if (p[1] >= '0' && p[1] <= '7')
4683
*pp = (*pp << 3) | (*p - '0');
4684
if (p[1] >= '0' && p[1] <= '7')
4687
*pp = (*pp << 3) | (*p - '0');
4696
case 'n': *pp = '\n'; break;
4697
case 'r': *pp = '\r'; break;
4698
case 't': *pp = '\t'; break;
4699
default: *pp = *p; break;
4704
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] == '_'))
4707
char *ps, *pe, op, *v, xbuf[11], path[MAXPATHLEN];
4711
debug1("- var %s\n", ps);
4715
if (*ps == '{' && *p == '}')
4717
if (*ps == ':' && *p == ':')
4719
if (*ps != '{' && *ps != ':' && (*p < 'a' || *p > 'z') && (*p < 'A' || *p > 'Z') && (*p < '0' || *p > '9') && *p != '_')
4724
if (*ps == '{' || *ps == ':')
4728
Msg(0, "%s: bad variable name.", rc_name);
4735
debug1("- var is '%s'\n", ps);
4737
v = gettermcapstring(ps + 1);
4743
if (!strcmp(ps, "TERM"))
4744
v = display ? D_termname : "unknown";
4745
else if (!strcmp(ps, "COLUMNS"))
4746
sprintf(xbuf, "%d", display ? D_width : -1);
4747
else if (!strcmp(ps, "LINES"))
4748
sprintf(xbuf, "%d", display ? D_height : -1);
4749
else if (!strcmp(ps, "PID"))
4750
sprintf(xbuf, "%d", getpid());
4751
else if (!strcmp(ps, "PWD"))
4753
if (getcwd(path, sizeof(path) - 1) == 0)
4758
else if (!strcmp(ps, "STY"))
4760
if ((v = strchr(SockName, '.'))) /* Skip the PID */
4769
vl = v ? strlen(v) : 0;
4772
debug1("- sub is '%s'\n", v);
4775
int right = buf + bufl - (p + strlen(p) + 1);
4778
bcopy(p, p + right, strlen(p) + 1);
4784
Msg(0, "%s: no space left for variable expansion.", rc_name);
4792
else if (delim != '\'' && *p == '^' && p[1])
4795
*pp++ = *p == '?' ? '\177' : *p & 0x1f;
4797
else if (delim == 0 && (*p == '\'' || *p == '"'))
4799
else if (delim == 0 && (*p == ' ' || *p == '\t' || *p == '\n'))
4807
Msg(0, "%s: Missing %c quote.", rc_name, delim);
4813
debug2("- arg done, '%s' rest %s\n", ap[-1], p);
4814
*lp++ = pp - ap[-1];
4833
if (DefaultEsc >= 0)
4834
ClearAction(&ktab[DefaultEsc]);
4835
if (DefaultMetaEsc >= 0)
4836
ClearAction(&ktab[DefaultMetaEsc]);
4839
DefaultMetaEsc = me;
4842
if (DefaultEsc >= 0)
4844
ClearAction(&ktab[DefaultEsc]);
4845
ktab[DefaultEsc].nr = RC_OTHER;
4847
if (DefaultMetaEsc >= 0)
4849
ClearAction(&ktab[DefaultMetaEsc]);
4850
ktab[DefaultMetaEsc].nr = RC_META;
4857
ParseSwitch(act, var)
4861
if (*act->args == 0)
4866
return ParseOnOff(act, var);
4870
ParseOnOff(act, var)
4874
register int num = -1;
4875
char **args = act->args;
4879
if (strcmp(args[0], "on") == 0)
4881
else if (strcmp(args[0], "off") == 0)
4886
Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name, comms[act->nr].name);
4894
ParseSaveStr(act, var)
4898
char **args = act->args;
4899
if (*args == 0 || args[1])
4901
Msg(0, "%s: %s: one argument required.", rc_name, comms[act->nr].name);
4906
*var = SaveStr(*args);
4916
char *p, **args = act->args;
4919
if (p == 0 || *p == 0 || args[1])
4921
Msg(0, "%s: %s: invalid argument. Give one argument.",
4922
rc_name, comms[act->nr].name);
4928
if (*p >= '0' && *p <= '9')
4929
i = 10 * i + (*p - '0');
4932
Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4933
rc_name, comms[act->nr].name);
4938
debug1("ParseNum got %d\n", i);
4944
ParseNum1000(act, var)
4949
char *p, **args = act->args;
4953
if (p == 0 || *p == 0 || args[1])
4955
Msg(0, "%s: %s: invalid argument. Give one argument.",
4956
rc_name, comms[act->nr].name);
4962
if (*p >= '0' && *p <= '9')
4965
i = 10 * i + (*p - '0');
4966
else if (dig == 4 && *p >= '5')
4971
else if (*p == '.' && !dig)
4975
Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4976
rc_name, comms[act->nr].name);
4987
i = (int)((unsigned int)~0 >> 1);
4988
debug1("ParseNum1000 got %d\n", i);
4999
for (p = windows; p; p = p->w_next)
5000
if (!strcmp(p->w_title, s))
5002
for (p = windows; p; p = p->w_next)
5003
if (!strncmp(p->w_title, s, strlen(s)))
5015
for (i = 0, s = str; *s; s++)
5017
if (*s < '0' || *s > '9')
5019
i = i * 10 + (*s - '0');
5025
* Get window number from Name or Number string.
5026
* Numbers are tried first, then names, a prefix match suffices.
5027
* Be careful when assigning numeric strings as WindowTitles.
5036
if ((i = WindowByNumber(str)) < 0 || i >= maxwin)
5038
if ((p = WindowByName(str)))
5046
ParseWinNum(act, var)
5050
char **args = act->args;
5053
if (*args == 0 || args[1])
5055
Msg(0, "%s: %s: one argument required.", rc_name, comms[act->nr].name);
5059
i = WindowByNoN(*args);
5062
Msg(0, "%s: %s: invalid argument. Give window number or name.",
5063
rc_name, comms[act->nr].name);
5066
debug1("ParseWinNum got %d\n", i);
5072
ParseBase(act, p, var, base, bname)
5084
Msg(0, "%s: %s: empty argument.", rc_name, comms[act->nr].name);
5089
if (c >= 'a' && c <= 'z')
5091
if (c >= 'A' && c <= 'Z')
5092
c -= 'A' - ('0' + 10);
5094
if (c < 0 || c >= base)
5096
Msg(0, "%s: %s: argument is not %s.", rc_name, comms[act->nr].name, bname);
5101
debug1("ParseBase got %d\n", i);
5111
for (base += '0'; *s; ++s)
5112
if (*s < '0' || *s > base)
5118
IsNumColon(s, base, p, psize)
5123
if ((q = rindex(s, ':')) != 0)
5125
strncpy(p, q + 1, psize - 1);
5126
p[psize - 1] = '\0';
5131
return IsNum(s, base);
5140
debug1("SwitchWindow %d\n", n);
5141
if (n < 0 || n >= maxwin)
5146
if ((p = wtab[n]) == 0)
5158
Msg(0, "This IS window %d (%s).", n, p->w_title);
5162
if (AclCheckPermWin(D_user, ACL_READ, p))
5164
Msg(0, "Access to window %d denied.", p->w_number);
5169
Activate(fore->w_norefresh);
5173
* SetForeWindow changes the window in the input focus of the display.
5174
* Puts window wi in canvas display->d_forecv.
5186
p = Layer2Window(D_forecv->c_layer);
5187
SetCanvasWindow(D_forecv, wi);
5189
WindowChanged(p, 'u');
5191
WindowChanged(wi, 'u');
5192
flayer = D_forecv->c_layer;
5193
/* Activate called afterwards, so no RefreshHStatus needed */
5197
/*****************************************************************/
5200
* Activate - make fore window active
5201
* norefresh = -1 forces a refresh, disregard all_norefresh then.
5207
debug1("Activate(%d)\n", norefresh);
5212
Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
5216
if (MayResizeLayer(D_forecv->c_layer))
5217
ResizeLayer(D_forecv->c_layer, D_forecv->c_xe - D_forecv->c_xs + 1, D_forecv->c_ye - D_forecv->c_ys + 1, display);
5223
if (fore->w_monitor != MON_OFF)
5224
fore->w_monitor = MON_ON;
5225
fore->w_bell = BELL_ON;
5226
WindowChanged(fore, 'f');
5229
if (ResizeDisplay(fore->w_width, fore->w_height))
5231
debug2("Cannot resize from (%d,%d)", D_width, D_height);
5232
debug2(" to (%d,%d) -> resize window\n", fore->w_width, fore->w_height);
5233
DoResize(D_width, D_height);
5237
Redisplay(norefresh + all_norefresh);
5244
register struct win **pp;
5245
int n = fore ? fore->w_number : maxwin;
5246
struct win *group = fore ? fore->w_group : 0;
5248
for (pp = fore ? wtab + n + 1 : wtab; pp != wtab + n; pp++)
5250
if (pp == wtab + maxwin)
5254
if (!fore || group == (*pp)->w_group)
5266
register struct win **pp;
5267
int n = fore ? fore->w_number : -1;
5268
struct win *group = fore ? fore->w_group : 0;
5270
for (pp = wtab + n - 1; pp != wtab + n; pp--)
5273
pp = wtab + maxwin - 1;
5276
if (!fore || group == (*pp)->w_group)
5288
char *m = "No other window.";
5289
if (windows && (fore == 0 || windows->w_next))
5293
Msg(0, "No window available");
5296
Msg(0, m, fore->w_number); /* other arg for nethack */
5304
struct win **pp, *p;
5310
* Remove window from linked list.
5312
for (pp = &windows; (p = *pp); pp = &p->w_next)
5318
wtab[wi->w_number] = 0;
5327
* switch to different window on all canvases
5329
for (display = displays; display; display = display->d_next)
5332
for (cv = D_cvlist; cv; cv = cv->c_next)
5334
if (Layer2Window(cv->c_layer) != wi)
5336
/* switch to other window */
5337
SetCanvasWindow(cv, FindNiceWindow(D_other, 0));
5343
if (wi->w_zdisplay == display)
5346
D_readev.condpos = D_readev.condneg = 0;
5353
/* do the same for the layouts */
5354
for (lay = layouts; lay; lay = lay->lay_next)
5355
UpdateLayoutCanvas(&lay->lay_canvas, wi);
5358
WindowChanged((struct win *)0, 'w');
5359
WindowChanged((struct win *)0, 'W');
5360
WindowChanged((struct win *)0, 0);
5369
if ((fore->w_log != 0) == on)
5371
if (display && !*rc_name)
5372
Msg(0, "You are %s logging.", on ? "already" : "not");
5375
if (fore->w_log != 0)
5377
Msg(0, "Logfile \"%s\" closed.", fore->w_log->name);
5378
logfclose(fore->w_log);
5380
WindowChanged(fore, 'f');
5383
if (DoStartLog(fore, buf, sizeof(buf)))
5385
Msg(errno, "Error opening logfile \"%s\"", buf);
5388
if (ftell(fore->w_log->fp) == 0)
5389
Msg(0, "Creating logfile \"%s\".", fore->w_log->name);
5391
Msg(0, "Appending to logfile \"%s\".", fore->w_log->name);
5392
WindowChanged(fore, 'f');
5396
AddWindows(buf, len, flags, where)
5402
register char *s, *ss;
5403
register struct win **pp, *p;
5408
if ((flags & 8) && where < 0)
5413
for (pp = ((flags & 4) && where >= 0) ? wtab + where + 1: wtab; pp < wtab + maxwin; pp++)
5416
if (pp - wtab == where && ss == buf)
5420
if ((flags & 1) && display && p == D_fore)
5422
if (display && D_fore && D_fore->w_group != p->w_group)
5429
if (s - buf + l > len - 24)
5431
if (s > buf || (flags & 4))
5436
if (p->w_number == where)
5442
if (!(flags & 4) || where < 0 || ((flags & 4) && where < p->w_number))
5444
if (p->w_monitor == MON_DONE && renditions[REND_MONITOR] != -1)
5445
rend = renditions[REND_MONITOR];
5446
else if ((p->w_bell == BELL_DONE || p->w_bell == BELL_FOUND) && renditions[REND_BELL] != -1)
5447
rend = renditions[REND_BELL];
5448
else if ((p->w_silence == SILENCE_FOUND || p->w_silence == SILENCE_DONE) && renditions[REND_SILENCE] != -1)
5449
rend = renditions[REND_SILENCE];
5452
AddWinMsgRend(s, rend);
5453
sprintf(s, "%d", p->w_number);
5455
if (display && p == D_fore)
5459
if (display && p == D_other)
5461
s = AddWindowFlags(s, len, p);
5467
AddWinMsgRend(s, -1);
5474
AddWindowFlags(buf, len, p)
5480
if (p == 0 || len < 12)
5486
if (display && p == D_fore)
5488
if (display && p == D_other)
5491
if (p->w_layer.l_cvlist && p->w_layer.l_cvlist->c_lnext)
5493
if (p->w_monitor == MON_DONE
5495
&& (ACLBYTE(p->w_mon_notify, D_user->u_id) & ACLBIT(D_user->u_id))
5499
if (p->w_bell == BELL_DONE)
5502
if (p->w_slot != (slot_t) 0 && p->w_slot != (slot_t) -1)
5510
if (p->w_ptyfd < 0 && p->w_type != W_TYPE_GROUP)
5517
AddOtherUsers(buf, len, p)
5522
struct display *d, *olddisplay = display;
5528
for (display = displays; display; display = display->d_next)
5530
if (olddisplay && D_user == olddisplay->d_user)
5532
for (cv = D_cvlist; cv; cv = cv->c_next)
5533
if (Layer2Window(cv->c_layer) == p)
5537
for (d = displays; d && d != display; d = d->d_next)
5538
if (D_user == d->d_user)
5540
if (d && d != display)
5542
if (len > 1 && s != buf)
5547
l = strlen(D_user->u_name);
5550
strcpy(s, D_user->u_name);
5555
display = olddisplay;
5566
if (display && where == -1 && D_fore)
5567
where = D_fore->w_number;
5568
ss = AddWindows(buf, sizeof(buf), 0, where);
5569
s = buf + strlen(buf);
5570
if (display && ss - buf > D_width / 2)
5573
if (s - ss < D_width)
5589
register struct win *wp = fore;
5594
Msg(0, "(%d,%d)/(%d,%d) no window", D_x + 1, D_y + 1, D_width, D_height);
5598
if (buf < (p += GetAnsiStatus(wp, p)))
5600
sprintf(p, "(%d,%d)/(%d,%d)",
5601
wp->w_x + 1, wp->w_y + 1, wp->w_width, wp->w_height);
5603
sprintf(p += strlen(p), "+%d", wp->w_histheight);
5605
sprintf(p += strlen(p), " %c%sflow",
5606
(wp->w_flow & FLOW_NOW) ? '+' : '-',
5607
(wp->w_flow & FLOW_AUTOFLAG) ? "" :
5608
((wp->w_flow & FLOW_AUTO) ? "(+)" : "(-)"));
5609
if (!wp->w_wrap) sprintf(p += strlen(p), " -wrap");
5610
if (wp->w_insert) sprintf(p += strlen(p), " ins");
5611
if (wp->w_origin) sprintf(p += strlen(p), " org");
5612
if (wp->w_keypad) sprintf(p += strlen(p), " app");
5613
if (wp->w_log) sprintf(p += strlen(p), " log");
5614
if (wp->w_monitor != MON_OFF
5616
&& (ACLBYTE(wp->w_mon_notify, D_user->u_id) & ACLBIT(D_user->u_id))
5619
sprintf(p += strlen(p), " mon");
5620
if (wp->w_mouse) sprintf(p += strlen(p), " mouse");
5622
if (wp->w_bce) sprintf(p += strlen(p), " bce");
5624
if (!wp->w_c1) sprintf(p += strlen(p), " -c1");
5625
if (wp->w_norefresh) sprintf(p += strlen(p), " nored");
5630
if (wp->w_encoding && (display == 0 || D_encoding != wp->w_encoding || EncodingDefFont(wp->w_encoding) <= 0))
5633
strcpy(p, EncodingName(wp->w_encoding));
5637
if (wp->w_encoding != UTF8)
5640
if (D_CC0 || (D_CS0 && *D_CS0))
5644
sprintf(p, " G%c", wp->w_Charset + '0');
5645
if (wp->w_FontE >= ' ')
5650
p[4] = wp->w_FontE ^ 0x40;
5657
sprintf(p++, " G%c%c[", wp->w_Charset + '0', wp->w_CharsetR + '0');
5659
sprintf(p, " G%c[", wp->w_Charset + '0');
5661
for (i = 0; i < 4; i++)
5663
if (wp->w_charsets[i] == ASCII)
5665
else if (wp->w_charsets[i] >= ' ')
5666
*p++ = wp->w_charsets[i];
5670
*p++ = wp->w_charsets[i] ^ 0x40;
5678
if (wp->w_type == W_TYPE_PLAIN)
5680
/* add info about modem control lines */
5682
TtyGetModemStatus(wp->w_ptyfd, p);
5684
#ifdef BUILTIN_TELNET
5685
else if (wp->w_type == W_TYPE_TELNET)
5688
TelStatus(wp, p, sizeof(buf) - 1 - (p - buf));
5691
Msg(0, "%s %d(%s)", buf, wp->w_number, wp->w_title);
5701
sprintf(p, "(%d,%d)", D_width, D_height),
5707
strcpy(p, EncodingName(D_encoding));
5713
strcpy(p, " xterm");
5719
strcpy(p, " color");
5726
strcpy(p, " iso2022");
5729
else if (D_CS0 && *D_CS0)
5731
strcpy(p, " altchar");
5739
AKAfin(buf, len, data)
5742
char *data; /* dummy */
5746
ChangeAKA(fore, buf, strlen(buf));
5754
Input("Set window's title to: ", sizeof(fore->w_akabuf) - 1, INP_COOKED, AKAfin, NULL, 0);
5760
if ((*(unsigned char *)s & 0x7f) < 0x20 || *s == 0x7f)
5764
LayProcess(&ss, &n);
5769
Colonfin(buf, len, data)
5772
char *data; /* dummy */
5777
if (buf[len] == '\t')
5780
int l = 0, r = RC_LAST;
5781
int showmessage = 0;
5784
while (*s && s - buf < len)
5788
/* Showing a message when there's no hardstatus or caption cancels the input */
5790
(captionalways || D_has_hstatus == HSTATUS_LASTLINE || (D_canvas.c_slperp && D_canvas.c_slperp->c_slnext)))
5796
x = strncmp(buf, comms[m].name, len);
5804
for (l = m - 1; l >= 0 && strncmp(buf, comms[l].name, len) == 0; l--)
5806
for (m = ++l; m <= r && strncmp(buf, comms[m].name, len) == 0 && s - mbuf < sizeof(mbuf); m++)
5807
s += snprintf(s, sizeof(mbuf) - (s - mbuf), " %s", comms[m].name);
5811
Msg(0, "Possible commands:%s", mbuf);
5816
len = snprintf(mbuf, sizeof(mbuf), "%s \t", comms[l].name + len);
5817
if (len > 0 && len < sizeof(mbuf))
5818
LayProcess(&s, &len);
5823
if (l > r && showmessage)
5824
Msg(0, "No commands matching '%*s'", len, buf);
5828
if (!len || buf[len])
5831
len = strlen(buf) + 1;
5832
if (len > (int)sizeof(mbuf))
5836
bcopy(buf, mbuf, len);
5837
RcLine(mbuf, sizeof mbuf);
5842
SelectFin(buf, len, data)
5845
char *data; /* dummy */
5849
if (!len || !display)
5851
if (len == 1 && *buf == '-')
5853
SetForeWindow((struct win *)0);
5857
if ((n = WindowByNoN(buf)) < 0)
5863
SelectLayoutFin(buf, len, data)
5866
char *data; /* dummy */
5870
if (!len || !display)
5872
if (len == 1 && *buf == '-')
5874
LoadLayout((struct layout *)0, (struct canvas *)0);
5878
lay = FindLayout(buf);
5880
Msg(0, "No such layout\n");
5881
else if (lay == D_layout)
5882
Msg(0, "This IS layout %d (%s).\n", lay->lay_number, lay->lay_title);
5885
LoadLayout(lay, &D_canvas);
5894
Input("Switch to window: ", 20, INP_COOKED, SelectFin, NULL, 0);
5897
static char setenv_var[31];
5901
SetenvFin1(buf, len, data)
5904
char *data; /* dummy */
5906
if (!len || !display)
5912
SetenvFin2(buf, len, data)
5915
char *data; /* dummy */
5917
if (!len || !display)
5919
debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var, buf);
5920
xsetenv(setenv_var, buf);
5928
static char setenv_buf[50 + sizeof(setenv_var)]; /* need to be static here, cannot be freed */
5932
strncpy(setenv_var, arg, sizeof(setenv_var) - 1);
5933
sprintf(setenv_buf, "Enter value for %s: ", setenv_var);
5934
Input(setenv_buf, 30, INP_COOKED, SetenvFin2, NULL, 0);
5937
Input("Setenv: Enter variable name: ", 30, INP_COOKED, SetenvFin1, NULL, 0);
5941
* the following options are understood by this parser:
5942
* -f, -f0, -f1, -fy, -fa
5943
* -t title, -T terminal-type, -h height-of-scrollback,
5944
* -ln, -l0, -ly, -l1, -l
5951
struct NewWindow nwin;
5956
while (av && *av && av[0][0] == '-')
5958
if (av[0][1] == '-')
5970
nwin.flowflag = FLOW_NOW * 0;
5975
nwin.flowflag = FLOW_NOW * 1;
5978
nwin.flowflag = FLOW_AUTOFLAG;
5984
case 't': /* no more -k */
5986
nwin.aka = &av[0][2];
5994
nwin.term = &av[0][2];
6002
nwin.histheight = atoi(av[0] + 2);
6004
nwin.histheight = atoi(*av);
6033
nwin.monitor = MON_ON;
6039
Msg(0, "%s: screen: invalid option -%c.", fn, av[0][1]);
6045
if (av && *av && IsNumColon(*av, 10, buf, sizeof(buf)))
6050
if (num < 0 || (maxwin && num > maxwin - 1) || (!maxwin && num > MAXWIN - 1))
6052
Msg(0, "%s: illegal screen number %d.", fn, num);
6062
nwin.aka = Filename(*av);
6069
* CompileKeys must be called before Markroutine is first used.
6070
* to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
6072
* s is an ascii string in a termcap-like syntax. It looks like
6073
* "j=u:k=d:l=r:h=l: =.:" and so on...
6074
* this example rebinds the cursormovement to the keys u (up), d (down),
6075
* l (left), r (right). placing a mark will now be done with ".".
6078
CompileKeys(s, sl, array)
6081
unsigned char *array;
6084
unsigned char key, value;
6088
for (i = 0; i < 256; i++)
6092
debug1("CompileKeys: '%s'\n", s);
6095
key = *(unsigned char *)s++;
6096
if (*s != '=' || sl < 3)
6103
value = *(unsigned char *)s++;
6106
while (*s == '=' && sl >= 2);
6115
#endif /* COPY_PASTE */
6118
* Asynchronous input functions
6121
#if defined(DETACH) && defined(POW_DETACH)
6123
pow_detach_fn(buf, len, data)
6126
char *data; /* dummy */
6128
debug("pow_detach_fn called\n");
6134
if (ktab[(int)(unsigned char)*buf].nr != RC_POW_DETACH)
6137
write(D_userfd, "\007", 1);
6138
Msg(0, "Detach aborted.");
6143
#endif /* POW_DETACH */
6147
copy_reg_fn(buf, len, data)
6150
char *data; /* dummy */
6152
struct plop *pp = plop_tab + (int)(unsigned char)*buf;
6163
if (D_user->u_plop.len)
6165
if ((pp->buf = (char *)malloc(D_user->u_plop.len)) == NULL)
6167
Msg(0, "%s", strnomem);
6170
bcopy(D_user->u_plop.buf, pp->buf, D_user->u_plop.len);
6172
pp->len = D_user->u_plop.len;
6174
pp->enc = D_user->u_plop.enc;
6176
Msg(0, "Copied %d characters into register %c", D_user->u_plop.len, *buf);
6180
ins_reg_fn(buf, len, data)
6183
char *data; /* dummy */
6185
struct plop *pp = plop_tab + (int)(unsigned char)*buf;
6193
return; /* Input() should not call us w/o fore, but you never know... */
6195
Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
6198
MakePaster(&fore->w_paster, pp->buf, pp->len, 0);
6201
Msg(0, "Empty register.");
6203
#endif /* COPY_PASTE */
6206
process_fn(buf, len, data)
6209
char *data; /* dummy */
6211
struct plop *pp = plop_tab + (int)(unsigned char)*buf;
6220
ProcessInput(pp->buf, pp->len);
6223
Msg(0, "Empty register.");
6227
confirm_fn(buf, len, data)
6234
if (len || (*buf != 'y' && *buf != 'Y'))
6239
act.nr = *(int *)data;
6249
struct acluser **up;
6251
char pw1[130]; /* FreeBSD crypts to 128 bytes */
6256
su_fin(buf, len, data)
6261
struct inputsu *i = (struct inputsu *)data;
6266
{ p = i->name; l = sizeof(i->name) - 1; }
6268
{ strcpy(p = i->pw1, "\377"); l = sizeof(i->pw1) - 1; }
6270
{ strcpy(p = i->pw2, "\377"); l = sizeof(i->pw2) - 1; }
6272
strncpy(p, buf, 1 + (l < len) ? l : len);
6274
Input("Screen User: ", sizeof(i->name) - 1, INP_COOKED, su_fin, (char *)i, 0);
6276
Input("User's UNIX Password: ", sizeof(i->pw1)-1, INP_COOKED|INP_NOECHO, su_fin, (char *)i, 0);
6278
Input("User's Screen Password: ", sizeof(i->pw2)-1, INP_COOKED|INP_NOECHO, su_fin, (char *)i, 0);
6281
if ((p = DoSu(i->up, i->name, i->pw2, i->pw1)))
6288
InputSu(w, up, name)
6290
struct acluser **up;
6295
if (!(i = (struct inputsu *)calloc(1, sizeof(struct inputsu))))
6300
su_fin(name, (int)strlen(name), (char *)i); /* can also initialise stuff */
6302
su_fin((char *)0, 0, (char *)i);
6305
#endif /* MULTIUSER */
6310
pass1(buf, len, data)
6315
struct acluser *u = (struct acluser *)data;
6320
if (u->u_password != NullStr)
6321
free((char *)u->u_password);
6322
u->u_password = SaveStr(buf);
6323
bzero(buf, strlen(buf));
6324
Input("Retype new password:", 100, INP_NOECHO, pass2, data, 0);
6328
pass2(buf, len, data)
6335
struct acluser *u = (struct acluser *)data;
6338
if (!buf || strcmp(u->u_password, buf))
6340
Msg(0, "[ Passwords don't match - checking turned off ]");
6341
if (u->u_password != NullStr)
6343
bzero(u->u_password, strlen(u->u_password));
6344
free((char *)u->u_password);
6346
u->u_password = NullStr;
6348
else if (u->u_password[0] == '\0')
6350
Msg(0, "[ No password - no secure ]");
6352
bzero(buf, strlen(buf));
6355
if (u->u_password != NullStr)
6357
for (st = 0; st < 2; st++)
6358
salt[st] = 'A' + (int)((time(0) >> 6 * st) % 26);
6360
buf = crypt(u->u_password, salt);
6361
bzero(u->u_password, strlen(u->u_password));
6362
free((char *)u->u_password);
6365
Msg(0, "[ crypt() error - no secure ]");
6366
u->u_password = NullStr;
6369
u->u_password = SaveStr(buf);
6370
bzero(buf, strlen(buf));
6373
UserFreeCopyBuffer(u);
6374
u->u_plop.len = strlen(u->u_password);
6378
if (!(u->u_plop.buf = SaveStr(u->u_password)))
6380
Msg(0, "%s", strnomem);
6381
D_user->u_plop.len = 0;
6384
Msg(0, "[ Password moved into copybuffer ]");
6385
#else /* COPY_PASTE */
6386
Msg(0, "[ Crypted password is \"%s\" ]", u->u_password);
6387
#endif /* COPY_PASTE */
6390
#endif /* PASSWORD */
6397
for (i = 0; i < MAX_DIGRAPH && digraphs[i].d[0]; i++)
6398
if ((digraphs[i].d[0] == (unsigned char)buf[0] && digraphs[i].d[1] == (unsigned char)buf[1]) ||
6399
(digraphs[i].d[0] == (unsigned char)buf[1] && digraphs[i].d[1] == (unsigned char)buf[0]))
6405
digraph_fn(buf, len, data)
6408
char *data; /* dummy */
6415
buf[len + 1] = ch; /* so we can restore it later */
6416
if (ch < ' ' || ch == '\177')
6418
if (len >= 1 && ((*buf == 'U' && buf[1] == '+') || (*buf == '0' && (buf[1] == 'x' || buf[1] == 'X'))))
6422
if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f') && (ch < 'A' || ch > 'F'))
6424
buf[len] = '\034'; /* ^] is ignored by Input() */
6427
if (len == (*buf == 'U' ? 5 : 3))
6431
if (len && *buf == '0')
6433
if (ch < '0' || ch > '7')
6435
buf[len] = '\034'; /* ^] is ignored by Input() */
6450
buf[len] = buf[len + 1]; /* stored above */
6455
if (!parse_input_int(buf, len, &x))
6457
i = digraph_find(buf);
6458
if ((x = digraphs[i].value) <= 0)
6460
Msg(0, "Unknown digraph");
6467
if (flayer->l_encoding == UTF8)
6468
i = ToUtf8(buf, x); /* buf is big enough for all UTF-8 codes */
6471
LayProcess(&buf, &i);
6483
debug1("StuffKey #%d", i);
6486
debug1(" - %s", term[i + T_CAPS].tcname);
6489
if (i < KMAP_KEYS && D_ESCseen)
6491
struct action *act = &D_ESCseen[i + 256];
6492
if (act->nr != RC_ILLEGAL)
6495
WindowChanged(fore, 'E');
6496
DoAction(act, i + 256);
6502
if (i >= T_CURSOR - T_CAPS && i < T_KEYPAD - T_CAPS && D_cursorkeys)
6503
i += T_OCAPS - T_CURSOR;
6504
else if (i >= T_KEYPAD - T_CAPS && i < T_OCAPS - T_CAPS && D_keypad)
6505
i += T_OCAPS - T_CURSOR;
6506
debug1(" - action %d\n", i);
6507
flayer = D_forecv->c_layer;
6511
if (flayer && flayer->l_mode == 1)
6512
act = i < KMAP_KEYS+KMAP_AKEYS ? &mmtab[i] : &kmap_exts[i - (KMAP_KEYS+KMAP_AKEYS)].mm;
6514
if ((!act || act->nr == RC_ILLEGAL) && !D_mapdefault)
6515
act = i < KMAP_KEYS+KMAP_AKEYS ? &umtab[i] : &kmap_exts[i - (KMAP_KEYS+KMAP_AKEYS)].um;
6516
if (!act || act->nr == RC_ILLEGAL)
6517
act = i < KMAP_KEYS+KMAP_AKEYS ? &dmtab[i] : &kmap_exts[i - (KMAP_KEYS+KMAP_AKEYS)].dm;
6519
if (discard && (!act || act->nr != RC_COMMAND))
6521
/* if the input was just a single byte we let it through */
6522
if (D_tcs[keyno + T_CAPS].str && strlen(D_tcs[keyno + T_CAPS].str) == 1)
6527
WindowChanged(fore, 'E');
6533
if (act == 0 || act->nr == RC_ILLEGAL)
6547
for (cv = D_cvlist; cv; cv = cv->c_next)
6548
if (Layer2Window(cv->c_layer) == wi)
6554
FindNiceWindow(wi, presel)
6560
debug2("FindNiceWindow %d %s\n", wi ? wi->w_number : -1 , presel ? presel : "NULL");
6563
i = WindowByNoN(presel);
6570
if (wi && AclCheckPermWin(D_user, ACL_READ, wi))
6573
if (!wi || (IsOnDisplay(wi) && !presel))
6575
/* try to get another window */
6578
for (wi = windows; wi; wi = wi->w_next)
6579
if (!wi->w_layer.l_cvlist && !AclCheckPermWin(D_user, ACL_WRITE, wi))
6582
for (wi = windows; wi; wi = wi->w_next)
6583
if (wi->w_layer.l_cvlist && !IsOnDisplay(wi) && !AclCheckPermWin(D_user, ACL_WRITE, wi))
6586
for (wi = windows; wi; wi = wi->w_next)
6587
if (!wi->w_layer.l_cvlist && !AclCheckPermWin(D_user, ACL_READ, wi))
6590
for (wi = windows; wi; wi = wi->w_next)
6591
if (wi->w_layer.l_cvlist && !IsOnDisplay(wi) && !AclCheckPermWin(D_user, ACL_READ, wi))
6595
for (wi = windows; wi; wi = wi->w_next)
6596
if (!wi->w_layer.l_cvlist)
6599
for (wi = windows; wi; wi = wi->w_next)
6600
if (wi->w_layer.l_cvlist && !IsOnDisplay(wi))
6604
if (wi && AclCheckPermWin(D_user, ACL_READ, wi))
6612
/* sorted list of all commands */
6613
static struct comm **commtab;
6614
static int ncommtab;
6619
void (*hand) __P((struct comm *, char **, int));
6622
for (n = 0; cos[n].name; n++)
6627
commtab = (struct commt *)realloc(commtab, sizeof(*commtab) * (ncommtab + n));
6629
commtab = (struct commt *)malloc(sizeof(*commtab) * (ncommtab + n));
6632
for (i = 0; i < n; i++)
6634
for (j = 0; j < ncommtab; j++)
6636
r = strcmp(cos[i].name, commtab[j]->name);
6638
Panic(0, "Duplicate command: %s\n", cos[i].name);
6642
for (r = ncommtab; r > j; r--)
6643
commtab[r] = commtab[r - 1];
6644
commtab[j] = cos + i;
6645
cos[i].handler = hand;
6646
bzero(cos[i].userbits, sizeof(cos[i].userbits));
6655
int x, m, l = 0, r = ncommtab - 1;
6659
x = strcmp(str, commtab[m]->name);
6673
CalcSlicePercent(cv, percent)
6678
if (!cv || !cv->c_slback)
6680
up = CalcSlicePercent(cv->c_slback->c_slback, percent);
6682
for (cv = cv->c_slback->c_slperp, wsum = 0; cv; cv = cv->c_slnext)
6683
wsum += cv->c_slweight;
6686
return (up * w) / wsum;
6690
ChangeCanvasSize(fcv, abs, diff, gflag, percent)
6691
struct canvas *fcv; /* make this canvas bigger */
6692
int abs; /* mode: 0:rel 1:abs 2:max */
6693
int diff; /* change this much */
6694
int gflag; /* go up if neccessary */
6698
int done, have, m, dir;
6700
debug3("ChangeCanvasSize abs %d diff %d percent=%d\n", abs, diff, percent);
6701
if (abs == 0 && diff == 0)
6706
fcv->c_slweight = 0;
6709
for (cv = fcv->c_slback->c_slperp; cv; cv = cv->c_slnext)
6711
fcv->c_slweight = 1;
6712
cv = fcv->c_slback->c_slback;
6713
if (gflag && cv && cv->c_slback)
6714
ChangeCanvasSize(cv, abs, diff, gflag, percent);
6722
if (percent && diff > percent)
6728
for (cv = fcv->c_slback->c_slperp, wsum = 0; cv; cv = cv->c_slnext)
6729
wsum += cv->c_slweight;
6732
up = gflag ? CalcSlicePercent(fcv->c_slback->c_slback, percent) : percent;
6733
debug3("up=%d, wsum=%d percent=%d\n", up, wsum, percent);
6736
int scale = wsum < 10 ? 1000 : 100;
6737
for (cv = fcv->c_slback->c_slperp; cv; cv = cv->c_slnext)
6738
cv->c_slweight *= scale;
6740
debug1("scaled wsum to %d\n", wsum);
6742
for (cv = fcv->c_slback->c_slperp; cv; cv = cv->c_slnext)
6746
cv->c_slweight = (cv->c_slweight * up) / percent;
6747
if (cv->c_slweight == 0)
6750
debug1(" - weight %d\n", cv->c_slweight);
6752
diff = (diff * wsum) / percent;
6758
if (abs && diff == (fcv->c_slorient == SLICE_VERT ? fcv->c_ye - fcv->c_ys + 2 : fcv->c_xe - fcv->c_xs + 2))
6760
/* fix weights to real size (can't be helped, sorry) */
6761
for (cv = fcv->c_slback->c_slperp; cv; cv = cv->c_slnext)
6763
cv->c_slweight = cv->c_slorient == SLICE_VERT ? cv->c_ye - cv->c_ys + 2 : cv->c_xe - cv->c_xs + 2;
6764
debug1(" - weight %d\n", cv->c_slweight);
6768
diff = diff - fcv->c_slweight;
6769
debug1("diff = %d\n", diff);
6774
cv = fcv->c_slnext ? fcv->c_slnext : fcv->c_slprev;
6775
fcv->c_slweight += diff;
6776
cv->c_slweight -= diff;
6781
for (cv = fcv->c_slnext; diff > 0; cv = dir > 0 ? cv->c_slnext : cv->c_slprev)
6785
debug1("reached end, dir is %d\n", dir);
6795
m = cv->c_slperp ? CountCanvasPerp(cv) * 2 : 2;
6796
debug2("min is %d, have %d\n", m, cv->c_slweight);
6797
if (cv->c_slweight > m)
6799
have = cv->c_slweight - m;
6802
debug1("subtract %d\n", have);
6803
cv->c_slweight -= have;
6810
/* need more room! */
6811
cv = fcv->c_slback->c_slback;
6812
if (cv && cv->c_slback)
6813
done += ChangeCanvasSize(fcv->c_slback->c_slback, 0, diff, gflag, percent);
6815
fcv->c_slweight += done;
6816
debug1("ChangeCanvasSize returns %d\n", done);
6821
ResizeRegions(arg, flags)
6827
int gflag = 0, abs = 0, percent = 0;
6833
if (D_forecv->c_slorient == SLICE_UNKN)
6835
Msg(0, "resize: need more than one region");
6838
gflag = flags & RESIZE_FLAG_L ? 0 : 1;
6839
orient |= flags & RESIZE_FLAG_H ? SLICE_HORI : 0;
6840
orient |= flags & RESIZE_FLAG_V ? SLICE_VERT : 0;
6842
orient = D_forecv->c_slorient;
6846
/* make all regions the same height */
6847
struct canvas *cv = gflag ? &D_canvas : D_forecv->c_slback;
6848
if (cv->c_slperp->c_slorient & orient)
6849
EqualizeCanvas(cv->c_slperp, gflag);
6850
/* can't use cv->c_slorient directly as it can be D_canvas */
6851
if ((cv->c_slperp->c_slorient ^ (SLICE_HORI ^ SLICE_VERT)) & orient)
6856
EqualizeCanvas(cv->c_slperp, gflag);
6859
EqualizeCanvas(cv, gflag);
6862
RecreateCanvasChain();
6863
RethinkDisplayViewports();
6864
ResizeLayersToCanvases();
6867
if (!strcmp(arg, "min") || !strcmp(arg, "0"))
6872
else if (!strcmp(arg, "max") || !strcmp(arg, "_"))
6879
if (l > 0 && arg[l - 1] == '%')
6882
diff = atoi(arg + 1);
6883
else if (*arg == '-')
6884
diff = -atoi(arg + 1);
6887
diff = atoi(arg); /* +1 because of caption line */
6890
abs = diff == 0 ? 2 : 1;
6896
diff = diff * percent / 100;
6898
if (cv->c_slorient & orient)
6899
ChangeCanvasSize(cv, abs, diff, gflag, percent);
6900
if (cv->c_slback->c_slorient & orient)
6901
ChangeCanvasSize(cv->c_slback, abs, diff, gflag, percent);
6903
ResizeCanvas(&D_canvas);
6904
RecreateCanvasChain();
6905
RethinkDisplayViewports();
6906
ResizeLayersToCanvases();
6913
if (siz + diff > dsize - (nreg - 1) * 2 - 1)
6914
diff = dsize - (nreg - 1) * 2 - 1 - siz;
6915
if (diff == 0 || siz + diff < 1)
6920
if (D_forecv->c_next)
6922
D_forecv->c_ye += diff;
6923
D_forecv->c_next->c_ys += diff;
6924
D_forecv->c_next->c_yoff += diff;
6928
for (cv = D_cvlist; cv; cv = cv->c_next)
6929
if (cv->c_next == D_forecv)
6933
D_forecv->c_ys -= diff;
6934
D_forecv->c_yoff -= diff;
6939
int s, i = 0, found = 0, di = diff, d2;
6940
s = dsize - (nreg - 1) * 2 - 1 - siz;
6941
for (cv = D_cvlist; cv; i = cv->c_ye + 2, cv = cv->c_next)
6945
cv->c_ye = i + (cv->c_ye - cv->c_ys) + diff;
6946
cv->c_yoff -= cv->c_ys - i;
6951
s -= cv->c_ye - cv->c_ys;
6959
d2 = di > cv->c_ye - cv->c_ys ? cv->c_ye - cv->c_ys : di;
6961
cv->c_ye = i + (cv->c_ye - cv->c_ys) - d2;
6962
cv->c_yoff -= cv->c_ys - i;
6966
RethinkDisplayViewports();
6967
ResizeLayersToCanvases();
6972
ResizeFin(buf, len, data)
6978
int flags = *(int *)data;
6979
ch = ((unsigned char *)buf)[len];
6982
ResizeRegions(buf, flags);
6986
flags ^= RESIZE_FLAG_H;
6988
flags ^= RESIZE_FLAG_V;
6990
flags |= RESIZE_FLAG_H|RESIZE_FLAG_V;
6992
flags ^= D_forecv->c_slorient == SLICE_VERT ? RESIZE_FLAG_H : RESIZE_FLAG_V;
6994
flags ^= RESIZE_FLAG_L;
6997
inp_setprompt(resizeprompts[flags], NULL);
6998
*(int *)data = flags;
7003
SetForeCanvas(d, cv)
7007
struct display *odisplay = display;
7008
if (d->d_forecv == cv)
7013
if ((focusminwidth && (focusminwidth < 0 || D_forecv->c_xe - D_forecv->c_xs + 1 < focusminwidth)) ||
7014
(focusminheight && (focusminheight < 0 || D_forecv->c_ye - D_forecv->c_ys + 1 < focusminheight)))
7016
ResizeCanvas(&D_canvas);
7017
RecreateCanvasChain();
7018
RethinkDisplayViewports();
7019
ResizeLayersToCanvases(); /* redisplays */
7021
fore = D_fore = Layer2Window(D_forecv->c_layer);
7022
if (D_other == fore)
7024
flayer = D_forecv->c_layer;
7026
if (D_xtermosc[2] || D_xtermosc[3])
7037
flayer = D_forecv->c_layer;
7038
CV_CALL(D_forecv, LayRestore();LaySetCursor());
7039
WindowChanged(0, 'F');
7052
p = Layer2Window(D_forecv->c_layer);
7053
for (i = 3; i >=0; i--)
7054
SetXtermOSC(i, p ? p->w_xtermosc[i] : 0);
7059
ParseAttrColor(s1, s2, msgok)
7071
while (*ss && *ss != ' ')
7075
if (*s && (s2 || *ss || !((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') || *s == '.')))
7077
int mode = 0, n = 0;
7095
if (*s >= '0' && *s <= '9')
7098
if (*s >= '0' && *s <= '9')
7099
n = n * 16 + (*s++ - '0');
7100
else if (*s >= 'a' && *s <= 'f')
7101
n = n * 16 + (*s++ - ('a' - 10));
7102
else if (*s >= 'A' && *s <= 'F')
7103
n = n * 16 + (*s++ - ('A' - 10));
7104
else if (*s && *s != ' ')
7107
Msg(0, "Illegal attribute hexchar '%c'", *s);
7113
while (*s && *s != ' ')
7130
Msg(0, "Illegal attribute specifier '%c'", *s);
7136
if (*s && *s != ' ')
7139
Msg(0, "junk after attribute description: '%c'", *s);
7151
while (*s && *s == ' ')
7159
Msg(0, "junk after description: '%c'", *s);
7163
while (*s && *s == ' ')
7170
static char costr[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
7180
for (j = 0; j < 2 && *s && *s != ' '; j++)
7182
for (i = 0; costr[i]; i++)
7188
Msg(0, "illegal color descriptor: '%c'", *s);
7192
n = n << 4 | (i & 15);
7195
n = (n & 0x20ff) | 0x200;
7199
if ((n & 0xf00) == 0xf00)
7200
n ^= 0xf00; /* clear superflous bits */
7203
n ^= 0x2400; /* shift bit into right position */
7206
n |= 0xf0; /* don't change bg color */
7207
if (numco != 2 && n != 0xff)
7208
n |= 0x100; /* special invert mode */
7209
if (*s && *s != ' ')
7212
Msg(0, "junk after color description: '%c'", *s);
7220
while (*s && *s == ' ')
7225
Msg(0, "junk after description: '%c'", *s);
7228
debug1("ParseAttrColor %06x\n", r);
7236
* e just set intensity
7237
* f don't change anything
7238
* Intensity is encoded into bits 17(fg) and 18(bg).
7241
ApplyAttrColor(i, mc)
7245
debug1("ApplyAttrColor %06x\n", i);
7246
mc->attr |= i >> 8 & 255;
7247
mc->attr ^= i & 255;
7249
i = (i >> 16) ^ 0xff;
7250
if ((i & 0x100) != 0)
7253
if (mc->attr & (A_SO|A_RV))
7255
i = ((i & 0x0f) << 4) | ((i & 0xf0) >> 4) | ((i & 0x200) << 1) | ((i & 0x400) >> 1);
7257
i = ((i & 0x0f) << 4) | ((i & 0xf0) >> 4);
7261
if ((i & 0x0f) != 0x0f)
7262
mc->attr = (mc->attr & 0xbf) | ((i >> 3) & 0x40);
7263
if ((i & 0xf0) != 0xf0)
7264
mc->attr = (mc->attr & 0x7f) | ((i >> 3) & 0x80);
7266
mc->color = 0x99 ^ mc->color;
7267
if ((i & 0x0e) == 0x0e)
7268
i = (i & 0xf0) | (mc->color & 0x0f);
7269
if ((i & 0xe0) == 0xe0)
7270
i = (i & 0x0f) | (mc->color & 0xf0);
7271
mc->color = 0x99 ^ i;
7272
debug2("ApplyAttrColor - %02x %02x\n", mc->attr, i);