home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-21 | 54.4 KB | 2,474 lines |
- Newsgroups: comp.sources.misc
- From: pvr@wang.com (Peter Reilley)
- Subject: v26i040: beav - Binary file editor and viewer, v1.32, Part04/09
- Message-ID: <1991Nov21.230219.1655@sparky.imd.sterling.com>
- X-Md4-Signature: f20cc013ae00501fda6bbbc0bf7e25ad
- Date: Thu, 21 Nov 1991 23:02:19 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: pvr@wang.com (Peter Reilley)
- Posting-number: Volume 26, Issue 40
- Archive-name: beav/part04
- Environment: UNIX, AIX, MS-DOS, AMIGA
- Supersedes: beav: Volume 22, Issue 10-18
-
- #! /bin/sh
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # The tool that generated this appeared in the comp.sources.unix newsgroup;
- # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
- # Contents: buffer.c random.c spawn.c
- # Wrapped by kent@sparky on Thu Nov 21 16:47:00 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 4 (of 9)."'
- if test -f 'buffer.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'buffer.c'\"
- else
- echo shar: Extracting \"'buffer.c'\" \(20883 characters\)
- sed "s/^X//" >'buffer.c' <<'END_OF_FILE'
- X/*
- X* Buffer handling.
- X*/
- X
- X#include "def.h"
- X
- Xbool onebuf ();
- Xbool killablebufs ();
- Xbool _yankbuffer ();
- Xchar next_buf ();
- Xbool bclear ();
- Xbool addline ();
- Xchar makelist ();
- Xbool popblist ();
- Xchar listbuffers ();
- Xchar _killbuffer ();
- Xbool _usebuffer ();
- X
- Xextern ROW_FMT text_fmt;
- Xextern char MSG_use_b[];
- Xextern char MSG_kill_b[];
- Xextern char MSG_not_fnd[];
- Xextern char MSG_no_del_m[];
- Xextern char MSG_buf_disp[];
- Xextern char MSG_main[];
- Xextern char MSG_l_buf_h[];
- Xextern char MSG_l_buf_h1[];
- Xextern char MSG_no_chg[];
- Xextern char MSG_yank_b[];
- Xextern char MSG_no_buf[];
- Xextern char MSG_no_s_yank[];
- Xextern char MSG_buf_nam[];
- Xextern char MSG_bad_l[];
- Xextern char MSG_pick[];
- Xextern char MSG_siz_chg[];
- Xextern char MSG_no_siz_chg[];
- Xextern char MSG_up_arrow[];
- Xextern char MSG_null[];
- Xextern char MSG_save_buf[];
- Xextern char MSG_cnt_al_b[];
- Xextern char MSG_ins_cnt[];
- X
- XBUFFER sav_buf;
- XLINE sav_line_h;
- X/*
- X* Attach a buffer to a window. The
- X* values of dot and mark come from the buffer
- X* if the use count is 0. Otherwise, they come
- X* from some other window.
- X*
- X* plus hacks for prev/next buffer and use-buffer-split (jam)
- X* functions (like in file.c)
- X*/
- Xchar usebuffer ()
- X{
- X
- X char bufn[NBUFN];
- X register char s;
- X
- X if ((s = ereply (MSG_use_b, bufn, NBUFN, 0)) != TRUE)
- X return (s);
- X return (_usebuffer (bufn));
- X}
- X
- X/* use buffer, split window first
- X*/
- Xchar use_buffer ()
- X{
- X char bufn[NBUFN];
- X register char s;
- X
- X if ((s = ereply (MSG_use_b, bufn, NBUFN, 0)) != TRUE)
- X return (s);
- X splitwind ();
- X return (_usebuffer (bufn));
- X}
- X
- X/* does all the work for changing to a new buffer for use-buffer,
- X* use-buffer-split and prev-buff & next-buff
- X*/
- Xbool _usebuffer (bufn)
- Xchar *bufn;
- X{
- X register BUFFER * bp;
- X register WINDOW * wp;
- X
- X if (strcmp (MSG_kill_b, bufn) == 0)/* hack! */
- X bp = blistp;
- X else
- X if ((bp = bfind (bufn, TRUE)) == NULL)
- X return (FALSE);
- X
- X /* if current buffer is special and new buffer is normal */
- X /* set to hex byte mode */
- X if ((curbp == blistp) && (R_TYPE(curwp) == TEXT))
- X {
- X dispsize1 ();
- X hexmode ();
- X }
- X
- X if (--curbp -> b_nwnd == 0)
- X {
- X /* Last use. */
- X curbp -> b_dotp = curwp -> w_dotp;
- X curbp -> b_doto = curwp -> w_doto;
- X curbp -> b_unit_offset = curwp -> w_unit_offset;/* pvr */
- X curbp -> b_markp = curwp -> w_markp;
- X curbp -> b_marko = curwp -> w_marko;
- X }
- X curbp = bp; /* Switch. */
- X curwp -> w_bufp = bp;
- X curwp -> w_linep = bp -> b_linep;/* For macros, ignored. */
- X curwp -> w_loff = 0; /* pvr */
- X curwp -> w_flag |= WFMODE | WFFORCE | WFHARD;
- X /* Quite nasty. */
- X if (bp -> b_nwnd++ == 0)
- X {
- X /* First use. */
- X curwp -> w_dotp = bp -> b_dotp;
- X curwp -> w_doto = bp -> b_doto;
- X curwp -> w_unit_offset = 0; /* pvr */
- X curwp -> w_markp = bp -> b_markp;
- X curwp -> w_marko = bp -> b_marko;
- X wind_on_dot (curwp);
- X /* if we are in the funny TEXT mode then goto standard HEX mode */
- X if (R_TYPE(curwp) == TEXT)
- X hexmode ();
- X return (TRUE);
- X }
- X wp = wheadp; /* Look for old. */
- X while (wp != NULL)
- X {
- X if (wp != curwp && wp -> w_bufp == bp)
- X {
- X curwp -> w_dotp = wp -> w_dotp;
- X curwp -> w_doto = wp -> w_doto;
- X curwp -> w_unit_offset = wp -> w_unit_offset;/* pvr */
- X curwp -> w_markp = wp -> w_markp;
- X curwp -> w_marko = wp -> w_marko;
- X break;
- X }
- X wp = wp -> w_wndp;
- X }
- X wind_on_dot (curwp);
- X /* if we are in the funny TEXT mode then goto standard HEX mode */
- X if (R_TYPE(curwp) == TEXT)
- X hexmode ();
- X return (TRUE);
- X}
- X
- X
- X/*
- X* Dispose of a buffer, by name.
- X* Ask for the name. Look it up (don't get too
- X* upset if it isn't there at all!). Get quite upset
- X* if the buffer is being displayed. Clear the buffer (ask
- X* if the buffer has been changed). Then free the header
- X* line and the buffer header. Bound to "C-X K".
- X*/
- Xchar killbuffer ()
- X{
- X register char s;
- X char bufn[NBUFN];
- X
- X if ((s = ereply (MSG_kill_b, bufn, NBUFN, 0)) != TRUE)
- X return (s);
- X if (s = _killbuffer (bufn))
- X writ_echo (okmsg); /* verbose-ness (jam) */
- X return (s);
- X}
- X
- X
- Xchar _killbuffer (bufn)
- Xchar *bufn;
- X{
- X register BUFFER * bp,
- X *bp1,
- X *bp2;
- X register char s,
- X x = 0;
- X
- X if (((bp = bfind (bufn, FALSE)) == NULL) ||
- X !strcmp (bufn, MSG_save_buf))
- X {
- X writ_echo (MSG_not_fnd);
- X return (FALSE);
- X }
- X
- X
- X if (killablebufs (bp)) /* can't kill '?' if no other buffers */
- X {
- X writ_echo (MSG_no_del_m);
- X return (FALSE);
- X }
- X
- X /* see if the buffer to be killed is in a window */
- X bp1 = bp;
- X if (curbp == blistp && onebuf (bp))/* Hack ! */
- X {
- X next_buf ();
- X onlywind ();
- X update ();
- X }
- X
- X if (bp -> b_nwnd > 0)
- X {
- X if ((s = eyesno (MSG_buf_disp)) != TRUE)
- X return (s);
- X
- X /* make the current window the only window if it is to die */
- X onlywind ();
- X if (curbp == bp)
- X {
- X next_buf ();
- X if (curbp == bp)
- X x++;
- X }
- X }
- X if ((s = bclear (bp)) != TRUE)/* Blow text away. */
- X {
- X if (bp1 == blistp) /* special buffer */
- X curbp = bp1;
- X else
- X if (!x)
- X _usebuffer (bp1 -> b_bname);
- X /* back to original buffer (jam) */
- X return (s);
- X }
- X if (x)
- X {
- X _usebuffer (MSG_main);
- X x++;
- X }
- X
- X free ((char *) bp -> b_linep);/* Release header line. */
- X bp1 = NULL; /* Find the header. */
- X bp2 = bheadp;
- X while (bp2 != bp)
- X {
- X bp1 = bp2;
- X bp2 = bp2 -> b_bufp;
- X }
- X bp2 = bp2 -> b_bufp; /* Next one in chain. */
- X if (bp1 == NULL) /* Unlink it. */
- X bheadp = bp2;
- X else
- X bp1 -> b_bufp = bp2;
- X free ((char *) bp); /* Release buffer block */
- X if (x)
- X update ();
- X /* update buffer display */
- X if ((blistp -> b_nwnd != 0) &&
- X (blistp -> b_type == BTLIST))
- X listbuffers ();
- X return (TRUE);
- X}
- X
- X/*
- X* Display the buffer list. This is done
- X* in two parts. The "makelist" routine figures out
- X* the text, and puts it in the buffer whoses header is
- X* pointed to by the external "blistp". The "popblist"
- X* then pops the data onto the screen. Bound to
- X* "C-X C-B".
- X*/
- Xchar listbuffers ()
- X{
- X register char s;
- X
- X if ((s = makelist ()) != TRUE)
- X return (s);
- X return (popblist ());
- X}
- X/*
- X* Display the save buffer contents.
- X* Bound to "Meta C-W".
- X*/
- Xchar showsavebuf ()
- X{
- X WINDOW *wp;
- X
- X if (sav_buf.b_nwnd == 0)
- X {
- X splitwind ();
- X _usebuffer (MSG_save_buf);
- X }
- X else
- X {
- X wp = wheadp; /* Look for old. */
- X while (wp != NULL)
- X {
- X if (wp -> w_bufp == &sav_buf)
- X {
- X wp -> w_flag |= WFMODE | WFFORCE | WFHARD;
- X break;
- X }
- X wp = wp -> w_wndp;
- X }
- X }
- X return (TRUE);
- X}
- X
- X/*
- X* Pop the special buffer whose
- X* buffer header is pointed to by the external
- X* variable "blistp" onto the screen. This is used
- X* by the "listbuffers" routine (above) and by
- X* some other packages. Returns a status.
- X*/
- Xbool popblist ()
- X{
- X register WINDOW * wp;
- X register BUFFER * bp;
- X
- X if (blistp -> b_nwnd == 0) /* Not on screen yet. */
- X {
- X if ((wp = wpopup ()) == NULL)
- X return (FALSE);
- X bp = wp -> w_bufp;
- X if (--bp -> b_nwnd == 0)
- X {
- X bp -> b_dotp = wp -> w_dotp;
- X bp -> b_doto = wp -> w_doto;
- X bp -> b_unit_offset = wp -> w_unit_offset;/* pvr */
- X bp -> b_markp = wp -> w_markp;
- X bp -> b_marko = wp -> w_marko;
- X }
- X curwp = wp;
- X curbp = blistp;
- X wp -> w_bufp = blistp;
- X ++blistp -> b_nwnd;
- X }
- X wp = wheadp;
- X while (wp != NULL)
- X {
- X if (wp -> w_bufp == blistp)
- X {
- X wp -> w_linep = lforw (blistp -> b_linep);
- X wp -> w_loff = 0;
- X wp -> w_dotp = lforw (blistp -> b_linep);
- X wp -> w_doto = 0;
- X wp -> w_unit_offset = 0;
- X wp -> w_markp = NULL;
- X wp -> w_marko = 0;
- X wp -> w_disp_shift = 0;
- X wp -> w_intel_mode = FALSE;
- X wp -> w_fmt_ptr = &text_fmt;
- X wp -> w_flag |= WFMODE | WFHARD;
- X }
- X wp = wp -> w_wndp;
- X }
- X return (TRUE);
- X}
- X
- X/*
- X* This routine rebuilds the
- X* text in the special secret buffer
- X* that holds the buffer list. It is called
- X* by the list buffers command. Return TRUE
- X* if everything works. Return FALSE if there
- X* is an error (if there is no memory).
- X*/
- Xchar makelist ()
- X{
- X register char *cp1;
- X register char *cp2;
- X register int c;
- X register BUFFER * bp;
- X register A32 nbytes;
- X register char s;
- X char b[8 + 1];
- X char line[128];
- X
- X blistp -> b_flag &= ~BFCHG; /* Blow away old. */
- X if ((s = bclear (blistp)) != TRUE)
- X return (s);
- X blistp -> b_flag |= BFVIEW;
- X blistp -> b_type = BTLIST;
- X strcpy (blistp -> b_fname, MSG_up_arrow);
- X if (addline (MSG_l_buf_h) == FALSE
- X || addline (MSG_l_buf_h1) == FALSE)
- X return (FALSE);
- X bp = bheadp; /* For all buffers */
- X while (bp != NULL)
- X {
- X cp1 = &line[0]; /* Start at left edge */
- X if ((bp -> b_flag & BFCHG) != 0)/* "*" if changed */
- X *cp1++ = '*';
- X else
- X if (bp -> b_flag & BFVIEW)/* jam */
- X *cp1++ = 'R'; /* readonly */
- X else
- X *cp1++ = ' ';
- X *cp1++ = ' '; /* Gap. */
- X if ((bp -> b_flag & BFBAD) != 0)/* "?" if maybe trashed */
- X *cp1++ = '?';
- X else
- X *cp1++ = ' ';
- X *cp1++ = ' '; /* Gap. */
- X nbytes = bp -> b_linep -> l_bp -> l_file_offset +
- X bp -> b_linep -> l_bp -> l_used;
- X sprintf (b, "%8lx", nbytes); /* 8 digit buffer size. */
- X cp2 = &b[0];
- X while ((c = *cp2++) != 0)
- X *cp1++ = c;
- X *cp1++ = ' '; /* Gap. */
- X cp2 = &bp -> b_bname[0];/* Buffer name */
- X while ((c = *cp2++) != 0)
- X *cp1++ = c;
- X *cp1++ = ' '; /* Gap. */
- X *cp1++ = ' '; /* Gap. */
- X cp2 = &bp -> b_fname[0];/* File name */
- X if (*cp2 != 0)
- X {
- X while (cp1 < &line[1 + 1 + 1 + 1 + 6 + 1 + NBUFN + 1])
- X *cp1++ = ' ';
- X while ((c = *cp2++) != 0)
- X {
- X if (cp1 < &line[128 - 1])
- X *cp1++ = c;
- X }
- X }
- X while (cp1 < &line[80]) /* Fill out line to col 80 */
- X *cp1++ = ' ';
- X
- X *cp1 = 0; /* Add to the buffer. */
- X if (addline (line) == FALSE)
- X return (FALSE);
- X bp = bp -> b_bufp;
- X }
- X return (TRUE); /* All done */
- X}
- X
- X/*
- X* The argument "text" points to
- X* a string. Append this line to the
- X* buffer list buffer.
- X* Return TRUE if it worked and
- X* FALSE if you ran out of room.
- X*/
- Xbool addline (text)
- Xchar *text;
- X{
- X register LINE * lp;
- X register int i, allocsize;
- X register int ntext;
- X
- X ntext = strlen (text);
- X allocsize = 128;
- X
- X if ((lp = lalloc (allocsize)) == NULL)
- X return (FALSE);
- X
- X for (i = 0; i < ntext; ++i)
- X lputc (lp, i, text[i]);
- X
- X for (; i < allocsize; ++i) /* fill out line with spaces */
- X lputc (lp, i, ' ');
- X
- X blistp -> b_linep -> l_bp -> l_fp = lp;/* Hook onto the end */
- X lp -> l_bp = blistp -> b_linep -> l_bp;
- X blistp -> b_linep -> l_bp = lp;
- X lp -> l_fp = blistp -> b_linep;
- X lp -> l_size = allocsize; /* line size is limited to 80 chars */
- X lp -> l_used = allocsize;
- X lp -> l_file_offset = lp -> l_bp -> l_file_offset + lp -> l_bp -> l_used;
- X if (blistp -> b_dotp == blistp -> b_linep)/* If "." is at the end */
- X blistp -> b_dotp = lp; /* move it to new line */
- X return (TRUE);
- X}
- X
- X
- X/*
- X* Look through the list of
- X* buffers. Return TRUE if there
- X* are any changed buffers. Special buffers
- X* like the buffer list buffer don't count, as
- X* they are not in the list. Return FALSE if
- X* there are no changed buffers.
- X*/
- Xbool anycb ()
- X{
- X register BUFFER * bp;
- X
- X bp = bheadp;
- X while (bp != NULL)
- X {
- X
- X if ((bp -> b_flag & BFCHG) != 0)
- X return (TRUE);
- X bp = bp -> b_bufp;
- X }
- X return (FALSE);
- X}
- X
- X
- X/*
- X* Search for a buffer, by name.
- X* If not found, and the "cflag" is TRUE,
- X* create a buffer and put it in the list of
- X* all buffers. Return pointer to the BUFFER
- X* block for the buffer.
- X*/
- XBUFFER * bfind (bname, cflag)
- Xregister char *bname;
- X{
- X register BUFFER * bp;
- X
- X bp = bheadp;
- X while (bp != NULL)
- X {
- X if (strcmp (bname, bp -> b_bname) == 0)
- X return (bp);
- X bp = bp -> b_bufp;
- X }
- X if (cflag != FALSE && (bp = bcreate (bname)) != NULL)
- X {
- X bp -> b_bufp = bheadp;
- X bheadp = bp;
- X }
- X return (bp);
- X}
- X
- X
- X/*
- X* Create a buffer, by name.
- X* Return a pointer to the BUFFER header
- X* block, or NULL if the buffer cannot
- X* be created. The BUFFER is not put in the
- X* list of all buffers; this is called by
- X* "edinit" to create the buffer list
- X* buffer.
- X*/
- XBUFFER * bcreate (bname)
- Xregister char *bname;
- X{
- X
- X register BUFFER * bp;
- X register LINE * lp;
- X
- X if ((bp = (BUFFER *) malloc (sizeof (BUFFER))) == NULL)
- X {
- X err_echo (MSG_cnt_al_b);
- X return (NULL);
- X }
- X if ((lp = lalloc (0)) == NULL)
- X {
- X free ((char *) bp);
- X return (NULL);
- X }
- X bp -> b_bufp = NULL;
- X bp -> b_dotp = lp;
- X bp -> b_doto = 0;
- X bp -> b_unit_offset = 0; /* unit offset pvr */
- X bp -> b_markp = NULL;
- X bp -> b_marko = 0;
- X bp -> b_flag = 0;
- X bp -> b_nwnd = 0;
- X bp -> b_linep = lp;
- X strcpy (bp -> b_fname, MSG_null);
- X strcpy (bp -> b_bname, bname);
- X lp -> l_fp = lp;
- X lp -> l_bp = lp;
- X lp -> l_file_offset = 0; /* pvr */
- X lp -> l_used = 0; /* pvr */
- X lp -> l_size = 0; /* size of zero indicates the header line pvr
- X */
- X return (bp);
- X}
- X
- X
- X/*
- X* This routine blows away all of the text
- X* in a buffer. If the buffer is marked as changed
- X* then we ask if it is ok to blow it away; this is
- X* to save the user the grief of losing text. The
- X* window chain is nearly always wrong if this gets
- X* called; the caller must arrange for the updates
- X* that are required. Return TRUE if everything
- X* looks good.
- X*/
- Xbool bclear (bp)
- Xregister BUFFER * bp;
- X{
- X register LINE * lp;
- X register char s;
- X
- X if ((bp -> b_flag & BFCHG) != 0/* Changed. */
- X && (s = eyesno (MSG_no_chg)) != TRUE)
- X return (s);
- X bp -> b_flag &= ~BFCHG; /* Not changed */
- X while ((lp = lforw (bp -> b_linep)) != bp -> b_linep)
- X lfree (lp);
- X bp -> b_dotp = bp -> b_linep;/* Fix "." */
- X bp -> b_doto = 0;
- X bp -> b_unit_offset = 0; /* pvr */
- X bp -> b_markp = NULL; /* Invalidate mark */
- X bp -> b_marko = 0;
- X return (TRUE);
- X}
- X
- X
- X/* flip to next buffer in the list, wrap
- X* to beginning if required (wrap around)
- X* (skips buffers saved by save-region)
- X*/
- Xchar next_buf ()
- X{
- X register BUFFER * bp;
- X
- X bp = curbp;
- X while (TRUE)
- X {
- X if (!(bp = bp -> b_bufp))
- X bp = bheadp;
- X if ((bp -> b_type == BTSAVE) ||
- X (bp -> b_type == BTLIST) ||
- X (bp -> b_type == BTHELP))
- X continue;
- X break;
- X }
- X _usebuffer (bp -> b_bname);
- X return (TRUE);
- X}
- X
- X
- X/* flip to prev buffer in the list, wrap
- X* to end if required (wrap around)
- X* (does NOT skip buffers saved by save-region)
- X*/
- Xchar prev_buf ()
- X{
- X register BUFFER * sp;
- X
- X if ((sp = curbp) == bheadp) /* front of list */
- X {
- X for (; sp -> b_bufp; sp = sp -> b_bufp)
- X ;
- X }
- X else /* cycle around */
- X {
- X for (sp = bheadp; sp -> b_bufp; sp = sp -> b_bufp)
- X {
- X if (sp -> b_bufp == curbp)
- X break;
- X }
- X }
- X return (_usebuffer (sp -> b_bname));
- X}
- X
- X
- X/* yank a buffer into current buffer
- X*/
- Xchar yank_buffer ()
- X{
- X char bufn[NBUFN];
- X
- X if (ereply (MSG_yank_b, bufn, NBUFN, 0) != TRUE)
- X return (FALSE);
- X return (_yankbuffer (bufn));
- X}
- X
- X
- Xbool _yankbuffer (bufn)
- Xchar *bufn;
- X{
- X register LINE * lp;
- X register BUFFER * bp = curbp;
- X register int s;
- X A32 cnt;
- X char buf[NFILEN], buf1[NFILEN];
- X
- X if ((bp = bfind (bufn, FALSE)) == NULL)
- X {
- X writ_echo (MSG_no_buf);
- X return (FALSE);
- X }
- X if (strcmp (bp -> b_bname, curbp -> b_bname) == 0)
- X {
- X writ_echo (MSG_no_s_yank);
- X return (FALSE);
- X }
- X cnt = 0;
- X lp = lforw (bp -> b_linep);
- X while (TRUE)
- X {
- X cnt += lp -> l_used;
- X for (s = 0; s < lp -> l_used; s++)
- X if (linsert (1, lp -> l_text[s]) == FALSE)
- X return (FALSE);
- X
- X if ((lp = lforw (lp)) == bp -> b_linep)
- X {
- X break;
- X }
- X
- X if ((cnt & 0x7ff) == 0)
- X {
- X sprintf (buf1, MSG_ins_cnt, R_POS_FMT(curwp));
- X sprintf (buf, buf1, cnt);
- X writ_echo (buf);
- X /* check if we should quit */
- X if (ttkeyready ())
- X {
- X l_fix_up (lp -> l_bp);
- X wind_on_dot_all();
- X if (ttgetc () == CTL_G) /* was it an abort key? */
- X return (FALSE);
- X }
- X }
- X }
- X writ_echo (okmsg);
- X return (TRUE);
- X}
- X
- X
- Xbool buffername ()
- X{
- X
- X register WINDOW * wp;
- X register char *p;
- X register char s;
- X char bname[NBUFN + 1];
- X
- X if ((s = ereply (MSG_buf_nam, bname, NBUFN, 0)) == ABORT)
- X return (s);
- X for (p = bname; *p && *p != ' '; p++)
- X ;
- X *p = 0; /* no blanks */
- X strcpy (curbp -> b_bname, bname);
- X wp = wheadp; /* Update mode lines. */
- X while (wp != NULL)
- X {
- X if (wp -> w_bufp == curbp)
- X wp -> w_flag |= WFMODE;
- X wp = wp -> w_wndp;
- X }
- X if ((blistp -> b_nwnd != 0) && /* update buffer display */
- X (blistp -> b_type == BTLIST))
- X listbuffers ();
- X return (TRUE);
- X}
- X
- X
- X/* any killable buffers around ? (jam)
- X*/
- Xbool killablebufs (bp)
- Xregister BUFFER * bp;
- X{
- X if (strcmp (bp -> b_bname, MSG_main) == 0)/* doomed buffer is 'empty' */
- X if (bheadp == bp) /* and is only buffer in list */
- X if (bheadp -> b_bufp == 0)/* then there are no killable buffers */
- X return (TRUE);
- X return (FALSE);
- X}
- X
- X
- X/* only 1 buffer around ?
- X*/
- Xbool onebuf (bp)
- Xregister BUFFER * bp;
- X{
- X if (strcmp (bp -> b_bname, bheadp -> b_bname) == 0)
- X if (bheadp -> b_bufp == 0)
- X return (TRUE);
- X return (FALSE);
- X}
- X
- X
- X/* funky new name; real yukky!!!! (jam)
- X*/
- Xvoid funky_name (bname, n)
- Xregister char *bname;
- Xint n;
- X{
- X char num[10];
- X register int i;
- X register char *p;
- X
- X for (i = 0; i < 10; i++)
- X num[i] = ' ';
- X for (p = bname; *p; p++)
- X *p = 0;
- X *bname++ = '#';
- X sprintf (num, "%lx", (long) n + 1);
- X for (p = num; *p; p++)
- X if (*p != ' ')
- X *bname++ = *p;
- X *bname = 0;
- X}
- X
- X
- X/* pick a buffer to goto/kill
- X*/
- X#define BUFFEROFFSET (13) /* depends on makelist !! */
- X
- Xbool pickone ()
- X{
- X register int s,
- X i,
- X c;
- X register LINE * lp;
- X char name[NBUFN + 1];
- X char buf[3];
- X WINDOW *wp;
- X
- X lp = curwp -> w_dotp; /* get the buffer name from the line */
- X
- X i = 0;
- X if (!llength (lp))
- X {
- X writ_echo (MSG_bad_l);
- X return (FALSE);
- X }
- X for (s = BUFFEROFFSET; (c = lgetc (lp, s)) != ' '; s++)
- X {
- X name[i++] = c;
- X if (s >= llength (lp))
- X break;
- X }
- X name[i] = 0;
- X if (!bfind (name, FALSE))
- X {
- X writ_echo (MSG_bad_l);
- X return (FALSE);
- X }
- Xloop:
- X if ((s = ereply (MSG_pick, buf, 2, name)) != TRUE)
- X return (FALSE);
- X if (ISLOWER (buf[0]) != FALSE)
- X buf[0] = TOUPPER (buf[0]);
- X if (buf[0] == 'K')
- X _killbuffer (name);
- X else
- X if (buf[0] == 'G')
- X _usebuffer (name);
- X else
- X if (buf[0] == 'S')
- X {
- X _usebuffer (name);
- X /* goto this buffer, but don't show the user */
- X filesave ();
- X _usebuffer (MSG_kill_b);
- X /* jump back to this window - HACK ! */
- X listbuffers (); /* update the list */
- X }
- X else
- X goto loop;
- X writ_echo (MSG_null);
- X return (TRUE);
- X}
- X/*
- X* Toggle the buffer size lock bit.
- X*/
- Xchar bufsizlock ()
- X{
- X if (curbp -> b_flag & BFSLOCK)
- X {
- X curbp -> b_flag &= ~BFSLOCK;
- X writ_echo (MSG_siz_chg);
- X }
- X else
- X {
- X if (insert_mode)
- X insert_toggle ();
- X curbp -> b_flag |= BFSLOCK;
- X writ_echo (MSG_no_siz_chg);
- X }
- X return (TRUE);
- X}
- X
- X/*
- X * Append the given line to the end of the given buffer.
- X */
- Xvoid b_append_l (buf_p, lp)
- XBUFFER *buf_p;
- XLINE *lp;
- X{
- X LINE *h_lp;
- X
- X h_lp = buf_p -> b_linep;
- X
- X lp -> l_fp = h_lp;
- X lp -> l_bp = h_lp -> l_bp;
- X lp -> l_bp -> l_fp = lp;
- X h_lp -> l_bp = lp;
- X lp -> l_file_offset = lp -> l_bp -> l_file_offset + lp -> l_bp -> l_used;
- X}
- X/*
- X * Append the given line to the end of the given buffer.
- X */
- Xbool b_append_c (buf_p, ch)
- XBUFFER *buf_p;
- XD8 ch;
- X{
- X LINE *lp;
- X
- X lp = buf_p -> b_linep -> l_bp; /* get last line */
- X /* do I need to get a new line? */
- X if (lp -> l_size <= lp -> l_used)
- X {
- X if ((lp = lalloc (KBLOCK)) == NULL)
- X return (FALSE);
- X
- X lp -> l_fp = buf_p -> b_linep;
- X lp -> l_bp = buf_p -> b_linep -> l_bp;
- X lp -> l_bp -> l_fp = lp;
- X buf_p -> b_linep -> l_bp = lp;
- X }
- X lp -> l_text[lp -> l_used++] = ch;
- X
- X return (TRUE);
- X}
- X
- X/*
- X * Initialize the save buffer.
- X */
- Xvoid save_buf_init ()
- X{
- X register BUFFER * bp;
- X
- X sav_line_h.l_fp = &sav_line_h;
- X sav_line_h.l_bp = &sav_line_h;
- X sav_line_h.l_file_offset = 0;
- X sav_line_h.l_used = 0;
- X sav_line_h.l_size = 0;
- X
- X sav_buf.b_type = BTSAVE;
- X sav_buf.b_bufp = NULL;
- X sav_buf.b_dotp = &sav_line_h;
- X sav_buf.b_doto = 0;
- X sav_buf.b_unit_offset = 0;
- X sav_buf.b_markp = NULL;
- X sav_buf.b_marko = 0;
- X sav_buf.b_linep = &sav_line_h;
- X sav_buf.b_nwnd = 0;
- X sav_buf.b_flag = BFVIEW;
- X sav_buf.b_begin_addr = 0;
- X sav_buf.b_file_size = 0;
- X sav_buf.b_fname[0] = 0;
- X strcpy (sav_buf.b_bname, MSG_save_buf);
- X
- X /* put on end of chain */
- X bp = bheadp;
- X while ((bp -> b_bufp) != NULL)
- X bp = bp -> b_bufp;
- X
- X bp->b_bufp = &sav_buf;
- X
- X}
- X
- X/*
- X * Set the save buffer dot pointer to the begining.
- X */
- Xvoid save_buf_home ()
- X{
- X sav_buf.b_dotp = sav_buf.b_linep -> l_fp;
- X sav_buf.b_doto = 0;
- X sav_buf.b_flag = BFVIEW;
- X}
- X
- XD16 get_save_char ()
- X{
- X D8 ch;
- X
- X /* are we past the end of the buffer */
- X if (sav_buf.b_dotp == sav_buf.b_linep)
- X return (-1);
- X ch = sav_buf.b_dotp -> l_text[sav_buf.b_doto++];
- X if (sav_buf.b_doto >= sav_buf.b_dotp -> l_used)
- X {
- X sav_buf.b_doto = 0;
- X sav_buf.b_dotp = sav_buf.b_dotp -> l_fp;
- X }
- X return ((D16)ch);
- X}
- X
- END_OF_FILE
- if test 20883 -ne `wc -c <'buffer.c'`; then
- echo shar: \"'buffer.c'\" unpacked with wrong size!
- fi
- # end of 'buffer.c'
- fi
- if test -f 'random.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'random.c'\"
- else
- echo shar: Extracting \"'random.c'\" \(28521 characters\)
- sed "s/^X//" >'random.c' <<'END_OF_FILE'
- X/*
- X* Assorted commands.
- X* The file contains the command
- X* processors for a large assortment of unrelated
- X* commands. The only thing they have in common is
- X* that they are all command processors.
- X*/
- X
- X#include "def.h"
- X
- Xchar backdel ();
- Xbool fill_out ();
- Xvoid bad_key ();
- X
- X
- X
- Xextern char MSG_sh_pos[];
- Xextern char MSG_sh_pos1[];
- Xextern char MSG_f_str[];
- Xextern char MSG_3u[];
- Xextern char MSG_5u[];
- Xextern char MSG_lu[];
- Xextern char MSG_03u[];
- Xextern char MSG_05u[];
- Xextern char MSG_010lu[];
- Xextern char MSG_lnk[];
- Xextern char MSG_unlink[];
- Xextern char MSG_link[];
- Xextern char MSG_bad_key[];
- Xextern char MSG_esc[];
- Xextern char MSG_ctl_x[];
- Xextern char MSG_ctl[];
- Xextern char MSG_key_code[];
- Xextern char char_str[];
- Xextern char MSG_w_not_empty[];
- Xextern char MSG_procing[];
- Xextern char MSG_ok[];
- X#if RUNCHK
- Xextern char ERR_rnd_1[];
- Xextern char ERR_rnd_2[];
- Xextern char ERR_rnd_3[];
- Xextern char ERR_rnd_4[];
- Xextern char ERR_rnd_5[];
- Xextern char ERR_rnd_6[];
- Xextern char ERR_rnd_7[];
- X#endif
- X
- Xextern ROW_FMT ascii_fmt;
- Xextern ROW_FMT ebcdic_fmt;
- Xextern ROW_FMT binary_8_fmt;
- Xextern ROW_FMT binary_16_fmt;
- Xextern ROW_FMT binary_32_fmt;
- Xextern ROW_FMT octal_8_fmt;
- Xextern ROW_FMT octal_16_fmt;
- Xextern ROW_FMT octal_32_fmt;
- Xextern ROW_FMT decimal_8_fmt;
- Xextern ROW_FMT decimal_16_fmt;
- Xextern ROW_FMT decimal_32_fmt;
- Xextern ROW_FMT hex_8_fmt;
- Xextern ROW_FMT hex_16_fmt;
- Xextern ROW_FMT hex_32_fmt;
- X
- Xextern bool read_pat_mode;
- Xextern bool dont_repeat;
- Xextern BUFFER sav_buf;
- X
- Xchar dec_chr_ok ();
- Xulong get_long ();
- Xvoid wind_on_dot_all ();
- X
- X/*
- X* Display a bunch of useful information about
- X* the current location of dot and mark.
- X* The position of the dot and mark and the difference between them.
- X* The total buffer size is displayed.
- X* This is normally bound to "C-X =".
- X*/
- Xbool showcpos (f, n, k)
- X{
- X
- X A32 dotoff,
- X markoff,
- X fsize,
- X bsize;
- X char buf[NCOL * 2], buf1[NCOL * 2];
- X
- X dotoff = curwp -> w_dotp -> l_file_offset;
- X dotoff += curwp -> w_doto;
- X
- X if (curwp -> w_markp != NULL)
- X {
- X markoff = curwp -> w_markp -> l_file_offset;
- X markoff += curwp -> w_marko;
- X }
- X
- X bsize = curwp -> w_bufp -> b_linep -> l_bp -> l_file_offset;
- X bsize += curwp -> w_bufp -> b_linep -> l_bp -> l_used;
- X fsize = curbp -> b_file_size;
- X
- X if (curwp -> w_markp != NULL)
- X {
- X /* build format string */
- X sprintf (buf1, MSG_sh_pos, R_POS_FMT(curwp), R_POS_FMT(curwp),
- X R_POS_FMT(curwp), R_POS_FMT(curwp));
- X sprintf (buf, buf1, dotoff, markoff, bsize, fsize);
- X }
- X else
- X {
- X /* build format string */
- X sprintf (buf1, MSG_sh_pos1, R_POS_FMT(curwp), R_POS_FMT(curwp),
- X R_POS_FMT(curwp));
- X sprintf (buf, buf1, dotoff, bsize, fsize);
- X }
- X
- X sprintf (&buf[strlen(buf)], MSG_f_str, curbp -> b_fname);
- X writ_echo (buf);
- X
- X return (TRUE);
- X}
- X
- X
- X/*
- X* Twiddle the two characters on either side of
- X* dot. If dot is at the end of the line twiddle the
- X* two characters before it. Return with an error if dot
- X* is at the beginning of line; it seems to be a bit
- X* pointless to make this work. This fixes up a very
- X* common typo with a single stroke. Normally bound
- X* to "C-T". This always works within a line, so
- X* "WFEDIT" is good enough.
- X*/
- Xbool twiddle ()
- X{
- X
- X register LINE * dotp;
- X register short doto;
- X char b_per_u,
- X f_buf[4],
- X s_buf[4],
- X i;
- X
- X dotp = curwp -> w_dotp;
- X doto = curwp -> w_doto;
- X b_per_u = curwp -> w_fmt_ptr -> r_b_per_u;
- X /* try to move back one unit */
- X if (!move_ptr (curwp, (long) - b_per_u, TRUE, TRUE, TRUE))
- X {
- X curwp -> w_dotp = dotp; /* if fail then restore dot and quit */
- X curwp -> w_doto = doto;
- X ttbeep ();
- X return (FALSE);
- X }
- X /* pick up first unit byte by byte */
- X for (i = 0; i < b_per_u; i++)
- X {
- X f_buf[i] = DOT_CHAR(curwp);
- X move_ptr (curwp, 1L, TRUE, FALSE, TRUE);
- X }
- X /* move to the end of the second unit */
- X if (!move_ptr (curwp, (long) (b_per_u - 1), TRUE, FALSE, TRUE))
- X {
- X curwp -> w_dotp = dotp; /* if fail then restore dot and quit */
- X curwp -> w_doto = doto;
- X ttbeep ();
- X return (FALSE);
- X }
- X /* pick up second unit (reverse order) and deposit second unit */
- X for (i = 0; i < b_per_u; i++)
- X {
- X s_buf[i] = DOT_CHAR(curwp);
- X DOT_CHAR(curwp) = f_buf[b_per_u - 1 - i];
- X move_ptr (curwp, -1L, TRUE, FALSE, TRUE);
- X }
- X /* deposit first unit */
- X for (i = 0; i < b_per_u; i++)
- X {
- X DOT_CHAR(curwp) = s_buf[i];
- X move_ptr (curwp, -1L, TRUE, FALSE, TRUE);
- X }
- X curwp -> w_dotp = dotp;
- X curwp -> w_doto = doto;
- X lchange (WFHARD);
- X return (TRUE);
- X}
- X
- X/*
- X* Quote the next character, and
- X* insert it into the buffer. All the characters
- X* are taken literally.
- X* The character
- X* is always read, even if it is inserted 0 times, for
- X* regularity.
- X*/
- Xbool quote (f, n, k)
- X{
- X register int c;
- X
- X if (kbdmop != NULL)
- X c = *kbdmop++;
- X else
- X {
- X c = ttgetc ();
- X if (kbdmip != NULL)
- X {
- X if (kbdmip > &kbdm[NKBDM - 4])
- X {
- X ctrlg (FALSE, 0, KRANDOM);
- X return (ABORT);
- X }
- X
- X *kbdmip++ = c;
- X }
- X
- X }
- X
- X if (n < 0)
- X return (FALSE);
- X if (n == 0)
- X return (TRUE);
- X
- X return (linsert (n, c));
- X}
- X
- X/*
- X* Toggle the insert mode. Insert mode is used only in ASCII or EBCDIC modes.
- X*/
- Xbool insert_toggle () /* toggle routine for selfinsert */
- X{
- X register WINDOW * wp;
- X
- X if (curbp -> b_flag & BFSLOCK)
- X return (TRUE);
- X
- X if (read_pat_mode)
- X dont_repeat = TRUE;
- X
- X insert_mode = !insert_mode;
- X for (wp = wheadp; wp; wp = wp -> w_wndp)
- X wp -> w_flag |= WFMODE; /* force mode line update */
- X return (TRUE);
- X}
- X
- X/*
- X* Ordinary text characters are bound to this function,
- X* which inserts them into the buffer. Characters marked as control
- X* characters (using the CTRL flag) may be remapped to their ASCII
- X* equivalent. This makes TAB (C-I) work right, and also makes the
- X* world look reasonable if a control character is bound to this
- X* this routine by hand. Any META or CTLX flags on the character
- X* are discarded.
- X*
- X* Edit the unit under the cursor.
- X* Check that the character is valid for the current display mode.
- X*/
- X
- Xbool selfinsert (f, n, k)
- X{
- X
- X register int c;
- X char edt_buf[4],
- X i_chr,
- X b_per_u,
- X u_offs,
- X u_roffs,
- X bit_shf,
- X i;
- X LINE * l_ptr;
- X short d_offs;
- X int bytes,
- X temp_int;
- X long dot_shf,
- X l_mask,
- X l_val;
- X char text_buf[12];
- X static char max_dec_8[] = "255";
- X static char max_dec_16[] = "65535";
- X static char max_dec_32[] = "4294967295";
- X int cur_col;
- X
- X bool intel;
- X
- X if (n < 0)
- X {
- X ttbeep ();
- X return (FALSE);
- X }
- X if (n == 0)
- X {
- X ttbeep ();
- X return (TRUE);
- X }
- X c = k & KCHAR;
- X if ((k & KCTRL) != 0 && c >= '@' && c <= '_')/* ASCII-ify. */
- X c -= '@';
- X b_per_u = curwp -> w_fmt_ptr -> r_b_per_u;
- X u_offs = curwp -> w_unit_offset;
- X u_roffs = curwp -> w_fmt_ptr -> r_chr_per_u - u_offs - 1;
- X intel = curwp -> w_intel_mode;
- X
- X cur_col = ttcol;
- X
- X switch (curwp -> w_fmt_ptr -> r_type)
- X {
- X case EBCDIC:
- X c = to_ebcdic (c); /* convert ASCII to EBCDIC */
- X case ASCII:
- X if ((insert_mode) || (DOT_POS(curwp) == BUF_SIZE(curwp)))
- X {
- X linsert (n, c);
- X if (read_pat_mode)
- X forwchar (0, 1, KRANDOM);/* advance the cursor */
- X }
- X else
- X lreplace (n, c);
- X break;
- X
- X case HEX:
- X if ((c >= '0') && (c <= '9'))
- X {
- X i_chr = c - '0';/* convert to binary */
- X }
- X else
- X if ((c >= 'A') && (c <= 'F'))
- X {
- X i_chr = c - 'A' + 10;/* convert to binary */
- X }
- X else
- X if ((c >= 'a') && (c <= 'f'))
- X {
- X i_chr = c - 'a' + 10;/* convert to binary */
- X }
- X else
- X {
- X bad_key (k);
- X return (FALSE);
- X }
- X fill_out (); /* expand buffer if necessary */
- X
- X /* position dot to byte to be altered */
- X if (intel)
- X dot_shf = u_roffs >> 1;
- X else
- X dot_shf = u_offs >> 1;
- X
- X /* save dot position for later */
- X l_ptr = curwp -> w_dotp;
- X d_offs = curwp -> w_doto;
- X move_ptr (curwp, dot_shf, TRUE, FALSE, TRUE);
- X
- X if (u_offs & 1)
- X { /* lower nibble in byte */
- X i_chr &= 0x0f;
- X DOT_CHAR(curwp) &= 0xf0;
- X DOT_CHAR(curwp) |= i_chr;
- X }
- X else
- X { /* upper nibble in byte */
- X i_chr <<= 4;
- X i_chr &= 0xf0;
- X DOT_CHAR(curwp) &= 0x0f;
- X DOT_CHAR(curwp) |= i_chr;
- X }
- X
- X /* restore dot position */
- X curwp -> w_dotp = l_ptr;
- X curwp -> w_doto = d_offs;
- X forwchar (0, 1, KRANDOM);/* advance the cursor */
- X break;
- X
- X case BINARY:
- X if ((c != '0') && (c != '1'))
- X {
- X bad_key (k);
- X return (FALSE);
- X }
- X
- X /* position dot to byte to be altered */
- X if (intel)
- X dot_shf = u_roffs >> 3;
- X else
- X dot_shf = u_offs >> 3;
- X
- X fill_out (); /* expand buffer if necessary */
- X
- X /* save dot position for later */
- X l_ptr = curwp -> w_dotp;
- X d_offs = curwp -> w_doto;
- X move_ptr (curwp, dot_shf, TRUE, FALSE, TRUE);
- X
- X bit_shf = u_roffs & 0x07;
- X
- X if (c == '0')
- X {
- X DOT_CHAR(curwp) &= ~(1 << bit_shf);
- X }
- X else
- X {
- X DOT_CHAR(curwp) |= 1 << bit_shf;
- X }
- X
- X /* restore dot position */
- X curwp -> w_dotp = l_ptr;
- X curwp -> w_doto = d_offs;
- X forwchar (0, 1, KRANDOM);/* advance the cursor */
- X break;
- X
- X case OCTAL:
- X if (c < '0')
- X {
- X bad_key (k);
- X return (FALSE);
- X }
- X else
- X if ((c > '1') && (u_offs == 0) &&
- X ((curwp -> w_fmt_ptr -> r_size) == WORDS))
- X {
- X bad_key (k);
- X return (FALSE);
- X }
- X else
- X if ((c > '3') && (u_offs == 0))
- X {
- X bad_key (k);
- X return (FALSE);
- X }
- X else
- X if (c > '7')
- X {
- X bad_key (k);
- X return (FALSE);
- X }
- X
- X dot_shf = (c - '0') & 7;/* get binary value */
- X l_mask = 7; /* create bit mask */
- X
- X dot_shf <<= (u_roffs * 3);
- X l_mask <<= (u_roffs * 3);
- X
- X fill_out (); /* expand buffer if necessary */
- X
- X /* save dot position for later */
- X l_ptr = curwp -> w_dotp;
- X d_offs = curwp -> w_doto;
- X
- X /* position dot to the byte to be altered */
- X if (intel)
- X {
- X for (i = 0; i < b_per_u; i++)
- X {
- X DOT_CHAR(curwp) &= ~((D8) l_mask & 0xff);
- X DOT_CHAR(curwp) |= (D8) dot_shf & 0xff;
- X l_mask >>= 8;
- X dot_shf >>= 8;
- X move_ptr (curwp, 1L, TRUE, FALSE, TRUE);
- X }
- X }
- X else
- X {
- X move_ptr (curwp, (long) (b_per_u - 1), TRUE, FALSE, TRUE);
- X /* move to last byte */
- X for (i = 0; i < b_per_u; i++)
- X {
- X DOT_CHAR(curwp) &= ~((D8) l_mask & 0xff);
- X DOT_CHAR(curwp) |= (D8) dot_shf & 0xff;
- X l_mask >>= 8;
- X dot_shf >>= 8;
- X move_ptr (curwp, -1L, TRUE, FALSE, TRUE);/* step back one byte */
- X }
- X }
- X
- X /* restore dot position */
- X curwp -> w_dotp = l_ptr;
- X curwp -> w_doto = d_offs;
- X forwchar (0, 1, KRANDOM);/* advance the cursor */
- X break;
- X
- X case DECIMAL:
- X fill_out (); /* expand buffer if necessary */
- X
- X /* save dot position for later */
- X l_ptr = curwp -> w_dotp;
- X d_offs = curwp -> w_doto;
- X
- X bytes = fill_buf (curwp, l_ptr, d_offs, edt_buf, b_per_u);
- X /* if last unit is not full and must be extended */
- X for (; bytes < b_per_u; bytes++)
- X {
- X edt_buf[3] = edt_buf[2];/* shuffle bytes down */
- X edt_buf[2] = edt_buf[1];
- X edt_buf[1] = edt_buf[0];
- X edt_buf[0] = 0;
- X }
- X switch (curwp -> w_fmt_ptr -> r_size)
- X {
- X case BYTES:
- X sprintf (text_buf, MSG_03u, (int) (edt_buf[0] & 0xff));
- X if (!dec_chr_ok (text_buf, max_dec_8, c, u_offs))
- X {
- X bad_key (k);
- X return (TRUE); /* TRUE so that mask will be same len */
- X }
- X sscanf (text_buf, MSG_3u, &i);/* convert back to binary */
- X l_val = (long) i & 0xff;
- X break;
- X
- X case WORDS:
- X l_val = get_int (edt_buf);/* do intel swap */
- X sprintf (text_buf, MSG_05u, (int) (l_val & 0xFFFF));
- X if (!dec_chr_ok (text_buf, max_dec_16, c, u_offs))
- X {
- X bad_key (k);
- X return (TRUE); /* TRUE so that mask will be same len */
- X }
- X sscanf (text_buf, MSG_5u, &temp_int);
- X /* convert back to binary */
- X l_val = get_int ((char *) & temp_int);/* do intel swap */
- X break;
- X
- X case DWORDS:
- X l_val = get_long (edt_buf);/* do intel swap */
- X sprintf (text_buf, MSG_010lu, l_val);
- X if (!dec_chr_ok (text_buf, max_dec_32, c, u_offs))
- X {
- X bad_key (k);
- X return (TRUE); /* TRUE so that mask will be same len */
- X }
- X sscanf (text_buf, MSG_lu, &l_val);
- X /* convert back to binary */
- X l_val = get_long ((char *) & l_val);/* do intel swap */
- X break;
- X#if RUNCHK
- X default:
- X writ_echo (ERR_rnd_2);
- X break;
- X#endif
- X }
- X DOT_CHAR(curwp) = (char) l_val & 0xff;
- X for (i = 1; i < b_per_u; i++)
- X {
- X l_val >>= 8;
- X move_ptr (curwp, 1L, TRUE, FALSE, TRUE);/* step forward one byte */
- X DOT_CHAR(curwp) = (char) l_val & 0xff;
- X }
- X
- X /* restore dot position */
- X curwp -> w_dotp = l_ptr;
- X curwp -> w_doto = d_offs;
- X forwchar (0, 1, KRANDOM);/* advance the cursor */
- X break;
- X
- X#if RUNCHK
- X default:
- X writ_echo (ERR_rnd_3);
- X break;
- X#endif
- X }
- X /* if cursor has wrapped to the next line then previous line
- X will not be refreshed with WFEDIT so do a WFHARD */
- X if (cur_col > get_curcol(curwp))
- X lchange (WFHARD);
- X else
- X lchange (WFEDIT);
- X
- X return (TRUE);
- X}
- X
- X/*
- X* Insert one unit of zeros at the current dot position.
- X*/
- Xbool insertunit (f, n, k)
- X{
- X lchange (WFEDIT);
- X linsert ((R_B_PER_U(curwp) * n), 0);
- X return (TRUE);
- X}
- X
- X/*
- X* Increase the size of the buffer if necessary.
- X* If dot is at the byte after the last full unit
- X* then add enough bytes to the buffer to create
- X* a full unit at the end.
- X*/
- X
- Xbool fill_out ()
- X{
- X long buf_size, dot_pos, last_unit;
- X int b_per_u;
- X char stat, shift;
- X int insert_val;
- X
- X buf_size = BUF_SIZE(curwp);
- X dot_pos = DOT_POS(curwp);
- X b_per_u = R_B_PER_U(curwp);
- X shift = curwp -> w_disp_shift;
- X stat = TRUE;
- X insert_val = 0;
- X last_unit = buf_size & ~((long)(b_per_u - 1));
- X /* there is an even number of units step back one */
- X if (last_unit == buf_size)
- X last_unit -= b_per_u;
- X last_unit += shift;
- X
- X /* if dot is one byte past the end of the buffer */
- X if (dot_pos > last_unit)
- X {
- X insert_val = b_per_u;
- X }
- X
- X /* if dot is pointed at the end of the buffer */
- X else if (dot_pos == last_unit)
- X {
- X insert_val = b_per_u - (buf_size - last_unit);
- X }
- X
- X /* if insert is necessary then do it */
- X if (insert_val != 0)
- X {
- X lchange (WFHARD);
- X move_ptr (curwp, buf_size, TRUE, FALSE, FALSE); /* move dot to end */
- X stat = linsert (insert_val, 0);
- X move_ptr (curwp, dot_pos, TRUE, TRUE, FALSE); /* put dot back */
- X }
- X return (stat);
- X}
- X
- X/*
- X* This checks that an entered character is ok
- X* for the position given.
- X*/
- X
- Xchar dec_chr_ok (char_buf, max_str, chr, pos)
- X
- Xchar chr,
- Xpos,
- X*char_buf,
- X*max_str;
- X
- X{
- X char i;
- X
- X if ((chr < '0') || (chr > '9'))
- X return (FALSE);
- X
- X char_buf[pos] = chr; /* insert typed char */
- X
- X /* check if number is too big */
- X for (i = 0; max_str[i] != 0; i++)
- X {
- X if (char_buf[i] < max_str[i])
- X break; /* if char is smaller then must be ok */
- X
- X if (char_buf[i] > max_str[i])
- X return (FALSE); /* val is too large; ERROR */
- X }
- X return (TRUE);
- X}
- X
- X/*
- X* Set the rest of the variables for the mode change.
- X*/
- Xvoid set_mode_vars ()
- X{
- X curwp -> w_disp_shift = 0; /* shift to 0 when changing mode */
- X curwp -> w_unit_offset = 0; /* go to end of unit */
- X /* if we are in the middle of a search then use the proper format struc */
- X if (read_pat_mode)
- X curwp -> w_fmt_ptr = curwp -> w_fmt_ptr -> r_srch_fmt;
- X
- X wind_on_dot (curwp);
- X curwp -> w_flag = WFHARD;
- X update ();
- X}
- X
- X/*
- X* Change the display mode to ASCII.
- X* The default binding is META C-A.
- X*/
- Xbool asciimode ()
- X{
- X curwp -> w_fmt_ptr = &ascii_fmt;
- X set_mode_vars ();
- X return (TRUE);
- X}
- X
- X/*
- X* Change the display mode to EBCDIC.
- X* The default binding is META C-E.
- X*/
- Xbool ebcdicmode ()
- X{
- X curwp -> w_fmt_ptr = &ebcdic_fmt;
- X set_mode_vars ();
- X return (TRUE);
- X}
- X
- X/*
- X* Change the display mode to DECIMAL.
- X* The default binding is META C-D.
- X*/
- Xbool decimalmode ()
- X{
- X switch (curwp -> w_fmt_ptr -> r_size)
- X {
- X case BYTES:
- X curwp -> w_fmt_ptr = &decimal_8_fmt;
- X break;
- X case WORDS:
- X curwp -> w_fmt_ptr = &decimal_16_fmt;
- X break;
- X
- X case DWORDS:
- X curwp -> w_fmt_ptr = &decimal_32_fmt;
- X break;
- X#if RUNCHK
- X default:
- X writ_echo (ERR_rnd_4);
- X break;
- X#endif
- X }
- X set_mode_vars ();
- X return (TRUE);
- X}
- X
- X/*
- X* Change the display mode to HEXADECIMAL.
- X* The default binding is META C-H.
- X*/
- Xbool hexmode ()
- X{
- X switch (curwp -> w_fmt_ptr -> r_size)
- X {
- X case BYTES:
- X curwp -> w_fmt_ptr = &hex_8_fmt;
- X break;
- X case WORDS:
- X curwp -> w_fmt_ptr = &hex_16_fmt;
- X break;
- X case DWORDS:
- X curwp -> w_fmt_ptr = &hex_32_fmt;
- X break;
- X#if RUNCHK
- X default:
- X writ_echo (ERR_rnd_5);
- X break;
- X#endif
- X }
- X set_mode_vars ();
- X return (TRUE);
- X}
- X
- X/*
- X* Change the display mode to OCTAL.
- X* The default binding is META C-O.
- X*/
- Xbool octalmode ()
- X{
- X switch (curwp -> w_fmt_ptr -> r_size)
- X {
- X case BYTES:
- X curwp -> w_fmt_ptr = &octal_8_fmt;
- X break;
- X
- X case WORDS:
- X curwp -> w_fmt_ptr = &octal_16_fmt;
- X break;
- X
- X case DWORDS:
- X curwp -> w_fmt_ptr = &octal_32_fmt;
- X break;
- X#if RUNCHK
- X default:
- X writ_echo (ERR_rnd_6);
- X break;
- X#endif
- X }
- X set_mode_vars ();
- X return (TRUE);
- X}
- X
- X/*
- X* Change the display mode to BINARY.
- X* The default binding is META C-B.
- X*/
- Xbool binarymode ()
- X{
- X switch (curwp -> w_fmt_ptr -> r_size)
- X {
- X case BYTES:
- X curwp -> w_fmt_ptr = &binary_8_fmt;
- X break;
- X case WORDS:
- X curwp -> w_fmt_ptr = &binary_16_fmt;
- X break;
- X case DWORDS:
- X curwp -> w_fmt_ptr = &binary_32_fmt;
- X break;
- X#if RUNCHK
- X default:
- X writ_echo (ERR_rnd_7);
- X break;
- X#endif
- X }
- X set_mode_vars ();
- X return (TRUE);
- X}
- X
- X/*
- X* Change the display shift.
- X* Circularly rotate through display shift of 0 through 3.
- X* This value is used to shift the display by the designated number of bytes.
- X* This is used to cause WORD and DWORD values to be calculated
- X* from the correct offset.
- X*/
- Xbool dispshift (f, n, k)
- X{
- X char mode,
- X size;
- X
- X if (read_pat_mode)
- X return (TRUE); /* no shift is allowed in search mode */
- X
- X
- X mode = curwp -> w_fmt_ptr -> r_type;
- X size = curwp -> w_fmt_ptr -> r_size;
- X
- X if (((mode == HEX) ||
- X (mode == DECIMAL) ||
- X (mode == BINARY) ||
- X (mode == OCTAL)) &&
- X (size != BYTES))
- X {
- X if ((size == WORDS) &&
- X (curwp -> w_disp_shift >= 1))
- X { /* roll over on words */
- X curwp -> w_disp_shift = 0;
- X }
- X else
- X if ((size == DWORDS) &&
- X (curwp -> w_disp_shift >= 3))
- X { /* roll over on double words */
- X curwp -> w_disp_shift = 0;
- X }
- X else
- X {
- X curwp -> w_disp_shift++;/* increment shift */
- X }
- X }
- X else
- X {
- X curwp -> w_disp_shift = 0;/* set to no shift */
- X }
- X move_ptr (curwp, 0L, TRUE, TRUE, TRUE);
- X wind_on_dot (curwp);
- X curwp -> w_flag = WFHARD; /* force full window refresh */
- X return (TRUE);
- X}
- X
- X/*
- X* Delete forward. This is real
- X* easy, because the basic delete routine does
- X* all of the work. Watches for negative arguments,
- X* and does the right thing. If any argument is
- X* present, it kills rather than deletes, to prevent
- X* loss of text if typed with a big argument.
- X* Normally bound to "C-D".
- X*/
- Xchar forwdel (f, n, k)
- X{
- X char s;
- X
- X if (n < 0)
- X return (backdel (f, -n, KRANDOM));
- X
- X s = FALSE;
- X if (R_SIZE(curwp) == BYTES)
- X {
- X if (f != FALSE)
- X {
- X /* Really a kill. */
- X if ((lastflag & CFKILL) == 0)
- X bclear (&sav_buf);
- X thisflag |= CFKILL;
- X }
- X s = ldelete ((A32)n, f);
- X curwp -> w_unit_offset = 0;
- X }
- X return (s);
- X}
- X
- X
- X/*
- X* Delete backwards. This is quite easy too,
- X* because it's all done with other functions. Just
- X* move the cursor back, and delete forwards.
- X* Like delete forward, this actually does a kill
- X* if presented with an argument.
- X*/
- Xchar backdel (f, n, k)
- X{
- X
- X int u_off;
- X char s;
- X
- X if (n < 0)
- X return (forwdel (f, -n, KRANDOM));
- X
- X s = FALSE;
- X if (R_SIZE(curwp) == BYTES)
- X {
- X u_off = curwp -> w_unit_offset;
- X curwp -> w_unit_offset = 0;
- X if ((s = backchar (f, n * R_CHR_PER_U(curwp), KRANDOM)) == TRUE)
- X {
- X s = ldelete ((A32)n, f);
- X if (f != FALSE)
- X {
- X /* Really a kill. */
- X if ((lastflag & CFKILL) == 0)
- X bclear (&sav_buf);
- X thisflag |= CFKILL;
- X }
- X }
- X curwp -> w_unit_offset = u_off;
- X }
- X return (s);
- X}
- X
- X
- X/*
- X* Change the size of the display unit to BYTE.
- X* Adjust byte shift to the allowable range.
- X* Normally bound to "META-1".
- X*/
- Xbool dispsize1 ()
- X{
- X curwp -> w_disp_shift = 0; /* shift to 0 when changing size */
- X curwp -> w_unit_offset = 0; /* go to end of unit */
- X
- X switch (R_TYPE(curwp))
- X {
- X case OCTAL:
- X curwp -> w_fmt_ptr = &octal_8_fmt;
- X break;
- X
- X case DECIMAL:
- X curwp -> w_fmt_ptr = &decimal_8_fmt;
- X break;
- X
- X case HEX:
- X curwp -> w_fmt_ptr = &hex_8_fmt;
- X break;
- X
- X case BINARY:
- X curwp -> w_fmt_ptr = &binary_8_fmt;
- X break;
- X
- X default:
- X return (TRUE);
- X break;
- X }
- X
- X /* if we are in the middle of a search then use the proper format struc */
- X if (read_pat_mode)
- X curwp -> w_fmt_ptr = curwp -> w_fmt_ptr -> r_srch_fmt;
- X
- X move_ptr (curwp, 0L, TRUE, TRUE, TRUE);
- X wind_on_dot (curwp);
- X curwp -> w_flag = WFHARD;
- X update ();
- X return (TRUE);
- X}
- X
- X/*
- X* Change the size of the display unit to WORD.
- X* Adjust byte shift to the allowable range.
- X* Normally bound to "META-2".
- X*/
- Xbool dispsize2 ()
- X{
- X curwp -> w_disp_shift = 0; /* shift to 0 when changing size */
- X curwp -> w_unit_offset = 0; /* go to end of unit */
- X
- X switch (R_TYPE(curwp))
- X {
- X case OCTAL:
- X curwp -> w_fmt_ptr = &octal_16_fmt;
- X break;
- X
- X case DECIMAL:
- X curwp -> w_fmt_ptr = &decimal_16_fmt;
- X break;
- X
- X case HEX:
- X curwp -> w_fmt_ptr = &hex_16_fmt;
- X break;
- X
- X case BINARY:
- X curwp -> w_fmt_ptr = &binary_16_fmt;
- X break;
- X
- X default:
- X return (TRUE);
- X break;
- X }
- X
- X /* if we are in the middle of a search then use the proper format struc */
- X if (read_pat_mode)
- X curwp -> w_fmt_ptr = curwp -> w_fmt_ptr -> r_srch_fmt;
- X
- X move_ptr (curwp, 0L, TRUE, TRUE, TRUE);
- X wind_on_dot (curwp);
- X curwp -> w_flag = WFHARD;
- X update ();
- X return (TRUE);
- X}
- X
- X/*
- X* Change the size of the display unit to DOUBLE WORD.
- X* Adjust byte shift to the allowable range.
- X* Normally bound to "META-4".
- X*/
- Xbool dispsize4 ()
- X{
- X curwp -> w_disp_shift = 0; /* shift to 0 when changing size */
- X curwp -> w_unit_offset = 0; /* go to end of unit */
- X
- X switch (R_TYPE(curwp))
- X {
- X case OCTAL:
- X curwp -> w_fmt_ptr = &octal_32_fmt;
- X break;
- X
- X case DECIMAL:
- X curwp -> w_fmt_ptr = &decimal_32_fmt;
- X break;
- X
- X case HEX:
- X curwp -> w_fmt_ptr = &hex_32_fmt;
- X break;
- X
- X case BINARY:
- X curwp -> w_fmt_ptr = &binary_32_fmt;
- X break;
- X
- X default:
- X return (TRUE);
- X break;
- X }
- X
- X /* if we are in the middle of a search then use the proper format struc */
- X if (read_pat_mode)
- X curwp -> w_fmt_ptr = curwp -> w_fmt_ptr -> r_srch_fmt;
- X
- X move_ptr (curwp, 0L, TRUE, TRUE, TRUE);
- X wind_on_dot (curwp);
- X curwp -> w_flag = WFHARD;
- X update ();
- X return (TRUE);
- X}
- X
- X/*
- X* Display byte swaped. This command causes the bytes
- X* that are displayed in WORD and DWORD mode to be swaped
- X* in the way that the INTEL microprocessors do it.
- X*/
- Xbool dispswapbyte (f, n, k)
- X{
- X if ((curwp -> w_fmt_ptr -> r_size) == BYTES)
- X return (TRUE);
- X
- X if (curwp -> w_intel_mode)
- X curwp -> w_intel_mode = FALSE;
- X else
- X curwp -> w_intel_mode = TRUE;
- X
- X curwp -> w_flag = WFHARD;
- X update ();
- X return (TRUE);
- X}
- X
- X/*
- X* Yank text back from the kill buffer. This
- X* is really easy. All of the work is done by the
- X* standard insert routines. All you do is run the loop,
- X* and check for errors.
- X* An attempt has been made to fix the cosmetic bug
- X* associated with a yank when dot is on the top line of
- X* the window (nothing moves, because all of the new
- X* text landed off screen).
- X*/
- Xbool yank (f, n, k)
- X{
- X register D16 c;
- X register A32 i;
- X char buf[NCOL], buf1[NCOL];
- X
- X if (n < 0)
- X return (FALSE);
- X while (n--)
- X {
- X i = 0;
- X save_buf_home ();
- X while ((c = get_save_char ()) != (D16)-1)
- X {
- X if (linsert (1, c) == FALSE)
- X return (FALSE);
- X if ((i & 0x2ff) == 0)
- X {
- X sprintf (buf1, MSG_procing, R_POS_FMT(curwp));
- X sprintf (buf, buf1, (ulong)i);
- X writ_echo (buf);
- X /* check if we should quit */
- X if (ttkeyready ())
- X {
- X wind_on_dot_all();
- X if (ttgetc () == CTL_G)
- X return (FALSE);
- X }
- X }
- X ++i;
- X }
- X }
- X /* update buffer display */
- X if ((blistp -> b_nwnd != 0) &&
- X (blistp -> b_type == BTLIST))
- X listbuffers ();
- X
- X curwp -> w_flag |= WFHARD;
- X return (TRUE);
- X}
- X
- X/*
- X* Link windows. pvr
- X* This function toggles the window linking function.
- X* When linking is enabled all windows that look at
- X* the same buffer will be forced to have the same
- X* dot position. Each window is then moved to be
- X* positioned on the dot. Thus when a user moves
- X* arround a buffer all other views into that buffer
- X* will follow.
- X*/
- X
- Xbool linkwind ()
- X
- X{
- X char buf[NCOL];
- X
- X if (curwp -> w_bufp -> b_flag & BFLINK)
- X {
- X curwp -> w_bufp -> b_flag &= ~(BFLINK & 0xff);
- X sprintf (buf, MSG_lnk, curwp -> w_bufp -> b_bname, MSG_unlink);
- X }
- X else
- X {
- X curwp -> w_bufp -> b_flag |= BFLINK;
- X sprintf (buf, MSG_lnk, curwp -> w_bufp -> b_bname, MSG_link);
- X }
- X writ_echo (buf);
- X return (TRUE);
- X}
- X/*
- X* Print all bad keys to the screen and beep
- X*/
- Xvoid bad_key (key)
- Xint key;
- X{
- X char buf[NCOL];
- X
- X ttbeep ();
- X sprintf (buf, MSG_bad_key);
- X keyname (&buf[strlen (buf)], key);
- X sprintf (&buf[strlen (buf)], ", %X", key);
- X writ_echo (buf);
- X}
- X
- X/*
- X * Combine sequential bytes from the rest of the windows
- X * into this window. This is useful in combining PROM
- X * image files from odd and even bytes into one file.
- X */
- Xbool n_way_combine (f, n, k)
- X{
- X WINDOW * dest_wp, *src_wp;
- X BUFFER *src_bp;
- X A32 dotp;
- X D8 byt;
- X int j = 0;
- X char buf[NCOL], buf1[NCOL];
- X
- X /* save the destination window for later restore */
- X dest_wp = curwp;
- X
- X if ((BUF_SIZE (curwp)) != (A32)0)
- X {
- X writ_echo (MSG_w_not_empty);
- X return(FALSE);
- X }
- X /* Current window must be empty, modifiable and not the only one. */
- X if ((BUF_SIZE (curwp) != 0) ||
- X (curwp -> w_wndp == NULL) ||
- X (curwp -> w_bufp -> b_flag & (BFVIEW | BFSLOCK)))
- X {
- X writ_echo (MSG_w_not_empty);
- X return(FALSE);
- X }
- X
- X
- X
- X
- X for (;;)
- X {
- X /* step to the next window after the destination window */
- X nextwind();
- X
- X /* as I cycle around the windows skip the destination window */
- X if (curwp == dest_wp)
- X {
- X continue;
- X }
- X byt = DOT_CHAR(curwp) & 0xff;
- X dotp = DOT_POS(curwp); /* get the current dot position */
- X /* move the dot position ahead in current buffer */
- X if (move_ptr (curwp, 1L, TRUE, FALSE, TRUE) == FALSE)
- X {
- X /* did we advance? */
- X if (DOT_POS(curwp) == dotp)
- X {
- X wind_on_dot_all();
- X writ_echo (MSG_ok);
- X return (TRUE); /* done all that we could */
- X }
- X }
- X
- X src_wp = curwp;
- X src_bp = curwp -> w_bufp;
- X curwp = dest_wp;
- X curbp = dest_wp -> w_bufp;
- X if (linsert (1, byt) == FALSE)
- X {
- X wind_on_dot_all();
- X return (FALSE); /* insert failed for some reason */
- X }
- X curwp = src_wp;
- X curbp = src_bp;
- X if ((j++ & 0x2ff) == 0)
- X {
- X sprintf (buf1, MSG_procing, R_POS_FMT(curwp));
- X sprintf (buf, buf1, dotp);
- X writ_echo (buf);
- X /* check if we should quit */
- X if (ttkeyready ())
- X {
- X wind_on_dot_all();
- X if (ttgetc () == CTL_G)
- X return (FALSE);
- X }
- X }
- X }
- X}
- X
- X/*
- X * Split the current buffer into the rest of the windows.
- X * This is useful in splitting a binary file into PROM
- X * image files.
- X */
- Xbool n_way_split (f, n, k)
- X{
- X WINDOW *src_wp;
- X A32 b_size;
- X D8 byt;
- X int j = 0;
- X char buf[NCOL], buf1[NCOL];
- X
- X /* save the source window and buffer for later restore */
- X src_wp = curwp;
- X
- X /* step to the next window after the source window */
- X nextwind();
- X
- X /* check that all the destination windows are empty and modifiable */
- X for (;;)
- X {
- X if ((BUF_SIZE (curwp) != 0) ||
- X (curwp -> w_bufp -> b_flag & (BFVIEW | BFSLOCK)))
- X {
- X writ_echo (MSG_w_not_empty);
- X return(FALSE);
- X }
- X
- X /* force all windows to be refreshed */
- X lchange (WFHARD);
- X /* step to the next window */
- X nextwind();
- X /* stop after one pass around the windows */
- X if (curwp == src_wp)
- X break;
- X }
- X
- X b_size = BUF_SIZE(src_wp); /* get the buffer size */
- X
- X /* do the split until source is exhausted */
- X for (;;)
- X {
- X /* step to the next window after the source window */
- X nextwind();
- X
- X /* current window cannot be the source */
- X if (curwp == src_wp)
- X continue;
- X
- X byt = DOT_CHAR(src_wp) & 0xff; /* get the byte to copy */
- X
- X /* are we at the end of the buffer */
- X if (b_size == DOT_POS(src_wp))
- X {
- X wind_on_dot_all();
- X writ_echo (MSG_ok);
- X return (TRUE);
- X }
- X if (linsert (1, byt) == FALSE)
- X {
- X wind_on_dot_all();
- X return (FALSE);
- X }
- X if ((j++ & 0x2ff) == 0)
- X {
- X sprintf (buf1, MSG_procing, R_POS_FMT(src_wp));
- X sprintf (buf, buf1, DOT_POS(src_wp));
- X writ_echo (buf);
- X /* check if we should quit */
- X if (ttkeyready ())
- X {
- X wind_on_dot_all();
- X if (ttgetc () == CTL_G)
- X return (FALSE);
- X }
- X }
- X if (move_ptr (src_wp, 1L, TRUE, FALSE, TRUE) == FALSE)
- X {
- X wind_on_dot_all();
- X writ_echo (MSG_ok);
- X return (TRUE); /* hit the end of the source buffer */
- X }
- X }
- X}
- X
- Xvoid wind_on_dot_all ()
- X{
- X WINDOW *wp;
- X
- X wp = curwp;
- X do
- X {
- X wind_on_dot (curwp);
- X nextwind();
- X } while (wp != curwp);
- X}
- END_OF_FILE
- if test 28521 -ne `wc -c <'random.c'`; then
- echo shar: \"'random.c'\" unpacked with wrong size!
- fi
- # end of 'random.c'
- fi
- if test -f 'spawn.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'spawn.c'\"
- else
- echo shar: Extracting \"'spawn.c'\" \(1390 characters\)
- sed "s/^X//" >'spawn.c' <<'END_OF_FILE'
- X/*
- X* MS-DOS spawn command.com
- X*/
- X#include "def.h"
- X
- Xextern char MSG_shell[];
- Xextern char MSG_def_shell[];
- Xextern char MSG_pmpt[];
- Xextern char MSG_pt[];
- Xextern char MSG_pme[];
- Xextern char MSG_null[];
- X
- X/* #include <dos.h> */
- X#if MSDOS
- X#include "process.h"
- X#endif
- Xchar *cspec = NULL; /* Command string. */
- Xchar *pspec = NULL;
- X
- X/*
- X* Create a subjob with a copy
- X* of the command intrepreter in it. When the
- X* command interpreter exits, mark the screen as
- X* garbage so that you do a full repaint.
- X*/
- Xbool spawncli (f, n, k)
- X{
- X#if MSDOS
- X
- X char *getenv ();
- X char old_prompt[NCOL];
- X char prompt_line[NCOL];
- X
- X ttcolor (CTEXT); /* Normal color. */
- X ttmove (nrow - 1, 0); /* Last line. */
- X ttflush ();
- X ttcooked ();
- X#ifndef IBM
- X strcpy (prompt_line, MSG_pmpt);
- X pspec = getenv (MSG_pt);
- X strcpy (old_prompt, pspec);
- X strcat (prompt_line, pspec);
- X if (strlen (prompt_line - strlen (MSG_pme)) >= 64)
- X /* VERY rude, but setenv not found */
- X {
- X if (putenv (MSG_pmpt) == -1)
- X exit (1);
- X }
- X else
- X if (putenv (prompt_line) == -1)
- X exit (1);
- X
- X#endif
- X if (!cspec && !(cspec = getenv (MSG_shell)))/* jam */
- X cspec = MSG_def_shell;
- X spawnl (P_WAIT, cspec, MSG_null, NULL);
- X putenv (MSG_pme);
- X if (putenv (old_prompt) == -1)
- X exit (1);
- X ttraw ();
- X sgarbf = TRUE;
- X#endif
- X return (TRUE);
- X}
- X
- END_OF_FILE
- if test 1390 -ne `wc -c <'spawn.c'`; then
- echo shar: \"'spawn.c'\" unpacked with wrong size!
- fi
- # end of 'spawn.c'
- fi
- echo shar: End of archive 4 \(of 9\).
- cp /dev/null ark4isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 9 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-