diff options
author | gareth | 2007-03-22 10:11:15 +0000 |
---|---|---|
committer | gareth | 2007-03-22 10:11:15 +0000 |
commit | 7daa3955bc3a1918e40962851f9e8d38597a245e (patch) | |
tree | bee3e1372a7eed0c1b220a8a49f7bee7d29a6b91 /Prebuild/src/Core/Utilities/CommandLineCollection.cs | |
parent | Load XML for neighbourinfo from grid (diff) | |
download | opensim-SC_OLD-7daa3955bc3a1918e40962851f9e8d38597a245e.zip opensim-SC_OLD-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.gz opensim-SC_OLD-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.bz2 opensim-SC_OLD-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.xz |
brought zircon branch into trunk
Diffstat (limited to '')
-rw-r--r-- | Prebuild/src/Core/Utilities/CommandLineCollection.cs | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/Prebuild/src/Core/Utilities/CommandLineCollection.cs b/Prebuild/src/Core/Utilities/CommandLineCollection.cs new file mode 100644 index 0000000..496731f --- /dev/null +++ b/Prebuild/src/Core/Utilities/CommandLineCollection.cs | |||
@@ -0,0 +1,162 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: robloach $ | ||
30 | * $Date: 2006-09-26 00:30:53 +0200 (ti, 26 sep 2006) $ | ||
31 | * $Revision: 165 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Specialized; | ||
38 | using System.Diagnostics; | ||
39 | |||
40 | namespace Prebuild.Core.Utilities | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// The CommandLine class parses and interprets the command-line arguments passed to | ||
44 | /// prebuild. | ||
45 | /// </summary> | ||
46 | public class CommandLineCollection | ||
47 | { | ||
48 | #region Fields | ||
49 | |||
50 | // The raw OS arguments | ||
51 | private string[] m_RawArgs; | ||
52 | |||
53 | // Command-line argument storage | ||
54 | private Hashtable m_Arguments; | ||
55 | |||
56 | #endregion | ||
57 | |||
58 | #region Constructors | ||
59 | |||
60 | /// <summary> | ||
61 | /// Create a new CommandLine instance and set some internal variables. | ||
62 | /// </summary> | ||
63 | public CommandLineCollection(string[] args) | ||
64 | { | ||
65 | m_RawArgs = args; | ||
66 | m_Arguments = new Hashtable(); | ||
67 | |||
68 | Parse(); | ||
69 | } | ||
70 | |||
71 | #endregion | ||
72 | |||
73 | #region Private Methods | ||
74 | |||
75 | private void Parse() | ||
76 | { | ||
77 | if(m_RawArgs.Length < 1) | ||
78 | return; | ||
79 | |||
80 | int idx = 0; | ||
81 | string arg = null, lastArg = null; | ||
82 | |||
83 | while(idx <m_RawArgs.Length) | ||
84 | { | ||
85 | arg = m_RawArgs[idx]; | ||
86 | |||
87 | if(arg.Length > 2 && arg[0] == '/') | ||
88 | { | ||
89 | arg = arg.Substring(1); | ||
90 | lastArg = arg; | ||
91 | m_Arguments[arg] = ""; | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | if(lastArg != null) | ||
96 | { | ||
97 | m_Arguments[lastArg] = arg; | ||
98 | lastArg = null; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | idx++; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | #endregion | ||
107 | |||
108 | #region Public Methods | ||
109 | |||
110 | /// <summary> | ||
111 | /// Wases the passed. | ||
112 | /// </summary> | ||
113 | /// <param name="arg">The arg.</param> | ||
114 | /// <returns></returns> | ||
115 | public bool WasPassed(string arg) | ||
116 | { | ||
117 | return (m_Arguments.ContainsKey(arg)); | ||
118 | } | ||
119 | |||
120 | #endregion | ||
121 | |||
122 | #region Properties | ||
123 | |||
124 | /// <summary> | ||
125 | /// Gets the parameter associated with the command line option | ||
126 | /// </summary> | ||
127 | /// <remarks>Returns null if option was not specified, | ||
128 | /// null string if no parameter was specified, and the value if a parameter was specified</remarks> | ||
129 | public string this[string index] | ||
130 | { | ||
131 | get | ||
132 | { | ||
133 | if(m_Arguments.ContainsKey(index)) | ||
134 | { | ||
135 | return (string)(m_Arguments[index]); | ||
136 | } | ||
137 | else | ||
138 | { | ||
139 | return null; | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | |||
144 | #endregion | ||
145 | |||
146 | #region IEnumerable Members | ||
147 | |||
148 | /// <summary> | ||
149 | /// Returns an enumerator that can iterate through a collection. | ||
150 | /// </summary> | ||
151 | /// <returns> | ||
152 | /// An <see cref="T:System.Collections.IDictionaryEnumerator"/> | ||
153 | /// that can be used to iterate through the collection. | ||
154 | /// </returns> | ||
155 | public IDictionaryEnumerator GetEnumerator() | ||
156 | { | ||
157 | return m_Arguments.GetEnumerator(); | ||
158 | } | ||
159 | |||
160 | #endregion | ||
161 | } | ||
162 | } | ||