From c0476d4addfa1cd58cd85cad32b89bb9fd93eae4 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 22 Nov 2005 22:34:35 +0000 Subject: [PATCH] strip #! from start of programs svn: r1376 --- collects/compiler/private/driver.ss | 7 ++---- collects/mzlib/compile.ss | 6 +++-- collects/mzlib/file.ss | 36 ++++++++++++++--------------- collects/mzlib/port.ss | 11 ++++++++- collects/syntax/moddep.ss | 5 +++- 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/collects/compiler/private/driver.ss b/collects/compiler/private/driver.ss index 91a10d5ee4..22fb868bb2 100644 --- a/collects/compiler/private/driver.ss +++ b/collects/compiler/private/driver.ss @@ -63,6 +63,7 @@ (require (lib "unitsig.ss") (lib "list.ss") (lib "file.ss") + (lib "port.ss") (lib "etc.ss") (lib "pretty.ss") (prefix src2src: "../src2src.ss")) @@ -440,11 +441,7 @@ path)) p)))]) ;; Skip leading "#!: - (let loop ([s (regexp-match-peek #rx"^#![^\r\n]*" p)]) - (when s - (read-line p) - (when (regexp-match #rx"\\\\$" (car s)) - (loop (regexp-match-peek #rx"^[^\r\n]*" p))))) + (strip-shell-command-start p) p)) ;;------------------------------------------------------------------------------- diff --git a/collects/mzlib/compile.ss b/collects/mzlib/compile.ss index 088725804f..b3357bab77 100644 --- a/collects/mzlib/compile.ss +++ b/collects/mzlib/compile.ss @@ -1,6 +1,7 @@ (module compile mzscheme - (require "file.ss") + (require "file.ss" + "port.ss") (provide compile-file) ;; (require (lib "src2src.ss" "compiler")) @@ -23,7 +24,8 @@ (dynamic-wind void (lambda () - (port-count-lines! (current-input-port)) + (port-count-lines! in) + (strip-shell-command-start in) (with-handlers ([void (lambda (exn) (with-handlers ([void void]) diff --git a/collects/mzlib/file.ss b/collects/mzlib/file.ss index 786cdd2517..ea246511e9 100644 --- a/collects/mzlib/file.ss +++ b/collects/mzlib/file.ss @@ -1,26 +1,26 @@ (module file mzscheme (provide find-relative-path - explode-path - normalize-path - build-absolute-path - build-relative-path - filename-extension - file-name-from-path - path-only - delete-directory/files - copy-directory/files - make-directory* - make-temporary-file - find-library + explode-path + normalize-path + build-absolute-path + build-relative-path + filename-extension + file-name-from-path + path-only + delete-directory/files + copy-directory/files + make-directory* + make-temporary-file + find-library - get-preference - put-preferences + get-preference + put-preferences - call-with-input-file* - call-with-output-file* + call-with-input-file* + call-with-output-file* - fold-files - find-files) + fold-files + find-files) (require "list.ss" "etc.ss") diff --git a/collects/mzlib/port.ss b/collects/mzlib/port.ss index 1a928c372e..bc072e2cb7 100644 --- a/collects/mzlib/port.ss +++ b/collects/mzlib/port.ss @@ -19,7 +19,8 @@ convert-stream make-limited-input-port reencode-input-port - reencode-output-port) + reencode-output-port + strip-shell-command-start) (define (exact-non-negative-integer? i) (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) (unless (input-port? src) (raise-type-error 'copy-port "input-port" src)) diff --git a/collects/syntax/moddep.ss b/collects/syntax/moddep.ss index 35825cad38..1e280f1802 100644 --- a/collects/syntax/moddep.ss +++ b/collects/syntax/moddep.ss @@ -1,6 +1,7 @@ (module moddep mzscheme (require (lib "etc.ss") + (lib "port.ss") (lib "resolver.ss" "planet")) @@ -95,7 +96,9 @@ (define (read-one path src?) (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 void (lambda ()