diff --git a/debug.lsp b/debug.lsp index 8e38ea0..5b7945f 100644 --- a/debug.lsp +++ b/debug.lsp @@ -16,11 +16,14 @@ (defun term-red (str) (sprintf (+ term-red-esc str term-rst-esc))) -(print (term-red "red") (sprintf "%.2f" (list 1.11)) "ss") +(print (+ (term-red (sprintf "%.2f" (list 1.11))) " " + (term-green (sprintf "%.2f" (list 1.11))) " " + (term-blue (sprintf "%.2f" (list 1.11))) " " + (term-yellow (sprintf "%.2f" (list 1.11))) " " + )) - (define q_change_str (sprintf "%+.2f %%" (list q))) + ;; (define q_change_str (sprintf "%+.2f %%" (list q))) ;; (if (>= q_change 0.0) ;; (define q_change_str (term-green q_change_str)) ;; (define q_change_str (term-red q_change_str))) - \ No newline at end of file diff --git a/ml.cpp b/ml.cpp index ab8b0f8..8797ed5 100644 --- a/ml.cpp +++ b/ml.cpp @@ -1773,7 +1773,20 @@ MlValue MlEnvironment::get(const std::string &name) const { throw MlError(MlValue::atom(name), *this, ATOM_NOT_DEFINED); } -int main(int argc, const char **argv) { +std::vector getCmdOption(char *argv[], int argc, const std::string &option) { + std::vector tokens; + for (int i = 1; i < argc; ++i) { + if (option == argv[i] && i + 1 < argc) { + i++; + tokens.push_back(std::string(argv[i])); + } + } + return tokens; +} + +bool cmdOptionExists(char **begin, char **end, const std::string &option) { return std::find(begin, end, option) != end; } + +int main(int argc, char *argv[]) { MlEnvironment env; std::vector args; for (int i = 0; i < argc; i++) @@ -1786,6 +1799,18 @@ int main(int argc, const char **argv) { // for xcode profiling // run(read_file_contents("/Users/vaclavt/Development/mlisp/tests/test.lsp"), env); + // help + if (cmdOptionExists(argv, argv + argc, "-h")) { + std::cout << "Usage:\n\t-h print this help\n\t-f source_file - executes code in file\n\t-c code - runs passed code\n\t-i runs repl\n\t-v prints version string\n\n"; + return 0; + } + + // version + if (cmdOptionExists(argv, argv + argc, "-v")) { + std::cout << VERSION << std::endl; + return 0; + } + if (argc == 1 || (argc == 2 && std::string(argv[1]) == "-i")) repl(env); else if (argc == 3 && std::string(argv[1]) == "-c") diff --git a/ml.h b/ml.h index 50ffa53..4910d97 100644 --- a/ml.h +++ b/ml.h @@ -7,6 +7,8 @@ #include #include +const std::string VERSION = "mi 0.1 (" __DATE__ " " __TIME__ ")"; + // Forward declaration for MlEnvironment class definition class MlValue; diff --git a/tests/test.lsp b/tests/test.lsp index d2cff1d..ad41c06 100644 --- a/tests/test.lsp +++ b/tests/test.lsp @@ -177,5 +177,10 @@ (print (term-underline "underline text")) (print "normal text") +(print (+ (term-red (sprintf "%.2f" (list 1.11))) " " + (term-green (sprintf "%.2f" (list 1.11))) " " + (term-blue (sprintf "%.2f" (list 1.11))) " " + (term-yellow (sprintf "%.2f" (list 1.11))) " " + )) (print "Test ends") \ No newline at end of file