Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce 'function' built-in. #77

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

Commits on Jun 1, 2024

  1. Introduce 'function' built-in

    As requested in tcsh-org#4, here's my proposal. This is a wrapper around goto and source. The script recurses itself and searches for a goto label. It's an error for labels not contain an exit to their end. Function calls outside labels are, by default, labeled main.
    
    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-in function command is evaluated before mine, thus those who attempt to execute it won't get the correct error message.
    Krush206 committed Jun 1, 2024
    Configuration menu
    Copy the full SHA
    faab6cc View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    b683769 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    4d90ff3 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    715a882 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    5e37bfc View commit details
    Browse the repository at this point in the history
  6. Better function parsing

    Krush206 committed Jun 1, 2024
    Configuration menu
    Copy the full SHA
    235b358 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    4a54e05 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    5bc9252 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    b1e4135 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    ede350d View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    fc7dbd3 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    d762fba View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    951264d View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    7d6eef8 View commit details
    Browse the repository at this point in the history
  15. Functions should work for sourced scripts.

    Next, make a table of functions so they can be called globally. Currently, it isn't possible to call functions from sourced files other than the current.
    Krush206 committed Jun 1, 2024
    Configuration menu
    Copy the full SHA
    c60a4c2 View commit details
    Browse the repository at this point in the history

Commits on Jun 3, 2024

  1. Rethought on functions

    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, functions may only 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.
    
    I was afraid this wouldn't work out for some operations, such as loops and gotos, because pipes cannot rewind. Fortunately, I was wrong, and the fact these operations are possible from interactive sessions, from a terminal, makes the assumption just as wrong, though I'm clueless as to how rewinding is possible on unsupported sources.
    Krush206 committed Jun 3, 2024
    Configuration menu
    Copy the full SHA
    954cfd6 View commit details
    Browse the repository at this point in the history
  2. Do not fork & fix interrupts

    Though POSIX defines a minimum for pipe buffer, I decided is safer writing one byte a time. This may render slow reads, though writing in larger quantities rendered broken reads.
    
    For an unknown reason, some operations, after SIGINT, rendered exiting the Shell. This happens on the ERR_RECURSION error as well. longjmp remedies the issue, though I'm afraid isn't the best solution.
    Krush206 committed Jun 3, 2024
    Configuration menu
    Copy the full SHA
    15d4e30 View commit details
    Browse the repository at this point in the history
  3. Refactor

    Krush206 committed Jun 3, 2024
    Configuration menu
    Copy the full SHA
    042e84b View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    2fa7967 View commit details
    Browse the repository at this point in the history
  5. sh.err.c: recursion/nest

    Krush206 committed Jun 3, 2024
    Configuration menu
    Copy the full SHA
    b950b85 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    d840e89 View commit details
    Browse the repository at this point in the history

Commits on Jun 4, 2024

  1. Configuration menu
    Copy the full SHA
    22d3150 View commit details
    Browse the repository at this point in the history
  2. Avoid SIGPIPE on doexit

    Krush206 committed Jun 4, 2024
    Configuration menu
    Copy the full SHA
    adea1b6 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d0167d4 View commit details
    Browse the repository at this point in the history

Commits on Jun 6, 2024

  1. Configuration menu
    Copy the full SHA
    911ed6e View commit details
    Browse the repository at this point in the history

Commits on Jun 7, 2024

  1. Configuration menu
    Copy the full SHA
    56e5e7d View commit details
    Browse the repository at this point in the history

Commits on Jun 13, 2024

  1. Prefer dozip over doreturn

    Krush206 committed Jun 13, 2024
    Configuration menu
    Copy the full SHA
    c8b8f51 View commit details
    Browse the repository at this point in the history