forked from KolibriOS/kolibrios
202 lines
3.9 KiB
ObjectPascal
202 lines
3.9 KiB
ObjectPascal
|
{cp866}
|
|||
|
unit System;
|
|||
|
|
|||
|
{$i _defines.inc}
|
|||
|
{$define HAS_CMDLINE}
|
|||
|
|
|||
|
interface
|
|||
|
|
|||
|
{$i systemh.inc}
|
|||
|
{$i kos_def.inc}
|
|||
|
{$i kosh.inc}
|
|||
|
|
|||
|
const
|
|||
|
LineEnding = #13#10;
|
|||
|
LFNSupport = True;
|
|||
|
DirectorySeparator = '/';
|
|||
|
DriveSeparator = '/';
|
|||
|
PathSeparator = ';';
|
|||
|
MaxExitCode = 65535;
|
|||
|
MaxPathLen = 512;
|
|||
|
|
|||
|
UnusedHandle : THandle = -1;
|
|||
|
StdInputHandle : THandle = 0;
|
|||
|
StdOutputHandle: THandle = 0;
|
|||
|
StdErrorHandle : THandle = 0;
|
|||
|
FileNameCaseSensitive: Boolean = True;
|
|||
|
CtrlZMarksEOF: Boolean = True;
|
|||
|
sLineBreak = LineEnding;
|
|||
|
DefaultTextLineBreakStyle: TTextLineBreakStyle = tlbsCRLF;
|
|||
|
|
|||
|
var
|
|||
|
Argc: Longint = 0;
|
|||
|
Argv: PPChar = nil;
|
|||
|
|
|||
|
Konsole: TKonsole;
|
|||
|
|
|||
|
|
|||
|
implementation
|
|||
|
|
|||
|
var
|
|||
|
SysInstance: Longint; public name '_FPC_SysInstance';
|
|||
|
|
|||
|
{$i system.inc}
|
|||
|
|
|||
|
|
|||
|
procedure SetupCmdLine;
|
|||
|
var
|
|||
|
Ptrs: array of PChar;
|
|||
|
Args: PChar;
|
|||
|
InQuotes: Boolean;
|
|||
|
I, L: Longint;
|
|||
|
begin
|
|||
|
Argc := 1;
|
|||
|
Args := PKosHeader(0)^.args;
|
|||
|
if Assigned(Args) then
|
|||
|
begin
|
|||
|
while Args^ <> #0 do
|
|||
|
begin
|
|||
|
{<7B>ய<EFBFBD><E0AEAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>騥 <20><EFBFBD><E0AEA1><EFBFBD>}
|
|||
|
while Args^ in [#1..#32] do Inc(Args);
|
|||
|
if Args^ = #0 then Break;
|
|||
|
|
|||
|
{<7B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 㪠<><E3AAA0>⥫<EFBFBD> <20><> <20><>ࠬ<EFBFBD><E0A0AC><EFBFBD>}
|
|||
|
SetLength(Ptrs, Argc);
|
|||
|
Ptrs[Argc - 1] := Args;
|
|||
|
Inc(Argc);
|
|||
|
|
|||
|
{<7B>ய<EFBFBD><E0AEAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ⥪<>騩 <20><>ࠬ<EFBFBD><E0A0AC><EFBFBD>}
|
|||
|
InQuotes := False;
|
|||
|
while (Args^ <> #0) and (not (Args^ in [#1..#32]) or InQuotes) do
|
|||
|
begin
|
|||
|
if Args^ = '"' then InQuotes := not InQuotes;
|
|||
|
Inc(Args);
|
|||
|
end;
|
|||
|
|
|||
|
{<7B><>⠭<EFBFBD><E2A0AD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>砭<EFBFBD><E7A0AD> <20><>ࠬ<EFBFBD><E0A0AC><EFBFBD><EFBFBD>}
|
|||
|
if Args^ in [#1..#32] then
|
|||
|
begin
|
|||
|
Args^ := #0;
|
|||
|
Inc(Args);
|
|||
|
end;
|
|||
|
end;
|
|||
|
end;
|
|||
|
Argv := GetMem(Argc * SizeOf(PChar)); {XXX: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><EFBFBD><E1A2AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}
|
|||
|
Argv[0] := PKosHeader(0)^.path;
|
|||
|
for I := 1 to Argc - 1 do
|
|||
|
begin
|
|||
|
Argv[I] := Ptrs[I - 1];
|
|||
|
{<7B>᪫<EFBFBD><E1AAAB><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>窨 <20><> <20><>ப<EFBFBD>}
|
|||
|
Args := Argv[I];
|
|||
|
L := 0;
|
|||
|
while Args^ <> #0 do begin Inc(Args); Inc(L); end;
|
|||
|
Args := Argv[I];
|
|||
|
while Args^ <> #0 do
|
|||
|
begin
|
|||
|
if Args^ = '"' then
|
|||
|
begin
|
|||
|
Move(PChar(Args + 1)^, Args^, L);
|
|||
|
Dec(L);
|
|||
|
end;
|
|||
|
Inc(Args);
|
|||
|
Dec(L);
|
|||
|
end;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
function ParamCount: Longint;
|
|||
|
begin
|
|||
|
Result := Argc - 1;
|
|||
|
end;
|
|||
|
|
|||
|
function ParamStr(L: Longint): String;
|
|||
|
begin
|
|||
|
if (L >= 0) and (L < Argc) then
|
|||
|
Result := StrPas(Argv[L]) else
|
|||
|
Result := '';
|
|||
|
end;
|
|||
|
|
|||
|
procedure Randomize;
|
|||
|
begin
|
|||
|
randseed := 0; {GetTickCount()}
|
|||
|
end;
|
|||
|
|
|||
|
const
|
|||
|
ProcessID: SizeUInt = 0;
|
|||
|
|
|||
|
function GetProcessID: SizeUInt;
|
|||
|
begin
|
|||
|
GetProcessID := ProcessID;
|
|||
|
end;
|
|||
|
|
|||
|
function CheckInitialStkLen(stklen: SizeUInt): SizeUInt;
|
|||
|
begin
|
|||
|
{TODO}
|
|||
|
Result := stklen;
|
|||
|
end;
|
|||
|
|
|||
|
{$i kos_stdio.inc}
|
|||
|
|
|||
|
procedure SysInitStdIO;
|
|||
|
begin
|
|||
|
if IsConsole then
|
|||
|
begin
|
|||
|
AssignStdin(Input);
|
|||
|
AssignStdout(Output);
|
|||
|
AssignStdout(ErrOutput);
|
|||
|
AssignStdout(StdOut);
|
|||
|
AssignStdout(StdErr);
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure System_Exit; [public, alias: 'SystemExit'];
|
|||
|
var
|
|||
|
event, count: DWord;
|
|||
|
begin
|
|||
|
if IsConsole then
|
|||
|
begin
|
|||
|
if ExitCode <> 0 then
|
|||
|
begin
|
|||
|
{XXX: <20><>易⥫쭮<E2A5AB> <20><EFBFBD><E1ABAE><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Konsole}
|
|||
|
Write(StdErr, '[Error #', ExitCode,', press any key]');
|
|||
|
{<7B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}
|
|||
|
Konsole.KeyPressed;
|
|||
|
while Konsole.KeyPressed = 0 do kos_delay(2);
|
|||
|
{TODO: <20><><EFBFBD>ࠢ<EFBFBD><E0A0A2><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ᮢ<EFBFBD><E1AEA2> Konsole}
|
|||
|
{<7B><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ⠪ <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><EFBFBD><E1A2AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><> <20>맮<EFBFBD><EBA7AE> <20>⮩ <20><><EFBFBD>楤<EFBFBD><E6A5A4><EFBFBD>}
|
|||
|
{<7B><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <> <20><>ᯥ<EFBFBD><E1AFA5><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><> <20><><EFBFBD> <><E1ABAE><EFBFBD>}
|
|||
|
{<7B> <20> <20> Konsole <20>ᯮ<EFBFBD>짮<EFBFBD><ECA7AE><EFBFBD><EFBFBD> <20>뤥<EFBFBD><EBA4A5><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>१ KosAPI?!}
|
|||
|
end;
|
|||
|
Close(StdErr);
|
|||
|
Close(StdOut);
|
|||
|
Close(ErrOutput);
|
|||
|
Close(Input);
|
|||
|
Close(Output);
|
|||
|
Konsole.Done();
|
|||
|
end;
|
|||
|
asm
|
|||
|
movl $-1, %eax
|
|||
|
int $0x40
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
{$i kos.inc}
|
|||
|
|
|||
|
begin
|
|||
|
SysResetFPU;
|
|||
|
StackLength := CheckInitialStkLen(InitialStkLen);
|
|||
|
StackBottom := Pointer(StackTop - StackLength);
|
|||
|
InitHeap;
|
|||
|
kos_initheap();
|
|||
|
SysInitExceptions;
|
|||
|
FPC_CpuCodeInit();
|
|||
|
InOutRes := 0;
|
|||
|
InitSystemThreads;
|
|||
|
Konsole.Init();
|
|||
|
SysInitStdIO;
|
|||
|
SetupCmdLine;
|
|||
|
InitVariantManager;
|
|||
|
{InitWideStringManager;}
|
|||
|
DispCallByIDProc := @DoDispCallByIDError;
|
|||
|
end.
|