summaryrefslogtreecommitdiff
path: root/getoptOLD/GetOpt.cs
diff options
context:
space:
mode:
authorfcolin2007-02-15 15:13:37 +0000
committerfcolin2007-02-15 15:13:37 +0000
commit52758d6ab4138dfa7cfe57e7b1ba10c6c085cb0f (patch)
tree631ee8c4ce5c8bd00385c827caf3238633315976 /getoptOLD/GetOpt.cs
parent26f415f8dd8d6f45b7d79dbf4f5876496ae4de4d (diff)
downloadivy-csharp-52758d6ab4138dfa7cfe57e7b1ba10c6c085cb0f.zip
ivy-csharp-52758d6ab4138dfa7cfe57e7b1ba10c6c085cb0f.tar.gz
ivy-csharp-52758d6ab4138dfa7cfe57e7b1ba10c6c085cb0f.tar.bz2
ivy-csharp-52758d6ab4138dfa7cfe57e7b1ba10c6c085cb0f.tar.xz
Renommé à distance
Diffstat (limited to 'getoptOLD/GetOpt.cs')
-rw-r--r--getoptOLD/GetOpt.cs98
1 files changed, 98 insertions, 0 deletions
diff --git a/getoptOLD/GetOpt.cs b/getoptOLD/GetOpt.cs
new file mode 100644
index 0000000..a158073
--- /dev/null
+++ b/getoptOLD/GetOpt.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Specialized;
+using System.Collections.Generic;
+
+namespace Gnu
+{
+ /// <summary>
+ /// An implementation of the getopt standard, as used by Gnu GetOpt
+ /// </summary>
+ public class GetOpt
+ {
+ StringCollection m_params = new StringCollection();
+ StringCollection m_extras = new StringCollection();
+ List<Arg> m_args = new List<Arg>();
+
+ public GetOpt(string[] CommandLineArgs, string ParametersDescription)
+ {
+ // Import the string array into the collection
+ foreach(string s in CommandLineArgs)
+ {
+ m_params.Add(s);
+ }
+
+ // Parse the params description
+ for(int i = 0; i < ParametersDescription.Length; i++)
+ {
+ Arg a = new Arg();
+ a.Flag = ParametersDescription[i];
+ if((ParametersDescription.Length > i + 1) && (ParametersDescription[i + 1] == ':'))
+ {
+ a.TakesParameter = true;
+ i++;
+ }
+
+ m_args.Add(a);
+ }
+ }
+
+ public Arg NextArg()
+ {
+ SnarfExtras();
+
+ if(m_params.Count == 0)
+ return null;
+
+ foreach(Arg a in m_args)
+ {
+ if(a.Flag == m_params[0][1] && m_params[0][0] == '-' )
+ {
+ Arg matched = a;
+ try
+ {
+ if(a.TakesParameter)
+ {
+ matched.Parameter = m_params[1];
+ m_params.RemoveAt(1);
+ }
+ }
+ catch(Exception)
+ {
+ }
+
+ m_params.RemoveAt(0);
+ return matched;
+ }
+ }
+
+ if(m_params[0][0] == '-')
+ {
+ Arg tempa = new Arg();
+ tempa.Flag = m_params[0][1];
+ tempa.TakesParameter = false;
+ return tempa;
+ }
+ return null;
+ }
+
+ public StringCollection Extras
+ {
+ get
+ {
+ SnarfExtras();
+
+ return m_extras;
+ }
+ }
+
+ private void SnarfExtras()
+ {
+ // Parameters must start with a hyphen
+ while((m_params.Count > 0) && (m_params[0][0] != '-'))
+ {
+ m_extras.Add(m_params[0]);
+ m_params.RemoveAt(0);
+ }
+ }
+ }
+}