[BACK]Return to buffer.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Diff for /src/usr.bin/mg/buffer.c between version 1.36 and 1.37

version 1.36, 2005/03/10 16:58:57 version 1.37, 2005/04/03 02:09:28
Line 23 
Line 23 
         }          }
         curwp->w_flag |= WFMODE;          curwp->w_flag |= WFMODE;
   
         return(1);          return (1);
 }  }
   
 /*  /*
Line 48 
Line 48 
                           EFNEW | EFBUF, curbp->b_altb->b_bname);                            EFNEW | EFBUF, curbp->b_altb->b_bname);
   
         if (bufp == NULL)          if (bufp == NULL)
                 return ABORT;                  return (ABORT);
         if (bufn[0] == 0 && curbp->b_altb != NULL)          if (bufn[0] == 0 && curbp->b_altb != NULL)
                 bp = curbp->b_altb;                  bp = curbp->b_altb;
         else if ((bp = bfind(bufn, TRUE)) == NULL)          else if ((bp = bfind(bufn, TRUE)) == NULL)
                 return FALSE;                  return (FALSE);
   
         /* and put it in current window */          /* and put it in current window */
         curbp = bp;          curbp = bp;
         return showbuffer(bp, curwp, WFFORCE | WFHARD);          return (showbuffer(bp, curwp, WFFORCE | WFHARD));
 }  }
   
 /*  /*
Line 79 
Line 79 
                 bufp = eread("Switch to buffer in other window: (default %s) ",                  bufp = eread("Switch to buffer in other window: (default %s) ",
                         bufn, NBUFN, EFNEW | EFBUF, curbp->b_altb->b_bname);                          bufn, NBUFN, EFNEW | EFBUF, curbp->b_altb->b_bname);
         if (bufp == NULL)          if (bufp == NULL)
                 return ABORT;                  return (ABORT);
         if (bufp[0] == 0 && curbp->b_altb != NULL)          if (bufp[0] == 0 && curbp->b_altb != NULL)
                 bp = curbp->b_altb;                  bp = curbp->b_altb;
         else if ((bp = bfind(bufn, TRUE)) == NULL)          else if ((bp = bfind(bufn, TRUE)) == NULL)
                 return FALSE;                  return (FALSE);
   
         /* and put it in a new window */          /* and put it in a new window */
         if ((wp = popbuf(bp)) == NULL)          if ((wp = popbuf(bp)) == NULL)
                 return FALSE;                  return (FALSE);
         curbp = bp;          curbp = bp;
         curwp = wp;          curwp = wp;
         return TRUE;          return (TRUE);
 }  }
   
 /*  /*
Line 109 
Line 109 
   
         if ((bufp = eread("Kill buffer: (default %s) ", bufn, NBUFN, EFNEW | EFBUF,          if ((bufp = eread("Kill buffer: (default %s) ", bufn, NBUFN, EFNEW | EFBUF,
             curbp->b_bname)) == NULL)              curbp->b_bname)) == NULL)
                 return ABORT;                  return (ABORT);
         else if (bufp[0] == 0)          else if (bufp[0] == 0)
                 bp = curbp;                  bp = curbp;
         else if ((bp = bfind(bufn, FALSE)) == NULL)          else if ((bp = bfind(bufn, FALSE)) == NULL)
                 return FALSE;                  return (FALSE);
         return killbuffer(bp);          return (killbuffer(bp));
 }  }
   
 int  int
Line 125 
Line 125 
         MGWIN  *wp;          MGWIN  *wp;
   
         /*          /*
          * Find some other buffer to display. try the alternate buffer,           * Find some other buffer to display. Try the alternate buffer,
          * then the first different buffer in the buffer list.  If there's           * then the first different buffer in the buffer list.  If there's
          * only one buffer, create buffer *scratch* and make it the alternate           * only one buffer, create buffer *scratch* and make it the alternate
          * buffer.  Return if *scratch* is only buffer...           * buffer.  Return if *scratch* is only buffer...
Line 135 
Line 135 
                 if (bp1 == NULL) {                  if (bp1 == NULL) {
                         /* only one buffer. see if it's *scratch* */                          /* only one buffer. see if it's *scratch* */
                         if (bp == bfind("*scratch*", FALSE))                          if (bp == bfind("*scratch*", FALSE))
                                 return FALSE;                                  return (FALSE);
                         /* create *scratch* for alternate buffer */                          /* create *scratch* for alternate buffer */
                         if ((bp1 = bfind("*scratch*", TRUE)) == NULL)                          if ((bp1 = bfind("*scratch*", TRUE)) == NULL)
                                 return FALSE;                                  return (FALSE);
                 }                  }
         }          }
         if (bclear(bp) != TRUE)          if (bclear(bp) != TRUE)
                 return TRUE;                  return (TRUE);
         for (wp = wheadp; bp->b_nwnd > 0; wp = wp->w_wndp) {          for (wp = wheadp; bp->b_nwnd > 0; wp = wp->w_wndp) {
                 if (wp->w_bufp == bp) {                  if (wp->w_bufp == bp) {
                         bp2 = bp1->b_altb;      /* save alternate buffer */                          bp2 = bp1->b_altb;      /* save alternate buffer */
Line 175 
Line 175 
         }          }
         free((char *)bp->b_bname);              /* Release name block    */          free((char *)bp->b_bname);              /* Release name block    */
         free(bp);                               /* Release buffer block */          free(bp);                               /* Release buffer block */
         return TRUE;          return (TRUE);
 }  }
   
 /*  /*
Line 186 
Line 186 
 savebuffers(int f, int n)  savebuffers(int f, int n)
 {  {
         if (anycb(f) == ABORT)          if (anycb(f) == ABORT)
                 return ABORT;                  return (ABORT);
         return TRUE;          return (TRUE);
 }  }
   
 /*  /*
Line 198 
Line 198 
 static int      listbuf_goto_buffer(int f, int n);  static int      listbuf_goto_buffer(int f, int n);
   
 static PF listbuf_pf[] = {  static PF listbuf_pf[] = {
         listbuf_goto_buffer,          listbuf_goto_buffer
 };  };
   
 static struct KEYMAPE (1 + IMAPEXT) listbufmap = {  static struct KEYMAPE (1 + IMAPEXT) listbufmap = {
Line 206 
Line 206 
         1 + IMAPEXT,          1 + IMAPEXT,
         rescan,          rescan,
         {          {
                 { CCHR('M'), CCHR('M'), listbuf_pf, NULL },                  { CCHR('M'), CCHR('M'), listbuf_pf, NULL }
         }          }
 };  };
   
Line 221 
Line 221 
 int  int
 listbuffers(int f, int n)  listbuffers(int f, int n)
 {  {
         static int initialized = 0;          static int       initialized = 0;
         BUFFER *bp;          BUFFER          *bp;
         MGWIN  *wp;          MGWIN           *wp;
   
         if (!initialized) {          if (!initialized) {
                 maps_add((KEYMAP *)&listbufmap, "listbufmap");                  maps_add((KEYMAP *)&listbufmap, "listbufmap");
Line 231 
Line 231 
         }          }
   
         if ((bp = makelist()) == NULL || (wp = popbuf(bp)) == NULL)          if ((bp = makelist()) == NULL || (wp = popbuf(bp)) == NULL)
                 return FALSE;                  return (FALSE);
         wp->w_dotp = bp->b_dotp;/* fix up if window already on screen */          wp->w_dotp = bp->b_dotp; /* fix up if window already on screen */
         wp->w_doto = bp->b_doto;          wp->w_doto = bp->b_doto;
         bp->b_modes[0] = name_mode("fundamental");          bp->b_modes[0] = name_mode("fundamental");
         bp->b_modes[1] = name_mode("listbufmap");          bp->b_modes[1] = name_mode("listbufmap");
         bp->b_nmodes = 1;          bp->b_nmodes = 1;
   
         return TRUE;          return (TRUE);
 }  }
   
 /*  /*
  * This routine rebuilds the text for the   * This routine rebuilds the text for the
  * list buffers command. Return TRUE if   * list buffers command. Return pointer
  * everything works. Return FALSE if there   * to new list if everything works.
  * is an error (if there is no memory).   * Return NULL if there is an error (if
    * there is no memory).
  */   */
 static BUFFER *  static BUFFER *
 makelist(void)  makelist(void)
