Annotation of gforth/kernel/accept.fs, revision 1.22

1.1       anton       1: \ Input                                                13feb93py
                      2: 
1.21      anton       3: \ Copyright (C) 1995,1996,1997,1999,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
1.1       anton       4: 
                      5: \ This file is part of Gforth.
                      6: 
                      7: \ Gforth is free software; you can redistribute it and/or
                      8: \ modify it under the terms of the GNU General Public License
1.22    ! anton       9: \ as published by the Free Software Foundation, either version 3
1.1       anton      10: \ of the License, or (at your option) any later version.
                     11: 
                     12: \ This program is distributed in the hope that it will be useful,
                     13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
                     14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     15: \ GNU General Public License for more details.
                     16: 
                     17: \ You should have received a copy of the GNU General Public License
1.22    ! anton      18: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.1       anton      19: 
                     20: : (ins) ( max span addr pos1 key -- max span addr pos2 )
1.13      pazsan     21:     >r  2over = IF  rdrop bell  EXIT  THEN
                     22:     2dup + r@ swap c! r> emit 1+ rot 1+ -rot ;
1.1       anton      23: : (bs) ( max span addr pos1 -- max span addr pos2 flag )
                     24:     dup IF
1.5       anton      25:        #bs emit space #bs emit 1- rot 1- -rot
1.1       anton      26:     THEN false ;
1.5       anton      27: : (ret) ( max span addr pos1 -- max span addr pos2 flag )
                     28:     true space ;
1.1       anton      29: 
                     30: Create ctrlkeys
1.9       jwilke     31:     ' false a, ' false a, ' false a, ' false a, 
                     32:     ' false a, ' false a, ' false a, ' false a,
                     33: 
                     34:     ' (bs)  a, ' false a, ' (ret) a, ' false a, 
                     35:     ' false a, ' (ret) a, ' false a, ' false a,
                     36: 
                     37:     ' false a, ' false a, ' false a, ' false a, 
                     38:     ' false a, ' false a, ' false a, ' false a,
                     39: 
                     40:     ' false a, ' false a, ' false a, ' false a, 
                     41:     ' false a, ' false a, ' false a, ' false a,
1.1       anton      42: 
                     43: defer insert-char
                     44: ' (ins) IS insert-char
                     45: defer everychar
                     46: ' noop IS everychar
1.12      pazsan     47: defer everyline
                     48: ' noop IS everyline
1.1       anton      49: 
                     50: : decode ( max span addr pos1 key -- max span addr pos2 flag )
1.17      anton      51:     \ perform action corresponding to key; addr max is the buffer,
                     52:     \ addr span is the current string in the buffer, and pos1 is the
                     53:     \ cursor position in the buffer.
1.10      pazsan     54:     everychar
                     55:     dup -1 =   IF  drop 4  THEN  \ -1 is EOF
                     56:     dup #del = IF  drop #bs  THEN  \ del is rubout
                     57:     dup bl u<  IF  cells ctrlkeys + perform  EXIT  THEN
                     58:     \ check for end reached
1.13      pazsan     59:     insert-char 0 ;
1.1       anton      60: 
1.8       anton      61: : edit-line ( c-addr n1 n2 -- n3 ) \ gforth
                     62:     \G edit the string with length @var{n2} in the buffer @var{c-addr
                     63:     \G n1}, like @code{accept}.
1.12      pazsan     64:     everyline
1.8       anton      65:     rot over
                     66:     2dup type
1.15      anton      67:     BEGIN  xkey decode  UNTIL
1.4       crook      68:     2drop nip ;
1.8       anton      69:     
                     70: : accept   ( c-addr +n1 -- +n2 ) \ core
                     71:     \G Get a string of up to @var{n1} characters from the user input
                     72:     \G device and store it at @var{c-addr}.  @var{n2} is the length of
                     73:     \G the received string. The user indicates the end by pressing
                     74:     \G @key{RET}.  Gforth supports all the editing functions available
                     75:     \G on the Forth command line (including history and word
                     76:     \G completion) in @code{accept}.
                     77:     dup 0< -&24 and throw \ use edit-line to edit given strings
                     78:     0 edit-line ;

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