home *** CD-ROM | disk | FTP | other *** search
/ Dream 48 / Amiga_Dream_48.iso / Atari / forth / forst.zoo / forst / lib / expect.s < prev    next >
Text File  |  1990-12-10  |  1KB  |  63 lines

  1. ( expect package )
  2.  
  3. decimal
  4.  
  5. 32 constant blank
  6. 13 constant cret
  7. 8 constant bs
  8. 27 constant esc
  9.  
  10.  
  11. (  : fill  { 3 regargs dest len char }
  12.   for len  char dest inc c! next ;
  13.   
  14. : key  7 a7 dec w!  gemdos  d0 255 and  2 addto a7 ;
  15. : emit  a7 dec w!  2 a7 dec w!  gemdos  4 addto a7 ; )
  16.  
  17. : backup  bs emit  blank emit  bs emit ; 
  18. : bspaces  0 do backup loop ;
  19.  
  20. : docontrol { 4 regargs char &ptr &got &more  1 reg sofar }
  21.  
  22.   &got @ to sofar
  23.  
  24.   char case
  25.   bs of
  26.    sofar 0>
  27.     if  -1 &got +!
  28.      1 &more +!
  29.     -1 &ptr +!  blank &ptr @ c!
  30.     backup
  31.     then
  32.   endof
  33.      
  34.   esc of
  35.    sofar 0>
  36.     if  0 &got !
  37.         sofar &more +!
  38.         sofar negate &ptr +!
  39.         &ptr @ sofar blank fill 
  40.         sofar bspaces
  41.     then
  42.   endof
  43.   endcase
  44. ;
  45.  
  46. : expect { 2 args ptr #chars 3 locals char #got #more }
  47.  
  48.     ptr #chars blank fill
  49.     0 to #got  #chars to #more
  50.     
  51.     begin #more 0=  if leave then
  52.           key to char
  53.           char cret -
  54.     while char blank <
  55.           if  char  addr ptr  addr #got  addr #more  docontrol
  56.           else char ptr inc c!
  57.             1 addto #got
  58.             -1 addto #more
  59.             char emit
  60.           then
  61.     repeat
  62. ;      
  63.