strip #! from start of programs

svn: r1376
This commit is contained in:
Matthew Flatt 2005-11-22 22:34:35 +00:00
parent 3e53a3fd05
commit c0476d4add
5 changed files with 38 additions and 27 deletions

View File

@ -63,6 +63,7 @@
(require (lib "unitsig.ss") (require (lib "unitsig.ss")
(lib "list.ss") (lib "list.ss")
(lib "file.ss") (lib "file.ss")
(lib "port.ss")
(lib "etc.ss") (lib "etc.ss")
(lib "pretty.ss") (lib "pretty.ss")
(prefix src2src: "../src2src.ss")) (prefix src2src: "../src2src.ss"))
@ -440,11 +441,7 @@
path)) path))
p)))]) p)))])
;; Skip leading "#!: ;; Skip leading "#!:
(let loop ([s (regexp-match-peek #rx"^#![^\r\n]*" p)]) (strip-shell-command-start p)
(when s
(read-line p)
(when (regexp-match #rx"\\\\$" (car s))
(loop (regexp-match-peek #rx"^[^\r\n]*" p)))))
p)) p))
;;------------------------------------------------------------------------------- ;;-------------------------------------------------------------------------------

View File

@ -1,6 +1,7 @@
(module compile mzscheme (module compile mzscheme
(require "file.ss") (require "file.ss"
"port.ss")
(provide compile-file) (provide compile-file)
;; (require (lib "src2src.ss" "compiler")) ;; (require (lib "src2src.ss" "compiler"))
@ -23,7 +24,8 @@
(dynamic-wind (dynamic-wind
void void
(lambda () (lambda ()
(port-count-lines! (current-input-port)) (port-count-lines! in)
(strip-shell-command-start in)
(with-handlers ([void (with-handlers ([void
(lambda (exn) (lambda (exn)
(with-handlers ([void void]) (with-handlers ([void void])

View File

@ -1,26 +1,26 @@
(module file mzscheme (module file mzscheme
(provide find-relative-path (provide find-relative-path
explode-path explode-path
normalize-path normalize-path
build-absolute-path build-absolute-path
build-relative-path build-relative-path
filename-extension filename-extension
file-name-from-path file-name-from-path
path-only path-only
delete-directory/files delete-directory/files
copy-directory/files copy-directory/files
make-directory* make-directory*
make-temporary-file make-temporary-file
find-library find-library
get-preference get-preference
put-preferences put-preferences
call-with-input-file* call-with-input-file*
call-with-output-file* call-with-output-file*
fold-files fold-files
find-files) find-files)
(require "list.ss" (require "list.ss"
"etc.ss") "etc.ss")

View File

@ -19,7 +19,8 @@
convert-stream convert-stream
make-limited-input-port make-limited-input-port
reencode-input-port reencode-input-port
reencode-output-port) reencode-output-port
strip-shell-command-start)
(define (exact-non-negative-integer? i) (define (exact-non-negative-integer? i)
(and (number? i) (exact? i) (integer? i) (i . >= . 0))) (and (number? i) (exact? i) (integer? i) (i . >= . 0)))
@ -77,6 +78,14 @@
;; ---------------------------------------- ;; ----------------------------------------
(define (strip-shell-command-start in)
(when (regexp-match-peek #rx#"^#![^\r\n]*" in)
(let loop ([s (read-line in)])
(when (regexp-match #rx#"\\\\$" s)
(loop (read-line in))))))
;; ----------------------------------------
(define (copy-port src dest . dests) (define (copy-port src dest . dests)
(unless (input-port? src) (unless (input-port? src)
(raise-type-error 'copy-port "input-port" src)) (raise-type-error 'copy-port "input-port" src))

View File

@ -1,6 +1,7 @@
(module moddep mzscheme (module moddep mzscheme
(require (lib "etc.ss") (require (lib "etc.ss")
(lib "port.ss")
(lib "resolver.ss" "planet")) (lib "resolver.ss" "planet"))
@ -95,7 +96,9 @@
(define (read-one path src?) (define (read-one path src?)
(let ([p ((moddep-current-open-input-file) path)]) (let ([p ((moddep-current-open-input-file) path)])
(when src? (port-count-lines! p)) (when src?
(port-count-lines! p)
(strip-shell-command-start p))
(dynamic-wind (dynamic-wind
void void
(lambda () (lambda ()