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

Diff for /src/usr.bin/mg/line.c between version 1.23 and 1.24

version 1.23, 2005/06/14 18:14:40 version 1.24, 2005/10/06 16:48:00
Line 336 
Line 336 
         LINE    *lp2;          LINE    *lp2;
         int      nlen;          int      nlen;
         MGWIN   *wp;          MGWIN   *wp;
           int      retval = TRUE;
   
         lchange(WFHARD);          lchange(WFHARD);
   
         undo_add_boundary();  
         undo_add_insert(lp1, llength(lp1), 1);  
         undo_add_boundary();  
   
         /* avoid unnecessary copying */          /* avoid unnecessary copying */
         if (doto == 0) {          if (doto == 0) {
                 /* new first part */                  /* new first part */
                 if ((lp2 = lalloc(0)) == NULL)                  if ((lp2 = lalloc(0)) == NULL) {
                         return (FALSE);                          retval = FALSE;
                           goto lnl_done;
                   }
                 lp2->l_bp = lp1->l_bp;                  lp2->l_bp = lp1->l_bp;
                 lp1->l_bp->l_fp = lp2;                  lp1->l_bp->l_fp = lp2;
                 lp2->l_fp = lp1;                  lp2->l_fp = lp1;
Line 355 
Line 354 
                 for (wp = wheadp; wp != NULL; wp = wp->w_wndp)                  for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
                         if (wp->w_linep == lp1)                          if (wp->w_linep == lp1)
                                 wp->w_linep = lp2;                                  wp->w_linep = lp2;
                 return (TRUE);                  goto lnl_done;
         }          }
   
         /* length of new part */          /* length of new part */
         nlen = llength(lp1) - doto;          nlen = llength(lp1) - doto;
   
         /* new second half line */          /* new second half line */
         if ((lp2 = lalloc(nlen)) == NULL)          if ((lp2 = lalloc(nlen)) == NULL) {
                 return (FALSE);                  retval = FALSE;
                   goto lnl_done;
           }
         if (nlen != 0)          if (nlen != 0)
                 bcopy(&lp1->l_text[doto], &lp2->l_text[0], nlen);                  bcopy(&lp1->l_text[doto], &lp2->l_text[0], nlen);
         lp1->l_used = doto;          lp1->l_used = doto;
Line 382 
Line 383 
                         wp->w_marko -= doto;                          wp->w_marko -= doto;
                 }                  }
         }          }
         return (TRUE);  lnl_done:
           undo_add_boundary();
           undo_add_insert(lp1, llength(lp1), 1);
           undo_add_boundary();
           return (retval);
 }  }
   
 /*  /*
Line 576 
Line 581 
 lreplace(RSIZE plen, char *st, int f)  lreplace(RSIZE plen, char *st, int f)
 {  {
         RSIZE   rlen;   /* replacement length            */          RSIZE   rlen;   /* replacement length            */
         int     rtype;  /* capitalization                */  
         int     c;      /* used for random characters    */  
         int     doto;   /* offset into line              */  
   
         if (curbp->b_flag & BFREADONLY) {          if (curbp->b_flag & BFREADONLY) {
                 ewprintf("Buffer is read only");                  ewprintf("Buffer is read only");
                 return (FALSE);                  return (FALSE);
         }          }
           undo_add_boundary();
         undo_add_change(curwp->w_dotp, curwp->w_doto, plen);          undo_no_boundary(TRUE);
   
         /*  
          * Find the capitalization of the word that was found.  f says use  
          * exact case of replacement string (same thing that happens with  
          * lowercase found), so bypass check.  
          */  
         /* NOSTRICT */  
         (void)backchar(FFARG | FFRAND, (int)plen);          (void)backchar(FFARG | FFRAND, (int)plen);
         rtype = _MG_L;          (void)ldelete(plen, KNONE);
         c = lgetc(curwp->w_dotp, curwp->w_doto);  
         if (ISUPPER(c) != FALSE && f == FALSE) {  
                 rtype = _MG_U | _MG_L;  
                 if (curwp->w_doto + 1 < llength(curwp->w_dotp)) {  
                         c = lgetc(curwp->w_dotp, curwp->w_doto + 1);  
                         if (ISUPPER(c) != FALSE) {  
                                 rtype = _MG_U;  
                         }  
                 }  
         }  
   
         /*  
          * make the string lengths match (either pad the line  
          * so that it will fit, or scrunch out the excess).  
          * be careful with dot's offset.  
          */  
         rlen = strlen(st);          rlen = strlen(st);
         doto = curwp->w_doto;          region_put_data(st, rlen);
         if (plen > rlen)  
                 (void)ldelete((RSIZE) (plen - rlen), KNONE);  
         else if (plen < rlen) {  
                 if (linsert((int)(rlen - plen), ' ') == FALSE)  
                         return (FALSE);  
         }  
         curwp->w_doto = doto;  
   
         /*  
          * do the replacement:  If was capital, then place first  
          * char as if upper, and subsequent chars as if lower.  
          * If inserting upper, check replacement for case.  
          */  
         while ((c = CHARMASK(*st++)) != '\0') {  
                 if ((rtype & _MG_U) != 0 && ISLOWER(c) != 0)  
                         c = TOUPPER(c);  
                 if (rtype == (_MG_U | _MG_L))  
                         rtype = _MG_L;  
                 if (c == CCHR('J')) {  
                         if (curwp->w_doto == llength(curwp->w_dotp))  
                                 (void)forwchar(FFRAND, 1);  
                         else {  
                                 if (ldelete((RSIZE) 1, KNONE) != FALSE)  
                                         (void)lnewline();  
                         }  
                 } else if (curwp->w_dotp == curbp->b_linep) {  
                         (void)linsert(1, c);  
                 } else if (curwp->w_doto == llength(curwp->w_dotp)) {  
                         if (ldelete((RSIZE) 1, KNONE) != FALSE)  
                                 (void)linsert(1, c);  
                 } else  
                         lputc(curwp->w_dotp, curwp->w_doto++, c);  
         }  
         lchange(WFHARD);          lchange(WFHARD);
   
           undo_no_boundary(FALSE);
           undo_add_boundary();
         return (TRUE);          return (TRUE);
 }  }
   

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24