mtx-context-compare.tex /size: 2307 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=mtx-context-compare,
3
%D version=2015.07.14,
4
%D title=\CONTEXT\ Extra Trickry,
5
%D subtitle=Compare Files,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
% begin help
15
%
16
% usage: context --extra=compare [options] file-1 file-2
17
%
18
% example: context --extra=compare file1.pdf file-2.pdf
19
%
20
% end help
21 22
\input
mtx
-
context
-
common
.
tex
23 24
\starttext
25 26
\starttexdefinition
unexpanded
ShowBoth
#
1
#
2
#
3
27
\startTEXpage
28
\startoverlay
29
{
\externalfigure
[#
1
][
page
=#
3
]
}
30
{
\externalfigure
[#
2
][
page
=#
3
]
}
31
\stopoverlay
32
\stopTEXpage
33
\stoptexdefinition
34 35
\starttexdefinition
unexpanded
ShowPage
#
1
#
2
36
\startTEXpage
37
\externalfigure
[#
1
][
page
=#
2
]
38
\stopTEXpage
39
\stoptexdefinition
40 41 42
\startluacode
43 44
local
report
=
logs
.
reporter
(
"
compare
"
)
45 46
local
fileone
=
document
.
files
[
1
]
or
"
"
47
local
filetwo
=
document
.
files
[
2
]
or
"
"
48 49
if
fileone
=
=
"
"
or
filetwo
=
=
"
"
then
50
report
(
"
provide two filenames
"
)
51
os
.
exit
(
)
52
end
53 54
if
not
lfs
.
isfile
(
fileone
)
then
55
report
(
"
unknown file %a
"
,
fileone
)
56
os
.
exit
(
)
57
end
58 59
if
not
lfs
.
isfile
(
filetwo
)
then
60
report
(
"
unknown file %a
"
,
filetwo
)
61
os
.
exit
(
)
62
end
63 64
local
function
check
(
name
)
65
local
fig
=
figures
.
push
{
name
=
name
}
66
figures
.
identify
(
)
67
figures
.
check
(
)
68
local
used
=
fig
.
used
69
figures
.
pop
(
)
70
return
used
71
end
72 73
local
one
=
check
(
fileone
)
74
local
two
=
check
(
filetwo
)
75 76
if
not
one
then
77
report
(
"
invalid file %a
"
,
fileone
)
78
os
.
exit
(
)
79
end
80 81
if
not
two
then
82
report
(
"
invalid file %a
"
,
filetwo
)
83
os
.
exit
(
)
84
end
85 86
local
n_one
=
tonumber
(
one
.
pages
)
87
local
n_two
=
tonumber
(
two
.
pages
)
88 89
if
not
n_one
or
n_one
~
=
n_two
then
90
report
(
"
files have different nofpages (%s vs %s)
"
,
n_one
or
"
?
"
,
n_two
or
"
?
"
)
91
end
92 93
if
n_one
>
n_two
then
94
for
i
=
1
,
n_two
do
95
context
.
ShowBoth
(
fileone
,
filetwo
,
i
)
96
end
97
for
i
=
n_two
+
1
,
n_one
do
98
context
.
ShowPage
(
fileone
,
i
)
99
end
100
else
101
for
i
=
1
,
n_one
do
102
context
.
ShowBoth
(
fileone
,
filetwo
,
i
)
103
end
104
for
i
=
n_one
+
1
,
n_two
do
105
context
.
ShowPage
(
filetwo
,
i
)
106
end
107
end
108 109
\stopluacode
110 111
\stoptext
112 113
\endinput
114