Copyright waiver under the Unlicense with BSD 3-Clause fallback.

This commit is contained in:
Tony Bark 2023-01-07 11:44:50 -05:00
parent dc2176b26d
commit 2794aa17f4
24 changed files with 572 additions and 473 deletions

View file

@ -1,3 +1,9 @@
/*
In jurisdictions that recognize copyright waivers, I've waived all copyright
and related or neighboring rights for to this project. In areas where these
waivers are not recognized, BSD-3-Clause is enforced.
See the (UN)LICENSE file in the project root for more information.
*/
global using System.Diagnostics.CodeAnalysis;
global using System.Diagnostics;
global using Tomas.Common.Programs;

View file

@ -1,40 +1,43 @@
// I license this project under the BSD 3-Clause license.
// See the LICENSE file in the project root for more information.
/*
In jurisdictions that recognize copyright waivers, I've waived all copyright
and related or neighboring rights for to this project. In areas where these
waivers are not recognized, BSD-3-Clause is enforced.
See the (UN)LICENSE file in the project root for more information.
*/
namespace Tomas.Terminal;
class Program
{
static void Main()
static void Main()
{
while (true)
{
var shell = new Shell();
var command = shell.ReadLine;
var programs = shell.Programs;
if (!programs.TryGetValue(command, out var program))
{
Console.WriteLine("Command Not Found.");
continue;
}
try
{
var start = program.Run(shell);
switch (start)
{
while (true)
{
var shell = new Shell();
var command = shell.ReadLine;
var programs = shell.Programs;
if (!programs.TryGetValue(command, out var program))
{
Console.WriteLine("Command Not Found.");
continue;
}
try
{
var start = program.Run(shell);
switch (start)
{
case true:
continue;
case false:
Console.WriteLine("Program closed unexpectedly.");
continue;
}
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
}
case true:
continue;
case false:
Console.WriteLine("Program closed unexpectedly.");
continue;
}
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
}
}
}

View file

@ -1,14 +1,16 @@
// I license this project under the BSD 3-Clause license.
// See the LICENSE file in the project root for more information.
using Tomas.Common;
/*
In jurisdictions that recognize copyright waivers, I've waived all copyright
and related or neighboring rights for to this project. In areas where these
waivers are not recognized, BSD-3-Clause is enforced.
See the (UN)LICENSE file in the project root for more information.
*/
namespace Tomas.Terminal.Programs;
public class About : IProgram
{
public bool Run(IShell shell)
{
Console.WriteLine($"{TermMeta.NAME} Terminal Emulator v{TermMeta.VERSION}");
return true;
}
public bool Run(IShell shell)
{
Console.WriteLine($"{TermMeta.NAME} Terminal Emulator v{TermMeta.VERSION}");
return true;
}
}

View file

@ -1,14 +1,18 @@
// I license this project under the BSD 3-Clause license.
// See the LICENSE file in the project root for more information.
/*
In jurisdictions that recognize copyright waivers, I've waived all copyright
and related or neighboring rights for to this project. In areas where these
waivers are not recognized, BSD-3-Clause is enforced.
See the (UN)LICENSE file in the project root for more information.
*/
using Tomas.Terminal.Programs;
namespace Tomas.Terminal;
public class Shell : IShell
{
const char SYMBOL = '$';
const char SYMBOL = '$';
public Dictionary<string, IProgram> Programs => new()
public Dictionary<string, IProgram> Programs => new()
{
{"about", new About()},
{"fensay", new FenSay()},
@ -16,13 +20,13 @@ public class Shell : IShell
{"commands", new Commands()}
};
public string ReadLine
{
get
{
Console.Write(SYMBOL);
var readl = Console.ReadLine();
return readl;
}
}
public string ReadLine
{
get
{
Console.Write(SYMBOL);
var readl = Console.ReadLine();
return readl;
}
}
}

View file

@ -1,48 +1,52 @@
// I license this project under the BSD 3-Clause license.
// See the LICENSE file in the project root for more information.
/*
In jurisdictions that recognize copyright waivers, I've waived all copyright
and related or neighboring rights for to this project. In areas where these
waivers are not recognized, BSD-3-Clause is enforced.
See the (UN)LICENSE file in the project root for more information.
*/
using System.Text;
namespace Tomas.Common;
namespace Tomas.Terminal;
/// <summary>
/// System metdata, such as name, version and build number.
/// </summary>
public struct TermMeta
{
/// <summary>
/// The name of the operating system.
/// </summary>
public const string NAME = "TOMAS Emulator";
/// <summary>
/// The name of the operating system.
/// </summary>
public const string NAME = "TOMAS Emulator";
/// <summary>
/// The version of the operating system, in the Calendar Versioning format: "yy.minor.patch".
/// The year, minor, and patch version numbers are automatically extracted from the Git repository
/// using the ThisAssembly.Git.SemVer object.
/// </summary>
public const string VERSION = $"{ThisAssembly.Git.SemVer.Major}.{ThisAssembly.Git.SemVer.Minor}.{ThisAssembly.Git.SemVer.Patch}";
/// <summary>
/// The version of the operating system, in the Calendar Versioning format: "yy.minor.patch".
/// The year, minor, and patch version numbers are automatically extracted from the Git repository
/// using the ThisAssembly.Git.SemVer object.
/// </summary>
public const string VERSION = $"{ThisAssembly.Git.SemVer.Major}.{ThisAssembly.Git.SemVer.Minor}.{ThisAssembly.Git.SemVer.Patch}";
/// <summary>
/// The build number of the operating system, generated from the commit hash.
/// The build number is a 6-digit number, with the first 3 digits being the first 3 digits of the commit hash
/// converted to a uint, and the last 3 digits being the last 3 digits of the commit hash converted to a uint.
/// </summary>
public static string BuildNumber = $"Build {BuildNumFromCommit}";
/// <summary>
/// The build number of the operating system, generated from the commit hash.
/// The build number is a 6-digit number, with the first 3 digits being the first 3 digits of the commit hash
/// converted to a uint, and the last 3 digits being the last 3 digits of the commit hash converted to a uint.
/// </summary>
public static string BuildNumber = $"Build {BuildNumFromCommit}";
/// <summary>
/// Generates the build number from the commit hash.
/// </summary>
/// <returns>The build number as a uint.</returns>
static uint BuildNumFromCommit
{
get
{
// Get the bytes of the commit hash as a UTF-8 encoded string
var commit = Encoding.UTF8.GetBytes(ThisAssembly.Git.Commit);
/// <summary>
/// Generates the build number from the commit hash.
/// </summary>
/// <returns>The build number as a uint.</returns>
static uint BuildNumFromCommit
{
get
{
// Get the bytes of the commit hash as a UTF-8 encoded string
var commit = Encoding.UTF8.GetBytes(ThisAssembly.Git.Commit);
// Convert the first 4 bytes of the commit hash to a uint and return it modulo 1000000
// (this will give us a 6-digit number with the first 3 digits being the first 3 digits of the commit hash
// and the last 3 digits being the last 3 digits of the commit hash)
return BitConverter.ToUInt32(commit, 0) % 1000000;
}
}
// Convert the first 4 bytes of the commit hash to a uint and return it modulo 1000000
// (this will give us a 6-digit number with the first 3 digits being the first 3 digits of the commit hash
// and the last 3 digits being the last 3 digits of the commit hash)
return BitConverter.ToUInt32(commit, 0) % 1000000;
}
}
}