From cf7cca9c7e9483dfe51894a467ae6775715ae997 Mon Sep 17 00:00:00 2001 From: "[GPL]Ed" Date: Sun, 30 Jul 2023 09:25:36 +0000 Subject: [PATCH] Add alt names for some commands, rename `%include` to `include` --- doc/man1/!.1 | 8 +++++--- doc/man1/@.1 | 10 +++++----- doc/man1/fork.1 | 1 + doc/man1/{%include.1 => include.1} | 8 ++++---- doc/man1/not.1 | 1 + examples/graph.zrc | 2 +- examples/minesweeper.zrc | 4 ++-- examples/quicksort.zrc | 2 +- src/config.hpp | 2 +- src/dispatch.hpp | 5 ++--- src/expr.cpp | 5 ++++- stdlib/cfuncs.zrc | 1 - stdlib/ipc.zrc | 2 +- stdlib/list.zrc | 2 +- stdlib/mathop.zrc | 2 +- 15 files changed, 30 insertions(+), 25 deletions(-) create mode 120000 doc/man1/fork.1 rename doc/man1/{%include.1 => include.1} (55%) create mode 120000 doc/man1/not.1 diff --git a/doc/man1/!.1 b/doc/man1/!.1 index 1780373..04001e2 100644 --- a/doc/man1/!.1 +++ b/doc/man1/!.1 @@ -1,8 +1,8 @@ -.TH ! 1 +.TH NOT 1 .SH NAME -! \- Run a command and return its opposite exit status +not|! \- Run a command and return its opposite exit status .SH SYNOPSIS -.BI "! [" ] +.BI "not|! [" ] .SH DESCRIPTION This builtin treats its arguments as a command, evaluates it and inverts the .I $? @@ -14,4 +14,6 @@ variable's value (if it is equal to 0, it sets its value to 1, otherwise it sets # Returns 0 ! return 1 + # Same thing + not return 1 .EE diff --git a/doc/man1/@.1 b/doc/man1/@.1 index 9c14dfa..e141307 100644 --- a/doc/man1/@.1 +++ b/doc/man1/@.1 @@ -1,10 +1,10 @@ -.TH @ 1 +.TH FORK 1 .SH NAME -@ \- Fork a subshell +@|fork \- Fork a subshell .SH SYNOPSIS -.BI "@ " +.BI "@|fork " .SH DESCRIPTION -.I @ +.I @ or fork must be followed by a string, representing a code block to be eval'ed. The utility forks off a new child process, executes the code inside of the block, and returns the last exit code from that block. .SH EXAMPLES .EX @@ -16,7 +16,7 @@ must be followed by a string, representing a code block to be eval'ed. The utili }] set a = b - @ { + fork { set a = c echo $a #shows 'c' } diff --git a/doc/man1/fork.1 b/doc/man1/fork.1 new file mode 120000 index 0000000..92a49c8 --- /dev/null +++ b/doc/man1/fork.1 @@ -0,0 +1 @@ +@.1 \ No newline at end of file diff --git a/doc/man1/%include.1 b/doc/man1/include.1 similarity index 55% rename from doc/man1/%include.1 rename to doc/man1/include.1 index 0fefc2d..2113ed0 100644 --- a/doc/man1/%include.1 +++ b/doc/man1/include.1 @@ -1,9 +1,9 @@ -.TH %INCLUDE 1 +.TH INCLUDE 1 .SH NAME -%include \- Load a ZrcLib header file. +include \- Load a ZrcLib header file. .SH SYNOPSIS -.BI "%include " +.BI "include " .SH DESCRIPTION The -.I %include +.I include utility sources a script header (by default) from /usr/lib/zrc/stdlib. diff --git a/doc/man1/not.1 b/doc/man1/not.1 new file mode 120000 index 0000000..47b0056 --- /dev/null +++ b/doc/man1/not.1 @@ -0,0 +1 @@ +!.1 \ No newline at end of file diff --git a/examples/graph.zrc b/examples/graph.zrc index ddbca8c..0b38ba6 100755 --- a/examples/graph.zrc +++ b/examples/graph.zrc @@ -5,7 +5,7 @@ # Code translated from C to Zrc from: # # https://c-for-dummies.com/blog/?p=831 # ######################################### -%include 'mathop' +include mathop set PI = 3.14159 set WIDTH = 60 set HEIGHT = 20 diff --git a/examples/minesweeper.zrc b/examples/minesweeper.zrc index 8162389..26855d9 100755 --- a/examples/minesweeper.zrc +++ b/examples/minesweeper.zrc @@ -1,6 +1,6 @@ #!../bin/zrc -%include 'cfuncs' -%include 'list' +include cfuncs +include list ################## # Reset terminal # diff --git a/examples/quicksort.zrc b/examples/quicksort.zrc index 5f4f14d..8a47a4a 100755 --- a/examples/quicksort.zrc +++ b/examples/quicksort.zrc @@ -2,7 +2,7 @@ ########################################### # Trivial quicksort implementation in Zrc.# ########################################### -%include list +include list fn quicksort { let {m pivot less equal greater vn x} { diff --git a/src/config.hpp b/src/config.hpp index aa48776..c201fe4 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -19,4 +19,4 @@ static std::string errmsg = "syntax error: "; static std::string default_prompt = "zrc% "; -static std::string ver = "zrc v0.7a"; +static std::string ver = "zrc v0.7b"; diff --git a/src/dispatch.hpp b/src/dispatch.hpp index 1c8b62b..e30f5fe 100644 --- a/src/dispatch.hpp +++ b/src/dispatch.hpp @@ -3,7 +3,7 @@ #define itoa ldtos #define OK(X) std::stold(expr(X)) #define de(X) { #X, zrc_builtin_##X } -#define ce(X,Y) { #X, zrc_builtin_##Y } +#define ce(X,Y) { #X, zrc_builtin_##Y }, { #Y, zrc_builtin_##Y } #define unless(X) if (!(X)) #define until(X) while (!(X)) @@ -829,7 +829,6 @@ Command(help); const DispatchTable> dispatch_table = { /* Aliased commands */ ce(!,not) , ce(.,source), ce(@,fork), - ce(%include , include), /* Normal cmds */ de(alias) , de(array) , de(bg), @@ -846,7 +845,7 @@ const DispatchTable> dispat de(unalias) , de(unless) , de(unset), de(until) , de(wait) , de(while), de(subst) , de(break) , de(continue), - de(concat) , de(rlimit) + de(concat) , de(rlimit) , de(include) }; /** Show a list of all BuiltIns **/ diff --git a/src/expr.cpp b/src/expr.cpp index 0ab731e..9ad3b23 100644 --- a/src/expr.cpp +++ b/src/expr.cpp @@ -207,7 +207,10 @@ expr(std::string e, ExprType mode) while (isnum(e[i]) && i < len) buf += e[i++]; --i; - nums.push(std::stold(buf)); + try { + nums.push(std::stold(buf)); + } catch (std::exception& ex) + {} /// opening paren } else if (e[i] == '(') { diff --git a/stdlib/cfuncs.zrc b/stdlib/cfuncs.zrc index a14cfda..fd51b17 100644 --- a/stdlib/cfuncs.zrc +++ b/stdlib/cfuncs.zrc @@ -34,7 +34,6 @@ alias sizeof { array length } # Other # ######### alias puts { echo } -alias fork { @ } alias new { malloc char } ######################################## diff --git a/stdlib/ipc.zrc b/stdlib/ipc.zrc index f5437d0..750cd5f 100644 --- a/stdlib/ipc.zrc +++ b/stdlib/ipc.zrc @@ -7,7 +7,7 @@ if {![string cmp $__IPC_ZRC_INCLUDED {}]} { set __IPC_ZRC_INCLUDED = 1 -%include cfuncs +include cfuncs ############################ # Pipe 2 lists as commands # diff --git a/stdlib/list.zrc b/stdlib/list.zrc index 95c4fc2..2b131ed 100644 --- a/stdlib/list.zrc +++ b/stdlib/list.zrc @@ -7,7 +7,7 @@ if {![string cmp $__LIST_ZRC_INCLUDED {}]} { set __LIST_ZRC_INCLUDED = 1 -%include cfuncs +include cfuncs ########################################## # Returns a list created from given args # diff --git a/stdlib/mathop.zrc b/stdlib/mathop.zrc index 9346e13..820d6e8 100644 --- a/stdlib/mathop.zrc +++ b/stdlib/mathop.zrc @@ -7,7 +7,7 @@ if {![string cmp $__MATHOP_ZRC_INCLUDED {}]} { set __MATHOP_ZRC_INCLUDED = 1 -%include cfuncs +include cfuncs ############################### # Helper to generate ops #