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

  1. #include    "stdio.h"
  2. #include    "ed.h"
  3.  
  4. /*
  5.  * Insert a newline into the buffer
  6.  * at the current location of dot in the current
  7.  * window. The funny ass-backwards way it does things
  8.  * is not a botch; it just makes the last line in
  9.  * the file not a special case. Return TRUE if everything
  10.  * works out and FALSE on error (memory allocation
  11.  * failure). The update of dot and mark is a bit
  12.  * easier then in the above case, because the split
  13.  * forces more updating.
  14.  */
  15. lnewline()
  16. {
  17.     register WINDOW    *wp;
  18.     register LINE    *lp1;
  19. #define lp2 (*(LINE **)0x90)
  20. #define doto  (*(int *)0x92)
  21. /*    register LINE    *lp2; */
  22. /*    register int    doto; */
  23.  
  24.     lchange( WFHARD );
  25.     wp = curwp;
  26.     lp1  = wp->w_dotp;            /* Get the address and    */
  27.     doto = wp->w_doto;            /* offset of "."    */
  28.     if ( ( lp2 = lalloc( doto )) == NULL )    /* New first half line    */
  29.         return (FALSE);
  30.     blockmv( &lp2->l_text[0], &lp1->l_text[0], doto );
  31.     blockmv( &lp1->l_text[ 0 ], &lp1->l_text[ doto ],
  32.         lp1->l_used - doto );
  33.     lp1->l_used -= doto;
  34.     lp2->l_bp = lp1->l_bp;
  35.     lp1->l_bp = lp2->l_bp->l_fp = lp2;
  36.     lp2->l_fp = lp1;
  37.     wp = wheadp;                /* Windows        */
  38.     while (wp != NULL)
  39.     {    if (wp->w_linep == lp1)
  40.             wp->w_linep = lp2;
  41.         if (wp->w_dotp == lp1)
  42.         {    if (wp->w_doto < doto)
  43.                 wp->w_dotp = lp2;
  44.             else
  45.                 wp->w_doto -= doto;
  46.         }
  47.         if (wp->w_markp == lp1)
  48.         {    if (wp->w_marko < doto)
  49.                 wp->w_markp = lp2;
  50.             else
  51.                 wp->w_marko -= doto;
  52.         }
  53.         wp = wp->w_wndp;
  54.     }    
  55.     return (TRUE);
  56. }
  57.