home *** CD-ROM | disk | FTP | other *** search
- #include "jam.h"
-
- /*
- * Buffer handling.
- */
- #include "stdlib.h"
- #include "def.h"
- #include "keyname.h"
- #include "kbd.h" /* needed for modes */
-
- #ifdef FAT
- # include "io.h"
- #endif
-
- static BUFFER rn_(*makelist,(void));
- static RSIZE rn_(itor,(char *buf, int width, RSIZE num));
- static int rn_(_tobuffer,(int f, int n, BOOL newwindow));
-
- /* JAM - made most strings static so defined at most 1 time
- */
- static char *switchto = "Switch to buffer: ";
- static char *switchtod = "Switch to buffer: (default %s) ";
- static char *switchtob = "Switch to buffer in other window: ";
- static char *switchtobd = "Switch to buffer in other window: (default %s) ";
- static char *insertbd = "Insert buffer: (default %s) ";
- static char *insertb = "Insert buffer: ";
- static char *notself = "Cannot insert buffer into self";
- static char *killb = "Kill buffer: (default %s) ";
- static char *only1 = "No other buffers.";
- static char *blist = "*Buffer List*";
- static char *mrbuffer = " MR Buffer";
- static char *sizefile = "Size File";
- static char *savefile = "Save file ";
- static char *nosave = "(No files need saving)";
- static char *killanyway = "Buffer modified; kill anyway";
- static char *notonname = "Cursor not on valid buffer name.";
- static char *notonword = "Cursor not on word.";
-
- /*
- * Attach a buffer to a window. The values of dot and mark come
- * from the buffer if the use count is 0. Otherwise, they come
- * from some other window. *scratch* is the default alternate
- * buffer.
- */
- /*ARGSUSED*/
- usebuffer(f, n)
- int f, n;
- {
- return (_tobuffer(f, n, FALSE));
- }
-
- /*
- * pop to buffer asked for by the user.
- */
- /*ARGSUSED*/
- poptobuffer(f, n)
- int f, n;
- {
- return (_tobuffer(f, n, TRUE));
- }
- /* work function for usebuffer and popbuffer - split by
- * me to shrink the code base, and add confusion! :) JAM
- */
- static int _tobuffer(f, n, newwindow)
- int f;
- int n;
- BOOL newwindow;
- {
- register BUFFER *bp, *scratch;
- register EWINDOW *wp;
- register int s;
- char bufn[NBUFN];
-
- /* check for NULL alt buffer
- */
- if (curbp->b_altb == NULL)
- curbp->b_altb = curbp->b_bufp;
- if ((curbp->b_altb == NULL) && (bheadp != curbp))
- curbp->b_altb = bheadp;
- if (curbp->b_altb == NULL)
- {
- if (!(scratch = bfind(Scratch, TRUE)))
- scratch = bheadp;
- curbp->b_altb = scratch; /* use scratch as last resort */
- }
-
- /* Get buffer to use from user - check for
- * no alt buff or in scratch and altb is same, no default
- */
- if ((curbp->b_altb == NULL) || (curbp == scratch))
- s=eread(switchto, bufn, NBUFN, EFNEW|EFBUF);
- else
- s=eread(switchtod, bufn, NBUFN,EFNEW|EFBUF, curbp->b_altb->b_bname);
-
- if (s == ABORT)
- return s;
- if ((s == FALSE) && (curbp->b_altb != NULL))
- bp = curbp->b_altb;
- else if ((bp=bfind(bufn, TRUE)) == NULL)
- return FALSE;
-
- if (!newwindow)
- {
- /* and put it in current window
- */
- if (showbuffer(bp, curwp, WFMODE|WFFORCE|WFHARD) != TRUE)
- return (FALSE);
- curbp = bp;
- thisflag |= CFNEWB;
- return (TRUE);
- }
- else
- {
- /* and put it in a new window
- */
- if ((wp = popbuf(bp)) == NULL)
- return FALSE;
- curbp = bp;
- curwp = wp;
- thisflag |= CFNEWB;
- return TRUE;
- }
- }
- /*
- * Dispose of a buffer, by name.
- * Ask for the name. Look it up (don't get too
- * upset if it isn't there at all!). Clear the buffer (ask
- * if the buffer has been changed). Then free the header
- * line and the buffer header. Bound to "C-X K".
- */
- /*ARGSUSED*/
- killbuffer(f, n)
- int f, n;
- {
- register BUFFER *bp;
- register int s;
- char bufn[NBUFN];
-
- if ((s=eread(killb, bufn, NBUFN, EFNEW|EFBUF, curbp->b_bname)) == ABORT)
- return (s);
- else if (s == FALSE)
- bp = curbp;
- else if ((bp=bfind(bufn, FALSE)) == (BUFFER *)0)
- return FALSE;
- return (nukebuffer(bp));
- }
-
- /* Guts of killbuffer split out so internal functions
- * can kill buffers when they want to (JAM)
- */
- int nukebuffer(bp)
- BUFFER *bp;
- {
- EWINDOW *wp;
- register BUFFER *bp1, *bp2;
-
- /* Find some other buffer to display. Try the alternate buffer,
- * then the first different buffer in the buffer list. If
- * there's only one buffer, create buffer *scratch* and make
- * it the alternate buffer. Return if *scratch* is only buffer.
- */
- if ((bp1 = bp->b_altb) == NULL)
- {
- bp1 = (bp == bheadp) ? bp->b_bufp : bheadp;
- if (bp1 == NULL)
- {
- /* Only one buffer; see if it's scratch
- * else create scratch as replacement/alternate
- */
- if (bp == bfind(Scratch, FALSE))
- {
- ewprintf(only1);
- return FALSE;
- }
- if ((bp1 = bfind(Scratch, TRUE)) == NULL)
- return FALSE;
- }
- }
-
- /* clear it; user can refuse if modified and if so,
- * just abort and go home happy
- */
- if (bclear(bp) != TRUE)
- return TRUE;
-
- /* Unhook it from any windows
- */
- for (wp = wheadp; bp->b_nwnd > 0; wp = wp->w_wndp)
- {
- if (wp->w_bufp == bp)
- {
- bp2 = bp1->b_altb; /* save alternate buffer */
- if (showbuffer(bp1, wp, WFMODE|WFFORCE|WFHARD))
- bp1->b_altb = bp2;
- else
- bp1 = bp2; /* gack! */
- }
- }
-
- #ifdef WINDOWED
- WindowSleepCursor();
- #endif
-
- /* Free it now; redirect any b_altb/b_bufp pointers from
- * doomed buffer and unlink doomed buffer from chain.
- */
- if (bp == curbp)
- curbp = bp1;
- free((char *) bp->b_linep); /* Release header line. */
- bp2 = NULL; /* Find the header. */
- bp1 = bheadp;
- while (bp1 != bp)
- {
- if (bp1->b_altb == bp)
- bp1->b_altb = ((bp->b_altb == bp1) ? NULL : bp->b_altb);
- bp2 = bp1;
- bp1 = bp1->b_bufp;
- }
- bp1 = bp1->b_bufp; /* Next one in chain. */
- if (bp2 == NULL) /* Unlink it. */
- bheadp = bp1;
- else
- bp2->b_bufp = bp1;
-
- /* Finish with altb's
- */
- while (bp1 != NULL)
- {
- if (bp1->b_altb == bp)
- bp1->b_altb = (bp->b_altb == bp1) ? NULL : bp->b_altb;
- bp1 = bp1->b_bufp;
- }
- free(bp->b_bname); /* Release name block */
-
- if (bp->b_iname[0] && fileisok(bp->b_iname))
- {
- unlink(bp->b_iname); /* Delete incremental save file */
- MakeIncSaveLog(); /* update crash file log */
- }
-
- clearUndo(bp);
-
- if (bp->b_flag & BFDELETE)
- unlink(bp->b_fname);
-
- free((char *) bp); /* Release buffer block */
-
- #ifdef WINDOWED
- WindowNormalCursor();
- #endif
-
- thisflag |= CFKILLB;
- return TRUE;
- }
-
- /*
- * Save some buffers - just call anycb with the arg flag.
- */
- /*ARGSUSED*/
- savebuffers(f, n)
- int f, n;
- {
- if (anycb(f) == ABORT)
- return ABORT;
- return TRUE;
- }
-
- /*
- * Display the buffer list. This is done
- * in two parts. The "makelist" routine figures out
- * the text, and puts it in a buffer. "popbuf"
- * then pops the data onto the screen. Bound to
- * "C-X C-B".
- */
- /*ARGSUSED*/
- listbuffers(f, n)
- int f, n;
- {
- register BUFFER *bp;
- register EWINDOW *wp;
-
- if ((bp=makelist()) == NULL || (wp=popbuf(bp)) == NULL)
- return FALSE;
- wp->w_dotp = bp->b_dotp; /* fix up if window already on screen */
- wp->w_doto = bp->b_doto;
- thisflag = 0;
-
- for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
- if (wp->w_bufp == bp)
- wp->w_flag |= WFHARD|WFFORCE;
-
- return TRUE;
- }
-
- /*
- * This routine rebuilds the text for the
- * list buffers command. Return TRUE if
- * everything works. Return FALSE if there
- * is an error (if there is no memory).
- */
- static BUFFER *makelist()
- {
- register char *cp1;
- register char *cp2;
- register char c;
- register BUFFER *bp;
- LINE *lp;
- register RSIZE nbytes;
- BUFFER *blp;
- #define SIZENUM 10
- #define LINENUM 200
- #define BUFNAMELEN NBUFN
- char b[SIZENUM+1];
- char line[LINENUM];
-
-
- if ((blp = bfind(blist, TRUE)) == NULL)
- return NULL;
-
- blp->b_flag &= ~(BFVIEW | BFCHG);
- if (bclear(blp) != TRUE)
- return NULL;
-
- (VOID) strcpy(line, mrbuffer);
- cp1 = line + 10;
- while(cp1 < line + 4 + BUFNAMELEN + 1)
- *cp1++ = ' ';
-
- (VOID) strcpy(cp1, sizefile);
- if (addline(blp, line) == NULL)
- return NULL;
- (VOID) strcpy(line, " -- ------");
- cp1 = line + 10;
-
- while(cp1 < line + 4 + BUFNAMELEN+ 1)
- *cp1++ = ' ';
-
- (VOID) strcpy(cp1, "---- ----");
- if (addline(blp, line) == NULL)
- return NULL;
-
- bp = bheadp; /* For all buffers */
- while (bp != NULL)
- {
- BOOL touched = FALSE;
- LINE *addedline;
-
- cp1 = line; /* Start at left edge */
- *cp1++ = (char)((bp == curbp) ? '>' : ' ');
- *cp1++ = (char)(((bp->b_flag&BFCHG) != 0) ? '*' :
- (bp->b_flag&BFVIEW) ? '%' : ' ');
- *cp1++ = (char)' '; /* Gap. */
- *cp1++ = (char)' ';
- cp2 = &bp->b_bname[0]; /* Buffer name */
- while ((c = *cp2++) != 0)
- *cp1++ = c;
- while (cp1 < &line[4+BUFNAMELEN+1])
- *cp1++ = ' ';
- nbytes = 0; /* Count bytes in buf. */
- if (bp != blp)
- {
- lp = lforw(bp->b_linep);
- while (lp != bp->b_linep)
- {
- if (lp->l_flag & LFCHANGE)
- touched = TRUE;
- nbytes += llength(lp)+1;
- lp = lforw(lp);
- }
- if(nbytes)
- nbytes--; /* no bonus newline */
- }
- (VOID) itor(b, SIZENUM, nbytes); /* 10 digit buffer size. */
- cp2 = &b[0];
- while ((c = *cp2++) != 0)
- *cp1++ = c;
- *cp1++ = ' '; /* Gap.. */
- cp2 = &bp->b_fname[0]; /* File name */
- if (*cp2 != 0)
- {
- while ((c = *cp2++) != 0)
- {
- if (cp1 < &line[LINENUM-1])
- *cp1++ = c;
- }
- }
- *cp1 = 0; /* Add to the buffer. */
- if ((addedline = addline(blp, line)) == NULL)
- return NULL;
- if (touched)
- changelineflag(addedline, TRUE);
- bp = bp->b_bufp;
- }
- blp->b_dotp = lforw(blp->b_linep); /* put dot at beginning of buffer */
- blp->b_doto = 0;
-
- blp->b_flag |= BFVIEW;
-
- if((blp->b_modes[0] = name_mode(BlistStr)) == NULL)
- {
- blp->b_modes[0] = &map_table[0];
- ewprintf("Can't set mode: %s", BlistStr);
- }
- return blp; /* All done */
- }
-
- /*
- * Used above.
- */
- static RSIZE itor(buf, width, num)
- register char buf[];
- register int width;
- register RSIZE num;
- {
- register RSIZE r;
-
- if (num / 10 == 0)
- {
- buf[0] = (char)((num % 10) + '0');
- for (r = 1; r < width; buf[r++] = ' ')
- ;
- buf[width] = '\0';
- return 1;
- }
- else
- {
- buf[r = itor(buf, width, num / (RSIZE)10)] =
- (char)((num % (RSIZE)10) + '0');
- return r + 1;
- }
- /*NOTREACHED*/
- }
-
- /*
- * The argument "text" points to
- * a string. Append this line to the
- * buffer. Handcraft the EOL
- * on the end. Return TRUE if it worked and
- * FALSE if you ran out of room.
- *
- * CAVEAT - this code will NOT mark added lines as LFCHANGE'd
- *
- */
- LINE *addline(bp, text)
- register BUFFER *bp;
- char *text;
- {
- register LINE *lp;
- register int i;
- register int ntext;
-
- if (bp->b_flag & BFVIEW)
- {
- ttbeep();
- return NULL;
- }
-
- if (filetimechanged(bp))
- return(FALSE);
-
- clearUndo(bp);
-
- ntext = strlen(text);
- if ((lp=lalloc(ntext)) == NULL)
- return NULL;
- for (i=0; i<ntext; ++i)
- lputc(lp, i, text[i]);
- bp->b_linep->l_bp->l_fp = lp; /* Hook onto the end */
- lp->l_bp = bp->b_linep->l_bp;
- bp->b_linep->l_bp = lp;
- lp->l_fp = bp->b_linep;
- #ifdef CANTHAPPEN
- if (bp->b_dotp == bp->b_linep) /* If "." is at the end */
- bp->b_dotp = lp; /* move it to new line */
- if (bp->b_markp == bp->b_linep) /* ditto for mark */
- bp->b_markp = lp;
- #endif
- return lp;
- }
-
- /*
- * Look through the list of buffers, giving the user
- * a chance to save them. Return TRUE if there are
- * any changed buffers afterwards. Buffers that don't
- * have an associated file don't count. Return FALSE
- * if there are no changed buffers.
- */
- anycb(f)
- int f;
- {
- register BUFFER *bp;
- register int s = FALSE, save = FALSE;
- char prompt[NFILEN + 11];
-
- for (bp = bheadp; bp != NULL; bp = bp->b_bufp)
- {
- if ((bp->b_fname[0] != '\0') && (bp->b_flag&BFCHG))
- {
- if (f == ABORT) /* Just care to find if 1 file */
- { /* is changed (JAM) */
- s = TRUE;
- break;
- }
- strcpy(prompt, savefile);
- strcpy(prompt + 10, bp->b_fname);
-
- if ((f == TRUE) || ((save = eyorn(prompt)) == TRUE)
- && (buffsave(bp) == TRUE))
- bp->b_flag &= ~BFCHG;
- else
- s = TRUE;
- if (save == ABORT)
- return (save);
- save = TRUE;
- }
- }
- if (save == FALSE)
- ewprintf(nosave);
- return s;
- }
-
- /*
- * Search for a buffer, by name.
- * If not found, and the "cflag" is TRUE,
- * create a buffer and put it in the list of
- * all buffers. Return pointer to the BUFFER
- * block for the buffer.
- */
- BUFFER *bfind(bname, cflag)
- register char *bname;
- int cflag;
- {
- register BUFFER *bp;
- register LINE *lp;
- int i;
- extern int defb_nmodes;
- extern MAPS *defb_modes[PBMODES];
- extern char defb_flag;
-
- bp = bheadp;
- for (bp = bheadp; bp; bp = bp->b_bufp)
- {
- if (strcmp(bname, bp->b_bname) == 0)
- return bp;
- }
- if (cflag!=TRUE)
- return NULL;
-
- /*NOSTRICT*/
- if (!(bp=(BUFFER *)calloc(1, sizeof(BUFFER))))
- {
- ewprintf(Nobytes, sizeof(BUFFER));
- return NULL;
- }
-
- if ((bp->b_bname=malloc((unsigned)(strlen(bname)+1))) == NULL)
- {
- ewprintf(Nobytes, strlen(bname)+1);
- free((char *) bp);
- return NULL;
- }
-
- if ((lp = lalloc(0)) == NULL)
- {
- free(bp->b_bname);
- free((char *) bp);
- return NULL;
- }
- bp->b_altb = bp->b_bufp = NULL;
- bp->b_dotp = lp;
- bp->b_flag = defb_flag;
- bp->b_linep = lp;
- bp->b_nmodes = defb_nmodes;
-
- i = 0;
- do
- {
- bp->b_modes[i] = defb_modes[i];
- } while(i++ < defb_nmodes);
-
- (VOID) strcpy(bp->b_bname, bname);
- lforw(lp) = lp;
- lback(lp) = lp;
- bp->b_bufp = bheadp;
- bheadp = bp;
- return bp;
- }
-
- /*
- * This routine blows away all of the text
- * in a buffer. If the buffer is marked as changed
- * then we ask if it is ok to blow it away; this is
- * to save the user the grief of losing text. The
- * window chain is nearly always wrong if this gets
- * called; the caller must arrange for the updates
- * that are required. Return TRUE if everything
- * looks good.
- */
- bclear(bp)
- register BUFFER *bp;
- {
- register LINE *lp;
- register int s;
- VOID lfree();
-
- if ((bp->b_flag&BFCHG) && (s=eyesno(killanyway)) != TRUE)
- return (s);
-
- #ifdef WINDOWED
- WindowSleepCursor();
- #endif
-
- bp->b_flag &= ~BFCHG; /* Not changed */
- while ((lp=lforw(bp->b_linep)) != bp->b_linep)
- lfree(lp);
- bp->b_dotp = bp->b_linep; /* Fix "." */
- bp->b_dotp->l_flag = 0;
- bp->b_doto = 0;
- bp->b_markp = NULL; /* Invalidate "mark" */
- bp->b_marko = 0;
- bp->b_time = 0;
- bp->b_flag &= ~(BFINC | BFVIEW | BFDIR | BFSAVED);
- clearUndo(bp);
-
- #ifdef WINDOWED
- WindowNormalCursor();
- #endif
- return TRUE;
- }
-
- /*
- * Display the given buffer in the given window. Flags indicated
- * action on redisplay.
- */
- showbuffer(bp, wp, flags)
- register BUFFER *bp;
- register EWINDOW *wp;
- int flags;
- {
- register BUFFER *obp;
-
- if (wp->w_bufp == bp) /* Easy case! */
- {
- wp->w_flag |= flags;
- return TRUE;
- }
-
- /* First, dettach the old buffer from the window
- */
- obp = wp->w_bufp;
- if (obp != NULL) /* null if new window only */
- {
- obp->b_nwnd--;
- obp->b_dotp = wp->w_dotp;
- obp->b_doto = wp->w_doto;
- obp->b_markp = wp->w_markp;
- obp->b_marko = wp->w_marko;
- }
-
- /* Now, attach the new buffer to the window
- */
- wp->w_bufp = bp;
- wp->w_dotp = bp->b_dotp;
- wp->w_doto = bp->b_doto;
- wp->w_markp = bp->b_markp;
- wp->w_marko = bp->b_marko;
-
- bp->b_altb = obp; /* remember any alt window */
- bp->b_nwnd++; /* add one to visible windows */
- wp->w_flag |= WFMODE|flags;
- return TRUE;
- }
-
- /*
- * Pop the buffer we got passed onto the screen.
- * Returns a status.
- */
- EWINDOW *popbuf(bp)
- register BUFFER *bp;
- {
- register EWINDOW *wp;
-
- if (bp->b_nwnd == 0) /* Not on screen yet. */
- {
- if ((wp=wpopup()) == NULL)
- return NULL;
- }
- else
- for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
- if (wp->w_bufp == bp)
- {
- wp->w_flag |= (WFHARD|WFFORCE);
- return wp ;
- }
- if (showbuffer(bp, wp, WFHARD) != TRUE)
- return NULL;
- return wp;
- }
-
- /*
- * Insert another buffer at dot. Very useful.
- */
- /*ARGSUSED*/
- bufferinsert(f, n)
- int f, n;
- {
- register BUFFER *bp;
- register LINE *clp;
- register int clo;
- register int nline;
- int s;
- char bufn[NBUFN];
-
- /* Get buffer to use from user */
- if (curbp->b_altb != NULL)
- s=eread(insertbd, bufn, NBUFN, EFNEW|EFBUF, curbp->b_altb->b_bname);
- else
- s=eread(insertb, bufn, NBUFN, EFNEW|EFBUF);
- if (s == ABORT)
- return (s);
- if (s == FALSE && curbp->b_altb != NULL)
- bp = curbp->b_altb;
- else
- if ((bp=bfind(bufn, FALSE)) == NULL)
- {
- ttbeep();
- ewprintf(nosuchbuffer);
- return FALSE;
- }
-
- if (bp==curbp)
- {
- ewprintf(notself);
- return FALSE;
- }
-
- if (curbp->b_flag & BFVIEW)
- {
- ttbeep();
- return FALSE;
- }
- if (filetimechanged(bp))
- return(FALSE);
- clearUndo(bp);
-
- /* insert the buffer
- */
- nline = 0;
- clp = lforw(bp->b_linep);
- for(;;)
- {
- for (clo = 0; clo < llength(clp); clo++)
- if (linsert(1, lgetc(clp, clo)) == FALSE)
- return FALSE;
- if((clp = lforw(clp)) == bp->b_linep)
- break;
- if (newline(FFRAND, 1) == FALSE) /* fake newline */
- return FALSE;
- nline++;
- }
-
- /* Are these 2 strings worth it?
- */
- if (nline == 1)
- ewprintf("[Inserted 1 line]");
- else
- ewprintf("[Inserted %d lines]", nline);
-
- clp = curwp->w_linep; /* cosmetic adjustment */
- if (curwp->w_dotp == clp) /* for offscreen insert */
- {
- while (nline-- && lback(clp)!=curbp->b_linep)
- clp = lback(clp);
- curwp->w_linep = clp; /* adjust framing. */
- curwp->w_flag |= WFHARD;
- }
- return (TRUE);
- }
-
- /*
- * Toggle the dirty bit on this buffer.
- */
- /*ARGSUSED*/
- togglemodified(f, n)
- int f, n;
- {
- BOOL hard = FALSE;
- register LINE *lp;
-
- if (curbp->b_flag & BFVIEW)
- {
- ewprintf("Readonly buffer.");
- return FALSE;
- }
-
- /* sigh, this is costly...should have the highlight
- * code check the modified bit on the buffer
- * also before lighting the bits; that way you don't
- * lose the info but the text doesn't light up
- * all the time
- */
- lp = lforw(curbp->b_linep);
- while (lp != curbp->b_linep)
- {
- if (lp->l_flag & LFCHANGE)
- hard = TRUE;
- changelineflag(lp, FALSE);
- lp = lforw(lp);
- }
-
- curbp->b_flag ^= BFCHG;
-
- if ((curbp->b_flag & BFCHG) == 0)
- curbp->b_flag &= ~(BFINC | BFSAVED);
- else
- curbp->b_flag |= BFINC;
-
- if (hard)
- upmodes(WFHARD);
-
- thisflag |= CFNEWC;
- return TRUE;
- }
- togglereadonly(f, n)
- int f, n;
- {
- if (curbp->b_modes[0] == name_mode(BlistStr))
- {
- ewprintf("Buffer List readonly!");
- return (FALSE);
- }
-
- curbp->b_flag ^= BFVIEW;
-
- if (curbp->b_flag & BFVIEW)
- curbp->b_flag &= ~(BFCHG | BFINC | BFSAVED);
-
- thisflag |= CFNEWC;
- return TRUE;
- }
-
- /*
- * Popbuf and set all windows to top of buffer. Currently only used by
- * help functions.
- */
- popbuftop(bp)
- register BUFFER *bp;
- {
- register EWINDOW *wp;
-
- bp->b_dotp = lforw(bp->b_linep);
- bp->b_doto = 0;
- if(bp->b_nwnd != 0)
- {
- for(wp = wheadp; wp!=NULL; wp = wp->w_wndp)
- if(wp->w_bufp == bp)
- {
- wp->w_dotp = bp->b_dotp;
- wp->w_doto = 0;
- wp->w_flag |= WFHARD;
- }
- }
- return popbuf(bp) != NULL;
- }
-
-
- /* Return name of active buffer, else
- * punt. (JAM)
- */
- char *GetCurrentBufferName()
- {
- if (curbp)
- return(curbp->b_fname);
- else
- return(Scratch);
- }
-
- /* Grab a word under the cursor - kinda ughly (JAM)
- */
- int grabword(lnum, col, bname, len, bbuf)
- int *lnum;
- int *col;
- char *bname;
- int len;
- BOOL bbuf;
- {
- register int i, j;
- char c;
- register BUFFER *bp;
-
- bname[0] = '\0';
- *lnum = -1;
-
- /* Find the word; if on space/tab, error and return
- * else backup to word and then copy till work end
- */
- if (((c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' ') ||
- ( c == '\t'))
- {
- ewprintf(bbuf ? notonname : notonword);
- return(ABORT);
- }
-
- /* backup to whitespace
- */
- for (i = curwp->w_doto; i >= 0; i--)
- {
- c = lgetc(curwp->w_dotp, i);
- if ((c == ' ') || (c == '\t'))
- {
- i++;
- break;
- }
- }
-
- /* get bname/word
- */
- *col = i;
- for (j = 0; i < llength(curwp->w_dotp); i++, j++)
- {
- c = lgetc(curwp->w_dotp, i);
- if ((j > len) || (c == ' ') || (c == '\t'))
- break;
- bname[j] = c;
- bname[j+1] = '\0';
- }
-
- /* Validate name (don't use blist from here - silly!)
- */
- if (bbuf)
- {
- if (strcmp(bname, blist) != 0)
- for (bp = bheadp; bp != NULL; bp = bp->b_bufp)
- if (strcmp(bp->b_bname, bname) == 0)
-
- /* found name, get line number & col
- */
- {
- LINE *lp;
-
- lp = lforw(curwp->w_bufp->b_linep); /* find the line number */
- for (i = 1; lp != curwp->w_dotp; i++)
- lp = lforw(lp);
- *lnum = i;
- return (TRUE);
- }
- ewprintf(notonname);
- return (ABORT);
- }
-
- /* just plain word
- */
- return (TRUE);
- }
- /* Activated via 's' in Buffer List window, if
- * on a valid buffer name (JAM)
- */
- int savethisbuffer(f, n)
- int f, n;
- {
- int s, lnum, col;
- BUFFER *bp;
- char name[NBUFN];
-
- if ((s = grabword(&lnum, &col, name, NBUFN, TRUE)) == TRUE)
- if (bp = bfind(name, FALSE))
- if (s = buffsave(bp))
- if (listbuffers(0, 1) == TRUE)
- {
- /* if worked, then curbp is buffer list
- */
- forwline(FFRAND, lnum -1); /* in case at end */
- curwp->w_doto = col;
- }
- return (s);
- }
- /* Activated via 'k' in Buffer List window, if
- * on a valid buffer name (JAM)
- */
- int zapbuffer(f, n)
- int f, n;
- {
- char bname[NBUFN+1];
- int s, lnum, col;
-
- if ((s = grabword(&lnum, &col, bname, NBUFN, TRUE) == TRUE))
- {
- AddString(bname); AddKchar(CCHR('J'));
- if (killbuffer(0, 1) == TRUE)
- if (listbuffers(0, 1) == TRUE)
- {
- curbp->b_dotp = curwp->w_dotp = lforw(curbp->b_linep);
- forwline(FFRAND, lnum - 1); /* 1 less line now */
- if (curwp->w_dotp == lforw(curwp->w_bufp->b_linep))
- forwline(FFRAND, lnum - 2); /* wrap to end */
- curbp->b_doto = curwp->w_doto = col;
- }
- }
- return (s);
- }
- /* Activated via 'u' in Buffer List window, if
- * on a valid buffer name (JAM)
- */
- int seebuffer(f, n)
- int f, n;
- {
- char bname[NBUFN+1];
- int s, lnum, col;
-
- if ((s = grabword(&lnum, &col, bname, NBUFN, TRUE) == TRUE))
- {
- AddString(bname); AddKchar(CCHR('J'));
- if (poptobuffer(0, 1) == TRUE)
- listbuffers(0, 1);
- }
- return (s);
- }
- /* Update buffer-list buffer if visible; icky
- * cause sometimes loses your place (JAM)
- */
- void update_blist()
- {
- register EWINDOW *wp;
-
- for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
- if (strcmp(wp->w_bufp->b_bname, blist) == 0)
- listbuffers(0, 1);
- }
-
- int showbufferfile(f, n)
- int f,n;
- {
- ewprintf("Current buffer is on %s disk", curbp->b_fname);
- return(TRUE);
- }