texutil.rb / last modification: 2020-01-30 14:16
banner = ['TeXUtil  ', 'version 9.1.0', '1997-2005', 'PRAGMA ADE/POD']

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

require &#39;base/switch'
require &#39;base/logger'
require &#39;base/file'
require &#39;base/texutil'

class Commands

    include CommandBase

    def references
        filename = @commandline.argument(&#39;first')
        if not filename.empty? and FileTest.file?(File.suffixed(filename,&#39;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(&#39;references', 'convert tui file into tuo file')

# todo features

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

# backward compatibility features

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

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

commandline.registeraction(&#39;filterpages')

# generic features

commandline.registeraction(&#39;help')
commandline.registeraction(&#39;version')

commandline.registerflag(&#39;verbose')

commandline.expand

Commands.new(commandline,logger,banner).send(commandline.action || &#39;main')