Annotation of gforth/kernel/io.fs, revision 1.11
1.1 anton 1: \ input output basics (extra since) 02mar97jaw
2:
1.6 anton 3: \ Copyright (C) 1995,1996,1997,1998 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
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:
1.2 jwilke 21: \ Output 13feb93py
22:
1.3 jwilke 23: has? os [IF]
1.2 jwilke 24: 0 Value outfile-id ( -- file-id ) \ gforth
1.5 pazsan 25: 0 Value infile-id ( -- file-id ) \ gforth
1.7 pazsan 26:
1.2 jwilke 27: : (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: ;
1.5 pazsan 34:
35: : (key) ( -- c ) \ gforth
36: infile-id key-file ;
37:
38: : (key?) ( -- flag ) \ gforth
39: infile-id key?-file ;
1.2 jwilke 40: [THEN]
41:
1.7 pazsan 42: undef-words
43:
44: Defer type ( c-addr u -- ) \ core
1.9 crook 45: \G If @var{u}>0, display @var{u} characters from a string starting
46: \G with the character stored at @var{c-addr}.
47: : (type) BEGIN dup WHILE
48: >r dup c@ (emit) 1+ r> 1- REPEAT 2drop ;
1.4 pazsan 49:
1.7 pazsan 50: [IFDEF] (type) ' (type) IS Type [THEN]
1.2 jwilke 51:
52: Defer emit ( c -- ) \ core
1.8 crook 53: \G Display the character associated with character value c.
1.7 pazsan 54: : (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]
1.2 jwilke 59:
1.10 crook 60: Defer key ( -- char ) \ core
61: \G Receive (but do not display) one character, @var{char}.
1.7 pazsan 62:
63: [IFDEF] (key) ' (key) IS key [THEN]
1.5 pazsan 64:
1.10 crook 65: Defer key? ( -- flag ) \ facility
66: \G Determine whether a character is available. If a character is
67: \G available, @var{flag} is true; the next call to @code{key} will
68: \G yield the character. Once @code{key?} returns true, subsequent
69: \G calls to @code{key?} without calling @code{key} or @code{ekey} will
70: \G also return true.
1.7 pazsan 71:
72: [IFDEF] (key?) ' (key?) IS key? [THEN]
73:
74: all-words
1.2 jwilke 75:
76: : (.") "lit count type ;
77: : (S") "lit count ;
78:
1.1 anton 79: \ Input 13feb93py
80:
81: 07 constant #bell ( -- c ) \ gforth
82: 08 constant #bs ( -- c ) \ gforth
83: 09 constant #tab ( -- c ) \ gforth
84: 7F constant #del ( -- c ) \ gforth
85: 0D constant #cr ( -- c ) \ gforth
86: \ the newline key code
87: 0C constant #ff ( -- c ) \ gforth
88: 0A constant #lf ( -- c ) \ gforth
89:
1.3 jwilke 90: : bell #bell emit [ has? os [IF] ] outfile-id flush-file drop [ [THEN] ] ;
1.1 anton 91: : cr ( -- ) \ core
1.8 crook 92: \G Output a carriage-return and (if appropriate for the host operating system)
93: \G a line feed.
1.3 jwilke 94: [ has? crlf [IF] ] #cr emit #lf emit
1.1 anton 95: [ [ELSE] ] #lf emit
96: [ [THEN] ]
97: ;
98:
1.8 crook 99: : space ( -- ) \ core
100: \G Display one space.
101: bl emit ;
102:
1.7 pazsan 103: has? ec [IF]
1.8 crook 104: : spaces ( n -- ) \ core
105: \G If n > 0, display n spaces.
106: 0 max 0 ?DO space LOOP ;
1.7 pazsan 107: : backspaces 0 max 0 ?DO #bs emit LOOP ;
108: [ELSE]
1.1 anton 109: \ space spaces 21mar93py
110: decimal
111: Create spaces ( u -- ) \ core
1.9 crook 112: \G If @var{n} > 0, display @var{n} spaces.
1.8 crook 113: bl 80 times \ times from target compiler! 11may93jaw
1.1 anton 114: DOES> ( u -- )
1.8 crook 115: swap
116: 0 max 0 ?DO I' I - &80 min 2dup type +LOOP drop ;
1.1 anton 117: Create backspaces
1.8 crook 118: 08 80 times \ times from target compiler! 11may93jaw
1.1 anton 119: DOES> ( u -- )
1.8 crook 120: swap
121: 0 max 0 ?DO I' I - &80 min 2dup type +LOOP drop ;
1.1 anton 122: hex
123: [THEN]
124:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>