1 /* Copyright (C) 2001, 2006 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * 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.
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., 51 Franklin Street, Fifth Floor, Boston, MA
29 #include "libguile/_scm.h"
31 #include "libguile/deprecation.h"
32 #include "libguile/strings.h"
33 #include "libguile/ports.h"
35 #include "libguile/private-options.h"
38 /* Windows defines. */
40 #define vsnprintf _vsnprintf
45 struct issued_warning
{
46 struct issued_warning
*prev
;
50 static struct issued_warning
*issued_warnings
;
51 static int print_summary
= 0;
54 scm_c_issue_deprecation_warning (const char *msg
)
56 if (!SCM_WARN_DEPRECATED
)
60 struct issued_warning
*iw
;
61 for (iw
= issued_warnings
; iw
; iw
= iw
->prev
)
62 if (!strcmp (iw
->message
, msg
))
65 fprintf (stderr
, "%s\n", msg
);
68 scm_puts (msg
, scm_current_error_port ());
69 scm_newline (scm_current_error_port ());
72 iw
= malloc (sizeof (struct issued_warning
));
73 if (msg
== NULL
|| iw
== NULL
)
76 iw
->prev
= issued_warnings
;
82 scm_c_issue_deprecation_warning_fmt (const char *msg
, ...)
88 vsnprintf (buf
, 511, msg
, ap
);
91 scm_c_issue_deprecation_warning (buf
);
94 SCM_DEFINE(scm_issue_deprecation_warning
,
95 "issue-deprecation-warning", 0, 0, 1,
97 "Output @var{msgs} to @code{(current-error-port)} when this "
98 "is the first call to @code{issue-deprecation-warning} with "
99 "this specific @var{msgs}. Do nothing otherwise. "
100 "The argument @var{msgs} should be a list of strings; "
101 "they are printed in turn, each one followed by a newline.")
102 #define FUNC_NAME s_scm_issue_deprecation_warning
104 if (!SCM_WARN_DEPRECATED
)
108 SCM nl
= scm_from_locale_string ("\n");
109 SCM msgs_nl
= SCM_EOL
;
111 while (scm_is_pair (msgs
))
113 if (msgs_nl
!= SCM_EOL
)
114 msgs_nl
= scm_cons (nl
, msgs_nl
);
115 msgs_nl
= scm_cons (SCM_CAR (msgs
), msgs_nl
);
116 msgs
= SCM_CDR (msgs
);
118 msgs_nl
= scm_string_append (scm_reverse_x (msgs_nl
, SCM_EOL
));
119 c_msgs
= scm_to_locale_string (msgs_nl
);
120 scm_c_issue_deprecation_warning (c_msgs
);
123 return SCM_UNSPECIFIED
;
128 print_deprecation_summary (void)
133 "Some deprecated features have been used. Set the environment\n"
134 "variable GUILE_WARN_DEPRECATED to \"detailed\" and rerun the\n"
135 "program to get more information. Set it to \"no\" to suppress\n"
136 "this message.\n", stderr
);
140 SCM_DEFINE(scm_include_deprecated_features
,
141 "include-deprecated-features", 0, 0, 0,
143 "Return @code{#t} iff deprecated features should be included "
144 "in public interfaces.")
145 #define FUNC_NAME s_scm_include_deprecated_features
147 return scm_from_bool (SCM_ENABLE_DEPRECATED
== 1);
155 scm_init_deprecation ()
157 const char *level
= getenv ("GUILE_WARN_DEPRECATED");
159 level
= SCM_WARN_DEPRECATED_DEFAULT
;
160 if (!strcmp (level
, "detailed"))
161 SCM_WARN_DEPRECATED
= 1;
162 else if (!strcmp (level
, "no"))
163 SCM_WARN_DEPRECATED
= 0;
166 SCM_WARN_DEPRECATED
= 0;
167 atexit (print_deprecation_summary
);
169 #include "libguile/deprecation.x"