File: channel.scm

package info (click to toggle)
scsh-0.6 0.6.7-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 15,124 kB
  • ctags: 16,788
  • sloc: lisp: 82,839; ansic: 23,112; sh: 3,116; makefile: 829
file content (52 lines) | stat: -rw-r--r-- 1,578 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
; Copyright (c) 1993-1999 by Richard Kelsey and Jonathan Rees. See file COPYING.

; Provides input and output channels.

(define (input-channel? thing)
  (and (channel? thing)
       (or (= (channel-status thing)
	      (enum channel-status-option input))
	   (= (channel-status thing)
	      (enum channel-status-option special-input)))))

(define (output-channel? thing)
  (and (channel? thing)
       (or (= (channel-status thing)
	      (enum channel-status-option output))
	   (= (channel-status thing)
	      (enum channel-status-option special-output)))))

;;; Scsh changes umask and cwd lazily
;;; placeholder until scsh sets it
(define (with-fs-context-aligned* thunk)
  (thunk))

(define (set-with-fs-context-aligned*! wpca*)
  (set! with-fs-context-aligned* wpca*))


(define (open-input-channel filename)
  (let ((channel (with-fs-context-aligned*
		  (lambda ()
		    (open-channel filename (enum channel-status-option input))))))
    (if (channel? channel)
	channel
	(error "cannot open input file" filename))))

(define (open-output-channel filename)
  (let ((channel (with-fs-context-aligned*
		  (lambda ()
		    (open-channel filename (enum channel-status-option output))))))
    (if (channel? channel)
	channel
	(error "cannot open output file" filename))))

(define (close-input-channel channel)
  (if (input-channel? channel)
      (close-channel channel)
      (call-error close-input-channel channel)))

(define (close-output-channel channel)
  (if (output-channel? channel)
      (close-channel channel)
      (call-error close-output-channel channel)))