comparison scripts/help/print_usage.m @ 17100:ae7872816611

print_usage.m: Fix handling of functions with multiple @deftypefn/@end deftypefn pairs. * scripts/help/print_usage.m: Fix handling of functions with multiple @deftypefn/@end deftypefn pairs (gallery.m). Use Octave coding conventions.
author Rik <rik@octave.org>
date Sun, 28 Jul 2013 14:55:53 -0700
parents 6f3363ff368c
children f4c8c66faf34
comparison
equal deleted inserted replaced
17099:a033fd3669c0 17100:ae7872816611
29 x = dbstack (); 29 x = dbstack ();
30 ## Handle input 30 ## Handle input
31 if (nargin == 0) 31 if (nargin == 0)
32 ## Determine the name of the calling function 32 ## Determine the name of the calling function
33 if (numel (x) > 1) 33 if (numel (x) > 1)
34 name = x (2).name; 34 name = x(2).name;
35 else 35 else
36 error ("Octave:invalid-context", "print_usage: invalid function\n"); 36 error ("Octave:invalid-context", "print_usage: invalid function\n");
37 endif 37 endif
38 fullpath = evalin ("caller", "mfilename (""fullpath"")"); 38 fullpath = evalin ("caller", 'mfilename ("fullpath")');
39 if (strcmp (fullpath(end-length(name)+1:end), name)) 39 if (strcmp (fullpath(end-length(name)+1:end), name))
40 fullname = [fullpath, ".m"]; 40 fullname = [fullpath ".m"];
41 endif 41 endif
42 elseif (!ischar (name)) 42 elseif (! ischar (name))
43 error ("Octave:invalid-input-arg", 43 error ("Octave:invalid-input-arg",
44 "print_usage: input argument must be a string"); 44 "print_usage: input argument must be a string");
45 else 45 else
46 fullname = name; 46 fullname = name;
47 endif 47 endif
48 48
49 ## Determine if we're called from top level. 49 ## Determine if we were called from top level.
50 at_toplev = length (x) < 2 || (length (x) == 2 && strcmp (x(2).name, name)); 50 at_toplev = length (x) < 2 || (length (x) == 2 && strcmp (x(2).name, name));
51 51
52 ## Do the actual work 52 ## Do the actual work
53 [text, format] = get_help_text (fullname); 53 [text, format] = get_help_text (fullname);
54 max_len = 80; 54 max_len = 80;
72 warning ("print_usage: Texinfo formatting filter exited abnormally"); 72 warning ("print_usage: Texinfo formatting filter exited abnormally");
73 warning ("print_usage: raw Texinfo source of help text follows...\n"); 73 warning ("print_usage: raw Texinfo source of help text follows...\n");
74 endif 74 endif
75 75
76 if (at_toplev) 76 if (at_toplev)
77 error ("Octave:invalid-fun-call", "Invalid call to %s. Correct usage is:\n\n%s\n%s", 77 error ("Octave:invalid-fun-call",
78 "Invalid call to %s. Correct usage is:\n\n%s\n%s",
78 name, usage_string, __additional_help_message__ ()); 79 name, usage_string, __additional_help_message__ ());
79 else 80 else
80 msg = sprintf ("Invalid call to %s. Correct usage is:\n\n%s", 81 msg = sprintf ("Invalid call to %s. Correct usage is:\n\n%s",
81 name, usage_string); 82 name, usage_string);
82 ## Ensure that the error doesn't end up with a newline, as that disables 83 ## Ensure that the error doesn't end up with a newline, as that disables
100 function [retval, status] = get_usage_texinfo (help_text, max_len) 101 function [retval, status] = get_usage_texinfo (help_text, max_len)
101 ## Lines ending with "@\n" are continuation lines, so they should be 102 ## Lines ending with "@\n" are continuation lines, so they should be
102 ## concatenated with the following line. 103 ## concatenated with the following line.
103 help_text = strrep (help_text, "@\n", " "); 104 help_text = strrep (help_text, "@\n", " ");
104 105
105 ## Find, and keep, lines that start with @def or @end def. This should include things 106 ## Find, and keep, lines that start with @def or @end def. This should
106 ## such as @deftypefn, @deftypefnx, @defvar, etc. and their corresponding @end's 107 ## include things such as @deftypefn, @deftypefnx, @defvar, etc. and their
108 ## corresponding @end's.
107 def_idx = strfind (help_text, "@def"); 109 def_idx = strfind (help_text, "@def");
108 if (!isempty (def_idx)) 110 if (! isempty (def_idx))
111 endf_idx = strfind (help_text, "@end def");
112 def_idx = sort ([def_idx, endf_idx]);
113 endl_idx = find (help_text == "\n");
109 buffer = ""; 114 buffer = "";
110 endl_idx = find (help_text == "\n");
111 for k = 1:length (def_idx) 115 for k = 1:length (def_idx)
112 endl = endl_idx (find (endl_idx > def_idx (k), 1)); 116 endl = endl_idx (find (endl_idx > def_idx(k), 1));
113 if (isempty (endl)) 117 if (isempty (endl))
114 buffer = strcat (buffer, help_text (def_idx (k):end), "\n"); 118 buffer = strcat (buffer, help_text (def_idx(k):end), "\n");
115 else 119 else
116 buffer = strcat (buffer, help_text (def_idx (k):endl)); 120 buffer = strcat (buffer, help_text (def_idx(k):endl));
117 endif 121 endif
118 endfor 122 endfor
119
120 end_def_idx = strfind (help_text, "@end def");
121 if (!isempty (end_def_idx))
122 buffer = strcat (buffer, help_text (end_def_idx:end));
123 endif
124 else 123 else
125 [retval, status] = get_usage_plain_text (help_text, max_len); 124 [retval, status] = get_usage_plain_text (help_text, max_len);
126 endif 125 endif
127 126
128 ## Run makeinfo to generate plain text 127 ## Run makeinfo to generate plain text