Open Krush206 opened 1 year ago
Perhaps some documentation and tests?
I think functions based on pipes makes a simpler feature, as well as allows for use in interactive sessions, resembling Bourne-compatible Shells better. Unlike the goto-based version, this new version only allows functions be called if they were previously declared (i.e: no forward jumps), making a similar behavior to Bourne-compatible Shells.
This version relies on a tree derived from variables and aliases. Unlike to aliases and variables, the tree is restrictive. Once a function is declared, may not be redeclared or undeclared.
As requested in https://github.com/tcsh-org/tcsh/issues/4, here's my proposal. This is a wrapper around
goto
andsource
. The script recurses itself and searches for agoto
label. It's an error for labels not contain anexit
to their end. Function calls outside labels are, by default, labeledmain
.This was tested sparsely, and may contain bugs I haven't faced, but is working as expected. One bug to be noted is that pipes don't give up on errors. This is possibly due to forking.
I noticed Tcsh has a built-in
function
command, but I can't trace the code. Said built-infunction
command is evaluated before mine, thus those who attempt to execute it won't get the correct error message.