5 ; doc-split - split snarfed documentation into seperate files for
6 ; primitives, hooks, concepts, and variables.
8 (use-modules (ice-9 getopt-long)
14 ;(display "doc-split running\n")
15 (debug-enable 'debug 'backtrace)
16 (read-enable 'positions)
18 ; globals. not very schemy. but I don't care.
20 (define opt-verbose #f)
22 (define concept-fp #f)
27 ;-----------------------------------------------------------------------------
30 (let* ((opts (getopt-long (program-arguments)
31 `((verbose (single-char #\v))
32 (debug (single-char #\x))
37 ; (format #t "opts=~a\n" opts)
40 (let ((a (assq 'verbose opts)))
45 (let ((a (assq 'debug opts)))
49 (if (assq 'basename opts)
50 (set! fprefix (cdr (assq 'basename opts))))
52 (set! concept-fp (open-file (string-append fprefix "-concepts.txt") "w"))
53 (set! hook-fp (open-file (string-append fprefix "-hooks.txt") "w"))
54 (set! var-fp (open-file (string-append fprefix "-variables.txt") "w"))
55 (set! proc-fp (open-file (string-append fprefix "-procedures.txt") "w"))
59 (if opt-debug (format #t "~a:\n" f))
60 (let ((fp (open-file f "r")))
61 (with-input-from-port fp
63 (process-file-by-lines f)))
65 (pick string? (assq '() opts)))
73 ; Use the read-hash-extend facility to add a syntax for constant
74 ; regular expressions that are to be compiled once when read in,
75 ; instead of during the normal flow of execution. This can let loops
76 ; that repeatedly use a constant regexp be optimized without moving the
77 ; expression's definition far away from its use.
79 ; With this hash-extension, these two expressions behave identicaly:
81 ; (regexp-exec (make-regexp "de+") "abcdeeef"))
82 ; (regexp-exec #+"de+" "abcdeeef")
84 (read-hash-extend #\+ (lambda (c port)
85 (let ((s (read port)))
88 (error "bad #+ value; string expected")))))
91 (define (process-file-by-lines fname)
93 (do ((line (read-line)
95 ((eof-object? line) #f)
97 (if (string-index line #\np )
98 (let ((line (read-line)))
99 (if (not (eof-object? line))
102 ((regexp-exec #+"^Concept: " line)
103 (set! fp concept-fp))
104 ((regexp-exec #+"^Hook: " line)
106 ((regexp-exec #+"^Variable: " line)
108 ((regexp-exec #+"^Procedure: " line)
113 (format fp "\f\n~a\n" line)))))
115 (format fp "~a\n" line))