private void DoWriteDelimitedComment(StringBuilder builder, string text)
	{
		int j = text.IndexOf("*/");
		if (j >= 0)
		{
			builder.WriteLine(text.Substring(0, j + 2));
			builder.WriteLine();
		}
	}
	private void DoWriteUsing(StringBuilder builder, CsNamespace ns, string indent)
	{
		if (ns.Uses.Length > 0)
		{
			foreach (CsUsingDirective u in ns.Uses)
			{
				builder.WriteLine("{0}using {1};", indent, u.Namespace);
			}
			builder.WriteLine();
		}
	}
	// Files often start with things like copyright notices which we want to preserve.
	private void DoWriteSingleLineComments(StringBuilder builder, string text)
	{
		int i = 0;
		
		while (i + 2 < text.Length && text[i] == '/' && text[i + 1] == '/')
		{
			int j = text.IndexOf('\n', i);
			if (j >= 0)
			{
				builder.WriteLine(text.Substring(i, j - i));
				i = j + 1;
			}
			else
				break;
		}
		builder.WriteLine();
	}
	private void DoBuildNewFile(string name, CsGlobalNamespace globals, CsDeclaration first, StringBuilder builder, string text, int offset, int length)
	{
		// If the file starts with a comment then write it out.
		if (text.Length > 2 && text[0] == '/' && text[1] == '/')
			DoWriteSingleLineComments(builder, text);
		else if (text.Length > 2 && text[0] == '/' && text[1] == '*')
			DoWriteDelimitedComment(builder, text);
		
		// Write the global using directives.
		DoWriteUsing(builder, globals, string.Empty);
		
		// Write the namespace the declaration was in.
		CsNamespace ns = DoGetNamespace(first);
		if (ns != null && ns.Name != "<globals>")
		{
			builder.WriteLine("namespace {0}{1}{2}", ns.Name, Constants.Bullet, "{");
			DoWriteUsing(builder, ns, "\t");
		}
		
		// If we're moving a member then create a dummy type.
		CsMember member = first as CsMember;
		if (member != null && member.DeclaringType != null)
		{
			string keyword = "?";
			if (member.DeclaringType is CsClass)
				keyword = "class";
			else if (member.DeclaringType is CsInterface)
				keyword = "interface";
			else if (member.DeclaringType is CsStruct)
				keyword = "struct";
				
			string modifiers;
			if (member.DeclaringType != null)
				modifiers = member.DeclaringType.Modifiers.ToString().ToLower();
			else
				modifiers = member.Modifiers.ToString().ToLower();
			modifiers = modifiers.Replace(",", string.Empty);
			
			builder.WriteLine("\t{0} {1} {2}", modifiers, keyword, name);
			builder.WriteLine("\t{");
		}
		
		// Write the selection.
		builder.Write(text.Substring(offset, length));
		
		// Close up type and namespaces.
		if (member != null && member.DeclaringType != null)
			builder.WriteLine("\t}");
		
		if (ns  != null && ns.Name != "<globals>")
			builder.WriteLine("}");
	}
Example #5
0
        public static string GetStatsString(string compiler, ICompilerCache cache)
        {
            var sb = new StringBuilder();
            sb.WriteLine("compiler: {0}", compiler);
            sb.WriteLine("cachedir: {0}", Settings.CacheDirectory);
            if (Settings.DebugEnabled)
            {
                sb.WriteLine("debug file: {0}", Settings.DebugFile);
            }
            if (Settings.Disabled)
            {
                sb.WriteLine("disabled: yes");
            }
            else
            {
                sb.WriteLine("disabled: no");
            }
            if (compiler != null)
            {
                if (cache != null)
                {
                    var stats = new CacheInfo(cache.OutputCache);

                    sb.WriteLine("outputCache usage: {0} kb", (int)(stats.CacheSize / 1024));
                    sb.WriteLine("cached files: {0}", stats.CacheObjects);
                    sb.WriteLine("hits: {0}", stats.CacheHits);
                    sb.WriteLine("misses: {0}", stats.CacheMisses);
                    sb.WriteLine("unsupported: {0}", stats.CacheUnsupported);
                    sb.WriteLine("slow hits: {0}", stats.SlowHitCount);
                }
            }
            return sb.ToString();
        }
Example #6
0
 public SVGGeometryOutput(StringBuilder stringOut)
 {
     sb = stringOut;
     sb.WriteLine("<?xml version='1.0' encoding='UTF-8' standalone='no'?>");
     sb.WriteLine("<!-- created with Enchanted Gears (http://www.enchantedage.com/gears) -->");
     sb.WriteLine("<svg xmlns:dc='http://purl.org/dc/elements/1.1/'");
     sb.WriteLine(" xmlns:cc='http://creativecommons.org/ns#'");
     sb.WriteLine(" xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'");
     sb.WriteLine(" xmlns:svg='http://www.w3.org/2000/svg'");
     sb.WriteLine(" xmlns='http://www.w3.org/2000/svg'");
     sb.WriteLine(" version='1.1'");
     sb.WriteLine(" width='1000'");
     sb.WriteLine(" height='1000'");
     sb.WriteLine(" id='gears-svg'>");
     sb.WriteLine("<defs id='defs-dummy' />");
     sb.WriteLine("<circle id='center' fill='none' stroke='#808080' cx='500' cy='500' r='10' />");
 }
Example #7
0
 public GCodeGeometryOutput(StringBuilder stringOut)
 {
     feed = 1;
     sb = stringOut;
     sb.WriteLine("G20");        //  inches
     sb.WriteLine("G90");        //  absolute
     sb.WriteLine("G17");        //  XY plane
     sb.WriteLine("M3");         //  start spindle
 }