1 /* Copyright (C) 2001, 2006 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "libguile/_scm.h"
30 #include "libguile/deprecation.h"
31 #include "libguile/strings.h"
32 #include "libguile/ports.h"
34 #include "libguile/private-options.h"
37 /* Windows defines. */
39 #define vsnprintf _vsnprintf
44 #if (SCM_ENABLE_DEPRECATED == 1)
46 struct issued_warning
{
47 struct issued_warning
*prev
;
51 static struct issued_warning
*issued_warnings
;
52 static int print_summary
= 0;
55 scm_c_issue_deprecation_warning (const char *msg
)
57 if (!SCM_WARN_DEPRECATED
)
61 struct issued_warning
*iw
;
62 for (iw
= issued_warnings
; iw
; iw
= iw
->prev
)
63 if (!strcmp (iw
->message
, msg
))
66 fprintf (stderr
, "%s\n", msg
);
69 scm_puts (msg
, scm_current_error_port ());
70 scm_newline (scm_current_error_port ());
73 iw
= malloc (sizeof (struct issued_warning
));
74 if (msg
== NULL
|| iw
== NULL
)
77 iw
->prev
= issued_warnings
;
83 scm_c_issue_deprecation_warning_fmt (const char *msg
, ...)
89 vsnprintf (buf
, 511, msg
, ap
);
92 scm_c_issue_deprecation_warning (buf
);
95 SCM_DEFINE(scm_issue_deprecation_warning
,
96 "issue-deprecation-warning", 0, 0, 1,
98 "Output @var{msgs} to @code{(current-error-port)} when this "
99 "is the first call to @code{issue-deprecation-warning} with "
100 "this specific @var{msgs}. Do nothing otherwise. "
101 "The argument @var{msgs} should be a list of strings; "
102 "they are printed in turn, each one followed by a newline.")
103 #define FUNC_NAME s_scm_issue_deprecation_warning
105 if (!SCM_WARN_DEPRECATED
)
109 SCM nl
= scm_from_locale_string ("\n");
110 SCM msgs_nl
= SCM_EOL
;
112 while (scm_is_pair (msgs
))
114 if (msgs_nl
!= SCM_EOL
)
115 msgs_nl
= scm_cons (nl
, msgs_nl
);
116 msgs_nl
= scm_cons (SCM_CAR (msgs
), msgs_nl
);
117 msgs
= SCM_CDR (msgs
);
119 msgs_nl
= scm_string_append (scm_reverse_x (msgs_nl
, SCM_EOL
));
120 c_msgs
= scm_to_locale_string (msgs_nl
);
121 scm_c_issue_deprecation_warning (c_msgs
);
124 return SCM_UNSPECIFIED
;
129 print_deprecation_summary (void)
134 "Some deprecated features have been used. Set the environment\n"
135 "variable GUILE_WARN_DEPRECATED to \"detailed\" and rerun the\n"
136 "program to get more information. Set it to \"no\" to suppress\n"
137 "this message.\n", stderr
);
141 #endif /* SCM_ENABLE_DEPRECATED == 1 */
143 SCM_DEFINE(scm_include_deprecated_features
,
144 "include-deprecated-features", 0, 0, 0,
146 "Return @code{#t} iff deprecated features should be included "
147 "in public interfaces.")
148 #define FUNC_NAME s_scm_include_deprecated_features
150 return scm_from_bool (SCM_ENABLE_DEPRECATED
== 1);
158 scm_init_deprecation ()
160 #if (SCM_ENABLE_DEPRECATED == 1)
161 const char *level
= getenv ("GUILE_WARN_DEPRECATED");
163 level
= SCM_WARN_DEPRECATED_DEFAULT
;
164 if (!strcmp (level
, "detailed"))
165 SCM_WARN_DEPRECATED
= 1;
166 else if (!strcmp (level
, "no"))
167 SCM_WARN_DEPRECATED
= 0;
170 SCM_WARN_DEPRECATED
= 0;
171 atexit (print_deprecation_summary
);
174 #include "libguile/deprecation.x"