1 ## Copyright (C) 2008-2012 David Bateman
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} intwarning (@var{action})
21 ## @deftypefnx {Function File} {} intwarning (@var{s})
22 ## @deftypefnx {Function File} {@var{s} =} intwarning (@dots{})
23 ## Control the state of the warning for integer conversions and math
28 ## With an output argument, return the current state of the integer
29 ## conversion and math warnings. With no output arguments, print the
31 ## @c Set example in small font to prevent overfull line
35 ## intwarning ("query")
36 ## The state of warning "Octave:int-convert-nan" is "off"
37 ## The state of warning "Octave:int-convert-non-int-val" is "off"
38 ## The state of warning "Octave:int-convert-overflow" is "off"
39 ## The state of warning "Octave:int-math-overflow" is "off"
45 ## Turn integer conversion and math warnings on (or off). If there is
46 ## no output argument, then nothing is printed. Otherwise the original
47 ## state of the state of the integer conversion and math warnings is
48 ## returned in a structure array.
51 ## The original state of the integer warnings can be restored by passing
52 ## the structure array returned by @code{intwarning} to a later call to
53 ## @code{intwarning}. For example:
57 ## s = intwarning ("off");
65 ## Deprecated in v. 3.4
67 function y = intwarning (x)
69 persistent warned = false;
72 warning ("Octave:deprecated-function",
73 "intwarning is obsolete and will be removed from a future version of Octave; integer math no longer produces warnings -- supply your own checks if you need those");
82 y = warning("query", "Octave:int-convert-nan");
83 y = [y; warning("query", "Octave:int-convert-non-int-val")];
84 y = [y; warning("query", "Octave:int-convert-overflow")];
85 y = [y; warning("query", "Octave:int-math-overflow")];
88 if (strcmpi (x, "query"))
90 __print_int_warn_state__ ("Octave:int-convert-nan");
91 __print_int_warn_state__ ("Octave:int-convert-non-int-val");
92 __print_int_warn_state__ ("Octave:int-convert-overflow");
93 __print_int_warn_state__ ("Octave:int-math-overflow");
96 elseif (strcmpi (x, "on"))
97 warning ("on", "Octave:int-convert-nan");
98 warning ("on", "Octave:int-convert-non-int-val");
99 warning ("on", "Octave:int-convert-overflow");
100 warning ("on", "Octave:int-math-overflow");
101 elseif (strcmpi (x, "off"))
102 warning ("off", "Octave:int-convert-nan");
103 warning ("off", "Octave:int-convert-non-int-val");
104 warning ("off", "Octave:int-convert-overflow");
105 warning ("off", "Octave:int-math-overflow");
107 error ("intwarning: unrecognized argument");
110 for fld = fieldnames (x)
111 if (strcmp ("Octave:int-convert-nan")
112 || strcmp ("Octave:int-convert-non-int-val")
113 || strcmp ("Octave:int-convert-overflow")
114 || strcmp ("Octave:int-cmath-overflow"))
115 s = getfield (x, fld);
116 if (! ischar (s) || !(strcmpi("s","on") || strcmpi("s","off")))
117 error ("intwarning: unexpected warning state");
121 error ("intwarning: unrecognized integer warning %s", fld);
125 error ("intwarning: unexpected input");
130 function __print_int_warn_state__ (s)
131 fprintf ("The state of warning \"%s\" is \"%s\"\n",
132 s, warning ("query", s).state);