[gforth] / gforth / kernel / io.fs  

gforth: gforth/kernel/io.fs

Diff for /gforth/kernel/io.fs between version 1.2 and 1.21

version 1.2, Sun Jul 6 16:09:55 1997 UTC version 1.21, Sat Sep 23 15:47:10 2000 UTC
Line 1 
Line 1 
 \ input output basics                           (extra since)   02mar97jaw  \ input output basics                           (extra since)   02mar97jaw
   
 \ Copyright (C) 1995-1997 Free Software Foundation, Inc.  \ Copyright (C) 1995,1996,1997,1998,2000 Free Software Foundation, Inc.
   
 \ This file is part of Gforth.  \ This file is part of Gforth.
   
Line 16 
Line 16 
   
 \ 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
   
 has-os [IF]  has? os [IF]
 0 Value outfile-id ( -- file-id ) \ gforth  0 Value outfile-id ( -- file-id ) \ gforth
   0 Value infile-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 ?
Line 30 
Line 33 
 : (emit) ( c -- ) \ gforth  : (emit) ( c -- ) \ gforth
     outfile-id emit-file drop \ !! use ?DUP-IF THROW ENDIF instead of DROP ?      outfile-id emit-file drop \ !! use ?DUP-IF THROW ENDIF instead of DROP ?
 ;  ;
   
   : (key) ( -- c ) \ gforth
       infile-id key-file ;
   
   : (key?) ( -- flag ) \ gforth
       infile-id key?-file ;
 [THEN]  [THEN]
   
   undef-words
   
 Defer type ( c-addr u -- ) \ core  Defer type ( c-addr u -- ) \ core
 ' (type) IS Type    \G If @var{u}>0, display @var{u} characters from a string starting
     \G with the character stored at @var{c-addr}.
   [IFDEF] write-file
   : (type) 0 write-file drop ;
   [ELSE]
   : (type) BEGIN dup WHILE
       >r dup c@ (emit) 1+ r> 1- REPEAT 2drop ;
   [THEN]
   
   [IFDEF] (type) ' (type) IS Type [THEN]
   
 Defer emit ( c -- ) \ core  Defer emit ( c -- ) \ core
 ' (Emit) IS Emit    \G Display the character associated with character value c.
   : (emit) ( c -- ) \ gforth
       0 emit-file drop \ !! use ?DUP-IF THROW ENDIF instead of DROP ?
   ;
   
   [IFDEF] (emit) ' (emit) IS emit [THEN]
   
   Defer key ( -- char ) \ core
   \G Receive (but do not display) one character, @var{char}.
   
 Defer key ( -- c ) \ core  [IFDEF] (key) ' (key) IS key [THEN]
 ' (key) IS key  
   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.
   
   [IFDEF] (key?) ' (key?) IS key? [THEN]
   
   all-words
   
 : (.")     "lit count type ;  : (.")     "lit count type ;
 : (S")     "lit count ;  : (S")     "lit count ;
Line 55 
Line 93 
 0C constant #ff ( -- c ) \ gforth  0C constant #ff ( -- 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
     \ emit a newline      \G Output a newline (of the favourite kind of the host OS).  Note
 [ ?? has-crlf [IF] ]    #cr emit #lf emit      \G that due to the way the Forth command line interpreter inserts
 [ [ELSE] ]              #lf emit      \G newlines, the preferred way to use @code{cr} is at the start
 [ [THEN] ]      \G of a piece of text; e.g., @code{cr ." hello, world"}.
     ;      newline type ;
   
   : space ( -- ) \ core
     \G Display one space.
     bl emit ;
   
 1 [IF]  has? ec [IF]
   : spaces ( n -- ) \ core
     \G If n > 0, display n spaces.
     0 max 0 ?DO space LOOP ;
   : backspaces  0 max 0 ?DO  #bs emit  LOOP ;
   [ELSE]
 \ space spaces                                          21mar93py  \ space spaces                                          21mar93py
 decimal  decimal
 Create spaces ( u -- ) \ core  Create spaces ( u -- ) \ core
     \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
Line 77 
Line 125 
    swap     swap
    0 max 0 ?DO  I' I - &80 min 2dup type  +LOOP  drop ;     0 max 0 ?DO  I' I - &80 min 2dup type  +LOOP  drop ;
 hex  hex
 : space ( -- ) \ core  
     1 spaces ;  
 [ELSE]  
 : space bl emit ;  
 : spaces 0 max 0 ?DO space LOOP ;  
   
 [THEN]  [THEN]
   


Generate output suitable for use with a patch program
Legend:
Removed from v.1.2  
changed lines
  Added in v.1.21

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help