Mercurial > hg > octave-nkf
annotate scripts/miscellaneous/edit.m @ 11104:2c356a35d7f5
fix copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 17 Oct 2010 23:43:42 -0400 |
parents | c9b0a75b02e8 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2001, 2007, 2008, 2009 Paul Kienzle |
7325 | 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 -*- | |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
20 ## @deftypefn {Command} {} edit @var{name} |
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
21 ## @deftypefnx {Command} {} edit @var{field} @var{value} |
7650 | 22 ## @deftypefnx {Command} {@var{value} =} edit get @var{field} |
7325 | 23 ## Edit the named function, or change editor settings. |
24 ## | |
25 ## If @code{edit} is called with the name of a file or function as | |
26 ## its argument it will be opened in a text editor. | |
27 ## | |
28 ## @itemize @bullet | |
29 ## @item | |
30 ## If the function @var{name} is available in a file on your path and | |
31 ## that file is modifiable, then it will be edited in place. If it | |
32 ## is a system function, then it will first be copied to the directory | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
33 ## @env{HOME} (see further down) and then edited. |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
34 ## If no file is found, then the m-file |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
35 ## variant, ending with ".m", will be considered. If still no file |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
36 ## is found, then variants with a leading "@@" and then with both a |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
37 ## leading "@@" and trailing ".m" will be considered. |
7325 | 38 ## |
39 ## @item | |
40 ## If @var{name} is the name of a function defined in the interpreter but | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
41 ## not in an m-file, then an m-file will be created in @env{HOME} |
7325 | 42 ## to contain that function along with its current definition. |
43 ## | |
44 ## @item | |
45 ## If @code{name.cc} is specified, then it will search for @code{name.cc} | |
46 ## in the path and try to modify it, otherwise it will create a new | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
47 ## @file{.cc} file in @env{HOME}. If @var{name} happens to be an |
7325 | 48 ## m-file or interpreter defined function, then the text of that |
49 ## function will be inserted into the .cc file as a comment. | |
50 ## | |
51 ## @item | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
52 ## If @var{name.ext} is on your path then it will be edited, otherwise |
7325 | 53 ## the editor will be started with @file{HOME/name.ext} as the |
54 ## filename. If @file{name.ext} is not modifiable, it will be copied to | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
55 ## @env{HOME} before editing. |
7325 | 56 ## |
57 ## @strong{WARNING!} You may need to clear name before the new definition | |
58 ## is available. If you are editing a .cc file, you will need | |
59 ## to mkoctfile @file{name.cc} before the definition will be available. | |
60 ## @end itemize | |
61 ## | |
62 ## If @code{edit} is called with @var{field} and @var{value} variables, | |
63 ## the value of the control field @var{field} will be @var{value}. | |
64 ## If an output argument is requested and the first argument is @code{get} | |
65 ## then @code{edit} will return the value of the control field @var{field}. | |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
66 ## If the control field does not exist, edit will return a structure |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
67 ## containing all fields and values. Thus, @code{edit get all} returns |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
68 ## a complete control structure. |
7325 | 69 ## The following control fields are used: |
70 ## | |
71 ## @table @samp | |
72 ## @item editor | |
73 ## This is the editor to use to modify the functions. By default it uses | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
74 ## Octave's @env{EDITOR} built-in function, which comes from |
7325 | 75 ## @code{getenv("EDITOR")} and defaults to @code{emacs}. Use @code{%s} |
76 ## In place of the function name. For example, | |
77 ## @table @samp | |
78 ## @item [EDITOR, " %s"] | |
79 ## Use the editor which Octave uses for @code{bug_report}. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
80 ## |
7325 | 81 ## @item "xedit %s &" |
82 ## pop up simple X11 editor in a separate window | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
83 ## |
7325 | 84 ## @item "gnudoit -q \"(find-file \\\"%s\\\")\"" |
85 ## Send it to current Emacs; must have @code{(gnuserv-start)} in @file{.emacs}. | |
86 ## @end table | |
87 ## | |
8795
bb38a86efa1b
improve documentation for edit.m
Ivan Sutoris <ivan.sutoris@gmail.com>
parents:
8746
diff
changeset
|
88 ## See also field 'mode', which controls how the editor is run by Octave. |
bb38a86efa1b
improve documentation for edit.m
Ivan Sutoris <ivan.sutoris@gmail.com>
parents:
8746
diff
changeset
|
89 ## |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
90 ## On Cygwin, you will need to convert the Cygwin path to a Windows |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
91 ## path if you are using a native Windows editor. For example: |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
92 ## @c Set example in small font to prevent overfull line in TeX |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
93 ## |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
94 ## @smallexample |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
95 ## @exdent '"C:/Program Files/Good Editor/Editor.exe" "$(cygpath -wa %s)"' |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
96 ## @end smallexample |
7325 | 97 ## |
98 ## @item home | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
99 ## This is the location of user local m-files. Be be sure it is in your |
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
100 ## path. The default is @file{~/octave}. |
7325 | 101 ## |
102 ## @item author | |
103 ## This is the name to put after the "## Author:" field of new functions. | |
104 ## By default it guesses from the @code{gecos} field of password database. | |
105 ## | |
106 ## @item email | |
107 ## This is the e-mail address to list after the name in the author field. | |
108 ## By default it guesses @code{<$LOGNAME@@$HOSTNAME>}, and if @code{$HOSTNAME} | |
109 ## is not defined it uses @code{uname -n}. You probably want to override this. | |
110 ## Be sure to use @code{<user@@host>} as your format. | |
111 ## | |
112 ## @item license | |
113 ## @table @samp | |
114 ## @item gpl | |
115 ## GNU General Public License (default). | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
116 ## |
7325 | 117 ## @item bsd |
118 ## BSD-style license without advertising clause. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
119 ## |
7325 | 120 ## @item pd |
121 ## Public domain. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
122 ## |
7325 | 123 ## @item "text" |
124 ## Your own default copyright and license. | |
125 ## @end table | |
126 ## | |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
127 ## Unless you specify @samp{pd}, edit will prepend the copyright statement |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
128 ## with "Copyright (C) yyyy Function Author". |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
129 ## |
7325 | 130 ## @item mode |
131 ## This value determines whether the editor should be started in async mode | |
8795
bb38a86efa1b
improve documentation for edit.m
Ivan Sutoris <ivan.sutoris@gmail.com>
parents:
8746
diff
changeset
|
132 ## (editor is started in the background and Octave continues) or sync mode |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
133 ## (Octave waits until the editor exits). Set it to "async" to start the editor |
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
134 ## in async mode. The default is "sync" (see also "system"). |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
135 ## |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
136 ## @item editinplace |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
137 ## Determines whether files should be edited in place, without regard to |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
138 ## whether they are modifiable or not. The default is @code{false}. |
7325 | 139 ## @end table |
140 ## @end deftypefn | |
141 | |
142 ## Author: Paul Kienzle <pkienzle@users.sf.net> | |
143 | |
144 ## Original version by Paul Kienzle distributed as free software in the | |
145 ## public domain. | |
146 | |
147 function ret = edit (file, state) | |
148 | |
149 ## Pick up globals or default them. | |
150 | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
151 persistent FUNCTION = struct ("EDITOR", cstrcat (EDITOR (), " %s"), |
10549 | 152 "HOME", fullfile (default_home, "octave"), |
153 "AUTHOR", default_user(1), | |
154 "EMAIL", [], | |
155 "LICENSE", "GPL", | |
156 "MODE", "sync", | |
157 "EDITINPLACE", false); | |
7325 | 158 |
8506 | 159 ## Make sure the state variables survive "clear functions". |
160 mlock; | |
7325 | 161 |
162 if (nargin == 2) | |
163 switch (toupper (file)) | |
164 case "EDITOR" | |
165 FUNCTION.EDITOR = state; | |
166 case "HOME" | |
167 if (! isempty (state) && state(1) == "~") | |
10549 | 168 state = [ default_home, state(2:end) ]; |
7325 | 169 endif |
170 FUNCTION.HOME = state; | |
171 case "AUTHOR" | |
172 FUNCTION.AUTHOR = state; | |
173 case "EMAIL" | |
174 FUNCTION.EMAIL = state; | |
175 case "LICENSE" | |
176 FUNCTION.LICENSE = state; | |
177 case "MODE" | |
178 if (strcmp (state, "sync") || strcmp (state, "async")) | |
179 FUNCTION.MODE = state; | |
180 else | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
181 error('edit: expected "edit MODE sync|async"'); |
7325 | 182 endif |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
183 case "EDITINPLACE" |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
184 if (ischar (state)) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
185 if (strcmpi (state, "true")) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
186 state = true; |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
187 elseif (strcmpi (state, "false")) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
188 state = false; |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
189 else |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
190 state = eval (state); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
191 endif |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
192 endif |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
193 FUNCTION.EDITINPLACE = state; |
7325 | 194 case "GET" |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
195 if (isfield (FUNCTION, toupper(state))) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
196 ret = FUNCTION.(toupper (state)); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
197 else |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
198 ret = FUNCTION; |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
199 endif |
7325 | 200 otherwise |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
201 error ('edit: expected "edit EDITOR|HOME|AUTHOR|EMAIL|LICENSE|MODE val"'); |
7325 | 202 endswitch |
203 return | |
204 endif | |
205 | |
206 ## Start the editor without a file if no file is given. | |
207 if (nargin < 1) | |
208 if (exist (FUNCTION.HOME, "dir") == 7 && (isunix () || ! ispc ())) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
209 system (cstrcat ("cd \"", FUNCTION.HOME, "\" ; ", |
10549 | 210 sprintf (FUNCTION.EDITOR, "")), |
211 [], FUNCTION.MODE); | |
7325 | 212 else |
213 system (sprintf (FUNCTION.EDITOR,""), [], FUNCTION.MODE); | |
214 endif | |
215 return; | |
216 endif | |
217 | |
218 ## Check whether the user is trying to edit a builtin of compiled function. | |
219 switch (exist (file)) | |
220 case {3, 5} | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
221 error ("edit: unable to edit a built-in or compiled function"); |
7325 | 222 endswitch |
223 | |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
224 ## Checks for whether the file is |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
225 ## absolute or relative should be handled inside file_in_loadpath. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
226 ## That way, it will be possible to look up files correctly given |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
227 ## partial path information. For example, you should be able to |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
228 ## edit a particular overloaded function by doing any one of |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
229 ## |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
230 ## edit classname/foo |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
231 ## edit classname/foo.m |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
232 ## edit @classname/foo |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
233 ## edit @classname/foo.m |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
234 ## |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
235 ## This functionality is needed for other functions as well (at least |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
236 ## help and type; there may be more). So the place to fix that is in |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
237 ## file_in_loadpath, possibly with some help from the load_path class. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
238 |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
239 ## The code below includes a portion that serves as a place-holder for |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
240 ## the changes suggested above. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
241 |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
242 ## Create list of explicit and implicit file names. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
243 filelist = {file}; |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
244 ## If file has no extension, add file.m and file.cc to the list. |
7325 | 245 idx = rindex (file, "."); |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
246 if (idx == 0) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
247 ## Create the list of files to look for |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
248 filelist = {file}; |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
249 if (isempty (regexp (file, '\.m$'))) |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
250 ## No ".m" at the end of the file, add to the list. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
251 filelist{end+1} = cat (2, file, ".m"); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
252 endif |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
253 if (isempty (regexp (file, '\.cc$'))) |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
254 ## No ".cc" at the end of the file, add to the list. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
255 filelist{end+1} = cat (2, file, ".cc"); |
7325 | 256 endif |
257 endif | |
258 | |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
259 ## If the file includes a path, it may be an overloaded function. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
260 if (! strcmp (file, "@") && index (file, filesep)) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
261 ## No "@" at the beginning of the file, add to the list. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
262 numfiles = numel(filelist); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
263 for n = 1:numfiles |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
264 filelist{n+numfiles} = cat (2, "@", filelist{n}); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
265 endfor |
7325 | 266 endif |
267 | |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
268 ## Search the entire path for the 1st instance of a file in the list. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
269 fileandpath = ""; |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
270 for n = 1:numel(filelist) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
271 filetoedit = file_in_path (path, filelist{n}); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
272 if (! isempty (filetoedit)) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
273 ## The path is explicitly included. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
274 fileandpath = filetoedit; |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
275 break; |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
276 endif |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
277 endfor |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
278 |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
279 if (! isempty (fileandpath)) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
280 ## If the file exists, then edit it. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
281 if (FUNCTION.EDITINPLACE) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
282 ## Edit in place even if it is protected. |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
283 system (sprintf (FUNCTION.EDITOR, cstrcat ("\"", fileandpath, "\"")), |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
284 [], FUNCTION.MODE); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
285 return; |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
286 else |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
287 ## If the file is modifiable in place then edit it, otherwise make |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
288 ## a copy in HOME and then edit it. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
289 fid = fopen (fileandpath, "r+t"); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
290 if (fid < 0) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
291 from = fileandpath; |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
292 fileandpath = cstrcat (FUNCTION.HOME, from (rindex (from, filesep):end)); |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
293 [status, msg] = copyfile (from, fileandpath, 1); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
294 if (status == 0) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
295 error (msg); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
296 endif |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
297 else |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
298 fclose (fid); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
299 endif |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
300 system (sprintf (FUNCTION.EDITOR, cstrcat ("\"", fileandpath, "\"")), |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
301 [], FUNCTION.MODE); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
302 return; |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
303 endif |
7325 | 304 endif |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
305 |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
306 ## If editing a new file that is neither a m-file or an oct-file, |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
307 ## just edit it. |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
308 fileandpath = file; |
7325 | 309 idx = rindex (file, "."); |
310 name = file(1:idx-1); | |
311 ext = file(idx+1:end); | |
312 switch (ext) | |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
313 case {"cc", "m"} |
7325 | 314 0; |
315 otherwise | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
316 system (sprintf (FUNCTION.EDITOR, cstrcat ("\"", fileandpath, "\"")), |
10549 | 317 [], FUNCTION.MODE); |
7325 | 318 return; |
319 endswitch | |
320 | |
321 ## The file doesn't exist in path so create it, put in the function | |
322 ## template and edit it. | |
323 | |
324 ## Guess the email name if it was not given. | |
325 if (isempty (FUNCTION.EMAIL)) | |
326 host = getenv("HOSTNAME"); | |
327 if (isempty (host) && ispc ()) | |
328 host = getenv ("COMPUTERNAME"); | |
329 endif | |
330 if (isempty (host)) | |
331 [status, host] = system ("uname -n"); | |
332 ## trim newline from end of hostname | |
333 if (! isempty (host)) | |
10549 | 334 host = host(1:end-1); |
7325 | 335 endif |
336 endif | |
337 if (isempty (host)) | |
338 FUNCTION.EMAIL = " "; | |
339 else | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
340 FUNCTION.EMAIL = cstrcat ("<", default_user(0), "@", host, ">"); |
7325 | 341 endif |
342 endif | |
343 | |
344 ## Fill in the revision string. | |
345 now = localtime (time); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
346 revs = cstrcat ("Created: ", strftime ("%Y-%m-%d", now)); |
7325 | 347 |
348 ## Fill in the copyright string. | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
349 copyright = cstrcat (strftime ("Copyright (C) %Y ", now), FUNCTION.AUTHOR); |
7325 | 350 |
351 ## Fill in the author tag field. | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
352 author = cstrcat ("Author: ", FUNCTION.AUTHOR, " ", FUNCTION.EMAIL); |
7325 | 353 |
354 ## Fill in the header. | |
355 uclicense = toupper (FUNCTION.LICENSE); | |
356 switch (uclicense) | |
357 case "GPL" | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
358 head = cstrcat (copyright, "\n\n", "\ |
7325 | 359 This program is free software; you can redistribute it and/or modify\n\ |
360 it under the terms of the GNU General Public License as published by\n\ | |
11104 | 361 the Free Software Foundation; either version 3 of the License, or\n\ |
7325 | 362 (at your option) any later version.\n\ |
363 \n\ | |
364 This program is distributed in the hope that it will be useful,\n\ | |
365 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ | |
366 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ | |
367 GNU General Public License for more details.\n\ | |
368 \n\ | |
369 You should have received a copy of the GNU General Public License\n\ | |
7444 | 370 along with Octave; see the file COPYING. If not, see\n\ |
371 <http://www.gnu.org/licenses/>.\ | |
7325 | 372 "); |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
373 tail = cstrcat (author, "\n", revs); |
7325 | 374 |
375 case "BSD" | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
376 head = cstrcat (copyright, "\n\n", "\ |
7325 | 377 This program is free software; redistribution and use in source and\n\ |
378 binary forms, with or without modification, are permitted provided that\n\ | |
379 the following conditions are met:\n\ | |
380 \n\ | |
381 1.Redistributions of source code must retain the above copyright\n\ | |
382 notice, this list of conditions and the following disclaimer.\n\ | |
383 2.Redistributions in binary form must reproduce the above copyright\n\ | |
384 notice, this list of conditions and the following disclaimer in the\n\ | |
385 documentation and/or other materials provided with the distribution.\n\ | |
386 \n\ | |
387 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n\ | |
388 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\ | |
389 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n\ | |
390 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n\ | |
391 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n\ | |
392 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n\ | |
393 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n\ | |
394 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n\ | |
395 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n\ | |
396 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n\ | |
397 SUCH DAMAGE.\ | |
398 "); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
399 tail = cstrcat (author, "\n", revs); |
7325 | 400 |
401 case "PD" | |
402 head = ""; | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
403 tail = cstrcat (author, "\n", revs, "\n\n", |
10549 | 404 "This program is granted to the public domain."); |
7325 | 405 |
406 otherwise | |
407 head = ""; | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
408 tail = cstrcat (copyright, "\n\n", FUNCTION.LICENSE, "\n", |
10549 | 409 author, "\n", revs); |
7325 | 410 endswitch |
411 | |
412 ## Generate the function template. | |
413 exists = exist (name); | |
414 switch (ext) | |
415 case {"cc", "C", "cpp"} | |
416 if (isempty (head)) | |
10549 | 417 comment = cstrcat ("/*\n", tail, "\n\n*/\n\n"); |
7325 | 418 else |
10549 | 419 comment = cstrcat ("/*\n", head, "\n\n", tail, "\n\n*/\n\n"); |
7325 | 420 endif |
421 ## If we are shadowing an m-file, paste the code for the m-file. | |
422 if (any (exists == [2, 103])) | |
10549 | 423 code = cstrcat ("\\ ", strrep (type (name), "\n", "\n// ")); |
7325 | 424 else |
10549 | 425 code = " "; |
7325 | 426 endif |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
427 body = cstrcat ("#include <octave/oct.h>\n\n", |
7325 | 428 "DEFUN_DLD(", name, ",args,nargout,\"\\\n", |
10549 | 429 name, "\\n\\\n\")\n{\n", |
430 " octave_value_list retval;\n", | |
431 " int nargin = args.length();\n\n", | |
432 code, "\n return retval;\n}\n"); | |
7325 | 433 |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
434 text = cstrcat (comment, body); |
7325 | 435 case "m" |
436 ## If we are editing a function defined on the fly, paste the | |
437 ## code. | |
438 if (any (exists == [2, 103])) | |
10549 | 439 body = type (name); |
7325 | 440 else |
10549 | 441 body = cstrcat ("function [ ret ] = ", name, " ()\n\nendfunction\n"); |
7325 | 442 endif |
443 if (isempty (head)) | |
10549 | 444 comment = cstrcat ("## ", name, "\n\n", |
445 "## ", strrep (tail, "\n", "\n## "), "\n\n"); | |
7325 | 446 else |
10549 | 447 comment = cstrcat ("## ", strrep(head,"\n","\n## "), "\n\n", ... |
448 "## ", name, "\n\n", ... | |
449 "## ", strrep (tail, "\n", "\n## "), "\n\n"); | |
7325 | 450 endif |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
451 text = cstrcat (comment, body); |
7325 | 452 endswitch |
453 | |
454 ## Write the initial file (if there is anything to write) | |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
455 fid = fopen (fileandpath, "wt"); |
7325 | 456 if (fid < 0) |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
457 error ("edit: could not create %s", fileandpath); |
7325 | 458 endif |
459 fputs (fid, text); | |
460 fclose (fid); | |
461 | |
462 ## Finally we are ready to edit it! | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
463 system (sprintf (FUNCTION.EDITOR, cstrcat ("\"", fileandpath, "\"")), |
10549 | 464 [], FUNCTION.MODE); |
7325 | 465 |
466 endfunction | |
467 | |
468 function ret = default_home () | |
469 | |
470 ret = getenv ("HOME"); | |
471 if (isempty (ret)) | |
472 ret = glob ("~"); | |
473 if (! isempty (ret)) | |
474 ret = ret{1}; | |
475 else | |
476 ret = ""; | |
477 endif | |
478 endif | |
479 | |
480 endfunction | |
481 | |
7434 | 482 ## Return the name associated with the current user ID. |
7325 | 483 ## |
7434 | 484 ## If LONG_FORM is 1, return the full name. This will be the |
485 ## default author. Otherwise return the login name. | |
7325 | 486 ## login@host will be the default email address. |
487 | |
488 function ret = default_user (long_form) | |
489 | |
490 ent = getpwuid (getuid); | |
491 if (! isstruct (ent)) | |
492 ret = getenv ("USER"); | |
7330 | 493 if (isempty (ret)) |
7325 | 494 ret = getenv ("USERNAME"); |
495 endif | |
496 elseif (long_form) | |
497 ret = ent.gecos; | |
7434 | 498 pos = strfind (ret, ","); |
499 if (! isempty (pos)) | |
500 ret = ret(1:pos-1); | |
501 endif | |
7325 | 502 else |
503 ret = ent.name; | |
504 endif | |
505 | |
506 endfunction | |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
507 |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
508 %!test |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
509 %! s.editor = edit ("get", "editor"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
510 %! s.home = edit ("get", "home"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
511 %! s.author = edit ("get", "author"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
512 %! s.email = edit ("get", "email"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
513 %! s.license = edit ("get", "license"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
514 %! s.editinplace = edit ("get", "editinplace"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
515 %! s.mode = edit ("get", "mode"); |
7502
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
516 %! edit editor none |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
517 %! edit home none |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
518 %! edit author none |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
519 %! edit email none |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
520 %! edit license none |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
521 %! edit ("editinplace", !s.editinplace) |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
522 %! if (s.mode(1) == "a") |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
523 %! edit mode sync |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
524 %! else |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
525 %! edit mode async |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
526 %! endif |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
527 %! edit ("editor", s.editor); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
528 %! edit ("home", s.home); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
529 %! edit ("author", s.author); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
530 %! edit ("email", s.email); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
531 %! edit ("license", s.license); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
532 %! edit ("editinplace", s.editinplace); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
533 %! edit ("mode", s.mode); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
534 %! assert (edit ("get", "editor"), s.editor); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
535 %! assert (edit ("get", "home"), s.home); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
536 %! assert (edit ("get", "author"), s.author); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
537 %! assert (edit ("get", "email"), s.email); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
538 %! assert (edit ("get", "license"), s.license); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
539 %! assert (edit ("get", "editinplace"), s.editinplace); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
540 %! assert (edit ("get", "mode"), s.mode); |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
541 |