From a7291869f5174076b8d4ee0f352d0d734bd66774 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Thu, 26 Jul 2018 17:00:14 -0700 Subject: 4427 - support for '--trace' argv This ports commit 4421 to the subx/ program. --- subx/001help.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'subx/001help.cc') 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 \n" "- Run a SubX binary using SubX itself (for better error messages):\n" " subx run \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" -- cgit 1.4.1-2-gfad0