// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Data; namespace Spludlow { public class ASCII { private static string TableFilename = Spludlow.Config.ProgramData + @"\Data\ASCII.txt"; public static DataTable Table = null; static ASCII() { if (File.Exists(TableFilename) == true) { Table = Spludlow.Data.TextTable.ReadFile(TableFilename); } } public static void MakeTable() { // ASCIINames.txt from http://ascii-code.com/ // Need to fix row 127 DEL  Delete // Blank out all names except control; <32 =127 // and Tidy up few descriptions // Id Name Number HTML Description // The GBP sign has number 163 in ISO-8859-1 (Latin-1) and Unicode // GBP sign number is 156 in "Code page 437" (DOS) DataTable namesTable = Spludlow.Data.TextTable.ReadFile(Spludlow.Config.ProgramData + @"\Data\ASCIINames.txt"); DataTable table = Spludlow.Data.TextTable.ReadText(new string[] { "CharId CharName CharDesc Printable HTML CharValue StringValue", "Int32* String String Boolean String Char String", }); Spludlow.Data.TextTable.Write(TableFilename, table); byte[] newLine = Encoding.ASCII.GetBytes(Environment.NewLine); byte[] tab = Encoding.ASCII.GetBytes("\t"); using (FileStream stream = new FileStream(TableFilename, FileMode.Append)) { for (int id = 0; id < 256; ++id) { DataRow nameRow = namesTable.Rows.Find(id); bool printable = true; string charName = ""; string charDesc = ""; if (id < 32 || id == 127) { printable = false; charName = (string)nameRow["Name"]; charDesc = (string)nameRow["Description"]; } if (printable == true && nameRow.IsNull("Number") == true) printable = false; string html = ""; if (nameRow.IsNull("HTML") == false) html = (string)nameRow["HTML"]; byte[] buffer; buffer = Encoding.ASCII.GetBytes(id.ToString()); stream.Write(buffer, 0, buffer.Length); stream.Write(tab, 0, tab.Length); buffer = Encoding.ASCII.GetBytes(charName); stream.Write(buffer, 0, buffer.Length); stream.Write(tab, 0, tab.Length); buffer = Encoding.ASCII.GetBytes(charDesc); stream.Write(buffer, 0, buffer.Length); stream.Write(tab, 0, tab.Length); buffer = Encoding.ASCII.GetBytes(printable.ToString()); stream.Write(buffer, 0, buffer.Length); stream.Write(tab, 0, tab.Length); buffer = Encoding.ASCII.GetBytes(html); stream.Write(buffer, 0, buffer.Length); stream.Write(tab, 0, tab.Length); if (printable == true) { buffer = new byte[1]; buffer[0] = (byte)id; } else { buffer = new byte[0]; } stream.Write(buffer, 0, buffer.Length); stream.Write(tab, 0, tab.Length); stream.Write(buffer, 0, buffer.Length); stream.Write(newLine, 0, newLine.Length); } } } } }