*** empty log message ***
[bpt/guile.git] / libguile / deprecation.c
CommitLineData
5cd06d5e 1/* Copyright (C) 2001 Free Software Foundation, Inc.
7e516288 2 *
73be1d9e
MV
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.
7e516288 7 *
73be1d9e
MV
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.
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
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
7e516288
MV
17
18\f
19
5f0bcfd5
RB
20#if HAVE_CONFIG_H
21# include <config.h>
22#endif
23
7e516288 24#include <stdio.h>
fbbdb121 25#include <string.h>
d013f095 26#include <stdarg.h>
7e516288
MV
27
28#include "libguile/_scm.h"
29
30#include "libguile/deprecation.h"
7e516288
MV
31#include "libguile/strings.h"
32#include "libguile/ports.h"
33
edb810bb
SJ
34/* Windows defines. */
35#ifdef __MINGW32__
36#define vsnprintf _vsnprintf
37#endif
38
7e516288
MV
39\f
40
8c494e99 41#if (SCM_ENABLE_DEPRECATED == 1)
7e516288 42
d013f095
MV
43struct issued_warning {
44 struct issued_warning *prev;
45 const char *message;
46};
47
48static struct issued_warning *issued_warnings;
49static enum { detailed, summary, summary_print } mode;
7e516288
MV
50
51void
52scm_c_issue_deprecation_warning (const char *msg)
53{
d013f095
MV
54 if (mode != detailed)
55 mode = summary_print;
7e516288 56 else
d013f095
MV
57 {
58 struct issued_warning *iw;
59 for (iw = issued_warnings; iw; iw = iw->prev)
60 if (!strcmp (iw->message, msg))
61 return;
62 if (scm_gc_running_p)
63 fprintf (stderr, "%s\n", msg);
64 else
65 {
66 scm_puts (msg, scm_current_error_port ());
67 scm_newline (scm_current_error_port ());
68 }
69 msg = strdup (msg);
67329a9e 70 iw = scm_malloc (sizeof (struct issued_warning));
d013f095
MV
71 if (msg == NULL || iw == NULL)
72 return;
73 iw->message = msg;
74 iw->prev = issued_warnings;
75 issued_warnings = iw;
76 }
77}
78
79void
80scm_c_issue_deprecation_warning_fmt (const char *msg, ...)
81{
82 va_list ap;
83 char buf[512];
84
85 va_start (ap, msg);
86 vsnprintf (buf, 511, msg, ap);
87 buf[511] = '\0';
88 scm_c_issue_deprecation_warning (buf);
7e516288
MV
89}
90
91SCM_DEFINE(scm_issue_deprecation_warning,
92 "issue-deprecation-warning", 0, 0, 1,
93 (SCM msgs),
94 "Output @var{msgs} to @code{(current-error-port)} when this "
95 "is the first call to @code{issue-deprecation-warning} with "
d013f095 96 "this specific @var{msgs}. Do nothing otherwise. "
7e516288
MV
97 "The argument @var{msgs} should be a list of strings; "
98 "they are printed in turn, each one followed by a newline.")
99#define FUNC_NAME s_scm_issue_deprecation_warning
100{
d013f095
MV
101 if (mode != detailed)
102 mode = summary_print;
7e516288
MV
103 else
104 {
d013f095
MV
105 SCM nl = scm_str2string ("\n");
106 SCM msgs_nl = SCM_EOL;
107 while (SCM_CONSP (msgs))
7e516288 108 {
d013f095
MV
109 if (msgs_nl != SCM_EOL)
110 msgs_nl = scm_cons (nl, msgs_nl);
111 msgs_nl = scm_cons (SCM_CAR (msgs), msgs_nl);
112 msgs = SCM_CDR (msgs);
7e516288 113 }
d013f095
MV
114 msgs_nl = scm_string_append (scm_reverse_x (msgs_nl, SCM_EOL));
115 scm_c_issue_deprecation_warning (SCM_STRING_CHARS (msgs_nl));
116 scm_remember_upto_here_1 (msgs_nl);
7e516288
MV
117 }
118 return SCM_UNSPECIFIED;
119}
120#undef FUNC_NAME
121
122static void
123print_deprecation_summary (void)
124{
d013f095 125 if (mode == summary_print)
7e516288
MV
126 {
127 fputs ("\n"
128 "Some deprecated features have been used. Set the environment\n"
129 "variable GUILE_WARN_DEPRECATED to \"detailed\" and rerun the\n"
130 "program to get more information. Set it to \"no\" to suppress\n"
131 "this message.\n", stderr);
132 }
133}
134
135#endif
136
137SCM_DEFINE(scm_include_deprecated_features,
138 "include-deprecated-features", 0, 0, 0,
139 (),
7bad99fd
MV
140 "Return @code{#t} iff deprecated features should be included "
141 "in public interfaces.")
7e516288
MV
142#define FUNC_NAME s_scm_include_deprecated_features
143{
8c494e99 144 return SCM_BOOL (SCM_ENABLE_DEPRECATED == 1);
7e516288
MV
145}
146#undef FUNC_NAME
147
148
149\f
150
151void
152scm_init_deprecation ()
153{
8c494e99 154#if (SCM_ENABLE_DEPRECATED == 1)
7e516288
MV
155 const char *level = getenv ("GUILE_WARN_DEPRECATED");
156 if (level == NULL)
887dfa7d 157 level = SCM_WARN_DEPRECATED_DEFAULT;
7e516288 158 if (!strcmp (level, "detailed"))
d013f095 159 mode = detailed;
7e516288 160 else if (!strcmp (level, "no"))
d013f095 161 mode = summary;
7e516288
MV
162 else
163 {
d013f095 164 mode = summary;
7e516288
MV
165 atexit (print_deprecation_summary);
166 }
167#endif
7e516288 168#include "libguile/deprecation.x"
7e516288
MV
169}
170
171/*
172 Local Variables:
173 c-file-style: "gnu"
174 End: */