2009-12-03 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / xaml-to-header.cs
blob0790de0ea5aa258cca8eb90e074486dd9e090371
1 using System;
2 using System.IO;
3 using System.Collections;
4 using System.Collections.Generic;
5 using System.Text;
7 class convert {
8 static int Main (string [] args)
10 try {
11 string sourcefile = args [0];
12 string cpp_symbol = args [1];
14 string destfile = Path.ChangeExtension (sourcefile, ".h");
15 string [] source = File.ReadAllLines (sourcefile);
16 List<string> dest = new List <string> ();
18 dest.Add (string.Format (@"/*
19 * {0}: the xaml for the fullscreen message.
21 * Contact:
22 * Moonlight List (moonlight-list@lists.ximian.com)
24 * Copyright 2007 Novell, Inc. (http://www.novell.com)
26 * See the LICENSE file included with the distribution for details.
28 */", destfile));
30 dest.Add (string.Format ("#define {0} \\", cpp_symbol));
32 for (int i = 0; i < source.Length; i++) {
33 int j;
34 StringBuilder sb = new StringBuilder ();
35 /* put the leading whitespace in the file */
36 for (j = 0; j < source[i].Length; j ++) {
37 if (!Char.IsWhiteSpace (source[i], j))
38 break;
40 if (j > 0) sb.Append (source[i].Substring (0, j));
41 sb.Append ("\"" + source [i].Substring (j).Replace ("\"", "\\\"") + (source[i][source[i].Length-1] == '>' ? "" : " ") + "\" \\");
42 dest.Add (sb.ToString());
44 dest.Add ("\"\"");
45 dest.Add ("");
46 File.WriteAllLines (destfile, dest.ToArray ());
48 return 0;
49 } catch (Exception ex) {
50 Console.WriteLine (ex.Message);
51 Console.WriteLine (ex.StackTrace);
52 return 1;