summaryrefslogtreecommitdiffabout
path: root/scheme/dry-run.scm
blob: 5fcc0ad0e8a7a0a0dfeda20a5d1be2b6bff3d3bf (plain)
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
;; dry-run.scm - run a script and show the frames it produces.
;; This file is part of Idest
;; Copyright (C) 2011, 2015 Sergey Poznyakoff
;; Idest 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.
;;
;; Idest 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 Idest.  If not, see <http://www.gnu.org/licenses/>.

(let* ((cmd (command-line))
       (progname (car cmd)))
  (set! %load-hook (lambda (filename)
		     (format #t "~A: loading ~a ...\n"
			     progname filename)))
  (cond
   ((< (length cmd) 3)
    (format (current-error-port) "usage: idest -S ~A SCRIPT FILE...

Normally you don't need to run this program manually.  Instead please
use: idest --dry-run [SCRIPTING OPTIONS]~%"
	    progname)
    (exit 1))
   (else
    (let ((file-name (list-ref cmd 1)))
      (set-program-arguments (cons (car cmd) (list-tail cmd 2)))
      ; Note: a bug in Guile 2.0.9 causes %load-hook to be called twice
      (primitive-load-path file-name)
      (cond
       (idest-readonly
	(format (current-error-port)
		"~A: info: ~A does not modify frames~%" progname file-name))
       ((catch #t
	       (lambda ()
		 (procedure? idest-main))
	       (lambda (key . args)
		 #f))
	(set! idest-readonly #t)
	(let ((main-func idest-main))
	  (set! idest-main
		(lambda (file frames)
		  (let ((result (main-func file frames)))
		    (format #t "File ~A~%" file)
		    (cond
		     ((not result)
		      (format #t "No modifications~%"))
		     ((null? result)
		      (format #t "Would delete all frames~%"))
		     (else
		      (for-each (lambda (frame)
				  (display frame)
				  (newline))
				result))))))))
       (else
	(format (current-error-port)
		"~A: idest-main is not defined in ~A~%" progname file-name)
	(exit 1)))))))

Return to:

Send suggestions and report system problems to the System administrator.