File: edit.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (77 lines) | stat: -rw-r--r-- 1,757 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function [res]=edit(macroname,editor)
// macroname : character string giving a macroname 
//
// Copyright INRIA
default_editor="/usr/bin/sensible-editor"
[lhs,rhs]=argn(0)
//
finded=%f;tmp=%f

if getenv('WIN32','NO')=='OK' & getenv('COMPILER','NO')=='VC++' then 
	write(%io(2),'edit: Not implemented on win32');
	res=evstr(macroname);
	return;
end

if rhs>=1 then // macroname is given
  errcatch(25,'continue','nomessage')
  libr=whereis(macroname)
  errcatch(-1)
  if iserror(25) then
    error(macroname+'is a uneditable hard coded function,')
    errclear(25)
  end
  if libr<>[] then // macroname is the name of a defined function
    w=string(evstr(libr));w=w(1)
    if part(w,1:4)=='SCI/' then //substitute SCI/ with the scilab path
      w=SCI+'/'+part(w,5:length(w))
    end
    //if file is not writable create a copy in TMPDIR
    rep=unix_g("if [ -w '+w+macroname+'.sci '+' ]; then echo ok ;else echo nok; fi")
    if part(rep,1:2)=='ok' then
      fname=w+macroname+'.sci'
    else
      fname=TMPDIR+'/'+macroname+'.sci'
      unix_s("cp "+w+macroname+'.sci '+fname+'; chmod +w '+fname )
      tmp=%t
    end
    finded=%t
  end  
else //no macroname specified
  macroname='untitled', 
  finded=%f
end

if ~finded then // macroname is the name of an undefined function
  comment='/'+'/'
  fname=TMPDIR+'/'+macroname+'.sci'
  head='function []='+macroname+'()'
  errcatch(-1,'continue','nomessage')
  write(fname,head)
  errclear(-1)
  errcatch(-1)
  tmp=%t
end
// call the editor with the filename
if rhs<=1, editor =default_editor ;end
unix_s(editor+' '+fname);

//load the macro in scilab
getf(fname,'c');
if tmp then write(%io(2),'modified file may be found in '+fname),end 
//return the loaded variable
res=evstr(macroname);