public static string CreateListing(List<ListEntry> output) { string listing = ""; int maxLength = 0, maxFileLength = 0; foreach (var entry in output) { int length = entry.FileName.Length + 1; if (length > maxFileLength) maxFileLength = length; } foreach (var entry in output) { int length = maxFileLength + entry.LineNumber.ToString().Length + 9; if (length > maxLength) maxLength = length; } TabifiedStringBuilder tsb; foreach (var listentry in output) { tsb = new TabifiedStringBuilder(); // FIX: TJMonk(04-20-2013) - Changing this code to use arrays, and adding support for '#' directives bool pass = false; if (listentry.ErrorCode == ErrorCode.Success) { string[] lineStarts = { ".", "#" }; string[] directives = { "dat", "dw", "db", "ascii","asciiz", "asciip", "asciic", "align", "fill", "pad", "incbin", "reserve", "incpack", "relocate" }; string toCheck = listentry.Code.ToLower(); bool checkLineStart = false; foreach (var s in lineStarts) { if (toCheck.StartsWith(s)) { checkLineStart = true; toCheck = toCheck.Substring(s.Length); break; } } if (checkLineStart) { foreach (var s in directives) { if (toCheck.StartsWith(s)) { pass = true; break; } } } } if (pass) { // ENDFIX: TJMonk(04-20-2013) // Write code line tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed) tsb.WriteAt(maxLength, "[0x" + LongHex(listentry.Address) + "] "); else tsb.WriteAt(maxLength, "[NOLIST] "); tsb.WriteAt(maxLength + 25, listentry.Code); listing += tsb.Value + Environment.NewLine; // Write data if (listentry.Output != null) { for (int i = 0; i < listentry.Output.Length; i += 8) { tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed) tsb.WriteAt(maxLength, "[0x" + LongHex((ushort)(listentry.Address + i)) + "] "); else tsb.WriteAt(maxLength, "[NOLIST] "); string data = ""; for (int j = 0; j < 8 && i + j < listentry.Output.Length; j++) { data += LongHex(listentry.Output[i + j]) + " "; } tsb.WriteAt(maxLength + 30, data.Remove(data.Length - 1)); listing += tsb.Value + Environment.NewLine; } } } else { if (listentry.ErrorCode != ErrorCode.Success) { tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed) tsb.WriteAt(maxLength, "[0x" + LongHex(listentry.Address) + "] "); else tsb.WriteAt(maxLength, "[NOLIST] "); tsb.WriteAt(maxLength + 8, "ERROR: " + ListEntry.GetFriendlyErrorMessage(listentry.ErrorCode)); listing += tsb.Value + Environment.NewLine; } if (listentry.WarningCode != WarningCode.None) { tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed) tsb.WriteAt(maxLength, "[0x" + LongHex(listentry.Address) + "] "); else tsb.WriteAt(maxLength, "[NOLIST] "); tsb.WriteAt(maxLength + 8, "WARNING: " + ListEntry.GetFriendlyWarningMessage(listentry.WarningCode)); listing += tsb.Value + Environment.NewLine; } tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed) tsb.WriteAt(maxLength, "[0x" + LongHex(listentry.Address) + "] "); else tsb.WriteAt(maxLength, "[NOLIST] "); if (listentry.Output != null) { if (listentry.Output.Length > 0) { tsb.WriteAt(maxLength + 8, DumpArray(listentry.Output)); tsb.WriteAt(maxLength + 25, listentry.Code); } } else tsb.WriteAt(maxLength + 23, listentry.Code); listing += tsb.Value + Environment.NewLine; } } return listing; }
public static string CreateListing(List <ListEntry> output) { string listing = ""; int maxLength = 0, maxFileLength = 0; foreach (var entry in output) { int length = entry.FileName.Length + 1; if (length > maxFileLength) { maxFileLength = length; } } foreach (var entry in output) { int length = maxFileLength + entry.LineNumber.ToString().Length + 9; if (length > maxLength) { maxLength = length; } } TabifiedStringBuilder tsb; foreach (var listentry in output) { tsb = new TabifiedStringBuilder(); // FIX: TJMonk(04-20-2013) - Changing this code to use arrays, and adding support for '#' directives bool pass = false; if (listentry.ErrorCode == ErrorCode.Success) { string[] lineStarts = { ".", "#" }; string[] directives = { "dat", "dw", "db", "ascii", "asciiz", "asciip", "asciic", "align", "fill", "pad", "incbin", "reserve", "incpack", "relocate" }; string toCheck = listentry.Code.ToLower(); bool checkLineStart = false; foreach (var s in lineStarts) { if (toCheck.StartsWith(s)) { checkLineStart = true; toCheck = toCheck.Substring(s.Length); break; } } if (checkLineStart) { foreach (var s in directives) { if (toCheck.StartsWith(s)) { pass = true; break; } } } } if (pass) { // ENDFIX: TJMonk(04-20-2013) // Write code line tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed) { tsb.WriteAt(maxLength, "[0x" + LongHex(listentry.Address) + "] "); } else { tsb.WriteAt(maxLength, "[NOLIST] "); } tsb.WriteAt(maxLength + 25, listentry.Code); listing += tsb.Value + Environment.NewLine; // Write data if (listentry.Output != null) { for (int i = 0; i < listentry.Output.Length; i += 8) { tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); //if (listentry.Listed) // tsb.WriteAt(maxLength, "[0x" + LongHex((ushort)(listentry.Address + i)) + "] "); //else tsb.WriteAt(maxLength, "[NOLIST] "); string data = ""; for (int j = 0; j < 8 && i + j < listentry.Output.Length; j++) { data += LongHex(listentry.Output[i + j]) + " "; } tsb.WriteAt(maxLength + 30, data.Remove(data.Length - 1)); listing += tsb.Value + Environment.NewLine; } } } else { if (listentry.ErrorCode != ErrorCode.Success) { tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed && listentry.Output != null) { tsb.WriteAt(maxLength, "[0x" + LongHex(listentry.Address) + "] "); } else { tsb.WriteAt(maxLength, "[NOLIST] "); } tsb.WriteAt(maxLength + 8, "ERROR: " + ListEntry.GetFriendlyErrorMessage(listentry.ErrorCode)); listing += tsb.Value + Environment.NewLine; } if (listentry.WarningCode != WarningCode.None) { tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed && listentry.Output != null) { tsb.WriteAt(maxLength, "[0x" + LongHex(listentry.Address) + "] "); } else { tsb.WriteAt(maxLength, "[NOLIST] "); } tsb.WriteAt(maxLength + 8, "WARNING: " + ListEntry.GetFriendlyWarningMessage(listentry.WarningCode)); listing += tsb.Value + Environment.NewLine; } tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed && (listentry.CodeType == CodeType.Label || listentry.Output != null)) { tsb.WriteAt(maxLength, "[0x" + LongHex(listentry.Address) + "] "); } else { tsb.WriteAt(maxLength, "[NOLIST] "); } if (listentry.Output != null) { if (listentry.Output.Length > 0) { tsb.WriteAt(maxLength + 8, DumpArray(listentry.Output)); tsb.WriteAt(maxLength + 25, listentry.Code); } } else { tsb.WriteAt(maxLength + 23, listentry.Code); } listing += tsb.Value + Environment.NewLine; } } return(listing); }
public static string CreateListing(List<ListEntry> output) { string listing = ""; int maxLength = 0, maxFileLength = 0; foreach (var entry in output) { int length = entry.FileName.Length + 1; if (length > maxFileLength) maxFileLength = length; } foreach (var entry in output) { int length = maxFileLength + entry.LineNumber.ToString().Length + 9; if (length > maxLength) maxLength = length; } TabifiedStringBuilder tsb; foreach (var listentry in output) { tsb = new TabifiedStringBuilder(); if ((listentry.Code.ToLower().StartsWith(".dat") || listentry.Code.ToLower().StartsWith(".dw") || listentry.Code.ToLower().StartsWith(".db") || listentry.Code.ToLower().StartsWith(".ascii") || listentry.Code.ToLower().StartsWith(".asciiz") || listentry.Code.ToLower().StartsWith(".asciip") || listentry.Code.ToLower().StartsWith(".asciic") || listentry.Code.ToLower().StartsWith(".align") || listentry.Code.ToLower().StartsWith(".fill") || listentry.Code.ToLower().StartsWith(".pad") || listentry.Code.ToLower().StartsWith(".incbin") || listentry.Code.ToLower().StartsWith(".reserve") || listentry.Code.ToLower().StartsWith(".incpack") || listentry.Code.ToLower().StartsWith(".relocate")) && listentry.ErrorCode == ErrorCode.Success) // TODO: Move these to an array? { // Write code line tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed) tsb.WriteAt(maxLength, "[0x" + LongHex(listentry.Address) + "] "); else tsb.WriteAt(maxLength, "[NOLIST] "); tsb.WriteAt(maxLength + 25, listentry.Code); listing += tsb.Value + "\n"; // Write data for (int i = 0; i < listentry.Output.Length; i += 8) { tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed) tsb.WriteAt(maxLength, "[0x" + LongHex((ushort)(listentry.Address + i)) + "] "); else tsb.WriteAt(maxLength, "[NOLIST] "); string data = ""; for (int j = 0; j < 8 && i + j < listentry.Output.Length; j++) { data += LongHex(listentry.Output[i + j]) + " "; } tsb.WriteAt(maxLength + 30, data.Remove(data.Length - 1)); listing += tsb.Value + "\n"; } } else { if (listentry.ErrorCode != ErrorCode.Success) { tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed) tsb.WriteAt(maxLength, "[0x" + LongHex(listentry.Address) + "] "); else tsb.WriteAt(maxLength, "[NOLIST] "); tsb.WriteAt(maxLength + 8, "ERROR: " + ListEntry.GetFriendlyErrorMessage(listentry.ErrorCode)); listing += tsb.Value + "\n"; } if (listentry.WarningCode != WarningCode.None) { tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed) tsb.WriteAt(maxLength, "[0x" + LongHex(listentry.Address) + "] "); else tsb.WriteAt(maxLength, "[NOLIST] "); tsb.WriteAt(maxLength + 8, "WARNING: " + ListEntry.GetFriendlyWarningMessage(listentry.WarningCode)); listing += tsb.Value + "\n"; } tsb = new TabifiedStringBuilder(); tsb.WriteAt(0, listentry.FileName); tsb.WriteAt(maxFileLength, "(line " + listentry.LineNumber + "): "); if (listentry.Listed) tsb.WriteAt(maxLength, "[0x" + LongHex(listentry.Address) + "] "); else tsb.WriteAt(maxLength, "[NOLIST] "); if (listentry.Output != null) { if (listentry.Output.Length > 0) { tsb.WriteAt(maxLength + 8, DumpArray(listentry.Output)); tsb.WriteAt(maxLength + 25, listentry.Code); } } else tsb.WriteAt(maxLength + 23, listentry.Code); listing += tsb.Value + "\n"; } } return listing; }
void assembler_AssemblyComplete(object sender, AssemblyCompleteEventArgs e) { // uploads a .dat file if (!upload || e.Output.Count == 0) return; Console.WriteLine("Uploading output to 0x10co.de..."); string oldFile = e.Output[0].FileName; string code = "; =====Begin file: " + oldFile + "\n"; // Get longest dat entry int maxLength = 0; foreach (var entry in e.Output) { if (!entry.Listed) continue; if (entry.Output != null) { if (entry.Output.Length != 0) { string dat = "dat "; foreach (ushort value in entry.Output) dat += "0x" + value.ToString("x") + ","; dat = dat.Remove(dat.Length - 1); if (dat.Length > maxLength && dat.Length < 30) maxLength = dat.Length; } } } foreach (var entry in e.Output) { if (!entry.Listed) continue; if (entry.FileName != oldFile) { code += "; =====Begin file: " + entry.FileName + "\n"; oldFile = entry.FileName; } if (entry.ErrorCode != ErrorCode.Success) code += "; ERROR: " + ListEntry.GetFriendlyErrorMessage(entry.ErrorCode) + "\n"; if (entry.WarningCode != WarningCode.None) code += "; WARNING: " + ListEntry.GetFriendlyWarningMessage(entry.WarningCode) + "\n"; if (entry.Output == null) code += "; " + entry.Code + " (line " + entry.LineNumber + ")" + "\n"; else { if (entry.Output.Length != 0) { TabifiedStringBuilder tsb = new TabifiedStringBuilder(); string dat = "dat "; foreach (ushort value in entry.Output) dat += "0x" + value.ToString("x") + ","; dat = dat.Remove(dat.Length - 1); tsb.WriteAt(0, dat); tsb.WriteAt(maxLength, "; " + entry.Code); code += tsb.Value + "\n"; } } } HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(new Uri("http://0x10co.de")); hwr.ContentType = "application/x-www-form-urlencoded"; hwr.Method = "POST"; string encodedCode = ""; while (code.Length != 0) { if (code.Length > 10000) { encodedCode += Uri.EscapeDataString(code.Remove(10000)); code = code.Substring(10000); } else { encodedCode += Uri.EscapeDataString(code); code = ""; } } string postData = "title=" + Uri.EscapeDataString(e.Output.First().FileName) + "&author=&description=Created+by+the+0x10co.de+Organic+plugin&password=&code=" + encodedCode; byte[] data = Encoding.ASCII.GetBytes(postData); hwr.ContentLength = data.Length; Stream s = hwr.GetRequestStream(); s.Write(data, 0, data.Length); s.Close(); HttpWebResponse resp = (HttpWebResponse)hwr.GetResponse(); s = resp.GetResponseStream(); MemoryStream ms = new MemoryStream(); int b = 0; while ((b = s.ReadByte()) != -1) ms.WriteByte((byte)b); string url = Encoding.ASCII.GetString(ms.GetBuffer()).Trim(' ', '\t', '\0'); Console.WriteLine("Uploaded to http://0x10co.de" + url + ". This URL has been copied to the clipboard."); Clipboard.SetText("http://0x10co.de" + url); }