Bump version number for 1.9.9.
[bpt/guile.git] / libguile / deprecation.c
CommitLineData
2b829bbb 1/* Copyright (C) 2001, 2006 Free Software Foundation, Inc.
7e516288 2 *
73be1d9e 3 * This library is free software; you can redistribute it and/or
53befeb7
NJ
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
7e516288 7 *
53befeb7
NJ
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
7e516288 12 *
73be1d9e
MV
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
53befeb7
NJ
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
73be1d9e 17 */
7e516288
MV
18
19\f
20
dbb605f5 21#ifdef HAVE_CONFIG_H
5f0bcfd5
RB
22# include <config.h>
23#endif
24
7e516288 25#include <stdio.h>
fbbdb121 26#include <string.h>
d013f095 27#include <stdarg.h>
7e516288
MV
28
29#include "libguile/_scm.h"
30
31#include "libguile/deprecation.h"
7e516288
MV
32#include "libguile/strings.h"
33#include "libguile/ports.h"
34
22fc179a
HWN
35#include "libguile/private-options.h"
36
37
edb810bb
SJ
38/* Windows defines. */
39#ifdef __MINGW32__
40#define vsnprintf _vsnprintf
41#endif
42
7e516288
MV
43\f
44
d013f095
MV
45struct issued_warning {
46 struct issued_warning *prev;
47 const char *message;
48};
49
50static struct issued_warning *issued_warnings;
65bc1f7a 51static int print_summary = 0;
7e516288
MV
52
53void
54scm_c_issue_deprecation_warning (const char *msg)
55{
65bc1f7a
MV
56 if (!SCM_WARN_DEPRECATED)
57 print_summary = 1;
7e516288 58 else
d013f095
MV
59 {
60 struct issued_warning *iw;
61 for (iw = issued_warnings; iw; iw = iw->prev)
62 if (!strcmp (iw->message, msg))
63 return;
64 if (scm_gc_running_p)
65 fprintf (stderr, "%s\n", msg);
66 else
67 {
68 scm_puts (msg, scm_current_error_port ());
69 scm_newline (scm_current_error_port ());
70 }
71 msg = strdup (msg);
fc240b46 72 iw = malloc (sizeof (struct issued_warning));
d013f095
MV
73 if (msg == NULL || iw == NULL)
74 return;
75 iw->message = msg;
76 iw->prev = issued_warnings;
77 issued_warnings = iw;
78 }
79}
80
81void
82scm_c_issue_deprecation_warning_fmt (const char *msg, ...)
83{
84 va_list ap;
85 char buf[512];
86
87 va_start (ap, msg);
88 vsnprintf (buf, 511, msg, ap);
11c47357 89 va_end (ap);
d013f095
MV
90 buf[511] = '\0';
91 scm_c_issue_deprecation_warning (buf);
7e516288
MV
92}
93
94SCM_DEFINE(scm_issue_deprecation_warning,
95 "issue-deprecation-warning", 0, 0, 1,
96 (SCM msgs),
97 "Output @var{msgs} to @code{(current-error-port)} when this "
98 "is the first call to @code{issue-deprecation-warning} with "
d013f095 99 "this specific @var{msgs}. Do nothing otherwise. "
7e516288
MV
100 "The argument @var{msgs} should be a list of strings; "
101 "they are printed in turn, each one followed by a newline.")
102#define FUNC_NAME s_scm_issue_deprecation_warning
103{
65bc1f7a
MV
104 if (!SCM_WARN_DEPRECATED)
105 print_summary = 1;
7e516288
MV
106 else
107 {
cc95e00a 108 SCM nl = scm_from_locale_string ("\n");
d013f095 109 SCM msgs_nl = SCM_EOL;
7f9994d9 110 char *c_msgs;
d2e53ed6 111 while (scm_is_pair (msgs))
7e516288 112 {
d013f095
MV
113 if (msgs_nl != SCM_EOL)
114 msgs_nl = scm_cons (nl, msgs_nl);
115 msgs_nl = scm_cons (SCM_CAR (msgs), msgs_nl);
116 msgs = SCM_CDR (msgs);
7e516288 117 }
d013f095 118 msgs_nl = scm_string_append (scm_reverse_x (msgs_nl, SCM_EOL));
7f9994d9
MV
119 c_msgs = scm_to_locale_string (msgs_nl);
120 scm_c_issue_deprecation_warning (c_msgs);
121 free (c_msgs);
7e516288
MV
122 }
123 return SCM_UNSPECIFIED;
124}
125#undef FUNC_NAME
126
127static void
128print_deprecation_summary (void)
129{
65bc1f7a 130 if (print_summary)
7e516288
MV
131 {
132 fputs ("\n"
133 "Some deprecated features have been used. Set the environment\n"
134 "variable GUILE_WARN_DEPRECATED to \"detailed\" and rerun the\n"
135 "program to get more information. Set it to \"no\" to suppress\n"
136 "this message.\n", stderr);
137 }
138}
139
7e516288
MV
140SCM_DEFINE(scm_include_deprecated_features,
141 "include-deprecated-features", 0, 0, 0,
142 (),
7bad99fd
MV
143 "Return @code{#t} iff deprecated features should be included "
144 "in public interfaces.")
7e516288
MV
145#define FUNC_NAME s_scm_include_deprecated_features
146{
7888309b 147 return scm_from_bool (SCM_ENABLE_DEPRECATED == 1);
7e516288
MV
148}
149#undef FUNC_NAME
150
151
152\f
153
154void
155scm_init_deprecation ()
156{
7e516288
MV
157 const char *level = getenv ("GUILE_WARN_DEPRECATED");
158 if (level == NULL)
887dfa7d 159 level = SCM_WARN_DEPRECATED_DEFAULT;
7e516288 160 if (!strcmp (level, "detailed"))
65bc1f7a 161 SCM_WARN_DEPRECATED = 1;
7e516288 162 else if (!strcmp (level, "no"))
65bc1f7a 163 SCM_WARN_DEPRECATED = 0;
7e516288
MV
164 else
165 {
65bc1f7a 166 SCM_WARN_DEPRECATED = 0;
7e516288
MV
167 atexit (print_deprecation_summary);
168 }
7e516288 169#include "libguile/deprecation.x"
7e516288
MV
170}
171
172/*
173 Local Variables:
174 c-file-style: "gnu"
53befeb7
NJ
175 End:
176 */