Subversion Repositories Kolibri OS

Rev

Rev 619 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. unit sysutils;
  2.  
  3. {$i _defines.inc}
  4.  
  5. interface
  6.  
  7. {$mode objfpc}
  8. { force ansistrings }
  9. {$h+}
  10.  
  11. {$DEFINE HAS_SLEEP}
  12. {-$DEFINE HAS_OSERROR}
  13. {-$DEFINE HAS_OSCONFIG}
  14. {-$DEFINE HAS_CREATEGUID}
  15.  
  16.  
  17. { Include platform independent interface part }
  18. {$i sysutilh.inc}
  19.  
  20. implementation
  21.  
  22.  
  23. uses
  24.   SysConst;
  25.  
  26.  
  27. {-$define HASCREATEGUID}
  28. {-$define HASEXPANDUNCFILENAME}
  29. {-$DEFINE FPC_NOGENERICANSIROUTINES}
  30. {-$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
  31. {-$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
  32.  
  33. { Include platform independent implementation part }
  34. {$i sysutils.inc}
  35.  
  36.  
  37. {****************************************************************************
  38.                               File Functions
  39. ****************************************************************************}
  40.  
  41. const
  42.   FILEHANDLEPREFIX = $4000;
  43. type
  44.   PFileRecord = ^TFileRecord;
  45.   TFileRecord = record
  46.     Filled: Boolean;
  47.     F: File;
  48.   end;
  49. var
  50.   FileHandles: array of TFileRecord;
  51.  
  52. function FileRecordByHandle(Handle: THandle): PFileRecord;
  53. begin
  54.   Dec(Handle, FILEHANDLEPREFIX);
  55.   Result := @FileHandles[Handle];
  56. end;
  57.  
  58. function CreateFileRecord(): THandle;
  59. var
  60.   I, C: Longword;
  61. begin
  62.   Result := -1;
  63.   C := Length(FileHandles);
  64.   for I := 0 to C - 1 do
  65.   if not FileHandles[I].Filled then
  66.   begin
  67.     Result := I;
  68.     Break;
  69.   end;
  70.   if Result < 0 then
  71.   begin
  72.     SetLength(FileHandles, C + 1);
  73.     Result := C;
  74.   end;
  75.   FileHandles[Result].Filled := True;
  76.   FillChar(FileHandles[Result].F, SizeOf(FileRec), 0);
  77.   Inc(Result, FILEHANDLEPREFIX);
  78. end;
  79.  
  80. procedure ReleaseFileRecord(Handle: THandle);
  81. begin
  82.   FileRecordByHandle(Handle)^.Filled := False;
  83. end;
  84.  
  85. function FileOpen(const FileName: String; Mode: Integer): THandle;
  86. var
  87.   F: File;
  88. begin
  89.   Filemode := Mode;
  90.   Assign(F, FileName);
  91.   Reset(F, 1);
  92.   if InOutRes = 0 then
  93.   begin
  94.     Result := CreateFileRecord();
  95.     FileRecordByHandle(Result)^.F := F;
  96.   end else
  97.     Result := feInvalidHandle;
  98. end;
  99.  
  100. function FileCreate(const FileName: String): THandle;
  101. var
  102.   F: File;
  103. begin
  104.   Assign(F, FileName);
  105.   Rewrite(F, 1);
  106.   if InOutRes = 0 then
  107.   begin
  108.     Result := CreateFileRecord();
  109.     FileRecordByHandle(Result)^.F := F;
  110.   end else
  111.     Result := feInvalidHandle;
  112. end;
  113.  
  114. function FileCreate(const FileName: String; Mode: Integer): THandle;
  115. var
  116.   F: File;
  117. begin
  118.   Filemode := Mode;
  119.   Assign(F, FileName);
  120.   Rewrite(F, 1);
  121.   if InOutRes = 0 then
  122.   begin
  123.     Result := CreateFileRecord();
  124.     FileRecordByHandle(Result)^.F := F;
  125.   end else
  126.     Result := feInvalidHandle;
  127. end;
  128.  
  129. function FileRead(Handle: THandle; var Buffer; Count: Longint): Longint;
  130. begin
  131.   BlockRead(FileRecordByHandle(Handle)^.F, Buffer, Count, Result);
  132. end;
  133.  
  134. function FileWrite(Handle: THandle; const Buffer; Count: Longint): Longint;
  135. begin
  136.   BlockWrite(FileRecordByHandle(Handle)^.F, Buffer, Count, Result);
  137. end;
  138.  
  139. function FileSeek(Handle: THandle; FOffset, Origin: Longint): Longint;
  140. begin
  141.   Result := FileSeek(Handle, Int64(FOffset), Origin);
  142. end;
  143.  
  144. function FileSeek(Handle: THandle; FOffset: Int64; Origin: Longint): Int64;
  145. var
  146.   Position: Int64;
  147. begin
  148.   case Origin of
  149.     fsFromBeginning: Position := FOffset;
  150.     fsFromCurrent: Position := FilePos(FileRecordByHandle(Handle)^.F) + FOffset;
  151.     fsFromEnd: Position := FileSize(FileRecordByHandle(Handle)^.F) + FOffset;
  152.   end;
  153.   {TODO: ¯à®¢¥àª  ᮮ⢥âá⢨ï [0..filesize]}
  154.   Seek(FileRecordByHandle(Handle)^.F, Position);
  155.   Result := Position;
  156. end;
  157.  
  158. procedure FileClose(Handle: THandle);
  159. begin
  160.   Close(FileRecordByHandle(Handle)^.F);
  161.   ReleaseFileRecord(Handle);
  162. end;
  163.  
  164. function FileTruncate(Handle: THandle; Size: Longint): Boolean;
  165. begin
  166.   Result := False;
  167. end;
  168.  
  169. function FileAge(const FileName: String): Longint;
  170. begin
  171.   Result := 0;
  172. end;
  173.  
  174. function FileExists(const FileName: String): Boolean;
  175. var
  176.   F: File;
  177. begin
  178.   Assign(F, FileName);
  179.   try
  180.     Reset(F);
  181.     FileSize(F);
  182.     Result := True;
  183.   except
  184.     Result := False;
  185.   end;
  186.   Close(F);
  187. end;
  188.  
  189. function DirectoryExists(const Directory: String): Boolean;
  190. begin
  191.   Result := False;
  192. end;
  193.  
  194. function FindMatch(var f: TSearchRec): Longint;
  195. begin
  196.   Result := feInvalidHandle;
  197. end;
  198.  
  199. function FindFirst(const Path: String; Attr: Longint; out Rslt: TSearchRec): Longint;
  200. begin
  201.   Result := feInvalidHandle;
  202. end;
  203.  
  204. function FindNext(var Rslt: TSearchRec): Longint;
  205. begin
  206.   Result := feInvalidHandle;
  207. end;
  208.  
  209. procedure FindClose(var F: TSearchrec);
  210. begin
  211. end;
  212.  
  213. function FileGetDate(Handle: THandle): Longint;
  214. begin
  215.   Result := feInvalidHandle;
  216. end;
  217.  
  218. function FileSetDate(Handle: THandle; Age: Longint): Longint;
  219. begin
  220.   Result := feInvalidHandle;
  221. end;
  222.  
  223. function FileGetAttr(const FileName: String): Longint;
  224. begin
  225.   Result := feInvalidHandle;
  226. end;
  227.  
  228. function FileSetAttr(const Filename: String; Attr: longint): Longint;
  229. begin
  230.   Result := feInvalidHandle;
  231. end;
  232.  
  233. function DeleteFile(const FileName: String): Boolean;
  234. begin
  235.   Result := False;
  236. end;
  237.  
  238. function RenameFile(const OldName, NewName: String): Boolean;
  239. begin
  240.   Result := False;
  241. end;
  242.  
  243.  
  244. {****************************************************************************
  245.                               Disk Functions
  246. ****************************************************************************}
  247.  
  248. function DiskFree(drive: Byte): Int64;
  249. begin
  250.   Result := 0;
  251. end;
  252.  
  253. function DiskSize(drive: Byte): Int64;
  254. begin
  255.   Result := 0;
  256. end;
  257.  
  258. function GetCurrentDir: String;
  259. begin
  260.   GetDir(0, Result);
  261. end;
  262.  
  263. function SetCurrentDir(const NewDir: String): Boolean;
  264. var
  265.   Path: String;
  266. begin
  267.   ChDir(NewDir);
  268.   GetDir(0, Path);
  269.   Result := Path = NewDir;
  270. end;
  271.  
  272. function CreateDir(const NewDir: String): Boolean;
  273. begin
  274.   Result := False;
  275. end;
  276.  
  277. function RemoveDir(const Dir: String): Boolean;
  278. begin
  279.   Result := False;
  280. end;
  281.  
  282.  
  283. {****************************************************************************
  284.                               Time Functions
  285. ****************************************************************************}
  286.  
  287. procedure GetLocalTime(var SystemTime: TSystemTime);
  288. begin
  289. end;
  290.  
  291.  
  292. {****************************************************************************
  293.                               Misc Functions
  294. ****************************************************************************}
  295.  
  296. procedure Beep;
  297. begin
  298. end;
  299.  
  300.  
  301. {****************************************************************************
  302.                               Locale Functions
  303. ****************************************************************************}
  304.  
  305. procedure GetFormatSettings;
  306. var
  307.   HF: String;
  308. begin
  309.   ShortMonthNames[1] := SShortMonthNameJan;
  310.   ShortMonthNames[2] := SShortMonthNameFeb;
  311.   ShortMonthNames[3] := SShortMonthNameMar;
  312.   ShortMonthNames[4] := SShortMonthNameApr;
  313.   ShortMonthNames[5] := SShortMonthNameMay;
  314.   ShortMonthNames[6] := SShortMonthNameJun;
  315.   ShortMonthNames[7] := SShortMonthNameJul;
  316.   ShortMonthNames[8] := SShortMonthNameAug;
  317.   ShortMonthNames[9] := SShortMonthNameSep;
  318.   ShortMonthNames[10] := SShortMonthNameOct;
  319.   ShortMonthNames[11] := SShortMonthNameNov;
  320.   ShortMonthNames[12] := SShortMonthNameDec;
  321.  
  322.   LongMonthNames[1] := SLongMonthNameJan;
  323.   LongMonthNames[2] := SLongMonthNameFeb;
  324.   LongMonthNames[3] := SLongMonthNameMar;
  325.   LongMonthNames[4] := SLongMonthNameApr;
  326.   LongMonthNames[5] := SLongMonthNameMay;
  327.   LongMonthNames[6] := SLongMonthNameJun;
  328.   LongMonthNames[7] := SLongMonthNameJul;
  329.   LongMonthNames[8] := SLongMonthNameAug;
  330.   LongMonthNames[9] := SLongMonthNameSep;
  331.   LongMonthNames[10] := SLongMonthNameOct;
  332.   LongMonthNames[11] := SLongMonthNameNov;
  333.   LongMonthNames[12] := SLongMonthNameDec;
  334.  
  335.   ShortDayNames[1] := SShortDayNameMon;
  336.   ShortDayNames[2] := SShortDayNameTue;
  337.   ShortDayNames[3] := SShortDayNameWed;
  338.   ShortDayNames[4] := SShortDayNameThu;
  339.   ShortDayNames[5] := SShortDayNameFri;
  340.   ShortDayNames[6] := SShortDayNameSat;
  341.   ShortDayNames[7] := SShortDayNameSun;
  342.  
  343.   LongDayNames[1] := SLongDayNameMon;
  344.   LongDayNames[2] := SLongDayNameTue;
  345.   LongDayNames[3] := SLongDayNameWed;
  346.   LongDayNames[4] := SLongDayNameThu;
  347.   LongDayNames[5] := SLongDayNameFri;
  348.   LongDayNames[6] := SLongDayNameSat;
  349.   LongDayNames[7] := SShortDayNameSun;
  350.  
  351.   DateSeparator := '/';
  352.   ShortDateFormat := 'd/mm/yy';
  353.   LongDateFormat := 'd mmmm yyyy';
  354.   { Time stuff }
  355.   TimeSeparator := ':';
  356.   TimeAMString := 'AM';
  357.   TimePMString := 'PM';
  358.   HF := 'hh';
  359.   // No support for 12 hour stuff at the moment...
  360.   ShortTimeFormat := HF + ':nn';
  361.   LongTimeFormat := HF + ':nn:ss';
  362.   { Currency stuff }
  363.   CurrencyString := '';
  364.   CurrencyFormat := 0;
  365.   NegCurrFormat := 0;
  366.   { Number stuff }
  367.   ThousandSeparator := ',';
  368.   DecimalSeparator := '.';
  369.   CurrencyDecimals := 2;
  370. end;
  371.  
  372. Procedure InitInternational;
  373. begin
  374.   InitInternationalGeneric;
  375.   GetFormatSettings;
  376. end;
  377.  
  378.  
  379. {****************************************************************************
  380.                            Target Dependent
  381. ****************************************************************************}
  382.  
  383. function SysErrorMessage(ErrorCode: Integer): String;
  384. const
  385.   MaxMsgSize = 255;
  386. var
  387.   MsgBuffer: PChar;
  388. begin
  389.   GetMem(MsgBuffer, MaxMsgSize);
  390.   FillChar(MsgBuffer^, MaxMsgSize, #0);
  391.   {TODO}
  392.   Result := StrPas(MsgBuffer);
  393.   FreeMem(MsgBuffer, MaxMsgSize);
  394. end;
  395.  
  396. {****************************************************************************
  397.                               Initialization code
  398. ****************************************************************************}
  399.  
  400. Function GetEnvironmentVariable(Const EnvVar: String): String;
  401. begin
  402.   Result := '';
  403. end;
  404.  
  405. Function GetEnvironmentVariableCount: Integer;
  406. begin
  407.   Result := 0;
  408. end;
  409.  
  410. Function GetEnvironmentString(Index : Integer) : String;
  411. begin
  412.   Result := '';
  413. end;
  414.  
  415. function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString): Integer;
  416. begin
  417.   Result := 0;
  418. end;
  419.  
  420. function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString): Integer;
  421. var
  422.   CommandLine: AnsiString;
  423.   i: Integer;
  424. begin
  425.   Commandline:='';
  426.   For i:=0 to high(ComLine) Do
  427.    Commandline:=CommandLine+' '+Comline[i];
  428.   ExecuteProcess:=ExecuteProcess(Path,CommandLine);
  429. end;
  430.  
  431. procedure Sleep(Milliseconds: Cardinal);
  432. begin
  433.   kos_delay(Milliseconds div 10);
  434. end;
  435.  
  436. function GetLastOSError: Integer;
  437. begin
  438.   Result := -1;
  439. end;
  440.  
  441.  
  442.  
  443. initialization
  444.   InitExceptions;
  445.   InitInternational;
  446. finalization
  447.   DoneExceptions;
  448. end.
  449.