Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
using System;
using System.Linq;
using System.Collections.Generic;
using Mono.Options;
class Test {
public static void Main (string[] args)
{
var show_help = false;
var macros = new Dictionary<string, string>();
bool create = false, extract = false, list = false;
string output = null, input = null;
string color = null;
var p = new OptionSet () {
"Usage: bundling [OPTIONS]+",
"Demo program to show the effects of bundling options and their values",
"",
"gcc-like options:",
{ "D:", "Predefine a macro with an (optional) value.",
(m, v) => {
if (m == null)
throw new OptionException ("Missing macro name for option -D.",
"-D");
macros.Add (m, v);
} },
{ "d={-->}{=>}", "Alternate macro syntax.",
(m, v) => macros.Add (m, v) },
{ "o=", "Specify the output file", v => output = v },
"",
"tar-like options:",
{ "f=", "The input file", v => input = v },
{ "x", "Extract the file", v => extract = v != null },
{ "c", "Create the file", v => create = v != null },
{ "t", "List the file", v => list = v != null },
"",
"ls-like optional values:",
{ "color:", "control whether and when color is used",
v => color = v },
"",
"other:",
{ "h|help", "show this message and exit",
v => show_help = v != null },
// default
{ "<>",
v => Console.WriteLine ("def handler: color={0}; arg={1}", color, v)},
};
try {
p.Parse (args);
}
catch (OptionException e) {
Console.Write ("bundling: ");
Console.WriteLine (e.Message);
Console.WriteLine ("Try `greet --help' for more information.");
return;
}
if (show_help) {
p.WriteOptionDescriptions (Console.Out);
return;
}
Console.WriteLine ("Macros:");
foreach (var m in (from k in macros.Keys orderby k select k)) {
Console.WriteLine ("\t{0}={1}", m, macros [m] ?? "<null>");
}
Console.WriteLine ("Options:");
Console.WriteLine ("\t Input File: {0}", input);
Console.WriteLine ("\tOuptut File: {0}", output);
Console.WriteLine ("\t Create: {0}", create);
Console.WriteLine ("\t Extract: {0}", extract);
Console.WriteLine ("\t List: {0}", list);
Console.WriteLine ("\t Color: {0}", color ?? "<null>");
}
}

View File

@@ -0,0 +1,13 @@
mono Documentation/en/examples/bundling.exe --help
mono Documentation/en/examples/bundling.exe -D
mono Documentation/en/examples/bundling.exe -DA -DB=C "-dD-->E" "-dF=>G" -d "H=>I" -cf input --color -ooutput
mono Documentation/en/examples/bundling.exe -cfv input
mono Documentation/en/examples/bundling.exe -xctf input
mono Documentation/en/examples/bundling.exe --color=auto -o output -finput
mono Documentation/en/examples/bundling.exe --color=on A B --color=off C D

View File

