5178
|
1 ## Copyright (C) 2000 Paul Kienzle |
|
2 ## |
5181
|
3 ## This file is part of Octave. |
5178
|
4 ## |
5181
|
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 2, or (at your option) |
|
8 ## 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. |
5178
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
5181
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
5178
|
19 |
|
20 ## isequal(x1, x2, ...) |
|
21 ## true if all parts of x1, x2, ... are equal |
|
22 |
5181
|
23 ## Author: Paul Kienzle |
|
24 ## Adapted-by: jwe |
|
25 |
|
26 function t = isequal (x, varargin) |
|
27 |
|
28 if (nargin != 2) |
|
29 usage ("isequal (x, y, ...)"); |
5178
|
30 endif |
|
31 |
5181
|
32 for arg = 1:length (varargin) |
5178
|
33 y = varargin{arg}; |
5181
|
34 if (isstruct (x)) |
5178
|
35 t = isstruct (y); |
|
36 for [v, k] = x |
5181
|
37 t = (t |
|
38 && struct_contains (y, k) |
|
39 && isequal (getfield (x, k), getfield (y, k))); |
5178
|
40 endfor |
5181
|
41 for [v, k] = y |
5178
|
42 t = t && struct_contains (x, k); |
|
43 endfor |
5181
|
44 elseif (islist (x)) |
5178
|
45 t = islist(y) && length(x) == length(y); |
5181
|
46 if (! t) |
|
47 return; |
|
48 endif |
|
49 for i = 1:length (x) |
5178
|
50 t = isequal (x{i}, y{i}); |
5181
|
51 if (! t) |
|
52 return; |
|
53 endif |
5178
|
54 endfor |
5181
|
55 elseif (any (size (x) != size (y))) |
5178
|
56 t = false; |
5181
|
57 elseif (iscell (x) || islist (x)) |
|
58 t = iscell (y) || islist (y); |
|
59 if (! t) |
|
60 return; |
|
61 endif |
|
62 x = x(:); |
|
63 y = y(:); |
|
64 for i = 1:length (x) |
5178
|
65 t = isequal (x{i}, y{i}); |
5181
|
66 if (! t) |
|
67 return; |
|
68 endif |
5178
|
69 endfor |
|
70 else |
5181
|
71 t = all (x(:) == y(:)); |
5178
|
72 endif |
5181
|
73 if (! t) |
|
74 return; |
|
75 endif |
5178
|
76 endfor |
5181
|
77 |
5178
|
78 endfunction |