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

📄 unitpas2html.pas

📁 图象处理的一些相关内容 不是很难的,实现简单,希望对大家有帮助
💻 PAS
字号:
unit UnitPas2Html;

interface
uses classes,Sysutils,comctrls, UnitParser,UnitKeywords;
type
  TPas2Html=class(TParser)
  private
    LastReserve:string;
    CurReserve:string;

  public
    procedure AddHead(AFileName:string);override;
    procedure AddTail(copyright:string); override;

    procedure getbc; override;
    function  IsLetter:boolean; override;
    function  IsDigit:boolean; override;
    function  IsReserve:boolean; override;
    procedure Convert(AProgressBar:TProgressBar);override;
    procedure BeginString; override;
    procedure EndString; override;
    procedure BeginKeyword; override;
    procedure EndKeyword; override;
    procedure BeginComment; override;
    procedure EndComment; override;
    procedure BeginDigit; override;
    procedure EndDigit; override;
    procedure BeginSymb; override;
    procedure EndSymb;override;
    procedure BeginIndint;override;
    procedure EndIndint; override;
    function  CovertSpecialCh(var s:string):boolean; override;
    constructor Create;
    destructor Destroy; override;

  protected

  end;



implementation

{ TPas2Html }

procedure TPas2Html.AddHead(AFileName: string);
begin
  outstr:='<html>'+#13#10+

        '<head>'+#13#10+
        '<meta http-equiv="Content-Language" content="en-us">'+#13#10+
        '<meta name="GENERATOR" content="Microsoft FrontPage 5.0">'+#13#10+
        '<meta name="ProgId" content="FrontPage.Editor.Document">'+#13#10+
        '<meta http-equiv="Content-Type" content="text/html; charset=gb2312">'+#13#10+
        '<title>'+ ExtractFileName(AFileName)+' </title>'+#13#10+
        '<link rel="stylesheet" href="style.css">'+#13#10+
        '</head>'+#13#10+


        '<BODY BGCOLOR="#FFFFFF">'+#13#10+
        '<font color=#0000FF>';
end;

procedure TPas2Html.AddTail(copyright: string);
begin
  outstr:=outstr+'</font>'+#13#10+#13#10+'<HR><CENTER<I><p>Created by ImageSee 1.0</p> '+#13#10+'<p> 作者:姜亮</p>'+#13#10+
                   '<p> E-mail:jiangliang@163.com</p>'+

                   '</CENTER></I>' +#13#10+'</BODY> </HTML>';
end;

procedure TPas2Html.BeginComment;
begin
  Outstr:=Outstr+ '<FONT COLOR="#000080"><I>';
end;

procedure TPas2Html.BeginDigit;
begin
  Outstr:=Outstr+'<FONT COLOR="#FF0000">';
end;

procedure TPas2Html.BeginIndint;
begin
   Outstr:=Outstr+'<FONT color="#0000FF">';
//
end;

procedure TPas2Html.BeginKeyword;
begin
  Outstr:=Outstr+ '<B><FONT COLOR="#000000">';
end;

procedure TPas2Html.BeginString;
begin
  Outstr:=Outstr+ '<FONT COLOR="#FF00FF">';
end;

procedure TPas2Html.BeginSymb;
begin
  Outstr:=Outstr+'<FONT COLOR="#008080">';
end;

procedure TPas2Html.Convert(AProgressBar: TProgressBar);
var
  SpecialStr:string;
