NB. built from project: ~Source\main\project\project

script_z_ '~system\main\compare.ijs'
script_z_ '~system\main\dir.ijs'
script_z_ '~system\main\dll.ijs'
script_z_ '~system\main\files.ijs'
script_z_ '~system\main\gl2.ijs'
script_z_ '~system\main\libpath.ijs'
script_z_ '~system\packages\print\print.ijs'
script_z_ '~system\main\regex.ijs'
script_z_ '~system\extras\util\scripdoc.ijs'
script_z_ '~system\main\strings.ijs'

coclass 'jproject'


('jijs';'j';'z') copath <'jproject'

MAXRECENT=: 20
STDLIBS=: 'stdlib';'colib';'winlib';'loadlib'

DEFBUILDOPTS=: 0 1 0 0 0 0 0

PJFILES=: ''
PROJECTFILE=: ''
PMTABS=: 0 2
PLINK=: ''
PLINKLAST=: ''
PROJECTRECENT=: ''
PROJECTLOOKIN=: ''

PID=: ''
PIDS=: i.0 2
PIDPATH=: ''
PIDTREE=: ''
PROJECTCFG=: jpath '~config\projects.ijs'
WINDOWS=: ''
WINDOWSTATE=: 0 
PPSCRIPT=: jpath '~system\extras\util\pp.ijs'

XOLD=: ''
XPROJECTRECENT=: PROJECTRECENT
PMTABS=: PMTABS
XPROJECTLOOKIN=: PROJECTLOOKIN
XFILES=: ''
XLIBS=: ''
TXPP=: i.0 2

j=. 'PRIMARYFILES PRIMARYLIBS DEVFILES DEVLIBS OTHERFILES'
j=. j,' TARGETFILE TARGETLOCALE TARGETHEADER TARGETEXTRA'
j=. j,' BUILDOPTS PREBUILDFILE POSTBUILDFILE TESTFILE'
PFILENAMES=: ;: j,' NOTES WINDOWS WINDOWSTATE'
XPFILENAMES=: 'X' ,each PFILENAMES
projreset=: 3 : 0
noteedit=: ''  
(PFILENAMES)=: a:
(XPFILENAMES)=: a:
WINDOWSTATE=: XWINDOWSTATE=: 0
BUILDOPTS=: XBUILDOPTS=: DEFBUILDOPTS
RLIBS=: _1   
RFILES=: ''
)

closeproject=: 3 : 0
projsaveok''
wd :: ] 'psel wnote;pclose'
try.
  wd 'psel projectform'
  wpsave 'projectform'
  wd 'pclose'
catch. end.
)
cutcommas=: 3 : 0
if. #y. do.
  a: -.~ <;._1 ',', y.
else.
  ''
end.
)
getpmfolders=: 3 : 0
a=. jpath '~system\'
b=. {:"1 y.
m=. (<a) ~: (#a) {.each b
m=. m *. b ~: <}:a
m # y.
)
openp=: 3 : 0
projreset''
setprojfile y.
projread ''
empty''
)
openpr=: 3 : 0
openp y.
projaddrecent ''
empty''
)
opennewproject=: 3 : 0
projsaveok''
while. 1 do.
  j=. '"Project Files(*.ijp)|*.ijp" ofn_nochangedir'
  f=. wd 'mbsave "New Project File" "',PIDPATH,'" "" ',j
  if. ''-:f do. return. end.
  f=. extijp f
  if. -. '.ijp' -: _4 {.f do.
    info 'Project filename extension should be .ijp'
  elseif. fexist f do.
    if.
      msg=. f,LF,'This file already exists.'
      msg=. msg,LF,LF,'Replace existing file?'
      0=2 1 query msg do. break.
    end.
  elseif. 1 do. break.
  end.
end.

XOLD=: ''
setprojfile f
projreset''
projsave 0
openprojectfile PROJECTFILE
projectform_show''
projaddrecent''
)
openoldproject=: 3 : 0
projsaveok''

while. 1 do.
  j=. '"Project Files(*.ijp)|*.ijp" ofn_filemustexist ofn_nochangedir'
  f=. wd 'mbopen "Open Project File" "',PIDPATH,'" "" ',j
  if. ''-:f do. return. end.
  f=. extijp f
  if. '.ijp' -: _4 {.f do. break. end.
  info 'Project filename extension should be .ijp'
end.

openprojectfile f
projectform_show''
)
openprojectfile=: 3 : 0
file=. fullproject y.

if. 0 = '.ijp' -: _4 {. file do.
  info 'Not a project file: ',file
  0 return.
end.

if. 0=fexist file do.
  info 'not found: ',file
  XPROJECTRECENT=: XPROJECTRECENT -. <file
  0 return.
end.

setprojfile file
p=. fullname@addfret each {:"1 USERFOLDERS
if. -. XPROJECTLOOKIN -: (#XPROJECTLOOKIN) {. file do.
  XPROJECTLOOKIN=: PROJECTLOOKIN=: ''
end.
b=. p = <XPROJECTLOOKIN

if. 1 e. b do.
  x=. i. # p
else.
  x=. \: # &> p
  p=. x { p
  m=. [ -: #@[ {. ]
  b=. p m &> <file
end.

if. 1 e. b do.
  ndx=. b i. 1
  pn=. 0 pick ndx { x { USERFOLDERS
  if. PID -: pn do.
    PJFILES=: sort ~. PJFILES, <file
  else.
    setprojpath pn, _1 |. (getpidpath pn) drophead XPROJECTLOOKIN
  end.
else.
  pn=. delfret fpath file
  TXPP=: TXPP,pn;pn
  setprojpath pn
end.

setpidtree''
projread''
snapshot''
1
)
getselectfiles=: 3 : 0
r=. ''
select. TABNDX
case. 0 do.
  if. #filelist_select do.
    r=. (".filelist_select) { XFILES
  end.
case. 1 do.
  if. #libto_select do.
    r=. getlibfiles (".libto_select) { XLIBS
  else.
    r=. getlibfiles cutopen libfrom
  end.
case. 2 do.
  if. #bpfiles_select do.
    r=. (".bpfiles_select) { BPFILES
  end.
case. 3 do.
  if. #spfiles_select do.
    r=. (".spfiles_select) { XOTHERFILES
  end.
end.
if. 0 = #r do. infonosel'' return. end.
r=. fromfoldername r
if. 0 e. b=. fexist &> r do.
  info 'not found:',LF,LF,tolist (b=0)#r
  '' return.
end.
)
popenfiles=: 3 : 0
if. # f=. getselectfiles '' do.
  open_j_ f
end.
projaddrecent''
)
setprojfile=: 3 : 0
if. #y. do.
  p=. y.
else.
  p=. 0 pick PJFILES,a:
end.
PROJECTFILE=: fullname p
)
viewfile=: 3 : 0
if. # f=. getselectfiles '' do.
  f=. >{.f
  try.
    f wdview 1!:1 <f
  catch.
  end.
  wd 'psel projectform;pactive'
end.
projaddrecent''
)
sprintfiles=: 3 : 0
if. # f=. getselectfiles '' do.
  sprintfile each f
end.
projaddrecent''
)
sprintfile=: 3 : 0
if. fexist y. do. printfiles y.
else. info 'Could not open file: ',y.
end.
)

3 : 0''
if. IFUNIX do.
  tocase=: [
else.
  tocase=: tolower
end.
0
)
bcfind=: #@[ (| - =) i. &: (tocase each)
bcfind0=: {."1 @ [ bcfind ]
find=: #@[ (| - =) i.
find0=: {."1 @ [ bcfind ]

boxlist=: (<;._2) -. a:"_
deb=: #~ (+. 1: |. (> </\))@(' '&~:)
delstring=: 4 : ';(x.E.r) <@((#x.)&}.) ;.1 r=. x.,y.'
do=: ".
drophead=: ] }.~ #@[ * [ -: &: tocase #@[ {. ]
dtb=: #~ [: +./\. ' '&~:
fix=: _1&".
index=: #@[ (| - =) i.
info=: wdinfo @ ('Project Manager'&;)
infonoproj=: info bind 'First select a project file'
infonosel=: info bind 'No file selected'
infonospec=: info bind 'No file specified'
isempty=: 0: e. $
matchhead=: [ -: &: tocase #@[ {. ]
query=: wdquery 'Project Manager'&;
sort=: /:~ : /:
subs=. 2 : 'x."_ I. @(e.&y.)@]} ]'
addfret=: , PATHSEP"_ -. [: {: PATHSEP"_ , ]
delfret=: }: , {: -. PATHSEP"_
termLF=: , (0: < #) # LF"_ -. _1&{.    
termdelLF=: }.~ [: - 0: i.~ LF&= @ |.  
toblank=: ' ' subs '_'
tounderscore=: '_' subs ' '
tolist=: }. @ ; @: (LF&, each)
tolist2=: (2&}.) @ ; @: ((LF,LF)&, each)
xin=: [ -. -.
a=. ''''
quote=: (a&,@(,&a))@ (#~ >:@(=&a))
imxq=: 9!:26        
imxs=: 9!:27        
imxsq=: 9!:28       
imxss=: 9!:29       
dqadd=: ]`('"'&, @ (,&'"')) @. (' '&e.)
dqrem=: ]`(}.@}:) @. ('"'"_ = {.@(1&{.))
dqdeb=: #~ (+. (1: |. (> </\))) @ (' '&~: +. [: ~:/\ =&'"')
dqcut=: -.&a: @ ((' '&= > [: ~:/\ =&'"') <@dqrem ;._1 ]) @ (' '&,)
addNB=: 3 : 0
if. 0=#y. do. '' return. end.
y=. <;._2 termLF y.
b=. 0='NB.'&-: @ (3&{.) &> y
add=. b #each <'NB. '
tolist add ,each y
)
decomment=: 3 : 0
dat=. <;._2 termLF toJ y.
if. 2 > #dat do. y. return. end.

com=. ('NB.'&-:)@(3&{.)&> dat
ncm=. com < (1|.0,}.com) +. (0,}._1|.com)
msk=. com +: ncm *. dat=a:

dat=. msk # dat

f=. 'NB.'&E. <: ~:/\@(e.&'''')
g=. #~ *./\@f
tolist g each dat
)
copynew=: 4 : 0
y=. boxopen y.
dat=. fread each y
if. 1 e. b=. dat = <_1 do.
  info 'file not found:',,' ',.>b#y
  return.
end.
x. copyto ; dat
)
copynews=: 4 : 0
y=. boxopen y.
dat=. freads each y
if. 1 e. b=. dat = <_1 do.
  info 'file not found:',,' ',.>b#y
  return.
end.
dat=. ptoHOST ; dat
x. copyto dat
)
copyto=: 4 : 0
if. 0 = pathcreate fpath x. do.
  info 'Cannot create path: ',fpath x. return.
end.
datold=. fread :: 0: x.
datnew=. y.
if. datold -: datnew do.
  'no change, size: ',":#datnew
else.
  datnew fwrite x.
  'copied, size: ',":#datnew
end.
)
dcopynew=: 4 : 0
fm=. addfret y.
to=. addfret x.
nms=. 1 dir fm
for_n. nms do.
  id=. 1 pick pathname >n
  (to,id) copynew >n
end.
)
fxcopy=: 4 : 0
0 pick 'kernel32 CopyFileA i *c *c i' cd y.;x.;0
)
flerase=: (1!:55&< :: _1: ) &>
flread=: (1!:1 :: _1:) @ boxopen
flstamp=: (1: >@{ ,@(1!:0)) ::(_1:)
flwrite=: (1!:2 :: _1:) boxopen
flreads=: 3 : 0
y=. boxopen y.
dat=. (1!:1) :: _1: y
if. (dat -: _1) +. 0=#dat do. return. end.
dat,LF -. {:dat=. toJ dat
)
flwrites=: 4 : 0
dat=. x.
if. -. 0 e. $dat do.
  if. 1>:#$dat do.
    dat=. ptoHOST dat
    dat=. dat,(LF ~: {:dat)#CRLF
  else. dat=. dat,"1 CRLF
  end.
end.
dat flwritenew y.
)
flwritenew=: 4 : 0
dat=. ,x.
new=. -. dat -: flread y.
if. new do. dat flwrite y. end.
new
)
loadscript=: 3 : 0
try. 0!:0 <y.
catch. info 'Unable to load: ',y.
end.
)
nounrep=: 3 : 0
LF ,~ y.,'=: ',nounrep1 ". y.
)
nounrep1=: 3 : 0
dat=. y.
if. #dat do.
  select. 3!:0 dat
  case. 2 do.
    if. LF e. dat do.
      dat=. dat, LF -. {:dat
      '0 : 0', LF, ; <;.2 dat,')'
    else.
      quote dat
    end.
  case. 32 do.
    5!:5 <'dat'
  case. do.
    ": dat
  end.
else.
  ''''''
end.
)
pathcreate=: 3 : 0
p=. jhostpath y.
p=. p, PATHSEP_j_ -. {: p
if. # 1!:0 }: p do. 1 return. end.
p=. (p e. '/\') <;.2 p
t=. ''
f=. 1!:5 :: 0:
while. #p do.
  t=. (_1 { p), t
  p=. }: p
  if. # 1!:0 }: ; p do.
    p=. ; p
    while. #t do.
      p=. p, > 0 { t
      t=. }. t
      if. 0 = f < p do. 0 return. end.
    end.
    1 return.
  end.
end.
0
)
ptoHOST=: 3 : 0
if. '~system' -: 7 {. XTARGETFILE do.
  toCRLF y.
else.
  toHOST y.
end.
)


filecopy=: 3 : 0
'source dest'=. y.
if. IFWIN32 do.
  0 pick 'kernel32 CopyFileA i *c *c i' cd source;dest;0
else.
  if. 0 = pathcreate fpath dest do. 0 return. end.
  if. _1 -: dat=. fread source do. 0 return. end.
  -. _1 -: dat fwrite dest
end.
)


