home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / emacs / src / ldelete.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-07  |  1.8 KB  |  71 lines

  1. #include    "stdio.h"
  2. #include    "ed.h"
  3.  
  4. /*
  5.  * This function deletes "n" bytes,
  6.  * starting at dot. It understands how do deal
  7.  * with end of lines, etc. It returns TRUE if all
  8.  * of the characters were deleted, and FALSE if
  9.  * they were not (because dot ran into the end of
  10.  * the buffer. The "kflag" is TRUE if the text
  11.  * should be put in the kill buffer.
  12.  */
  13. ldelete(n, kflag)
  14. {
  15.     register WINDOW    *wp;
  16. #define dotp (*(LINE **)0x90)
  17.     register char    *cp1;
  18. #define cp3 (*(char **)0x9a)
  19. #define cp2 (*(char**)0x92)
  20. #define doto (*(int *)0x94)
  21. #define chunk (*(int *)0x96)
  22. #define left (*(int *)0x98)
  23. #define localn (*(int *)0xa2)
  24.  
  25.     localn = n;
  26.     while ( localn > 0 )
  27.     {    if ( curbp->b_linep == ( dotp = curwp->w_dotp ) )
  28.             return ( 0 );    /* Hit end of buffer.    */
  29.         doto = curwp->w_doto;
  30.  
  31.         if ( localn < ( chunk = left = dotp->l_used - doto ) )
  32.             chunk = localn;
  33.         if ( chunk == 0 )    /* End of line, merge. */
  34.         {    lchange(WFHARD);
  35.             if ( ldelnewline() == FALSE
  36.             || ( kflag != FALSE && kinsert('\n') == FALSE ))
  37.                 return (FALSE);
  38.             --localn;
  39.             continue;
  40.         }
  41.         lchange(WFEDIT);
  42.         cp2 = ( cp3 = cp1 = &dotp->l_text[doto] ) + chunk;
  43.  
  44.         if (kflag != FALSE)    /* Kill? */
  45.         {    while ( cp1 != cp2 )
  46.             {    if (kinsert( *cp1++ ) == FALSE)
  47.                     return (FALSE);
  48.             }
  49.         }
  50.          blockmv( cp3, cp2, left - chunk );
  51.  
  52.         dotp->l_used -= chunk;
  53.         wp = wheadp;    /* Fix windows    */
  54.         while (wp != NULL)
  55.         {    if ( wp->w_dotp == dotp && wp->w_doto >= doto )
  56.             {    wp->w_doto -= chunk;
  57.                 if (wp->w_doto < doto)
  58.                     wp->w_doto = doto;
  59.             }    
  60.             if ( wp->w_markp == dotp && wp->w_marko >= doto )
  61.             {    wp->w_marko -= chunk;
  62.                 if (wp->w_marko < doto)
  63.                     wp->w_marko = doto;
  64.             }
  65.             wp = wp->w_wndp;
  66.         }
  67.         localn -= chunk;
  68.     }
  69.     return (TRUE);
  70. }
  71.