From c4745240f68839843909b6a4d8624f15f58fa7c1 Mon Sep 17 00:00:00 2001 From: kitty Date: Sun, 8 Mar 2026 19:41:56 +1100 Subject: port strlen, argc, argv, environ from jonesforth --- jefs.fs | 8 +++++++- readme.md | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/jefs.fs b/jefs.fs index d3e4331..8dd4a8e 100644 --- a/jefs.fs +++ b/jefs.fs @@ -71,8 +71,8 @@ hex : ret, c3 c, ; decimal : ." [compile] s" ' say compile, ; immediate \ lol this word breaks the highlighting, here have another " : z" 1 >in +! [ char " ] literal cparse branch >mark >r 2dup cmove, 0 c, nip r> dup >resolve 4 + [compile] lit drop ( 1+ [compile] lit ) ; immediate -\ todo s>z z>s : s>z ( a u -- zstr ) here @ -rot cmove, 0 c, ; +: strlen ( zstr -- len ) dup begin dup c@ 0<> while 1+ repeat swap - ; \ creates a word called _ (so don't create an actual word called that!!!) \ maybe it could be an empty string but that might require some rewriting @@ -353,6 +353,12 @@ make line-buffer line-buffer-length allot : include ( "path" -- ) parse included ; \ }}} +\ ARGS {{{ +: argc rs0 @ @ ; +: argv ( n -- a u ) 1+ cells rs0 @ + @ dup strlen ; \ segfaults if n>=argc +: environ argc 2 + cells rs0 @ + ; +\ }}} + \ TERMINAL CONTROL {{{ 60 constant termios# make termios termios# allot diff --git a/readme.md b/readme.md index 16392e7..48b2326 100644 --- a/readme.md +++ b/readme.md @@ -59,7 +59,6 @@ the error codes are: ## TODO -- argc + argv - testing - `DEPTH` - more terminal control words -- cgit v1.2.3