mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-08 13:59:50 +02:00
jcf: sync with r764:
- Fix to 2130798 - Indentation strange on procedure local type/var declarations - Notepad UI has save and save as for input files, and remembers the file name - Fix to SF bug ID: 2490118 Parser exception with empty var section in a class - Fixed an issue in handling utf-8 encoded files git-svn-id: trunk@18246 -
This commit is contained in:
parent
841e7c90e9
commit
ce19796997
@ -230,6 +230,10 @@ object fmJCFNotepad: TfmJCFNotepad
|
|||||||
Caption = 'Save &Input'
|
Caption = 'Save &Input'
|
||||||
OnClick = mnuFileSaveInClick
|
OnClick = mnuFileSaveInClick
|
||||||
end
|
end
|
||||||
|
object mnuFileSaveInAs: TMenuItem
|
||||||
|
Caption = 'Save Input &as...'
|
||||||
|
OnClick = mnuFileSaveInAsClick
|
||||||
|
end
|
||||||
object N1: TMenuItem
|
object N1: TMenuItem
|
||||||
Caption = '-'
|
Caption = '-'
|
||||||
end
|
end
|
||||||
|
@ -37,7 +37,7 @@ uses
|
|||||||
{ JEDI }
|
{ JEDI }
|
||||||
JvMRUManager, JvMemo, JvComponent, JvExStdCtrls, JvFormPlacement, JvComponentBase,
|
JvMRUManager, JvMemo, JvComponent, JvExStdCtrls, JvFormPlacement, JvComponentBase,
|
||||||
{ local }
|
{ local }
|
||||||
JcfRegistrySettings, Converter, ConvertTypes;
|
JcfRegistrySettings, Converter, ConvertTypes, JcfUnicodeFiles;
|
||||||
|
|
||||||
{ have to do file pos display *after* various processing }
|
{ have to do file pos display *after* various processing }
|
||||||
const
|
const
|
||||||
@ -85,7 +85,7 @@ type
|
|||||||
mnuEditSelectAll: TMenuItem;
|
mnuEditSelectAll: TMenuItem;
|
||||||
mnuEditCopyMessages: TMenuItem;
|
mnuEditCopyMessages: TMenuItem;
|
||||||
mnuFormat: TMenuItem;
|
mnuFormat: TMenuItem;
|
||||||
mnuFileSaveIn: TMenuItem;
|
mnuFileSaveInAs: TMenuItem;
|
||||||
mnuHelp: TMenuItem;
|
mnuHelp: TMenuItem;
|
||||||
mnuHelpAbout: TMenuItem;
|
mnuHelpAbout: TMenuItem;
|
||||||
mnuShowRegSetting: TMenuItem;
|
mnuShowRegSetting: TMenuItem;
|
||||||
@ -93,6 +93,7 @@ type
|
|||||||
ActCut: TAction;
|
ActCut: TAction;
|
||||||
Contents1: TMenuItem;
|
Contents1: TMenuItem;
|
||||||
JvFormStorage1: TJvFormStorage;
|
JvFormStorage1: TJvFormStorage;
|
||||||
|
mnuFileSaveIn: TMenuItem;
|
||||||
procedure FormResize(Sender: TObject);
|
procedure FormResize(Sender: TObject);
|
||||||
procedure pcPagesChange(Sender: TObject);
|
procedure pcPagesChange(Sender: TObject);
|
||||||
procedure actGoExecute(Sender: TObject);
|
procedure actGoExecute(Sender: TObject);
|
||||||
@ -111,7 +112,7 @@ type
|
|||||||
procedure mnuEditCopyOutputClick(Sender: TObject);
|
procedure mnuEditCopyOutputClick(Sender: TObject);
|
||||||
procedure mnuEditSelectAllClick(Sender: TObject);
|
procedure mnuEditSelectAllClick(Sender: TObject);
|
||||||
procedure mnuEditCopyMessagesClick(Sender: TObject);
|
procedure mnuEditCopyMessagesClick(Sender: TObject);
|
||||||
procedure mnuFileSaveInClick(Sender: TObject);
|
procedure mnuFileSaveInAsClick(Sender: TObject);
|
||||||
procedure mnuHelpAboutClick(Sender: TObject);
|
procedure mnuHelpAboutClick(Sender: TObject);
|
||||||
procedure mnuShowRegSettingClick(Sender: TObject);
|
procedure mnuShowRegSettingClick(Sender: TObject);
|
||||||
procedure mnuFormatSettingsClick(Sender: TObject);
|
procedure mnuFormatSettingsClick(Sender: TObject);
|
||||||
@ -127,8 +128,11 @@ type
|
|||||||
procedure mInputClick(Sender: TObject);
|
procedure mInputClick(Sender: TObject);
|
||||||
procedure mOutputClick(Sender: TObject);
|
procedure mOutputClick(Sender: TObject);
|
||||||
procedure mInputKeyPress(Sender: TObject; var Key: char);
|
procedure mInputKeyPress(Sender: TObject; var Key: char);
|
||||||
|
procedure mnuFileSaveInClick(Sender: TObject);
|
||||||
private
|
private
|
||||||
fcConvert: TConverter;
|
fcConvert: TConverter;
|
||||||
|
fsLastInputFileName: string;
|
||||||
|
feLastInputContentType: TFileContentType;
|
||||||
|
|
||||||
procedure OnConvertStatusMessage(const psUnit, psMessage: string;
|
procedure OnConvertStatusMessage(const psUnit, psMessage: string;
|
||||||
const peMessageType: TStatusMessageType;
|
const peMessageType: TStatusMessageType;
|
||||||
@ -137,6 +141,10 @@ type
|
|||||||
procedure CheckInputState;
|
procedure CheckInputState;
|
||||||
procedure CheckCutPasteState;
|
procedure CheckCutPasteState;
|
||||||
procedure DoFileOpen(const psFileName: string);
|
procedure DoFileOpen(const psFileName: string);
|
||||||
|
procedure SaveInputToFile(const psFileName: string);
|
||||||
|
|
||||||
|
procedure CheckSaveEnabled;
|
||||||
|
|
||||||
procedure AddCheckMRU(const psFile: string);
|
procedure AddCheckMRU(const psFile: string);
|
||||||
|
|
||||||
procedure ShowFilePos;
|
procedure ShowFilePos;
|
||||||
@ -157,7 +165,7 @@ uses
|
|||||||
{ jcl }
|
{ jcl }
|
||||||
JclStrings,
|
JclStrings,
|
||||||
{ local }
|
{ local }
|
||||||
JcfUnicodeFiles, JcfStringUtils,
|
JcfStringUtils,
|
||||||
JCFHelp, fAbout, fRegistrySettings, fAllSettings, JcfFontSetFunctions;
|
JCFHelp, fAbout, fRegistrySettings, fAllSettings, JcfFontSetFunctions;
|
||||||
|
|
||||||
{$ifdef FPC}
|
{$ifdef FPC}
|
||||||
@ -172,6 +180,11 @@ begin
|
|||||||
actClear.Enabled := (mInput.Text <> '');
|
actClear.Enabled := (mInput.Text <> '');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TfmJCFNotepad.CheckSaveEnabled;
|
||||||
|
begin
|
||||||
|
mnuFileSaveIn.Enabled := (fsLastInputFileName <> '');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TfmJCFNotepad.CheckCutPasteState;
|
procedure TfmJCFNotepad.CheckCutPasteState;
|
||||||
var
|
var
|
||||||
lbHasOutput: boolean;
|
lbHasOutput: boolean;
|
||||||
@ -192,7 +205,6 @@ end;
|
|||||||
procedure TfmJCFNotepad.DoFileOpen(const psFileName: string);
|
procedure TfmJCFNotepad.DoFileOpen(const psFileName: string);
|
||||||
var
|
var
|
||||||
lsFileContents: WideString;
|
lsFileContents: WideString;
|
||||||
leContentType: TFileContentType;
|
|
||||||
begin
|
begin
|
||||||
if psFileName = '' then
|
if psFileName = '' then
|
||||||
exit;
|
exit;
|
||||||
@ -201,7 +213,7 @@ begin
|
|||||||
|
|
||||||
GetRegSettings.InputDir := ExtractFilePath(psFileName);
|
GetRegSettings.InputDir := ExtractFilePath(psFileName);
|
||||||
|
|
||||||
ReadTextFile(psFileName, lsFileContents, leContentType);
|
ReadTextFile(psFileName, lsFileContents, feLastInputContentType);
|
||||||
|
|
||||||
// use standard line breaks - temp
|
// use standard line breaks - temp
|
||||||
//lsFileContents := WideStringReplace(lsFileContents, NativeLineFeed, NativeCrLf, [rfReplaceAll]);
|
//lsFileContents := WideStringReplace(lsFileContents, NativeLineFeed, NativeCrLf, [rfReplaceAll]);
|
||||||
@ -212,6 +224,28 @@ begin
|
|||||||
|
|
||||||
CheckInputState;
|
CheckInputState;
|
||||||
SendShowFilePos;
|
SendShowFilePos;
|
||||||
|
CheckSaveEnabled;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TfmJCFNotepad.SaveInputToFile(const psFileName: string);
|
||||||
|
begin
|
||||||
|
if psFileName = '' then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
// default the file type to utf-8 if it's not known
|
||||||
|
if feLastInputContentType = eUnknown then
|
||||||
|
begin
|
||||||
|
feLastInputContentType := eUtf8;
|
||||||
|
end;
|
||||||
|
|
||||||
|
WriteTextFile(psFileName, mInput.Text, feLastInputContentType);
|
||||||
|
|
||||||
|
|
||||||
|
sb1.Panels[1].Text := 'Saved input as ' + psFileName;
|
||||||
|
AddCheckMRU(psFileName);
|
||||||
|
|
||||||
|
fsLastInputFileName := psFileName;
|
||||||
|
CheckSaveEnabled;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TfmJCFNotepad.AddCheckMRU(const psFile: string);
|
procedure TfmJCFNotepad.AddCheckMRU(const psFile: string);
|
||||||
@ -355,6 +389,11 @@ begin
|
|||||||
mruFiles.RemoveInvalid;
|
mruFiles.RemoveInvalid;
|
||||||
|
|
||||||
pcPages.ActivePage := tsInput;
|
pcPages.ActivePage := tsInput;
|
||||||
|
|
||||||
|
feLastInputContentType := eUnknown;
|
||||||
|
fsLastInputFileName := '';
|
||||||
|
|
||||||
|
CheckSaveEnabled;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TfmJCFNotepad.FormDestroy(Sender: TObject);
|
procedure TfmJCFNotepad.FormDestroy(Sender: TObject);
|
||||||
@ -423,6 +462,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TfmJCFNotepad.mnuFileSaveInClick(Sender: TObject);
|
procedure TfmJCFNotepad.mnuFileSaveInClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
if fsLastInputFileName <> '' then
|
||||||
|
begin
|
||||||
|
SaveInputToFile(fsLastInputFileName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TfmJCFNotepad.mnuFileSaveInAsClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
SaveDialog1.InitialDir := GetRegSettings.OutputDir;
|
SaveDialog1.InitialDir := GetRegSettings.OutputDir;
|
||||||
SaveDialog1.Title := 'Save input file';
|
SaveDialog1.Title := 'Save input file';
|
||||||
@ -431,9 +480,8 @@ begin
|
|||||||
if SaveDialog1.Execute then
|
if SaveDialog1.Execute then
|
||||||
begin
|
begin
|
||||||
GetRegSettings.OutputDir := ExtractFilePath(SaveDialog1.FileName);
|
GetRegSettings.OutputDir := ExtractFilePath(SaveDialog1.FileName);
|
||||||
StringToFile(SaveDialog1.FileName, AnsiString(mInput.Text));
|
|
||||||
sb1.Panels[1].Text := 'Saved input as ' + SaveDialog1.FileName;
|
SaveInputToFile(SaveDialog1.FileName);
|
||||||
AddCheckMRU(SaveDialog1.FileName);
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -2198,10 +2198,12 @@ begin
|
|||||||
// VarSection -> VAR (VarDecl ';')...
|
// VarSection -> VAR (VarDecl ';')...
|
||||||
Recognise([ttVar, ttThreadvar]);
|
Recognise([ttVar, ttThreadvar]);
|
||||||
|
|
||||||
repeat
|
// can be enpty
|
||||||
|
while not (fcTokenList.FirstSolidTokenType in leEndVarSection) do
|
||||||
|
begin
|
||||||
RecogniseVarDecl;
|
RecogniseVarDecl;
|
||||||
Recognise(ttSemicolon);
|
Recognise(ttSemicolon);
|
||||||
until (fcTokenList.FirstSolidTokenType in leEndVarSection);
|
end;
|
||||||
|
|
||||||
PopNode;
|
PopNode;
|
||||||
end;
|
end;
|
||||||
|
@ -110,6 +110,23 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function InGlobalTypeOrVarSection(const pt: TSourceToken): Boolean;
|
||||||
|
begin
|
||||||
|
// are we in a type or var section?
|
||||||
|
if not pt.HasParentNode([nTypeSection, nVarSection]) then
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if pt.HasParentNode([nProcedureDecl, nFunctionDecl, nConstructorDecl, nDestructorDecl]) then
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
|
||||||
function IsIndented(const pt: TSourceToken): Boolean;
|
function IsIndented(const pt: TSourceToken): Boolean;
|
||||||
begin
|
begin
|
||||||
@ -573,7 +590,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
if pt.HasParentNode([nLibrary, nProgram]) and (liIndentCount >= 1) then
|
if pt.HasParentNode([nLibrary, nProgram]) and (liIndentCount >= 1) then
|
||||||
begin
|
begin
|
||||||
if not pt.HasParentNode([nExports, nUses, nTypeSection, nVarSection]) then
|
if not pt.HasParentNode([nExports, nUses]) and (not InGlobalTypeOrVarSection(pt)) then
|
||||||
begin
|
begin
|
||||||
if pt.HasParentNode([nCompoundStatement]) and not pt.HasParentNode([nDeclSection]) then
|
if pt.HasParentNode([nCompoundStatement]) and not pt.HasParentNode([nDeclSection]) then
|
||||||
begin
|
begin
|
||||||
|
@ -172,6 +172,29 @@ begin
|
|||||||
Result := WideString(lsContents8bit);
|
Result := WideString(lsContents8bit);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function ReadUtf8File(const pcFileStream: TFileStream): WideString;
|
||||||
|
var
|
||||||
|
liBytesRemaining: integer;
|
||||||
|
lsContents: AnsiString;
|
||||||
|
begin
|
||||||
|
liBytesRemaining := pcFileStream.Size - pcFileStream.Position;
|
||||||
|
// read the bytes into a string
|
||||||
|
SetLength(lsContents, liBytesRemaining);
|
||||||
|
if pcFileStream.Size > 0 then
|
||||||
|
begin
|
||||||
|
pcFileStream.ReadBuffer(lsContents[1], liBytesRemaining);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// convert to wide string
|
||||||
|
{$IFDEF DELPHI12}
|
||||||
|
Result := UTF8ToWideString(lsContents);
|
||||||
|
{$ELSE}
|
||||||
|
Result := UTF8Decode(lsContents);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function Read16BitFile(const pcFileStream: TFileStream; const pbBigEndian: boolean): WideString;
|
function Read16BitFile(const pcFileStream: TFileStream; const pbBigEndian: boolean): WideString;
|
||||||
var
|
var
|
||||||
liBytesRemaining: integer;
|
liBytesRemaining: integer;
|
||||||
@ -258,10 +281,15 @@ begin
|
|||||||
ReadPastFileHeader(fs, peContentType);
|
ReadPastFileHeader(fs, peContentType);
|
||||||
|
|
||||||
case peContentType of
|
case peContentType of
|
||||||
e8Bit, eUtf8:
|
e8Bit:
|
||||||
psContents := Read8BitFile(fs);
|
psContents := Read8BitFile(fs);
|
||||||
|
|
||||||
|
eUtf8:
|
||||||
|
psContents := ReadUtf8File(fs);
|
||||||
|
|
||||||
eUtf16LittleEndian, eUtf16BigEndian:
|
eUtf16LittleEndian, eUtf16BigEndian:
|
||||||
psContents := Read16BitFile(fs, peContentType = eUtf16BigEndian);
|
psContents := Read16BitFile(fs, peContentType = eUtf16BigEndian);
|
||||||
|
|
||||||
eUtf32LittleEndian, eUtf32BigEndian:
|
eUtf32LittleEndian, eUtf32BigEndian:
|
||||||
psContents := Read32BitFile(fs, peContentType = eUtf32BigEndian);
|
psContents := Read32BitFile(fs, peContentType = eUtf32BigEndian);
|
||||||
else
|
else
|
||||||
@ -275,24 +303,37 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{ this is one of the few cases when "AnsiString" must be used }
|
{ this is one of the few cases when "AnsiString" must be used }
|
||||||
procedure Write8BitFile(const pcFileStream: TFileStream;
|
procedure Write8BitFile(const pcFileStream: TFileStream; const psContents: WideString);
|
||||||
const psContents: WideString; const pbUtf8Header: boolean);
|
var
|
||||||
|
Len: integer;
|
||||||
|
lsContents: AnsiString;
|
||||||
|
begin
|
||||||
|
lsContents := AnsiString(psContents);
|
||||||
|
|
||||||
|
Len := Length(lsContents);
|
||||||
|
|
||||||
|
if Len > 0 then
|
||||||
|
begin
|
||||||
|
pcFileStream.WriteBuffer(lsContents[1], Len);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ this is one of the few cases when "AnsiString" must be used }
|
||||||
|
procedure WriteUtf8File(const pcFileStream: TFileStream; const psContents: WideString);
|
||||||
var
|
var
|
||||||
Len: integer;
|
Len: integer;
|
||||||
lsContents: AnsiString;
|
lsContents: AnsiString;
|
||||||
utf8Header: array [0..2] of byte;
|
utf8Header: array [0..2] of byte;
|
||||||
begin
|
begin
|
||||||
lsContents := AnsiString(psContents);
|
lsContents := UTF8Encode(psContents);
|
||||||
|
|
||||||
Len := Length(lsContents);
|
Len := Length(lsContents);
|
||||||
|
|
||||||
if pbUtf8Header then
|
// write the BOM
|
||||||
begin
|
utf8Header[0] := Utf8Marker1;
|
||||||
// write the BOM
|
utf8Header[1] := Utf8Marker2;
|
||||||
utf8Header[0] := Utf8Marker1;
|
utf8Header[2] := Utf8Marker3;
|
||||||
utf8Header[1] := Utf8Marker2;
|
pcFileStream.WriteBuffer(utf8Header[0], 3);
|
||||||
utf8Header[2] := Utf8Marker3;
|
|
||||||
pcFileStream.WriteBuffer(utf8Header[0], 3);
|
|
||||||
end;
|
|
||||||
|
|
||||||
if Len > 0 then
|
if Len > 0 then
|
||||||
begin
|
begin
|
||||||
@ -386,9 +427,14 @@ var
|
|||||||
try
|
try
|
||||||
|
|
||||||
case peContentType of
|
case peContentType of
|
||||||
e8Bit, eUtf8:
|
e8Bit:
|
||||||
begin
|
begin
|
||||||
Write8BitFile(fs, psContents, peContentType = eUtf8);
|
Write8BitFile(fs, psContents);
|
||||||
|
end;
|
||||||
|
|
||||||
|
eUtf8:
|
||||||
|
begin
|
||||||
|
WriteUtf8File(fs, psContents);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
eUtf16LittleEndian, eUtf16BigEndian:
|
eUtf16LittleEndian, eUtf16BigEndian:
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
This directory contains a copy (sometimes modified) of r746 jcf2 svn tree: https://jedicodeformat.svn.sourceforge.net/svnroot/jedicodeformat/trunk/CodeFormat/Jcf2
|
This directory contains a copy (sometimes modified) of r764 jcf2 svn tree: https://jedicodeformat.svn.sourceforge.net/svnroot/jedicodeformat/trunk/CodeFormat/Jcf2
|
||||||
|
|
||||||
Only command line utility works currently.
|
Only command line utility works currently.
|
Loading…
Reference in New Issue
Block a user