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