Currently, INCLUDE and REQUIRE parse file names which are delimited by a space or white space character. These words preclude file names with
spaces. There are, of course, INCLUDED and REQUIRED which take a string argument from the stack, and, thus, filenames with spaces can be processed.
However, if a user wants to write a word which can parse file names with spaces, then some type of convention must be used. For example, one can define PARSE"
: parse" [char] " parse ;
and use it like this,
parse" A file name with spaces.txt"
PARSE" seems like a good solution, and is more readable than
char " parse A file name with spaces.txt"
or, equivalently in Forth-2012,
'"' parse A filename with spaces.txt"
What other methods do Forthers use for file names with spaces?
--
Krishna
...
What other methods do Forthers use for file names with spaces?
Currently, INCLUDE and REQUIRE parse file names which are delimited by a space or white space character. These words preclude file names with
spaces. There are, of course, INCLUDED and REQUIRED which take a string argument from the stack, and, thus, filenames with spaces can be processed.
However, if a user wants to write a word which can parse file names with spaces, then some type of convention must be used. For example, one can define PARSE"
: parse" [char] " parse ;
and use it like this,
parse" A file name with spaces.txt"
PARSE" seems like a good solution, and is more readable than
char " parse A file name with spaces.txt"
or, equivalently in Forth-2012,
'"' parse A filename with spaces.txt"
What other methods do Forthers use for file names with spaces?
--
Krishna
However, if a user wants to write a word which can parse file names with >spaces, then some type of convention must be used. For example, one can >define PARSE"
: parse" [char] " parse ;
Krishna Myneni <krishna.myneni@ccreweb.org> writes:...
: parse" [char] " parse ;
The result is very similar to the interpretation semantics of FILE S",
except that with PARSE" the resulting parsed string is only valid
while the current line is being parsed, while S" gives you two
buffers, each with unlimited life time.
For the problem with embedded quotes or other characters that cannot
occur in S" strings, there is S\".
Your suggestion is that a better definition of PARSE" would be
: PARSE" ( "text" -- c-addr u ) ['] s" execute ;
What do
you mean by S" gives you *two* buffers?
What do
you mean by S" gives you *two* buffers?
According to
<https://forth-standard.org/standard/file#subsection.11.3.4>:
|[...] there shall be at least two buffers. The system should be able
|to store two strings defined by sequential use of S" or S\".
Currently, INCLUDE and REQUIRE parse file names which are delimited by a >space or white space character. These words preclude file names with
spaces. There are, of course, INCLUDED and REQUIRED which take a string >argument from the stack, and, thus, filenames with spaces can be processed.
However, if a user wants to write a word which can parse file names with >spaces, then some type of convention must be used. For example, one can >define PARSE"
: parse" [char] " parse ;
and use it like this,
parse" A file name with spaces.txt"
PARSE" seems like a good solution, and is more readable than
char " parse A file name with spaces.txt"
or, equivalently in Forth-2012,
'"' parse A filename with spaces.txt"
What other methods do Forthers use for file names with spaces?
--
Krishna
In article <10pu4t0$12cqm$1@dont-email.me>,
Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
Currently, INCLUDE and REQUIRE parse file names which are delimited by a
space or white space character. These words preclude file names with
spaces. There are, of course, INCLUDED and REQUIRED which take a string
argument from the stack, and, thus, filenames with spaces can be processed. >>
However, if a user wants to write a word which can parse file names with
spaces, then some type of convention must be used. For example, one can
define PARSE"
: parse" [char] " parse ;
and use it like this,
parse" A file name with spaces.txt"
PARSE" seems like a good solution, and is more readable than
char " parse A file name with spaces.txt"
or, equivalently in Forth-2012,
'"' parse A filename with spaces.txt"
What other methods do Forthers use for file names with spaces?
A better solution is to rename files that contains spaces. --------------------------------------------------
for i in *
do
if ( echo "$i" | fgrep ' ' )
then
mv "$i" "`echo $i | sed -e s/\ /_/g`"
fi
done
-----------------------------------------------------
For what it is worth.
"this is a ""silly filename with spaces and quotes" R/W OPEN-FILE
at least shows what the file is.
On 25/03/2026 12:51 am, Krishna Myneni wrote:
...
What other methods do Forthers use for file names with spaces?
Don't recall the origin but I had this stashed away.
: GETFILENAME ( -- c-addr u )
>in @ char dup rot >in !
[char] " - if drop bl then word count
dup 0= abort" filename?" ;
On 25/03/2026 1:28 am, dxf wrote:
On 25/03/2026 12:51 am, Krishna Myneni wrote:
...
What other methods do Forthers use for file names with spaces?
Don't recall the origin but I had this stashed away.
: GETFILENAME ( -- c-addr u )
>in @ char dup rot >in !
[char] " - if drop bl then word count
dup 0= abort" filename?" ;
Fixes some quirks.
: GETFILENAME ( -- c-addr u )
source >in @ /string tuck bl skip negate rot + >in +!
c@ dup [char] " - if drop bl then word count
dup 0= abort" filename?" ;
: t getfilename cr type ;
t foobar
foobar ok
t foobar
foobar ok
t "foobar"
foobar ok
t "foobar"
foobar ok
t "foo bar"
foo bar ok
t "foo bar"
foo bar ok
t filename?
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,105 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 492369:17:25 |
| Calls: | 14,160 |
| Calls today: | 2 |
| Files: | 186,285 |
| D/L today: |
2,034 files (638M bytes) |
| Messages: | 2,503,450 |