@@ -0,0 +1,84 @@
$ mono bundling.exe --help
Usage: bundling [OPTIONS]+
Demo program to show the effects of bundling options and their values
gcc-like options:
-D[=VALUE1:VALUE2] Predefine a macro with an (optional) value.
-d=VALUE1-->VALUE2 Alternate macro syntax.
-o=VALUE Specify the output file
tar-like options:
-f=VALUE The input file
-x Extract the file
-c Create the file
-t List the file
ls-like optional values:
--color[=VALUE] control whether and when color is used
other:
-h, --help show this message and exit
$ mono bundling.exe -D
bundling: Missing macro name for option -D.
Try `greet --help' for more information.
$ mono bundling.exe -DA -DB=C "-dD-->E" "-dF=>G" -d "H=>I" -cf input --color -ooutput
Macros:
A=<null>
B=C
D=E
F=G
H=I
Options:
Input File: input
Ouptut File: output
Create: True
Extract: False
List: False
Color: <null>
$ mono bundling.exe -cfv input
def handler: color=; arg=input
Macros:
Options:
Input File: v
Ouptut File:
Create: True
Extract: False
List: False
Color: <null>
$ mono bundling.exe -xctf input
Macros:
Options:
Input File: input
Ouptut File:
Create: True
Extract: True
List: True
Color: <null>
$ mono bundling.exe --color=auto -o output -finput
Macros:
Options:
Input File: input
Ouptut File: output
Create: False
Extract: False
List: False
Color: auto
$ mono bundling.exe --color=on A B --color=off C D
def handler: color=on; arg=A
def handler: color=on; arg=B
def handler: color=off; arg=C
def handler: color=off; arg=D
Macros:
Options:
Input File:
Ouptut File:
Create: False
Extract: False
List: False
Color: off

View File

@@ -0,0 +1,78 @@
using System;
using System.ComponentModel;
using System.Globalization;
using Mono.Options;
class FooConverter : TypeConverter {
public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof (string))
return true;
return base.CanConvertFrom (context, sourceType);
}
public override object ConvertFrom (ITypeDescriptorContext context,
CultureInfo culture, object value)
{
string v = value as string;
if (v != null) {
switch (v) {
case "A": return Foo.A;
case "B": return Foo.B;
}
}
return base.ConvertFrom (context, culture, value);
}
}
[TypeConverter (typeof(FooConverter))]
class Foo {
public static readonly Foo A = new Foo ("A");
public static readonly Foo B = new Foo ("B");
string s;
Foo (string s) { this.s = s; }
public override string ToString () {return s;}
}
class DemoOption<T> : Option {
Action<T> action;
public DemoOption (string prototype, Action<T> action)
: base (prototype, null)
{
this.action = action;
}
protected override void OnParseComplete (OptionContext c)
{
Console.WriteLine ("# Parsed {0}; Value={1}; Index={2}",
c.OptionName, c.OptionValues [0] ?? "<null>", c.OptionIndex);
action (Parse<T> (c.OptionValues [0], c));
}
}
class Test {
public static void Main (string[] args)
{
Foo f = null;
int n = -1;
string s = null;
OptionSet p = new OptionSet () {
new DemoOption<Foo> ("f:", v => f = v),
new DemoOption<int> ("n=", v => n = v),
new DemoOption<string> ("s:", v => s = v),
};
try {
p.Parse (args);
}
catch (OptionException e) {
Console.Write ("context: ");
Console.WriteLine (e.Message);
return;
}
Console.WriteLine ("f={0}", f == null ? "<null>" : f.ToString ());
Console.WriteLine ("n={0}", n);
Console.WriteLine ("s={0}", s ?? "<null>");
}
}

View File

@@ -0,0 +1,13 @@
mono Documentation/en/examples/context.exe -f
mono Documentation/en/examples/context.exe -n
mono Documentation/en/examples/context.exe -s
mono Documentation/en/examples/context.exe -f=invalid
mono Documentation/en/examples/context.exe -n invalid
mono Documentation/en/examples/context.exe -s=
mono Documentation/en/examples/context.exe -f=A --n=42 /s=fourty-two

View File

@@ -0,0 +1,36 @@
$ mono context.exe -f
# Parsed -f; Value=<null>; Index=0
f=<null>
n=-1
s=<null>
$ mono context.exe -n
context: Missing required value for option '-n'.
$ mono context.exe -s
# Parsed -s; Value=<null>; Index=0
f=<null>
n=-1
s=<null>
$ mono context.exe -f=invalid
# Parsed -f; Value=invalid; Index=0
context: Could not convert string `invalid' to type Foo for option `-f'.
$ mono context.exe -n invalid
# Parsed -n; Value=invalid; Index=1
context: Could not convert string `invalid' to type Int32 for option `-n'.
$ mono context.exe -s=
# Parsed -s; Value=; Index=0
f=<null>
n=-1
s=
$ mono context.exe -f=A --n=42 /s=fourty-two
# Parsed -f; Value=A; Index=0
# Parsed --n; Value=42; Index=1
# Parsed /s; Value=fourty-two; Index=2
f=A
n=42
s=fourty-two

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using Mono.Options;
class Test {
static int verbosity;
public static void Main (string[] args)
{
bool show_help = false;
List<string> names = new List<string> ();
int repeat = 1;
var p = new OptionSet () {
"Usage: greet [OPTIONS]+ message",
"Greet a list of individuals with an optional message.",
"If no message is specified, a generic greeting is used.",
"",
"Options:",
{ "n|name=", "the {NAME} of someone to greet.",
v => names.Add (v) },
{ "r|repeat=",
"the number of {TIMES} to repeat the greeting.\n" +
"this must be an integer.",
(int v) => repeat = v },
{ "v", "increase debug message verbosity",
v => { if (v != null) ++verbosity; } },
{ "h|help", "show this message and exit",
v => show_help = v != null },
};
List<string> extra;
try {
extra = p.Parse (args);
}
catch (OptionException e) {
Console.Write ("greet: ");
Console.WriteLine (e.Message);
Console.WriteLine ("Try `greet --help' for more information.");
return;
}
if (show_help) {
p.WriteOptionDescriptions (Console.Out);
return;
}
string message;
if (extra.Count > 0) {
message = string.Join (" ", extra.ToArray ());
Debug ("Using new message: {0}", message);
}
else {
message = "Hello {0}!";
Debug ("Using default message: {0}", message);
}
foreach (string name in names) {
for (int i = 0; i < repeat; ++i)
Console.WriteLine (message, name);
}
}
static void Debug (string format, params object[] args)
{
if (verbosity > 0) {
Console.Write ("# ");
Console.WriteLine (format, args);
}
}
}

