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>
29 # include <sys/ioctl.h>
36 #include "logfile.h" /* logfopen() */
38 extern struct display
*displays
, *display
;
39 extern struct win
*windows
, *fore
, *wtab
[], *console_window
;
40 extern char *ShellArgs
[];
41 extern char *ShellProg
;
42 extern char screenterm
[];
43 extern char *screenlogfile
;
44 extern char HostName
[];
46 extern int SilenceWait
;
47 extern int real_uid
, real_gid
, eff_uid
, eff_gid
;
48 extern char Termcap
[];
50 extern int visual_bell
, maxwin
;
51 extern struct event logflushev
;
52 extern int log_flush
, logtstamp_after
;
53 extern int ZombieKey_destroy
, ZombieKey_resurrect
, ZombieKey_onerror
;
54 extern struct layer
*flayer
;
55 extern int maxusercount
;
56 extern int pty_preopen
;
58 extern int zmodem_mode
;
59 extern struct mchar mchar_blank
;
60 extern char *zmodem_sendcmd
;
61 extern char *zmodem_recvcmd
;
64 #if defined(TIOCSWINSZ) || defined(TIOCGWINSZ)
65 extern struct winsize glwz
;
69 extern int separate_sids
;
72 static void WinProcess
__P((char **, int *));
73 static void WinRedisplayLine
__P((int, int, int, int));
74 static void WinClearLine
__P((int, int, int, int));
75 static int WinRewrite
__P((int, int, int, struct mchar
*, int));
76 static int WinResize
__P((int, int));
77 static void WinRestore
__P((void));
78 static int DoAutolf
__P((char *, int *, int));
79 static void ZombieProcess
__P((char **, int *));
80 static void win_readev_fn
__P((struct event
*, char *));
81 static void win_writeev_fn
__P((struct event
*, char *));
82 static int muchpending
__P((struct win
*, struct event
*));
84 static void paste_slowev_fn
__P((struct event
*, char *));
87 static void pseu_readev_fn
__P((struct event
*, char *));
88 static void pseu_writeev_fn
__P((struct event
*, char *));
90 static void win_silenceev_fn
__P((struct event
*, char *));
92 static int OpenDevice
__P((char **, int, int *, char **));
93 static int ForkWindow
__P((struct win
*, char **, char *));
95 static void zmodem_found
__P((struct win
*, int, char *, int));
96 static void zmodem_fin
__P((char *, int, char *));
97 static int zmodem_parse
__P((struct win
*, char *, int));
102 int VerboseCreate
= 0; /* XXX move this to user.h */
104 char DefaultShell
[] = "/bin/sh";
105 static char DefaultPath
[] = ":/usr/ucb:/bin:/usr/bin";
107 /* keep this in sync with the structure definition in window.h */
108 struct NewWindow nwin_undef
=
112 (char **)0, /* args */
114 (char *)0, /* term */
129 (char *)0, /* hstatus */
130 (char *)0 /* charset */
133 struct NewWindow nwin_default
=
137 ShellArgs
, /* args */
139 screenterm
, /* term */
141 1*FLOW_NOW
, /* flowflag */
142 LOGINDEFAULT
, /* lflag */
143 DEFAULTHISTHEIGHT
, /* histheight */
144 MON_OFF
, /* monitor */
145 WLOCK_OFF
, /* wlock */
154 (char *)0, /* hstatus */
155 (char *)0 /* charset */
158 struct NewWindow nwin_options
;
160 static int const_IOSIZE
= IOSIZE
;
161 static int const_one
= 1;
164 nwin_compose(def
, new, res
)
165 struct NewWindow
*def
, *new, *res
;
167 #define COMPOSE(x) res->x = new->x != nwin_undef.x ? new->x : def->x
192 /*****************************************************************
194 * The window layer functions
197 struct LayFuncs WinLf
=
209 DoAutolf(buf
, lenp
, fr
)
218 for (p
= buf
; len
> 0; p
++, len
--)
229 bcopy(p
, p
+ 1, len
++);
237 WinProcess(bufpp
, lenp
)
241 int l2
= 0, f
, *ilen
, l
= *lenp
, trunc
;
244 debug1("WinProcess: %d bytes\n", *lenp
);
245 fore
= (struct win
*)flayer
->l_data
;
247 if (fore
->w_type
== W_TYPE_GROUP
)
253 if (fore
->w_ptyfd
< 0) /* zombie? */
255 ZombieProcess(bufpp
, lenp
);
259 /* a pending writelock is this:
260 * fore->w_wlock == WLOCK_AUTO, fore->w_wlockuse = NULL
261 * The user who wants to use this window next, will get the lock, if he can.
263 if (display
&& fore
->w_wlock
== WLOCK_AUTO
&&
264 !fore
->w_wlockuser
&& !AclCheckPermWin(D_user
, ACL_WRITE
, fore
))
266 fore
->w_wlockuser
= D_user
;
267 debug2("window %d: pending writelock grabbed by user %s\n",
268 fore
->w_number
, fore
->w_wlockuser
->u_name
);
270 /* if w_wlock is set, only one user may write, else we check acls */
271 if (display
&& ((fore
->w_wlock
== WLOCK_OFF
) ?
272 AclCheckPermWin(D_user
, ACL_WRITE
, fore
) :
273 (D_user
!= fore
->w_wlockuser
)))
275 debug2("window %d, user %s: ", fore
->w_number
, D_user
->u_name
);
276 debug2("writelock %d (wlockuser %s)\n", fore
->w_wlock
,
277 fore
->w_wlockuser
? fore
->w_wlockuser
->u_name
: "NULL");
278 /* XXX FIXME only display !*/
279 WBell(fore
, visual_bell
);
284 #endif /* MULTIUSER */
286 #ifdef BUILTIN_TELNET
287 if (fore
->w_type
== W_TYPE_TELNET
&& TelIsline(fore
) && *bufpp
!= fore
->w_telbuf
)
289 TelProcessLine(bufpp
, lenp
);
297 /* we send the user input to our pseudowin */
298 ibuf
= fore
->w_pwin
->p_inbuf
; ilen
= &fore
->w_pwin
->p_inlen
;
299 f
= sizeof(fore
->w_pwin
->p_inbuf
) - *ilen
;
304 /* we send the user input to the window */
305 ibuf
= fore
->w_inbuf
; ilen
= &fore
->w_inlen
;
306 f
= sizeof(fore
->w_inbuf
) - *ilen
;
311 #ifdef BUILTIN_TELNET
318 bcopy(*bufpp
, ibuf
+ *ilen
, l2
);
319 if (fore
->w_autolf
&& (trunc
= DoAutolf(ibuf
+ *ilen
, &l2
, f
- l2
)))
321 #ifdef BUILTIN_TELNET
322 if (fore
->w_type
== W_TYPE_TELNET
&& (trunc
= DoTelnet(ibuf
+ *ilen
, &l2
, f
- l2
)))
326 continue; /* need exact value */
337 ZombieProcess(bufpp
, lenp
)
342 char *buf
= *bufpp
, b1
[10], b2
[10];
344 debug1("ZombieProcess: %d bytes\n", *lenp
);
345 fore
= (struct win
*)flayer
->l_data
;
347 ASSERT(fore
->w_ptyfd
< 0);
350 for (; l
-- > 0; buf
++)
352 if (*(unsigned char *)buf
== ZombieKey_destroy
)
354 debug1("Turning undead: %d\n", fore
->w_number
);
358 if (*(unsigned char *)buf
== ZombieKey_resurrect
)
360 debug1("Resurrecting Zombie: %d\n", fore
->w_number
);
361 WriteString(fore
, "\r\n", 2);
366 b1
[AddXChar(b1
, ZombieKey_destroy
)] = '\0';
367 b2
[AddXChar(b2
, ZombieKey_resurrect
)] = '\0';
368 Msg(0, "Press %s to destroy or %s to resurrect window", b1
, b2
);
372 WinRedisplayLine(y
, from
, to
, isblank
)
373 int y
, from
, to
, isblank
;
375 debug3("WinRedisplayLine %d %d %d\n", y
, from
, to
);
378 fore
= (struct win
*)flayer
->l_data
;
379 if (from
== 0 && y
> 0 && fore
->w_mlines
[y
- 1].image
[fore
->w_width
] == 0)
380 LCDisplayLineWrap(&fore
->w_layer
, &fore
->w_mlines
[y
], y
, from
, to
, isblank
);
382 LCDisplayLine(&fore
->w_layer
, &fore
->w_mlines
[y
], y
, from
, to
, isblank
);
386 WinRewrite(y
, x1
, x2
, rend
, doit
)
390 register int cost
, dx
;
391 register unsigned char *p
, *i
;
393 register unsigned char *f
;
396 register unsigned char *c
;
398 register unsigned char *cx
;
402 debug3("WinRewrite %d, %d-%d\n", y
, x1
, x2
);
403 fore
= (struct win
*)flayer
->l_data
;
407 i
= fore
->w_mlines
[y
].image
+ x1
;
412 p
= fore
->w_mlines
[y
].attr
+ x1
;
414 f
= fore
->w_mlines
[y
].font
+ x1
;
416 if (is_dw_font(rend
->font
))
420 if (fore
->w_encoding
&& fore
->w_encoding
!= UTF8
&& D_encoding
== UTF8
&& ContainsSpecialDeffont(fore
->w_mlines
+ y
, x1
, x2
, fore
->w_encoding
))
425 c
= fore
->w_mlines
[y
].color
+ x1
;
427 cx
= fore
->w_mlines
[y
].colorx
+ x1
;
431 cost
= dx
= x2
- x1
+ 1;
434 if (*p
++ != rend
->attr
)
437 if (*f
++ != rend
->font
)
441 if (*c
++ != rend
->color
)
444 if (*cx
++ != rend
->colorx
)
453 WinClearLine(y
, xs
, xe
, bce
)
456 fore
= (struct win
*)flayer
->l_data
;
457 debug3("WinClearLine %d %d-%d\n", y
, xs
, xe
);
458 LClearLine(flayer
, y
, xs
, xe
, bce
, &fore
->w_mlines
[y
]);
465 fore
= (struct win
*)flayer
->l_data
;
466 ChangeWindowSize(fore
, wi
, he
, fore
->w_histheight
);
474 fore
= (struct win
*)flayer
->l_data
;
475 debug1("WinRestore: win %p\n", fore
);
476 for (cv
= flayer
->l_cvlist
; cv
; cv
= cv
->c_next
)
478 display
= cv
->c_display
;
481 /* ChangeScrollRegion(fore->w_top, fore->w_bot); */
482 KeypadMode(fore
->w_keypad
);
483 CursorkeysMode(fore
->w_cursorkeys
);
484 SetFlow(fore
->w_flow
& FLOW_NOW
);
485 InsertMode(fore
->w_insert
);
486 ReverseVideo(fore
->w_revvid
);
487 CursorVisibility(fore
->w_curinv
? -1 : fore
->w_curvvis
);
488 MouseMode(fore
->w_mouse
);
492 /*****************************************************************/
496 * DoStartLog constructs a path for the "want to be logfile" in buf and
499 * returns 0 on success.
502 DoStartLog(w
, buf
, bufsize
)
511 strncpy(buf
, MakeWinMsg(screenlogfile
, w
, '%'), bufsize
- 1);
512 buf
[bufsize
- 1] = 0;
514 debug2("DoStartLog: win %d, file %s\n", w
->w_number
, buf
);
516 if (w
->w_log
!= NULL
)
519 if ((w
->w_log
= logfopen(buf
, islogfile(buf
) ? NULL
: secfopen(buf
, "a"))) == NULL
)
521 if (!logflushev
.queued
)
523 n
= log_flush
? log_flush
: (logtstamp_after
+ 4) / 5;
526 SetTimeout(&logflushev
, n
* 1000);
534 * Umask & wlock are set for the user of the display,
535 * The display d (if specified) switches to that window.
539 struct NewWindow
*newwin
;
541 register struct win
**pp
, *p
;
544 struct NewWindow nwin
;
548 extern struct acluser
*users
;
551 debug1("NewWindow: StartAt %d\n", newwin
->StartAt
);
552 debug1("NewWindow: aka %s\n", newwin
->aka
?newwin
->aka
:"NULL");
553 debug1("NewWindow: dir %s\n", newwin
->dir
?newwin
->dir
:"NULL");
554 debug1("NewWindow: term %s\n", newwin
->term
?newwin
->term
:"NULL");
556 nwin_compose(&nwin_default
, newwin
, &nwin
);
557 debug1("NWin: aka %s\n", nwin
.aka
? nwin
.aka
: "NULL");
558 debug1("NWin: wlock %d\n", nwin
.wlock
);
559 debug1("NWin: Lflag %d\n", nwin
.Lflag
);
561 startat
= nwin
.StartAt
< maxwin
? nwin
.StartAt
: 0;
568 if (++pp
== wtab
+ maxwin
)
571 while (pp
!= wtab
+ startat
);
574 Msg(0, "No more windows.");
578 #if defined(USRLIMIT) && defined(UTMPOK)
580 * Count current number of users, if logging windows in.
582 if (nwin
.lflag
&& CountUsers() >= USRLIMIT
)
584 Msg(0, "User limit reached. Window will not be logged in.");
589 debug1("Makewin creating %d\n", n
);
591 if ((f
= OpenDevice(nwin
.args
, nwin
.lflag
, &type
, &TtyName
)) < 0)
593 if (type
== W_TYPE_GROUP
)
596 if ((p
= (struct win
*)malloc(sizeof(struct win
))) == 0)
602 bzero((char *)p
, (int)sizeof(struct win
));
605 if (type
!= W_TYPE_PTY
)
611 /* save the command line so that zombies can be resurrected */
612 for (i
= 0; nwin
.args
[i
] && i
< MAXARGS
- 1; i
++)
613 p
->w_cmdargs
[i
] = SaveStr(nwin
.args
[i
]);
616 p
->w_dir
= SaveStr(nwin
.dir
);
618 p
->w_term
= SaveStr(nwin
.term
);
622 if (p
->w_type
!= W_TYPE_GROUP
&& fore
&& fore
->w_type
== W_TYPE_GROUP
)
624 else if (p
->w_type
!= W_TYPE_GROUP
&& fore
&& fore
->w_group
)
625 p
->w_group
= fore
->w_group
;
628 * This is dangerous: without a display we use creators umask
629 * This is intended to be usefull for detached startup.
630 * But is still better than default bits with a NULL user.
632 if (NewWindowAcl(p
, display
? D_user
: users
))
640 p
->w_layer
.l_next
= 0;
641 p
->w_layer
.l_bottom
= &p
->w_layer
;
642 p
->w_layer
.l_layfn
= &WinLf
;
643 p
->w_layer
.l_data
= (char *)p
;
644 p
->w_savelayer
= &p
->w_layer
;
649 if (display
&& !AclCheckPermWin(D_user
, ACL_WRITE
, p
))
650 p
->w_wlockuser
= D_user
;
651 p
->w_wlock
= nwin
.wlock
;
654 p
->w_aflag
= nwin
.aflag
;
655 p
->w_flow
= nwin
.flowflag
| ((nwin
.flowflag
& FLOW_AUTOFLAG
) ? (FLOW_AUTO
|FLOW_NOW
) : FLOW_AUTO
);
657 nwin
.aka
= Filename(nwin
.args
[0]);
658 strncpy(p
->w_akabuf
, nwin
.aka
, sizeof(p
->w_akabuf
) - 1);
659 if ((nwin
.aka
= rindex(p
->w_akabuf
, '|')) != NULL
)
663 p
->w_title
= nwin
.aka
;
664 p
->w_akachange
= nwin
.aka
+ strlen(nwin
.aka
);
667 p
->w_title
= p
->w_akachange
= p
->w_akabuf
;
669 p
->w_hstatus
= SaveStr(nwin
.hstatus
);
670 p
->w_monitor
= nwin
.monitor
;
672 if (p
->w_monitor
== MON_ON
)
674 /* always tell all users */
675 for (i
= 0; i
< maxusercount
; i
++)
676 ACLBYTE(p
->w_mon_notify
, i
) |= ACLBIT(i
);
680 * defsilence by Lloyd Zusman (zusman_lloyd@jpmorgan.com)
682 p
->w_silence
= nwin
.silence
;
683 p
->w_silencewait
= SilenceWait
;
685 if (p
->w_silence
== SILENCE_ON
)
687 /* always tell all users */
688 for (i
= 0; i
< maxusercount
; i
++)
689 ACLBYTE(p
->w_lio_notify
, i
) |= ACLBIT(i
);
693 p
->w_slowpaste
= nwin
.slow
;
699 strncpy(p
->w_tty
, TtyName
, MAXSTR
- 1);
702 /* XXX Fixme display resize */
703 if (ChangeWindowSize(p
, display
? D_defwidth
: 80,
704 display
? D_defheight
: 24,
711 if (ChangeWindowSize(p
, display
? D_forecv
->c_xe
- D_forecv
->c_xs
+ 1: 80,
712 display
? D_forecv
->c_ye
- D_forecv
->c_ys
+ 1 : 24,
720 p
->w_encoding
= nwin
.encoding
;
721 ResetWindow(p
); /* sets w_wrap, w_c1, w_gr, w_bce */
725 SetCharsets(p
, nwin
.charset
);
728 if (VerboseCreate
&& type
!= W_TYPE_GROUP
)
730 struct display
*d
= display
; /* WriteString zaps display */
732 WriteString(p
, ":screen (", 9);
733 WriteString(p
, p
->w_title
, strlen(p
->w_title
));
734 WriteString(p
, "):", 2);
735 for (f
= 0; p
->w_cmdargs
[f
]; f
++)
737 WriteString(p
, " ", 1);
738 WriteString(p
, p
->w_cmdargs
[f
], strlen(p
->w_cmdargs
[f
]));
740 WriteString(p
, "\r\n", 2);
750 #ifdef BUILTIN_TELNET
751 if (type
== W_TYPE_TELNET
)
761 if (type
== W_TYPE_PTY
)
763 p
->w_pid
= ForkWindow(p
, nwin
.args
, TtyName
);
772 * Place the new window at the head of the most-recently-used list.
774 if (display
&& D_fore
)
780 if (type
== W_TYPE_GROUP
)
783 Activate(p
->w_norefresh
);
784 WindowChanged((struct win
*)0, 'w');
785 WindowChanged((struct win
*)0, 'W');
786 WindowChanged((struct win
*)0, 0);
790 p
->w_lflag
= nwin
.lflag
;
792 p
->w_slot
= (slot_t
)-1;
794 debug1("MakeWindow will %slog in.\n", nwin
.lflag
?"":"not ");
796 # else /* LOGOUTOK */
797 debug1("MakeWindow will log in, LOGOUTOK undefined in config.h%s.\n",
798 nwin
.lflag
?"":" (although lflag=0)");
799 # endif /* LOGOUTOK */
801 p
->w_slot
= (slot_t
)0;
802 if (display
|| (p
->w_lflag
& 2))
806 CarefulUtmp(); /* If all 've been zombies, we've had no slot */
813 DoStartLog(p
, buf
, sizeof(buf
));
816 p
->w_readev
.fd
= p
->w_writeev
.fd
= p
->w_ptyfd
;
817 p
->w_readev
.type
= EV_READ
;
818 p
->w_writeev
.type
= EV_WRITE
;
819 p
->w_readev
.data
= p
->w_writeev
.data
= (char *)p
;
820 p
->w_readev
.handler
= win_readev_fn
;
821 p
->w_writeev
.handler
= win_writeev_fn
;
822 p
->w_writeev
.condpos
= &p
->w_inlen
;
824 evenq(&p
->w_writeev
);
826 p
->w_paster
.pa_slowev
.type
= EV_TIMEOUT
;
827 p
->w_paster
.pa_slowev
.data
= (char *)&p
->w_paster
;
828 p
->w_paster
.pa_slowev
.handler
= paste_slowev_fn
;
830 p
->w_silenceev
.type
= EV_TIMEOUT
;
831 p
->w_silenceev
.data
= (char *)p
;
832 p
->w_silenceev
.handler
= win_silenceev_fn
;
833 if (p
->w_silence
> 0)
835 debug("New window has silence enabled.\n");
836 SetTimeout(&p
->w_silenceev
, p
->w_silencewait
* 1000);
837 evenq(&p
->w_silenceev
);
841 Activate(p
->w_norefresh
);
842 WindowChanged((struct win
*)0, 'w');
843 WindowChanged((struct win
*)0, 'W');
844 WindowChanged((struct win
*)0, 0);
849 * Resurrect a window from Zombie state.
850 * The command vector is therefore stored in the window structure.
851 * Note: The terminaltype defaults to screenterm again, the current
852 * working directory is lost.
861 lflag
= nwin_default
.lflag
;
862 if ((f
= OpenDevice(p
->w_cmdargs
, lflag
, &p
->w_type
, &TtyName
)) < 0)
865 strncpy(p
->w_tty
, *TtyName
? TtyName
: p
->w_title
, MAXSTR
- 1);
870 evenq(&p
->w_writeev
);
874 struct display
*d
= display
; /* WriteString zaps display */
876 WriteString(p
, ":screen (", 9);
877 WriteString(p
, p
->w_title
, strlen(p
->w_title
));
878 WriteString(p
, "):", 2);
879 for (f
= 0; p
->w_cmdargs
[f
]; f
++)
881 WriteString(p
, " ", 1);
882 WriteString(p
, p
->w_cmdargs
[f
], strlen(p
->w_cmdargs
[f
]));
884 WriteString(p
, "\r\n", 2);
890 #ifdef BUILTIN_TELNET
891 if (p
->w_type
== W_TYPE_TELNET
)
898 if (p
->w_type
== W_TYPE_PTY
)
900 p
->w_pid
= ForkWindow(p
, p
->w_cmdargs
, TtyName
);
906 if (p
->w_slot
== (slot_t
)0 && (display
|| (p
->w_lflag
& 2)))
909 CarefulUtmp(); /* If all 've been zombies, we've had no slot */
912 WindowChanged(p
, 'f');
922 if (wp
->w_type
== W_TYPE_PTY
)
925 (void)chmod(wp
->w_tty
, 0666);
926 (void)chown(wp
->w_tty
, 0, 0);
931 evdeq(&wp
->w_readev
);
932 evdeq(&wp
->w_writeev
);
933 #ifdef BUILTIN_TELNET
934 evdeq(&wp
->w_telconnev
);
936 wp
->w_readev
.fd
= wp
->w_writeev
.fd
= -1;
945 struct canvas
*cv
, *ncv
;
948 debug1("FreeWindow %d\n", wp
? wp
->w_number
: -1);
958 if (wp
== console_window
)
960 TtyGrabConsole(-1, -1, "free");
963 if (wp
->w_log
!= NULL
)
964 logfclose(wp
->w_log
);
965 ChangeWindowSize(wp
, 0, 0, 0);
967 if (wp
->w_type
== W_TYPE_GROUP
)
970 for (win
= windows
; win
; win
= win
->w_next
)
971 if (win
->w_group
== wp
)
972 win
->w_group
= wp
->w_group
;
977 for (i
= 0; wp
->w_cmdargs
[i
]; i
++)
978 free(wp
->w_cmdargs
[i
]);
983 for (d
= displays
; d
; d
= d
->d_next
)
985 if (d
->d_other
== wp
)
986 d
->d_other
= d
->d_fore
&& d
->d_fore
->w_next
!= wp
? d
->d_fore
->w_next
: wp
->w_next
;
989 for (cv
= d
->d_cvlist
; cv
; cv
= cv
->c_next
)
991 for (l
= cv
->c_layer
; l
; l
= l
->l_next
)
992 if (l
->l_layfn
== &WinLf
)
996 if ((struct win
*)l
->l_data
!= wp
)
998 if (cv
->c_layer
== wp
->w_savelayer
)
1000 KillLayerChain(cv
->c_layer
);
1003 if (wp
->w_savelayer
)
1004 KillLayerChain(wp
->w_savelayer
);
1005 for (cv
= wp
->w_layer
.l_cvlist
; cv
; cv
= ncv
)
1008 cv
->c_layer
= &cv
->c_blank
;
1009 cv
->c_blank
.l_cvlist
= cv
;
1011 cv
->c_xoff
= cv
->c_xs
;
1012 cv
->c_yoff
= cv
->c_ys
;
1013 RethinkViewportOffsets(cv
);
1015 wp
->w_layer
.l_cvlist
= 0;
1016 if (flayer
== &wp
->w_layer
)
1021 #endif /* MULTIUSER */
1022 evdeq(&wp
->w_readev
); /* just in case */
1023 evdeq(&wp
->w_writeev
); /* just in case */
1024 evdeq(&wp
->w_silenceev
);
1026 FreePaster(&wp
->w_paster
);
1032 OpenDevice(args
, lflag
, typep
, namep
)
1038 char *arg
= args
[0];
1044 if (strcmp(arg
, "//group") == 0)
1046 *typep
= W_TYPE_GROUP
;
1050 #ifdef BUILTIN_TELNET
1051 if (strcmp(arg
, "//telnet") == 0)
1053 f
= TelOpen(args
+ 1);
1055 *typep
= W_TYPE_TELNET
;
1060 if ((stat(arg
, &st
)) == 0 && S_ISCHR(st
.st_mode
))
1062 if (access(arg
, R_OK
| W_OK
) == -1)
1064 Msg(errno
, "Cannot access line '%s' for R/W", arg
);
1067 debug("OpenDevice: OpenTTY\n");
1068 if ((f
= OpenTTY(arg
, args
[1])) < 0)
1071 *typep
= W_TYPE_PLAIN
;
1076 *typep
= W_TYPE_PTY
;
1080 Msg(0, "No more PTYs.");
1086 if (ioctl(f
, TIOCPKT
, (char *)&flag
))
1088 Msg(errno
, "TIOCPKT ioctl");
1093 #endif /* TIOCPKT */
1095 debug1("fcntl(%d, F_SETFL, FNBLOCK)\n", f
);
1096 (void) fcntl(f
, F_SETFL
, FNBLOCK
);
1099 * Tenebreux (zeus@ns.acadiacom.net) has Linux 1.3.70 where select
1100 * gets confused in the following condition:
1101 * Open a pty-master side, request a flush on it, then set packet
1102 * mode and call select(). Select will return a possible read, where
1103 * the one byte response to the flush can be found. Select will
1104 * thereafter return a possible read, which yields I/O error.
1106 * If we request another flush *after* switching into packet mode,
1107 * this I/O error does not occur. We receive a single response byte
1108 * although we send two flush requests now.
1110 * Maybe we should not flush at all.
1114 if (*typep
== W_TYPE_PTY
|| *typep
== W_TYPE_PLAIN
)
1115 tcflush(f
, TCIOFLUSH
);
1118 if (*typep
!= W_TYPE_PTY
)
1123 if (chown(*namep
, real_uid
, PTYGROUP
) && !eff_uid
)
1125 if (chown(*namep
, real_uid
, real_gid
) && !eff_uid
)
1128 Msg(errno
, "chown tty");
1133 if (chmod(*namep
, lflag
? TtyMode
: (TtyMode
& ~022)) && !eff_uid
)
1135 if (chmod(*namep
, TtyMode
) && !eff_uid
)
1138 Msg(errno
, "chmod tty");
1147 * Fields w_width, w_height, aflag, number (and w_tty)
1148 * are read from struct win *win. No fields written.
1149 * If pwin is nonzero, filedescriptors are distributed
1150 * between win->w_tty and open(ttyn)
1154 ForkWindow(win
, args
, ttyn
)
1161 char shellbuf
[7 + MAXPATHLEN
];
1164 char libuf
[20], cobuf
[20];
1167 int w
= win
->w_width
;
1168 int h
= win
->w_height
;
1170 int i
, pat
, wfdused
;
1171 struct pseudowin
*pwin
= win
->w_pwin
;
1178 debug("pre-opening slave...\n");
1179 if ((slave
= open(ttyn
, O_RDWR
|O_NOCTTY
)) == -1)
1186 debug("forking...\n");
1195 switch (pid
= fork())
1201 signal(SIGHUP
, SIG_DFL
);
1202 signal(SIGINT
, SIG_DFL
);
1203 signal(SIGQUIT
, SIG_DFL
);
1204 signal(SIGTERM
, SIG_DFL
);
1206 signal(SIGTTIN
, SIG_DFL
);
1207 signal(SIGTTOU
, SIG_DFL
);
1210 signal(SIGPIPE
, SIG_DFL
);
1213 signal(SIGXFSZ
, SIG_DFL
);
1216 displays
= 0; /* beware of Panic() */
1217 if (setgid(real_gid
) || setuid(real_uid
))
1218 Panic(errno
, "Setuid/gid");
1222 if (!pwin
) /* ignore directory if pseudo */
1224 if (win
->w_dir
&& *win
->w_dir
&& chdir(win
->w_dir
))
1225 Panic(errno
, "Cannot chdir to %s", win
->w_dir
);
1235 if (dfp
&& dfp
!= stderr
)
1243 closeallfiles(win
->w_ptyfd
);
1247 closeallfiles(win
->w_ptyfd
);
1249 if (dfp
) /* do not produce child debug, when debug is "off" */
1253 sprintf(buf
, "%s/screen.child", DEBUGDIR
);
1254 if ((dfp
= fopen(buf
, "a")) == 0)
1257 (void) chmod(buf
, 0666);
1259 debug1("=== ForkWindow: pid %d\n", (int)getpid());
1261 /* Close the three /dev/null descriptors */
1267 * distribute filedescriptors between the ttys
1270 pat
= pwin
? pwin
->p_fdpat
:
1271 ((F_PFRONT
<<(F_PSHIFT
*2)) | (F_PFRONT
<<F_PSHIFT
) | F_PFRONT
);
1272 debug1("Using window pattern 0x%x\n", pat
);
1274 for(i
= 0; i
< 3; i
++)
1276 if (pat
& F_PFRONT
<< F_PSHIFT
* i
)
1282 newfd
= open(ttyn
, O_RDWR
);
1284 newfd
= open(ttyn
, O_RDWR
|O_NOCTTY
);
1286 newfd
= open(ttyn
, O_RDWR
);
1289 Panic(errno
, "Cannot open %s", ttyn
);
1303 * the pseudo window process should not be surprised with a
1304 * nonblocking filedescriptor. Poor Backend!
1306 debug1("Clearing NBLOCK on window-fd(%d)\n", win
->w_ptyfd
);
1307 if (fcntl(win
->w_ptyfd
, F_SETFL
, 0))
1308 Msg(errno
, "Warning: clear NBLOCK fcntl failed");
1313 newfd
= open(ttyn
, O_RDWR
);
1315 newfd
= open(ttyn
, O_RDWR
|O_NOCTTY
);
1317 newfd
= open(ttyn
, O_RDWR
);
1320 Panic(errno
, "Cannot open %s", ttyn
);
1323 #endif /* PSEUDOS */
1324 close(win
->w_ptyfd
);
1329 struct mode fakemode
, *modep
;
1332 Msg(errno
, "fgtty");
1335 debug("ForkWindow: using display tty mode for new child.\n");
1340 debug("No display - creating tty setting\n");
1347 /* We only want echo if the users input goes to the pseudo
1348 * and the pseudo's stdout is not send to the window.
1351 if (pwin
&& (!(pat
& F_UWP
) || (pat
& F_PBACK
<< F_PSHIFT
)))
1353 debug1("clearing echo on pseudywin fd (pat %x)\n", pat
);
1354 # if defined(POSIX) || defined(TERMIO)
1355 modep
->tio
.c_lflag
&= ~ECHO
;
1356 modep
->tio
.c_iflag
&= ~ICRNL
;
1358 modep
->m_ttyb
.sg_flags
&= ~ECHO
;
1362 SetTTY(newfd
, modep
);
1366 (void) ioctl(newfd
, TIOCSWINSZ
, (char *)&glwz
);
1368 /* Always turn off nonblocking mode */
1369 (void)fcntl(newfd
, F_SETFL
, 0);
1372 sprintf(libuf
, "LINES=%d", h
);
1373 sprintf(cobuf
, "COLUMNS=%d", w
);
1378 NewEnv
[2] = MakeTermcap(display
== 0 || win
->w_aflag
);
1381 NewEnv
[2] = MakeTermcap(1);
1383 NewEnv
[2] = Termcap
;
1385 strcpy(shellbuf
, "SHELL=");
1386 strncpy(shellbuf
+ 6, ShellProg
+ (*ShellProg
== '-'), sizeof(shellbuf
) - 7);
1387 shellbuf
[sizeof(shellbuf
) - 1] = 0;
1388 NewEnv
[4] = shellbuf
;
1389 debug1("ForkWindow: NewEnv[4] = '%s'\n", shellbuf
);
1390 if (win
->w_term
&& *win
->w_term
&& strcmp(screenterm
, win
->w_term
) &&
1391 (strlen(win
->w_term
) < 20))
1395 sprintf(tebuf
, "TERM=%s", win
->w_term
);
1396 debug2("Makewindow %d with %s\n", win
->w_number
, tebuf
);
1397 tl
= strlen(win
->w_term
);
1399 if ((s1
= index(NewEnv
[2], '|')))
1401 if ((s2
= index(++s1
, '|')))
1403 if (strlen(NewEnv
[2]) - (s2
- s1
) + tl
< 1024)
1405 bcopy(s2
, s1
+ tl
, strlen(s2
) + 1);
1406 bcopy(win
->w_term
, s1
, tl
);
1411 sprintf(ebuf
, "WINDOW=%d", win
->w_number
);
1417 proc
= DefaultShell
;
1418 debug1("calling execvpe %s\n", proc
);
1419 execvpe(proc
, args
, NewEnv
);
1420 debug1("exec error: %d\n", errno
);
1421 Panic(errno
, "Cannot exec '%s'", proc
);
1431 execvpe(prog
, args
, env
)
1432 char *prog
, **args
, **env
;
1434 register char *path
= NULL
, *p
;
1436 char *shargs
[MAXARGS
+ 1];
1437 register int i
, eaccess
= 0;
1439 if (rindex(prog
, '/'))
1441 if (!path
&& !(path
= getenv("PATH")))
1445 for (p
= buf
; *path
&& *path
!= ':'; path
++)
1446 if (p
- buf
< (int)sizeof(buf
) - 2)
1450 if (p
- buf
+ strlen(prog
) >= sizeof(buf
) - 1)
1453 execve(buf
, args
, env
);
1457 shargs
[0] = DefaultShell
;
1459 for (i
= 1; (shargs
[i
+ 1] = args
[i
]) != NULL
; ++i
)
1461 execve(DefaultShell
, shargs
, env
);
1484 int i
, r
= 0, l
= 0;
1486 extern struct display
*display
;
1487 extern struct win
*windows
;
1488 struct pseudowin
*pwin
;
1491 if ((w
= display
? fore
: windows
) == NULL
)
1493 if (!*av
|| w
->w_pwin
)
1495 Msg(0, "Filter running: %s", w
->w_pwin
? w
->w_pwin
->p_cmd
: "(none)");
1500 Msg(0, "You feel dead inside.");
1503 if (!(pwin
= (struct pseudowin
*)malloc(sizeof(struct pseudowin
))))
1508 bzero((char *)pwin
, (int)sizeof(*pwin
));
1510 /* allow ^a:!!./ttytest as a short form for ^a:exec !.. ./ttytest */
1511 for (s
= *av
; *s
== ' '; s
++)
1513 for (p
= s
; *p
== ':' || *p
== '.' || *p
== '!'; p
++)
1516 while (*p
&& p
> s
&& p
[-1] == '.')
1529 for (i
= 0; i
< 3; i
++)
1531 *t
= (s
< p
) ? *s
++ : '.';
1536 l
|= F_PFRONT
<< (i
* F_PSHIFT
);
1539 l
|= F_PBACK
<< (i
* F_PSHIFT
);
1542 l
|= F_PBOTH
<< (i
* F_PSHIFT
);
1550 if ((l
& F_PMASK
) == F_PFRONT
)
1553 l
^= F_PFRONT
| F_PBACK
;
1560 debug1("winexec: '%#x'\n", pwin
->p_fdpat
);
1563 for (pp
= av
; *pp
; pp
++)
1566 while (*p
&& l
-- > 0)
1573 debug1("%s\n", pwin
->p_cmd
);
1575 if ((pwin
->p_ptyfd
= OpenDevice(av
, 0, &type
, &t
)) < 0)
1580 strncpy(pwin
->p_tty
, t
, MAXSTR
- 1);
1582 if (type
!= W_TYPE_PTY
)
1585 Msg(0, "Cannot only use commands as pseudo win.");
1588 if (!(pwin
->p_fdpat
& F_PFRONT
))
1589 evdeq(&w
->w_readev
);
1594 if (ioctl(pwin
->p_ptyfd
, TIOCPKT
, (char *)&flag
))
1596 Msg(errno
, "TIOCPKT pwin ioctl");
1600 if (w
->w_type
== W_TYPE_PTY
&& !(pwin
->p_fdpat
& F_PFRONT
))
1602 if (ioctl(w
->w_ptyfd
, TIOCPKT
, (char *)&flag
))
1604 Msg(errno
, "TIOCPKT win ioctl");
1610 #endif /* TIOCPKT */
1612 pwin
->p_readev
.fd
= pwin
->p_writeev
.fd
= pwin
->p_ptyfd
;
1613 pwin
->p_readev
.type
= EV_READ
;
1614 pwin
->p_writeev
.type
= EV_WRITE
;
1615 pwin
->p_readev
.data
= pwin
->p_writeev
.data
= (char *)w
;
1616 pwin
->p_readev
.handler
= pseu_readev_fn
;
1617 pwin
->p_writeev
.handler
= pseu_writeev_fn
;
1618 pwin
->p_writeev
.condpos
= &pwin
->p_inlen
;
1619 if (pwin
->p_fdpat
& (F_PFRONT
<< F_PSHIFT
* 2 | F_PFRONT
<< F_PSHIFT
))
1620 evenq(&pwin
->p_readev
);
1621 evenq(&pwin
->p_writeev
);
1622 r
= pwin
->p_pid
= ForkWindow(w
, av
, t
);
1632 struct pseudowin
*pwin
= w
->w_pwin
;
1635 if (fcntl(w
->w_ptyfd
, F_SETFL
, FNBLOCK
))
1636 Msg(errno
, "Warning: FreePseudowin: NBLOCK fcntl failed");
1638 if (w
->w_type
== W_TYPE_PTY
&& !(pwin
->p_fdpat
& F_PFRONT
))
1641 if (ioctl(w
->w_ptyfd
, TIOCPKT
, (char *)&flag
))
1642 Msg(errno
, "Warning: FreePseudowin: TIOCPKT win ioctl");
1645 /* should be able to use CloseDevice() here */
1646 (void)chmod(pwin
->p_tty
, 0666);
1647 (void)chown(pwin
->p_tty
, 0, 0);
1648 if (pwin
->p_ptyfd
>= 0)
1649 close(pwin
->p_ptyfd
);
1650 evdeq(&pwin
->p_readev
);
1651 evdeq(&pwin
->p_writeev
);
1652 if (w
->w_readev
.condneg
== &pwin
->p_inlen
)
1653 w
->w_readev
.condpos
= w
->w_readev
.condneg
= 0;
1654 evenq(&w
->w_readev
);
1659 #endif /* PSEUDOS */
1664 * returns 0, if the lock really has been released
1667 ReleaseAutoWritelock(dis
, w
)
1668 struct display
*dis
;
1671 debug2("ReleaseAutoWritelock: user %s, window %d\n",
1672 dis
->d_user
->u_name
, w
->w_number
);
1674 /* release auto writelock when user has no other display here */
1675 if (w
->w_wlock
== WLOCK_AUTO
&& w
->w_wlockuser
== dis
->d_user
)
1679 for (d
= displays
; d
; d
= d
->d_next
)
1680 if (( d
!= dis
) && (d
->d_fore
== w
) && (d
->d_user
== dis
->d_user
))
1682 debug3("%s %s autolock on win %d\n",
1683 dis
->d_user
->u_name
, d
? "keeps" : "releases", w
->w_number
);
1686 w
->w_wlockuser
= NULL
;
1694 * returns 0, if the lock really could be obtained
1697 ObtainAutoWritelock(d
, w
)
1701 if ((w
->w_wlock
== WLOCK_AUTO
) &&
1702 !AclCheckPermWin(d
->d_user
, ACL_WRITE
, w
) &&
1705 debug2("%s obtained auto writelock for exported window %d\n",
1706 d
->d_user
->u_name
, w
->w_number
);
1707 w
->w_wlockuser
= d
->d_user
;
1713 #endif /* MULTIUSER */
1717 /********************************************************************/
1721 paste_slowev_fn(ev
, data
)
1725 struct paster
*pa
= (struct paster
*)data
;
1729 flayer
= pa
->pa_pastelayer
;
1731 pa
->pa_pastelen
= 0;
1732 if (!pa
->pa_pastelen
)
1734 p
= Layer2Window(flayer
);
1735 DoProcess(p
, &pa
->pa_pasteptr
, &l
, pa
);
1736 pa
->pa_pastelen
-= 1 - l
;
1737 if (pa
->pa_pastelen
> 0)
1739 SetTimeout(&pa
->pa_slowev
, p
->w_slowpaste
);
1740 evenq(&pa
->pa_slowev
);
1752 for (cv
= p
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
1754 display
= cv
->c_display
;
1755 if (D_status
== STATUS_ON_WIN
&& !D_status_bell
)
1757 /* wait 'til status is gone */
1758 debug("BLOCKING because of status\n");
1759 ev
->condpos
= &const_one
;
1760 ev
->condneg
= &D_status
;
1763 debug2("muchpending %s %d: ", D_usertty
, D_blocked
);
1764 debug3("%d %d %d\n", D_obufp
- D_obuf
, D_obufmax
, D_blocked_fuzz
);
1767 if (D_obufp
- D_obuf
> D_obufmax
+ D_blocked_fuzz
)
1769 if (D_nonblock
== 0)
1771 debug1("obuf is full, stopping output to display %s\n", D_usertty
);
1775 debug("BLOCKING because of full obuf\n");
1776 ev
->condpos
= &D_obuffree
;
1777 ev
->condneg
= &D_obuflenmax
;
1778 if (D_nonblock
> 0 && !D_blockedev
.queued
)
1780 debug1("created timeout of %g secs\n", D_nonblock
/1000.);
1781 SetTimeout(&D_blockedev
, D_nonblock
);
1782 evenq(&D_blockedev
);
1791 win_readev_fn(ev
, data
)
1795 struct win
*p
= (struct win
*)data
;
1796 char buf
[IOSIZE
], *bp
;
1806 wtop
= p
->w_pwin
&& W_WTOP(p
);
1809 ASSERT(sizeof(p
->w_pwin
->p_inbuf
) == IOSIZE
);
1810 size
= IOSIZE
- p
->w_pwin
->p_inlen
;
1813 ev
->condpos
= &const_IOSIZE
;
1814 ev
->condneg
= &p
->w_pwin
->p_inlen
;
1819 if (p
->w_layer
.l_cvlist
&& muchpending(p
, ev
))
1826 ev
->condpos
= &const_one
;
1827 ev
->condneg
= &p
->w_blocked
;
1831 ev
->condpos
= ev
->condneg
= 0;
1833 if ((len
= p
->w_outlen
))
1836 WriteString(p
, p
->w_outbuf
, len
);
1840 debug1("going to read from window fd %d\n", ev
->fd
);
1841 if ((len
= read(ev
->fd
, buf
, size
)) < 0)
1843 if (errno
== EINTR
|| errno
== EAGAIN
)
1845 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
1846 if (errno
== EWOULDBLOCK
)
1849 debug2("Window %d: read error (errno %d) - killing window\n", p
->w_number
, errno
);
1850 WindowDied(p
, 0, 0);
1855 debug1("Window %d: EOF - killing window\n", p
->w_number
);
1856 WindowDied(p
, 0, 0);
1859 debug1(" -> %d bytes\n", len
);
1861 if (p
->w_type
== W_TYPE_PTY
)
1865 debug1("PAKET %x\n", buf
[0]);
1866 if (buf
[0] & TIOCPKT_NOSTOP
)
1868 if (buf
[0] & TIOCPKT_DOSTOP
)
1875 #ifdef BUILTIN_TELNET
1876 if (p
->w_type
== W_TYPE_TELNET
)
1877 len
= TelIn(p
, bp
, len
, buf
+ sizeof(buf
) - (bp
+ len
));
1882 if (zmodem_mode
&& zmodem_parse(p
, bp
, len
))
1888 debug("sending input to pwin\n");
1889 bcopy(bp
, p
->w_pwin
->p_inbuf
+ p
->w_pwin
->p_inlen
, len
);
1890 p
->w_pwin
->p_inlen
+= len
;
1893 WriteString(p
, bp
, len
);
1899 win_writeev_fn(ev
, data
)
1903 struct win
*p
= (struct win
*)data
;
1907 debug2("writing %d bytes to win %d\n", p
->w_inlen
, p
->w_number
);
1908 if ((len
= write(ev
->fd
, p
->w_inbuf
, p
->w_inlen
)) <= 0)
1909 len
= p
->w_inlen
; /* dead window */
1910 if ((p
->w_inlen
-= len
))
1911 bcopy(p
->w_inbuf
+ len
, p
->w_inbuf
, p
->w_inlen
);
1914 if (p
->w_paster
.pa_pastelen
&& !p
->w_slowpaste
)
1916 struct paster
*pa
= &p
->w_paster
;
1917 flayer
= pa
->pa_pastelayer
;
1919 DoProcess(p
, &pa
->pa_pasteptr
, &pa
->pa_pastelen
, pa
);
1930 pseu_readev_fn(ev
, data
)
1934 struct win
*p
= (struct win
*)data
;
1936 int size
, ptow
, len
;
1943 ASSERT(sizeof(p
->w_inbuf
) == IOSIZE
);
1944 size
= IOSIZE
- p
->w_inlen
;
1947 ev
->condpos
= &const_IOSIZE
;
1948 ev
->condneg
= &p
->w_inlen
;
1952 if (p
->w_layer
.l_cvlist
&& muchpending(p
, ev
))
1956 ev
->condpos
= &const_one
;
1957 ev
->condneg
= &p
->w_blocked
;
1961 ev
->condpos
= ev
->condneg
= 0;
1963 if ((len
= p
->w_outlen
))
1966 WriteString(p
, p
->w_outbuf
, len
);
1970 if ((len
= read(ev
->fd
, buf
, size
)) <= 0)
1972 if (errno
== EINTR
|| errno
== EAGAIN
)
1974 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
1975 if (errno
== EWOULDBLOCK
)
1978 debug2("Window %d: pseudowin read error (errno %d) -- removing pseudowin\n", p
->w_number
, len
? errno
: 0);
1982 /* no packet mode on pseudos! */
1985 bcopy(buf
, p
->w_inbuf
+ p
->w_inlen
, len
);
1988 WriteString(p
, buf
, len
);
1993 pseu_writeev_fn(ev
, data
)
1997 struct win
*p
= (struct win
*)data
;
1998 struct pseudowin
*pw
= p
->w_pwin
;
2002 if (pw
->p_inlen
== 0)
2004 if ((len
= write(ev
->fd
, pw
->p_inbuf
, pw
->p_inlen
)) <= 0)
2005 len
= pw
->p_inlen
; /* dead pseudo */
2006 if ((p
->w_pwin
->p_inlen
-= len
))
2007 bcopy(p
->w_pwin
->p_inbuf
+ len
, p
->w_pwin
->p_inbuf
, p
->w_pwin
->p_inlen
);
2011 #endif /* PSEUDOS */
2014 win_silenceev_fn(ev
, data
)
2018 struct win
*p
= (struct win
*)data
;
2020 debug1("FOUND silence win %d\n", p
->w_number
);
2021 for (display
= displays
; display
; display
= display
->d_next
)
2023 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2024 if (cv
->c_layer
->l_bottom
== &p
->w_layer
)
2027 continue; /* user already sees window */
2029 if (!(ACLBYTE(p
->w_lio_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
)))
2032 Msg(0, "Window %d: silence for %d seconds", p
->w_number
, p
->w_silencewait
);
2039 zmodem_parse(p
, bp
, len
)
2046 for (i
= 0; i
< len
; i
++, b2
++)
2048 if (p
->w_zauto
== 0)
2050 for (; i
< len
; i
++, b2
++)
2055 if (i
> 1 && b2
[-1] == '*' && b2
[-2] == '*')
2059 if (p
->w_zauto
> 5 || *b2
== "**\030B00"[p
->w_zauto
] || (p
->w_zauto
== 5 && *b2
== '1') || (p
->w_zauto
== 5 && p
->w_zdisplay
&& *b2
== '8'))
2061 if (++p
->w_zauto
< 6)
2063 if (p
->w_zauto
== 6)
2068 WriteString(p
, bp
, i
+ 1 - 6);
2069 WriteString(p
, "\r\n", 2);
2070 zmodem_found(p
, *b2
== '1', b2
+ 1, len
- i
- 1);
2073 else if (p
->w_zauto
== 7 || *b2
== '8')
2075 int se
= p
->w_zdisplay
->d_blocked
== 2 ? 'O' : '\212';
2076 for (; i
< len
; i
++, b2
++)
2083 D_readev
.condpos
= D_readev
.condneg
= 0;
2087 Activate(D_fore
? D_fore
->w_norefresh
: 0);
2094 p
->w_zauto
= *b2
== '*' ? (p
->w_zauto
== 2 ? 2 : 1) : 0;
2096 if (p
->w_zauto
== 0 && bp
[len
- 1] == '*')
2097 p
->w_zauto
= len
> 1 && bp
[len
- 2] == '*' ? 2 : 1;
2100 display
= p
->w_zdisplay
;
2109 zmodem_fin(buf
, len
, data
)
2118 RcLine(buf
, strlen(buf
) + 1);
2121 s
= "\030\030\030\030\030\030\030\030\030\030";
2128 zmodem_found(p
, send
, bp
, len
)
2136 extern int zmodem_mode
;
2138 /* check for abort sequence */
2140 for (i
= 0; i
< len
; i
++)
2145 if (zmodem_mode
== 3 || (zmodem_mode
== 1 && p
->w_type
!= W_TYPE_PLAIN
))
2147 struct display
*d
, *olddisplay
;
2149 olddisplay
= display
;
2151 if (!d
|| d
->d_fore
!= p
)
2152 for (d
= displays
; d
; d
= d
->d_next
)
2155 if (!d
&& p
->w_layer
.l_cvlist
)
2156 d
= p
->w_layer
.l_cvlist
->c_display
;
2163 p
->w_zdisplay
= display
;
2164 D_blocked
= 2 + send
;
2165 flayer
= &p
->w_layer
;
2168 evdeq(&D_blockedev
);
2169 D_readev
.condpos
= &const_IOSIZE
;
2170 D_readev
.condneg
= &p
->w_inlen
;
2173 SetRendition(&mchar_blank
);
2174 AddStr("Zmodem active\r\n\r\n");
2175 AddStr(send
? "**\030B01" : "**\030B00");
2178 display
= olddisplay
;
2181 flayer
= &p
->w_layer
;
2182 Input(":", 100, INP_COOKED
, zmodem_fin
, NULL
, 0);
2183 s
= send
? zmodem_sendcmd
: zmodem_recvcmd
;
2193 struct display
*olddisplay
= display
;
2194 struct layer
*oldflayer
= flayer
;
2197 if (p
->w_savelayer
&& p
->w_savelayer
->l_next
)
2199 if (oldflayer
== p
->w_savelayer
)
2200 oldflayer
= flayer
->l_next
;
2201 flayer
= p
->w_savelayer
;
2206 LRefreshAll(&p
->w_layer
, 0);
2212 D_readev
.condpos
= D_readev
.condneg
= 0;
2213 Activate(D_fore
? D_fore
->w_norefresh
: 0);
2215 display
= olddisplay
;