Skip to content

Commit

Permalink
[mdoc] Add response file support to all mdoc commands.
Browse files Browse the repository at this point in the history
...because it's so much easier dealing with 77 arguments for
mdoc-update-ecma-xml when I can use a text editor instead of bash...
  • Loading branch information
jonpryor committed Aug 27, 2010
1 parent 00732aa commit c20627e
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion mcs/tools/mdoc/Mono.Documentation/mdoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using Mono.Options;

namespace Mono.Documentation {
Expand Down Expand Up @@ -49,14 +51,21 @@ private void Run (string[] args)

bool showVersion = false;
bool showHelp = false;
var extra = new List<string> ();
var p = new OptionSet () {
{ "version", v => showVersion = v != null },
{ "v:", (int? v) => verbosity = v.HasValue ? v.Value : verbosity+1 },
{ "debug", v => debug = v != null },
{ "h|?|help", v => showHelp = v != null },
{ "<>", v => {
if (v.Length > 0 && v [0] == '@')
extra.AddRange (ReadResponseFile (v.Substring (1)));
else
extra.Add (v);
} },
};

List<string> extra = p.Parse (args);
p.Parse (args);

if (showVersion) {
Console.WriteLine ("mdoc {0}", Consts.MonoVersion);
Expand All @@ -72,6 +81,52 @@ private void Run (string[] args)
GetCommand (extra [0]).Run (extra);
}

// Cribbed from mcs/driver.cs:LoadArgs(string)
static IEnumerable<string> ReadResponseFile (string file)
{
StreamReader response;
try {
response = File.OpenText (file);
} catch {
yield break;
}

using (response) {
StringBuilder arg = new StringBuilder ();

string line;
while ((line = response.ReadLine ()) != null) {
int t = line.Length;

for (int i = 0; i < t; i++) {
char c = line [i];

if (c == '"' || c == '\'') {
char end = c;

for (i++; i < t; i++){
c = line [i];

if (c == end)
break;
arg.Append (c);
}
} else if (c == ' ') {
if (arg.Length > 0) {
yield return arg.ToString ();
arg.Length = 0;
}
} else
arg.Append (c);
}
if (arg.Length > 0) {
yield return arg.ToString ();
arg.Length = 0;
}
}
}
}

internal MDocCommand GetCommand (string command)
{
MDocCommand h;
Expand Down

0 comments on commit c20627e

Please sign in to comment.