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
|
#!/usr/bin/env ruby
# program : tmftools
# copyright : PRAGMA Advanced Document Engineering
# version : 2005
# author : Hans Hagen
#
# project : ConTeXt
# concept : Hans Hagen
# info : j.hagen@xs4all.nl
# www : www.pragma-ade.com
# The script based alternative is not slower than the kpse one.
# Loading is a bit faster when the log file is used.
# todo: create database
# tmftools [some of the kpsewhich switches]
# tmftools --analyze
# tmftools --analyze > kpsewhat.log
# tmftools --analyze --strict > kpsewhat.log
# tmftools --analyze --delete --force "texmf-local/fonts/.*/somename"
# the real thing
banner = ['TMFTools', 'version 1.0.0 (experimental, no help yet)', '2005', 'PRAGMA ADE/POD']
unless defined? ownpath
ownpath = $0.sub(/[\\\/][a-z0-9\-]*?\.rb/i,'')
$: << ownpath
end
require 'base/switch'
require 'base/logger'
require 'base/kpsefast'
class Commands
include CommandBase
def init_kpse
k = KPSEFAST.new
k.rootpath = @commandline.option('rootpath')
k.treepath = @commandline.option('treepath')
k.progname = @commandline.option('progname')
k.engine = @commandline.option('engine')
k.format = @commandline.option('format')
k.diskcache = @commandline.option('diskcache')
k.renewcache = @commandline.option('renewcache')
k.load_cnf
k.expand_variables
k.load_lsr
return k
end
def main
if option = @commandline.option('expand-braces') and not option.empty? then
puts init_kpse.expand_braces(option)
elsif option = @commandline.option('expand-path') and not option.empty? then
puts init_kpse.expand_path(option)
elsif option = @commandline.option('expand-var') and not option.empty? then
if option == '*' then
init_kpse.list_expansions()
else
puts init_kpse.expand_var(option)
end
elsif option = @commandline.option('show-path') and not option.empty? then
puts init_kpse.show_path(option)
elsif option = @commandline.option('var-value') and not option.empty? then
if option == '*' then
init_kpse.list_variables()
else
puts init_kpse.expand_var(option)
end
elsif @commandline.arguments.size > 0 then
kpse = init_kpse
@commandline.arguments.each do |option|
puts kpse.find_file(option)
end
else
help
end
end
def analyze
pattern = @commandline.argument('first')
strict = @commandline.option('strict')
sort = @commandline.option('sort')
delete = @commandline.option('delete') and @commandline.option('force')
init_kpse.analyze_files(pattern, strict, sort, delete)
end
end
logger = Logger.new(banner.shift)
commandline = CommandLine.new
# kpsewhich compatible options
commandline.registervalue('expand-braces','')
commandline.registervalue('expand-path','')
commandline.registervalue('expand-var','')
commandline.registervalue('show-path','')
commandline.registervalue('var-value','')
commandline.registervalue('engine','')
commandline.registervalue('progname','')
commandline.registervalue('format','')
# additional goodies
commandline.registervalue('rootpath','')
commandline.registervalue('treepath','')
commandline.registervalue('sort','')
commandline.registerflag('diskcache')
commandline.registerflag('renewcache')
commandline.registerflag('strict')
commandline.registerflag('delete')
commandline.registerflag('force')
commandline.registeraction('analyze', "[--strict --sort --rootpath --treepath]\n[--delete [--force]] [pattern]")
# general purpose options
commandline.registerflag('verbose')
commandline.registeraction('help')
commandline.registeraction('version')
commandline.expand
Commands.new(commandline,logger,banner).send(commandline.action || 'main')
|