home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / cpm / emacs / emacssrc.lzh / line.c < prev    next >
C/C++ Source or Header  |  1992-03-11  |  2KB  |  80 lines

  1. /*
  2.  * The functions in this file
  3.  * are a general set of line management
  4.  * utilities. They are the only routines that
  5.  * touch the text. They also touch the buffer
  6.  * and window structures, to make sure that the
  7.  * necessary updating gets done. There are routines
  8.  * in this file that handle the kill buffer too.
  9.  * It isn't here for any good reason.
  10.  *
  11.  * Note that this code only updates the dot and
  12.  * mark values in the window list. Since all the code
  13.  * acts on the current window, the buffer that we
  14.  * are editing must be being displayed, which means
  15.  * that "b_nwnd" is non zero, which means that the
  16.  * dot and mark values in the buffer headers are
  17.  * nonsense.
  18.  */
  19. #include    "stdio.h"
  20. #include    "ed.h"
  21.  
  22. #define    NBLOCK    4            /* Line block chunk size    */
  23. /* changed from 16 to 8 in an attempt to save space. */
  24.  
  25. /*
  26.  * This routine allocates a block
  27.  * of memory large enough to hold a LINE
  28.  * containing "used" characters. The block is
  29.  * always rounded up a bit. Return a pointer
  30.  * to the new block, or NULL if there isn't
  31.  * any memory left. Print a message in the
  32.  * message line if no space.
  33.  */
  34. LINE    *
  35. lalloc(used)
  36. int    used;
  37. {
  38.     register LINE    *lp;
  39.     register int    size;
  40.  
  41.     size = (used+NBLOCK-1) & ~(NBLOCK-1);
  42.     if (size == 0)                /* Assume that an empty    */
  43.         size = NBLOCK;            /* line is for type-in.    */
  44.     if ((lp = (LINE *) malloc(sizeof(LINE)+size)) == NULL) {
  45.         mlwrite("No Memory");
  46.         return (NULL);
  47.     }
  48.     lp->l_size = size;
  49.     lp->l_used = used;
  50.     return (lp);
  51. }
  52.  
  53. /*
  54.  * This routine gets called when
  55.  * a character is changed in place in the
  56.  * current buffer. It updates all of the required
  57.  * flags in the buffer and window system. The flag
  58.  * used is passed as an argument; if the buffer is being
  59.  * displayed in more than 1 window we change EDIT to
  60.  * HARD. Set MODE if the mode line needs to be
  61.  * updated (the "*" has to be set).
  62.  */
  63. lchange(flag)
  64. {
  65.     register WINDOW    *wp;
  66.  
  67.     if (curbp->b_nwnd != 1)            /* Ensure hard.        */
  68.         flag = WFHARD;
  69.     if ((curbp->b_flag&BFCHG) == 0) {    /* First change, so     */
  70.         flag |= WFMODE;            /* update mode lines.    */
  71.         curbp->b_flag |= BFCHG;
  72.     }
  73.     wp = wheadp;
  74.     while (wp != NULL) {
  75.         if (wp->w_bufp == curbp)
  76.             wp->w_flag |= flag;
  77.         wp = wp->w_wndp;
  78.     }
  79. }
  80.