| : only-path ( adr len path^ -- ) |
: only-path ( adr len path^ -- ) |
| dup 0 swap cell+ ! also-path ; |
dup 0 swap cell+ ! also-path ; |
| |
|
| : path+ name rot also-path ; |
: path+ ( path-addr "dir" -- ) \ gforth |
| : fpath+ fpath path+ ; |
\G adds a directory to the search path path-addr |
| |
name rot also-path ; |
| : path= name 2dup bounds ?DO i c@ '| = IF 0 i c! THEN LOOP |
|
| |
: fpath+ ( "dir" ) \ gforth |
| |
\G adds a directory to the forth search path |
| |
fpath path+ ; |
| |
|
| |
: path= ( path-addr "dir1|dir2|dir3" ) \ gforth |
| |
\G makes complete new searchpath, seperator is | |
| |
name 2dup bounds ?DO i c@ '| = IF 0 i c! THEN LOOP |
| rot only-path ; |
rot only-path ; |
| : fpath= fpath path= ; |
|
| |
: fpath= ( "dir1|dir2|dir3" ) \ gforth |
| |
\G makes complete new searchpath, serpeator is | |
| |
fpath path= ; |
| |
|
| : path>counted cell+ dup cell+ swap @ ; |
: path>counted cell+ dup cell+ swap @ ; |
| |
|
| dup path>counted |
dup path>counted |
| BEGIN tuck dup WHILE repeat ; |
BEGIN tuck dup WHILE repeat ; |
| |
|
| : .path |
: .path ( path-addr -- ) \ gforth |
| |
\G displays the contents of the search path path-addr |
| path>counted |
path>counted |
| BEGIN next-path dup WHILE type space REPEAT 2drop 2drop ; |
BEGIN next-path dup WHILE type space REPEAT 2drop 2drop ; |
| |
|
| : .fpath fpath .path ; |
: .fpath ( ) \ gforth |
| |
\G displays the contents of the forth search patch |
| |
fpath .path ; |
| |
|
| : absolut-path? ( addr u -- flag ) \ gforth |
: absolut-path? ( addr u -- flag ) \ gforth |
| \G a path is absolute, if it starts with a / or a ~ (~ expansion), |
\G a path is absolute, if it starts with a / or a ~ (~ expansion), |
| |
|
| : need/ ofile dup c@ + c@ pathsep? 0= IF s" /" ofile +place THEN ; |
: need/ ofile dup c@ + c@ pathsep? 0= IF s" /" ofile +place THEN ; |
| |
|
| : check-path ( adr1 len1 adr2 len2 -- fd 0 | 0 <>0 ) |
: extractpath ( adr len -- adr len2 ) |
| 0 ofile ! >r >r ofile place need/ |
BEGIN dup WHILE 1- |
| r> r> ofile +place |
2dup + c@ pathsep? IF EXIT THEN |
| ofile count r/o open-file ; |
REPEAT ; |
| |
|
| : expandtopic |
: expandtopic |
| ofile count 2 min s" ~+" compare 0= |
ofile count 2 min s" ~+" compare 0= |
| IF ofile count 2 /string tfile place |
IF ofile count 2 /string tfile place |
| 0 ofile c! sourcefilename onlypath ofile place need/ |
0 ofile c! sourcefilename extractpath ofile place need/ |
| tfile count ofile +place |
tfile count ofile +place |
| THEN ; |
THEN ; |
| |
|
| : onlypath ( adr len -- adr len2 ) |
: check-path ( adr1 len1 adr2 len2 -- fd 0 | 0 <>0 ) |
| BEGIN dup WHILE 1- |
0 ofile ! >r >r ofile place need/ |
| 2dup + c@ pathsep? IF EXIT THEN |
r> r> ofile +place |
| REPEAT ; |
expandtopic |
| |
ofile count r/o open-file ; |
| |
|
| : open-path-file ( adr len path -- fd adr1 len2 ) |
: open-path-file ( adr len path-addr -- fd adr1 len2 0 | ior ) \ gforth |
| |
\G looks in path path-addr for the file specified by adr len |
| |
\G when found the resulting path and an open file descriptor |
| |
\G is returned. If the file is not found ior is non zero |
| >r |
>r |
| 2dup absolut-path? |
2dup absolut-path? |
| IF rdrop |
IF rdrop |
| ofile place expandtopic ofile count r/o open-file throw |
ofile place expandtopic ofile count r/o open-file throw |
| ofile count EXIT |
ofile count 0 EXIT |
| ELSE r> path>counted |
ELSE r> path>counted |
| BEGIN next-path dup |
BEGIN next-path dup |
| WHILE 5 pick 5 pick check-path |
WHILE 5 pick 5 pick check-path |
| 0= IF >r 2drop 2drop r> ofile count EXIT ELSE drop THEN |
0= IF >r 2drop 2drop r> ofile count 0 EXIT ELSE drop THEN |
| REPEAT |
REPEAT |
| 2drop 2drop 2drop -&38 throw |
2drop 2drop 2drop -&38 |
| THEN ; |
THEN ; |
| |
|
| : open-fpath-file fpath open-path-file ; |
: open-fpath-file ( adr len -- fd adr1 len2 0 | ior ) \ gforth |
| |
\G looks in the forth search path for the file specified by adr len |
| |
\G when found the resulting path and an open file descriptor |
| |
\G is returned. If the file is not found ior is non zero |
| |
fpath open-path-file ; |