From 290a5e6b6447af5a719e26e6eb55d9b674cf662c Mon Sep 17 00:00:00 2001 From: moosecrab Date: Sun, 29 May 2022 02:29:46 -0700 Subject: [PATCH] Add project files. --- mfs/Program.cs | 10 +++++ mfs/TLGDatabase.cs | 99 ++++++++++++++++++++++++++++++++++++++++++++++ mfs/mfs.csproj | 10 +++++ mfs2022.sln | 25 ++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 mfs/Program.cs create mode 100644 mfs/TLGDatabase.cs create mode 100644 mfs/mfs.csproj create mode 100644 mfs2022.sln diff --git a/mfs/Program.cs b/mfs/Program.cs new file mode 100644 index 0000000..c5e2e2b --- /dev/null +++ b/mfs/Program.cs @@ -0,0 +1,10 @@ +using System; + +namespace mfs +{ + internal class Program { + static void Main(string[] args) { + TLGDatabase testdb = new("aero\\Master Files\\Stratolaunch_CA_AllTables_Master_RevL.dat"); + } + } +} \ No newline at end of file diff --git a/mfs/TLGDatabase.cs b/mfs/TLGDatabase.cs new file mode 100644 index 0000000..1b2808f --- /dev/null +++ b/mfs/TLGDatabase.cs @@ -0,0 +1,99 @@ +namespace mfs { + internal class TLGDatabase { + private enum block_types { + NONE, + REFERENCE_DATA, + BASIC_TABLE, + INCREMENT_TABLE, + DERIVATIVE_TABLE, + } ; + private block_types currentblock = block_types.NONE; + + public Dictionary reference_values = new Dictionary(); + + public TLGDatabase(string path) { + readfile(path); + } + + private void readfile(string path) { + StreamReader fs = File.OpenText(path); + string line = ""; + + while (!fs.EndOfStream) { + line = fs.ReadLine(); + if (line == null) { + line = ""; + } + if (string.IsNullOrWhiteSpace(line) || (line[0] == '%')) { + // lines starting with % are comment lines and ignored + // blank or whitespace lines also ignored + } else if (line == "END BLOCK") { + currentblock = block_types.NONE; + + } else { + switch (currentblock) { + + case block_types.NONE: + // look for data blocks, or an include line + switch (line) { + case "BEGIN REFERENCE DATA BLOCK": + currentblock = block_types.REFERENCE_DATA; + break; + case "BEGIN BASIC TABLE BLOCK": + currentblock = block_types.BASIC_TABLE; + break; + case "BEGIN INCREMENT TABLE BLOCK": + currentblock = block_types.INCREMENT_TABLE; + break; + case "BEGIN DERIVATIVE TABLE BLOCK": + currentblock = block_types.DERIVATIVE_TABLE; + break; + } + + if (line.StartsWith("INCLUDE,", StringComparison.InvariantCultureIgnoreCase)) { + string includepath = line.Substring(8).Trim(); + if (File.Exists(includepath)) { + readfile(includepath); + } else { + throw new Exception("Could not find included file " + includepath); + } + } + break; + + case block_types.REFERENCE_DATA: + string[] splitline = line.Split(',', StringSplitOptions.TrimEntries & StringSplitOptions.RemoveEmptyEntries); + if (splitline.Length != 2) { + throw new Exception("Error parsing reference parameter " + splitline[0]); + } else { + double val = double.NaN; + if (double.TryParse(splitline[1], out val)) { + reference_values.Add(splitline[0], val); + } else { + throw new Exception("Could not parse reference parameter " + splitline[0]); + } + + } + break; + + case block_types.BASIC_TABLE: + break; + + case block_types.INCREMENT_TABLE: + break; + + case block_types.DERIVATIVE_TABLE: + break; + + default: + break; + } + } + } + if (currentblock != block_types.NONE) { + throw new Exception("End of file encountered inside a block"); + } + + fs.Close(); + } + } +} diff --git a/mfs/mfs.csproj b/mfs/mfs.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/mfs/mfs.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/mfs2022.sln b/mfs2022.sln new file mode 100644 index 0000000..c3179ff --- /dev/null +++ b/mfs2022.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32519.379 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mfs", "mfs\mfs.csproj", "{CF0AB839-D840-4F7F-A4F1-87B3A216C764}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CF0AB839-D840-4F7F-A4F1-87B3A216C764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF0AB839-D840-4F7F-A4F1-87B3A216C764}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF0AB839-D840-4F7F-A4F1-87B3A216C764}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF0AB839-D840-4F7F-A4F1-87B3A216C764}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {80A68656-006C-412E-931E-D1F282DFA9F4} + EndGlobalSection +EndGlobal