I want to say `./setup.exe --site <ports> --site <local-repo>', so there
it is.
2011-05-30 SZAVAI Gyula <sz...@ludens.elte.hu>
* libgetopt++/src/StringArrayOption.cc: New file.
* libgetopt++/include/getopt++/StringArrayOption.h: New file.
* libgetopt++/Makefile.am: Add new files.
* site.cc (SiteSetting::SiteSetting): Use them for multiple
--site options.
* crypto.cc (verify_ini_file_sig): Use them for multiple
--pubkey and --sexpr-pubkey options.
* package_meta.cc (packagemeta::isManuallyWanted): Use them for
multiple --packages and --categories options.
diff --git a/crypto.cc b/crypto.cc
index 9c48514..80e4eaa 100755
--- a/crypto.cc
+++ b/crypto.cc
@@ -28,7 +28,7 @@ static const char *cvsid =
#include "gcrypt.h"
#include "msg.h"
#include "resource.h"
-#include "getopt++/StringOption.h"
+#include "getopt++/StringArrayOption.h"
#include "getopt++/BoolOption.h"
#include "KeysSetting.h"
#include "gpg-packet.h"
@@ -45,11 +45,11 @@ static const char *cvsid =
#endif /* CRYPTODEBUGGING */
/* Command-line options for specifying and controlling extra keys. */
-static StringOption ExtraKeyOption ("", 'K', "pubkey",
- "URL of extra public key file (gpg format)", true);
+static StringArrayOption ExtraKeyOption ('K', "pubkey",
+ "URL of extra public key file (gpg format)");
-static StringOption SexprExtraKeyOption ("", 'S', "sexpr-pubkey",
- "Extra public key in s-expr format", true);
+static StringArrayOption SexprExtraKeyOption ('S', "sexpr-pubkey",
+ "Extra public key in s-expr format");
static BoolOption UntrustedKeysOption (false, 'u', "untrusted-keys",
"Use untrusted keys from last-extrakeys");
@@ -509,13 +509,14 @@ verify_ini_file_sig (io_stream *ini_file, io_stream
*ini_sig_file, HWND owner)
}
/* Next, there may have been command-line options. */
- std::string SexprExtraKeyString = SexprExtraKeyOption;
- MESSAGE ("key str is '%s'\n", SexprExtraKeyString.c_str ());
- if (SexprExtraKeyString.size ())
+ std::vector<std::string> SexprExtraKeyStrings = SexprExtraKeyOption;
+ for (std::vector<std::string>::const_iterator it
+ = SexprExtraKeyStrings.begin ();
+ it != SexprExtraKeyStrings.end (); ++it)
{
+ MESSAGE ("key str is '%s'\n", it->c_str ());
gcry_sexp_t dsa_key2 = 0;
- rv = gcry_sexp_new (&dsa_key2, SexprExtraKeyString.c_str (),
- SexprExtraKeyString.size (), 1);
+ rv = gcry_sexp_new (&dsa_key2, it->c_str (), it->size (), 1);
if (rv == GPG_ERR_NO_ERROR)
{
// We probably want to add it to the extra keys setting
@@ -539,10 +540,12 @@ verify_ini_file_sig (io_stream *ini_file, io_stream
*ini_sig_file, HWND owner)
}
/* Also, we may have to read a key(s) file. */
- std::string ExtraKeysFile = ExtraKeyOption;
- if (ExtraKeysFile.size ())
+ std::vector<std::string> ExtraKeysFiles = ExtraKeyOption;
+ for (std::vector<std::string>::const_iterator it
+ = ExtraKeysFiles.begin ();
+ it != ExtraKeysFiles.end (); ++it)
{
- io_stream *keys = get_url_to_membuf (ExtraKeysFile, owner);
+ io_stream *keys = get_url_to_membuf (*it, owner);
if (keys)
{
struct key_data kdat;
diff --git a/libgetopt++/Makefile.am b/libgetopt++/Makefile.am
index 0ab10ed..a423d05 100644
--- a/libgetopt++/Makefile.am
+++ b/libgetopt++/Makefile.am
@@ -26,7 +26,7 @@ TESTS = tests/OptionSet tests/optioniterator
tests/BoolOptionTest
libgetopt___la_SOURCES = src/GetOption.cc src/Option.cc src/BoolOption.cc \
src/OptionSet.cc \
- src/StringOption.cc
+ src/StringArrayOption.cc src/StringOption.cc
libgetopt___la_LDFLAGS = -version-info 1:1:0
@@ -35,6 +35,7 @@ getoptinclude_HEADERS = include/getopt++/Option.h \
include/getopt++/DefaultFormatter.h \
include/getopt++/GetOption.h \
include/getopt++/OptionSet.h \
+ include/getopt++/StringArrayOption.h \
include/getopt++/StringOption.h
tests_testoption_SOURCES = tests/testoption.cc
diff --git a/libgetopt++/include/getopt++/StringArrayOption.h
b/libgetopt++/include/getopt++/StringArrayOption.h
new file mode 100644
index 0000000..d3f87c0
--- /dev/null
+++ b/libgetopt++/include/getopt++/StringArrayOption.h
@@ -0,0 +1,44 @@
+/*
+ * Modified from StringOption.h by Szavai Gyula in 2011
+ *
+ * Copyright (c) 2002 Robert Collins.
+ *
+ * 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.
+ *
+ * A copy of the GNU General Public License can be found at
+ * http://www.gnu.org/
+ */
+
+#ifndef _STRINGARRAYOPTION_H_
+#define _STRINGARRAYOPTION_H_
+
+#include <getopt++/Option.h>
+#include <getopt++/GetOption.h>
+
+// Each registered option must implement this class.
+class StringArrayOption : public Option
+{
+public:
+ StringArrayOption(char shortopt, char const *longopt = 0,
+ std::string const &shorthelp = std::string(),
+ OptionSet &owner=GetOption::GetInstance());
+ virtual ~ StringArrayOption ();
+ virtual std::string const shortOption () const;
+ virtual std::string const longOption () const;
+ virtual std::string const shortHelp () const;
+ virtual Result Process (char const *);
+ virtual Argument argument () const;
+ operator std::vector<std::string> () const;
+
+private:
+ Argument _optional;
+ std::vector<std::string> _value;
+ char _shortopt;
+ char const *_longopt;
+ std::string _shorthelp;
+};
+
+#endif // _STRINGARRAYOPTION_H_
diff --git a/libgetopt++/src/StringArrayOption.cc
b/libgetopt++/src/StringArrayOption.cc
new file mode 100644
index 0000000..66376ae
--- /dev/null
+++ b/libgetopt++/src/StringArrayOption.cc
@@ -0,0 +1,68 @@
+/*
+ * Modified from StringOption.cc by Szavai Gyula in 2011
+ *
+ * Copyright (c) 2002 Robert Collins.
+ *
+ * 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.
+ *
+ * A copy of the GNU General Public License can be found at
+ * http://www.gnu.org/
+ */
+
+#include <getopt++/StringArrayOption.h>
+
+using namespace std;
+
+StringArrayOption::StringArrayOption(char shortopt,
+ char const *longopt, string const &shorthelp,
+ OptionSet &owner) :
+ _optional(Required), _shortopt(shortopt),
+ _longopt (longopt), _shorthelp (shorthelp)
+{
+ owner.Register (this);
+};
+
+StringArrayOption::~ StringArrayOption () {};
+
+string const
+StringArrayOption::shortOption () const
+{
+ return string() + _shortopt + ":";
+}
+
+string const
+StringArrayOption::longOption () const
+{
+ return _longopt;
+}
+
+string const
+StringArrayOption::shortHelp () const
+{
+ return _shorthelp;
+}
+
+Option::Result
+StringArrayOption::Process (char const *optarg)
+{
+ if (optarg)
+ {
+ _value.push_back(optarg);
+ return Ok;
+ }
+ return Failed;
+}
+
+StringArrayOption::operator vector<string> () const
+{
+ return _value;
+}
+
+Option::Argument
+StringArrayOption::argument () const
+{
+ return _optional;
+}
diff --git a/package_meta.cc b/package_meta.cc
index 2b0350a..765792c 100644
--- a/package_meta.cc
+++ b/package_meta.cc
@@ -27,7 +27,7 @@ using namespace std;
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
-#include "getopt++/StringOption.h"
+#include "getopt++/StringArrayOption.h"
#include "io_stream.h"
#include "compress.h"
@@ -51,8 +51,8 @@ using namespace std;
using namespace std;
-static StringOption PackageOption ("", 'P', "packages", "Specify packages to
install");
-static StringOption CategoryOption ("", 'C', "categories", "Specify entire
categories to install");
+static StringArrayOption PackageOption ('P', "packages", "Specify packages to
install");
+static StringArrayOption CategoryOption ('C', "categories", "Specify entire
categories to install");
/*****************/
@@ -315,10 +315,18 @@ bool packagemeta::isManuallyWanted() const
option string and store them away in an STL set. */
if (!parsed_yet)
{
- string packages_option = PackageOption;
- string categories_option = CategoryOption;
- parseNames (parsed_names, packages_option);
- parseNames (parsed_categories, categories_option);
+ vector<string> packages_options = PackageOption;
+ vector<string> categories_options = CategoryOption;
+ for (vector<string>::iterator n = packages_options.begin ();
+ n != packages_options.end (); ++n)
+ {
+ parseNames (parsed_names, *n);
+ }
+ for (vector<string>::iterator n = categories_options.begin ();
+ n != categories_options.end (); ++n)
+ {
+ parseNames (parsed_categories, *n);
+ }
parsed_yet = true;
}
diff --git a/site.cc b/site.cc
index a08c634..a80fec4 100644
--- a/site.cc
+++ b/site.cc
@@ -77,7 +77,7 @@ SitePage::SitePage ()
sizeProcessor.AddControlInfo (SiteControlsInfo);
}
-#include "getopt++/StringOption.h"
+#include "getopt++/StringArrayOption.h"
#include "getopt++/BoolOption.h"
#include "UserSettings.h"
@@ -99,15 +99,19 @@ SiteList cached_site_list;
/* Stale selected sites to warn about and add to cache */
SiteList dropped_site_list;
-StringOption SiteOption("", 's', "site", "Download site", false);
+StringArrayOption SiteOption('s', "site", "Download site");
BoolOption OnlySiteOption(false, 'O', "only-site", "Ignore all sites except
for -s");
SiteSetting::SiteSetting (): saved (false)
{
- string SiteOptionString = SiteOption;
- if (SiteOptionString.size())
- registerSavedSite (SiteOptionString.c_str());
+ vector<string> SiteOptionStrings = SiteOption;
+ if (SiteOptionStrings.size())
+ {
+ for (vector<string>::const_iterator n = SiteOptionStrings.begin ();
+ n != SiteOptionStrings.end (); ++n)
+ registerSavedSite (n->c_str ());
+ }
else
getSavedSites ();
}