]> Creatis software - CreaPhase.git/blob - octave_packages/m/deprecated/intwarning.m
update packages
[CreaPhase.git] / octave_packages / m / deprecated / intwarning.m
1 ## Copyright (C) 2008-2012 David Bateman
2 ##
3 ## This file is part of Octave.
4 ##
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.
9 ##
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.
14 ##
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/>.
18
19 ## -*- texinfo -*-
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
24 ## operations.
25 ##
26 ## @table @asis
27 ## @item "query"
28 ## With an output argument, return the current state of the integer
29 ## conversion and math warnings.  With no output arguments, print the
30 ## current state.
31 ## @c Set example in small font to prevent overfull line
32 ##
33 ## @smallexample
34 ## @group
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"
40 ## @end group
41 ## @end smallexample
42 ##
43 ## @item "on"
44 ## @itemx "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.
49 ## @end table
50 ##
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:
54 ##
55 ## @example
56 ## @group
57 ## s = intwarning ("off");
58 ## @dots{}
59 ## intwarning (s);
60 ## @end group
61 ## @end example
62 ## @seealso{warning}
63 ## @end deftypefn
64
65 ## Deprecated in v. 3.4
66
67 function y = intwarning (x)
68
69   persistent warned = false;
70   if (! warned)
71     warned = true;
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");
74   endif
75
76   return;
77
78   if (nargin != 1)
79     print_usage ();
80   else
81     if (nargout > 0)
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")];
86     endif
87     if (ischar (x))
88       if (strcmpi (x, "query"))
89         if (nargout == 0)
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");
94           printf("\n");
95         endif
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");
106       else
107         error ("intwarning: unrecognized argument");
108       endif
109     elseif (isstruct(x))
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");
118           endif
119           warning (s, fld);
120         else
121           error ("intwarning: unrecognized integer warning %s", fld);
122         endif
123       endfor
124     else
125       error ("intwarning: unexpected input");
126     endif
127   endif
128 endfunction
129
130 function __print_int_warn_state__ (s)
131   fprintf ("The state of warning \"%s\" is \"%s\"\n",
132            s, warning ("query", s).state);
133 endfunction