[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.7 and 1.8

version 1.7, 2001/05/23 22:36:14 version 1.8, 2001/05/24 03:05:23
Line 2 
Line 2 
   
 /*  /*
  *              Text line handling.   *              Text line handling.
  *   *
  * The functions in this file are a general set of line management   * The functions in this file are a general set of line management
  * utilities. They are the only routines that touch the text. They   * utilities. They are the only routines that touch the text. They
  * also touch the buffer and window structures to make sure that the   * also touch the buffer and window structures to make sure that the
  * necessary updating gets done.  There are routines in this file that   * necessary updating gets done.  There are routines in this file that
  * handle the kill buffer too.  It isn't here for any good reason.   * handle the kill buffer too.  It isn't here for any good reason.
  *   *
  * Note that this code only updates the dot and mark values in the window   * Note that this code only updates the dot and mark values in the window
  * list.  Since all the code acts on the current window, the buffer that   * list.  Since all the code acts on the current window, the buffer that
  * we are editing must be displayed, which means that "b_nwnd" is non-zero,   * we are editing must be displayed, which means that "b_nwnd" is non-zero,
  * which means that the dot and mark values in the buffer headers are   * which means that the dot and mark values in the buffer headers are
  * nonsense.   * nonsense.
  */   */
   
 #include "def.h"  #include "def.h"
   
 /*  /*
  * The number of bytes member from the start of the structure type should be   * The number of bytes member from the start of the structure type should be
  * computed at compile time.   * computed at compile time.
  */   */
   
Line 46 
Line 46 
  * This routine allocates a block of memory large enough to hold a LINE   * This routine allocates a block of memory large enough to hold a LINE
  * containing "used" characters. The block is rounded up to whatever   * containing "used" characters. The block is rounded up to whatever
  * needs to be allocated. (use lallocx for lines likely to grow.)   * needs to be allocated. (use lallocx for lines likely to grow.)
  * Return a pointer to the new block, or NULL if there isn't any memory   * Return a pointer to the new block, or NULL if there isn't any memory
  * left. Print a message in the message line if no space.   * left. Print a message in the message line if no space.
  */   */
 LINE *  LINE *
Line 91 
Line 91 
   
 /*  /*
  * Delete line "lp".  Fix all of the links that might point to it (they are   * Delete line "lp".  Fix all of the links that might point to it (they are
  * moved to offset 0 of the next line.  Unlink the line from whatever buffer   * moved to offset 0 of the next line.  Unlink the line from whatever buffer
  * it might be in, and release the memory.  The buffers are updated too; the   * it might be in, and release the memory.  The buffers are updated too; the
  * magic conditions described in the above comments don't hold here.   * magic conditions described in the above comments don't hold here.
  */   */
 void  void
Line 132 
Line 132 
 }  }
   
 /*  /*
  * This routine is called when a character changes in place in the current   * This routine is called when a character changes in place in the current
  * buffer. It updates all of the required flags in the buffer and window   * buffer. It updates all of the required flags in the buffer and window
  * system. The flag used is passed as an argument; if the buffer is being   * system. The flag used is passed as an argument; if the buffer is being
  * displayed in more than 1 window we change EDIT to HARD. Set MODE if the   * displayed in more than 1 window we change EDIT to HARD. Set MODE if the
  * mode line needs to be updated (the "*" has to be set).   * mode line needs to be updated (the "*" has to be set).
  */   */
 void  void
Line 159 
Line 159 
 }  }
   
 /*  /*
  * Insert "n" copies of the character "c" at the current location of dot.   * Insert "n" copies of the character "c" at the current location of dot.
  * In the easy case all that happens is the text is stored in the line.   * In the easy case all that happens is the text is stored in the line.
  * In the hard case, the line has to be reallocated.  When the window list   * In the hard case, the line has to be reallocated.  When the window list
  * is updated, take special care; I screwed it up once.  You always update   * is updated, take special care; I screwed it up once.  You always update
  * dot in the current window.  You update mark and a dot in another window   * dot in the current window.  You update mark and a dot in another window
  * if it is greater than the place where you did the insert. Return TRUE   * if it is greater than the place where you did the insert. Return TRUE
  * if all is well, and FALSE on errors.   * if all is well, and FALSE on errors.
Line 269 
Line 269 
 }  }
   
 /*  /*
  * Insert a newline into the buffer at the current location of dot in the   * Insert a newline into the buffer at the current location of dot in the
  * current window.  The funny ass-backwards way is no longer used.   * current window.  The funny ass-backwards way is no longer used.
  */   */
 int  int
