Mercurial > hg > octave-nkf
annotate scripts/miscellaneous/edit.m @ 8795:bb38a86efa1b
improve documentation for edit.m
author | Ivan Sutoris <ivan.sutoris@gmail.com> |
---|---|
date | Wed, 18 Feb 2009 01:31:14 -0500 |
parents | 5dd06f19e9be |
children | eb63fbe60fab |
rev | line source |
---|---|
7325 | 1 ## Copyright (C) 2001, 2007 Paul Kienzle |
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 {Command} edit @var{name} | |
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 | |
33 ## @code{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 |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
35 ## variant, ending with ".m", will be considered. If still no 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
|
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 | |
41 ## not in an m-file, then an m-file will be created in @code{HOME} | |
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 | |
47 ## @file{.cc} file in @code{HOME}. If @var{name} happens to be an | |
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 | |
52 ## If @var{name.ext} is on your path then it will be editted, otherwise | |
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 | |
55 ## @code{HOME} before editing. | |
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 |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
67 ## containing all fields and values. Thus, @code{edit get all} returns |
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 | |
74 ## Octave's @code{EDITOR} built-in function, which comes from | |
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}. | |
80 ## @item "xedit %s &" | |
81 ## pop up simple X11 editor in a separate window | |
82 ## @item "gnudoit -q \"(find-file \\\"%s\\\")\"" | |
83 ## Send it to current Emacs; must have @code{(gnuserv-start)} in @file{.emacs}. | |
84 ## @end table | |
85 ## | |
8795
bb38a86efa1b
improve documentation for edit.m
Ivan Sutoris <ivan.sutoris@gmail.com>
parents:
8746
diff
changeset
|
86 ## 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
|
87 ## |
7325 | 88 ## On cygwin, you will need to convert the cygwin path to a windows |
89 ## path if you are using a native Windows editor. For example | |
90 ## @example | |
91 ## '"C:/Program Files/Good Editor/Editor.exe" "$(cygpath -wa %s)"' | |
92 ## @end example | |
93 ## | |
94 ## @item home | |
95 ## This is the location of user local m-files. Be be sure it is in your | |
96 ## path. The default is @file{~/octave}. | |
97 ## | |
98 ## @item author | |
99 ## This is the name to put after the "## Author:" field of new functions. | |
100 ## By default it guesses from the @code{gecos} field of password database. | |
101 ## | |
102 ## @item email | |
103 ## This is the e-mail address to list after the name in the author field. | |
104 ## By default it guesses @code{<$LOGNAME@@$HOSTNAME>}, and if @code{$HOSTNAME} | |
105 ## is not defined it uses @code{uname -n}. You probably want to override this. | |
106 ## Be sure to use @code{<user@@host>} as your format. | |
107 ## | |
108 ## @item license | |
109 ## @table @samp | |
110 ## @item gpl | |
111 ## GNU General Public License (default). | |
112 ## @item bsd | |
113 ## BSD-style license without advertising clause. | |
114 ## @item pd | |
115 ## Public domain. | |
116 ## @item "text" | |
117 ## Your own default copyright and license. | |
118 ## @end table | |
119 ## | |
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
|
120 ## 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
|
121 ## 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
|
122 ## |
7325 | 123 ## @item mode |
124 ## 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
|
125 ## (editor is started in the background and Octave continues) or sync mode |
bb38a86efa1b
improve documentation for edit.m
Ivan Sutoris <ivan.sutoris@gmail.com>
parents:
8746
diff
changeset
|
126 ## (Octave waits until the editor exits). Set it to "async" to start the editor |
bb38a86efa1b
improve documentation for edit.m
Ivan Sutoris <ivan.sutoris@gmail.com>
parents:
8746
diff
changeset
|
127 ## 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
|
128 ## |
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 ## @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
|
130 ## Determines whether files should be edited in place, without regard 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
|
131 ## whether they are modifiable or not. The default is @code{false}. |
7325 | 132 ## @end table |
133 ## @end deftypefn | |
134 | |
135 ## Author: Paul Kienzle <pkienzle@users.sf.net> | |
136 | |
137 ## Original version by Paul Kienzle distributed as free software in the | |
138 ## public domain. | |
139 | |
140 function ret = edit (file, state) | |
141 | |
142 ## Pick up globals or default them. | |
143 | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
144 persistent FUNCTION = struct ("EDITOR", cstrcat (EDITOR (), " %s"), |
7325 | 145 "HOME", fullfile (default_home, "octave"), |
146 "AUTHOR", default_user(1), | |
147 "EMAIL", [], | |
148 "LICENSE", "GPL", | |
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
|
149 "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
|
150 "EDITINPLACE", false); |
7325 | 151 |
8506 | 152 ## Make sure the state variables survive "clear functions". |
153 mlock; | |
7325 | 154 |
155 if (nargin == 2) | |
156 switch (toupper (file)) | |
157 case "EDITOR" | |
158 FUNCTION.EDITOR = state; | |
159 case "HOME" | |
160 if (! isempty (state) && state(1) == "~") | |
161 state = [ default_home, state(2:end) ]; | |
162 endif | |
163 FUNCTION.HOME = state; | |
164 case "AUTHOR" | |
165 FUNCTION.AUTHOR = state; | |
166 case "EMAIL" | |
167 FUNCTION.EMAIL = state; | |
168 case "LICENSE" | |
169 FUNCTION.LICENSE = state; | |
170 case "MODE" | |
171 if (strcmp (state, "sync") || strcmp (state, "async")) | |
172 FUNCTION.MODE = state; | |
173 else | |
174 error('expected "edit MODE sync|async"'); | |
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 FUNCTION.EDITINPLACE = state; |
7325 | 187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 endif |
7325 | 193 otherwise |
194 error ("expected \"edit EDITOR|HOME|AUTHOR|EMAIL|LICENSE|MODE val\""); | |
195 endswitch | |
196 return | |
197 endif | |
198 | |
199 ## Start the editor without a file if no file is given. | |
200 if (nargin < 1) | |
201 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
|
202 system (cstrcat ("cd \"", FUNCTION.HOME, "\" ; ", |
7325 | 203 sprintf (FUNCTION.EDITOR, "")), |
204 [], FUNCTION.MODE); | |
205 else | |
206 system (sprintf (FUNCTION.EDITOR,""), [], FUNCTION.MODE); | |
207 endif | |
208 return; | |
209 endif | |
210 | |
211 ## Check whether the user is trying to edit a builtin of compiled function. | |
212 switch (exist (file)) | |
213 case {3, 5} | |
214 error ("unable to edit a built-in or compiled function"); | |
215 endswitch | |
216 | |
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
|
217 ## 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
|
218 ## 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
|
219 ## 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
|
220 ## 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
|
221 ## 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
|
222 ## |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
223 ## 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
|
224 ## 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
|
225 ## 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
|
226 ## 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
|
227 ## |
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 ## 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
|
229 ## 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
|
230 ## 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
|
231 |
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 ## 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
|
233 ## 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
|
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 ## 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
|
236 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
|
237 ## If file has no extension, add file.m and file.cc to the list. |
7325 | 238 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
|
239 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
|
240 ## 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
|
241 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
|
242 if (isempty (regexp (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
|
243 ## 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
|
244 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
|
245 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
|
246 if (isempty (regexp (file, "\\.cc$"))) |
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 ## 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
|
248 filelist{end+1} = cat (2, file, ".cc"); |
7325 | 249 endif |
250 endif | |
251 | |
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
|
252 ## 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
|
253 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
|
254 ## 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
|
255 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
|
256 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
|
257 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
|
258 endfor |
7325 | 259 endif |
260 | |
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
|
261 ## 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 ## 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 |
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 (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
|
273 ## 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
|
274 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
|
275 ## 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
|
276 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
|
277 [], 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
|
278 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
|
279 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
|
280 ## 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
|
281 ## 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
|
282 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
|
283 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
|
284 from = fileandpath; |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
285 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
|
286 [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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 endif |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
293 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
|
294 [], 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
|
295 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
|
296 endif |
7325 | 297 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
|
298 |
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 ## 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
|
300 ## 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
|
301 fileandpath = file; |
7325 | 302 idx = rindex (file, "."); |
303 name = file(1:idx-1); | |
304 ext = file(idx+1:end); | |
305 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
|
306 case {"cc", "m"} |
7325 | 307 0; |
308 otherwise | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
309 system (sprintf (FUNCTION.EDITOR, cstrcat ("\"", fileandpath, "\"")), |
7325 | 310 [], FUNCTION.MODE); |
311 return; | |
312 endswitch | |
313 | |
314 ## The file doesn't exist in path so create it, put in the function | |
315 ## template and edit it. | |
316 | |
317 ## Guess the email name if it was not given. | |
318 if (isempty (FUNCTION.EMAIL)) | |
319 host = getenv("HOSTNAME"); | |
320 if (isempty (host) && ispc ()) | |
321 host = getenv ("COMPUTERNAME"); | |
322 endif | |
323 if (isempty (host)) | |
324 [status, host] = system ("uname -n"); | |
325 ## trim newline from end of hostname | |
326 if (! isempty (host)) | |
327 host = host(1:end-1); | |
328 endif | |
329 endif | |
330 if (isempty (host)) | |
331 FUNCTION.EMAIL = " "; | |
332 else | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
333 FUNCTION.EMAIL = cstrcat ("<", default_user(0), "@", host, ">"); |
7325 | 334 endif |
335 endif | |
336 | |
337 ## Fill in the revision string. | |
338 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
|
339 revs = cstrcat ("Created: ", strftime ("%Y-%m-%d", now)); |
7325 | 340 |
341 ## 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
|
342 copyright = cstrcat (strftime ("Copyright (C) %Y ", now), FUNCTION.AUTHOR); |
7325 | 343 |
344 ## 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
|
345 author = cstrcat ("Author: ", FUNCTION.AUTHOR, " ", FUNCTION.EMAIL); |
7325 | 346 |
347 ## Fill in the header. | |
348 uclicense = toupper (FUNCTION.LICENSE); | |
349 switch (uclicense) | |
350 case "GPL" | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
351 head = cstrcat (copyright, "\n\n", "\ |
7325 | 352 This program is free software; you can redistribute it and/or modify\n\ |
353 it under the terms of the GNU General Public License as published by\n\ | |
354 the Free Software Foundation; either version 2 of the License, or\n\ | |
355 (at your option) any later version.\n\ | |
356 \n\ | |
357 This program is distributed in the hope that it will be useful,\n\ | |
358 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ | |
359 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ | |
360 GNU General Public License for more details.\n\ | |
361 \n\ | |
362 You should have received a copy of the GNU General Public License\n\ | |
7444 | 363 along with Octave; see the file COPYING. If not, see\n\ |
364 <http://www.gnu.org/licenses/>.\ | |
7325 | 365 "); |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
366 tail = cstrcat (author, "\n", revs); |
7325 | 367 |
368 case "BSD" | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
369 head = cstrcat (copyright, "\n\n", "\ |
7325 | 370 This program is free software; redistribution and use in source and\n\ |
371 binary forms, with or without modification, are permitted provided that\n\ | |
372 the following conditions are met:\n\ | |
373 \n\ | |
374 1.Redistributions of source code must retain the above copyright\n\ | |
375 notice, this list of conditions and the following disclaimer.\n\ | |
376 2.Redistributions in binary form must reproduce the above copyright\n\ | |
377 notice, this list of conditions and the following disclaimer in the\n\ | |
378 documentation and/or other materials provided with the distribution.\n\ | |
379 \n\ | |
380 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n\ | |
381 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\ | |
382 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n\ | |
383 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n\ | |
384 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n\ | |
385 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n\ | |
386 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n\ | |
387 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n\ | |
388 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n\ | |
389 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n\ | |
390 SUCH DAMAGE.\ | |
391 "); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
392 tail = cstrcat (author, "\n", revs); |
7325 | 393 |
394 case "PD" | |
395 head = ""; | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
396 tail = cstrcat (author, "\n", revs, "\n\n", |
7434 | 397 "This program is granted to the public domain."); |
7325 | 398 |
399 otherwise | |
400 head = ""; | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
401 tail = cstrcat (copyright, "\n\n", FUNCTION.LICENSE, "\n", |
7434 | 402 author, "\n", revs); |
7325 | 403 endswitch |
404 | |
405 ## Generate the function template. | |
406 exists = exist (name); | |
407 switch (ext) | |
408 case {"cc", "C", "cpp"} | |
409 if (isempty (head)) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
410 comment = cstrcat ("/*\n", tail, "\n\n*/\n\n"); |
7325 | 411 else |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
412 comment = cstrcat ("/*\n", head, "\n\n", tail, "\n\n*/\n\n"); |
7325 | 413 endif |
414 ## If we are shadowing an m-file, paste the code for the m-file. | |
415 if (any (exists == [2, 103])) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
416 code = cstrcat ("\\ ", strrep (type (name), "\n", "\n// ")); |
7325 | 417 else |
418 code = " "; | |
419 endif | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
420 body = cstrcat ("#include <octave/oct.h>\n\n", |
7325 | 421 "DEFUN_DLD(", name, ",args,nargout,\"\\\n", |
422 name, "\\n\\\n\")\n{\n", | |
423 " octave_value_list retval;\n", | |
424 " int nargin = args.length();\n\n", | |
425 code, "\n return retval;\n}\n"); | |
426 | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
427 text = cstrcat (comment, body); |
7325 | 428 case "m" |
429 ## If we are editing a function defined on the fly, paste the | |
430 ## code. | |
431 if (any (exists == [2, 103])) | |
432 body = type (name); | |
433 else | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
434 body = cstrcat ("function [ ret ] = ", name, " ()\n\nendfunction\n"); |
7325 | 435 endif |
436 if (isempty (head)) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
437 comment = cstrcat ("## ", name, "\n\n", |
7325 | 438 "## ", strrep (tail, "\n", "\n## "), "\n\n"); |
439 else | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
440 comment = cstrcat ("## ", strrep(head,"\n","\n## "), "\n\n", ... |
7325 | 441 "## ", name, "\n\n", ... |
442 "## ", strrep (tail, "\n", "\n## "), "\n\n"); | |
443 endif | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
444 text = cstrcat (comment, body); |
7325 | 445 endswitch |
446 | |
447 ## 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
|
448 fid = fopen (fileandpath, "wt"); |
7325 | 449 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
|
450 error ("edit: could not create %s", fileandpath); |
7325 | 451 endif |
452 fputs (fid, text); | |
453 fclose (fid); | |
454 | |
455 ## 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
|
456 system (sprintf (FUNCTION.EDITOR, cstrcat ("\"", fileandpath, "\"")), |
7325 | 457 [], FUNCTION.MODE); |
458 | |
459 endfunction | |
460 | |
461 function ret = default_home () | |
462 | |
463 ret = getenv ("HOME"); | |
464 if (isempty (ret)) | |
465 ret = glob ("~"); | |
466 if (! isempty (ret)) | |
467 ret = ret{1}; | |
468 else | |
469 ret = ""; | |
470 endif | |
471 endif | |
472 | |
473 endfunction | |
474 | |
7434 | 475 ## Return the name associated with the current user ID. |
7325 | 476 ## |
7434 | 477 ## If LONG_FORM is 1, return the full name. This will be the |
478 ## default author. Otherwise return the login name. | |
7325 | 479 ## login@host will be the default email address. |
480 | |
481 function ret = default_user (long_form) | |
482 | |
483 ent = getpwuid (getuid); | |
484 if (! isstruct (ent)) | |
485 ret = getenv ("USER"); | |
7330 | 486 if (isempty (ret)) |
7325 | 487 ret = getenv ("USERNAME"); |
488 endif | |
489 elseif (long_form) | |
490 ret = ent.gecos; | |
7434 | 491 pos = strfind (ret, ","); |
492 if (! isempty (pos)) | |
493 ret = ret(1:pos-1); | |
494 endif | |
7325 | 495 else |
496 ret = ent.name; | |
497 endif | |
498 | |
499 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
|
500 |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
501 %!test |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
502 %! s.editor = edit ("get", "editor"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
503 %! s.home = edit ("get", "home"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
504 %! s.author = edit ("get", "author"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
505 %! s.email = edit ("get", "email"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
506 %! s.license = edit ("get", "license"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
507 %! s.editinplace = edit ("get", "editinplace"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
508 %! 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
|
509 %! 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
|
510 %! 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
|
511 %! 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
|
512 %! 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
|
513 %! 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
|
514 %! 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
|
515 %! 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
|
516 %! 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
|
517 %! 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
|
518 %! 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
|
519 %! 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
|
520 %! 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
|
521 %! 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
|
522 %! 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
|
523 %! 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
|
524 %! 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
|
525 %! 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
|
526 %! 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
|
527 %! 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
|
528 %! 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
|
529 %! 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
|
530 %! 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
|
531 %! 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
|
532 %! 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
|
533 %! 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
|
534 |