| \ input output basics (extra since) 02mar97jaw |
\ input output basics (extra since) 02mar97jaw |
| |
|
| \ Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc. |
\ Copyright (C) 1995,1996,1997,1998,2000,2003,2006 Free Software Foundation, Inc. |
| |
|
| \ This file is part of Gforth. |
\ This file is part of Gforth. |
| |
|
| |
|
| \ You should have received a copy of the GNU General Public License |
\ You should have received a copy of the GNU General Public License |
| \ along with this program; if not, write to the Free Software |
\ along with this program; if not, write to the Free Software |
| \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
\ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
| |
|
| |
require ./basics.fs |
| |
|
| \ Output 13feb93py |
\ Output 13feb93py |
| |
|
| undef-words |
undef-words |
| |
|
| Defer type ( c-addr u -- ) \ core |
Defer type ( c-addr u -- ) \ core |
| \G If u>0, display u characters from a string starting with the character |
\G If @var{u}>0, display @var{u} characters from a string starting |
| \G stored at c-addr. |
\G with the character stored at @var{c-addr}. |
| |
[IFDEF] write-file |
| |
: (type) 0 write-file drop ; |
| |
[ELSE] |
| : (type) BEGIN dup WHILE |
: (type) BEGIN dup WHILE |
| >r dup c@ (emit) 1+ r> 1- REPEAT 2drop ; |
>r dup c@ (emit) 1+ r> 1- REPEAT 2drop ; |
| |
[THEN] |
| |
|
| [IFDEF] (type) ' (type) IS Type [THEN] |
[IFDEF] (type) ' (type) IS Type [THEN] |
| |
|
| |
|
| [IFDEF] (emit) ' (emit) IS emit [THEN] |
[IFDEF] (emit) ' (emit) IS emit [THEN] |
| |
|
| Defer key ( -- c ) \ core |
Defer key ( -- char ) \ core |
| |
\G Receive (but do not display) one character, @var{char}. |
| : (key) ( -- c ) \ gforth |
: (key) ( -- c ) \ gforth |
| 0 key-file ; |
infile-id key-file ; |
| |
: infile-id stdin ; |
| |
|
| [IFDEF] (key) ' (key) IS key [THEN] |
[IFDEF] (key) ' (key) IS key [THEN] |
| |
|
| Defer key? ( -- flag ) \ core |
Defer key? ( -- flag ) \ facility key-question |
| |
\G Determine whether a character is available. If a character is |
| |
\G available, @var{flag} is true; the next call to @code{key} will |
| |
\G yield the character. Once @code{key?} returns true, subsequent |
| |
\G calls to @code{key?} before calling @code{key} or @code{ekey} will |
| |
\G also return true. |
| : (key?) ( -- flag ) \ gforth |
: (key?) ( -- flag ) \ gforth |
| 0 key?-file ; |
infile-id key?-file ; |
| |
: infile-id stdin ; |
| |
|
| [IFDEF] (key?) ' (key?) IS key? [THEN] |
[IFDEF] (key?) ' (key?) IS key? [THEN] |
| |
|
| |
|
| \ Input 13feb93py |
\ Input 13feb93py |
| |
|
| |
04 constant #eof ( -- c ) \ gforth |
| 07 constant #bell ( -- c ) \ gforth |
07 constant #bell ( -- c ) \ gforth |
| 08 constant #bs ( -- c ) \ gforth |
08 constant #bs ( -- c ) \ gforth |
| 09 constant #tab ( -- c ) \ gforth |
09 constant #tab ( -- c ) \ gforth |
| 0A constant #lf ( -- c ) \ gforth |
0A constant #lf ( -- c ) \ gforth |
| |
|
| : bell #bell emit [ has? os [IF] ] outfile-id flush-file drop [ [THEN] ] ; |
: bell #bell emit [ has? os [IF] ] outfile-id flush-file drop [ [THEN] ] ; |
| : cr ( -- ) \ core |
: cr ( -- ) \ core c-r |
| \G Output a carriage-return and (if appropriate for the host operating system) |
\G Output a newline (of the favourite kind of the host OS). Note |
| \G a line feed. |
\G that due to the way the Forth command line interpreter inserts |
| [ has? crlf [IF] ] #cr emit #lf emit |
\G newlines, the preferred way to use @code{cr} is at the start |
| [ [ELSE] ] #lf emit |
\G of a piece of text; e.g., @code{cr ." hello, world"}. |
| [ [THEN] ] |
newline type ; |
| ; |
|
| |
|
| : space ( -- ) \ core |
: space ( -- ) \ core |
| \G Display one space. |
\G Display one space. |
| bl emit ; |
bl emit ; |
| |
|
| has? ec [IF] |
has? os 0= [IF] |
| : spaces ( n -- ) \ core |
: spaces ( n -- ) \ core |
| \G If n > 0, display n spaces. |
\G If n > 0, display n spaces. |
| 0 max 0 ?DO space LOOP ; |
0 max 0 ?DO space LOOP ; |
| \ space spaces 21mar93py |
\ space spaces 21mar93py |
| decimal |
decimal |
| Create spaces ( u -- ) \ core |
Create spaces ( u -- ) \ core |
| \G If n > 0, display n spaces. |
\G Display @var{n} spaces. |
| bl 80 times \ times from target compiler! 11may93jaw |
bl 80 times \ times from target compiler! 11may93jaw |
| DOES> ( u -- ) |
DOES> ( u -- ) |
| swap |
swap |