Branswe更新&环境变量

This commit is contained in:
2026-02-01 18:05:54 +08:00
parent 3fb0697045
commit 17aac021e3
5 changed files with 625 additions and 404 deletions

View File

@@ -18,20 +18,20 @@ using Console = System.Console;
using Sys = Cosmos.System;
public static class Branswe
//Branswe<77><65>ѭMIT<49><54><EFBFBD><EFBFBD>֤<EFBFBD><D6A4>
{
private static string varlib = "";
private static string geted = "";
private static string runlib = "";
private static string methods = "";
public static void Run(string Code)
{
//<2F><>ʼ<EFBFBD><CABC>
string[] codelines = Code.Split("\n");
int Codelength = codelines.Length;
long Codelength = codelines.Length;
for (int coderun = 0; coderun < Codelength; coderun++)
for (long coderun = 0; coderun < Codelength; coderun++)
{
string line = codelines[coderun];
@@ -45,23 +45,114 @@ public static class Branswe
switch (line.Split(" ")[0])
{
case "method":
// 与CMLeonOS不兼容删除此功能
Console.WriteLine("Error: method command is not compatible with CMLeonOS");
break;
{
string rest = line.Substring(6).Trim();
int arrowIndex = rest.IndexOf("<<");
string varPart = rest.Substring(0, arrowIndex).Trim();
string codePart = rest.Substring(arrowIndex + 2).Trim();
// <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD> varPart <20>DZ<EFBFBD><C7B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ֵ
if (!varPart.Contains(" "))
{
Branswe.Run("ref getvar " + varPart);
if (!string.IsNullOrEmpty(geted)) varPart = geted;
}
// <20><><EFBFBD> codePart <20>DZ<EFBFBD><C7B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ֵ
if (!codePart.Contains(" "))
{
Branswe.Run("ref getvar " + codePart);
if (!string.IsNullOrEmpty(geted)) codePart = geted;
}
methods += "\uE001" + varPart + "\uE002" + codePart;
break;
}
case "diskfile":
// 与CMLeonOS不兼容删除此功能
Console.WriteLine("Error: diskfile command is not compatible with CMLeonOS");
{
switch (line.Split(" ")[1])
{
/*case "read":
{
Branswe.Run("ref getvar " + line.Split(" ", 5)[2]);
var get0 = geted;
switch (line.Split(" ")[3])
{
case "to":
{
Branswe.Run("ref getvar " + line.Split(" ", 5)[4]);
var get1 = geted;
Branswe.Run("var(text) " + get1 + " = " + VFSManager.GetFile(get0));
break;
}
}
break;
}*/
case "reg":
{
VFSBase vfs = new CosmosVFS();
VFSManager.RegisterVFS(vfs);
break;
}
case "create":
{
switch (line.Split(" ")[2])
{
case "file":
{
Branswe.Run("ref getvar " + line.Split(" ", 4)[3]);
var get = geted;
VFSManager.CreateFile(get);
break;
}
case "dir":
{
Branswe.Run("ref getvar " + line.Split(" ", 4)[3]);
var get = geted;
VFSManager.CreateDirectory(get);
break;
}
}
break;
}
case "write":
{
Branswe.Run("ref getvar " + line.Split(" ", 5)[2]);
var get0 = geted;
switch (line.Split(" ", 5)[3])
{
case "to":
{
Branswe.Run("ref getvar " + line.Split(" ", 5)[4]);
var get1 = geted;
File.WriteAllText(get0, get1);
break;
}
}
}
break;
}
}
break;
case "rstr": //rstr=Read String To Run
// 与CMLeonOS不兼容删除此功能
Console.WriteLine("Error: rstr command is not compatible with CMLeonOS");
break;
{
var parts = line.Split(" ", 2);
Branswe.Run("ref getvar " + parts[1]);
var code = geted;
for (long i = 0; i < code.Split("\\n").Length; i++)
{
Branswe.Run(code.Split("\\n")[i]);
}
break;
}
case "var()":
{
var parts = line.Split(" ", 4);
@@ -92,40 +183,40 @@ public static class Branswe
case "=+":
{
Branswe.Run("ref getvar " + parts[1]);
int wc0 = int.Parse(geted);
long wc0 = long.Parse(geted);
Branswe.Run("ref getvar " + parts[3]);
int wc1 = int.Parse(geted);
int calced = wc0 + wc1;
long wc1 = long.Parse(geted);
long calced = wc0 + wc1;
Branswe.Run("var(text) " + parts[1] + " = " + calced);
break;
}
case "=-":
{
Branswe.Run("ref getvar " + parts[1]);
int wc0 = int.Parse(geted);
long wc0 = long.Parse(geted);
Branswe.Run("ref getvar " + parts[3]);
int wc1 = int.Parse(geted);
int calced = wc0 - wc1;
long wc1 = long.Parse(geted);
long calced = wc0 - wc1;
Branswe.Run("var(text) " + parts[1] + " = " + calced);
break;
}
case "=*":
{
Branswe.Run("ref getvar " + parts[1]);
int wc0 = int.Parse(geted);
long wc0 = long.Parse(geted);
Branswe.Run("ref getvar " + parts[3]);
int wc1 = int.Parse(geted);
int calced = wc0 * wc1;
long wc1 = long.Parse(geted);
long calced = wc0 * wc1;
Branswe.Run("var(text) " + parts[1] + " = " + calced);
break;
}
case "=/":
{
Branswe.Run("ref getvar " + parts[1]);
int wc0 = int.Parse(geted);
long wc0 = long.Parse(geted);
Branswe.Run("ref getvar " + parts[3]);
int wc1 = int.Parse(geted);
int calced = wc0 / wc1;
long wc1 = long.Parse(geted);
long calced = wc0 / wc1;
Branswe.Run("var(text) " + parts[1] + " = " + calced);
break;
}
@@ -170,63 +261,35 @@ public static class Branswe
switch (parts[1])
{
case "mousex":
// 与CMLeonOS不兼容删除此功能
Console.WriteLine("Error: mousex command is not compatible with CMLeonOS");
break;
case "mousey":
// 与CMLeonOS不兼容删除此功能
Console.WriteLine("Error: mousey command is not compatible with CMLeonOS");
break;
case "screenx":
// 与CMLeonOS不兼容删除此功能
Console.WriteLine("Error: screenx command is not compatible with CMLeonOS");
break;
case "screeny":
// 与CMLeonOS不兼容删除此功能
Console.WriteLine("Error: screeny command is not compatible with CMLeonOS");
break;
case "concolour-b":
// 与CMLeonOS不兼容删除此功能
Console.WriteLine("Error: concolour-b command is not compatible with CMLeonOS");
break;
case "concolour-f":
// 与CMLeonOS不兼容删除此功能
Console.WriteLine("Error: concolour-f command is not compatible with CMLeonOS");
break;
Branswe.Run("var(text) [] = " + MouseManager.X);
break;
case "mousey":
Branswe.Run("var(text) [] = " + MouseManager.Y);
break;
case "screenx":
Branswe.Run("var(text) [] = " + Console.WindowWidth);
break;
case "screeny":
Branswe.Run("var(text) [] = " + Console.WindowHeight);
break;
case "concolour-b":
Branswe.Run("var(text) [] = " + Console.BackgroundColor);
break;
case "concolour-f":
Branswe.Run("var(text) [] = " + Console.ForegroundColor);
break;
case "getalldisks":
{
Branswe.Run("var(text) [] = " + VFSManager.GetDisks().ToArray());
break;
}
case "to":
{
switch (parts[2])
{
case "raw":
{
Branswe.Run("ref getvar " + parts[3]);
Branswe.Run("var(text) [] = " + byte.Parse(geted).ToString());
break;
}
/*case "int":
{
int.Parse(parts[3]);
break;
}
case "long":
{
long.Parse(parts[3]);
break;
}
case "decimal":
{
decimal.Parse(parts[3]);
break;
}*/
}
break;
}
case "getvar":
{
@@ -277,14 +340,9 @@ public static class Branswe
case "sleep":
{
Branswe.Run("ref getvar " + line.Split(" ")[1]);
Thread.Sleep(TimeSpan.FromMilliseconds(long.Parse(geted)));//<2F><><EFBFBD><EFBFBD>C# Threading<6E><67>Sleep
Thread.Sleep(TimeSpan.FromMilliseconds(long.Parse(geted))); //<2F><><EFBFBD><EFBFBD>C# Threading<6E><67>Sleep
break;
}
/*case "if":
{
if ()
break;
}*/
case "loop":
{
var parts = line.Split(" ");
@@ -297,22 +355,31 @@ public static class Branswe
}
break;
}
case "canvas":
// 与CMLeonOS不兼容删除此功能
Console.WriteLine("Error: canvas command is not compatible with CMLeonOS");
break;
case "end":
{
throw new Exception("\uE001");
}
/*case "graphics":
// 与CMLeonOS不兼容删除此功能
Console.WriteLine("Error: graphics command is not compatible with CMLeonOS");
break;*/
case "power":
// 与CMLeonOS不兼容删除此功能
Console.WriteLine("Error: power command is not compatible with CMLeonOS");
break;
{
switch (line.Split(" ")[1])
{
case "off":
{
ACPI.Shutdown();
CPU.Halt();
break;
}
case "reboot":
{
ACPI.Reboot();
CPU.Reboot();
break;
}
}
break;
}
case "decide":
{
var parts = line.Split(" ");
@@ -445,57 +512,37 @@ public static class Branswe
Console.Clear();
break;
}
/*case "conchange":
{
switch (line.Split(" ")[1])
{
case "bgcolor":
{
Console.BackgroundColor = Color.FromArgb(int.Parse(line.Split(" ")[2]));
break;
}
}
}*/
default:
{
var methodEntries = methods.Split('\uE001', StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < methodEntries.Length; i++)
for (long i = 0; i < methodEntries.Length; i++)
{
var parts = methodEntries[i].Split('\uE002');
if (parts.Length < 2) continue;
string varPart = parts[0].Trim(); // "a c b"
string codeTemplate = parts[1].Trim(); // "d"
string varPart = parts[0]; //keep spaces as is
string codeTemplate = parts[1]; //keep spaces
// 1. <20>ƶϷ<C6B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> varPart <20>ĵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var firstToken = varPart.Split(' ')[0];
Branswe.Run("ref getvar " + firstToken);
string methodName = geted.TrimEnd('(').Trim(); // "print(" <20><> "print"
string methodName = geted; //no .TrimEnd('(').Trim()
// 2. <20><><EFBFBD><EFBFBD>Ƿ<EFBFBD>ƥ<EFBFBD><C6A5>
if (line.StartsWith(methodName))
{
// 3. <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
string args = line.Substring(methodName.Length).Trim();
if (args.StartsWith("(") && args.EndsWith(")"))
{
args = args.Substring(1, args.Length - 2);
}
string args = line.Substring(methodName.Length); //keep spaces
Branswe.Run("ref getvar " + args);
string argValue = geted; //value may contain spaces
// 4. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>մ<EFBFBD><D5B4><EFBFBD>
string finalCode = codeTemplate;
var varTokens = varPart.Split(' ', StringSplitOptions.RemoveEmptyEntries);
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int j = 1; j < varTokens.Length; j++) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (long j = 1; j < varTokens.Length; j++)
{
var token = varTokens[j];
if (token == "[]")
{
// varPart <20>е<EFBFBD> [] <20>Ѿ<EFBFBD><D1BE><EFBFBD> args ʹ<><CAB9><EFBFBD><EFBFBD>
// codeTemplate <20>п<EFBFBD><D0BF><EFBFBD>Ҳ<EFBFBD><D2B2> []<5D><><EFBFBD><EFBFBD>Ҫ<EFBFBD>
finalCode = finalCode.Replace("[]", args);
finalCode = finalCode.Replace("[]", argValue);
}
else
{
@@ -504,179 +551,12 @@ public static class Branswe
}
}
// 5. ִ<><D6B4>
Branswe.Run(finalCode);
return;
break;
}
}
// û<><C3BB>ƥ<EFBFBD><C6A5>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>ִ<EFBFBD><D6B4>
Branswe.Run(line);
break;
}
case "cat":
{
// 与CMLeonOS兼容支持cat命令
var parts = line.Split(" ", 2);
if (parts.Length < 2)
{
Console.WriteLine("Error: Please specify file name");
Console.WriteLine("Usage: cat <filename>");
break;
}
string filePath = parts[1];
if (!File.Exists(filePath))
{
Console.WriteLine($"Error: File not found: {filePath}");
break;
}
try
{
string content = File.ReadAllText(filePath);
Console.WriteLine(content);
}
catch (Exception ex)
{
Console.WriteLine($"Error reading file: {ex.Message}");
}
break;
}
case "echo":
{
// 与CMLeonOS兼容支持echo命令
var parts = line.Split(" ", 2);
if (parts.Length < 2)
{
Console.WriteLine("Error: Please specify text");
Console.WriteLine("Usage: echo <text>");
break;
}
try
{
File.WriteAllText(parts[1], parts[0]);
Console.WriteLine("Text written successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error writing file: {ex.Message}");
}
break;
}
case "ls":
{
// 与CMLeonOS兼容支持ls命令
var parts = line.Split(" ", 2);
string dirPath = parts.Length >= 2 ? parts[1] : "";
try
{
if (Directory.Exists(dirPath))
{
var files = Directory.GetFiles(dirPath);
var dirs = Directory.GetDirectories(dirPath);
foreach (var file in files)
{
Console.WriteLine($" {file}");
}
foreach (var dir in dirs)
{
Console.WriteLine($" [{dir}]/");
}
}
else
{
Console.WriteLine($"Error: Directory not found: {dirPath}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error listing directory: {ex.Message}");
}
break;
}
case "pwd":
{
// 与CMLeonOS兼容支持pwd命令
Console.WriteLine("0:\\");
break;
}
case "mkdir":
{
// 与CMLeonOS兼容支持mkdir命令
var parts = line.Split(" ", 2);
if (parts.Length < 2)
{
Console.WriteLine("Error: Please specify directory name");
Console.WriteLine("Usage: mkdir <dirname>");
break;
}
try
{
Directory.CreateDirectory(parts[1]);
Console.WriteLine($"Directory created: {parts[1]}");
}
catch (Exception ex)
{
Console.WriteLine($"Error creating directory: {ex.Message}");
}
break;
}
case "rm":
{
// 与CMLeonOS兼容支持rm命令
var parts = line.Split(" ", 2);
if (parts.Length < 2)
{
Console.WriteLine("Error: Please specify file name");
Console.WriteLine("Usage: rm <filename>");
break;
}
string filePath = parts[1];
try
{
File.Delete(filePath);
Console.WriteLine($"File deleted: {filePath}");
}
catch (Exception ex)
{
Console.WriteLine($"Error deleting file: {ex.Message}");
}
break;
}
case "rmdir":
{
// 与CMLeonOS兼容支持rmdir命令
var parts = line.Split(" ", 2);
if (parts.Length < 2)
{
Console.WriteLine("Error: Please specify directory name");
Console.WriteLine("Usage: rmdir <dirname>");
break;
}
try
{
Directory.Delete(parts[1]);
Console.WriteLine($"Directory deleted: {parts[1]}");
}
catch (Exception ex)
{
Console.WriteLine($"Error deleting directory: {ex.Message}");
}
break;
}
// default:
// {
// // û<><C3BB>ƥ<EFBFBD><C6A5>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>ִ<EFBFBD><D6B4>
// Branswe.Run(line);
// break;
// }
}
}
}