alpha support for response files
authorRafael Teixeira <monoman@gmail.com>
Sun, 20 Oct 2002 20:06:40 +0000 (20:06 -0000)
committerRafael Teixeira <monoman@gmail.com>
Sun, 20 Oct 2002 20:06:40 +0000 (20:06 -0000)
svn path=/trunk/mcs/; revision=8431

mcs/class/Mono.GetOptions/OptionList.cs
mcs/class/Mono.GetOptions/Options.cs

index 50ba4faebc6079b4cbe3c06e169c2ea63d267899..4962db1d8d8ef16eaf97ab0a3274ce3a896717d1 100644 (file)
@@ -242,54 +242,94 @@ namespace Mono.GetOptions
 
                #region Arguments Processing
 
-               public string[] NormalizeArgs(string[] args)
+               public string[] ExpandResponseFiles(string[] args)
                {
-                       bool ParsingOptions = true;
                        ArrayList result = new ArrayList();
 
                        foreach(string arg in args)
                        {
-                               if (ParsingOptions)
+                               if (arg.StartsWith("@"))
                                {
-                                       if (endOptionProcessingWithDoubleDash && (arg == "--"))
+                                       try 
+                                       {
+                                               StreamReader tr = new StreamReader(arg.Substring(1));
+                                               string line;
+                                               while ((line = tr.ReadLine()) != null)
+                                               {
+                                                       result.AddRange(line.Split());
+                                               }
+                                               tr.Close(); 
+                                       }
+                                       catch (FileNotFoundException exception)
                                        {
-                                               ParsingOptions = false;
+                                               Console.WriteLine("Could not find response file: " + arg.Substring(1));
                                                continue;
                                        }
+                                       catch (Exception exception)
+                                       {
+                                               Console.WriteLine("Error trying to read response file: " + arg.Substring(1));
+                                               Console.WriteLine(exception.Message);
+                                               continue;
+                                       }
+                               }
+                               else
+                                       result.Add(arg);
+                       }
+
+                       return (string[])result.ToArray(typeof(string));
+               }
+
+               public string[] NormalizeArgs(string[] args)
+               {
+                       bool ParsingOptions = true;
+                       ArrayList result = new ArrayList();
 
-                                       if ((parsingMode & OptionsParsingMode.Windows) > 0)
+                       foreach(string arg in ExpandResponseFiles(args))
+                       {
+                               if (arg.Length > 0)
+                               {
+                                       if (ParsingOptions)
                                        {
-                                               if ((arg.Length == 2) && (arg[0] == '/')) // Windows options only come in this fashion
+                                               if (endOptionProcessingWithDoubleDash && (arg == "--"))
                                                {
-                                                       result.Add("-" + arg[1]); // translate to Linux style
+                                                       ParsingOptions = false;
                                                        continue;
                                                }
-                                       }
 
-                                       if ((parsingMode & OptionsParsingMode.Linux) > 0)
-                                       {
-                                               if ((arg[0] == '-') && (arg[1] != '-'))
+                                               if ((parsingMode & OptionsParsingMode.Windows) > 0)
                                                {
-                                                       foreach(char c in arg.Substring(1)) // many single-letter options
-                                                               result.Add("-" + c); // expand into individualized options
-                                                       continue;
+                                                       if ((arg.Length == 2) && (arg[0] == '/')) // Windows options only come in this fashion
+                                                       {
+                                                               result.Add("-" + arg[1]); // translate to Linux style
+                                                               continue;
+                                                       }
                                                }
 
-                                               if (arg.StartsWith("--"))
+                                               if ((parsingMode & OptionsParsingMode.Linux) > 0)
                                                {
-                                                       result.AddRange(arg.Split('='));  // put in the same form of one-letter options with a parameter
-                                                       continue;
+                                                       if ((arg[0] == '-') && (arg[1] != '-'))
+                                                       {
+                                                               foreach(char c in arg.Substring(1)) // many single-letter options
+                                                                       result.Add("-" + c); // expand into individualized options
+                                                               continue;
+                                                       }
+
+                                                       if (arg.StartsWith("--"))
+                                                       {
+                                                               result.AddRange(arg.Split('='));  // put in the same form of one-letter options with a parameter
+                                                               continue;
+                                                       }
                                                }
                                        }
-                               }
-                               else
-                               {
-                                       argumentsTail.Add(arg);
-                                       continue;
-                               }
+                                       else
+                                       {
+                                               argumentsTail.Add(arg);
+                                               continue;
+                                       }
 
-                               // if nothing else matches then it get here
-                               result.Add(arg);
+                                       // if nothing else matches then it get here
+                                       result.Add(arg);
+                               }
                        }
 
                        return (string[])result.ToArray(typeof(string));
index 13aa56bfc5110390e47d71521a02d858ca62deab..c6f6a36c11fdf33f7f805fdd51869d4b88490bbf 100644 (file)
@@ -29,7 +29,7 @@ namespace Mono.GetOptions
                        return optionParser.DoHelp();
                }
 
-               [Option("Display version and licensing information", 'V',"version")]
+               [Option("Display version and licensing information", 'V', "version")]
                public virtual WhatToDoNext DoAbout()
                {
                        return optionParser.DoAbout();