BFILES=: 0 : 0
pc bfiles owner;
xywh 3 3 55 11;cc s0 static;cn "Project Files:";
xywh 2 15 138 147;cc bpfiles listbox ws_hscroll ws_vscroll lbs_extendedsel rightmove bottommove;
xywh 144 11 36 12;cc bopen button leftmove rightmove;cn "&Open";
xywh 144 24 36 12;cc bview button leftmove rightmove;cn "&View";
xywh 144 37 36 12;cc bprint button leftmove rightmove;cn "&Print";
xywh 144 50 36 12;cc add button leftmove rightmove;cn "&Add";
xywh 144 63 36 12;cc remove button leftmove rightmove;cn "&Remove";
xywh 144 146 36 12;cc cancel button leftmove topmove rightmove bottommove;cn "Close";
pas 0 0;
rem form end;
)
bfiles_run=: 3 : 0
wd BFILES
wd 'pshow;'
)
bfiles_cancel_button=: closeproject
bfiles_show=: 3 : 0
j=. buildfiles''
k=. buildfilestag''
b=. 0 < # &> j
BPFILES=: b # j
if. 1 e. b do.
  p=. (shortname b # j) ,each b # k
  wd 'set bpfiles *',tolist p
else.
  wd 'set bpfiles'
end.
)
bfiles_add_button=: bfadd_run
bfiles_remove_button=: 3 : 0

if. 0 e. #bpfiles do. infonosel'' return. end.

files=. (".bpfiles_select) { BPFILES
files=. files -. a:

if. 1 e. files e. <PROJECTFILE
do. info 'You cannot remove the project file' return.
end.

ff=. tolist shortname files
if. 1=2 query 'OK to remove:',LF,LF,ff do. return. end.

XTARGETFILE=: ,> XTARGETFILE jflminus files
XPREBUILDFILE=: ,> XPREBUILDFILE jflminus files
XPOSTBUILDFILE=: ,> XPOSTBUILDFILE jflminus files
XTESTFILE=: ,> XTESTFILE jflminus files

bfiles_show''
)
bfiles_bopen_button=: popenfiles
bfiles_bview_button=: viewfile
bfiles_bprint_button=: sprintfiles
bfiles_bpfiles_button=: popenfiles
buildfiles=: 3 : 0
PROJECTFILE;XTARGETFILE;XPREBUILDFILE;XPOSTBUILDFILE;XTESTFILE
)
buildfilestag=: 3 : 0
' (project)';' (target)';' (prebuild)';' (postbuild)';' (test)'
)

BFNAMES=: ;: 'XTARGETFILE XPREBUILDFILE XPOSTBUILDFILE XTESTFILE'

BFADD=: 0 : 0
pc bfadd owner;pn "Add Project Script";
xywh 6 6 75 65;cc g0 groupbox;cn "Project Script";
xywh 13 18 64 11;cc btarg radiobutton;cn "Target";
xywh 13 31 64 11;cc bpre radiobutton group;cn "Pre-Build";
xywh 13 44 64 11;cc bpost radiobutton group;cn "Post-Build";
xywh 13 57 64 11;cc btest radiobutton group;cn "Test";
xywh 92 9 40 12;cc ok button;cn "OK";
xywh 92 24 40 12;cc cancel button;cn "Close";
pas 4 4;pcenter;
rem form end;
)
bfadd_run=: 3 : 0
wd BFADD
ndx=. 0 i.~ #@". &> BFNAMES
wd 'set btarg 0;set bpre 0;set bpost 0;set btest 0'
if. ndx<4 do.
  wd 'set ',(ndx pick ;: 'btarg bpre bpost btest'),' 1'
end.
wd 'pshow'
)
bfadd_ok_button=: 3 : 0
if. 0=#PROJECTFILE do. infonoproj'' return. end.

ndx=. '1' i.~ btarg,bpre,bpost,btest
if. ndx=4 do.
  info 'No Project Script selected' return.
end.

iftarget=. ndx=0
extok=. '.ij'&, each 's',iftarget#'rl'

nam=. ndx pick <;._1 ' Target Pre-Build Post-Build Test'
xnm=. ndx pick BFNAMES
xvl=. ". xnm

p=. ppath''

while. 1 do.
  if. iftarget do.
    j=. '"Script Files(*.ijs)|*.ijs|Runtime Scripts(*.ijr)|*.ijr|Locked Scripts(*.ijl)|*.ijl"'
  else.
    j=. '"Script Files(*.ijs)|*.ijs"'
  end.
  j=. j,' ofn_nochangedir'
  f=. wd 'mbopen "',nam,' File" "',p,'" "',xvl,'" ',j
  if. ''-:f do. return. end.
  f=. extijs f
  if. (<_4 {.f) e. extok do.
    file=. <f
    if. f -: xvl do. return. end.
    if. file jflin XPRIMARYFILES, XDEVFILES do.
      info 'already in project: ',>shortname file break.
    end.
    
    if. #xvl do.
      if. 0 ~: 2 query 'OK to replace ',nam,' File?' do. continue. end.
    end.
    break. end.
  
  info 'Script filename extension should be .ijs'
  p=. fpath f
end.
if. 0=fexist file do. '' flwrites file end.

f=. tofoldername1 > file

". xnm,'=: f'
XOTHERFILES=: XOTHERFILES jflminus file

bfadd_close''
)
bfadd_close=: 3 : 0
wd 'pclose;psel projectform;pactive'
bfiles_show''
)

bfadd_cancel_button=: bfadd_cancel=: bfadd_close
bfadd_enter=: bfadd_ok_button

BPNAMES=: 'XBUILDOPTS XTARGETEXTRA XTARGETLOCALE XTARGETHEADER'

WBUILD=: 0 : 0
pc wbuild owner;pn "Build Options";
xywh 5 6 146 76;cc g0 groupbox;cn "Include Files";
xywh 88 13 30 9;cc s1 static;cn "Include";
xywh 118 13 28 9;cc s2 static;cn "Require";
xywh 11 22 66 9;cc s3 static;cn "Project source:";
xywh 99 23 9 9;cc incsrc radiobutton;cn "";
xywh 126 23 9 9;cc reqsrc radiobutton group;cn "";
xywh 11 33 66 9;cc s4 static;cn "Project libraries:";
xywh 99 34 9 9;cc inclib checkbox;cn "";
xywh 126 34 9 9;cc reqlib checkbox;cn "";
xywh 11 46 72 9;cc s6 static;cn "For standalone files:";
xywh 11 56 70 9;cc s5 static;cn "Standard libraries:";
xywh 90 49 58 1;cc s7 staticbox ss_etchedhorz;
xywh 99 57 9 9;cc incstd checkbox;cn "";
xywh 126 57 9 9;cc reqstd checkbox;cn "";
xywh 11 68 137 9;cc jdll checkbox;cn "Use libraries for J DLL only";
xywh 5 91 196 115;cc g1 groupbox rightmove bottommove;cn "Build Options";
xywh 11 102 139 9;cc decom checkbox;cn "Delete comments (except header)";
xywh 11 113 139 9;cc noshow checkbox;cn "Do not show J session manager";
xywh 11 123 140 11;cc label static;cn "Header Comments:";
xywh 10 135 185 34;cc theader editm ws_vscroll rightmove bottommove;
xywh 10 176 53 11;cc label static topmove bottommove;cn "Load in locale: ";
xywh 65 175 131 12;cc tlocale edit ws_border es_autohscroll topmove rightmove bottommove;
xywh 11 191 53 11;cc label static topmove bottommove;cn "Append to file:";
xywh 65 190 131 12;cc textra edit ws_border es_autohscroll topmove rightmove bottommove;
xywh 158 6 44 12;cc ok button bs_defpushbutton leftmove rightmove;cn "Close";
xywh 158 22 44 12;cc buildapp button leftmove rightmove;cn "&Build Now";
xywh 158 38 44 12;cc help button leftmove rightmove;cn "&Help";
pas 3 2;pcenter;
rem form end;
)
wbuild_run=: 3 : 0
pos=. wd 'qformx'
wd WBUILD
wdcenter pos
wd 'set reqsrc ',":0{XBUILDOPTS
wbuildshowlib''
wbuildshowstd''
wd 'set decom ',":3{XBUILDOPTS
wd 'set jdll ',":4{XBUILDOPTS
wd 'set noshow ',":6{XBUILDOPTS
wd 'set theader *',XTARGETHEADER
wd 'set tlocale *',XTARGETLOCALE
wd 'set textra *',XTARGETEXTRA
wd 'pshow;'
)
wbuild_close=: 3 : 0
wbuild_saveok''
wbuildclose''
)
wbuildclose=: 3 : 0
wd 'psel projectform'
wother_show''
wd :: [ 'psel wbuild;pclose'
wd 'psel projectform;pactive'
)
wbuild_inclib_button=: 3 : 0
t=. #. (". inclib),". reqlib
t=. t { 2 1 0 0
XBUILDOPTS=: t 1} XBUILDOPTS
wbuildshowlib''
)
wbuild_reqlib_button=: 3 : 0
t=. #. (". inclib),". reqlib
t=. t { 2 1 0 1
XBUILDOPTS=: t 1} XBUILDOPTS
wbuildshowlib''
)
wbuild_incstd_button=: 3 : 0
t=. ". incstd
XBUILDOPTS=: t 2} XBUILDOPTS
wbuildshowstd''
)
wbuild_reqstd_button=: 3 : 0
t=. 2*". reqstd
XBUILDOPTS=: t 2} XBUILDOPTS
wbuildshowstd''
)
wbuildshowlib=: 3 : 0
t=. 1{XBUILDOPTS
wd 'set inclib ',":t=0
wd 'set reqlib ',":t=1
)
wbuildshowstd=: 3 : 0
t=. 2{XBUILDOPTS
wd 'set incstd ',":t=1
wd 'set reqstd ',":t=2
)
wbuild_help_button=: 3 : 0
htmlhelp 'user\build_apps.htm'
)
wbuild_read=: 3 : 0
c=. (".reqsrc), (1 2{XBUILDOPTS), ". &> decom,jdll,'0',noshow
d=. textra
e=. tlocale
f=. theader
c;d;e;f
)
wbuild_saveok=: 3 : 0
old=. ".each ;: BPNAMES
new=. wbuild_read''
if. old-:new do. return. end.
j=. 'Build options have changed. Save them?'
if. 1=2 query j do. return. end.
wbuild_save''
)
wbuild_save=: 3 : 0
p=. <ppath''
TARGET_j_=: (p , <tlocale) , (p ~: {."1 TARGET) # TARGET
(BPNAMES)=: wbuild_read''
)
wbuild_cancel=: wbuild_close
wbuild_ok_button=: wbuildclose @ wbuild_save
wbuild_enter=: wbuild_ok_button
wbuild_buildapp_button=: buildapp @ wbuild_save
buildopt=: wbuild_run

DEFREQUIRE=: 'require_z_=: ]',LF
checkrequire=: 3 : 0
if. STANDALONE *. DOREQUIRE do.
  DOREQUIRE=: 0
  DEFREQUIRE
else.
  ''
end.
)
getstdlibs=: 3 : 0
(;: 'sysenv stdlib colib') , (-.IFDLL) # <'winlib'
)
getstdboot=: 3 : 0
f=. ' jpath ''~system\main\'&, @ (,&'.ijs''')
libs=. getstdlibs''
j=. <'boot_z_=: 3 : ''0!:0 <y.'''
tolist j, 'boot_z_'&, each f each libs
)
setclass=: 3 : 0
y=. ,> y.
if. 0 = #y do. '' return. end.
f=. '''',y,''''
(((<y) e. ;: 'base z') pick 'coclass ';'cocurrent '),f,LF
)
buildproject=: 3 : 0
saveopenwindows''
nms=. 'IFREQSRC IFREQLIB STANDALONE IFDELCMT IFDLL j IFNOSHOW'
(nms)=: BUILDOPTS
DOREQUIRE=: 1
if. 0=buildprescript'' do. return. end.
buildtarget''
buildpostscript''
)
buildapp=: 3 : 0

