1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%
3% File:         PXK:EXTERNALS.SL
4% Description:  Definitions of foreign language functions
5% Author:       Brian Beach, Hewlett-Packard CRC
6% Created:      19-Apr-84
7% Modified:     15-Feb-85 13:25:43
8% Mode:         Lisp
9% Package:
10% Status:       Open Source: BSD License
11%
12% (c) Copyright 1983, Hewlett-Packard Company, see the file
13%            HP_disclaimer at the root of the PSL file tree
14%
15%
16% Redistribution and use in source and binary forms, with or without
17% modification, are permitted provided that the following conditions are met:
18%
19%    * Redistributions of source code must retain the relevant copyright
20%      notice, this list of conditions and the following disclaimer.
21%    * Redistributions in binary form must reproduce the above copyright
22%      notice, this list of conditions and the following disclaimer in the
23%      documentation and/or other materials provided with the distribution.
24%
25% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27% THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28% PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNERS OR
29% CONTRIBUTORS
30% BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36% POSSIBILITY OF SUCH DAMAGE.
37%
38%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39%
40% Revisions:
41%
42% 17-Feb-89 (Chris Burdorf)
43% Changed name of sigset to sun3_sigset for sun os/4.
44% 05-Apr-88 (Julian Padget)
45%  Once more reinstated handle for alarm and ualarm.
46% 29-May-87 (Harold Carr & Leigh Stoller)
47%  Added external definition for setenv.
48% 05-May-87 (Leigh Stoller)
49%  Added external definitions for fast-math.sl. They are in float.c
50% 13-Apr-87 (Leigh Stoller & Harold Carr)
51%  Added external definition of allocatemorebps, defined in bpsheap.c.
52% 26-Sep-86 (Leigh Stoller)
53%  Added external entry for exit which is needed on the sun to pass an exit
54%  code back to unix.
55% 01-Sep-86 (Leigh Stoller)
56%  Added external-system to do a standard system call from C.
57% 19-Aug-86 (Leigh Stoller)
58%  Added entries for get_file_status, sigrelse, and sigset.
59% 15-Feb-85 13:25:18 (Brian Beach)
60%  Commented out a couple of functions for Pisces.
61% 01-Feb-85 (Bill Williams)
62%  Add external entries for Lisp terminal emulator.
63% 24-Jan-85 (Vicki O'Day)
64%  Added sleep entry.
65% 7-Jan-85 (Vicki O'Day)
66%  Removed nmodekeys entry.
67% 17-Dec-84 (Vicki O'Day)
68%  Added setlinebuf entry.
69%  Added syscall entry, for access to HP-UX system calls.  The syntax
70%  of this command is (syscall <system call #> <arg1> <arg2> ...).
71%  Currently, a limit of four arguments to the system call is imposed,
72%  since no system calls that we can use have more than this.  The
73%  various forms of execl do, but since we can't use fork now, we don't
74%  need this.  When we can use fork, the number of arguments allowed
75%  by syscall should be increased.
76% 7-Dec-84 (Vicki O'Day)
77%  Added nmodekeys entry, so 9836-users can call it.
78% 27-Sep-84 19:57:38 (Dave Matthews)
79%  Added an external function declaration for the new alterheapsize function.
80% 17-Jul-84 22:51:12 (RAM)
81%  Changed chdir to unixcd and time to external_time.
82%  Added external_stat, link, and unlink.
83%
84%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85
86(compiletime
87 (setf *foreign-functions* nil)
88 )
89
90(compiletime
91 (defmacro external-function (name args)
92     (setf *foreign-functions* (cons name *foreign-functions*))
93     (flag1 name 'foreignfunction)
94     `(de ,name ,args
95        (,name ,@args)
96        )))
97
98(off r2i)
99
100% Defined in echo.c
101%
102(external-function echoon               ())
103(external-function echooff              ())
104(external-function external_charsininputbuffer    (chan))
105(external-function flushstdoutputbuffer ())
106(external-function external_user_homedir_string    ())
107(external-function external_anyuser_homedir_string (user))
108
109
110% Defined in bpsheap.c
111%
112(external-function alterheapsize        (integer))
113(external-function allocatemorebps      (amount))
114(external-function get_imagefilepath    ())
115
116% Defined in file-status.c
117%
118(external-function get_file_status      (filename block flag))
119
120
121% Defined in os-hooks.c
122%
123(external-function os_startup_hook      (pargc pargv))
124(external-function os_cleanup_hook      ())
125(external-function get_execfilepath     ())
126
127
128% Defined in pslextras.c
129%
130(external-function external_alarm      (sec))
131(external-function external_ualarm     (usec repeat))
132(external-function external_time       (buffer))
133(external-function external_timc       (buffer))
134(external-function external_stat       (path buf))
135(external-function external_rmdir      (path))
136(external-function external_mkdir      (path mode))
137(external-function external_link       (path1 path2))
138(external-function external_unlink     (path))
139(external-function external_strlen     (strptr))
140(external-function external_setenv     (varstring valstring))
141(external-function external_getenv     (envstring))
142(external-function uxfloat             (buffer integer))
143(external-function uxfix               (buffer))
144(external-function uxassign            (arg1-buffer arg2-buffer))
145(external-function uxplus2             (result-buffer arg1-buffer arg2-buffer))
146(external-function uxdifference        (result-buffer arg1-buffer arg2-buffer))
147(external-function uxtimes2            (result-buffer arg1-buffer arg2-buffer))
148(external-function uxquotient          (result-buffer arg1-buffer arg2-buffer))
149(external-function uxminus             (arg1-buffer arg2-buffer))
150(external-function uxgreaterp          (arg1-buffer arg2-buffer tee nill))
151(external-function uxlessp             (arg1-buffer arg2-buffer tee nill))
152(external-function uxwritefloat        (buffer floatptr convstr))
153(external-function uxwritefloat8       (buffer floatptr convstr dummy))
154(external-function uxdoubletofloat     (x y))
155(external-function uxfloattodouble     (y y))
156(external-function uxsin               (r x))
157(external-function uxcos               (r x))
158(external-function uxtan               (r x))
159(external-function uxasin              (r x))
160(external-function uxacos              (r x))
161(external-function uxatan              (r x))
162(external-function uxsqrt              (r x))
163(external-function uxexp               (r x))
164(external-function uxlog               (r x))
165(external-function uxatan2             (r y x))
166
167(external-function get_registry_value  (key subkey name infobuffer))
168
169
170% Defined in pwd-fn.c
171%
172(external-function external_pwd         ())
173
174
175% Defined in sigs.c
176%
177(external-function sun3_sigset         (signame handler))
178(external-function sigrelse            (signame))
179(external-function _resetstkoflw       ())
180
181% Defined In unexec.c
182%
183(external-function unexec               (newname aname dstart bstart))
184
185
186% Defined in unix-io.c
187%
188(external-function unixputc             (ch))
189(external-function unixputs             (str))
190(external-function unixputn             (num))
191(external-function unixcleario          ())
192(external-function expand_file_name     (str))
193(external-function unixopen             (name mode))
194(external-function unixcd               (dir))
195(external-function ctime                (buffer))
196(external-function external_system      (command))
197(external-function external_fullpath    (relpath))
198
199
200% Defined In the C Library
201%
202(external-function external_exit        (status))
203(external-function fopen                (name mode))
204(external-function fclose               (fp))
205(external-function fread                (buf size count fp))
206(external-function fputc                (ch fp))
207(external-function fgetc                (fp))
208(external-function fgets                (buf count fp))
209(external-function fwrite               (str strlen count fp))
210(external-function fflush               (fp))
211(external-function fseek                (fp offset ptrname))
212(external-function clearerr             (fp))
213(external-function xgetw                (fp))
214(external-function putw                 (w fp))
215(external-function signal               (signame handler))
216(external-function sleep        (sec))
217(external-function ieee_handler (str1 str2 handl))
218(external-function ieee_flags		(str1 str2 str3 str4))
219
220%% See $pxnk/sys-io.sl for the call to this. In SYS V, it may have to be
221%% moved into the microkernel since it is not directly supported. Under
222%% SYS V, buffering can only be changed before any writes on the stream,
223%% which means it must be called before setupbpsandheap. Also, under BSD,
224%% setlinebuf is a system call, while under SYS V, it must be written using
225%% setbuf and setvbuf. See the Bobcat version of setlinebuf.c in $pb.
226(external-function setlinebuf           (iobuff))
227
228(external-function getpid ())
229(external-function gethostid ())
230
231%%socketinterface
232
233(external-function unixsocketopen (name number))
234(external-function getsocket (fd name number))
235(external-function writesocket (fd name number))
236(external-function unixclosesocket (number))
237
238%% fork and wait
239
240(external-function fork())
241(external-function wait(ptr))
242
243%% popen, pclose
244
245(external-function popen                (cmd mode))
246(external-function pclose               (stream))
247
248%% shared memory , semaphores
249
250(external-function shmctl (shmid cmd buf))
251(external-function shmget (key size shmflg))
252(external-function shmat  (shmid shmaddr  shmflag))
253(external-function shmdt (shmaddr))
254
255(external-function semctl (semid semnum cmd arg))
256(external-function semget (key nsems semflg))
257(external-function semop  (semid sembuf nsops))
258
259
260(on r2i)
261
262(compiletime
263 (for (in name *foreign-functions*)
264      (do (remflag1 name 'foreignfunction))
265      ))
266
267(compiletime (flag '(profil) 'foreignfunction))
268
269(de unix-profile (a b c d)
270   (profil a b c d))
271
272(compiletime (remflag '(profil) 'foreignfunction))
273
274