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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#!/bin/sh
# aside from this initial boilerplate, this is actually -*- scheme -*- code
main="(module-ref (resolve-module '(gint extract-exports)) 'main)
"
exec ${GUILE-guile} -l $0 -c "(apply $main (command-line))" "$@"
!#
;;;; This file is part of Gint
;;;; Copyright (C) 2010 Sergey Poznyakoff
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 3, or (at your option)
;;;; any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (gint extract-exports)
:use-module (ice-9 getopt-long))
(define (snarf-exports)
(let loop ((elt (read)))
(cond
((not (eof-object? elt))
(if (and (pair? elt)
(eq? (car elt) 'id)
(string? (cdr elt))
(string=? (cdr elt) "fname"))
(let ((name (read)))
(if (string? name)
(format #t "(export ~A)~%" name))))
(loop (read))))))
(define output-file-name #f)
(define input-file-list '())
(define (usage)
(display "usage: extract-exports [OPTIONS] [FILE [FILE...]]\n")
(display "\n")
(display "OPTIONS are:\n")
(display " -o, --output FILE set output file name\n")
(display " -h, --help display this help summary\n"))
(define (do-file-list)
(if (null? input-file-list)
(snarf-exports)
(for-each
(lambda (file)
(with-input-from-file
file
snarf-exports))
input-file-list)))
(define (main . cmdline)
(let ((grammar `((output (single-char #\o)
(value #t))
(help (single-char #\h)))))
(for-each
(lambda (x)
(case (car x)
((output)
(set! output-file-name (cdr x)))
((help)
(usage)
(exit 0))
('()
(set! input-file-list (cdr x)))))
(getopt-long cmdline grammar)))
(if output-file-name
(with-output-to-file
output-file-name
do-file-list)
(do-file-list)))
|