home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / d / elvis / Docs / internal < prev    next >
Encoding:
Text File  |  1989-12-31  |  4.2 KB  |  92 lines

  1. INTERNAL TEXT REPRESENTATION
  2.     When vi starts up, the file is copied into a temporary file.  Small
  3.     amounts of extra space are inserted into the temporary file to insure
  4.     that no text lines cross block boundaries; this speeds up processing.
  5.     The "extra space" is filled with NUL charcters; the input file must
  6.     not contain any NULs, to avoid confusion.
  7.  
  8.     The first block of the temporary file is an array of shorts which
  9.     describe the order of the blocks; i.e. header[1] is the block number
  10.     of the first block, and so on.  This limits the temporary file to
  11.     512 active blocks, so the largest file you can edit is about 400K
  12.     bytes long.  I hope that's enough!
  13.  
  14.     When blocks are altered, they are rewritten to a *different* block
  15.     in the file, and the in-core version of the header block is updated
  16.     accordingly.  The in-core header block will be copied to the temp
  17.     file immediately before the next change... or, to undo this change,
  18.     swap the old header (from the temp file) with the new (in-core)
  19.     header.
  20.  
  21.     Vi maintains another in-core array which contains the line-number of
  22.     the last line in every block.  This allows you to go directly to a
  23.     line, given its line number.
  24.  
  25. IMPLEMENTATION OF EDITING
  26.     There are three basic operations which affect text:
  27.  
  28.         * delete text    - delete(from, to)
  29.         * add text    - add(at, text)
  30.         * yank text    - cut(from, to)
  31.  
  32.     To yank text, all text between two text positions is copied into
  33.     a cut buffer.  The original text is not changed.  To copy the text
  34.     into a cut buffer, you need only remember which physical blocks that
  35.     contain the cut text, the offset into the first block of the start of
  36.     the cut, the offset into the last block of the end of the cut, and
  37.     what kind of cut it was.  (Cuts may be either character cuts or line
  38.     cuts; the kind of a cut affects the way it is later "put".)
  39.  
  40.     To delete text, you must modify the first and last blocks, and remove
  41.     any reference to the intervening blocks in the header's list.  The
  42.     text to be deleted is specified by two marks.
  43.  
  44.     To add text, you must specify the text to insert (as a NUL-terminated
  45.     string) and the place to insert it (as a mark).  The block into which
  46.     the text is to be inserted may need to be split into as many as four
  47.     blocks, with new intervening blocks needed as well... or it could be
  48.     as simple as modifying the block.
  49.  
  50.     When text is deleted or added, an internal file-revision counter,
  51.     called "changes", is incremented.  This counter is used to detect
  52.     when certain caches are out of date.  (The "changes" counter is
  53.     also incremented when we switch to a different file, and also in
  54.     one or two similar situations -- all related to invalidating caches.)
  55.  
  56. MARKS AND THE CURSOR
  57.     Marks are places within the text.  They are represented internally
  58.     as a long variable which is split into two bitfields: a line number
  59.     and a character index. Line numbers start with 1, and character
  60.     indexes start with 0.
  61.  
  62.     Since line numbers start with 1, it is impossible for a set mark to
  63.     have a value of 0L.  0L is therefore used to represent unset marks.
  64.  
  65.     When you do the "delete text" change, any marks that were part of
  66.     the deleted text are unset, and any marks that were set to points
  67.     after it are adjusted.  Similarly, marks are adjusted after new text
  68.     is inserted.
  69.  
  70.     The cursor is represented as a mark.
  71.  
  72. EX COMMAND INTERPRETATION
  73.     EX commands are parsed, and the command name is looked up in an array
  74.     of structures which also contain a pointer to the function that
  75.     implements the command, and a description of the arguments that the
  76.     command can take.  If the command is recognized and its arguments
  77.     are legal, then the function is called.
  78.  
  79.     Each function performs its task; this may cause the cursor to be moved
  80.     to a different line, or whatever.
  81.  
  82. SCREEN CONTROL
  83.     The screen is updated via a package which looks like the "curses"
  84.     library, but which is actually implemented in a simpler, faster way.
  85.     Most curses operations are implemented as macros which copy characters
  86.     into a large I/O buffer, which is then written with a single large
  87.     write() call as part of the refresh() operation.
  88.  
  89.     The functions which modify text remember where text has been modified;
  90.     the screen redrawing function needs this information to help it reduce
  91.     the amount of text that is redrawn each time.
  92.