From f2407dfbe70365d7fc1c0f81504297d9e58c18b3 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 22 Apr 2016 01:35:30 -0400 Subject: [PATCH] CLI: Added handling of argv[0] when it is not named 'timew' --- src/CLI.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/CLI.cpp b/src/CLI.cpp index b9ddcae3..11ef32aa 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -144,6 +144,11 @@ void CLI::add (const std::string& argument) //////////////////////////////////////////////////////////////////////////////// // Arg0 is the first argument, which is the name and potentially a relative or // absolute path to the invoked binary. +// +// The binary name is 'timew', but if the binary is reported as 'foo' then it +// was invoked via symbolic link, in which case capture the first argument as +// 'foo'. This should allow any command/extension to do this. +// void CLI::handleArg0 () { // Capture arg0 separately, because it is the command that was run, and could @@ -152,6 +157,18 @@ void CLI::handleArg0 () A2 a (raw, Lexer::Type::word); a.tag ("BINARY"); + std::string basename = "timew"; + auto slash = raw.rfind ('/'); + if (slash != std::string::npos) + basename = raw.substr (slash + 1); + + a.attribute ("basename", basename); + if (basename != "timew") + { + A2 cal (basename, Lexer::Type::word); + _args.push_back (cal); + } + _args.push_back (a); }