aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Utilities/CommandLineCollection.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2010-09-11 01:13:08 +0100
committerJustin Clark-Casey (justincc)2010-09-11 01:13:08 +0100
commit7e65590a55ba575d0086bdfc25addaf1051d799b (patch)
tree1dc11683170d45d80d7aab6eefdfcc836d3e773b /Prebuild/src/Core/Utilities/CommandLineCollection.cs
parentMake it clear that the "create region" command will reference ini files in th... (diff)
downloadopensim-SC-7e65590a55ba575d0086bdfc25addaf1051d799b.zip
opensim-SC-7e65590a55ba575d0086bdfc25addaf1051d799b.tar.gz
opensim-SC-7e65590a55ba575d0086bdfc25addaf1051d799b.tar.bz2
opensim-SC-7e65590a55ba575d0086bdfc25addaf1051d799b.tar.xz
Update Prebuild.exe with Prebuild r323 + an existing OpenSim specific nant hack to correctly clean up chosen OpenSim exes and dlls in bin/ on a "nant clean"
Source code is included for reference. This can go away again once Prebuild is updated with a more general mechanism for cleaning up files. The Prebuild source code here can be built with nant, or regnerated for other tools using the prebuild at {root}/bin/Prebuild.exe
Diffstat (limited to 'Prebuild/src/Core/Utilities/CommandLineCollection.cs')
-rw-r--r--Prebuild/src/Core/Utilities/CommandLineCollection.cs152
1 files changed, 152 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..786fa1e
--- /dev/null
+++ b/Prebuild/src/Core/Utilities/CommandLineCollection.cs
@@ -0,0 +1,152 @@
1#region BSD License
2/*
3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided 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
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System.Collections;
27using System.Collections.Generic;
28
29namespace Prebuild.Core.Utilities
30{
31 /// <summary>
32 /// The CommandLine class parses and interprets the command-line arguments passed to
33 /// prebuild.
34 /// </summary>
35 public class CommandLineCollection : IEnumerable<KeyValuePair<string, string>>
36 {
37 #region Fields
38
39 // The raw OS arguments
40 private readonly string[] m_RawArgs;
41
42 // Command-line argument storage
43 private readonly Dictionary<string, string> m_Arguments = new Dictionary<string, string>();
44
45 #endregion
46
47 #region Constructors
48
49 /// <summary>
50 /// Create a new CommandLine instance and set some internal variables.
51 /// </summary>
52 public CommandLineCollection(string[] args)
53 {
54 m_RawArgs = args;
55
56 Parse();
57 }
58
59 #endregion
60
61 #region Private Methods
62
63 private void Parse()
64 {
65 if(m_RawArgs.Length < 1)
66 return;
67
68 int idx = 0;
69 string lastArg = null;
70
71 while(idx <m_RawArgs.Length)
72 {
73 string arg = m_RawArgs[idx];
74
75 if(arg.Length > 2 && arg[0] == '/')
76 {
77 arg = arg.Substring(1);
78 lastArg = arg;
79 m_Arguments[arg] = "";
80 }
81 else
82 {
83 if(lastArg != null)
84 {
85 m_Arguments[lastArg] = arg;
86 lastArg = null;
87 }
88 }
89
90 idx++;
91 }
92 }
93
94 #endregion
95
96 #region Public Methods
97
98 /// <summary>
99 /// Wases the passed.
100 /// </summary>
101 /// <param name="arg">The arg.</param>
102 /// <returns></returns>
103 public bool WasPassed(string arg)
104 {
105 return (m_Arguments.ContainsKey(arg));
106 }
107
108 #endregion
109
110 #region Properties
111
112 /// <summary>
113 /// Gets the parameter associated with the command line option
114 /// </summary>
115 /// <remarks>Returns null if option was not specified,
116 /// null string if no parameter was specified, and the value if a parameter was specified</remarks>
117 public string this[string index]
118 {
119 get
120 {
121 if(m_Arguments.ContainsKey(index))
122 {
123 return (m_Arguments[index]);
124 }
125 return null;
126 }
127 }
128
129 #endregion
130
131 #region IEnumerable Members
132
133 /// <summary>
134 /// Returns an enumerator that can iterate through a collection.
135 /// </summary>
136 /// <returns>
137 /// An <see cref="T:System.Collections.IDictionaryEnumerator"/>
138 /// that can be used to iterate through the collection.
139 /// </returns>
140 public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
141 {
142 return m_Arguments.GetEnumerator();
143 }
144
145 IEnumerator IEnumerable.GetEnumerator()
146 {
147 return GetEnumerator();
148 }
149
150 #endregion
151 }
152}