File: listhome.scm

package info (click to toggle)
gimp 2.8.18-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 153,908 kB
  • sloc: ansic: 704,570; makefile: 10,969; lisp: 10,839; sh: 4,430; python: 3,793; perl: 3,411; xml: 1,307; yacc: 588; lex: 342
file content (58 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download | duplicates (12)
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
53
54
55
56
57
58
; listhome.scm
; Sample usage of TinyScheme Extension
; This simple program lists the directory entries on the
; user's home directory.

; It uses the following TinyScheme Extension functions:
;    getenv
;      Used to get HOME environment variable.
;    open-dir-stream
;      Used to open directory stream.
;    read-dir-entry
;      Used to read directory entries.
;    close-dir-entry
;      Used at the end, to close directory stream when done.

; check that extensions are enabled
(if (not (defined? 'load-extension))
    (begin
      (display "TinyScheme has extensions disabled. Enable them!!")
      (newline)
      (quit)))

; load TinyScheme extension
(load-extension "tsx-1.1/tsx")

; check that the necessary functions are available (the user
; might have removed some functionality...)
(if (or
      (not (defined? 'getenv))
      (not (defined? 'dir-open-stream))
      (not (defined? 'dir-read-entry))
      (not (defined? 'dir-close-stream)))
    (begin
      (display "Some necessary functions are not available. Exiting!")
      (newline)
      (quit)))

; get user's home dir from HOME environment var
(define homedir (getenv "HOME"))
(display "Listing contents of ") (display homedir) (newline)

; create directory stream to read dir entries
(define dirstream (dir-open-stream homedir))
(if (not dirstream)
  (begin
    (display "Unable to open home directory!! Check value of HOME environment var.")
    (quit)))

(let listentry ((entry (dir-read-entry dirstream)))
  (if (eof-object? entry)
    #t
    (begin
      (display entry)
      (newline)
      (listentry (dir-read-entry dirstream)))))

(dir-close-stream dirstream)