saveopenwindows''
getfoldernames''
projsavenew''
projaddrecent''

if. 0 = (#XTARGETFILE) + (#XPREBUILDFILE) + #XPOSTBUILDFILE do.
  info 'First set target or build files in the Project tab' return.
end.

xtg=. fromfoldername1 XTARGETFILE

if. #xtg do.
  old=. (flread;flstamp) xtg
else.
  old=. _1
end.

if. 0=buildproject'' do. return. end.

if. y. -: 1 do. return. end.

if. #xtg do.
  if. old -: (flread;flstamp) xtg do.
    DB=: old ; <(flread;flstamp) xtg
    info 'No change: ',xtg
  else.
    info 'Saved: ',xtg
  end.
else.
  info 'Project Built'
end.

)
buildprescript=: 3 : 0
if. 0=#XPREBUILDFILE do. 1 return. end.
fl=. fromfoldername1 XPREBUILDFILE
try. 1 [ load__ <fl
catch. 0 [ info 'Error loading: ',,":fl
end.
)
buildpostscript=: 3 : 0
if. 0=#XPOSTBUILDFILE do. 1 return. end.
fl=. fromfoldername1 XPOSTBUILDFILE
try. 1 [ load__ <fl
catch. 0 [ info 'Error loading: ',,":fl
end.
)
buildtarget=: 3 : 0
if. 0=#XTARGETFILE do. return. end.

j=. addNB XTARGETHEADER
j=. j, (0<#j)#LF
pjf=. tofoldername1 extnone PROJECTFILE
tag=. j,'NB. built from project: ',pjf,LF

'cmt tgt'=. buildtargetfiles''
tag=. tag, cmt

std=. buildstdlibs''
trg=. buildtargetlibs''
sys=. buildsystemdefs trg
dat=. std;sys;trg
dat=. dat,<buildlocale''
dat=. dat,<tgt
dat=. dat,<XTARGETEXTRA
dat=. tolist dtb each dat -. a:

if. IFDELCMT do. dat=. decomment dat end.
if. IFNOSHOW do. dat=. 'IFJIJX_j_=: 1',LF,dat end.

dat=. ptoHOST tag, LF, dat

xtg=. fromfoldername1 XTARGETFILE
if. 0 = pathcreate fpath xtg do.
  info 'Could not create path: ',fpath xtg return.
end.
if. 'l'= {:xtg do.
  dat=. 3!:6 dat
end.

if. dat flwritenew xtg do.
  LOADED_j_=: LOADED -. xtg
end.
)
buildlocale=: 3 : 0
if. #XTARGETLOCALE do.
  setclass XTARGETLOCALE
elseif. (1=STANDALONE) +. (0=IFREQLIB) *. 0<#XPRIMARYLIBS do.
  setclass 'base'
elseif. 1 do. ''
end.
)
buildstdlibs=: 3 : 0
select. STANDALONE
case. 0 do. ''
case. 1 do.
  libs=. getstdlibs''
  txt=. tolist <@(1!:1) fromfoldername getlibfiles libs
case. 2 do.
  getstdboot''
end.
)
getsystemdefs=: 3 : 0
1!:1 <fromfoldername1 '~system\main\defs\',y.,'_',tolower UNAME,'.ijs'
)
buildsystemdefs=: 3 : 0
dat=. y.
res=. ''
if. STANDALONE = 0 do. return. end.
c=. 'jsystemdefs *''hostdefs''' rxmatches dat
if. #c do.
  res=. (getsystemdefs 'hostdefs'),LF
end.
c=. 'jsystemdefs *''netdefs''' rxmatches dat
if. #c do.
  res=. res, (getsystemdefs 'netdefs'),LF
end.
if. #res do.
  'jsystemdefs_z_=: ]',LF,res
else.
  ''
