about summary refs log tree commit diff stats
path: root/subx/001help.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-07-26 17:00:14 -0700
committerKartik Agaram <vc@akkartik.com>2018-07-26 17:00:37 -0700
commita7291869f5174076b8d4ee0f352d0d734bd66774 (patch)
treebef98c313b4d28b0e298ddef46dc8ed3e9992e0c /subx/001help.cc
parent87fe3d7a9e5ae9503ee89a3d69f8b84a88ad24de (diff)
downloadmu-a7291869f5174076b8d4ee0f352d0d734bd66774.tar.gz
4427 - support for '--trace' argv
This ports commit 4421 to the subx/ program.
Diffstat (limited to 'subx/001help.cc')
-rw-r--r--subx/001help.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/subx/001help.cc b/subx/001help.cc
index 636205ad..65e291c5 100644
--- a/subx/001help.cc
+++ b/subx/001help.cc
@@ -9,6 +9,19 @@ if (argc <= 1 || is_equal(argv[1], "--help")) {
   return 0;
 }
 
+//: Support for option parsing.
+//: Options always begin with '--' and are always the first arguments. An
+//: option will never follow a non-option.
+char** arg = &argv[1];
+while (argc > 1 && starts_with(*arg, "--")) {
+  if (false)
+    ;  // no-op branch just so any further additions can consistently always start with 'else'
+  // End Commandline Options(*arg)
+  else
+    cerr << "skipping unknown option " << *arg << '\n';
+  --argc;  ++argv;  ++arg;
+}
+
 if (is_equal(argv[1], "help")) {
   if (argc == 2) {
     cerr << "help on what?\n";
@@ -63,6 +76,8 @@ void init_help() {
     "    subx translate <input 'source' file> <output ELF binary>\n"
     "- Run a SubX binary using SubX itself (for better error messages):\n"
     "    subx run <ELF binary>\n"
+    "Add '--trace' to any of these commands to also emit a trace, for debugging purposes.\n"
+    "However, options starting with '--' must always come before any other arguments.\n"
     "\n"
     "To start learning how to write SubX programs, run:\n"
     "  subx help\n"