21637
21634
copyright="PRAGMA ADE / ConTeXt Development Team",
21638
21635
license="see context related readme files"
21640
local format,lower,gsub,concat=string.format,string.lower,string.gsub,table.concat
21641
local concat=table.concat
21642
local mkdirs,isdir,isfile=dir.mkdirs,lfs.isdir,lfs.isfile
21643
local addsuffix,is_writable,is_readable=file.addsuffix,file.is_writable,file.is_readable
21637
local next,type=next,type
21638
local pcall,loadfile,collectgarbage=pcall,loadfile,collectgarbage
21639
local format,lower,gsub=string.format,string.lower,string.gsub
21640
local concat,serialize,fastserialize,serializetofile=table.concat,table.serialize,table.fastserialize,table.tofile
21641
local mkdirs,expanddirname,isdir,isfile=dir.mkdirs,dir.expandname,lfs.isdir,lfs.isfile
21642
local is_writable,is_readable=file.is_writable,file.is_readable
21643
local collapsepath,joinfile,addsuffix,dirname=file.collapsepath,file.join,file.addsuffix,file.dirname
21644
local savedata=file.savedata
21644
21645
local formatters=string.formatters
21645
local next,type=next,type
21646
local osexit,osdate,osuuid=os.exit,os.date,os.uuid
21647
local removefile=os.remove
21648
local md5hex=md5.hex
21646
21649
local trace_locating=false trackers.register("resolvers.locating",function(v) trace_locating=v end)
21647
21650
local trace_cache=false trackers.register("resolvers.cache",function(v) trace_cache=v end)
21648
21651
local report_caches=logs.reporter("resolvers","caches")
21649
21652
local report_resolvers=logs.reporter("resolvers","caching")
21650
21653
local resolvers=resolvers
21651
21654
local cleanpath=resolvers.cleanpath
21652
local directive_cleanup=false directives.register("system.compile.cleanup",function(v) directive_cleanup=v end)
21653
local directive_strip=false directives.register("system.compile.strip",function(v) directive_strip=v end)
21654
local compile=utilities.lua.compile
21655
function utilities.lua.compile(luafile,lucfile,cleanup,strip)
21656
if cleanup==nil then cleanup=directive_cleanup end
21657
if strip==nil then strip=directive_strip end
21658
return compile(luafile,lucfile,cleanup,strip)
21655
local resolvepath=resolvers.resolve
21656
local luautilities=utilities.lua
21658
local directive_cleanup=false directives.register("system.compile.cleanup",function(v) directive_cleanup=v end)
21659
local directive_strip=false directives.register("system.compile.strip",function(v) directive_strip=v end)
21660
local compilelua=luautilities.compile
21661
function luautilities.compile(luafile,lucfile,cleanup,strip)
21662
if cleanup==nil then cleanup=directive_cleanup end
21663
if strip==nil then strip=directive_strip end
21664
return compilelua(luafile,lucfile,cleanup,strip)
21660
21667
caches=caches or {}
21661
21668
local caches=caches
21662
local luasuffixes=utilities.lua.suffixes
21663
caches.base=caches.base or "luatex-cache"
21664
caches.more=caches.more or "context"
21665
caches.direct=false
21669
caches.relocate=false
21671
local usedreadables={}
21672
local compilelua=luautilities.compile
21673
local luasuffixes=luautilities.suffixes
21674
caches.base=caches.base or "luatex-cache"
21675
caches.more=caches.more or "context"
21670
21676
caches.defaults={ "TMPDIR","TEMPDIR","TMP","TEMP","HOME","HOMEPATH" }
21671
directives.register("system.caches.fast",function(v) caches.fast=true end)
21672
directives.register("system.caches.direct",function(v) caches.direct=true end)
21673
local writable,readables,usedreadables=nil,{},{}
21677
local direct_cache=false
21678
local fast_cache=false
21679
local cache_tree=false
21680
directives.register("system.caches.direct",function(v) direct_cache=true end)
21681
directives.register("system.caches.fast",function(v) fast_cache=true end)
21682
local function configfiles()
21683
return concat(resolvers.configurationfiles(),";")
21685
local function hashed(tree)
21686
tree=gsub(tree,"[\\/]+$","")
21688
local hash=md5hex(tree)
21689
if trace_cache or trace_locating then
21690
report_caches("hashing tree %a, hash %a",tree,hash)
21694
local function treehash()
21695
local tree=configfiles()
21696
if not tree or tree=="" then
21699
return hashed(tree)
21702
caches.hashed=hashed
21703
caches.treehash=treehash
21704
caches.configfiles=configfiles
21674
21705
local function identify()
21675
21706
local texmfcaches=resolvers.cleanpathlist("TEXMFCACHE")
21676
21707
if texmfcaches then
21677
21708
for k=1,#texmfcaches do
21678
21709
local cachepath=texmfcaches[k]
21679
21710
if cachepath~="" then
21680
cachepath=resolvers.resolve(cachepath)
21681
cachepath=resolvers.cleanpath(cachepath)
21682
cachepath=file.collapsepath(cachepath)
21711
cachepath=resolvepath(cachepath)
21712
cachepath=cleanpath(cachepath)
21713
cachepath=collapsepath(cachepath)
21683
21714
local valid=isdir(cachepath)
21684
21715
if valid then
21685
21716
if is_readable(cachepath) then
22216
22262
resolvers.getenv=getenv
22217
resolvers.env=getenv
22218
local function resolvevariable(k)
22219
return instance.expansions[k]
22263
resolvers.setenv=setenv
22221
22264
local dollarstripper=lpeg.stripper("$")
22222
22265
local inhibitstripper=P("!")^0*Cs(P(1)^0)
22223
local somevariable=P("$")/""
22224
local somekey=C(R("az","AZ","09","__","--")^1)
22225
local somethingelse=P(";")*((1-S("!{}/\\"))^1*P(";")/"")+P(";")*(P(";")/"")+P(1)
22226
local variableexpander=Cs((somevariable*(somekey/resolvevariable)+somethingelse)^1 )
22227
local cleaner=P("\\")/"/"+P(";")*S("!{}/\\")^0*P(";")^1/";"
22228
local variablecleaner=Cs((cleaner+P(1))^0)
22229
local somevariable=R("az","AZ","09","__","--")^1/resolvevariable
22230
local variable=(P("$")/"")*(somevariable+(P("{")/"")*somevariable*(P("}")/""))
22231
local variableresolver=Cs((variable+P(1))^0)
22232
local function expandedvariable(var)
22233
return lpegmatch(variableexpander,var) or var
22235
function resolvers.reset()
22236
if trace_locating then
22237
report_resolving("creating instance")
22239
local environment={}
22241
local expansions={}
22244
environment=environment,
22245
variables=variables,
22246
expansions=expansions,
22266
force_suffixes=true,
22269
setmetatableindex(variables,function(t,k)
22266
local expandedvariable,resolvedvariable do
22267
local function resolveinstancevariable(k)
22268
return instance.expansions[k]
22270
local p_variable=P("$")/""
22271
local p_key=C(R("az","AZ","09","__","--")^1)
22272
local p_whatever=P(";")*((1-S("!{}/\\"))^1*P(";")/"")+P(";")*(P(";")/"")+P(1)
22273
local variableexpander=Cs((p_variable*(p_key/resolveinstancevariable)+p_whatever)^1 )
22274
local p_cleaner=P("\\")/"/"+P(";")*S("!{}/\\")^0*P(";")^1/";"
22275
local variablecleaner=Cs((p_cleaner+P(1))^0)
22276
local p_variable=R("az","AZ","09","__","--")^1/resolveinstancevariable
22277
local p_variable=(P("$")/"")*(p_variable+(P("{")/"")*p_variable*(P("}")/""))
22278
local variableresolver=Cs((p_variable+P(1))^0)
22279
expandedvariable=function(var)
22280
return lpegmatch(variableexpander,var) or var
22282
function resolvers.reset()
22283
if trace_locating then
22284
report_resolving("creating instance")
22286
local environment={}
22288
local expansions={}
22291
environment=environment,
22292
variables=variables,
22293
expansions=expansions,
22313
force_suffixes=true,
22316
setmetatableindex(variables,function(t,k)
22331
local repath=resolvers.repath
22332
setmetatableindex(environment,function(t,k)
22333
local v=osgetenv(k)
22273
22337
if v~=nil then
22284
setmetatableindex(environment,function(t,k)
22285
local v=osgetenv(k)
22290
v=checkedvariable(v) or ""
22292
v=resolvers.repath(v)
22296
setmetatableindex(expansions,function(t,k)
22297
local v=environment[k]
22298
if type(v)=="string" then
22299
v=lpegmatch(variableresolver,v)
22300
v=lpegmatch(variablecleaner,v)
22338
v=checkedvariable(v) or ""
22344
setmetatableindex(expansions,function(t,k)
22345
local v=environment[k]
22346
if type(v)=="string" then
22347
v=lpegmatch(variableresolver,v)
22348
v=lpegmatch(variablecleaner,v)
22306
22355
function resolvers.initialized()
22307
22356
return instance~=nil
22595
22652
function resolvers.appendhash(type,name,cache)
22596
if not instance.hashed[name] then
22653
local hashed=instance.hashed
22654
local hashes=instance.hashes
22655
if hashed[name] then
22597
22657
if trace_locating then
22598
22658
report_resolving("hash %a appended",name)
22600
insert(instance.hashes,{ type=type,name=name,cache=cache } )
22601
instance.hashed[name]=cache
22660
insert(hashes,{ type=type,name=name,cache=cache } )
22604
22664
function resolvers.prependhash(type,name,cache)
22605
if not instance.hashed[name] then
22665
local hashed=instance.hashed
22666
local hashes=instance.hashes
22667
if hashed[name] then
22606
22669
if trace_locating then
22607
22670
report_resolving("hash %a prepended",name)
22609
insert(instance.hashes,1,{ type=type,name=name,cache=cache } )
22610
instance.hashed[name]=cache
22672
insert(hashes,1,{ type=type,name=name,cache=cache } )
22613
22676
function resolvers.extendtexmfvariable(specification)
22614
local t=resolvers.splitpath(getenv("TEXMF"))
22615
insert(t,1,specification)
22616
local newspec=concat(t,",")
22617
if instance.environment["TEXMF"] then
22618
instance.environment["TEXMF"]=newspec
22619
elseif instance.variables["TEXMF"] then
22620
instance.variables["TEXMF"]=newspec
22677
local environment=instance.environment
22678
local variables=instance.variables
22679
local texmftrees=splitpath(getenv("TEXMF"))
22680
insert(texmftrees,1,specification)
22681
texmftrees=concat(texmftrees,",")
22682
if environment["TEXMF"] then
22683
environment["TEXMF"]=texmftrees
22684
elseif variables["TEXMF"] then
22685
variables["TEXMF"]=texmftrees
22623
22688
reset_hashes()
22625
22690
function resolvers.splitexpansions()
22626
local ie=instance.expansions
22627
for k,v in next,ie do
22691
local expansions=instance.expansions
22692
for k,v in next,expansions do
22628
22693
local t,tn,h,p={},0,{},splitconfigurationpath(v)
22629
22694
for kk=1,#p do
22630
22695
local vv=p[kk]
22836
22895
local lists=instance.lists
22837
22896
local lst=lists[str]
22838
22897
if not lst then
22839
local l=made_list(instance,resolvers.splitpath(resolvers.expansion(str)),extra_too)
22898
local l=made_list(instance,splitpath(expansion(str)),extra_too)
22840
22899
lst=expandedpathfromlist(l)
22841
22900
lists[str]=lst
22845
local lst=resolvers.splitpath(resolvers.expansion(str))
22904
local lst=splitpath(expansion(str))
22846
22905
return made_list(instance,expandedpathfromlist(lst),extra_too)
22849
function resolvers.expandedpathlistfromvariable(str)
22908
resolvers.expandedpathlist=expandedpathlist
22909
resolvers.unexpandedpathlist=unexpandedpathlist
22910
function resolvers.cleanpathlist(str)
22911
local t=expandedpathlist(str)
22914
t[i]=collapsepath(cleanpath(t[i]))
22919
function resolvers.expandpath(str)
22920
return joinpath(expandedpathlist(str))
22922
local function expandedpathlistfromvariable(str)
22850
22923
str=lpegmatch(dollarstripper,str)
22851
22924
local tmp=resolvers.variableofformatorsuffix(str)
22852
return resolvers.expandedpathlist(tmp~="" and tmp or str)
22925
return expandedpathlist(tmp~="" and tmp or str)
22854
22927
function resolvers.expandpathfromvariable(str)
22855
return joinpath(resolvers.expandedpathlistfromvariable(str))
22928
return joinpath(expandedpathlistfromvariable(str))
22930
resolvers.expandedpathlistfromvariable=expandedpathlistfromvariable
22857
22931
function resolvers.cleanedpathlist(v)
22858
local t=resolvers.expandedpathlist(v)
22932
local t=expandedpathlist(v)
22859
22933
for i=1,#t do
22860
t[i]=resolvers.resolve(resolvers.cleanpath(t[i]))
22934
t[i]=resolveprefix(cleanpath(t[i]))
22864
22938
function resolvers.expandbraces(str)
22865
local pth=expandedpathfromlist(resolvers.splitpath(str))
22939
local pth=expandedpathfromlist(splitpath(str))
22866
22940
return joinpath(pth)
22868
22942
function resolvers.registerfilehash(name,content,someerror)
22943
local files=instance.files
22869
22944
if content then
22870
instance.files[name]=content
22945
files[name]=content
22872
instance.files[name]={}
22873
22948
if somerror==true then
22874
22949
instance.loaderror=someerror
23921
24010
copyright="PRAGMA ADE / ConTeXt Development Team",
23922
24011
license="see context related readme files"
24013
local ioopen=io.open
24014
local isdir=lfs.isdir
23924
24015
local trace_locating=false trackers.register("resolvers.locating",function(v) trace_locating=v end)
23925
24016
local report_files=logs.reporter("resolvers","files")
23926
24017
local resolvers=resolvers
23927
24018
local resolveprefix=resolvers.resolve
23928
local finders,openers,loaders,savers=resolvers.finders,resolvers.openers,resolvers.loaders,resolvers.savers
23929
local locators,hashers,generators,concatinators=resolvers.locators,resolvers.hashers,resolvers.generators,resolvers.concatinators
24019
local findfile=resolvers.findfile
24020
local scanfiles=resolvers.scanfiles
24021
local registerfilehash=resolvers.registerfilehash
24022
local appendhash=resolvers.appendhash
24023
local loadcachecontent=caches.loadcontent
23930
24024
local checkgarbage=utilities.garbagecollector and utilities.garbagecollector.check
23931
function locators.file(specification)
24025
function resolvers.locators.file(specification)
23932
24026
local filename=specification.filename
23933
24027
local realname=resolveprefix(filename)
23934
if realname and realname~='' and lfs.isdir(realname) then
24028
if realname and realname~='' and isdir(realname) then
23935
24029
if trace_locating then
23936
24030
report_files("file locator %a found as %a",filename,realname)
23938
resolvers.appendhash('file',filename,true)
24032
appendhash('file',filename,true)
23939
24033
elseif trace_locating then
23940
24034
report_files("file locator %a not found",filename)
23943
function hashers.file(specification)
23944
local pathname=specification.filename
23945
local content=caches.loadcontent(pathname,'files')
23946
resolvers.registerfilehash(pathname,content,content==nil)
23948
function generators.file(specification)
23949
local pathname=specification.filename
23950
local content=resolvers.scanfiles(pathname,false,true)
23951
resolvers.registerfilehash(pathname,content,true)
23953
concatinators.file=file.join
24037
function resolvers.hashers.file(specification)
24038
local pathname=specification.filename
24039
local content=loadcachecontent(pathname,'files')
24040
registerfilehash(pathname,content,content==nil)
24042
function resolvers.generators.file(specification)
24043
local pathname=specification.filename
24044
local content=scanfiles(pathname,false,true)
24045
registerfilehash(pathname,content,true)
24047
resolvers.concatinators.file=file.join
24048
local finders=resolvers.finders
24049
local notfound=finders.notfound
23954
24050
function finders.file(specification,filetype)
23955
24051
local filename=specification.filename
23956
local foundname=resolvers.findfile(filename,filetype)
24052
local foundname=findfile(filename,filetype)
23957
24053
if foundname and foundname~="" then
23958
24054
if trace_locating then
23959
24055
report_files("file finder: %a found",filename)
23963
24059
if trace_locating then
23964
24060
report_files("file finder: %a not found",filename)
23966
return finders.notfound()
23969
function openers.helpers.textopener(tag,filename,f)
24065
local openers=resolvers.openers
24066
local notfound=openers.notfound
24067
local overloaded=false
24068
local function textopener(tag,filename,f)
23971
reader=function() return f:read () end,
23972
close=function() logs.show_close(filename) return f:close() end,
24070
reader=function() return f:read () end,
24071
close=function() return f:close() end,
24074
function openers.helpers.textopener(...)
24075
return textopener(...)
24077
function openers.helpers.settextopener(opener)
24079
report_files("file opener: %s overloaded","already")
24081
if trace_locating then
24082
report_files("file opener: %s overloaded","once")
23975
24088
function openers.file(specification,filetype)
23976
24089
local filename=specification.filename
23977
24090
if filename and filename~="" then
23978
local f=io.open(filename,"r")
24091
local f=ioopen(filename,"r")
23980
24093
if trace_locating then
23981
24094
report_files("file opener: %a opened",filename)
23983
return openers.helpers.textopener("file",filename,f)
24096
return textopener("file",filename,f)
23986
24099
if trace_locating then
23987
24100
report_files("file opener: %a not found",filename)
23989
return openers.notfound()
24104
local loaders=resolvers.loaders
24105
local notfound=loaders.notfound
23991
24106
function loaders.file(specification,filetype)
23992
24107
local filename=specification.filename
23993
24108
if filename and filename~="" then
23994
local f=io.open(filename,"rb")
24109
local f=ioopen(filename,"rb")
23996
logs.show_load(filename)
23997
24111
if trace_locating then
23998
24112
report_files("file loader: %a loaded",filename)
24476
24580
if trace_locating then
24477
24581
report_zip("loader: %a not found",original)
24479
return resolvers.openers.notfound()
24481
function resolvers.usezipfile(archive)
24482
local specification=resolvers.splitmethod(archive)
24483
local archive=specification.filename
24484
if archive and not registeredfiles[archive] then
24485
local z=zip.openarchive(archive)
24487
local tree=url.query(specification.query).tree or ""
24488
if trace_locating then
24489
report_zip("registering: archive %a",archive)
24491
resolvers.starttiming()
24492
resolvers.prependhash('zip',archive)
24493
resolvers.extendtexmfvariable(archive)
24494
registeredfiles[archive]=z
24495
resolvers.registerfilehash(archive,resolvers.registerzipfile(z,tree))
24496
resolvers.stoptiming()
24497
elseif trace_locating then
24498
report_zip("registering: unknown archive %a",archive)
24500
elseif trace_locating then
24501
report_zip("registering: archive %a not found",archive)
24504
function resolvers.registerzipfile(z,tree)
24585
local function registerzipfile(z,tree)
24505
24586
local names={}
24506
24587
local files={}
24507
24588
local remap={}
24509
24590
local filter=tree=="" and "^(.+)/(.-)$" or format("^%s/(.+)/(.-)$",tree)
24510
local register=resolvers.registerfile
24511
24591
if trace_locating then
24512
24592
report_zip("registering: using filter %a",filter)
24514
24595
for i in traversezip(z) do
24515
24596
local filename=i.filename
24516
24597
local path,name=match(filename,filter)
24517
24598
if not path then
24519
register(names,filename,"")
24600
registerfile(names,filename,"")
24520
24601
local usedname=lower(filename)
24521
24602
files[usedname]=""
24522
24603
if usedname~=filename then
24563
24675
local trace_locating=false trackers.register("resolvers.locating",function(v) trace_locating=v end)
24564
24676
local report_trees=logs.reporter("resolvers","trees")
24565
24677
local resolvers=resolvers
24566
local resolveprefix=resolvers.resolve
24567
local notfound=resolvers.finders.notfound
24568
local lookup=resolvers.get_from_content
24569
local collectors={}
24571
function resolvers.finders.tree(specification)
24572
local spec=specification.filename
24573
local okay=found[spec]
24576
local path=dirname(spec)
24577
local name=basename(spec)
24581
local names=collectors[path]
24583
local pattern=find(path,"/%*+$") and path or (path.."/*")
24584
names=globdir(pattern)
24585
collectors[path]=names
24587
local pattern="/"..gsub(name,"([%.%-%+])","%%%1").."$"
24589
local fullname=names[i]
24590
if find(fullname,pattern) then
24591
found[spec]=fullname
24595
local pattern=lower(pattern)
24597
local fullname=lower(names[i])
24598
if find(fullname,pattern) then
24599
if isfile(fullname) then
24678
local finders=resolvers.finders
24679
local openers=resolvers.openers
24680
local loaders=resolvers.loaders
24681
local locators=resolvers.locators
24682
local hashers=resolvers.hashers
24683
local generators=resolvers.generators
24685
local collectors={}
24687
local notfound=finders.notfound
24688
function finders.tree(specification)
24689
local spec=specification.filename
24690
local okay=found[spec]
24693
local path=dirname(spec)
24694
local name=basename(spec)
24698
local names=collectors[path]
24700
local pattern=find(path,"/%*+$") and path or (path.."/*")
24701
names=globdir(pattern)
24702
collectors[path]=names
24704
local pattern="/"..gsub(name,"([%.%-%+])","%%%1").."$"
24706
local fullname=names[i]
24707
if find(fullname,pattern) then
24600
24708
found[spec]=fullname
24601
24709
return fullname
24613
function resolvers.locators.tree(specification)
24614
local name=specification.filename
24615
local realname=resolveprefix(name)
24616
if realname and realname~='' and isdir(realname) then
24712
local pattern=lower(pattern)
24714
local fullname=lower(names[i])
24715
if find(fullname,pattern) then
24716
if isfile(fullname) then
24717
found[spec]=fullname
24732
local resolveprefix=resolvers.resolve
24733
local appendhash=resolvers.appendhash
24734
local function dolocate(specification)
24735
local name=specification.filename
24736
local realname=resolveprefix(name)
24737
if realname and realname~='' and isdir(realname) then
24738
if trace_locating then
24739
report_trees("locator %a found",realname)
24741
appendhash('tree',name,false)
24742
elseif trace_locating then
24743
report_trees("locator %a not found",name)
24746
locators.tree=dolocate
24747
locators.dirlist=dolocate
24748
locators.dirfile=dolocate
24751
local filegenerator=generators.file
24752
generators.dirlist=filegenerator
24753
generators.dirfile=filegenerator
24756
local filegenerator=generators.file
24757
local methodhandler=resolvers.methodhandler
24758
local function dohash(specification)
24759
local name=specification.filename
24617
24760
if trace_locating then
24618
report_trees("locator %a found",realname)
24620
resolvers.appendhash('tree',name,false)
24621
elseif trace_locating then
24622
report_trees("locator %a not found",name)
24625
function resolvers.hashers.tree(specification)
24626
local name=specification.filename
24627
if trace_locating then
24628
report_trees("analyzing %a",name)
24630
resolvers.methodhandler("hashers",name)
24631
resolvers.generators.file(specification)
24633
local collectors={}
24634
local splitter=lpeg.splitat("/**/")
24635
local stripper=lpeg.replacer { [P("/")*P("*")^1*P(-1)]="" }
24636
table.setmetatableindex(collectors,function(t,k)
24637
local rootname=lpegmatch(stripper,k)
24638
local dataname=joinname(rootname,"dirlist")
24639
local content=caches.loadcontent(dataname,"files",dataname)
24640
if not content then
24641
content=resolvers.scanfiles(rootname,nil,nil,false,true)
24642
caches.savecontent(dataname,"files",content,dataname)
24647
local function checked(root,p,n)
24649
if type(p)=="table" then
24651
local fullname=joinname(root,p[i],n)
24761
report_trees("analyzing %a",name)
24763
methodhandler("hashers",name)
24764
filegenerator(specification)
24766
hashers.tree=dohash
24767
hashers.dirlist=dohash
24768
hashers.dirfile=dohash
24771
local collectors={}
24772
local splitter=lpeg.splitat("/**/")
24773
local stripper=lpeg.replacer { [P("/")*P("*")^1*P(-1)]="" }
24774
local loadcontent=caches.loadcontent
24775
local savecontent=caches.savecontent
24776
local notfound=finders.notfound
24777
local scanfiles=resolvers.scanfiles
24778
local lookup=resolvers.get_from_content
24779
table.setmetatableindex(collectors,function(t,k)
24780
local rootname=lpegmatch(stripper,k)
24781
local dataname=joinname(rootname,"dirlist")
24782
local content=loadcontent(dataname,"files",dataname)
24783
if not content then
24784
content=scanfiles(rootname,nil,nil,false,true)
24785
savecontent(dataname,"files",content,dataname)
24790
local function checked(root,p,n)
24792
if type(p)=="table" then
24794
local fullname=joinname(root,p[i],n)
24795
if isfile(fullname) then
24800
local fullname=joinname(root,p,n)
24652
24801
if isfile(fullname) then
24653
24802
return fullname
24808
resolve=function(specification)
24809
local filename=specification.filename
24810
if filename~="" then
24811
local root,rest=lpegmatch(splitter,filename)
24812
if root and rest then
24813
local path,name=dirname(rest),basename(rest)
24815
local content=collectors[root]
24816
local p,n=lookup(content,name)
24820
local pattern=".*/"..path.."$"
24821
local istable=type(p)=="table"
24825
if pi==path or find(pi,pattern) then
24826
local fullname=joinname(root,pi,n)
24827
if isfile(fullname) then
24832
elseif p==path or find(p,pattern) then
24833
local fullname=joinname(root,p,n)
24834
if isfile(fullname) then
24838
local queries=specification.queries
24839
if queries and queries.option=="fileonly" then
24840
return checked(root,p,n)
24846
local path=dirname(filename)
24847
local name=basename(filename)
24848
local root=lpegmatch(stripper,path)
24849
local content=collectors[path]
24850
local p,n=lookup(content,name)
24852
return checked(root,p,n)
24857
finders.dirlist=resolve
24858
function finders.dirfile(specification)
24859
local queries=specification.queries
24861
queries.option="fileonly"
24657
local fullname=joinname(root,p,n)
24658
if isfile(fullname) then
24665
local function resolve(specification)
24666
local filename=specification.filename
24667
if filename~="" then
24668
local root,rest=lpegmatch(splitter,filename)
24669
if root and rest then
24670
local path,name=dirname(rest),basename(rest)
24672
local content=collectors[root]
24673
local p,n=lookup(content,name)
24677
local pattern=".*/"..path.."$"
24678
local istable=type(p)=="table"
24682
if pi==path or find(pi,pattern) then
24683
local fullname=joinname(root,pi,n)
24684
if isfile(fullname) then
24689
elseif p==path or find(p,pattern) then
24690
local fullname=joinname(root,p,n)
24691
if isfile(fullname) then
24695
local queries=specification.queries
24696
if queries and queries.option=="fileonly" then
24697
return checked(root,p,n)
24703
local path,name=dirname(filename),basename(filename)
24704
local root=lpegmatch(stripper,path)
24705
local content=collectors[path]
24706
local p,n=lookup(content,name)
24708
return checked(root,p,n)
24713
resolvers.finders .dirlist=resolve
24714
resolvers.locators .dirlist=resolvers.locators .tree
24715
resolvers.hashers .dirlist=resolvers.hashers .tree
24716
resolvers.generators.dirlist=resolvers.generators.file
24717
resolvers.openers .dirlist=resolvers.openers .file
24718
resolvers.loaders .dirlist=resolvers.loaders .file
24719
function resolvers.finders.dirfile(specification)
24720
local queries=specification.queries
24722
queries.option="fileonly"
24724
specification.queries={ option="fileonly" }
24726
return resolve(specification)
24728
resolvers.locators .dirfile=resolvers.locators .dirlist
24729
resolvers.hashers .dirfile=resolvers.hashers .dirlist
24730
resolvers.generators.dirfile=resolvers.generators.dirlist
24731
resolvers.openers .dirfile=resolvers.openers .dirlist
24732
resolvers.loaders .dirfile=resolvers.loaders .dirlist
24863
specification.queries={ option="fileonly" }
24865
return resolve(specification)
24869
local fileopener=openers.file
24870
local fileloader=loaders.file
24871
openers.dirlist=fileopener
24872
loaders.dirlist=fileloader
24873
openers.dirfile=fileopener
24874
loaders.dirfile=fileloader
24735
24878
end -- of closure
25173
25324
license="see context related readme files"
25175
25326
local type=type
25176
local concat,sortedhash=table.concat,table.sortedhash
25327
local sortedhash=table.sortedhash
25328
local isdir=lfs.isdir
25177
25329
local resolvers=resolvers
25178
25330
local listers=resolvers.listers or {}
25179
25331
resolvers.listers=listers
25180
25332
local resolveprefix=resolvers.resolve
25333
local configurationfiles=resolvers.configurationfiles
25334
local expandedpathfromlist=resolvers.expandedpathfromlist
25335
local splitpath=resolvers.splitpath
25336
local knownvariables=resolvers.knownvariables
25181
25337
local report_lists=logs.reporter("resolvers","lists")
25182
25338
local report_resolved=logs.reporter("system","resolved")
25183
local function tabstr(str)
25184
if type(str)=='table' then
25185
return concat(str," | ")
25190
25339
function listers.variables(pattern)
25191
25340
local result=resolvers.knownvariables(pattern)
25341
local unset={ "unset" }
25192
25342
for key,value in sortedhash(result) do
25193
25343
report_lists(key)
25194
report_lists(" env: %s",tabstr(value.environment or "unset"))
25195
report_lists(" var: %s",tabstr(value.variable or "unset"))
25196
report_lists(" exp: %s",tabstr(value.expansion or "unset"))
25197
report_lists(" res: %s",tabstr(value.resolved or "unset"))
25344
report_lists(" env: % | t",value.environment or unset)
25345
report_lists(" var: % | t",value.variable or unset)
25346
report_lists(" exp: % | t",value.expansion or unset)
25347
report_lists(" res: % | t",value.resolved or unset)
25200
25350
function listers.configurations()
25201
local configurations=resolvers.configurationfiles()
25351
local configurations=configurationfiles()
25202
25352
for i=1,#configurations do
25203
25353
report_resolved("file : %s",resolveprefix(configurations[i]))
25205
25355
report_resolved("")
25206
local list=resolvers.expandedpathfromlist(resolvers.splitpath(resolvers.luacnfspec))
25356
local list=expandedpathfromlist(splitpath(resolvers.luacnfspec))
25207
25357
for i=1,#list do
25208
25358
local li=resolveprefix(list[i])
25209
if lfs.isdir(li) then
25210
25360
report_resolved("path - %s",li)
25212
25362
report_resolved("path + %s",li)