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>
31 char version
[40]; /* initialised by main() */
33 extern struct layer
*flayer
;
34 extern struct display
*display
, *displays
;
35 extern struct win
*windows
;
36 extern char *noargs
[];
37 extern struct mchar mchar_blank
, mchar_so
;
38 extern unsigned char *blank
;
39 extern struct win
*wtab
[];
41 extern struct term term
[];
44 static void PadStr
__P((char *, int, int, int));
46 extern char *wliststr
;
47 extern char *wlisttit
;
50 exit_with_usage(myname
, message
, arg
)
51 char *myname
, *message
, *arg
;
53 printf("Use: %s [-opts] [cmd [args]]\n", myname
);
54 printf(" or: %s -r [host.tty]\n\nOptions:\n", myname
);
55 printf("-a Force all capabilities into each window's termcap.\n");
56 printf("-A -[r|R] Adapt all windows to the new display width & height.\n");
57 printf("-c file Read configuration file instead of '.screenrc'.\n");
59 printf("-d (-r) Detach the elsewhere running screen (and reattach here).\n");
60 printf("-dmS name Start as daemon: Screen session in detached mode.\n");
61 printf("-D (-r) Detach and logout remote (and reattach here).\n");
62 printf("-D -RR Do whatever is needed to get a screen session.\n");
64 printf("-e xy Change command characters.\n");
65 printf("-f Flow control on, -fn = off, -fa = auto.\n");
66 printf("-h lines Set the size of the scrollback history buffer.\n");
67 printf("-i Interrupt output sooner when flow control is on.\n");
68 #if defined(LOGOUTOK) && defined(UTMPOK)
69 printf("-l Login mode on (update %s), -ln = off.\n", UTMPFILE
);
71 printf("-list or -ls. Do nothing, just list our SockDir.\n");
72 printf("-L Turn on output logging.\n");
73 printf("-m ignore $STY variable, do create a new screen session.\n");
74 printf("-O Choose optimal output rather than exact vt100 emulation.\n");
75 printf("-p window Preselect the named window if it exists.\n");
76 printf("-q Quiet startup. Exits with non-zero return code if unsuccessful.\n");
77 printf("-r Reattach to a detached screen process.\n");
78 printf("-R Reattach if possible, otherwise start a new session.\n");
79 printf("-s shell Shell to execute rather than $SHELL.\n");
80 printf("-S sockname Name this session <pid>.sockname instead of <pid>.<tty>.<host>.\n");
81 printf("-t title Set title. (window's name).\n");
82 printf("-T term Use term as $TERM for windows, rather than \"screen\".\n");
84 printf("-U Tell screen to use UTF-8 encoding.\n");
86 printf("-v Print \"Screen version %s\".\n", version
);
87 printf("-wipe Do nothing, just clean up SockDir.\n");
89 printf("-x Attach to a not detached screen. (Multi display mode).\n");
91 printf("-X Execute <cmd> as a screen command in the specified session.\n");
92 if (message
&& *message
)
102 ** Here come the help page routines
105 extern struct comm comms
[];
106 extern struct action ktab
[];
108 static void HelpProcess
__P((char **, int *));
109 static void HelpAbort
__P((void));
110 static void HelpRedisplayLine
__P((int, int, int, int));
111 static void add_key_to_buf
__P((char *, int));
112 static void AddAction
__P((struct action
*, int, int));
113 static int helppage
__P((void));
118 struct action
*ktabp
;
119 int maxrow
, grow
, numcols
, numrows
, num_names
;
120 int numskip
, numpages
;
121 int command_search
, command_bindings
;
122 int refgrow
, refcommand_search
;
123 int inter
, mcom
, mkey
;
124 int nact
[RC_LAST
+ 1];
129 static struct LayFuncs HelpLf
=
142 display_help(class, ktabp
)
144 struct action
*ktabp
;
146 int i
, n
, key
, mcom
, mkey
, l
;
147 struct helpdata
*helpdata
;
148 int used
[RC_LAST
+ 1];
150 if (flayer
->l_height
< 6)
152 LMsg(0, "Window height too small for help page");
155 if (InitOverlayPage(sizeof(*helpdata
), &HelpLf
, 0))
158 helpdata
= (struct helpdata
*)flayer
->l_data
;
159 helpdata
->class = class;
160 helpdata
->ktabp
= ktabp
;
161 helpdata
->num_names
= helpdata
->command_bindings
= 0;
162 helpdata
->command_search
= 0;
163 for (n
= 0; n
<= RC_LAST
; n
++)
167 for (key
= 0; key
< 256 + KMAP_KEYS
; key
++)
172 if (ktabp
[key
].args
== noargs
)
174 used
[n
] += (key
<= ' ' || key
== 0x7f) ? 3 :
175 (key
> 0x7f) ? 5 : 2;
178 helpdata
->command_bindings
++;
180 for (n
= i
= 0; n
<= RC_LAST
; n
++)
183 l
= strlen(comms
[n
].name
);
188 helpdata
->nact
[i
++] = n
;
190 debug1("help: %d commands bound to keys with no arguments\n", i
);
191 debug2("mcom: %d mkey: %d\n", mcom
, mkey
);
192 helpdata
->num_names
= i
;
196 helpdata
->numcols
= flayer
->l_width
/ (mcom
+ mkey
+ 1);
197 if (helpdata
->numcols
== 0)
200 LMsg(0, "Width too small");
203 helpdata
->inter
= (flayer
->l_width
- (mcom
+ mkey
) * helpdata
->numcols
) / (helpdata
->numcols
+ 1);
204 if (helpdata
->inter
<= 0)
206 debug1("inter: %d\n", helpdata
->inter
);
207 helpdata
->mcom
= mcom
;
208 helpdata
->mkey
= mkey
;
209 helpdata
->numrows
= (helpdata
->num_names
+ helpdata
->numcols
- 1) / helpdata
->numcols
;
210 debug1("Numrows: %d\n", helpdata
->numrows
);
211 helpdata
->numskip
= flayer
->l_height
-5 - (2 + helpdata
->numrows
);
212 while (helpdata
->numskip
< 0)
213 helpdata
->numskip
+= flayer
->l_height
-5;
214 helpdata
->numskip
%= flayer
->l_height
-5;
215 debug1("Numskip: %d\n", helpdata
->numskip
);
216 if (helpdata
->numskip
> flayer
->l_height
/3 || helpdata
->numskip
> helpdata
->command_bindings
)
217 helpdata
->numskip
= 1;
218 helpdata
->maxrow
= 2 + helpdata
->numrows
+ helpdata
->numskip
+ helpdata
->command_bindings
;
221 helpdata
->numpages
= (helpdata
->maxrow
+ flayer
->l_height
-6) / (flayer
->l_height
-5);
223 flayer
->l_y
= flayer
->l_height
- 1;
228 HelpProcess(ppbuf
, plen
)
234 while (!done
&& *plen
> 0)
259 LAY_CALL_UP(LRefreshAll(flayer
, 0));
267 struct helpdata
*helpdata
;
268 int col
, crow
, n
, key
, x
;
269 char buf
[MAXKLEN
], Esc_buf
[5], cbuf
[256];
270 struct action
*ktabp
;
272 helpdata
= (struct helpdata
*)flayer
->l_data
;
274 ktabp
= helpdata
->ktabp
;
275 if (helpdata
->grow
>= helpdata
->maxrow
)
277 helpdata
->refgrow
= helpdata
->grow
;
278 helpdata
->refcommand_search
= helpdata
->command_search
;
280 /* Clear the help screen */
281 LClearAll(flayer
, 0);
283 sprintf(cbuf
,"Screen key bindings, page %d of %d.", helpdata
->grow
/ (flayer
->l_height
-5) + 1, helpdata
->numpages
);
289 /* XXX fix escape character */
290 if (flayer
->l_cvlist
&& flayer
->l_cvlist
->c_display
)
292 add_key_to_buf(buf
, flayer
->l_cvlist
->c_display
->d_user
->u_MetaEsc
);
293 add_key_to_buf(Esc_buf
, flayer
->l_cvlist
->c_display
->d_user
->u_Esc
);
297 strcpy(Esc_buf
, "??");
301 for (; crow
< flayer
->l_height
- 3; crow
++)
303 if (helpdata
->grow
< 1)
306 sprintf(cbuf
,"Command key: %s Literal %s: %s", Esc_buf
, Esc_buf
, buf
);
308 sprintf(cbuf
,"Command class: '%.80s'", helpdata
->class);
309 centerline(cbuf
, crow
);
312 else if (helpdata
->grow
>= 2 && helpdata
->grow
-2 < helpdata
->numrows
)
315 for (col
= 0; col
< helpdata
->numcols
&& (n
= helpdata
->numrows
* col
+ (helpdata
->grow
-2)) < helpdata
->num_names
; col
++)
317 x
+= helpdata
->inter
- !col
;
318 n
= helpdata
->nact
[n
];
320 for (key
= 0; key
< 256 + KMAP_KEYS
; key
++)
321 if (ktabp
[key
].nr
== n
&& ktabp
[key
].args
== noargs
&& strlen(buf
) < sizeof(buf
) - 7)
324 add_key_to_buf(buf
, key
);
326 PadStr(comms
[n
].name
, helpdata
->mcom
, x
, crow
);
328 PadStr(buf
, helpdata
->mkey
, x
, crow
);
333 else if (helpdata
->grow
-2-helpdata
->numrows
>= helpdata
->numskip
334 && helpdata
->grow
-2-helpdata
->numrows
-helpdata
->numskip
< helpdata
->command_bindings
)
336 while ((n
= ktabp
[helpdata
->command_search
].nr
) == RC_ILLEGAL
337 || ktabp
[helpdata
->command_search
].args
== noargs
)
339 if (++helpdata
->command_search
>= 256 + KMAP_KEYS
)
343 add_key_to_buf(buf
, helpdata
->command_search
);
344 PadStr(buf
, 5, 0, crow
);
345 AddAction(&ktabp
[helpdata
->command_search
++], 5, crow
);
351 sprintf(cbuf
,"[Press Space %s Return to end.]",
352 helpdata
->grow
< helpdata
->maxrow
? "for next page;" : "or");
353 centerline(cbuf
, flayer
->l_height
- 2);
368 struct mchar mchar_dol
;
370 mchar_dol
= mchar_blank
;
371 mchar_dol
.image
= '$';
373 fr
= flayer
->l_width
- 1 - x
;
376 l
= strlen(comms
[act
->nr
].name
);
380 PadStr(comms
[act
->nr
].name
, l
, x
, y
);
383 LPutChar(flayer
, fr
? &mchar_blank
: &mchar_dol
, x
++, y
);
387 while (pp
&& (cp
= *pp
) != NULL
)
392 if (!ll
|| (index(cp
, ' ') != NULL
))
394 if (index(cp
, '\'') != NULL
)
399 while (ll
-- && bp
< buf
+ 250)
400 bp
+= AddXChar(bp
, *(unsigned char *)cp
++);
404 if ((fr
-= (bp
- buf
) + 1) < 0)
408 PadStr(buf
, fr
, x
, y
);
410 LPutChar(flayer
, &mchar_dol
, x
, y
);
413 PadStr(buf
, strlen(buf
), x
, y
);
417 LPutChar(flayer
, fr
? &mchar_blank
: &mchar_dol
, x
++, y
);
422 add_key_to_buf(buf
, key
)
428 strcpy(buf
, "unset");
434 key
= key
- 256 + T_CAPS
;
436 buf
[1] = term
[key
].tcname
[0];
437 buf
[2] = term
[key
].tcname
[1];
443 buf
[AddXChar(buf
, key
)] = 0;
448 HelpRedisplayLine(y
, xs
, xe
, isblank
)
449 int y
, xs
, xe
, isblank
;
453 struct helpdata
*helpdata
;
455 helpdata
= (struct helpdata
*)flayer
->l_data
;
456 helpdata
->grow
= helpdata
->refgrow
;
457 helpdata
->command_search
= helpdata
->refcommand_search
;
461 if (y
!= 0 && y
!= flayer
->l_height
- 1)
464 LClearArea(flayer
, xs
, y
, xe
, y
, 0, 0);
470 ** here is all the copyright stuff
474 static void CopyrightProcess
__P((char **, int *));
475 static void CopyrightRedisplayLine
__P((int, int, int, int));
476 static void CopyrightAbort
__P((void));
477 static void copypage
__P((void));
481 char *cps
, *savedcps
; /* position in the message */
482 char *refcps
, *refsavedcps
; /* backup for redisplaying */
485 static struct LayFuncs CopyrightLf
=
489 CopyrightRedisplayLine
,
496 static const char cpmsg
[] = "\
500 Copyright (c) 1993-2002 Juergen Weigert, Michael Schroeder\n\
501 Copyright (c) 1987 Oliver Laumann\n\
503 This program is free software; you can redistribute it and/or \
504 modify it under the terms of the GNU General Public License as published \
505 by the Free Software Foundation; either version 2, or (at your option) \
506 any later version.\n\
508 This program is distributed in the hope that it will be useful, \
509 but WITHOUT ANY WARRANTY; without even the implied warranty of \
510 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \
511 GNU General Public License for more details.\n\
513 You should have received a copy of the GNU General Public License \
514 along with this program (see the file COPYING); if not, write to the \
515 Free Software Foundation, Inc., \
516 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n\
518 Send bugreports, fixes, enhancements, t-shirts, money, beer & pizza to \
519 screen@uni-erlangen.de\n";
523 CopyrightProcess(ppbuf
, plen
)
528 struct copydata
*copydata
;
530 copydata
= (struct copydata
*)flayer
->l_data
;
531 while (!done
&& *plen
> 0)
558 LAY_CALL_UP(LRefreshAll(flayer
, 0));
565 struct copydata
*copydata
;
567 if (flayer
->l_width
< 10 || flayer
->l_height
< 5)
569 LMsg(0, "Window size too small for copyright page");
572 if (InitOverlayPage(sizeof(*copydata
), &CopyrightLf
, 0))
574 copydata
= (struct copydata
*)flayer
->l_data
;
575 copydata
->cps
= (char *)cpmsg
;
576 copydata
->savedcps
= 0;
578 flayer
->l_y
= flayer
->l_height
- 1;
589 struct copydata
*copydata
;
592 copydata
= (struct copydata
*)flayer
->l_data
;
594 LClearAll(flayer
, 0);
597 copydata
->refcps
= cps
;
598 copydata
->refsavedcps
= copydata
->savedcps
;
599 while (*cps
&& y
< flayer
->l_height
- 3)
604 if (strncmp(cps
, "%v", 2) == 0)
606 copydata
->savedcps
= cps
+ 2;
610 while (*cps
&& *cps
!= ' ' && *cps
!= '\n')
614 if (l
> flayer
->l_width
- 1)
615 l
= flayer
->l_width
- 1;
616 if (x
&& x
+ l
>= flayer
->l_width
- 2)
624 LPutChar(flayer
, &mchar_blank
, x
, y
);
628 LPutStr(flayer
, ws
, l
, &mchar_blank
, x
, y
);
631 if (*cps
== 0 && copydata
->savedcps
)
633 cps
= copydata
->savedcps
;
634 copydata
->savedcps
= 0;
641 if (*cps
== ' ' || *cps
== '\n')
646 sprintf(cbuf
,"[Press Space %s Return to end.]",
647 *cps
? "for next page;" : "or");
648 centerline(cbuf
, flayer
->l_height
- 2);
654 CopyrightRedisplayLine(y
, xs
, xe
, isblank
)
655 int y
, xs
, xe
, isblank
;
660 struct copydata
*copydata
;
662 copydata
= (struct copydata
*)flayer
->l_data
;
663 copydata
->cps
= copydata
->refcps
;
664 copydata
->savedcps
= copydata
->refsavedcps
;
668 if (y
!= 0 && y
!= flayer
->l_height
- 1)
672 LClearArea(flayer
, xs
, y
, xe
, y
, 0, 0);
679 ** here is all the displays stuff
685 static void DisplaysProcess
__P((char **, int *));
686 static void DisplaysRedisplayLine
__P((int, int, int, int));
687 static void displayspage
__P((void));
691 int dummy_element_for_solaris
;
694 static struct LayFuncs DisplaysLf
=
698 DisplaysRedisplayLine
,
706 DisplaysProcess(ppbuf
, plen
)
713 while (!done
&& *plen
> 0)
737 if (flayer
->l_width
< 10 || flayer
->l_height
< 5)
739 LMsg(0, "Window size too small for displays page");
742 if (InitOverlayPage(sizeof(struct displaysdata
), &DisplaysLf
, 0))
745 flayer
->l_y
= flayer
->l_height
- 1;
750 * layout of the displays page is as follows:
752 xterm 80x42 jnweiger@/dev/ttyp4 0(m11) &rWx
753 facit 80x24 nb mlschroe@/dev/ttyhf 11(tcsh) rwx
754 xterm 80x42 jnhollma@/dev/ttyp5 0(m11) &R.x
756 | | | | | | | | ¦___ window permissions
757 | | | | | | | | (R. is locked r-only,
758 | | | | | | | | W has wlock)
759 | | | | | | | |___ Window is shared
760 | | | | | | |___ Name/Title of window
761 | | | | | |___ Number of window
762 | | | | |___ Name of the display (the attached device)
763 | | | |___ Username who is logged in at the display
764 | | |___ Display is in nonblocking mode. Shows 'NB' if obuf is full.
765 | |___ Displays geometry as width x height.
766 |___ the terminal type known by screen for this display.
777 static char *blockstates
[5] = {"nb", "NB", "Z<", "Z>", "BL"};
779 LClearAll(flayer
, 0);
781 leftline("term-type size user interface window", 0);
782 leftline("---------- ------- ---------- ----------------- ----------", 1);
785 for (d
= displays
; d
; d
= d
->d_next
)
789 if (y
>= flayer
->l_height
- 3)
791 sprintf(tbuf
, "%-10.10s%4dx%-4d%10.10s@%-16.16s%s",
792 d
->d_termname
, d
->d_width
, d
->d_height
, d
->d_user
->u_name
,
794 (d
->d_blocked
|| d
->d_nonblock
>= 0) && d
->d_blocked
<= 4 ? blockstates
[d
->d_blocked
] : " ");
798 l
= 10 - strlen(w
->w_title
);
801 sprintf(tbuf
+ strlen(tbuf
), "%3d(%.10s)%*s%c%c%c%c",
802 w
->w_number
, w
->w_title
, l
, "",
803 /* w->w_dlist->next */ 0 ? '&' : ' ',
806 * -,r,R no read, read, read only due to foreign wlock
807 * -,.,w,W no write, write suppressed by foreign wlock,
809 * -,x no execute, execute
812 (AclCheckPermWin(d
->d_user
, ACL_READ
, w
) ? '-' :
813 ((w
->w_wlock
== WLOCK_OFF
|| d
->d_user
== w
->w_wlockuser
) ?
815 (AclCheckPermWin(d
->d_user
, ACL_READ
, w
) ? '-' :
816 ((w
->w_wlock
== WLOCK_OFF
) ? 'w' :
817 ((d
->d_user
== w
->w_wlockuser
) ? 'W' : 'v'))),
818 (AclCheckPermWin(d
->d_user
, ACL_READ
, w
) ? '-' : 'x')
827 sprintf(tbuf
,"[Press Space %s Return to end.]",
828 1 ? "to refresh;" : "or");
829 centerline(tbuf
, flayer
->l_height
- 2);
834 DisplaysRedisplayLine(y
, xs
, xe
, isblank
)
835 int y
, xs
, xe
, isblank
;
843 if (y
!= 0 && y
!= flayer
->l_height
- 1)
847 LClearArea(flayer
, xs
, y
, xe
, y
, 0, 0);
848 /* To be filled in... */
856 ** here is the windowlist
862 static void WListProcess
__P((char **, int *));
863 static void WListRedisplayLine
__P((int, int, int, int));
864 static void wlistpage
__P((void));
865 static void WListLine
__P((int, int, int, int));
866 static void WListLines
__P((int, int));
867 static void WListMove
__P((int, int));
868 static void WListUpdate
__P((struct win
*));
869 static int WListNormalize
__P((void));
870 static int WListResize
__P((int, int));
871 static int WListNext
__P((struct wlistdata
*, int, int));
887 static struct LayFuncs WListLf
=
898 #define WTAB_GROUP_MATCHES(i) (group == wtab[i]->w_group)
904 struct wlistdata
*wlistdata
;
905 if (wi
< 10 || he
< 5)
907 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
908 flayer
->l_width
= wi
;
909 flayer
->l_height
= he
;
910 wlistdata
->numwin
= he
- 3;
911 if (wlistdata
->ypos
>= wlistdata
->numwin
)
912 wlistdata
->ypos
= wlistdata
->numwin
- 1;
913 flayer
->l_y
= he
- 1;
918 WListProcess(ppbuf
, plen
)
923 struct wlistdata
*wlistdata
;
924 struct display
*olddisplay
= display
;
929 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
930 group
= wlistdata
->group
;
931 h
= wlistdata
->numwin
;
932 while (!done
&& *plen
> 0)
934 if ((unsigned char)**ppbuf
>= '0' && (unsigned char)**ppbuf
<= '9')
936 int n
= (unsigned char)**ppbuf
- '0';
938 if (n
< MAXWIN
&& wtab
[n
] && WTAB_GROUP_MATCHES(n
))
941 for (d
= -wlistdata
->npos
, i
= WListNext(wlistdata
, -1, 0); i
!= n
; i
= WListNext(wlistdata
, i
, 1), d
++)
947 switch ((unsigned char)**ppbuf
)
950 case 16: /* ^P like emacs */
954 case 0216: /* down */
955 case 14: /* ^N like emacs */
960 WListMove(-(h
/ 2), wlistdata
->ypos
);
963 WListMove(h
/ 2, wlistdata
->ypos
);
973 case 0201: /* home */
974 WListMove(-wlistdata
->pos
, -1);
977 WListMove(MAXWIN
, -1);
983 if (h
== MAXWIN
&& Layer2Window(flayer
) && Layer2Window(flayer
)->w_type
== W_TYPE_GROUP
)
985 if (display
&& h
!= MAXWIN
&& wtab
[h
] == D_fore
)
987 wlistdata
->group
= wtab
[h
];
988 wlistdata
->pos
= wtab
[h
]->w_number
;
993 if (!display
|| h
== MAXWIN
|| !wtab
[h
] || wtab
[h
] == D_fore
|| (flayer
->l_cvlist
&& flayer
->l_cvlist
->c_lnext
))
996 else if (AclCheckPermWin(D_user
, ACL_READ
, wtab
[h
]))
1000 ExitOverlayPage(); /* no need to redisplay */
1001 /* restore display, don't switch wrong user */
1002 display
= olddisplay
;
1008 h
= wlistdata
->start
;
1009 if (h
== -1 && Layer2Window(flayer
) && Layer2Window(flayer
)->w_type
== W_TYPE_GROUP
)
1012 display
= olddisplay
;
1013 if (h
>= 0 && wtab
[h
])
1017 struct win
*p
= FindNiceWindow(display
? D_other
: (struct win
*)0, 0);
1019 SwitchWindow(p
->w_number
);
1023 case '\010': /* ctrl-h */
1025 if (!wlistdata
->group
)
1027 wlistdata
->pos
= wlistdata
->group
->w_number
;
1028 wlistdata
->group
= wlistdata
->group
->w_group
;
1029 if (wlistdata
->group
)
1030 wlistdata
->pos
= wlistdata
->group
->w_number
;
1042 WListLine(y
, i
, pos
, isblank
)
1050 struct wlistdata
*wlistdata
;
1055 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1056 if (wlistdata
->nested
&& wtab
[i
])
1057 for (group
= wtab
[i
]->w_group
, xoff
= 0; group
!= wlistdata
->group
;
1058 group
= group
->w_group
, xoff
+= 2)
1060 yoff
= wlistdata
->group
? 3 : 2;
1061 display
= Layer2Window(flayer
) ? 0 : flayer
->l_cvlist
? flayer
->l_cvlist
->c_display
: 0;
1062 str
= MakeWinMsgEv(wliststr
, wtab
[i
], '%', flayer
->l_width
- xoff
, (struct event
*)0, 0);
1064 if (i
!= pos
&& isblank
)
1065 while (n
&& str
[n
- 1] == ' ')
1067 LPutWinMsg(flayer
, str
, (i
== pos
|| !isblank
) ? flayer
->l_width
: n
, i
== pos
? &mchar_so
: &mchar_blank
, xoff
, y
+ yoff
);
1069 LPutWinMsg(flayer
, "", xoff
, i
== pos
? &mchar_so
: &mchar_blank
, 0, y
+ yoff
);
1071 LPutStr(flayer
, str
, n
, i
== pos
? &mchar_so
: &mchar_blank
, 0, y
+ yoff
);
1072 if (i
== pos
|| !isblank
)
1073 while(n
< flayer
->l_width
)
1074 LPutChar(flayer
, i
== pos
? &mchar_so
: &mchar_blank
, n
++, y
+ yoff
);
1081 WListNext(wlistdata
, old
, delta
)
1082 struct wlistdata
*wlistdata
;
1093 for (i
= 0; i
< MAXWIN
&& wlistdata
->list
[i
] != -1; i
++)
1094 if (wlistdata
->list
[i
] == old
)
1096 if (i
< MAXWIN
&& wlistdata
->list
[i
] != -1)
1101 if (old
< 0 || old
>= MAXWIN
|| wlistdata
->list
[old
] == -1)
1103 return wlistdata
->list
[old
];
1107 WListLines(up
, oldpos
)
1110 struct wlistdata
*wlistdata
;
1114 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1115 ypos
= wlistdata
->ypos
;
1116 pos
= wlistdata
->pos
;
1118 i
= WListNext(wlistdata
, pos
, -ypos
);
1119 for (y
= 0; y
< wlistdata
->numwin
; y
++)
1121 if (i
== MAXWIN
|| !wtab
[i
])
1124 wlistdata
->first
= i
;
1125 wlistdata
->last
= i
;
1126 if (((i
== oldpos
|| i
== pos
) && pos
!= oldpos
) || (up
> 0 && y
>= wlistdata
->numwin
- up
) || (up
< 0 && y
< -up
))
1127 WListLine(y
, i
, pos
, i
!= oldpos
);
1129 wlistdata
->ypos
= y
;
1131 i
= WListNext(wlistdata
, i
, 1);
1132 if (i
== MAXWIN
|| i
== oldi
)
1140 struct wlistdata
*wlistdata
;
1144 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1145 ypos
= wlistdata
->ypos
;
1146 pos
= wlistdata
->pos
;
1149 if (ypos
>= wlistdata
->numwin
)
1150 ypos
= wlistdata
->numwin
- 1;
1151 for (n
= 0, oldi
= MAXWIN
, i
= pos
; i
!= MAXWIN
&& i
!= oldi
&& n
< wlistdata
->numwin
; oldi
= i
, i
= WListNext(wlistdata
, i
, 1))
1153 if (ypos
< wlistdata
->numwin
- n
)
1154 ypos
= wlistdata
->numwin
- n
;
1155 for (n
= 0, oldi
= MAXWIN
, i
= WListNext(wlistdata
, -1, 0); i
!= MAXWIN
&& i
!= oldi
&& i
!= pos
; oldi
= i
, i
= WListNext(wlistdata
, i
, 1))
1159 wlistdata
->ypos
= ypos
;
1160 wlistdata
->npos
= n
;
1165 WListMove(num
, ypos
)
1169 struct wlistdata
*wlistdata
;
1170 int oldpos
, oldypos
, oldnpos
;
1173 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1174 oldpos
= wlistdata
->pos
;
1175 oldypos
= wlistdata
->ypos
;
1176 oldnpos
= wlistdata
->npos
;
1177 wlistdata
->ypos
= ypos
== -1 ? oldypos
+ num
: ypos
;
1178 pos
= WListNext(wlistdata
, oldpos
, num
);
1179 wlistdata
->pos
= pos
;
1180 ypos
= WListNormalize();
1181 up
= wlistdata
->npos
- ypos
- (oldnpos
- oldypos
);
1184 LScrollV(flayer
, up
, 2, 2 + wlistdata
->numwin
- 1, 0);
1185 WListLines(up
, oldpos
);
1191 WListLine(oldypos
, oldpos
, pos
, 0);
1192 WListLine(ypos
, pos
, pos
, 1);
1197 WListRedisplayLine(y
, xs
, xe
, isblank
)
1198 int y
, xs
, xe
, isblank
;
1206 if (y
!= 0 && y
!= flayer
->l_height
- 1)
1209 LClearArea(flayer
, xs
, y
, xe
, y
, 0, 0);
1213 WListOrder(wlistdata
, ind
, start
, group
)
1214 struct wlistdata
*wlistdata
;
1223 for (i
= 0; i
< MAXWIN
; i
++)
1224 wlistdata
->list
[i
] = -1;
1226 if (wlistdata
->order
== WLIST_MRU
)
1229 start
= windows
->w_number
;
1235 while (start
< MAXWIN
&& !wtab
[start
])
1239 if (start
>= MAXWIN
|| !wtab
[start
])
1242 if (!WTAB_GROUP_MATCHES(start
))
1244 while (start
< MAXWIN
&& (!wtab
[start
] || !WTAB_GROUP_MATCHES(start
)))
1245 if (wlistdata
->order
!= WLIST_MRU
)
1247 else if (wtab
[start
]->w_next
)
1248 start
= wtab
[start
]->w_next
->w_number
;
1251 if (start
>= MAXWIN
|| !wtab
[start
])
1255 wlistdata
->list
[ind
++] = start
;
1256 if (wlistdata
->nested
&& wtab
[start
]->w_type
== W_TYPE_GROUP
)
1257 ind
= WListOrder(wlistdata
, ind
, -1, wtab
[start
]);
1259 if (wlistdata
->order
!= WLIST_MRU
)
1261 else if (wtab
[start
]->w_next
)
1262 start
= wtab
[start
]->w_next
->w_number
;
1265 return WListOrder(wlistdata
, ind
, start
, group
);
1269 display_wlist(onblank
, order
, group
)
1275 struct wlistdata
*wlistdata
;
1277 if (flayer
->l_width
< 10 || flayer
->l_height
< 6)
1279 LMsg(0, "Window size too small for window list page");
1284 debug3("flayer %x %d %x\n", flayer
, flayer
->l_width
, flayer
->l_height
);
1287 LMsg(0, "windowlist -b: display required");
1293 SetForeWindow((struct win
*)0);
1296 D_fore
= p
->w_group
;
1297 flayer
->l_data
= (char *)p
->w_group
;
1301 if (flayer
->l_width
< 10 || flayer
->l_height
< 6)
1303 LMsg(0, "Window size too small for window list page");
1308 p
= Layer2Window(flayer
);
1311 if (InitOverlayPage(sizeof(*wlistdata
), &WListLf
, 0))
1313 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1315 flayer
->l_y
= flayer
->l_height
- 1;
1316 wlistdata
->start
= onblank
&& p
? p
->w_number
: -1;
1317 wlistdata
->order
= (order
& 0x1);
1318 wlistdata
->group
= group
;
1319 wlistdata
->pos
= p
? p
->w_number
: WListNext(wlistdata
, -1, 0);
1320 wlistdata
->ypos
= wlistdata
->npos
= 0;
1321 wlistdata
->numwin
= flayer
->l_height
- (group
? 4 : 3);
1322 wlistdata
->nested
= (order
& WLIST_NESTED
);
1329 struct wlistdata
*wlistdata
;
1334 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1335 group
= wlistdata
->group
;
1337 LClearAll(flayer
, 0);
1338 if (wlistdata
->start
>= 0 && wtab
[wlistdata
->start
] == 0)
1339 wlistdata
->start
= -2;
1341 WListOrder(wlistdata
, 0, -1, group
);
1342 pos
= wlistdata
->pos
;
1343 if (pos
== MAXWIN
|| !wtab
[pos
] || !WTAB_GROUP_MATCHES(pos
))
1345 if (wlistdata
->order
== WLIST_MRU
)
1346 pos
= WListNext(wlistdata
, -1, wlistdata
->npos
);
1349 /* find new position */
1351 while(++pos
< MAXWIN
)
1352 if (wtab
[pos
] && WTAB_GROUP_MATCHES(pos
))
1356 if (wtab
[pos
] && WTAB_GROUP_MATCHES(pos
))
1362 wlistdata
->pos
= pos
;
1365 str
= MakeWinMsgEv(wlisttit
, (struct win
*)0, '%', flayer
->l_width
, (struct event
*)0, 0);
1366 if (wlistdata
->group
)
1368 LPutWinMsg(flayer
, "Group: ", 7, &mchar_blank
, 0, 0);
1369 LPutWinMsg(flayer
, wlistdata
->group
->w_title
, strlen(wlistdata
->group
->w_title
), &mchar_blank
, 7, 0);
1370 LPutWinMsg(flayer
, str
, strlen(str
), &mchar_blank
, 0, 1);
1374 LPutWinMsg(flayer
, str
, strlen(str
), &mchar_blank
, 0, 0);
1377 WListLines(wlistdata
->numwin
, -1);
1385 struct wlistdata
*wlistdata
;
1393 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1395 if (wlistdata
->order
== WLIST_NUM
&& (n
< wlistdata
->first
|| n
> wlistdata
->last
))
1397 i
= wlistdata
->first
;
1398 for (y
= 0; y
< wlistdata
->numwin
; y
++)
1402 i
= WListNext(wlistdata
, i
, 1);
1404 if (y
== wlistdata
->numwin
)
1406 WListLine(y
, i
, wlistdata
->pos
, 0);
1411 WListUpdatecv(cv
, p
)
1415 if (cv
->c_layer
->l_layfn
!= &WListLf
)
1417 CV_CALL(cv
, WListUpdate(p
));
1423 struct display
*olddisplay
= display
;
1425 struct wlistdata
*wlistdata
;
1427 for (display
= displays
; display
; display
= display
->d_next
)
1428 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
1430 if (!cv
->c_layer
|| cv
->c_layer
->l_layfn
!= &WListLf
)
1432 wlistdata
= (struct wlistdata
*)cv
->c_layer
->l_data
;
1433 if (wlistdata
->order
!= WLIST_MRU
)
1435 CV_CALL(cv
, WListUpdate(0));
1437 display
= olddisplay
;
1443 if (flayer
&& flayer
->l_layfn
== &WListLf
)
1452 ** The bindkey help page
1457 extern struct kmap_ext
*kmap_exts
;
1458 extern int kmap_extn
;
1459 extern struct action dmtab
[];
1460 extern struct action mmtab
[];
1463 static void BindkeyProcess
__P((char **, int *));
1464 static void BindkeyAbort
__P((void));
1465 static void BindkeyRedisplayLine
__P((int, int, int, int));
1466 static void bindkeypage
__P((void));
1478 static struct LayFuncs BindkeyLf
=
1482 BindkeyRedisplayLine
,
1491 display_bindkey(title
, tab
)
1495 struct bindkeydata
*bindkeydata
;
1498 if (flayer
->l_height
< 6)
1500 LMsg(0, "Window height too small for bindkey page");
1503 if (InitOverlayPage(sizeof(*bindkeydata
), &BindkeyLf
, 0))
1506 bindkeydata
= (struct bindkeydata
*)flayer
->l_data
;
1507 bindkeydata
->title
= title
;
1508 bindkeydata
->tab
= tab
;
1511 for (i
= 0; i
< KMAP_KEYS
+KMAP_AKEYS
+kmap_extn
; i
++)
1513 if (tab
[i
].nr
!= RC_ILLEGAL
)
1516 bindkeydata
->pos
= 0;
1517 bindkeydata
->page
= 1;
1518 bindkeydata
->pages
= (n
+ flayer
->l_height
- 6) / (flayer
->l_height
- 5);
1519 if (bindkeydata
->pages
== 0)
1520 bindkeydata
->pages
= 1;
1522 flayer
->l_y
= flayer
->l_height
- 1;
1529 LAY_CALL_UP(LRefreshAll(flayer
, 0));
1536 struct bindkeydata
*bindkeydata
;
1537 struct kmap_ext
*kme
;
1543 bindkeydata
= (struct bindkeydata
*)flayer
->l_data
;
1545 LClearAll(flayer
, 0);
1547 sprintf(tbuf
, "%s key bindings, page %d of %d.", bindkeydata
->title
, bindkeydata
->page
, bindkeydata
->pages
);
1548 centerline(tbuf
, 0);
1550 for (i
= bindkeydata
->pos
; i
< KMAP_KEYS
+KMAP_AKEYS
+kmap_extn
&& y
< flayer
->l_height
- 3; i
++)
1556 act
= &bindkeydata
->tab
[i
];
1557 if (act
->nr
== RC_ILLEGAL
)
1560 s
= term
[i
+ T_CAPS
].tcname
;
1561 sl
= s
? strlen(s
) : 0;
1563 else if (i
< KMAP_KEYS
+KMAP_AKEYS
)
1565 act
= &bindkeydata
->tab
[i
];
1566 if (act
->nr
== RC_ILLEGAL
)
1569 s
= term
[i
+ (T_CAPS
- T_OCAPS
+ T_CURSOR
)].tcname
;
1570 sl
= s
? strlen(s
) : 0;
1575 kme
= kmap_exts
+ (i
- (KMAP_KEYS
+KMAP_AKEYS
));
1578 sl
= kme
->fl
& ~KMAP_NOTIMEOUT
;
1579 if ((kme
->fl
& KMAP_NOTIMEOUT
) != 0)
1581 act
= bindkeydata
->tab
== dmtab
? &kme
->dm
: bindkeydata
->tab
== mmtab
? &kme
->mm
: &kme
->um
;
1582 if (act
->nr
== RC_ILLEGAL
)
1586 p
+= AddXChar(p
, *(unsigned char *)s
++);
1590 while (p
< tbuf
+ 15)
1592 sprintf(p
, "%s -> ", xch
);
1594 if (p
- tbuf
> flayer
->l_width
- 1)
1596 tbuf
[flayer
->l_width
- 2] = '$';
1597 tbuf
[flayer
->l_width
- 1] = 0;
1599 PadStr(tbuf
, strlen(tbuf
), 0, y
);
1600 AddAction(act
, strlen(tbuf
), y
);
1604 bindkeydata
->last
= i
;
1605 sprintf(tbuf
,"[Press Space %s Return to end.]", bindkeydata
->page
< bindkeydata
->pages
? "for next page;" : "or");
1606 centerline(tbuf
, flayer
->l_height
- 2);
1611 BindkeyProcess(ppbuf
, plen
)
1616 struct bindkeydata
*bindkeydata
;
1618 bindkeydata
= (struct bindkeydata
*)flayer
->l_data
;
1619 while (!done
&& *plen
> 0)
1624 if (bindkeydata
->page
< bindkeydata
->pages
)
1626 bindkeydata
->pos
= bindkeydata
->last
;
1627 bindkeydata
->page
++;
1647 BindkeyRedisplayLine(y
, xs
, xe
, isblank
)
1648 int y
, xs
, xe
, isblank
;
1655 if (y
!= 0 && y
!= flayer
->l_height
- 1)
1658 LClearArea(flayer
, xs
, y
, xe
, y
, 0, 0);
1661 #endif /* MAPKEYS */
1666 ** The zmodem active page
1672 static void ZmodemRedisplayLine
__P((int, int, int, int));
1673 static int ZmodemResize
__P((int, int));
1675 static struct LayFuncs ZmodemLf
=
1679 ZmodemRedisplayLine
,
1688 ZmodemResize(wi
, he
)
1691 flayer
->l_width
= wi
;
1692 flayer
->l_height
= he
;
1693 flayer
->l_x
= flayer
->l_width
> 32 ? 32 : 0;
1698 ZmodemRedisplayLine(y
, xs
, xe
, isblank
)
1699 int y
, xs
, xe
, isblank
;
1701 DefRedisplayLine(y
, xs
, xe
, isblank
);
1702 if (y
== 0 && xs
== 0)
1703 LPutStr(flayer
, "Zmodem active on another display", flayer
->l_width
> 32 ? 32 : flayer
->l_width
, &mchar_blank
, 0, 0);
1709 if (InitOverlayPage(1, &ZmodemLf
, 1))
1711 LRefreshAll(flayer
, 0);
1712 flayer
->l_x
= flayer
->l_width
> 32 ? 32 : 0;
1721 PadStr(str
, n
, x
, y
)
1730 LPutStr(flayer
, str
, l
, &mchar_blank
, x
, y
);
1732 LPutStr(flayer
, (char *)blank
, n
- l
, &mchar_blank
, x
+ l
, y
);