--- /dev/null
+package MyOptions;
+
+use strict;
+use warnings;
+use Exporter qw(import);
+use Getopt::Long qw(GetOptions);
+use Config::Simple;
+use File::Spec;
+
+our @EXPORT= qw(options_matchxsa options_xenreleaselogs options_makewebpage);
+our @EXPORT_OK = qw(handleoptions);
+
+my %o = (
+ 'VERSION' => "none",
+ 'MAJOR' => "none",
+ 'SINCE' => "none",
+ 'UNTIL' => "stable",
+ 'LOGROOT' => "../xen-release-logs",
+ 'XSALISTDIR' => "../xsa-lists",
+# LATER: Remove these
+ 'NOCHECKOUT' => 0,
+);
+
+my %optionspec = (
+# Applicable to: match-xsa, xen-release-logs and make-webpage
+ 'version=s' => \$o{'VERSION'},
+ 'major=s' => \$o{'MAJOR'},
+ 'since=s' => \$o{'SINCE'},
+ 'minor-since=s'=> \$o{'SINCE'},
+ 'until=s' => \$o{'UNTIL'},
+ 'minor-until=s'=> \$o{'UNTIL'},
+ 'logroot=s' => \$o{'LOGROOT'},
+ 'outputfile=s' => \$o{'OUTPUTFILE'},
+
+# Applicable to: match-xsa
+ 'xsadir=s' => \$o{'XSADIR'},
+ 'xsalist=s' => \$o{'XSALIST'}, # DOCUMENT: Was xsa and $XSALIST
+ 'xsalistdir=s' => \$o{'XSALISTDIR'},
+
+# LATER: Remove these / default
+# Applicable to: match-xsa
+ 'smart' => \$o{'SMART'},
+ 'debug' => \$o{'DEBUG'},
+ 'html' => \$o{'HTML'},
+
+# LATER: Remove these
+ 'nocheckout' => \$o{'NOCHECKOUT'},
+ 'getlogs' => \$o{'GETLOGS'},
+
+# Make these available to match-xsa
+# Applicable to: match-xsa, make-webpage
+ 'xsastart=s' => \$o{'XSASTART'},
+ 'xsaend=s' => \$o{'XSAEND'},
+ );
+
+sub handleoptions {
+ my $outputfile = shift;
+ my $usage = shift;
+
+ # Add $outputfile default
+ $o{'OUTPUTFILE'} = $outputfile;
+
+ # Get Configuration file entries
+ Config::Simple->import_from('config/config', \%o);
+
+ # Get Options
+ GetOptions(%optionspec) or die "Usage: $0".$usage;
+ # Error checking
+ if ($o{'VERSION'} eq "none" ) {
+ die "Usage: $0".$usage."\n".
+ " --version not specified\n";
+ }
+ if ($o{'MAJOR'} eq "none" ) {
+ die "Usage: $0".$usage."\n".
+ " --major not specified\n";
+ }
+
+ # XSADIR SPECIAL CASING?
+
+ # Normalize Calculate Derived Options
+ $o{'SHORT'} = $o{'VERSION'}.$o{'MAJOR'}.$o{'SINCE'}."-".$o{'UNTIL'};
+ $o{'LOGROOT'} = File::Spec->rel2abs($o{'LOGROOT'});
+ if (!-d $o{'LOGROOT'}) {
+ mkdir $o{'LOGROOT'};
+ }
+ $o{'LOGDIR'} = $o{'LOGROOT'}."/logs-".$o{'SHORT'};
+ $o{'OUTPUTFILE'} = $o{'LOGDIR'}."/".$o{'OUTPUTFILE'};
+ $o{'TMPDIR'} = $o{'LOGDIR'}."/tmp";
+ $o{'DEBUGDIR'} = $o{'LOGDIR'}."/debug";
+ $o{'XEN_GIT'} = $o{'LOGDIR'}."/xen";
+ $o{'QEMUU_GIT'} = $o{'LOGDIR'}."/qemu-xen";
+ $o{'QEMUT_GIT'} = $o{'LOGDIR'}."/qemu-xen-traditional";
+
+ return %o;
+}
+
+sub options_matchxsa {
+ my $u = " --version <xen version, e.g. 4>".
+ " --major <major version>".
+ " [--since|--minor-since <minor version start>]".
+ " [--until|--minor-until <minor version end>]".
+ " [--outputfile filename (relative to logdir)]".
+# " [--smart] [--debug] [--html]".
+# " [--getlogs]".
+ " [--xsadir xsadir (default=../xsaweb; files fetched from".
+ " http://xenbits.xenproject.org/xsa/)]".
+ " [--logroot directory]".
+ " [--xsalistdir directory]".
+ " --xsalist xsalistfile\n";
+
+ my %opt = handleoptions("output_xsamatch.html", $u);
+
+ # Error checking
+ if (! defined $o{'XSALIST'}) {
+ die "Usage: $0".$u."\n".
+ " --xsalist not specified\n";
+ }
+
+ # Calculate extra options
+ $o{'XSALISTDIR'} = File::Spec->rel2abs($o{'XSALISTDIR'});
+ $o{'XSALISTFILE'} = $o{'XSALISTDIR'}."/".$o{'XSALIST'};
+
+ # Check whether files/directories exist
+ if (!-d $o{'XSALISTDIR'}) {
+ die "Usage: $0".$u."\n".
+ " directory ".$o{'XSALISTDIR'}." does not exist.\n";
+ }
+ if (!-f $o{'XSALISTFILE'}) {
+ die "Usage: $0".$u."\n".
+ " file ".$o{'XSALISTFILE'}." does not exist.\n";
+ }
+
+ return %opt;
+}
+
+sub options_xenreleaselogs {
+ my $u = " --version <xen version, e.g. 4>".
+ " --major <major version>".
+ " [--since|--minor-since <minor version start>]".
+ " [--until|--minor-until <minor version end>]".
+ " [--outputfile filename (relative to logdir)]".
+# " [--nocheckout]".
+ " [--logroot directory\n";
+
+ my %opt = handleoptions("output_xenreleaselogs.txt", $u);
+
+ return %opt;
+}
+
+sub options_makewebpage {
+ my $u = " --version <xen version, e.g. 4>".
+ " --major <major version>".
+ " [--since|--minor-since <minor version start>]".
+ " [--until|--minor-until <minor version end>]".
+ " [--outputfile filename (relative to logdir)]".
+# " [--nocheckout]".
+ " --xsastart <number of 1st xsa>".
+ " --xsasend <number of last xsa>".
+ " [--logroot directory]\n";
+
+ my %opt = handleoptions("output_webpage.html", $u);
+
+ # Error checking
+ if (! defined $o{'XSASTART'}) {
+ die "Usage: $0".$u."\n".
+ " --xsastart not specified\n";
+ }
+ # Error checking
+ if (! defined $o{'XSAEND'}) {
+ die "Usage: $0".$u."\n".
+ " --xsasend not specified\n";
+ }
+
+ return %opt;
+}
+
+1;