| 1 : |
anton
|
1.1
|
\ input output basics (extra since) 02mar97jaw |
| 2 : |
|
|
|
| 3 : |
anton
|
1.6
|
\ Copyright (C) 1995,1996,1997,1998 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 : |
|
|
\ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 : |
|
|
|
| 21 : |
jwilke
|
1.2
|
\ Output 13feb93py |
| 22 : |
|
|
|
| 23 : |
jwilke
|
1.3
|
has? os [IF] |
| 24 : |
jwilke
|
1.2
|
0 Value outfile-id ( -- file-id ) \ gforth |
| 25 : |
pazsan
|
1.5
|
0 Value infile-id ( -- file-id ) \ gforth |
| 26 : |
pazsan
|
1.7
|
|
| 27 : |
jwilke
|
1.2
|
: (type) ( c-addr u -- ) \ gforth |
| 28 : |
|
|
outfile-id write-file drop \ !! use ?DUP-IF THROW ENDIF instead of DROP ? |
| 29 : |
|
|
; |
| 30 : |
|
|
|
| 31 : |
|
|
: (emit) ( c -- ) \ gforth |
| 32 : |
|
|
outfile-id emit-file drop \ !! use ?DUP-IF THROW ENDIF instead of DROP ? |
| 33 : |
|
|
; |
| 34 : |
pazsan
|
1.5
|
|
| 35 : |
|
|
: (key) ( -- c ) \ gforth |
| 36 : |
|
|
infile-id key-file ; |
| 37 : |
|
|
|
| 38 : |
|
|
: (key?) ( -- flag ) \ gforth |
| 39 : |
|
|
infile-id key?-file ; |
| 40 : |
jwilke
|
1.2
|
[THEN] |
| 41 : |
|
|
|
| 42 : |
pazsan
|
1.7
|
undef-words |
| 43 : |
|
|
|
| 44 : |
|
|
Defer type ( c-addr u -- ) \ core |
| 45 : |
crook
|
1.8
|
\G If u>0, display u characters from a string starting with the character |
| 46 : |
|
|
\G stored at c-addr. |
| 47 : |
pazsan
|
1.4
|
: (type) BEGIN dup WHILE |
| 48 : |
|
|
>r dup c@ (emit) 1+ r> 1- REPEAT 2drop ; |
| 49 : |
|
|
|
| 50 : |
pazsan
|
1.7
|
[IFDEF] (type) ' (type) IS Type [THEN] |
| 51 : |
jwilke
|
1.2
|
|
| 52 : |
|
|
Defer emit ( c -- ) \ core |
| 53 : |
crook
|
1.8
|
\G Display the character associated with character value c. |
| 54 : |
pazsan
|
1.7
|
: (emit) ( c -- ) \ gforth |
| 55 : |
|
|
0 emit-file drop \ !! use ?DUP-IF THROW ENDIF instead of DROP ? |
| 56 : |
|
|
; |
| 57 : |
|
|
|
| 58 : |
|
|
[IFDEF] (emit) ' (emit) IS emit [THEN] |
| 59 : |
jwilke
|
1.2
|
|
| 60 : |
|
|
Defer key ( -- c ) \ core |
| 61 : |
pazsan
|
1.7
|
: (key) ( -- c ) \ gforth |
| 62 : |
|
|
0 key-file ; |
| 63 : |
|
|
|
| 64 : |
|
|
[IFDEF] (key) ' (key) IS key [THEN] |
| 65 : |
pazsan
|
1.5
|
|
| 66 : |
|
|
Defer key? ( -- flag ) \ core |
| 67 : |
pazsan
|
1.7
|
: (key?) ( -- flag ) \ gforth |
| 68 : |
|
|
0 key?-file ; |
| 69 : |
|
|
|
| 70 : |
|
|
[IFDEF] (key?) ' (key?) IS key? [THEN] |
| 71 : |
|
|
|
| 72 : |
|
|
all-words |
| 73 : |
jwilke
|
1.2
|
|
| 74 : |
|
|
: (.") "lit count type ; |
| 75 : |
|
|
: (S") "lit count ; |
| 76 : |
|
|
|
| 77 : |
anton
|
1.1
|
\ Input 13feb93py |
| 78 : |
|
|
|
| 79 : |
|
|
07 constant #bell ( -- c ) \ gforth |
| 80 : |
|
|
08 constant #bs ( -- c ) \ gforth |
| 81 : |
|
|
09 constant #tab ( -- c ) \ gforth |
| 82 : |
|
|
7F constant #del ( -- c ) \ gforth |
| 83 : |
|
|
0D constant #cr ( -- c ) \ gforth |
| 84 : |
|
|
\ the newline key code |
| 85 : |
|
|
0C constant #ff ( -- c ) \ gforth |
| 86 : |
|
|
0A constant #lf ( -- c ) \ gforth |
| 87 : |
|
|
|
| 88 : |
jwilke
|
1.3
|
: bell #bell emit [ has? os [IF] ] outfile-id flush-file drop [ [THEN] ] ; |
| 89 : |
anton
|
1.1
|
: cr ( -- ) \ core |
| 90 : |
crook
|
1.8
|
\G Output a carriage-return and (if appropriate for the host operating system) |
| 91 : |
|
|
\G a line feed. |
| 92 : |
jwilke
|
1.3
|
[ has? crlf [IF] ] #cr emit #lf emit |
| 93 : |
anton
|
1.1
|
[ [ELSE] ] #lf emit |
| 94 : |
|
|
[ [THEN] ] |
| 95 : |
|
|
; |
| 96 : |
|
|
|
| 97 : |
crook
|
1.8
|
: space ( -- ) \ core |
| 98 : |
|
|
\G Display one space. |
| 99 : |
|
|
bl emit ; |
| 100 : |
|
|
|
| 101 : |
pazsan
|
1.7
|
has? ec [IF] |
| 102 : |
crook
|
1.8
|
: spaces ( n -- ) \ core |
| 103 : |
|
|
\G If n > 0, display n spaces. |
| 104 : |
|
|
0 max 0 ?DO space LOOP ; |
| 105 : |
pazsan
|
1.7
|
: backspaces 0 max 0 ?DO #bs emit LOOP ; |
| 106 : |
|
|
[ELSE] |
| 107 : |
anton
|
1.1
|
\ space spaces 21mar93py |
| 108 : |
|
|
decimal |
| 109 : |
|
|
Create spaces ( u -- ) \ core |
| 110 : |
crook
|
1.8
|
\G If n > 0, display n spaces. |
| 111 : |
|
|
bl 80 times \ times from target compiler! 11may93jaw |
| 112 : |
anton
|
1.1
|
DOES> ( u -- ) |
| 113 : |
crook
|
1.8
|
swap |
| 114 : |
|
|
0 max 0 ?DO I' I - &80 min 2dup type +LOOP drop ; |
| 115 : |
anton
|
1.1
|
Create backspaces |
| 116 : |
crook
|
1.8
|
08 80 times \ times from target compiler! 11may93jaw |
| 117 : |
anton
|
1.1
|
DOES> ( u -- ) |
| 118 : |
crook
|
1.8
|
swap |
| 119 : |
|
|
0 max 0 ?DO I' I - &80 min 2dup type +LOOP drop ; |
| 120 : |
anton
|
1.1
|
hex |
| 121 : |
|
|
[THEN] |
| 122 : |
|
|
|