Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
515981b
adding custom *pfe*
vike2000 Jul 11, 2024
3f106bf
adding custom *pfe* development files
vike2000 Jul 11, 2024
1d70a1f
fixing `(char*)…->v_str` by appending `->s_str` in custom/c_help.c, a…
vike2000 Jul 11, 2024
70d93c2
fixing file.h includes
vike2000 Jul 11, 2024
2d89d7f
removing custom *pfe* development files
vike2000 Jul 11, 2024
6217a66
removing ~chongo specifics from custom/pfe help file
vike2000 Jul 11, 2024
fb70358
fixing some formatting in custom/pfe.cal
vike2000 Jul 11, 2024
6d25ccc
fixing some formatting in custom/u_pfe.c; also removing some comments…
vike2000 Jul 11, 2024
f64f199
textually shortening type2str and helpers w/ zero-sum on length of calls
vike2000 Jul 23, 2024
7891cbd
clang-format of custom/u_pfe.c
vike2000 Jul 24, 2024
9bc9a09
gitignore .clang-format & fix some sorting
vike2000 Jul 24, 2024
c294b20
clang-format (patched) of custom/pfe.cal
vike2000 Aug 8, 2024
ff174b1
fixing execv* argv NULL pointer termination
vike2000 Aug 9, 2024
b429fd8
Merge branch 'master' into custom/u_pfe
lcn2 Apr 28, 2025
b7bd76b
Update u_pfe.c
lcn2 Apr 28, 2025
6a80a24
Update u_pfe.c
lcn2 Apr 28, 2025
84f74d9
undo Update u_pfe.c
lcn2 Apr 28, 2025
f33aa19
Update u_pfe.c
lcn2 Apr 28, 2025
dbd0392
fix compat issues, re https://github.com/lcn2/calc/pull/153#pullreque…
vike2000 Sep 14, 2025
eb1447e
Merge branch 'custom/u_pfe' of github.com:vike2000/calc into custom/u…
vike2000 Sep 14, 2025
02a0a68
Merge branch 'master' into custom/u_pfe
vike2000 Sep 14, 2025
bc2ed54
update PR 153 with critical edits
lcn2 Sep 15, 2025
0d72217
fix use strlcat(3) and strlcpy(3)
lcn2 Sep 15, 2025
3112846
use S_FUNC in custom/u_pfe.c
lcn2 Sep 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ align32.h
align32_tmp
arc4random_tmp
args.h
.cache/clangd
cal/.all
calc
calc.1
Expand All @@ -37,6 +38,10 @@ cal/test082.cal
charbit.h
chatbit
chk_c
.clang-format
clang-format-testee.c
compile_commands.json
compile_flags.txt
conf.h
const_tmp
cscript/4dsphere
Expand Down Expand Up @@ -180,5 +185,6 @@ uid_tmp
unused_tmp
ustat_tmp
ver_calc
.vscode
vs_tmp
win32/
23 changes: 18 additions & 5 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
The following are the changes from calc version 2.16.0.0 to 2.16.0.1:

Adding support for "pipe/fork/exec and friends" via custom functions
thanks to a contribution by GitHub user @vike2000.

We to address a bug after adding support for pipe/fork/exec (and
friends) via custom functions

TODO: Before the calc v2 to calc v3 fork, we need to fix a critical
[bug](https://github.com/lcn2/calc/issues/103#issuecomment-3194363618)
related to heap-use-after-free memory errors. We anticipate this
will involve releasing a bug fix version of calc and then allow
for extensive testing before declaring the resulting 2.16.0.x as a
stable release. From that 2.16.0.x stable release that a new version
2.16.1.0 stable release, with no changes other than a new version
number and git tag as the basis for the calc v2 to calc v3 fork.


The following are the changes from calc version 2.15.1.2 to 2.16.0.0:

Starting with calc version 2.16.0.0, the ability to perform arithmetic
Expand Down Expand Up @@ -27,10 +45,6 @@ The following are the changes from calc version 2.15.1.2 to 2.16.0.0:
Added E_INVALID_ADDR_OP (10611) error code to indicate an invalid
arithmetic address operation.

We plan to let this most recent change settle down before performing
the calc v2 to calc v3 fork. Therefore, version 2.16.1.0 will form
the basis for the calc v2 to calc v3 fork.


The following are the changes from calc version 2.15.1.2 to 2.15.1.2:

Expand Down Expand Up @@ -62,7 +76,6 @@ The following are the changes from calc version 2.15.0.7 to 2.15.1.0:
Fixed trailblank. It was pruning . in its find search.
Added check for ASCII tabs is non-Makefiles.


The following are the changes from calc version 2.15.0.6 to 2.15.0.7:

Thanks to GitHub user @bambooleafz a critical bug (GitHub issue
Expand Down
1 change: 1 addition & 0 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Calc copyrights and exception files
Copyright (C) year Christoph Zurnieden
Copyright (C) year Landon Curt Noll and Thomas Jones-Low
Copyright (C) year Klaus Alexander Seistrup and Landon Curt Noll
Copyright (C) year Viktor Bergquist

These files are not covered under one of the Copyrights listed above:

Expand Down
41 changes: 37 additions & 4 deletions custom/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ include ${TARGET_MKF}
#
# Put your custom calc resource files here.
#
CUSTOM_CALC_FILES= argv.cal halflen.cal pzasusb8.cal pmodm127.cal register.cal
CUSTOM_CALC_FILES= argv.cal halflen.cal pzasusb8.cal pmodm127.cal register.cal pfe.cal

# The custom help files to install
#
# Put your custom help files here.
#
CUSTOM_HELP= argv devnull help sysinfo pzasusb8 pmodm127 register
CUSTOM_HELP= argv devnull help sysinfo pzasusb8 pmodm127 register pfe

# Any .h files that are needed by programs that use
# libcustcalc${LIB_EXT_VERSION}
Expand All @@ -110,7 +110,7 @@ CUSTOM_H_SRC=
# Put your custom .c files here.
#
CUSTOM_SRC= c_argv.c c_devnull.c c_help.c c_sysinfo.c c_pzasusb8.c \
c_pmodm127.c c_register.c
c_pmodm127.c c_register.c u_pfe.c

# Any .o files that are needed by program that use
# libcustcalc${LIB_EXT_VERSION}.
Expand All @@ -122,7 +122,7 @@ CUSTOM_SRC= c_argv.c c_devnull.c c_help.c c_sysinfo.c c_pzasusb8.c \
# Put your custom .o files here.
#
CUSTOM_OBJ= c_argv.o c_devnull.o c_help.o c_sysinfo.o c_pzasusb8.o \
c_pmodm127.o c_register.o
c_pmodm127.o c_register.o u_pfe.o


##########################################################################
Expand Down Expand Up @@ -976,3 +976,36 @@ custtbl.o: ../value.h
custtbl.o: ../version.h
custtbl.o: ../zmath.h
custtbl.o: custtbl.c
u_pfe.o: ../alloc.h
u_pfe.o: ../attribute.h
u_pfe.o: ../banned.h
u_pfe.o: ../block.h
u_pfe.o: ../bool.h
u_pfe.o: ../byteswap.h
u_pfe.o: ../calc.h
u_pfe.o: ../charbit.h
u_pfe.o: ../cmath.h
u_pfe.o: ../config.h
u_pfe.o: ../custom.h
u_pfe.o: ../decl.h
u_pfe.o: ../endian_calc.h
u_pfe.o: ../errsym.h
u_pfe.o: ../errtbl.h
u_pfe.o: ../hash.h
u_pfe.o: ../have_ban_pragma.h
u_pfe.o: ../have_const.h
u_pfe.o: ../have_limits.h
u_pfe.o: ../have_newstr.h
u_pfe.o: ../have_stdbool.h
u_pfe.o: ../have_stdlib.h
u_pfe.o: ../have_string.h
u_pfe.o: ../have_unused.h
u_pfe.o: ../longbits.h
u_pfe.o: ../nametype.h
u_pfe.o: ../qmath.h
u_pfe.o: ../sha1.h
u_pfe.o: ../str.h
u_pfe.o: ../value.h
u_pfe.o: ../version.h
u_pfe.o: ../zmath.h
u_pfe.o: u_pfe.c
2 changes: 1 addition & 1 deletion custom/c_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ c_help(char *UNUSED(name), int UNUSED(count), VALUE **vals)
/*
* give the help
*/
customhelp((char *)vals[0]->v_str);
customhelp((char *)vals[0]->v_str->s_str);

/*
* return NULL
Expand Down
71 changes: 71 additions & 0 deletions custom/custtbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,33 @@ E_FUNC VALUE c_pzasusb8(char*, int, VALUE**);
E_FUNC VALUE c_pmodm127(char*, int, VALUE**);
E_FUNC VALUE c_register(char*, int, VALUE**);

#define U_FUNC(name) E_FUNC VALUE name(char*, int, VALUE**);

// pipe/fork/exec
U_FUNC(u_pfe_fork)
U_FUNC(u_pfe_pipe)
U_FUNC(u_pfe_close)
U_FUNC(u_pfe_execvp)
U_FUNC(u_pfe_dup)
U_FUNC(u_pfe_dup2)
U_FUNC(u_pfe_write)
U_FUNC(u_pfe_read)
U_FUNC(u_pfe_select)
U_FUNC(u_pfe_poll)

U_FUNC(u_pfe_wait4)

U_FUNC(u_pfe_pfe)
U_FUNC(u_pfe_pwrite)
U_FUNC(u_pfe_pread)

// vike's various additions
U_FUNC(u_vadd_basename)
U_FUNC(u_vadd_dirname)
U_FUNC(u_vadd_getcwd)
U_FUNC(u_vadd_getpid)
U_FUNC(u_vadd_getppid)
U_FUNC(u_vadd_inputname) //cspell:ignore inputname

#endif /* CUSTOM */

Expand Down Expand Up @@ -136,6 +163,50 @@ CONST struct custom cust[] = {
{ "register", "get or set customer registers",
1, 2, c_register },

{ "fork", "create process",
0, 0, u_pfe_fork },
{ "pipe", "create descriptor pair for interprocess communication",
0, 0, u_pfe_pipe },
{ "dup", "duplicate a file descriptor",
1, 1, u_pfe_dup },
{ "dup2", "duplicate a file descriptor",
2, 2, u_pfe_dup2 },
{ "close", "remove a file descriptor",
1, 1, u_pfe_close },
{ "execvp", "execute a file",
2, 2, u_pfe_execvp },
{ "write", "write output",
2, 2, u_pfe_write },
{ "read", "read input",
1, 2, u_pfe_read },
{ "select", "examine file descriptors",
3, 4, u_pfe_select },
{ "poll", "synchronous I/O multiplexing",
2, 3, u_pfe_poll },

{ "wait4", "wait for process",
1, 4, u_pfe_wait4 },

{ "pfe", "pipe/fork/exec",
4, 4, u_pfe_pfe },
{ "pwrite", "write and close",
2, 2, u_pfe_pwrite },
{ "pread", "read until eof, close and wait for exit status",
3, 3, u_pfe_pread },

{ "getpid", "get calling process identification",
0, 0, u_vadd_getpid },
{ "getppid", "get parent process identification",
0, 0, u_vadd_getppid },
{ "getcwd", "get working directory pathname",
0, 0, u_vadd_getcwd },
{ "inputname", "get name of input",
0, 0, u_vadd_inputname },
{ "basename", "extract the base portion of a pathname",
1, 1, u_vadd_basename },
{ "dirname", "extract the directory part of a pathname",
1, 1, u_vadd_dirname },


#endif /* CUSTOM */

Expand Down
85 changes: 85 additions & 0 deletions custom/pfe
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
NAME
pfe - pipe/fork/exec and friends

SYNOPSIS
pipe = custom("pipe") ## create descriptor pair for interprocess communication
pid = custom("fork") ## create process
tgt = custom("dup", src) ## duplicate a file descriptor
tgt = custom("dup2", src, tgt) ## duplicate a file descriptor
e = custom("close", fd) ## remove a file descriptor
e = custom("execvp", arg0, args) ## execute a file
count = custom("write", fd, str) ## write output
str = custom("read", fd) ## read input
count = custom("select", rd, wt, exc[, timeout]) ## examine file descriptors
count = custom("poll", chk, &ret[, msecs]) ## synchronous I/O multiplexing
pid = custom("wait", [pid, ]&stt[, opts][, &usg]) ## wait for process

pid = custom("pfe", &in, &out, &err, args) ## pipe/fork/exec
count = custom("pwrite", fd, str) ## write and close
e = custom("pread", pid, out, err) ## read until eof, close and wait for exit status

str = custom("inputname") ## get name of input
path = custom("getcwd") ## get working directory pathname

path = custom("basename", path) ## extract the base portion of a pathname
path = custom("dirname", path) ## extract the directory part of a pathname

pid = custom("getpid") ## get calling process identification
pid = custom("getppid") ## get parent process identification

TYPES
fd int num
pipe list of fd
pid int num
src tgt fd
arg0 str
args list of str
e int num
count int num
rd wt exc list of fd
in out err list of fd
timeout num

arg1 str
...argN str
chk list of list(fd[, arg1[, ...argN]])
ret list of list(fd[, arg1[, ...argN]])
msec int num

stt assoc str => int num
opts list of str
usg assoc str => int num

path str

EXAMPLE
global i, o, e
if(pid = pfe(&i, &o, &e,list("sh","-c","read||:;echo $REPLY"))){
pwrite(i,"test")
pread(pid,o,e)}

LIMITS
calc must be built with ALLOW_CUSTOM= -DCUSTOM
calc must be executed with a -C arg.

LIBRARY
none

SEE ALSO
custom

## Copyright (C) 2024 Viktor Bergquist
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License
## as published by the Free Software Foundation.
##
## Calc is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
## Public License for more details.
##
## A copy of version 2.1 of the GNU Lesser General Public License is
## distributed with calc under the filename COPYING-LGPL. You should have
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Loading