From: Ian Hulin Date: Sun, 9 May 2010 01:58:36 +0000 (-0600) Subject: Have LilyPond issue a success/failure termination message X-Git-Tag: release/2.13.21-1~5 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=8b2c05295e13b8000833627a5d5e3dcaaa8e5a7b;p=lilypond.git Have LilyPond issue a success/failure termination message --- diff --git a/flower/include/warn.hh b/flower/include/warn.hh index 170fbca827..10c800c443 100644 --- a/flower/include/warn.hh +++ b/flower/include/warn.hh @@ -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 */ diff --git a/flower/warn.cc b/flower/warn.cc index 0bf8983c7a..37751f7bde 100644 --- a/flower/warn.cc +++ b/flower/warn.cc @@ -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) diff --git a/lily/general-scheme.cc b/lily/general-scheme.cc index d409ce0967..c8816b43a7 100644 --- a/lily/general-scheme.cc +++ b/lily/general-scheme.cc @@ -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; } diff --git a/scm/lily.scm b/scm/lily.scm index 2b6ca651b4..7c10affaa3 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -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)))