1 \ SAVE-INPUT and RESTORE-INPUT
3 \ This code is part of pForth.
5 \ Permission to use, copy, modify, and/or distribute this
6 \ software for any purpose with or without fee is hereby granted.
8 \ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
9 \ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
10 \ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
11 \ THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
12 \ CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
13 \ FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
14 \ CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 \ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 anew task-save-input.fth
21 : SAVE-BUFFER ( -- column source-id 2 ) >in @ source-id 2 ;
23 \ Restore >IN from COLUMN unless COLUMN is too large. Valid values
24 \ for COLUMN are from 0 to (including) the length of SOURCE plus one.
25 : RESTORE-COLUMN ( column -- flag )
32 \ Return the file-position of the beginning of the current line in
33 \ file SOURCE-ID. Assume that the current line is stored in SOURCE
34 \ and that the current file-position is at an end-of-line (or
36 : LINE-START-POSITION ( -- ud )
37 source-id file-position throw
38 \ unless at end-of-file, subtract newline
39 source-id file-size throw 2over d= 0= IF 1 s>d d- THEN
40 \ subtract line length
44 : SAVE-FILE ( column line filepos:ud source-id 5 -- )
52 : RESTORE-FILE ( column line filepos:ud -- flag )
53 source-id reposition-file IF 2drop true EXIT THEN
54 refill 0= IF 2drop true EXIT THEN
59 : NDROP ( n*x n -- ) 0 ?DO drop LOOP ;
64 \ EVALUATE >IN SourceID=(-1) 2
65 \ keyboard >IN SourceID=(0) 2
66 \ file >IN lineNumber filePos SourceID=(fileID) 5
67 : SAVE-INPUT ( -- column {line filepos}? source-id n )
69 -1 OF save-buffer ENDOF
70 0 OF save-buffer ENDOF
75 : RESTORE-INPUT ( column {line filepos}? source-id n -- flag )
76 over source-id <> IF ndrop true EXIT THEN
79 -1 OF restore-column ENDOF
80 0 OF restore-column ENDOF
81 drop restore-file EXIT