Functions | |
if (nargin==2) switch(toupper(file)) case"EDITOR"FUNCTION.EDITOR | |
case HOME | if (!isempty(state)&&state(1)=="~") state |
case MODE | if (strcmp(state,"sync")||strcmp(state,"async")) FUNCTION.MODE |
else | error ('expected"edit MODE sync|async"') |
endif case EDITINPLACE | if (ischar(state)) if(strcmpi(state |
elseif (strcmpi(state,"false")) state | |
case GET | if (isfield(FUNCTION, toupper(state))) ret |
endif otherwise | error ("expected \"edit EDITOR|HOME|AUTHOR|EMAIL|LICENSE|MODE val\"") |
endswitch return endif | if (nargin< 1) if(exist(FUNCTION.HOME |
else | system (sprintf(FUNCTION.EDITOR,""),[], FUNCTION.MODE) |
endif | switch (exist(file)) case |
error ("unable to edit a built-in or compiled function") | |
if (idx==0) filelist | |
if (isempty(regexp(file,"\\.m$"))) filelist | |
endif | if (isempty(regexp(file,"\\.cc$"))) filelist |
endif endif | if (!strcmp(file,"@")&&index(file, filesep)) numfiles |
if (!isempty(filetoedit)) fileandpath | |
endif endfor | if (!isempty(fileandpath)) if(FUNCTION.EDITINPLACE) system(sprintf(FUNCTION.EDITOR |
endif endfor | cstrcat ("\"", fileandpath,"\"")) |
if (status==0) error(msg) | |
endif else | fclose (fid) |
endif | system (sprintf(FUNCTION.EDITOR, cstrcat("\"", fileandpath,"\"")),[], FUNCTION.MODE) |
switch (ext) case | |
endswitch | if (isempty(FUNCTION.EMAIL)) host |
if (isempty(host)&&ispc()) host | |
endif | if (isempty(host))[status |
if (!isempty(host)) host | |
switch (uclicense) case"GPL"head | |
if (isempty(head)) comment | |
endif | if (any(exists==[2, 103])) code |
if (isempty(ret)) ret | |
if (!isempty(ret)) ret | |
if (!isstruct(ent)) ret | |
endif | elseif (long_form) ret |
if (!isempty(pos)) ret | |
!edit editor none!edit home none!edit author none!edit email none!edit license none | !edit ("editinplace",!s.editinplace)%!if(s.mode(1) |
!edit ("home", s.home) | |
!edit ("author", s.author) | |
!edit ("email", s.email) | |
!edit ("license", s.license) | |
!edit ("editinplace", s.editinplace) | |
!edit ("mode", s.mode) | |
!assert (edit("get","editor"), s.editor) | |
!assert (edit("get","home"), s.home) | |
!assert (edit("get","author"), s.author) | |
!assert (edit("get","email"), s.email) | |
!assert (edit("get","license"), s.license) | |
!assert (edit("get","editinplace"), s.editinplace) | |
!assert (edit("get","mode"), s.mode) | |
Variables | |
function | ret |
mlock | |
endif FUNCTION | HOME = state |
case AUTHOR FUNCTION | AUTHOR = state |
case EMAIL FUNCTION | EMAIL = state |
case LICENSE FUNCTION | LICENSE = state |
endif case EDITINPLACE true | state = true |
endif endif FUNCTION | EDITINPLACE = state |
endswitch return endif | dir |
endif | return |
endswitch | filelist = {file} |
idx = rindex (file, ".") | |
for | n |
endfor endif | fileandpath = "" |
break | |
endif endfor FUNCTION | MODE |
else | fid = fopen (fileandpath, "r+t") |
name = file(1:idx-1) | |
ext = file(idx+1:end) | |
endif | host = system ("uname -n") |
endif endif | now = localtime (time) |
revs = cstrcat ("Created: ", strftime ("%Y-%m-%d", now)) | |
copyright = cstrcat (strftime ("Copyright (C) %Y ", now), FUNCTION.AUTHOR) | |
author = cstrcat ("Author: ", FUNCTION.AUTHOR, " ", FUNCTION.EMAIL) | |
uclicense = toupper (FUNCTION.LICENSE) | |
tail = cstrcat (author, "\n", revs) | |
case BSD | head |
endswitch | exists = exist (name) |
else | comment = cstrcat ("/*\n", head, "\n\n", tail, "\n\n*/\n\n") |
else | code = " " |
endif | body |
text = cstrcat (comment, body) | |
pos = strfind (ret, ",") | |
endif endfunction!test!s | editor = edit ("get", "editor") |
!s | home = edit ("get", "home") |
!s | email = edit ("get", "email") |
!s | license = edit ("get", "license") |
!s | editinplace = edit ("get", "editinplace") |
!s | mode = edit ("get", "mode") |
!assert | ( | edit("get","mode") | , | |
s. | mode | |||
) |
!assert | ( | edit("get","editinplace") | , | |
s. | editinplace | |||
) |
!assert | ( | edit("get","license") | , | |
s. | license | |||
) |
!assert | ( | edit("get","email") | , | |
s. | ||||
) |
!assert | ( | edit("get","author") | , | |
s. | author | |||
) |
!assert | ( | edit("get","home") | , | |
s. | home | |||
) |
!assert | ( | edit("get","editor") | , | |
s. | editor | |||
) |
!edit | ( | "mode" | , | |
s. | mode | |||
) |
!edit | ( | "editinplace" | , | |
s. | editinplace | |||
) |
!edit | ( | "license" | , | |
s. | license | |||
) |
!edit | ( | "email" | , | |
s. | ||||
) |
!edit | ( | "author" | , | |
s. | author | |||
) |
!edit | ( | "home" | , | |
s. | home | |||
) |
! edit editor none ! edit home none ! edit author none ! edit email none ! edit license none !edit | ( | "editinplace" | , | |
!s. | editinplace | |||
) |
endif endfor cstrcat | ( | "\"" | , | |
fileandpath | , | |||
"\"" | ||||
) |
endif elseif | ( | long_form | ) |
elseif | ( | strcmpi(state,"false") | ) |
if | ( | ! | isemptypos | ) |
if | ( | ! | isstructent | ) |
if | ( | ! | isemptyret | ) |
if | ( | isempty(ret) | ) |
if | ( | isempty(head) | ) |
if | ( | ! | isemptyhost | ) |
if | ( | isempty(host)&&ispc() | ) |
endswitch if | ( | isempty(FUNCTION.EMAIL) | ) |
if | ( | status | = =0 |
) |
if | ( | ! | isemptyfiletoedit | ) |
if | ( | isempty(regexp(file,"\\.m$")) | ) |
if | ( | idx | = =0 |
) |
case GET if | ( | isfield(FUNCTION, toupper(state)) | ) |
endif case EDITINPLACE if | ( | ischar(state) | ) |
case HOME if | ( | ! | isemptystate)&&state(1 = ="~" |
) |
if | ( | nargin | = =2 |
) |
switch | ( | uclicense | ) |
switch | ( | ext | ) |
otherwise system | ( | sprintf(FUNCTION.EDITOR, cstrcat("\"", fileandpath,"\"")) | , | |
FUNCTION. | MODE | |||
) |
else system | ( | sprintf(FUNCTION.EDITOR,"") | , | |
FUNCTION. | MODE | |||
) |
s author = cstrcat ("Author: ", FUNCTION.AUTHOR, " ", FUNCTION.EMAIL) |
break |
copyright = cstrcat (strftime ("Copyright (C) %Y ", now), FUNCTION.AUTHOR) |
! s editinplace = edit ("get", "editinplace") |
endif endif FUNCTION EDITINPLACE = state |
endif endfunction !test ! s editor = edit ("get", "editor") |
ext = file(idx+1:end) |
endswitch fid = fopen (fileandpath, "r+t") |
endif endif fileandpath = "" |
otherwise head |
Initial value:
cstrcat (copyright, "\n\n", "\ This program is free software; redistribution and use in source and\n\ binary forms, with or without modification, are permitted provided that\n\ the following conditions are met:\n\ \n\ 1.Redistributions of source code must retain the above copyright\n\ notice, this list of conditions and the following disclaimer.\n\ 2.Redistributions in binary form must reproduce the above copyright\n\ notice, this list of conditions and the following disclaimer in the\n\ documentation and/or other materials provided with the distribution.\n\ \n\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n\ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n\ SUCH DAMAGE.\ ")
idx = rindex (file, ".") |
mlock |
! s mode = edit ("get", "mode") |
pos = strfind (ret, ",") |
return |
revs = cstrcat ("Created: ", strftime ("%Y-%m-%d", now)) |
uclicense = toupper (FUNCTION.LICENSE) |