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

📄 dpp_preprocess.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      for i := 0 to FIncFiles.Count - 1 do
        DeleteFile(FIncFiles.Strings[i]);
    end;
  finally
    FFilenameMapper.Clear;
    FVirtualFileList.Clear;
    FPasFiles.Clear;
    FIncFiles.Clear;
    FFileInfos.Clear;
  end;
end;

procedure TPreProcessor.EvError(Sender: TObject; const Filename,
  Msg: string; LineNum: Integer);
var s: string;
begin
  if Assigned(FOnErrorWarningEx) then
  begin
    FOnErrorWarningEx(Self, True, Filename, Msg, LineNum);
  end
  else
  begin
    s := Format('Error in %s (%d): %s', [ExtractFileName(Filename), LineNum, Msg]);
    if Assigned(FOnError) then
      FOnError(Self, s)
    else
      WriteLn(ErrOutput, s);
  end;
end;

procedure TPreProcessor.EvWarning(Sender: TObject; const Filename,
  Msg: string; LineNum: Integer);
var s: string;
begin
  if Assigned(FOnErrorWarningEx) then
  begin
    FOnErrorWarningEx(Self, False, Filename, Msg, LineNum);
  end
  else
  begin
    s := Format('Warning in %s (%d): %s', [ExtractFileName(Filename), LineNum, Msg]);
    if Assigned(FOnError) then
      FOnWarning(Self, s)
    else
      WriteLn(ErrOutput, s);
  end;
end;

procedure TPreProcessor.EvPredefineMacros(Sender: TObject);
begin
 // not implemented yet

{TODO allow user pre-defined macros}
// FMacros.RegisterMacro('');
end;

procedure TPreProcessor.EvDefaultConditionals(Sender: TObject);
var i: Integer;
begin
  for i := 0 to FConditionals.Count - 1 do
    FMacros.Define(FConditionals.Strings[i]);
end;

{ TMacroFileSys }

constructor TMacroFileSys.Create(PreProcessor: TPreProcessor);
begin
  inherited Create;
  FPreProcessor := PreProcessor;
end;

procedure TMacroFileSys.BeforeFile(const Filename: string; IsIncludeFile: Boolean);
begin
  // do nothing
end;

procedure TMacroFileSys.AfterFile(const Filename,
  NewFilename: string; IsIncludeFile, Modified: Boolean);
begin
 // do nothing
end;

procedure TMacroFileSys.LoadFile(const Filename: string;
  out Content: string; IsIncludeFile: Boolean);
begin
  with FPreProcessor do
  begin
    if FFileSys.IsVirtualFile(Filename) then
    begin
      FFileSys.GetVirtualFileContent(Filename, Content);
      if (FCompilePrepare) and not (IsIncludeFile) then
        StringToFile(ChangeFileExt(Filename, '.dpp'), Content); // backup
      FVirtualFileList.Add(Filename);
    end
    else
    begin
      if (FCompilePrepare) then FFileInfos.SaveInfos(Filename);
      FileToString(Filename, Content);
    end;
  end; // with
end;

procedure TMacroFileSys.SaveFile(const Filename: string;
  var NewFilename: string; const Content: string; IsIncludeFile: Boolean);
var dpp: string;
begin
  with FPreProcessor do
  begin
    if IsIncludeFile then
      FIncFiles.Add(NewFilename)  // save include file name for later deletion
    else
      FPasFiles.Add(Filename);    // save unit file name for later restore

    if (not FCompilePrepare) then
    begin
      StringToFile(NewFilename, Content); // store virtual files to disk too
      Exit;
     // --------
    end;

    if (IsIncludeFile) then
    begin
      StringToFile(NewFilename, Content);
    end
    else
    begin
      if FFileSys.IsVirtualFile(Filename) then
      begin
       // Replace edit buffer's content. The original content is stored in a .dpp
       // file.
        FFileSys.SetVirtualFileContent(Filename, Content);
      end
      else
      begin
        dpp := ChangeFileExt(Filename, '.dpp');
        NewFilename := Filename; // save .i as .pas

       // .pas -> .dpp  <-- backup file
        if not MoveFile(Filename, dpp) then
          raise Exception.CreateFmt(SErrorMovingFile, [Filename, dpp]);

       // store content
        StringToFile(NewFilename, Content);
       // set file times and attributes to origial one's
        FFileInfos.RestoreInfos(Filename);
      end;
    end;
  end; // with
end;

function TMacroFileSys.ExTestFilename(const Filename: string): Boolean;
begin
  Result := FPreProcessor.FFileSys.IsVirtualFile(Filename);
end;

function TMacroFileSys.FindFile(const Filename: string; IsIncludeFile: Boolean): string;
begin
  with FPreProcessor do
  begin
   // is the file already mapped?
    if FFilenameMapper.FindFilename(Filename, Result) then Exit;

    Result := Filename;
    if ExtractFilePath(Result) = '' then
    begin
      if IsIncludeFile then
        Result := TestFilenames(FIncludePaths, Result, ExTestFilename)
      else
        Result := TestFilenames(FUnitPaths, Result, ExTestFilename);
    end
    else
    begin
      if Pos('.' + PathDelim, Result) > 0 then // relative path
        Result := FollowRelativePath(FProjectPath, Result);
      if not Self.FileExists(Result) then Result := '';
    end;
    FFilenameMapper.AddFilename(Filename, Result);
  end; // with
end;

function TMacroFileSys.FileExists(const Filename: string): Boolean;
begin
  with FPreProcessor do
  begin
    Result := (FFileSys.IsVirtualFile(Filename)) or (FileExistsX(Filename));
  end; // with
end;

procedure TMacroFileSys.LinesMoved(const Filename: string; LineNum, AddedLines: Integer);
begin
  with FPreProcessor do
  begin
//    if FFileSys.IsVirtualFile(Filename) then
      FFileSys.AdjustLines(Filename, LineNum, AddedLines);
  end;
end;


{ TNoVirtualFileSys }

procedure TNoVirtualFileSys.AdjustLines(const Filename: string; LineNum,
  Count: Integer);
begin
//  WriteLn('Filename: ', Filename, ' --- ', LineNum, ' +', Count);
end;

procedure TNoVirtualFileSys.GetVirtualFileContent(const Filename: string;
  out Content: string);
begin
end;

procedure TNoVirtualFileSys.InitPreProcessorFileSys;
begin
end;

function TNoVirtualFileSys.IsVirtualFile(const Filename: string): Boolean;
begin
  Result := False;
end;

procedure TNoVirtualFileSys.RestoreVirtualFileContent(const Filename: string;
  const BackupedContent: string);
begin
end;

procedure TNoVirtualFileSys.SetVirtualFileContent(const Filename, Content: string);
begin
end;

end.

⌨️ 快捷键说明

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