1 /* Copyright (C) 2001 Free Software Foundation, Inc.
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)
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.
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
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
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.
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
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.
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. */
48 #include "libguile/_scm.h"
50 #include "libguile/deprecation.h"
51 #include "libguile/strings.h"
52 #include "libguile/ports.h"
54 /* Windows defines. */
56 #define vsnprintf _vsnprintf
61 #if (SCM_ENABLE_DEPRECATED == 1)
63 struct issued_warning
{
64 struct issued_warning
*prev
;
68 static struct issued_warning
*issued_warnings
;
69 static enum { detailed
, summary
, summary_print
} mode
;
72 scm_c_issue_deprecation_warning (const char *msg
)
78 struct issued_warning
*iw
;
79 for (iw
= issued_warnings
; iw
; iw
= iw
->prev
)
80 if (!strcmp (iw
->message
, msg
))
83 fprintf (stderr
, "%s\n", msg
);
86 scm_puts (msg
, scm_current_error_port ());
87 scm_newline (scm_current_error_port ());
90 iw
= scm_malloc (sizeof (struct issued_warning
));
91 if (msg
== NULL
|| iw
== NULL
)
94 iw
->prev
= issued_warnings
;
100 scm_c_issue_deprecation_warning_fmt (const char *msg
, ...)
106 vsnprintf (buf
, 511, msg
, ap
);
108 scm_c_issue_deprecation_warning (buf
);
111 SCM_DEFINE(scm_issue_deprecation_warning
,
112 "issue-deprecation-warning", 0, 0, 1,
114 "Output @var{msgs} to @code{(current-error-port)} when this "
115 "is the first call to @code{issue-deprecation-warning} with "
116 "this specific @var{msgs}. Do nothing otherwise. "
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
121 if (mode
!= detailed
)
122 mode
= summary_print
;
125 SCM nl
= scm_str2string ("\n");
126 SCM msgs_nl
= SCM_EOL
;
127 while (SCM_CONSP (msgs
))
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
);
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
);
138 return SCM_UNSPECIFIED
;
143 print_deprecation_summary (void)
145 if (mode
== summary_print
)
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
);
157 SCM_DEFINE(scm_include_deprecated_features
,
158 "include-deprecated-features", 0, 0, 0,
160 "Return @code{#t} iff deprecated features should be included "
161 "in public interfaces.")
162 #define FUNC_NAME s_scm_include_deprecated_features
164 return SCM_BOOL (SCM_ENABLE_DEPRECATED
== 1);
172 scm_init_deprecation ()
174 #if (SCM_ENABLE_DEPRECATED == 1)
175 const char *level
= getenv ("GUILE_WARN_DEPRECATED");
177 level
= SCM_WARN_DEPRECATED_DEFAULT
;
178 if (!strcmp (level
, "detailed"))
180 else if (!strcmp (level
, "no"))
185 atexit (print_deprecation_summary
);
188 #include "libguile/deprecation.x"