1
/* Copyright (c) 1993-2002
2
* Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3
* Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4
* Copyright (c) 1987 Oliver Laumann
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program (see the file COPYING); if not, write to the
18
* Free Software Foundation, Inc.,
19
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21
****************************************************************
24
#include <sys/types.h>
28
#if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
33
#include <sys/ioctl.h>
39
/* for solaris 2.1, Unixware (SVR4.2) and possibly others: */
41
# include <sys/stropts.h>
48
extern struct comm comms[];
50
extern char *RcFileName, *home;
51
extern char *BellString, *ActivityString, *ShellProg, *ShellArgs[];
52
extern char *hstatusstring, *captionstring, *timestring;
53
extern char *wliststr, *wlisttit;
54
extern int captionalways;
55
extern char *hardcopydir, *screenlogfile, *logtstamp_string;
56
extern int log_flush, logtstamp_on, logtstamp_after;
57
extern char *VisualBellString;
58
extern int VBellWait, MsgWait, MsgMinWait, SilenceWait;
59
extern char SockPath[], *SockName;
60
extern int TtyMode, auto_detach, use_altscreen;
61
extern int iflag, maxwin;
62
extern int use_hardstatus, visual_bell;
64
extern int attr2color[][4];
65
extern int nattr2color;
67
extern int hardstatusemu;
68
extern char *printcmd;
69
extern int default_startup;
70
extern int defobuflimit;
71
extern int defnonblock;
72
extern int ZombieKey_destroy;
73
extern int ZombieKey_resurrect;
75
extern int defautonuke;
77
extern int separate_sids;
78
extern struct NewWindow nwin_default, nwin_undef;
80
extern int join_with_cr;
81
extern int compacthist;
86
extern unsigned char mark_key_tab[];
87
extern char *BufferFile;
90
extern char *BufferFile, *PowDetachString;
93
extern struct acluser *EffectiveAclUser; /* acl.c */
95
extern struct term term[]; /* terminal capabilities */
97
extern char *kmapdef[];
98
extern char *kmapadef[];
99
extern char *kmapmdef[];
101
extern struct mchar mchar_so, mchar_null;
102
extern int VerboseCreate;
104
extern char *screenencodings;
107
static int CheckArgNum __P((int, char **));
108
static void ClearAction __P((struct action *));
109
static void SaveAction __P((struct action *, int, char **, int *));
110
static int NextWindow __P((void));
111
static int PreviousWindow __P((void));
112
static int MoreWindows __P((void));
113
static void LogToggle __P((int));
114
static void ShowInfo __P((void));
115
static void ShowDInfo __P((void));
116
static struct win *WindowByName __P((char *));
117
static int WindowByNumber __P((char *));
118
static int ParseOnOff __P((struct action *, int *));
119
static int ParseWinNum __P((struct action *, int *));
120
static int ParseBase __P((struct action *, char *, int *, int, char *));
121
static int ParseNum1000 __P((struct action *, int *));
122
static char **SaveArgs __P((char **));
123
static int IsNum __P((char *, int));
124
static void Colonfin __P((char *, int, char *));
125
static void InputSelect __P((void));
126
static void InputSetenv __P((char *));
127
static void InputAKA __P((void));
129
static int InputSu __P((struct win *, struct acluser **, char *));
130
static void su_fin __P((char *, int, char *));
132
static void AKAfin __P((char *, int, char *));
134
static void copy_reg_fn __P((char *, int, char *));
135
static void ins_reg_fn __P((char *, int, char *));
137
static void process_fn __P((char *, int, char *));
139
static void pass1 __P((char *, int, char *));
140
static void pass2 __P((char *, int, char *));
143
static void pow_detach_fn __P((char *, int, char *));
145
static void digraph_fn __P((char *, int, char *));
146
static void confirm_fn __P((char *, int, char *));
147
static int IsOnDisplay __P((struct win *));
148
static void ResizeRegions __P((char*));
149
static void ResizeFin __P((char *, int, char *));
150
static struct action *FindKtab __P((char *, int));
153
extern struct layer *flayer;
154
extern struct display *display, *displays;
155
extern struct win *fore, *console_window, *windows;
156
extern struct acluser *users;
158
extern char screenterm[], HostName[], version[];
159
extern struct NewWindow nwin_undef, nwin_default;
160
extern struct LayFuncs WinLf;
162
extern int Z0width, Z1width;
163
extern int real_uid, real_gid;
166
extern int nethackflag;
170
struct win *wtab[MAXWIN]; /* window table, should be dynamic */
174
extern int maxusercount;
178
struct plop plop_tab[MAX_PLOP_DEFS];
181
# define PTYMODE 0622
184
int TtyMode = PTYMODE;
185
int hardcopy_append = 0;
186
int all_norefresh = 0;
189
char *zmodem_sendcmd;
190
char *zmodem_recvcmd;
191
static char *zmodes[4] = {"off", "auto", "catch", "pass"};
195
struct action idleaction;
200
struct action ktab[256]; /* command key translation table */
204
struct action ktab[256];
206
struct kclass *kclasses;
209
struct action umtab[KMAP_KEYS+KMAP_AKEYS];
210
struct action dmtab[KMAP_KEYS+KMAP_AKEYS];
211
struct action mmtab[KMAP_KEYS+KMAP_AKEYS];
212
struct kmap_ext *kmap_exts;
214
static int maptimeout = 300;
218
/* digraph table taken from old vim and rfc1345 */
219
static const unsigned char digraphs[][3] = {
220
{' ', ' ', 160}, /* ļæ½ */
221
{'N', 'S', 160}, /* ļæ½ */
222
{'~', '!', 161}, /* ļæ½ */
223
{'!', '!', 161}, /* ļæ½ */
224
{'!', 'I', 161}, /* ļæ½ */
225
{'c', '|', 162}, /* ļæ½ */
226
{'c', 't', 162}, /* ļæ½ */
227
{'$', '$', 163}, /* ļæ½ */
228
{'P', 'd', 163}, /* ļæ½ */
229
{'o', 'x', 164}, /* ļæ½ */
230
{'C', 'u', 164}, /* ļæ½ */
231
{'C', 'u', 164}, /* ļæ½ */
232
{'E', 'u', 164}, /* ļæ½ */
233
{'Y', '-', 165}, /* ļæ½ */
234
{'Y', 'e', 165}, /* ļæ½ */
235
{'|', '|', 166}, /* ļæ½ */
236
{'B', 'B', 166}, /* ļæ½ */
237
{'p', 'a', 167}, /* ļæ½ */
238
{'S', 'E', 167}, /* ļæ½ */
239
{'"', '"', 168}, /* ļæ½ */
240
{'\'', ':', 168}, /* ļæ½ */
241
{'c', 'O', 169}, /* ļæ½ */
242
{'C', 'o', 169}, /* ļæ½ */
243
{'a', '-', 170}, /* ļæ½ */
244
{'<', '<', 171}, /* ļæ½ */
245
{'-', ',', 172}, /* ļæ½ */
246
{'N', 'O', 172}, /* ļæ½ */
247
{'-', '-', 173}, /* ļæ½ */
248
{'r', 'O', 174}, /* ļæ½ */
249
{'R', 'g', 174}, /* ļæ½ */
250
{'-', '=', 175}, /* ļæ½ */
251
{'\'', 'm', 175}, /* ļæ½ */
252
{'~', 'o', 176}, /* ļæ½ */
253
{'D', 'G', 176}, /* ļæ½ */
254
{'+', '-', 177}, /* ļæ½ */
255
{'2', '2', 178}, /* ļæ½ */
256
{'2', 'S', 178}, /* ļæ½ */
257
{'3', '3', 179}, /* ļæ½ */
258
{'3', 'S', 179}, /* ļæ½ */
259
{'\'', '\'', 180}, /* ļæ½ */
260
{'j', 'u', 181}, /* ļæ½ */
261
{'M', 'y', 181}, /* ļæ½ */
262
{'p', 'p', 182}, /* ļæ½ */
263
{'P', 'I', 182}, /* ļæ½ */
264
{'~', '.', 183}, /* ļæ½ */
265
{'.', 'M', 183}, /* ļæ½ */
266
{',', ',', 184}, /* ļæ½ */
267
{'\'', ',', 184}, /* ļæ½ */
268
{'1', '1', 185}, /* ļæ½ */
269
{'1', 'S', 185}, /* ļæ½ */
270
{'o', '-', 186}, /* ļæ½ */
271
{'>', '>', 187}, /* ļæ½ */
272
{'1', '4', 188}, /* ļæ½ */
273
{'1', '2', 189}, /* ļæ½ */
274
{'3', '4', 190}, /* ļæ½ */
275
{'~', '?', 191}, /* ļæ½ */
276
{'?', '?', 191}, /* ļæ½ */
277
{'?', 'I', 191}, /* ļæ½ */
278
{'A', '`', 192}, /* ļæ½ */
279
{'A', '!', 192}, /* ļæ½ */
280
{'A', '\'', 193}, /* ļæ½ */
281
{'A', '^', 194}, /* ļæ½ */
282
{'A', '>', 194}, /* ļæ½ */
283
{'A', '~', 195}, /* ļæ½ */
284
{'A', '?', 195}, /* ļæ½ */
285
{'A', '"', 196}, /* ļæ½ */
286
{'A', ':', 196}, /* ļæ½ */
287
{'A', '@', 197}, /* ļæ½ */
288
{'A', 'A', 197}, /* ļæ½ */
289
{'A', 'E', 198}, /* ļæ½ */
290
{'C', ',', 199}, /* ļæ½ */
291
{'E', '`', 200}, /* ļæ½ */
292
{'E', '!', 200}, /* ļæ½ */
293
{'E', '\'', 201}, /* ļæ½ */
294
{'E', '^', 202}, /* ļæ½ */
295
{'E', '>', 202}, /* ļæ½ */
296
{'E', '"', 203}, /* ļæ½ */
297
{'E', ':', 203}, /* ļæ½ */
298
{'I', '`', 204}, /* ļæ½ */
299
{'I', '!', 204}, /* ļæ½ */
300
{'I', '\'', 205}, /* ļæ½ */
301
{'I', '^', 206}, /* ļæ½ */
302
{'I', '>', 206}, /* ļæ½ */
303
{'I', '"', 207}, /* ļæ½ */
304
{'I', ':', 207}, /* ļæ½ */
305
{'D', '-', 208}, /* ļæ½ */
306
{'N', '~', 209}, /* ļæ½ */
307
{'N', '?', 209}, /* ļæ½ */
308
{'O', '`', 210}, /* ļæ½ */
309
{'O', '!', 210}, /* ļæ½ */
310
{'O', '\'', 211}, /* ļæ½ */
311
{'O', '^', 212}, /* ļæ½ */
312
{'O', '>', 212}, /* ļæ½ */
313
{'O', '~', 213}, /* ļæ½ */
314
{'O', '?', 213}, /* ļæ½ */
315
{'O', '"', 214}, /* ļæ½ */
316
{'O', ':', 214}, /* ļæ½ */
317
{'/', '\\', 215}, /* ļæ½ */
318
{'*', 'x', 215}, /* ļæ½ */
319
{'O', '/', 216}, /* ļæ½ */
320
{'U', '`', 217}, /* ļæ½ */
321
{'U', '!', 217}, /* ļæ½ */
322
{'U', '\'', 218}, /* ļæ½ */
323
{'U', '^', 219}, /* ļæ½ */
324
{'U', '>', 219}, /* ļæ½ */
325
{'U', '"', 220}, /* ļæ½ */
326
{'U', ':', 220}, /* ļæ½ */
327
{'Y', '\'', 221}, /* ļæ½ */
328
{'I', 'p', 222}, /* ļæ½ */
329
{'T', 'H', 222}, /* ļæ½ */
330
{'s', 's', 223}, /* ļæ½ */
331
{'s', '"', 223}, /* ļæ½ */
332
{'a', '`', 224}, /* ļæ½ */
333
{'a', '!', 224}, /* ļæ½ */
334
{'a', '\'', 225}, /* ļæ½ */
335
{'a', '^', 226}, /* ļæ½ */
336
{'a', '>', 226}, /* ļæ½ */
337
{'a', '~', 227}, /* ļæ½ */
338
{'a', '?', 227}, /* ļæ½ */
339
{'a', '"', 228}, /* ļæ½ */
340
{'a', ':', 228}, /* ļæ½ */
341
{'a', 'a', 229}, /* ļæ½ */
342
{'a', 'e', 230}, /* ļæ½ */
343
{'c', ',', 231}, /* ļæ½ */
344
{'e', '`', 232}, /* ļæ½ */
345
{'e', '!', 232}, /* ļæ½ */
346
{'e', '\'', 233}, /* ļæ½ */
347
{'e', '^', 234}, /* ļæ½ */
348
{'e', '>', 234}, /* ļæ½ */
349
{'e', '"', 235}, /* ļæ½ */
350
{'e', ':', 235}, /* ļæ½ */
351
{'i', '`', 236}, /* ļæ½ */
352
{'i', '!', 236}, /* ļæ½ */
353
{'i', '\'', 237}, /* ļæ½ */
354
{'i', '^', 238}, /* ļæ½ */
355
{'i', '>', 238}, /* ļæ½ */
356
{'i', '"', 239}, /* ļæ½ */
357
{'i', ':', 239}, /* ļæ½ */
358
{'d', '-', 240}, /* ļæ½ */
359
{'n', '~', 241}, /* ļæ½ */
360
{'n', '?', 241}, /* ļæ½ */
361
{'o', '`', 242}, /* ļæ½ */
362
{'o', '!', 242}, /* ļæ½ */
363
{'o', '\'', 243}, /* ļæ½ */
364
{'o', '^', 244}, /* ļæ½ */
365
{'o', '>', 244}, /* ļæ½ */
366
{'o', '~', 245}, /* ļæ½ */
367
{'o', '?', 245}, /* ļæ½ */
368
{'o', '"', 246}, /* ļæ½ */
369
{'o', ':', 246}, /* ļæ½ */
370
{':', '-', 247}, /* ļæ½ */
371
{'o', '/', 248}, /* ļæ½ */
372
{'u', '`', 249}, /* ļæ½ */
373
{'u', '!', 249}, /* ļæ½ */
374
{'u', '\'', 250}, /* ļæ½ */
375
{'u', '^', 251}, /* ļæ½ */
376
{'u', '>', 251}, /* ļæ½ */
377
{'u', '"', 252}, /* ļæ½ */
378
{'u', ':', 252}, /* ļæ½ */
379
{'y', '\'', 253}, /* ļæ½ */
380
{'i', 'p', 254}, /* ļæ½ */
381
{'t', 'h', 254}, /* ļæ½ */
382
{'y', '"', 255}, /* ļæ½ */
383
{'y', ':', 255}, /* ļæ½ */
384
{'"', '[', 196}, /* ļæ½ */
385
{'"', '\\', 214}, /* ļæ½ */
386
{'"', ']', 220}, /* ļæ½ */
387
{'"', '{', 228}, /* ļæ½ */
388
{'"', '|', 246}, /* ļæ½ */
389
{'"', '}', 252}, /* ļæ½ */
390
{'"', '~', 223} /* ļæ½ */
399
register unsigned int i;
404
for (i = 0; i < sizeof(ktab)/sizeof(*ktab); i++)
406
ktab[i].nr = RC_ILLEGAL;
407
ktab[i].args = noargs;
411
for (i = 0; i < KMAP_KEYS+KMAP_AKEYS; i++)
413
umtab[i].nr = RC_ILLEGAL;
414
umtab[i].args = noargs;
416
dmtab[i].nr = RC_ILLEGAL;
417
dmtab[i].args = noargs;
419
mmtab[i].nr = RC_ILLEGAL;
420
mmtab[i].args = noargs;
424
for (i = 0; i < NKMAPDEF; i++)
426
if (i + KMAPDEFSTART < T_CAPS)
428
if (i + KMAPDEFSTART >= T_CAPS + KMAP_KEYS)
432
argarr[0] = kmapdef[i];
433
SaveAction(dmtab + i + (KMAPDEFSTART - T_CAPS), RC_STUFF, argarr, 0);
435
for (i = 0; i < NKMAPADEF; i++)
437
if (i + KMAPADEFSTART < T_CURSOR)
439
if (i + KMAPADEFSTART >= T_CURSOR + KMAP_AKEYS)
441
if (kmapadef[i] == 0)
443
argarr[0] = kmapadef[i];
444
SaveAction(dmtab + i + (KMAPADEFSTART - T_CURSOR + KMAP_KEYS), RC_STUFF, argarr, 0);
446
for (i = 0; i < NKMAPMDEF; i++)
448
if (i + KMAPMDEFSTART < T_CAPS)
450
if (i + KMAPMDEFSTART >= T_CAPS + KMAP_KEYS)
452
if (kmapmdef[i] == 0)
454
argarr[0] = kmapmdef[i];
456
SaveAction(mmtab + i + (KMAPMDEFSTART - T_CAPS), RC_STUFF, argarr, 0);
460
ktab['h'].nr = RC_HARDCOPY;
462
ktab['z'].nr = ktab[Ctrl('z')].nr = RC_SUSPEND;
464
ktab['c'].nr = ktab[Ctrl('c')].nr = RC_SCREEN;
465
ktab[' '].nr = ktab[Ctrl(' ')].nr =
466
ktab['n'].nr = ktab[Ctrl('n')].nr = RC_NEXT;
467
ktab['N'].nr = RC_NUMBER;
468
ktab[Ctrl('h')].nr = ktab[0177].nr = ktab['p'].nr = ktab[Ctrl('p')].nr = RC_PREV;
469
ktab['k'].nr = ktab[Ctrl('k')].nr = RC_KILL;
470
ktab['l'].nr = ktab[Ctrl('l')].nr = RC_REDISPLAY;
471
ktab['w'].nr = ktab[Ctrl('w')].nr = RC_WINDOWS;
472
ktab['v'].nr = RC_VERSION;
473
ktab[Ctrl('v')].nr = RC_DIGRAPH;
474
ktab['q'].nr = ktab[Ctrl('q')].nr = RC_XON;
475
ktab['s'].nr = ktab[Ctrl('s')].nr = RC_XOFF;
476
ktab['t'].nr = ktab[Ctrl('t')].nr = RC_TIME;
477
ktab['i'].nr = ktab[Ctrl('i')].nr = RC_INFO;
478
ktab['m'].nr = ktab[Ctrl('m')].nr = RC_LASTMSG;
479
ktab['A'].nr = RC_TITLE;
480
#if defined(UTMPOK) && defined(LOGOUTOK)
481
ktab['L'].nr = RC_LOGIN;
483
ktab[','].nr = RC_LICENSE;
484
ktab['W'].nr = RC_WIDTH;
485
ktab['.'].nr = RC_DUMPTERMCAP;
486
ktab[Ctrl('\\')].nr = RC_QUIT;
488
ktab['d'].nr = ktab[Ctrl('d')].nr = RC_DETACH;
490
ktab['D'].nr = RC_POW_DETACH;
493
ktab['r'].nr = ktab[Ctrl('r')].nr = RC_WRAP;
494
ktab['f'].nr = ktab[Ctrl('f')].nr = RC_FLOW;
495
ktab['C'].nr = RC_CLEAR;
496
ktab['Z'].nr = RC_RESET;
497
ktab['H'].nr = RC_LOG;
498
ktab['M'].nr = RC_MONITOR;
499
ktab['?'].nr = RC_HELP;
501
ktab['*'].nr = RC_DISPLAYS;
507
SaveAction(ktab + '-', RC_SELECT, args, 0);
509
for (i = 0; i < ((MAXWIN < 10) ? MAXWIN : 10); i++)
511
char *args[2], arg1[10];
514
sprintf(arg1, "%d", i);
515
SaveAction(ktab + '0' + i, RC_SELECT, args, 0);
517
ktab['\''].nr = RC_SELECT; /* calling a window by name */
522
SaveAction(ktab + '"', RC_WINDOWLIST, args, 0);
524
ktab[Ctrl('G')].nr = RC_VBELL;
525
ktab[':'].nr = RC_COLON;
527
ktab['['].nr = ktab[Ctrl('[')].nr = RC_COPY;
532
SaveAction(ktab + ']', RC_PASTE, args, 0);
533
SaveAction(ktab + Ctrl(']'), RC_PASTE, args, 0);
535
ktab['{'].nr = RC_HISTORY;
536
ktab['}'].nr = RC_HISTORY;
537
ktab['>'].nr = RC_WRITEBUF;
538
ktab['<'].nr = RC_READBUF;
539
ktab['='].nr = RC_REMOVEBUF;
542
ktab['D'].nr = RC_POW_DETACH;
545
ktab['x'].nr = ktab[Ctrl('x')].nr = RC_LOCKSCREEN;
547
ktab['b'].nr = ktab[Ctrl('b')].nr = RC_BREAK;
548
ktab['B'].nr = RC_POW_BREAK;
549
ktab['_'].nr = RC_SILENCE;
550
ktab['S'].nr = RC_SPLIT;
551
ktab['Q'].nr = RC_ONLY;
552
ktab['X'].nr = RC_REMOVE;
553
ktab['F'].nr = RC_FIT;
554
ktab['\t'].nr = RC_FOCUS;
555
/* These come last; they may want overwrite others: */
558
ClearAction(&ktab[DefaultEsc]);
559
ktab[DefaultEsc].nr = RC_OTHER;
561
if (DefaultMetaEsc >= 0)
563
ClearAction(&ktab[DefaultMetaEsc]);
564
ktab[DefaultMetaEsc].nr = RC_META;
567
idleaction.nr = RC_BLANKER;
568
idleaction.args = noargs;
572
static struct action *
573
FindKtab(class, create)
577
struct kclass *kp, **kpp;
582
for (kpp = &kclasses; (kp = *kpp) != 0; kpp = &kp->next)
583
if (!strcmp(kp->name, class))
589
if (strlen(class) > 80)
591
Msg(0, "Command class name too long.");
594
kp = malloc(sizeof(*kp));
600
kp->name = SaveStr(class);
601
for (i = 0; i < (int)(sizeof(kp->ktab)/sizeof(*kp->ktab)); i++)
603
kp->ktab[i].nr = RC_ILLEGAL;
604
kp->ktab[i].args = noargs;
618
if (act->nr == RC_ILLEGAL)
620
act->nr = RC_ILLEGAL;
621
if (act->args == noargs)
623
for (p = act->args; *p; p++)
625
free((char *)act->args);
631
* ProcessInput: process input from display and feed it into
632
* the layer on canvas D_forecv.
638
* This ProcessInput just does the keybindings and passes
639
* everything else on to ProcessInput2.
643
ProcessInput(ibuf, ilen)
648
unsigned char *s, *q;
652
debug1("ProcessInput: %d bytes\n", ilen);
653
if (display == 0 || ilen == 0)
658
s = (unsigned char *)ibuf;
662
if (D_dontmap || !D_nseqs)
669
debug3("cmp %c %c[%d]\n", ch, *D_seqp, D_seqp - D_kmaps);
672
l = D_seqp[D_seqp[-D_seql-1] + 1];
676
debug1("miss %d\n", D_seqp - D_kmaps);
679
debug("complete miss\n");
682
p = (char *)D_seqp - l;
684
D_seqp = D_kmaps + 3;
687
if ((q = D_seqh) != 0)
690
i = q[0] << 8 | q[1];
691
i &= ~KMAP_NOTIMEOUT;
692
debug1("Mapping former hit #%d - ", i);
693
debug2("%d(%s) - ", q[2], q + 3);
695
ProcessInput2((char *)q + 3, q[2]);
703
debug1("flush old %d\n", l);
712
/* Finish old stuff */
714
debug1("finish old %d\n", slen);
716
ProcessInput2(ibuf, slen);
725
debug2("length am %d, want %d\n", l, D_seqp[-l - 1]);
726
if (l == D_seqp[-l - 1])
731
if (D_kmaps + D_nseqs > q && q[2] > l && !bcmp(D_seqp - l, q + 3, l))
733
debug1("have another mapping (%s), delay execution\n", q + 3);
734
D_seqh = D_seqp - 3 - l;
739
i = D_seqp[-l - 3] << 8 | D_seqp[-l - 2];
740
i &= ~KMAP_NOTIMEOUT;
741
debug1("Mapping #%d - ", i);
742
p = (char *)D_seqp - l;
743
debug2("%d(%s) - ", l, p);
745
D_seqp = D_kmaps + 3;
757
debug("am in sequence -> check for timeout\n");
759
for (s = D_seqp; ; s += i * 2 + 4)
761
if (s[-l-3] & KMAP_NOTIMEOUT >> 8)
763
if ((i = s[s[-l-1] + 1]) == 0)
765
SetTimeout(&D_mapev, maptimeout);
771
ProcessInput2(ibuf, slen);
775
# define ProcessInput2 ProcessInput
780
* Here only the screen escape commands are handled.
784
ProcessInput2(ibuf, ilen)
790
struct action *ktabp;
792
debug1("ProcessInput2: %d bytes\n", ilen);
793
while (ilen && display)
795
debug1(" - ilen now %d bytes\n", ilen);
796
flayer = D_forecv->c_layer;
804
if ((unsigned char)*s++ == D_user->u_Esc)
810
DoProcess(fore, &ibuf, &slen, 0);
816
ktabp = D_ESCseen ? D_ESCseen : ktab;
818
ch = (unsigned char)*s;
821
* As users have different esc characters, but a common ktab[],
822
* we fold back the users esc and meta-esc key to the Default keys
823
* that can be looked up in the ktab[]. grmbl. jw.
824
* XXX: make ktab[] a per user thing.
826
if (ch == D_user->u_Esc)
828
else if (ch == D_user->u_MetaEsc)
832
DoAction(&ktabp[ch], ch);
833
ibuf = (char *)(s + 1);
839
DoProcess(p, bufp, lenp, pa)
846
struct display *d = display;
849
/* XXX -> PasteStart */
850
if (pa && *lenp > 1 && p && p->w_slowpaste)
852
/* schedule slowpaste event */
853
SetTimeout(&p->w_paster.pa_slowev, p->w_slowpaste);
854
evenq(&p->w_paster.pa_slowev);
858
while (flayer && *lenp)
861
if (!pa && p && p->w_paster.pa_pastelen && flayer == p->w_paster.pa_pastelayer)
863
debug("layer is busy - beep!\n");
864
WBell(p, visual_bell);
872
LayProcess(bufp, lenp);
874
if (pa && !pa->pa_pastelayer)
875
break; /* flush rest of paste */
884
/* We're full, let's beep */
885
debug("layer is full - beep!\n");
886
WBell(p, visual_bell);
894
if (pa && pa->pa_pastelen == 0)
903
int x, m, l = 0, r = RC_LAST;
907
x = strcmp(str, comms[m].name);
919
CheckArgNum(nr, args)
924
static char *argss[] = {"no", "one", "two", "three", "four", "OOPS"};
925
static char *orformat[] =
927
"%s: %s: %s argument%s required",
928
"%s: %s: %s or %s argument%s required",
929
"%s: %s: %s, %s or %s argument%s required",
930
"%s: %s: %s, %s, %s or %s argument%s required"
933
n = comms[nr].flags & ARGS_MASK;
934
for (i = 0; args[i]; i++)
936
if (comms[nr].flags & ARGS_ORMORE)
940
Msg(0, "%s: %s: at least %s argument%s required",
941
rc_name, comms[nr].name, argss[n], n != 1 ? "s" : "");
945
else if ((comms[nr].flags & ARGS_PLUS1) &&
946
(comms[nr].flags & ARGS_PLUS2) &&
947
(comms[nr].flags & ARGS_PLUS3))
949
if (i != n && i != n + 1 && i != n + 2 && i != n + 3)
951
Msg(0, orformat[3], rc_name, comms[nr].name, argss[n],
952
argss[n + 1], argss[n + 2], argss[n + 3], "");
956
else if ((comms[nr].flags & ARGS_PLUS1) &&
957
(comms[nr].flags & ARGS_PLUS2))
959
if (i != n && i != n + 1 && i != n + 2)
961
Msg(0, orformat[2], rc_name, comms[nr].name, argss[n],
962
argss[n + 1], argss[n + 2], "");
966
else if ((comms[nr].flags & ARGS_PLUS1) &&
967
(comms[nr].flags & ARGS_PLUS3))
969
if (i != n && i != n + 1 && i != n + 3)
971
Msg(0, orformat[2], rc_name, comms[nr].name, argss[n],
972
argss[n + 1], argss[n + 3], "");
976
else if ((comms[nr].flags & ARGS_PLUS2) &&
977
(comms[nr].flags & ARGS_PLUS3))
979
if (i != n && i != n + 2 && i != n + 3)
981
Msg(0, orformat[2], rc_name, comms[nr].name, argss[n],
982
argss[n + 2], argss[n + 3], "");
986
else if (comms[nr].flags & ARGS_PLUS1)
988
if (i != n && i != n + 1)
990
Msg(0, orformat[1], rc_name, comms[nr].name, argss[n],
991
argss[n + 1], n != 0 ? "s" : "");
995
else if (comms[nr].flags & ARGS_PLUS2)
997
if (i != n && i != n + 2)
999
Msg(0, orformat[1], rc_name, comms[nr].name, argss[n],
1004
else if (comms[nr].flags & ARGS_PLUS3)
1006
if (i != n && i != n + 3)
1008
Msg(0, orformat[1], rc_name, comms[nr].name, argss[n],
1015
Msg(0, orformat[0], rc_name, comms[nr].name, argss[n], n != 1 ? "s" : "");
1028
char **args = act->args;
1029
int *argl = act->argl;
1031
int argc, i, n, msgok;
1034
struct display *odisplay = display;
1035
struct acluser *user;
1037
user = display ? D_user : users;
1038
if (nr == RC_ILLEGAL)
1040
debug1("key '%c': No action\n", key);
1043
n = comms[nr].flags;
1044
if ((n & NEED_DISPLAY) && display == 0)
1046
Msg(0, "%s: %s: display required", rc_name, comms[nr].name);
1049
if ((n & NEED_FORE) && fore == 0)
1051
Msg(0, "%s: %s: window required", rc_name, comms[nr].name);
1054
if ((n & NEED_LAYER) && flayer == 0)
1056
Msg(0, "%s: %s: display or window required", rc_name, comms[nr].name);
1059
if ((argc = CheckArgNum(nr, args)) < 0)
1064
if (AclCheckPermCmd(D_user, ACL_EXEC, &comms[nr]))
1066
Msg(0, "%s: %s: permission denied (user %s)",
1067
rc_name, comms[nr].name, (EffectiveAclUser ? EffectiveAclUser : D_user)->u_name);
1071
#endif /* MULTIUSER */
1073
msgok = display && !*rc_name;
1079
else if (args[0][0] == '-' && !args[0][1])
1081
SetForeWindow((struct win *)0);
1084
else if (args[0][0] == '.' && !args[0][1])
1087
Msg(0, "select . needs a window");
1090
SetForeWindow(fore);
1094
else if (ParseWinNum(act, &n) == 0)
1098
case RC_DEFAUTONUKE:
1099
if (ParseOnOff(act, &defautonuke) == 0 && msgok)
1100
Msg(0, "Default autonuke turned %s", defautonuke ? "on" : "off");
1101
if (display && *rc_name)
1102
D_auto_nuke = defautonuke;
1105
if (ParseOnOff(act, &D_auto_nuke) == 0 && msgok)
1106
Msg(0, "Autonuke turned %s", D_auto_nuke ? "on" : "off");
1109
case RC_DEFOBUFLIMIT:
1110
if (ParseNum(act, &defobuflimit) == 0 && msgok)
1111
Msg(0, "Default limit set to %d", defobuflimit);
1112
if (display && *rc_name)
1114
D_obufmax = defobuflimit;
1115
D_obuflenmax = D_obuflen - D_obufmax;
1120
Msg(0, "Limit is %d, current buffer size is %d", D_obufmax, D_obuflen);
1121
else if (ParseNum(act, &D_obufmax) == 0 && msgok)
1122
Msg(0, "Limit set to %d", D_obufmax);
1123
D_obuflenmax = D_obuflen - D_obufmax;
1125
case RC_DUMPTERMCAP:
1126
WriteFile(user, (char *)0, DUMP_TERMCAP);
1130
int mode = DUMP_HARDCOPY;
1132
if (argc > 1 && !strcmp(*args, "-h"))
1134
mode = DUMP_SCROLLBACK;
1138
if (*args && args[1])
1140
Msg(0, "%s: hardcopy: too many arguments", rc_name);
1143
if (fore == 0 && *args == 0)
1144
Msg(0, "%s: hardcopy: window required", rc_name);
1146
WriteFile(user, *args, mode);
1150
(void)ParseOnOff(act, &nwin_default.Lflag);
1153
n = fore->w_log ? 1 : 0;
1154
ParseSwitch(act, &n);
1164
SwitchWindow(NextWindow());
1168
SwitchWindow(PreviousWindow());
1177
Input(fore->w_pwin ? "Really kill this filter [y/n]" : "Really kill this window [y/n]", 1, INP_RAW, confirm_fn, (char *)RC_KILL);
1179
Input("Really kill this window [y/n]", 1, INP_RAW, confirm_fn, (char *)RC_KILL);
1187
FreePseudowin(fore);
1188
Msg(0, "Filter removed.");
1192
name = SaveStr(fore->w_title);
1194
Msg(0, "Window %d (%s) killed.", n, name);
1202
Input("Really quit and kill all your windows [y/n]", 1, INP_RAW, confirm_fn, (char *)RC_QUIT);
1209
if (*args && !strcmp(*args, "-h"))
1221
Input(buf, 1, INP_RAW, pow_detach_fn, NULL);
1224
Detach(D_POWER); /* detach and kill Attacher's parent */
1233
Msg(0, "debugging info is written to %s/", DEBUGDIR);
1235
Msg(0, "debugging is currently off. Use 'debug on' to enable.");
1240
debug("debug: closing debug file.\n");
1245
if (strcmp("off", *args))
1249
kill(D_userpid, SIG_NODEBUG); /* a one shot item, but hey... */
1250
# endif /* SIG_NODEBUG */
1252
if (*args == 0 || strcmp("off", *args))
1253
Msg(0, "Sorry, screen was compiled without -DDEBUG option.");
1258
if (*args && !strcmp(*args, "sendcmd"))
1262
free(zmodem_sendcmd);
1263
zmodem_sendcmd = SaveStr(args[1]);
1266
Msg(0, "zmodem sendcmd: %s", zmodem_sendcmd);
1269
if (*args && !strcmp(*args, "recvcmd"))
1273
free(zmodem_recvcmd);
1274
zmodem_recvcmd = SaveStr(args[1]);
1277
Msg(0, "zmodem recvcmd: %s", zmodem_recvcmd);
1282
for (i = 0; i < 4; i++)
1283
if (!strcmp(zmodes[i], *args))
1285
if (i == 4 && !strcmp(*args, "on"))
1289
Msg(0, "usage: zmodem off|auto|catch|pass");
1295
Msg(0, "zmodem mode is %s", zmodes[zmodem_mode]);
1302
ZombieKey_destroy = 0;
1305
if (*argl == 0 || *argl > 2)
1307
Msg(0, "%s:zombie: one or two characters expected.", rc_name);
1310
ZombieKey_destroy = args[0][0];
1311
ZombieKey_resurrect = *argl == 2 ? args[0][1] : 0;
1321
struct display *olddisplay = display;
1322
display = 0; /* no display will cause a broadcast */
1323
Msg(0, "%s: %s", s, *args);
1324
display = olddisplay;
1328
/* where this AT command comes from: */
1330
s = SaveStr(D_user->u_name);
1331
/* DO NOT RETURN FROM HERE WITHOUT RESETTING THIS: */
1332
EffectiveAclUser = D_user;
1334
s = SaveStr(D_usertty);
1336
n = strlen(args[0]);
1339
* the windows/displays loops are quite dangerous here, take extra
1340
* care not to trigger landmines. Things may appear/disappear while
1341
* we are walking along.
1345
case '*': /* user */
1353
for (u = users; u; u = u->u_next)
1355
debug3("strncmp('%s', '%s', %d)\n", *args, u->u_name, n);
1356
if (!strncmp(*args, u->u_name, n))
1359
debug1("at all displays of user %s\n", u->u_name);
1360
for (display = displays; display; display = nd)
1362
nd = display->d_next;
1365
flayer = D_forecv->c_layer;
1369
debug1("AT display %s\n", D_usertty);
1370
DoCommand(args + 1, argl + 1);
1372
Msg(0, "command from %s: %s %s",
1373
s, args[1], args[2] ? args[2] : "");
1380
case '%': /* display */
1384
debug1("at display matching '%s'\n", args[0]);
1385
for (display = displays; display; display = nd)
1387
nd = display->d_next;
1391
flayer = D_forecv->c_layer;
1392
if (strncmp(args[0], D_usertty, n) &&
1393
(strncmp("/dev/", D_usertty, 5) ||
1394
strncmp(args[0], D_usertty + 5, n)) &&
1395
(strncmp("/dev/tty", D_usertty, 8) ||
1396
strncmp(args[0], D_usertty + 8, n)))
1398
debug1("AT display %s\n", D_usertty);
1399
DoCommand(args + 1, argl + 1);
1401
Msg(0, "command from %s: %s %s",
1402
s, args[1], args[2] ? args[2] : "");
1409
case '#': /* window */
1420
if (!*args[0] || (i = WindowByNumber(args[0])) < 0)
1422
args[0][n] = ch; /* must restore string in case of bind */
1423
/* try looping over titles */
1424
for (fore = windows; fore; fore = nw)
1427
if (strncmp(args[0], fore->w_title, n))
1429
debug2("AT window %d(%s)\n", fore->w_number, fore->w_title);
1431
* consider this a bug or a feature:
1432
* while looping through windows, we have fore AND
1433
* display context. This will confuse users who try to
1434
* set up loops inside of loops, but often allows to do
1435
* what you mean, even when you adress your context wrong.
1438
/* XXX: other displays? */
1439
if (fore->w_layer.l_cvlist)
1440
display = fore->w_layer.l_cvlist->c_display;
1441
flayer = fore->w_savelayer ? fore->w_savelayer : &fore->w_layer;
1442
DoCommand(args + 1, argl + 1); /* may destroy our display */
1443
if (fore && fore->w_layer.l_cvlist)
1445
display = fore->w_layer.l_cvlist->c_display;
1446
Msg(0, "command from %s: %s %s",
1447
s, args[1], args[2] ? args[2] : "");
1453
Msg(0, "%s: at '%s': no such window.\n", rc_name, args[0]);
1456
else if (i < MAXWIN && (fore = wtab[i]))
1458
args[0][n] = ch; /* must restore string in case of bind */
1459
debug2("AT window %d (%s)\n", fore->w_number, fore->w_title);
1460
if (fore->w_layer.l_cvlist)
1461
display = fore->w_layer.l_cvlist->c_display;
1462
flayer = fore->w_savelayer ? fore->w_savelayer : &fore->w_layer;
1463
DoCommand(args + 1, argl + 1);
1464
if (fore && fore->w_layer.l_cvlist)
1466
display = fore->w_layer.l_cvlist->c_display;
1467
Msg(0, "command from %s: %s %s",
1468
s, args[1], args[2] ? args[2] : "");
1474
Msg(0, "%s: at [identifier][%%|*|#] command [args]", rc_name);
1480
EffectiveAclUser = NULL;
1487
i = fore ? fore->w_encoding : display ? display->d_encoding : 0;
1488
if (args[0] && args[1] && !strcmp(args[0], "-e"))
1490
i = FindEncoding(args[1]);
1493
Msg(0, "%s: readreg: unknown encoding", rc_name);
1500
* Without arguments we prompt for a destination register.
1501
* It will receive the copybuffer contents.
1502
* This is not done by RC_PASTE, as we prompt for source
1505
if ((s = *args) == NULL)
1507
Input("Copy to register:", 1, INP_RAW, copy_reg_fn, NULL);
1512
Msg(0, "%s: copyreg: character, ^x, or (octal) \\032 expected.", rc_name);
1517
* With two arguments we *really* read register contents from file
1523
Msg(0, "%s: readreg: too many arguments", rc_name);
1526
if ((s = ReadFile(args[1], &n)))
1528
struct plop *pp = plop_tab + (int)(unsigned char)ch;
1541
* with one argument we copy the copybuffer into a specified register
1542
* This could be done with RC_PASTE too, but is here to be consistent
1543
* with the zero argument call.
1545
copy_reg_fn(&ch, 0, NULL);
1550
i = fore ? fore->w_encoding : display ? display->d_encoding : 0;
1551
if (args[0] && args[1] && !strcmp(args[0], "-e"))
1553
i = FindEncoding(args[1]);
1556
Msg(0, "%s: register: unknown encoding", rc_name);
1565
Msg(0, "%s: register: illegal number of arguments.", rc_name);
1570
Msg(0, "%s: register: character, ^x, or (octal) \\032 expected.", rc_name);
1577
if (user->u_plop.buf != NULL)
1578
UserFreeCopyBuffer(user);
1579
if (args[1] && args[1][0])
1581
user->u_plop.buf = SaveStrn(args[1], argl[1]);
1582
user->u_plop.len = argl[1];
1584
user->u_plop.enc = i;
1591
struct plop *plp = plop_tab + (int)(unsigned char)ch;
1595
plp->buf = SaveStrn(args[1], argl[1]);
1603
if ((s = *args) == NULL)
1605
Input("Process register:", 1, INP_RAW, process_fn, NULL);
1610
Msg(0, "%s: process: character, ^x, or (octal) \\032 expected.", rc_name);
1614
process_fn(&ch, 0, NULL);
1621
if (strcmp(s, "-k"))
1623
Msg(0, "%s: stuff: invalid option %s", rc_name, s);
1627
for (i = T_CAPS; i < T_OCAPS; i++)
1628
if (strcmp(term[i].tcname, s) == 0)
1632
Msg(0, "%s: stuff: unknown key '%s'", rc_name, s);
1636
if (StuffKey(i - T_CAPS) == 0)
1639
s = display ? D_tcs[i].str : 0;
1654
Msg(0, "screen %s", version);
1659
timestring = SaveStr(*args);
1662
Msg(0, "%s", MakeWinMsg(timestring, fore, '%'));
1672
struct action *ktabp = ktab;
1673
if (argc == 2 && !strcmp(*args, "-c"))
1675
if ((ktabp = FindKtab(args[1], 0)) == 0)
1677
Msg(0, "Unknown command class '%s'", args[1]);
1681
if (D_ESCseen != ktab || ktabp != ktab)
1691
SwitchWindow(display && D_other ? D_other->w_number : NextWindow());
1694
if (user->u_Esc == -1)
1713
case RC_DEFBREAKTYPE:
1716
static char *types[] = { "TIOCSBRK", "TCSBRK", "tcsendbreak", NULL };
1717
extern int breaktype;
1721
if (ParseNum(act, &n))
1722
for (n = 0; n < (int)(sizeof(types)/sizeof(*types)); n++)
1724
for (i = 0; i < 4; i++)
1727
if (ch >= 'a' && ch <= 'z')
1729
if (ch != types[n][i] && (ch + ('a' - 'A')) != types[n][i])
1735
if (n < 0 || n >= (int)(sizeof(types)/sizeof(*types)))
1736
Msg(0, "%s invalid, chose one of %s, %s or %s", *args, types[0], types[1], types[2]);
1740
Msg(0, "breaktype set to (%d) %s", n, types[n]);
1744
Msg(0, "breaktype is (%d) %s", breaktype, types[breaktype]);
1750
if (*args && ParseNum(act, &n))
1752
SendBreak(fore, n, nr == RC_POW_BREAK);
1766
if (*args && !strcmp(*args, "-w"))
1768
else if (*args && !strcmp(*args, "-d"))
1772
if (what == 0 && flayer && !display)
1778
Msg(0, "%s: %s: window required", rc_name, comms[nr].name);
1781
w = flayer->l_width;
1782
h = flayer->l_height;
1788
Msg(0, "%s: %s: display required", rc_name, comms[nr].name);
1794
if (*args && args[0][0] == '-')
1796
Msg(0, "%s: %s: unknown option %s", rc_name, comms[nr].name, *args);
1799
if (nr == RC_HEIGHT)
1807
else if (h == H1height)
1809
else if (h > (H0height + H1height) / 2)
1827
else if (w == Z1width)
1829
else if (w > (Z0width + Z1width) / 2)
1841
if (*args && args[1] && args[2])
1843
Msg(0, "%s: %s: too many arguments", rc_name, comms[nr].name);
1848
Msg(0, "Illegal width");
1853
Msg(0, "Illegal height");
1858
if (flayer->l_width == w && flayer->l_height == h)
1860
ResizeLayer(flayer, w, h, (struct display *)0);
1863
if (D_width == w && D_height == h)
1867
ChangeScreenSize(w, h, 1);
1871
if (ResizeDisplay(w, h) == 0)
1873
Activate(D_fore ? D_fore->w_norefresh : 0);
1875
ResizeLayer(D_forecv->c_layer, D_forecv->c_xe - D_forecv->c_xs + 1, D_forecv->c_ye - D_forecv->c_ys + 1, 0);
1879
Msg(0, "Your termcap does not specify how to change the terminal's width to %d.", w);
1880
else if (w == D_width)
1881
Msg(0, "Your termcap does not specify how to change the terminal's height to %d.", h);
1883
Msg(0, "Your termcap does not specify how to change the terminal's resolution to %dx%d.", w, h);
1891
ChangeAKA(fore, *args, strlen(*args));
1894
Input(":", 100, INP_COOKED, Colonfin, NULL);
1895
if (*args && **args)
1903
if (D_status_lastmsg)
1904
Msg(0, "%s", D_status_lastmsg);
1907
DoScreen("key", args);
1910
if (ParseSwitch(act, &fore->w_wrap) == 0 && msgok)
1911
Msg(0, "%cwrap", fore->w_wrap ? '+' : '-');
1916
if (args[0][0] == 'a')
1918
fore->w_flow = (fore->w_flow & FLOW_AUTO) ? FLOW_AUTOFLAG |FLOW_AUTO|FLOW_NOW : FLOW_AUTOFLAG;
1922
if (ParseOnOff(act, &n))
1924
fore->w_flow = (fore->w_flow & FLOW_AUTO) | n;
1929
if (fore->w_flow & FLOW_AUTOFLAG)
1930
fore->w_flow = (fore->w_flow & FLOW_AUTO) | FLOW_NOW;
1931
else if (fore->w_flow & FLOW_NOW)
1932
fore->w_flow &= ~FLOW_NOW;
1934
fore->w_flow = fore->w_flow ? FLOW_AUTOFLAG|FLOW_AUTO|FLOW_NOW : FLOW_AUTOFLAG;
1936
SetFlow(fore->w_flow & FLOW_NOW);
1938
Msg(0, "%cflow%s", (fore->w_flow & FLOW_NOW) ? '+' : '-',
1939
(fore->w_flow & FLOW_AUTOFLAG) ? "(auto)" : "");
1942
case RC_DEFWRITELOCK:
1943
if (args[0][0] == 'a')
1944
nwin_default.wlock = WLOCK_AUTO;
1947
if (ParseOnOff(act, &n))
1949
nwin_default.wlock = n ? WLOCK_ON : WLOCK_OFF;
1955
if (args[0][0] == 'a')
1957
fore->w_wlock = WLOCK_AUTO;
1961
if (ParseOnOff(act, &n))
1963
fore->w_wlock = n ? WLOCK_ON : WLOCK_OFF;
1966
* user may have permission to change the writelock setting,
1967
* but he may never aquire the lock himself without write permission
1969
if (!AclCheckPermWin(D_user, ACL_WRITE, fore))
1970
fore->w_wlockuser = D_user;
1972
Msg(0, "writelock %s", (fore->w_wlock == WLOCK_AUTO) ? "auto" :
1973
((fore->w_wlock == WLOCK_OFF) ? "off" : "on"));
1977
ResetAnsiState(fore);
1978
WriteString(fore, "\033[H\033[J", 6);
1981
ResetAnsiState(fore);
1983
if (fore->w_zdisplay)
1984
zmodem_abort(fore, fore->w_zdisplay);
1986
WriteString(fore, "\033c", 2);
1989
n = fore->w_monitor != MON_OFF;
1990
if (ParseSwitch(act, &n))
1995
if (display) /* we tell only this user */
1996
ACLBYTE(fore->w_mon_notify, D_user->u_id) |= ACLBIT(D_user->u_id);
1998
for (i = 0; i < maxusercount; i++)
1999
ACLBYTE(fore->w_mon_notify, i) |= ACLBIT(i);
2001
if (fore->w_monitor == MON_OFF)
2002
fore->w_monitor = MON_ON;
2003
Msg(0, "Window %d (%s) is now being monitored for all activity.", fore->w_number, fore->w_title);
2008
if (display) /* we remove only this user */
2009
ACLBYTE(fore->w_mon_notify, D_user->u_id)
2010
&= ~ACLBIT(D_user->u_id);
2012
for (i = 0; i < maxusercount; i++)
2013
ACLBYTE(fore->w_mon_notify, i) &= ~ACLBIT(i);
2014
for (i = maxusercount - 1; i >= 0; i--)
2015
if (ACLBYTE(fore->w_mon_notify, i))
2019
fore->w_monitor = MON_OFF;
2020
Msg(0, "Window %d (%s) is no longer being monitored for activity.", fore->w_number, fore->w_title);
2030
display_wlist(0, WLIST_NUM);
2031
else if (!strcmp(*args, "-m") && !args[1])
2032
display_wlist(0, WLIST_MRU);
2033
else if (!strcmp(*args, "-b") && !args[1])
2034
display_wlist(1, WLIST_NUM);
2035
else if (!strcmp(*args, "-b") && !strcmp(args[1], "-m") && !args[2])
2036
display_wlist(1, WLIST_MRU);
2037
else if (!strcmp(*args, "-m") && !strcmp(args[1], "-b") && !args[2])
2038
display_wlist(1, WLIST_MRU);
2039
else if (!strcmp(*args, "string"))
2045
wliststr = SaveStr(args[1]);
2048
Msg(0, "windowlist string is '%s'", wliststr);
2050
else if (!strcmp(*args, "title"))
2056
wlisttit = SaveStr(args[1]);
2059
Msg(0, "windowlist title is '%s'", wlisttit);
2062
Msg(0, "usage: windowlist [-b] [string [string] | title [title]]");
2065
if (argc == 2 && !strcmp(*args, "-c"))
2067
struct action *ktabp;
2068
if ((ktabp = FindKtab(args[1], 0)) == 0)
2070
Msg(0, "Unknown command class '%s'", args[1]);
2073
display_help(args[1], ktabp);
2076
display_help((char *)0, ktab);
2079
display_copyright();
2083
if (flayer->l_layfn != &WinLf)
2085
Msg(0, "Must be on a window layer");
2092
static char *pasteargs[] = {".", 0};
2093
static int pasteargl[] = {1};
2095
if (flayer->l_layfn != &WinLf)
2097
Msg(0, "Must be on a window layer");
2100
if (GetHistory() == 0)
2102
if (user->u_plop.buf == NULL)
2110
char *ss, *dbuf, dch;
2117
* without args we prompt for one(!) register to be pasted in the window
2119
if ((s = *args) == NULL)
2121
Input("Paste from register:", 1, INP_RAW, ins_reg_fn, NULL);
2124
if (args[1] == 0 && !fore) /* no window? */
2127
* with two arguments we paste into a destination register
2128
* (no window needed here).
2130
if (args[1] && argl[1] != 1)
2132
Msg(0, "%s: paste destination: character, ^x, or (octal) \\032 expected.",
2138
enc = fore->w_encoding;
2142
* measure length of needed buffer
2144
for (ss = s = *args; (ch = *ss); ss++)
2150
enc = user->u_plop.enc;
2151
if (enc != user->u_plop.enc)
2152
l += RecodeBuf((unsigned char *)user->u_plop.buf, user->u_plop.len, user->u_plop.enc, enc, (unsigned char *)0);
2155
l += user->u_plop.len;
2161
enc = plop_tab[(int)(unsigned char)ch].enc;
2162
if (enc != plop_tab[(int)(unsigned char)ch].enc)
2163
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);
2166
l += plop_tab[(int)(unsigned char)ch].len;
2171
Msg(0, "empty buffer");
2176
* if there is only one source and the destination is a window, then
2177
* pass a pointer rather than duplicating the buffer.
2179
if (s[1] == 0 && args[1] == 0)
2181
if (enc == (*s == '.' ? user->u_plop.enc : plop_tab[(int)(unsigned char)*s].enc))
2184
MakePaster(&fore->w_paster, *s == '.' ? user->u_plop.buf : plop_tab[(int)(unsigned char)*s].buf, l, 0);
2188
* if no shortcut, we construct a buffer
2190
if ((dbuf = (char *)malloc(l)) == 0)
2197
* concatenate all sources into our own buffer, copy buffer is
2198
* special and is skipped if no display exists.
2200
for (ss = s; (ch = *ss); ss++)
2202
struct plop *pp = (ch == '.' ? &user->u_plop : &plop_tab[(int)(unsigned char)ch]);
2206
l += RecodeBuf((unsigned char *)pp->buf, pp->len, pp->enc, enc, (unsigned char *)dbuf + l);
2210
bcopy(pp->buf, dbuf + l, pp->len);
2214
* when called with one argument we paste our buffer into the window
2218
MakePaster(&fore->w_paster, dbuf, l, 1);
2223
* we have two arguments, the second is already in dch.
2224
* use this as destination rather than the window.
2229
if (user->u_plop.buf != NULL)
2230
UserFreeCopyBuffer(user);
2231
user->u_plop.buf = dbuf;
2232
user->u_plop.len = l;
2234
user->u_plop.enc = enc;
2239
struct plop *pp = plop_tab + (int)(unsigned char)dch;
2252
if (!user->u_plop.buf)
2254
Msg(0, "empty buffer");
2259
struct plop oldplop;
2261
oldplop = user->u_plop;
2262
if (args[0] && args[1] && !strcmp(args[0], "-e"))
2267
enc = FindEncoding(args[1]);
2270
Msg(0, "%s: writebuf: unknown encoding", rc_name);
2273
if (enc != oldplop.enc)
2275
l = RecodeBuf((unsigned char *)oldplop.buf, oldplop.len, oldplop.enc, enc, (unsigned char *)0);
2276
newbuf = malloc(l + 1);
2282
user->u_plop.len = RecodeBuf((unsigned char *)oldplop.buf, oldplop.len, oldplop.enc, enc, (unsigned char *)newbuf);
2283
user->u_plop.buf = newbuf;
2284
user->u_plop.enc = enc;
2289
if (args[0] && args[1])
2290
Msg(0, "%s: writebuf: too many arguments", rc_name);
2292
WriteFile(user, args[0], DUMP_EXCHANGE);
2294
if (user->u_plop.buf != oldplop.buf)
2295
free(user->u_plop.buf);
2296
user->u_plop = oldplop;
2302
i = fore ? fore->w_encoding : display ? display->d_encoding : 0;
2303
if (args[0] && args[1] && !strcmp(args[0], "-e"))
2305
i = FindEncoding(args[1]);
2308
Msg(0, "%s: readbuf: unknown encoding", rc_name);
2314
if (args[0] && args[1])
2316
Msg(0, "%s: readbuf: too many arguments", rc_name);
2319
if ((s = ReadFile(args[0] ? args[0] : BufferFile, &n)))
2321
if (user->u_plop.buf)
2322
UserFreeCopyBuffer(user);
2323
user->u_plop.len = n;
2324
user->u_plop.buf = s;
2326
user->u_plop.enc = i;
2334
(void)ParseSwitch(act, &search_ic);
2336
Msg(0, "Will %signore case in searches", search_ic ? "" : "not ");
2338
#endif /* COPY_PASTE */
2341
SetEscape(user, -1, -1);
2342
else if (*argl == 2)
2343
SetEscape(user, (int)(unsigned char)args[0][0], (int)(unsigned char)args[0][1]);
2346
Msg(0, "%s: two characters required after escape.", rc_name);
2349
/* Change defescape if master user. This is because we only
2352
if (display && user != users)
2357
SetEscape(NULL, -1, -1);
2358
else if (*argl == 2)
2359
SetEscape(NULL, (int)(unsigned char)args[0][0], (int)(unsigned char)args[0][1]);
2362
Msg(0, "%s: two characters required after defescape.", rc_name);
2370
s = *args ? *args : home;
2372
Msg(errno, "%s", s);
2376
if (ParseSaveStr(act, &ShellProg) == 0)
2377
ShellArgs[0] = ShellProg;
2379
case RC_HARDCOPYDIR:
2381
(void)ParseSaveStr(act, &hardcopydir);
2383
Msg(0, "hardcopydir is %s\n", hardcopydir && *hardcopydir ? hardcopydir : "<cwd>");
2388
if (args[1] && !(strcmp(*args, "flush")))
2390
log_flush = atoi(args[1]);
2392
Msg(0, "log flush timeout set to %ds\n", log_flush);
2395
if (ParseSaveStr(act, &screenlogfile) || !msgok)
2398
Msg(0, "logfile is '%s'", screenlogfile);
2401
if (!*args || !strcmp(*args, "on") || !strcmp(*args, "off"))
2403
if (ParseSwitch(act, &logtstamp_on) == 0 && msgok)
2404
Msg(0, "timestamps turned %s", logtstamp_on ? "on" : "off");
2406
else if (!strcmp(*args, "string"))
2410
if (logtstamp_string)
2411
free(logtstamp_string);
2412
logtstamp_string = SaveStr(args[1]);
2415
Msg(0, "logfile timestamp is '%s'", logtstamp_string);
2417
else if (!strcmp(*args, "after"))
2421
logtstamp_after = atoi(args[1]);
2425
Msg(0, "timestamp printed after %ds\n", logtstamp_after);
2428
Msg(0, "usage: logtstamp [after [n]|string [str]|on|off]");
2431
(void)ParseSaveStr(act, &nwin_default.aka);
2434
case RC_TERMCAPINFO:
2436
if (!rc_name || !*rc_name)
2437
Msg(0, "Sorry, too late now. Place that in your .screenrc file.");
2440
break; /* Already handled */
2443
if (ParseSaveStr(act, &s))
2445
if (strlen(s) >= 20)
2447
Msg(0, "%s: term: argument too long ( < 20)", rc_name);
2451
strcpy(screenterm, s);
2453
debug1("screenterm set to %s\n", screenterm);
2454
MakeTermcap((display == 0));
2455
debug("new termcap made\n");
2458
if (!msgok && (!rc_name || strcmp(rc_name, "-X")))
2461
* user typed ^A:echo... well, echo isn't FinishRc's job,
2462
* but as he wanted to test us, we show good will
2464
if (argc > 1 && !strcmp(*args, "-n"))
2470
if (argc > 1 && !strcmp(*args, "-p"))
2476
s = MakeWinMsg(s, fore, '%');
2481
Msg(0, "%s: 'echo [-n] [-p] \"string\"' expected.", rc_name);
2488
AddXChars(buf, sizeof(buf), BellString);
2489
Msg(0, "bell_msg is '%s'", buf);
2492
(void)ParseSaveStr(act, &BellString);
2497
BufferFile = SaveStr(DEFAULT_BUFFERFILE);
2498
else if (ParseSaveStr(act, &BufferFile))
2501
Msg(0, "Bufferfile is now '%s'", BufferFile);
2505
(void)ParseSaveStr(act, &ActivityString);
2507
#if defined(DETACH) && defined(POW_DETACH)
2508
case RC_POW_DETACH_MSG:
2512
AddXChars(buf, sizeof(buf), PowDetachString);
2513
Msg(0, "pow_detach_msg is '%s'", buf);
2516
(void)ParseSaveStr(act, &PowDetachString);
2519
#if defined(UTMPOK) && defined(LOGOUTOK)
2521
n = fore->w_slot != (slot_t)-1;
2522
if (*args && !strcmp(*args, "always"))
2529
if (*args && !strcmp(*args, "attached"))
2536
if (ParseSwitch(act, &n) == 0)
2540
if (!strcmp(*args, "always"))
2541
nwin_default.lflag |= 2;
2542
else if (!strcmp(*args, "attached"))
2543
nwin_default.lflag &= ~2;
2545
(void)ParseOnOff(act, &nwin_default.lflag);
2549
if (args[0] && args[1] && args[1][0] == 'i')
2552
for (display = displays; display; display = display->d_next)
2556
#if defined(TERMIO) || defined(POSIX)
2557
D_NewMode.tio.c_cc[VINTR] = D_OldMode.tio.c_cc[VINTR];
2558
D_NewMode.tio.c_lflag |= ISIG;
2559
#else /* TERMIO || POSIX */
2560
D_NewMode.m_tchars.t_intrc = D_OldMode.m_tchars.t_intrc;
2561
#endif /* TERMIO || POSIX */
2562
SetTTY(D_userfd, &D_NewMode);
2565
if (args[0] && args[0][0] == 'a')
2566
nwin_default.flowflag = FLOW_AUTOFLAG;
2568
(void)ParseOnOff(act, &nwin_default.flowflag);
2571
(void)ParseOnOff(act, &nwin_default.wrap);
2574
(void)ParseOnOff(act, &nwin_default.c1);
2578
(void)ParseOnOff(act, &nwin_default.bce);
2582
(void)ParseOnOff(act, &nwin_default.gr);
2585
if (ParseOnOff(act, &n) == 0)
2586
nwin_default.monitor = (n == 0) ? MON_OFF : MON_ON;
2589
if (ParseOnOff(act, &n) == 0)
2590
nwin_default.silence = (n == 0) ? SILENCE_OFF : SILENCE_ON;
2594
Msg(0, "W%s echo command when creating windows.",
2595
VerboseCreate ? "ill" : "on't");
2596
else if (ParseOnOff(act, &n) == 0)
2602
Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
2605
if (args[0] && strcmp(args[0], "on") && strcmp(args[0], "off"))
2607
struct display *olddisplay = display;
2608
int old_use, new_use = -1;
2611
if (!strncmp(s, "always", 6))
2613
if (!strcmp(s, "lastline"))
2614
new_use = HSTATUS_LASTLINE;
2615
else if (!strcmp(s, "ignore"))
2616
new_use = HSTATUS_IGNORE;
2617
else if (!strcmp(s, "message"))
2618
new_use = HSTATUS_MESSAGE;
2619
else if (!strcmp(args[0], "string"))
2624
AddXChars(buf, sizeof(buf), hstatusstring);
2625
Msg(0, "hardstatus string is '%s'", buf);
2631
Msg(0, "%s: usage: hardstatus [always]lastline|ignore|message|string [string]", rc_name);
2636
hardstatusemu = new_use | (s == args[0] ? 0 : HSTATUS_ALWAYS);
2637
for (display = displays; display; display = display->d_next)
2640
new_use = hardstatusemu & ~HSTATUS_ALWAYS;
2641
if (D_HS && s == args[0])
2642
new_use = HSTATUS_HS;
2643
ShowHStatus((char *)0);
2644
old_use = D_has_hstatus;
2645
D_has_hstatus = new_use;
2646
if ((new_use == HSTATUS_LASTLINE && old_use != HSTATUS_LASTLINE) || (new_use != HSTATUS_LASTLINE && old_use == HSTATUS_LASTLINE))
2647
ChangeScreenSize(D_width, D_height, 1);
2654
free(hstatusstring);
2655
hstatusstring = SaveStr(args[1]);
2656
for (display = displays; display; display = display->d_next)
2659
display = olddisplay;
2662
(void)ParseSwitch(act, &use_hardstatus);
2664
Msg(0, "messages displayed on %s", use_hardstatus ? "hardstatus line" : "window");
2667
if (strcmp(args[0], "always") == 0 || strcmp(args[0], "splitonly") == 0)
2669
struct display *olddisplay = display;
2671
captionalways = args[0][0] == 'a';
2672
for (display = displays; display; display = display->d_next)
2673
ChangeScreenSize(D_width, D_height, 1);
2674
display = olddisplay;
2676
else if (strcmp(args[0], "string") == 0)
2681
AddXChars(buf, sizeof(buf), captionstring);
2682
Msg(0, "caption string is '%s'", buf);
2688
Msg(0, "%s: usage: caption always|splitonly|string <string>", rc_name);
2694
free(captionstring);
2695
captionstring = SaveStr(args[1]);
2696
RedisplayDisplays(0);
2699
n = (console_window != 0);
2700
if (ParseSwitch(act, &n))
2702
if (TtyGrabConsole(fore->w_ptyfd, n, rc_name))
2705
Msg(0, "%s: releasing console %s", rc_name, HostName);
2706
else if (console_window)
2707
Msg(0, "%s: stealing console %s from window %d (%s)", rc_name,
2708
HostName, console_window->w_number, console_window->w_title);
2710
Msg(0, "%s: grabbing console %s", rc_name, HostName);
2711
console_window = n ? fore : 0;
2714
if (ParseOnOff(act, &all_norefresh))
2716
if (!all_norefresh && fore)
2719
Msg(0, all_norefresh ? "No refresh on window change!\n" :
2720
"Window specific refresh\n");
2723
(void)ParseSwitch(act, &n);
2724
fore->w_norefresh = n;
2727
if (ParseSwitch(act, &visual_bell) || !msgok)
2729
if (visual_bell == 0)
2730
Msg(0, "switched to audible bell.");
2732
Msg(0, "switched to visual bell.");
2735
if (ParseNum1000(act, &VBellWait) == 0 && msgok)
2736
Msg(0, "vbellwait set to %.10g seconds", VBellWait/1000.);
2739
if (ParseNum1000(act, &MsgWait) == 0 && msgok)
2740
Msg(0, "msgwait set to %.10g seconds", MsgWait/1000.);
2743
if (ParseNum1000(act, &MsgMinWait) == 0 && msgok)
2744
Msg(0, "msgminwait set to %.10g seconds", MsgMinWait/1000.);
2746
case RC_SILENCEWAIT:
2747
if (ParseNum(act, &SilenceWait))
2749
if (SilenceWait < 1)
2751
for (p = windows; p; p = p->w_next)
2752
p->w_silencewait = SilenceWait;
2754
Msg(0, "silencewait set to %d seconds", SilenceWait);
2758
Msg(0, "This is window %d (%s).\n", fore->w_number, fore->w_title);
2761
int old = fore->w_number;
2763
if (ParseNum(act, &n) || n >= maxwin)
2772
/* exchange the acls for these windows. */
2776
/* exchange the utmp-slots for these windows */
2777
if ((fore->w_slot != (slot_t) -1) && (fore->w_slot != (slot_t) 0))
2782
if (p && (p->w_slot != (slot_t) -1) && (p->w_slot != (slot_t) 0))
2784
/* XXX: first display wins? */
2785
display = fore->w_layer.l_cvlist ? fore->w_layer.l_cvlist->c_display : 0;
2791
WindowChanged(fore, 'n');
2792
WindowChanged((struct win *)0, 'w');
2793
WindowChanged((struct win *)0, 'W');
2794
WindowChanged((struct win *)0, 0);
2798
n = fore->w_silence != 0;
2799
i = fore->w_silencewait;
2800
if (args[0] && (args[0][0] == '-' || (args[0][0] >= '0' && args[0][0] <= '9')))
2802
if (ParseNum(act, &i))
2806
else if (ParseSwitch(act, &n))
2811
if (display) /* we tell only this user */
2812
ACLBYTE(fore->w_lio_notify, D_user->u_id) |= ACLBIT(D_user->u_id);
2814
for (n = 0; n < maxusercount; n++)
2815
ACLBYTE(fore->w_lio_notify, n) |= ACLBIT(n);
2817
fore->w_silencewait = i;
2818
fore->w_silence = SILENCE_ON;
2819
SetTimeout(&fore->w_silenceev, fore->w_silencewait * 1000);
2820
evenq(&fore->w_silenceev);
2824
Msg(0, "The window is now being monitored for %d sec. silence.", fore->w_silencewait);
2829
if (display) /* we remove only this user */
2830
ACLBYTE(fore->w_lio_notify, D_user->u_id)
2831
&= ~ACLBIT(D_user->u_id);
2833
for (n = 0; n < maxusercount; n++)
2834
ACLBYTE(fore->w_lio_notify, n) &= ~ACLBIT(n);
2835
for (i = maxusercount - 1; i >= 0; i--)
2836
if (ACLBYTE(fore->w_lio_notify, i))
2841
fore->w_silence = SILENCE_OFF;
2842
evdeq(&fore->w_silenceev);
2846
Msg(0, "The window is no longer being monitored for silence.");
2850
case RC_DEFSCROLLBACK:
2851
(void)ParseNum(act, &nwin_default.histheight);
2854
(void)ParseNum(act, &n);
2855
ChangeWindowSize(fore, fore->w_width, fore->w_height, n);
2857
Msg(0, "scrollback set to %d", fore->w_histheight);
2860
case RC_SESSIONNAME:
2862
Msg(0, "This session is named '%s'\n", SockName);
2865
char buf[MAXPATHLEN];
2868
if (ParseSaveStr(act, &s))
2870
if (!*s || strlen(s) + (SockName - SockPath) > MAXPATHLEN - 13 || index(s, '/'))
2872
Msg(0, "%s: bad session name '%s'\n", rc_name, s);
2876
strncpy(buf, SockPath, SockName - SockPath);
2877
sprintf(buf + (SockName - SockPath), "%d.%s", (int)getpid(), s);
2879
if ((access(buf, F_OK) == 0) || (errno != ENOENT))
2881
Msg(0, "%s: inappropriate path: '%s'.", rc_name, buf);
2884
if (rename(SockPath, buf))
2886
Msg(errno, "%s: failed to rename(%s, %s)", rc_name, SockPath, buf);
2889
debug2("rename(%s, %s) done\n", SockPath, buf);
2890
strcpy(SockPath, buf);
2895
if (!args[0] || !args[1])
2897
debug1("RC_SETENV arguments missing: %s\n", args[0] ? args[0] : "");
2898
InputSetenv(args[0]);
2902
xsetenv(args[0], args[1]);
2911
case RC_DEFSLOWPASTE:
2912
(void)ParseNum(act, &nwin_default.slow);
2916
Msg(0, fore->w_slowpaste ?
2917
"Slowpaste in window %d is %d milliseconds." :
2918
"Slowpaste in window %d is unset.",
2919
fore->w_number, fore->w_slowpaste);
2920
else if (ParseNum(act, &fore->w_slowpaste) == 0 && msgok)
2921
Msg(0, fore->w_slowpaste ?
2922
"Slowpaste in window %d set to %d milliseconds." :
2923
"Slowpaste in window %d now unset.",
2924
fore->w_number, fore->w_slowpaste);
2927
if (CompileKeys(*args, *argl, mark_key_tab))
2929
Msg(0, "%s: markkeys: syntax error.", rc_name);
2932
debug1("markkeys %s\n", *args);
2936
if (ParseSwitch(act, &pastefont) == 0 && msgok)
2937
Msg(0, "Will %spaste font settings", pastefont ? "" : "not ");
2941
(void)ParseSwitch(act, &join_with_cr);
2943
case RC_COMPACTHIST:
2944
if (ParseSwitch(act, &compacthist) == 0 && msgok)
2945
Msg(0, "%scompacting history lines", compacthist ? "" : "not ");
2950
(void)ParseOnOff(act, &nethackflag);
2953
case RC_HARDCOPY_APPEND:
2954
(void)ParseOnOff(act, &hardcopy_append);
2960
AddXChars(buf, sizeof(buf), VisualBellString);
2961
Msg(0, "vbell_msg is '%s'", buf);
2964
(void)ParseSaveStr(act, &VisualBellString);
2965
debug1(" new vbellstr '%s'\n", VisualBellString);
2968
if (ParseBase(act, *args, &n, 8, "octal"))
2970
if (n < 0 || n > 0777)
2972
Msg(0, "%s: mode: Invalid tty mode %o", rc_name, n);
2977
Msg(0, "Ttymode set to %03o", TtyMode);
2980
(void)ParseOnOff(act, &auto_detach);
2982
case RC_STARTUP_MESSAGE:
2983
(void)ParseOnOff(act, &default_startup);
2989
n = (*user->u_password) ? 1 : 0;
2990
if (user->u_password != NullStr) free((char *)user->u_password);
2991
user->u_password = SaveStr(*args);
2992
if (!strcmp(user->u_password, "none"))
2995
Msg(0, "Password checking disabled");
2996
free(user->u_password);
2997
user->u_password = NullStr;
3004
Msg(0, "%s: password: window required", rc_name);
3007
Input("New screen password:", 100, INP_NOECHO, pass1, display ? (char *)D_user : (char *)users);
3010
#endif /* PASSWORD */
3013
struct action *ktabp = ktab;
3015
if (argc > 2 && !strcmp(*args, "-c"))
3017
ktabp = FindKtab(args[1], 1);
3025
Msg(0, "%s: bind: character, ^x, or (octal) \\032 expected.", rc_name);
3028
n = (unsigned char)args[0][0];
3031
if ((i = FindCommnr(args[1])) == RC_ILLEGAL)
3033
Msg(0, "%s: bind: unknown command '%s'", rc_name, args[1]);
3036
if (CheckArgNum(i, args + 2) < 0)
3038
ClearAction(&ktabp[n]);
3039
SaveAction(ktabp + n, i, args + 2, argl + 2);
3042
ClearAction(&ktabp[n]);
3048
struct action *newact;
3049
int newnr, fl = 0, kf = 0, af = 0, df = 0, mf = 0;
3050
struct display *odisp = display;
3052
struct kmap_ext *kme;
3054
for (; *args && **args == '-'; args++, argl++)
3056
if (strcmp(*args, "-t") == 0)
3057
fl = KMAP_NOTIMEOUT;
3058
else if (strcmp(*args, "-k") == 0)
3060
else if (strcmp(*args, "-a") == 0)
3062
else if (strcmp(*args, "-d") == 0)
3064
else if (strcmp(*args, "-m") == 0)
3066
else if (strcmp(*args, "--") == 0)
3074
Msg(0, "%s: bindkey: invalid option %s", rc_name, *args);
3080
Msg(0, "%s: bindkey: -d does not work with -m", rc_name);
3086
display_bindkey("Edit mode", mmtab);
3088
display_bindkey("Default", dmtab);
3090
display_bindkey("User", umtab);
3097
Msg(0, "%s: bindkey: -a only works with -k", rc_name);
3102
Msg(0, "%s: bindkey: empty string makes no sense", rc_name);
3105
for (i = 0, kme = kmap_exts; i < kmap_extn; i++, kme++)
3112
if (*argl == (kme->fl & ~KMAP_NOTIMEOUT) && bcmp(kme->str, *args, *argl) == 0)
3118
Msg(0, "%s: bindkey: keybinding not found", rc_name);
3122
kmap_exts = (struct kmap_ext *)xrealloc((char *)kmap_exts, kmap_extn * sizeof(*kmap_exts));
3123
kme = kmap_exts + i;
3124
bzero((char *)kme, 8 * sizeof(*kmap_exts));
3125
for (; i < kmap_extn; i++, kme++)
3128
kme->dm.nr = kme->mm.nr = kme->um.nr = RC_ILLEGAL;
3129
kme->dm.args = kme->mm.args = kme->um.args = noargs;
3134
if (df == 0 && kme->dm.nr != RC_ILLEGAL)
3136
if (mf == 0 && kme->mm.nr != RC_ILLEGAL)
3138
if ((df || mf) && kme->um.nr != RC_ILLEGAL)
3140
i += KMAP_KEYS + KMAP_AKEYS;
3141
newact = df ? &kme->dm : mf ? &kme->mm : &kme->um;
3145
for (i = T_CAPS; i < T_OCAPS; i++)
3146
if (strcmp(term[i].tcname, *args) == 0)
3150
Msg(0, "%s: bindkey: unknown key '%s'", rc_name, *args);
3153
if (af && i >= T_CURSOR && i < T_OCAPS)
3154
i -= T_CURSOR - KMAP_KEYS;
3157
newact = df ? &dmtab[i] : mf ? &mmtab[i] : &umtab[i];
3161
if ((newnr = FindCommnr(args[1])) == RC_ILLEGAL)
3163
Msg(0, "%s: bindkey: unknown command '%s'", rc_name, args[1]);
3166
if (CheckArgNum(newnr, args + 2) < 0)
3168
ClearAction(newact);
3169
SaveAction(newact, newnr, args + 2, argl + 2);
3170
if (kf == 0 && args[1])
3174
kme->str = SaveStrn(*args, *argl);
3175
kme->fl = fl | *argl;
3179
ClearAction(newact);
3180
for (display = displays; display; display = display->d_next)
3181
remap(i, args[1] ? 1 : 0);
3182
if (kf == 0 && !args[1])
3184
if (!used && kme->str)
3197
if (ParseNum(act, &n))
3201
Msg(0, "%s: maptimeout: illegal time %d", rc_name, n);
3206
if (*args == 0 || msgok)
3207
Msg(0, "maptimeout is %dms", maptimeout);
3221
UsersAcl(NULL, argc, args);
3224
if (UserDel(args[0], NULL))
3227
Msg(0, "%s removed from acl database", args[0]);
3231
* modify a user to gain or lose rights granted to a group.
3232
* This group is actually a normal user whose rights were defined
3233
* with chacl in the usual way.
3237
if (strcmp(args[1], "none")) /* link a user to another user */
3239
if (AclLinkUser(args[0], args[1]))
3242
Msg(0, "User %s joined acl-group %s", args[0], args[1]);
3244
else /* remove all groups from user */
3247
struct aclusergroup *g;
3249
if (!(u = *FindUserPtr(args[0])))
3251
while ((g = u->u_group))
3253
u->u_group = g->next;
3258
else /* show all groups of user */
3260
char buf[256], *p = buf;
3263
struct aclusergroup *g;
3265
if (!(u = *FindUserPtr(args[0])))
3268
Msg(0, "User %s does not exist.", args[0]);
3275
sprintf(p, "%s ", g->u->u_name);
3283
Msg(0, "%s's group%s: %s.", args[0], (ngroups == 1) ? "" : "s",
3284
(ngroups == 0) ? "none" : buf);
3289
while ((s = *args++))
3293
if (AclUmask(display ? D_user : users, s, &err))
3294
Msg(0, "umask: %s\n", err);
3298
if (ParseOnOff(act, &n))
3303
Msg(0, "Multiuser mode %s", multi ? "enabled" : "disabled");
3305
#endif /* MULTIUSER */
3313
i = D_nonblock >= 0;
3314
if (*args && ((args[0][0] >= '0' && args[0][0] <= '9') || args[0][0] == '.'))
3316
if (ParseNum1000(act, &i))
3319
else if (!ParseSwitch(act, &i))
3320
i = i == 0 ? -1 : 1000;
3323
if (msgok && i == -1)
3324
Msg(0, "display set to blocking mode");
3325
else if (msgok && i == 0)
3326
Msg(0, "display set to nonblocking mode, no timeout");
3328
Msg(0, "display set to nonblocking mode, %.10gs timeout", i/1000.);
3330
if (D_nonblock <= 0)
3331
evdeq(&D_blockedev);
3333
case RC_DEFNONBLOCK:
3334
if (*args && ((args[0][0] >= '0' && args[0][0] <= '9') || args[0][0] == '.'))
3336
if (ParseNum1000(act, &defnonblock))
3339
else if (!ParseOnOff(act, &defnonblock))
3340
defnonblock = defnonblock == 0 ? -1 : 1000;
3343
if (display && *rc_name)
3345
D_nonblock = defnonblock;
3346
if (D_nonblock <= 0)
3347
evdeq(&D_blockedev);
3353
if (fore->w_gr == 2)
3356
if (ParseSwitch(act, &fore->w_gr) == 0 && msgok)
3357
Msg(0, "Will %suse GR", fore->w_gr ? "" : "not ");
3359
if (fore->w_gr == 0 && fore->w_FontE)
3364
if (ParseSwitch(act, &fore->w_c1) == 0 && msgok)
3365
Msg(0, "Will %suse C1", fore->w_c1 ? "" : "not ");
3369
if (ParseSwitch(act, &fore->w_bce) == 0 && msgok)
3370
Msg(0, "Will %serase with background color", fore->w_bce ? "" : "not ");
3377
if (*args && !strcmp(args[0], "-d"))
3380
Msg(0, "encodings directory is %s", screenencodings ? screenencodings : "<unset>");
3383
free(screenencodings);
3384
screenencodings = SaveStr(args[1]);
3388
if (*args && !strcmp(args[0], "-l"))
3391
Msg(0, "encoding: -l: argument required");
3392
else if (LoadFontTranslation(-1, args[1]))
3393
Msg(0, "encoding: could not load utf8 encoding file");
3395
Msg(0, "encoding: utf8 encoding file loaded");
3399
if (*args && (!strcmp(args[0], "-l") || !strcmp(args[0], "-d")))
3402
Msg(0, "encoding: screen is not compiled for UTF-8.");
3406
for (i = 0; i < 2; i++)
3410
if (!strcmp(args[i], "."))
3412
n = FindEncoding(args[i]);
3415
Msg(0, "encoding: unknown encoding '%s'", args[i]);
3420
WinSwitchEncoding(fore, n);
3421
ResetCharsets(fore);
3423
else if (i && display)
3428
case RC_DEFENCODING:
3429
n = FindEncoding(*args);
3432
Msg(0, "defencoding: unknown encoding '%s'", *args);
3435
nwin_default.encoding = n;
3441
n = nwin_default.encoding == UTF8;
3442
if (ParseSwitch(act, &n) == 0)
3444
nwin_default.encoding = n ? UTF8 : 0;
3446
Msg(0, "Will %suse UTF-8 encoding for new windows", n ? "" : "not ");
3450
for (i = 0; i < 2; i++)
3452
if (i && args[i] == 0)
3455
n = fore->w_encoding != UTF8;
3456
else if (strcmp(args[i], "off") == 0)
3458
else if (strcmp(args[i], "on") == 0)
3462
Msg(0, "utf8: illegal argument (%s)", args[i]);
3467
WinSwitchEncoding(fore, n ? UTF8 : 0);
3469
Msg(0, "Will %suse UTF-8 encoding", n ? "" : "not ");
3472
D_encoding = n ? UTF8 : 0;
3486
printcmd = SaveStr(*args);
3488
if (*args == 0 || msgok)
3491
Msg(0, "using '%s' as print command", printcmd);
3493
Msg(0, "using termcap entries for printing");
3499
Input("Enter digraph: ", 10, INP_EVERY, digraph_fn, NULL);
3500
if (*args && **args)
3513
if (nwin_default.hstatus)
3514
AddXChars(buf, sizeof(buf), nwin_default.hstatus);
3515
Msg(0, "default hstatus is '%s'", buf);
3518
(void)ParseSaveStr(act, &nwin_default.hstatus);
3519
if (*nwin_default.hstatus == 0)
3521
free(nwin_default.hstatus);
3522
nwin_default.hstatus = 0;
3526
(void)ParseSaveStr(act, &fore->w_hstatus);
3527
if (*fore->w_hstatus == 0)
3529
free(fore->w_hstatus);
3530
fore->w_hstatus = 0;
3532
WindowChanged(fore, 'h');
3542
if (nwin_default.charset)
3543
AddXChars(buf, sizeof(buf), nwin_default.charset);
3544
Msg(0, "default charset is '%s'", buf);
3548
if (n == 0 || n > 6)
3550
Msg(0, "%s: %s: string has illegal size.", rc_name, comms[nr].name);
3554
((args[0][4] < '0' || args[0][4] > '3') && args[0][4] != '.') ||
3555
((args[0][5] < '0' || args[0][5] > '3') && args[0][5] && args[0][5] != '.')))
3557
Msg(0, "%s: %s: illegal mapping number.", rc_name, comms[nr].name);
3560
if (nr == RC_CHARSET)
3562
SetCharsets(fore, *args);
3565
if (nwin_default.charset)
3566
free(nwin_default.charset);
3567
nwin_default.charset = SaveStr(*args);
3573
if (*s >= '0' && *s <= '9')
3576
for (i = 0; i < 8; i++)
3577
if (*s == "dubrsBiI"[i])
3581
if (*s && s[1] && !s[2])
3583
if (*s == 'd' && s[1] == 'd')
3585
else if (*s == '.' && s[1] == 'd')
3587
else if (*s == 'd' && s[1] == '.')
3589
else if (*s != '.' || s[1] != '.')
3593
if (*s || i < 0 || i >= 8)
3595
Msg(0, "%s: attrcolor: unknown attribute '%s'.", rc_name, args[0]);
3600
n = ParseAttrColor(args[1], args[2], 1);
3603
attr2color[i][nr] = n;
3605
for (i = 0; i < 8; i++)
3606
if (attr2color[i][0] || attr2color[i][1] || attr2color[i][2] || attr2color[i][3])
3611
case RC_SORENDITION:
3615
i = ParseAttrColor(*args, args[1], 1);
3618
ApplyAttrColor(i, &mchar_so);
3619
debug2("--> %x %x\n", mchar_so.attr, mchar_so.color);
3623
Msg(0, "Standout attributes 0x%02x color 0x%02x", (unsigned char)mchar_so.attr, 0x99 ^ (unsigned char)mchar_so.color);
3625
Msg(0, "Standout attributes 0x%02x ", (unsigned char)mchar_so.attr);
3638
Msg(0, "%s:%s screen login", HostName, SockPath);
3639
InputSu(D_fore, &D_user, NULL);
3642
InputSu(D_fore, &D_user, args[0]);
3644
s = DoSu(&D_user, args[0], args[1], "\377");
3646
s = DoSu(&D_user, args[0], args[1], args[2]);
3650
#endif /* MULTIUSER */
3664
D_forecv->c_xoff = D_forecv->c_xs;
3665
D_forecv->c_yoff = D_forecv->c_ys;
3666
RethinkViewportOffsets(D_forecv);
3667
ResizeLayer(D_forecv->c_layer, D_forecv->c_xe - D_forecv->c_xs + 1, D_forecv->c_ye - D_forecv->c_ys + 1, 0);
3668
flayer = D_forecv->c_layer;
3672
if (!*args || !strcmp(*args, "down"))
3673
D_forecv = D_forecv->c_next ? D_forecv->c_next : D_cvlist;
3674
else if (!strcmp(*args, "up"))
3677
for (cv = D_cvlist; cv->c_next && cv->c_next != D_forecv; cv = cv->c_next)
3681
else if (!strcmp(*args, "top"))
3682
D_forecv = D_cvlist;
3683
else if (!strcmp(*args, "bottom"))
3686
for (cv = D_cvlist; cv->c_next; cv = cv->c_next)
3692
Msg(0, "%s: usage: focus [up|down|top|bottom]", rc_name);
3695
fore = D_fore = Layer2Window(D_forecv->c_layer);
3696
flayer = D_forecv->c_layer;
3698
if (D_xtermosc[2] || D_xtermosc[3])
3708
flayer = D_forecv->c_layer;
3709
CV_CALL(D_forecv, LayRestore();LaySetCursor());
3710
WindowChanged(0, 'F');
3714
ResizeRegions(*args);
3716
Input("resize # lines: ", 20, INP_COOKED, ResizeFin, (char*)0);
3719
(void)ParseSwitch(act, &separate_sids);
3722
for (; *args; args++)
3724
char *ss = SaveStr(*args);
3726
Colonfin(ss, strlen(ss), (char *)0);
3731
(void)ParseSwitch(act, &use_altscreen);
3733
Msg(0, "Will %sdo alternate screen switching", use_altscreen ? "" : "not ");
3736
if (ParseNum(act, &n))
3739
Msg(0, "illegal maxwin number specified");
3740
else if (n > maxwin)
3741
Msg(0, "may only decrease maxwin number");
3746
if (ParseBase(act, *args, &n, 10, "decimal"))
3749
setbacktick(n, 0, 0, (char **)0);
3755
Msg(0, "%s: usage: backtick num [lifespan tick cmd args...]", rc_name);
3758
if (ParseBase(act, args[1], &lifespan, 10, "decimal"))
3760
if (ParseBase(act, args[2], &tick, 10, "decimal"))
3762
setbacktick(n, lifespan, tick, SaveArgs(args + 3));
3764
WindowChanged(0, '`');
3770
RunBlanker(blankerprg);
3775
CursorVisibility(-1);
3783
for (pp = blankerprg; *pp; pp++)
3789
blankerprg = SaveArgs(args);
3795
struct display *olddisplay = display;
3796
if (!strcmp(*args, "off"))
3798
else if (args[0][0])
3799
idletimo = atoi(*args) * 1000;
3802
if ((i = FindCommnr(args[1])) == RC_ILLEGAL)
3804
Msg(0, "%s: idle: unknown command '%s'", rc_name, args[1]);
3807
if (CheckArgNum(i, args + 2) < 0)
3809
ClearAction(&idleaction);
3810
SaveAction(&idleaction, i, args + 2, argl + 2);
3812
for (display = displays; display; display = display->d_next)
3814
display = olddisplay;
3819
Msg(0, "idle timeout %ds, %s", idletimo / 1000, comms[idleaction.nr].name);
3826
/* key == -2: input from braille keybord, msgok always 0 */
3827
DoBrailleAction(act, key == -2 ? 0 : msgok);
3831
if (display != odisplay)
3833
for (display = displays; display; display = display->d_next)
3834
if (display == odisplay)
3840
DoCommand(argv, argl)
3846
if ((act.nr = FindCommnr(*argv)) == RC_ILLEGAL)
3848
Msg(0, "%s: unknown command '%s'", rc_name, *argv);
3851
act.args = argv + 1;
3852
act.argl = argl + 1;
3857
SaveAction(act, nr, args, argl)
3863
register int argc = 0;
3877
if ((pp = (char **)malloc((unsigned)(argc + 1) * sizeof(char **))) == 0)
3879
if ((lp = (int *)malloc((unsigned)(argc) * sizeof(int *))) == 0)
3886
*lp = argl ? *argl++ : (int)strlen(*args);
3887
*pp++ = SaveStrn(*args++, *lp++);
3896
register char **ap, **pp;
3897
register int argc = 0;
3901
if ((pp = ap = (char **)malloc((unsigned)(argc + 1) * sizeof(char **))) == 0)
3904
*pp++ = SaveStr(*args++);
3911
* buf is split into argument vector args.
3912
* leading whitespace is removed.
3913
* @!| abbreviations are expanded.
3914
* the end of buffer is recognized by '\0' or an un-escaped '#'.
3915
* " and ' are interpreted.
3920
Parse(buf, bufl, args, argl)
3924
register char *p = buf, **ap = args, *pp;
3925
register int delim, argc;
3928
debug2("Parse %d %s\n", bufl, buf);
3934
while (*p && (*p == ' ' || *p == '\t'))
3937
if (argc == 0 && *p == '!')
3946
if (*p == '\0' || *p == '#' || *p == '\n')
3949
for (delim = 0; delim < argc; delim++)
3950
debug1("-- %s\n", args[delim]);
3954
if (++argc >= MAXARGS)
3956
Msg(0, "%s: too many tokens.", rc_name);
3961
debug1("- new arg %s\n", p);
3966
else if (delim != '\'' && *p == '\\' && (p[1] == '\'' || p[1] == '"' || p[1] == '\\' || p[1] == '$' || p[1] == '#' || p[1] == '^' || (p[1] >= '0' && p[1] <= '7')))
3969
if (*p >= '0' && *p <= '7')
3972
if (p[1] >= '0' && p[1] <= '7')
3975
*pp = (*pp << 3) | (*p - '0');
3976
if (p[1] >= '0' && p[1] <= '7')
3979
*pp = (*pp << 3) | (*p - '0');
3987
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] == '_'))
3990
char *ps, *pe, op, *v, xbuf[11];
3994
debug1("- var %s\n", ps);
3998
if (*ps == '{' && *p == '}')
4000
if (*ps == ':' && *p == ':')
4002
if (*ps != '{' && *ps != ':' && (*p < 'a' || *p > 'z') && (*p < 'A' || *p > 'Z') && (*p < '0' || *p > '9') && *p != '_')
4007
if (*ps == '{' || *ps == ':')
4011
Msg(0, "%s: bad variable name.", rc_name);
4018
debug1("- var is '%s'\n", ps);
4020
v = gettermcapstring(ps + 1);
4026
if (!strcmp(ps, "TERM"))
4027
v = display ? D_termname : "unknown";
4028
else if (!strcmp(ps, "COLUMNS"))
4029
sprintf(xbuf, "%d", display ? D_width : -1);
4030
else if (!strcmp(ps, "LINES"))
4031
sprintf(xbuf, "%d", display ? D_height : -1);
4036
vl = v ? strlen(v) : 0;
4039
debug1("- sub is '%s'\n", v);
4042
int right = buf + bufl - (p + strlen(p) + 1);
4045
bcopy(p, p + right, strlen(p) + 1);
4051
Msg(0, "%s: no space left for variable expansion.", rc_name);
4059
else if (delim != '\'' && *p == '^' && p[1])
4062
*pp++ = *p == '?' ? '\177' : *p & 0x1f;
4064
else if (delim == 0 && (*p == '\'' || *p == '"'))
4066
else if (delim == 0 && (*p == ' ' || *p == '\t' || *p == '\n'))
4074
Msg(0, "%s: Missing %c quote.", rc_name, delim);
4080
debug2("- arg done, '%s' rest %s\n", ap[-1], p);
4081
*lp++ = pp - ap[-1];
4100
if (DefaultEsc >= 0)
4101
ClearAction(&ktab[DefaultEsc]);
4102
if (DefaultMetaEsc >= 0)
4103
ClearAction(&ktab[DefaultMetaEsc]);
4106
DefaultMetaEsc = me;
4109
if (DefaultEsc >= 0)
4111
ClearAction(&ktab[DefaultEsc]);
4112
ktab[DefaultEsc].nr = RC_OTHER;
4114
if (DefaultMetaEsc >= 0)
4116
ClearAction(&ktab[DefaultMetaEsc]);
4117
ktab[DefaultMetaEsc].nr = RC_META;
4124
ParseSwitch(act, var)
4128
if (*act->args == 0)
4133
return ParseOnOff(act, var);
4137
ParseOnOff(act, var)
4141
register int num = -1;
4142
char **args = act->args;
4146
if (strcmp(args[0], "on") == 0)
4148
else if (strcmp(args[0], "off") == 0)
4153
Msg(0, "%s: %s: invalid argument. Give 'on' or 'off'", rc_name, comms[act->nr].name);
4161
ParseSaveStr(act, var)
4165
char **args = act->args;
4166
if (*args == 0 || args[1])
4168
Msg(0, "%s: %s: one argument required.", rc_name, comms[act->nr].name);
4173
*var = SaveStr(*args);
4183
char *p, **args = act->args;
4186
if (p == 0 || *p == 0 || args[1])
4188
Msg(0, "%s: %s: invalid argument. Give one argument.",
4189
rc_name, comms[act->nr].name);
4195
if (*p >= '0' && *p <= '9')
4196
i = 10 * i + (*p - '0');
4199
Msg(0, "%s: %s: invalid argument. Give numeric argument.",
4200
rc_name, comms[act->nr].name);
4205
debug1("ParseNum got %d\n", i);
4211
ParseNum1000(act, var)
4216
char *p, **args = act->args;
4220
if (p == 0 || *p == 0 || args[1])
4222
Msg(0, "%s: %s: invalid argument. Give one argument.",
4223
rc_name, comms[act->nr].name);
4229
if (*p >= '0' && *p <= '9')
4232
i = 10 * i + (*p - '0');
4233
else if (dig == 4 && *p >= '5')
4238
else if (*p == '.' && !dig)
4242
Msg(0, "%s: %s: invalid argument. Give floating point argument.",
4243
rc_name, comms[act->nr].name);
4254
i = (int)((unsigned int)~0 >> 1);
4255
debug1("ParseNum1000 got %d\n", i);
4266
for (p = windows; p; p = p->w_next)
4267
if (!strcmp(p->w_title, s))
4269
for (p = windows; p; p = p->w_next)
4270
if (!strncmp(p->w_title, s, strlen(s)))
4282
for (i = 0, s = str; *s; s++)
4284
if (*s < '0' || *s > '9')
4286
i = i * 10 + (*s - '0');
4292
* Get window number from Name or Number string.
4293
* Numbers are tried first, then names, a prefix match suffices.
4294
* Be careful when assigning numeric strings as WindowTitles.
4303
if ((i = WindowByNumber(str)) < 0 || i >= MAXWIN)
4305
if ((p = WindowByName(str)))
4313
ParseWinNum(act, var)
4317
char **args = act->args;
4320
if (*args == 0 || args[1])
4322
Msg(0, "%s: %s: one argument required.", rc_name, comms[act->nr].name);
4326
i = WindowByNoN(*args);
4329
Msg(0, "%s: %s: invalid argument. Give window number or name.",
4330
rc_name, comms[act->nr].name);
4333
debug1("ParseWinNum got %d\n", i);
4339
ParseBase(act, p, var, base, bname)
4351
Msg(0, "%s: %s: empty argument.", rc_name, comms[act->nr].name);
4356
if (c >= 'a' && c <= 'z')
4358
if (c >= 'A' && c <= 'Z')
4359
c -= 'A' - ('0' + 10);
4361
if (c < 0 || c >= base)
4363
Msg(0, "%s: %s: argument is not %s.", rc_name, comms[act->nr].name, bname);
4368
debug1("ParseBase got %d\n", i);
4378
for (base += '0'; *s; ++s)
4379
if (*s < '0' || *s > base)
4385
IsNumColon(s, base, p, psize)
4390
if ((q = rindex(s, ':')) != 0)
4392
strncpy(p, q + 1, psize - 1);
4393
p[psize - 1] = '\0';
4398
return IsNum(s, base);
4407
debug1("SwitchWindow %d\n", n);
4408
if (n < 0 || n >= MAXWIN)
4413
if ((p = wtab[n]) == 0)
4425
Msg(0, "This IS window %d (%s).", n, p->w_title);
4429
if (AclCheckPermWin(D_user, ACL_READ, p))
4431
Msg(0, "Access to window %d denied.", p->w_number);
4436
Activate(fore->w_norefresh);
4441
SetCanvasWindow(cv, wi)
4445
struct win *p = 0, **pp;
4447
struct canvas *cvp, **cvpp;
4450
display = cv->c_display;
4454
/* remove old layer */
4455
for (cvpp = &l->l_cvlist; (cvp = *cvpp); cvpp = &cvp->c_lnext)
4459
*cvpp = cvp->c_lnext;
4461
p = Layer2Window(l);
4465
if (p && cv == D_forecv)
4468
ReleaseAutoWritelock(display, p);
4472
SetTimeout(&p->w_silenceev, p->w_silencewait * 1000);
4473
evenq(&p->w_silenceev);
4478
if (l->l_cvlist == 0 && (p == 0 || l != p->w_savelayer))
4482
/* find right layer to display on canvas */
4486
if (wi->w_savelayer && (wi->w_blocked || wi->w_savelayer->l_cvlist == 0))
4487
l = wi->w_savelayer;
4492
/* add our canvas to the layer's canvaslist */
4493
cv->c_lnext = l->l_cvlist;
4496
cv->c_xoff = cv->c_xs;
4497
cv->c_yoff = cv->c_ys;
4498
RethinkViewportOffsets(cv);
4503
if (wi && D_other == wi)
4504
D_other = wi->w_next; /* Might be 0, but that's OK. */
4508
fore = D_fore; /* XXX ? */
4512
ObtainAutoWritelock(display, wi);
4515
* Place the window at the head of the most-recently-used list
4519
for (pp = &windows; (p = *pp); pp = &p->w_next)
4524
p->w_next = windows;
4534
* SetForeWindow changes the window in the input focus of the display.
4535
* Puts window wi in canvas display->d_forecv.
4547
p = Layer2Window(D_forecv->c_layer);
4548
SetCanvasWindow(D_forecv, wi);
4550
WindowChanged(p, 'u');
4552
WindowChanged(wi, 'u');
4553
flayer = D_forecv->c_layer;
4554
/* Activate called afterwards, so no RefreshHStatus needed */
4558
/*****************************************************************/
4561
* Activate - make fore window active
4562
* norefresh = -1 forces a refresh, disregard all_norefresh then.
4568
debug1("Activate(%d)\n", norefresh);
4573
Msg(0, "%s", ""); /* wait till mintime (keep gcc quiet) */
4577
if (MayResizeLayer(D_forecv->c_layer))
4578
ResizeLayer(D_forecv->c_layer, D_forecv->c_xe - D_forecv->c_xs + 1, D_forecv->c_ye - D_forecv->c_ys + 1, display);
4584
if (fore->w_monitor != MON_OFF)
4585
fore->w_monitor = MON_ON;
4586
fore->w_bell = BELL_ON;
4587
WindowChanged(fore, 'f');
4590
if (ResizeDisplay(fore->w_width, fore->w_height))
4592
debug2("Cannot resize from (%d,%d)", D_width, D_height);
4593
debug2(" to (%d,%d) -> resize window\n", fore->w_width, fore->w_height);
4594
DoResize(D_width, D_height);
4598
Redisplay(norefresh + all_norefresh);
4605
register struct win **pp;
4606
int n = fore ? fore->w_number : -1;
4608
for (pp = wtab + n + 1; pp != wtab + n; pp++)
4610
if (pp == wtab + MAXWIN)
4621
register struct win **pp;
4622
int n = fore ? fore->w_number : MAXWIN - 1;
4624
for (pp = wtab + n - 1; pp != wtab + n; pp--)
4627
pp = wtab + MAXWIN - 1;
4637
char *m = "No other window.";
4638
if (windows && (fore == 0 || windows->w_next))
4642
Msg(0, "No window available");
4645
Msg(0, m, fore->w_number); /* other arg for nethack */
4653
struct win **pp, *p;
4658
* Remove window from linked list.
4660
for (pp = &windows; (p = *pp); pp = &p->w_next)
4666
wtab[wi->w_number] = 0;
4675
* switch to different window on all canvases
4677
for (display = displays; display; display = display->d_next)
4680
for (cv = D_cvlist; cv; cv = cv->c_next)
4682
if (Layer2Window(cv->c_layer) != wi)
4684
/* switch to other window */
4685
SetCanvasWindow(cv, FindNiceWindow(D_other, 0));
4691
if (wi->w_zdisplay == display)
4694
D_readev.condpos = D_readev.condneg = 0;
4701
WindowChanged((struct win *)0, 'w');
4702
WindowChanged((struct win *)0, 'W');
4703
WindowChanged((struct win *)0, 0);
4712
if ((fore->w_log != 0) == on)
4714
if (display && !*rc_name)
4715
Msg(0, "You are %s logging.", on ? "already" : "not");
4718
if (fore->w_log != 0)
4720
Msg(0, "Logfile \"%s\" closed.", fore->w_log->name);
4721
logfclose(fore->w_log);
4723
WindowChanged(fore, 'f');
4726
if (DoStartLog(fore, buf, sizeof(buf)))
4728
Msg(errno, "Error opening logfile \"%s\"", buf);
4731
if (ftell(fore->w_log->fp) == 0)
4732
Msg(0, "Creating logfile \"%s\".", fore->w_log->name);
4734
Msg(0, "Appending to logfile \"%s\".", fore->w_log->name);
4735
WindowChanged(fore, 'f');
4739
AddWindows(buf, len, flags, where)
4745
register char *s, *ss;
4746
register struct win **pp, *p;
4751
for (pp = ((flags & 4) && where >= 0) ? wtab + where + 1: wtab; pp < wtab + MAXWIN; pp++)
4753
if (pp - wtab == where && ss == buf)
4757
if ((flags & 1) && display && p == D_fore)
4764
if (s - buf + l > len - 24)
4766
if (s > buf || (flags & 4))
4771
sprintf(s, "%d", p->w_number);
4772
if (p->w_number == where)
4775
if (display && p == D_fore)
4779
if (display && p == D_other)
4781
s = AddWindowFlags(s, len, p);
4792
AddWindowFlags(buf, len, p)
4798
if (p == 0 || len < 12)
4804
if (display && p == D_fore)
4806
if (display && p == D_other)
4809
if (p->w_layer.l_cvlist && p->w_layer.l_cvlist->c_lnext)
4811
if (p->w_monitor == MON_DONE)
4813
if (p->w_bell == BELL_DONE)
4816
if (p->w_slot != (slot_t) 0 && p->w_slot != (slot_t) -1)
4831
AddOtherUsers(buf, len, p)
4836
struct display *d, *olddisplay = display;
4842
for (display = displays; display; display = display->d_next)
4844
if (D_user == olddisplay->d_user)
4846
for (cv = D_cvlist; cv; cv = cv->c_next)
4847
if (Layer2Window(cv->c_layer) == p)
4851
for (d = displays; d && d != display; d = d->d_next)
4852
if (D_user == d->d_user)
4854
if (d && d != display)
4856
if (len > 1 && s != buf)
4861
l = strlen(D_user->u_name);
4864
strcpy(s, D_user->u_name);
4869
display = olddisplay;
4882
if (where == -1 && D_fore)
4883
where = D_fore->w_number;
4884
ss = AddWindows(buf, sizeof(buf), 0, where);
4885
s = buf + strlen(buf);
4886
if (ss - buf > D_width / 2)
4889
if (s - ss < D_width)
4905
register struct win *wp = fore;
4910
Msg(0, "(%d,%d)/(%d,%d) no window", D_x + 1, D_y + 1, D_width, D_height);
4914
if (buf < (p += GetAnsiStatus(wp, p)))
4916
sprintf(p, "(%d,%d)/(%d,%d)",
4917
wp->w_x + 1, wp->w_y + 1, wp->w_width, wp->w_height);
4919
sprintf(p += strlen(p), "+%d", wp->w_histheight);
4921
sprintf(p += strlen(p), " %c%sflow",
4922
(wp->w_flow & FLOW_NOW) ? '+' : '-',
4923
(wp->w_flow & FLOW_AUTOFLAG) ? "" :
4924
((wp->w_flow & FLOW_AUTO) ? "(+)" : "(-)"));
4925
if (!wp->w_wrap) sprintf(p += strlen(p), " -wrap");
4926
if (wp->w_insert) sprintf(p += strlen(p), " ins");
4927
if (wp->w_origin) sprintf(p += strlen(p), " org");
4928
if (wp->w_keypad) sprintf(p += strlen(p), " app");
4929
if (wp->w_log) sprintf(p += strlen(p), " log");
4930
if (wp->w_monitor != MON_OFF) sprintf(p += strlen(p), " mon");
4931
if (wp->w_mouse) sprintf(p += strlen(p), " mouse");
4933
if (wp->w_bce) sprintf(p += strlen(p), " bce");
4935
if (!wp->w_c1) sprintf(p += strlen(p), " -c1");
4936
if (wp->w_norefresh) sprintf(p += strlen(p), " nored");
4941
if (wp->w_encoding && (display == 0 || D_encoding != wp->w_encoding || EncodingDefFont(wp->w_encoding) <= 0))
4944
strcpy(p, EncodingName(wp->w_encoding));
4948
if (wp->w_encoding != UTF8)
4951
if (D_CC0 || (D_CS0 && *D_CS0))
4955
sprintf(p, " G%c", wp->w_Charset + '0');
4956
if (wp->w_FontE >= ' ')
4961
p[4] = wp->w_FontE ^ 0x40;
4968
sprintf(p++, " G%c%c[", wp->w_Charset + '0', wp->w_CharsetR + '0');
4970
sprintf(p, " G%c[", wp->w_Charset + '0');
4972
for (i = 0; i < 4; i++)
4974
if (wp->w_charsets[i] == ASCII)
4976
else if (wp->w_charsets[i] >= ' ')
4977
*p++ = wp->w_charsets[i];
4981
*p++ = wp->w_charsets[i] ^ 0x40;
4989
if (wp->w_type == W_TYPE_PLAIN)
4991
/* add info about modem control lines */
4993
TtyGetModemStatus(wp->w_ptyfd, p);
4995
#ifdef BUILTIN_TELNET
4996
else if (wp->w_type == W_TYPE_TELNET)
4999
TelStatus(wp, p, sizeof(buf) - 1 - (p - buf));
5002
Msg(0, "%s %d(%s)", buf, wp->w_number, wp->w_title);
5012
sprintf(p, "(%d,%d)", D_width, D_height),
5018
strcpy(p, EncodingName(D_encoding));
5024
strcpy(p, " xterm");
5030
strcpy(p, " color");
5037
strcpy(p, " iso2022");
5040
else if (D_CS0 && *D_CS0)
5042
strcpy(p, " altchar");
5050
AKAfin(buf, len, data)
5053
char *data; /* dummy */
5057
ChangeAKA(fore, buf, strlen(buf));
5065
Input("Set window's title to: ", sizeof(fore->w_akabuf) - 1, INP_COOKED, AKAfin, NULL);
5071
if ((*(unsigned char *)s & 0x7f) < 0x20 || *s == 0x7f)
5075
LayProcess(&ss, &n);
5080
Colonfin(buf, len, data)
5083
char *data; /* dummy */
5088
len = strlen(buf) + 1;
5089
if (len > (int)sizeof(mbuf))
5093
bcopy(buf, mbuf, len);
5094
RcLine(mbuf, sizeof mbuf);
5100
SelectFin(buf, len, data)
5103
char *data; /* dummy */
5107
if (!len || !display)
5109
if (len == 1 && *buf == '-')
5111
SetForeWindow((struct win *)0);
5115
if ((n = WindowByNoN(buf)) < 0)
5123
Input("Switch to window: ", 20, INP_COOKED, SelectFin, NULL);
5126
static char setenv_var[31];
5130
SetenvFin1(buf, len, data)
5133
char *data; /* dummy */
5135
if (!len || !display)
5141
SetenvFin2(buf, len, data)
5144
char *data; /* dummy */
5146
if (!len || !display)
5148
debug2("SetenvFin2: setenv '%s' '%s'\n", setenv_var, buf);
5149
xsetenv(setenv_var, buf);
5157
static char setenv_buf[50 + sizeof(setenv_var)]; /* need to be static here, cannot be freed */
5161
strncpy(setenv_var, arg, sizeof(setenv_var) - 1);
5162
sprintf(setenv_buf, "Enter value for %s: ", setenv_var);
5163
Input(setenv_buf, 30, INP_COOKED, SetenvFin2, NULL);
5166
Input("Setenv: Enter variable name: ", 30, INP_COOKED, SetenvFin1, NULL);
5170
* the following options are understood by this parser:
5171
* -f, -f0, -f1, -fy, -fa
5172
* -t title, -T terminal-type, -h height-of-scrollback,
5173
* -ln, -l0, -ly, -l1, -l
5180
struct NewWindow nwin;
5185
while (av && *av && av[0][0] == '-')
5187
if (av[0][1] == '-')
5199
nwin.flowflag = FLOW_NOW * 0;
5204
nwin.flowflag = FLOW_NOW * 1;
5207
nwin.flowflag = FLOW_AUTOFLAG;
5213
case 't': /* no more -k */
5215
nwin.aka = &av[0][2];
5223
nwin.term = &av[0][2];
5231
nwin.histheight = atoi(av[0] + 2);
5233
nwin.histheight = atoi(*av);
5262
nwin.monitor = MON_ON;
5268
Msg(0, "%s: screen: invalid option -%c.", fn, av[0][1]);
5274
if (av && *av && IsNumColon(*av, 10, buf, sizeof(buf)))
5279
if (num < 0 || num > MAXWIN - 1)
5281
Msg(0, "%s: illegal screen number %d.", fn, num);
5291
nwin.aka = Filename(*av);
5298
* CompileKeys must be called before Markroutine is first used.
5299
* to initialise the keys with defaults, call CompileKeys(NULL, mark_key_tab);
5301
* s is an ascii string in a termcap-like syntax. It looks like
5302
* "j=u:k=d:l=r:h=l: =.:" and so on...
5303
* this example rebinds the cursormovement to the keys u (up), d (down),
5304
* l (left), r (right). placing a mark will now be done with ".".
5307
CompileKeys(s, sl, array)
5310
unsigned char *array;
5313
unsigned char key, value;
5317
for (i = 0; i < 256; i++)
5321
debug1("CompileKeys: '%s'\n", s);
5324
key = *(unsigned char *)s++;
5325
if (*s != '=' || sl < 3)
5332
value = *(unsigned char *)s++;
5335
while (*s == '=' && sl >= 2);
5344
#endif /* COPY_PASTE */
5347
* Asynchronous input functions
5350
#if defined(DETACH) && defined(POW_DETACH)
5352
pow_detach_fn(buf, len, data)
5355
char *data; /* dummy */
5357
debug("pow_detach_fn called\n");
5363
if (ktab[(int)(unsigned char)*buf].nr != RC_POW_DETACH)
5366
write(D_userfd, "\007", 1);
5367
Msg(0, "Detach aborted.");
5372
#endif /* POW_DETACH */
5376
copy_reg_fn(buf, len, data)
5379
char *data; /* dummy */
5381
struct plop *pp = plop_tab + (int)(unsigned char)*buf;
5392
if (D_user->u_plop.len)
5394
if ((pp->buf = (char *)malloc(D_user->u_plop.len)) == NULL)
5399
bcopy(D_user->u_plop.buf, pp->buf, D_user->u_plop.len);
5401
pp->len = D_user->u_plop.len;
5403
pp->enc = D_user->u_plop.enc;
5405
Msg(0, "Copied %d characters into register %c", D_user->u_plop.len, *buf);
5409
ins_reg_fn(buf, len, data)
5412
char *data; /* dummy */
5414
struct plop *pp = plop_tab + (int)(unsigned char)*buf;
5418
return; /* Input() should not call us w/o fore, but you never know... */
5420
Msg(0, "ins_reg_fn: Warning: pasting real register '.'!");
5428
MakePaster(&fore->w_paster, pp->buf, pp->len, 0);
5431
Msg(0, "Empty register.");
5433
#endif /* COPY_PASTE */
5436
process_fn(buf, len, data)
5439
char *data; /* dummy */
5441
struct plop *pp = plop_tab + (int)(unsigned char)*buf;
5450
ProcessInput(pp->buf, pp->len);
5453
Msg(0, "Empty register.");
5457
confirm_fn(buf, len, data)
5460
char *data; /* dummy */
5464
if (len || (*buf != 'y' && *buf != 'Y'))
5478
struct acluser **up;
5480
char pw1[130]; /* FreeBSD crypts to 128 bytes */
5485
su_fin(buf, len, data)
5490
struct inputsu *i = (struct inputsu *)data;
5495
{ p = i->name; l = sizeof(i->name) - 1; }
5497
{ strcpy(p = i->pw1, "\377"); l = sizeof(i->pw1) - 1; }
5499
{ strcpy(p = i->pw2, "\377"); l = sizeof(i->pw2) - 1; }
5501
strncpy(p, buf, 1 + (l < len) ? l : len);
5503
Input("Screen User: ", sizeof(i->name) - 1, INP_COOKED, su_fin, (char *)i);
5505
Input("User's UNIX Password: ", sizeof(i->pw1)-1, INP_COOKED|INP_NOECHO, su_fin, (char *)i);
5507
Input("User's Screen Password: ", sizeof(i->pw2)-1, INP_COOKED|INP_NOECHO, su_fin, (char *)i);
5510
if ((p = DoSu(i->up, i->name, i->pw2, i->pw1)))
5517
InputSu(w, up, name)
5519
struct acluser **up;
5524
if (!(i = (struct inputsu *)calloc(1, sizeof(struct inputsu))))
5529
su_fin(name, (int)strlen(name), (char *)i); /* can also initialise stuff */
5531
su_fin((char *)0, 0, (char *)i);
5534
#endif /* MULTIUSER */
5539
pass1(buf, len, data)
5544
struct acluser *u = (struct acluser *)data;
5549
if (u->u_password != NullStr)
5550
free((char *)u->u_password);
5551
u->u_password = SaveStr(buf);
5552
bzero(buf, strlen(buf));
5553
Input("Retype new password:", 100, INP_NOECHO, pass2, data);
5557
pass2(buf, len, data)
5564
struct acluser *u = (struct acluser *)data;
5567
if (!buf || strcmp(u->u_password, buf))
5569
Msg(0, "[ Passwords don't match - checking turned off ]");
5570
if (u->u_password != NullStr)
5572
bzero(u->u_password, strlen(u->u_password));
5573
free((char *)u->u_password);
5575
u->u_password = NullStr;
5577
else if (u->u_password[0] == '\0')
5579
Msg(0, "[ No password - no secure ]");
5581
bzero(buf, strlen(buf));
5584
if (u->u_password != NullStr)
5586
for (st = 0; st < 2; st++)
5587
salt[st] = 'A' + (int)((time(0) >> 6 * st) % 26);
5589
buf = crypt(u->u_password, salt);
5590
bzero(u->u_password, strlen(u->u_password));
5591
free((char *)u->u_password);
5592
u->u_password = SaveStr(buf);
5593
bzero(buf, strlen(buf));
5596
UserFreeCopyBuffer(u);
5597
u->u_plop.len = strlen(u->u_password);
5601
if (!(u->u_plop.buf = SaveStr(u->u_password)))
5604
D_user->u_plop.len = 0;
5607
Msg(0, "[ Password moved into copybuffer ]");
5608
#else /* COPY_PASTE */
5609
Msg(0, "[ Crypted password is \"%s\" ]", u->u_password);
5610
#endif /* COPY_PASTE */
5613
#endif /* PASSWORD */
5616
digraph_fn(buf, len, data)
5619
char *data; /* dummy */
5626
if (ch < ' ' || ch == '\177')
5628
if (len >= 1 && ((*buf == 'U' && buf[1] == '+') || (*buf == '0' && (buf[1] == 'x' || buf[1] == 'X'))))
5632
if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f') && (ch < 'A' || ch > 'F'))
5634
buf[len] = '\034'; /* ^] is ignored by Input() */
5637
if (len == (*buf == 'U' ? 5 : 3))
5641
if (len && *buf == '0')
5643
if (ch < '0' || ch > '7')
5645
buf[len] = '\034'; /* ^] is ignored by Input() */
5656
buf[len] = buf[len + 1]; /* gross */
5660
if (len >= 1 && ((*buf == 'U' && buf[1] == '+') || (*buf == '0' && (buf[1] == 'x' || buf[1] == 'X'))))
5663
for (i = 2; i < len; i++)
5665
if (buf[i] >= '0' && buf[i] <= '9')
5666
x = x * 16 | (buf[i] - '0');
5667
else if (buf[i] >= 'a' && buf[i] <= 'f')
5668
x = x * 16 | (buf[i] - ('a' - 10));
5669
else if (buf[i] >= 'A' && buf[i] <= 'F')
5670
x = x * 16 | (buf[i] - ('A' - 10));
5675
else if (buf[0] == '0')
5678
for (i = 1; i < len; i++)
5680
if (buf[i] < '0' || buf[i] > '7')
5682
x = x * 8 | (buf[i] - '0');
5687
for (i = 0; i < (int)(sizeof(digraphs)/sizeof(*digraphs)); i++)
5688
if ((digraphs[i][0] == (unsigned char)buf[0] && digraphs[i][1] == (unsigned char)buf[1]) ||
5689
(digraphs[i][0] == (unsigned char)buf[1] && digraphs[i][1] == (unsigned char)buf[0]))
5691
if (i == (int)(sizeof(digraphs)/sizeof(*digraphs)))
5693
Msg(0, "Unknown digraph");
5701
if (flayer->l_encoding == UTF8)
5702
i = ToUtf8(buf, x); /* buf is big enough for all UTF-8 codes */
5705
LayProcess(&buf, &i);
5715
debug1("StuffKey #%d", i);
5718
debug1(" - %s", term[i + T_CAPS].tcname);
5720
if (i >= T_CURSOR - T_CAPS && i < T_KEYPAD - T_CAPS && D_cursorkeys)
5721
i += T_OCAPS - T_CURSOR;
5722
else if (i >= T_KEYPAD - T_CAPS && i < T_OCAPS - T_CAPS && D_keypad)
5723
i += T_OCAPS - T_CURSOR;
5724
debug1(" - action %d\n", i);
5725
flayer = D_forecv->c_layer;
5729
if (InMark() || InInput() || InWList())
5730
act = i < KMAP_KEYS+KMAP_AKEYS ? &mmtab[i] : &kmap_exts[i - (KMAP_KEYS+KMAP_AKEYS)].mm;
5732
if ((!act || act->nr == RC_ILLEGAL) && !D_mapdefault)
5733
act = i < KMAP_KEYS+KMAP_AKEYS ? &umtab[i] : &kmap_exts[i - (KMAP_KEYS+KMAP_AKEYS)].um;
5735
if (!act || act->nr == RC_ILLEGAL)
5736
act = i < KMAP_KEYS+KMAP_AKEYS ? &dmtab[i] : &kmap_exts[i - (KMAP_KEYS+KMAP_AKEYS)].dm;
5737
if (act == 0 || act->nr == RC_ILLEGAL)
5751
for (cv = D_cvlist; cv; cv = cv->c_next)
5752
if (Layer2Window(cv->c_layer) == wi)
5758
FindNiceWindow(wi, presel)
5764
debug2("FindNiceWindow %d %s\n", wi ? wi->w_number : -1 , presel ? presel : "NULL");
5767
i = WindowByNoN(presel);
5774
if (wi && AclCheckPermWin(D_user, ACL_READ, wi))
5777
if (!wi || (IsOnDisplay(wi) && !presel))
5779
/* try to get another window */
5782
for (wi = windows; wi; wi = wi->w_next)
5783
if (!wi->w_layer.l_cvlist && !AclCheckPermWin(D_user, ACL_WRITE, wi))
5786
for (wi = windows; wi; wi = wi->w_next)
5787
if (wi->w_layer.l_cvlist && !IsOnDisplay(wi) && !AclCheckPermWin(D_user, ACL_WRITE, wi))
5790
for (wi = windows; wi; wi = wi->w_next)
5791
if (!wi->w_layer.l_cvlist && !AclCheckPermWin(D_user, ACL_READ, wi))
5794
for (wi = windows; wi; wi = wi->w_next)
5795
if (wi->w_layer.l_cvlist && !IsOnDisplay(wi) && !AclCheckPermWin(D_user, ACL_READ, wi))
5799
for (wi = windows; wi; wi = wi->w_next)
5800
if (!wi->w_layer.l_cvlist)
5803
for (wi = windows; wi; wi = wi->w_next)
5804
if (wi->w_layer.l_cvlist && !IsOnDisplay(wi))
5808
if (wi && AclCheckPermWin(D_user, ACL_READ, wi))
5816
/* sorted list of all commands */
5817
static struct comm **commtab;
5818
static int ncommtab;
5823
void (*hand) __P((struct comm *, char **, int));
5826
for (n = 0; cos[n].name; n++)
5831
commtab = (struct commt *)realloc(commtab, sizeof(*commtab) * (ncommtab + n));
5833
commtab = (struct commt *)malloc(sizeof(*commtab) * (ncommtab + n));
5836
for (i = 0; i < n; i++)
5838
for (j = 0; j < ncommtab; j++)
5840
r = strcmp(cos[i].name, commtab[j]->name);
5842
Panic(0, "Duplicate command: %s\n", cos[i].name);
5846
for (r = ncommtab; r > j; r--)
5847
commtab[r] = commtab[r - 1];
5848
commtab[j] = cos + i;
5849
cos[i].handler = hand;
5850
bzero(cos[i].userbits, sizeof(cos[i].userbits));
5859
int x, m, l = 0, r = ncommtab - 1;
5863
x = strcmp(str, commtab[m]->name);
5881
int nreg, dsize, diff, siz;
5884
for (nreg = 0, cv = D_cvlist; cv; cv = cv->c_next)
5888
Msg(0, "resize: need more than one region");
5891
dsize = D_height - (D_has_hstatus == HSTATUS_LASTLINE);
5894
/* make all regions the same height */
5897
for (cv = D_cvlist; cv; cv = cv->c_next)
5899
hh = h / nreg-- - 1;
5901
cv->c_ye = i + hh - 1;
5906
RethinkDisplayViewports();
5907
ResizeLayersToCanvases();
5910
siz = D_forecv->c_ye - D_forecv->c_ys + 1;
5912
diff = atoi(arg + 1);
5913
else if (*arg == '-')
5914
diff = -atoi(arg + 1);
5915
else if (!strcmp(arg, "min"))
5917
else if (!strcmp(arg, "max"))
5918
diff = dsize - (nreg - 1) * 2 - 1 - siz;
5920
diff = atoi(arg) - siz;
5925
if (siz + diff > dsize - (nreg - 1) * 2 - 1)
5926
diff = dsize - (nreg - 1) * 2 - 1 - siz;
5927
if (diff == 0 || siz + diff < 1)
5932
if (D_forecv->c_next)
5934
D_forecv->c_ye += diff;
5935
D_forecv->c_next->c_ys += diff;
5936
D_forecv->c_next->c_yoff += diff;
5940
for (cv = D_cvlist; cv; cv = cv->c_next)
5941
if (cv->c_next == D_forecv)
5945
D_forecv->c_ys -= diff;
5946
D_forecv->c_yoff -= diff;
5951
int s, i = 0, found = 0, di = diff, d2;
5952
s = dsize - (nreg - 1) * 2 - 1 - siz;
5953
for (cv = D_cvlist; cv; i = cv->c_ye + 2, cv = cv->c_next)
5957
cv->c_ye = i + (cv->c_ye - cv->c_ys) + diff;
5958
cv->c_yoff -= cv->c_ys - i;
5963
s -= cv->c_ye - cv->c_ys;
5971
d2 = di > cv->c_ye - cv->c_ys ? cv->c_ye - cv->c_ys : di;
5973
cv->c_ye = i + (cv->c_ye - cv->c_ys) - d2;
5974
cv->c_yoff -= cv->c_ys - i;
5978
RethinkDisplayViewports();
5979
ResizeLayersToCanvases();
5983
ResizeFin(buf, len, data)
5998
p = Layer2Window(D_forecv->c_layer);
5999
for (i = 3; i >=0; i--)
6000
SetXtermOSC(i, p ? p->w_xtermosc[i] : 0);
6005
ParseAttrColor(s1, s2, msgok)
6017
while (*ss && *ss != ' ')
6021
if (*s && (s2 || *ss || !((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') || *s == '.')))
6023
int mode = 0, n = 0;
6041
if (*s >= '0' && *s <= '9')
6044
if (*s >= '0' && *s <= '9')
6045
n = n * 16 + (*s++ - '0');
6046
else if (*s >= 'a' && *s <= 'f')
6047
n = n * 16 + (*s++ - ('a' - 10));
6048
else if (*s >= 'A' && *s <= 'F')
6049
n = n * 16 + (*s++ - ('A' - 10));
6050
else if (*s && *s != ' ')
6053
Msg(0, "Illegal attribute hexchar '%c'", *s);
6059
while (*s && *s != ' ')
6076
Msg(0, "Illegal attribute specifier '%c'", *s);
6082
if (*s && *s != ' ')
6085
Msg(0, "junk after attribute description: '%c'", *s);
6097
while (*s && *s == ' ')
6105
Msg(0, "junk after description: '%c'", *s);
6109
while (*s && *s == ' ')
6116
static char costr[] = "krgybmcw d i.01234567 9 f FKRGYBMCW I ";
6126
for (j = 0; j < 2 && *s && *s != ' '; j++)
6128
for (i = 0; costr[i]; i++)
6134
Msg(0, "illegal color descriptor: '%c'", *s);
6138
n = n << 4 | (i & 15);
6141
n = (n & 0x20ff) | 0x200;
6145
if ((n & 0xf00) == 0xf00)
6146
n ^= 0xf00; /* clear superflous bits */
6149
n ^= 0x2400; /* shift bit into right position */
6152
n |= 0xf0; /* don't change bg color */
6153
if (numco != 2 && n != 0xff)
6154
n |= 0x100; /* special invert mode */
6155
if (*s && *s != ' ')
6158
Msg(0, "junk after color description: '%c'", *s);
6166
while (*s && *s == ' ')
6171
Msg(0, "junk after description: '%c'", *s);
6174
debug1("ParseAttrColor %06x\n", r);
6182
* e just set intensity
6183
* f don't change anything
6184
* Intensity is encoded into bits 17(fg) and 18(bg).
6187
ApplyAttrColor(i, mc)
6191
debug1("ApplyAttrColor %06x\n", i);
6192
mc->attr |= i >> 8 & 255;
6193
mc->attr ^= i & 255;
6195
i = (i >> 16) ^ 0xff;
6196
if ((i & 0x100) != 0)
6199
if (mc->attr & (A_SO|A_RV))
6201
i = ((i & 0x0f) << 4) | ((i & 0xf0) >> 4) | ((i & 0x200) << 1) | ((i & 0x400) >> 1);
6203
i = ((i & 0x0f) << 4) | ((i & 0xf0) >> 4);
6207
if ((i & 0x0f) != 0x0f)
6208
mc->attr = (mc->attr & 0xbf) | ((i >> 3) & 0x40);
6209
if ((i & 0xf0) != 0xf0)
6210
mc->attr = (mc->attr & 0x7f) | ((i >> 3) & 0x80);
6212
mc->color = 0x99 ^ mc->color;
6213
if ((i & 0x0e) == 0x0e)
6214
i = (i & 0xf0) | (mc->color & 0x0f);
6215
if ((i & 0xe0) == 0xe0)
6216
i = (i & 0x0f) | (mc->color & 0xf0);
6217
mc->color = 0x99 ^ i;
6218
debug2("ApplyAttrColor - %02x %02x\n", mc->attr, i);