Debian Codegraph @

lib/compat/stk.scm

raw
1 ;;;
2 ;;; port.stk - stk compatibility interface
3 ;;;
4 ;;; Copyright (c) 2000-2024 Shiro Kawai <[email protected]>
5 ;;;
6 ;;; Redistribution and use in source and binary forms, with or without
7 ;;; modification, are permitted provided that the following conditions
8 ;;; are met:
9 ;;;
10 ;;; 1. Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
12 ;;;
13 ;;; 2. Redistributions in binary form must reproduce the above copyright
14 ;;; notice, this list of conditions and the following disclaimer in the
15 ;;; documentation and/or other materials provided with the distribution.
16 ;;;
17 ;;; 3. Neither the name of the authors nor the names of its contributors
18 ;;; may be used to endorse or promote products derived from this
19 ;;; software without specific prior written permission.
20 ;;;
21 ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ;;;
33
34 #!no-fold-case
35
36 (define-module compat.stk
37 (use scheme.list)
38 (use scheme.charset)
39 (use srfi.13)
40 (use gauche.sequence)
41 (export *argc*
42 copy-tree remq remv remove string->uninterned-symbol bignum?
43 string-find string-index string-lower string-upper split-string
44 vector-copy vector-resize promise? continuation? catch
45 procedure-body input-file-port? output-file-port? open-file
46 close-port port-closed? try-load autoload?
47 when-port-readable when-port-writable error
48 input-string-port? output-string-port? read-from-string
49 open-input-virtual open-output-virtual
50 input-virtual-port? output-virtual-port?
51 keyword->string
52 environment? the-environment parent-environment global-environment
53 environment->list procedure-environment
54 eval-hook
55 export-symbol export-all-symbols
56 module-environment module-symbols
57 macro macro? macro-expand macro-expand-1 macro-body
58 address-of address?
59 set-signal-handler! add-signal-handler! get-signal-handlers
60 send-signal
61 getcwd chdir getpid expand-file-name canonical-path
62 system getenv setenv! file-is-readable? file-is-writable?
63 file-is-executable? glob remove-file rename-file
64 temporary-file-name
65 gc gc-stats expand-heap version machine-type
66 random set-random-seed! dump get-internal-info
67 time uncode
68 posix-perror posix-stat posix-stat->vector
69 posix-access posix-pipe posix-unlink posix-symlink
70 posix-chmod posix-rename posix-getlogin posix-mkdir
71 posix-rmdir posix-time posix-ctime posix-localtime
72 posix-gmtime posix-mktime posix-tm->vector vector->posix-tm
73 posix-strftime posix-fork posix-wait posix-uname
74 posix-host-name posix-domain-name
75 )
76 )
77 (select-module compat.stk)
78
79 ;(define *argc* (length *argv*))
80
81 ; copy-tree
82
83 (define (remq item list) (delete item list eq?))
84 (define (remv item list) (delete item list eqv?))
85 (define (remove item list) (delete item list equal?))
86
87 ; string->uninterned-symbol
88 ; bignum?
89
90 (define (string-find sub str)
91 (number? (string-contains str sub)))
92 (define (string-index sub str)
93 (string-contains str sub))
94 (define string-lower string-downcase)
95 (define string-upper string-upcase)
96 (define (split-string str :optional (delim #[\s]))
97 (string-tokenize str (char-set-complement delim)))
98
99 ; vector-copy
100 ; vector-resize
101
102 ; promise?
103 ; continuation?
104 ; catch
105 ; procedure-body
106
107 ; input-file-port?
108 ; output-file-port?
109 ; open-file
110 ; close-port
111 ; port-closed?
112
113 ; try-load
114 ; autoload?
115
116 ; when-port-readable
117 ; when-port-writable
118
119 (define error errorf)
120
121 ; input-string-port?
122 ; output-string-port?
123
124 (define (read-from-string str) (with-input-from-string str read))
125
126 ; open-input-virtual
127 ; open-output-virtual
128 ; input-virtual-port?
129 ; output-virtual-port?
130
131 ; keyword->string
132
133 ; environment?
134 ; the-environment
135 ; parent-environent
136 ; global-environment
137 ; environment->list
138 ; procedure-environment
139
140 ; eval-hook
141
142 ; export-symbol
143 ; export-all-symbols
144
145 ; module-environment
146 ; module-symbols
147
148 ; macro
149 ; macro?
150 ; macro-expand
151 ; macro-expand-1
152 ; macro-body
153
154 ; address-of
155 ; address?
156
157 ; set-signal-handler!
158 ; add-signal-handler!
159 ; get-signal-handlers
160 ; send-signal
161
162 (define getcwd sys-getcwd)
163 (define chdir sys-chdir)
164 (define getpid sys-getpid)
165 (define (expand-file-name name)
166 (sys-normalize-pathname name :expand #t))
167 (define (canonical-path name)
168 (sys-normalize-pathname name :canonical #t))
169 (define system sys-system)
170 (define getenv sys-getenv)
171 (define setenv! sys-putenv)
172
173 (define (file-is-readable? file) (sys-access file R_OK))
174 (define (file-is-writable? file) (sys-access file W_OK))
175 (define (file-is-executable? file) (sys-access file X_OK))
176
177 (define glob sys-glob)
178 (define remove-file sys-unlink)
179 (define rename-file sys-rename)
180 (define temporary-file-name sys-tmpnam)
181
182 (define (eval-string str) (eval (read-from-string str)))
183
184 ; gc
185 ; gc-stats
186 ; expand-heap
187 (define version gauche-version)
188 ; machine-type
189 (define random sys-random)
190 (define set-random-seed! sys-srandom)
191 ; dump
192 ; get-internal-info
193 ; time
194 ; uncode
195
196 ;; POSIX
197 (provide "posix") ; to fool (require "posix")
198
199 ; *errno*
200 ; posix-perror
201
202 (define posix-stat sys-stat)
203 (define (posix-stat->vector stat)
204 (apply vector
205 (map (^p (p stat))
206 (list sys-stat->dev
207 sys-stat->ino
208 sys-stat->mode
209 sys-stat->nlink
210 sys-stat->uid
211 sys-stat->gid
212 sys-stat->size
213 sys-stat->atime
214 sys-stat->mtime
215 sys-stat->ctime))))
216 (define posix-access sys-access)
217 (define (posix-pipe)
218 (receive io (sys-pipe) io))
219 (define posix-unlink sys-unlink)
220 (define posix-symlink sys-symlink)
221 (define posix-chmod sys-chmod)
222 (define posix-rename sys-rename)
223 (define posix-getlogin sys-getlogin)
224 (define posix-rmdir sys-rmdir)
225 (define posix-time sys-time)
226 (define posix-ctime sys-ctime)
227 (define posix-localtime sys-localtime)
228 (define posix-gmtime sys-gmtime)
229 (define posix-mktime sys-mktime)
230 (define (posix-tm->vector tm)
231 (error "not implemented yet"))
232 (define (vector->posix-tm tm)
233 (error "not implemented yet"))
234 (define posix-strftime sys-strftime)
235 (define posix-fork sys-fork)
236 (define (posix-wait)
237 (receive st (sys-wait) st))
238 (define (posix-uname)
239 (list->vector (sys-uname)))
240 (define posix-host-name sys-gethostname)
241 (define posix-domain-name sys-getdomainname)