Line 256 
Line 257 
   
   
         if ((blp = bfind("*Buffer List*", TRUE)) == NULL)          if ((blp = bfind("*Buffer List*", TRUE)) == NULL)
                 return NULL;                  return (NULL);
         if (bclear(blp) != TRUE)          if (bclear(blp) != TRUE)
                 return NULL;                  return (NULL);
         blp->b_flag &= ~BFCHG;          /* Blow away old.        */          blp->b_flag &= ~BFCHG;          /* Blow away old.        */
         blp->b_flag |= BFREADONLY;          blp->b_flag |= BFREADONLY;
   
Line 266 
Line 267 
   
         if (addlinef(blp, "%-*s%s", w, " MR Buffer", "Size   File") == FALSE ||          if (addlinef(blp, "%-*s%s", w, " MR Buffer", "Size   File") == FALSE ||
             addlinef(blp, "%-*s%s", w, " -- ------", "----   ----") == FALSE)              addlinef(blp, "%-*s%s", w, " -- ------", "----   ----") == FALSE)
                 return NULL;                  return (NULL);
   
         for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {          for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
                 RSIZE nbytes;                  RSIZE nbytes;
Line 293 
Line 294 
                     nbytes,             /* buffer size */                      nbytes,             /* buffer size */
                     w - 7,              /* seven chars already written */                      w - 7,              /* seven chars already written */
                     bp->b_fname) == FALSE)                      bp->b_fname) == FALSE)
                         return NULL;                          return (NULL);
         }          }
         blp->b_dotp = lforw(blp->b_linep);      /* put dot at beginning of          blp->b_dotp = lforw(blp->b_linep);      /* put dot at beginning of
                                                  * buffer */                                                   * buffer */
         blp->b_doto = 0;          blp->b_doto = 0;
         return blp;                             /* All done              */          return (blp);                           /* All done              */
 }  }
   
 static int  static int
 listbuf_goto_buffer(int f, int n)  listbuf_goto_buffer(int f, int n)
 {  {
         BUFFER *bp;          BUFFER  *bp;
         MGWIN *wp;          MGWIN   *wp;
         char *line;          char    *line;
         int i;          int      i;
   
         if (curwp->w_dotp->l_text[listbuf_ncol/2 - 1] == '$') {          if (curwp->w_dotp->l_text[listbuf_ncol/2 - 1] == '$') {
                 ewprintf("buffer name truncated");                  ewprintf("buffer name truncated");
                 return FALSE;                  return (FALSE);
         }          }
   
         if ((line = malloc(listbuf_ncol/2)) == NULL)          if ((line = malloc(listbuf_ncol/2)) == NULL)
                 return FALSE;                  return (FALSE);
   
         memcpy(line, curwp->w_dotp->l_text + 4, listbuf_ncol/2 - 5);          memcpy(line, curwp->w_dotp->l_text + 4, listbuf_ncol/2 - 5);
         for (i = listbuf_ncol/2 - 6; i > 0; i--) {          for (i = listbuf_ncol/2 - 6; i > 0; i--) {
Line 324 
Line 325 
                         break;                          break;
                 }                  }
         }          }
         if (i == 0) {          if (i == 0)
                 return FALSE;                  return (FALSE);
         }  
   
         for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {          for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
                 if (strcmp(bp->b_bname, line) == 0)                  if (strcmp(bp->b_bname, line) == 0)
                         break;                          break;
         }          }
         if (bp == NULL) {          if (bp == NULL)
                 return FALSE;                  return (FALSE);
         }  
         if ((wp = popbuf(bp)) == NULL)          if ((wp = popbuf(bp)) == NULL)
                 return FALSE;                  return (FALSE);
         curbp = bp;          curbp = bp;
         curwp = wp;          curwp = wp;
   
         return TRUE;          return (TRUE);
 }  }
   
 /*  /*
Line 351 
Line 351 
 int  int
 addlinef(BUFFER *bp, char *fmt, ...)  addlinef(BUFFER *bp, char *fmt, ...)
 {  {
         va_list ap;          va_list  ap;
         LINE  *lp;          LINE    *lp;
   
         if ((lp = lalloc(0)) == NULL)          if ((lp = lalloc(0)) == NULL)
                 return (FALSE);                  return (FALSE);
Line 370 
Line 370 
         bp->b_linep->l_bp = lp;          bp->b_linep->l_bp = lp;
         lp->l_fp = bp->b_linep;          lp->l_fp = bp->b_linep;
   
         return TRUE;          return (TRUE);
 }  }
   
 /*  /*
Line 383 
Line 383 
 anycb(int f)  anycb(int f)
 {  {
         BUFFER *bp;          BUFFER *bp;
         int s = FALSE, save = FALSE;          int     s = FALSE, save = FALSE;
         char prompt[NFILEN + 11];          char    prompt[NFILEN + 11];
   
         for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {          for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
                 if (bp->b_fname != NULL && *(bp->b_fname) != '\0' &&                  if (bp->b_fname != NULL && *(bp->b_fname) != '\0' &&
                     (bp->b_flag & BFCHG) != 0) {                      (bp->b_flag & BFCHG) != 0) {
                         snprintf(prompt, sizeof prompt, "Save file %s",                          snprintf(prompt, sizeof(prompt), "Save file %s",
                             bp->b_fname);                              bp->b_fname);
                         if ((f == TRUE || (save = eyorn(prompt)) == TRUE) &&                          if ((f == TRUE || (save = eyorn(prompt)) == TRUE) &&
                             buffsave(bp) == TRUE) {                              buffsave(bp) == TRUE) {
Line 404 
Line 404 
         }          }
         if (save == FALSE /* && kbdmop == NULL */ )     /* experimental */          if (save == FALSE /* && kbdmop == NULL */ )     /* experimental */
                 ewprintf("(No files need saving)");                  ewprintf("(No files need saving)");
         return s;          return (s);
 }  }
   
 /*  /*
Line 424 
Line 424 
         bp = bheadp;          bp = bheadp;
         while (bp != NULL) {          while (bp != NULL) {
                 if (strcmp(bname, bp->b_bname) == 0)                  if (strcmp(bname, bp->b_bname) == 0)
                         return bp;                          return (bp);
                 bp = bp->b_bufp;                  bp = bp->b_bufp;
         }          }
         if (cflag != TRUE)          if (cflag != TRUE)
                 return NULL;                  return (NULL);
   
         bp = calloc(1, sizeof(BUFFER));          bp = calloc(1, sizeof(BUFFER));
         if (bp == NULL) {          if (bp == NULL) {
                 ewprintf("Can't get %d bytes", sizeof(BUFFER));                  ewprintf("Can't get %d bytes", sizeof(BUFFER));
                 return NULL;                  return (NULL);
         }          }
         if ((bp->b_bname = strdup(bname)) == NULL) {          if ((bp->b_bname = strdup(bname)) == NULL) {
                 ewprintf("Can't get %d bytes", strlen(bname) + 1);                  ewprintf("Can't get %d bytes", strlen(bname) + 1);
                 free(bp);                  free(bp);
                 return NULL;                  return (NULL);
         }          }
         if ((lp = lalloc(0)) == NULL) {          if ((lp = lalloc(0)) == NULL) {
                 free((char *) bp->b_bname);                  free((char *) bp->b_bname);
                 free(bp);                  free(bp);
                 return NULL;                  return (NULL);
         }          }
         bp->b_altb = bp->b_bufp = NULL;          bp->b_altb = bp->b_bufp = NULL;
         bp->b_dotp = lp;          bp->b_dotp = lp;
Line 464 
Line 464 
         lp->l_bp = lp;          lp->l_bp = lp;
         bp->b_bufp = bheadp;          bp->b_bufp = bheadp;
         bheadp = bp;          bheadp = bp;
         return bp;          return (bp);
 }  }
   
 /*  /*
Line 483 
Line 483 
         LINE  *lp;          LINE  *lp;
         int    s;          int    s;
   
         if ((bp->b_flag & BFCHG) != 0 &&        /* Changed.              */          if ((bp->b_flag & BFCHG) != 0 &&        /* Changed. */
             (s = eyesno("Buffer modified; kill anyway")) != TRUE)              (s = eyesno("Buffer modified; kill anyway")) != TRUE)
                 return (s);                  return (s);
         bp->b_flag &= ~BFCHG;   /* Not changed           */          bp->b_flag &= ~BFCHG;   /* Not changed           */
