-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathptok.e
2835 lines (2726 loc) · 100 KB
/
ptok.e
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- ptok.e
--
-- File read and tokeniser.
--
----/**/without debug -- no gain
without trace
integer fn
fn = -1
--procedure loadFile()
---- load a single source into memory.
---- fn should be set on entry to an open filename (as found by
---- scanning EUDIR,EUINC, etc). It is closed on exit.
--
----/* RDS compatible code:
--integer textlen
--integer lllen
--object line
--string lastline
--
-- text = {}
-- while 1 do
-- line = gets(fn)
-- if atom(line) then exit end if
-- text = append(text,line)
-- end while
-- textlen = length(text)
-- if textlen then
-- lastline=text[textlen]
-- lllen=length(lastline)
-- if lllen=0 or lastline[lllen]!='\n' then
-- text[textlen]=append(lastline,'\n')
-- end if
-- end if
----*/
-- close(fn)
-- fn = -1
--end procedure
global --DEV 1/11/09 for psym.e
integer ltl -- length(text)
ltl = -1
procedure loadFile()
string msg
--
-- Load a single source into memory.
-- fn should be set on entry to an open filename (as found by
-- scanning EUDIR,EUINC, etc). It is closed on exit.
--
if not minus_e then
text = get_text(fn,GT_WHOLE_FILE)
end if
ltl = length(text)
-- 01/08/2013:
col = 0
if ltl>=3 and text[1..3]={#EF,#BB,#BF} then
col += 3
elsif ltl>=2 and find(text[1..2],{{#FF,#FE},{#FE,#FF}}) then
msg = "UTF16 source files are not supported"
if length(allfiles)=0 then
-- (no source line to report against)
Fatal(msg)
-- abort(1) -- Fatal() does not return
else
Abort(msg)
end if
end if
close(fn)
fn = -1
end procedure
--
-- when I include misc\file.e, and file.e just includes file2.e, then I want it to
-- have a look in misc\. So we build a table of paths to search and extend it from
-- time to time.
--
--constant usegpp = 01
-- if usegpp:
--include builtins\peekstr.e
--include builtins\pgetpath.e
--DEV no longer quite sure what these do. I think the plan was that in eg:
-- main.e:
-- include arwen\arwen.ew
-- include thing.e
-- arwen\arwen.ew:
-- include misc_arwen.e (etc)
-- Then (obviously) it would look for the sub-include misc_arwen.e in the
-- "active" path "arwen\" (which it does), but at EOF of arwen.ew, that
-- would become "inactive" (no evidence of that I can find) and it would
-- NOT look for thing.e in "arwen\" (but it DOES). OK, this is a BUG.
-- (posted on the bugs forum 18/09/2010, asking for volunteers)
sequence activepaths
global integer alwaysactive -- used in stripPathInfo() in pemit.e
alwaysactive = 0
integer lastPath = 0
procedure addPath(sequence path)
-- if not usegpp then
-- path = lower(path)
-- end if
--DEV (temp)
if platform()=LINUX then
if match("./",path)=1 then
-- path = "/home/pete/phix/"&path[3..$]
path = getenv("HOME")&"/phix/"&path[3..$]
-- path = mainpath&path[3..$]
-- path = current_dir()&SLASH&path[3..$]
-- if testall then
-- path = mainpath[1..-6]&path[3..$]
-- else
-- path = mainpath&path[3..$]
-- end if
end if
end if
-- if not find(path,filepaths) then
lastPath = find(path,filepaths)
if lastPath=0 then
filepaths = append(filepaths,path)
lastPath = length(filepaths)
activepaths = append(activepaths,1)
end if
end procedure
--with trace
--/**/-- not strictly necessary, but reduces opCallOnce/fwd calls/onDeclaration
--/**/include penv.e -- getenv()
--/**/include pdir.e -- dir()
--newEmit
--!/**/include psprint.e -- "?" --[DEV] ["VM\\psprintN.e"]
integer vmpath = 0
global procedure initFilePathSet()
object incpath
integer semicolon, sm1
filepaths = {}
activepaths = {}
incpath = getenv("EUDIR")
if not atom(incpath) then
incpath = get_proper_path(incpath&SLASH&"include"&SLASH,"")
addPath(incpath)
end if
incpath = getenv("EUINC")
if not atom(incpath) then
while 1 do
semicolon = find(';',incpath)
if semicolon=1 then
-- skip nulls (ie/eg ;;) in EUINC
elsif semicolon then
sm1 = semicolon-1
if incpath[sm1]!=SLASH then
incpath[semicolon] = SLASH
sm1 = semicolon
end if
addPath(get_proper_path(incpath[1..sm1],""))
else
if incpath[length(incpath)]!=SLASH then
incpath &= SLASH
end if
incpath = get_proper_path(incpath,"")
addPath(incpath)
exit
end if
incpath = incpath[semicolon+1..length(incpath)]
if not length(incpath) then exit end if
end while
end if
addPath(rootpath&"builtins"&SLASH)
--DEV
addPath(rootpath&"builtins"&SLASH&"VM"&SLASH) -- (added 8/4/15)
-- vmpath = length(filepaths)
-- vmpath = find(rootpath&"builtins"&SLASH&"VM"&SLASH,filepaths)
vmpath = lastPath
addPath(rootpath)
addPath(mainpath)
alwaysactive = length(filepaths)
-- activepaths = repeat(1,alwaysactive)
--printf(1,"initFilePathSet: ")
--?activepaths
allfiles = {}
exptext = {}
expandedYet = {}
unresolved_routine_ids = {}
finalOptWarn = {}
filenames = {}
end procedure
-- Files which should have a "Phix compatible" marker:
constant phixcompat = { "win32lib.ew",
"arwen.ew",
"database.e",
"dll.e",
"file.e",
"get.e",
"graphics.e",
"image.e",
"machine.e",
"misc.e",
"msgbox.e",
"pcfunc.e",
"pcfileio3.e",
"prtnid.e",
"ppp.e",
"syswait.ew",
"wildcard.e"
}
--DEV
--C:\euphoria\include\std\console.e:46 kernel_dll = machine_func(M_OPEN_DLL, "kernel32.dll"),
--C:\euphoria\include\std\convert.e:20 atom mem = machine_func(M_ALLOC,4)
--C:\euphoria\include\std\filesys.e:304 return machine_func(M_DIR, name)
--C:\euphoria\include\std\graphcst.e:215 return machine_func(M_VIDEO_CONFIG, 0)
--C:\euphoria\include\std\io.e:849 return machine_func(M_SEEK, {fn, pos})
--C:\euphoria\include\std\os.e:75 return machine_func(M_INSTANCE, 0)
--C:\euphoria\include\std\rand.e:241 return machine_func(M_GET_RAND, {})
--C:\euphoria\include\std\regex.e:642 return machine_func(M_PCRE_COMPILE, { pattern, options })
--C:\euphoria\include\std\safe.e:298 machine_func(M_SLEEP,0.1)
--C:\euphoria\include\std\socket.e:49 return machine_func(M_SOCK_ERROR_CODE, {})
-- Files which should be checked for auto-include completeness:
constant vctrl = { {"pcfunc.e",{0,6,3}},
{"pcfileio3.e",{0,6,3}},
{"prtnid.e",{0,6,3}},
$}
sequence vmset = {}
--integer FincMax = 0
--DEV/temp:
--global function getFincMax()
-- return FincMax
--end function
--without warning -- needs to be around the definition
--forward global procedure AddFincParent() -- (defined in psym.e)
--with warning
global procedure Finc(string file)
-- Fake include. Pretends a builtins\VM file has already been loaded.
-- Note that an "include builtins\VM\xx.e" will actually open the file,
-- but then close it and return -fileno, rather than read/compile it.
--string text
-- text = "via optable"
-- allfiles = append(allfiles,text)
-- allpfiles = append(allpfiles,text)
-- exptext = append(exptext,0)
-- expandedYet = append(expandedYet,0)
-- unresolved_routine_ids = append(unresolved_routine_ids,0)
-- finalOptWarn = append(finalOptWarn,optset[OptWarning])
-- filenames = append(filenames,{vmpath,file})
-- FincMax = length(filenames)
-- AddFincParent()
-- ah, this already done in optable...
--if 01 then
-- if find(file,{"pHeap.e","pStack.e"}) then
-- file[-2..$] = "D.e"
-- end if
--end if
if not find(file,vmset) then
vmset = append(vmset,file)
end if
end procedure
forward global procedure eof_processing()
--without trace
--with trace
include ppp.e
--integer icount = 0
--with trace
global procedure includeFile(string file, integer autoInclude, integer emitcol)
integer pathno, k, km1, kp1, kp2, kp3
object path
string thispath
sequence triedpaths
integer semicolon, sm1
string fatalmsg
sequence inpart
integer wasfileno
string msg
integer wline,wcol
integer ch
object cversion
--integer dbg
string thispath2
fn = -1
if showfileprogress then
puts(1,"includeFile started\n")
?file
end if
--if file="VM\\pcallfunc.e" then
-- icount += 1
-- if icount>2 then
-- ?9/0
-- end if
--else
-- icount = 0
--end if
while 1 do
k = find(WRONGSLASH,file)
if not k then exit end if
file[k] = SLASH
end while
--ffs: it works if I debug it!!
--if file = "./test/t02parms.exw" then
-- ?"file = \"./test/t02parms.exw\""
--end if
--DEV (temp)
if platform()=LINUX then
if match("./",file)=1 then
-- file = "/home/pete/phix/"&file[3..$]
file = getenv("HOME")&"/phix/"&file[3..$]
-- file = mainpath&file[3..$]
-- file = current_dir()&SLASH&file[3..$]
-- if testall then
-- file = mainpath[1..-6]&file[3..$]
-- else
-- file = mainpath&file[3..$]
-- end if
end if
end if
--dbg = 0
if platform()=WINDOWS then
while 1 do
k = match("\\\\",file)
if k=0 then exit end if
--if dbg=0 then
-- dbg=1
---- ?file
----puts(1,"includeFile thing\n")
--end if
file = file[1..k]&file[k+2..length(file)]
--?{file}
end while
--elsif platform()=LINUX then
-- if length(file) and file[$]='\n' then file = file[1..$-1] end if
elsif platform()=LINUX then
while 1 do
k = match("//",file)
if k=0 then exit end if
file = file[1..k]&file[k+2..length(file)]
end while
end if
--if dbg then
--puts(1,"match \\\\'d\n")
--end if
triedpaths = {}
if (platform()=WINDOWS and length(file)>1 and file[2]=':')
or (platform()=LINUX and length(file)>=1 and file[1]='/')
or (platform()=LINUX and length(file)>=2 and file[1..2]="./") then
if showfileprogress then
?"rooted"
end if
-- fn = open(file,"rb")
fn = open(file,"r")
thispath = ""
elsif minus_e then
thispath = ""
else
for i=length(filepaths) to 1 by -1 do
if i<=alwaysactive
--26/7/17: (undone before testing, changed activepaths setup instead...)
or (activepaths[i] and not autoInclude) then
-- or (i<=length(activepaths) and activepaths[i] and not autoInclude) then
thispath = filepaths[i]
-- fn = open(thispath&file,"rb")
--14/10/21:
--integer was_safe_mode = safe_mode
--safe_mode = 1
fn = open(thispath&file,"r")
--safe_mode = was_safe_mode
if fn!=-1 then exit end if
triedpaths = append(triedpaths,thispath)
end if
end for
-- if this is top level file, search PATH.
--DEV or everything in allfiles is via Finc()...
if fn=-1 and length(allfiles)=0 then
-- if fn=-1 and length(allfiles)=FincMax then
path = getenv("PATH")
if not atom(path) then
while 1 do
semicolon = find(';',path)
if semicolon!=1 then -- skip nulls (ie/eg ;;) in path
if semicolon then
sm1 = semicolon-1
if path[sm1]!=SLASH then
path[semicolon] = SLASH
thispath = path[1..semicolon]
else
thispath = path[1..sm1]
end if
else
if path[length(path)]!=SLASH then
path &= SLASH
end if
thispath = path
end if
if not find(thispath,filepaths) then
-- fn = open(thispath&file,"rb")
fn = open(thispath&file,"r")
if fn!=-1 then exit end if
if not find(thispath,triedpaths) then
triedpaths = append(triedpaths,thispath) -- for error reporting
end if
end if
end if
if not semicolon then exit end if
path = path[semicolon+1..length(path)]
if not length(path) then exit end if
end while
end if
end if
if fn=-1 and find(SLASH,file) then
thispath = ""
-- fn = open(file,"r")
-- fn = open(file,"rb")
fn = open(file,"r")
end if
end if
if fn!=-1 or minus_e then
--if usegpp then
--?{thispath,file}
if not minus_e then
file = get_proper_path(thispath&file,"")
end if
--?{{file}}
--/*
global integer intellisense = 0
global sequence trapfile, trapkey
global integer trapline, trapcol, trapmode, trapns
--*/
if intellisense=1 then
if file=trapfile then
intellisense = 2 -- (more stuff gets done rsn)
-- printf(1,"intellisense:got %s\n",file)
-- else
-- printf(1,"intellisense:not %s\n",file)
end if
end if
--DEV
--/*
if intellisense=1
and file = ??? then
close(fn)
file = ????
fn = open(file,"rb")
if fn=-1 then
fatal("intellisense intercept error (%s)",file)
end if
intellisense = 2
end if
--*/
--else
-- file = lower(thispath&file)
-- --
-- -- first check for and remove any \..\ in filepath
-- --
-- while 1 do
-- k = match("\\..\\",file)
-- if k=0 then exit end if
-- for j=k-1 to 1 by -1 do
-- if file[j]='\\' then
-- -- remove "\\xxx\\.."
----/**/ file[j..k+2] = "" --/* -- Phix
-- file = file[1..j-1] & file[k+3..length(file)] --*/ -- RDS
-- k = 0 -- signal found
-- exit
-- end if
-- end for
-- if k!=0 then
-- puts(1,"Warning, cannot cleanup "&file&'\n')
---- ?9/0
-- exit
-- end if
-- end while
-- --
-- -- repeat for any \.\
-- --
-- while 1 do
-- k = match("\\.\\",file)
-- if k=0 then exit end if
-- -- remove "\\."
----/**/ file[k..k+1] = "" --/* -- Phix
-- file = file[1..k-1] & file[k+2..length(file)] --*/ -- RDS
-- end while
-- --
-- -- repeat for any \\
-- --
-- while 1 do
-- k = match("\\\\",file)
-- if k=0 then exit end if
-- -- remove 1st "\\" of 2
----/**/ file[k..k] = "" --/* -- Phix
-- file = file[1..k-1] & file[k+1..length(file)] --*/ -- RDS
-- end while
--end if
if find(SLASH,file) then
for j=length(file) to 1 by -1 do
if file[j]=SLASH then
thispath = file[1..j]
file = file[j+1..length(file)]
exit
end if
end for
end if
--**NB** Do not remove (referenced in docs/Qu.htm):
--pHeapD hack:
--if 01 then
-- if find(file,{"pHeap.e","pStack.e"}) then
-- file[-2..$] = "D.e"
-- close(fn)
-- fn = open(thispath&file,"rb")
-- if fn=-1 then ?9/0 end if
-- end if
--end if
pathno = find(thispath,filepaths)
--DEV/kludge
if platform()=LINUX then
if pathno=0 then
if match(mainpath,thispath)=1 then
thispath2 = rootpath&thispath[length(mainpath)+1..$]
pathno = find(thispath,filepaths)
if pathno!=0 then
thispath = thispath2
end if
end if
end if
end if
if pathno=0 then
if showfileprogress then
?{"newpath",thispath}
end if
filepaths = append(filepaths,thispath)
pathno = length(filepaths)
activepaths = append(activepaths,length(filenames)+1)
--printf(1,"includeFile pathno=0 case (%s): ",{file})
--?activepaths
else
-- fileno = find({pathno,file},filenames)
k = find({pathno,file},filenames)
-- if fileno then
if k then
if showfileprogress then
?"already included"
end if
close(fn)
fn = -1
-- fileno = -fileno
fileno = -k
--DEV: this may be required here:
-- col = 0
return -- -fileno
end if
--DEV
--?{pathno,vmpath,file,vmset,find(file,vmset)}
if pathno=vmpath
and find(file,vmset) then
close(fn)
fn = -1
fileno = -1
return
end if
if not activepaths[pathno] then
--printf(1,"includeFile pathno!=0 case (%s): ",{file})
--?activepaths
activepaths[pathno] = length(filenames)+1
--?activepaths
end if
end if
wasfileno = fileno
loadFile()
--if filenames={} then ?text {} = wait_key() end if
if showfileprogress then
--?text
?"loadFile"
end if
allfiles = append(allfiles,text)
allpfiles = append(allpfiles,text)
exptext = append(exptext,0)
expandedYet = append(expandedYet,0)
unresolved_routine_ids = append(unresolved_routine_ids,0)
finalOptWarn = append(finalOptWarn,optset[OptWarning])
--DEV
if length(filenames)=0 then
-- if length(filenames)=FincMax then
-- (the testset (p -test) contains some ..\\)
if showfileprogress then
?"ptok.e line 583: thispath="&thispath
end if
mainpath = thispath
mainfile = file
end if
filenames = append(filenames,{pathno,file})
fileno = length(filenames)
if intellisense=2 then
trapfileno = fileno
if trapline!=0 then -- (unparsed builtin retry uses trapline of 0; see eaisense.ew)
--
-- crop the trapfile (so we can intercept EOF and do the lookup)
--
exptext[$] = expandIntoLines()
exptext[$] = exptext[$][1..trapline]
exptext[$][$] = exptext[$][$][1..trapcol-1]&'\n'
linestarts = linestarts[1..trapline]
expandedYet[$] = linestarts
text = packLines(exptext[$])
ltl = length(text)
allfiles[$] = text
allpfiles[$] = text
end if
intellisense = 3
end if
-- aside: this is actually almost the polar opposite of requires()...
-- this is the compiler trying to make sure it is getting
-- the builtins it shipped with; the latter is anything or
-- anyone asking the compiler to make an explicit check.
cversion = {0}
k = find(lower(file),phixcompat)
if k then
k = match("Phix compatible",text)
if k then
--trace(1)
k += length("Phix compatible")
while 1 do
ch = text[k]
if ch=')' then exit end if
if ch!=' ' then
if ch='.' then
cversion &= 0
elsif ch<'0' or ch>'9' then
-- Abort("invalid version")
exit
else
cversion[$] = cversion[$]*10+(ch-'0')
end if
end if
k += 1
end while
if cversion>phixversion then
tokcol = k
tokline = 1
for i=1 to k do
if text[i]='\n' then
tokline += 1
end if
end for
Abort("invalid Phix compatible version")
-- Fatal("invalid Phix compatible version")
end if
k = 0
for i=1 to length(vctrl) do
if lower(file)=vctrl[i][1] then
if cversion<vctrl[i][2] then
k = 1
end if
exit
end if
end for
elsif length(text)>1000 then -- skip link stubs
k = -1
end if
end if
if k!=0 then
if k<0 then
msg = "not marked Phix compatible"
else
msg = "invalid Phix compatible version"
end if
wline = tokline
wcol = tokcol
if wasfileno then
fileno = wasfileno
if autoInclude then
-- no include statement, show warning on line 1 column 1
wcol = 1
wline = 1
--PL 5/7/13: wtf?
-- wasfileno = 0
else
-- display the warning on the include statement, with actual file in message
text = allfiles[fileno]
wcol = emitcol
-- 5/7/13: (moved out)
-- msg = thispath&file&" "&msg
end if
msg = thispath&file&" "&msg
end if
Warn(msg,wline,wcol,0)
if wasfileno then
fileno = length(filenames)
--29/12/2010
-- text = allfiles[fileno]
text = allpfiles[fileno]
end if
end if
-- return newfileno
--end function
if showfileprogress then
if not testall then
puts(1,thispath&file&'\n')
if wasfileno then
printf(1," included by file %s, line %d\n",{filenames[wasfileno][2],tokline})
end if
end if
end if
return -- fileno
end if
--
-- allow eg "t01" as shorthand for "test\t01type",
--
--trace(1)
k = length(mainpath)
if length(filenames)=0
and autoInclude=0
and k<length(file)
and equal(file[1..k],mainpath) then
kp1 = k+1
kp2 = k+2
kp3 = k+3
if length(file)=k+7 -- ie as in "t01.exw"
and file[kp1]='t'
and file[kp2]>='0' and file[kp2]<='9'
and file[kp3]>='0' and file[kp3]<='9'
and equal(file[k+4..k+7],".exw") then
path = dir(mainpath&"test"&SLASH&file[k+1..k+3]&"*.exw")
elsif length(file)=k+5 -- ie as in "b.exw"
and equal(file[k+1..k+5],"b.exw") then
path = dir(mainpath&"bench"&SLASH&"bench.exw")
elsif length(file)=k+5 -- ie as in "a.exw"
and equal(file[k+1..k+5],"a.exw") then
--DEV -norun?
path = dir(mainpath&"demo\\arwen\\arwen.ew")
if sequence(path) and length(path)=1 then
path[1][1] = "demo\\arwen\\"&path[1][1]
end if
elsif length(file)=k+5 -- ie as in "w.exw"
and equal(file[k+1..k+5],"w.exw") then
--DEV -norun?
path = dir(mainpath&"demo\\win32lib\\win32lib.ew")
if sequence(path) and length(path)=1 then
path[1][1] = "demo\\win32lib\\"&path[1][1]
end if
elsif length(file)=k+6 -- ie as in "bt.exw"
and equal(file[k+1..k+6],"bt.exw") then
path = dir(mainpath&"bench"&SLASH&"benchtst.exw")
elsif length(file)=k+8 -- ie as in "edix.exw"
and equal(file[k+1..k+8],"edix.exw") then
path = dir(mainpath&"demo\\edix\\edix.exw")
if sequence(path) and length(path)=1 then
path[1][1] = mainpath&"demo\\edix\\edix.exw"
mainpath &= "demo\\edix\\"
end if
elsif length(file)=k+9 -- ie as in "edita.exw"
and equal(file[k+1..k+9],"edita.exw") then
--DEV newEmit...
if newEmit then
path = dir(mainpath&"demo\\edita\\edita.exw")
--?path
if sequence(path) and length(path)=1 then
-- path[1][1] = mainpath&path[1][1]
path[1][1] = mainpath&"demo\\edita\\edita.exw"
mainpath &= "demo\\edita\\"
--?mainpath
--?path
-- else
--?9/0
-- path = dir("C:\\Program Files (x86)\\Edita\\edita.exw")
-- if sequence(path) and length(path)=1 then
-- path[1][1] = "C:\\Program Files (x86)\\Edita\\"&path[1][1]
-- end if
end if
else -- old code
path = dir("C:\\Program Files\\Edita\\edita.exw")
if sequence(path) and length(path)=1 then
path[1][1] = "C:\\Program Files\\Edita\\"&path[1][1]
else
path = dir("C:\\Program Files (x86)\\Edita\\edita.exw")
if sequence(path) and length(path)=1 then
path[1][1] = "C:\\Program Files (x86)\\Edita\\"&path[1][1]
end if
end if
end if
--2/11/17 for tom: (if we could not find xx.exw, look for xx.ex)
elsif length(file)>4 and file[-4..-1]=".exw" then
path = {{file[1..$-1]}}
else
if find('*',file)>k then
path = dir(file)
if sequence(path) and length(path)=1 then
OptConsole = 1
if showfileprogress then
?"recurse"
end if
includeFile(mainpath&path[1][1],0,emitcol)
return
end if
end if
path = 0
end if
if sequence(path) and length(path)=1 then
path = path[1][1]
OptConsole = 1
if not find(SLASH,path) then
if find(path[1],"tT") then
path = mainpath&"test"&SLASH&path
elsif find(path[1],"bB") then
path = mainpath&"bench"&SLASH&path
end if
end if
if showfileprogress then
?"recurse2"
end if
includeFile(path,0,emitcol)
return
end if
end if
-- allow a top-level "include actual\path\really\required\xxx.e"
-- to do the job of stopping a nested (3rd party) "include xxx.e"
-- spannering the whole show; you can't find it now but it has the
-- same name as something managed prior, so just assume...
--DEV add this to the inc5 test set, eg:
--include test\t05\inc5\t2.e
--include t2.e
--?z
--abort(0)
--trace(1)
for i=1 to length(filenames) do
inpart = filenames[i]
inpart = filepaths[inpart[1]]&inpart[2]
k = match(file,inpart)
km1 = k-1
if k=length(inpart)-length(file)+1
and (k=1 or inpart[km1]=SLASH) then
--DEV for j=i+1 to length(filenames) do
-- report ambiguity
fileno = -i
return
end if
end for
?current_dir()
fatalmsg = "Cannot open "&file
if autoInclude then
fatalmsg = "Cannot open autoinclude "&file
end if
-- build list of directories searched:
if length(triedpaths) then
inpart = "\nin "
for i=1 to length(triedpaths)-1 do
fatalmsg &= inpart&triedpaths[i]&","
inpart = "\n "
end for
if equal(inpart,"\n ") then
inpart = "\nor "
end if
fatalmsg &= inpart&triedpaths[length(triedpaths)]&'.'
end if
tokcol = emitcol
if length(allfiles)=0
or autoInclude then
-- (no source line to report against)
Fatal(fatalmsg)
-- abort(1) -- Fatal() does not return
else
if intellisense
and trapfileno = fileno then
intellisense = 5
eof_processing()
end if
Abort(fatalmsg)
end if
end procedure
--without trace
constant Tmap = {"integer","atom","string","sequence","object"}
function unmapsig(sequence sig, integer ParmN)
-- (opposite of mapsig in psym.e)
string res
integer k
res = ""
for i=2 to length(sig) do
k = sig[i]
k = find(k,{T_integer,T_atom,T_string,T_sequence,T_object})
--DEV if k>T_object? (I think we are only doing builtins here anyway, but there is a ttree way to get names...)
if i-1=ParmN+1 then
res &= "["
end if
if length(res) then
res &= ","
end if
res &= Tmap[k]
end for
if length(sig)-1>ParmN then
res &= "]"
end if
return res
end function
--forward global function getBuiltinName(integer routineNo) -- defined in psym.e
global integer r_getBuiltinName
--with trace
integer ifn
function isDumpIds(sequence name, integer node)
-- intellisense output
sequence si,sf
integer symidx,fno,nTyp
object v
string tiptext
integer p, minp, maxp
symidx = tt[node+EQ]
if symidx>=1 and symidx<=length(symtab) then
-- loop added 03/02/14:
while symidx do
si = symtab[symidx]
fno = si[S_FPno]
if fno=fileno or fno=0 or and_bits(si[S_State],K_gbl) then
if trapmode=0 then -- standard lookup
puts(ifn,name&"\n")
elsif trapmode=1 then -- intellilink
-- 3/2/14:
-- if name=trapkey then
if name=trapkey
and (trapns=0 or trapns=fno) then
nTyp = si[S_NTyp]
if fno=0 then
if nTyp=S_Const then
v = si[S_value]
if integer(v) and v>15 then
printf(ifn,"Defined in psym.e with a value of %d[#%08x]\n",{v,v})
else
printf(ifn,"Defined in psym.e with a value of %s\n",{ppf(v)})
end if
elsif nTyp>=S_Type then
printf(ifn,"Defined in psym.e as builtin %s(%s)\n",{NTdesc[nTyp][1..$-1],unmapsig(si[S_sig],si[S_ParmN])})
else
printf(ifn,"Defined in psym.e as a %s\n",{NTdesc[nTyp]})
end if
elsif fno>length(filenames) then
-- picked apart and retried in eaisense.ew:
-- (ie/eg name=sort but we have hit EOF (as the file is cropped to cursor line/col) before
-- pmain.e/checkforbuiltins() has had a chance to load/parse builtins\psort.e; eaisense
-- will try "sort" again but this time with the full text of rootpath\builtins\psort.e)
string bname = call_func(r_getBuiltinName,{symidx})
printf(ifn,"Defined in psym.e as an autoinclude; %s not yet resolved, see %sbuiltins"&SLASH&"%s\n",
{name,rootpath,bname})
else
sf = filenames[fno]
if nTyp<=S_TVar then
tokcol = si[S_ErrV]
else
tokcol = si[S_ErrR]
end if
if equal(expandedYet[fno],0) then
text = allfiles[fno]
exptext[fno] = expandIntoLines()
expandedYet[fno] = linestarts
text = allpfiles[fno]
else
linestarts = expandedYet[fno]
end if
convertToLineColumn(tokcol)
printf(ifn,"%s%s:%d\n",{filepaths[sf[1]],sf[2],eLine})
end if
end if
elsif trapmode=3 then -- intellitip
--DEV parameters...
if name=trapkey
and (trapns=0 or trapns=fno) then
-- puts(ifn,name&"(")
nTyp = si[S_NTyp]
if nTyp>=S_Type then
if fno=0 then
-- if 1 then