home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / CPM3 / CCP105P.ARK / HISTORY.DOC < prev    next >
Text File  |  1986-10-17  |  7KB  |  195 lines

  1. ;
  2. ;   >>>>>>--  COMMAND LINE HISTORY PROCESSING FOR CP/M PLUS --<<<<<<
  3. ;
  4. ;    (C) Copyright 1986 by Michael D. Kersenbrock, 18625 S.W. Hennig
  5. ;    Court, Aloha, Oregon 97006  All rights Reserved.
  6. ;
  7. ;       Personal non-commercial use and distribution of this software
  8. ;    is permitted so long as the above Copyright notice is maintained
  9. ;    with this and subsequent copies.
  10. ;
  11. ;    History (no pun intended, but noted):
  12. ;
  13. ;        Version 1.0 - September 1986  Original release
  14. ;
  15. ;
  16. ;  This was written first in psuedo HLL code, then hand coded into assembly
  17. ;  language.  That psuedo-HLL code is included below as comment lines.
  18. ;
  19. ;Note: No matter how efficiently written, this isn't really practical without
  20. ;      a ramdisk or a fast hard disk.  No strong effort is done to minimize
  21. ;      the file size (and thus disk speed) because it isn't likely to 
  22. ;      acceptably fast with a floppy (regardless). I use a FAST 720K ramdisk.
  23. ;      Actually, I have tried it with my floppy, and it isn't too bad at all
  24. ;      but then, the floppy IS cache'd.  I did my own cacheing over and above
  25. ;      CP/M 3.0's (didn't like theirs), so I don't know how it works with
  26. ;      DRI's version of cache. I have 178K of floppy-file cacheing.
  27. ;
  28. ;      This history implements "!!", "!pattern", "!number" for command
  29. ;      substitution, and implements the command 'h' to give a list of 
  30. ;      previous commands and their numbers.
  31. ;
  32. ;      These examples use '!' as the history command character, this is
  33. ;      the same as Berkeley-UNIX's (tm of AT&T) CSH shell.  This CP/M
  34. ;      implementation uses '|' interchangeably.  The functions implemented
  35. ;      are:
  36. ;
  37. ;        !!            Repeat last command, similar to ^W
  38. ;
  39. ;        !<pattern>    Repeat last command that starts with
  40. ;                the given pattern.
  41. ;
  42. ;        !<number>    Repeat command numbered <number>
  43. ;
  44. ;                EACH OF THE ABOVE THREE: append the rest of
  45. ;                "this line" to the substituted line. Example:
  46. ;
  47. ;                   If command #40 were: "COMPILE -O -C", then
  48. ;                   "!40 ROUTINE.C" would result in:
  49. ;                   "COMPILE -O -C ROUTINE.C"
  50. ;
  51. ;        h        Command that gives numbered command history 
  52. ;                list to be used with the above command.
  53. ;
  54. ;    When a history-substitution is made for a command, the new
  55. ;    command line is presented to the console for editing in a
  56. ;    similar fashion to the banked-^W command (unlike csh).
  57. ;
  58. ;    With the substitutions, the rest of the calling command line
  59. ;    (if any) is added onto the substitution-replacement line.
  60. ;
  61. ;    If you don't want submit files to store their internal-commands
  62. ;    into the history record, put a space in front of those commands.
  63. ;
  64. ;    If the file "<tempdisk>: CCP.EXT" exists, then that program is
  65. ;    loaded into memory at address 6000H, then executed with HBUFFER 
  66. ;    and CMDLINE address-pointers passed on the stack "above" the
  67. ;       return address. CMDLINE's pointer is "just" above the return address.
  68. ;
  69. ;
  70. ;    Data structure "buffer" has 42 CMDSIZE-byte records numbered 0-41.
  71. ;
  72. ;        defns: when file is read in, 
  73. ;                record 1: contains the last command number
  74. ;                record 2: contains the last command
  75. ;            then...
  76. ;                record 0: is where last command nr is moved to
  77. ;                record 1: is where "translated" current command
  78. ;                      is built.
  79. ;    
  80. ;        
  81. ;History file format:
  82. ;
  83. ;        One command line per RECSIZE byte logical record.
  84. ;
  85. ;        First sector contains the current command number (1-byte)
  86. ;
  87. ;        Second sector contains the last command 
  88. ;        Third sector contains the command before last 
  89. ;                (etc.)
  90. ;
  91. ;        If the first byte of a sector is a null, we have
  92. ;        "reached the end" of the history (null-commands are
  93. ;        not stored).
  94. ;
  95. ;        The file saves the last 40 command lines.
  96. ;
  97. ;        A "command-line" has the first byte being the byte count,
  98. ;        and a null-terminator just after the last "real" byte.
  99. ;
  100. ;            If a substituted command line is modified by the line
  101. ;          editor (when given the opportunity), then this new changed
  102. ;        version will be put into the history along with the one
  103. ;        "fetched" from history.
  104. ;
  105. ; Pattern: String of non-space and non-control characters
  106. ;
  107. ;
  108. ;
  109. ; This history routine is called with a newly gotten command in the
  110. ; CMDLINE buffer.  This routine will play games with the buffer (possibly
  111. ; modifying its contents), then return.
  112. ;
  113. ;    if (Command length == 0 || cmd starts w/' ' or ':') {
  114. ;        return();
  115. ;    }
  116. ;    buffer is cleared to nulls
  117. ;    Check to see if "temp:Historyx.dat" exists
  118. ;
  119. ;    if (exists) {
  120. ;        readfile into data buffer starting at record-1 point
  121. ;    }
  122. ;
  123. ;    read command number from record-1, and write it to record-0 
  124. ;    reset substitution and error flags;
  125. ;    if (first-char == '!') {
  126. ;        if (2nd char == '!') {
  127. ;            copy line at record-2 to record-1;
  128. ;            copy rest of cmdline onto end of the record-1 line;
  129. ;            set substitution flag;
  130. ;        }
  131. ;        else if (rest up to a terminator is numeric) {
  132. ;            translate number to binary;
  133. ;            if ( command number wanted is NOT in our list ) {
  134. ;                clear cmd line
  135. ;                print "not found"
  136. ;                set errorflag;
  137. ;                break out from first level 'if'
  138. ;            }
  139. ;            else {
  140. ;                copy record[(cmdnr-number+1)] to record-1;
  141. ;            copy rest of cmdline onto end of the record-1 line;
  142. ;                set substitution flag;
  143. ;            }
  144. ;        }
  145. ;        else {
  146. ;            search (bottom-up) for a string match (no white space)
  147. ;            if (found) {
  148. ;                copy that line to record-1;
  149. ;                copy rest of cmd line onto end of record-1 line
  150. ;                set substitution flag;
  151. ;            }
  152. ;            else {    
  153. ;                clear cmd line
  154. ;                print "not found"
  155. ;                set errorflag;
  156. ;                break out from first level 'if'
  157. ;            }
  158. ;        }
  159. ;        copy record-1 to cmdline;
  160. ;
  161. ;    }
  162. ;    else if (1st char == 'h' && 2rd char == terminator) {
  163. ;        reset substitution flag, and set err flag
  164. ;        print cmd lines w/numbers to screen
  165. ;    }
  166. ;    else {
  167. ;        copy cmdline to record-1
  168. ;    }
  169. ;    if (not ERRORFLAG) {
  170. ;        increment command number at 0 ;
  171. ;        if (first-char-of-cmd is printable, and not ' ' or ':') {
  172. ;            write buffer starting at record0 (bumps last one out)
  173. ;        }
  174. ;    }
  175. ;    else {
  176. ;        reset command line;
  177. ;    }
  178. ;
  179. ;    if (substitution flag set) {
  180. ;        calculate checksum of cmdline;
  181. ;        set DMA address to cmdline;
  182. ;        set DE to zero and call function 10 (edit substitution line);
  183. ;        if (new checksum != old checksum) {
  184. ;            go through self again;
  185. ;        }
  186. ;    }
  187. ;
  188. ;    command line now contains command line, ready for "normal" processing.
  189. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  190. ;;;;;;;;;;;;;;;;;;;;;;;                    ;;;;;;;;;;;;;;;;;;;;;;
  191. ;;;;;;;;;;;;;;;;;;;;;;;        END OF HISTORY MODULE    ;;;;;;;;;;;;;;;;;;;;;;
  192. ;;;;;;;;;;;;;;;;;;;;;;;                    ;;;;;;;;;;;;;;;;;;;;;;
  193. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  194. set substitution flag, and set err flag
  195. ;        print cmd lines w/numbers to scre