]> git.donarmstrong.com Git - lilypond.git/commitdiff
Have LilyPond issue a success/failure termination message
authorIan Hulin <ian@hulin.org.uk>
Sun, 9 May 2010 01:58:36 +0000 (19:58 -0600)
committerCarl Sorensen <c_sorensen@byu.edu>
Sun, 9 May 2010 02:00:27 +0000 (20:00 -0600)
flower/include/warn.hh
flower/warn.cc
lily/general-scheme.cc
scm/lily.scm

index 170fbca827810ffeb8e99cfe16691961f760b8e4..10c800c44344db383b1dd1a01aa1691a68581d82 100644 (file)
@@ -28,5 +28,6 @@ void non_fatal_error (string);
 void programming_error (string s);
 void progress_indication (string s);
 void warning (string s);
+void successful (string s);
 
 #endif /* WARN_HH */
index 0bf8983c7a83f4dbd27a369404faf686c0c33cfe..37751f7bde731ec02965e46b2381eb695d622124 100644 (file)
@@ -52,6 +52,13 @@ message (string s)
   progress_indication (s);
 }
 
+/* Display a success message.  Always starts on a new line.  */
+void
+successful (string s)
+{
+  message (_f ("success: %s", s.c_str ()) + "\n");
+}
+
 /* Display a warning message.  Always starts on a new line.  */
 void
 warning (string s)
index d409ce0967813d1503037ff9558f24de7e3cc86a..c8816b43a7902350c91fb7ddac2a146f7402e5c3 100644 (file)
@@ -144,6 +144,17 @@ LY_DEFINE (ly_programming_error, "ly:programming-error",
   return SCM_UNSPECIFIED;
 }
 
+LY_DEFINE (ly_success, "ly:success",
+          1, 0, 1, (SCM str, SCM rest),
+          "A Scheme callable function to issue a success message @code{str}."
+          "  The message is formatted with @code{format} and @code{rest}.")
+{
+  LY_ASSERT_TYPE (scm_is_string, str, 1);
+  str = scm_simple_format (SCM_BOOL_F, str, rest);
+  successful (ly_scm2string (str));
+  return SCM_UNSPECIFIED;
+
+}
 LY_DEFINE (ly_warning, "ly:warning",
           1, 0, 1, (SCM str, SCM rest),
           "A Scheme callable function to issue the warning @code{str}."
@@ -440,12 +451,13 @@ LY_DEFINE (ly_stderr_redirect, "ly:stderr-redirect",
   LY_ASSERT_TYPE (scm_is_string, file_name, 1);
 
   string m = "w";
+  FILE *stderrfile;
   if (mode != SCM_UNDEFINED && scm_string_p (mode))
     m = ly_scm2string (mode);
   /* dup2 and (fileno (current-error-port)) do not work with mingw'c
      gcc -mwindows.  */
   fflush (stderr);
-  freopen (ly_scm2string (file_name).c_str (), m.c_str (), stderr);
+  stderrfile = freopen (ly_scm2string (file_name).c_str (), m.c_str (), stderr);
   return SCM_UNSPECIFIED;
 }
 
index 2b6ca651b4adbc83a3e911b25b6acc65fb4ef3cf..7c10affaa355ba5efc88f8f241fb0880f29a111a 100644 (file)
@@ -660,20 +660,32 @@ PIDs or the number of the process."
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+(define* (ly:exit status #:optional (silently #f) )
+    "Exit function for lilypond"
+    (if (not silently)
+       (case status
+           ((0) (ly:success "Compilation successfully completed"))
+           ((1) (ly:warning "Compilation completed with warnings or errors"))
+           (else (ly:message "")))
+       )
+    (exit status)
+    )
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
 (define-public (lilypond-main files)
   "Entry point for LilyPond."
   (eval-string (ly:command-line-code))
   (if (ly:get-option 'help)
       (begin (ly:option-usage)
-            (exit 0)))
+            (ly:exit 0 #t )))
   (if (ly:get-option 'show-available-fonts)
       (begin (ly:font-config-display-fonts)
-            (exit 0)))
+            (ly:exit 0 #t)))
   (if (ly:get-option 'gui)
       (gui-main files))
   (if (null? files)
       (begin (ly:usage)
-            (exit 2)))
+            (ly:exit 2 #t)))
   (if (ly:get-option 'read-file-list)
       (set! files
            (filter (lambda (s)
@@ -729,9 +741,10 @@ PIDs or the number of the process."
                   (if (ly:get-option 'dump-profile)
                       (dump-profile "lily-run-total"
                                     '(0 0) (profile-measurements)))
-                  (exit (if (null? errors)
-                            0
-                            1))))))
+                  (if (null? errors)
+                      (ly:exit 0 #f)
+                      (ly:exit 1 #f))))))
+
   (if (string-or-symbol? (ly:get-option 'log-file))
       (ly:stderr-redirect (format "~a.log" (ly:get-option 'log-file)) "w"))
   (let ((failed (lilypond-all files)))
@@ -741,11 +754,10 @@ PIDs or the number of the process."
                               (string-contains f "lilypond")))))
     (if (pair? failed)
        (begin (ly:error (_ "failed files: ~S") (string-join failed))
-              (exit 1))
+               (ly:exit 1 #f))
        (begin
-         ;; HACK: be sure to exit with single newline
-         (ly:message "")
-         (exit 0)))))
+         (ly:exit 0 #f)))))
+
 
 (define-public (lilypond-all files)
   (let* ((failed '())
@@ -787,7 +799,7 @@ PIDs or the number of the process."
         (ly:set-option 'debug-gc-assert-parsed-dead #f)
         (if (ly:get-option 'debug-gc)
             (dump-gc-protects)
-            (ly:reset-all-fonts))))
+             (ly:reset-all-fonts))))
      files)
 
     ;; we want the failed-files notice in the aggregrate logfile.
@@ -823,7 +835,7 @@ PIDs or the number of the process."
              (ly:error (_ "failed files: ~S") (string-join failed))
              ;; not reached?
              (exit 1))
-           (exit 0)))))
+           (ly:exit 0 #f)))))
 
 (define (gui-no-files-handler)
   (let* ((ly (string-append (ly:effective-prefix) "/ly/"))
@@ -832,4 +844,4 @@ PIDs or the number of the process."
         (cmd (get-editor-command welcome-ly 0 0 0)))
     (ly:message (_ "Invoking `~a'...\n") cmd)
     (system cmd)
-    (exit 1)))
+    (ly:exit 1 #f)))