Commit 762c9e3d authored by Samuel Newbold's avatar Samuel Newbold

Remove leading rwsh from internal function names

parent 9792d9ba
......@@ -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}
.function_all_flags f1 name {.argfunction}
.whence_function f1; .echo $nl
f1 f2 {rwsh.argfunction}
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
.whence_function rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}
f1 f2 {
.echo noname $1 $nl
.whence_function rwsh.argfunction {rwsh.argfunction}
.whence_function .argfunction {.argfunction}
.echo $nl end of nothing $nl}
fw {
.echo function name $name $nl
.whence_function 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
.whence_function 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
.whence_function 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
.whence_function 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
.whence_function 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
.whence_function 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
.whence_function 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
.whence_function 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
.whence_function 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
.whence_function 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,
......
......@@ -84,7 +84,7 @@ int b_collect_errors_except(const Argm& argm, Error_list& exceptions) {
if (Named_executable::unwind_stack()) return 0;
Argm blank(argm.parent_map(), argm.input, argm.output.child_stream(),
argm.error);
blank.push_back("rwsh.mapped_argfunction");
blank.push_back(".mapped_argfunction");
std::vector<std::string> exceptional(argm.begin()+1, argm.end());
return argm.argfunction()->collect_errors_core(blank, exceptional, true,
exceptions);}
......@@ -100,7 +100,7 @@ int b_collect_errors_only(const Argm& argm, Error_list& exceptions) {
if (Named_executable::unwind_stack()) return 0;
Argm blank(argm.parent_map(), argm.input, argm.output.child_stream(),
argm.error);
blank.push_back("rwsh.mapped_argfunction");
blank.push_back(".mapped_argfunction");
std::vector<std::string> exceptional(argm.begin()+1, argm.end());
return argm.argfunction()->collect_errors_core(blank, exceptional, false,
exceptions);}
......@@ -209,7 +209,7 @@ int b_for(const Argm& argm, Error_list& exceptions) {
if (!argm.argfunction()) throw Exception(Argm::Missing_argfunction);
int ret = -1;
Argm body(argm.parent_map(), argm.input, argm.output, argm.error);
body.push_back("rwsh.mapped_argfunction");
body.push_back(".mapped_argfunction");
body.push_back("");
for (auto i: argm.subrange(1)) {
if (argm.argfunction()) {
......@@ -229,7 +229,7 @@ int b_for_each_line(const Argm& argm, Error_list& exceptions) {
std::string line;
// shouldn't interfere with input being consumed by this builtin
Argm body(argm.parent_map(), default_input, argm.output, argm.error);
body.push_back("rwsh.mapped_argfunction");
body.push_back(".mapped_argfunction");
argm.input.getline(line);
if (argm.input.fail() && !line.size()) break;
tokenize(line, std::back_inserter(body),
......@@ -359,7 +359,7 @@ int if_core(const Argm& argm, Error_list& exceptions, bool logic, bool is_else){
if (argm.argfunction()) {
Argm mapped_argm(argm.parent_map(),
argm.input, argm.output.child_stream(), argm.error);
mapped_argm.push_back("rwsh.mapped_argfunction");
mapped_argm.push_back(".mapped_argfunction");
ret = (*argm.argfunction())(mapped_argm, exceptions);}
if (Base_executable::unwind_stack())
conditional_block_exception = ! is_else;
......@@ -702,7 +702,7 @@ int b_stepwise(const Argm& argm, Error_list& exceptions) {
int ret = -1;
for (auto j: f->body) {
Argm body_i(j.interpret(params, exceptions));
Argm body("rwsh.mapped_argfunction", body_i.argv(), nullptr,
Argm body(".mapped_argfunction", body_i.argv(), nullptr,
body_i.parent_map(), body_i.input, body_i.output, body_i.error);
ret = (*argm.argfunction())(body, exceptions);
if (Named_executable::unwind_stack()) {
......@@ -720,7 +720,7 @@ int b_store_output(const Argm& argm, Error_list& exceptions) {
Substitution_stream text;
Argm mapped_argm(argm.parent_map(),
argm.input, text.child_stream(), argm.error);
mapped_argm.push_back("rwsh.mapped_argfunction");
mapped_argm.push_back(".mapped_argfunction");
int ret = (*argm.argfunction())(mapped_argm, exceptions);
if (Named_executable::unwind_stack()) return -1;
if (ret) return ret;
......@@ -731,7 +731,7 @@ int b_store_output(const Argm& argm, Error_list& exceptions) {
int b_test_executable_exists(const Argm& argm, Error_list& exceptions) {
if (argm.argc() != 2) throw Exception(Argm::Bad_argc, argm.argc()-1, 1, 0);
Argm lookup(argm.subrange(1), argm.argfunction(), argm.parent_map());
if (lookup[0] == "rwsh.argfunction") lookup[0] = "rwsh.mapped_argfunction";
if (lookup[0] == ".argfunction") lookup[0] = ".mapped_argfunction";
return !executable_map.find_second(lookup);}
// list the files specified by the arguments if they exist
......@@ -860,7 +860,7 @@ int b_try_catch_recursive(const Argm& argm, Error_list& exceptions) {
if (!argm.argfunction()) throw Exception(Argm::Missing_argfunction);
Argm mapped_argm(argm.parent_map(),
argm.input, argm.output.child_stream(), argm.error);
mapped_argm.push_back("rwsh.mapped_argfunction");
mapped_argm.push_back(".mapped_argfunction");
int ret = (*argm.argfunction())(mapped_argm, exceptions);
if (Named_executable::unwind_stack()) {
Base_executable::catch_blocks(argm, exceptions);
......@@ -872,7 +872,7 @@ int b_type(const Argm& argm, Error_list& exceptions) {
exceptions.add_error(Exception(Argm::Bad_argc, argm.argc()-1, 1, 0));
if (Named_executable::unwind_stack()) return 0;
Argm lookup(argm.subrange(1), argm.argfunction(), argm.parent_map());
if (lookup[0] == "rwsh.argfunction") lookup[0] = "rwsh.mapped_argfunction";
if (lookup[0] == ".argfunction") lookup[0] = ".mapped_argfunction";
Base_executable *e = executable_map.find_second(lookup);
if (!e) exceptions.add_error(Exception(Argm::Function_not_found, argm[1]));
else if (dynamic_cast<Function*>(e)) argm.output <<"function";
......@@ -884,7 +884,7 @@ int b_type(const Argm& argm, Error_list& exceptions) {
// removes the given variable from the variable map. you could be really
// pedantic and throw an rwsh.undefined_variable if it doesn't exist, but the
// pedantic and throw an .undefined_variable if it doesn't exist, but the
// fact is that the requested state (one where this variable isn't set) is
// already the case, so it's hard to say what you're protecting people from.
int b_unset(const Argm& argm, Error_list& exceptions) {
......@@ -1044,7 +1044,7 @@ int b_waiting_for_user(const Argm& argm, Error_list& exceptions) {
int b_whence_function(const Argm& argm, Error_list& exceptions) {
if (argm.argc() != 2) throw Exception(Argm::Bad_argc, argm.argc()-1, 1, 0);
Argm lookup(argm.subrange(1), argm.argfunction(), argm.parent_map());
if (lookup[0] == "rwsh.argfunction") lookup[0] = "rwsh.mapped_argfunction";
if (lookup[0] == ".argfunction") lookup[0] = ".mapped_argfunction";
Base_executable* focus = executable_map.find_second(lookup);
if (focus) {
argm.output <<focus->str();
......@@ -1087,7 +1087,7 @@ int b_while(const Argm& argm, Error_list& exceptions) {
if (Named_executable::unwind_stack()) return -1;
Argm mapped_argm(argm.parent_map(), argm.input, argm.output.child_stream(),
argm.error);
mapped_argm.push_back("rwsh.mapped_argfunction");
mapped_argm.push_back(".mapped_argfunction");
ret = (*argm.argfunction())(mapped_argm, exceptions);
if (Named_executable::unwind_stack()) return -1;}
return ret;}
......
// 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 {
......
......@@ -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);
......
......@@ -69,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; .whence_function $1}\n"
" .if .test_executable_exists $1 {.nop}\n"
" .else {.echo &&1 not defined (\n)}}\n"
" .if .test_executable_exists 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",
......
......@@ -3,7 +3,7 @@
.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 .test_executable_exists $full_path {.binary $full_path}
......@@ -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
......@@ -150,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
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -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.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment