Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions .gitignore
Copy link
Owner

@lcn2 lcn2 Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are curious about these additions to .gitignore (not that we have any problem when them), @vike2000:

Can you tell us about each of the ignored additions? Some seem clang related and have hints at being useful. What do each of the excludes do?

Ignoring custom/.gitignore is an interning choice. We might skip that addition when we "mod your mod" to the .gitignore file.

How are you using such files?

Are you willing to give us, where makes sense, what sort of content they contain>
Perhaps, where reasonable and you feel comfortable, you could also attach ignored files as a tarball.

This won't impact our processing your PR: we just are interested in knowing.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cal/test082.cal
charbit.h
chatbit
chk_c
.cache/clangd
conf.h
const_tmp
cscript/4dsphere
Expand All @@ -53,6 +54,9 @@ cscript/simple
cscript/square
custom/.all
custom/libcustcalc*
custom/.gitignore
compile_commands.json
compile_flags.txt
debug.out
.dynamic
endian
Expand Down Expand Up @@ -184,4 +188,5 @@ unused_tmp
ustat_tmp
ver_calc
vs_tmp
.vscode
win32/
4 changes: 4 additions & 0 deletions CHANGES
Copy link
Owner

@lcn2 lcn2 Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our plan is to make your PR the basis for calc version 2.16.0.1, and so we will "mod your mod" and update CHANGES accordingly, including moving your "Adding support for pipe/fork/exec" change into that new section.

We will add a TODO about the pending changes prior to the calc v2 / v3 fork.

Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
The following are the changes from calc version 2.15.0.7 to 2.15.0.8:

Adding support for pipe/fork/exec via custom functions.

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 custhelp
Copy link
Owner

@lcn2 lcn2 Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this top level symlink, @vike2000 ? Is it needed or was it left in by mistake?

The custom help files will work once calc is installed.

BTW: We had to chmod 0444 custom/pfe

In the mean time, if you want to test something like help pfe before installing, use:

make run

This will launch the ./calc with the proper environment variables so that things like CALCCUSTOMHELP point to your local directory tree.

8 changes: 4 additions & 4 deletions custom/Makefile
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 although we will update as per make depend by a "mod of your mod".

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
2 changes: 1 addition & 1 deletion custom/c_help.c
Copy link
Owner

@lcn2 lcn2 Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, good catch. 👍

We wonder if this mistake you corrected has happened elsewhere in calc.

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
Copy link
Owner

@lcn2 lcn2 Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 (except for a minor bit of trailing whitespace where we will "mod your mod" 😉)

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the help file! Too many contributors fail to add this!

We plan to address the trailing whitespace and convert to the ASCII tab into spaces as your terminal appears to use a 4 character tab stop that others might not use. Better to use just ASCII space as they are more "portable" 🤓. So we plan to "mod your mod" 😉.

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