From edd80fc3c55d1a676eecdc54cb03fda196d0d34b Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Wed, 15 Jun 2016 13:25:41 -0400 Subject: [PATCH] version builtin --- builtins.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++--- builtins.h | 1 + command.cpp | 1 + 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/builtins.cpp b/builtins.cpp index bc61657..5dc1472 100644 --- a/builtins.cpp +++ b/builtins.cpp @@ -19,6 +19,8 @@ //MAXPATHLEN #include +#define VERSION "0.1" + namespace ToolBox { std::string MacToUnix(const std::string path); @@ -687,6 +689,46 @@ int builtin_which(Environment &env, const std::vector &tokens, cons return 2; // not found. } +int builtin_version(Environment &env, const std::vector &tokens, const fdmask &fds) { + + + bool _v = false; + bool error = false; + + auto argv = getopt(tokens, [&](char c){ + switch(tolower(c)) + { + case 'v': + _v = true; + break; + default: + fprintf(stderr, "### Version - \"-%c\" is not an option.\n", c); + error = true; + break; + } + }); + + if (argv.size() != 0) { + fprintf(stderr, "### Version - Too many parameters were specified.\n"); + error = true; + } + + if (error) { + fprintf(stderr, "# Usage - Version [-v]\n"); + return 1; + } + + //fputs("MPW Shell 3.5, Copyright Apple Computer, Inc. 1985-99. All rights reserved.\n", stdout); + fputs("MPW Shell " VERSION ", Copyright Kelvin W Sherlock 2016. All rights reserved.\n", stdout); + fputs("based on MPW Shell 3.5, Copyright Apple Computer, Inc. 1985-99. All rights reserved.\n", stdout); + + if (_v) { + fputs("This version built on " __DATE__ " at " __TIME__ ".\n", stdout); + } + + return 0; +} + int builtin_aboutbox(Environment &env, const std::vector &tokens, const fdmask &fds) { // the most important command of all! @@ -723,13 +765,13 @@ int builtin_aboutbox(Environment &env, const std::vector &tokens, c } - fputs( + fprintf(stdout, "+--------------------------------------+\n" -"| MPW Shell 0.1 - February 2016 |\n" +"| MPW Shell %-4s |\n" "| |\n" "| |\n" "| (c) 2016 Kelvin W Sherlock |\n" "+--------------------------------------+\n" - ,stdout); + ,VERSION); return 0; } diff --git a/builtins.h b/builtins.h index 072ef98..e56c16b 100644 --- a/builtins.h +++ b/builtins.h @@ -18,6 +18,7 @@ int builtin_export(Environment &e, const std::vector &, const fdmas int builtin_unexport(Environment &e, const std::vector &, const fdmask &); int builtin_which(Environment &e, const std::vector &, const fdmask &); int builtin_aboutbox(Environment &e, const std::vector &, const fdmask &); +int builtin_version(Environment &e, const std::vector &, const fdmask &); int builtin_exists(Environment &e, const std::vector &, const fdmask &); diff --git a/command.cpp b/command.cpp index 750a682..adf2ccf 100644 --- a/command.cpp +++ b/command.cpp @@ -104,6 +104,7 @@ namespace { {"set", builtin_set}, {"unexport", builtin_unexport}, {"unset", builtin_unset}, + {"version", builtin_version}, {"which", builtin_which}, };