Beispiel #1
0
	public static void Main(string[] args) {
		if (args.Length != 2)
			return;
		
		// Read in the output rules files
		
		XmlDocument stylesheet = new XmlDocument();
		
		XmlElement stylesheet_root = stylesheet.CreateElement("xsl:stylesheet", "http://www.w3.org/1999/XSL/Transform");
		stylesheet_root.SetAttribute("version", "1.0");
		stylesheet.AppendChild(stylesheet_root);

		/*XmlElement outputnode = stylesheet.CreateElement("xsl:output", "http://www.w3.org/1999/XSL/Transform");
		outputnode.SetAttribute("method", "text");
		stylesheet_root.AppendChild(outputnode);*/

		XmlElement basetemplate = stylesheet.CreateElement("xsl:template", "http://www.w3.org/1999/XSL/Transform");
		basetemplate.SetAttribute("match", "*");
		basetemplate.InnerXml = "[<xsl:value-of xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select=\"name()\"/>:"
			+ "<xsl:for-each select='*' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"
			+ "[<xsl:value-of select='name(.)'/>]"
			+ "</xsl:for-each>]";
		stylesheet_root.AppendChild(basetemplate);
		
		StreamReader csgen = new StreamReader("csgen.txt");
		System.Text.RegularExpressions.Regex SubstParam = new System.Text.RegularExpressions.Regex(@"@([\w\*]+)(\[[^\]]+\])?");
		string csgen_line;
		while ((csgen_line = csgen.ReadLine()) != null) {
			if (csgen_line == "" || csgen_line[0] == '#') { continue; }
			int sp = csgen_line.IndexOf(" ");
			if (sp == -1) { continue; }
			string rule = csgen_line.Substring(sp+1);
			
			int priority = -1;
			
			if (csgen_line.StartsWith("*"))
				priority = 10;
			if (csgen_line.StartsWith("!")) {
				priority = 20;
				csgen_line = csgen_line.Substring(1);
			}
			
			XmlElement template = stylesheet.CreateElement("xsl:template", "http://www.w3.org/1999/XSL/Transform");
			template.SetAttribute("match", csgen_line.Substring(0, sp));
			template.SetAttribute("xml:space", "preserve");

			if (priority != -1)
				template.SetAttribute("priority", priority.ToString());
			if (rule == "none") {
				template.InnerXml = "<xsl:apply-templates xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select='*'/>";
			} else if (rule == "text") {
				template.InnerXml = "<xsl:value-of xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select='@Text'/>";
			} else {
				rule = rule.Replace("|", "\n");
				if (!rule.EndsWith("\\")) rule += "\n"; else rule = rule.Substring(0, rule.Length-1);

				rule = rule.Replace("@@1", "<xsl:apply-templates xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select='*[position()&gt;1]'/>");
				rule = rule.Replace("@@", "<xsl:apply-templates xmlns:xsl='http://www.w3.org/1999/XSL/Transform'/>");
				
				foreach (System.Text.RegularExpressions.Match match in SubstParam.Matches(rule)) {
					string type = match.Result("$1");
					string sep = match.Result("$2");
					if (sep != "") sep = sep.Substring(1, sep.Length-2);
					if (type == "text") {
						rule = rule.Replace(match.Value, "<xsl:value-of xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select='@Text'/>");
					} else {
						if (char.IsDigit(type[0]))
							type = "*[position()=" + type + "]";
						if (sep == "")
							rule = rule.Replace(match.Value, "<xsl:apply-templates xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select='" + type + "'/>");
						else
							rule = rule.Replace(match.Value,
							"<xsl:for-each xmlns:xsl='http://www.w3.org/1999/XSL/Transform' select='" + type + "'>" 
							+ "<xsl:if test='not(position()=1)'>" + sep + "</xsl:if>"
							+ "<xsl:apply-templates select='.'/>"
							+ "</xsl:for-each>");
					}
				}

				template.InnerXml = rule;
			}
			stylesheet_root.AppendChild(template);
		}
		
		CSharpAST
			left = GetAST(args[0]),
			right = GetAST(args[1]);
		
		StringWriter buffer = new StringWriter();
		XmlTextWriter output = new XmlTextWriter(buffer);
		//output.Formatting = Formatting.Indented;
		StructuredDiff test = new XmlOutputStructuredDiff(output, null);
		test.AddInterface(typeof(ASTNode), new ASTNodeInterface());		
		test.Compare(left, right);		
		output.Close();
		
		XmlDocument diff = new XmlDocument();
		diff.LoadXml(buffer.ToString());
		
		XslTransform transform = new XslTransform();
		transform.Load(stylesheet);
		
		XmlReader diffcontent = transform.Transform(diff, null);
		
		throw new Exception(diffcontent.BaseURI == null ? "null" : "not null");
		
		XmlDocument diffdoc = new XmlDocument();
		diffdoc.Load(diffcontent);
		diffdoc.Normalize();
		
		WriteChildren(diffdoc.DocumentElement, 0, ' ');

		
		Console.WriteLine();
	}
