calc icon indicating copy to clipboard operation
calc copied to clipboard

pipe/fork/exec and friends as custom functions

Open vike2000 opened this issue 7 months ago • 16 comments

Greetings!

Wanting to support external shell/binary cli use in calc; since system() doesn't catch and return output, as in cli calc '2+system("echo 3")'.

Hopefully the custom/pfe help-file synopsis outlines the added functions. If you think I should reproduce or reference more of the underlying syscalls' docs, I'll try.

I have very little experience in authoring PRs, and not too much experience of C (but some), nor of calc, so please bear with me. I don't know how much of 3f106bf3799a56048b42bb23b98f370edc4fd361 you want or whether 1d70a1fda2d830882430240b9c2152fd167db16f and 70d93c2db3c472e35c244b6dc8ef42fead2b4599 should be in separate PR(s) so please tell me what you think about that, if and how I should modify or recreate this PR.

Only built and tested on macOS 13.6.6 using Apple clang 14.0.3, part of Xcode 14.3.1, but my IDE is VSCode, w/ some clangd extension residue .gitignored. Build req. readline and IDE support py38-pip installed as Macports ports. VSCode clangd support then installed w/ pip-3.8 install compiledb.

I've tried to adhere to perceived convention/style in .h/.c, albeit loosely vis-à-vis heavy tabbing for column alignment. In .cal and .sh I've allowed myself my own style - sorry; of course I'll reformat if requested.

As with everything else, naming and/or prefixing is open for discussion, especially in pfe, pread, and pwrite, being higher level utilities implemented first in calc/.cal and then in .h/.c.

I am a bit unsure whether I am responsible for any more free() than I do. I tried doing leaks(1) at some point but didn't know how to investigate from there.

Some of the functions use "addr" features (where support functions are named …ref…), some use optional arguments (valv_opt…) and type checking in combination, and some use all in combination. Only a minuscule subset of possible usage alternatives there are tested. We could also do more sanity checks after optional/type checking.

If these functions should try to be compatible with general file-handles like from fopen or calcs equivalents, I'd have to investigate that.

Grateful for any suggestions!

vike2000 avatar Jul 11 '24 17:07 vike2000