From 41b53ca7364669ca78dc522d98fa5ab552f9179a Mon Sep 17 00:00:00 2001
From: janneke <janneke>
Date: Mon, 23 May 2005 19:18:58 +0000
Subject: [PATCH] * lily/main.cc (setup_paths)[__MINGW32__]: Normalize
 LILYPONDPREFIX.

* lily/general-scheme.cc (ly:stderr-redirect): Rename from
ly:port-move.  Needs to be stderr-specific on mingw.
Run fixcc.

* lily/general-scheme.cc (ly:port-move): Remove.

* scm/backend-library.scm (postscript->pdf): Remove -dSAFER in
windows.

* lily/main.cc (setup_paths) [ARGV0_RELOCATION]: Reinstate GS_*
variables.  This eliminates the need for a gs.bat wrapper, which
opens a console.

* scripts/lilypond-invoke-editor.scm (running-from-gui?):
* scm/lily.scm (running-from-gui?):
* lily/main.cc[MINGW]: Remove isatty inversion, this is an
artifact of not compiling with -mwindows.

* scm/editor.scm: Define PLATFORM.
---
 ChangeLog                                  | 33 ++++++++++
 Documentation/user/advanced-notation.itely | 15 ++---
 lily/general-scheme.cc                     | 74 ++++++++++++----------
 lily/main.cc                               | 28 ++++++--
 scm/backend-library.scm                    |  4 +-
 scm/editor.scm                             | 24 ++++---
 scm/lily.scm                               | 13 ++--
 scripts/lilypond-invoke-editor.scm         |  4 +-
 8 files changed, 129 insertions(+), 66 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f4b14dec21..387ec86374 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,31 @@
+2005-05-23  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+	* lily/main.cc (setup_paths)[__MINGW32__]: Normalize LILYPONDPREFIX.
+
+2005-05-21  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+	* lily/general-scheme.cc (ly:stderr-redirect): Rename from
+	ly:port-move.  Needs to be stderr-specific on mingw.
+	Run fixcc.
+
+2005-05-20  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+	* lily/general-scheme.cc (ly:port-move): Remove.
+
+	* scm/backend-library.scm (postscript->pdf): Remove -dSAFER in
+	windows.
+
+	* lily/main.cc (setup_paths) [ARGV0_RELOCATION]: Reinstate GS_*
+	variables.  This eliminates the need for a gs.bat wrapper, which
+	opens a console.
+
+	* scripts/lilypond-invoke-editor.scm (running-from-gui?): 
+	* scm/lily.scm (running-from-gui?): 
+	* lily/main.cc[MINGW]: Remove isatty inversion, this is an
+	artifact of not compiling with -mwindows.
+
+	* scm/editor.scm: Define PLATFORM.
+
 2005-05-23  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
 	* scripts/lilypond-book.py (PREAMBLE_LY): add marker, where people
@@ -78,6 +106,11 @@
 
 2005-05-18  Jan Nieuwenhuizen  <janneke@gnu.org>
 
+	* Documentation/user/advanced-notation.itely (Text scripts):
+	Change nonexisting @internalsref{Text markup} to @ref{Text
+	markup}.  Change @internalsref{Text script} to
+	@internalsref{TextScript}.
+
 	* lily/main.cc (setup_paths): Bugfix: pangorc is not pango.modules.
 
 2005-05-17  Graham Percival  <gperlist@shaw.ca>
diff --git a/Documentation/user/advanced-notation.itely b/Documentation/user/advanced-notation.itely
index 74b1457d37..c936755fa5 100644
--- a/Documentation/user/advanced-notation.itely
+++ b/Documentation/user/advanced-notation.itely
@@ -49,11 +49,10 @@ your scores.
 @cindex text items, non-empty
 @cindex non-empty texts
 
-It is possible to place arbitrary strings of text or
-@internalsref{Text markup} above or below notes by using a string
-@code{c^"text"}.  By default, these indications do not influence the
-note spacing, but by using the command @code{\fatText}, the widths
-will be taken into account
+It is possible to place arbitrary strings of text or @ref{Text markup}
+above or below notes by using a string @code{c^"text"}.  By default,
+these indications do not influence the note spacing, but by using the
+command @code{\fatText}, the widths will be taken into account
 
 @lilypond[quote,fragment,raggedright,verbatim,relative=1]
 c4^"longtext" \fatText c4_"longlongtext" c4
@@ -66,7 +65,7 @@ c'4^\markup { bla \bold bla }
 @end lilypond
 
 The @code{\markup} is described in more detail in
