1 // cilc -- a CIL-to-C binding generator
2 // Copyright (C) 2003, 2004, 2005, 2006, 2007 Alp Toker <alp@atoker.com>
3 // Licensed under the terms of the MIT License
10 private StreamWriter w;
12 public CodeWriter (string fname)
17 public bool IsDuplicate = false;
19 void Init (string fname)
21 if (File.Exists (fname)) {
22 string newfname = fname + ".x";
23 //Console.WriteLine ("Warning: File " + fname + " already exists, using " + newfname);
29 FileStream fs = new FileStream (fname, FileMode.OpenOrCreate, FileAccess.Write);
30 w = new StreamWriter (fs);
33 public string Indenter = " ";
34 string cur_indent = String.Empty;
40 cur_indent = String.Empty;
41 for (int i = 0; i != level ; i++) cur_indent += Indenter;
44 public void Outdent ()
47 cur_indent = String.Empty;
48 for (int i = 0; i != level ; i++) cur_indent += Indenter;
51 public void Write (string text)
56 public void WriteLine (string text)
58 WriteLine (text, true);
61 public void WriteLine (string text, bool autoindent)
63 char[] opentags = {'{', '('};
64 char[] closetags = {'}', ')'};
66 if (autoindent && text.TrimStart (closetags) != text)
72 if (autoindent && text.TrimEnd (opentags) != text)
76 public void WriteLine (string text, CodeWriter cc)
78 WriteLine (text, String.Empty, cc, String.Empty);
81 public void WriteLine (string text, CodeWriter cc, string suffix)
83 WriteLine (text, String.Empty, cc, suffix);
86 public void WriteLine (string text, string prefix, CodeWriter cc)
88 WriteLine (text, prefix, cc, String.Empty);
91 public void WriteLine (string text, string prefix, CodeWriter cc, string suffix)
94 cc.WriteLine (prefix + text + suffix);
97 public void WriteComment (string text)
99 w.WriteLine ("/* " + text + " */");
102 public void WriteLine ()
104 w.WriteLine (String.Empty);