Commit c776e510 authored by Samuel Newbold's avatar Samuel Newbold

Raise exceptions in .cd .which_path .function .exec .ls

Function not found - if the meaning of “Executable not found” is confusing to
me, there's no reason why anybody else should understand it:
    s/rwsh.executable_not_found/rwsh.function_not_found/g

Oh, and stop printing trailing whitespace in exception handlers
parent 34a9dee9
......@@ -34,9 +34,11 @@ class Argm {
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,
......@@ -47,11 +49,14 @@ class Argm {
Excessive_exceptions_collected,
Excessive_exceptions_in_catch,
Excessive_nesting,
Executable_not_found,
Exec_failed,
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,
......@@ -63,6 +68,7 @@ class Argm {
Missing_argfunction,
Multiple_argfunctions,
Not_a_number,
Not_a_directory,
Not_executable,
Not_soon_enough,
Raw_command,
......
This diff is collapsed.
......@@ -48,6 +48,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_file_exists(const Argm& argm, Error_list& exceptions);
int b_test_greater(const Argm& argm, Error_list& exceptions);
int b_test_is_number(const Argm& argm, Error_list& exceptions);
int b_test_less(const Argm& argm, Error_list& exceptions);
......
......@@ -149,7 +149,6 @@ void Base_executable::catch_blocks(const Argm& argm,
Binary::Binary(const std::string& impl) : implementation(impl) {}
#include <iostream>
// run the given binary
int Binary::execute(const Argm& argm_i, Error_list& exceptions) const {
int ret,
......@@ -158,14 +157,15 @@ int Binary::execute(const Argm& argm_i, Error_list& exceptions) const {
error = argm_i.error.fd();
if (!fork()) {
plumber.after_fork();
if (dup2(input, 0) < 0) std::cerr <<"dup2 didn't like changing input\n";
if (dup2(output, 1) < 0) std::cerr <<"dup2 didn't like changing output\n";
if (dup2(error, 2) < 0) std::cerr <<"dup2 didn't like changing error\n";
if (dup2(input, 0) < 0) argm_i.error <<"dup2 didn't like changing input\n";
if (dup2(output, 1) < 0)
argm_i.error <<"dup2 didn't like changing output\n";
if (dup2(error, 2) < 0) argm_i.error <<"dup2 didn't like changing error\n";
Old_argv argv(argm_i);
std::vector<char *>env;
argm_i.export_env(env);
ret = execve(implementation.c_str(), argv.argv(), &env[0]);
Exception error_argm(Argm::Binary_not_found, argm_i[0]);
Exception error_argm(Argm::Binary_does_not_exist, argm_i[0]);
executable_map.run(error_argm, exceptions);
executable_map.unused_var_check_at_exit();
exit(ret);}
......
......@@ -98,12 +98,12 @@ int Executable_map::run(Argm& argm, Error_list& exceptions) {
return -1;}}
int Executable_map::not_found(Argm& argm_i, Error_list& exceptions) {
Exception temp_argm(Argm::Executable_not_found, argm_i[0]);
Exception temp_argm(Argm::Function_not_found, argm_i[0]);
Base_executable* i = find(temp_argm);
if (!i) { // reset executable_not_found
std::string::size_type point = 0;
set(new Function(Argm::exception_names[Argm::Executable_not_found],
set(new Function(Argm::exception_names[Argm::Function_not_found],
"{.echo $1 (: command not found) \\( $* \\) (\n)\n"
".return -1}", point, 0, exceptions));}
throw Exception(Argm::Executable_not_found, argm_i);}
throw Exception(Argm::Function_not_found, argm_i);}
......@@ -51,9 +51,11 @@ std::string Argm::exception_names[Argm::Exception_count] = {
"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",
......@@ -64,11 +66,14 @@ std::string Argm::exception_names[Argm::Exception_count] = {
"rwsh.excessive_exceptions_collected",
"rwsh.excessive_exceptions_in_catch",
"rwsh.excessive_nesting",
"rwsh.executable_not_found",
"rwsh.exec_failed",
"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",
......@@ -80,6 +85,7 @@ std::string Argm::exception_names[Argm::Exception_count] = {
"rwsh.missing_argfunction",
"rwsh.multiple_argfunctions",
"rwsh.not_a_number",
"rwsh.not_a_directory",
"rwsh.not_executable",
"rwsh.not_soon_enough",
"rwsh.raw_command",
......
......@@ -100,6 +100,7 @@ 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_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));
executable_map.set(new Builtin(".test_less", b_test_less));
......
......@@ -12,44 +12,62 @@
)
# internal functions
.function rwsh.unused_variable {echo $1 was unused with call stack $*2}
.function rwsh.unchecked_variable {echo $1 was not checked with call stack $*2}
.function_all_flags rwsh.bad_args -- proto assigned needed excess call_stack ... {
.combine (unacceptable arguments: for prototype ) $proto , $nl
if_only .test_not_empty $assigned {
.combine ( assigned )
.for $assigned$ {.combine $1$0 = ${paren_if_words $1$1} ( )}
.combine , $nl ( but)}
if_only .test_not_empty $needed {
.combine ( needed \() $needed \), $nl
if_only .test_not_empty $excess {.combine ( and)}}
if_only .test_not_empty $excess {
.combine ( found \() $excess (\) excess) $nl}
echo \ call stack: $call_stack
.return -1}
.function rwsh.binary_does_not_exist {
echo $1 : binary does not exist
echo call stack: $*2
.return -1}
.function rwsh.binary_not_found {
echo $1 : binary not found in $2
echo call stack: $*3
.return -1}
.function rwsh.directory_not_found {
.combine $1 ( directory does not exist) $nl
echo call stack $*2}
.function rwsh.exec_failed {
.combine (.exec failed for ) $1 ( with errno ) $2 $nl
echo call stack $*3}
.function rwsh.file_not_found {
echo $1 : could not find file
.return -1}
.function rwsh.illegal_function_name {
.combine \$ $1 ( cannot be a function) $nl
echo call stack $*2}
.function rwsh.illegal_variable_name {
.combine \$ $1 ( cannot be set) $nl
echo call stack $*2}
.function rwsh.not_a_directory {
.combine $1 ( is not a directory) $nl
echo call stack $*2}
.function rwsh.unused_variable {echo $1 was unused with call stack $*2}
.function rwsh.unchecked_variable {echo $1 was not checked with call stack $*2}
# ability of functions to act as builtin wrappers
.function_all_flags af -- [argv ...] {rwsh.argfunction}
.function_all_flags c -- text ... {.combine $text$}
.function_all_flags e -- text ... {.echo $text}
.function_all_flags echo -- text ... {.echo $text $nl}
.function_all_flags echo -- text ... {.echo $text; .combine $nl}
.function_all_flags exec -- argv ... {.exec $argv$}
.function_all_flags elif command ... {.else_if $command$ {rwsh.argfunction}}
.function_all_flags else {.else {rwsh.argfunction}}
.function_all_flags fn -- prototype ... {
.function_all_flags $prototype$ {rwsh.argfunction}
.local ret $?
.if .test_number_equal $ret 1 {echo cannot set paths as functions}
.else_if .test_number_equal $ret 2 {echo cannot set builtins as functions}
.else_if .test_number_equal $ret 3 {echo cannot set argfunctions in executable map}
.else_if .test_number_equal $ret 4 {echo function &&1 did not exist to be erased}
.else {.return $ret}}
.function_all_flags $prototype$ {rwsh.argfunction}}
.function_all_flags fni -- name args ... {
.function_all_flags $name -- $args$ {rwsh.argfunction}
.local ret $?
.if .test_number_equal $ret 1 {echo cannot set paths as functions}
.else_if .test_number_equal $ret 2 {echo cannot set builtins as functions}
.else_if .test_number_equal $ret 3 {echo cannot set argfunctions in executable map}
.else_if .test_number_equal $ret 4 {echo function &&1 did not exist to be erased}
.else {.return $ret}}
.function_all_flags $name -- $args$ {rwsh.argfunction}}
.function_all_flags fns -- name args ... {
.function_all_flags $name [-*] $args$ {rwsh.argfunction}
.local ret $?
.if .test_number_equal $ret 1 {echo cannot set paths as functions}
.else_if .test_number_equal $ret 2 {echo cannot set builtins as functions}
.else_if .test_number_equal $ret 3 {echo cannot set argfunctions in executable map}
.else_if .test_number_equal $ret 4 {echo function &&1 did not exist to be erased}
.else {.return $ret}}
.function_all_flags $name [-*] $args$ {rwsh.argfunction}}
.function_all_flags iee var {
.if .var_exists $var {.echo $$var}
.else {.nop}}
......@@ -78,16 +96,12 @@ fn ntimes n {
.while test_var_greater n 0 {
rwsh.mapped_argfunction {rwsh.argfunction}
.var_subtract n 1}}
fn mark {ntimes 4 {.echo ####################}}
.function unset {.unset $1}
fn which command {
.if .which_test $command {
.combine ${.which_executable $command {rwsh.argfunction}} $nl}
.else {echo no $command}}
fn whichp binary {
.which_path $binary $PATH
.if .test_number_equal $? 0 {.nop}
.else {echo &&binary not found in $PATH; .return 1}}
fn whichp binary {.which_path $binary $PATH}
.function while {.while $* {rwsh.argfunction}}
.function_all_flags var_exists -- var {.var_exists $var}
.function_all_flags var_val -- [var ...] {
......@@ -96,16 +110,3 @@ fn whichp binary {
.function_all_flags paren_if_words -- value {
.if .test_number_equal ${.argc $value$} 1 {.combine $value}
.else {.combine \( $value \)}}
.function_all_flags rwsh.bad_args -- proto assigned needed excess call_stack ... {
.combine (unacceptable arguments: for prototype ) $proto , $nl
if_only .test_not_empty $assigned {
.combine ( assigned )
.for $assigned$ {.combine $1$0 = ${paren_if_words $1$1} ( )}
.combine , $nl ( but)}
if_only .test_not_empty $needed {
.combine ( needed \() $needed \), $nl
if_only .test_not_empty $excess {.combine ( and)}}
if_only .test_not_empty $excess {
.combine ( found \() $excess (\) excess) $nl}
.echo \ call stack: $call_stack $nl
.return -1}
......@@ -39,12 +39,8 @@ sfn cat
fn cd [path] {
if_only .var_exists path {.selection_set s $path}
.cd @$s
.local ret $?
.if .test_number_equal $ret 1 {echo @$s does not exist}
.else_if .test_number_equal $ret 2 {echo @$s is not a directory}
.else {
&{whichp pwd}
.set s (); .set s2 ()}}
&{whichp pwd}
.set s (); .set s2 ()}
fns chmod mode [file ...] {
if_only .var_exists file {.selection_set s $file}
&{whichp chmod} $-*$ $mode @$s}
......@@ -176,9 +172,6 @@ fn unselect {.set s ()}
.function rwsh.bad_if_nest {
.echo nested .if without .else with call stack: $* $nl
.return -1}
.function rwsh.binary_not_found {
.echo $1 : could not run binary $nl
.return -1}
.function rwsh.dash_dash_argument {
.echo optional -- parameter cannot take arguments \( $1 \) with call stack: $*2 $nl
.return -1}
......@@ -220,7 +213,7 @@ fn unselect {.set s ()}
.function rwsh.excess_argfunction {
.echo $1 does not accept an argfunction with call stack: $* $nl
.return -1}
.function rwsh.executable_not_found {
.function rwsh.function_not_found {
.echo $1 : command not found \( $* \) $nl
.return -1}
.function rwsh.failed_substitution {
......@@ -332,6 +325,7 @@ fn unselect {.set s ()}
.function_all_flags exit {.exit}
.function last_time {.which_last_execution_time $*; c $nl}
fn local {. &{c $HOME /.rwshrc}}
fn mark {ntimes 4 {.echo ####################}; c $nl}
fn ret {.return $*}
.function total_time {.which_total_execution_time $*; c $nl}
.function user_shell_ratio {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
.global nl (
)
.for &{.internal_functions}$ {.function $1 {.echo signal triggered: $0 \( $* \) $nl; .return -1}}
.for &{.internal_functions}$ {.nop
.function $1 {.echo signal triggered: $0 \( $* \); .combine $nl; .return -1}}
.function rwsh.raw_command {.echo $1; .echo $nl}
.global last_command_return -10
.global A \
......
......@@ -212,7 +212,7 @@ y
# file redirection (but don't overwrite files that exist)
# .for_each_line
.if .ls dummy_file {.exit}
.if .test_file_exists dummy_file {.echo something went wrong}
.else {}
/bin/cat <dummy_file
.for_each_line <dummy_file {e line of $# \( $* \)}
......@@ -267,6 +267,8 @@ f x
.cd
.cd /bin {excess argfunc}
.cd /bin /
.cd /bn
.cd /bin/rwsh
.cd /bin
/bin/pwd
......@@ -283,9 +285,13 @@ f x
# .exec .fork
.fork
.fork e text
.fork .return 1
.fork .return 127
.exec
.exec something {excess argfunc}
.exec /bin/ech does not exist
.exec /etc/rwshrc-default config files are not interpreters
.exec /bin cannot exec a directory
.exec /bin/rwsh/insanity errno is ENOTDIR
.fork m {.exec /bin/echo something; /bin/echo else}
# .fallback_handler .get_fallback_message .set_fallback_message
......@@ -311,7 +317,7 @@ f x
# .function
.function
.function /bin/echo {.echo $* $nl}
.function /bin/echo {.echo wrong echo $* $nl}
.function .exit {.nop}
.function rwsh.escaped_argfunction {.nop}
.function a
......@@ -788,6 +794,7 @@ m {.is_default_error}
# .ls
.ls
.ls /bin {excess argfunc}
.ls /bin/usr/
.ls /bin /usr/
# .nop
......@@ -937,18 +944,18 @@ m {.collect_errors_except .nop {
.throw rwsh.not_a_number 7
echo after exception}
echo between exceptions
.scope () {.throw rwsh.executable_not_found foo}
.scope () {.throw rwsh.function_not_found foo}
echo inside collect}
echo outside collect}
m {.collect_errors_except echo {
.throw rwsh.executable_not_found foo
.throw rwsh.function_not_found foo
echo between exceptions
.throw echo 7
echo inside collect}
echo outside collect}
# .collect_errors_except .echo {${.throw .echo exception thrown directly}}
m {.collect_errors_only rwsh.executable_not_found {
.throw rwsh.executable_not_found foo
m {.collect_errors_only rwsh.function_not_found {
.throw rwsh.function_not_found foo
echo between exceptions
.throw echo 7
echo inside collect}
......@@ -1011,16 +1018,16 @@ m {.collect_errors_only rwsh.executable_not_found {
.get_max_collectible_exceptions
# .try_catch_recursive .get_max_extra_exceptions .set_max_extra_exceptions
.try_catch_recursive rwsh.executable_not_found
.try_catch_recursive rwsh.function_not_found
.try_catch_recursive {.return A}
f e_after {m {rwsh.argfunction}; echo after}
e_after {.try_catch_recursive rwsh.not_a_number rwsh.executable_not_found {
e_after {.try_catch_recursive rwsh.not_a_number rwsh.function_not_found {
.return A}}
f rwsh.autofunction {.nop}
e_after {.try_catch_recursive rwsh.executable_not_found {.eturn A}}
e_after {.try_catch_recursive rwsh.function_not_found {.eturn A}}
e_after {.try_catch_recursive rwsh.not_a_number {.return A}}
e_after {.try_catch_recursive rwsh.not_a_number {.cho A}}
e_after {.try_catch_recursive rwsh.not_a_number rwsh.executable_not_found {echo A}}
e_after {.try_catch_recursive rwsh.not_a_number rwsh.function_not_found {echo A}}
e_after {m echo hi {.try_catch_recursive ${.internal_functions}$ {&&&*}}}
.get_max_extra_exceptions excess
.set_max_extra_exceptions
......@@ -1057,6 +1064,12 @@ wrapper 1 2
.stepwise wrapper 1 2 {d $*}
.stepwise wrapper 1 2 {e $* $nl}
# .test_file_exists
.test_file_exists
.test_file_exists dummy_file {excess argfunc}
.test_file_exists /b /in
.test_file_exists /b /bin /in
# .test_string_equal .test_string_unequal .test_not_empty
.test_string_equal x
.test_string_equal x x x
......@@ -1370,13 +1383,13 @@ f rwsh.autofunction
# m {e hi >dummy_file}
# m {e &{e hi #>dummy_file}}
# rwsh.executable_not_found
# rwsh.function_not_found
m {m {x; e should not be printed}}
f rwsh.executable_not_found
w rwsh.executable_not_found
f rwsh.function_not_found
w rwsh.function_not_found
w x
x
w rwsh.executable_not_found
w rwsh.function_not_found
# rwsh.mapped_argfunction rwsh.unescaped_argfunction rwsh.argfunction
# rwsh.escaped_argfunction
......
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