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 struct issued_warning
{
45 struct issued_warning
*prev
;
49 static struct issued_warning
*issued_warnings
;
50 static int print_summary
= 0;
53 scm_c_issue_deprecation_warning (const char *msg
)
55 if (!SCM_WARN_DEPRECATED
)
59 struct issued_warning
*iw
;
60 for (iw
= issued_warnings
; iw
; iw
= iw
->prev
)
61 if (!strcmp (iw
->message
, msg
))
64 fprintf (stderr
, "%s\n", msg
);
67 scm_puts (msg
, scm_current_error_port ());
68 scm_newline (scm_current_error_port ());
71 iw
= malloc (sizeof (struct issued_warning
));
72 if (msg
== NULL
|| iw
== NULL
)
75 iw
->prev
= issued_warnings
;
81 scm_c_issue_deprecation_warning_fmt (const char *msg
, ...)
87 vsnprintf (buf
, 511, msg
, ap
);
90 scm_c_issue_deprecation_warning (buf
);
93 SCM_DEFINE(scm_issue_deprecation_warning
,
94 "issue-deprecation-warning", 0, 0, 1,
96 "Output @var{msgs} to @code{(current-error-port)} when this "
97 "is the first call to @code{issue-deprecation-warning} with "
98 "this specific @var{msgs}. Do nothing otherwise. "
99 "The argument @var{msgs} should be a list of strings; "
100 "they are printed in turn, each one followed by a newline.")
101 #define FUNC_NAME s_scm_issue_deprecation_warning
103 if (!SCM_WARN_DEPRECATED
)
107 SCM nl
= scm_from_locale_string ("\n");
108 SCM msgs_nl
= SCM_EOL
;
110 while (scm_is_pair (msgs
))
112 if (msgs_nl
!= SCM_EOL
)
113 msgs_nl
= scm_cons (nl
, msgs_nl
);
114 msgs_nl
= scm_cons (SCM_CAR (msgs
), msgs_nl
);
115 msgs
= SCM_CDR (msgs
);
117 msgs_nl
= scm_string_append (scm_reverse_x (msgs_nl
, SCM_EOL
));
118 c_msgs
= scm_to_locale_string (msgs_nl
);
119 scm_c_issue_deprecation_warning (c_msgs
);
122 return SCM_UNSPECIFIED
;
127 print_deprecation_summary (void)
132 "Some deprecated features have been used. Set the environment\n"
133 "variable GUILE_WARN_DEPRECATED to \"detailed\" and rerun the\n"
134 "program to get more information. Set it to \"no\" to suppress\n"
135 "this message.\n", stderr
);
139 SCM_DEFINE(scm_include_deprecated_features
,
140 "include-deprecated-features", 0, 0, 0,
142 "Return @code{#t} iff deprecated features should be included "
143 "in public interfaces.")
144 #define FUNC_NAME s_scm_include_deprecated_features
146 return scm_from_bool (SCM_ENABLE_DEPRECATED
== 1);
154 scm_init_deprecation ()
156 const char *level
= getenv ("GUILE_WARN_DEPRECATED");
158 level
= SCM_WARN_DEPRECATED_DEFAULT
;
159 if (!strcmp (level
, "detailed"))
160 SCM_WARN_DEPRECATED
= 1;
161 else if (!strcmp (level
, "no"))
162 SCM_WARN_DEPRECATED
= 0;
165 SCM_WARN_DEPRECATED
= 0;
166 atexit (print_deprecation_summary
);
168 #include "libguile/deprecation.x"