Update README on using libraries in non-standard locations
[bpt/guile.git] / libguile / deprecation.c
CommitLineData
2b829bbb 1/* Copyright (C) 2001, 2006 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
92205699 15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
73be1d9e 16 */
7e516288
MV
17
18\f
19
dbb605f5 20#ifdef HAVE_CONFIG_H
5f0bcfd5
RB
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
22fc179a
HWN
34#include "libguile/private-options.h"
35
36
edb810bb
SJ
37/* Windows defines. */
38#ifdef __MINGW32__
39#define vsnprintf _vsnprintf
40#endif
41
7e516288
MV
42\f
43
d013f095
MV
44struct issued_warning {
45 struct issued_warning *prev;
46 const char *message;
47};
48
49static struct issued_warning *issued_warnings;
65bc1f7a 50static int print_summary = 0;
7e516288
MV
51
52void
53scm_c_issue_deprecation_warning (const char *msg)
54{
65bc1f7a
MV
55 if (!SCM_WARN_DEPRECATED)
56 print_summary = 1;
7e516288 57 else
d013f095
MV
58 {
59 struct issued_warning *iw;
60 for (iw = issued_warnings; iw; iw = iw->prev)
61 if (!strcmp (iw->message, msg))
62 return;
63 if (scm_gc_running_p)
64 fprintf (stderr, "%s\n", msg);
65 else
66 {
67 scm_puts (msg, scm_current_error_port ());
68 scm_newline (scm_current_error_port ());
69 }
70 msg = strdup (msg);
fc240b46 71 iw = malloc (sizeof (struct issued_warning));
d013f095
MV
72 if (msg == NULL || iw == NULL)
73 return;
74 iw->message = msg;
75 iw->prev = issued_warnings;
76 issued_warnings = iw;
77 }
78}
79
80void
81scm_c_issue_deprecation_warning_fmt (const char *msg, ...)
82{
83 va_list ap;
84 char buf[512];
85
86 va_start (ap, msg);
87 vsnprintf (buf, 511, msg, ap);
11c47357 88 va_end (ap);
d013f095
MV
89 buf[511] = '\0';
90 scm_c_issue_deprecation_warning (buf);
7e516288
MV
91}
92
93SCM_DEFINE(scm_issue_deprecation_warning,
94 "issue-deprecation-warning", 0, 0, 1,
95 (SCM msgs),
96 "Output @var{msgs} to @code{(current-error-port)} when this "
97 "is the first call to @code{issue-deprecation-warning} with "
d013f095 98 "this specific @var{msgs}. Do nothing otherwise. "
7e516288
MV
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
102{
65bc1f7a
MV
103 if (!SCM_WARN_DEPRECATED)
104 print_summary = 1;
7e516288
MV
105 else
106 {
cc95e00a 107 SCM nl = scm_from_locale_string ("\n");
d013f095 108 SCM msgs_nl = SCM_EOL;
7f9994d9 109 char *c_msgs;
d2e53ed6 110 while (scm_is_pair (msgs))
7e516288 111 {
d013f095
MV
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);
7e516288 116 }
d013f095 117 msgs_nl = scm_string_append (scm_reverse_x (msgs_nl, SCM_EOL));
7f9994d9
MV
118 c_msgs = scm_to_locale_string (msgs_nl);
119 scm_c_issue_deprecation_warning (c_msgs);
120 free (c_msgs);
7e516288
MV
121 }
122 return SCM_UNSPECIFIED;
123}
124#undef FUNC_NAME
125
126static void
127print_deprecation_summary (void)
128{
65bc1f7a 129 if (print_summary)
7e516288
MV
130 {
131 fputs ("\n"
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);
136 }
137}
138
7e516288
MV
139SCM_DEFINE(scm_include_deprecated_features,
140 "include-deprecated-features", 0, 0, 0,
141 (),
7bad99fd
MV
142 "Return @code{#t} iff deprecated features should be included "
143 "in public interfaces.")
7e516288
MV
144#define FUNC_NAME s_scm_include_deprecated_features
145{
7888309b 146 return scm_from_bool (SCM_ENABLE_DEPRECATED == 1);
7e516288
MV
147}
148#undef FUNC_NAME
149
150
151\f
152
153void
154scm_init_deprecation ()
155{
7e516288
MV
156 const char *level = getenv ("GUILE_WARN_DEPRECATED");
157 if (level == NULL)
887dfa7d 158 level = SCM_WARN_DEPRECATED_DEFAULT;
7e516288 159 if (!strcmp (level, "detailed"))
65bc1f7a 160 SCM_WARN_DEPRECATED = 1;
7e516288 161 else if (!strcmp (level, "no"))
65bc1f7a 162 SCM_WARN_DEPRECATED = 0;
7e516288
MV
163 else
164 {
65bc1f7a 165 SCM_WARN_DEPRECATED = 0;
7e516288
MV
166 atexit (print_deprecation_summary);
167 }
7e516288 168#include "libguile/deprecation.x"
7e516288
MV
169}
170
171/*
172 Local Variables:
173 c-file-style: "gnu"
174 End: */