DACSEXPR(1) | DACS Commands Manual | DACSEXPR(1) |
NAME¶
dacsexpr - DACS expression language shell and interpreter
SYNOPSIS¶
dacsexpr [-x] [dacsoptions[1]]
[-dl] [-e expr] [-n] [-p]
[-s] [-h | -help] [-test]
[--] [filename] [script-arg...]
DESCRIPTION¶
This program is part of the DACS suite.
The dacsexpr utility evaluates DACS expressions (see dacs.exprs(5)[2]). It is often a useful aid when composing or testing expressions to be used in access control rules, or when debugging ACLs and configuration directives. While they continue to be referred to as "expressions" for historical reasons, it has become possible to write small programs, and the language can also be useful as a simple scripting language independent of the rest of DACS.
If an expression is provided, it is evaluated and the result is printed to the standard output. At most one expression can be specified. If the -q flag is given (one of the dacsoptions[1]), nothing is printed, expression evaluation errors are suppressed, and the program terminates with an appropriate exit status[3]; otherwise the result is written to the standard output. If neither a -q flag is given nor any flag that controls the logging level, then the logging level is set to warn overriding any configuration file logging level directive; this behaviour is usually convenient.
If no expression is provided, the program reads its standard input. If the input is not coming from a terminal type device, the program runs in "batch mode" and prompting is suppressed; otherwise, the program runs in "interactive mode". When prompted in interactive mode, enter help for assistance. If the readline(3)[4] functionality was configured when the program was built, command line editing and history are available in interactive mode.
A script can be executed through the system's "#!" mechanism:
#!/usr/local/dacs/bin/dacsexpr printf("%s\n", "Hello, world.")
Such programs always use the script file as input, therefore no expression or other file can be specified on the "#!" line.
Command line arguments can be passed to a script. If dig-it contains:
#!/usr/local/dacs/bin/dacsexpr if (${Argv::#} != 3) {
printf("Usage: dig-it digest-name msg\n");
exit(1); } printf("%s\n", digest(${Argv::2}, 0, ${Argv::1}));
then running the script produces:
% ./dig-it sha3-224 mymsg 88fdaa49d0371a79efa2d6e8a55d27d62cd39ad393309d9a18665763
The Env namespace is initialized from the program's environment. For example, if the value of the environment variable LOGNAME is bobo, then ${Env::LOGNAME} will be instantiated with that value. Syntactically invalid variable names are silently ignored.
An empty Expr namespace is created. In interactive use, the prompt string can be changed by assigning a string to ${Expr::prompt} and the continuation prompt can be changed by setting ${Expr::prompt2}.
Note
Configuration directives and the Conf variable namespace are available only if a configuration file is processed (e.g., by giving the -uj command line flag). This is relevant, for example, if the http()[5] function is called using the https scheme because proper operation will require the SSL_PROG[6] directive to be configured. See dacs.conf(5)[7].
OPTIONS¶
If an expression or file has not already been specified, a filename may appear as the last argument. If filename is "-", the standard input is read.
-dl
-e expr
-h
-help
-n
-p
-s
-test
#!/usr/local/dacs/bin/dacsexpr -test // expect-exact:17 ${x} = 17;
A test case consists of options followed by an expression. There can be zero or more options, one per line, embedded within a // style comment:
{ whitespace* "//" whitespace* option-name ":" option-value end-of-line }*
No whitespace is allowed before or after the ":". As a special case, lines having the following format are ignored:
whitespace* "///" .* end-of-line
The first non-option line terminates the options and is the first line of the expression to be evaluated.
Here is an example:
/// Test bitwise shifts // expect-exact:1024 1 << 10
An option controls how the test is to be performed and gives the expected result:
expect:regex
expect-regex:regex
expect-identical:string
expect-exact:string
expect-code:code
expect-type:type
expect-flags:flags
show-result:{yes | no}
If the test fails, a descriptive message is printed to the standard error. The program's exit status will be 0 if the test was successful, 1 otherwise.
This example should succeed without displaying the result:
// expect-exact:2 // expect-type:integer /// show-result:yes 1 + 1
Note
The DACS distribution includes a set of test cases in the src/tests directory that can be run for regression testing (do "make tests" from the src directory). Some of the functions provided by dacs.exprs(5)[2] are also used internally by DACS, so it is critical that all tests are successful even for functions that are not used from the user level.
-x
--
EXAMPLES¶
The following command evaluates the expression argument (note that it is a single argument to the command) and outputs the result to stdout:
% dacsexpr -e "1+1" 2 % dacsexpr -e '${Env::USER}' "bobo" % dacsexpr -u example.com -e '"FEDERATION_NAME=" . ${Conf::FEDERATION_NAME}' "FEDERATION_NAME=EXAMPLE" % dacsexpr - a b c <<HERE ? print("First arg is \"\${Argv::1}\"") ? HERE First arg is "a" % cat ex #!/usr/local/dacs/bin/dacsexpr print("Argv[2] is ${Argv::2}"); % chmod 0755 ex % ./ex foo bar baz Argv[2] is bar
DIAGNOSTICS¶
If an error occurs, a message may be written to stderr, depending on the logging level. In general, the program exits 0 if and only if everything was fine. If a command line expression is evaluated, the program exits 0 if the expression evaluates to True, 1 if it evaluates to False, and 2 if an error occurs. If an explicit call to exit() is made and no true error condition occurred, then the program will exit with the argument value.
SEE ALSO¶
dacs.exprs(5)[2]
BUGS¶
New and little-used features should be used with care. This advice applies to all software.
AUTHOR¶
Distributed Systems Software (www.dss.ca[9])
COPYING¶
Copyright © 2003-2018 Distributed Systems Software. See the LICENSE[10] file that accompanies the distribution for licensing information.
NOTES¶
- 1.
- dacsoptions
- 2.
- dacs.exprs(5)
- 3.
- exit status
- 4.
- readline(3)
- 5.
- http()
- 6.
- SSL_PROG
- 7.
- dacs.conf(5)
- 8.
- from()
- 9.
- www.dss.ca
- 10.
- LICENSE
08/23/2020 | DACS 1.4.40 |