Something went wrong. Try again.
A OS written in C# and COSMOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;
namespace openPrism{ public class CommandManager { private readonly List<Command> commands; private readonly Dictionary<string, string> aliases = new Dictionary<string, string>();
public CommandManager() { commands = new List<Command> { new Core.UOP.WhoamI(), new Core.Sys.Version(), new Core.RTC.Time(), new Core.Power.Shutdown(), new Core.Power.Reboot(), new FS.Disks.Disks(), new FS.Disks.Format(), new FS.UF.Cd(), new FS.UF.Mkdir(), new FS.UF.Ls(), new FS.Sys.Free(), new Shell.Utils.Clear(), new Shell.Utils.Color(), new FS.UF.Mkfil(), new FS.UF.Mkfil("touch"), new FS.UF.Readf(), new FS.UF.Readf("cat"), new Shell.Base.Echo(), new Core.Keymap.Kbd(), new FS.UF.Rmdir(), new FS.UF.Rmdir("deldir"), new FS.UF.Delf(), new FS.UF.Delf("rm"), new FS.UF.Delf("rmf"), new FS.FOP.Appf(), new FS.FOP.Writef(), new FS.FOP.Nl(), new FS.FOP.Rml(), new FS.FOP.Rpt(), new FS.FOP.Rmt(), new FS.FOP.Rmtl(), new Qute.Qute(), new Shell.Utils.Alias(this), new FS.UF.Mv(), new FS.UF.Cp() }; } public void AddAlias(string name, string command) { if (aliases.ContainsKey(name)) { aliases[name] = command; } else { aliases.Add(name, command); } }
public void ProcInput(string input) { if (string.IsNullOrWhiteSpace(input)) return;
var argsList = new List<string>(); bool inQuotes = false; StringBuilder currArg = new StringBuilder();
foreach (char c in input) { if (c == '\"') { inQuotes = !inQuotes; } else if (c == ' ' && !inQuotes) { if (currArg.Length > 0) { argsList.Add(currArg.ToString()); currArg.Clear(); } } else { currArg.Append(c); } } if (currArg.Length > 0) argsList.Add(currArg.ToString());
string[] args = argsList.ToArray(); string origcmd = args[0].ToLower();
if (aliases.ContainsKey(origcmd)) { string full = aliases[origcmd]; ProcInput(full); return; }
foreach (var cmd in commands) { if (cmd.Name == origcmd) { cmd.Execute(args); return; } }
Console.WriteLine($"sush: command {origcmd} not found"); } }}