Line 328 
Line 328 
 }  }
   
 /*  /*
  * This function deletes "n" bytes, starting at dot. It understands how to   * This function deletes "n" bytes, starting at dot. It understands how to
  * deal with end of lines, etc.  It returns TRUE if all of the characters   * deal with end of lines, etc.  It returns TRUE if all of the characters
  * were deleted, and FALSE if they were not (because dot ran into the end   * were deleted, and FALSE if they were not (because dot ran into the end
  * of the buffer.  The "kflag" indicates either no insertion, or direction   * of the buffer.  The "kflag" indicates either no insertion, or direction
  * of insertion into the kill buffer.   * of insertion into the kill buffer.
  */   */
 int  int
Line 368 
Line 368 
                                 /* End of buffer */                                  /* End of buffer */
                                 return FALSE;                                  return FALSE;
                         lchange(WFHARD);                          lchange(WFHARD);
                         if (ldelnewline() == FALSE ||                          if (ldelnewline() == FALSE ||
                             (kflag != KNONE && kinsert('\n', kflag) == FALSE))                              (kflag != KNONE && kinsert('\n', kflag) == FALSE))
                                 return FALSE;                                  return FALSE;
                         --n;                          --n;
Line 415 
Line 415 
 }  }
   
 /*  /*
  * Delete a newline and join the current line with the next line. If the next   * Delete a newline and join the current line with the next line. If the next
  * line is the magic header line always return TRUE; merging the last line   * line is the magic header line always return TRUE; merging the last line
  * with the header line can be thought of as always being a successful   * with the header line can be thought of as always being a successful
  * operation.  Even if nothing is done, this makes the kill buffer work   * operation.  Even if nothing is done, this makes the kill buffer work
  * "right".  Easy cases can be done by shuffling data around.  Hard cases   * "right".  Easy cases can be done by shuffling data around.  Hard cases
  * require that lines be moved about in memory.  Return FALSE on error and   * require that lines be moved about in memory.  Return FALSE on error and
  * TRUE if all looks ok.   * TRUE if all looks ok.
  */   */
 int  int
Line 484 
Line 484 
 }  }
   
 /*  /*
  * Replace plen characters before dot with argument string.  Control-J   * Replace plen characters before dot with argument string.  Control-J
  * characters in st are interpreted as newlines.  There is a casehack   * characters in st are interpreted as newlines.  There is a casehack
  * disable flag (normally it likes to match case of replacement to what   * disable flag (normally it likes to match case of replacement to what
  * was there).   * was there).
  */   */
 int  int
 lreplace(plen, st, f)  lreplace(plen, st, f)
         RSIZE  plen;    /* length to remove              */          RSIZE   plen;   /* length to remove              */
         char  *st;      /* replacement string            */          char    *st;    /* replacement string            */
         int    f;       /* case hack disable             */          int     f;      /* case hack disable             */
 {  {
         RSIZE   rlen;   /* replacement length            */          RSIZE   rlen;   /* replacement length            */
         int     rtype;  /* capitalization                */          int     rtype;  /* capitalization                */
Line 501 
Line 501 
         int     doto;   /* offset into line              */          int     doto;   /* offset into line              */
   
         /*          /*
          * Find the capitalization of the word that was found.  f says use           * Find the capitalization of the word that was found.  f says use
          * exact case of replacement string (same thing that happens with           * exact case of replacement string (same thing that happens with
          * lowercase found), so bypass check.           * lowercase found), so bypass check.
          */           */
         /* NOSTRICT */          /* NOSTRICT */
Line 563 
Line 563 
 }  }
   
 /*  /*
  * Delete all of the text saved in the kill buffer.  Called by commands when   * Delete all of the text saved in the kill buffer.  Called by commands when
  * a new kill context is created. The kill buffer array is released, just in   * a new kill context is created. The kill buffer array is released, just in
  * case the buffer has grown to an immense size.  No errors.   * case the buffer has grown to an immense size.  No errors.
  */   */
 void  void
Line 578 
Line 578 
 }  }
   
 /*  /*
  * Insert a character to the kill buffer, enlarging the buffer if there   * Insert a character to the kill buffer, enlarging the buffer if there
  * isn't any room. Always grow the buffer in chunks, on the assumption   * isn't any room. Always grow the buffer in chunks, on the assumption
  * that if you put something in the kill buffer you are going to put more   * that if you put something in the kill buffer you are going to put more
  * stuff there too later. Return TRUE if all is well, and FALSE on errors.   * stuff there too later. Return TRUE if all is well, and FALSE on errors.
  * Print a message on errors.  Dir says whether to put it at back or front.   * Print a message on errors.  Dir says whether to put it at back or front.
  */   */
 int  int
Line 633 
Line 633 
 }  }
   
 /*  /*
  * This function gets characters from the kill buffer. If the character   * This function gets characters from the kill buffer. If the character
  * index "n" is off the end, it returns "-1". This lets the caller just   * index "n" is off the end, it returns "-1". This lets the caller just
  * scan along until it gets a "-1" back.   * scan along until it gets a "-1" back.
  */   */
 int  int

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8