end.
)
buildtargetfiles=: 3 : 0
if. 0=#XPRIMARYFILES do. '';'' return. end.
xpf=. XPRIMARYFILES
if. 0=IFREQSRC do.
  xpf=. fromfoldername xpf
  top=. LF cutopen 1!:1 {. xpf
  msk=. *./\ ('NB.'"_ -: 3: {. ]) &> top
  if. {. msk do.
    cmt=. (tolist msk # top), LF
    top=. (-.msk) # top
  else.
    cmt=. ''
  end.
  top=. tolist top
  cmt ; tolist2 top ; <@(1!:1) }.xpf
else.
  dat=. checkrequire ''
  f=. 'script <'''&, @ (,&'''')
  '' ; dat, LF ,~ tolist f each xpf
end.
)
buildtargetlibs=: 3 : 0
if. 0=#XPRIMARYLIBS do. '' return. end.
select. IFREQLIB
case. 0 do.
  libs=. reqlibs1 XPRIMARYLIBS
  fls=. fromfoldername getlibfiles libs
  nodepends tolist <@(1!:1) fls
case. 1 do.
  dat=. checkrequire ''
  libs=. getlibfiles XPRIMARYLIBS
  dat, ;'script_z_ '''&, each libs ,each <('''',LF)
case. do. ''
end.
)

CFG=: 0 : 0
pc cfg owner;pn "Configuration";
xywh 6 8 248 74;cc v1 groupbox rightmove;cn "Snapshots";
xywh 11 20 86 11;cc busesnaps checkbox;cn "Use Snapshots";
xywh 11 34 59 11;cc s3 static;cn "Max Snapshots:";
xywh 72 33 20 12;cc snaps edit ws_border es_autohscroll;
xywh 11 49 238 11;cc s4 static;cn "Exclusion List (comma separated):";
xywh 11 63 239 12;cc snapx edit ws_border es_autohscroll rightmove;
xywh 6 92 248 59;cc g0 groupbox rightmove;cn "Format Script";
xywh 11 107 238 11;cc btab radiobutton;cn "Tab with TAB characters (Hard tabs)";
xywh 11 120 238 11;cc bspc radiobutton group;cn "Tab with space characters (Soft tabs)";
xywh 11 134 39 11;cc s0 static;cn "Tab width:";
xywh 50 134 20 12;cc espc edit ws_border es_autohscroll;
xywh 275 12 44 12;cc ok button leftmove rightmove;cn "OK";
xywh 275 26 44 12;cc cancel button leftmove rightmove;cn "Cancel";
pas 6 6;pcenter;
rem form end;
)
cfg_run=: 3 : 0
if. y.=0 do.
  wd CFG
end.
USESNAPS=: 0 < PMSNAPS
MAXSNAPS=: PMSNAPS + 5 * PMSNAPS=0
CFSNAPX=: PMSNAPX
CFTABS=: PMTABS
cfg_show''
wd 'setfocus ok'
wd 'pshow'
)
cfg_refresh=: 3 : 0
cfg_read''
cfg_show''
)
cfg_busesnaps_button=: cfg_refresh
cfg_btab_button=: cfg_refresh
cfg_bspc_button=: cfg_refresh
cfg_ok_button=: 3 : 0
cfg_read''
PMSNAPS=: USESNAPS * MAXSNAPS
PMSNAPX=: CFSNAPX
PMTABS=: CFTABS
projcfgsave''
wd 'pclose'
wd 'psel ',HWNDP
wd 'setenable snapmake ',": 0 < PMSNAPS
wd 'setenable snapview ',": 0 < PMSNAPS
)
cfg_read=: 3 : 0
USESNAPS=: 0 ". busesnaps
MAXSNAPS=: 0 ". snaps
CFTABS=: (0 ". bspc), 0 ". espc
CFSNAPX=: deb each cutcommas snapx
)
cfg_show=: 3 : 0
b=. ": USESNAPS
wd 'set busesnaps ',b
wd 'setenable snaps ',b
wd 'setenable snapx ',b
wd 'set snaps ',": MAXSNAPS
wd 'set snapx *', 2 }. ; (<', ') ,each CFSNAPX
b=. 1 = 0 { CFTABS
wd 'set btab ', ": -. b
wd 'set bspc ', ": b
wd 'set espc ',": 1 { CFTABS
wd 'setenable espc ',": b
)
cfg_cancel_button=: wd bind 'pclose'

pathname=: 3 : '(b#y.);(-.b=.+./\.y.=PATHSEP)#y.'
fpath=: 3 : 'y.#~+./\.y.=PATHSEP'
fexist=: 1:@(1!:4)@boxopen :: 0:
fexists=: #~ fexist&>
extijp=: 3 : 0
y., ((0 < #y.) > '.ijp' -: _4 {. y.) # '.ijp'
)
extijs=: 3 : 0
y., ((0 < #y.) > '.ijs' -: _4 {. y.) # '.ijs'
)
extnone=: 3 : 0
(- 4 * (<_4 {. y.) e. '.ijp';'.ijs') }. y.
)
fullname=: 3 : 0
if. 0 = # y. do. '' return. end.
p=. PATHSEP
d=. fromfoldername1 y.
b=. (</ d i. ':',p) +. ('~' = {. d) +. (2{.d) -: 2#p
if. b do.
elseif. p ~: 1{.d do.
  d=. jcwdpath d
elseif. IFWIN32 do.
  d=. (2{.jcwdpath''),d
end.

if. IFWIN32 do. tolower d else. d end.
)
fullproject=: fullname @ extijp
fullscript=: (0: < #) # fullname @ extijs
pidname=: 3 : 0
y=. PIDPATH drophead extnone y.
x=. <;.1 PATHSEP,y
if. =/ _2 {. x do. }. ; }: x else. y end.
)
ppath=: 3 : '0 pick pathname PROJECTFILE'
plinkpath=: 3 : '0 pick pathname jpath PLINK'
shortname=: 3 : 0
if. 0 e. # y. do. '' return. end.
files=. y.
full=. fromfoldername y.
path=. ppath''
len=. #path
ndx=. I. (<path) = len {. each full
(len }. each ndx { full) ndx } files
)
shortname1=: 3 : '> shortname <y.'
fixrelative1=: 3 : 0
fn=. y.
if. 0 = #fn do. return. end.
if. '~' = {. fn do. return. end.
if. PATHSEP = {. fn do. return. end.
if. IFWIN32 *. ':' = 1 { fn,':' do. return. end.
tofoldername1 fullname fn
)

fromfoldername=: 3 : 0
nms=. boxxopen y.
ind=. I. '~' = ({. @ (,&' ')) &> nms
new=. }. each ind { nms
ndx=. <./ @ (i.&'/\') &> new
tag=. ndx {. each new
par=. '.' = {. &> tag
len=. ('.'&= i. 0:) &> tag
tag=. len }. each tag
inx=. PPIDS i. tag
msk=. inx < # PPIDS
hdr=. (msk # inx) { PPATHS
if. 1 e. msk # par do.
  sel=. I. msk # par
  shd=. sel { hdr
  f=. #@] | ([: +/\. ] e. '/\'"_) i: [
  top=. (sel { len) f each shd
  shd=. top {. each shd
  hdr=. shd sel } hdr
end.
new=. hdr ,each msk # ndx }. each new
nms=. new (msk # ind) } nms
jhostpath each nms
)
fromfoldername1=: 3 : 0
nam=. , > y.
if. '~' = {. nam do.
  ind=. <./ nam i. '/\'
  tag=. }. ind {. nam
  par=. '.' = {. tag
  if. par do.
    len=. ('.' = tag) i. 0
    tag=. len }. tag
  end.
  ndx=. PPIDS i. <tag
  if. ndx < # PPIDS do.
    bal=. ind }. nam
    pfx=. ndx pick PPATHS
    if. par do.
      pfx=. ((#pfx) | (+/\. pfx e. '/\') i: len) {. pfx
    end.
    nam=. pfx,bal
  end.
end.
jhostpath nam
)
getfoldernames=: 3 : 0
folders=. SYSTEMFOLDERS,USERFOLDERS
folders=. folders \: # &> {:"1 folders
PPATHS=: {:"1 folders
if. IFWIN32 do.
  PPATHS=: tolower each PPATHS
end.
PPIDS=: {."1 folders
)
tofoldername1=: 3 : 0
nam=. y.
if. '~' = {. nam,'~' do. return. end.

if. IFWIN32 do. nam=. tolower nam end.

pps=. PPATHS ,each PATHSEP
len=. # &> pps
msk=. pps = len {. each <nam
if. 1 e. msk do.
  ndx=. ((i. >./) msk # len) { I. msk
  '~', (ndx pick PPIDS),(<: ndx { len) }. nam return.
end.

pid=. PIDPATH
msk=. pid = (#pid) {. nam
ndx=. msk i. 0
if. ndx <: 1 do. nam return. end.
if. 1 >: +/ PATHSEP = ndx {. pid do. nam return. end.
cnt=. (+/ PATHSEP = ndx }. pid) - getdepth''
'~', (cnt # '.'), PID, (<:ndx) }. nam
)
jflin=: 4 : 0
x=. boxxopen x.
y=. a: -.~ boxxopen y.
(fromfoldername x) e. fromfoldername y
)
jflminus=: 4 : 0
x=. boxxopen x.
y=. a: -.~ boxxopen y.
(-. (fromfoldername x) e. fromfoldername y) # x
)


cutdeb=: [: -.&a: <@deb;._2@termLF

pr1=: (fixrelative1 @ extijs each) @: cutdeb
pr2=: cutdeb
pr3=: cutopen @ termLF
pr4=: fixrelative1 @ extijs
pr5=: (fixrelative1 each) @: cutdeb

tr1=: tolist @: (extnone each)
tr2=: tolist
changedepth=: 3 : 0
if. 0 = #PROJECTFILE do. return. end.
if. y.=1 do.
  a=. PIDPATH&drophead each PJFILES
  PIDTREE=: (PID,PATHSEP) &, each ~.(a i.&> PATHSEP) {. each a
  path=. getpidpath PID
  rest=. path drophead PROJECTFILE
  ndx=. rest i. PATHSEP
  dir=. ndx {. rest
  PID=: PID, PATHSEP, dir
  PIDPATH=: PIDPATH, dir, PATHSEP
  msk=. (<PIDPATH) = (#PIDPATH) {.each PJFILES
  PJFILES=: msk # PJFILES
else.
  ndx=. PID i: PATHSEP
  PID=: ndx {. PID
  ndx=. 1 + (}:PIDPATH) i: PATHSEP
  PIDPATH=: ndx {. PIDPATH
  PJFILES=: fullproject each projgetfiles PIDPATH
  setpidtree''
end.
projsetlookin''
)
deletefile=: 3 : 0

p=. ppath''
j=. '"Script Files (*.ijs)|*.ijs|Text Files (*.txt)|*.txt|'
j=. j,'All Files (*.*)|*.*" ofn_nochangedir'
f=. wd 'mbopen "Delete File" "',p,'" "" ',j

if. ''-:f do. return. end.

if. 0=fexist f do. return. end.

if. 1=2 query 'OK to delete: ',f,'?' do. return. end.

file=. <f

1!:55 file
XPRIMARYFILES=: XPRIMARYFILES jflminus file
XDEVFILES=: XDEVFILES jflminus file
XOTHERFILES=: XOTHERFILES jflminus file
showfiles''
)
fixfret=: 4 : 0
fls=. {."1 dirtree y.
res=. ''
if. x. -: CRLF do.
  tofret=. toCRLF
else.
  tofret=. toJ
end.
for_f. fls do.
  dat=. 1!:1 f
  if. 2 = 3!:0 dat do.
    fix=. tofret dat
    if. -. fix -: dat do.
      fix 1!:2 f
      res=. res,f
    end.
  end.
end.
if. #res do.
  }. ; LF ,each (#y.) }. each res
else.
  empty''
end.
)

fixfretCRLF=: CRLF & fixfret
fixfretLF=: LF & fixfret
getdepth=: 3 : 0
+/ PID = PATHSEP
)
getmaxdepth=: 3 : 0
if. 0 = #PROJECTFILE do. 0 return. end.
path=. getpidpath (PID i. PATHSEP) {. PID
0 >. <: +/ PATHSEP = path drophead PROJECTFILE
)
getpidpath=: 3 : 0
pid=. y.
ind=. pid i. PATHSEP
ndx=. ({."1 USERFOLDERS) bcfind <ind {. pid
if. ndx ~: _1 do.
  t=. (> {: ndx{USERFOLDERS),ind }. pid
else.
  t=. pid
end.
fullname addfret t
)
projgetfiles=: 3 : 0
p=. addfret y.
files=. projtree p
if. IFWIN32 do.
  files=. tolower each files
end.
sort files
)
projinit=: 3 : 0
projcfgread''
PID=: ''  
if. #PROJECTFILE do.
  openprojectfile PROJECTFILE
elseif. #XPROJECTRECENT do.
  openprojectfile 0 pick XPROJECTRECENT
elseif. 1 do.
  setprojpathfile 0 pick {.USERFOLDERS,a:
end.
1
)
projread=: 3 : 0
projreset''
projread1''
)
projread1=: 3 : 0
getfoldernames''
loadscript PROJECTFILE

BUILDOPTS=: (#DEFBUILDOPTS) {. BUILDOPTS,(#BUILDOPTS)}.DEFBUILDOPTS

if. '<' = {. PRIMARYFILES do.
  PLINKLAST=: PLINK=: }. PRIMARYFILES
  PRIMARYFILES=: 'PRIMARYFILES' readlink1 PLINK
  PLINKOLD=: PRIMARYFILES
else.
  PLINK=: ''
end.

OTHERFILES=: jhostpath OTHERFILES
PRIMARYFILES=: jhostpath PRIMARYFILES
DEVFILES=: jhostpath DEVFILES
TARGETFILE=: jhostpath TARGETFILE
PREBUILDFILE=: jhostpath PREBUILDFILE
POSTBUILDFILE=: jhostpath POSTBUILDFILE
TESTFILE=: jhostpath TESTFILE

XPRIMARYFILES=: pr1 PRIMARYFILES
XDEVFILES=: pr1 DEVFILES
XPRIMARYLIBS=: pr2 PRIMARYLIBS
XDEVLIBS=: pr2 DEVLIBS
XOTHERFILES=: pr5 OTHERFILES
XTARGETLOCALE=: TARGETLOCALE
XTARGETHEADER=: TARGETHEADER
XTARGETEXTRA=: TARGETEXTRA

XTARGETFILE=: pr4 TARGETFILE
XPREBUILDFILE=: pr4 PREBUILDFILE
XPOSTBUILDFILE=: pr4 POSTBUILDFILE
XTESTFILE=: pr4 TESTFILE

XBUILDOPTS=: BUILDOPTS
XNOTES=: NOTES
XWINDOWS=: pr3 WINDOWS
XOLD=: ".each XPFILENAMES
XWINDOWSTATE=: WINDOWSTATE=: 0

)
projcopyback=: 3 : 0
getfoldernames''

PRIMARYFILES=: tr1 XPRIMARYFILES

DEVFILES=: tr1 XDEVFILES
PRIMARYLIBS=: tr2 XPRIMARYLIBS
DEVLIBS=: tr2 XDEVLIBS
OTHERFILES=: tr2 XOTHERFILES

TARGETLOCALE=: XTARGETLOCALE
TARGETHEADER=: XTARGETHEADER
TARGETEXTRA=: XTARGETEXTRA

TARGETFILE=: XTARGETFILE
PREBUILDFILE=: XPREBUILDFILE
POSTBUILDFILE=: XPOSTBUILDFILE
TESTFILE=: XTESTFILE

BUILDOPTS=: XBUILDOPTS
NOTES=: XNOTES
WINDOWS=: tolist XWINDOWS
WINDOWSTATE=: XWINDOWSTATE=: 0
if. #PLINK do.
  if. -. PLINKOLD -: PRIMARYFILES do.
    (nounrep 'PRIMARYFILES') writelink1 PLINK
  end.
  PRIMARYFILES=: '<',PLINK
end.

empty''
)
projsave=: 3 : 0
if. (y.=0) *. XOLD -: ".each XPFILENAMES do. return. end.
pn=. extnone extnone PROJECTFILE
hdr=. 'NB. project file: ',pn,LF,LF
hdr=. hdr,'coclass ''jproject''',LF
nms=. PFILENAMES
dat=. hdr, ; LF&, each nounrep each nms
dat flwrites PROJECTFILE
XOLD=: ".each XPFILENAMES
)
projsavenew=: 3 : 0
projcopyback''
projsave 0
)
projsaveok=: 3 : 0
if. 0 e. #PROJECTFILE do. return. end.
if. 0 = XOLD -: ".each XPFILENAMES do.
  if. 0=2 query 'Project has changed. Save it?' do.
    projsavenew''
  end.
end.
)
projsaveokc=: 3 : 0
res=. 1
if. #PROJECTFILE do.
  if. 0 = XOLD -: ".each XPFILENAMES do.
    j=. 3 query 'Project has changed. Save it?'
    res=. j e. 0 1
    if. j=0 do. projsavenew'' end.
  end.
end.
res
)
selproj=: (#~ ([:(<'.ijp')&=_4&{.&.>)) @: ({."1)
seldir=: #~ '-d'&-:"1 @ (1 4&{"1) @ > @ (4&{"1)
projtree=: 3 : 0
r=. ''
t=. y.
ps=. PATHSEP_j_
if. #t do. t=. t, ps -. {:t end.
dirs=. <t
while. #dirs do.
  fpath=. (>{.dirs) &,
  dirs=. }. dirs
  dat=. 1!:0 fpath '*'
  if. #dat do.
    drs=. seldir dat
    if. #drs do.
      dirs=. (fpath @ (,&ps) each {."1 drs),dirs
    end.
    r=. r, fpath each selproj dat
  end.
end.
if. IFWIN32 do.
  r=. tolower each r
end.
/:~ r
)
setpidtree=: 3 : 0

if. -. PATHSEP e. PID do.
  res=. {."1 getpmfolders USERFOLDERS
else.
  
  pid=. (PID i: PATHSEP) {. PID
  path=. (1 + (}:PIDPATH) i: PATHSEP) {. PIDPATH
  a=. (#path) }. each projgetfiles path
  res=. (pid,PATHSEP)&, each ~. (a i.&> PATHSEP) {. each a
end.
PIDTREE=: res
)
setprojpath=: 3 : 0
projreset''
PID=: y.
PIDPATH=: getpidpath PID
setpidtree''
PJFILES=: fullproject each projgetfiles PIDPATH
projsetlookin''
)
setprojpathfile=: 3 : 0
setprojpath y.
if. -. (<PROJECTFILE) e. PJFILES do.
  PROJECTFILE=: fromfoldername1 0 pick PJFILES,a:
end.
)

LFILES=: 0 : 0
pc lfiles;
xywh 3 3 55 11;cc z0 static;cn "Select From:";
xywh 2 15 67 147;cc libfrom listbox ws_vscroll rightscale bottommove;
xywh 74 3 55 11;cc z1 static leftscale rightscale;cn "Selected:";
xywh 73 15 67 147;cc libto listbox ws_vscroll leftscale rightmove bottommove;
xywh 144 11 36 12;cc open button leftmove rightmove;cn "&Open";
xywh 144 24 36 12;cc view button leftmove rightmove;cn "&View";
xywh 144 37 36 12;cc print button leftmove rightmove;cn "&Print";
xywh 144 50 17 11;cc lmove button leftmove rightmove;cn "&<<";
xywh 163 50 17 11;cc rmove button leftmove rightmove;cn "&>>";
xywh 144 146 36 12;cc cancel button leftmove topmove rightmove bottommove;cn "Close";
pas 2 2;
rem form end;
)
lfiles_run=: 3 : 0
wd LFILES
wd 'pshow;'
)
lfiles_cancel_button=: closeproject
lfiles_rlibs=: 3 : 0
~. (req -. ]) getlibfiles XPRIMARYLIBS,XDEVLIBS
)
lfiles_show=: 3 : 0

