-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathjfif.ijs
More file actions
273 lines (234 loc) · 5.9 KB
/
jfif.ijs
File metadata and controls
273 lines (234 loc) · 5.9 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
coclass'jfif'
coinsert'jhs'
MAXFILES=: 100000 NB. fails if too many files in search path
HBS=: 0 : 0
jhclose'find in files'
'find' jhb'Find'
'context' jhselect(<;._2 FIFCONTEXT);1;0
'mcase' jhb 'Aa'
'mfolders' jhb '/...'
'nameonly' jhb 'lines'
jhbr
'what' jhtext '<what>';50
jhbr
'where' jhtext '<where>';50
jhbr
jhresize''
'area' jhdiv''
)
CSS=: 0 : 0
*{font-family:PC_FONTFIXED;}
)
jev_get=: 3 : 0
'jfif'jhr''
)
ev_find_click=: 3 : 0
t=. <;._2 getv'jdata'
'FIFWHAT FIFCONTEXTNDX FIFTYPE FIFDIR FIFCASE FIFSUBDIR FIFNAMEONLY'=: t
FIFTYPE=: '*.ijs'
if. 0~:#FIFDIR do.
if. '/'~:{:FIFDIR do.
i=. FIFDIR i:'/'
t=. }.i}.FIFDIR
if. '*'={.t do.
FIFTYPE=: t
FIFDIR=: i{.FIFDIR
end.
FIFDIR=: FIFDIR,'/'
end.
end.
FIFCONTEXTNDX=: ".FIFCONTEXTNDX
FIFCASE=: ".FIFCASE
FIFSUBDIR=: ".FIFSUBDIR
FIFNAMEONLY=: ".FIFNAMEONLY
FIFFOUND=: ''
FIFINFO=: ''
JHSFOUNDFILES=: ''
fiff_find_button''
t=. FIFINFO
if. 0~:#t do. t=. t,'<br><br>find WHAT WHERE<br>find abcd ~addons<br>find abcd ~addons/*.txt' end.
jhrajax t,>FIFNAMEONLY{JHSFOUNDFILES;FIFFOUND
)
fiff_find_button=: 3 : 0
if. 0=#FIFWHAT do. finfo 'WHAT is empty - nothing to find' return. end.
if. 0=#FIFDIR do. finfo 'WHERE is empty' return. end.
if. 0=#dir FIFDIR do. finfo 'WHERE is not a folder' return. end.
dat=. ffss''
if. ''-:dat do. return. end. NB. finfo called
if. 0=# 0 pick dat do. finfo'no match' return. end.
'FIFFOUND FIFLINES FIFHITS FIFMSK FIFFILES'=: dat
)
termLF=: , (0: < #) # LF"_ -. _1&{.
toLF=: (10{a.)&(I. @(e.&(13{a.))@]})
fifplain=: ;@(,~&.> e.&'[](){}$^.*+?|\' #&.> (<'\')"_) NB. escape NOT /
3 : 0''
if. IFUNIX do. filecase=: [ else. filecase=: tolower end.
0
)
ffssinit=: 3 : 0
p=. y
nna=. '(^|[^[:alnum:]_])'
nnz=. '($|[^[:alnum:]_.:])'
ass=. '[[:space:]]*='
select. FIFCONTEXTNDX
case. 0 do. p=. fifplain y
case. 1 do. p=. nna,p,nnz
case. 2 do. p=. nna,p,ass,':'
case. 3 do. p=. nna,p,ass,'\.'
case. 4 do. p=. nna,p,ass,'[:.]'
case. 5 do. p=. y NB. regex
end.
FIFCOMP=: rxcomp_jregex_ :: _1: p
)
NB. return '' if finfo called
ffss=: 3 : 0
JHSFOUNDFILES=: ''
if. FIFCASE=0 do.
what=. tolower FIFWHAT
else.
what=. FIFWHAT
end.
fls=. ffgetfiles''
if. ''-:fls do. '' return. end.
if. _1=ffssinit what do. finfo'regex failed' return. end.
fnd=. ''
lns=. ''
msk=. ''
hit=. ''
dr=. fls
read=. (1!:1 :: _1:) @ <
read=. toLF @ (read f.)
while. #dr do.
dat=. read fl=. >{.dr
dr=. }.dr
if. dat -: _1 do. msk=. msk,0 continue. end.
dat=. termLF dat
if. FIFCASE do. txt=. dat else. txt=. tolower dat end.
ndx=. FIFCOMP rxmatches_jregex_ txt
ndx=. +/"1 {."2 ndx
if. rws=. #ndx do.
msk=. msk,1
t=. jhsfixfl fl
fnd=. fnd,t,' (',(":#ndx),')'
JHSFOUNDFILES=: JHSFOUNDFILES,t
txt=. dat
ind=. +/ ndx >"1 0 I.txt=LF NB. display found line just from LF
b=. ~: ind
ind=. b#ind
hit=. hit, <b#ndx
lns=. lns, <ind
txt=. ; ind { <;.2 txt
fnd=. fnd,jhsfixtxt txt
else.
msk=. msk,0
end.
end.
rxfree_jregex_ FIFCOMP
fnd;lns;hit;msk;<fls
)
NB. return list of files or finfo
ffgetfiles=: 3 : 0
dirs=. <FIFDIR
r=. ''
dirs=. fullname_j_ each dirs
while. #dirs do.
if. MAXFILES<#r do. finfo 'too many files to search' return. end.
fpath=. (>{.dirs) &,
dirs=. }.dirs
dat=. a: -.~ 1!:0 each fpath each <FIFTYPE
if. #dat do.
dat=.('d'~:;4{each 4{"1 ;dat)#{."1 ;dat
r=. r, fpath each /:~ dat
end.
if. FIFSUBDIR do.
if. #j=. 1!:0 fpath '*' do.
if. #j=. ({."1 ffgetsubdir j) do.
dirs=. ((fpath @ (,&'/')) each j),dirs
end.
end.
end.
end.
r=. ~.jpath each ( ;@:((# {. 1:)&.>) <;.1 filecase@;) r
if. 0=#r do. finfo'no files to search' return. end.
r
)
ffgetsubdir=: #~ '-d'&-:"1 @ (1 4&{"1) @ > @ (4&{"1)
finfo=: 3 : 0
FIFINFO=: y
''
)
FIFCONTEXT=: 0 : 0
any
name
=:
=.
=: =.
regex
)
jhsfixfl=: 3 : 0
t=. jshortname y
'<br>',('file*',jurlencode t)jhab t
)
jhsfixtxt=: 3 : 0
'<br>',jhfroma y
)
JS=: 0 : 0
function ev_body_load()
{
setlast("what");
setlast("where");
jform.context.selectedIndex= getls("context");
setchkstate('mcase', getls('mcase'));
setchkstate('mfolders',getls('mfolders'));
setchkstate('nameonly',getls('nameonly'));
jbyid("what").focus();
jresize();
}
function ev_what_enter(){jscdo("find");}
function ev_where_enter(){jscdo("find");}
function ev_find_click_ajax(ts){jbyid("area").innerHTML=ts[0];}
function ev_find_click()
{
jbyid('area').innerHTML= 'searching...';
adrecall("what",jform.what.value,"0");
adrecall("where",jform.where.value,"0");
setls("context", jform.context.selectedIndex);
setls('mcase', getchkstate('mcase'));
setls('mfolders', getchkstate('mfolders'));
setls('nameonly', getchkstate('nameonly'));
var t=jform.what.value+JASEP;
t+=jform.context.selectedIndex+JASEP;
t+=0+JASEP; // type is part of where - jform.type.value+JASEP;
t+=jform.where.value+JASEP;
t+=(getchkstate('mcase')?1:0)+JASEP;
t+=(getchkstate('mfolders')?1:0)+JASEP;
t+=(getchkstate('nameonly')?1:0)+JASEP;
jdoajax([],t);
}
function ev_file_click(){
if(null!=window.frameElement){
var a= 'jifr-jijs?jwid='+decodeURIComponent(jsid.value);
var b= 'jijs?jwid='+(jsid.value);
jijxwindow.newpage(a,'jifr',b);
}else{
var t= 'jijs?jpagearg='+jsid.value;
pageopen(t,t); // open in same browser window
}
}
function ev_mcase_click(){flipchkstate('mcase');jscdo('find');}
function ev_mfolders_click(){flipchkstate('mfolders');jscdo('find');}
function ev_nameonly_click(){flipchkstate('nameonly');jscdo('find');}
function ev_context_change()
{
jscdo('find');
//jbyid("which").innerHTML= JEV+" : "+jbyid("sel").selectedIndex;
}
// early support for chkbutton - normal button with 2 color backgroundcolors
// move eventually to utiljs
var chk1='lightgrey';chk0= 'white';
function getchkstate(id){
return (jbyid(id).style.backgroundColor==chk1)?1:0;
}
function setchkstate(id,v){jbyid(id).style.backgroundColor= (v==0)?chk0:chk1;}
function flipchkstate(id){setchkstate(id,getchkstate(id)!=1)};
)