Skip to content

Commit

Permalink
Add alt names for some commands, rename %include to include
Browse files Browse the repository at this point in the history
  • Loading branch information
Edd12321 committed Jul 30, 2023
1 parent ab3907d commit cf7cca9
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 25 deletions.
8 changes: 5 additions & 3 deletions doc/man1/!.1
Original file line number Diff line number Diff line change
@@ -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 "! [" <cmd> ]
.BI "not|! [" <cmd> ]
.SH DESCRIPTION
This builtin treats its arguments as a command, evaluates it and inverts the
.I $?
Expand All @@ -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
10 changes: 5 additions & 5 deletions doc/man1/@.1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.TH @ 1
.TH FORK 1
.SH NAME
@ \- Fork a subshell
@|fork \- Fork a subshell
.SH SYNOPSIS
.BI "@ " <block>
.BI "@|fork " <block>
.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
Expand All @@ -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'
}
Expand Down
1 change: 1 addition & 0 deletions doc/man1/fork.1
8 changes: 4 additions & 4 deletions doc/man1/%include.1 → doc/man1/include.1
Original file line number Diff line number Diff line change
@@ -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 " <library>
.BI "include " <library>
.SH DESCRIPTION
The
.I %include
.I include
utility sources a script header (by default) from /usr/lib/zrc/stdlib.
1 change: 1 addition & 0 deletions doc/man1/not.1
2 changes: 1 addition & 1 deletion examples/graph.zrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/minesweeper.zrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!../bin/zrc
%include 'cfuncs'
%include 'list'
include cfuncs
include list

##################
# Reset terminal #
Expand Down
2 changes: 1 addition & 1 deletion examples/quicksort.zrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
###########################################
# Trivial quicksort implementation in Zrc.#
###########################################
%include list
include list

fn quicksort {
let {m pivot less equal greater vn x} {
Expand Down
2 changes: 1 addition & 1 deletion src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
5 changes: 2 additions & 3 deletions src/dispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -829,7 +829,6 @@ Command(help);
const DispatchTable<std::string, std::function<std::string(int, char**)>> dispatch_table = {
/* Aliased commands */
ce(!,not) , ce(.,source), ce(@,fork),
ce(%include , include),

/* Normal cmds */
de(alias) , de(array) , de(bg),
Expand All @@ -846,7 +845,7 @@ const DispatchTable<std::string, std::function<std::string(int, char**)>> 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 **/
Expand Down
5 changes: 4 additions & 1 deletion src/expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] == '(') {
Expand Down
1 change: 0 additions & 1 deletion stdlib/cfuncs.zrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ alias sizeof { array length }
# Other #
#########
alias puts { echo }
alias fork { @ }
alias new { malloc char }

########################################
Expand Down
2 changes: 1 addition & 1 deletion stdlib/ipc.zrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if {![string cmp $__IPC_ZRC_INCLUDED {}]} {
set __IPC_ZRC_INCLUDED = 1

%include cfuncs
include cfuncs

############################
# Pipe 2 lists as commands #
Expand Down
2 changes: 1 addition & 1 deletion stdlib/list.zrc
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down
2 changes: 1 addition & 1 deletion stdlib/mathop.zrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if {![string cmp $__MATHOP_ZRC_INCLUDED {}]} {
set __MATHOP_ZRC_INCLUDED = 1

%include cfuncs
include cfuncs

###############################
# Helper to generate ops #
Expand Down

0 comments on commit cf7cca9

Please sign in to comment.