#!/bin/env ruby #encoding: UTF-8 =begin /*************************************************************************** * ©2023-2024, Michael Uplawski * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE * * * * 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. * * * ***************************************************************************/ =end # This program is Linux only if ! /linux/ =~ RUBY_PLATFORM msg = "ERROR ! This script #{$0} cannot be used with #{RUBY_PLATFORM}" msg << "\n\tABORTING! Bye." STDERR.puts msg exit false end require 'tempfile' require 'filemagic' require_relative '../lib/override' require_relative '../lib/flnews_post_proc' require_relative '../lib/basic_logging' require_relative '../lib/configuration' require_relative '../lib/version' self.extend(BasicLogging) def usage usage = "\nWhat do you want me to do? Where is the article to post-process?" usage << "\nUsage: " usage << "\n\t#{$0} < article.text" info usage STDERR.puts usage exit false end msg = PROGNAME.dup << ' ' << PROGVERSION << ' starting' msg = "–––––– " << msg << " ––––––" info msg # Get a configuration config = Configuration::instance # store the path to the main executable # config.set(:BINDIR, File::dirname(__FILE__) ) # Only if data is on STDIN if (!STDIN.tty?) # read from STDIN artext = ARGF.read # There is content, create the post-processor. if !artext.strip.empty? mime = FileMagic.mime.buffer artext debug('mime is ' << mime) if mime.start_with?('message/news') #-----------> # Allow to override the configuration, # if not disabled (default is true) if config.OVERRIDE_CONFIG != false cdlg = OverrideDlg.new discarded = cdlg.show if discarded && !discarded.empty? debug('options overriden ' << discarded) OverrideDlg.cvars.each do |v| if discarded.include?(v.to_s) debug('removing ' << v.to_s) config.set(v, nil) end end end debug('new config: ' << config.inspect) end #<-------------- pp = PostProcessor.new(artext) # ... and print its result. article = pp.article if article # -------------> The main objective <------ puts article # <------------- over and out ------> exit true end # whatever. exit false else error ("Input is of wrong mime-type" << mime) end else error( "Cannot read the article, no content" ) end else usage() end # Ω