d1=. req x1=. getlibfiles XPRIMARYLIBS
f=. XPRIMARYLIBS

d2=. req x2=. getlibfiles XDEVLIBS
d1=. d1 -. x1,x2
d2=. d2 -. d1,x1,x2
d1=. getlibids d1
d2=. getlibids d2
RLIBS=: d1,d2
XLIBS=: XPRIMARYLIBS,d1,XDEVLIBS,d2
f=. f, (,&' (r)') each d1
f=. f, (,&' (d)') each XDEVLIBS
f=. f, (,&' (dr)') each d2

j=. (getliball'') -. XPRIMARYLIBS,XDEVLIBS
wd 'set libfrom *', tolist j
wd 'set libto *', tolist f
)
lfiles_rmove_button=: 3 : 0
if. -. 0 e. #libfrom do.
  XPRIMARYLIBS=: sort XPRIMARYLIBS,<libfrom
  lfiles_show''
end.
)
lfiles_lmove_button=: 3 : 0
if. -. 0 e. #libto do.
  file=. (".libto_select) { XLIBS
  if. file e. RLIBS do.
    info 'Cannot deselect required files' return.
  end.
  XPRIMARYLIBS=: XPRIMARYLIBS -. file
  XDEVLIBS=: XDEVLIBS -. file
  lfiles_show''
end.
)
lfiles_libfrom_button=: lfiles_rmove_button
lfiles_libto_button=: lfiles_lmove_button
lfiles_open_button=: popenfiles
lfiles_view_button=: viewfile
lfiles_print_button=: sprintfiles
lfiles_dev=: 3 : 0
if. 0 e. #libto_select do.
  if. #libfrom_select do.
    info 'Dev File applies only to files in the Selected list' return.
  else.
    infonosel'' return.
  end.
end.
file=. (".libto_select) { XLIBS
if. file e. RLIBS do.
  info 'Dev File does not apply to required files' return.
end.
p=. file -. XPRIMARYLIBS
q=. file -. XDEVLIBS
XPRIMARYLIBS=: sort p , XPRIMARYLIBS -. q
XDEVLIBS=: sort q, XDEVLIBS -. p
lfiles_show''
)

LINK=: 0 : 0
pc link owner;pn "Project Link";
xywh 216 7 45 12;cc ok button leftmove rightmove;cn "OK";
xywh 216 22 45 12;cc cancel button leftmove rightmove;cn "Cancel";
xywh 9 8 198 45;cc g0 groupbox rightmove;cn "Link Project";
xywh 15 20 133 11;cc enablelink checkbox;cn "Enable Link";
xywh 14 34 190 12;cc projlink edit ws_border es_autohscroll rightmove;
xywh 156 19 45 12;cc bprojlink button leftmove rightmove;cn "Browse...";
pas 3 4;pcenter;
rem form end;
)
link_run=: 3 : 0
wd LINK
link_show 0 < #PLINK
wd 'set projlink *',PLINK
wd 'setfocus ok'
wd 'pshow;'
)
link_bprojlink_button=: 3 : 0
'p f'=. pathname (0<#projlink) pick PLINKLAST;projlink
j=. '"Project Files (*.ijp)|*.ijp" ofn_filemustexist ofn_nochangedir'
r=. wd 'mbopen "Select File" "',p,'" "',f,'" ',j
if. #r do.
  wd 'set projlink *',r
end.
)
link_enablelink_button=: 3 : 0
on=. '1' = enablelink
if. -. on do.
  if. #projlink do.
    if. 2 query 'Confirm remove project link?' do. return. end.
  end.
end.
link_show on
)
link_show=: 3 : 0
if. y. do.
  wd 'set enablelink 1'
  wd 'setenable projlink 1'
else.
  wd 'set enablelink 0'
  wd 'setenable projlink 0'
  wd 'set projlink'
end.
)
link_ok_button=: 3 : 0
on=. '1' = enablelink
if. on do.
  if. 0 = #projlink do.
    info 'First set project link' return.
  end.
  if. PROJECTFILE -: jpath projlink do.
    msg=. 'The linked project is the same as the current project file.'
    msg=. msg,LF,LF,'Select another project or remove the link.'
    info msg return.
  end.
  projlink=. tofoldername1 projlink
  if. -. (fromfoldername1 projlink) -: fromfoldername1 PLINK do.
    PLINKLAST=: PLINK=: projlink
    if. 0 -: pfs=. 'PRIMARYFILES' readlink1 PLINK do. return. end.
    PRIMARYFILES=: pfs
    XPRIMARYFILES=: pr1 PRIMARYFILES
    PLINKOLD=: PRIMARYFILES
  end.
else.
  if. #PLINK do.
    PLINKOLD=: XPRIMARYFILES=: PRIMARYFILES=: PLINK=: ''
  end.
end.
wd 'pclose'
showfiles''
)
link_close=: link_ok_button
ink_cancel=: link_cancel_button=: wd bind 'pclose'
readlink1=: 4 : 0
nam=. > x.
a=. freads jpath y.
if. a -: _1 do.
  info 'Unable to read link project: ',y.
  0 return.