Beispiel #2
0
	public static void Main(string[] args) {
		OptsType opts = new OptsType();
		opts.ProcessArgs(args);
		
		if (opts.RemainingArguments.Length != 2) {
			opts.DoHelp();
			return;
		}
		
		XmlDocument left = new XmlDocument();
		left.Load(opts.RemainingArguments[0]);

		XmlDocument right = new XmlDocument();
		right.Load(opts.RemainingArguments[1]);
		
		StringWriter buffer = null;
		XmlWriter output;
		
		if (opts.output == "xml") {
			XmlTextWriter textoutput = new XmlTextWriter(Console.Out);
			textoutput.Formatting = Formatting.Indented;
			output = textoutput;
		} else {
			buffer = new StringWriter();
			output = new XmlTextWriter(buffer);
		}
		
		StructuredDiff test = new XmlOutputStructuredDiff(output, opts.full ? null : opts.context == null ? "*" : String.Join(",", opts.context));

		XmlNodeInterface xmlint = new XmlNodeInterface();
		
		test.AddInterface(typeof(XmlAttribute), xmlint);
		test.AddInterface(typeof(XmlCDataSection), xmlint);
		test.AddInterface(typeof(XmlComment), xmlint);
		test.AddInterface(typeof(XmlDeclaration), xmlint);
		test.AddInterface(typeof(XmlDocument), xmlint);
		test.AddInterface(typeof(XmlDocumentType), xmlint);
		test.AddInterface(typeof(XmlElement), xmlint);
		test.AddInterface(typeof(XmlEntity), xmlint);
		test.AddInterface(typeof(XmlEntityReference), xmlint);
		test.AddInterface(typeof(XmlNotation), xmlint);
		test.AddInterface(typeof(XmlProcessingInstruction), xmlint);
		test.AddInterface(typeof(XmlSignificantWhitespace), xmlint);
		test.AddInterface(typeof(XmlText), xmlint);
		test.AddInterface(typeof(XmlWhitespace), xmlint);
		
		test.Compare(left, right);
		
		output.Close();
		
		if (opts.output != "xml") {
			XmlDocument doc = new XmlDocument();
			doc.LoadXml(buffer.ToString());

			TextWriter rawoutput;
			XmlTextWriter textoutput;
			
			if (opts.output == "groff") {
				System.Diagnostics.Process groff = new System.Diagnostics.Process();
				groff.StartInfo.FileName = "groff";
				groff.StartInfo.Arguments = "-Tlatin1 -Ww";
				groff.StartInfo.RedirectStandardInput = true;
				groff.StartInfo.UseShellExecute = false;				
				groff.Start();
				textoutput = new XmlTextWriter(new RoffWriter(groff.StandardInput));
				rawoutput = groff.StandardInput;
			} else {
				textoutput = new XmlTextWriter(Console.Out);
				rawoutput = Console.Out;
			}
			textoutput.Formatting = Formatting.Indented;
			
			WriteNode((XmlElement)doc.DocumentElement.SelectSingleNode("*"), opts.output, textoutput, rawoutput);
		}
	}