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

Diff for /src/usr.bin/mg/file.c between version 1.63 and 1.64

version 1.63, 2006/11/17 08:45:31 version 1.64, 2006/12/24 01:20:53
Line 337 
Line 337 
                 (void)strlcat(bp->b_cwd, "/", sizeof(bp->b_cwd));                  (void)strlcat(bp->b_cwd, "/", sizeof(bp->b_cwd));
         }          }
         opos = curwp->w_doto;          opos = curwp->w_doto;
   
         /* Open a new line, at point, and start inserting after it. */  
         x2 = undo_enable(FALSE);  
         oline = curwp->w_dotline;          oline = curwp->w_dotline;
           /*
            * Open a new line at dot and start inserting after it.
            * We will delete this newline after insertion.
            * Disable undo, as we create the undo record manually.
            */
           x2 = undo_enable(FALSE);
         (void)lnewline();          (void)lnewline();
         olp = lback(curwp->w_dotp);          olp = lback(curwp->w_dotp);
         if (olp == curbp->b_headp) {  
                 /* if at end of buffer, create a line to insert before */  
                 (void)lnewline();  
                 curwp->w_dotp = lback(curwp->w_dotp);  
         }  
         undo_enable(x2);          undo_enable(x2);
   
         /* don't count fake lines at the end */  
         nline = 0;          nline = 0;
         siz = 0;          siz = 0;
         while ((s = ffgetline(line, linesize, &nbytes)) != FIOERR) {          while ((s = ffgetline(line, linesize, &nbytes)) != FIOERR) {
 doneread:  retry:
                 siz += nbytes + 1;                  siz += nbytes + 1;
                 switch (s) {                  switch (s) {
                 case FIOSUC:                  case FIOSUC:
                         /* FALLTHRU */                          /* FALLTHRU */
                 case FIOEOF:                  case FIOEOF:
                         /* the last line of the file */  
                         ++nline;                          ++nline;
                         if ((lp1 = lalloc(nbytes)) == NULL) {                          if ((lp1 = lalloc(nbytes)) == NULL) {
                                 /* keep message on the display */                                  /* keep message on the display */
                                 s = FIOERR;                                  s = FIOERR;
                                   undo_add_insert(olp, opos,
                                       siz - nbytes - 1 - 1);
                                 goto endoffile;                                  goto endoffile;
                         }                          }
                         bcopy(line, &ltext(lp1)[0], nbytes);                          bcopy(line, &ltext(lp1)[0], nbytes);
Line 373 
Line 371 
                         lp1->l_fp = curwp->w_dotp;                          lp1->l_fp = curwp->w_dotp;
                         lp1->l_bp = lp2;                          lp1->l_bp = lp2;
                         curwp->w_dotp->l_bp = lp1;                          curwp->w_dotp->l_bp = lp1;
                         if (s == FIOEOF)                          if (s == FIOEOF) {
                                   undo_add_insert(olp, opos, siz - 1);
                                 goto endoffile;                                  goto endoffile;
                           }
                         break;                          break;
                 case FIOLONG: {                  case FIOLONG: {
                                 /* a line too long to fit in our buffer */                                  /* a line too long to fit in our buffer */
Line 398 
Line 398 
                                 linesize = newsize;                                  linesize = newsize;
                                 if (s == FIOERR)                                  if (s == FIOERR)
                                         goto endoffile;                                          goto endoffile;
                                 goto doneread;                                  goto retry;
                         }                          }
                 default:                  default:
                         ewprintf("Unknown code %d reading file", s);                          ewprintf("Unknown code %d reading file", s);
Line 407 
Line 407 
                 }                  }
         }          }
 endoffile:  endoffile:
         undo_add_insert(olp, opos, siz - 1);  
   
         /* ignore errors */          /* ignore errors */
         ffclose(NULL);          ffclose(NULL);
         /* don't zap an error */          /* don't zap an error */
Line 421 
Line 419 
         /* set mark at the end of the text */          /* set mark at the end of the text */
         curwp->w_dotp = curwp->w_markp = lback(curwp->w_dotp);          curwp->w_dotp = curwp->w_markp = lback(curwp->w_dotp);
         curwp->w_marko = llength(curwp->w_markp);          curwp->w_marko = llength(curwp->w_markp);
         (void)ldelnewline();          curwp->w_markline = oline + nline + 1;
           /*
            * if we are at the end of the file, ldelnewline is a no-op,
            * but we still need to decrement the line and markline counts
            * as we've accounted for this fencepost in our arithmetic
            */
           if (lforw(curwp->w_dotp) == curwp->w_bufp->b_headp) {
                   curwp->w_bufp->b_lines--;
                   curwp->w_markline--;
           } else
                   (void)ldelnewline();
         curwp->w_dotp = olp;          curwp->w_dotp = olp;
         curwp->w_doto = opos;          curwp->w_doto = opos;
         curwp->w_dotline = oline;          curwp->w_dotline = oline;

Legend:
Removed from v.1.63  
changed lines
  Added in v.1.64