-@internalsref{Text markup}.
+@ref{Text markup}.
 
 
 @refcommands
@@ -200,7 +199,7 @@ c1^\markup { hi \bold there, is \italic anyone home? }
 @end lilypond
 
 @noindent
-@code{\markup} is primarily used for @internalsref{Text scripts},
+@code{\markup} is primarily used for @internalsref{TextScript}s,
 but it can also be used anywhere text is called in lilypond
 
 @lilypond[quote,verbatim]
@@ -474,7 +473,7 @@ R1*2 | R1*5 | R1*9
 @cindex fermata on multi-measure rest
 
 Texts can be added to multi-measure rests by using the
-@var{note}-@code{markup} syntax @internalsref{Text markup}.
+@var{note}-@code{markup} syntax @ref{Text markup}.
 A variable (@code{\fermataMarkup}) is provided for
 adding fermatas
 
diff --git a/lily/general-scheme.cc b/lily/general-scheme.cc
index 11fb65790f..fe33278802 100644
--- a/lily/general-scheme.cc
+++ b/lily/general-scheme.cc
@@ -143,8 +143,7 @@ LY_DEFINE (ly_assoc_get, "ly:assoc-get",
 
   if (scm_is_pair (handle))
     return scm_cdr (handle);
-  else
-    return default_value;
+  return default_value;
 }
 
 LY_DEFINE (ly_number2string, "ly:number->string",
@@ -166,7 +165,7 @@ LY_DEFINE (ly_number2string, "ly:number->string",
 	  {
 	    programming_error (_ ("infinity or NaN encountered while converting Real number"));
 	    programming_error (_ ("setting to zero"));
-			       
+
 	    r = 0.0;
 	  }
 
@@ -248,28 +247,35 @@ LY_DEFINE (ly_wchar_to_utf_8, "ly:wide-char->utf-8",
 
   SCM_ASSERT_TYPE (scm_is_integer (wc), wc, SCM_ARG1, __FUNCTION__, "integer");
   unsigned wide_char = (unsigned) scm_to_int (wc);
-  char * p = buf;
-
-  if (wide_char < 0x0080) {
-    *p++ = (char)wide_char;
-  } else if (wide_char < 0x0800) {
-    *p++ = (char)(((wide_char >>  6)       ) | 0xC0);
-    *p++ = (char)(((wide_char      ) & 0x3F) | 0x80);
-  } else if (wide_char < 0x10000) {
-    *p++ = (char)(((wide_char >> 12)       ) | 0xE0);
-    *p++ = (char)(((wide_char >>  6) & 0x3F) | 0x80);
-    *p++ = (char)(((wide_char      ) & 0x3F) | 0x80);
-  } else {
-    *p++ = (char)(((wide_char >> 18)       ) | 0xF0);
-    *p++ = (char)(((wide_char >> 12) & 0x3F) | 0x80);
-    *p++ = (char)(((wide_char >>  6) & 0x3F) | 0x80);
-    *p++ = (char)(((wide_char      ) & 0x3F) | 0x80);
-  }
+  char *p = buf;
+
+  if (wide_char < 0x0080)
+    {
+      *p++ = (char)wide_char;
+    }
+  else if (wide_char < 0x0800)
+    {
+      *p++ = (char) (((wide_char >> 6)) | 0xC0);
+      *p++ = (char) (((wide_char) & 0x3F) | 0x80);
+    }
+  else if (wide_char < 0x10000)
+    {
+      *p++ = (char) (((wide_char >> 12)) | 0xE0);
+      *p++ = (char) (((wide_char >> 6) & 0x3F) | 0x80);
+      *p++ = (char) (((wide_char) & 0x3F) | 0x80);
+    }
+  else
+    {
+      *p++ = (char) (((wide_char >> 18)) | 0xF0);
+      *p++ = (char) (((wide_char >> 12) & 0x3F) | 0x80);
+      *p++ = (char) (((wide_char >> 6) & 0x3F) | 0x80);
+      *p++ = (char) (((wide_char) & 0x3F) | 0x80);
+    }
   *p = 0;
 
   return scm_makfrom0str (buf);
 }
-	  
+
 LY_DEFINE (ly_effective_prefix, "ly:effective-prefix",
 	   0, 0, 0, (),
 	   "Return effective prefix.")
@@ -279,8 +285,9 @@ LY_DEFINE (ly_effective_prefix, "ly:effective-prefix",
 
 LY_DEFINE (ly_chain_assoc_get, "ly:chain-assoc-get",
 	   2, 1, 0, (SCM key, SCM achain, SCM dfault),
-	   "Return value for @var{key} from a list of alists @var{achain}. Return @var{dfault} "
-	   "if no entry is found, or #f if not specified. ")
+	   "Return value for @var{key} from a list of alists @var{achain}.  "
+	   "If no if no entry is found, return DFAULT, "
+	   "or #f if no DFAULT not specified.")
 {
   if (scm_is_pair (achain))
     {
@@ -290,17 +297,20 @@ LY_DEFINE (ly_chain_assoc_get, "ly:chain-assoc-get",
       else
 	return ly_chain_assoc_get (key, scm_cdr (achain), dfault);
     }
-  else
-    return dfault == SCM_UNDEFINED ? SCM_BOOL_F : dfault;
+  return dfault == SCM_UNDEFINED ? SCM_BOOL_F : dfault;
 }
 
-LY_DEFINE (ly_port_move, "ly:port-move",
-	   2, 0, 0, (SCM fd, SCM port),
-	   "Move file descriptor FD to PORT.")
+LY_DEFINE (ly_stderr_redirect, "ly:stderr-redirect",
+	   1, 1, 0, (SCM file_name, SCM mode),
+	   "Redirect stderr to FILE-NAME, opened with MODE.")
 {
-  SCM_ASSERT_TYPE (scm_port_p (port), port, SCM_ARG1, __FUNCTION__, "port");
-  SCM_ASSERT_TYPE (scm_integer_p (fd), fd, SCM_ARG1, __FUNCTION__, "fd");
-  freopen (ly_scm2newstr (scm_port_filename (port), 0), "a",
-	   fdopen (scm_to_int (fd), "a"));
+  SCM_ASSERT_TYPE (scm_string_p (file_name), file_name, SCM_ARG1,
+		   __FUNCTION__, "file_name");
+  char const* m = "w";
+  if (mode != SCM_UNDEFINED && scm_string_p (mode))
+    m = ly_scm2newstr (mode, 0);
+  /* dup2 and (fileno (current-error-port)) do not work with mingw'c
+     gcc -mwindows.  */
+  freopen (ly_scm2newstr (file_name, 0), m, stderr);
   return SCM_UNSPECIFIED;
 }
diff --git a/lily/main.cc b/lily/main.cc
index da1a508ab6..4c8af368e0 100644
--- a/lily/main.cc
+++ b/lily/main.cc
@@ -190,6 +190,8 @@ dir_info (FILE *out)
 #if ARGV0_RELOCATION
   env_var_info (out, "FONTCONFIG_FILE");
   env_var_info (out, "FONTCONFIG_PATH");
+  env_var_info (out, "GS_FONTPATH");
+  env_var_info (out, "GS_LIB");
   env_var_info (out, "GUILE_LOAD_PATH");
   env_var_info (out, "PANGO_RC_FILE");
   env_var_info (out, "PATH");
@@ -285,6 +287,10 @@ dir_name (String const file_name)
 }
 #endif
 
+#ifdef __MINGW32__
+#  include <winbase.h>
+#endif
+
 static void
 setup_paths (char const* argv0)
 {
@@ -305,6 +311,14 @@ setup_paths (char const* argv0)
       prefix_directory = datadir + "/lilypond/" TOPLEVEL_VERSION;
 
       sane_putenv ("FONTCONFIG_FILE", sysconfdir + "/fonts/fonts.conf", false);
+#ifdef __MINGW32__
+      char font_dir[PATH_MAX];
+      ExpandEnvironmentStrings ("%windir%/fonts", font_dir, sizeof (font_dir));
+      prepend_env_path ("GS_FONTPATH", font_dir);
+#endif
+      prepend_env_path ("GS_FONTPATH", datadir + "/gs/fonts");
+      prepend_env_path ("GS_LIB", datadir + "/gs/Resource");
+      prepend_env_path ("GS_LIB", datadir + "/gs/lib");
       prepend_env_path ("GUILE_LOAD_PATH", datadir
 			+ to_string ("/guile/%d.%d",
 				     SCM_MAJOR_VERSION, SCM_MINOR_VERSION));
@@ -316,7 +330,13 @@ setup_paths (char const* argv0)
 #endif /* ARGV0_RELOCATION */
     
   if (char const *env = getenv ("LILYPONDPREFIX"))
-    prefix_directory = env;
+    {
+#ifdef __MINGW32__
+      /* Normalize file name.  */
+      env = File_name (env).to_string ().get_copy_str0 ();
+#endif
+      prefix_directory = env;
+    }
 
   global_path.append ("");
 
@@ -659,12 +679,6 @@ 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)
 {
diff --git a/scm/backend-library.scm b/scm/backend-library.scm
index 47b6a20895..e0170fb433 100644
--- a/scm/backend-library.scm
+++ b/scm/backend-library.scm
@@ -53,7 +53,9 @@
     ;; The wrapper on windows cannot handle `=' signs,
     ;; gs has a workaround with #.
     (if (eq? PLATFORM 'windows)
-	(set! cmd (string-regexp-substitute "=" "#" cmd)))
+	(begin
+	  (set! cmd (string-regexp-substitute "=" "#" cmd))
+	  (set! cmd (string-regexp-substitute "-dSAFER " "" cmd))))
 
     (if (access? pdf-name W_OK)
 	(delete-file pdf-name))
diff --git a/scm/editor.scm b/scm/editor.scm
index 2491e0c4ca..cde166fbfd 100644
--- a/scm/editor.scm
+++ b/scm/editor.scm
@@ -6,16 +6,16 @@
 
 (define-module (scm editor))
 
+;; Also for standalone use, so cannot include any lily modules.
 (use-modules
- (ice-9 regex))
+ (ice-9 regex)
+  (srfi srfi-13)
+  (srfi srfi-14))
 
-(define editor-command-template-alist
-  '(("emacs" .  "emacsclient --no-wait +%(line)s:%(column)s %(file)s")
-    ("gvim" . "gvim --remote +:%(line)s:norm%(column)s %(file)s")
-    ("nedit" . "nc -noask +%(line)s %(file)s")
-    ("gedit" . "gedit +%(line)s %(file)s")
-    ("jedit" . "jedit %(file)s +line:%(line)s")
-    ("lilypad" . "lilypad +%(line)s:%(column)s %(file)s")))
+(define PLATFORM
+  (string->symbol
+   (string-downcase
+    (car (string-tokenize (vector-ref (uname) 0) char-set:letter)))))
 
 (define (get-editor)
   (or (getenv "LYEDITOR")
@@ -29,6 +29,14 @@
 	(else
 	 "emacs"))))
 
+(define editor-command-template-alist
+  '(("emacs" .  "emacsclient --no-wait +%(line)s:%(column)s %(file)s")
+    ("gvim" . "gvim --remote +:%(line)s:norm%(column)s %(file)s")
+    ("nedit" . "nc -noask +%(line)s %(file)s")
+    ("gedit" . "gedit +%(line)s %(file)s")
+    ("jedit" . "jedit %(file)s +line:%(line)s")
+    ("lilypad" . "lilypad +%(line)s:%(column)s %(file)s")))
+
 (define (get-command-template alist editor)
   (define (get-command-template-helper)
     (if (null? alist)
diff --git a/scm/lily.scm b/scm/lily.scm
index 2584e13f8c..46035c4f00 100644
--- a/scm/lily.scm
+++ b/scm/lily.scm
@@ -375,12 +375,12 @@ The syntax is the same as `define*-public'."
 
 (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.
-
     (cond
-     ((eq? PLATFORM 'windows) have-tty?)
+     ((eq? PLATFORM 'windows)
+      ;; This only works for i586-mingw32msvc-gcc -mwindows
+      (not (string-match "standard input"
+			 (format #f "~S" (current-input-port)))))
      ((eq? PLATFORM 'darwin) #f)
      (else
       (not have-tty?)))))
@@ -388,11 +388,10 @@ The syntax is the same as `define*-public'."
 (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")))
+	 (log-name (string-append base ".log")))
     (if (not (running-from-gui?))
 	(ly:message (_ "Redirecting output to ~a...") log-name))
-    (ly:port-move (fileno (current-error-port)) log-file)
+    (ly:stderr-redirect log-name "w")
     (ly:message "# -*-compilation-*-")
     (let ((failed (lilypond-all files)))
       (if (pair? failed)
diff --git a/scripts/lilypond-invoke-editor.scm b/scripts/lilypond-invoke-editor.scm
index e61d10f779..a9cf32c249 100755
--- a/scripts/lilypond-invoke-editor.scm
+++ b/scripts/lilypond-invoke-editor.scm
@@ -106,9 +106,7 @@ Options:
 (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?))))
+    (not have-tty?)))
 
 (define (main args)
   (let ((files (parse-options args)))
-- 
2.39.5