core-sys.lua /size: 4114 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
core-sys
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to core-sys.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
local
lower
,
format
,
gsub
=
string
.
lower
,
string
.
format
,
string
.
gsub
10
local
suffixonly
,
basename
,
removesuffix
=
file
.
suffix
,
file
.
basename
,
file
.
removesuffix
11 12
local
environment
=
environment
13
local
context
=
context
14
local
implement
=
interfaces
.
implement
15 16
local
report_files
=
logs
.
reporter
(
"
system
"
,
"
files
"
)
17 18
function
environment
.
initializefilenames
(
)
19 20
local
arguments
=
environment
.
arguments
21 22
local
jobname
=
arguments
.
jobname
or
tex
.
jobname
23
local
fulljobname
=
arguments
.
fulljobname
or
jobname
24
local
inputfilename
=
arguments
.
input
or
fulljobname
25
local
outputfilename
=
arguments
.
result
or
removesuffix
(
jobname
)
26 27
local
inputfilename
=
suffixonly
(
inputfilename
)
=
=
"
tex
"
and
removesuffix
(
inputfilename
)
or
inputfilename
or
"
"
28 29
local
filename
=
fulljobname
30
local
suffix
=
suffixonly
(
filename
)
31 32
local
filename
=
ctxrunner
.
resolve
(
filename
)
-- in case we're prepped
33 34
local
jobfilename
=
jobname
or
inputfilename
or
tex
.
jobname
or
"
"
35
local
inputfilename
=
inputfilename
or
"
"
36 37
local
jobfilebase
=
basename
(
jobfilename
)
38
local
inputfilebase
=
basename
(
inputfilename
)
39 40
-- jobfilename = gsub(jobfilename, "^./","")
41
-- inputfilename = gsub(inputfilename,"^./","")
42 43
environment
.
jobfilefullname
=
fulljobname
44
environment
.
jobfilename
=
jobfilebase
45
environment
.
jobfilesuffix
=
lower
(
suffixonly
(
jobfilebase
)
)
46 47
environment
.
inputfilename
=
inputfilename
-- so here we keep e.g. ./ or explicit paths
48
environment
.
inputfilebarename
=
removesuffix
(
inputfilebase
)
49
environment
.
inputfilesuffix
=
lower
(
suffixonly
(
inputfilebase
)
)
50 51
environment
.
outputfilename
=
outputfilename
or
environment
.
inputfilebarename
or
"
"
52 53
environment
.
filename
=
filename
54
environment
.
suffix
=
suffix
55 56
-- if tex then
57
-- tex.jobname = jobfilename
58
-- end
59 60
report_files
(
"
jobname %a, input %a, result %a
"
,
jobfilename
,
inputfilename
,
outputfilename
)
61 62
function
environment
.
initializefilenames
(
)
end
63
end
64 65
-- we could set a macro (but will that work when we're expanding? needs testing!)
66 67
implement
{
name
=
"
operatingsystem
"
,
actions
=
function
(
)
context
(
os
.
platform
)
end
}
68
implement
{
name
=
"
jobfilefullname
"
,
actions
=
function
(
)
context
(
environment
.
jobfilefullname
)
end
}
69
implement
{
name
=
"
jobfilename
"
,
actions
=
function
(
)
context
(
environment
.
jobfilename
)
end
}
70
implement
{
name
=
"
jobfilesuffix
"
,
actions
=
function
(
)
context
(
environment
.
jobfilesuffix
)
end
}
71
implement
{
name
=
"
inputfilebarename
"
,
actions
=
function
(
)
context
(
environment
.
inputfilebarename
)
end
}
72
implement
{
name
=
"
inputfilerealsuffix
"
,
actions
=
function
(
)
context
(
environment
.
inputfilerealsuffix
)
end
}
73
implement
{
name
=
"
inputfilesuffix
"
,
actions
=
function
(
)
context
(
environment
.
inputfilesuffix
)
end
}
74
implement
{
name
=
"
inputfilename
"
,
actions
=
function
(
)
context
(
environment
.
inputfilename
)
end
}
75
implement
{
name
=
"
outputfilename
"
,
actions
=
function
(
)
context
(
environment
.
outputfilename
)
end
}
76 77
statistics
.
register
(
"
result saved in file
"
,
function
(
)
78
-- suffix will be fetched from backend
79
local
outputfilename
=
environment
.
outputfilename
or
environment
.
jobname
or
tex
.
jobname
or
"
<unset>
"
80
-- if (tex.pdfoutput or tex.outputmode) > 0 then
81
return
format
(
"
%s.%s, compresslevel %s, objectcompresslevel %s
"
,
outputfilename
,
"
pdf
"
,
82
lpdf
.
getcompression
(
)
83
)
84
-- else
85
-- return format("%s.%s",outputfilename,"dvi") -- hard to imagine
86
-- end
87
end
)
88 89
implement
{
90
name
=
"
systemlog
"
,
91
arguments
=
"
3 strings
"
,
92
actions
=
function
(
whereto
,
category
,
text
)
93
logs
.
system
(
whereto
,
"
context
"
,
tex
.
jobname
,
category
,
text
)
94
end
,
95
}
96