mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-04 09:06:41 +02:00
Refactor argument handling in ExecuteProgramWithArgs for clarity
This commit is contained in:
@@ -18,35 +18,36 @@ internal class SystemStatements : StatementRuntimeInformation
|
|||||||
public void ExecuteProgramWithArgs(string input)
|
public void ExecuteProgramWithArgs(string input)
|
||||||
{
|
{
|
||||||
string[] parts = input.FromSafeString().Split(" with ", 2, StringSplitOptions.None);
|
string[] parts = input.FromSafeString().Split(" with ", 2, StringSplitOptions.None);
|
||||||
parts[0] = parts[0].Trim();
|
string program = parts[0].Trim();
|
||||||
|
|
||||||
string[] functionArguments = parts[1].Split(',');
|
foreach (string argument in parts[1].Split(','))
|
||||||
|
|
||||||
foreach (string argument in functionArguments)
|
|
||||||
{
|
{
|
||||||
RuntimeInfo.InParametersStack.Push(argument.Trim());
|
RuntimeInfo.InParametersStack.Push(argument.Trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StartProcess(parts[0], string.Join(" ", RuntimeInfo.InParametersStack.Reverse()));
|
StartProcess(program, string.Join(" ", RuntimeInfo.InParametersStack.Reverse()));
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
RuntimeInfo.Exit(ExitMessages.CannotFindFile(parts[0]), false);
|
RuntimeInfo.Exit(ExitMessages.CannotFindFile(program), false);
|
||||||
}
|
}
|
||||||
catch (Win32Exception ex)
|
catch (Win32Exception ex)
|
||||||
{
|
{
|
||||||
RuntimeInfo.Exit(ExitMessages.FailedToStart(parts[0], ex.Message), false);
|
RuntimeInfo.Exit(ExitMessages.FailedToStart(program, ex.Message), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK: Clear line to avoid execution from another "exec" statement.
|
|
||||||
RuntimeInfo.CurrentLine = string.Empty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Statement("exec", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Magenta, Priority = Priority.VeryLow)]
|
[Statement("exec", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Magenta, Priority = Priority.VeryLow)]
|
||||||
public void ExecuteProgram(string input)
|
public void ExecuteProgram(string input)
|
||||||
{
|
{
|
||||||
|
// This is to prevent the "exec with" statement from being triggered by this one, since they both start with "exec"
|
||||||
|
if (input.Contains(" with "))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StartProcess(input, string.Join(" ", RuntimeInfo.InParametersStack.Reverse()));
|
StartProcess(input, string.Join(" ", RuntimeInfo.InParametersStack.Reverse()));
|
||||||
|
|||||||
Reference in New Issue
Block a user