Commit | Line | Data |
---|---|---|
5cd06d5e | 1 | /* Copyright (C) 2001 Free Software Foundation, Inc. |
7e516288 MV |
2 | * |
3 | * This program is free software; you can redistribute it and/or modify | |
4 | * it under the terms of the GNU General Public License as published by | |
5 | * the Free Software Foundation; either version 2, or (at your option) | |
6 | * any later version. | |
7 | * | |
8 | * This program 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 | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License | |
14 | * along with this software; see the file COPYING. If not, write to | |
15 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
16 | * Boston, MA 02111-1307 USA | |
17 | * | |
18 | * As a special exception, the Free Software Foundation gives permission | |
19 | * for additional uses of the text contained in its release of GUILE. | |
20 | * | |
21 | * The exception is that, if you link the GUILE library with other files | |
22 | * to produce an executable, this does not by itself cause the | |
23 | * resulting executable to be covered by the GNU General Public License. | |
24 | * Your use of that executable is in no way restricted on account of | |
25 | * linking the GUILE library code into it. | |
26 | * | |
27 | * This exception does not however invalidate any other reasons why | |
28 | * the executable file might be covered by the GNU General Public License. | |
29 | * | |
30 | * This exception applies only to the code released by the | |
31 | * Free Software Foundation under the name GUILE. If you copy | |
32 | * code from other Free Software Foundation releases into a copy of | |
33 | * GUILE, as the General Public License permits, the exception does | |
34 | * not apply to the code that you add in this way. To avoid misleading | |
35 | * anyone as to the status of such modified files, you must delete | |
36 | * this exception notice from them. | |
37 | * | |
38 | * If you write modifications of your own for GUILE, it is your choice | |
39 | * whether to permit this exception to apply to your modifications. | |
40 | * If you do not wish that, delete this exception notice. */ | |
41 | ||
42 | \f | |
43 | ||
5f0bcfd5 RB |
44 | #if HAVE_CONFIG_H |
45 | # include <config.h> | |
46 | #endif | |
47 | ||
7e516288 | 48 | #include <stdio.h> |
fbbdb121 | 49 | #include <string.h> |
d013f095 | 50 | #include <stdarg.h> |
7e516288 MV |
51 | |
52 | #include "libguile/_scm.h" | |
53 | ||
54 | #include "libguile/deprecation.h" | |
7e516288 MV |
55 | #include "libguile/strings.h" |
56 | #include "libguile/ports.h" | |
57 | ||
edb810bb SJ |
58 | /* Windows defines. */ |
59 | #ifdef __MINGW32__ | |
60 | #define vsnprintf _vsnprintf | |
61 | #endif | |
62 | ||
7e516288 MV |
63 | \f |
64 | ||
8c494e99 | 65 | #if (SCM_ENABLE_DEPRECATED == 1) |
7e516288 | 66 | |
d013f095 MV |
67 | struct issued_warning { |
68 | struct issued_warning *prev; | |
69 | const char *message; | |
70 | }; | |
71 | ||
72 | static struct issued_warning *issued_warnings; | |
73 | static enum { detailed, summary, summary_print } mode; | |
7e516288 MV |
74 | |
75 | void | |
76 | scm_c_issue_deprecation_warning (const char *msg) | |
77 | { | |
d013f095 MV |
78 | if (mode != detailed) |
79 | mode = summary_print; | |
7e516288 | 80 | else |
d013f095 MV |
81 | { |
82 | struct issued_warning *iw; | |
83 | for (iw = issued_warnings; iw; iw = iw->prev) | |
84 | if (!strcmp (iw->message, msg)) | |
85 | return; | |
86 | if (scm_gc_running_p) | |
87 | fprintf (stderr, "%s\n", msg); | |
88 | else | |
89 | { | |
90 | scm_puts (msg, scm_current_error_port ()); | |
91 | scm_newline (scm_current_error_port ()); | |
92 | } | |
93 | msg = strdup (msg); | |
67329a9e | 94 | iw = scm_malloc (sizeof (struct issued_warning)); |
d013f095 MV |
95 | if (msg == NULL || iw == NULL) |
96 | return; | |
97 | iw->message = msg; | |
98 | iw->prev = issued_warnings; | |
99 | issued_warnings = iw; | |
100 | } | |
101 | } | |
102 | ||
103 | void | |
104 | scm_c_issue_deprecation_warning_fmt (const char *msg, ...) | |
105 | { | |
106 | va_list ap; | |
107 | char buf[512]; | |
108 | ||
109 | va_start (ap, msg); | |
110 | vsnprintf (buf, 511, msg, ap); | |
111 | buf[511] = '\0'; | |
112 | scm_c_issue_deprecation_warning (buf); | |
7e516288 MV |
113 | } |
114 | ||
115 | SCM_DEFINE(scm_issue_deprecation_warning, | |
116 | "issue-deprecation-warning", 0, 0, 1, | |
117 | (SCM msgs), | |
118 | "Output @var{msgs} to @code{(current-error-port)} when this " | |
119 | "is the first call to @code{issue-deprecation-warning} with " | |
d013f095 | 120 | "this specific @var{msgs}. Do nothing otherwise. " |
7e516288 MV |
121 | "The argument @var{msgs} should be a list of strings; " |
122 | "they are printed in turn, each one followed by a newline.") | |
123 | #define FUNC_NAME s_scm_issue_deprecation_warning | |
124 | { | |
d013f095 MV |
125 | if (mode != detailed) |
126 | mode = summary_print; | |
7e516288 MV |
127 | else |
128 | { | |
d013f095 MV |
129 | SCM nl = scm_str2string ("\n"); |
130 | SCM msgs_nl = SCM_EOL; | |
131 | while (SCM_CONSP (msgs)) | |
7e516288 | 132 | { |
d013f095 MV |
133 | if (msgs_nl != SCM_EOL) |
134 | msgs_nl = scm_cons (nl, msgs_nl); | |
135 | msgs_nl = scm_cons (SCM_CAR (msgs), msgs_nl); | |
136 | msgs = SCM_CDR (msgs); | |
7e516288 | 137 | } |
d013f095 MV |
138 | msgs_nl = scm_string_append (scm_reverse_x (msgs_nl, SCM_EOL)); |
139 | scm_c_issue_deprecation_warning (SCM_STRING_CHARS (msgs_nl)); | |
140 | scm_remember_upto_here_1 (msgs_nl); | |
7e516288 MV |
141 | } |
142 | return SCM_UNSPECIFIED; | |
143 | } | |
144 | #undef FUNC_NAME | |
145 | ||
146 | static void | |
147 | print_deprecation_summary (void) | |
148 | { | |
d013f095 | 149 | if (mode == summary_print) |
7e516288 MV |
150 | { |
151 | fputs ("\n" | |
152 | "Some deprecated features have been used. Set the environment\n" | |
153 | "variable GUILE_WARN_DEPRECATED to \"detailed\" and rerun the\n" | |
154 | "program to get more information. Set it to \"no\" to suppress\n" | |
155 | "this message.\n", stderr); | |
156 | } | |
157 | } | |
158 | ||
159 | #endif | |
160 | ||
161 | SCM_DEFINE(scm_include_deprecated_features, | |
162 | "include-deprecated-features", 0, 0, 0, | |
163 | (), | |
7bad99fd MV |
164 | "Return @code{#t} iff deprecated features should be included " |
165 | "in public interfaces.") | |
7e516288 MV |
166 | #define FUNC_NAME s_scm_include_deprecated_features |
167 | { | |
8c494e99 | 168 | return SCM_BOOL (SCM_ENABLE_DEPRECATED == 1); |
7e516288 MV |
169 | } |
170 | #undef FUNC_NAME | |
171 | ||
172 | ||
173 | \f | |
174 | ||
175 | void | |
176 | scm_init_deprecation () | |
177 | { | |
8c494e99 | 178 | #if (SCM_ENABLE_DEPRECATED == 1) |
7e516288 MV |
179 | const char *level = getenv ("GUILE_WARN_DEPRECATED"); |
180 | if (level == NULL) | |
887dfa7d | 181 | level = SCM_WARN_DEPRECATED_DEFAULT; |
7e516288 | 182 | if (!strcmp (level, "detailed")) |
d013f095 | 183 | mode = detailed; |
7e516288 | 184 | else if (!strcmp (level, "no")) |
d013f095 | 185 | mode = summary; |
7e516288 MV |
186 | else |
187 | { | |
d013f095 | 188 | mode = summary; |
7e516288 MV |
189 | atexit (print_deprecation_summary); |
190 | } | |
191 | #endif | |
7e516288 | 192 | #include "libguile/deprecation.x" |
7e516288 MV |
193 | } |
194 | ||
195 | /* | |
196 | Local Variables: | |
197 | c-file-style: "gnu" | |
198 | End: */ |