⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filedrv.pas

📁 Draak is a multi-language, macro compiler, meaning all syntax and code generation is defined in a si
💻 PAS
字号:
(* filedrv.pas: Please see the end of Draak.pas for copyright information     *)
(* This file may NOT be distributed without Draak.pas and is under the same   *)
(* licence agreement as Draak.pas.                                            *)
unit filedrv;

interface

uses Sysutils, classes;

type
  PFile = ^TFile;
  TFile = class
    private
      inFile: integer;
      Handle: THandle;
      enlin: char;
      enof: boolean;
      closed: boolean;
      FlineCount: cardinal;
      initF: function (f: PChar): integer; stdcall;
      readCharF: function (f: integer): char; stdcall;
      closeF: procedure (f: integer); stdcall;
    public
      property lineCount: cardinal read FlineCount;
      constructor init(inF: string);
      function getLine: string;
      function eof: boolean;
  end;

implementation

{$ifdef MSWindows}
uses windows;
  const preprocess = 'preprocess.dll';
{$Endif}
{$ifdef Linux}
  const preprocess = 'libpreprocess.so';
{$Endif}

constructor TFile.init(inF: string);
var s: PChar;
begin
  s := AnsiStrRScan(PChar(inF), '.')+1;
  if s = 'gmr' then
    s := preprocess
  else
    s := PChar(s+PathDelim+preprocess);
  Handle := LoadLibrary(s);
  if Handle = 0 then
  begin
    Handle := LoadLibrary(preprocess);
    if Handle = 0 then
      Raise EInOutError.Create('Could not load any preprocess driver for: '+s);
  end;
  @initF := GetProcAddress(Handle, 'init');
  @readCharF := GetProcAddress(Handle, 'readChar');
  @closeF := GetProcAddress(Handle, 'close');

  inFile := initF(PChar(inF));
  enLin := #13;
  enof := false;
  closed := false;
end;

function TFile.getLine: string;
var i: char;
  o: char;
  space: boolean;
procedure callrcf;
begin
      o := readCharF(inFile);
end;
begin
  i := #0; result := ''; space := true;
  repeat
    while i <> enLin do
    begin
callrcf;
      i := o;
      if o = #0 then
      begin
        enof := true;
        exit;
      end;
     	if i < #32 then
      begin
	      if space = true then
      	  continue
    	  else
  	      space := true;
        result := result + ' ';
        continue;
      end;
  	  if i = #32 then
	      if space = true then
      	  continue
    	  else
  	      space := true
	    else
    	  space := false;
      result := result + char(i);
    end;
    inc(FlineCount);
    if (i = enLin) AND (result = '') then
    begin
      o := readCharF(inFile);
      i := o;
      if o = #0 then
      begin
        enof := true;
        exit;
      end;
    end;
  until result <> '';
end;

function TFile.eof: boolean;
begin
  if enof = true then
  begin
    if closed <> true then
    begin
      closeF(inFile);
      FreeLibrary(Handle);
      closed := true;
    end;
  end;
  result := enof;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -