aboutsummaryrefslogtreecommitdiffstats
path: root/c/args.c
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-16 07:30:34 +0200
committeruser <user@clank>2026-07-16 07:30:34 +0200
commit8682553498d32d3c18dea41c598ab40de18404a3 (patch)
tree74096aa1fcefce24f80583ee10f25e5831a3b589 /c/args.c
parentlibc + CLI tools: a small C userland (diff)
downloadgbos-8682553498d32d3c18dea41c598ab40de18404a3.tar.gz
gbos-8682553498d32d3c18dea41c598ab40de18404a3.tar.xz
gbos-8682553498d32d3c18dea41c598ab40de18404a3.zip
tools: wc, head, and an argc/argv demo (args) + libc.c helpers
- c/libc.c: shared C helpers linked into every program - putu (print decimal), atou (parse decimal), argv_parse (tokenize getargs() into argc/argv). - wc: count lines/words/chars of stdin. head [n]: first n lines (drains rest to EOF). args: argc/argv demo. - pid now uses libc putu; build.sh links libc.c; Makefile CBLOBS + libc dep. - README: document the new tools + argv_parse. - verified: 'args one two three' -> argc=3/argv[..]; wc '2 3 16'; head 2.
Diffstat (limited to '')
-rw-r--r--c/args.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/c/args.c b/c/args.c
new file mode 100644
index 0000000..c6f4db3
--- /dev/null
+++ b/c/args.c
@@ -0,0 +1,12 @@
+#include "gbos.h"
+/* args: an argc/argv demo. Splits its argument string into argv[] and prints
+ argc plus each argument. Try: `args one two three` */
+void main(void) {
+ char *argv[8];
+ unsigned char argc = argv_parse(argv, 8);
+ unsigned char i;
+ puts("argc="); putu(argc); nl();
+ for (i = 0; i < argc; i++) {
+ puts("argv["); putu(i); puts("]="); puts(argv[i]); nl();
+ }
+}