• Parsing a file name with spaces

    From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Tue Mar 24 08:51:28 2026
    From Newsgroup: comp.lang.forth

    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




    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Tue Mar 24 15:24:02 2026
    From Newsgroup: comp.lang.forth

    On Tue, 24 Mar 2026 08:51:28 -0500
    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?

    --
    Krishna

    I have cd for setting the current directory.
    It parses the whole line and uses that. it is defined as

    : CD \ commandline utility cd d:\directory
    source dup >r >in @ /string r> >in ! setcd
    abort" Invalid directory" ;

    setcd ( addr len -- ior) does that actual change

    of course there can be no comments after the directory path!

    BR
    Peter

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Wed Mar 25 01:28:58 2026
    From Newsgroup: comp.lang.forth

    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?" ;

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Stephen Pelc@stephen@vfxforth.com to comp.lang.forth on Tue Mar 24 15:55:48 2026
    From Newsgroup: comp.lang.forth

    On 24 Mar 2026 at 14:51:28 CET, "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?

    --
    Krishna

    We see this problem most often when parsing file names. Some operating
    systems allow you to use " as a name separator. We (Wodni&Pelc, ex MPE)
    provide this in VFX Forth.

    : GetPathSpec \ -- c-addr u | c-addr 0 ; 0 if null string
    \ *G Parse the input stream for a file/path name and return
    \ ** the address and length. If the name starts with a '"'
    \ ** character the returned string contains the characters
    \ ** between the first and second '"' characters but does
    \ ** not include the '"' characters themselves. If you need
    \ ** to include names that include '"' characters, delimit
    \ ** the string with '(' and ')'. In all other cases a space
    \ ** is used as the delimiting character. *\fo{GetPathSpec} does
    \ ** not expand text macro names.

    The text is in DocGen format, which VFX uses to generate manuals.

    Stephen
    --
    Stephen Pelc, stephen@vfxforth.com
    Wodni & Pelc GmbH
    Vienna, Austria
    Tel: +44 (0)7803 903612, +34 649 662 974 http://www.vfxforth.com/downloads/VfxCommunity/
    free VFX Forth downloads
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Tue Mar 24 17:58:26 2026
    From Newsgroup: comp.lang.forth

    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    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 ;

    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\".

    - anton
    --
    M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
    comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
    New standard: https://forth-standard.org/
    EuroForth 2025 proceedings: http://www.euroforth.org/ef25/papers/
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Tue Mar 24 13:41:57 2026
    From Newsgroup: comp.lang.forth

    On 3/24/26 12:58 PM, Anton Ertl wrote:
    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 ;

    because the buffer in which the string resides has persistence. What do
    you mean by S" gives you *two* buffers?

    --
    Krishna

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Tue Mar 24 20:40:03 2026
    From Newsgroup: comp.lang.forth

    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    Your suggestion is that a better definition of PARSE" would be

    : PARSE" ( "text" -- c-addr u ) ['] s" execute ;

    My suggestion is to use S" or S\" instead of PARSE".

    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\".
    --
    M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
    comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
    New standard: https://forth-standard.org/
    EuroForth 2025 proceedings: http://www.euroforth.org/ef25/papers/
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Tue Mar 24 20:26:59 2026
    From Newsgroup: comp.lang.forth

    On 3/24/26 3:40 PM, Anton Ertl wrote:
    ...
    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\".



    All S" strings are persistent for the life of the session in kForth, so
    I never worry about that.

    --
    KM

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From albert@albert@spenarnc.xs4all.nl to comp.lang.forth on Wed Mar 25 10:37:34 2026
    From Newsgroup: comp.lang.forth

    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.


    --
    Krishna

    Groetjes Albert
    --
    The Chinese government is satisfied with its military superiority over USA.
    The next 5 year plan has as primary goal to advance life expectancy
    over 80 years, like Western Europe.
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Wed Mar 25 05:13:39 2026
    From Newsgroup: comp.lang.forth

    On 3/25/26 4:37 AM, albert@spenarnc.xs4all.nl wrote:
    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.



    Yes, but it doesn't reflect how general users name files today.

    --
    Krishna

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Wed Mar 25 21:24:54 2026
    From Newsgroup: comp.lang.forth

    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?


    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From albert@albert@spenarnc.xs4all.nl to comp.lang.forth on Wed Mar 25 14:57:42 2026
    From Newsgroup: comp.lang.forth

    In article <69c3b7f6$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote:
    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?



    Not enthusiast about this approach. I use OS-IMPORT.

    The remainder of the line is passed as is to the shell, pretty thoughtless. This guarantees that the behaviour is the same than in $SHELL.

    SEE cat
    "cat" OS-IMPORT cat
    OK
    SEE OS-IMPORT
    : OS-IMPORT CREATE , ,
    DOES> 2@ cmdbuf $! BL cmdbuf $C+ ^J PARSE cmdbuf $+!
    cmdbuf $@ SYSTEM ;
    OK


    In 'lina -t'
    ------------------------------
    ...
    "123456" OK
    "" AAP "" " OK
    PUT-FILE OK
    cat *AAP*
    123456 OK
    ls -l *A* 2>/dev/null
    -rwxr-xr-x 1 albert albert 6 Mar 25 14:41 ' " AAP " '
    -rw-rw-r-- 1 albert albert 17323668 Dec 24 13:49 ADA364024.pdf
    -rw-rw-r-- 1 albert albert 2740 Dec 9 16:20 AvdH-2025-06-08--final.frt -rw-rw-r-- 1 albert albert 2144441 Dec 24 13:26 EFTA00009676.pdf
    -rw-rw-r-- 1 albert albert 1541273 Dec 24 13:32 EFTA00009767.pdf
    -rw-rw-r-- 1 albert albert 88700 Dec 24 13:35 EFTA00009823.pdf
    -rw-rw-r-- 1 albert albert 27771 Jan 27 14:02 MAINLP.ASM
    OK

    I guess you can't do
    OK
    cat *AAP* | od -c
    0000000 1 2 3 4 5 6
    0000006
    OK

    (This is from Forth )

    Groetjes Albert
    --
    The Chinese government is satisfied with its military superiority over USA.
    The next 5 year plan has as primary goal to advance life expectancy
    over 80 years, like Western Europe.
    --- Synchronet 3.21f-Linux NewsLink 1.2