From f4aa78ac924c0947683833dd248e89d521910869 Mon Sep 17 00:00:00 2001 From: David Levine Date: Sun, 25 Dec 2011 15:00:49 -0600 Subject: [PATCH] Removed unused vmh.c and wmh.c. --- man/Makefile.in | 3 - man/msh.man | 15 - man/vmh.man | 101 ---- uip/Makefile.in | 9 +- uip/vmh.c | 1515 ------------------------------------------------------- uip/vmhtest.c | 324 ------------ uip/wmh.c | 1389 -------------------------------------------------- 7 files changed, 1 insertion(+), 3355 deletions(-) delete mode 100644 man/vmh.man delete mode 100644 uip/vmh.c delete mode 100644 uip/vmhtest.c delete mode 100644 uip/wmh.c diff --git a/man/Makefile.in b/man/Makefile.in index c94ab00..75eb9c1 100644 --- a/man/Makefile.in +++ b/man/Makefile.in @@ -74,9 +74,6 @@ MAN1 = $(MAN1SRC:.=.$(manext1)) MAN5 = $(MAN5SRC:.=.$(manext5)) MAN8 = $(MAN8SRC:.=.$(manext8)) -# Since vmh is not built or distributed, neither should vmh.1 be -# MANEXTRA = vmh. - # source for man pages DIST_MANSRC = $(MAN1SRC) $(MAN5SRC) $(MAN8SRC) DIST_MAN = $(DIST_MANSRC:.=.man) diff --git a/man/msh.man b/man/msh.man index 93d0282..7d0d131 100644 --- a/man/msh.man +++ b/man/msh.man @@ -212,21 +212,6 @@ to mark all messages as seen and then For speedy type\-in, this command is often abbreviated as just .BR qe . .PP -When invoked from -.BR vmh , -another special feature is enabled: -The `topcur' switch directs -.B msh -to have the current message -\*(lqtrack\*(rq the top line of the -.B vmh -scan window. Normally, -.B msh -has the current message \*(lqtrack\*(rq the center of the window -(under -.BR \-notopcur , -which is the default). -.PP .B msh supports an output redirection facility. Commands may be followed by one of diff --git a/man/vmh.man b/man/vmh.man deleted file mode 100644 index 9fe9220..0000000 --- a/man/vmh.man +++ /dev/null @@ -1,101 +0,0 @@ -.\" -.\" %nmhwarning% -.\" -.TH VMH %manext1% "%nmhdate%" MH.6.8 [%nmhversion%] -.SH NAME -vmh \- visual front-end to nmh -.SH SYNOPSIS -.in +.5i -.ti -.5i -vmh -\%[\-prompt\ string] -\%[\-vmhproc\ program] \%[\-novmhproc] -.br -\%[switches\ for\ \fIvmhproc\fR] -\%[\-version] -\%[\-help] -.in -.5i -.SH DESCRIPTION -\fIvmh\fR is a program which implements the server side of the \fInmh\fR -window management protocol and uses \fIcurses\fR\0(3) routines to maintain -a split\-screen interface to any program which implements the client -side of the protocol. This latter program, called the \fIvmhproc\fR, -is specified using the `\-vmhproc\ program' switch. - -The upshot of all this is that one can run \fImsh\fR on a display terminal -and get a nice visual interface. To do this, for example, just add -the line - -.ti +.5i -mshproc: vmh - -to your \&.mh\(ruprofile. (This takes advantage of the fact that -\fImsh\fR is the default \fIvmhproc\fR for \fIvmh\fR.) - -In order to facilitate things, if the `\-novmhproc' switch is given, -and \fIvmh\fR can't run on the user's terminal, the \fIvmhproc\fR is -run directly without the window management protocol. - -After initializing the protocol, \fIvmh\fR prompts the user for a command -to be given to the client. Usually, this results in output being sent to -one or more windows. If a output to a window would cause it to scroll, -\fIvmh\fR prompts the user for instructions, roughly permitting the -capabilities of \fIless\fR or \fImore\fR (e.g., the ability to scroll -backwards and forwards): - -.nf -.in +.5i -.ta \w'RETURN 'u +\w'* 'u -SPACE advance to the next windowful -RETURN * advance to the next line -y * retreat to the previous line -d * advance to the next ten lines -u * retreat to the previous ten lines -g * go to an arbitrary line - (preceed g with the line number) -G * go to the end of the window - (if a line number is given, this acts like `g') -CTRL\-L refresh the entire screen -h print a help message -q abort the window -.re -.in -.5i -.fi - -(A `*' indicates that a numeric prefix is meaningful for this command.) - -Note that if a command resulted in more than one window's worth of -information being displayed, and you allow the command which is generating -information for the window to gracefully finish (i.e., you don't use -the `q' command to abort information being sent to the window), then -\fIvmh\fR will give you one last change to peruse the window. This is -useful for scrolling back and forth. Just type `q' when you're done. - -To abnormally terminate \fIvmh\fR (without core dump), use -(usually CTRL\-\\). For instance, this does the \*(lqright\*(rq thing -with \fIbbc\fR and \fImsh\fR. - -.Fi -^$HOME/\&.mh\(ruprofile~^The user profile -.Pr -^Path:~^To determine the user's nmh directory -.Sa -msh(1) -.De -`\-prompt\ (vmh)\ ' -.Ds -`\-vmhproc\ msh' -.Co -None -.Bu -The argument to the `\-prompt' switch must be interpreted as a single -token by the shell that invokes \fIvmh\fR. Therefore, one must usually -place the argument to this switch inside double\-quotes. - -At present, there is no way to pass signals (e.g., interrupt, quit) to -the client. However, generating QUIT when \fIvmh\fR is reading a command -from the terminal is sufficient to tell the client to go away quickly. - -Acts strangely (loses peer or botches window management protocol with -peer) on random occasions. -.En diff --git a/uip/Makefile.in b/uip/Makefile.in index 370fc15..5b5ed02 100644 --- a/uip/Makefile.in +++ b/uip/Makefile.in @@ -55,9 +55,6 @@ CMDS = ali anno burst comp dist flist folder forw install-mh mark mhbuild \ msh new packf pick prompter refile repl rmf rmm scan send show \ sortm whatnow whom -## removed this from CMDS until I can fix it -## OTHERCMDS = vmh - # commands that are links to other commands LCMDS = flists folders next prev @@ -79,8 +76,7 @@ SRCS = ali.c aliasbr.c anno.c annosbr.c ap.c burst.c comp.c \ post.c prompter.c rcvdist.c rcvpack.c rcvstore.c rcvtty.c \ refile.c repl.c replsbr.c rmf.c rmm.c scan.c scansbr.c send.c \ sendsbr.c show.c slocal.c sortm.c spost.c termsbr.c viamail.c \ - vmh.c vmhsbr.c vmhtest.c whatnow.c whatnowproc.c whatnowsbr.c \ - whom.c wmh.c + vmhsbr.c whatnow.c whatnowproc.c whatnowsbr.c whom.c # auxiliary files AUX = Makefile.in @@ -235,9 +231,6 @@ spost: spost.o aliasbr.o $(LOCALLIBS) viamail: viamail.o mhmisc.o mhoutsbr.o sendsbr.o annosbr.o distsbr.o $(LOCALLIBS) $(LINK) viamail.o mhmisc.o mhoutsbr.o sendsbr.o annosbr.o distsbr.o $(LINKLIBS) $(TERMLIB) -vmh: vmh.o vmhsbr.o $(LOCALLIBS) - $(LINK) vmh.o vmhsbr.o $(LINKLIBS) $(TERMLIB) - whatnow: whatnow.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o $(LOCALLIBS) $(LINK) whatnow.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o $(LINKLIBS) diff --git a/uip/vmh.c b/uip/vmh.c deleted file mode 100644 index 908df85..0000000 --- a/uip/vmh.c +++ /dev/null @@ -1,1515 +0,0 @@ - -/* - * vmh.c -- visual front-end to nmh - * - * This code is Copyright (c) 2002, by the authors of nmh. See the - * COPYRIGHT file in the root directory of the nmh distribution for - * complete copyright information. - */ - -#include -#include - -#if 0 -#if defined(SYS5) && !defined(TERMINFO) -/* - * Define TERMINFO if you have it. - * You get it automatically if you're running SYS5, and you don't get - * it if you're not. (If you're not SYS5, you probably have termcap.) - * We distinguish TERMINFO from SYS5 because in this file SYS5 really - * means "AT&T line discipline" (termio, not sgttyb), whereas terminfo - * is quite a separate issue. - */ -#define TERMINFO 1 -#endif -#endif - -/* - * TODO: - * 1) Pass signals to client during execution - * 2) Figure out a way for the user to say how big the Scan/Display - * windows should be. - * 3) If curses ever gets fixed, then XYZ code can be removed - */ - -#include - -#ifdef ncr -# define _SYS_REG_H /* NCR redefines "ERR" in */ -#endif - -#undef OK /* tricky */ - -/* removed for right now */ -#if 0 -#ifdef TERMINFO -# include /* variables describing terminal capabilities */ -#endif /* TERMINFO */ -#endif - -#include -#include -#include -#include - -#ifndef sigmask -# define sigmask(s) (1 << ((s) - 1)) -#endif /* not sigmask */ - -#ifdef ridge -# undef SIGTSTP -#endif /* ridge */ - -#ifdef HAVE_WRITEV -# include -#else -struct iovec { - char *iov_base; - int iov_len; -}; -#endif - -#ifdef hpux -# include -# define TCGETATTR /* tcgetattr() */ -#endif - -#ifdef BSD44 -# define USE_OLD_TTY -# define _maxx maxx /* curses.h */ -# define _maxy maxy -# define _curx curx /* curses.h */ -# define _cury cury -void __cputchar __P((int)); -# undef _putchar -# define _putchar __cputchar -# include /* sgttyb */ -#endif - -#define ALARM ((unsigned int) 10) -#define PAUSE ((unsigned int) 2) - -#ifndef abs -# define abs(a) ((a) > 0 ? (a) : -(a)) -#endif - -#define SMALLMOVE 1 -#define LARGEMOVE 10 - -#define XYZ /* XXX */ - -static struct swit switches[] = { -#define PRMPTSW 0 - { "prompt string", 6 }, -#define PROGSW 1 - { "vmhproc program", 7 }, -#define NPROGSW 2 - { "novmhproc", 9 }, -#define VERSIONSW 3 - { "version", 0 }, -#define HELPSW 4 - { "help", 0 }, - { NULL, 0 } -}; - - /* PEERS */ -static int PEERpid = NOTOK; - -static jmp_buf PEERctx; - - /* WINDOWS */ -static char *myprompt = "(%s) "; - -static WINDOW *Scan; -static WINDOW *Status; -static WINDOW *Display; -static WINDOW *Command; - -#define NWIN 3 -static int numwins; -WINDOW *windows[NWIN + 1]; - - - /* LINES */ - -struct line { - int l_no; - char *l_buf; - struct line *l_prev; - struct line *l_next; -}; - -static struct line *lhead = NULL; -static struct line *ltop = NULL; -static struct line *ltail = NULL; - -static int did_less = 0; -static int smallmove = SMALLMOVE; -static int largemove = LARGEMOVE; - - - /* TTYS */ - -static int tty_ready = NOTOK; - -static int intrc; - -#ifndef SYS5 -# define ERASE sg.sg_erase -# define KILL sg.sg_kill -static struct sgttyb sg; - -#define EOFC tc.t_eofc -#define INTR tc.t_intrc -static struct tchars tc; -#else /* SYS5 */ -# define ERASE sg.c_cc[VERASE] -# define KILL sg.c_cc[VKILL] -# define EOFC sg.c_cc[VEOF] -# define INTR sg.c_cc[VINTR] -static struct termio sg; -#endif /* SYS5 */ - -#ifndef TIOCGLTC -# define WERASC ('W' & 037) -#else /* TIOCGLTC */ -# ifndef SVR4 -# define WERASC ltc.t_werasc -static struct ltchars ltc; -# else /* SVR4 */ -# define WERASC sg.c_cc[VWERASE] -# undef TIOCGLTC /* the define exists, but struct ltchars doesn't */ -# endif -#endif /* TIOCGLTC */ - - -#if !defined(SYS5) && !defined(BSD44) -int _putchar(); -#endif /* not SYS5 */ - -#ifdef SIGTSTP -char *tgoto(); -#endif /* SIGTSTP */ - - /* SIGNALS */ -static RETSIGTYPE ALRMser(int); -static RETSIGTYPE PIPEser(int); -static RETSIGTYPE SIGser(int); -#ifdef SIGTSTP -static RETSIGTYPE TSTPser(int); -#endif /* SIGTSTP */ - - - /* MISCELLANY */ - -/* - * static prototypes - */ -static void adorn (char *, char *, ...); - -static vmh(), lreset(), linsert(), ladvance(), lretreat(), lgo(); -static TTYon(), TTYoff(), foreground(); -static int PEERinit(), pINI(), pLOOP(), pTTY(), pWIN(), WINinit(); -static int WINgetstr(), WINless(), WINputc(), TTYinit(), pWINaux(); - - -int -main (int argc, char **argv) -{ - int vecp = 1, nprog = 0; - char *cp, buffer[BUFSIZ]; - char **argp, **arguments, *vec[MAXARGS]; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) - if (*cp == '-') - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - vec[vecp++] = --cp; - continue; - - case HELPSW: - snprintf (buffer, sizeof(buffer), "%s [switches for vmhproc]", - invo_name); - print_help (buffer, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case PRMPTSW: - if (!(myprompt = *argp++) || *myprompt == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case PROGSW: - if (!(vmhproc = *argp++) || *vmhproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NPROGSW: - nprog++; - continue; - } - else - vec[vecp++] = cp; - - if (TTYinit (nprog) == NOTOK || WINinit (nprog) == NOTOK) { - vec[vecp] = NULL; - - vec[0] = r1bindex (vmhproc, '/'); - execvp (vmhproc, vec); - adios (vmhproc, "unable to exec"); - } - TTYoff (); - PEERinit (vecp, vec); - TTYon (); - - vmh (); - - return done (0); -} - - -static void -vmh (void) -{ - char buffer[BUFSIZ]; - - for (;;) { - pLOOP (RC_QRY, NULL); - - wmove (Command, 0, 0); - wprintw (Command, myprompt, invo_name); - wclrtoeol (Command); - wrefresh (Command); - - switch (WINgetstr (Command, buffer)) { - case NOTOK: - break; - - case OK: - done (0); /* NOTREACHED */ - - default: - if (*buffer) - pLOOP (RC_CMD, buffer); - break; - } - } -} - -/* PEERS */ - -static int -PEERinit (int vecp, char *vec[]) -{ - int pfd0[2], pfd1[2]; - char buf1[BUFSIZ], buf2[BUFSIZ]; - - if (pipe (pfd0) == NOTOK || pipe (pfd1) == NOTOK) - adios ("pipe", "unable to"); -#ifdef hpux - switch (PEERpid = fork ()) { - /* - * Calling vfork() and then another routine [like close()] before - * an exec() messes up the stack frame, causing crib death. - * Use fork() instead. - */ -#else /* not hpux */ - switch (PEERpid = vfork ()) { -#endif /* not hpux */ - case NOTOK: - adios ("vfork", "unable to");/* NOTREACHED */ - - case OK: - close (pfd0[0]); - close (pfd1[1]); - - vec[vecp++] = "-vmhread"; - snprintf (buf1, sizeof(buf1), "%d", pfd1[0]); - vec[vecp++] = buf1; - vec[vecp++] = "-vmhwrite"; - snprintf (buf2, sizeof(buf2), "%d", pfd0[1]); - vec[vecp++] = buf2; - vec[vecp] = NULL; - - SIGNAL (SIGINT, SIG_DFL); - SIGNAL (SIGQUIT, SIG_DFL); - - vec[0] = r1bindex (vmhproc, '/'); - execvp (vmhproc, vec); - perror (vmhproc); - _exit (-1); /* NOTREACHED */ - - default: - close (pfd0[1]); - close (pfd1[0]); - - rcinit (pfd0[0], pfd1[1]); - return pINI (); - } -} - - -static int -pINI (void) -{ - int len, buflen; - char *bp, buffer[BUFSIZ]; - struct record rcs; - register struct record *rc = &rcs; - register WINDOW **w; - - initrc (rc); - - /* Get buffer ready to go */ - bp = buffer; - buflen = sizeof(buffer); - - snprintf (bp, buflen, "%d %d", RC_VRSN, numwins); - len = strlen (bp); - bp += len; - buflen -= len; - - for (w = windows; *w; w++) { - snprintf (bp, buflen, " %d", (*w)->_maxy); - len = strlen (bp); - bp += len; - buflen -= len; - } - - switch (str2rc (RC_INI, buffer, rc)) { - case RC_ACK: - return OK; - - case RC_ERR: - if (rc->rc_len) - adios (NULL, "%s", rc->rc_data); - else - adios (NULL, "pINI peer error"); - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - adios (NULL, "pINI protocol screw-up"); - } -/* NOTREACHED */ -} - - -static int -pLOOP (char *code, char *str) -{ - int i; - struct record rcs; - register struct record *rc = &rcs; - - initrc (rc); - - str2peer (code, str); - for (;;) - switch (peer2rc (rc)) { - case RC_TTY: - if (pTTY (rc) == NOTOK) - return NOTOK; - break; - - case RC_WIN: - if (sscanf (rc->rc_data, "%d", &i) != 1 - || i <= 0 - || i > numwins) { - fmt2peer (RC_ERR, "no such window \"%s\"", rc->rc_data); - return NOTOK; - } - if (pWIN (windows[i - 1]) == NOTOK) - return NOTOK; - break; - - case RC_EOF: - return OK; - - case RC_ERR: - if (rc->rc_len) - adorn (NULL, "%s", rc->rc_data); - else - adorn (NULL, "pLOOP(%s) peer error", - code == RC_QRY ? "QRY" : "CMD"); - return NOTOK; - - case RC_FIN: - if (rc->rc_len) - adorn (NULL, "%s", rc->rc_data); - rcdone (); - i = pidwait (PEERpid, OK); - PEERpid = NOTOK; - done (i); - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - adios (NULL, "pLOOP(%s) protocol screw-up", - code == RC_QRY ? "QRY" : "CMD"); - } -} - - -static int -pTTY (struct record *r) -{ - SIGNAL_HANDLER hstat, istat, qstat, tstat; - struct record rcs; - register struct record *rc = &rcs; - - initrc (rc); - - TTYoff (); - - /* should be changed to block instead of ignore */ - hstat = SIGNAL (SIGHUP, SIG_IGN); - istat = SIGNAL (SIGINT, SIG_IGN); - qstat = SIGNAL (SIGQUIT, SIG_IGN); - tstat = SIGNAL (SIGTERM, SIG_IGN); - - rc2rc (RC_ACK, 0, NULL, rc); - - SIGNAL (SIGHUP, hstat); - SIGNAL (SIGINT, istat); - SIGNAL (SIGQUIT, qstat); - SIGNAL (SIGTERM, tstat); - - TTYon (); - - if (r->rc_len && strcmp (r->rc_data, "FAST") == 0) - goto no_refresh; - -#ifdef SIGTSTP - SIGNAL (SIGTSTP, SIG_IGN); -#endif - -#ifndef TERMINFO - if (SO) - tputs (SO, 0, _putchar); -#else /* TERMINFO */ - putp(enter_standout_mode); -#endif /* TERMINFO */ - fprintf (stdout, "Type any key to continue... "); - fflush (stdout); -#ifndef TERMINFO - if (SE) - tputs (SE, 0, _putchar); -#else /* TERMINFO */ - putp(exit_standout_mode); -#endif /* TERMINFO */ - getc (stdin); -#ifdef SIGTSTP - SIGNAL (SIGTSTP, TSTPser); -#endif /* SIGTSTP */ - - wrefresh (curscr); - -no_refresh: ; - switch (rc->rc_type) { - case RC_EOF: - rc2peer (RC_ACK, 0, NULL); - return OK; - - case RC_ERR: - if (rc->rc_len) - adorn (NULL, "%s", rc->rc_data); - else - adorn (NULL, "pTTY peer error"); - return NOTOK; - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - adios (NULL, "pTTY protocol screw-up"); - } -/* NOTREACHED */ -} - - -static int -pWIN (WINDOW *w) -{ - int i; - - did_less = 0; - if ((i = pWINaux (w)) == OK && did_less) - WINless (w, 1); - - lreset (); - - return i; -} - - -static int -pWINaux (WINDOW *w) -{ - register int n; - int eol; - register char c, *bp; - struct record rcs; - register struct record *rc = &rcs; - - initrc (rc); - - werase (w); - wmove (w, 0, 0); -#ifdef XYZ - if (w == Status) - wstandout (w); -#endif /* XYZ */ - - for (eol = 0;;) - switch (rc2rc (RC_ACK, 0, NULL, rc)) { - case RC_DATA: - if (eol && WINputc (w, '\n') == ERR && WINless (w, 0)) - goto flush; - for (bp = rc->rc_data, n = rc->rc_len; n-- > 0; ) { - if ((c = *bp++) == '\n') - linsert (w); - if (WINputc (w, c) == ERR) - if (n == 0 && c == '\n') - eol++; - else - if (WINless (w, 0)) { -flush: ; - fmt2peer (RC_ERR, "flush window"); -#ifdef XYZ /* should NEVER happen... */ - if (w == Status) - wstandend (w); -#endif /* XYZ */ - wrefresh (w); - return NOTOK; - } - } - break; - - case RC_EOF: - rc2peer (RC_ACK, 0, NULL); -#ifdef XYZ - if (w == Status) - wstandend (w); -#endif /* XYZ */ - wrefresh (w); - return OK; - - case RC_ERR: - if (rc->rc_len) - adorn (NULL, "%s", rc->rc_data); - else - adorn (NULL, "pWIN peer error"); - return NOTOK; - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - adios (NULL, "pWIN protocol screw-up"); - } -/* NOTREACHED */ -} - - -static int -pFIN (void) -{ - int status; - - if (PEERpid <= OK) - return OK; - - rc2peer (RC_FIN, 0, NULL); - rcdone (); - - switch (setjmp (PEERctx)) { - case OK: - SIGNAL (SIGALRM, ALRMser); - alarm (ALARM); - - status = pidwait (PEERpid, OK); - - alarm (0); - break; - - default: - kill (PEERpid, SIGKILL); - status = NOTOK; - break; - } - PEERpid = NOTOK; - - return status; -} - -/* WINDOWS */ - -static int -WINinit (int nprog) -{ - register int nlines, /* not "lines" because terminfo uses that */ - top, - bottom; - - foreground (); - if (initscr () == (WINDOW *) ERR) - if (nprog) - return NOTOK; - else - adios (NULL, "could not initialize terminal"); -#ifdef SIGTSTP - SIGNAL (SIGTSTP, SIG_DFL); -#endif /* SIGTSTP */ - sideground (); - -#ifndef TERMINFO - if (CM == NULL) -#else /* TERMINFO */ - if (cursor_address == NULL) /* assume mtr wanted "cm", not "CM" */ -#endif /* TERMINFO */ - if (nprog) - return NOTOK; - else - adios (NULL, - "sorry, your terminal isn't powerful enough to run %s", - invo_name); - -#ifndef TERMINFO - if (tgetflag ("xt") || tgetnum ("sg") > 0) - SO = SE = US = UE = NULL; -#else /* TERMINFO */ -/* - * If termcap mapped directly to terminfo, we'd use the following: - * if (teleray_glitch || magic_cookie_glitch > 0) - * enter_standout_mode = exit_standout_mode = - * enter_underline_mode = exit_underline_mode = NULL; - * But terminfo does the right thing so we don't have to resort to that. - */ -#endif /* TERMINFO */ - - if ((nlines = LINES - 1) < 11) - adios (NULL, "screen too small"); - if ((top = nlines / 3 + 1) > LINES / 4 + 2) - top--; - bottom = nlines - top - 2; - - numwins = 0; - Scan = windows[numwins++] = newwin (top, COLS, 0, 0); - Status = windows[numwins++] = newwin (1, COLS, top, 0); -#ifndef XYZ - wstandout (Status); -#endif /* XYZ */ - Display = windows[numwins++] = newwin (bottom, COLS, top + 1, 0); - Command = newwin (1, COLS - 1, top + 1 + bottom, 0); - windows[numwins] = NULL; - - largemove = Display->_maxy / 2 + 2; - return OK; -} - - -static int WINgetstr (WINDOW *w, char *buffer) -{ - register int c; - register char *bp; - - bp = buffer; - *bp = 0; - - for (;;) { - switch (c = toascii (wgetch (w))) { - case ERR: - adios (NULL, "wgetch lost"); - - case '\f': - wrefresh (curscr); - break; - - case '\r': - case '\n': - *bp = 0; - if (bp > buffer) { - leaveok (curscr, FALSE); - wmove (w, 0, w->_curx - (bp - buffer)); - wrefresh (w); - leaveok (curscr, TRUE); - } - return DONE; - - default: - if (c == intrc) { - wprintw (w, " "); - wstandout (w); - wprintw (w, "Interrupt"); - wstandend (w); - wrefresh (w); - *buffer = 0; - return NOTOK; - } - if (c == EOFC) { - if (bp <= buffer) - return OK; - break; - } - if (c == ERASE) { - if (bp <= buffer) - continue; - bp--, w->_curx--; - wclrtoeol (w); - break; - } - if (c == KILL) { - if (bp <= buffer) - continue; - w->_curx -= bp - buffer; - bp = buffer; - wclrtoeol (w); - break; - } - if (c == WERASC) { - if (bp <= buffer) - continue; - do { - bp--, w->_curx--; - } while (isspace (*bp) && bp > buffer); - - if (bp > buffer) { - do { - bp--, w->_curx--; - } while (!isspace (*bp) && bp > buffer); - if (isspace (*bp)) - bp++, w->_curx++; - } - wclrtoeol (w); - break; - } - - if (c >= ' ' && c < '\177') - waddch (w, *bp++ = c); - break; - } - - wrefresh (w); - } -} - - -static int -WINwritev (WINDOW *w, struct iovec *iov, int n) -{ - register int i; - - werase (w); - wmove (w, 0, 0); - for (i = 0; i < n; i++, iov++) - wprintw (w, "%*.*s", iov->iov_len, iov->iov_len, iov->iov_base); - wrefresh (w); - - sleep (PAUSE); - - return OK; -} - - -static struct { - char *h_msg; - int *h_val; -} hlpmsg[] = { - " forward backwards", NULL, - " ------- ---------", NULL, - "next screen SPACE", NULL, - "next %d line%s RETURN y", &smallmove, - "next %d line%s EOT u", &largemove, - "go g G", NULL, - "", NULL, - "refresh CTRL-L", NULL, - "quit q", NULL, - - NULL, NULL -}; - - -static int -WINless (WINDOW *w, int fin) -{ - register int c, i, n; - char *cp; - register struct line *lbottom; - int nfresh, nwait; - -#ifdef notdef - int nlatch; -#endif - - did_less++; - - cp = NULL; -#ifdef notdef - if (fin) - ltop = NULL; -#endif /* notdef */ - lbottom = NULL; - nfresh = 1; - nwait = 0; - wrefresh (w); - - for (;;) { - if (nfresh || nwait) { - nfresh = 0; -#ifdef notdef - nlatch = 1; - -once_only: ; -#endif /* notdef */ - werase (w); - wmove (w, 0, 0); - - if (ltop == NULL) - if (fin) { - lgo (ltail->l_no - w->_maxy + 1); - if (ltop == NULL) - ltop = lhead; - } - else - ltop = lbottom && lbottom->l_prev ? lbottom->l_prev - : lbottom; - - for (lbottom = ltop; lbottom; lbottom = lbottom->l_next) - if (waddstr (w, lbottom->l_buf) == ERR - || waddch (w, '\n') == ERR) - break; - if (lbottom == NULL) - if (fin) { -#ifdef notdef - if (nlatch && (ltail->l_no >= w->_maxy)) { - lgo (ltail->l_no - w->_maxy + 1); - nlatch = 0; - goto once_only; - } -#endif /* notdef */ - lbottom = ltail; - while (waddstr (w, "~\n") != ERR) - continue; - } - else { - wrefresh (w); - return 0; - } - - if (!nwait) - wrefresh (w); - } - - wmove (Command, 0, 0); - if (cp) { - wstandout (Command); - wprintw (Command, "%s", cp); - wstandend (Command); - cp = NULL; - } - else - wprintw (Command, fin ? "top:%d bot:%d end:%d" : "top:%d bot:%d", - ltop->l_no, lbottom->l_no, ltail->l_no); - wprintw (Command, ">> "); - wclrtoeol (Command); - wrefresh (Command); - - c = toascii (wgetch (Command)); - - werase (Command); - wrefresh (Command); - - if (nwait) { - nwait = 0; - wrefresh (w); - } - - n = 0; -again: ; - switch (c) { - case ' ': - ltop = lbottom->l_next; - nfresh++; - break; - - case '\r': - case '\n': - case 'e': - case 'j': - if (n) - smallmove = n; - if (ladvance (smallmove)) - nfresh++; - break; - - case 'y': - case 'k': - if (n) - smallmove = n; - if (lretreat (smallmove)) - nfresh++; - break; - - case 'd': - eof: ; - if (n) - largemove = n; - if (ladvance (largemove)) - nfresh++; - break; - - case 'u': - if (n) - largemove = n; - if (lretreat (largemove)) - nfresh++; - break; - - case 'g': - if (lgo (n ? n : 1)) - nfresh++; - break; - - case 'G': - if (lgo (n ? n : ltail->l_no - w->_maxy + 1)) - nfresh++; - break; - - case '\f': - case 'r': - wrefresh (curscr); - break; - - case 'h': - case '?': - werase (w); - wmove (w, 0, 0); - for (i = 0; hlpmsg[i].h_msg; i++) { - if (hlpmsg[i].h_val) - wprintw (w, hlpmsg[i].h_msg, *hlpmsg[i].h_val, - *hlpmsg[i].h_val != 1 ? "s" : ""); - else - waddstr (w, hlpmsg[i].h_msg); - waddch (w, '\n'); - } - wrefresh (w); - nwait++; - break; - - case 'q': - return 1; - - default: - if (c == EOFC) - goto eof; - - if (isdigit (c)) { - wmove (Command, 0, 0); - i = 0; - while (isdigit (c)) { - wprintw (Command, "%c", c); - wrefresh (Command); - i = i * 10 + c - '0'; - c = toascii (wgetch (Command)); - } - werase (Command); - wrefresh (Command); - - if (i > 0) { - n = i; - goto again; - } - cp = "bad number"; - } - else - cp = "not understood"; - break; - } - } -} - - -static int -WINputc (WINDOW *w, char c) -{ - register int x, y; - - switch (c) { - default: - if (!isascii (c)) { - if (WINputc (w, 'M') == ERR || WINputc (w, '-') == ERR) - return ERR; - c = toascii (c); - } - else - if (c < ' ' || c == '\177') { - if (WINputc (w, '^') == ERR) - return ERR; - c ^= 0100; - } - break; - - case '\t': - case '\n': - break; - } - - if (w != Scan) - return waddch (w, c); - - if ((x = w->_curx) < 0 || x >= w->_maxx - || (y = w->_cury) < 0 || y >= w->_maxy) - return DONE; - - switch (c) { - case '\t': - for (x = 8 - (x & 0x07); x > 0; x--) - if (WINputc (w, ' ') == ERR) - return ERR; - break; - - case '\n': - if (++y < w->_maxy) - waddch (w, c); - else - wclrtoeol (w); - break; - - default: - if (++x < w->_maxx) - waddch (w, c); - break; - } - - return DONE; -} - -/* LINES */ - -static void -lreset (void) -{ - register struct line *lp, *mp; - - for (lp = lhead; lp; lp = mp) { - mp = lp->l_next; - free (lp->l_buf); - free ((char *) lp); - } - lhead = ltop = ltail = NULL; -} - - -static void -linsert (WINDOW *w) -{ - register char *cp; - register struct line *lp; - - if ((lp = (struct line *) calloc ((size_t) 1, sizeof *lp)) == NULL) - adios (NULL, "unable to allocate line storage"); - - lp->l_no = (ltail ? ltail->l_no : 0) + 1; -#ifndef BSD44 - lp->l_buf = getcpy (w->_y[w->_cury]); -#else - lp->l_buf = getcpy (w->lines[w->_cury]->line); -#endif - for (cp = lp->l_buf + strlen (lp->l_buf) - 1; cp >= lp->l_buf; cp--) - if (isspace (*cp)) - *cp = 0; - else - break; - - if (lhead == NULL) - lhead = lp; - if (ltop == NULL) - ltop = lp; - if (ltail) - ltail->l_next = lp; - lp->l_prev = ltail; - ltail = lp; -} - - -static int -ladvance (int n) -{ - register int i; - register struct line *lp; - - for (i = 0, lp = ltop; i < n && lp; i++, lp = lp->l_next) - continue; - - if (ltop == lp) - return 0; - - ltop = lp; - return 1; -} - - -static int -lretreat (int n) -{ - register int i; - register struct line *lp; - - for (i = 0, lp = ltop; i < n && lp; i++, lp = lp->l_prev) - if (!lp->l_prev) - break; - - if (ltop == lp) - return 0; - - ltop = lp; - return 1; -} - - -static int -lgo (int n) -{ - register int i, j; - register struct line *lp; - - if ((i = n - (lp = lhead)->l_no) - > (j = abs (n - (ltop ? ltop : ltail)->l_no))) - i = j, lp = ltop ? ltop : ltail; - if (i > (j = abs (ltail->l_no - n))) - i = j, lp = ltail; - - if (n >= lp->l_no) { - for (; lp; lp = lp->l_next) - if (lp->l_no == n) - break; - } - else { - for (; lp; lp = lp->l_prev) - if (lp->l_no == n) - break; - if (!lp) - lp = lhead; - } - - if (ltop == lp) - return 0; - - ltop = lp; - return 1; -} - -/* TTYS */ - -static int -TTYinit (int nprog) -{ - if (!isatty (fileno (stdin)) || !isatty (fileno (stdout))) - if (nprog) - return NOTOK; - else - adios (NULL, "not a tty"); - - foreground (); -#ifndef SYS5 - if (ioctl (fileno (stdin), TIOCGETP, (char *) &sg) == NOTOK) - adios ("failed", "ioctl TIOCGETP"); - if (ioctl (fileno (stdin), TIOCGETC, (char *) &tc) == NOTOK) - adios ("failed", "ioctl TIOCGETC"); -#else -#ifdef TCGETATTR - if( tcgetattr( fileno(stdin), &sg) == NOTOK) - adios( "failed", "tcgetattr"); -#else /* SYS5 */ - if (ioctl (fileno (stdin), TCGETA, &sg) == NOTOK) - adios ("failed", "ioctl TCGETA"); -#endif -#endif -#ifdef TIOCGLTC - if (ioctl (fileno (stdin), TIOCGLTC, (char *) <c) == NOTOK) - adios ("failed", "ioctl TIOCGLTC"); -#endif /* TIOCGLTC */ - intrc = INTR; - sideground (); - - tty_ready = OK; - - SIGNAL (SIGPIPE, PIPEser); - - return OK; -} - - -static void -TTYon (void) -{ - if (tty_ready == DONE) - return; - - INTR = NOTOK; -#ifndef SYS5 - ioctl (fileno (stdin), TIOCSETC, (char *) &tc); -#else /* SYS5 */ - ioctl (fileno (stdin), TCSETA, &sg); -#endif /* SYS5 */ - - crmode (); - noecho (); - nonl (); - scrollok (curscr, FALSE); - - discard (stdin); - - tty_ready = DONE; - - SIGNAL (SIGHUP, SIGser); - SIGNAL (SIGINT, SIGser); - SIGNAL (SIGQUIT, SIGser); -#ifdef SIGTSTP - SIGNAL (SIGTSTP, TSTPser); -#endif /* SIGTSTP */ -} - - -static void -TTYoff (void) -{ - if (tty_ready == NOTOK) - return; - - INTR = intrc; -#ifndef SYS5 - ioctl (fileno (stdin), TIOCSETC, (char *) &tc); -#else /* SYS5 */ - ioctl (fileno (stdin), TCSETA, &sg); -#endif /* SYS5 */ - - leaveok (curscr, TRUE); - mvcur (0, COLS - 1, LINES - 1, 0); - endwin (); - if (tty_ready == DONE) { -#ifndef TERMINFO - if (CE) - tputs (CE, 0, _putchar); - else -#else /* TERMINFO */ - putp(clr_eol); -#endif /* TERMINFO */ - fprintf (stdout, "\r\n"); - } - fflush (stdout); - - tty_ready = NOTOK; - - SIGNAL (SIGHUP, SIG_DFL); - SIGNAL (SIGINT, SIG_DFL); - SIGNAL (SIGQUIT, SIG_DFL); -#ifdef SIGTSTP - SIGNAL (SIGTSTP, SIG_DFL); -#endif /* SIGTSTP */ -} - - -static void -foreground (void) -{ -#ifdef TIOCGPGRP - int pgrp, tpgrp; - SIGNAL_HANDLER tstat; - - if ((pgrp = getpgrp()) == NOTOK) - adios ("process group", "unable to determine"); - for (;;) { - if (ioctl (fileno (stdin), TIOCGPGRP, (char *) &tpgrp) == NOTOK) - adios ("tty's process group", "unable to determine"); - if (pgrp == tpgrp) - break; - - tstat = SIGNAL (SIGTTIN, SIG_DFL); - kill (0, SIGTTIN); - SIGNAL (SIGTTIN, tstat); - } - - SIGNAL (SIGTTIN, SIG_IGN); - SIGNAL (SIGTTOU, SIG_IGN); - SIGNAL (SIGTSTP, SIG_IGN); -#endif /* TIOCGPGRP */ -} - - -void -sideground (void) -{ -#ifdef TIOCGPGRP - SIGNAL (SIGTTIN, SIG_DFL); - SIGNAL (SIGTTOU, SIG_DFL); - SIGNAL (SIGTSTP, SIG_DFL); -#endif /* TIOCGPGRP */ -} - -/* SIGNALS */ - - -static RETSIGTYPE -ALRMser (int sig) -{ - longjmp (PEERctx, DONE); -} - - -#ifdef BSD42 -/* ARGSUSED */ -#endif /* BSD42 */ - -static RETSIGTYPE -PIPEser (int sig) -{ -#ifndef RELIABLE_SIGNALS - SIGNAL (sig, SIG_IGN); -#endif - - adios (NULL, "lost peer"); -} - - -static RETSIGTYPE -SIGser (int sig) -{ -#ifndef RELIABLE_SIGNALS - SIGNAL (sig, SIG_IGN); -#endif - - done (1); -} - - -#ifdef SIGTSTP -static RETSIGTYPE -TSTPser (int sig) -{ -#ifndef TERMINFO - tputs (tgoto (CM, 0, LINES - 1), 0, _putchar); -#else /* TERMINFO */ - move(LINES - 1, 0); /* to lower left corner */ - clrtoeol(); /* clear bottom line */ - wrefresh(curscr); /* flush out everything */ -#endif /* TERMINFO */ - fflush (stdout); - - TTYoff (); -#ifdef BSD42 - sigsetmask (sigblock (0) & ~sigmask (SIGTSTP)); -#endif /* BSD42 */ - - kill (getpid (), sig); - -#ifdef BSD42 - sigblock (sigmask (SIGTSTP)); -#endif /* BSD42 */ - TTYon (); - - wrefresh (curscr); -} -#endif /* SIGTSTP */ - - -/* MISCELLANY */ - -int -done (int status) -{ - TTYoff (); - pFIN (); - - exit (status); - return 1; /* dead code to satisfy the compiler */ -} - - -static void -adorn (char *what, char *fmt, ...) -{ - va_list ap; - char *cp; - - cp = invo_name; - invo_name = NULL; - - va_start(ap, fmt); - advertise (what, NULL, fmt, ap); - va_end(ap); - - invo_name = cp; -} - - -void -advertise (char *what, char *tail, char *fmt, va_list ap) -{ - int eindex = errno; - char buffer[BUFSIZ], err[BUFSIZ]; - struct iovec iob[20]; - register struct iovec *iov = iob; - - fflush (stdout); - fflush (stderr); - - if (invo_name) { - iov->iov_len = strlen (iov->iov_base = invo_name); - iov++; - iov->iov_len = strlen (iov->iov_base = ": "); - iov++; - } - - vsnprintf (buffer, sizeof(buffer), fmt, ap); - iov->iov_len = strlen (iov->iov_base = buffer); - iov++; - if (what) { - if (*what) { - iov->iov_len = strlen (iov->iov_base = " "); - iov++; - iov->iov_len = strlen (iov->iov_base = what); - iov++; - iov->iov_len = strlen (iov->iov_base = ": "); - iov++; - } - if (!(iov->iov_base = strerror (eindex))) { - snprintf (err, sizeof(err), "Error %d", eindex); - iov->iov_base = err; - } - iov->iov_len = strlen (iov->iov_base); - iov++; - } - if (tail && *tail) { - iov->iov_len = strlen (iov->iov_base = ", "); - iov++; - iov->iov_len = strlen (iov->iov_base = tail); - iov++; - } - iov->iov_len = strlen (iov->iov_base = "\n"); - iov++; - - if (tty_ready == DONE) - WINwritev (Display, iob, iov - iob); - else - writev (fileno (stderr), iob, iov - iob); -} - diff --git a/uip/vmhtest.c b/uip/vmhtest.c deleted file mode 100644 index 572bad5..0000000 --- a/uip/vmhtest.c +++ /dev/null @@ -1,324 +0,0 @@ - -/* - * vmhtest.c -- test out vmh protocol - * - * This code is Copyright (c) 2002, by the authors of nmh. See the - * COPYRIGHT file in the root directory of the nmh distribution for - * complete copyright information. - */ - -#include -#include - -static struct swit switches[] = { -#define READSW 0 - { "vmhread fd", 7 }, -#define WRITESW 1 - { "vmhwrite fd", 8 }, -#define VERSIONSW 2 - { "version", 0 }, -#define HELPSW 3 - { "help", 0 }, - { NULL, NULL } -}; - -#define NWIN 20 -static int numwins = 0; -static int windows[NWIN + 1]; - - -static int selcmds = 0; -#define selcmd() (selcmds++ % 2) - -static int selwins = 0; -#define selwin() (selwins++ % 2 ? 3 : 1) - - -int -main (int argc, char **argv) -{ - int fd1, fd2; - char *cp, buffer[BUFSIZ]; - char **argp, **arguments; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* foil search of user profile/context */ - if (context_foil (NULL) == -1) - done (1); - - arguments = getarguments (invo_name, argc, argv, 0); - argp = arguments; - - while ((cp = *argp++)) - if (*cp == '-') - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buffer, sizeof(buffer), "%s [switches]", invo_name); - print_help (buffer, switches, 0); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case READSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((fd1 = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); - continue; - case WRITESW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((fd2 = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); - continue; - } - else - adios (NULL, "usage: %s [switches]", invo_name); - - rcinit (fd1, fd2); - pINI (); - pLOOP (); - - return done (0); -} - - -static int pINI () { - int i, - vrsn; - char *bp; - struct record rcs, - *rc = &rcs; - - initrc (rc); - - switch (peer2rc (rc)) { - case RC_INI: - bp = rc->rc_data; - while (isspace (*bp)) - bp++; - if (sscanf (bp, "%d", &vrsn) != 1) { - bad_init: ; - fmt2peer (RC_ERR, "bad init \"%s\"", rc->rc_data); - done (1); - } - if (vrsn != RC_VRSN) { - fmt2peer (RC_ERR, "version %d unsupported", vrsn); - done (1); - } - - while (*bp && !isspace (*bp)) - bp++; - while (isspace (*bp)) - bp++; - if (sscanf (bp, "%d", &numwins) != 1 || numwins <= 0) - goto bad_init; - if (numwins > NWIN) - numwins = NWIN; - - for (i = 1; i <= numwins; i++) { - while (*bp && !isspace (*bp)) - bp++; - while (isspace (*bp)) - bp++; - if (sscanf (bp, "%d", &windows[i]) != 1 || windows[i] <= 0) - goto bad_init; - } - rc2peer (RC_ACK, 0, NULL); - return OK; - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - fmt2peer (RC_ERR, "pINI protocol screw-up"); - done (1); /* NOTREACHED */ - } -} - - -static int pLOOP () { - struct record rcs, - *rc = &rcs; - - initrc (rc); - - for (;;) - switch (peer2rc (rc)) { - case RC_QRY: - pQRY (rc->rc_data); - break; - - case RC_CMD: - pCMD (rc->rc_data); - break; - - case RC_FIN: - done (0); - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - fmt2peer (RC_ERR, "pLOOP protocol screw-up"); - done (1); - } -} - - -static int pQRY (str) -char *str; -{ - rc2peer (RC_EOF, 0, NULL); - return OK; -} - - -static int pCMD (str) -char *str; -{ - if ((selcmd () ? pTTY (str) : pWIN (str)) == NOTOK) - return NOTOK; - rc2peer (RC_EOF, 0, NULL); - return OK; -} - - -static int pTTY (str) -char *str; -{ - struct record rcs, - *rc = &rcs; - - initrc (rc); - - switch (rc2rc (RC_TTY, 0, NULL, rc)) { - case RC_ACK: - break; - - case RC_ERR: - return NOTOK; - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - fmt2peer (RC_ERR, "pTTY protocol screw-up"); - done (1); - } - - system (str); - - switch (rc2rc (RC_EOF, 0, NULL, rc)) { - case RC_ACK: - return OK; - - case RC_XXX: - adios (NULL, "%s", rc->rc_data);/* NOTREACHED */ - - default: - fmt2peer (RC_ERR, "pTTY protocol screw-up"); - done (1); /* NOTREACHED */ - } -} - - -static int pWIN (str) -char *str; -{ - int i, - pid, - pd[2]; - char buffer[BUFSIZ]; - struct record rcs, - *rc = &rcs; - - initrc (rc); - - snprintf (buffer, sizeof(buffer), "%d", selwin ()); - switch (str2rc (RC_WIN, buffer, rc)) { - case RC_ACK: - break; - - case RC_ERR: - return NOTOK; - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - fmt2peer (RC_ERR, "pWIN protocol screw-up"); - done (1); - } - - if (pipe (pd) == NOTOK) { - fmt2peer (RC_ERR, "no pipes"); - return NOTOK; - } - - switch (pid = vfork ()) { - case NOTOK: - fmt2peer (RC_ERR, "no forks"); - return NOTOK; - - case OK: - close (0); - open ("/dev/null", O_RDONLY); - dup2 (pd[1], 1); - dup2 (pd[1], 2); - close (pd[0]); - close (pd[1]); - execlp ("/bin/sh", "sh", "-c", str, NULL); - write (2, "no shell\n", strlen ("no shell\n")); - _exit (1); - - default: - close (pd[1]); - while ((i = read (pd[0], buffer, sizeof buffer)) > 0) - switch (rc2rc (RC_DATA, i, buffer, rc)) { - case RC_ACK: - break; - - case RC_ERR: - close (pd[0]); - pidwait (pid, OK); - return NOTOK; - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - fmt2peer (RC_ERR, "pWIN protocol screw-up"); - done (1); - } - if (i == OK) - switch (rc2rc (RC_EOF, 0, NULL, rc)) { - case RC_ACK: - break; - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - fmt2peer (RC_ERR, "pWIN protocol screw-up"); - done (1); - } - if (i == NOTOK) - fmt2peer (RC_ERR, "read from pipe lost"); - - close (pd[0]); - pidwait (pid, OK); - return (i != NOTOK ? OK : NOTOK); - } -} diff --git a/uip/wmh.c b/uip/wmh.c deleted file mode 100644 index e5ff490..0000000 --- a/uip/wmh.c +++ /dev/null @@ -1,1389 +0,0 @@ - -/* - * wmh.c -- window front-end to nmh - * - * This code is Copyright (c) 2002, by the authors of nmh. See the - * COPYRIGHT file in the root directory of the nmh distribution for - * complete copyright information. - */ - -/* - * TODO: - * Pass signals to client during execution - * - * Figure out a way for the user to say how big the Scan/Display - * windows should be, and where all the windows should be. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#define ALARM ((unsigned int) 10) -#define PAUSE ((unsigned int) 2) - -#define SZ(a) (sizeof a / sizeof a[0]) - -static struct swit switches[] = { -#define PRMPTSW 0 - { "prompt string", 6 }, -#define PROGSW 1 - { "vmhproc program", 7 }, -#define NPROGSW 2 - { "novmhproc", 9 }, -#define VERSIONSW 3 - { "version", 0 }, -#define HELPSW 4 - { "help", 0 }, - { NULL, NULL } -}; - /* PEERS */ -static int PEERpid = NOTOK; - -static jmp_buf PEERctx; - - - /* WINDOWS */ -static int dfd = NOTOK; -static int twd = NOTOK; -static char *myprompt = "(%s) "; - -struct line { - int l_no; - char *l_buf; - struct line *l_prev; - struct line *l_next; -}; - -#define W_NULL 0x00 -#define W_CMND 0x01 -#define W_FAKE 0x02 -#define W_EBAR 0x04 - -typedef struct { - int w_fd; - int w_flags; - int w_wd; - struct wstate w_ws; - char *w_eb; - int w_ebloc; - int w_ebsize; - int w_cbase; - int w_height; - int w_cheight; - int w_width; - int w_cwidth; - struct line *w_head; - struct line *w_top; - struct line *w_bottom; - struct line *w_tail; - char w_buffer[BUFSIZ]; - int w_bufpos; -} WINDOW; - - -static WINDOW *Scan; -static WINDOW *Status; -static WINDOW *Display; -static WINDOW *Command; - -#define NWIN 4 -static int numwins; -WINDOW *windows[NWIN + 1]; - -WINDOW *WINnew (); - - -#ifdef HAVE_TERMIOS_H -static struct termios tio; -# define ERASE tio.c_cc[VERASE] -# define KILL tio.c_cc[VKILL] -# define INTR tio.c_cc[VINTR] -#else -# ifdef HAVE_TERMIO_H -static struct termio tio; -# define ERASE tio.c_cc[VERASE] -# define KILL tio.c_cc[VKILL] -# define INTR tio.c_cc[VINTR] -# else -static struct sgttyb tio; -static struct tchars tc; -# define ERASE tio.sg_erase -# define KILL tio.sg_kill -# define INTR tc.t_intrc -# define EOFC tc.t_eofc -# endif -#endif - -#define WERASC ltc.t_werasc -static struct ltchars ltc; - - -int ALRMser (), PIPEser (), SIGser (); -int ADJser (), REFser (); - -/* - * static prototypes - */ -static void adorn(char *, char *, ...); - - -int -main (int argc, char **argv) -{ - int vecp = 1, nprog = 0; - char *cp, buffer[BUFSIZ], **argp; - char **arguments, *vec[MAXARGS]; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc,argv, 1); - argp = arguments; - - while ((cp = *argp++)) - if (*cp == '-') - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - vec[vecp++] = --cp; - continue; - - case HELPSW: - snprintf (buffer, sizeof(buffer), "%s [switches for vmhproc]", - invo_name); - print_help (buffer, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case PRMPTSW: - if (!(myprompt = *argp++) || *myprompt == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case PROGSW: - if (!(vmhproc = *argp++) || *vmhproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NPROGSW: - nprog++; - continue; - } - else - vec[vecp++] = cp; - - SIGinit (); - if (WINinit (nprog) == NOTOK) { - vec[vecp] = NULL; - - vec[0] = r1bindex (vmhproc, '/'); - execvp (vmhproc, vec); - adios (vmhproc, "unable to exec"); - } - PEERinit (vecp, vec); - - vmh (); - - return done (0); -} - - -static void -vmh (void) -{ - char buffer[BUFSIZ], prompt[BUFSIZ]; - - for (;;) { - pLOOP (RC_QRY, NULL); - - snprintf (prompt, sizeof(prompt), myprompt, invo_name); - - switch (WINgetstr (Command, prompt, buffer)) { - case NOTOK: - break; - - case OK: - done (0); /* NOTREACHED */ - - default: - if (*buffer) - pLOOP (RC_CMD, buffer); - break; - } - } -} - -/* PEERS */ - -static int -PEERinit (int vecp, char *vec[]) -{ - int pfd0[2], pfd1[2]; - char buf1[BUFSIZ], buf2[BUFSIZ]; - register WINDOW **w; - - SIGNAL (SIGPIPE, PIPEser); - - if (pipe (pfd0) == NOTOK || pipe (pfd1) == NOTOK) - adios ("pipe", "unable to"); - switch (PEERpid = vfork ()) { - case NOTOK: - adios ("vfork", "unable to");/* NOTREACHED */ - - case OK: - for (w = windows; *w; w++) - if ((*w)->w_fd != NOTOK) - close ((*w)->w_fd); - close (pfd0[0]); - close (pfd1[1]); - - vec[vecp++] = "-vmhread"; - snprintf (buf1, sizeof(buf1), "%d", pfd1[0]); - vec[vecp++] = buf1; - vec[vecp++] = "-vmhwrite"; - snprintf (buf2, sizeof(buf2), "%d", pfd0[1]); - vec[vecp++] = buf2; - vec[vecp] = NULL; - - SIGNAL (SIGINT, SIG_DFL); - SIGNAL (SIGQUIT, SIG_DFL); - SIGNAL (SIGTERM, SIG_DFL); - - vec[0] = r1bindex (vmhproc, '/'); - execvp (vmhproc, vec); - perror (vmhproc); - _exit (-1); /* NOTREACHED */ - - default: - close (pfd0[1]); - close (pfd1[0]); - - rcinit (pfd0[0], pfd1[1]); - return pINI (); - } -} - - -static int -pINI (void) -{ - int len, buflen; - char *bp, buffer[BUFSIZ]; - struct record rcs, *rc; - WINDOW **w; - - rc = &rcs; - initrc (rc); - - /* Get buffer ready to go */ - bp = buffer; - buflen = sizeof(buffer); - - snprintf (bp, buflen, "%d %d", RC_VRSN, numwins); - len = strlen (bp); - bp += len; - buflen -= len; - - for (w = windows; *w; w++) { - snprintf (bp, buflen, " %d", (*w)->w_height); - len = strlen (bp); - bp += len; - buflen -= len; - } - - switch (str2rc (RC_INI, buffer, rc)) { - case RC_ACK: - return OK; - - case RC_ERR: - if (rc->rc_len) - adios (NULL, "%s", rc->rc_data); - else - adios (NULL, "pINI peer error"); - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - adios (NULL, "pINI protocol screw-up"); - } -/* NOTREACHED */ -} - - -static int -pLOOP (char code, char *str) -{ - int i; - struct record rcs, *rc; - WINDOW *w; - - rc = &rcs; - initrc (rc); - - str2peer (code, str); - for (;;) - switch (peer2rc (rc)) { - case RC_TTY: - if (pTTY () == NOTOK) - return NOTOK; - break; - - case RC_WIN: - if (sscanf (rc->rc_data, "%d", &i) != 1 - || i <= 0 - || i > numwins) { - fmt2peer (RC_ERR, "no such window \"%s\"", rc->rc_data); - return NOTOK; - } - if ((w = windows[i - 1])->w_flags & W_CMND) { - fmt2peer (RC_ERR, "not a display window \"%s\"", rc->rc_data); - return NOTOK; - } - if (pWIN (w) == NOTOK) - return NOTOK; - break; - - case RC_EOF: - return OK; - - case RC_ERR: - if (rc->rc_len) - adorn (NULL, "%s", rc->rc_data); - else - adorn (NULL, "pLOOP(%s) peer error", - code == RC_QRY ? "QRY" : "CMD"); - return NOTOK; - - case RC_FIN: - if (rc->rc_len) - adorn (NULL, "%s", rc->rc_data); - rcdone (); - i = pidwait (PEERpid, OK); - PEERpid = NOTOK; - done (i); - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - adios (NULL, "pLOOP(%s) protocol screw-up", - code == RC_QRY ? "QRY" : "CMD"); - } -} - - -static int -pTTY (void) -{ - SIGNAL_HANDLER hstat, istat, qstat, tstat; - struct record rcs, *rc; - - rc = &rcs; - initrc (rc); - - if (ChangeWindowDepth (dfd, twd, 0) == NOTOK) - adios ("failed", "ChangeWindowDepth"); - - /* should block here instead of ignore */ - hstat = SIGNAL (SIGHUP, SIG_IGN); - istat = SIGNAL (SIGINT, SIG_IGN); - qstat = SIGNAL (SIGQUIT, SIG_IGN); - tstat = SIGNAL (SIGTERM, SIG_IGN); - - rc2rc (RC_ACK, 0, NULL, rc); - - SIGNAL (SIGHUP, hstat); - SIGNAL (SIGINT, istat); - SIGNAL (SIGQUIT, qstat); - SIGNAL (SIGTERM, tstat); - - switch (rc->rc_type) { - case RC_EOF: - rc2peer (RC_ACK, 0, NULL); - return OK; - - case RC_ERR: - if (rc->rc_len) - adorn (NULL, "%s", rc->rc_data); - else - adorn (NULL, "pTTY peer error"); - return NOTOK; - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - adios (NULL, "pTTY protocol screw-up"); - } -/* NOTREACHED */ -} - - -static int -pWIN (WINDOW *w) -{ - int i; - - if ((i = pWINaux (w)) == OK) - WINless (w); - - return i; -} - - -static int -pWINaux (WINDOW *w) -{ - register int n; - register char *bp; - register struct line *lp, *mp; - struct record rcs, *rc; - - rc = &rcs; - initrc (rc); - - for (lp = w->w_head; lp; lp = mp) { - mp = lp->l_next; - free (lp->l_buf); - free ((char *) lp); - } - w->w_head = w->w_top = w->w_bottom = w->w_tail = NULL; - w->w_bufpos = 0; - - for (;;) - switch (rc2rc (RC_ACK, 0, NULL, rc)) { - case RC_DATA: - for (bp = rc->rc_data, n = rc->rc_len; n-- > 0; ) - WINputc (w, *bp++); - break; - - case RC_EOF: - rc2peer (RC_ACK, 0, NULL); - if (w->w_bufpos) - WINputc (w, '\n'); - return OK; - - case RC_ERR: - if (rc->rc_len) - adorn (NULL, "%s", rc->rc_data); - else - adorn (NULL, "pWIN peer error"); - return NOTOK; - - case RC_XXX: - adios (NULL, "%s", rc->rc_data); - - default: - adios (NULL, "pWIN protocol screw-up"); - } -/* NOTREACHED */ -} - - -static int -pFIN (void) -{ - int status; - - if (PEERpid <= OK) - return OK; - - rc2peer (RC_FIN, 0, NULL); - rcdone (); - - switch (setjmp (PEERctx)) { - case OK: - SIGNAL (SIGALRM, ALRMser); - alarm (ALARM); - - status = pidwait (PEERpid, OK); - - alarm (0); - break; - - default: - kill (PEERpid, SIGKILL); - status = NOTOK; - break; - } - PEERpid = NOTOK; - - return status; -} - -/* WINDOWS */ - -/* should dynamically determine all this stuff from gconfig... */ - -#define MyX 20 /* anchored hpos */ -#define MyY 40 /* .. vpos */ -#define MyW 800 /* .. width */ -#define MyH 500 /* .. height */ -#define MyS 30 /* .. height for Status, about one line */ - - -#define MySlop 45 /* slop */ - -#define EWIDTH 25 /* Width of vertical EBAR */ -#define ESLOP 5 /* .. slop */ - - -static intWINinit (nprog) { - short wx, wy, wh, sy; - struct gconfig gc; - - if (GetGraphicsConfig (fileno (stderr), &gc) == NOTOK) - if (nprog) - return NOTOK; - else - adios (NULL, "not a window"); - - if ((dfd = open ("/dev/ttyw0", O_RDWR)) == NOTOK) - adios ("/dev/ttyw0", "unable to open"); - - if ((twd = GetTopWindow (dfd)) == NOTOK) - adios ("failed", "GetTopWindow"); - - BlockRefreshAdjust (1); - - numwins = 0; - - wx = gc.w - (MyX + MyW + EWIDTH + ESLOP); - Scan = WINnew (wx, wy = MyY, MyW, wh = MyH * 2 / 3, "Scan", W_EBAR); - - wy += wh + MySlop; - Status = WINnew (wx, sy = wy, MyW, wh = MyS, "Status", W_FAKE); - - wy += wh + MySlop; - Display = WINnew (wx, wy, MyW, MyH, "Display", W_EBAR); - - Command = WINnew (wx, sy, MyW, MyS, invo_name, W_CMND); - - windows[numwins] = NULL; - - return OK; -} - - -WINDOW * -WINnew (short wx, short wy, short ww, short wh, char *name, int flags) -{ - register WINDOW *w; - - if ((w = (WINDOW *) calloc (1, sizeof *w)) == NULL) - adios (NULL, "unable to allocate window"); - - if ((w->w_flags = flags) & W_FAKE) { - w->w_fd = NOTOK; - w->w_height = 1; - - goto out; - } - - if (w->w_flags & W_EBAR) - ww += EWIDTH + ESLOP; - else - wx += EWIDTH + ESLOP; - - if ((w->w_fd = OpenWindow (wx, wy, ww, wh, name)) == NOTOK) - adios ("failed", "OpenWindow"); - if ((w->w_wd = GetTopWindow (dfd)) == NOTOK) - adios ("failed", "GetTopWindow"); - if (GetWindowState (w->w_fd, &w->w_ws) == NOTOK) - adios ("failed", "GetWindowState"); - if (SetLineDisc (w->w_fd, TWSDISC) == NOTOK) - adios ("failed", "SetLineDisc"); - - SetBuf (w->w_fd, 1024); - SetAdjust (w->w_fd, numwins, ADJser); - SetRefresh (w->w_fd, numwins, REFser); - - SetAddressing (w->w_fd, VT_ABSOLUTE); - - if (w->w_flags & W_EBAR) { - w->w_eb = CreateElevatorBar (w->w_fd, 0, 0, EWIDTH, - w->w_ws.height, VT_Gray50, 1, EB_VERTICAL, - EB_ARROWS, w->w_ebloc = 0, w->w_ebsize = EB_MAX, - VT_White); - if (w->w_eb == NULL) - adios (NULL, "CreateElevatorBar failed"); - RefreshElevatorBar (w->w_eb); - } - - if ((w->w_cbase = CharacterBaseline (w->w_ws.font)) <= 0) - w->w_cbase = 14; - - if ((w->w_cheight = CharacterHeight (w->w_ws.font)) <= 0) - w->w_cheight = 20; - w->w_height = w->w_ws.height / w->w_cheight; - if (w->w_height < 1) - w->w_height = 1; - - /* 1 em */ - if ((w->w_cwidth = CharacterWidth (w->w_ws.font, 'm')) <= 0) - w->w_cwidth = 10; - w->w_width = (w->w_ws.width - (w->w_eb ? (EWIDTH + ESLOP) : 0)) - / w->w_cwidth; - if (w->w_width < 1) - w->w_width = 1; - -out: ; - windows[numwins++] = w; - - return w; -} - - -static int -WINgetstr (WINDOW *w, char *prompt, char *buffer) -{ - register int c; - register char *bp, *ip; - char image[BUFSIZ]; - struct vtseq vts; - register struct vtseq *vt = &vts; - - if (w->w_eb != NULL) - adios (NULL, "internal error--elevator bar found"); - - if (w->w_head == NULL - && (w->w_head = (struct line *) calloc (1, sizeof *w->w_head)) - == NULL) - adios (NULL, "unable to allocate line storage"); - w->w_head->l_buf = image; - w->w_top = w->w_bottom = w->w_tail = w->w_head; - - if (ChangeWindowDepth (dfd, w->w_wd, 0) == NOTOK) - adios ("failed", "ChangeWindowDepth"); - - strncpy (image, prompt, sizeof(image)); - bp = ip = image + strlen (image); - - Redisplay (w, 0); - - for (;;) - switch (getvtseq (w->w_fd, vt)) { - case VT_HARDKEY: - DisplayStatus (w->w_fd, "no hardkeys, please"); - break; - - case VT_ASCII: - switch (c = toascii (vt->u.ascii)) { - case '\f': /* refresh? */ - break; - - case '\r': - case '\n': - strcpy (buffer, ip); - return DONE; - - default: - if (c == INTR) { - adorn (NULL, "Interrupt"); - return NOTOK; - } - - if (c == EOFC) { - if (bp <= ip) - return OK; - break; - } - - if (c == ERASE) { - if (bp <= ip) - continue; - bp--; - break; - } - - if (c == KILL) { - if (bp <= ip) - continue; - bp = ip; - break; - } - - if (c == WERASC) { - if (bp <= ip) - continue; - do { - bp--; - } while (isspace (*bp) && bp > ip); - if (bp > ip) { - do { - bp--; - } while (!isspace (*bp) && bp > buffer); - if (isspace (*bp)) - bp++; - } - break; - } - - if (c < ' ' || c >= '\177') - continue; - *bp++ = c; - break; - } - *bp = NULL; - Redisplay (w, 0); - break; - - case VT_MOUSE: - switch (vt->u.mouse.buttons - & (VT_MOUSE_LEFT | VT_MOUSE_MIDDLE | VT_MOUSE_RIGHT)) { - case VT_MOUSE_LEFT: - DisplayStatus (w->w_fd, "use middle or right button"); - break; - -#define WPOP "WMH\0Advance\0Burst\0Exit\0EOF\0" - case VT_MOUSE_MIDDLE: - SetPosition (w->w_fd, vt->u.mouse.x, - vt->u.mouse.y); - switch (DisplayPopUp (w->w_fd, WPOP)) { - case 1: /* Advance */ - do_advance: ; - strcpy (buffer, "advance"); - return DONE; - - case 2: /* Burst */ - strcpy (buffer, "burst"); - return DONE; - - case 3: /* Exit */ - strcpy (buffer, "exit"); - return DONE; - - case 4: /* EOF */ - return OK; - - default: /* failed or none taken */ - break; - } - break; -#undef WPOP - - case VT_MOUSE_RIGHT: - goto do_advance; - } - break; - - case VT_EOF: - adios (NULL, "end-of-file on window");/* NOTREACHED */ - - default: - DisplayStatus (w->w_fd, "unknown VT sequence"); - break; - } -} - - -static int -WINputc (WINDOW *w, char c) -{ - register int i; - register char *cp; - register struct line *lp; - - switch (c) { - default: - if (!isascii (c)) { - if (WINputc (w, 'M') == NOTOK || WINputc (w, '-') == NOTOK) - return NOTOK; - c = toascii (c); - } - else - if (c < ' ' || c == '\177') { - if (WINputc (w, '^') == NOTOK) - return NOTOK; - c ^= 0100; - } - break; - - case '\t': - for (i = 8 - (w->w_bufpos & 0x07); i > 0; i--) - if (WINputc (w, ' ') == NOTOK) - return NOTOK; - return OK; - - case '\b': - if (w->w_bufpos > 0) - w->w_bufpos--; - return OK; - - case '\n': - break; - } - - if (c != '\n') { - w->w_buffer[w->w_bufpos++] = c; - return OK; - } - - w->w_buffer[w->w_bufpos] = NULL; - w->w_bufpos = 0; - - if ((lp = (struct line *) calloc (1, sizeof *lp)) == NULL) - adios (NULL, "unable to allocate line storage"); - - lp->l_no = (w->w_tail ? w->w_tail->l_no : 0) + 1; - lp->l_buf = getcpy (w->w_buffer); - for (cp = lp->l_buf + strlen (lp->l_buf) - 1; cp >= lp->l_buf; cp--) - if (isspace (*cp)) - *cp = NULL; - else - break; - - if (w->w_head == NULL) - w->w_head = lp; - if (w->w_top == NULL) - w->w_top = lp; - if (w->w_bottom == NULL) - w->w_bottom = lp; - if (w->w_tail) - w->w_tail->l_next = lp; - lp->l_prev = w->w_tail; - w->w_tail = lp; - - return DONE; -} - -#define PSLOP 2 - - -static char mylineno[5]; - -static bool cancel[] = { 1 }; -static struct choice mychoices[] = { LABEL, "cancel", VT_White }; - -static struct question myquestions[] = { - STRING, "Line", SZ (mylineno), (struct choice *) 0, - - TOGGLE, "", SZ (mychoices), mychoices -}; - -static struct menu mymenu = { "Goto", SZ (myquestions), myquestions }; - -static int *myanswers[] = { (int *) mylineno, (int *) cancel }; - - -static void -WINless (WINDOW *w) -{ - int clear, pos, forw, refresh; - struct vtseq vts; - register struct vtseq *vt = &vts; - - if (w->w_fd == NOTOK) { - if (w->w_head) - DisplayStatus (dfd, w->w_top->l_buf); - else - RemoveStatus (dfd); - - return; - } - - if (ChangeWindowDepth (dfd, w->w_wd, 0) == NOTOK) - adios ("failed", "ChangeWindowDepth"); - - Redisplay (w, 0); - - if (w->w_bottom == w->w_tail) - return; - - if (w->w_eb == NULL) - adios (NULL, "internal error--no elevator bar"); - - for (clear = refresh = 0, forw = 1;;) { - if (clear) { - RemoveStatus (w->w_fd); - clear = 0; - } - if (refresh) { - Redisplay (w, 0); - refresh = 0; - } - - switch (getvtseq (w->w_fd, vt)) { - case VT_HARDKEY: - case VT_ASCII: - DisplayStatus (w->w_fd, "use the mouse"); - clear++; - break; - - case VT_MOUSE: - switch (vt->u.mouse.buttons - & (VT_MOUSE_LEFT | VT_MOUSE_MIDDLE | VT_MOUSE_RIGHT)) { - case VT_MOUSE_LEFT: - if ((pos = vt->u.mouse.x) < EWIDTH) { - pos = w->w_ebloc = DoElevatorBar (w->w_eb, pos, - vt->u.mouse.y); - refresh = WINgoto (w, ((pos * (w->w_tail->l_no - - w->w_head->l_no)) - / EB_MAX) + w->w_head->l_no); - } - break; - -#define WPOP "Paging\0Next\0Prev\0Left\0Right\0First\0Last\0Goto ...\0Exit\0" - case VT_MOUSE_MIDDLE: - SetPosition (w->w_fd, vt->u.mouse.x, - vt->u.mouse.y); - switch (DisplayPopUp (w->w_fd, WPOP)) { - case 1: /* Next */ - do_next_page: ; - if (w->w_bottom == w->w_tail) - forw = 0; - refresh = WINgoto (w, w->w_bottom->l_no + 1 - PSLOP); - break; - - case 2: /* Prev */ - do_prev_page: ; - if (w->w_top == w->w_head) - forw = 1; - refresh = WINgoto (w, w->w_top->l_no - - w->w_height + PSLOP); - break; - - case 3: /* Left */ - case 4: /* Right */ - DisplayStatus (w->w_fd, "not yet"); - clear++; - break; - - case 5: /* First */ - forw = 1; - refresh = WINgoto (w, w->w_head->l_no); - break; - - case 6: /* Last */ - forw = 0; - refresh = WINgoto (w, w->w_tail->l_no - - w->w_height + 1); - break; - - case 7: /* Goto ... */ - snprintf (mylineno, sizeof(mylineno), - "%d", w->w_top->l_no); - cancel[0] = 0; - if (PresentMenu (&mymenu, myanswers) - || cancel[0]) - break; - if (sscanf (mylineno, "%d", &pos) != 1) { - DisplayStatus (w->w_fd, "bad format"); - clear++; - break; - } - if (pos < w->w_head->l_no - || pos > w->w_tail->l_no) { - DisplayStatus (w->w_fd, "no such line"); - clear++; - break; - } - refresh = WINgoto (w, pos); - break; - - case 8: /* Exit */ - return; - - default: /* failed or none taken */ - break; - } - break; -#undef WPOP - - case VT_MOUSE_RIGHT: - if (forw) { - if (w->w_bottom == w->w_tail) - return; - else - goto do_next_page; - } - else - goto do_prev_page; - } - break; - - case VT_EOF: - adios (NULL, "end-of-file on window");/* NOTREACHED */ - - default: - DisplayStatus (w->w_fd, "unknown VT sequence"); - clear++; - break; - } - } -} - - -static int -WINgoto (WINDOW *w, int n) -{ - register int i, j; - register struct line *lp; - - if (n > (i = w->w_tail->l_no - w->w_height + 1)) - n = i; - if (n < w->w_head->l_no) - n = w->w_head->l_no; - - if ((i = n - (lp = w->w_head)->l_no) - > (j = abs (n - w->w_top->l_no))) - i = j, lp = w->w_top; - - if (i > (j = abs (w->w_tail->l_no - n))) - i = j, lp = w->w_tail; - - if (n >= lp->l_no) { - for (; lp; lp = lp->l_next) - if (lp->l_no == n) - break; - } - else { - for (; lp; lp = lp->l_prev) - if (lp->l_no == n) - break; - if (!lp) - lp = w->w_head; - } - - if (w->w_top == lp) - return 0; - - w->w_top = lp; - - return 1; -} - - -static int -ADJser (int id, short ww, short wh) -{ - register WINDOW *w; - - if (id < 0 || id >= numwins) - adios (NULL, "ADJser on bogus window (%d)", id); - w = windows[id]; - if (w->w_fd == NOTOK) - adios (NULL, "ADJser on closed window (%d)", id); - - w->w_ws.width = w->w_ws.tw = ww; - w->w_ws.height = w->w_ws.th = wh; - - if (w->w_eb) { - DeleteElevatorBar (w->w_eb); - w->w_eb = CreateElevatorBar (w->w_fd, 0, 0, EWIDTH, - w->w_ws.height, VT_Gray50, 1, EB_VERTICAL, - EB_ARROWS, w->w_ebloc = 0, w->w_ebsize = EB_MAX, - VT_White); - if (w->w_eb == NULL) - adios (NULL, "CreateElevatorBar failed"); - } - - Redisplay (w, 1); -} - - -static int -REFser (int id, short wx, short wy, short ww, short wh) -{ - short cx, cy, cw, ch; - register WINDOW *w; - - if (id < 0 || id >= numwins) - adios (NULL, "REFser on bogus window (%d)", id); - w = windows[id]; - if (w->w_fd == NOTOK) - adios (NULL, "REFser on closed window (%d)", id); - - - if (GetWindowState (w->w_fd, &w->w_ws) == NOTOK) - adios ("failed", "GetWindowState"); - - GetPermanentClipping (w->w_fd, &cx, &cy, &cw, &ch); - SetPermanentClipping (w->w_fd, wx, wy, ww, wh); - Redisplay (w, 1); - SetPermanentClipping (w->w_fd, cx, cy, cw, ch); -} - - -static void -Redisplay (WINDOW *w, int doeb) -{ - register int y; - short sx; - register struct line *lp; - - if (w->w_fd == NOTOK) - return; - - sx = w->w_eb ? (EWIDTH + ESLOP) : 0; - w->w_height = w->w_ws.height / w->w_cheight; - if (w->w_height < 1) - w->w_height = 1; - - w->w_width = (w->w_ws.width - (w->w_eb ? (EWIDTH + ESLOP) : 0)) - / w->w_cwidth; - if (w->w_width < 1) - w->w_width = 1; - - SetPosition (w->w_fd, sx, 0); - SetColor (w->w_fd, VT_White); - PaintRectangleInterior (w->w_fd, w->w_ws.width, w->w_ws.height); - - if (w->w_head) { - SetColor (w->w_fd, VT_Black); - for (lp = w->w_top, y = 0; - lp && y < w->w_height; - w->w_bottom = lp, lp = lp->l_next, y++) { - SetPosition (w->w_fd, sx, y * w->w_cheight + w->w_cbase); - PaintString (w->w_fd, VT_STREND, lp->l_buf); - } - } - - if (w->w_eb) { - if ((y = EB_LOC (w)) != w->w_ebloc) - MoveElevator (w->w_eb, w->w_ebloc = y); - if ((y = EB_SIZE (w)) != w->w_ebsize) - SizeElevator (w->w_eb, w->w_ebsize = y); - if (doeb) - RefreshElevatorBar (w->w_eb); - } - - Flush (w->w_fd); -} - - -static int -EB_SIZE (WINDOW *w) -{ - register int i; - - if (w->w_head == NULL) - return 0; - - if ((i = w->w_tail->l_no - w->w_head->l_no) <= 0) - return EB_MAX; - - return (((w->w_bottom->l_no - w->w_top->l_no) * EB_MAX) / i); -} - - -static int -EB_LOC (WINDOW *w) -{ - register int i; - - if (w->w_head == NULL) - return 0; - - if ((i = w->w_tail->l_no - w->w_head->l_no) <= 0) - return EB_MAX; - - return (((w->w_top->l_no - w->w_head->l_no) * EB_MAX) / i); -} - -/* SIGNALS */ - -static void -SIGinit (void) -{ - foreground (); - if (ioctl (fileno (stdin), TIOCGETP, (char *) &tio) == NOTOK) - adios ("failed", "ioctl TIOCGETP"); - if (ioctl (fileno (stdin), TIOCGETC, (char *) &tc) == NOTOK) - adios ("failed", "ioctl TIOCGETC"); - if (ioctl (fileno (stdin), TIOCGLTC, (char *) <c) == NOTOK) - adios ("failed", "ioctl TIOCGLTC"); - sideground (); - - SIGNAL (SIGHUP, SIGser); - SIGNAL (SIGINT, SIGser); - SIGNAL (SIGQUIT, SIGser); -} - - -static void -foreground (void) -{ -#ifdef TIOCGPGRP - int pgrp, tpgrp; - SIGNAL_HANDLER tstat; - - if ((pgrp = getpgrp (0)) == NOTOK) - adios ("process group", "unable to determine"); - for (;;) { - if (ioctl (fileno (stdin), TIOCGPGRP, (char *) &tpgrp) == NOTOK) - adios ("tty's process group", "unable to determine"); - if (pgrp == tpgrp) - break; - - tstat = SIGNAL (SIGTTIN, SIG_DFL); - kill (0, SIGTTIN); - SIGNAL (SIGTTIN, tstat); - } - - SIGNAL (SIGTTIN, SIG_IGN); - SIGNAL (SIGTTOU, SIG_IGN); - SIGNAL (SIGTSTP, SIG_IGN); -#endif TIOCGPGRP -} - - -static void -sideground (void) -{ -#ifdef TIOCGPGRP - SIGNAL (SIGTTIN, SIG_DFL); - SIGNAL (SIGTTOU, SIG_DFL); - SIGNAL (SIGTSTP, SIG_DFL); -#endif TIOCGPGRP -} - - -static int -ALRMser (int sig) -{ - longjmp (PEERctx, DONE); -} - - -static int -PIPEser (int sig) -{ -#ifndef RELIABLE_SIGNALS - SIGNAL (sig, SIG_IGN); -#endif - - adios (NULL, "lost peer"); -} - - -static int -SIGser (int sig) -{ -#ifndef RELIABLE_SIGNALS - SIGNAL (sig, SIG_IGN); -#endif - - done (1); -} - - -int -done (int status) -{ - if (dfd != NOTOK) - RemoveStatus (dfd); - - pFIN (); - - exit (status); - return 1; /* dead code to satisfy the compiler */ -} - - -static void -adorn (char *what, char *fmt, ...) -{ - va_list ap - char *cp; - - cp = invo_name; - invo_name = NULL; - - va_start(ap, fmt); - advertise (what, NULL, fmt, ap); - va_end(ap); - - invo_name = cp; -} - - -void -advertise (char *what, char *tail, va_list ap) -{ - int eindex = errno; - char buffer[BUFSIZ], err[BUFSIZ]; - struct iovec iob[20]; - register struct iovec *iov = iob; - - fflush (stdout); - fflush (stderr); - - if (invo_name) { - iov->iov_len = strlen (iov->iov_base = invo_name); - iov++; - iov->iov_len = strlen (iov->iov_base = ": "); - iov++; - } - - vsnprintf (buffer, sizeof(buffer), fmt, ap); - iov->iov_len = strlen (iov->iov_base = buffer); - iov++; - if (what) { - if (*what) { - iov->iov_len = strlen (iov->iov_base = " "); - iov++; - iov->iov_len = strlen (iov->iov_base = what); - iov++; - iov->iov_len = strlen (iov->iov_base = ": "); - iov++; - } - if (!(iov->iov_base = strerror (eindex))) { - snprintf (err, sizeof(err), "unknown error %d", eindex); - iov->iov_base = err; - } - iov->iov_len = strlen (iov->iov_base); - iov++; - } - if (tail && *tail) { - iov->iov_len = strlen (iov->iov_base = ", "); - iov++; - iov->iov_len = strlen (iov->iov_base = tail); - iov++; - } - iov->iov_len = strlen (iov->iov_base = "\n"); - iov++; - - if (dfd != NOTOK) - DisplayVector (iob, iov - iob); - else - writev (fileno (stderr), iob, iov - iob); -} - - -static void -DisplayVector (struct iovec *iov, int n) -{ - register int i; - register char *cp; - char buffer[BUFSIZ]; - - for (i = 0, cp = NULL; i < n; i++, iov++) { - snprintf (buffer, sizeof(buffer), "%*.*s", iov->iov_len, - iov->iov_len, iov->iov_base); - cp = add (buffer, cp); - } - - DisplayStatus (dfd, cp); - free (cp); - sleep (PAUSE); - RemoveStatus (dfd); -} -- 1.7.10.4