Standard Pascal Write/WriteLn procedures added

This commit is contained in:
Владислав Джавадов 2020-06-24 17:50:45 +03:00
parent 700e45b364
commit 73d3f78bdf
6 changed files with 221 additions and 86 deletions

View File

@ -11,17 +11,16 @@ begin
CursorOff; CursorOff;
GotoXY(27, 11); GotoXY(27, 11);
Write( WriteEx(
'System Date and System Time'#10 + 'System Date and System Time'#10 +
' ' ' '
); );
CursorXY := WhereXY; CursorXY := WhereXY;
repeat repeat
with GetSystemDate, GetSystemTime do with GetSystemDate do
begin WriteEx('%02x.%02x.%02x', [Day, Month, Year]);
Write('%02x.%02x.%02x', [Day, Month, Year]); with GetSystemTime do
Write(' - %02x:%02x:%02x', [Hours, Minutes, Seconds]); WriteEx(' - %02x:%02x:%02x', [Hours, Minutes, Seconds]);
end;
GotoXY(CursorXY); GotoXY(CursorXY);
Delay(500); Delay(500);
until KeyPressed; until KeyPressed;

View File

@ -17,7 +17,7 @@ begin
GetCurrentDirectory(Buffer, BUFFER_SIZE); GetCurrentDirectory(Buffer, BUFFER_SIZE);
WriteLn('AppPath is "%s"', [AppPath^]); WriteLnEx('AppPath is "%s"', [AppPath^]);
WriteLn('CmdLine is "%s"', [CmdLine^]); WriteLnEx('CmdLine is "%s"', [CmdLine^]);
WriteLn('Current Directory is "%s"', [Buffer]); WriteLnEx('Current Directory is "%s"', [Buffer]);
end. end.

View File

@ -10,5 +10,5 @@ var
begin begin
InitConsole('Load File'); InitConsole('Load File');
Buffer := LoadFile('/sys/example.asm', FileSize); Buffer := LoadFile('/sys/example.asm', FileSize);
WriteLn(Buffer, FileSize); WriteLnEx(Buffer, FileSize);
end. end.

View File

@ -1,12 +1,7 @@
program ReadFolderApp; program ReadFolderApp;
uses uses
KolibriOS, CRT; KolibriOS, CRT, SysUtils;
type
TInt64Rec = packed record
Lo, Hi: LongWord;
end;
const const
FolderPath = '/sys'; FolderPath = '/sys';
@ -21,36 +16,36 @@ begin
if ReadFolder(FolderPath, FolderInformation, 0, 0, 0, BlocksRead) = 0 then if ReadFolder(FolderPath, FolderInformation, 0, 0, 0, BlocksRead) = 0 then
with FolderInformation do with FolderInformation do
WriteLn('Folder "%s" contains %u files and/or folders.', [FolderPath, FileCount], 2) WriteLnEx('Folder "%s" contains %u files and/or folders.', [FolderPath, FileCount], 2)
else else
WriteLn('Folder "%s" can not be read.', [FolderPath]); WriteLnEx('Folder "%s" can not be read.', [FolderPath]);
Pos := 0; Pos := 0;
while ReadFolder(FolderPath, FolderInformation, 1, Pos, 0, BlocksRead) = 0 do while ReadFolder(FolderPath, FolderInformation, 1, Pos, 0, BlocksRead) = 0 do
begin begin
with FolderInformation, FileInformation[0] do with FolderInformation, FileInformation[0] do
begin begin
WriteLn('FileName = %s', [Name]); WriteLnEx('FileName = %s', [Name]);
with Attributes do with Attributes do
begin begin
WriteLn( 'SizeLo = %u', [TInt64Rec(Size).Lo]); WriteLnEx( 'SizeLo = %u', [Int64Rec(Size).Lo]);
WriteLn( 'SizeHi = %u', [TInt64Rec(Size).Hi]); WriteLnEx( 'SizeHi = %u', [Int64Rec(Size).Hi]);
with Modify.Date do with Modify.Date do
WriteLn('Modify Date = %02d.%02d.%02d', [Day, Month, Year]); WriteLnEx('Modify Date = %02d.%02d.%02d', [Day, Month, Year]);
with Modify.Time do with Modify.Time do
WriteLn('Modify Time = %02d:%02d:%02d', [Hours, Minutes, Seconds]); WriteLnEx('Modify Time = %02d:%02d:%02d', [Hours, Minutes, Seconds]);
with Access.Date do with Access.Date do
WriteLn('Access Date = %02d.%02d.%02d', [Day, Month, Year]); WriteLnEx('Access Date = %02d.%02d.%02d', [Day, Month, Year]);
with Access.Time do with Access.Time do
WriteLn('Access Time = %02d:%02d:%02d', [Hours, Minutes, Seconds]); WriteLnEx('Access Time = %02d:%02d:%02d', [Hours, Minutes, Seconds]);
with Creation.Date do with Creation.Date do
WriteLn('Creation Date = %02d.%02d.%02d', [Day, Month, Year]); WriteLnEx('Creation Date = %02d.%02d.%02d', [Day, Month, Year]);
with Creation.Time do with Creation.Time do
WriteLn('Creation Time = %02d:%02d:%02d', [Hours, Minutes, Seconds]); WriteLnEx('Creation Time = %02d:%02d:%02d', [Hours, Minutes, Seconds]);
WriteLn( 'Attributes = 0x%08x', [Attributes]); WriteLnEx( 'Attributes = 0x%08x', [Attributes]);
end; end;
end; end;
WriteLn; WriteLnEx;
Inc(Pos); Inc(Pos);
end; end;
end. end.

