Skip to content

Commit 515981b

Browse files
committed
adding custom *pfe*
1 parent fe9cefe commit 515981b

File tree

7 files changed

+1750
-4
lines changed

7 files changed

+1750
-4
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ cal/test082.cal
3939
charbit.h
4040
chatbit
4141
chk_c
42+
.cache/clangd
4243
conf.h
4344
const_tmp
4445
cscript/4dsphere
@@ -53,6 +54,8 @@ cscript/simple
5354
cscript/square
5455
custom/.all
5556
custom/libcustcalc*
57+
custom/.gitignore
58+
compile_commands.json
5659
debug.out
5760
.dynamic
5861
endian

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
The following are the changes from calc version 2.15.0.7 to 2.15.0.8:
2+
3+
Adding support for pipe/fork/exec via custom functions.
4+
15
The following are the changes from calc version 2.15.0.6 to 2.15.0.7:
26

37
Thanks to GitHub user @bambooleafz a critical bug (GitHub issue

custom/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ include ${TARGET_MKF}
8585
#
8686
# Put your custom calc resource files here.
8787
#
88-
CUSTOM_CALC_FILES= argv.cal halflen.cal pzasusb8.cal pmodm127.cal register.cal
88+
CUSTOM_CALC_FILES= argv.cal halflen.cal pzasusb8.cal pmodm127.cal register.cal pfe.cal
8989

9090
# The custom help files to install
9191
#
9292
# Put your custom help files here.
9393
#
94-
CUSTOM_HELP= argv devnull help sysinfo pzasusb8 pmodm127 register
94+
CUSTOM_HELP= argv devnull help sysinfo pzasusb8 pmodm127 register pfe
9595

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

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

127127

128128
##########################################################################

custom/custtbl.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@ E_FUNC VALUE c_pzasusb8(char*, int, VALUE**);
7979
E_FUNC VALUE c_pmodm127(char*, int, VALUE**);
8080
E_FUNC VALUE c_register(char*, int, VALUE**);
8181

82+
#define U_FUNC(name) E_FUNC VALUE name(char*, int, VALUE**);
83+
84+
// pipe/fork/exec
85+
U_FUNC(u_pfe_fork)
86+
U_FUNC(u_pfe_pipe)
87+
U_FUNC(u_pfe_close)
88+
U_FUNC(u_pfe_execvp)
89+
U_FUNC(u_pfe_dup)
90+
U_FUNC(u_pfe_dup2)
91+
U_FUNC(u_pfe_write)
92+
U_FUNC(u_pfe_read)
93+
U_FUNC(u_pfe_select)
94+
U_FUNC(u_pfe_poll)
95+
96+
U_FUNC(u_pfe_wait4)
97+
98+
U_FUNC(u_pfe_pfe)
99+
U_FUNC(u_pfe_pwrite)
100+
U_FUNC(u_pfe_pread)
101+
102+
// vike's various additions
103+
U_FUNC(u_vadd_basename)
104+
U_FUNC(u_vadd_dirname)
105+
U_FUNC(u_vadd_getcwd)
106+
U_FUNC(u_vadd_getpid)
107+
U_FUNC(u_vadd_getppid)
108+
U_FUNC(u_vadd_inputname) //cspell:ignore inputname
82109

83110
#endif /* CUSTOM */
84111

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

166+
{ "fork", "create process",
167+
0, 0, u_pfe_fork },
168+
{ "pipe", "create descriptor pair for interprocess communication",
169+
0, 0, u_pfe_pipe },
170+
{ "dup", "duplicate a file descriptor",
171+
1, 1, u_pfe_dup },
172+
{ "dup2", "duplicate a file descriptor",
173+
2, 2, u_pfe_dup2 },
174+
{ "close", "remove a file descriptor",
175+
1, 1, u_pfe_close },
176+
{ "execvp", "execute a file",
177+
2, 2, u_pfe_execvp },
178+
{ "write", "write output",
179+
2, 2, u_pfe_write },
180+
{ "read", "read input",
181+
1, 2, u_pfe_read },
182+
{ "select", "examine file descriptors",
183+
3, 4, u_pfe_select },
184+
{ "poll", "synchronous I/O multiplexing",
185+
2, 3, u_pfe_poll },
186+
187+
{ "wait4", "wait for process",
188+
1, 4, u_pfe_wait4 },
189+
190+
{ "pfe", "pipe/fork/exec",
191+
4, 4, u_pfe_pfe },
192+
{ "pwrite", "write and close",
193+
2, 2, u_pfe_pwrite },
194+
{ "pread", "read until eof, close and wait for exit status",
195+
3, 3, u_pfe_pread },
196+
197+
{ "getpid", "get calling process identification",
198+
0, 0, u_vadd_getpid },
199+
{ "getppid", "get parent process identification",
200+
0, 0, u_vadd_getppid },
201+
{ "getcwd", "get working directory pathname",
202+
0, 0, u_vadd_getcwd },
203+
{ "inputname", "get name of input",
204+
0, 0, u_vadd_inputname },
205+
{ "basename", "extract the base portion of a pathname",
206+
1, 1, u_vadd_basename },
207+
{ "dirname", "extract the directory part of a pathname",
208+
1, 1, u_vadd_dirname },
209+
139210

140211
#endif /* CUSTOM */
141212

custom/pfe

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
NAME
2+
pfe - pipe/fork/exec and friends
3+
4+
SYNOPSIS
5+
pipe = custom("pipe") ## create descriptor pair for interprocess communication
6+
pid = custom("fork") ## create process
7+
tgt = custom("dup", src) ## duplicate a file descriptor
8+
tgt = custom("dup2", src, tgt) ## duplicate a file descriptor
9+
e = custom("close", fd) ## remove a file descriptor
10+
e = custom("execvp", arg0, args) ## execute a file
11+
count = custom("write", fd, str) ## write output
12+
str = custom("read", fd) ## read input
13+
count = custom("select", rd, wt, exc[, timeout]) ## examine file descriptors
14+
count = custom("poll", chk, &ret[, msecs]) ## synchronous I/O multiplexing
15+
pid = custom("wait", [pid, ]&stt[, opts][, &usg]) ## wait for process
16+
17+
pid = custom("pfe", &in, &out, &err, args) ## pipe/fork/exec
18+
count = custom("pwrite", fd, str) ## write and close
19+
e = custom("pread", pid, out, err) ## read until eof, close and wait for exit status
20+
21+
str = custom("inputname") ## get name of input
22+
path = custom("getcwd") ## get working directory pathname
23+
24+
path = custom("basename", path) ## extract the base portion of a pathname
25+
path = custom("dirname", path) ## extract the directory part of a pathname
26+
27+
pid = custom("getpid") ## get calling process identification
28+
pid = custom("getppid") ## get parent process identification
29+
30+
TYPES
31+
fd int num
32+
pipe list of fd
33+
pid int num
34+
src tgt fd
35+
arg0 str
36+
args list of str
37+
e int num
38+
count int num
39+
rd wt exc list of fd
40+
in out err list of fd
41+
timeout num
42+
43+
arg1 str
44+
...argN str
45+
chk list of list(fd[, arg1[, ...argN]])
46+
ret list of list(fd[, arg1[, ...argN]])
47+
msec int num
48+
49+
stt assoc str => int num
50+
opts list of str
51+
usg assoc str => int num
52+
53+
path str
54+
55+
EXAMPLE
56+
global i, o, e
57+
if(pid = pfe(&i, &o, &e,list("sh","-c","read||:;echo $REPLY"))){
58+
pwrite(i,"test")
59+
pread(pid,o,e)}
60+
61+
LIMITS
62+
calc must be built with ALLOW_CUSTOM= -DCUSTOM
63+
calc must be executed with a -C arg.
64+
65+
LIBRARY
66+
none
67+
68+
SEE ALSO
69+
custom
70+
71+
## Copyright (C) 2024 Viktor Bergquist
72+
##
73+
## Calc is open software; you can redistribute it and/or modify it under
74+
## the terms of the version 2.1 of the GNU Lesser General Public License
75+
## as published by the Free Software Foundation.
76+
##
77+
## Calc is distributed in the hope that it will be useful, but WITHOUT
78+
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
79+
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
80+
## Public License for more details.
81+
##
82+
## A copy of version 2.1 of the GNU Lesser General Public License is
83+
## distributed with calc under the filename COPYING-LGPL. You should have
84+
## received a copy with calc; if not, write to Free Software Foundation, Inc.
85+
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
86+
##
87+
## Under source code control: 1997/03/09 20:28:01
88+
## File existed as early as: 1997
89+
##
90+
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
91+
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

0 commit comments

Comments
 (0)