2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2012 Jan Nieuwenhuizen <janneke@gnu.org>
5 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 #include "lily-guile.hh"
24 #include "program-option.hh"
26 #include "international.hh"
30 Error / warning / progress / debug message output functions
33 LY_DEFINE (ly_error, "ly:error",
34 1, 0, 1, (SCM str, SCM rest),
35 "A Scheme callable function to issue the error @var{str}."
36 " The error is formatted with @code{format} and @var{rest}.")
38 LY_ASSERT_TYPE (scm_is_string, str, 1);
39 str = scm_simple_format (SCM_BOOL_F, str, rest);
40 error (ly_scm2string (str));
41 return SCM_UNSPECIFIED;
44 LY_DEFINE (ly_programming_error, "ly:programming-error",
45 1, 0, 1, (SCM str, SCM rest),
46 "A Scheme callable function to issue the internal warning"
47 " @var{str}. The message is formatted with @code{format}"
50 LY_ASSERT_TYPE (scm_is_string, str, 1);
51 str = scm_simple_format (SCM_BOOL_F, str, rest);
52 programming_error (ly_scm2string (str));
53 return SCM_UNSPECIFIED;
56 LY_DEFINE (ly_warning, "ly:warning",
57 1, 0, 1, (SCM str, SCM rest),
58 "A Scheme callable function to issue the warning @var{str}."
59 " The message is formatted with @code{format} and @var{rest}.")
61 LY_ASSERT_TYPE (scm_is_string, str, 1);
62 str = scm_simple_format (SCM_BOOL_F, str, rest);
63 warning (ly_scm2string (str));
64 return SCM_UNSPECIFIED;
67 LY_DEFINE (ly_progress, "ly:progress",
68 1, 0, 1, (SCM str, SCM rest),
69 "A Scheme callable function to print progress @var{str}."
70 " The message is formatted with @code{format} and @var{rest}.")
72 LY_ASSERT_TYPE (scm_is_string, str, 1);
73 str = scm_simple_format (SCM_BOOL_F, str, rest);
74 // Calls to ly:progress should in general not start a new line
75 progress_indication (ly_scm2string (str), false);
76 return SCM_UNSPECIFIED;
79 LY_DEFINE (ly_basic_progress, "ly:basic-progress",
80 1, 0, 1, (SCM str, SCM rest),
81 "A Scheme callable function to issue a basic progress message @var{str}."
82 " The message is formatted with @code{format} and @var{rest}.")
84 LY_ASSERT_TYPE (scm_is_string, str, 1);
85 str = scm_simple_format (SCM_BOOL_F, str, rest);
86 basic_progress (ly_scm2string (str));
87 return SCM_UNSPECIFIED;
90 LY_DEFINE (ly_message, "ly:message",
91 1, 0, 1, (SCM str, SCM rest),
92 "A Scheme callable function to issue the message @var{str}."
93 " The message is formatted with @code{format} and @var{rest}.")
95 LY_ASSERT_TYPE (scm_is_string, str, 1);
96 str = scm_simple_format (SCM_BOOL_F, str, rest);
97 message (ly_scm2string (str));
98 return SCM_UNSPECIFIED;
101 LY_DEFINE (ly_debug, "ly:debug",
102 1, 0, 1, (SCM str, SCM rest),
103 "A Scheme callable function to issue a debug message @var{str}."
104 " The message is formatted with @code{format} and @var{rest}.")
106 // TODO: Add the newline flag!
107 LY_ASSERT_TYPE (scm_is_string, str, 1);
108 str = scm_simple_format (SCM_BOOL_F, str, rest);
109 debug_output (ly_scm2string (str));
110 return SCM_UNSPECIFIED;
113 LY_DEFINE (ly_warning_located, "ly:warning-located",
114 2, 0, 1, (SCM location, SCM str, SCM rest),
115 "A Scheme callable function to issue the warning @var{str} at"
116 " the specified location in an input file."
117 " The message is formatted with @code{format} and @var{rest}.")
119 LY_ASSERT_TYPE (scm_is_string, location, 1);
120 LY_ASSERT_TYPE (scm_is_string, str, 2);
121 str = scm_simple_format (SCM_BOOL_F, str, rest);
122 warning (ly_scm2string (str), ly_scm2string (location));
123 return SCM_UNSPECIFIED;
126 LY_DEFINE (ly_expect_warning, "ly:expect-warning",
127 1, 0, 1, (SCM str, SCM rest),
128 "A Scheme callable function to register a warning to be expected"
129 " and subsequently suppressed. If the warning is not encountered,"
130 " a warning about the missing warning will be shown. The message"
131 " should be translated with @code{(_ ...)} and changing parameters"
132 " given after the format string.")
134 LY_ASSERT_TYPE (scm_is_string, str, 1);
135 str = scm_simple_format (SCM_BOOL_F, str, rest);
136 expect_warning (ly_scm2string (str));
137 return SCM_UNSPECIFIED;
140 LY_DEFINE (ly_check_expected_warnings, "ly:check-expected-warnings",
142 "Check whether all expected warnings have really been triggered.")
144 check_expected_warnings ();
145 return SCM_UNSPECIFIED;
148 LY_DEFINE (ly_translate_cpp_warning_scheme, "ly:translate-cpp-warning-scheme",
150 "Translates a string in C++ printf format and modifies it to use"
151 " it for scheme formatting.")
153 LY_ASSERT_TYPE (scm_is_string, str, 1);
154 string s = _ (ly_scm2string (str).c_str ());
156 /* Now replace all printf placeholders by scheme placeholders (~a).
157 * Guile's format syntax is pretty similar to C's printf, only with
158 * a tilde as the placeholder instead of a percent sign.
159 * There is no easy way to replace all ~ -> ~~, %% -> %, % -> ~,
160 * so simply walk through each character.
163 const char *pos = s.c_str ();
167 // In some cases (%%, %s) we need to do a lookahead. As the C string is
168 // always \0-terminated the next char is never beyond the end of the
176 if (*(pos + 1) == '%')
179 // Skip the second '%'
182 else if (*(pos + 1) == 's' || *(pos + 1) == 'd')
184 // %s in C++ corresponds to ~a; ~s would add quotes!
185 // ~d is only supported by ice-9, use ~a instead
187 // Skip the following 's'
198 return ly_string2scm (result);