//  a3_n:integer;
begin
 // a:=$78;
  LastReserve:='';
  CurReserve:='';


  try
    SrcFile:=TFileStream.Create(SrcFilename,fmOpenRead);
    getchar;
    token:='';

    AProgressBar.Visible:=true;
    AProgressBar.Max:=srcfile.Size;
    while srcfile.Position <srcfile.Size do
    begin
      getbc;

      case ch of
      'a'..'z','A'..'Z':
      begin    //begin case ch of  'a'..'z','A'..'Z':
        while  Isletter or Isdigit do
        begin
          concat;
          getchar;
        end;

        if IsReserve then
        begin
          LastReserve:=CurReserve;
          CurReserve:=token;
          if (LastReserve='end') and
          ((CurReserve='procedure') or (CurReserve='function')) then
          outstr:=outstr+'<hr>';

          BeginKeyWord;
          outstr:=outstr+token;
          EndKeyWord;
          token:='';
        end
        else
        begin
          BeginIndint;
          outstr:=outstr+token;
          EndIndint;
          token:='';
        end;

      end; //end case ch of  'a'..'z','A'..'Z':

      '0'..'9':
       begin  //begin case of   '0'..'9':
         while   Isdigit  do
         begin
           concat;
           getchar;
         end;
         BeginDigit;
         outstr:=outstr+token;
         EndDigit;
         token:='';
       end;   //end case of   '0'..'9':

       '=',    '+',    '-',    '_',    '*',    '>',

       '<',    ':',    ';',    ')',    '@',

       '.',    ',',    '[',    ']',    '^':

       begin
         BeginSymb;
         outstr:=outstr+ch;
         EndSymb;
         getchar;
         token:='';
       end;
       '$':
       begin
         BeginDigit;
         while ch in ['$','0'..'9','a'..'d','A'..'D'] do
         begin
           outstr:=outstr+ch;
           getchar;
         end;
         EndDigit;

       end;

       '#':
       begin
         BeginString;
         while ch in ['#','0'..'9'] do
         begin
           outstr:=outstr+ch;
           getchar;
         end;
         EndString;



       end;

       '{':
       begin  //begin case of '{':
         BeginComment;
         outstr:=outstr+ch;
         getchar;
         while ch<>'}' do
         begin
           if ch=#13 then
           begin
             outstr:=outstr+'<br>';
             getchar;
           end
           else
           begin
             if CovertSpecialCh(SpecialStr) then
               outstr:=outstr+SpecialStr
             else
               outstr:=outstr+ch;

             getchar;
           end;
         end;
         outstr:=outstr+ch;
         EndComment;
         getchar;
       end;   //end case of '{':
       '(':
       begin
         if NextCh='*' then
         begin
           BeginComment;
           repeat
             outstr:=outstr+ch;
             getchar;
           until (ch='*') and (Nextch=')');


           outstr:=outstr+ch;
           getchar;
           outstr:=outstr+ch;
           EndComment;
           getchar;


         end
         else
         begin
           BeginSymb;
           outstr:=outstr+ch;
           EndSymb;
           getchar;
           token:='';

         end;

       end;
       '/':
       begin
         if Nextch='/' then
         begin
           BeginComment;
           repeat
             if CovertSpecialCh(SpecialStr) then
               outstr:=outstr+SpecialStr
             else
               outstr:=outstr+ch;

             getchar;
           until (ch=#13);
           //跳过#10
           getchar;
           outstr:=outstr+'<br>';
           EndComment;
           getchar;

         end
         else
         begin
           BeginSymb;
           outstr:=outstr+ch;
           EndSymb;
           getchar;
           token:='';

         end;

       end;
       {
       #13:
       begin
         if NextCh=#10 then
         begin
           outstr:=outstr+'<br>');
           getchar;
           getchar;
         end;

       end;
       }
      // #10:;
       #39:
       begin   //begin #39
         BeginString;
         outstr:=outstr+ch;
         getchar;
         while ch<>#39 do
         begin
           if CovertSpecialCh(SpecialStr) then
           outstr:=outstr+SpecialStr
           else
           outstr:=outstr+ch;

           getchar;
         end;
         outstr:=outstr+ch;
         Endstring;
         getchar;
       end;    //end #39

       else
       begin
         //showmessage(inttostr(ord(ch)));
         outstr:=outstr+ch;
         getchar;
       end;

     end; //end case
     AProgressBar.Position:=srcfile.Position;
     //form1.ProgressBar1.Refresh;
     //showmessage('ProgressBar1.Position='+inttostr(form1.ProgressBar1.Position) );

    end;  //end srcfile.Position <srcfile.Size
  finally
    AddTail('sdaf');
    SrcFile.Free;
  end;

  try
    DesFile:=TFileStream.Create(DesFileName,fmopenwrite or fmcreate);

    DesFile.WriteBuffer (Pointer(outstr)^, Length (outstr));
  finally
    desfile.Free;
  end;
  AProgressBar.Visible:=false;

end;


function TPas2Html.CovertSpecialCh(var s: string): boolean;
begin
  result:=false;
  case ch of
  '<':
  begin
    s:='&lt;';
    result:=true;
  end;

  '>':
  begin
    s:='&gt;';
    result:=true;
  end;

  ' ':
  begin
    s:='&nbsp;';
    result:=true;
  end;

  end;  //end case

end;

constructor TPas2Html.Create;
begin
  FKeywords:=PascalKeywords;
end;

destructor TPas2Html.Destroy;
begin
  inherited;
  FKeywords:=nil;
end;

procedure TPas2Html.EndComment;
begin
  Outstr:=Outstr+ '</I></FONT>';
end;

procedure TPas2Html.EndDigit;
begin
  Outstr:=Outstr+'</FONT>';
end;

procedure TPas2Html.EndIndint;
begin
  Outstr:=Outstr+'</FONT>';
end;

procedure TPas2Html.EndKeyword;
begin
  Outstr:=Outstr+ '</B></font>';
end;

procedure TPas2Html.EndString;
begin
  Outstr:=Outstr+'</FONT>';
end;

procedure TPas2Html.EndSymb;
begin
  Outstr:=Outstr+'</FONT>';
end;

procedure TPas2Html.getbc;
begin
  while (ch=' ') or (ch=#13) do
  begin
    if ch=' ' then
      outstr:=outstr+'&nbsp;'
    else if ch=#13 then
    begin
      //跳过#10
      getchar;
      outstr:=outstr+'<br>';
    end;
    getchar;
  end;

end;

function TPas2Html.IsDigit: boolean;
begin
  if ch in['0'..'9']then
    result:=true
  else  result:=false
end;

function TPas2Html.IsLetter: boolean;
begin
  if (ch in ['a'..'z','A'..'Z','_']) then
  result:=true
  else  result:=false

end;

function TPas2Html.IsReserve: boolean;
begin
  if FKeywords.IndexOf(token)<0 then
    result:=false
  else
    result:=true;

  //
end;

end.

⌨️ 快捷键说明

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