Commit 9792d9ba authored by Samuel Newbold's avatar Samuel Newbold

Replace which_* builtins with names more consistent with zsh/ksh

parent eb2042c2
This diff is collapsed.
......@@ -3,64 +3,64 @@
.function_all_flags # [args ...] {.nop $args$}
.function_all_flags fw {
.function_all_flags f1 name {rwsh.argfunction}
.which_executable f1; .echo $nl
.whence_function f1; .echo $nl
f1 f2 {rwsh.argfunction}
.which_executable f2; .echo $nl
.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}}}
.function_all_flags f1 name {
.echo function name $name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function rwsh.argfunction {rwsh.argfunction}
.echo $nl end of function body $nl}
f1 f2 {
.echo noname $1 $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function rwsh.argfunction {rwsh.argfunction}
.echo $nl end of nothing $nl}
fw {
.echo function name $name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function rwsh.argfunction {rwsh.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 rwsh.argfunction {rwsh.argfunction}
.echo $nl end of function body $nl}}
fw {.for 1 2 3 {rwsh.mapped_argfunction $1 {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function rwsh.argfunction {rwsh.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 {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function rwsh.argfunction {rwsh.argfunction}
.echo $nl end of function body $nl}}}
# mostly as wierd
fw {rwsh.mapped_argfunction rwsh.not_a_number {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function rwsh.argfunction {rwsh.argfunction}
.echo $nl end of function body $nl}}
# normal again
fw {.try_catch_recursive rwsh.not_a_number {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function rwsh.argfunction {rwsh.argfunction}
.echo $nl end of function body $nl}}
fw {.for 1 2 3 {.try_catch_recursive rwsh.not_a_number {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function rwsh.argfunction {rwsh.argfunction}
.echo $nl end of function body $nl}}}
fw {.try_catch_recursive rwsh.not_a_number {.for 1 2 3 {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function rwsh.argfunction {rwsh.argfunction}
.echo $nl end of function body $nl}}}
# maybe weird?
fw {rwsh.mapped_argfunction $1 {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function rwsh.argfunction {rwsh.argfunction}
.echo $nl end of function body $nl}}
# definitely weird
fw {rwsh.mapped_argfunction $name {.for a b {
.echo function name &&name $nl
.which_executable rwsh.argfunction {rwsh.argfunction}
.whence_function rwsh.argfunction {rwsh.argfunction}
.echo $nl end of function body $nl}}}
fw {rwsh.mapped_argfunction {.function_all_flags $name {rwsh.argfunction}}}
.return 0
......
......@@ -167,6 +167,18 @@ int b_exec(const Argm& argm, Error_list& exceptions) {
else exceptions.add_error(Exception(Argm::Exec_failed, argm[1], errno));
return 0;} // we are depending on the error handlers to indicate failure
// print the number of times that the executable in the executable map with
// key $1 has been run
int b_execution_count(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());
Base_executable* focus = executable_map.find_second(lookup);
if (focus) {
argm.output <<focus->execution_count();
argm.output.flush();
return 0;}
else return 1;} // executable does not exist
// exit the shell
int b_exit(const Argm& argm, Error_list& exceptions) {
if (argm.argc() != 1) throw Exception(Argm::Bad_argc, argm.argc()-1, 0, 0);
......@@ -441,6 +453,30 @@ int b_is_default_error(const Argm& argm, Error_list& exceptions) {
if (argm.argfunction()) throw Exception(Argm::Excess_argfunction);
return !argm.error.is_default();}
// print the last exception that was thrown by this function
int b_last_exception(const Argm& argm, Error_list& exceptions) {
if (argm.argc() != 2) throw Exception(Argm::Bad_argc, argm.argc()-1, 1, 0);
if (argm.argfunction()) throw Exception(Argm::Excess_argfunction);
Argm lookup(argm.subrange(1), argm.argfunction(), argm.parent_map());
Base_executable* focus = executable_map.find_second(lookup);
if (focus) {
argm.output <<focus->last_exception();
argm.output.flush();
return 0;}
else return 1;} // executable does not exist
// print the number of times that the executable in the executable map with
// key $1 has been run
int b_last_execution_time(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());
Base_executable* focus = executable_map.find_second(lookup);
if (focus) {
argm.output <<focus->last_execution_time();
argm.output.flush();
return 0;}
else return 1;} // executable does not exist
// print the environment that the shell started in
int b_list_environment(const Argm& argm, Error_list& exceptions) {
if (argm.argc() != 1) throw Exception(Argm::Bad_argc, argm.argc()-1, 0, 0);
......@@ -691,6 +727,13 @@ int b_store_output(const Argm& argm, Error_list& exceptions) {
argm.set_var(argm[1], text.value());
return 0;}
// return true if there is an executable in the executable map with key $1
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";
return !executable_map.find_second(lookup);}
// list the files specified by the arguments if they exist
int b_test_file_exists(const Argm& argm, Error_list& exceptions) {
if (argm.argc() < 2) throw Exception(Argm::Bad_argc, argm.argc()-1, 1, 0);
......@@ -798,6 +841,19 @@ int b_toggle_readline(const Argm& argm, Error_list& exceptions) {
readline_enabled = ! readline_enabled;
return 0;}
// print the number of times that the executable in the executable map with
// key $1 has been run
int b_total_execution_time(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());
Base_executable* focus = executable_map.find_second(lookup);
if (focus) {
struct timeval val = focus->total_execution_time();
argm.output <<val;
argm.output.flush();
return 0;}
else return 1;} // executable does not exist
// run the handler for specified exceptions
int b_try_catch_recursive(const Argm& argm, Error_list& exceptions) {
if (argm.argc() < 2) throw Exception(Argm::Bad_argc, argm.argc()-1, 1, 0);
......@@ -810,6 +866,22 @@ int b_try_catch_recursive(const Argm& argm, Error_list& exceptions) {
Base_executable::catch_blocks(argm, exceptions);
return -1;}
return ret;}
// print the type of executable with name $1 from executable map
int b_type(const Argm& argm, Error_list& exceptions) {
if (argm.argc() != 2)
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";
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";
else if (dynamic_cast<Binary*>(e)) argm.output <<"file";
else if (dynamic_cast<Builtin*>(e)) argm.output <<"builtin";
else if (dynamic_cast<Command_block*>(e)) argm.output <<"argfunction";
else std::abort(); // successfully removed executable
return 0;}
// 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
......@@ -969,65 +1041,16 @@ int b_waiting_for_user(const Argm& argm, Error_list& exceptions) {
// print the string corresponding to the executable in the executable map with
// key $1
int b_which_executable(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";
Base_executable* focus = executable_map.find_second(lookup);
if (focus) {
argm.output <<focus->str();
argm.output.flush();
return 0;}
else return 1;} // executable does not exist
// print the number of times that the executable in the executable map with
// key $1 has been run
int b_which_execution_count(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());
Base_executable* focus = executable_map.find_second(lookup);
if (focus) {
argm.output <<focus->execution_count();
argm.output.flush();
return 0;}
else return 1;} // executable does not exist
// print the last exception that was thrown by this function
int b_which_last_exception(const Argm& argm, Error_list& exceptions) {
if (argm.argc() != 2) throw Exception(Argm::Bad_argc, argm.argc()-1, 1, 0);
if (argm.argfunction()) throw Exception(Argm::Excess_argfunction);
Argm lookup(argm.subrange(1), argm.argfunction(), argm.parent_map());
Base_executable* focus = executable_map.find_second(lookup);
if (focus) {
argm.output <<focus->last_exception();
argm.output.flush();
return 0;}
else return 1;} // executable does not exist
// print the number of times that the executable in the executable map with
// key $1 has been run
int b_which_last_execution_time(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());
Base_executable* focus = executable_map.find_second(lookup);
if (focus) {
argm.output <<focus->last_execution_time();
argm.output.flush();
return 0;}
else return 1;} // executable does not exist
// print the number of times that the executable in the executable map with
// key $1 has been run
int b_which_total_execution_time(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());
Base_executable* focus = executable_map.find_second(lookup);
if (focus) {
struct timeval val = focus->total_execution_time();
argm.output <<val;
argm.output.flush();
return 0;}
else return 1;} // executable does not exist
argm.output.flush();}
else exceptions.add_error(Exception(Argm::Function_not_found, argm[1]));
return 0;}
// if the filename has a leading dot, then check in current directory
// otherwise find the binary in $2 with filename $1
......@@ -1052,24 +1075,6 @@ int b_which_path(const Argm& argm, Error_list& exceptions) {
exceptions.add_error(Exception(Argm::Binary_not_found, argm[1], argm[2]));
return 0;} // executable does not exist
// prints the last return value of the executable with named $1
int b_which_return(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());
Base_executable* focus = executable_map.find_second(lookup);
if (focus) {
argm.output <<focus->last_ret();
argm.output.flush();
return 0;}
else return 1;} // executable does not exist
// return true if there is an executable in the executable map with key $1
int b_which_test(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";
return !executable_map.find_second(lookup);}
// for each time that the arguments return true, run the argfunction
// returns the last return from the argfunction
int b_while(const Argm& argm, Error_list& exceptions) {
......
......@@ -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);
......@@ -4,7 +4,7 @@
.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)))))))))
......
......@@ -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",
......@@ -72,10 +74,10 @@ void internal_init(Error_list& exceptions) {
"call stack ) $stack (\n)}\n"
" .function_all_flags rwsh.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_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));
......@@ -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));
......
......@@ -6,7 +6,7 @@
.function_all_flags rwsh.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$}}
......
......@@ -2,6 +2,7 @@
# set up environment
.set_max_collectible_exceptions 10
.set_max_extra_exceptions 5
.global nl (
)
......@@ -242,11 +243,15 @@ fn ntimes n {
.else {.global $var $value}}
fn single -- args ... {.scope ${$args$}$ result {echo $result}}
fn test_var_not_equal var value {.test_string_unequal $$var $value}
.function_all_flags test_var_greater -- var value {.test_greater $$var $value}
fn which command {
.if .which_test $command {
.combine ${.which_executable $command {rwsh.argfunction}} $nl}
.else {echo no $command}}
fn test_var_greater -- var value {.test_greater $$var $value}
fn type [-t] args ... {
.for $args$ {
.try_catch_recursive rwsh.function_not_found {
if_only_not .var_exists -t {.echo &&&1 is ()}
.combine &&&&{.type &&&1 {rwsh.argfunction}} $nl}}}
fn whence command {
.try_catch_recursive rwsh.function_not_found {
.combine ${.whence_function $command {rwsh.argfunction}} $nl}}
fn whichp binary {.which_path $binary $PATH}
.function_all_flags var_exists -- var {.var_exists $var}
.function_all_flags var_val -- [var ...] {
......
......@@ -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}
......@@ -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.
......@@ -30,6 +30,7 @@ call stack .source rwsh.mapped_argfunction
# set up environment
.set_max_collectible_exceptions 10
.set_max_extra_exceptions 5
.global nl (
)
......@@ -270,11 +271,15 @@ fn ntimes n {
.else {.global $var $value}}
fn single -- args ... {.scope ${$args$}$ result {echo $result}}
fn test_var_not_equal var value {.test_string_unequal $$var $value}
.function_all_flags test_var_greater -- var value {.test_greater $$var $value}
fn which command {
.if .which_test $command {
.combine ${.which_executable $command {rwsh.argfunction}} $nl}
.else {echo no $command}}
fn test_var_greater -- var value {.test_greater $$var $value}
fn type [-t] args ... {
.for $args$ {
.try_catch_recursive rwsh.function_not_found {
if_only_not .var_exists -t {.echo &&&1 is ()}
.combine &&&&{.type &&&1 {rwsh.argfunction}} $nl}}}
fn whence command {
.try_catch_recursive rwsh.function_not_found {
.combine ${.whence_function $command {rwsh.argfunction}} $nl}}
fn whichp binary {.which_path $binary $PATH}
.function_all_flags var_exists -- var {.var_exists $var}
.function_all_flags var_val -- [var ...] {
......@@ -320,6 +325,7 @@ $.source /etc/rwshrc-basic
# set up environment
.set_max_collectible_exceptions 10
.set_max_extra_exceptions 5
.global nl (
)
......@@ -560,11 +566,15 @@ fn ntimes n {
.else {.global $var $value}}
fn single -- args ... {.scope ${$args$}$ result {echo $result}}
fn test_var_not_equal var value {.test_string_unequal $$var $value}
.function_all_flags test_var_greater -- var value {.test_greater $$var $value}
fn which command {
.if .which_test $command {
.combine ${.which_executable $command {rwsh.argfunction}} $nl}
.else {echo no $command}}
fn test_var_greater -- var value {.test_greater $$var $value}
fn type [-t] args ... {
.for $args$ {
.try_catch_recursive rwsh.function_not_found {
if_only_not .var_exists -t {.echo &&&1 is ()}
.combine &&&&{.type &&&1 {rwsh.argfunction}} $nl}}}
fn whence command {
.try_catch_recursive rwsh.function_not_found {
.combine ${.whence_function $command {rwsh.argfunction}} $nl}}
fn whichp binary {.which_path $binary $PATH}
.function_all_flags var_exists -- var {.var_exists $var}
.function_all_flags var_val -- [var ...] {
......@@ -596,15 +606,15 @@ $.global PATH /bin:/usr/bin
0
$.getpid
2615
32357
0
$.getppid
14621
15140
0
$.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}
0
$.function_all_flags clock-watch {
......@@ -620,22 +630,22 @@ $.function_all_flags clock-watch {
$clock-watch
timings: last(0.000000) total(0.000000) count(0)
clock-watch: last(0.000000) total(0.000000) count(0)
usleep overhead: 8.7e-05
.usleep: last(0.000687) total(0.000687) count(1)
/bin/true: last(0.000927) total(0.000927) count(1)
usleep overhead: 6.4e-05
.usleep: last(0.000664) total(0.000664) count(1)
/bin/true: last(0.001054) total(0.001054) count(1)
0
$clock-watch
timings: last(0.000114) total(0.000555) count(4)
clock-watch: last(0.002654) total(0.002654) count(1)
usleep overhead: 8.85e-05
.usleep: last(0.000690) total(0.001377) count(2)
/bin/true: last(0.000846) total(0.001773) count(2)
timings: last(0.000182) total(0.000865) count(4)
clock-watch: last(0.003217) total(0.003217) count(1)
usleep overhead: 6.45e-05
.usleep: last(0.000665) total(0.001329) count(2)
/bin/true: last(0.000836) total(0.001890) count(2)
0
$rwsh.mapped_argfunction {timings timings; timings clock-watch}
timings: last(0.000131) total(0.001093) count(8)
clock-watch: last(0.002177) total(0.004831) count(2)
timings: last(0.000112) total(0.001404) count(8)
clock-watch: last(0.002163) total(0.005380) count(2)
0
$.error a stderr print will come before the diff $nl
......
......@@ -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
......
This diff is collapsed.
......@@ -30,6 +30,7 @@ call stack .source rwsh.mapped_argfunction
# set up environment
.set_max_collectible_exceptions 10
.set_max_extra_exceptions 5
.global nl (
)
......@@ -270,11 +271,15 @@ fn ntimes n {
.else {.global $var $value}}
fn single -- args ... {.scope ${$args$}$ result {echo $result}}
fn test_var_not_equal var value {.test_string_unequal $$var $value}
.function_all_flags test_var_greater -- var value {.test_greater $$var $value}
fn which command {
.if .which_test $command {
.combine ${.which_executable $command {rwsh.argfunction}} $nl}
.else {echo no $command}}
fn test_var_greater -- var value {.test_greater $$var $value}
fn type [-t] args ... {
.for $args$ {
.try_catch_recursive rwsh.function_not_found {
if_only_not .var_exists -t {.echo &&&1 is ()}
.combine &&&&{.type &&&1 {rwsh.argfunction}} $nl}}}
fn whence command {
.try_catch_recursive rwsh.function_not_found {
.combine ${.whence_function $command {rwsh.argfunction}} $nl}}
fn whichp binary {.which_path $binary $PATH}
.function_all_flags var_exists -- var {.var_exists $var}
.function_all_flags var_val -- [var ...] {
......@@ -322,7 +327,7 @@ $.function_all_flags a [-*] [-x b ...] c {
$.nop $A $FIGNORE
0
$.which_executable a
$.whence_function a
.function_all_flags a [-?] [-x b ...] c {
.for &{.list_locals}$ {.combine $1 \( $$1 \) ( )}}
0
......@@ -355,7 +360,7 @@ $.function_all_flags a [-*] [-x ... b] c {
}
0
$.which_executable a
$.whence_function a
.function_all_flags a [-?] [-x ... b] c {
.for &{.list_locals}$ {.combine $1 \( $$1 \) ( )}
.combine $nl
......
.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
......
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