Diff for /gforth/history.fs between versions 1.3 and 1.4

version 1.3, 1994/11/03 15:27:57 version 1.4, 1994/11/15 15:55:37
Line 1 Line 1
 \ History file support                                 16oct94py  \ History file support                                 16oct94py
   
 0 Value history  0 Value history
   
 2Variable forward^  2Variable forward^
 2Variable backward^  2Variable backward^
 2Variable end^  2Variable end^
   
 : get-history ( addr len -- wid )  : get-history ( addr len -- wid )
   2dup r/w open-file 0<    2dup r/w open-file 0<
   IF  drop r/w create-file throw  ELSE  nip nip  THEN    IF  drop r/w create-file throw  ELSE  nip nip  THEN
   to history    to history
   history file-size throw    history file-size throw
   2dup forward^ 2! 2dup backward^ 2! end^ 2! ;    2dup forward^ 2! 2dup backward^ 2! end^ 2! ;
   
 s" gforth.history" get-history  s" gforth.history" get-history
   
 \ moving in history file                               16oct94py  : history-cold  Defers 'cold
     s" gforth.history" get-history ;
 : clear-line ( max span addr pos1 -- max addr )  
   backspaces over spaces swap backspaces ;  ' history-cold IS 'cold
   
 : clear-tib ( max span addr pos -- max 0 addr 0 false )  \ moving in history file                               16oct94py
   clear-line 0 tuck dup ;  
   : clear-line ( max span addr pos1 -- max addr )
 : get-line ( max addr -- max span addr pos dpos )    backspaces over spaces swap backspaces ;
   history file-position throw  backward^ 2!  
   2dup swap history read-line throw drop  : clear-tib ( max span addr pos -- max 0 addr 0 false )
   2dup type tuck    clear-line 0 tuck dup ;
   history file-position throw  forward^ 2! ;  
   : get-line ( max addr -- max span addr pos dpos )
 : next-line  ( max span addr pos1 -- max span addr pos2 false )    history file-position throw  backward^ 2!
   clear-line    2dup swap history read-line throw drop
   forward^ 2@ history reposition-file throw    2dup type tuck
   get-line  0 ;    history file-position throw  forward^ 2! ;
   
 : prev-line  ( max span addr pos1 -- max span addr pos2 false )  : next-line  ( max span addr pos1 -- max span addr pos2 false )
   clear-line over 2 + negate s>d backward^ 2@ d+ 0. dmax    clear-line
   2dup history reposition-file throw    forward^ 2@ history reposition-file throw
   BEGIN   2over swap history read-line throw  WHILE    get-line  0 ;
           >r history file-position throw  
           2dup backward^ 2@ d<  WHILE  2swap 2drop rdrop  : prev-line  ( max span addr pos1 -- max span addr pos2 false )
   REPEAT  ELSE  >r history file-position throw  THEN    clear-line over 2 + negate s>d backward^ 2@ d+ 0. dmax
   forward^ 2!  backward^ 2!  r> tuck 2dup type 0 ;    2dup history reposition-file throw
     BEGIN   2over swap history read-line throw  WHILE
 : ctrl  ( "<char>" -- ctrl-code )            >r history file-position throw
   char [char] @ - postpone Literal ; immediate            2dup backward^ 2@ d<  WHILE  2swap 2drop rdrop
     REPEAT  ELSE  >r history file-position throw  THEN
 Create lfpad #lf c,    forward^ 2!  backward^ 2!  r> tuck 2dup type 0 ;
   
 : (enter)  ( max span addr pos1 -- max span addr pos2 true )  : ctrl  ( "<char>" -- ctrl-code )
   >r end^ 2@ history reposition-file throw    char [char] @ - postpone Literal ; immediate
   2dup swap history write-file throw  
   lfpad 1 history write-file throw  Create lfpad #lf c,
   history file-position throw 2dup backward^ 2! end^ 2!  
   r> (ret) ;  : (enter)  ( max span addr pos1 -- max span addr pos2 true )
     >r end^ 2@ history reposition-file throw
 \ some other key commands                              16oct94py    2dup swap history write-file throw
     lfpad 1 history write-file throw
 : first-pos  ( max span addr pos1 -- max span addr 0 0 )    history file-position throw 2dup backward^ 2! end^ 2!
   backspaces 0 0 ;    r> (ret) ;
 : end-pos  ( max span addr pos1 -- max span addr span 0 )  
   type-rest 2drop over 0 ;  \ some other key commands                              16oct94py
   
 : extract-word ( addr len -- addr' len' )  dup >r  : first-pos  ( max span addr pos1 -- max span addr 0 0 )
   BEGIN  1- dup 0>=  WHILE  2dup + c@ bl =  UNTIL  THEN  1+    backspaces 0 0 ;
   tuck + r> rot - ;  : end-pos  ( max span addr pos1 -- max span addr span 0 )
     type-rest 2drop over 0 ;
 Create prefix-found  0 , 0 ,  
   : extract-word ( addr len -- addr' len' )  dup >r
 : word-lex ( nfa1 nfa2 -- -1/0/1 )    BEGIN  1- dup 0>=  WHILE  2dup + c@ bl =  UNTIL  THEN  1+
   dup 0=  IF  2drop 1  EXIT  THEN    tuck + r> rot - ;
   cell+ >r cell+ count $1F and  
   dup r@ c@ $1F and =  Create prefix-found  0 , 0 ,
   IF  r> char+ capscomp 0<=  EXIT  THEN  
   nip r> c@ $1F and < ;  : word-lex ( nfa1 nfa2 -- -1/0/1 )
     dup 0=  IF  2drop 1  EXIT  THEN
 : search-prefix  ( addr len1 -- suffix len2 )  0 >r  context    cell+ >r cell+ count $1F and
   BEGIN  BEGIN  dup @ over  cell - @ =  WHILE  cell -  REPEAT    dup r@ c@ $1F and =
          dup >r -rot r> @ @    IF  r> char+ capscomp 0<=  EXIT  THEN
          BEGIN  dup  WHILE  >r dup r@ cell+ c@ $1F and <=    nip r> c@ $1F and < ;
                 IF  2dup r@ cell+ char+ capscomp  0=  
                     IF  r> dup r@ word-lex  : search-prefix  ( addr len1 -- suffix len2 )  0 >r  context
                         IF  dup prefix-found @ word-lex    BEGIN  BEGIN  dup @ over  cell - @ =  WHILE  cell -  REPEAT
                             0>= IF  rdrop dup >r  THEN           dup >r -rot r> @ @
                         THEN >r           BEGIN  dup  WHILE  >r dup r@ cell+ c@ $1F and <=
                     THEN                  IF  2dup r@ cell+ char+ capscomp  0=
                 THEN  r> @                      IF  r> dup r@ word-lex
          REPEAT  drop rot cell -  dup vp u> 0=                          IF  dup prefix-found @ word-lex
   UNTIL  drop r> dup prefix-found ! ?dup                              0>= IF  rdrop dup >r  THEN
   IF    cell+ count $1F and rot /string rot drop                          THEN >r
   ELSE  2drop s" "  THEN  ;                      THEN
                   THEN  r> @
 : tab-expand ( max span addr pos1 -- max span addr pos2 0 )           REPEAT  drop rot cell -  dup vp u> 0=
   prefix-found cell+ @  0 ?DO  (del)  LOOP    UNTIL  drop r> dup prefix-found ! ?dup
   2dup extract-word search-prefix    IF    cell+ count $1F and rot /string rot drop
   dup prefix-found @ 0<> - prefix-found cell+ !    ELSE  2drop s" "  THEN  ;
   bounds ?DO  I c@ (ins)  LOOP  
   prefix-found @ IF  bl (ins)  THEN  0 ;  : tab-expand ( max span addr pos1 -- max span addr pos2 0 )
     prefix-found cell+ @  0 ?DO  (del)  LOOP
 : kill-prefix  ( key -- key )    2dup extract-word search-prefix
   dup #tab <> IF  0 0 prefix-found 2!  THEN ;    dup prefix-found @ 0<> - prefix-found cell+ !
     bounds ?DO  I c@ (ins)  LOOP
 ' kill-prefix IS everychar    prefix-found @ IF  bl (ins)  THEN  0 ;
   
 ' next-line  ctrl N cells ctrlkeys + !  : kill-prefix  ( key -- key )
 ' prev-line  ctrl P cells ctrlkeys + !    dup #tab <> IF  0 0 prefix-found 2!  THEN ;
 ' clear-tib  ctrl K cells ctrlkeys + !  
 ' first-pos  ctrl A cells ctrlkeys + !  ' kill-prefix IS everychar
 ' end-pos    ctrl E cells ctrlkeys + !  
 ' (enter)    #lf    cells ctrlkeys + !  ' next-line  ctrl N cells ctrlkeys + !
 ' (enter)    #cr    cells ctrlkeys + !  ' prev-line  ctrl P cells ctrlkeys + !
 ' tab-expand #tab   cells ctrlkeys + !  ' clear-tib  ctrl K cells ctrlkeys + !
   ' first-pos  ctrl A cells ctrlkeys + !
   ' end-pos    ctrl E cells ctrlkeys + !
   ' (enter)    #lf    cells ctrlkeys + !
   ' (enter)    #cr    cells ctrlkeys + !
   ' tab-expand #tab   cells ctrlkeys + !

Removed from v.1.3  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>