home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / editor / elvis / internal.doc < prev    next >
Text File  |  1994-01-30  |  12KB  |  331 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. _8.  _I_N_T_E_R_N_A_L
  8.  
  9.      You don't need to know the material in this section  to
  10. use Elvis.  You only need it if you intend to modify Elvis.
  11.  
  12.      You should also check out the CFLAGS, TERMCAP, ENVIRON-
  13. MENT  VARIABLES, VERSIONS, and QUIESTIONS & ANSWERS sections
  14. of this manual.
  15.  
  16. _8._1.  _T_h_e _t_e_m_p_o_r_a_r_y _f_i_l_e
  17.  
  18.      The temporary file is divided into blocks of 1024 bytes
  19. each.  The functions in "blk.c" maintain a cache of the five
  20. most recently used blocks, to minimize file I/O.
  21.  
  22.      When Elvis starts up, the file is copied into the  tem-
  23. porary  file  by  the function ttttmmmmppppssssttttaaaarrrrtttt(((()))) in "tmp.c".  Small
  24. amounts of extra space are inserted into the temporary  file
  25. to  insure  that no text lines cross block boundaries.  This
  26. speeds up processing and simplifies storage management.  The
  27. extra  space  is filled with NUL characters.  the input file
  28. must not contain any NULs, to avoid  confusion.   This  also
  29. limits lines to a length of 1023 characters or less.
  30.  
  31.      The data blocks aren't necessarily stored in  sequence.
  32. For  example,  it  is  entirely possible that the data block
  33. containing the first lines of text will be stored after  the
  34. block containing the last lines of text.
  35.  
  36.      In RAM, Elvis maintains two lists: one  that  describes
  37. the  "proper"  order  of  the  disk blocks, and another that
  38. records the line number of the  last  line  in  each  block.
  39. When  Elvis  needs  to  fetch  a given line of text, it uses
  40. these tables to locate the data block  which  contains  that
  41. line.
  42.  
  43.      Before each change is made to the file, these lists are
  44. copied.  The copies can be used to "undo" the change.  Also,
  45. the first list -- the one that  lists  the  data  blocks  in
  46. their  proper order -- is written to the first data block of
  47. the temp file.  This list can be used during file recovery.
  48.  
  49.      When blocks are altered, they are rewritten to  a  _d_i_f_-
  50. _f_e_r_e_n_t  block  in  the  file,  and the order list is updated
  51. accordingly.  The original block is  left  intact,  so  that
  52. "undo"  can  be  performed  easily.   Elvis  will eventually
  53. reclaim the original block, when it is no longer needed.
  54.  
  55. _8._2.  _I_m_p_l_e_m_e_n_t_a_t_i_o_n _o_f _E_d_i_t_i_n_g
  56.  
  57.      There are three basic operations which affect text:
  58.  
  59.         +o delete text   - delete(from, to)
  60.         +o add text      - add(at, text)
  61.  
  62.  
  63.  
  64.                        June 13, 1992
  65.  
  66.  
  67.  
  68.  
  69.  
  70. 8-2                       INTERNAL                       8-2
  71.  
  72.  
  73.         +o yank text     - cut(from, to)
  74.  
  75.  
  76.      To yank text, all text between two  text  positions  is
  77. copied into a cut buffer.  The original text is not changed.
  78. To copy the text into a cut buffer, you need  only  remember
  79. which  physical blocks that contain the cut text, the offset
  80. into the first block of the start of  the  cut,  the  offset
  81. into  the last block of the end of the cut, and what kind of
  82. cut it was.  (Cuts may be  either  character  cuts  or  line
  83. cuts;  the kind of a cut affects the way it is later "put".)
  84. Yanking is implemented in the function ccccuuuutttt(((()))), and pasting is
  85. implemented  in  the  function ppppaaaasssstttteeee(((()))).  These functions are
  86. defined in "cut.c".
  87.  
  88.      To delete text, you must  modify  the  first  and  last
  89. blocks,  and  remove any reference to the intervening blocks
  90. in the header's list.  The text to be deleted  is  specified
  91. by two marks.  This is implemented in the function ddddeeeelllleeeetttteeee(((()))).
  92.  
  93.      To add text, you must specify the text to insert (as  a
  94. NUL-terminated  string)  and  the  place  to insert it (as a
  95. mark).  The block into which the text is to be inserted  may
  96. need  to  be  split  into  as  many as four blocks, with new
  97. intervening blocks needed as well...  or it could be as sim-
  98. ple as modifying a single block.  This is implemented in the
  99. function aaaadddddddd(((()))).
  100.  
  101.      There is also a cccchhhhaaaannnnggggeeee(((()))) function, which generally just
  102. calls delete() and add().  For the special case where a sin-
  103. gle character is being replaced by another single character,
  104. though,  change() will optimize things somewhat.  The add(),
  105. delete(),  and  change()  functions  are  all   defined   in
  106. "modify.c".
  107.  
  108.      The iiiinnnnppppuuuutttt(((()))) function reads text from a user and inserts
  109. it  into  the  file.   It  makes  heavy  use  of  the add(),
  110. delete(), and change() functions.  It inserts characters one
  111. at a time, as they are typed.
  112.  
  113.      When  text  is  modified,  an  internal   file-revision
  114. counter,  called  cccchhhhaaaannnnggggeeeessss,  is incremented.  This counter is
  115. used to detect when certain caches are out  of  date.   (The
  116. "changes"  counter  is  also incremented when we switch to a
  117. different file, and also in one or two similar situations --
  118. all related to invalidating caches.)
  119.  
  120. _8._3.  _M_a_r_k_s _a_n_d _t_h_e _C_u_r_s_o_r
  121.  
  122.      Marks are places within the text.  They are represented
  123. internally  as  32-bit  values which are split into two bit-
  124. fields: a line number and a character index.   Line  numbers
  125. start with 1, and character indexes start with 0.  Lines can
  126. be up to 1023 characters long, so the character index is  10
  127.  
  128.  
  129.  
  130.                        June 13, 1992
  131.  
  132.  
  133.  
  134.  
  135.  
  136. 8-3                       INTERNAL                       8-3
  137.  
  138.  
  139. bits wide and the line number fills the remaining 22 bits in
  140. the long int.
  141.  
  142.      Since line numbers start with 1, it is impossible for a
  143. valid  mark  to have a value of 0L.  0L is therefore used to
  144. represent unset marks.
  145.  
  146.      When you do the "delete text" change,  any  marks  that
  147. were  part of the deleted text are unset, and any marks that
  148. were set  to  points  after  it  are  adjusted.   Marks  are
  149. adjusted similarly after new text is inserted.
  150.  
  151.      The cursor is represented as a mark.
  152.  
  153. _8._4.  _C_o_l_o_n _C_o_m_m_a_n_d _I_n_t_e_r_p_r_e_t_a_t_i_o_n
  154.  
  155.      Colon commands are parsed,  and  the  command  name  is
  156. looked  up  in  an  array of structures which also contain a
  157. pointer to the function that implements the command,  and  a
  158. description  of the arguments that the command can take.  If
  159. the command is recognized and its arguments are legal,  then
  160. the function is called.
  161.  
  162.      Each function performs its task;  this  may  cause  the
  163. cursor to be moved to a different line, or whatever.
  164.  
  165. _8._5.  _S_c_r_e_e_n _C_o_n_t_r_o_l
  166.  
  167.      In input mode or visual command  mode,  the  screen  is
  168. redrawn  by  a  function  called rrrreeeeddddrrrraaaawwww(((()))).  This function is
  169. called in the getkey() function  before  each  keystroke  is
  170. read in, if necessary.
  171.  
  172.      Redraw() write to the screen via a package which  looks
  173. like  the  "curses" library, but isn't.  It is actually much
  174. simpler.  Most curses operations are implemented  as  macros
  175. which copy characters into a large I/O buffer, which is then
  176. written with a single large write()  call  as  part  of  the
  177. refresh() operation.
  178.  
  179.      (Note: Under MS-DOS, the pseudo-curses macros check  to
  180. see  whether you're using the pcbios interface.  If you are,
  181. then the macros call functions in "pc.c" to implement screen
  182. updates.)
  183.  
  184.      The  low-level  functions  which  modify  text  (namely
  185. add(), delete(), and change()) supply redraw() with clues to
  186. help redraw() decide which  parts  of  the  screen  must  be
  187. redrawn.    The  clues  are  given  via  a  function  called
  188. rrrreeeeddddrrrraaaawwwwrrrraaaannnnggggeeee(((()))).
  189.  
  190.      Most EX commands use the pseudo-curses package to  per-
  191. form their output, like redraw().
  192.  
  193.  
  194.  
  195.  
  196.                        June 13, 1992
  197.  
  198.  
  199.  
  200.  
  201.  
  202. 8-4                       INTERNAL                       8-4
  203.  
  204.  
  205.      There is also a function called mmmmssssgggg(((())))  which  uses  the
  206. same  syntax  as printf().  In EX mode, msg() writes message
  207. to the screen and automatically adds a newline.  In VI mode,
  208. msg()  writes  the  message on the bottom line of the screen
  209. with the "standout" character attribute turned on.
  210.  
  211. _8._6.  _O_p_t_i_o_n_s
  212.  
  213.      For each option available through the  ":set"  command,
  214. Elvis contains a character array variable, named "o__o_p_t_i_o_n".
  215. For example, the  "lines"  option  uses  a  variable  called
  216. "o_lines".
  217.  
  218.      For boolean options, the array has a  dimension  of  1.
  219. The  first  (and only) character of the array will be NUL if
  220. the variable's value is FALSE, and some other value if it is
  221. TRUE.   To  check  the  value, just by dereference the array
  222. name, as in "if (*o_autoindent)".
  223.  
  224.      For number options, the array has  a  dimension  of  3.
  225. The  array  is  treated as three unsigned one-byte integers.
  226. The first byte is the current  value  of  the  option.   The
  227. second  and  third  bytes  are the lower and upper bounds of
  228. that option.
  229.  
  230.      For string options, the array usually has  a  dimension
  231. of about 60 but this may vary.  The option's value is stored
  232. as a normal NUL-terminated string.
  233.  
  234.      All of the options are declared in "opts.c".  Most  are
  235. initialized to their default values; the iiiinnnniiiittttooooppppttttssss(((()))) function
  236. is used to perform any environment-specific initialization.
  237.  
  238. _8._7.  _P_o_r_t_a_b_i_l_i_t_y
  239.  
  240.      To improve portability, Elvis collects as many  of  the
  241. system-dependent definitions as possible into the "config.h"
  242. file.  This file begins with some preprocessor  instructions
  243. which attempt to determine which compiler and operating sys-
  244. tem you have.  After that,  it  conditionally  defines  some
  245. macros and constants for your system.
  246.  
  247.      One of the more significant macros is ttttttttyyyyrrrreeeeaaaadddd(((()))).   This
  248. macro is used to read raw characters from the keyboard, pos-
  249. sibly with timeout.  For UNIX systems, this basically  reads
  250. bytes  from  stdin.  For MSDOS, TOS, and OS9, ttyread() is a
  251. function defined in curses.c.  There is  also  a  ttttttttyyyywwwwrrrriiiitttteeee(((())))
  252. macro.
  253.  
  254.      The ttttrrrreeeeaaaadddd(((()))) and ttttwwwwrrrriiiitttteeee(((()))) macros are versions of  read()
  255. and  write() that are used for text files.  On UNIX systems,
  256. these are equivelent to  read()  and  write().   On  MS-DOS,
  257. these  are  also equivelent to read() and write(), since DOS
  258. libraries are generally clever  enough  to  convert  newline
  259.  
  260.  
  261.  
  262.                        June 13, 1992
  263.  
  264.  
  265.  
  266.  
  267.  
  268. 8-5                       INTERNAL                       8-5
  269.  
  270.  
  271. characters  automatically.   For  Atari TOS, though, the MWC
  272. library is too stupid to do  this,  so  we  had  to  do  the
  273. conversion explicitly.
  274.  
  275.      Other macros may substitute index()  for  strchr(),  or
  276. bcopy()  for memcpy(), or map the "void" data type to "int",
  277. or whatever.
  278.  
  279.      The file "tinytcap.c" contains a set of functions  that
  280. emulate  the  termcap  library  for  a small set of terminal
  281. types.  The terminal-specific info is hard-coded  into  this
  282. file.   It  is only used for systems that don't support real
  283. termcap.  Another alternative for screen control can be seen
  284. in  the  "curses.h"  and  "pc.c"  files.  Here, macros named
  285. VOIDBIOS and CHECKBIOS are used to indirectly call functions
  286. which perform low-level screen manipulation via BIOS calls.
  287.  
  288.      The stat() function must be able to come up with  UNIX-
  289. style  major/minor/inode  numbers  that  uniquely identify a
  290. file or directory.
  291.  
  292.      Please try to keep you changes localized, and wrap them
  293. in  #if/#endif pairs, so that Elvis can still be compiled on
  294. other systems.  And PLEASE let me know about it,  so  I  can
  295. incorporate your changes into my latest-and-greatest version
  296. of Elvis.
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.                        June 13, 1992
  329.  
  330.  
  331.