]> git.donarmstrong.com Git - lilypond.git/commitdiff
* scripts/lilypond-invoke-editor.scm (dissect-uri): Handle URIs
authorJan Nieuwenhuizen <janneke@gnu.org>
Sat, 14 May 2005 21:43:04 +0000 (21:43 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Sat, 14 May 2005 21:43:04 +0000 (21:43 +0000)
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.

12 files changed:
ChangeLog
Documentation/pictures/GNUmakefile
flower/file-name.cc
flower/file-path.cc
flower/include/file-path.hh
lily/includable-lexer.cc
lily/main.cc
scm/backend-library.scm
scm/editor.scm
scm/lily.scm
scm/output-ps.scm
scripts/lilypond-invoke-editor.scm

index 3219947beecce6988e9a0aa3c33b0403b916da2c..3fee7dbd95164ebeade9c9004c9d3f920604ace7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2005-05-14  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * 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  <janneke@gnu.org>
 
        * Documentation/user/preface.itely (Preface): Run
index 30873a98e33e431bff5008739ceba7f9eda2ee9f..7490fd6a5974b6be7d154a95209df4d5abf99241 100644 (file)
@@ -6,18 +6,15 @@ OUTGIF_FILES = $(addprefix $(outdir)/,$(XPM_FILES:.xpm=.gif))
 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)/%-16.png: %-48.xpm
 
 $(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 ac9e6832e0a351c7bf16ff25a6c124360a66fc70..f4ba75a18fe7cce26ab900878116a244660bb2d4 100644 (file)
@@ -54,7 +54,7 @@ dos_to_posix (String file_name)
 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 3711cf7c2f4fe96f9f95d6f954c6b06d46c1a459..f8504396cf0b9fcae5f09403457e709a317d4683 100644 (file)
@@ -22,6 +22,7 @@
 #endif
 
 #include "file-name.hh"
+#include "warn.hh"
 
 #ifndef PATHSEP
 #define PATHSEP ':'
@@ -47,6 +48,54 @@ File_path::parse_path (String p)
     }
 }
 
+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 @@ File_path::find (String name) const
   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 @@ File_path::try_append (String s)
 {
   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 @@ String
 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 f9d9f816ccbeb2279133ca4a75910f264aaa509e..3c7cc264617ddd179cbe84e01a22a0bc0e62e75c 100644 (file)
@@ -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 540f8de8f418c2fa1ebdd8a75aa4d275592c67ba..7cde6bfc3724ac7b063ce50251175835ca091ace 100644 (file)
@@ -133,9 +133,7 @@ Includable_lexer::here_str0 () const
 Includable_lexer::~Includable_lexer ()
 {
   while (!include_stack_.is_empty ())
-    {
-      close_input ();
-    }
+    close_input ();
 }
 
 Source_file *
@@ -143,6 +141,5 @@ Includable_lexer::get_source_file () const
 {
   if (include_stack_.is_empty ())
     return 0;
-  else
-    return include_stack_.top ();
+  return include_stack_.top ();
 }
index 7d490d8a6a1fcd5caf012a5313e5772c237e75b5..eb2f222d174a76227600f01958ad6fe294b6432e 100644 (file)
@@ -590,6 +590,12 @@ parse_argv (int argc, char **argv)
     }
 }
 
+#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 a9367de7c2896b39efe7448f296fc7fb46414065..5fef767162eaefaba4cbbfe854b4250598e4c765 100644 (file)
 
 (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 4bf560d24342530a8884fc48c578e9e35704000f..aeea02b615eb95cb432133ed256c6133bef8894a 100644 (file)
@@ -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 63da7812d9067ece4616dd1b591bdbfff25fe6cc..565a5e3c696526e188d6c42f0e1a7b7e70c46f1a 100644 (file)
 
 (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 @@ The syntax is the same as `define*-public'."
 
 (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 @@ The syntax is the same as `define*-public'."
     (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 aa6581adf47d78a3cd1fe2c8feb5b1f23d1be3c5..cc021b84234809fdaaae12fb4e0666b5a0bd9e94 100644 (file)
     (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 
        ""
        (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 81cf6f0a4ebe0059094b86cea3acce2944bcdd96..26e7e364a4bf9733b3394c18bc78919f14b10ac2 100755 (executable)
@@ -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 @@ Options:
 (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))