]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/private/__file_filter__.m
update packages
[CreaPhase.git] / octave_packages / m / plot / private / __file_filter__.m
1 ## Copyright (C) 2010-2012 Kai Habel
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} {} __file_filter__ (@var{file_filter})
21 ## Undocumented internal function.
22 ## @end deftypefn
23
24 ## Author: Kai Habel
25
26 function [retval, defname, defdir] = __file_filter__ (file_filter, name)
27
28   revtal = {};
29   defname = "";
30   defdir = "";
31
32   if (iscell (file_filter))
33     [r, c] = size (file_filter);
34     if (c != 1 && c != 2)
35       error ("%s: invalid filter specification", name);
36     endif
37     if (c == 1)
38       retval = cell (r, 2);
39       for i = 1:r
40         retval{i, 1} = file_filter{i};
41         retval{i, 2} = __default_filtername__ (file_filter{i});
42       endfor
43     else
44       retval = file_filter;
45       for i = 1:r
46         if (isempty (retval{i, 2}))
47           retval{i, 2} = __default_filtername__ (retval{i, 1});
48         endif
49       endfor
50     endif
51   elseif (ischar (file_filter))
52     [defdir, fname, fext] = fileparts (file_filter);
53     if (! strcmp (fname, "*"))
54       defname = strcat (fname, fext);
55     endif
56     if (length (fext) > 0)
57       fext = strcat ("*", fext);
58       retval = {fext, __default_filtername__(fext)};
59     endif
60   endif
61
62   retval(end+1,:) = {"*", __default_filtername__("*")};
63
64 endfunction
65
66 function name = __default_filtername__ (filterext)
67
68   name = "";
69
70   switch (filterext)
71     case "*"
72       name = "All Files";
73     case "*.m"
74       name = "Octave Source Files";
75     case "*.c"
76       name = "C Source Files";
77     case {"*.cc" "*.c++" "*.cpp"}
78       name = "C++ Source Files";
79     case "*.oct"
80       name = "Octave Compiled Files";
81   endswitch
82
83   if (isempty (name))
84     extlist = strsplit(filterext, ";");
85     extlist = strrep (extlist, "*.", "");
86     extlist = toupper (extlist);
87     extlist(end+1, :) = repmat ({","}, 1, length (extlist));
88     extlist = strcat (extlist{:});
89     extlist = extlist(1:end-1);
90     name = strcat (extlist, "-Files");
91   endif
92
93 endfunction