summaryrefslogtreecommitdiff
path: root/scripts/context/ruby/texutil.rb
blob: ee0fc1e5e400e3c4abc444e6dc59f05185c51677 (plain)
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
banner = ['TeXUtil  ', 'version 9.1.0', '1997-2005', 'PRAGMA ADE/POD']

$: << File.expand_path(File.dirname($0)) ; $: << File.join($:.last,'lib') ; $:.uniq!

require 'base/switch'
require 'base/logger'
require 'base/file'
require 'base/texutil'

class Commands

    include CommandBase

    def references
        filename = @commandline.argument('first')
        if not filename.empty? and FileTest.file?(File.suffixed(filename,'tuo')) then
            if tu = TeXUtil::Converter.new(logger) and tu.loaded(filename) then
                tu.saved if tu.processed
            end
        end
    end

    def main
        if @commandline.arguments.length>0 then
            references
        else
            help
        end
    end

    def purgefiles
        system("texmfstart ctxtools --purge #{@commandline.arguments.join(' ')}")
    end

    def purgeallfiles
        system("texmfstart ctxtools --purge --all #{@commandline.arguments.join(' ')}")
    end

    def documentation
        system("texmfstart ctxtools --document #{@commandline.arguments.join(' ')}")
    end

    def analyzefile
        system("texmfstart pdftools --analyze #{@commandline.arguments.join(' ')}")
    end

    def filterpages # obsolete
        system("texmfstart ctxtools --purge #{@commandline.arguments.join(' ')}")
    end

    def figures
        report("this code is not yet converted from perl to ruby")
    end

    def logfile
        report("this code is not yet converted from perl to ruby")
    end

end

logger      = Logger.new(banner.shift)
commandline = CommandLine.new

# main feature

commandline.registeraction('references', 'convert tui file into tuo file')

# todo features

commandline.registeraction('figures', 'generate figure dimensions file')
commandline.registeraction('logfile', 'filter essential log messages')

# backward compatibility features

commandline.registeraction('purgefiles', 'remove most temporary files')
commandline.registeraction('purgeallfiles', 'remove all temporary files')
commandline.registeraction('documentation', 'generate documentation file from source')
commandline.registeraction('analyzefile', 'analyze pdf file')

# old feature, not needed any longer due to extension of pdftex

commandline.registeraction('filterpages')

# generic features

commandline.registeraction('help')
commandline.registeraction('version')

commandline.registerflag('verbose')

commandline.expand

Commands.new(commandline,logger,banner).send(commandline.action || 'main')