NB. built from project: ~Source\main\jade\jade
NB. script load
NB.
NB. FRET           J fret
NB. LOADED         loaded files
NB. PUBLIC         public scripts
NB. DISPLAYLOAD    if display scripts as they are loaded
NB.
NB. load           load script file
NB. loads          load scripts
NB. require        load script file if not already loaded
NB.
NB. utilities:
NB. exist          if file exists (unsecure mode)
NB. fullname       convert file/directory to full pathname
NB.
NB. plus "z" verbs: load, loadd, require
NB.
NB. this script is written to jadecon.ijs


cocurrent 'j'

LOADED=: ''
PUBLIC=: i. 0 2
TARGET=: i.0 2
USERFOLDERS=: i. 0 2

deb=: #~ (+. 1: |. (> </\))@(' '&~:)
extijs=: , ((0: < #) *. [: -. '.'"_ e. ]) # '.ijs'"_
fexist=: 1:@(1!:4)@boxopen :: 0:
cutnames=: 3 : 0
if. LF e. y. do.
  txt=. y., LF
  nms=. (txt = LF) <;._2 txt
else.
  txt=. y., ' '
  msk=. txt = '"'
  com=. (txt = ' ') > ~: /\ msk
  msk=. (msk *. ~:/\msk) < msk <: 1 |. msk
  nms=. (msk # com) <;._2 msk # txt
end.
nms -. a:
)
fullname=: 3 : 0
p=. PATHSEP_j_
d=. jpath y.
if. </ d i. ':',p do.
elseif. (2{.d) -: 2#p do.
elseif. p ~: 1{.d do.
  jcwdpath d
elseif. IFWIN32 do.
  (2{.jcwdpath''),d
end.
)
buildpublic=: 3 : 0
dat=. deb toJ y.
dat=. a: -.~ <;._2 dat, LF
ndx=. dat i. &> ' '
short=. ndx {.each dat
long=. ndx }. each dat
long=. extijs@jhostpath@deb each long
msk=. (<'system',PATHSEP) = 7 {. each long
long=. (msk{'';'~') ,each long
PUBLIC=: sort ~. PUBLIC,~ short,.long
empty''
)
3 : 0''
if. 0=9!:24'' do.
  exist=: fexist
else.
  exist=: 0:
end.
1
)
getscripts=: 3 : 0
if. 0=#y=. y. do. '' return. end.
if. 0=L.y do.
  if. fexist y do.
    y=. <y
  else.
    y=. cutnames y
  end.
end.
if. 0=#y do. '' return. end.
ndx=. ({."1 PUBLIC) i. y
ind=. I. ndx < # PUBLIC
y=. ((ind { ndx) { 1 {"1 PUBLIC) ind } y
fullname each jpath each y
)
getpath=: ([: +./\. =&PATHSEP_j_) # ]
gettarget=: 3 : 0
p=. getpath each y.
rem=. jpath '~system\'
msk=. -. (rem"_ -: (#rem)&{.) &> p
if. 1 e. msk do.
  p=. msk # p
  ndx=. ({."1 TARGET) i. p
  if. 1 e. b=. ndx = #TARGET do.
    TARGET=: TARGET, gettargetlocale ~. b#p
    ndx=. ({."1 TARGET) i. p
  end.
  msk #^:_1 {:"1 ndx { TARGET
else.
  (#y.)#a:
end.
)
gettargetlocale=: 3 : 0
r=. ''
for_dir. y. do.
  dir=. >dir
  p=. 1!:0 <dir,'*.ijp'
  if. 0 e. #p do.
    r=. r,a:
  else.
    dat=. 1!:1 <dir,0 pick ,p
    dat=. (14 + ('TARGETLOCALE=:' E. dat) i. 1) }. dat
    r=. r, <". (<. / dat i. CRLF) {. dat
  end.
end.
y. ,. r
)
load_z_=: 3 : 0
0 load y.
:
fls=. getscripts_j_ y.
fn=. ('script',x.#'d')~
for_fl. fls do.
  if. DISPLAYLOAD_j_ do. smoutput > fl end.
  fn fl
  LOADED_j_=: ~. LOADED_j_,fl
end.
empty''
)

loadd_z_=: 1&load
require_z_=: 3 : 0
fls=. LOADED_j_ -.~ getscripts_j_ y.
if. # fls do. load fls else. empty'' end.
)

jpath=: 3 : 0
nam=. y.
if. '~' = {. nam do.
  fld=. SYSTEMFOLDERS, USERFOLDERS
  ind=. <./ nam i. '/\'
  tag=. }. ind {. nam
  par=. '.' = {. tag
  if. par do.
    len=. ('.' = tag) i. 0
    tag=. len }. tag
  end.
  ndx=. ({."1 fld) i. <tag
  if. ndx < # fld do.
    bal=. ind }. nam
    pfx=. 1 pick ndx { fld
    if. par do.
      pfx=. ((#pfx) | (+/\. pfx e. '/\') i: len) {. pfx
    end.
    nam=. pfx,bal
  end.
end.
jhostpath nam
)

jpath_z_=: jpath_j_

INPUTLOGFILE=: jpath '~config\input.log'

dltb=: #~ +./\@(-.@e.&(' ',179{a.)) *. +./\.@(~:&' ')
getinputlog=: 3 : 0
log=. wd 'sminputlog'
log=. < @ dltb ;._2 log
log=. log #~ (1: e. e.&(33}.127{.a.)) &> log
|. ~. |. log
)
editinputlog=: 3 : 0

require 'jpick'

log=. getinputlog''

if. 0=#log do.
  wdinfo 'Input Log';'Nothing in the input log' return.
end.

'old sel'=. INPUTLOG
if. log -: old do.
  x=. sel
else.
  x=. <:#log
end.

INPUTLOG_j_=: log;x

sel=. INPUTLOG,'Input Log';'editinputprompt'
sel conew 'jpick'
)
editinputprompt=: 3 : 0
if. # y. do.
  log=. 0 pick INPUTLOG
  INPUTLOG_j_=: log ; y.
  smprompt_jijs_ y. pick log
end.
)
saveinputlog=: 3 : 0
)

readinputlog=: 3 : 0
)

INPUTLOG=: '';0
WINPOS=: i.0 2
filex=: ] , ([: -. '.'"_ e. ]) # [
edit=: 3 : 0
'n s'=. y.
file=. {.,getscripts_j_ s
dat=. 1!:1 :: _1: file
if. dat -: _1 do.
  'file read error: ',,>file return.
end.
dat=. toJ dat
dat=. < @ (;: :: <) ;._2 dat,LF
ndx=. I. (1: e. (n;'=:')&E.) &> dat
if. 0 = #ndx do.
  m=. }:(2<:+/\.n='_')#n
  ndx=. I. (1: e. (m;'=:')&E.) &> dat
end.
if. 0 = #ndx do.
  wdinfo 'not found: ',":n return.
end.
if. IFWINCE do.
  open file
else.
  ({.ndx) open_jijs_ file
end.
)

formeditrun=: 3 : 0
'form file'=. y.
load file
if. +./'coclass' E. 1!:1<file do.
  t1=. 'object=:''''conew''',form,''''
  t2=. 'object_base_ =:''''conew_base_''',form,''''
else.
  t1=. form,'_run'''''
  t2=. form,'_run_base_'''''
end.
smoutput '   ',t1
".t2
empty''
)
loadp=: ''&$: : (4 : 0)
require jpath '~system\extras\util\project.ijs'
x. loadproject_jproject_ y.
)
open=: 3 : 0
f=. ,getscripts y.
b=. exist"0 f
if. 0 e. b do.
  j=. (b=0)#f
  if. 1=#j do. j=. ,>j
  else. j=. LF,; LF&, each j
  end.
  wdinfo 'not found: ',j
end.
if. #f=. b#f do. openfiles f end.
)
openfiles=: 3 : 0
if. IFWINCE do.
  require jpath '~system\extras\util\edit.ijs'
  y. conew each <'jedit'
else.
  try.
    open_jijs_ each y.
  catch. end.
end.
empty''
)
save=: 4 : 0
fl=. boxopen x.
lc=. y.
'' 1!:2 fl
if. 0=#lc do. lc=. 4!:1[6 end.
lc=. , each cutopen lc
lc=. (lc e.4!:1[6)#lc
if. 0=#lc do. empty'' return. end.
nms=. 3 : '(<''y.'')-.~(''namelist_'',(y.),''_'')~0 1 2 3' each lc
nms=. ;nms (,each <) each '_'&,@(,&'_') each lc
res=. nms ,each <'=:'
res=. res ,each <@(5!:5) nms
res=. ; res ,each LF
(toHOST res) 1!:3 fl
empty ''
)
saveuserfolders=: 3 : 0
0!:0 <jpath '~system\extras\util\cfguser.ijs'
)
scriptmake=: 4 : 0
y=. getscripts y.
txt=. ''
while. #y do.
  f=. {.{.y
  dat=. 1!:1 :: _1: f
  if. dat -: _1 do.
    'file read error: ',>f return.
  end.
  txt=. txt,LF,dat
  y=. }.y
end.
txt=. toJ txt,LF
txt=. <;._2 txt
f=. #~ -.@(('NB.'&-:)@(3&{.)&>)
txt=. f txt
f=. 'NB.'&E. <: ~:/\@(''''&=)
g=. (,&CRLF)@(#~ *./\@f)
txt=. ;g each txt
txt 1!:2 boxopen x.
#txt
)
scripts=: 3 : 0
if. 0=#y. do.
  list 0{"1 PUBLIC
elseif. 'reset'-:y. do.
  0!:0 <SCRIPTS
elseif. 'v'e.y. do.
  dir=. PUBLIC
  a=. >0{"1 dir
  b=. >1{"1 dir
  a /:~ a,.' ',.b
elseif. 'e' e.y. do.
  open SCRIPTS
elseif. 1 do.
  'invalid argument to scripts: ',,":y.
end.
)
selactive=: 3 : 0
fl=. qsmact_jijs_''
if. '.ijs' -: _4{.fl do.
  smselact_jijs_''
  'n x'=. globaldefs smread_jijs_''
  's t'=. wdselect 'select';<n
  if. s do. smscroll_jijs_ t{x end.
end.
empty''
)
lastactive_j_=: 3 : 0
d=. wdforms''
b=. (3 {"1 d) e. 'jijs';'jijx'
d=. b#d
last=. ".>4{"1 d
b=. last=>./last
>1{,b#d
)
wpsave=: 3 : 0
'' wpsave y.
:
if. #y. do.
  if. #x. do.
    pos=. x.
  else.
    if. # wd :: 0: 'psel ',y. do. return. end.
    pos=. 0 ". wd 'qformx'
  end.
  siz=. _2 {. pos
  
  if. IFJAVA do.
    max=. 2 {. 0 ". wd 'qm'
  else.
    max=. 14 15 { 0 ". wd 'qm'
  end.
  
  min=. 100 40    
  if. 1 e. (min > siz) +. max < siz do. return. end.
  ndx=. ({."1 WINPOS_j_) i. <y.
  if. ndx = #WINPOS_j_ do.
    WINPOS_j_=: WINPOS_j_,y.;pos-1
  end.
  if. pos -: >{:ndx{WINPOS_j_ do. return. end.
  WINPOS_j_=: (y.;pos) ndx}WINPOS_j_
end.
dat=. 'WINPOS=:',5!:5 <'WINPOS_j_'
dat 1!:2 <jpath '~config\winpos.ijs'
)
wpset=: 3 : 0
ndx=. ({."1 WINPOS_j_) i. <y.
if. r=. ndx < #WINPOS_j_ do.
  'x y w h'=. >{:ndx{WINPOS_j_
  'sx sy'=. 2 {. 0 ". wd 'qm'
  x=. x <. sx - w=. w <. sx
  y=. y <. sy - h=. h <. sy
  wd 'pmovex ',":x,y,w,h
end.
r
)
wpreset=: 3 : 0
if. #y=. a: -.~ boxopen y. do.
  b=. -. ({."1 WINPOS_j_) e. y
else. b=. 0 end.
WINPOS_j_=: b#WINPOS_j_
wpsave''
)
cleantable=: [: sort ([: ~: {."1) # ]
globaldefs=: 3 : 0
dat=. <;._2 y.,LF
f=. [: (#~ (<'=:')&-:@{:) [: 2&{. ;:
def=. f &.> dat
b=. *#&>def
nms=. {.&>b#def
ndx=. b#i.#b
ind=. /:>nms
(ind{nms);<ind{ndx
)
origin=: 3 : 0
((<''),4!:3 '') {~ >: 4!:4 cutopen y.
)
0!:0 :: ] <jpath '~config\winpos.ijs'
fileopen=: 3 : 0
require jpath '~system\extras\util\edit.ijs'
y=. y.
if. 0=#y do. y=. 0 end.
y conew 'jedit'
)

filenew=: 3 : 0
require jpath '~system\extras\util\edit.ijs'
1 conew 'jedit'
)

3 : 0''
if. IFWINCE do.
  wpsave=: wpset=: wpreset=: 0:
  prints=: printfiles=: 0:
end.
0
)

classwizard=: 3 : 0
require jpath '~system\extras\util\wizard.ijs'
classwizard_jwizard_ y.
)
config=: 3 : 0
script <jpath '~system\extras\util\cfgfns.ijs'
)
debug=: 3 : 0
require 'debug'
dbg_z_ 1
)
demos=: 3 : 0
script <jpath '~system\extras\util\demos.ijs'
)
dirmatch=: 3 : 0
require jpath '~system\extras\util\dirmatch.ijs'
dmrun_jdirmatch_ y.
)
editfind=: 3 : 0
require jpath '~system\extras\util\fiw.ijs'
fiw_jfiw_ y.
)
fif=: 3 : 0
require jpath '~system\extras\util\fif.ijs'
fif_jfif_ y.
)
filenewform=: 3 : 0
require jpath '~system\extras\util\wizard.ijs'
classwizard_jwizard_''
)
fileprint_j_=: 3 : 0
smselact_jijs_''
dat=. smread_jijs_''
if. ~:/ r=. smgetsel_jijs_'' do.
  prints (--/r) {. ({.r) }. dat
else.
  prints dat
end.
)
fileprintsetup=: empty @ wd bind 'mbprinter pd_printsetup'
formedit=: 3 : 0
require jpath '~system\extras\util\formedit.ijs'
y. conew 'jformedit'
)
forms=: 3 : 0
require jpath '~system\extras\util\forms.ijs'
forms_jforms_''
)
gridwizard=: 3 : 0
require jpath '~system\extras\util\autocode.ijs'
autocode_jautocode_ y.
)
help=: 3 : 0
require jpath '~system\extras\util\help.ijs'
require jpath '~system\extras\util\scripdoc.ijs'
help_jhelp_ y.
)
htmlhelp=: 3 : 0
require jpath '~system\extras\util\browser.ijs'
launch_jbrowser_ jpath '~system\extras\help\',y.
)
lab=: 3 : 0
require jpath '~system\extras\util\lab.ijs'
lab_jlab_ y.
)
publish=: 3 : 0
require jpath '~system\packages\publish\publish.ijs'
publish_jpublish_ '1' e. sysmodifiers
)
prints=: 3 : 0
'' prints y.
:
require 'print'
f=. SMPRINT_j_
try.
  x. f~ y.
catch.
  wdinfo 'Print';'Print failed.',LF,LF,'Check the printer is installed'
end.
)
printfiles=: 3 : 0
'' printfiles y.
:
require 'print'
f=. SMPRINT_j_
f=. (5{.f),'file',5}.f
try.
  x. f~ y.
catch.
  wdinfo 'Print';'Print failed.',LF,LF,'Check the printer is installed'
end.
)
projectmanager=: 3 : 0
require jpath '~system\extras\util\project.ijs'
projectmanager_jproject_ y.
)

SCRIPTS=: jpath '~system\extras\config\scripts.ijs'
0!:0 <SCRIPTS

edit_z_=: 3 : 0
y=. cutopen y.
if. 0=#y do. empty'' return. end.
if. 1=#y do.
  if. _1 = s=. 4!:4 y do.
    open y return. end.
  y=. y,<s{4!:3 ''
end.
edit_j_ y
)
loadp_z_=: loadp_j_
open_z_=: open_j_
scripts_z_=: scripts_j_