Update of /cvsroot/aaron/aaron/src/main
In directory usw-pr-cvs1:/tmp/cvs-serv8885
Modified Files:
aaron.rb
Log Message:
Added args processing (GetoptLong)
Added 1st pass config file parsing
Index: aaron.rb
===================================================================
RCS file: /cvsroot/aaron/aaron/src/main/aaron.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** aaron.rb 2001/06/29 02:09:30 1.1
--- aaron.rb 2001/07/05 11:03:16 1.2
***************
*** 61,68 ****
# Main file from which aaron runs
- puts <<AARON
- Hello World... oh wait, my bad. ::grin::
! Off to create some configuration parsing routines and testing routines. I'll
! come back to this file in a while. -sc
! AARON
--- 61,197 ----
# Main file from which aaron runs
! # Global includes/requires
! require 'getoptlong'
!
! # Global variables
! config = Hash.new()
!
!
!
! # Loads the file paths for all of the remaining configuration and libraries.
! # The phase one config file is required otherwise Aaron will not know where to
! # go inorder to find the remaining configuration files and misc modules.
! def loadPathConfig(config, path_config_file_name = "./paths.conf")
! unless File.readable?(path_config_file_name)
! $stderr.printf("ERROR[loadPathConfig]: The path config file \"%s\" does not exist.\n\n", path_config_file_name)
! printHelp()
! exit(1)
! end
!
! # Load the file and parse out comments and blank lines
! IO.foreach(path_config_file_name) do |line|
! next if /\A\s*\#/ =~ line # comments
! line.gsub!(/\A\s+\z/, '') # blank lines
! next if line.empty? # empty lines
! /(.*?)\s*=\s*(.*)/ =~ line # find key/value pairs
! config[$1] = $2
! end
!
! # Expand out the various *_mod_dirs
! config["action_mod_dir"] = config["module_path"] + "/" + config["action_mod_dir"]
! config["response_mod_dir"] = config["module_path"] + "/" + config["response_mod_dir"]
! config["transaction_mod_dir"] = config["module_path"] + "/" + config["transaction_mod_dir"]
!
!
! return(config)
! end
!
!
!
! # Prints out debugging level information
! def printDebugLevel(config)
! print "Debug level: " << config["debug"].to_s << "\n"
! end
!
!
!
! # Prints out a usage/help message
! def printHelp()
! printf("Usage: %s [OPTIONS]\n", $0)
! print " -h, --help\t\tDisplay this help and exit.\n"
! print " -d, --debug [n]\tSet debug level to 'n'\n"
! print " -c, --config <config>\tPath to phase one aaron config (default \"./path.conf\")\n"
! print " -V, --version\t\tDisplay aaron version information\n\n"
! end
!
!
!
! # Prints out the version of aaron.
! # This should pull the sticky tag, but the file's revision will work for now
! def printVersion()
! version = "$Revision 1.0 $"
! version = version.scan(/\$\s*Revision\s*(.*?)\s*\$/)
! printf("%s Ver: %s\n", $0, version)
! end
!
!
! # Function responsible for processing arguments and setting up config
! def processArgs(config)
! ENV["POSIXLY_CORRECT"] = "true"
!
! # Begin exception handling for GetoptLong
! begin
! opts = GetoptLong.new(
! [ "--debug", "-d", GetoptLong::OPTIONAL_ARGUMENT ],
! [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ],
! [ "--help", "-h", GetoptLong::NO_ARGUMENT ],
! [ "--version", "-V", GetoptLong::NO_ARGUMENT ]
! )
! opts.ordering = GetoptLong::REQUIRE_ORDER
! opts.quiet = TRUE
! opts.each do |opt, arg|
! opt.sub!(/\A--/, '')
! config[opt] = arg
! case opt
! when "debug"
! config["debug"].sub!(/\D+/, '')
! config["debug"] = "1" if config["debug"].empty?
! config["debug"] = config["debug"].to_i
! printDebugLevel(config)
! when "help"
! printHelp()
! exit(0)
! when "version"
! printVersion()
! exit(0)
! end
! end
!
! rescue GetoptLong::AmbigousOption
! $stderr.print "Error: #{$!}\n\n"
! printHelp()
! exit(1)
! rescue GetoptLong::InvalidOption
! $stderr.print "Error: #{$!}\n\n"
! printHelp()
! exit(1)
! rescue GetoptLong::MissingArgument
! $stderr.print "Error: #{$!}\n\n"
! printHelp()
! exit(1)
! rescue GetoptLong::NeedlessArgument
! $stderr.print "Error: #{$!}\n\n"
! printHelp()
! exit(1)
! end # End exception handling
!
! # Provide defaults for values that aren't required on the command line
! config["debug"] = 0 unless config.has_key?("debug")
! config["config"] = "./paths.conf" unless config.has_key?("config")
!
! return(config)
! end
!
!
! # Like C, this is the method that contains all of the magic
! def main(config, argv)
! config = processArgs(config)
! config = loadPathConfig(config, config["config"])
! config.keys.sort.each { |key| puts "Config Key: #{key}\tVal: #{config[key]}" } if config["debug"] > 0
!
! return(0)
! end
!
! # This should be the last line in the program
! exit(main(config, ARGV))
|