kolibrios-gitea/programs/develop/fp/rtl/system.pp
bw f23fc38433 FreePascal RTL
git-svn-id: svn://kolibrios.org@616 a494cfbc-eb01-0410-851d-a64ba20cac60
2007-08-29 09:16:31 +00:00

202 lines
3.9 KiB
ObjectPascal
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{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>யãáâ¨âì «¨¤¨àãî騥 ¯à®¡¥«ë}
while Args^ in [#1..#32] do Inc(Args);
if Args^ = #0 then Break;
{‡ ¯®¬­¨âì 㪠§ â¥«ì ­  ¯ à ¬¥âà}
SetLength(Ptrs, Argc);
Ptrs[Argc - 1] := Args;
Inc(Argc);
{<7B>யãáâ¨âì ⥪ã騩 ¯ à ¬¥âà}
InQuotes := False;
while (Args^ <> #0) and (not (Args^ in [#1..#32]) or InQuotes) do
begin
if Args^ = '"' then InQuotes := not InQuotes;
Inc(Args);
end;
{“áâ ­®¢¨âì ®ª®­ç ­¨¥ ¯ à ¬¥âà }
if Args^ in [#1..#32] then
begin
Args^ := #0;
Inc(Args);
end;
end;
end;
Argv := GetMem(Argc * SizeOf(PChar)); {XXX: ¯ ¬ïâì ­¥ ®á¢®¡®¦¤ ¥âáï}
Argv[0] := PKosHeader(0)^.path;
for I := 1 to Argc - 1 do
begin
Argv[I] := Ptrs[I - 1];
{ˆáª«îç¨âì ª ¢ë窨 ¨§ áâப¨}
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: ®¡ï§ â¥«ì­®¥ ãá«®¢¨¥ ­  ®¤­®¯®â®ç­ë© Konsole}
Write(StdErr, '[Error #', ExitCode,', press any key]');
{®¦¨¤ âì ­ ¦ â¨ï ª« ¢¨è¨}
Konsole.KeyPressed;
while Konsole.KeyPressed = 0 do kos_delay(2);
{TODO: ¨á¯à ¢¨âì ª®áïª ¯à¨ ¯¥à¥à¨á®¢ª¥ Konsole}
{íâ® ­¥¢®§¬®¦­®, â ª ª ª ªãç  ®á¢®¡®¦¤ ¥âáï ¥é¥ ¤® ¢ë§®¢  í⮩ ¯à®æ¥¤ãàë}
{¬®¦­® ­ ¯¨á âì ᢮© ¤¨á¯¥âç¥à ¯ ¬ïâ¨, ­® íâ® á«®¦­®}
{  ¥á«¨ ¢ Konsole ¨á¯®«ì§®¢ âì ¢ë¤¥«¥­¨¥ ¯ ¬ï⨠­ ¯àï¬ãî ç¥à¥§ 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.