View File

@ -57,20 +57,20 @@ function TextColor(Color: Byte): LongWord; overload;
procedure ClrScr; procedure ClrScr;
procedure Write(Str: PKolibriChar); overload; procedure WriteEx(Str: PKolibriChar); overload;
procedure Write(Str: PKolibriChar; Length: LongWord); overload; procedure WriteEx(Str: PKolibriChar; Length: LongWord); overload;
procedure Write(const Str: ShortString); overload; procedure WriteEx(const Str: ShortString); overload;
function Write(Format: PKolibriChar; const Args: array of const): Integer; overload; function WriteEx(Format: PKolibriChar; const Args: array of const): Integer; overload;
procedure WriteLn(LineBreaks: Integer = 1); overload; procedure WriteLnEx(LineBreaks: Integer = 1); overload;
procedure WriteLn(Str: PKolibriChar; LineBreaks: Integer = 1); overload; procedure WriteLnEx(Str: PKolibriChar; LineBreaks: Integer = 1); overload;
procedure WriteLn(Str: PKolibriChar; Length: LongWord; LineBreaks: Integer = 1); overload; procedure WriteLnEx(Str: PKolibriChar; Length: LongWord; LineBreaks: Integer = 1); overload;
procedure WriteLn(const Str: ShortString; LineBreaks: Integer = 1); overload; procedure WriteLnEx(const Str: ShortString; LineBreaks: Integer = 1); overload;
function WriteLn(Format: PKolibriChar; const Args: array of const; LineBreaks: Integer = 1): Integer; overload; function WriteLnEx(Format: PKolibriChar; const Args: array of const; LineBreaks: Integer = 1): Integer; overload;
procedure Read(var Result: KolibriChar); overload; procedure Read(var Result: KolibriChar); overload;
procedure Read(var Result: TKey); overload; procedure Read(var Result: TKey); overload;
procedure ReadLn(var Result: ShortString); procedure ReadLn(var Result: ShortString);
function CursorBig: Integer; function CursorBig: Integer;
function CursorHeight: Integer; overload; function CursorHeight: Integer; overload;
@ -91,38 +91,12 @@ uses
SysUtils; SysUtils;
var var
ConsoleInterface: TConsoleInterface;
CloseWindow: Boolean; CloseWindow: Boolean;
procedure InitConsole(Title: PKolibriChar; CloseWindowOnExit: Boolean; procedure InitConsole(Title: PKolibriChar; CloseWindowOnExit: Boolean;
WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord); WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord);
var
hConsole: Pointer;
begin begin
hConsole := LoadLibrary('/sys/lib/console.obj'); ConsoleInterface.ConsoleInit(WndWidth, WndHeight, ScrWidth, ScrHeight, Title);
with ConsoleInterface do
begin
Cls := GetProcAddress(hConsole, 'con_cls');
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
ConsoleInit := GetProcAddress(hConsole, 'con_init');
GetCh := GetProcAddress(hConsole, 'con_getch');
GetCh2 := GetProcAddress(hConsole, 'con_getch2');
GetCursorPos := GetProcAddress(hConsole, 'con_get_cursor_pos');
GetCursorHeight := GetProcAddress(hConsole, 'con_get_cursor_height');
GetFlags := GetProcAddress(hConsole, 'con_get_flags');
GetFontHeight := GetProcAddress(hConsole, 'con_get_font_height');
GetS := GetProcAddress(hConsole, 'con_gets');
KbdHit := GetProcAddress(hConsole, 'con_kbhit');
PrintF := GetProcAddress(hConsole, 'con_printf');
SetCursorHeight := GetProcAddress(hConsole, 'con_set_cursor_height');
SetCursorPos := GetProcAddress(hConsole, 'con_set_cursor_pos');
SetFlags := GetProcAddress(hConsole, 'con_set_flags');
SetTitle := GetProcAddress(hConsole, 'con_set_title');
WriteASCIIZ := GetProcAddress(hConsole, 'con_write_asciiz');
WriteString := GetProcAddress(hConsole, 'con_write_string');
ConsoleInit(WndWidth, WndHeight, ScrWidth, ScrHeight, Title);
end;
CloseWindow := CloseWindowOnExit; CloseWindow := CloseWindowOnExit;
end; end;
@ -236,22 +210,22 @@ begin
ConsoleInterface.Cls; ConsoleInterface.Cls;
end; end;
procedure Write(Str: PKolibriChar); procedure WriteEx(Str: PKolibriChar);
begin begin
ConsoleInterface.WriteASCIIZ(Str); ConsoleInterface.WriteASCIIZ(Str);
end; end;
procedure Write(Str: PKolibriChar; Length: LongWord); procedure WriteEx(Str: PKolibriChar; Length: LongWord);
begin begin
ConsoleInterface.WriteString(Str, Length); ConsoleInterface.WriteString(Str, Length);
end; end;
procedure Write(const Str: ShortString); procedure WriteEx(const Str: ShortString);
begin begin
ConsoleInterface.WriteString(@Str[1], Length(Str)); ConsoleInterface.WriteString(@Str[1], Length(Str));
end; end;
function Write(Format: PKolibriChar; const Args: array of const): Integer; function WriteEx(Format: PKolibriChar; const Args: array of const): Integer;
const const
VarArgSize = SizeOf(TVarRec); VarArgSize = SizeOf(TVarRec);
asm asm
@ -271,7 +245,7 @@ asm
POP EBX POP EBX
end; end;
procedure WriteLn(LineBreaks: Integer); procedure WriteLnEx(LineBreaks: Integer);
var var
I: Integer; I: Integer;
begin begin
@ -279,28 +253,28 @@ begin
ConsoleInterface.WriteString(#10, 1); ConsoleInterface.WriteString(#10, 1);
end; end;
procedure WriteLn(Str: PKolibriChar; LineBreaks: Integer); procedure WriteLnEx(Str: PKolibriChar; LineBreaks: Integer);
begin begin
ConsoleInterface.WriteASCIIZ(Str); ConsoleInterface.WriteASCIIZ(Str);
WriteLn(LineBreaks); WriteLnEx(LineBreaks);
end; end;
procedure WriteLn(Str: PKolibriChar; Length: LongWord; LineBreaks: Integer); procedure WriteLnEx(Str: PKolibriChar; Length: LongWord; LineBreaks: Integer);
begin begin
ConsoleInterface.WriteString(Str, Length); ConsoleInterface.WriteString(Str, Length);
WriteLn(LineBreaks); WriteLnEx(LineBreaks);
end; end;
procedure WriteLn(const Str: ShortString; LineBreaks: Integer); procedure WriteLnEx(const Str: ShortString; LineBreaks: Integer);
begin begin
ConsoleInterface.WriteString(@Str[1], Length(Str)); ConsoleInterface.WriteString(@Str[1], Length(Str));
WriteLn(LineBreaks); WriteLnEx(LineBreaks);
end; end;
function WriteLn(Format: PKolibriChar; const Args: array of const; LineBreaks: Integer = 1): Integer; function WriteLnEx(Format: PKolibriChar; const Args: array of const; LineBreaks: Integer = 1): Integer;
begin begin
Result := Write(Format, Args); Result := WriteEx(Format, Args);
WriteLn(LineBreaks); WriteLnEx(LineBreaks);
end; end;
procedure Read(var Result: KolibriChar); procedure Read(var Result: KolibriChar);
@ -352,7 +326,32 @@ begin
Sleep((Milliseconds + 10 div 2) div 10); Sleep((Milliseconds + 10 div 2) div 10);
end; end;
var
hConsole: Pointer;
initialization initialization
hConsole := LoadLibrary('/sys/lib/console.obj');
with ConsoleInterface do
begin
Cls := GetProcAddress(hConsole, 'con_cls');
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
ConsoleInit := GetProcAddress(hConsole, 'con_init');
GetCh := GetProcAddress(hConsole, 'con_getch');
GetCh2 := GetProcAddress(hConsole, 'con_getch2');
GetCursorPos := GetProcAddress(hConsole, 'con_get_cursor_pos');
GetCursorHeight := GetProcAddress(hConsole, 'con_get_cursor_height');
GetFlags := GetProcAddress(hConsole, 'con_get_flags');
GetFontHeight := GetProcAddress(hConsole, 'con_get_font_height');
GetS := GetProcAddress(hConsole, 'con_gets');
KbdHit := GetProcAddress(hConsole, 'con_kbhit');
PrintF := GetProcAddress(hConsole, 'con_printf');
SetCursorHeight := GetProcAddress(hConsole, 'con_set_cursor_height');
SetCursorPos := GetProcAddress(hConsole, 'con_set_cursor_pos');
SetFlags := GetProcAddress(hConsole, 'con_set_flags');
SetTitle := GetProcAddress(hConsole, 'con_set_title');
WriteASCIIZ := GetProcAddress(hConsole, 'con_write_asciiz');
WriteString := GetProcAddress(hConsole, 'con_write_string');
end;
finalization finalization
with ConsoleInterface do with ConsoleInterface do

View File

@ -13,15 +13,17 @@ const
RTLVersion = 15.2006; // <---' RTLVersion = 15.2006; // <---'
{$IFEND} {$IFEND}
UnicodeCompiler = CompilerVersion >= 20.0; UnicodeCompiler = CompilerVersion >= 20;
type type
PPAnsiChar = ^PAnsiChar; PPAnsiChar = ^PAnsiChar;
KolibriChar = AnsiChar; KolibriChar = AnsiChar;
PKolibriChar = PAnsiChar; PKolibriChar = PAnsiChar;
PPKolibriChar = PPAnsiChar; PPKolibriChar = PPAnsiChar;
KolibriString = AnsiString;
{$IF CompilerVersion < 15} {$IF CompilerVersion < 15}
UInt64 = Int64; UInt64 = Int64;
{$IFEND} {$IFEND}
@ -104,11 +106,11 @@ type
case Byte of case Byte of
vtInteger: (VInteger: Integer; VType: Byte); vtInteger: (VInteger: Integer; VType: Byte);
vtBoolean: (VBoolean: Boolean); vtBoolean: (VBoolean: Boolean);
vtChar: (VChar: AnsiChar); vtChar: (VChar: KolibriChar);
vtExtended: (VExtended: PExtended); vtExtended: (VExtended: PExtended);
vtString: (VString: PShortString); vtString: (VString: PShortString);
vtPointer: (VPointer: Pointer); vtPointer: (VPointer: Pointer);
vtPChar: (VPChar: PAnsiChar); vtPChar: (VPChar: PKolibriChar);
vtObject: (VObject: Pointer); vtObject: (VObject: Pointer);
vtClass: (VClass: Pointer); vtClass: (VClass: Pointer);
vtWideChar: (VWideChar: WideChar); vtWideChar: (VWideChar: WideChar);
@ -146,6 +148,20 @@ type
WriteString: procedure(Str: PKolibriChar; Length: LongWord); stdcall; WriteString: procedure(Str: PKolibriChar; Length: LongWord); stdcall;
end; end;
PTextBuf = ^TTextBuf;
TTextBuf = array[0..127] of KolibriChar;
TTextRec = packed record
Handle: THandle;
Mode, Flags: Word;
BufSize, BufPos, BufEnd: Cardinal;
BufPtr: PKolibriChar;
OpenFunc, InOutFunc, FlushFunc, CloseFunc: Pointer;
UserData: array[1..32] of Byte;
Name: array[0..259] of Char;
Buffer: TTextBuf;
end;
procedure _Halt0; procedure _Halt0;
procedure _HandleFinally; procedure _HandleFinally;
procedure _StartExe(InitTable: PPackageInfo); procedure _StartExe(InitTable: PPackageInfo);
@ -166,6 +182,31 @@ procedure Randomize;
function UpCase(Ch: KolibriChar): KolibriChar; function UpCase(Ch: KolibriChar): KolibriChar;
function _LStrLen(const S: KolibriString): LongInt;
function _LStrToPChar(const S: KolibriString): PKolibriChar;
var
ConsoleInterface: TConsoleInterface;
IOResult: Integer;
Output: Text;
function _Flush(var T: TTextRec): Integer;
procedure __IOTest;
procedure _Write0Bool(var T: TTextRec; Value: Boolean);
procedure _Write0Char(var T: TTextRec; Ch: KolibriChar);
procedure _Write0Long(var T: TTextRec; Value: LongInt);
procedure _Write0String(var T: TTextRec; const S: ShortString);
procedure _Write0CString(var T: TTextRec; S: PKolibriChar);
procedure _Write0LString(var T: TTextRec; const S: KolibriString);
procedure _WriteBool(var T: TTextRec; Value: Boolean; Width: LongInt);
procedure _WriteChar(var T: TTextRec; Ch: KolibriChar; Width: LongInt);
procedure _WriteCString(var T: TTextRec; S: PKolibriChar; Width: LongInt);
procedure _WriteLong(var T: TTextRec; Value, Width: LongInt);
procedure _WriteString(var T: TTextRec; const S: ShortString; Width: LongInt);
procedure _WriteLString(var T: TTextRec; const S: KolibriString; Width: LongInt);
procedure _WriteLn(var T: TTextRec);
implementation implementation
uses uses
@ -298,6 +339,107 @@ begin
Result := Ch; Result := Ch;
end; end;
type
PStrRec = ^TStrRec;
TStrRec = packed record
{$IFDEF UnicodeCompiler}
CodePage, CharSize: Word;
{$ENDIF}
RefCount, Length: LongInt;
end;
function _LStrLen(const S: KolibriString): LongInt;
begin
Result := PStrRec(PKolibriChar(Pointer(S)) - SizeOf(TStrRec)).Length;
end;
function _LStrToPChar(const S: KolibriString): PKolibriChar;
const
EmptyString = '';
begin
if Pointer(S) = nil then
Result := EmptyString
else
Result := Pointer(S);
end;
function _Flush(var T: TTextRec): Integer;
asm
end;
procedure __IOTest;
asm
// TODO: I/O error call
end;
const
Booleans: array[Boolean] of PKolibriChar = ('False', 'True');
procedure _Write0Bool(var T: TTextRec; Value: Boolean);
begin
ConsoleInterface.WriteASCIIZ(Booleans[Value]);
end;
procedure _Write0Char(var T: TTextRec; Ch: KolibriChar);
begin
ConsoleInterface.WriteString(@Ch, 1);
end;
procedure _Write0Long(var T: TTextRec; Value: LongInt);
begin
ConsoleInterface.PrintF('%d', Value);
end;
procedure _Write0String(var T: TTextRec; const S: ShortString);
begin
ConsoleInterface.WriteString(@S[1], Length(S));
end;
procedure _Write0CString(var T: TTextRec; S: PKolibriChar);
begin
ConsoleInterface.WriteASCIIZ(S);
end;
procedure _Write0LString(var T: TTextRec; const S: KolibriString);
begin
ConsoleInterface.WriteString(Pointer(S), Length(S));
end;
procedure _WriteBool(var T: TTextRec; Value: Boolean; Width: LongInt);
begin
ConsoleInterface.PrintF('%*s', Width, Booleans[Value]);
end;
procedure _WriteChar(var T: TTextRec; Ch: KolibriChar; Width: LongInt);
begin
ConsoleInterface.PrintF('%*c', Width, Ch);
end;
procedure _WriteCString(var T: TTextRec; S: PKolibriChar; Width: LongInt);
begin
ConsoleInterface.PrintF('%*s', Width, S);
end;
procedure _WriteLong(var T: TTextRec; Value, Width: LongInt);
begin
ConsoleInterface.PrintF('%*d', Width, Value);
end;
procedure _WriteString(var T: TTextRec; const S: ShortString; Width: LongInt);
begin
ConsoleInterface.PrintF('%*s', Width, @S[1]);
end;
procedure _WriteLString(var T: TTextRec; const S: KolibriString; Width: LongInt);
begin
ConsoleInterface.PrintF('%*s', Width, Pointer(S));
end;
procedure _WriteLn(var T: TTextRec);
begin
ConsoleInterface.WriteString(#10, 1);
end;
initialization initialization
asm // InitFPU asm // InitFPU