diff options
Diffstat (limited to 'Prebuild/src/Core/Utilities/CommandLineCollection.cs')
-rw-r--r-- | Prebuild/src/Core/Utilities/CommandLineCollection.cs | 254 |
1 files changed, 127 insertions, 127 deletions
diff --git a/Prebuild/src/Core/Utilities/CommandLineCollection.cs b/Prebuild/src/Core/Utilities/CommandLineCollection.cs index 786fa1e..5e6face 100644 --- a/Prebuild/src/Core/Utilities/CommandLineCollection.cs +++ b/Prebuild/src/Core/Utilities/CommandLineCollection.cs | |||
@@ -5,16 +5,16 @@ Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehea | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted |
6 | provided that the following conditions are met: | 6 | provided that the following conditions are met: |
7 | 7 | ||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | 8 | * Redistributions of source code must retain the above copyright notice, this list of conditions |
9 | and the following disclaimer. | 9 | and the following disclaimer. |
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | 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 | 11 | and the following disclaimer in the documentation and/or other materials provided with the |
12 | distribution. | 12 | distribution. |
13 | * The name of the author may not be used to endorse or promote products derived from this software | 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. | 14 | without specific prior written permission. |
15 | 15 | ||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | 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 | 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, | 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 | 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 | 20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
@@ -27,126 +27,126 @@ using System.Collections; | |||
27 | using System.Collections.Generic; | 27 | using System.Collections.Generic; |
28 | 28 | ||
29 | namespace Prebuild.Core.Utilities | 29 | namespace Prebuild.Core.Utilities |
30 | { | 30 | { |
31 | /// <summary> | 31 | /// <summary> |
32 | /// The CommandLine class parses and interprets the command-line arguments passed to | 32 | /// The CommandLine class parses and interprets the command-line arguments passed to |
33 | /// prebuild. | 33 | /// prebuild. |
34 | /// </summary> | 34 | /// </summary> |
35 | public class CommandLineCollection : IEnumerable<KeyValuePair<string, string>> | 35 | public class CommandLineCollection : IEnumerable<KeyValuePair<string, string>> |
36 | { | 36 | { |
37 | #region Fields | 37 | #region Fields |
38 | 38 | ||
39 | // The raw OS arguments | 39 | // The raw OS arguments |
40 | private readonly string[] m_RawArgs; | 40 | private readonly string[] m_RawArgs; |
41 | 41 | ||
42 | // Command-line argument storage | 42 | // Command-line argument storage |
43 | private readonly Dictionary<string, string> m_Arguments = new Dictionary<string, string>(); | 43 | private readonly Dictionary<string, string> m_Arguments = new Dictionary<string, string>(); |
44 | 44 | ||
45 | #endregion | 45 | #endregion |
46 | 46 | ||
47 | #region Constructors | 47 | #region Constructors |
48 | 48 | ||
49 | /// <summary> | 49 | /// <summary> |
50 | /// Create a new CommandLine instance and set some internal variables. | 50 | /// Create a new CommandLine instance and set some internal variables. |
51 | /// </summary> | 51 | /// </summary> |
52 | public CommandLineCollection(string[] args) | 52 | public CommandLineCollection(string[] args) |
53 | { | 53 | { |
54 | m_RawArgs = args; | 54 | m_RawArgs = args; |
55 | 55 | ||
56 | Parse(); | 56 | Parse(); |
57 | } | 57 | } |
58 | 58 | ||
59 | #endregion | 59 | #endregion |
60 | 60 | ||
61 | #region Private Methods | 61 | #region Private Methods |
62 | 62 | ||
63 | private void Parse() | 63 | private void Parse() |
64 | { | 64 | { |
65 | if(m_RawArgs.Length < 1) | 65 | if(m_RawArgs.Length < 1) |
66 | return; | 66 | return; |
67 | 67 | ||
68 | int idx = 0; | 68 | int idx = 0; |
69 | string lastArg = null; | 69 | string lastArg = null; |
70 | 70 | ||
71 | while(idx <m_RawArgs.Length) | 71 | while(idx <m_RawArgs.Length) |
72 | { | 72 | { |
73 | string arg = m_RawArgs[idx]; | 73 | string arg = m_RawArgs[idx]; |
74 | 74 | ||
75 | if(arg.Length > 2 && arg[0] == '/') | 75 | if(arg.Length > 2 && arg[0] == '/') |
76 | { | 76 | { |
77 | arg = arg.Substring(1); | 77 | arg = arg.Substring(1); |
78 | lastArg = arg; | 78 | lastArg = arg; |
79 | m_Arguments[arg] = ""; | 79 | m_Arguments[arg] = ""; |
80 | } | 80 | } |
81 | else | 81 | else |
82 | { | 82 | { |
83 | if(lastArg != null) | 83 | if(lastArg != null) |
84 | { | 84 | { |
85 | m_Arguments[lastArg] = arg; | 85 | m_Arguments[lastArg] = arg; |
86 | lastArg = null; | 86 | lastArg = null; |
87 | } | 87 | } |
88 | } | 88 | } |
89 | 89 | ||
90 | idx++; | 90 | idx++; |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | #endregion | 94 | #endregion |
95 | 95 | ||
96 | #region Public Methods | 96 | #region Public Methods |
97 | 97 | ||
98 | /// <summary> | 98 | /// <summary> |
99 | /// Wases the passed. | 99 | /// Wases the passed. |
100 | /// </summary> | 100 | /// </summary> |
101 | /// <param name="arg">The arg.</param> | 101 | /// <param name="arg">The arg.</param> |
102 | /// <returns></returns> | 102 | /// <returns></returns> |
103 | public bool WasPassed(string arg) | 103 | public bool WasPassed(string arg) |
104 | { | 104 | { |
105 | return (m_Arguments.ContainsKey(arg)); | 105 | return (m_Arguments.ContainsKey(arg)); |
106 | } | 106 | } |
107 | 107 | ||
108 | #endregion | 108 | #endregion |
109 | 109 | ||
110 | #region Properties | 110 | #region Properties |
111 | 111 | ||
112 | /// <summary> | 112 | /// <summary> |
113 | /// Gets the parameter associated with the command line option | 113 | /// Gets the parameter associated with the command line option |
114 | /// </summary> | 114 | /// </summary> |
115 | /// <remarks>Returns null if option was not specified, | 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> | 116 | /// null string if no parameter was specified, and the value if a parameter was specified</remarks> |
117 | public string this[string index] | 117 | public string this[string index] |
118 | { | 118 | { |
119 | get | 119 | get |
120 | { | 120 | { |
121 | if(m_Arguments.ContainsKey(index)) | 121 | if(m_Arguments.ContainsKey(index)) |
122 | { | 122 | { |
123 | return (m_Arguments[index]); | 123 | return (m_Arguments[index]); |
124 | } | 124 | } |
125 | return null; | 125 | return null; |
126 | } | 126 | } |
127 | } | 127 | } |
128 | 128 | ||
129 | #endregion | 129 | #endregion |
130 | 130 | ||
131 | #region IEnumerable Members | 131 | #region IEnumerable Members |
132 | 132 | ||
133 | /// <summary> | 133 | /// <summary> |
134 | /// Returns an enumerator that can iterate through a collection. | 134 | /// Returns an enumerator that can iterate through a collection. |
135 | /// </summary> | 135 | /// </summary> |
136 | /// <returns> | 136 | /// <returns> |
137 | /// An <see cref="T:System.Collections.IDictionaryEnumerator"/> | 137 | /// An <see cref="T:System.Collections.IDictionaryEnumerator"/> |
138 | /// that can be used to iterate through the collection. | 138 | /// that can be used to iterate through the collection. |
139 | /// </returns> | 139 | /// </returns> |
140 | public IEnumerator<KeyValuePair<string, string>> GetEnumerator() | 140 | public IEnumerator<KeyValuePair<string, string>> GetEnumerator() |
141 | { | 141 | { |
142 | return m_Arguments.GetEnumerator(); | 142 | return m_Arguments.GetEnumerator(); |
143 | } | 143 | } |
144 | 144 | ||
145 | IEnumerator IEnumerable.GetEnumerator() | 145 | IEnumerator IEnumerable.GetEnumerator() |
146 | { | 146 | { |
147 | return GetEnumerator(); | 147 | return GetEnumerator(); |
148 | } | 148 | } |
149 | 149 | ||
150 | #endregion | 150 | #endregion |
151 | } | 151 | } |
152 | } | 152 | } |