File:
[gforth] /
gforth /
kernel /
io.fs
Revision
1.13:
download - view:
text,
annotated -
select for diffs
Sun Aug 29 21:44:46 1999 UTC (24 years, 8 months ago) by
pazsan
Branches:
MAIN
CVS tags:
HEAD
Made block 0 the first block and provided OFFSET for backward compatibility
(store 1 there).
Fixed bug for negative buffers.
Added a type in write-file for OS-less ports.
Some corrections to make the SHARC port compile again.
HAS_DEBUG is now a central flag which replaces perror and fprintf if not set.
1: \ input output basics (extra since) 02mar97jaw
2:
3: \ Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
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:
21: require ./basics.fs
22:
23: \ Output 13feb93py
24:
25: has? os [IF]
26: 0 Value outfile-id ( -- file-id ) \ gforth
27: 0 Value infile-id ( -- file-id ) \ gforth
28:
29: : (type) ( c-addr u -- ) \ gforth
30: outfile-id write-file drop \ !! use ?DUP-IF THROW ENDIF instead of DROP ?
31: ;
32:
33: : (emit) ( c -- ) \ gforth
34: outfile-id emit-file drop \ !! use ?DUP-IF THROW ENDIF instead of DROP ?
35: ;
36:
37: : (key) ( -- c ) \ gforth
38: infile-id key-file ;
39:
40: : (key?) ( -- flag ) \ gforth
41: infile-id key?-file ;
42: [THEN]
43:
44: undef-words
45:
46: Defer type ( c-addr u -- ) \ core
47: \G If @var{u}>0, display @var{u} characters from a string starting
48: \G with the character stored at @var{c-addr}.
49: [IFDEF] write-file
50: : (type) 0 write-file drop ;
51: [ELSE]
52: : (type) BEGIN dup WHILE
53: >r dup c@ (emit) 1+ r> 1- REPEAT 2drop ;
54: [THEN]
55:
56: [IFDEF] (type) ' (type) IS Type [THEN]
57:
58: Defer emit ( c -- ) \ core
59: \G Display the character associated with character value c.
60: : (emit) ( c -- ) \ gforth
61: 0 emit-file drop \ !! use ?DUP-IF THROW ENDIF instead of DROP ?
62: ;
63:
64: [IFDEF] (emit) ' (emit) IS emit [THEN]
65:
66: Defer key ( -- char ) \ core
67: \G Receive (but do not display) one character, @var{char}.
68:
69: [IFDEF] (key) ' (key) IS key [THEN]
70:
71: Defer key? ( -- flag ) \ facility
72: \G Determine whether a character is available. If a character is
73: \G available, @var{flag} is true; the next call to @code{key} will
74: \G yield the character. Once @code{key?} returns true, subsequent
75: \G calls to @code{key?} without calling @code{key} or @code{ekey} will
76: \G also return true.
77:
78: [IFDEF] (key?) ' (key?) IS key? [THEN]
79:
80: all-words
81:
82: : (.") "lit count type ;
83: : (S") "lit count ;
84:
85: \ Input 13feb93py
86:
87: 07 constant #bell ( -- c ) \ gforth
88: 08 constant #bs ( -- c ) \ gforth
89: 09 constant #tab ( -- c ) \ gforth
90: 7F constant #del ( -- c ) \ gforth
91: 0D constant #cr ( -- c ) \ gforth
92: \ the newline key code
93: 0C constant #ff ( -- c ) \ gforth
94: 0A constant #lf ( -- c ) \ gforth
95:
96: : bell #bell emit [ has? os [IF] ] outfile-id flush-file drop [ [THEN] ] ;
97: : cr ( -- ) \ core
98: \G Output a carriage-return and (if appropriate for the host operating system)
99: \G a line feed.
100: [ has? crlf [IF] ] #cr emit #lf emit
101: [ [ELSE] ] #lf emit
102: [ [THEN] ]
103: ;
104:
105: : space ( -- ) \ core
106: \G Display one space.
107: bl emit ;
108:
109: has? ec [IF]
110: : spaces ( n -- ) \ core
111: \G If n > 0, display n spaces.
112: 0 max 0 ?DO space LOOP ;
113: : backspaces 0 max 0 ?DO #bs emit LOOP ;
114: [ELSE]
115: \ space spaces 21mar93py
116: decimal
117: Create spaces ( u -- ) \ core
118: \G If @var{n} > 0, display @var{n} spaces.
119: bl 80 times \ times from target compiler! 11may93jaw
120: DOES> ( u -- )
121: swap
122: 0 max 0 ?DO I' I - &80 min 2dup type +LOOP drop ;
123: Create backspaces
124: 08 80 times \ times from target compiler! 11may93jaw
125: DOES> ( u -- )
126: swap
127: 0 max 0 ?DO I' I - &80 min 2dup type +LOOP drop ;
128: hex
129: [THEN]
130:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>