| \ input output basics (extra since) 02mar97jaw |
\ input output basics (extra since) 02mar97jaw |
| |
|
| \ Copyright (C) 1995,1996,1997,1998,2000 Free Software Foundation, Inc. |
\ Copyright (C) 1995,1996,1997,1998,2000,2003,2006,2007 Free Software Foundation, Inc. |
| |
|
| \ This file is part of Gforth. |
\ This file is part of Gforth. |
| |
|
| \ Gforth is free software; you can redistribute it and/or |
\ Gforth is free software; you can redistribute it and/or |
| \ modify it under the terms of the GNU General Public License |
\ modify it under the terms of the GNU General Public License |
| \ as published by the Free Software Foundation; either version 2 |
\ as published by the Free Software Foundation, either version 3 |
| \ of the License, or (at your option) any later version. |
\ of the License, or (at your option) any later version. |
| |
|
| \ This program is distributed in the hope that it will be useful, |
\ This program is distributed in the hope that it will be useful, |
| \ GNU General Public License for more details. |
\ GNU General Public License for more details. |
| |
|
| \ 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, see http://www.gnu.org/licenses/. |
| \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
|
| |
|
| require ./basics.fs |
require ./basics.fs |
| |
|
| \ Output 13feb93py |
\ Output 13feb93py |
| |
|
| has? os [IF] |
has? os [IF] |
| 0 Value outfile-id ( -- file-id ) \ gforth |
|
| 0 Value infile-id ( -- file-id ) \ gforth |
0 Value infile-id ( -- file-id ) \ gforth |
| |
0 Value outfile-id ( -- file-id ) \ gforth |
| |
0 Value errfile-id ( -- file-id ) \ gforth |
| |
|
| : (type) ( c-addr u -- ) \ gforth |
: (type) ( c-addr u -- ) \ gforth |
| outfile-id write-file drop \ !! use ?DUP-IF THROW ENDIF instead of DROP ? |
outfile-id write-file drop \ !! use ?DUP-IF THROW ENDIF instead of DROP ? |
| |
|
| Defer key ( -- char ) \ core |
Defer key ( -- char ) \ core |
| \G Receive (but do not display) one character, @var{char}. |
\G Receive (but do not display) one character, @var{char}. |
| |
: (key) ( -- c ) \ gforth |
| |
infile-id key-file ; |
| |
: infile-id stdin ; |
| |
|
| [IFDEF] (key) ' (key) IS key [THEN] |
[IFDEF] (key) ' (key) IS key [THEN] |
| |
|
| \G yield the character. Once @code{key?} returns true, subsequent |
\G yield the character. Once @code{key?} returns true, subsequent |
| \G calls to @code{key?} before calling @code{key} or @code{ekey} will |
\G calls to @code{key?} before calling @code{key} or @code{ekey} will |
| \G also return true. |
\G also return true. |
| |
: (key?) ( -- flag ) \ gforth |
| |
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 c-r |
Defer cr ( -- ) \ core c-r |
| \G Output a newline (of the favourite kind of the host OS). Note |
\G Output a newline (of the favourite kind of the host OS). Note |
| \G that due to the way the Forth command line interpreter inserts |
\G that due to the way the Forth command line interpreter inserts |
| \G newlines, the preferred way to use @code{cr} is at the start |
\G newlines, the preferred way to use @code{cr} is at the start |
| \G of a piece of text; e.g., @code{cr ." hello, world"}. |
\G of a piece of text; e.g., @code{cr ." hello, world"}. |
| |
: (cr) ( -- ) |
| newline type ; |
newline type ; |
| |
' (cr) IS cr |
| |
|
| : 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 ; |