]> Creatis software - CreaPhase.git/blob - octave_packages/miscellaneous-1.1.0/infoskeleton.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / miscellaneous-1.1.0 / infoskeleton.m
1 ## Copyright (C) 2008 Muthiah Annamalai <muthiah.annamalai@mavs.uta.edu>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ##-*- texinfo -*-
17 ## @deftypefn{Function File} infoskeleton(@var{prototype}, @var{index_str}, @var{see_also})
18 ## Generate TeXinfo skeleton documentation of @var{prototype}.
19 ##
20 ## Optionally @var{index_str} and @var{see_also} can be specified.
21 ##
22 ## Usage of this function is typically,
23 ## @example
24 ## infoskeleton('[V,Q] = eig( A )','linear algebra','eigs, chol, qr, det')
25 ## @end example
26 ## @seealso{info}
27 ## @end deftypefn
28
29 function infoskeleton( prototype , index_str, seealso)
30
31   ## FIXME: add placeholders for math TeX code, examples etc.
32
33   if nargin < 1
34     print_usage();
35   end
36
37   if nargin < 2
38     index_str = "";
39   end
40
41   if nargin < 3
42     seealso = "";
43   end
44
45   ## 
46   ## try to parse the function prototype
47   ## as:
48   ## function retval = fname ( arg1, arg2, etc )"
49   ##
50   prototype = strtrim( prototype );
51   idx = strfind( prototype, "function" );
52   if ( !isempty( idx ) )
53     prototype(idx:idx+7) = "";
54   end
55
56   idx = strfind( prototype, "=" );
57   retval = "";
58   if( !isempty( idx )   )  
59      retval = strtrim ( prototype( 1 : idx(1)-1 ) );
60      prototype = prototype ( idx(1) + 1: end );
61   end     
62
63
64   idx = strfind( prototype, "(" );
65   fname = prototype;
66   if( !isempty( idx )   )  
67     fname = strtrim( prototype(1:idx(1)-1) );
68     prototype = prototype(idx(1) + 1:end);
69   end
70
71   ## next time, use strtok() very easy & simple
72
73   pos = 0; args = {};
74   idx =  strfind( prototype , "," );
75   if ( !isempty( idx ) )
76     prev = [ 0, idx ];
77     for pos=1:length( idx )
78       args{ pos } = strtrim ( prototype(prev( pos )+1 :idx(pos)-1) );
79     end
80     prototype = prototype(idx(end) + 1:end);
81   end
82
83   idx = strfind( prototype, ")" );
84   if ( !isempty( idx ) )
85     lvar = strtrim ( prototype(1:idx(1)-1) );
86     if ( length( lvar ) > 0 ) 
87       args{ pos + 1 } =  lvar;
88     end
89   end
90
91
92   ## generate the code
93   fprintf("## -*- texinfo -*-\n")
94   if ( length( retval ) > 0 )
95     fprintf("## @deftypefn{Function File} {@var{%s} = } %s (", ...
96             retval,fname );
97   else
98     fprintf("## @deftypefn{Function File} { } %s (", ...
99             fname );
100   end
101
102   pos = 0;
103   for pos = 1:length(args)-1
104     fprintf(" %s,", args{pos} );
105   end
106   if ( length(args) > 0 )
107     fprintf(" %s ) \n", args{pos+1} );
108   end
109   fprintf("## @cindex %s \n",index_str);
110   fprintf("##  The function %s calculates    where",fname );
111   pos = 0;
112   for pos = 1:length(args)-1
113     fprintf(" @var{%s} is ,", args{pos} );
114   end
115   if ( length(args) > 0 )
116     fprintf(" @var{%s} is   .\n", args{pos+1} );
117   end
118    
119   fprintf("## @example\n");
120   fprintf("## \n");
121   fprintf("## @end example\n");
122
123   fprintf("## @seealso{%s}\n",seealso);
124   fprintf("## @end deftypefn\n");
125 end
126
127 %!demo infoskeleton( ' [x,y,z]=infoskeleton(func , z , z9 , jj, fjh, x)  ')
128 %!demo infoskeleton('[V,Q] = eig( A )','linear algebra','eigs, chol, qr, det')
129 %!demo infoskeleton( 'function [x,y,z] =  indian_languages ( x)  ')