[gforth] / gforth / kernel / accept.fs  

gforth: gforth/kernel/accept.fs


1 : anton 1.1 \ Input 13feb93py
2 :    
3 : anton 1.18 \ Copyright (C) 1995,1996,1997,1999,2003,2004,2005,2006 Free Software Foundation, Inc.
4 : anton 1.1
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
9 :     \ as published by the Free Software Foundation; either version 2
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
18 :     \ along with this program; if not, write to the Free Software
19 : anton 1.7 \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
20 : anton 1.1
21 :     : (ins) ( max span addr pos1 key -- max span addr pos2 )
22 : pazsan 1.13 >r 2over = IF rdrop bell EXIT THEN
23 :     2dup + r@ swap c! r> emit 1+ rot 1+ -rot ;
24 : anton 1.1 : (bs) ( max span addr pos1 -- max span addr pos2 flag )
25 :     dup IF
26 : anton 1.5 #bs emit space #bs emit 1- rot 1- -rot
27 : anton 1.1 THEN false ;
28 : anton 1.5 : (ret) ( max span addr pos1 -- max span addr pos2 flag )
29 :     true space ;
30 : anton 1.1
31 :     Create ctrlkeys
32 : jwilke 1.9 ' false a, ' false a, ' false a, ' false a,
33 :     ' false a, ' false a, ' false a, ' false a,
34 :    
35 :     ' (bs) a, ' false a, ' (ret) a, ' false a,
36 :     ' false a, ' (ret) a, ' false a, ' false a,
37 :    
38 :     ' false a, ' false a, ' false a, ' false a,
39 :     ' false a, ' false a, ' false a, ' false a,
40 :    
41 :     ' false a, ' false a, ' false a, ' false a,
42 :     ' false a, ' false a, ' false a, ' false a,
43 : anton 1.1
44 :     defer insert-char
45 :     ' (ins) IS insert-char
46 :     defer everychar
47 :     ' noop IS everychar
48 : pazsan 1.12 defer everyline
49 :     ' noop IS everyline
50 : anton 1.1
51 :     : decode ( max span addr pos1 key -- max span addr pos2 flag )
52 : anton 1.17 \ perform action corresponding to key; addr max is the buffer,
53 :     \ addr span is the current string in the buffer, and pos1 is the
54 :     \ cursor position in the buffer.
55 : pazsan 1.10 everychar
56 :     dup -1 = IF drop 4 THEN \ -1 is EOF
57 :     dup #del = IF drop #bs THEN \ del is rubout
58 :     dup bl u< IF cells ctrlkeys + perform EXIT THEN
59 :     \ check for end reached
60 : pazsan 1.13 insert-char 0 ;
61 : anton 1.1
62 : anton 1.8 : edit-line ( c-addr n1 n2 -- n3 ) \ gforth
63 :     \G edit the string with length @var{n2} in the buffer @var{c-addr
64 :     \G n1}, like @code{accept}.
65 : pazsan 1.12 everyline
66 : anton 1.8 rot over
67 :     2dup type
68 : anton 1.15 BEGIN xkey decode UNTIL
69 : crook 1.4 2drop nip ;
70 : anton 1.8
71 :     : accept ( c-addr +n1 -- +n2 ) \ core
72 :     \G Get a string of up to @var{n1} characters from the user input
73 :     \G device and store it at @var{c-addr}. @var{n2} is the length of
74 :     \G the received string. The user indicates the end by pressing
75 :     \G @key{RET}. Gforth supports all the editing functions available
76 :     \G on the Forth command line (including history and word
77 :     \G completion) in @code{accept}.
78 :     dup 0< -&24 and throw \ use edit-line to edit given strings
79 :     0 edit-line ;

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help