diff options
author | Adam Frisby | 2007-06-21 17:08:21 +0000 |
---|---|---|
committer | Adam Frisby | 2007-06-21 17:08:21 +0000 |
commit | e93869c7a785a4f375685ffa33c913033ed1c85a (patch) | |
tree | abb5e2c58f8750a1bc05acf58716b6b025da4d15 /tools/mass test client/Arguments.cs | |
parent | Fixed the struct and null compare bug. (diff) | |
download | opensim-SC_OLD-e93869c7a785a4f375685ffa33c913033ed1c85a.zip opensim-SC_OLD-e93869c7a785a4f375685ffa33c913033ed1c85a.tar.gz opensim-SC_OLD-e93869c7a785a4f375685ffa33c913033ed1c85a.tar.bz2 opensim-SC_OLD-e93869c7a785a4f375685ffa33c913033ed1c85a.tar.xz |
* Importing Ming's mass test client
Diffstat (limited to 'tools/mass test client/Arguments.cs')
-rw-r--r-- | tools/mass test client/Arguments.cs | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/tools/mass test client/Arguments.cs b/tools/mass test client/Arguments.cs new file mode 100644 index 0000000..302ae95 --- /dev/null +++ b/tools/mass test client/Arguments.cs | |||
@@ -0,0 +1,111 @@ | |||
1 | using System; | ||
2 | using System.Collections.Specialized; | ||
3 | using System.Text.RegularExpressions; | ||
4 | |||
5 | namespace CommandLine.Utility | ||
6 | { | ||
7 | /// <summary> | ||
8 | /// Arguments class | ||
9 | /// </summary> | ||
10 | public class Arguments | ||
11 | { | ||
12 | // Variables | ||
13 | private StringDictionary Parameters; | ||
14 | |||
15 | // Constructor | ||
16 | public Arguments(string[] Args) | ||
17 | { | ||
18 | Parameters = new StringDictionary(); | ||
19 | Regex Splitter = new Regex(@"^-{1,2}|=|:", | ||
20 | RegexOptions.IgnoreCase | RegexOptions.Compiled); | ||
21 | |||
22 | Regex Remover = new Regex(@"^['""]?(.*?)['""]?$", | ||
23 | RegexOptions.IgnoreCase | RegexOptions.Compiled); | ||
24 | |||
25 | string Parameter = null; | ||
26 | string[] Parts; | ||
27 | |||
28 | // Valid parameters forms: | ||
29 | // {-,/,--}param{ ,=,:}((",')value(",')) | ||
30 | // Examples: | ||
31 | // -param1 value1 --param2 /param3:"Test-:-work" | ||
32 | // /param4=happy -param5 '--=nice=--' | ||
33 | foreach (string Txt in Args) | ||
34 | { | ||
35 | // Look for new parameters (-,/ or --) and a | ||
36 | // possible enclosed value (=,:) | ||
37 | Parts = Splitter.Split(Txt, 3); | ||
38 | |||
39 | switch (Parts.Length) | ||
40 | { | ||
41 | // Found a value (for the last parameter | ||
42 | // found (space separator)) | ||
43 | case 1: | ||
44 | if (Parameter != null) | ||
45 | { | ||
46 | if (!Parameters.ContainsKey(Parameter)) | ||
47 | { | ||
48 | Parts[0] = | ||
49 | Remover.Replace(Parts[0], "$1"); | ||
50 | |||
51 | Parameters.Add(Parameter, Parts[0]); | ||
52 | } | ||
53 | Parameter = null; | ||
54 | } | ||
55 | // else Error: no parameter waiting for a value (skipped) | ||
56 | break; | ||
57 | |||
58 | // Found just a parameter | ||
59 | case 2: | ||
60 | // The last parameter is still waiting. | ||
61 | // With no value, set it to true. | ||
62 | if (Parameter != null) | ||
63 | { | ||
64 | if (!Parameters.ContainsKey(Parameter)) | ||
65 | Parameters.Add(Parameter, "true"); | ||
66 | } | ||
67 | Parameter = Parts[1]; | ||
68 | break; | ||
69 | |||
70 | // Parameter with enclosed value | ||
71 | case 3: | ||
72 | // The last parameter is still waiting. | ||
73 | // With no value, set it to true. | ||
74 | if (Parameter != null) | ||
75 | { | ||
76 | if (!Parameters.ContainsKey(Parameter)) | ||
77 | Parameters.Add(Parameter, "true"); | ||
78 | } | ||
79 | |||
80 | Parameter = Parts[1]; | ||
81 | |||
82 | // Remove possible enclosing characters (",') | ||
83 | if (!Parameters.ContainsKey(Parameter)) | ||
84 | { | ||
85 | Parts[2] = Remover.Replace(Parts[2], "$1"); | ||
86 | Parameters.Add(Parameter, Parts[2]); | ||
87 | } | ||
88 | |||
89 | Parameter = null; | ||
90 | break; | ||
91 | } | ||
92 | } | ||
93 | // In case a parameter is still waiting | ||
94 | if (Parameter != null) | ||
95 | { | ||
96 | if (!Parameters.ContainsKey(Parameter)) | ||
97 | Parameters.Add(Parameter, "true"); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | // Retrieve a parameter value if it exists | ||
102 | // (overriding C# indexer property) | ||
103 | public string this[string Param] | ||
104 | { | ||
105 | get | ||
106 | { | ||
107 | return (Parameters[Param]); | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | } | ||