Am Montag, 13. April 2026, 17:34:04 Mitteleuropäische Sommerzeit schrieb Anton 
Ertl:
> Instead, plug your word into "'COLD".  Best read the whole
> Section "Modifying the Startup Sequence".

The documentation there is a bit short. The right way to deal with special 
treatment of command line options in your user programm is to either hook 
PROCESS-OPTIONS (this is a recognizer, so it has to follow the recognizer 
API), or add words to the vocabulary OPTIONS.  E.g. if you have a command that 
needs to change to a directory, you can add an option:

get-current also options definitions

: --directory ( -- )
  next-arg 2dup d0<> if
      set-dir throw
  else
      2drop \ maybe also print out a warning
  then ;
synonym -d --directory

previous set-current

Then you can start your program with

myprogram -d $HOME/.local/share/myprogram

or wherever the files are kept.

Or, if you want to match more complex patterns (e.g. all directories starting 
with /, ./, or ../ passed are cd'd to), you can create a recognizer for that 
and add it to the recognizer sequence PROCESS-VOC-OPTION.

If your way of dealing with arguments doesn't fit into the way PROCESS-ARGS 
does it (i.e. recognize each argument), then you need to stick it in 'COLD 
before, but this only works if you save your program as image.  If you load 
your program as script, just perform your argument parsing yourself, because 
you are already inside the PROCESS-ARGS loop.  There, the best thing is 
something like

script? [IF]
    next-arg 2dup d<> [IF]  set-dir throw  [ELSE]  2drop  [THEN]
[THEN]

before you start reading your files.  Then you can start it with

gforth myprogram.fs $HOME/.local/share/myprogram

BTW: ARGC is a variable, so you might want to check ARGC @ instead of ARGC.  
ARGC is 1 if no argument is passed, because the program name is always passed 
as argument 0.  Checking NEXT-ARG for 0 0 also works.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
net2o id: kQusJzA;7*?t=uy@X}1GWr!+0qqp_Cn176t4(dQ*
https://net2o.de/

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to