Mercurial > octave-nkf
comparison scripts/miscellaneous/doc.m @ 5830:0bb816a28335
[project @ 2006-05-26 19:04:08 by jwe]
author | jwe |
---|---|
date | Fri, 26 May 2006 19:04:08 +0000 |
parents | 1138ced03f14 |
children | 45f612d96d0e |
comparison
equal
deleted
inserted
replaced
5829:93785a1b0f97 | 5830:0bb816a28335 |
---|---|
31 | 31 |
32 ## PKG_ADD: mark_as_command doc | 32 ## PKG_ADD: mark_as_command doc |
33 | 33 |
34 function retval = doc (fname) | 34 function retval = doc (fname) |
35 | 35 |
36 if (nargin != 1 || ! ischar (fname)) | 36 if (nargin == 0 || nargin == 1) |
37 usage ("doc function_name") | |
38 endif | |
39 | 37 |
40 ## Get the directory where the function lives. | 38 ftype = 0; |
41 ## FIXME -- maybe we should have a better way of doing this. | |
42 | 39 |
43 x = exist (fname); | 40 if (nargin == 1) |
41 ## Get the directory where the function lives. | |
42 ## FIXME -- maybe we should have a better way of doing this. | |
44 | 43 |
45 if (x == 2) | 44 if (ischar (fname)) |
46 ffile = file_in_loadpath (strcat (fname, ".")); | 45 ftype = exist (fname); |
47 elseif (x == 3) | 46 else |
48 ffile = file_in_loadpath (strcat (fname, ".")); | 47 error ("doc: expecting argument to be a character string"); |
48 endif | |
49 else | |
50 fname = ""; | |
51 endif | |
52 | |
53 if (ftype == 2 || ftype == 3) | |
54 ffile = file_in_loadpath (strcat (fname, ".")); | |
55 else | |
56 ffile = ""; | |
57 endif | |
58 | |
59 if (isempty (ffile)) | |
60 info_dir = octave_config_info ("infodir"); | |
61 else | |
62 info_dir = fileparts (ffile); | |
63 endif | |
64 | |
65 ## Determine if a file called doc.info exist in the same | |
66 ## directory as the function. | |
67 | |
68 info_file_name = fullfile (info_dir, "doc.info"); | |
69 | |
70 [stat_info, err] = stat (info_file_name); | |
71 | |
72 if (err < 0) | |
73 info_file_name = info_file (); | |
74 endif | |
75 | |
76 cmd = sprintf ("\"%s\" --directory \"%s\" --file \"%s\"", | |
77 info_program (), info_dir, info_file_name); | |
78 | |
79 if (! isempty (fname)) | |
80 cmd = sprintf ("%s --index-search %s", cmd, fname); | |
81 endif | |
82 | |
83 status = system (cmd); | |
84 | |
85 if (status == 127) | |
86 warning ("unable to find info program `%s'", info_program ()); | |
87 endif | |
88 | |
89 if (nargout > 0) | |
90 retval = status; | |
91 endif | |
92 | |
49 else | 93 else |
50 ffile = ""; | 94 print_usage (); |
51 endif | |
52 | |
53 if (! isempty (ffile)) | |
54 info_dir = fileparts (ffile); | |
55 else | |
56 info_dir = octave_config_info ("infodir"); | |
57 endif | |
58 | |
59 ## Determine if a file called doc.info exist in the same | |
60 ## directory as the function. | |
61 | |
62 info_file_name = fullfile (info_dir, "doc.info"); | |
63 | |
64 if (! isstruct (stat (info_file_name))) | |
65 info_file_name = info_file (); | |
66 endif | |
67 | |
68 cmd = sprintf ("\"%s\" --directory \"%s\" --file \"%s\" --index-search %s", | |
69 info_program (), info_dir, info_file_name, fname); | |
70 | |
71 status = system (cmd); | |
72 | |
73 if (status == 127) | |
74 warning ("unable to find info program `%s'", info_program ()); | |
75 endif | |
76 | |
77 if (nargout > 0) | |
78 retval = status; | |
79 endif | 95 endif |
80 | 96 |
81 endfunction | 97 endfunction |