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

View File

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

View File

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

View File

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

View File

@ -57,16 +57,16 @@ function TextColor(Color: Byte): LongWord; overload;
procedure ClrScr;
procedure Write(Str: PKolibriChar); overload;
procedure Write(Str: PKolibriChar; Length: LongWord); overload;
procedure Write(const Str: ShortString); overload;
function Write(Format: PKolibriChar; const Args: array of const): Integer; overload;
procedure WriteEx(Str: PKolibriChar); overload;
procedure WriteEx(Str: PKolibriChar; Length: LongWord); overload;
procedure WriteEx(const Str: ShortString); overload;
function WriteEx(Format: PKolibriChar; const Args: array of const): Integer; overload;
procedure WriteLn(LineBreaks: Integer = 1); overload;
procedure WriteLn(Str: PKolibriChar; LineBreaks: Integer = 1); overload;
procedure WriteLn(Str: PKolibriChar; Length: LongWord; LineBreaks: Integer = 1); overload;
procedure WriteLn(const Str: ShortString; LineBreaks: Integer = 1); overload;
function WriteLn(Format: PKolibriChar; const Args: array of const; LineBreaks: Integer = 1): Integer; overload;
procedure WriteLnEx(LineBreaks: Integer = 1); overload;
procedure WriteLnEx(Str: PKolibriChar; LineBreaks: Integer = 1); overload;
procedure WriteLnEx(Str: PKolibriChar; Length: LongWord; LineBreaks: Integer = 1); overload;
procedure WriteLnEx(const Str: ShortString; LineBreaks: Integer = 1); 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: TKey); overload;
@ -91,38 +91,12 @@ uses
SysUtils;
var
ConsoleInterface: TConsoleInterface;
CloseWindow: Boolean;
procedure InitConsole(Title: PKolibriChar; CloseWindowOnExit: Boolean;
WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord);
var
hConsole: Pointer;
begin
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');
ConsoleInit(WndWidth, WndHeight, ScrWidth, ScrHeight, Title);
end;
ConsoleInterface.ConsoleInit(WndWidth, WndHeight, ScrWidth, ScrHeight, Title);
CloseWindow := CloseWindowOnExit;
end;
@ -236,22 +210,22 @@ begin
ConsoleInterface.Cls;
end;
procedure Write(Str: PKolibriChar);
procedure WriteEx(Str: PKolibriChar);
begin
ConsoleInterface.WriteASCIIZ(Str);
end;
procedure Write(Str: PKolibriChar; Length: LongWord);
procedure WriteEx(Str: PKolibriChar; Length: LongWord);
begin
ConsoleInterface.WriteString(Str, Length);
end;
procedure Write(const Str: ShortString);
procedure WriteEx(const Str: ShortString);
begin
ConsoleInterface.WriteString(@Str[1], Length(Str));
end;
function Write(Format: PKolibriChar; const Args: array of const): Integer;
function WriteEx(Format: PKolibriChar; const Args: array of const): Integer;
const
VarArgSize = SizeOf(TVarRec);
asm
@ -271,7 +245,7 @@ asm
POP EBX
end;
procedure WriteLn(LineBreaks: Integer);
procedure WriteLnEx(LineBreaks: Integer);
var
I: Integer;
begin
@ -279,28 +253,28 @@ begin
ConsoleInterface.WriteString(#10, 1);
end;
procedure WriteLn(Str: PKolibriChar; LineBreaks: Integer);
procedure WriteLnEx(Str: PKolibriChar; LineBreaks: Integer);
begin
ConsoleInterface.WriteASCIIZ(Str);
WriteLn(LineBreaks);
WriteLnEx(LineBreaks);
end;
procedure WriteLn(Str: PKolibriChar; Length: LongWord; LineBreaks: Integer);
procedure WriteLnEx(Str: PKolibriChar; Length: LongWord; LineBreaks: Integer);
begin
ConsoleInterface.WriteString(Str, Length);
WriteLn(LineBreaks);
WriteLnEx(LineBreaks);
end;
procedure WriteLn(const Str: ShortString; LineBreaks: Integer);
procedure WriteLnEx(const Str: ShortString; LineBreaks: Integer);
begin
ConsoleInterface.WriteString(@Str[1], Length(Str));
WriteLn(LineBreaks);
WriteLnEx(LineBreaks);
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
Result := Write(Format, Args);
WriteLn(LineBreaks);
Result := WriteEx(Format, Args);
WriteLnEx(LineBreaks);
end;
procedure Read(var Result: KolibriChar);
@ -352,7 +326,32 @@ begin
Sleep((Milliseconds + 10 div 2) div 10);
end;
var
hConsole: Pointer;
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
with ConsoleInterface do

View File

@ -13,7 +13,7 @@ const
RTLVersion = 15.2006; // <---'
{$IFEND}
UnicodeCompiler = CompilerVersion >= 20.0;
UnicodeCompiler = CompilerVersion >= 20;
type
PPAnsiChar = ^PAnsiChar;
@ -22,6 +22,8 @@ type
PKolibriChar = PAnsiChar;
PPKolibriChar = PPAnsiChar;
KolibriString = AnsiString;
{$IF CompilerVersion < 15}
UInt64 = Int64;
{$IFEND}
@ -104,11 +106,11 @@ type
case Byte of
vtInteger: (VInteger: Integer; VType: Byte);
vtBoolean: (VBoolean: Boolean);
vtChar: (VChar: AnsiChar);
vtChar: (VChar: KolibriChar);
vtExtended: (VExtended: PExtended);
vtString: (VString: PShortString);
vtPointer: (VPointer: Pointer);
vtPChar: (VPChar: PAnsiChar);
vtPChar: (VPChar: PKolibriChar);
vtObject: (VObject: Pointer);
vtClass: (VClass: Pointer);
vtWideChar: (VWideChar: WideChar);
@ -146,6 +148,20 @@ type
WriteString: procedure(Str: PKolibriChar; Length: LongWord); stdcall;
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 _HandleFinally;
procedure _StartExe(InitTable: PPackageInfo);
@ -166,6 +182,31 @@ procedure Randomize;
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
uses
@ -298,6 +339,107 @@ begin
Result := Ch;
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
asm // InitFPU