View File

@@ -0,0 +1,9 @@
mono Documentation/en/examples/greet.exe --help
mono Documentation/en/examples/greet.exe -v- -n A -name=B --name=C /name D -nE
mono Documentation/en/examples/greet.exe -v -n E custom greeting for: {0}
mono Documentation/en/examples/greet.exe -r 3 -n A
mono Documentation/en/examples/greet.exe -r not-an-int

View File

@@ -0,0 +1,31 @@
$ mono greet.exe --help
Usage: greet [OPTIONS]+ message
Greet a list of individuals with an optional message.
If no message is specified, a generic greeting is used.
Options:
-n, --name=NAME the NAME of someone to greet.
-r, --repeat=TIMES the number of TIMES to repeat the greeting.
this must be an integer.
-v increase debug message verbosity
-h, --help show this message and exit
$ mono greet.exe -v- -n A -name=B --name=C /name D -nE
Hello A!
Hello B!
Hello C!
Hello D!
Hello E!
$ mono greet.exe -v -n E custom greeting for: {0}
# Using new message: custom greeting for: {0}
custom greeting for: E
$ mono greet.exe -r 3 -n A
Hello A!
Hello A!
Hello A!
$ mono greet.exe -r not-an-int
greet: Could not convert string `not-an-int' to type Int32 for option `-r'.
Try `greet --help' for more information.

View File

@@ -0,0 +1,86 @@
# NDesk.Options localization example.
# Copyright (C) 2008 Novell, Inc.
# This file is distributed under the same license as the NDesk.Options package.
# Jonathan Pryor <jonpryor@vt.edu>, 2008
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: NDesk.Options localization demo 1.0\n"
"Report-Msgid-Bugs-To: jonpryor@vt.edu\n"
"POT-Creation-Date: 2008-01-19 13:59-0500\n"
"PO-Revision-Date: 2008-01-19 02:43+EST\n"
"Last-Translator: Google\n"
"Language-Team: http://translate.google.com/translate_t?langpair=en|es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: localization.cs:16
msgid "with-unix"
msgstr ""
#: localization.cs:19
msgid "with-hello"
msgstr ""
#: localization.cs:20
msgid "hello:"
msgstr ""
#: localization.cs:21
msgid "with-default"
msgstr ""
#: localization.cs:26
msgid "localization"
msgstr ""
#: localization.cs:28
msgid "locale"
msgstr ""
#: localization.cs:34
msgid "h|?|help"
msgstr ""
#: localization.cs:34
msgid "show this message and exit."
msgstr "A mostrar este mensaje y salir."
#: localization.cs:36
msgid "v|verbose"
msgstr ""
#: localization.cs:36
msgid "increase message verbosity."
msgstr "Aumento mensaje verbosidad."
#: localization.cs:38
msgid "n="
msgstr ""
#: localization.cs:38
msgid "must be an int"
msgstr "Debe ser un int"
#: localization.cs:40
msgid "V|version"
msgstr ""
#: localization.cs:40
msgid "output version information and exit."
msgstr "Salida de informaciĂłn de versiĂłn y sale."
#: localization.cs:47
msgid "localization: "
msgstr ""
#: localization.cs:54
msgid "NDesk.Options Localizer Demo 1.0"
msgstr ""
#: localization.cs:56
#, csharp-format
msgid "Message level: {0}"
msgstr ""

View File

@@ -0,0 +1,63 @@
// Localization with NDesk.Options.OptionSet.
//
// Compile as:
// gmcs -r:Mono.Posix.dll -r:NDesk.Options.dll code-localization.cs
using System;
using System.IO;
using Mono.Options;
using Mono.Unix;
class LocalizationDemo {
public static void Main (string[] args)
{
bool with_gettext = false;
string useLocalizer = null;
var p = new OptionSet () {
{ "with-gettext", v => { useLocalizer = "gettext"; } },
{ "with-hello", v => { useLocalizer = "hello"; } },
{ "with-default", v => { /* do nothing */ } },
};
p.Parse (args);
Converter<string, string> localizer = f => f;
switch (useLocalizer) {
case "gettext":
Catalog.Init ("localization",
Path.Combine (AppDomain.CurrentDomain.BaseDirectory,
"locale"));
localizer = f => { return Catalog.GetString (f); };
break;
case "hello":
localizer = f => { return "hello:" + f; };;
break;
}
bool help = false;
int verbose = 0;
bool version = false;
p = new OptionSet (localizer) {
{ "h|?|help", "show this message and exit.",
v => help = v != null },
{ "v|verbose", "increase message verbosity.",
v => { ++verbose; } },
{ "n=", "must be an int",
(int n) => { /* ignore */ } },
{ "V|version", "output version information and exit.",
v => version = v != null },
};
try {
p.Parse (args);
}
catch (OptionException e) {
Console.Write ("localization: ");
Console.WriteLine (e.Message);
return;
}
if (help)
p.WriteOptionDescriptions (Console.Out);
if (version)
Console.WriteLine ("NDesk.Options Localizer Demo 1.0");
if (verbose > 0)
Console.WriteLine ("Message level: {0}", verbose);
}
}

View File

@@ -0,0 +1,9 @@
mono Documentation/en/examples/localization.exe --help --version
LANGUAGE=es mono Documentation/en/examples/localization.exe --with-gettext --help --version
mono Documentation/en/examples/localization.exe --with-hello --help --version
mono Documentation/en/examples/localization.exe -n not-an-int
mono Documentation/en/examples/localization.exe --with-hello -n not-an-int

View File

@@ -0,0 +1,26 @@
$ mono localization.exe --help --version
-h, -?, --help show this message and exit.
-v, --verbose increase message verbosity.
-n=VALUE must be an int
-V, --version output version information and exit.
NDesk.Options Localizer Demo 1.0
$ LANGUAGE=es mono localization.exe --with-gettext --help --version
-h, -?, --help A mostrar este mensaje y salir.
-v, --verbose Aumento mensaje verbosidad.
-n=VALUE Debe ser un int
-V, --version Salida de informaciĂłn de versiĂłn y sale.
NDesk.Options Localizer Demo 1.0
$ mono localization.exe --with-hello --help --version
-h, -?, --help hello:show this message and exit.
-v, --verbose hello:increase message verbosity.
-nhello:=VALUE hello:must be an int
-V, --version hello:output version information and exit.
NDesk.Options Localizer Demo 1.0
$ mono localization.exe -n not-an-int
localization: Could not convert string `not-an-int' to type Int32 for option `-n'.
$ mono localization.exe --with-hello -n not-an-int
localization: hello:Could not convert string `not-an-int' to type Int32 for option `-n'.

