rslibtool.rb / last modification: 2020-01-30 14:16
# program   : rslibtool
# copyright : PRAGMA Publishing On Demand
# version   : 1.00 - 2002
# author    : Hans Hagen
#
# project   : eXaMpLe
# concept   : Hans Hagen
# info      : j.hagen@xs4all.nl
# www       : www.pragma-pod.com / www.pragma-ade.com

# --add      --base=filename --path=directory pattern
# --remove   --base=filename --path=directory label
# --sort     --base=filename --path=directory
# --purge    --base=filename --path=directory
# --dummy    --base=filename
# --namespace

# rewrite

unless defined? ownpath
    ownpath = $0.sub(/[\\\/]\w*?\.rb/i,'')
    $: << ownpath
end

require &#39;rslb/base'
require &#39;xmpl/base'
require &#39;xmpl/switch'

session = Example.new(&#39;rslbtool', '1.0', 'PRAGMA POD')

session.identify

commandline = CommandLine.new

commandline.registerflag(&#39;add')
commandline.registerflag(&#39;remove')
commandline.registerflag(&#39;delete')
commandline.registerflag(&#39;sort')
commandline.registerflag(&#39;purge')
commandline.registerflag(&#39;dummy')
commandline.registerflag(&#39;process')
commandline.registerflag(&#39;namespace')

commandline.registervalue(&#39;prefix')
commandline.registervalue(&#39;base')
commandline.registervalue(&#39;path')
commandline.registervalue(&#39;result')
commandline.registervalue(&#39;texexec')
commandline.registervalue(&#39;zipalso')

commandline.expand

session.inherit(commandline)

base = session.get(&#39;option.base')
path = session.get(&#39;option.path')

base = &#39;rslbtool.xml' if base.empty?

# when path is given, assume that arg list is list of
# suffixes, else assume it is a list of globbed filespec

if path.empty?
	base += &#39;.xml' unless base =~ /\..+$/
	list = commandline.arguments
else
	Dir.chdir(File.dirname(path))
	list = Dir.glob("*.{#{commandline.arguments.join(',')}}")
end

begin
	reslib = Resource.new(base,session.get(&#39;option.namespace'))
	reslib.load(base)
rescue
	session.error(&#39;problems with loading base')
	exit
end

unless session.get(&#39;option.texexec').empty?
    reslib.set_texexec(session.get(&#39;option.texexec'))
end

if session.get(&#39;option.add')

	session.report(&#39;adding records', list)
	reslib.add_figures(list,session.get(&#39;option.prefix'))

elsif session.get(&#39;option.remove') or session.get('option.delete')

	session.report(&#39;removing records')
	reslib.delete_figures(list)

elsif session.get(&#39;option.sort')

	session.report(&#39;sorting records')
	reslib.sort_figures()

elsif session.get(&#39;option.purge')

	session.report(&#39;purging records')
	reslib.purge_figures()

elsif session.get(&#39;option.dummy')

	session.report(&#39;creating dummy records')
    reslib.create_dummies(session.get(&#39;option.process'),session.get('option.result'),session.get('option.zipalso'))

else

	session.warning(&#39;provide action')

end

reslib.save(base)