philburk / pforth

Portable Forth in C
BSD Zero Clause License
602 stars 99 forks source link

Implement getopt() in Unix/Linux #134

Closed mschwartz closed 1 year ago

mschwartz commented 1 year ago

https://github.com/philburk/pforth/issues/131

Added getopt to parse arguments.

Removed a compiler flag that was being flagged with a warning message on my Mac.

Not sure why this can't automatically merge. Maybe you need to fix something in your repo?

I didn't test on linux. Don't see why it wouldn't work identically. The getopt() function is in .

No change in functionality except: added -h and -? for help:

./pforth -h           
Usage:
        pforth {-i} {-q} {-d filename.dic} {sourcefilename}
./pforth   
PForth V28-LE/64, built Dec 11 2022 16:35:27
pForth loading dictionary from file pforth.dic
     File format version is 10 
     Name space size = 120000 
     Code space size = 300000 
     Entry Point     = 0 
     Cell Size       = 8 
     Little  Endian Dictionary

1 1 +    ok
Stack<10> 2 

Note that make test with the main branch code reports the same one error as this PR.

Output of 'make test':

make test         
wd=$(pwd); (cd ../../fth; ${wd}/pforth_standalone -q t_corex.fth)
Include t_tools.fth
    include added 1496 bytes,38508 left.
IF YOU SEE THIS THEN .( WORKED!
    1234 - SHOULD LINE UP WITH NEXT LINE.
    1234
TEST NULL STRING IN .( 
10 9 8 7 6 5 

    ABCD4321 - SHOULD LINE UP WITH NEXT LINE.
    ABCD4321
 108 passed,    0 failed.
wd=$(pwd); (cd ../../fth; ${wd}/pforth_standalone -q t_strings.fth)
Include t_tools.fth
    include added 1496 bytes,38508 left.
  36 passed,    0 failed.
wd=$(pwd); (cd ../../fth; ${wd}/pforth_standalone -q t_locals.fth)
Include t_tools.fth
    include added 1496 bytes,38508 left.
Test warning when no locals defined.
(LOCAL) - Warning: no locals defined!
   9 passed,    0 failed.
wd=$(pwd); (cd ../../fth; ${wd}/pforth_standalone -q t_alloc.fth)
Testing ALLOCATE and FREE
10000 tests
Total Avail = 40960 
Please wait for test to complete...
Final    MAX = 40960 
Original MAX = 40960 
Test PASSED.
wd=$(pwd); (cd ../../fth; ${wd}/pforth_standalone -q t_floats.fth)
Include t_tools.fth
    include added 1496 bytes,38508 left.
T_F. T.SERIES final = 1.234533e+17 
T_F. T.SERIES final = 1.234533e+17 
T_F. T.SERIES final = 9.303299e+20 
T_F>D T.SERIES final = 1.175126e+17 
T_FS. T.SERIES final = 1.081004e+16 
T_FS. T.SERIES final = 6.448631e-18 
T_FE. T.SERIES final = 1.601179e+17 
T_FE. T.SERIES final = 1.219607e-18 
T_FE. T.SERIES final = 1.019165e+23 
T_FE. T.SERIES final = 2.103802e-12 
  49 passed,    0 failed.
wd=$(pwd); (cd ../../fth; ${wd}/pforth_standalone -q t_file.fth)
Include t_tools.fth
    include added 1496 bytes,38508 left.
Include t_required_helper1.fth
    include added 0 bytes,37388 left.
Include t_required_helper1.fth
    include added 0 bytes,37388 left.
Include t_required_helper2.fth
    include added 0 bytes,37388 left.
Include t_required_helper2.fth
    include added 0 bytes,37388 left.
INCORRECT RESULT: T{ S" abcd"  S" 1234" SSQ13  S= ROT ROT SSQ12 S= -> TRUE TRUE }T
  90 passed,    1 failed.
mschwartz commented 1 year ago

Not sure what the issue is with Makefile. I just deleted one line.

Maybe line endings or tabs/spaces?

mschwartz commented 1 year ago

You might want to look at the failed test. It failed on 64 bit and whatever endianness the m1 CPU uses.

mschwartz commented 1 year ago

We can trivially add more command line switches and options. I see in the tests how you pipe FORTH code as stdin to pforth. Neat.