Line 493 
Line 493 
         bp->b_doto = 0;          bp->b_doto = 0;
         bp->b_markp = NULL;     /* Invalidate "mark"     */          bp->b_markp = NULL;     /* Invalidate "mark"     */
         bp->b_marko = 0;          bp->b_marko = 0;
         return TRUE;          return (TRUE);
 }  }
   
 /*  /*
Line 510 
Line 510 
                 wp->w_flag |= flags;                  wp->w_flag |= flags;
                 wp->w_dotp = bp->b_dotp;                  wp->w_dotp = bp->b_dotp;
                 wp->w_doto = bp->b_doto;                  wp->w_doto = bp->b_doto;
                 return TRUE;                  return (TRUE);
         }          }
         /* First, dettach the old buffer from the window */          /* First, detach the old buffer from the window */
         if ((bp->b_altb = obp = wp->w_bufp) != NULL) {          if ((bp->b_altb = obp = wp->w_bufp) != NULL) {
                 if (--obp->b_nwnd == 0) {                  if (--obp->b_nwnd == 0) {
                         obp->b_dotp = wp->w_dotp;                          obp->b_dotp = wp->w_dotp;
Line 540 
Line 540 
                                 break;                                  break;
                         }                          }
         wp->w_flag |= WFMODE | flags;          wp->w_flag |= WFMODE | flags;
         return TRUE;          return (TRUE);
 }  }
   
 /*  /*
Line 554 
Line 554 
   
         if (bp->b_nwnd == 0) {  /* Not on screen yet.    */          if (bp->b_nwnd == 0) {  /* Not on screen yet.    */
                 if ((wp = wpopup()) == NULL)                  if ((wp = wpopup()) == NULL)
                         return NULL;                          return (NULL);
         } else          } else
                 for (wp = wheadp; wp != NULL; wp = wp->w_wndp)                  for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
                         if (wp->w_bufp == bp) {                          if (wp->w_bufp == bp) {
                                 wp->w_flag |= WFHARD | WFFORCE;                                  wp->w_flag |= WFHARD | WFFORCE;
                                 return wp;                                  return (wp);
                         }                          }
         if (showbuffer(bp, wp, WFHARD) != TRUE)          if (showbuffer(bp, wp, WFHARD) != TRUE)
                 return NULL;                  return (NULL);
         return wp;          return (wp);
 }  }
   
 /*  /*
Line 585 
Line 585 
         else          else
                 bufp = eread("Insert buffer: ", bufn, NBUFN, EFNEW | EFBUF, NULL);                  bufp = eread("Insert buffer: ", bufn, NBUFN, EFNEW | EFBUF, NULL);
         if (bufp == NULL)          if (bufp == NULL)
                 return ABORT;                  return (ABORT);
         if (bufp[0] == '\0' && curbp->b_altb != NULL)          if (bufp[0] == '\0' && curbp->b_altb != NULL)
                 bp = curbp->b_altb;                  bp = curbp->b_altb;
         else if ((bp = bfind(bufn, FALSE)) == NULL)          else if ((bp = bfind(bufn, FALSE)) == NULL)
                 return FALSE;                  return (FALSE);
   
         if (bp == curbp) {          if (bp == curbp) {
                 ewprintf("Cannot insert buffer into self");                  ewprintf("Cannot insert buffer into self");
                 return FALSE;                  return (FALSE);
         }          }
         /* insert the buffer */          /* insert the buffer */
         nline = 0;          nline = 0;