end.
x=. 1 i.~ (nam,'=: ') E. a
a=. (x + 3 + #nam) }. a
if. '0' = {.a do.
  a=. (1 + a i. LF) }. a
  (1 i.~ (LF,')') E. a) {. a
else.
  a=. }. a
  (a i. '''') {. a
end.
)
writelink1=: 4 : 0
f=. jpath y.
a=. 'b' freads f
a=. a ,each LF
b=. (1: e. '=: '&E.) &> a
b=. 1 (0) } b
a=. b <@; ;.1 a
h=. (1 + x. i. ' ') {. x.
ndx=. 1 i. ~ (<h) = (#h) {.each a
if. ndx < # a do.
  a=. (<x.,LF) ndx } a
else.
  a=. a , <x.,LF
end.
a=. ; a
a fwrites f
)
readlinkedproject=: 4 : 0
cocurrent x.
coclass=: ]
0!:0 <y.
)

WNOTE=: 0 : 0
pc wnote owner;
xywh 2 3 55 9;cc z0 static;cn "Notes:";
xywh 0 12 141 127;cc noteedit editm ws_border ws_hscroll ws_vscroll rightmove bottommove;
xywh 105 1 36 12;;cc cancel button leftmove rightmove;cn "Close";
pas 0 0;
rem form end;
)
wnote_run=: 3 : 0
if. wdisparent 'wnote' do.
  wd 'psel wnote;pactive' return.
end.
pos=. wd 'qformx'
wd WNOTE
wd 'set noteedit *',XNOTES
wd 'setfocus noteedit'
wdcenter pos
wd 'pshow'
)
wnoteclose=: 3 : 0
XNOTES=: termLF (#~ +./\.@(~:&LF)) noteedit
wd 'pclose'
wd 'psel projectform;pactive'
)

wnote_cancel_button=: wnote_cancel=: wnote_close=: wnoteclose

WOTHER=: 0 : 0
pc wother owner;
xywh 3 3 55 11;cc s0 static;cn "Other Files:";
xywh 2 15 138 147;cc spfiles listbox ws_hscroll ws_vscroll lbs_extendedsel rightmove bottommove;
xywh 144 11 36 12;cc bopen button leftmove rightmove;cn "&Open";
xywh 144 24 36 12;cc bview button leftmove rightmove;cn "&View";
xywh 144 37 36 12;cc bprint button leftmove rightmove;cn "&Print";
xywh 144 50 36 12;cc add button leftmove rightmove;cn "&Add";
xywh 144 63 36 12;cc remove button leftmove rightmove;cn "&Remove";
xywh 144 146 36 12;cc cancel button leftmove topmove rightmove bottommove;cn "Close";
pas 0 0;
rem form end;
)
wother_run=: 3 : 0
wd WOTHER
wd 'pshow;'
)
wother_cancel_button=: closeproject
wother_show=: 3 : 0
XOTHERFILES=: XOTHERFILES jflminus XPRIMARYFILES,XDEVFILES,buildfiles''
wd 'set spfiles *',tolist shortname XOTHERFILES
)
wother_add_button=: 3 : 0
if. 0=#PROJECTFILE do. infonoproj'' return. end.
p=. ppath''

j=. '"Script Files (*.ijs)|*.ijs|Project Files (*.ijp)|*.ijp|'
j=. j,'Lab Files (*.ijt)|*.ijt|Text Files (*.txt)|*.txt|'
j=. j,'All Files (*.*)|*.*"'
j=. j,' ofn_nochangedir'
f=. wd 'mbopen "Other File" "',p,'" "" ',j
if. '' -: f do. return. end.

f=. f, (-. '.' e. f) # '.ijs'

if. f jflin XPRIMARYFILES, XDEVFILES, XOTHERFILES, buildfiles'' do.
  info 'already in project: ',shortname1 f return.
end.
if. 0=fexist f do. '' flwrites f end.

XOTHERFILES=: /:~ XOTHERFILES, < tofoldername1 f
wother_show''
)
wother_remove_button=: 3 : 0
if. 0 e. #spfiles do. infonosel'' return. end.

files=. (".spfiles_select) { XOTHERFILES
ff=. tolist shortname files
if. 1=2 query 'OK to remove:',LF,LF,ff do. return. end.

XOTHERFILES=: XOTHERFILES jflminus files
wother_show''
)
wother_bopen_button=: popenfiles
wother_bview_button=: viewfile
wother_bprint_button=: sprintfiles
wother_spfiles_button=: popenfiles

WPPATH=: 0 : 0
pc wppath closeok owner;pn "Folders";
xywh 3 1 156 88;cc g0 groupbox rightmove bottommove;cn "";
xywh 8 8 46 8;cc s0 static;cn "Name";
xywh 61 8 62 8;cc s1 static;cn "Folder Path";
xywh 7 16 148 58;cc types listbox ws_hscroll ws_vscroll rightmove bottommove;
xywh 8 75 38 11;cc up button topmove bottommove;cn "Move &Up";
xywh 49 75 38 11;cc down button topmove bottommove;cn "Move Do&wn";
xywh 115 75 38 11;cc delete button topmove bottommove;cn "&Delete";
xywh 3 93 156 45;cc g0 groupbox topmove rightmove bottommove;cn "";
xywh 8 100 22 9;cc label static topmove bottommove;cn "Name:";
xywh 33 99 122 11;cc desc edit ws_border es_autohscroll topmove rightmove bottommove;
xywh 8 112 22 9;cc label static topmove bottommove;cn "Folder:";
xywh 33 111 122 11;cc efolder edit ws_border es_autohscroll topmove rightmove bottommove;
xywh 8 124 38 11;cc addtop button topmove bottommove;cn "Add at &top";
xywh 49 124 38 11;cc addend button topmove bottommove;cn "Add at &end";
xywh 115 124 38 11;cc replace button topmove bottommove;cn "&Replace";
xywh 162 6 36 12;;cc ok button leftmove rightmove;cn "OK";
xywh 162 21 36 12;;cc cancel button leftmove rightmove;cn "Cancel";
pas 2 2;pcenter;
rem form end;
)
wppath_run=: 3 : 0
XPP=: USERFOLDERS -. TXPP

pos=. wd 'qformx'
wd WPPATH
wdcenter pos
wd 'settabstops types 60'
XNDX=: ({."1 XPP) bcfind <PID
wppathshow''
wd 'pshow;'
)
wppathshow=: 3 : 0
if. #XPP do.
  'a b'=. |: XPP
  j=. }. , LF ,. '"' ,. a ,. TAB ,"1 b ,. '"'
  wd 'set types ', j
  wd 'setselect types ',": XNDX
  wppathshowdetails''
end.
)
wppathshowdetails=: 3 : 0
if. 0 <: XNDX do.
  'j k'=. XNDX { XPP
  wd 'set desc *',j
  wd 'set efolder *',delfret k
end.
)
wppath_cancel_button=: 3 : 0
wd :: [ 'pclose;'
wd 'psel projectform;'
)

wppath_cancel=: wppath_cancel_button
wppath_up_button=: 3 : 0
if. #ndx=. ". types_select do.
  ind=. ndx, ndx1=. 0 >. ndx-1
  XPP=: (|.ind{XPP) ind} XPP
  XNDX=: ndx1
  wppathshow''
end.
)
wppath_down_button=: 3 : 0
if. #ndx=. ". types_select do.
  ind=. ndx, ndx1=. (<:#XPP) <. ndx+1
  XPP=: (|.ind{XPP) ind} XPP
  XNDX=: ndx1
  wppathshow''
end.
)
wppath_delete_button=: 3 : 0
if. #ndx=. ". types_select do.
  if. 1=#XPP do.
    info 'You cannot delete the only folder' return.
  end.
  msg=. 'OK to delete: ',>{.ndx{XPP
  if. 0=2 query msg do.
    XPP=: XPP #~ -. (i.#XPP) e. ndx
    XNDX=: (<:#XPP) <. ndx
    wppathshow''
  end.
end.
)
wppath_types_select=: 3 : 0
XNDX=: ". types_select
wppathshowdetails''
)
wppath_addtop_button=: 3 : 0
if. wppath_addcheck 0 do.
  XPP=: ~. (desc;efolder),XPP
  XNDX=: 0
  wppathshow''
end.
)
wppath_addend_button=: 3 : 0
if. wppath_addcheck 0 do.
  XPP=: ~. XPP, desc;efolder
  XNDX=: ({."1 XPP) i. <desc
  wppathshow''
end.
)
wppath_replace_button=: 3 : 0
if. wppath_addcheck 1 do.
  if. #ndx=. ". types_select do.
    XPP=: (desc;efolder) ndx} XPP
    XNDX=: ndx
    wppathshow''
  end.
end.
)
wppath_addcheck=: 3 : 0

desc=: deb desc
efolder=: deb efolder

if. (desc;efolder) e. XPP do. 0 return. end.
r=. 0

if. 0=#desc do.
  info 'Enter the name'
elseif. 20<#desc do.
  info 'Name may not exceed 20 characters'
elseif. 0=#efolder do.
  info 'Enter the folder paths'
elseif. y. < (<desc) e. {."1 XPP do.
  info 'Name already in use'
elseif. y. < (<efolder) e. {:"1 XPP do.
  info 'Folder already in use'
elseif. 1 do. r=. 1
end.

r
)
wppath_close=: 3 : 0

if. -. USERFOLDERS -: XPP do.
  TXPP=: TXPP -. XPP
  USERFOLDERS_j_=: XPP, TXPP
  projcfgsave''
  saveuserfolders''
end.

if. #types_select do.
  p=. ({.".types_select) { USERFOLDERS
else.
  p=. 0 pick {.USERFOLDERS
end.

'pp pd'=. p

if. -. p -: PID;PIDPATH do.
  projsaveok''
  setprojpathfile pp
  projectform_load''
end.

wd :: [ 'psel wppath;pclose'
wd 'psel projectform;pactive'
)
wppath_ok_button=: wppath_close

CFGHDR=: ; < @ ('NB. '&,) ;.2 (0 : 0)
Projects configuration

defines:
PMSNAPS           snapshots
PMSNAPX           snapshot exclusion list
PMTABS            use tabs, tab width for convert to spaces
PROJECTLOOKIN     last project "look in"
PROJECTRECENT     recent project loads
)
projsplit=: 3 : 0
if. 0 < L. y. do. y. return. end.
if. 0=#y. do. '';'' return. end.
dat=. <;._2 y.
g=. i.&' '
h=. g (toblank@{. ; deb@}.) ]
h &> dat
)
projcfgread=: 3 : 0
PMTABS=: 0 2
PMSNAPS=: 0
PMSNAPX=: ''
PROJECTLOOKIN=: ''
PROJECTRECENT=: ''
try. 0!:0 <PROJECTCFG catch. end.
XPROJECTRECENT=: fexists fullproject each cutopen PROJECTRECENT
XPROJECTLOOKIN=: fullname PROJECTLOOKIN
)
projcfgsave=: 3 : 0
PROJECTRECENT=: tolist extnone each XPROJECTRECENT
PROJECTLOOKIN=: extnone XPROJECTLOOKIN
dat=. CFGHDR
dat=. dat,LF,nounrep 'PMSNAPS'
dat=. dat,LF,nounrep 'PMSNAPX'
dat=. dat,LF,nounrep 'PMTABS'
dat=. dat,LF,nounrep 'PROJECTLOOKIN'
dat=. dat,LF,nounrep 'PROJECTRECENT'
dat flwrites PROJECTCFG
)
projaddrecent=: 3 : 0
if. -. (<PROJECTFILE) -: {.1{.XPROJECTRECENT do.
  XPROJECTRECENT=: ({.~ MAXRECENT"_ <. #) ~. (<PROJECTFILE),XPROJECTRECENT
  projcfgsave''
end.
)
projsetlookin=: 3 : 0
if. -. PIDPATH -: XPROJECTLOOKIN do.
  XPROJECTLOOKIN=: PIDPATH
  projcfgsave''
end.
)

RECENT=: 0 : 0
pc precent nomin owner;pn "Recent Projects";
xywh 4 8 51 10;cc s0 static;cn "Project Files:";
xywh 3 18 174 123;cc l0 listbox ws_vscroll rightmove bottommove;
xywh 95 5 40 12;cc cancel button leftmove rightmove;cn "Cancel";
xywh 136 5 40 12;cc ok button bs_defpushbutton leftmove rightmove;cn "OK";
pas 2 2;pcenter;
rem form end;
)
precent_run=: 3 : 0

if. 0 e. #XPROJECTRECENT do.
  info 'No recent project files' return.
end.

projsaveok''

rp=. extnone each XPROJECTRECENT

pos=. wd 'qformx'
wd RECENT
wdcenter pos

wd 'set l0 *', tolist rp
wd 'setselect l0 0'
wd 'setfocus l0'
wd 'pshow'
)
precent_close=: 3 : 0
wd 'pclose'
wd 'psel projectform;pactive'
)
precent_doit=: 3 : 0
wd 'pclose'
if. #l0 do.
  wd 'psel projectform'
  openprojectfile fullproject l0
  projaddrecent''
  projectform_show''
end.
wd 'psel projectform;pactive'
)
precent_enter=: precent_ok_button=: precent_l0_button=: precent_doit
precent_cancel=: precent_cancel_button=: precent_close
plast_run=: 3 : 0
j=. XPROJECTRECENT -. < PROJECTFILE
if. 0 e. #j do.
  info 'No recent project files' return.
end.
projsaveok''
openprojectfile >{.j
projaddrecent''
projectform_show''
)

RX=: '^(load|require|script<|script_z_<|script <|script_z_) *(''(''''|[^''])*'')'

reqread=: 1!:1 :: (''"_)
reqscripts=: getlibfiles @ ; @: (cutopen@".&.>)
reqlibs=: getlibids @: req @: getlibfiles
reqlibs1=: 3 : 0
a=. y.
b=. ''
while. -. '' -: r=. reqlibs a do.
  a=. r [ b=. r,b
end.
~.b,y.
)
getliball=: 3 : 0
sort STDLIBS -.~ ~. {."1 PUBLIC
)
getlibfiles=: 3 : 0
f=. (0{"1 PUBLIC),y.
t=. (1{"1 PUBLIC),y.
t {~ f i. y.
)
getlibids=: 3 : 0
s=. extnone each y.
f=. (1{"1 PUBLIC),y.
t=. (0{"1 PUBLIC),s
t {~ f i. y.
)
nodepends=: 3 : 0
if. 0=#y. do. '' return. end.
dat=. (LF,LF),y.
hit=. RX rxmatches_jregex_ dat
if. 0=#hit do. y. return. end.
ndx=. 0, {.@(1&{)"2 hit
dat=. ((i.#dat) e. ndx) <;.1 dat
dat=. 6 }. ; 'NB. '&, each dat
)
req=: 3 : 0
RXH=: rxcomp_jregex_ RX
files=. fromfoldername boxxopen y.
done=. ''
found=. i.0 2
while. #files do.
  done=. done,f=. {.files
  r=. req1 f
  found=. found, r ,. f
  files=. ~. (}.files), r -. done
end.
rxfree_jregex_ RXH
reqsort found
)
req1=: 3 : 0
dat=. reqread < jpath > y.
if. 0=#dat do. '' return. end.
hit=. RXH rxmatches_jregex_ LF,dat
if. 0=#hit do. '' return. end.
reqscripts (2{"2 hit) rxfrom_jregex_ LF,dat
)
reqsort=: 3 : 0
b=. {."1 y.
e=. {:"1 y.
r=. ''
while. #b do.
  n=. b -. e
  if. 0=#n do. n=. {.b end.
  r=. r,n
  msk=. -. b e. n
  e=. msk#e
  b=. msk#b
end.
~. r
)

loadproject=: 4 : 0
f=. jpath extijp y.
if. 0=fexist f do.
  info 'not found: ',f return.
end.
setprojfile fullname f
projcfgread''
projread''
runprojectfiles 'p' e. x.
)
runproject=: 3 : 0
if. 0=#PROJECTFILE do. infonoproj'' return. end.
runproject1 0
)
runproject1=: 3 : 0
saveopenwindows''
projsaveok''
j=. y. pick 'loadp ';'''c'' loadp ';'''cp'' loadp '
('   ',j,'''',PROJECTFILE,'''') 1!:2 [ 2
runprojectfiles y.=2
)
runprojectfiles=: 3 : 0
projaddrecent ''
if. y.=1 do.
  l=. PRIMARYLIBS
  f=. XPRIMARYFILES
else.
  l=. PRIMARYLIBS,LF,DEVLIBS
  f=. XPRIMARYFILES,XDEVFILES
end.
load l
if. #f do.
  f=. extijs each f  
  if. #XTARGETLOCALE do.
    if. 0 = 4!:0 <'COCLASSPATH_',XTARGETLOCALE,'_' do.
      cocurrent XTARGETLOCALE
    else.
      coclass XTARGETLOCALE
    end.
  else.
    cocurrent 'base'
  end.
  load f
end.
)

runtest=: 3 : 0
stk=. 13!:13''
if. # stk do.
  nms=. ;: 'runtest projectform_runtest_button wdhandler_jproject_'
  if. -. nms -: {."1 stk do.
    smoutput 'Stack cleared - run Test again'
    jdb_close_jdebug_ :: ] ''
    return.
  end.
end.
13!:0 [ 13!:17 ''
f=. fromfoldername1 XTESTFILE
if. 0=#f do. info 'No test file defined' return. end.
if. 0=fexist f do. info 'Not found: ',LF,LF,f return. end.
saveopenwindows''
runimmx0 '0!:0 <''',f,''''
)

SFILES=: 0 : 0
pc sfiles;
xywh 3 3 55 11;cc s0 static;cn "Files:";
xywh 2 15 138 147;cc filelist listbox ws_vscroll lbs_extendedsel rightmove bottommove;
xywh 144 11 36 12;cc open button leftmove rightmove;cn "&Open";
xywh 144 24 36 12;cc view button leftmove rightmove;cn "&View";
xywh 144 37 36 12;cc print button leftmove rightmove;cn "&Print";
xywh 144 50 36 12;cc add button leftmove rightmove;cn "&Add";
xywh 144 63 36 12;cc remove button leftmove rightmove;cn "&Remove";
xywh 144 146 36 12;cc cancel button leftmove topmove rightmove bottommove;cn "Close";
pas 0 0;
rem form end;
)
sfiles_run=: 3 : 0
wd SFILES
wd 'pshow;'
)
sfiles_cancel_button=: closeproject
sfiles_show=: 3 : 0
wd 'psel projectform'
if. 0=#PROJECTFILE do.
  wd 'set filelist *' return.
else.
  wd 'set filelist *', getfilelist''
  if. #y. do.
    ndx=. XFILES i. y.
    ndx=. ndx #~ ndx = ({.ndx)+i.#ndx
    wd@('setselect filelist '&,@":) &> ndx
  end.
  wd 'setshow filelist 0;setshow filelist 1'
end.
)
sfiles_add_button=: 3 : 0
if. 0=#PROJECTFILE do. infonoproj'' return. end.
if. #PLINK do.
  p=. plinkpath''
else.
  p=. ppath''
end.
while. 1 do.
  j=. '"Script Files(*.ijs)|*.ijs"'
  j=. j,' ofn_nochangedir'
  f=. wd 'mbopen "New Source File" "',p,'" "" ',j
  if. ''-:f do. return. end.
  f=. extijs f
  if. '.ijs' -: _4 {.f do. break. end.
  info 'Script filename extension should be .ijs'
end.
if. IFWIN32 do. f=. tolower f end.

if. f jflin XPRIMARYFILES, XDEVFILES do.
  info 'already in project: ',shortname1 extnone f return.
end.

if. #PLINK do.
  if. -. p -: (#p) {. f do.
    info 'New linked script must be in link directory.' return.
  end.
end.
if. 0=fexist f do. '' flwrites f end.

XPRIMARYFILES=: XPRIMARYFILES, < tofoldername1 f
XDEVFILES=: XDEVFILES jflminus f
sfiles_show''
projaddrecent''
)
sfiles_remove_button=: 3 : 0
if. 0 e. #filelist do. infonosel'' return. end.

files=. (".filelist_select) { XFILES

if. 1 e. files e. RFILES do.
  info 'You cannot remove required files' return.
end.

ff=. tolist shortname extnone each files

if. 1=2 query 'OK to remove:',LF,LF,ff do. return. end.

XFILES=: XFILES jflminus files
XPRIMARYFILES=: XPRIMARYFILES jflminus files
XDEVFILES=: XDEVFILES jflminus files
sfiles_show''
projaddrecent''
)

sfiles_filelist_button=: popenfiles
sfiles_open_button=: popenfiles
sfiles_view_button=: viewfile
sfiles_print_button=: sprintfiles
sfiles_dev=: 3 : 0
if. 0 e. #filelist do. infonosel'' return. end.
files=. (".filelist_select) { XFILES
if. 1 e. files e. RFILES do.
  info 'You cannot make a required file into a dev file' return.
end.
p=. files jflminus XPRIMARYFILES
q=. files jflminus XDEVFILES
XPRIMARYFILES=: (XPRIMARYFILES jflminus q),p
XDEVFILES=: (XDEVFILES jflminus p),q
sfiles_show''
)
sfiles_move=: 3 : 0
if. TABNDX ~: 0 do.
  info 'Source Move applies only in the Source Tab' return.
end.
if. 0 e. #filelist do. infonosel'' return. end.
files=. (".filelist_select) { XFILES
if. 1 e. files e. RFILES do.
  info 'Cannot move required files' return.
end.
if. #fp=. files jflminus XDEVFILES do.
  ndx=. XPRIMARYFILES i. fp
  j=. y.,(#XPRIMARYFILES),({.ndx),{:ndx
  XPRIMARYFILES=: XPRIMARYFILES {~ ssort j
end.
if. #fd=. files jflminus XPRIMARYFILES do.
  ndx=. XDEVFILES i. fd
  j=. y.,(#XDEVFILES),({.ndx),{:ndx
  XDEVFILES=: XDEVFILES {~ ssort j
end.
sfiles_show files
)
ssort=: 3 : 0
'd l b e'=. y.
x=. i.l
if. (y.=0) *. b>0 do.
  b=. b-1 [ e=. e+1
  (b{.x),(1|.b}.e{.x),e}.x
elseif. (y.=1) *. e<l-1 do.
  e=. e+2
  (b{.x),(_1|.b}.e{.x),e}.x
end.
)
getfilelist=: 3 : 0
if. #PLINK do.
  XFILES=: XPRIMARYFILES
  p=. plinkpath''
  f=. fromfoldername XPRIMARYFILES
  f=. extnone each p & drophead each f
  tolist f ,each <' (l)' return.
end.
if. 0 = (#XPRIMARYFILES) + #XDEVFILES do.
  RFILES=: ''
  XFILES=: ''
  return.
end.

if. _1 -: RLIBS do. RLIBS=: lfiles_rlibs'' end.

inlibs=. getlibfiles XPRIMARYLIBS,RLIBS
d1=. (req XPRIMARYFILES) jflminus inlibs

inlibs=. inlibs,getlibfiles XDEVLIBS
d2=. (req XDEVFILES) jflminus inlibs
d1=. d1 jflminus XPRIMARYFILES,XDEVFILES
d2=. d2 jflminus d1,XPRIMARYFILES,XDEVFILES
RFILES=: d1,d2
XFILES=: XPRIMARYFILES,d1,XDEVFILES,d2

f=. extnone each XPRIMARYFILES
f=. f, (,&' (r)') each extnone each d1
f=. f, (,&' (d)') each extnone each XDEVFILES
f=. f, (,&' (dr)') each extnone each d2

f=. shortname f

tolist f
)

snapshot=: 3 : 0
if. PMSNAPS=0 do. return. end.

today=. 's', 2 }. ": <. 100 #. 3 {.6!:0''
p=. (ppath''),'.snp'
if. 0 = #1!:0 p do.
  if. -. ss_makedir p do. return. end.
end.
p=. p,PATHSEP
d=. 1!:0 p,'*'
pfx=. p,today
if. 0=#d do. ss_make pfx,'001' return. end.
d=. \:~ {."1 d #~ 'd' = 4{"1 > 4{"1 d
last=. 0 pick d
iftoday=. today -: 7 {. last
if. y. -: 1 do.
  if. (p,last) ss_match ppath'' do.
    ss_info 'Last snapshot matches current project.' return.
  end.
  if. iftoday do.
    f=. pfx,_3 {. '00',": 1 + 0 ". _3 {. last
  else.
    f=. pfx,'001'
  end.
  ss_make f
  ss_info 'New snapshot: ',1 pick pathname f
  
else.
  if. iftoday do. return. end.
  if. (p,last) ss_match ppath'' do. return. end.
  ss_make pfx,'001'
end.
d=. (PMSNAPS-1) }. d
for_s. d do.
  f=. p,(>s),PATHSEP
  1!:55 f&, each {."1 [ 1!:0 f,'*'
  1!:55 <f
end.
)
snapview=: 3 : 0
require jpath '~system\extras\util\dirmatch.ijs'
PJPROJ_jdirmatch_=: ''
dmrun_jdirmatch_ 1 1
)
ss_files=: 3 : 0
t=. 1!:0 y.,'*'
if. 0=#t do. return. end.
att=. > 4{"1 t
msk=. ('h' = 1{"1 att) +: 'd' = 4{"1 att
t=. /:~ msk # t
if. #PMSNAPX do.
  t #~ -. +./ PMSNAPX (1: e. E.) &>/ {."1 t
end.
)
ss_info=: wdinfo @ ('Snapshot'&;)
ss_make=: 3 : 0
fm=. ppath''
to=. y.,PATHSEP
if. 0 -: 1!:5 :: 0: <to do.
  ss_info 'Unable to create snapshot directory.'
  0 return.
end.
f=. {."1 ss_files fm
fm=. (<fm) ,each f
to=. (<to) ,each f
res=. filecopy"1 fm ,. to
if. 0 e. res do.
  txt=. 'Unable to copy:',LF,LF,tolist (res=0)#fm
  ss_info txt
end.
)
ss_makedir=: 3 : 0
if. 0 -: 1!:5 :: 0: <y. do.
  ss_info 'Unable to create snapshot directory.'
  0 return.
end.
arw=. 'rw' 0 1 } 1!:7 <y.
if. 0 -: arw 1!:7 :: 0: <y. do.
  ss_info 'Unable to set read/write attributes for snapshot directory.'
  0 return.
end.
if. -.IFUNIX do.
  ph=. 'h' 1 } 1!:6 <y.
  if. 0 -: ph 1!:6 :: 0: <y. do.
    ss_info 'Unable to set hidden attribute for snapshot directory.'
  end.
end.
1
)
ss_match=: 4 : 0
x=. addfret x.
y=. addfret y.
a=. ss_files x
b=. ss_files y
ra=. #a
rb=. #b
if. 0 e. ra,rb do.
  ra = rb return.
end.
fa=. {."1 a
fb=. {."1 b
if. -. fa -: fb do. 0 return. end.
if. -. (2 {"1 a) -: (2 {"1 b) do. 0 return. end.
fx=. x&, each fa
fy=. y&, each fa
(<@(1!:1) fy) -: <@(1!:1) fx
)
ss_list=: 3 : 0
if. isempty y. do.
  p=. ppath ''
else.
  p=. 0 pick pathname y.
end.
d=. 1!:0 p,'.snp',PATHSEP_j_,'*'
if. #d do.
  d=. d #~ 'd' = 4 {"1 > 4 {"1 d
  \:~ {."1 d
else.
  ''
end.
)

tagparen=: ' ('&, @ (,&')') @ ":
globalassigns=: 3 : 0
rx=. '([[:alpha:]][[:alnum:]_]*|x\.|y\.|m\.|n\.|u\.|v\.) *=:'
/:~ (-.&' ') @ (_2&}.) each rx rxall y.
)
prettyprint=: 3 : 0
if. 0=#f=. getselectfiles'' do. return. end.
saveopenwindows''
load PPSCRIPT
r=. PMTABS pp_jpp_ f
if. r -: _1 do. return. end.
b=. r > 0
if. 1 e. b do.
  txt=. 'Changed:',LF,tolist b#f
else.
  txt=. 'No change'
end.
info txt
)
publishdoc=: 3 : 0
if. 0=#f=. getselectfiles'' do. return. end.
publish >{.f
)
showassignments=: 3 : 0
if. 0=#f=. getselectfiles'' do. return. end.
saveopenwindows''
showassignments1 f
)
showassignments1=: 3 : 0
f=. y.
none=. <,<'{none}'
fls=. 'In file: '&, each shortname f
nms=. globalassigns @ flread each f
if. 1 < #f do.
  all=. sort ; ~. each nms
  nub=. ~. all
  cnt=. #/.~ all
  if. 2 < #f do.
    fls=. fls,~<'In more than one file:'
    nms=. nms ,~ <((cnt<#f) *. cnt>1)#nub
  end.
  fls=. fls,~<'In every file:'
  nms=. nms ,~ <(cnt=#f)#nub
end.
fls=. (, @ (,.&LF) @ (,:&'-')) each fls
nms=. tagcount each nms
nms=. none (I. 0=# &> nms)} nms
nms=. , @ (,.&LF) @: > each nms
'Global Assignments' wdview tolist fls ,each nms
)
getorphans=: 3 : 0
if. 0=#PROJECTFILE do. infonoproj'' return. end.
saveopenwindows''
f=. getprojdirfiles''
j=. PROJECTFILE;XTARGETFILE;XPREBUILDFILE;XPOSTBUILDFILE;XTESTFILE
j=. j,XPRIMARYFILES,XDEVFILES,XOTHERFILES
f=. fullname each f
j=. fullname each j -. a:
if. IFWIN32 do.
  f=. tolower each f
  j=. tolower each j
end.
orphan=. f -. j
widow=. (-.@fexist &> # ]) j
orphan;<widow
)
getprojdirfiles=: 3 : 0
p=. ppath''
t=. 1!:0 p,'*'
t=. t #~ 'd'~: 4{ &> 4{"1 t
p&, each {."1 t
)
showorphans=: 3 : 0
'orphan widow'=. getorphans''
if. 0=#orphan,widow do.
  info 'No orphan files' return.
end.
if. #orphan do.
  j=. 'Files in project directory not referenced in project:',LF
  orphan=. (*#orphan) # j, tolist sort shortname orphan
else.
  orphan=. ''
end.

j=. 'Files referenced in project that do not exist:',LF
widow=. (*#widow) # ((*#orphan)#LF,LF), j, tolist sort shortname widow
'Orphan Files' wdview orphan,widow
)
showprojdir=: 3 : 0
dirs ppath''
)
tagcount=: 3 : 0
cnt=. #/.~ y.
nms=. ~. y.
if. 1 e. b=. cnt > 1 do.
  tag=. tagparen each b#cnt
  tag=. (b#nms) ,each tag
  tag (I. b)} nms
end.
)
viewscriptdoc=: 3 : 0
if. 0=#f=. getselectfiles'' do. return. end.
scriptdoc f
)

allwindows=: 3 : 0
<;._2 qsmallijs''
)
openwindow=: 3 : 0
'name pos'=. ';' cutopen y.
open name
smmove pos
)
windows_close=: 3 : 0
for_f. qsmallijs'' do.
  smsel f
  smsave ''
  smclose ''
end.
wd 'psel projectform;pactive'
)
windows_open=: 3 : 0
if. 0=#PROJECTFILE do. infonoproj'' return. end.
if. 0=#XWINDOWS do.
  info 'no windows to open' return.
end.
openwindow each XWINDOWS
wd 'psel projectform;pactive'
)
windows_save=: 3 : 0
if. 0=#PROJECTFILE do. infonoproj'' return. end.
f=. qsmallijs''
if. 0=#f do.
  WINDOWS=: XWINDOWS=: ''
else.
  qsize=. ';'&, @ ": @ qsmsize @ smsel
  XWINDOWS=: (id2names f) ,each qsize each f
  WINDOWS=: tolist XWINDOWS
end.
WINDOWSTATE=: XWINDOWSTATE=: 0
projsave 0
if. (<PROJECTFILE) e. allwindows'' do.
  smsel PROJECTFILE
  smwrite flreads PROJECTFILE
end.
)

TABGROUPS=: ;: 'sfiles lfiles bfiles wother'
PTOP=: 0
PROJECTFORM=: 0 : 0
pc projectform;pn "Project Manager";
menupop "&File";
menu pnew "&New..." "" "" "";
menu popen "&Open..." "" "" "";
menusep ;
menu plast "&Last" "Ctrl+L" "" "";
menu precent "&Recent..." "" "" "";
menusep ;
menu save "&Save" "Ctrl+S" "" "";
menusep ;
menu notes "No&tes..." "" "" "";
menusep ;
menu refresh "Re&fresh Tabs" "" "" "";
menusep ;
menu delete "&Delete File..." "" "" "";
menusep ;
menu exit "E&xit" "" "" "";
menupopz;
menupop "&Options";
menu dev "Mark as Dev Only" "" "" "";
menusep ;
menu up "Source Move Up" "Ctrl+U" "" "";
menu down "Source Move Down" "Ctrl+N" "" "";
menusep ;
menu ptop "Topmost window" "Ctrl+T" "" "";
menusep ;
menu paths "Look &In Folders..." "" "" "";
menusep ;
menu configure "Confi&gure..." "" "" "";
menupopz;
menupop "&Tools";
menu runfile "&Run File" "Ctrl+W" "" "";
menusep ;
menu ass "&Global Assignments in File" "" "" "";
menusep ;
menu sdoc "&View scriptdoc" "" "" "";
menu pub "HTML P&ublish..." "" "" "";
menusep ;
menu pp "&Format Script File" "" "" "";
menusep ;
menu orphan "Project &Orphan Files" "" "" "";
menu projdir "Project &Directory" "" "" "";
menusep ;
menu snapview "&Compare Snapshots..." "" "" "";
menusep ;
menu snapmake "&Make Snapshot" "" "" "";
menupopz;
menupop "&Windows";
menu closewin "&Close Windows" "" "" "";
menusep ;
menu openwin "&Open Windows" "" "" "";
menusep ;
menu savewin "&Save Windows" "" "" "";
menupopz;
menupop "&Project";
menu buildopt "Build &Options..." "" "" "";
menusep ;
menu linkproject "&Link Project..." "" "" "";
menupopz;
menupop "&Help";
menu helpover "&Overview" "" "" "";
menusep ;
menu helpproj "&Project Manager" "" "" "";
menupopz;
xywh 2 5 30 11;cc s0 static;cn "Pro&ject:";
xywh 33 4 94 300;cc projectfile combodrop ws_vscroll rightmove;
xywh 2 20 30 11;cc s1 static;cn "Look &In:";
xywh 33 19 94 300;cc projectpath combodrop ws_vscroll rightmove;
xywh 130 21 7 10;cc selectpathup button leftmove rightmove;cn "<";
xywh 137 21 7 10;cc selectpathdown button leftmove rightmove;cn ">";
xywh 0 35 186 1;cc s2 staticbox ss_etchedhorz rightmove;
xywh 2 40 184 176;cc tabs tab rightmove bottommove;
xywh 148 4 36 12;cc load button leftmove rightmove;cn "&Load";
xywh 148 19 36 12;cc buildapp button leftmove rightmove;cn "&Build";
xywh 148 37 36 12;cc runtest button leftmove rightmove;cn "&Test";
pas 0 2;pcenter;
rem form end;
)
projectform_run=: 3 : 0
getfoldernames''
if. wdisparent 'projectform' do.
  wd 'psel projectform;pshow;pactive' return.
end.
TABNDX=: 0
TXFILES=: i.0 2
wd PROJECTFORM
HWNDP=: wd 'qhwndp'
wd 'set tabs "Source" "Library" "Project" "Other"'
wd 'creategroup tabs'
sfiles_run''
lfiles_run''
bfiles_run''
wother_run''
wd 'creategroup'
projinit''
projectform_show''
wd 'setenable snapmake ',": 0 < PMSNAPS
wd 'setenable snapview ',": 0 < PMSNAPS
wd 'setshow sfiles 1'
wd 'setfocus load'
wd 'set ptop ',":PTOP
wpset 'projectform'
wd 'pshow;'
)
projectform_buildapp_button=: 3 : 0
if. 0=#PROJECTFILE do. infonoproj'' return. end.
buildapp''
)
projectform_buildopt_button=: 3 : 0
if. 0=#PROJECTFILE do. infonoproj'' return. end.
buildopt''
)
projectform_dev_button=: 3 : 0
if. TABNDX=0 do. sfiles_dev'' else. lfiles_dev'' end.
)
projectform_helpover_button=: 3 : 0
htmlhelp 'user\project_overview.htm'
)
projectform_helpproj_button=: 3 : 0
htmlhelp 'user\project_man.htm'
)
projectform_projectfile_select=: 3 : 0
if. #projectfile_select do.
  j=. (".projectfile_select) pick PJFNDX { PJFILES
  if. j -: PROJECTFILE do. return. end.
  projsaveok''
  projectform_load j
  projaddrecent''
end.
)
projectform_projectpath_select=: 3 : 0
if. projectpath -: PID do. return. end.
projsaveok''
setprojpathfile projectpath
projectform_load PROJECTFILE
)
projectform_save_button=: 3 : 0
if. 0=#PROJECTFILE do. infonoproj'' return. end.
projsavenew''
info 'Saved: ',PROJECTFILE
)
projectform_selectpath=: 3 : 0
dep=. getdepth''
if. y. = 1 do.
  max=. getmaxdepth''
  if. dep = max do. return. end.
  changedepth 1
else.
  if. dep = 0 do. return. end.
  changedepth _1
end.
showproject''
)

projectform_selectpathdown_button=: projectform_selectpath bind 1
projectform_selectpathup_button=: projectform_selectpath bind 0
projectform_tabs_button=: 3 : 0
new=. ".tabs_select
if. new=3 do. wother_show'' end.
wd 'setshow ',(>TABNDX{TABGROUPS),' 0'
TABNDX=: new
wd 'setshow ',(>TABNDX{TABGROUPS),' 1'
)
projectform_ptop_button=: 3 : 0
PTOP=: ".ptop
wd 'ptop ',ptop
)
projectform_enter=: ]
projectform_cancel=: projectform_close=: closeproject
projectform_ass_button=: showassignments
projectform_closewin_button=: windows_close
projectform_configure_button=: cfg_run
projectform_linkproject_button=: link_run
projectform_delete_button=: deletefile
projectform_down_button=: sfiles_move bind 1
projectform_exit_button=: projectform_close
projectform_load_button=: runproject
projectform_notes_button=: wnote_run
projectform_openwin_button=: windows_open
projectform_orphan_button=: showorphans
projectform_paths_button=: wppath_run
projectform_plast_button=: plast_run
projectform_pnew_button=: opennewproject
projectform_popen_button=: openoldproject
projectform_pp_button=: prettyprint
projectform_precent_button=: precent_run
projectform_projdir_button=: showprojdir
projectform_projectfile_button=: projectform_projectfile_select
projectform_projectpath_button=: projectform_projectpath_select
projectform_pub_button=: publishdoc
projectform_refresh_button=: showfiles
projectform_runfile_button=: load @: getselectfiles
projectform_runtest_button=: runtest
projectform_savewin_button=: windows_save
projectform_sdoc_button=: viewscriptdoc
projectform_snapmake_button=: snapshot bind 1
projectform_snapview_button=: snapview
projectform_up_button=: sfiles_move bind 0

projectform_bctrl_fkey=: projectform_buildapp_button
projectform_dctrl_fkey=: editinputlog
projectform_fctrl_fkey=: editfind
projectform_fctrlshift_fkey=: fif
projectform_lctrl_fkey=: projectform_plast_button
projectform_nctrl_fkey=: projectform_down_button
projectform_sctrl_fkey=: projectform_save_button
projectform_uctrl_fkey=: projectform_up_button
projectform_wctrl_fkey=: projectform_runfile_button
projectform_load=: 3 : 0
projreset''
if. #y. do.
  setprojfile y.
else.
  setprojfile 0 pick PJFILES,a:
end.
if. #PROJECTFILE do.
  projread ''
  snapshot''
end.
projectform_show''
)
projectform_show=: 3 : 0
wd 'psel projectform'
showproject''
showfiles''
wd 'setshow ',(0 pick TABGROUPS),' ',":0=TABNDX
wd 'setshow ',(1 pick TABGROUPS),' ',":1=TABNDX
wd 'setshow ',(2 pick TABGROUPS),' ',":2=TABNDX
wd 'setshow ',(3 pick TABGROUPS),' ',":3=TABNDX
wd 'setselect tabs ',":TABNDX
wd :: [ 'psel projpath;pclose'
wd 'psel projectform;pactive'
wd 'setfocus load'
)
showfiles=: lfiles_show @ sfiles_show @ bfiles_show @ wother_show
projectmanager=: projectform_run
showproject=: 3 : 0
if. #PJFILES do.
  nms=. pidname each PJFILES
  PJFNDX=: /: nms
  wd 'set projectfile *', tolist PJFNDX { nms
  wd 'setselect projectfile ',": (PJFNDX { PJFILES) bcfind <PROJECTFILE
  wd 'setenable projectfile 1'
else.
  PJFNDX=: ''
  wd 'set projectfile *'
  wd 'setenable projectfile 0'
end.
if. #PIDTREE do.
  wd 'set projectpath *', tolist PIDTREE
  wd 'setselect projectpath ',": 0 >. PIDTREE bcfind <PID
else.
  wd 'set projectpath *'
end.
)