2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Micah Cowan (micah@cowan.name)
5 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
6 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
7 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
8 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
9 * Copyright (c) 1987 Oliver Laumann
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, see
23 * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 ****************************************************************
29 #include <sys/types.h>
36 char version
[60]; /* initialised by main() */
38 extern struct layer
*flayer
;
39 extern struct display
*display
, *displays
;
40 extern struct win
*windows
;
41 extern char *noargs
[];
42 extern struct mchar mchar_blank
, mchar_so
;
43 extern unsigned char *blank
;
44 extern struct win
*wtab
[];
46 extern struct term term
[];
49 static void PadStr
__P((char *, int, int, int));
51 extern char *wliststr
;
52 extern char *wlisttit
;
55 exit_with_usage(myname
, message
, arg
)
56 char *myname
, *message
, *arg
;
58 printf("Use: %s [-opts] [cmd [args]]\n", myname
);
59 printf(" or: %s -r [host.tty]\n\nOptions:\n", myname
);
60 printf("-a Force all capabilities into each window's termcap.\n");
61 printf("-A -[r|R] Adapt all windows to the new display width & height.\n");
62 printf("-c file Read configuration file instead of '.screenrc'.\n");
64 printf("-d (-r) Detach the elsewhere running screen (and reattach here).\n");
65 printf("-dmS name Start as daemon: Screen session in detached mode.\n");
66 printf("-D (-r) Detach and logout remote (and reattach here).\n");
67 printf("-D -RR Do whatever is needed to get a screen session.\n");
69 printf("-e xy Change command characters.\n");
70 printf("-f Flow control on, -fn = off, -fa = auto.\n");
71 printf("-h lines Set the size of the scrollback history buffer.\n");
72 printf("-i Interrupt output sooner when flow control is on.\n");
73 #if defined(LOGOUTOK) && defined(UTMPOK)
74 printf("-l Login mode on (update %s), -ln = off.\n", UTMPFILE
);
76 printf("-list or -ls. Do nothing, just list our SockDir.\n");
77 printf("-L Turn on output logging.\n");
78 printf("-m ignore $STY variable, do create a new screen session.\n");
79 printf("-O Choose optimal output rather than exact vt100 emulation.\n");
80 printf("-p window Preselect the named window if it exists.\n");
81 printf("-q Quiet startup. Exits with non-zero return code if unsuccessful.\n");
82 printf("-r Reattach to a detached screen process.\n");
83 printf("-R Reattach if possible, otherwise start a new session.\n");
84 printf("-s shell Shell to execute rather than $SHELL.\n");
85 printf("-S sockname Name this session <pid>.sockname instead of <pid>.<tty>.<host>.\n");
86 printf("-t title Set title. (window's name).\n");
87 printf("-T term Use term as $TERM for windows, rather than \"screen\".\n");
89 printf("-U Tell screen to use UTF-8 encoding.\n");
91 printf("-v Print \"Screen version %s\".\n", version
);
92 printf("-wipe Do nothing, just clean up SockDir.\n");
94 printf("-x Attach to a not detached screen. (Multi display mode).\n");
96 printf("-X Execute <cmd> as a screen command in the specified session.\n");
97 if (message
&& *message
)
100 printf(message
, arg
);
107 ** Here come the help page routines
110 extern struct comm comms
[];
111 extern struct action ktab
[];
113 static void HelpProcess
__P((char **, int *));
114 static void HelpAbort
__P((void));
115 static void HelpRedisplayLine
__P((int, int, int, int));
116 static void add_key_to_buf
__P((char *, int));
117 static void AddAction
__P((struct action
*, int, int));
118 static int helppage
__P((void));
123 struct action
*ktabp
;
124 int maxrow
, grow
, numcols
, numrows
, num_names
;
125 int numskip
, numpages
;
126 int command_search
, command_bindings
;
127 int refgrow
, refcommand_search
;
128 int inter
, mcom
, mkey
;
129 int nact
[RC_LAST
+ 1];
134 static struct LayFuncs HelpLf
=
147 display_help(class, ktabp
)
149 struct action
*ktabp
;
151 int i
, n
, key
, mcom
, mkey
, l
;
152 struct helpdata
*helpdata
;
153 int used
[RC_LAST
+ 1];
155 if (flayer
->l_height
< 6)
157 LMsg(0, "Window height too small for help page");
160 if (InitOverlayPage(sizeof(*helpdata
), &HelpLf
, 0))
163 helpdata
= (struct helpdata
*)flayer
->l_data
;
164 helpdata
->class = class;
165 helpdata
->ktabp
= ktabp
;
166 helpdata
->num_names
= helpdata
->command_bindings
= 0;
167 helpdata
->command_search
= 0;
168 for (n
= 0; n
<= RC_LAST
; n
++)
172 for (key
= 0; key
< 256 + KMAP_KEYS
; key
++)
177 if (ktabp
[key
].args
== noargs
)
179 used
[n
] += (key
<= ' ' || key
== 0x7f) ? 3 :
180 (key
> 0x7f) ? 5 : 2;
183 helpdata
->command_bindings
++;
185 for (n
= i
= 0; n
<= RC_LAST
; n
++)
188 l
= strlen(comms
[n
].name
);
193 helpdata
->nact
[i
++] = n
;
195 debug1("help: %d commands bound to keys with no arguments\n", i
);
196 debug2("mcom: %d mkey: %d\n", mcom
, mkey
);
197 helpdata
->num_names
= i
;
201 helpdata
->numcols
= flayer
->l_width
/ (mcom
+ mkey
+ 1);
202 if (helpdata
->numcols
== 0)
205 LMsg(0, "Width too small");
208 helpdata
->inter
= (flayer
->l_width
- (mcom
+ mkey
) * helpdata
->numcols
) / (helpdata
->numcols
+ 1);
209 if (helpdata
->inter
<= 0)
211 debug1("inter: %d\n", helpdata
->inter
);
212 helpdata
->mcom
= mcom
;
213 helpdata
->mkey
= mkey
;
214 helpdata
->numrows
= (helpdata
->num_names
+ helpdata
->numcols
- 1) / helpdata
->numcols
;
215 debug1("Numrows: %d\n", helpdata
->numrows
);
216 helpdata
->numskip
= flayer
->l_height
-5 - (2 + helpdata
->numrows
);
217 while (helpdata
->numskip
< 0)
218 helpdata
->numskip
+= flayer
->l_height
-5;
219 helpdata
->numskip
%= flayer
->l_height
-5;
220 debug1("Numskip: %d\n", helpdata
->numskip
);
221 if (helpdata
->numskip
> flayer
->l_height
/3 || helpdata
->numskip
> helpdata
->command_bindings
)
222 helpdata
->numskip
= 1;
223 helpdata
->maxrow
= 2 + helpdata
->numrows
+ helpdata
->numskip
+ helpdata
->command_bindings
;
226 helpdata
->numpages
= (helpdata
->maxrow
+ flayer
->l_height
-6) / (flayer
->l_height
-5);
228 flayer
->l_y
= flayer
->l_height
- 1;
233 HelpProcess(ppbuf
, plen
)
239 while (!done
&& *plen
> 0)
264 LAY_CALL_UP(LRefreshAll(flayer
, 0));
272 struct helpdata
*helpdata
;
273 int col
, crow
, n
, key
, x
;
274 char buf
[MAXKLEN
], Esc_buf
[5], cbuf
[256];
275 struct action
*ktabp
;
277 helpdata
= (struct helpdata
*)flayer
->l_data
;
279 ktabp
= helpdata
->ktabp
;
280 if (helpdata
->grow
>= helpdata
->maxrow
)
282 helpdata
->refgrow
= helpdata
->grow
;
283 helpdata
->refcommand_search
= helpdata
->command_search
;
285 /* Clear the help screen */
286 LClearAll(flayer
, 0);
288 sprintf(cbuf
,"Screen key bindings, page %d of %d.", helpdata
->grow
/ (flayer
->l_height
-5) + 1, helpdata
->numpages
);
294 /* XXX fix escape character */
295 if (flayer
->l_cvlist
&& flayer
->l_cvlist
->c_display
)
297 add_key_to_buf(buf
, flayer
->l_cvlist
->c_display
->d_user
->u_MetaEsc
);
298 add_key_to_buf(Esc_buf
, flayer
->l_cvlist
->c_display
->d_user
->u_Esc
);
302 strcpy(Esc_buf
, "??");
306 for (; crow
< flayer
->l_height
- 3; crow
++)
308 if (helpdata
->grow
< 1)
311 sprintf(cbuf
,"Command key: %s Literal %s: %s", Esc_buf
, Esc_buf
, buf
);
313 sprintf(cbuf
,"Command class: '%.80s'", helpdata
->class);
314 centerline(cbuf
, crow
);
317 else if (helpdata
->grow
>= 2 && helpdata
->grow
-2 < helpdata
->numrows
)
320 for (col
= 0; col
< helpdata
->numcols
&& (n
= helpdata
->numrows
* col
+ (helpdata
->grow
-2)) < helpdata
->num_names
; col
++)
322 x
+= helpdata
->inter
- !col
;
323 n
= helpdata
->nact
[n
];
325 for (key
= 0; key
< 256 + KMAP_KEYS
; key
++)
326 if (ktabp
[key
].nr
== n
&& ktabp
[key
].args
== noargs
&& strlen(buf
) < sizeof(buf
) - 7)
329 add_key_to_buf(buf
, key
);
331 PadStr(comms
[n
].name
, helpdata
->mcom
, x
, crow
);
333 PadStr(buf
, helpdata
->mkey
, x
, crow
);
338 else if (helpdata
->grow
-2-helpdata
->numrows
>= helpdata
->numskip
339 && helpdata
->grow
-2-helpdata
->numrows
-helpdata
->numskip
< helpdata
->command_bindings
)
341 while ((n
= ktabp
[helpdata
->command_search
].nr
) == RC_ILLEGAL
342 || ktabp
[helpdata
->command_search
].args
== noargs
)
344 if (++helpdata
->command_search
>= 256 + KMAP_KEYS
)
348 add_key_to_buf(buf
, helpdata
->command_search
);
349 PadStr(buf
, 5, 0, crow
);
350 AddAction(&ktabp
[helpdata
->command_search
++], 5, crow
);
356 sprintf(cbuf
,"[Press Space %s Return to end.]",
357 helpdata
->grow
< helpdata
->maxrow
? "for next page;" : "or");
358 centerline(cbuf
, flayer
->l_height
- 2);
373 struct mchar mchar_dol
;
375 mchar_dol
= mchar_blank
;
376 mchar_dol
.image
= '$';
378 fr
= flayer
->l_width
- 1 - x
;
381 l
= strlen(comms
[act
->nr
].name
);
385 PadStr(comms
[act
->nr
].name
, l
, x
, y
);
388 LPutChar(flayer
, fr
? &mchar_blank
: &mchar_dol
, x
++, y
);
392 while (pp
&& (cp
= *pp
) != NULL
)
397 if (!ll
|| (index(cp
, ' ') != NULL
))
399 if (index(cp
, '\'') != NULL
)
404 while (ll
-- && bp
< buf
+ 250)
405 bp
+= AddXChar(bp
, *(unsigned char *)cp
++);
409 if ((fr
-= (bp
- buf
) + 1) < 0)
413 PadStr(buf
, fr
, x
, y
);
415 LPutChar(flayer
, &mchar_dol
, x
, y
);
418 PadStr(buf
, strlen(buf
), x
, y
);
422 LPutChar(flayer
, fr
? &mchar_blank
: &mchar_dol
, x
++, y
);
427 add_key_to_buf(buf
, key
)
433 strcpy(buf
, "unset");
439 key
= key
- 256 + T_CAPS
;
441 buf
[1] = term
[key
].tcname
[0];
442 buf
[2] = term
[key
].tcname
[1];
448 buf
[AddXChar(buf
, key
)] = 0;
453 HelpRedisplayLine(y
, xs
, xe
, isblank
)
454 int y
, xs
, xe
, isblank
;
458 struct helpdata
*helpdata
;
460 helpdata
= (struct helpdata
*)flayer
->l_data
;
461 helpdata
->grow
= helpdata
->refgrow
;
462 helpdata
->command_search
= helpdata
->refcommand_search
;
466 if (y
!= 0 && y
!= flayer
->l_height
- 1)
469 LClearArea(flayer
, xs
, y
, xe
, y
, 0, 0);
475 ** here is all the copyright stuff
479 static void CopyrightProcess
__P((char **, int *));
480 static void CopyrightRedisplayLine
__P((int, int, int, int));
481 static void CopyrightAbort
__P((void));
482 static void copypage
__P((void));
486 char *cps
, *savedcps
; /* position in the message */
487 char *refcps
, *refsavedcps
; /* backup for redisplaying */
490 static struct LayFuncs CopyrightLf
=
494 CopyrightRedisplayLine
,
501 static const char cpmsg
[] = "\
505 Copyright (c) 2008 Juergen Weigert, Michael Schroeder, Micah Cowan, Sadrul Habib Chowdhury\n\
506 Copyright (c) 1993-2002, 2003, 2005, 2006, 2007 Juergen Weigert, Michael Schroeder\n\
507 Copyright (c) 1987 Oliver Laumann\n\
509 This program is free software; you can redistribute it and/or \
510 modify it under the terms of the GNU General Public License as published \
511 by the Free Software Foundation; either version 3, or (at your option) \
512 any later version.\n\
514 This program is distributed in the hope that it will be useful, \
515 but WITHOUT ANY WARRANTY; without even the implied warranty of \
516 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \
517 GNU General Public License for more details.\n\
519 You should have received a copy of the GNU General Public License \
520 along with this program (see the file COPYING); if not, see \
521 http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc., \
522 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA.\n\
524 Send bugreports, fixes, enhancements, t-shirts, money, beer & pizza to \
525 screen@uni-erlangen.de\n";
529 CopyrightProcess(ppbuf
, plen
)
534 struct copydata
*copydata
;
536 copydata
= (struct copydata
*)flayer
->l_data
;
537 while (!done
&& *plen
> 0)
564 LAY_CALL_UP(LRefreshAll(flayer
, 0));
571 struct copydata
*copydata
;
573 if (flayer
->l_width
< 10 || flayer
->l_height
< 5)
575 LMsg(0, "Window size too small for copyright page");
578 if (InitOverlayPage(sizeof(*copydata
), &CopyrightLf
, 0))
580 copydata
= (struct copydata
*)flayer
->l_data
;
581 copydata
->cps
= (char *)cpmsg
;
582 copydata
->savedcps
= 0;
584 flayer
->l_y
= flayer
->l_height
- 1;
595 struct copydata
*copydata
;
598 copydata
= (struct copydata
*)flayer
->l_data
;
600 LClearAll(flayer
, 0);
603 copydata
->refcps
= cps
;
604 copydata
->refsavedcps
= copydata
->savedcps
;
605 while (*cps
&& y
< flayer
->l_height
- 3)
610 if (strncmp(cps
, "%v", 2) == 0)
612 copydata
->savedcps
= cps
+ 2;
616 while (*cps
&& *cps
!= ' ' && *cps
!= '\n')
620 if (l
> flayer
->l_width
- 1)
621 l
= flayer
->l_width
- 1;
622 if (x
&& x
+ l
>= flayer
->l_width
- 2)
630 LPutChar(flayer
, &mchar_blank
, x
, y
);
634 LPutStr(flayer
, ws
, l
, &mchar_blank
, x
, y
);
637 if (*cps
== 0 && copydata
->savedcps
)
639 cps
= copydata
->savedcps
;
640 copydata
->savedcps
= 0;
647 if (*cps
== ' ' || *cps
== '\n')
652 sprintf(cbuf
,"[Press Space %s Return to end.]",
653 *cps
? "for next page;" : "or");
654 centerline(cbuf
, flayer
->l_height
- 2);
660 CopyrightRedisplayLine(y
, xs
, xe
, isblank
)
661 int y
, xs
, xe
, isblank
;
666 struct copydata
*copydata
;
668 copydata
= (struct copydata
*)flayer
->l_data
;
669 copydata
->cps
= copydata
->refcps
;
670 copydata
->savedcps
= copydata
->refsavedcps
;
674 if (y
!= 0 && y
!= flayer
->l_height
- 1)
678 LClearArea(flayer
, xs
, y
, xe
, y
, 0, 0);
685 ** here is all the displays stuff
691 static void DisplaysProcess
__P((char **, int *));
692 static void DisplaysRedisplayLine
__P((int, int, int, int));
693 static void displayspage
__P((void));
697 int dummy_element_for_solaris
;
700 static struct LayFuncs DisplaysLf
=
704 DisplaysRedisplayLine
,
712 DisplaysProcess(ppbuf
, plen
)
719 while (!done
&& *plen
> 0)
743 if (flayer
->l_width
< 10 || flayer
->l_height
< 5)
745 LMsg(0, "Window size too small for displays page");
748 if (InitOverlayPage(sizeof(struct displaysdata
), &DisplaysLf
, 0))
751 flayer
->l_y
= flayer
->l_height
- 1;
756 * layout of the displays page is as follows:
758 xterm 80x42 jnweiger@/dev/ttyp4 0(m11) &rWx
759 facit 80x24 nb mlschroe@/dev/ttyhf 11(tcsh) rwx
760 xterm 80x42 jnhollma@/dev/ttyp5 0(m11) &R.x
762 | | | | | | | | ¦___ window permissions
763 | | | | | | | | (R. is locked r-only,
764 | | | | | | | | W has wlock)
765 | | | | | | | |___ Window is shared
766 | | | | | | |___ Name/Title of window
767 | | | | | |___ Number of window
768 | | | | |___ Name of the display (the attached device)
769 | | | |___ Username who is logged in at the display
770 | | |___ Display is in nonblocking mode. Shows 'NB' if obuf is full.
771 | |___ Displays geometry as width x height.
772 |___ the terminal type known by screen for this display.
783 static char *blockstates
[5] = {"nb", "NB", "Z<", "Z>", "BL"};
785 LClearAll(flayer
, 0);
787 leftline("term-type size user interface window", 0);
788 leftline("---------- ------- ---------- ----------------- ----------", 1);
791 for (d
= displays
; d
; d
= d
->d_next
)
795 if (y
>= flayer
->l_height
- 3)
797 sprintf(tbuf
, "%-10.10s%4dx%-4d%10.10s@%-16.16s%s",
798 d
->d_termname
, d
->d_width
, d
->d_height
, d
->d_user
->u_name
,
800 (d
->d_blocked
|| d
->d_nonblock
>= 0) && d
->d_blocked
<= 4 ? blockstates
[d
->d_blocked
] : " ");
804 l
= 10 - strlen(w
->w_title
);
807 sprintf(tbuf
+ strlen(tbuf
), "%3d(%.10s)%*s%c%c%c%c",
808 w
->w_number
, w
->w_title
, l
, "",
809 /* w->w_dlist->next */ 0 ? '&' : ' ',
812 * -,r,R no read, read, read only due to foreign wlock
813 * -,.,w,W no write, write suppressed by foreign wlock,
815 * -,x no execute, execute
818 (AclCheckPermWin(d
->d_user
, ACL_READ
, w
) ? '-' :
819 ((w
->w_wlock
== WLOCK_OFF
|| d
->d_user
== w
->w_wlockuser
) ?
821 (AclCheckPermWin(d
->d_user
, ACL_READ
, w
) ? '-' :
822 ((w
->w_wlock
== WLOCK_OFF
) ? 'w' :
823 ((d
->d_user
== w
->w_wlockuser
) ? 'W' : 'v'))),
824 (AclCheckPermWin(d
->d_user
, ACL_READ
, w
) ? '-' : 'x')
833 sprintf(tbuf
,"[Press Space %s Return to end.]",
834 1 ? "to refresh;" : "or");
835 centerline(tbuf
, flayer
->l_height
- 2);
840 DisplaysRedisplayLine(y
, xs
, xe
, isblank
)
841 int y
, xs
, xe
, isblank
;
849 if (y
!= 0 && y
!= flayer
->l_height
- 1)
853 LClearArea(flayer
, xs
, y
, xe
, y
, 0, 0);
854 /* To be filled in... */
862 ** here is the windowlist
868 static void WListProcess
__P((char **, int *));
869 static void WListRedisplayLine
__P((int, int, int, int));
870 static void wlistpage
__P((void));
871 static void WListLine
__P((int, int, int, int));
872 static void WListLines
__P((int, int));
873 static void WListMove
__P((int, int));
874 static void WListUpdate
__P((struct win
*));
875 static int WListNormalize
__P((void));
876 static int WListResize
__P((int, int));
877 static int WListNext
__P((struct wlistdata
*, int, int));
893 static struct LayFuncs WListLf
=
904 #define WTAB_GROUP_MATCHES(i) (group == wtab[i]->w_group)
910 struct wlistdata
*wlistdata
;
911 if (wi
< 10 || he
< 5)
913 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
914 flayer
->l_width
= wi
;
915 flayer
->l_height
= he
;
916 wlistdata
->numwin
= he
- 3;
917 if (wlistdata
->ypos
>= wlistdata
->numwin
)
918 wlistdata
->ypos
= wlistdata
->numwin
- 1;
919 flayer
->l_y
= he
- 1;
924 WListProcess(ppbuf
, plen
)
929 struct wlistdata
*wlistdata
;
930 struct display
*olddisplay
= display
;
935 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
936 group
= wlistdata
->group
;
937 h
= wlistdata
->numwin
;
938 while (!done
&& *plen
> 0)
940 if ((unsigned char)**ppbuf
>= '0' && (unsigned char)**ppbuf
<= '9')
942 int n
= (unsigned char)**ppbuf
- '0';
944 if (n
< MAXWIN
&& wtab
[n
] && WTAB_GROUP_MATCHES(n
))
947 for (d
= -wlistdata
->npos
, i
= WListNext(wlistdata
, -1, 0); i
!= n
; i
= WListNext(wlistdata
, i
, 1), d
++)
953 switch ((unsigned char)**ppbuf
)
956 case 16: /* ^P like emacs */
960 case 0216: /* down */
961 case 14: /* ^N like emacs */
966 WListMove(-(h
/ 2), wlistdata
->ypos
);
969 WListMove(h
/ 2, wlistdata
->ypos
);
979 case 0201: /* home */
980 WListMove(-wlistdata
->pos
, -1);
983 WListMove(MAXWIN
, -1);
986 /* All-window view */
987 wlistdata
->group
= 0;
988 wlistdata
->nested
= WLIST_NESTED
;
992 /* Toggle nested view */
993 wlistdata
->nested
^= WLIST_NESTED
;
997 /* Toggle MRU view */
998 wlistdata
->order
^= 1;
1005 if (h
== MAXWIN
&& Layer2Window(flayer
) && Layer2Window(flayer
)->w_type
== W_TYPE_GROUP
)
1007 if (display
&& h
!= MAXWIN
&& wtab
[h
] && (wtab
[h
]->w_type
== W_TYPE_GROUP
|| wtab
[h
] == D_fore
))
1009 wlistdata
->group
= wtab
[h
];
1010 wlistdata
->pos
= wtab
[h
]->w_number
;
1015 if (!display
|| h
== MAXWIN
|| !wtab
[h
] || wtab
[h
] == D_fore
|| (flayer
->l_cvlist
&& flayer
->l_cvlist
->c_lnext
))
1018 else if (AclCheckPermWin(D_user
, ACL_READ
, wtab
[h
]))
1022 ExitOverlayPage(); /* no need to redisplay */
1023 /* restore display, don't switch wrong user */
1024 display
= olddisplay
;
1030 h
= wlistdata
->start
;
1031 if (h
== -1 && Layer2Window(flayer
) && Layer2Window(flayer
)->w_type
== W_TYPE_GROUP
)
1033 struct win
*p
= Layer2Window(flayer
);
1034 if (wlistdata
->group
!= p
)
1036 wlistdata
->group
= p
;
1042 display
= olddisplay
;
1043 if (h
>= 0 && wtab
[h
])
1047 struct win
*p
= FindNiceWindow(display
? D_other
: (struct win
*)0, 0);
1049 SwitchWindow(p
->w_number
);
1053 case '\010': /* ctrl-h */
1055 if (!wlistdata
->group
)
1057 wlistdata
->pos
= wlistdata
->group
->w_number
;
1058 wlistdata
->group
= wlistdata
->group
->w_group
;
1059 if (wlistdata
->group
)
1060 wlistdata
->pos
= wlistdata
->group
->w_number
;
1072 WListLine(y
, i
, pos
, isblank
)
1080 struct wlistdata
*wlistdata
;
1085 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1086 if (wlistdata
->nested
&& wtab
[i
])
1087 for (group
= wtab
[i
]->w_group
, xoff
= 0; group
!= wlistdata
->group
;
1088 group
= group
->w_group
, xoff
+= 2)
1090 yoff
= wlistdata
->group
? 3 : 2;
1091 display
= Layer2Window(flayer
) ? 0 : flayer
->l_cvlist
? flayer
->l_cvlist
->c_display
: 0;
1092 str
= MakeWinMsgEv(wliststr
, wtab
[i
], '%', flayer
->l_width
- xoff
, (struct event
*)0, 0);
1094 if (i
!= pos
&& isblank
)
1095 while (n
&& str
[n
- 1] == ' ')
1097 LPutWinMsg(flayer
, str
, (i
== pos
|| !isblank
) ? flayer
->l_width
: n
, i
== pos
? &mchar_so
: &mchar_blank
, xoff
, y
+ yoff
);
1099 LPutWinMsg(flayer
, "", xoff
, i
== pos
? &mchar_so
: &mchar_blank
, 0, y
+ yoff
);
1101 LPutStr(flayer
, str
, n
, i
== pos
? &mchar_so
: &mchar_blank
, 0, y
+ yoff
);
1102 if (i
== pos
|| !isblank
)
1103 while(n
< flayer
->l_width
)
1104 LPutChar(flayer
, i
== pos
? &mchar_so
: &mchar_blank
, n
++, y
+ yoff
);
1111 WListNext(wlistdata
, old
, delta
)
1112 struct wlistdata
*wlistdata
;
1123 for (i
= 0; i
< MAXWIN
&& wlistdata
->list
[i
] != -1; i
++)
1124 if (wlistdata
->list
[i
] == old
)
1126 if (i
< MAXWIN
&& wlistdata
->list
[i
] != -1)
1131 if (old
< 0 || old
>= MAXWIN
|| wlistdata
->list
[old
] == -1)
1133 return wlistdata
->list
[old
];
1137 WListLines(up
, oldpos
)
1140 struct wlistdata
*wlistdata
;
1144 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1145 ypos
= wlistdata
->ypos
;
1146 pos
= wlistdata
->pos
;
1148 i
= WListNext(wlistdata
, pos
, -ypos
);
1149 for (y
= 0; y
< wlistdata
->numwin
; y
++)
1151 if (i
== MAXWIN
|| !wtab
[i
])
1154 wlistdata
->first
= i
;
1155 wlistdata
->last
= i
;
1156 if (((i
== oldpos
|| i
== pos
) && pos
!= oldpos
) || (up
> 0 && y
>= wlistdata
->numwin
- up
) || (up
< 0 && y
< -up
))
1157 WListLine(y
, i
, pos
, i
!= oldpos
);
1159 wlistdata
->ypos
= y
;
1161 i
= WListNext(wlistdata
, i
, 1);
1162 if (i
== MAXWIN
|| i
== oldi
)
1170 struct wlistdata
*wlistdata
;
1174 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1175 ypos
= wlistdata
->ypos
;
1176 pos
= wlistdata
->pos
;
1179 if (ypos
>= wlistdata
->numwin
)
1180 ypos
= wlistdata
->numwin
- 1;
1181 for (n
= 0, oldi
= MAXWIN
, i
= pos
; i
!= MAXWIN
&& i
!= oldi
&& n
< wlistdata
->numwin
; oldi
= i
, i
= WListNext(wlistdata
, i
, 1))
1183 if (ypos
< wlistdata
->numwin
- n
)
1184 ypos
= wlistdata
->numwin
- n
;
1185 for (n
= 0, oldi
= MAXWIN
, i
= WListNext(wlistdata
, -1, 0); i
!= MAXWIN
&& i
!= oldi
&& i
!= pos
; oldi
= i
, i
= WListNext(wlistdata
, i
, 1))
1189 wlistdata
->ypos
= ypos
;
1190 wlistdata
->npos
= n
;
1195 WListMove(num
, ypos
)
1199 struct wlistdata
*wlistdata
;
1200 int oldpos
, oldypos
, oldnpos
;
1203 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1204 oldpos
= wlistdata
->pos
;
1205 oldypos
= wlistdata
->ypos
;
1206 oldnpos
= wlistdata
->npos
;
1207 wlistdata
->ypos
= ypos
== -1 ? oldypos
+ num
: ypos
;
1208 pos
= WListNext(wlistdata
, oldpos
, num
);
1209 wlistdata
->pos
= pos
;
1210 ypos
= WListNormalize();
1211 up
= wlistdata
->npos
- ypos
- (oldnpos
- oldypos
);
1214 LScrollV(flayer
, up
, 2, 2 + wlistdata
->numwin
- 1, 0);
1215 WListLines(up
, oldpos
);
1221 WListLine(oldypos
, oldpos
, pos
, 0);
1222 WListLine(ypos
, pos
, pos
, 1);
1227 WListRedisplayLine(y
, xs
, xe
, isblank
)
1228 int y
, xs
, xe
, isblank
;
1236 if (y
!= 0 && y
!= flayer
->l_height
- 1)
1239 LClearArea(flayer
, xs
, y
, xe
, y
, 0, 0);
1243 WListOrder(wlistdata
, ind
, start
, group
)
1244 struct wlistdata
*wlistdata
;
1253 for (i
= 0; i
< MAXWIN
; i
++)
1254 wlistdata
->list
[i
] = -1;
1256 if (wlistdata
->order
== WLIST_MRU
)
1259 start
= windows
->w_number
;
1265 while (start
< MAXWIN
&& !wtab
[start
])
1269 if (start
>= MAXWIN
|| !wtab
[start
])
1272 if (!WTAB_GROUP_MATCHES(start
))
1274 while (start
< MAXWIN
&& (!wtab
[start
] || !WTAB_GROUP_MATCHES(start
)))
1275 if (wlistdata
->order
!= WLIST_MRU
)
1277 else if (wtab
[start
]->w_next
)
1278 start
= wtab
[start
]->w_next
->w_number
;
1281 if (start
>= MAXWIN
|| !wtab
[start
])
1285 wlistdata
->list
[ind
++] = start
;
1286 if (wlistdata
->nested
&& wtab
[start
]->w_type
== W_TYPE_GROUP
)
1287 ind
= WListOrder(wlistdata
, ind
, -1, wtab
[start
]);
1289 if (wlistdata
->order
!= WLIST_MRU
)
1291 else if (wtab
[start
]->w_next
)
1292 start
= wtab
[start
]->w_next
->w_number
;
1295 return WListOrder(wlistdata
, ind
, start
, group
);
1299 display_wlist(onblank
, order
, group
)
1305 struct wlistdata
*wlistdata
;
1307 if (flayer
->l_width
< 10 || flayer
->l_height
< 6)
1309 LMsg(0, "Window size too small for window list page");
1314 debug3("flayer %x %d %x\n", flayer
, flayer
->l_width
, flayer
->l_height
);
1317 LMsg(0, "windowlist -b: display required");
1323 SetForeWindow((struct win
*)0);
1326 D_fore
= p
->w_group
;
1327 flayer
->l_data
= (char *)p
->w_group
;
1331 if (flayer
->l_width
< 10 || flayer
->l_height
< 6)
1333 LMsg(0, "Window size too small for window list page");
1338 p
= Layer2Window(flayer
);
1341 if (InitOverlayPage(sizeof(*wlistdata
), &WListLf
, 0))
1343 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1345 flayer
->l_y
= flayer
->l_height
- 1;
1346 wlistdata
->start
= onblank
&& p
? p
->w_number
: -1;
1347 wlistdata
->order
= (order
& 0x1);
1348 wlistdata
->group
= group
;
1349 wlistdata
->pos
= p
? p
->w_number
: WListNext(wlistdata
, -1, 0);
1350 wlistdata
->ypos
= wlistdata
->npos
= 0;
1351 wlistdata
->numwin
= flayer
->l_height
- (group
? 4 : 3);
1352 wlistdata
->nested
= (order
& WLIST_NESTED
);
1359 struct wlistdata
*wlistdata
;
1364 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1365 group
= wlistdata
->group
;
1367 LClearAll(flayer
, 0);
1368 if (wlistdata
->start
>= 0 && wtab
[wlistdata
->start
] == 0)
1369 wlistdata
->start
= -2;
1371 WListOrder(wlistdata
, 0, -1, group
);
1372 pos
= wlistdata
->pos
;
1373 if (pos
== MAXWIN
|| !wtab
[pos
] || !WTAB_GROUP_MATCHES(pos
))
1375 if (wlistdata
->order
== WLIST_MRU
)
1376 pos
= WListNext(wlistdata
, -1, wlistdata
->npos
);
1379 /* find new position */
1381 while(++pos
< MAXWIN
)
1382 if (wtab
[pos
] && WTAB_GROUP_MATCHES(pos
))
1386 if (wtab
[pos
] && WTAB_GROUP_MATCHES(pos
))
1392 wlistdata
->pos
= pos
;
1395 str
= MakeWinMsgEv(wlisttit
, (struct win
*)0, '%', flayer
->l_width
, (struct event
*)0, 0);
1396 if (wlistdata
->group
)
1398 LPutWinMsg(flayer
, "Group: ", 7, &mchar_blank
, 0, 0);
1399 LPutWinMsg(flayer
, wlistdata
->group
->w_title
, strlen(wlistdata
->group
->w_title
), &mchar_blank
, 7, 0);
1400 LPutWinMsg(flayer
, str
, strlen(str
), &mchar_blank
, 0, 1);
1404 LPutWinMsg(flayer
, str
, strlen(str
), &mchar_blank
, 0, 0);
1407 WListLines(wlistdata
->numwin
, -1);
1415 struct wlistdata
*wlistdata
;
1423 wlistdata
= (struct wlistdata
*)flayer
->l_data
;
1425 if (wlistdata
->order
== WLIST_NUM
&& (n
< wlistdata
->first
|| n
> wlistdata
->last
))
1427 i
= wlistdata
->first
;
1428 for (y
= 0; y
< wlistdata
->numwin
; y
++)
1432 i
= WListNext(wlistdata
, i
, 1);
1434 if (y
== wlistdata
->numwin
)
1436 WListLine(y
, i
, wlistdata
->pos
, 0);
1441 WListUpdatecv(cv
, p
)
1445 if (cv
->c_layer
->l_layfn
!= &WListLf
)
1447 CV_CALL(cv
, WListUpdate(p
));
1453 struct display
*olddisplay
= display
;
1455 struct wlistdata
*wlistdata
;
1457 for (display
= displays
; display
; display
= display
->d_next
)
1458 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
1460 if (!cv
->c_layer
|| cv
->c_layer
->l_layfn
!= &WListLf
)
1462 wlistdata
= (struct wlistdata
*)cv
->c_layer
->l_data
;
1463 if (wlistdata
->order
!= WLIST_MRU
)
1465 CV_CALL(cv
, WListUpdate(0));
1467 display
= olddisplay
;
1473 if (flayer
&& flayer
->l_layfn
== &WListLf
)
1482 ** The bindkey help page
1487 extern struct kmap_ext
*kmap_exts
;
1488 extern int kmap_extn
;
1489 extern struct action dmtab
[];
1490 extern struct action mmtab
[];
1493 static void BindkeyProcess
__P((char **, int *));
1494 static void BindkeyAbort
__P((void));
1495 static void BindkeyRedisplayLine
__P((int, int, int, int));
1496 static void bindkeypage
__P((void));
1508 static struct LayFuncs BindkeyLf
=
1512 BindkeyRedisplayLine
,
1521 display_bindkey(title
, tab
)
1525 struct bindkeydata
*bindkeydata
;
1528 if (flayer
->l_height
< 6)
1530 LMsg(0, "Window height too small for bindkey page");
1533 if (InitOverlayPage(sizeof(*bindkeydata
), &BindkeyLf
, 0))
1536 bindkeydata
= (struct bindkeydata
*)flayer
->l_data
;
1537 bindkeydata
->title
= title
;
1538 bindkeydata
->tab
= tab
;
1541 for (i
= 0; i
< KMAP_KEYS
+KMAP_AKEYS
+kmap_extn
; i
++)
1543 if (tab
[i
].nr
!= RC_ILLEGAL
)
1546 bindkeydata
->pos
= 0;
1547 bindkeydata
->page
= 1;
1548 bindkeydata
->pages
= (n
+ flayer
->l_height
- 6) / (flayer
->l_height
- 5);
1549 if (bindkeydata
->pages
== 0)
1550 bindkeydata
->pages
= 1;
1552 flayer
->l_y
= flayer
->l_height
- 1;
1559 LAY_CALL_UP(LRefreshAll(flayer
, 0));
1566 struct bindkeydata
*bindkeydata
;
1567 struct kmap_ext
*kme
;
1573 bindkeydata
= (struct bindkeydata
*)flayer
->l_data
;
1575 LClearAll(flayer
, 0);
1577 sprintf(tbuf
, "%s key bindings, page %d of %d.", bindkeydata
->title
, bindkeydata
->page
, bindkeydata
->pages
);
1578 centerline(tbuf
, 0);
1580 for (i
= bindkeydata
->pos
; i
< KMAP_KEYS
+KMAP_AKEYS
+kmap_extn
&& y
< flayer
->l_height
- 3; i
++)
1586 act
= &bindkeydata
->tab
[i
];
1587 if (act
->nr
== RC_ILLEGAL
)
1590 s
= term
[i
+ T_CAPS
].tcname
;
1591 sl
= s
? strlen(s
) : 0;
1593 else if (i
< KMAP_KEYS
+KMAP_AKEYS
)
1595 act
= &bindkeydata
->tab
[i
];
1596 if (act
->nr
== RC_ILLEGAL
)
1599 s
= term
[i
+ (T_CAPS
- T_OCAPS
+ T_CURSOR
)].tcname
;
1600 sl
= s
? strlen(s
) : 0;
1605 kme
= kmap_exts
+ (i
- (KMAP_KEYS
+KMAP_AKEYS
));
1608 sl
= kme
->fl
& ~KMAP_NOTIMEOUT
;
1609 if ((kme
->fl
& KMAP_NOTIMEOUT
) != 0)
1611 act
= bindkeydata
->tab
== dmtab
? &kme
->dm
: bindkeydata
->tab
== mmtab
? &kme
->mm
: &kme
->um
;
1612 if (act
->nr
== RC_ILLEGAL
)
1616 p
+= AddXChar(p
, *(unsigned char *)s
++);
1620 while (p
< tbuf
+ 15)
1622 sprintf(p
, "%s -> ", xch
);
1624 if (p
- tbuf
> flayer
->l_width
- 1)
1626 tbuf
[flayer
->l_width
- 2] = '$';
1627 tbuf
[flayer
->l_width
- 1] = 0;
1629 PadStr(tbuf
, strlen(tbuf
), 0, y
);
1630 AddAction(act
, strlen(tbuf
), y
);
1634 bindkeydata
->last
= i
;
1635 sprintf(tbuf
,"[Press Space %s Return to end.]", bindkeydata
->page
< bindkeydata
->pages
? "for next page;" : "or");
1636 centerline(tbuf
, flayer
->l_height
- 2);
1641 BindkeyProcess(ppbuf
, plen
)
1646 struct bindkeydata
*bindkeydata
;
1648 bindkeydata
= (struct bindkeydata
*)flayer
->l_data
;
1649 while (!done
&& *plen
> 0)
1654 if (bindkeydata
->page
< bindkeydata
->pages
)
1656 bindkeydata
->pos
= bindkeydata
->last
;
1657 bindkeydata
->page
++;
1677 BindkeyRedisplayLine(y
, xs
, xe
, isblank
)
1678 int y
, xs
, xe
, isblank
;
1685 if (y
!= 0 && y
!= flayer
->l_height
- 1)
1688 LClearArea(flayer
, xs
, y
, xe
, y
, 0, 0);
1691 #endif /* MAPKEYS */
1696 ** The zmodem active page
1702 static void ZmodemRedisplayLine
__P((int, int, int, int));
1703 static int ZmodemResize
__P((int, int));
1705 static struct LayFuncs ZmodemLf
=
1709 ZmodemRedisplayLine
,
1718 ZmodemResize(wi
, he
)
1721 flayer
->l_width
= wi
;
1722 flayer
->l_height
= he
;
1723 flayer
->l_x
= flayer
->l_width
> 32 ? 32 : 0;
1728 ZmodemRedisplayLine(y
, xs
, xe
, isblank
)
1729 int y
, xs
, xe
, isblank
;
1731 DefRedisplayLine(y
, xs
, xe
, isblank
);
1732 if (y
== 0 && xs
== 0)
1733 LPutStr(flayer
, "Zmodem active on another display", flayer
->l_width
> 32 ? 32 : flayer
->l_width
, &mchar_blank
, 0, 0);
1739 if (InitOverlayPage(1, &ZmodemLf
, 1))
1741 LRefreshAll(flayer
, 0);
1742 flayer
->l_x
= flayer
->l_width
> 32 ? 32 : 0;
1751 PadStr(str
, n
, x
, y
)
1760 LPutStr(flayer
, str
, l
, &mchar_blank
, x
, y
);
1762 LPutStr(flayer
, (char *)blank
, n
- l
, &mchar_blank
, x
+ l
, y
);