View File

@@ -0,0 +1,135 @@
// Case-Insensitive and Concatenating OptionSet
using System;
using System.Collections.Generic;
using Mono.Options;
class DemoOptionSet : OptionSet {
protected override void InsertItem (int index, Option item)
{
if (item.Prototype.ToLower () != item.Prototype)
throw new ArgumentException ("prototypes must be lower-case!");
base.InsertItem (index, item);
}
protected override OptionContext CreateOptionContext ()
{
return new OptionContext (this);
}
protected override bool Parse (string option, OptionContext c)
{
string f, n, s, v;
bool haveParts = GetOptionParts (option, out f, out n, out s, out v);
Option nextOption = null;
string newOption = option;
if (haveParts) {
string nl = n.ToLower ();
nextOption = Contains (nl) ? this [nl] : null;
newOption = f + n.ToLower () + (v != null ? s + v : "");
}
if (c.Option != null) {
// Prevent --a --b
if (c.Option != null && haveParts) {
if (nextOption == null) {
// ignore
}
else
throw new OptionException (
string.Format ("Found option `{0}' as value for option `{1}'.",
option, c.OptionName), c.OptionName);
}
// have a option w/ required value; try to concat values.
if (AppendValue (option, c)) {
if (!option.EndsWith ("\\") &&
c.Option.MaxValueCount == c.OptionValues.Count) {
c.Option.Invoke (c);
}
return true;
}
else
base.Parse (newOption, c);
}
if (!haveParts || v == null) {
// Not an option; let base handle as a non-option argument.
return base.Parse (newOption, c);
}
if (nextOption.OptionValueType != OptionValueType.None &&
v.EndsWith ("\\")) {
c.Option = nextOption;
c.OptionValues.Add (v);
c.OptionName = f + n;
return true;
}
return base.Parse (newOption, c);
}
private bool AppendValue (string value, OptionContext c)
{
bool added = false;
string[] seps = c.Option.GetValueSeparators ();
foreach (var o in seps.Length != 0
? value.Split (seps, StringSplitOptions.None)
: new string[]{value}) {
int idx = c.OptionValues.Count-1;
if (idx == -1 || !c.OptionValues [idx].EndsWith ("\\")) {
c.OptionValues.Add (o);
added = true;
}
else {
c.OptionValues [idx] += value;
added = true;
}
}
return added;
}
}
class Demo {
public static void Main (string[] args)
{
List<string> names = new List<string> ();
Dictionary<string,string> map = new Dictionary<string,string> ();
int repeat = 1;
OptionSet p = new DemoOptionSet () {
{ "n|name=", v => names.Add (v) },
{ "r|repeat:", (int v) => repeat = v },
{ "m|map=", (k,v) => map.Add (k, v) },
};
List<string> extra;
try {
extra = p.Parse (args);
}
catch (OptionException e) {
Console.Write ("subclass: ");
Console.WriteLine (e.Message);
return;
}
string message;
if (extra.Count > 0) {
message = string.Join (" ", extra.ToArray ());
}
else {
message = "Hello {0}!";
}
foreach (string name in names) {
for (int i = 0; i < repeat; ++i)
Console.WriteLine (message, name);
}
List<string> keys = new List<string>(map.Keys);
keys.Sort ();
foreach (string key in keys) {
Console.WriteLine ("Key: {0}={1}", key, map [key]);
}
}
}

View File

@@ -0,0 +1,9 @@
mono Documentation/en/examples/subclass.exe -n A -Name=B --NAME=C /nAMe D
mono Documentation/en/examples/subclass.exe --Repeat -name A
mono Documentation/en/examples/subclass.exe -Name --Repeat 3
mono Documentation/en/examples/subclass.exe --Map a b -mAp c=d /maP=e=f
mono Documentation/en/examples/subclass.exe --map 'a\\' 'b\\' c 'd\\' 'e\\' f

View File

@@ -0,0 +1,18 @@
$ mono subclass.exe -n A -Name=B --NAME=C /nAMe D
Hello A!
Hello B!
Hello C!
Hello D!
$ mono subclass.exe --Repeat -name A
$ mono subclass.exe -Name --Repeat 3
subclass: Found option `--Repeat' as value for option `-name'.
$ mono subclass.exe --Map a b -mAp c=d /maP=e=f
Key: a=b
Key: c=d
Key: e=f
$ mono subclass.exe --map 'a\' 'b\' c 'd\' 'e\' f
Key: a\b\c=d\e\f