home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CMDSRC.ZIP / BUFFERS.INC < prev    next >
Text File  |  1990-04-29  |  5KB  |  157 lines

  1. ; BUFFERS.INC
  2. ; (c) 1989, 1990 Ashok P. Nadkarni
  3. ;
  4. ; Various definitions for string buffer structures in CMDEDIT.
  5. ;
  6.  
  7. WANT_MARKERS    equ    0        ;1 if the marker routines are wanted
  8. ;                     0 otherwise. Note Markers have not
  9. ;                     been tested and are not used in
  10. ;                     CMDEDIT. Keep this defined as 0.
  11.  
  12. ; $STRING_STACK is a descriptor for a buffer that is maintained as a stack of
  13. ; strings. Each string has a one byte header and a one byte trailer that
  14. ; contain the length of the string. These are used to traverse up and down
  15. ; the stack allowing access to elements inside the stack. The stack grows
  16. ; upwards in memory. The string header appears at the lower address followed
  17. ; by the string itself and then the trailer.
  18. ;
  19. ; The string can be of length between 0 and 255 bytes
  20. ;
  21. ; There is a NULL string always present at the bottom of the stack. This
  22. ; consists of a 0 byte at location low followed by another 0 byte (these
  23. ; bytes are the header and trailer respectively and denote a 0 length
  24. ; string. When the stack is empty, a zero length string is returned by
  25. ; operations like popping the stack. Stack empty is true IFF 
  26. ;    top = cur = low+1
  27. ;    
  28. ; MARKERS :
  29. ; The user can also set markers to point at the various elements in the
  30. ; stack. These markers are accessed strictly as a stack through various
  31. ; routines. When a string associated with a marker is deleted, the marker
  32. ; is set to point to the string above the deleted string except when the
  33. ; string was the topmost string in which case the marker will point to
  34. ; the new top of stack (which may even be the sentinel). Thus the markers
  35. ; will "percolate" upwards through the stack as strings are deleted until
  36. ; they reach the top. Note that if a marker points to the top of the stack,
  37. ; and a new string is pushed onto the stack, the marker still points to the
  38. ; old top of stack. When the stack is empty, any existing markers will point
  39. ; to the sentinel null string and then keep pointing there even if strings
  40. ; are added. (The strstk_purge_marks function will delete these markers).
  41. ; The marker stack is itself stored at the top of the buffer and grows 
  42. ; downwards.
  43. ;
  44. ; Each element of the descriptor structure is as follows :
  45. ;    low -  Contains the lowest address of the buffer.
  46. ;    high - Contains the highest address of the buffer. 
  47. ;    top - Points to the trailer of the topmost string.
  48. ;        Note that this is the highest occupied location of in
  49. ;        the buffer. 
  50. ;    cur - cur is a pointer to the "current" string within the stack.
  51. ;        Most requested operations are done with respect to the
  52. ;        "current" string.
  53. ;    savecur - used to temporarily hold a previous value of cur while
  54. ;          cur is moved around.
  55. ;    topmark - location where the last marker is stored.
  56. ;          = high+1 if no markers.
  57. ;
  58. ;
  59. ; For example the following diagram shows these various relationships
  60. ; and structures.
  61. ;
  62. ; Assuming the buffer contains two strings and a single mark pointing
  63. ; to the first string,
  64. ;
  65. ;    Descriptor            Buffer (range 100h - 10F)
  66. ;                    +---------------+
  67. ;    low    = 100h        10F    |     01h    |
  68. ;                    +---------------+
  69. ;    high    = 10Fh        10E    |     05h    |
  70. ;                    +---------------+
  71. ;    top    = 10Ah        10D    |        -    |
  72. ;                    +---------------+
  73. ;    topmark = 10Eh        10C    |    -    |
  74. ;                    +---------------+
  75. ;                10B    |    -    |
  76. ;                    +---------------+
  77. ;                10A    |  Len(B)=3    |
  78. ;                    +---------------+
  79. ;                109    |    b3    |
  80. ;                    +---------------+
  81. ;                108    |    b2    |
  82. ;                    +---------------+
  83. ;                107    |    b1    |
  84. ;                    +---------------+
  85. ;                106    |  Len(B)=3    |
  86. ;                    +---------------+
  87. ;                105    |  Len(A)=2    |
  88. ;                    +---------------+
  89. ;                104    |    a2    |
  90. ;                    +---------------+
  91. ;                103    |      a1    |
  92. ;                    +---------------+
  93. ;                102    |  Len(A)=2    |
  94. ;                    +---------------+
  95. ;                101    |    0    |
  96. ;                    +---------------+
  97. ;                100    |       0    |
  98. ;                    +---------------+
  99. ;
  100. ; The functions defined for these buffers make specific assumptions about
  101. ; how these are manipulated so the user code should NOT write to them directly.
  102.  
  103. $string_stack    STRUC
  104. top        dw    ?
  105. cur        dw    ?
  106. savecur        dw    ?
  107. low_end        dw    ?
  108. high_end    dw    ?
  109. topmark        dw    ?        ;This field must be present
  110. ;                      even if WANT_MARKERS is 0
  111. $string_stack    ENDS
  112.  
  113.  
  114.     IFDEF    STRSTACK_ASM
  115.  
  116.     PUBLIC    strstk_init
  117.     PUBLIC    strstk_reset
  118.     PUBLIC    strstk_push
  119.     PUBLIC    strstk_makespace
  120.     PUBLIC    strstk_space
  121.     PUBLIC    strstk_fwd_match
  122.     PUBLIC    strstk_bck_match
  123.     PUBLIC    strstk_fwd_find
  124.     PUBLIC    strstk_bck_find
  125.     PUBLIC    strstk_settop
  126.     PUBLIC    strstk_setbot
  127.     PUBLIC    strstk_kill
  128.     PUBLIC    strstk_copy
  129.     PUBLIC    strstk_compare
  130.     PUBLIC    strstk_prefix
  131.     PUBLIC    strstk_save_cur
  132.     PUBLIC    strstk_restore_cur
  133.     ELSE
  134.  
  135. CSEG    SEGMENT    PARA PUBLIC 'CODE'
  136.     EXTRN    strstk_init:PROC
  137.     EXTRN    strstk_reset:PROC
  138.     EXTRN    strstk_push:PROC
  139.     EXTRN    strstk_makespace:PROC
  140.     EXTRN    strstk_space:PROC
  141.     EXTRN    strstk_fwd_match:PROC
  142.     EXTRN    strstk_bck_match:PROC
  143.     EXTRN    strstk_fwd_find:PROC
  144.     EXTRN    strstk_bck_find:PROC
  145.     EXTRN    strstk_settop:PROC
  146.     EXTRN    strstk_setbot:PROC
  147.     EXTRN    strstk_kill:PROC
  148.     EXTRN    strstk_copy:PROC
  149.     EXTRN    strstk_compare:PROC
  150.     EXTRN    strstk_prefix:PROC
  151.     EXTRN    strstk_save_cur:PROC
  152.     EXTRN    strstk_restore_cur:PROC
  153. CSEG    ENDS
  154.  
  155.     ENDIF
  156.