...
 
Commits (2)
......@@ -11,8 +11,6 @@ arguments more often than with them).
Several changes are coming shortly, which may easily break scripts designed for
this version of the shell, including the following.
* Internal functions will loose the initial "rwsh" - e.g.
rwsh.function_not_found will become .function_not_found
* Functions will not return integers - they will either successfully
complete their execution or they will throw an exception. Control flow
statements like .if or .while will respond to a specific exception
......
......@@ -126,13 +126,13 @@ std::string::size_type Arg_script::constructor(const std::string& src,
after_loop:
if (!args.size()) args.push_back(Arg_spec("", max_soon, errors));
if (is_argfunction_name(args.front().str()) && // argfunction_level handling
args.front().str() != "rwsh.mapped_argfunction")
args.front().str() != ".mapped_argfunction")
if (args.size() != 1 || argfunction)
errors.add_error(Exception(Argm::Arguments_for_argfunction, str()));
else if (args.front().str() == "rwsh.unescaped_argfunction")
else if (args.front().str() == ".unescaped_argfunction")
argfunction_level = 1;
else if (args.front().str() == "rwsh.argfunction") argfunction_level = 2;
else if (args.front().str() == "rwsh.escaped_argfunction")
else if (args.front().str() == ".argfunction") argfunction_level = 2;
else if (args.front().str() == ".escaped_argfunction")
argfunction_level = 3;
else std::abort(); // unhandled argfunction level
if (src[point] == '}') terminator = *"";
......@@ -196,8 +196,8 @@ Argm Arg_script::argm(void) const {
if (!argfunction_level) {
for(auto j: args) result.push_back(j.str());
result.set_argfunction(argfunction->copy_pointer());}
else if (argfunction_level == 1) result.push_back("rwsh.argfunction");
else if (argfunction_level == 2) result.push_back("rwsh.escaped_argfunction");
else if (argfunction_level == 1) result.push_back(".argfunction");
else if (argfunction_level == 2) result.push_back(".escaped_argfunction");
else std::abort(); // unhandled argfunction_level
return result;}
......@@ -213,9 +213,9 @@ std::string Arg_script::str(void) const {
if (argfunction) result += (result.size()?" ":"") + argfunction->str();
if (terminator) return result + terminator;
else return result;}
else if (argfunction_level == 1) return "rwsh.argfunction";
else if (argfunction_level == 2) return "rwsh.escaped_argfunction";
else if (argfunction_level == 3) return "rwsh.super_escaped_argfunction";
else if (argfunction_level == 1) return ".argfunction";
else if (argfunction_level == 2) return ".escaped_argfunction";
else if (argfunction_level == 3) return ".super_escaped_argfunction";
else {std::abort(); return "";}} // unhandled argfunction_level
Argm Arg_script::base_interpret(const Argm& src, Error_list& errors) const {
......@@ -235,12 +235,12 @@ Argm Arg_script::interpret(const Argm& src, Error_list& exceptions) const {
if (argfunction)
result.set_argfunction(argfunction->apply(src, 0, exceptions));}
else if (is_argfunction()) {
result.push_back("rwsh.mapped_argfunction");
result.push_back(".mapped_argfunction");
copy(src.begin()+1, src.end(), std::back_inserter(result));
result.set_argfunction(src.argfunction()->copy_pointer());}
else if (argfunction_level == 2)
result.push_back("rwsh.unescaped_argfunction");
else if (argfunction_level == 3) result.push_back("rwsh.argfunction");
result.push_back(".unescaped_argfunction");
else if (argfunction_level == 3) result.push_back(".argfunction");
else std::abort(); // unhandled argfunction_level
return result;}
......@@ -268,7 +268,7 @@ void Arg_script::promote_soons(unsigned nesting) {
// test whether an executable name corresponds to one of those used for
// argument functions.
bool is_argfunction_name(const std::string& focus) {
return focus == "rwsh.mapped_argfunction" ||
focus == "rwsh.unescaped_argfunction" ||
focus == "rwsh.argfunction" ||
focus == "rwsh.escaped_argfunction";}
return focus == ".mapped_argfunction" ||
focus == ".unescaped_argfunction" ||
focus == ".argfunction" ||
focus == ".escaped_argfunction";}
This diff is collapsed.
......@@ -2,70 +2,70 @@
.return 0
.function_all_flags # [args ...] {.nop $args$}
.function_all_flags fw {
.function_all_flags f1 name {rwsh.argfunction}
.which_executable f1; .echo $nl
f1 f2 {rwsh.argfunction}
.which_executable f2; .echo $nl
.function_all_flags f1 name {.argfunction}
.whence_function f1; .echo $nl
f1 f2 {.argfunction}
.whence_function f2; .echo $nl
.rm_executable f1; .rm_executable f2}
fw {.echo hi $nl; .function_all_flags $name {rwsh.argfunction}}
fw {.while .return 1 {.function_all_flags &&name {rwsh.argfunction}}}
fw {.echo hi $nl; .function_all_flags $name {.argfunction}}
fw {.while .return 1 {.function_all_flags &&name {.argfunction}}}
.function_all_flags f1 name {
.echo function name $name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}
f1 f2 {
.echo noname $1 $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of nothing $nl}
fw {
.echo function name $name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}
fw {.for 1 2 3 {
.echo function name $1 $name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}}
fw {.for 1 2 3 {rwsh.mapped_argfunction $1 {
fw {.for 1 2 3 {.mapped_argfunction $1 {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}}}
# all of the above make sense, and the next should be identical to the last
fw {rwsh.mapped_argfunction $1 {.for 1 2 3 {
fw {.mapped_argfunction $1 {.for 1 2 3 {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}}}
# mostly as wierd
fw {rwsh.mapped_argfunction rwsh.not_a_number {
fw {.mapped_argfunction .not_a_number {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}}
# normal again
fw {.try_catch_recursive rwsh.not_a_number {
fw {.try_catch_recursive .not_a_number {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}}
fw {.for 1 2 3 {.try_catch_recursive rwsh.not_a_number {
fw {.for 1 2 3 {.try_catch_recursive .not_a_number {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}}}
fw {.try_catch_recursive rwsh.not_a_number {.for 1 2 3 {
fw {.try_catch_recursive .not_a_number {.for 1 2 3 {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}}}
# maybe weird?
fw {rwsh.mapped_argfunction $1 {
fw {.mapped_argfunction $1 {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}}
# definitely weird
fw {rwsh.mapped_argfunction $name {.for a b {
fw {.mapped_argfunction $name {.for a b {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}}}
fw {rwsh.mapped_argfunction {.function_all_flags $name {rwsh.argfunction}}}
fw {.mapped_argfunction {.function_all_flags $name {.argfunction}}}
.return 0
.nop $A $FIGNORE
.function_all_flags rwsh.shutdown -- args ... {
.function_all_flags .shutdown -- args ... {
.nop $args
.combine $nl (now terminating normally) $nl}
.exit
......
......@@ -30,6 +30,7 @@ class Argm {
No_exception,
Ambiguous_prototype_dash_dash,
Arguments_for_argfunction,
Autofunction,
Bad_argc,
Bad_argfunction_style,
Bad_args,
......
This diff is collapsed.
......@@ -14,6 +14,7 @@ int b_else_if_not(const Argm& argm, Error_list& exceptions);
int b_enable_readline(const Argm& argm, Error_list& exceptions);
int b_error(const Argm& argm, Error_list& exceptions);
int b_exec(const Argm& argm, Error_list& exceptions);
int b_execution_count(const Argm& argm, Error_list& exceptions);
int b_exit(const Argm& argm, Error_list& exceptions);
int b_fallback_handler(const Argm& argm, Error_list& exceptions);
int b_for(const Argm& argm, Error_list& exceptions);
......@@ -33,6 +34,8 @@ int b_internal_functions(const Argm& argm, Error_list& exceptions);
int b_is_default_error(const Argm& argm, Error_list& exceptions);
int b_is_default_input(const Argm& argm, Error_list& exceptions);
int b_is_default_output(const Argm& argm, Error_list& exceptions);
int b_last_exception(const Argm& argm, Error_list& exceptions);
int b_last_execution_time(const Argm& argm, Error_list& exceptions);
int b_list_environment(const Argm& argm, Error_list& exceptions);
int b_list_executables(const Argm& argm, Error_list& exceptions);
int b_list_locals(const Argm& argm, Error_list& exceptions);
......@@ -51,6 +54,7 @@ int b_set_max_nesting(const Argm& argm, Error_list& exceptions);
int b_source(const Argm& argm, Error_list& exceptions);
int b_stepwise(const Argm& argm, Error_list& exceptions);
int b_store_output(const Argm& argm, Error_list& exceptions);
int b_test_executable_exists(const Argm& argm, Error_list& exceptions);
int b_test_file_exists(const Argm& argm, Error_list& exceptions);
int b_test_greater(const Argm& argm, Error_list& exceptions);
int b_test_in(const Argm& argm, Error_list& exceptions);
......@@ -62,7 +66,9 @@ int b_test_string_equal(const Argm& argm, Error_list& exceptions);
int b_test_string_unequal(const Argm& argm, Error_list& exceptions);
int b_throw(const Argm& argm, Error_list& exceptions);
int b_toggle_readline(const Argm& argm, Error_list& exceptions);
int b_total_execution_time(const Argm& argm, Error_list& exceptions);
int b_try_catch_recursive(const Argm& argm, Error_list& exceptions);
int b_type(const Argm& argm, Error_list& exceptions);
int b_unset(const Argm& argm, Error_list& exceptions);
int b_usleep(const Argm& argm, Error_list& exceptions);
int b_usleep_overhead(const Argm& argm, Error_list& exceptions);
......@@ -75,12 +81,6 @@ int b_version(const Argm& argm, Error_list& exceptions);
int b_waiting_for_binary(const Argm& argm, Error_list& exceptions);
int b_waiting_for_shell(const Argm& argm, Error_list& exceptions);
int b_waiting_for_user(const Argm& argm, Error_list& exceptions);
int b_which_executable(const Argm& argm, Error_list& exceptions);
int b_which_execution_count(const Argm& argm, Error_list& exceptions);
int b_which_last_exception(const Argm& argm, Error_list& exceptions);
int b_which_last_execution_time(const Argm& argm, Error_list& exceptions);
int b_whence_function(const Argm& argm, Error_list& exceptions);
int b_which_path(const Argm& argm, Error_list& exceptions);
int b_which_return(const Argm& argm, Error_list& exceptions);
int b_which_test(const Argm& argm, Error_list& exceptions);
int b_which_total_execution_time(const Argm& argm, Error_list& exceptions);
int b_while(const Argm& argm, Error_list& exceptions);
// The definition of the Command_stream class. It is constructed from a
// standard stream and defines an input operator for Argm objects. It also
// handles the calling of rwsh.prompt.
// handles the calling of .prompt.
//
// Copyright (C) 2005-2018 Samuel Newbold
......@@ -30,7 +30,7 @@
Command_stream::Command_stream(Rwsh_istream_p& s, bool subprompt_i) :
src(s), subprompt(subprompt_i) {}
// write the next command to dest. run rwsh.prompt as appropriate
// write the next command to dest. run .prompt as appropriate
Command_stream& Command_stream::getline(Arg_script& dest, Error_list& errors) {
if (this->fail()) return *this;
std::string cmd;
......
.global nl (
)
.for &{.internal_functions}$ {.nop
.if .test_string_unequal $1 rwsh.raw_command {
.if .test_string_unequal $1 .raw_command {
.function_all_flags &&1 -- args ... {.nop
.echo signal triggered: $0 \( $args$ \)
.combine $nl}}
.else {.function_all_flags &&1 -- args ... {.nop $args}}}
.function_all_flags rwsh.prompt {.nop}
.function_all_flags rwsh.help {.echo type the strings you want to count $nl}
.function_all_flags .prompt {.nop}
.function_all_flags .help {.echo type the strings you want to count $nl}
.binary /usr/bin/printenv
.function_all_flags rwsh.autofunction var_name {.nop
.function_all_flags .autofunction var_name {.nop
.if .var_exists $var_name {.var_add $var_name 1}
.else {.global $var_name 1; .nop $$var_name}}
.function_all_flags rwsh.function_not_found cmd ... {.nop $cmd}
.function_all_flags .function_not_found cmd ... {.nop $cmd}
.nop count even the blank lines
.rm_executable ()
.function_all_flags rwsh.shutdown -- args ... {.nop $FIGNORE $args
.function_all_flags .shutdown -- args ... {.nop $FIGNORE $args
.unset nl
/usr/bin/printenv}
......@@ -49,7 +49,7 @@ Executable_map::size_type Executable_map::erase (const std::string& key) {
Base_executable* Executable_map::find_second(const Argm& key) {
iterator i = Base::find(key[0]);
if (i != end()) return i->second;
else if (key[0] == "rwsh.mapped_argfunction") return key.argfunction();
else if (key[0] == ".mapped_argfunction") return key.argfunction();
else return nullptr;}
bool Executable_map::run_if_exists(const std::string& key, Argm& argm_i) {
......@@ -85,8 +85,9 @@ int Executable_map::run(Argm& argm, Error_list& exceptions) {
not_found(argm, exceptions);
else {
in_autofunction = true;
Argm auto_argm("rwsh.autofunction", argm.argv(), argm.argfunction(),
argm.parent_map(), argm.input, argm.output, argm.error);
Argm auto_argm(Argm::exception_names[Argm::Autofunction], argm.argv(),
argm.argfunction(), argm.parent_map(),
argm.input, argm.output, argm.error);
run(auto_argm, exceptions);
in_autofunction = false;
i = find_second(argm); // second check for key
......
// Copyright (C) 2005-2018 Samuel Newbold
// Executable_map must be able to lookup rwsh.argfunction, which is
// Executable_map must be able to lookup .argfunction, which is
// part of an Argm. Thus Argm must be the key_type so as to specify which
// rwsh.argfunction is intended. Argm are not stored in the map, so
// .argfunction is intended. Argm are not stored in the map, so
// value_type is not std::pair<key_type, mapped_type>
class Executable_map : private std::map<std::string, Base_executable*> {
typedef std::map<std::string, Base_executable*> Base;
......
......@@ -105,7 +105,7 @@ Command_block::Command_block(const std::string& src,
while (tpoint != std::string::npos && src[tpoint] != '}') {
push_back(Arg_script(src, ++tpoint, max_soon, errors));
if (size() != 1 && back().is_argfunction())
default_output <<"rwsh.argfunction cannot occur as one of several "
default_output <<".argfunction cannot occur as one of several "
"commands\n";}
if (tpoint == std::string::npos)
throw Unclosed_brace(src.substr(0, point-1));
......
.function_flag_ignorant # args ... {.nop $args}
.function if_only {.if $* {rwsh.argfunction}; .else {.nop}}
.function if_only {.if $* {.argfunction}; .else {.nop}}
.function_flag_ignorant c args ... {.combine $args$}
.function_flag_ignorant cc args {.combine $args$}
.function_all_flags a [-*] [-x b ...] c {
.for &&{.list_locals}$ {.combine $1 \( $$1 \) \ }}
.which_executable a
.whence_function a
a first
a -x first
a -x (fi rst) second
......@@ -18,13 +18,13 @@ a -x (fi rst) (sec ond) third fourth
if_only .var_exists b {c (b: ) $b$ $nl}
if_only .var_exists c {c (c: ) $c$ $nl}
}
.which_executable a
.whence_function a
a first
a -x first
a -x (fi rst) second
a -x first (sec ond) third
a -x (fi rst) (sec ond) third fourth
.which_executable if_only
.whence_function if_only
.combine &{c (sec ond)} x $nl x
.combine &{c (sec ond)}$ x $nl x
.combine &{cc (sec ond)} x $nl x
......@@ -47,7 +47,7 @@ a -x (fi rst) (sec ond) third fourth
.else_if .test_less $nest 20 {rx $lhs$ $rhs}
.else {.nop}
.var_subtract nest 1}
.which_executable recurse
.whence_function recurse
recurse a b c d e f g h i j k l m n o p q r s t u v w x y z
# recurse ((((((((a b))) (c d)) (e f)) (g h)) (i j)) k l) m n (o (p (q (r (s (t (u (v (w (x (y z)))))))))))
recurse (a b) ((c d e) ((f g h) ((i j k) ((l m n) ((o p q) ((r s t) ((u v w) ((x y z)))))))))
......
......@@ -44,79 +44,80 @@ unsigned Base_executable::current_exception_count(0);
unsigned Base_executable::dropped_catches(0);
std::string Argm::exception_names[Argm::Exception_count] = {
"no exception",
"rwsh.ambiguous_prototype_dash_dash",
"rwsh.arguments_for_argfunction",
"rwsh.bad_argc",
"rwsh.bad_argfunction_style",
"rwsh.bad_args",
"rwsh.bad_if_nest",
"rwsh.binary_does_not_exist",
"rwsh.binary_not_found",
"rwsh.dash_dash_argument",
"rwsh.dash_star_argument",
"rwsh.directory_not_found",
"rwsh.divide_by_zero",
"rwsh.double_redirection",
"rwsh.duplicate_parameter",
"rwsh.elipsis_first_arg",
"rwsh.elipsis_out_of_option_group",
"rwsh.else_without_if",
"rwsh.excess_argfunction",
"rwsh.excessive_exceptions_collected",
"rwsh.excessive_exceptions_in_catch",
"rwsh.excessive_nesting",
"rwsh.exec_failed",
"rwsh.executable_already_exists",
"rwsh.failed_substitution",
"rwsh.file_open_failure",
"rwsh.file_not_found",
"rwsh.flag_in_elipsis",
"rwsh.function_not_found",
"rwsh.if_before_else",
"rwsh.illegal_function_name",
"rwsh.illegal_variable_name",
"rwsh.input_range",
"rwsh.internal_error",
"rwsh.invalid_word_selection",
// "rwsh.line_continuation",
"rwsh.mismatched_brace",
"rwsh.mismatched_bracket",
"rwsh.mismatched_parenthesis",
"rwsh.missing_argfunction",
"rwsh.multiple_argfunctions",
"rwsh.not_a_directory",
"rwsh.not_a_function",
"rwsh.not_a_number",
"rwsh.not_executable",
"rwsh.not_soon_enough",
"rwsh.raw_command",
"rwsh.return_code",
"rwsh.result_range",
"rwsh.post_elipsis_option",
"rwsh.post_dash_dash_flag",
"rwsh.prompt",
"rwsh.selection_not_found",
"rwsh.shutdown",
"rwsh.sighup",
"rwsh.sigint",
"rwsh.sigquit",
"rwsh.sigpipe",
"rwsh.sigterm",
"rwsh.sigtstp",
"rwsh.sigcont",
"rwsh.sigchld",
"rwsh.sigusr1",
"rwsh.sigusr2",
"rwsh.sigunknown",
"rwsh.tardy_flag",
"rwsh.unchecked_variable",
"rwsh.undeclared_variable",
"rwsh.undefined_variable",
"rwsh.unreadable_dir",
"rwsh.unrecognized_flag",
"rwsh.unused_before_set",
"rwsh.unused_variable",
"rwsh.version_incompatible"};
".ambiguous_prototype_dash_dash",
".arguments_for_argfunction",
".autofunction",
".bad_argc",
".bad_argfunction_style",
".bad_args",
".bad_if_nest",
".binary_does_not_exist",
".binary_not_found",
".dash_dash_argument",
".dash_star_argument",
".directory_not_found",
".divide_by_zero",
".double_redirection",
".duplicate_parameter",
".elipsis_first_arg",
".elipsis_out_of_option_group",
".else_without_if",
".excess_argfunction",
".excessive_exceptions_collected",
".excessive_exceptions_in_catch",
".excessive_nesting",
".exec_failed",
".executable_already_exists",
".failed_substitution",
".file_open_failure",
".file_not_found",
".flag_in_elipsis",
".function_not_found",
".if_before_else",
".illegal_function_name",
".illegal_variable_name",
".input_range",
".internal_error",
".invalid_word_selection",
// ".line_continuation",
".mismatched_brace",
".mismatched_bracket",
".mismatched_parenthesis",
".missing_argfunction",
".multiple_argfunctions",
".not_a_directory",
".not_a_function",
".not_a_number",
".not_executable",
".not_soon_enough",
".raw_command",
".return_code",
".result_range",
".post_elipsis_option",
".post_dash_dash_flag",
".prompt",
".selection_not_found",
".shutdown",
".sighup",
".sigint",
".sigquit",
".sigpipe",
".sigterm",
".sigtstp",
".sigcont",
".sigchld",
".sigusr1",
".sigusr2",
".sigunknown",
".tardy_flag",
".unchecked_variable",
".undeclared_variable",
".undefined_variable",
".unreadable_dir",
".unrecognized_flag",
".unused_before_set",
".unused_variable",
".version_incompatible"};
bool readline_enabled = false;
Variable_map root_variable_map(nullptr);
unsigned Base_executable::max_nesting = 0;
......@@ -174,10 +175,10 @@ int main(int argc, char *argv[]) {
else if (command_stream.fail()) break;
else command = script.base_interpret(script.argm(), exceptions);}
catch (Exception exception) {command = exception;}
executable_map.run_if_exists("rwsh.before_command", command);
if (!executable_map.run_if_exists("rwsh.run_logic", command))
executable_map.run_if_exists(".before_command", command);
if (!executable_map.run_if_exists(".run_logic", command))
executable_map.base_run(command, exceptions);
executable_map.run_if_exists("rwsh.after_command", command);}
executable_map.run_if_exists(".after_command", command);}
Argm shutdown_command(Argm::exception_names[Argm::Shutdown],
std_argv, nullptr, Variable_map::global_map,
default_input, default_output, default_error);
......
......@@ -45,6 +45,8 @@ void internal_init(Error_list& exceptions) {
executable_map.set(new Builtin(".else_if", b_else_if));
executable_map.set(new Builtin(".else_if_not", b_else_if_not));
executable_map.set(new Builtin(".exec", b_exec));
executable_map.set(new Builtin(".execution_count",
b_execution_count));
executable_map.set(new Builtin(".exit", b_exit));
executable_map.set(new Builtin(".fallback_handler", b_fallback_handler));
executable_map.set(new Builtin(".get_fallback_message",
......@@ -67,22 +69,22 @@ void internal_init(Error_list& exceptions) {
executable_map.set(new Function(".init",
any_args.begin(), any_args.end(), false,
"{.set_max_nesting 10\n"
" .function_all_flags rwsh.file_open_failure name stack ... {"
" .function_all_flags .file_open_failure name stack ... {"
" .combine (init file ) $name ( does not exist\n"
"call stack ) $stack (\n)}\n"
" .function_all_flags rwsh.raw_command -- args ... {.nop $args}\n"
" .function_all_flags .raw_command -- args ... {.nop $args}\n"
" .source /etc/rwshrc $args$\n"
" .for &{.internal_functions}$ {" //.echo $1; .which_executable $1}\n"
" .if .which_test $1 {.nop}\n"
" .for &{.internal_functions}$ {" //.echo $1; .whence_function $1}\n"
" .if .test_executable_exists $1 {.nop}\n"
" .else {.echo &&1 not defined (\n)}}\n"
" .if .which_test rwsh.help {"
" .if .test_not_empty &&{rwsh.help} {.nop}\n"
" .else {.echo rwsh.help produces no output (\n)}}\n"
" .else {.echo rwsh.help not defined (\n)}}", exceptions));
" .if .test_executable_exists .help {"
" .if .test_not_empty ${.help} {.nop}\n"
" .else {.echo .help produces no output (\n)}}\n"
" .else {.echo .help not defined (\n)}}", exceptions));
executable_map.set(new Function(".internal_features",
empty_prototype.begin(), empty_prototype.end(), false,
"{.if .test_number_equal $# 1 {"
".echo rwsh.after_command rwsh.before_command rwsh.run_logic}; "
".echo .after_command .before_command .run_logic}; "
".else {.echo wrong argument count; .return -1}}", exceptions));
executable_map.set(new Builtin(".internal_functions", b_internal_functions));
executable_map.set(new Function(".internal_vars",
......@@ -93,6 +95,10 @@ void internal_init(Error_list& exceptions) {
executable_map.set(new Builtin(".is_default_input", b_is_default_input));
executable_map.set(new Builtin(".is_default_output", b_is_default_output));
executable_map.set(new Builtin(".is_default_error", b_is_default_error));
executable_map.set(new Builtin(".last_exception",
b_last_exception));
executable_map.set(new Builtin(".last_execution_time",
b_last_execution_time));
executable_map.set(new Builtin(".list_environment", b_list_environment));
executable_map.set(new Builtin(".list_executables", b_list_executables));
executable_map.set(new Builtin(".list_locals", b_list_locals));
......@@ -114,6 +120,8 @@ void internal_init(Error_list& exceptions) {
executable_map.set(new Builtin(".source", b_source));
executable_map.set(new Builtin(".stepwise", b_stepwise));
executable_map.set(new Builtin(".store_output", b_store_output));
executable_map.set(new Builtin(".test_executable_exists",
b_test_executable_exists));
executable_map.set(new Builtin(".test_file_exists", b_test_file_exists));
executable_map.set(new Builtin(".test_greater", b_test_greater));
executable_map.set(new Builtin(".test_is_number", b_test_is_number));
......@@ -126,26 +134,19 @@ void internal_init(Error_list& exceptions) {
b_test_string_unequal));
executable_map.set(new Builtin(".throw", b_throw));
executable_map.set(new Builtin(".toggle_readline", b_toggle_readline));
executable_map.set(new Builtin(".total_execution_time",
b_total_execution_time));
executable_map.set(new Builtin(".try_catch_recursive",
b_try_catch_recursive));
executable_map.set(new Builtin(".type", b_type));
executable_map.set(new Builtin(".unset", b_unset));
executable_map.set(new Builtin(".usleep", b_usleep));
executable_map.set(new Builtin(".usleep_overhead", b_usleep_overhead));
executable_map.set(new Builtin(".waiting_for_binary", b_waiting_for_binary));
executable_map.set(new Builtin(".waiting_for_shell", b_waiting_for_shell));
executable_map.set(new Builtin(".waiting_for_user", b_waiting_for_user));
executable_map.set(new Builtin(".which_executable", b_which_executable));
executable_map.set(new Builtin(".which_execution_count",
b_which_execution_count));
executable_map.set(new Builtin(".which_last_exception",
b_which_last_exception));
executable_map.set(new Builtin(".which_last_execution_time",
b_which_last_execution_time));
executable_map.set(new Builtin(".whence_function", b_whence_function));
executable_map.set(new Builtin(".which_path", b_which_path));
executable_map.set(new Builtin(".which_return", b_which_return));
executable_map.set(new Builtin(".which_test", b_which_test));
executable_map.set(new Builtin(".which_total_execution_time",
b_which_total_execution_time));
executable_map.set(new Builtin(".while", b_while));
executable_map.set(new Builtin(".var_add", b_var_add));
executable_map.set(new Builtin(".var_divide", b_var_divide));
......
......@@ -3,10 +3,10 @@
.set_max_nesting 20
.function_all_flags () {.nop}
.function_all_flags #! -- ignored ... {.nop $ignored}
.function_all_flags rwsh.autofunction -- cmd [args ...] {
.function_all_flags .autofunction -- cmd [args ...] {
.nop $args$
.local full_path ${.which_path $cmd $PATH}
if_only_not .which_test $full_path {.binary $full_path}
if_only_not .test_executable_exists $full_path {.binary $full_path}
if_only_not .test_string_equal $cmd $full_path {
.function_all_flags $cmd -- [args ...] {
&&full_path $args$}}
......@@ -26,10 +26,10 @@
.global $var $val
.nop $$var}}
.source /etc/rwshrc-basic
.function_all_flags rwsh.if_before_else stack ... {.nop $stack}
.function_all_flags rwsh.shutdown -- args ... {.nop $args; .return 0}
.function_all_flags .if_before_else stack ... {.nop $stack}
.function_all_flags .shutdown -- args ... {.nop $args; .return 0}
.collect_errors_except .nop {
rwsh.mapped_argfunction &3 {$1$}
.mapped_argfunction &3 {$1$}
.exit}}
.else {
.echo unexpected command line: &* (
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
.disable_readline
.enable_readline
.try_catch_recursive rwsh.unused_variable {.collect_errors_except .nop {
.try_catch_recursive .unused_variable {.collect_errors_except .nop {
# set up environment
.function_all_flags set_if_undefined -- var [value] {
.if .var_exists $var {.nop $value$}
......@@ -97,7 +97,7 @@ sfn-subcommand git status
fns grep [-l] [regex] [file ...] {
if_only .var_exists regex {.set REGEX $regex}
if_only .var_exists file {.selection_set s $file}
.try_catch_recursive rwsh.return_code {
.try_catch_recursive .return_code {
.if var_exists -l {
.local result ()
.nop $result
......@@ -106,7 +106,6 @@ fns grep [-l] [regex] [file ...] {
.set grep-sel $result$}
.else {&{whichp grep} $-*$ $REGEX @$s}}}
fn grep-sel {.set s $grep-sel}
fn gs {.set s $grep-sel}
sfn gzip
sfn gunzip
fn home {cd $HOME}
......@@ -151,13 +150,13 @@ sfn wc
fn unselect {.set s ()}
# internal functions
.function_all_flags rwsh.run_logic -- cmd [args ...] {
.try_catch_recursive &{.internal_functions}$ {$cmd $args$ {rwsh.argfunction}}
# $* {rwsh.argfunction}
.function_all_flags .run_logic -- cmd [args ...] {
.try_catch_recursive &{.internal_functions}$ {$cmd $args$ {.argfunction}}
# $* {.argfunction}
.local ret $?
if_only_not .test_number_equal $ret 0 {echo $cmd returned $ret}}
.function_all_flags rwsh.prompt {.echo $s; .echo \$}
.function_all_flags rwsh.vars {
.function_all_flags .prompt {.echo $s; .echo \$}
.function_all_flags .vars {
.internal_vars
echo $nl HOME $HOME
echo REGEX $REGEX
......@@ -165,18 +164,18 @@ fn unselect {.set s ()}
# misc
.function_all_flags . -- command ... {.source $command$}
.function_all_flags ex_count -- cmd {.which_execution_count $cmd; c $nl}
.function_all_flags ex_count -- cmd {.execution_count $cmd; c $nl}
.function_all_flags exec -- command ... {.exec $command$ }
.function_all_flags exit {.exit}
.function_all_flags last_time cmd {.which_last_execution_time $cmd; c $nl}
.function_all_flags last_time cmd {.last_execution_time $cmd; c $nl}
fn local {. &{c $HOME /.rwshrc}}
fn mark {ntimes 4 {.echo ####################}; c $nl}
fn ret {.return $*}
.function_all_flags timings cmd {
.echo last time (); .which_last_execution_time $cmd; c $nl
.echo total time (); .which_total_execution_time $cmd; c $nl
.echo execution count (); .which_execution_count $cmd; c $nl}
.function_all_flags total_time cmd {.which_total_execution_time $cmd; c $nl}
.echo last time (); .last_execution_time $cmd; c $nl
.echo total time (); .total_execution_time $cmd; c $nl
.echo execution count (); .execution_count $cmd; c $nl}
.function_all_flags total_time cmd {.total_execution_time $cmd; c $nl}
.function_all_flags user_shell_ratio {
.local time &&{.waiting_for_user}
.var_divide time &&{.waiting_for_shell}
......@@ -217,9 +216,13 @@ fn qt [-?] [-nc] {
&{whichp diff} $-?$ test_quick.result last.test_quick.result}
.else {&{whichp diff} -c test_quick.result last.test_quick.result}}}
fn bless-qt {&{whichp cp} last.test_quick.result test_quick.result}
fn arg-out {/bin/rwsh -to <argfunction.sh}
fn arg-diff {/bin/rwsh -to <argfunction.sh >argfunction.result.last
&{whichp diff} -c argfunction.basic-result argfunction.result.last}
fn arg-out {./rwsh -to <argfunction.sh}
fn arg-diff [-?] {
arg-out >argfunction.result.last
.if .test_not_empty $-? {
&{whichp diff} $-?$ argfunction.basic-result argfunction.result.last}
.else {&{whichp diff} -c argfunction.basic-result argfunction.result.last}}
fn bless-arg {&{whichp cp} argfunction.result.last argfunction.basic-result}
# final setup and individual configuration
.source &{c $HOME /.rwshrc}
......
This diff is collapsed.
This diff is collapsed.
......@@ -3,9 +3,9 @@
.getpid
.getppid
.function_all_flags timings focus {
.combine $focus (: last\() ${.which_last_execution_time $focus} \) \
.combine (total\() ${.which_total_execution_time $focus} \) \
.combine (count\() ${.which_execution_count $focus} \) $nl}
.combine $focus (: last\() ${.last_execution_time $focus} \) \
.combine (total\() ${.total_execution_time $focus} \) \
.combine (count\() ${.execution_count $focus} \) $nl}
.function_all_flags clock-watch {
.usleep 600
/bin/true
......@@ -16,7 +16,7 @@
timings /bin/true}
clock-watch
clock-watch
rwsh.mapped_argfunction {timings timings; timings clock-watch}
.mapped_argfunction {timings timings; timings clock-watch}
.error a stderr print will come before the diff $nl
.nop $A $FIGNORE
.global nl (
)
.try_catch_recursive rwsh.file_open_failure {
.try_catch_recursive .file_open_failure {
.source /non-existent/file/to/test/failure}
.function_all_flags rwsh.raw_command -- cmd {.echo $cmd; .echo $nl}
.for ${.echo rwsh.sigterm rwsh.multiple_argfunctions}$ {.nop
.function_all_flags $1 {.echo signal triggered: $0 \( \); .combine $nl; .return -1}}
.function_all_flags .raw_command -- cmd {.echo $cmd; .echo $nl}
.global last_command_return -10
.global A \
.global N \
.nop $N
.nop .function_all_flags rwsh.run_logic -- cmd [args ...] {
.nop .function_all_flags .run_logic -- cmd [args ...] {
.return $last_command_return
.signal_handler &{.internal_functions}$ {&&* {rwsh.argfunction}}
rwsh.mapped_argfunction {&&* {rwsh.argfunction}}
&&* {rwsh.argfunction}
.signal_handler &{.internal_functions}$ {&&* {.argfunction}}
.mapped_argfunction {&&* {.argfunction}}
&&* {.argfunction}
.set last_command_return $?
.echo $nl
.echo $last_command_return
.echo $nl}
.function_all_flags rwsh.before_command -- args ... {
.function_all_flags .before_command -- args ... {
.nop $args
.return $last_command_return}
.function_all_flags rwsh.after_command -- args ... {
.function_all_flags .after_command -- args ... {
.nop $args
.set last_command_return $?
.combine $nl $last_command_return $nl}
.function_all_flags rwsh.prompt {.echo \$}
.function_all_flags rwsh.vars {.internal_vars}
.function_all_flags .prompt {.echo \$}
.function_all_flags .vars {.internal_vars}
.source /etc/rwshrc-basic
This diff is collapsed.
This diff is collapsed.
.function_all_flags a [-*] [-x b ...] c {
.for &&{.list_locals}$ {.combine $1 \( $$1 \) \ }}
.nop $A $FIGNORE
.which_executable a
.whence_function a
a first
a -x first
a -x (fi rst) second
......@@ -15,7 +15,7 @@ a -x (fi rst) (sec ond) third fourth
# if_only .var_exists b {c (b: ) $b$ $nl}
# if_only .var_exists c {c (c: ) $c$ $nl}
}
.which_executable a
.whence_function a
a first
a -x first
a -x (fi rst) second
......