CVSROOT: /cvsroot/lilypond Module name: lilypond Branch: Changes by: Jan Nieuwenhuizen <[EMAIL PROTECTED]> 05/05/14 21:43:05
Modified files: scripts : lilypond-invoke-editor.scm scm : output-ps.scm lily.scm editor.scm backend-library.scm lily : main.cc includable-lexer.cc flower/include : file-path.hh flower : file-path.cc file-name.cc Documentation/pictures: GNUmakefile . : ChangeLog Log message: * scripts/lilypond-invoke-editor.scm (dissect-uri): Handle URIs with Windows root in file name. * scm/backend-library.scm (ly:system): Only redirect output (using system and shell, ugh) if /dev/null is writable. * Documentation/pictures/GNUmakefile [PLATFORM_WINDOWS]: Build windows icon. * scm/lily.scm (is-absolute?): New function. Fixes absolute files on Mingw. * scm/output-ps.scm (grob-cause): Use it. Fixes PDF point and click. * flower/file-path.cc (is_dir, is_file): New function. Actually use result of stat when available. * flower/file-path.cc (find): Use it. Refactor. Fixes Mingw, absolute file name and root. * scm/lily.scm (PLATFORM): On mingw, slashify getcwd. * scm/editor.scm (get-editor-command): Typo: do not apply editor. * flower/file-name.cc (slashify): Bugfix, do substitute if no slashes in file name. CVSWeb URLs: http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scripts/lilypond-invoke-editor.scm.diff?tr1=1.1&tr2=1.2&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scm/output-ps.scm.diff?tr1=1.137&tr2=1.138&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scm/lily.scm.diff?tr1=1.336&tr2=1.337&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scm/editor.scm.diff?tr1=1.3&tr2=1.4&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scm/backend-library.scm.diff?tr1=1.23&tr2=1.24&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/main.cc.diff?tr1=1.250&tr2=1.251&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/includable-lexer.cc.diff?tr1=1.46&tr2=1.47&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/flower/include/file-path.hh.diff?tr1=1.18&tr2=1.19&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/flower/file-path.cc.diff?tr1=1.31&tr2=1.32&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/flower/file-name.cc.diff?tr1=1.8&tr2=1.9&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/Documentation/pictures/GNUmakefile.diff?tr1=1.7&tr2=1.8&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ChangeLog.diff?tr1=1.3612&tr2=1.3613&r1=text&r2=text Patches: Index: lilypond/ChangeLog diff -u lilypond/ChangeLog:1.3612 lilypond/ChangeLog:1.3613 --- lilypond/ChangeLog:1.3612 Fri May 13 16:13:34 2005 +++ lilypond/ChangeLog Sat May 14 21:43:04 2005 @@ -1,3 +1,33 @@ +2005-05-14 Jan Nieuwenhuizen <[EMAIL PROTECTED]> + + * scripts/lilypond-invoke-editor.scm (dissect-uri): Handle URIs + with Windows root in file name. + + * scm/backend-library.scm (ly:system): Only redirect output (using + system and shell, ugh) if /dev/null is writable. + + * Documentation/pictures/GNUmakefile [PLATFORM_WINDOWS]: Build + windows icon. + + * scm/lily.scm (is-absolute?): New function. Fixes absolute files + on Mingw. + + * scm/output-ps.scm (grob-cause): Use it. Fixes PDF point and + click. + + * flower/file-path.cc (is_dir, is_file): New function. Actually + use result of stat when available. + + * flower/file-path.cc (find): Use it. Refactor. Fixes Mingw, + absolute file name and root. + + * scm/lily.scm (PLATFORM): On mingw, slashify getcwd. + + * scm/editor.scm (get-editor-command): Typo: do not apply editor. + + * flower/file-name.cc (slashify): Bugfix, do substitute if no + slashes in file name. + 2005-05-13 Jan Nieuwenhuizen <[EMAIL PROTECTED]> * Documentation/user/preface.itely (Preface): Run Index: lilypond/Documentation/pictures/GNUmakefile diff -u lilypond/Documentation/pictures/GNUmakefile:1.7 lilypond/Documentation/pictures/GNUmakefile:1.8 --- lilypond/Documentation/pictures/GNUmakefile:1.7 Fri May 13 15:45:33 2005 +++ lilypond/Documentation/pictures/GNUmakefile Sat May 14 21:43:04 2005 @@ -6,18 +6,15 @@ OUTPNG_FILES = $(addprefix $(outdir)/,$(XPM_FILES:.xpm=.png)) EXTRA_DIST_FILES= $(XPM_FILES) -OUT_DIST_FILES = $(icon) #$(package-icon) + +ifeq ($(PLATFORM_WINDOWS),yes) +OUT_DIST_FILES = $(icon) # $(package-icon) icon = $(outdir)/lilypond.ico ICON_SIZES=48 32 16 #$(outdir)/lilypond.ico: platte-lucht-kikker-ly-48.xpm -include $(depth)/make/stepmake.make - -default: $(icon) -local-dist: $(icon) # $(package-icon) - $(outdir)/%.ico: $(ICON_SIZES:%=$(outdir)/\%-%.png) $(ICON_SIZES:%=$(outdir)/\%-%-8.png) #convert +adjoin $^ $@ icotool --output=$@ --create $^ @@ -36,9 +33,13 @@ $(outdir)/%-8.png: $(outdir)/%.png convert -depth 8 $< $@ +endif # PLATFORM_WINDOWS +include $(depth)/make/stepmake.make + +default: $(icon) +local-dist: $(icon) # $(package-icon) xgifs: $(OUTGIF_FILES) pngs: $(OUTPNG_FILES) - local-WWW: $(OUTPNG_FILES) Index: lilypond/flower/file-name.cc diff -u lilypond/flower/file-name.cc:1.8 lilypond/flower/file-name.cc:1.9 --- lilypond/flower/file-name.cc:1.8 Fri May 13 15:45:33 2005 +++ lilypond/flower/file-name.cc Sat May 14 21:43:04 2005 @@ -54,7 +54,7 @@ static String slashify (String file_name) { - if (file_name.index ('/')) + if (file_name.index ('/') >= 0) return file_name; file_name.substitute ('\\', '/'); file_name.substitute ("\"", "\\\""); Index: lilypond/flower/file-path.cc diff -u lilypond/flower/file-path.cc:1.31 lilypond/flower/file-path.cc:1.32 --- lilypond/flower/file-path.cc:1.31 Fri May 13 15:45:33 2005 +++ lilypond/flower/file-path.cc Sat May 14 21:43:04 2005 @@ -22,6 +22,7 @@ #endif #include "file-name.hh" +#include "warn.hh" #ifndef PATHSEP #define PATHSEP ':' @@ -47,6 +48,54 @@ } } +static bool +is_file (String file_name) +{ +#if 0 /* Check if directory. TODO: encapsulate for autoconf */ + struct stat sbuf; + if (stat (file_name.to_str0 (), &sbuf) != 0) + return false; + + if (!(sbuf.st_mode & __S_IFREG)) + return false; +#endif +#if !STAT_MACROS_BROKEN + struct stat sbuf; + if (stat (file_name.to_str0 (), &sbuf) != 0) + return false; + + return !S_ISDIR (sbuf.st_mode); +#endif + + if (FILE *f = fopen (file_name.to_str0 (), "r")) + { + fclose (f); + return true; + } + + return false; +} + +static bool +is_dir (String file_name) +{ +#if !STAT_MACROS_BROKEN + struct stat sbuf; + if (stat (file_name.to_str0 (), &sbuf) != 0) + return false; + + return S_ISDIR (sbuf.st_mode); +#endif + + if (FILE *f = fopen (file_name.to_str0 (), "r")) + { + fclose (f); + return true; + } + return false; +} + + /** Find a file. Check absolute file name, search in the current dir (DUH! FIXME!), @@ -62,51 +111,24 @@ if (!name.length () || (name == "-")) return name; +#ifdef __MINGW32__ + if (name[0] == '\\' || (name.length () > 2 && name[2] == '\\')) + programming_error ("file name not normalized: " + name); +#endif /* __MINGW32__ */ + /* Handle absolute file name. */ - if (name[0] == DIRSEP) - { - if (FILE *f = fopen (name.to_str0 (), "r")) - { - fclose (f); - return name; - } - } + File_name file_name (name); + if (file_name.dir_[0] == DIRSEP && is_file (file_name.to_string ())) + return file_name.to_string (); - for (int i = 0; i < size (); i++) + for (int i = 0, n = size (); i < n; i++) { - String file_name = elem (i); - String sep = ::to_string (DIRSEP); - String right (file_name.right_string (1)); - if (file_name.length () && right != sep) - file_name += ::to_string (DIRSEP); - - file_name += name; - -#if 0 /* Check if directory. TODO: encapsulate for autoconf */ - struct stat sbuf; - if (stat (file_name.to_str0 (), &sbuf) != 0) - continue; - - if (! (sbuf.st_mode & __S_IFREG)) - continue; -#endif -#if !STAT_MACROS_BROKEN - - struct stat sbuf; - if (stat (file_name.to_str0 (), &sbuf) != 0) - continue; - - if (S_ISDIR (sbuf.st_mode)) - continue; -#endif - - /* ugh */ - FILE *f = fopen (file_name.to_str0 (), "r"); - if (f) - { - fclose (f); - return file_name; - } + File_name dir = elem (i); + file_name.root_ = dir.root_; + dir.root_ = ""; + file_name.dir_ = dir.to_string (); + if (is_file (file_name.to_string ())) + return file_name.to_string (); } return ""; } @@ -151,9 +173,8 @@ { if (s == "") s = "."; - if (FILE *f = fopen (s.to_str0 (), "r")) + if (is_dir (s)) { - fclose (f); append (s); return true; } @@ -164,8 +185,7 @@ File_path::to_string () const { String s; - int n = size (); - for (int i = 0; i < n; i++) + for (int i = 0, n = size (); i < n; i++) { s = s + elem (i); if (i < n - 1) Index: lilypond/flower/include/file-path.hh diff -u lilypond/flower/include/file-path.hh:1.18 lilypond/flower/include/file-path.hh:1.19 --- lilypond/flower/include/file-path.hh:1.18 Thu Mar 10 14:36:16 2005 +++ lilypond/flower/include/file-path.hh Sat May 14 21:43:04 2005 @@ -1,5 +1,5 @@ /* - file-path.hh -- declare File_name and File_path + file-path.hh -- declare File_path source file of the Flower Library Index: lilypond/lily/includable-lexer.cc diff -u lilypond/lily/includable-lexer.cc:1.46 lilypond/lily/includable-lexer.cc:1.47 --- lilypond/lily/includable-lexer.cc:1.46 Tue Apr 12 22:49:28 2005 +++ lilypond/lily/includable-lexer.cc Sat May 14 21:43:04 2005 @@ -133,9 +133,7 @@ Includable_lexer::~Includable_lexer () { while (!include_stack_.is_empty ()) - { - close_input (); - } + close_input (); } Source_file * @@ -143,6 +141,5 @@ { if (include_stack_.is_empty ()) return 0; - else - return include_stack_.top (); + return include_stack_.top (); } Index: lilypond/lily/main.cc diff -u lilypond/lily/main.cc:1.250 lilypond/lily/main.cc:1.251 --- lilypond/lily/main.cc:1.250 Fri May 13 15:45:33 2005 +++ lilypond/lily/main.cc Sat May 14 21:43:04 2005 @@ -590,6 +590,12 @@ } } +#ifdef __MINGW32__ +/* If no TTY and not using safe, assume running from GUI. + For mingw, the test must be inverted. */ +# define isatty(x) (!isatty (x)) +#endif + int main (int argc, char **argv) { Index: lilypond/scm/backend-library.scm diff -u lilypond/scm/backend-library.scm:1.23 lilypond/scm/backend-library.scm:1.24 --- lilypond/scm/backend-library.scm:1.23 Fri May 13 15:45:32 2005 +++ lilypond/scm/backend-library.scm Sat May 14 21:43:04 2005 @@ -10,10 +10,11 @@ (define-public (ly:system command) (let* ((status 0) - (silenced - (string-append command (if (ly:get-option 'verbose) - "" - " > /dev/null 2>&1 ")))) + (dev-null "/dev/null") + (silenced (if (or (ly:get-option 'verbose) + (not (access? dev-null W_OK))) + command + (format #f "~a > ~a 2>&1 " command dev-null)))) (if (ly:get-option 'verbose) (ly:message (_ "Invoking `~a'...") command)) Index: lilypond/scm/editor.scm diff -u lilypond/scm/editor.scm:1.3 lilypond/scm/editor.scm:1.4 --- lilypond/scm/editor.scm:1.3 Fri May 13 16:13:34 2005 +++ lilypond/scm/editor.scm Sat May 14 21:43:04 2005 @@ -29,7 +29,7 @@ (define (get-command-template alist editor) (if (null? alist) (if (string-match "%\\(file\\)s" editor) - (editor) + editor (string-append editor " %(file)s")) (if (string-match (caar alist) editor) (cdar alist) Index: lilypond/scm/lily.scm diff -u lilypond/scm/lily.scm:1.336 lilypond/scm/lily.scm:1.337 --- lilypond/scm/lily.scm:1.336 Fri May 13 15:45:32 2005 +++ lilypond/scm/lily.scm Sat May 14 21:43:04 2005 @@ -77,6 +77,42 @@ (define-public TEX_STRING_HASHLIMIT 10000000) +;; Cygwin +;; #(CYGWIN_NT-5.1 Hostname 1.5.12(0.116/4/2) 2004-11-10 08:34 i686) +;; +;; Debian +;; #(Linux hostname 2.4.27-1-686 #1 Fri Sep 3 06:28:00 UTC 2004 i686) +;; +;; Mingw +;; #(Windows XP HOSTNAME build 2600 5.01 Service Pack 1 i686) +;; +(define PLATFORM + (string->symbol + (string-downcase + (car (string-tokenize (vector-ref (uname) 0) char-set:letter))))) + +(case PLATFORM + ((windows) + (define native-getcwd getcwd) + (define (slashify x) + (if (string-index x #\/) + x + (string-regexp-substitute "\\" "/" x))) + ;; FIXME: this prints a warning. + (define-public (ly-getcwd) + (slashify (native-getcwd)))) + (else (define-public ly-getcwd getcwd))) + +(define-public (is-absolute? file-name) + (let ((file-name-length (string-length file-name))) + (if (= file-name-length 0) + #f + (or (eq? (string-ref file-name 0) #\/) + (and (eq? PLATFORM 'windows) + (> file-name-length 2) + (eq? (string-ref file-name 1) #\:) + (eq? (string-ref file-name 2) #\/)))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (type-check-list location signature arguments) @@ -337,21 +373,30 @@ (use-modules (scm editor)) +(define (running-from-gui?) + (let ((have-tty? (isatty? (current-input-port)))) + ;; If no TTY and not using safe, assume running from GUI. + ;; For mingw, the test must be inverted. + (if (eq? PLATFORM 'windows) + have-tty? (not have-tty?)))) + (define-public (gui-main files) (if (null? files) (gui-no-files-handler)) (let* ((base (basename (car files) ".ly")) (log-name (string-append base ".log")) (log-file (open-file log-name "w"))) - ;; Ugh, his opens a terminal - ;; Do this when invoked using --quiet, --log or something? - ;; (ly:message (_ "Redirecting output to ~a...") log-name) + (if (not (running-from-gui?)) + (ly:message (_ "Redirecting output to ~a...") log-name)) (ly:port-move (fileno (current-error-port)) log-file) (ly:message "# -*-compilation-*-") - (if (null? (lilypond-all files)) - (exit 0) - (begin - (system (get-editor-command log-name 0 0)) - (exit 1))))) + (let ((failed (lilypond-all files))) + (if (pair? failed) + (begin + (system (get-editor-command log-name 0 0)) + (ly:error (_ "failed files: ~S") (string-join failed)) + ;; not reached? + (exit 1)) + (exit 0))))) (define (gui-no-files-handler) (let* ((ly (string-append (ly:effective-prefix) "/ly/")) @@ -362,7 +407,6 @@ (system cmd) (exit 1))) -;; If no TTY and not using safe, assume running from GUI. -(or (isatty? (current-input-port)) +(or (not (running-from-gui?)) (ly:get-option 'safe) (define lilypond-main gui-main)) Index: lilypond/scm/output-ps.scm diff -u lilypond/scm/output-ps.scm:1.137 lilypond/scm/output-ps.scm:1.138 --- lilypond/scm/output-ps.scm:1.137 Tue May 10 18:40:44 2005 +++ lilypond/scm/output-ps.scm Sat May 14 21:43:04 2005 @@ -106,18 +106,17 @@ (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket")) +(define (char font i) + (string-append + (ps-font-command font) " setfont " + "(\\" (ly:inexact->string i 8) ") show")) + (define (circle radius thick fill) (format "~a ~a ~a draw_circle" radius thick (if fill "true " - "false ") - )) - -(define (char font i) - (string-append - (ps-font-command font) " setfont " - "(\\" (ly:inexact->string i 8) ") show")) + "false "))) (define (dashed-line thick on off dx dy) (string-append @@ -204,10 +203,9 @@ "" (let* ((location (ly:input-file-line-column music-origin)) (raw-file (car location)) - (file (if (and (> (string-length raw-file) 0) - (eq? (string-ref raw-file 0) #\/)) + (file (if (is-absolute? raw-file) raw-file - (string-append (getcwd) "/" raw-file))) + (string-append (ly-getcwd) "/" raw-file))) (x-ext (ly:grob-extent grob grob X)) (y-ext (ly:grob-extent grob grob Y))) Index: lilypond/scripts/lilypond-invoke-editor.scm diff -u lilypond/scripts/lilypond-invoke-editor.scm:1.1 lilypond/scripts/lilypond-invoke-editor.scm:1.2 --- lilypond/scripts/lilypond-invoke-editor.scm:1.1 Tue May 10 21:58:45 2005 +++ lilypond/scripts/lilypond-invoke-editor.scm Sat May 14 21:43:04 2005 @@ -9,7 +9,9 @@ (use-modules (ice-9 getopt-long) - (ice-9 regex)) + (ice-9 regex) + (srfi srfi-13) + (srfi srfi-14)) (define PROGRAM-NAME "lilypond-invoke-editor") (define TOPLEVEL-VERSION "@TOPLEVEL_VERSION@") @@ -57,20 +59,42 @@ (define (dissect-uri uri) (let* ((ri "textedit://") (file-name:line:column (re-sub ri "" uri)) - (match (string-match "([^:]+):([^:]+):(.*)" file-name:line:column))) + (match (string-match "(.*):([^:]+):(.*)$" file-name:line:column))) (if match (list (match:substring match 1) (match:substring match 2) (match:substring match 3)) (begin + ;; FIXME: why be so strict wrt :LINE:COLUMN, + ;; esp. considering omitting textedit:// is explicitly + ;; allowed. (format (current-error-port) (_ "invalid URI: ~a") uri) (newline (current-error-port)) (format (current-error-port) (_ "expect: ~aFILE:LINE:COLUMN") ri) (newline (current-error-port)) (exit 1))))) - + +(define PLATFORM + (string->symbol + (string-downcase + (car (string-tokenize (vector-ref (uname) 0) char-set:letter))))) + +(define (running-from-gui?) + (let ((have-tty? (isatty? (current-input-port)))) + ;; If no TTY and not using safe, assume running from GUI. + ;; for mingw, the test must be inverted. + (if (eq? PLATFORM 'windows) + have-tty? (not have-tty?)))) + (define (main args) (let ((files (parse-options args))) + (if (running-from-gui?) + (redirect-port (current-error-port) + (open-file (string-append + (or (getenv "TMP") + (getenv "TEMP") + "/tmp") + "/lilypond-invoke-editor.log") "a"))) (if (not (= (length files) 1)) (begin (show-help (current-error-port)) _______________________________________________ Lilypond-cvs mailing list Lilypond-cvs@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-cvs