#!/usr/bin/ruby -Ke -*- ruby -*- # MONPE -- an repoting creation/manipulation program # It was originally based on a Dia version 0.84. # Copyright (C) 2002 Shimizu Koji # # Dia -- an diagram creation/manipulation program # Copyright (C) 1998 Alexander Larsson # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ### ### Configuration ### MONPE_VERSION = "0.3.9-0+1jma1" prefix = '/usr' ### ### Process ### require "getoptlong" require "tempfile" exec_prefix = prefix + '/bin/' RED2REC = exec_prefix + "red2rec" RED2EMBED = exec_prefix + "red2embed" MONPE = exec_prefix + "monpe-print" LPR = "lpr" DATA_DIR = "/tmp/montest/#{MONPE_VERSION}/" RED_EXT = ".red" DATA_EXT = ".dat" PS_EXT = ".ps" def usage $stderr.printf(< [-o output ps] [-p printer] EOF end $output_ps = nil $printer = nil parser = GetoptLong.new parser.set_options(['-o', GetoptLong::REQUIRED_ARGUMENT], ['-p', GetoptLong::REQUIRED_ARGUMENT], ['--help', '-h', GetoptLong::NO_ARGUMENT]) begin parser.each_option do |name, arg| case name when "-o" $output_ps = arg when "-p" $printer = arg when "--help" usage exit end end rescue usage exit(1) end if ARGV.size < 2 usage exit 1 end if $printer == nil $printer = "lp1" end $red_file = ARGV.shift $cob_file = ARGV.shift rec_file = Tempfile.new("red-rec") out_file = Tempfile.new("red-out") rec_file.close out_file.close system("#{RED2REC} -f -i #{$red_file} -o #{rec_file.path} -r PS") system("#{RED2EMBED} -i #{$red_file} -r #{rec_file.path} -d #{$cob_file} -o #{out_file.path}") ps_file = Tempfile.new("red2pstest_ps") ps_file.close system("#{MONPE} -p #{ps_file.path} #{out_file.path}") if $output_ps system("cp #{ps_file.path} #{$output_ps}") else system("#{LPR} -P #{$printer} #{ps_file.path}") end error = false message = "" if !FileTest.exist?(DATA_DIR) if !system("mkdir -p #{DATA_DIR}") message = "Could not make directory." error = true elsif !system("chmod 777 #{DATA_DIR}") message = "Could not change 777." error = true end elsif !FileTest.directory?(DATA_DIR) message = "Not directory." error = true elsif !FileTest.writable?(DATA_DIR) message = "Does not write directory." error = true end if error $stderr.print("red2pstest error: #{message} \'#{DATA_DIR}\'") exit(1) end report_id = File.basename($red_file, RED_EXT) i = 1 while true num = sprintf("%02d", i) data_path = DATA_DIR + report_id + "_" + num + DATA_EXT ps_path = DATA_DIR + report_id + "_" + num + PS_EXT if !FileTest.exist?(data_path) && !FileTest.exist?(ps_path) break end i += 1 end system("cp #{$cob_file} #{data_path}") system("chmod 664 #{data_path}") system("cp #{ps_file.path} #{ps_path}") system("chmod 664 #{ps_path}")