Line 601 
Line 601 
         for (;;) {          for (;;) {
                 for (clo = 0; clo < llength(clp); clo++)                  for (clo = 0; clo < llength(clp); clo++)
                         if (linsert(1, lgetc(clp, clo)) == FALSE)                          if (linsert(1, lgetc(clp, clo)) == FALSE)
                                 return FALSE;                                  return (FALSE);
                 if ((clp = lforw(clp)) == bp->b_linep)                  if ((clp = lforw(clp)) == bp->b_linep)
                         break;                          break;
                 if (newline(FFRAND, 1) == FALSE)        /* fake newline */                  if (newline(FFRAND, 1) == FALSE)        /* fake newline */
                         return FALSE;                          return (FALSE);
                 nline++;                  nline++;
         }          }
         if (nline == 1)          if (nline == 1)
Line 613 
Line 613 
         else          else
                 ewprintf("[Inserted %d lines]", nline);                  ewprintf("[Inserted %d lines]", nline);
   
         clp = curwp->w_linep;   /* cosmetic adjustment */          clp = curwp->w_linep;           /* cosmetic adjustment  */
         if (curwp->w_dotp == clp) {     /* for offscreen insert */          if (curwp->w_dotp == clp) {     /* for offscreen insert */
                 while (nline-- && lback(clp) != curbp->b_linep)                  while (nline-- && lback(clp) != curbp->b_linep)
                         clp = lback(clp);                          clp = lback(clp);
                 curwp->w_linep = clp;   /* adjust framing.       */                  curwp->w_linep = clp;   /* adjust framing.      */
                 curwp->w_flag |= WFHARD;                  curwp->w_flag |= WFHARD;
         }          }
         return (TRUE);          return (TRUE);
Line 640 
Line 640 
                 wp = wp->w_wndp;                  wp = wp->w_wndp;
         }          }
         ewprintf("Modification-flag cleared");          ewprintf("Modification-flag cleared");
         return TRUE;          return (TRUE);
 }  }
   
 #ifndef NO_HELP  #ifndef NO_HELP
Line 663 
Line 663 
                                 wp->w_flag |= WFHARD;                                  wp->w_flag |= WFHARD;
                         }                          }
         }          }
         return popbuf(bp) != NULL;          return (popbuf(bp) != NULL);
 }  }
 #endif  #endif

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.37