added option -h and -v
This commit is contained in:
parent
11ad7fc3bc
commit
55d39ef321
|
|
@ -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)))
|
||||
|
||||
|
||||
27
ml.cpp
27
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<std::string> getCmdOption(char *argv[], int argc, const std::string &option) {
|
||||
std::vector<std::string> 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<MlValue> 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")
|
||||
|
|
|
|||
2
ml.h
2
ml.h
|
|
@ -7,6 +7,8 @@
|
|||
#include <sstream>
|
||||
#include <exception>
|
||||
|
||||
const std::string VERSION = "mi 0.1 (" __DATE__ " " __TIME__ ")";
|
||||
|
||||
|
||||
// Forward declaration for MlEnvironment class definition
|
||||
class MlValue;
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
Loading…
Reference in New Issue