From 25c58a81ca9202af54d28888d2b068ebeb2a376f Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 15 Jun 2008 11:42:49 +0200 Subject: Portability fixes --- Makefile | 1 - UConfig.pas | 11 ++++---- UCoreUtils.pas | 86 ++++++++++++++++++++++++++++++++------------------------ UEngines.pas | 4 +-- UGnome.pas | 14 ++++----- ULibc.pas | 9 ------ UMain.pas | 2 +- USearch.pas | 18 ++++++------ tuxcmd.dpr | 4 +-- vfs/UVFSCore.pas | 13 ++------- 10 files changed, 78 insertions(+), 84 deletions(-) diff --git a/Makefile b/Makefile index 10ff1a5..cd72bc1 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,6 @@ tuxcmd:: echo " ConstFPCTargetOSString = '`fpc -iTO`';" >> fpcver.inc echo " ConstFPCTargetProcessorString = '`fpc -iTP`';" >> fpcver.inc fpc -Mdelphi $(CFLAGS) \ - -d__FPC__ \ -Fu./libgtk_kylix -Fu./translations -Fu./vfs \ tuxcmd.dpr diff --git a/UConfig.pas b/UConfig.pas index 4dd13aa..034fd11 100644 --- a/UConfig.pas +++ b/UConfig.pas @@ -25,10 +25,10 @@ uses Classes, ULocale; resourcestring ConstAppTitle = 'Tux Commander'; - ConstAboutVersion = '0.6.43-dev'; - ConstAboutBuildDate = '2008-06-14'; + ConstAboutVersion = '0.6.44-dev'; + ConstAboutBuildDate = '2008-06-15'; -{$IFDEF __FPC__} +{$IFDEF FPC} {$INCLUDE fpcver.inc} {$ENDIF} @@ -1121,9 +1121,10 @@ end; initialization SetDefaults; ParseCMDLine; - {$IFDEF __FPC__} + {$IFDEF FPC} DebugMsg(['Tux Commander v', ConstAboutVersion, ' [', ConstAboutBuildDate, '] FreePascal build ', - '(version ', ConstFPCVersionString, ' ', ConstFPCDateString, ', define ', {$IFDEF CPU64}'x86_64'{$ELSE}'i386'{$ENDIF}, + '(version ', ConstFPCVersionString, ' ', ConstFPCDateString, ', define ', + {$IFDEF CPU64} {$IFDEF ENDIAN_LITTLE}'x86_64'{$ELSE}'ppc64'{$ENDIF} {$ELSE} {$IFNDEF CPUPOWERPC}'i386'{$ELSE}'ppc' {$ENDIF} {$ENDIF}, ', compiled on ', ConstFPCCompilerOSString, '/', ConstFPCCompilerHostProcessorString, ' for ', ConstFPCTargetOSString, '/', ConstFPCTargetProcessorString, ')']); {$ELSE} diff --git a/UCoreUtils.pas b/UCoreUtils.pas index ed43589..0bccb8b 100644 --- a/UCoreUtils.pas +++ b/UCoreUtils.pas @@ -112,10 +112,7 @@ procedure SetupColors; function ConstructURI(HidePasswd: boolean; Protocol, Server, Username, Password, Dir: string): string; function URIHidePassword(const SrcURI: string): string; -{$IFDEF __FPC__} -function StrToDateDef(const S: string; const Default: TDateTime): TDateTime; -function UnixToDateTime(const AValue: Int64): TDateTime; -{$ENDIF} +function StrTotimetDef(const S: string; const Default: time_t): time_t; procedure SaveItemToHistory(s: string; History: TStringList); @@ -1053,6 +1050,9 @@ begin vtCurrency: Write(ErrOutput, CurrToStr(VCurrency^)); vtVariant: Write(ErrOutput, string(VVariant^)); vtInt64: Write(ErrOutput, IntToStr(VInt64^)); +{$IFDEF FPC} + vtQWord: Write(ErrOutput, IntToStr(VQWord^)); +{$ENDIF} end; WriteLn(ErrOutput); end; @@ -1061,9 +1061,8 @@ end; (********************************************************************************************************************************) function SpawnProcess(const AppPath: string; var Running: boolean; const Parameters: array of string): Cardinal; var child_pid: __pid_t; - args_list: System.PPChar; + args_list: PPChar; i: integer; - Temp: string; sv: sigval_t; begin Result := 0; @@ -1073,16 +1072,12 @@ begin // Make the args_list array args_list := nil; if Length(Parameters) > 0 then begin - args_list := malloc((Length(Parameters) + 1) * SizeOf(PChar)); - memset(args_list, 0, (Length(Parameters) + 1) * SizeOf(PChar)); + args_list := malloc((Length(Parameters) + 1) * sizeof(PChar)); + memset(args_list, 0, (Length(Parameters) + 1) * sizeof(PChar)); for I := 0 to Length(Parameters) - 1 do begin - Temp := Parameters[i]; {$R-} -// PCharArray(args_list^)[I] := malloc(Length(Temp)+1); -// memset(PCharArray(args_list^)[I], 0, Length(Temp)+1); -// StrCopy(PCharArray(args_list^)[I], PChar(Temp)); - PCharArray(args_list^)[I] := strdup(PChar(Temp)); + PCharArray(args_list^)[I] := strdup(PChar(Parameters[i])); {$R+} end; {$R-} @@ -1095,6 +1090,11 @@ begin if child_pid <> 0 then begin Result := child_pid; Sleep(100); + //* FIXME: strange behaviour when freed +{ for i := 0 to Length(Parameters) - 1 do + if PCharArray(args_list^)[i] <> nil then + libc_free(PCharArray(args_list^)[i]); } + if args_list <> nil then libc_free(args_list); Application.ProcessMessages; Running := ChildExitStatus < 0; if not Running then Result := 0; @@ -1211,7 +1211,7 @@ end; (********************************************************************************************************************************) function IsItX11App(const Application: string): boolean; -const BSize = 32768; +const BSize = 65536; What = 'libX11.so'; var stream: PFILE; Buffer: Pointer; @@ -1242,6 +1242,8 @@ begin end; end; pclose(stream); + libc_free(Buffer); + SetLength(str, 0); end; // unsetenv('LD_TRACE_LOADED_OBJECTS'); @@ -1252,7 +1254,7 @@ begin end; function HandleSystemCommand(const Command, ErrorText: string): boolean; -const BSize = 32768; +const BSize = 65536; var stream: PFILE; Buffer: Pointer; i, NumRead: integer; @@ -1277,9 +1279,9 @@ begin libc_close(fds[1]); stream := fdopen(fds[0], 'r'); Buffer := malloc(BSize); - DebugMsg(['x0']); +// DebugMsg(['x0']); memset(Buffer, 0, BSize); - DebugMsg(['x1']); +// DebugMsg(['x1']); if buffer = nil then Writeln('buffer nil: ', integer(errno)); if stream = nil then Writeln('stream nil'); @@ -1293,12 +1295,12 @@ begin end; end; libc_close(fds[0]); - DebugMsg(['x2']); +// DebugMsg(['x2']); TrimCRLFESC(s); - DebugMsg(['x3']); +// DebugMsg(['x3']); - free(Buffer); - DebugMsg(['x4']); + libc_free(Buffer); +// DebugMsg(['x4']); end // forked PID @@ -1338,6 +1340,7 @@ begin Result := Length(s) = 0; if not Result then Application.MessageBox(Format('%s%s', [ErrorText, StrToUTF8(s)]), [mbOK], mbError, mbOK, mbOK); + SetLength(s, 0); except on E: Exception do DebugMsg(['***** function HandleSystemCommand(''', Command, '''):Exception: ', E.Message]); end; @@ -1549,6 +1552,12 @@ begin Result := 0; end; {$ELSE} +{$IFDEF CPUPOWERPC} +function CRC32(CRC: LongWord; Data: Pointer; DataSize: LongWord): LongWord; +begin + Result := 0; +end; +{$ELSE} function CRC32(CRC: LongWord; Data: Pointer; DataSize: LongWord): LongWord; assembler; asm AND EDX,EDX @@ -1639,6 +1648,7 @@ asm DD 06E656761h, 064655220h, 06E616D64h, 06FBBA36Eh end; {$ENDIF} +{$ENDIF} (********************************************************************************************************************************) constructor THash_MD5.Create; begin @@ -1738,6 +1748,12 @@ begin Result := nil; end; {$ELSE} +{$IFDEF CPUPOWERPC} +function THash_MD5.TestVector: Pointer; +begin + Result := nil; +end; +{$ELSE} function THash_MD5.TestVector: Pointer; asm MOV EAX,OFFSET @Vector @@ -1746,6 +1762,7 @@ asm DB 075h,05Dh,04Bh,0C9h,0FEh,0DCh,0C2h,0C6h end; {$ENDIF} +{$ENDIF} {$Q-} procedure THash_MD5.Transform(Buffer: PIntArray); @@ -1921,12 +1938,15 @@ end; procedure ReportGTKVersion; begin - if Application.GTKVersion_2_8_0_Up then DebugMsg(['Using GTK+ version >= 2.8.0']) else - if Application.GTKVersion_2_6_0_Up then DebugMsg(['Using GTK+ version >= 2.6.0']) else - if Application.GTKVersion_2_4_0_Up then DebugMsg(['Using GTK+ version >= 2.4.0']) else - if Application.GTKVersion_2_2_0_Up then DebugMsg(['Using GTK+ version >= 2.2.0']) else - if Application.GTKVersion_2_0_5_Up then DebugMsg(['Using GTK+ version >= 2.0.5']) else - DebugMsg(['Using GTK+ version < 2.0.5']); +{$IFDEF FPC} + DebugMsg(['Reported GTK version: ', gtk_major_version, '.', gtk_minor_version, '.', gtk_micro_version]); +{$ENDIF} + if Application.GTKVersion_2_8_0_Up then DebugMsg(['Using quirks for GTK+ >= 2.8.0']) else + if Application.GTKVersion_2_6_0_Up then DebugMsg(['Using quirks for GTK+ >= 2.6.0']) else + if Application.GTKVersion_2_4_0_Up then DebugMsg(['Using quirks for GTK+ >= 2.4.0']) else + if Application.GTKVersion_2_2_0_Up then DebugMsg(['Using quirks for GTK+ >= 2.2.0']) else + if Application.GTKVersion_2_0_5_Up then DebugMsg(['Using quirks for GTK+ >= 2.0.5']) else + DebugMsg(['Using quirks for GTK+ < 2.0.5']); end; @@ -1980,23 +2000,15 @@ end; (********************************************************************************************************************************) -{$IFDEF __FPC__} -function StrToDateDef(const S: string; const Default: TDateTime): TDateTime; +function StrTotimetDef(const S: string; const Default: time_t): time_t; begin try - Result := StrToDate(S); + Result := DateTimeToUnix(StrToDate(S)); except Result := Default; end; end; - -function UnixToDateTime(const AValue: Int64): TDateTime; -begin - Result := AValue / SecsPerDay + UnixDateDelta; -end; -{$ENDIF} - (********************************************************************************************************************************) procedure SaveItemToHistory(s: string; History: TStringList); var i: integer; diff --git a/UEngines.pas b/UEngines.pas index 6cb8d7a..b4dc319 100644 --- a/UEngines.pas +++ b/UEngines.pas @@ -81,7 +81,6 @@ type LastHighlightItem, SavePath: string; constructor Create; destructor Destroy; override; -// function GetListing(var List: PGSList): integer; virtual; abstract; // Returns errorcode function GetListing(var List: TList; const AddDotFiles: boolean): integer; overload; virtual; abstract; // Returns errorcode function GetListing(var List: TList; const AddDotFiles: boolean; APath: string): integer; overload; virtual; abstract; // Returns errorcode function ChangeDir(const NewPath: string; const ShowProgress: boolean = True): integer; virtual; abstract; // Returns errorcode @@ -135,7 +134,6 @@ type public constructor Create; destructor Destroy; override; -// function GetListing(var List: PGSList): integer; override; function GetListing(var List: TList; const AddDotFiles: boolean): integer; override; function GetListing(var List: TList; const AddDotFiles: boolean; APath: string): integer; override; function ChangeDir(const NewPath: string; const ShowProgress: boolean = True): integer; override; @@ -728,9 +726,9 @@ var fsrc, fdest: PFILE; BytesWritten: Int64; Res: boolean; begin - try Result := False; Res := True; + try // DebugMsg(['*** Using old copy function due to bug in sendfile']); // WriteLn('x1'); Buffer := malloc(FBlockSize); diff --git a/UGnome.pas b/UGnome.pas index a54adbf..8659410 100644 --- a/UGnome.pas +++ b/UGnome.pas @@ -58,13 +58,13 @@ type TGnomeColorButton = class(TGTKButton) TGnomeDateEdit = class(TGTKHBox) private - function GetTime: TDateTime; - procedure SetTime(Value: TDateTime); + function GetTime: time_t; + procedure SetTime(Value: time_t); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published - property Time: TDateTime read GetTime write SetTime; + property Time: time_t read GetTime write SetTime; end; TEphyNotebook = class; @@ -336,14 +336,14 @@ begin inherited Destroy; end; -function TGnomeDateEdit.GetTime: TDateTime; +function TGnomeDateEdit.GetTime: time_t; begin - Result := UnixToDateTime(gnome_date_edit_get_time(FWidget)); + Result := gnome_date_edit_get_time(FWidget); end; -procedure TGnomeDateEdit.SetTime(Value: TDateTime); +procedure TGnomeDateEdit.SetTime(Value: time_t); begin - gnome_date_edit_set_time(FWidget, DateTimeToUnix(Value)); + gnome_date_edit_set_time(FWidget, Value); end; (********************************************************************************************************************************) diff --git a/ULibc.pas b/ULibc.pas index c11566d..f2fda81 100644 --- a/ULibc.pas +++ b/ULibc.pas @@ -111,18 +111,9 @@ type st_size : __off64_t; st_blksize : __blksize_t; st_blocks : __blkcnt64_t; - st_atim : Ttimespec; st_mtim : Ttimespec; st_ctim : Ttimespec; - -{ st_atime : __time_t; - __unused1 : dword; - st_mtime : __time_t; - __unused2 : dword; - st_ctime : __time_t; - __unused3 : dword; } - st_ino : __ino64_t; {$ELSE} // 64-bit platform st_dev : QWORD; diff --git a/UMain.pas b/UMain.pas index f131b3d..b57b58d 100644 --- a/UMain.pas +++ b/UMain.pas @@ -1531,7 +1531,7 @@ begin // Filter out all non-character keys s := UTF8Encode(WideChar(KeyValToUnicode(Key))); if (Length(s) = 0) or (s = #0) then begin - DebugMsg(['HandleKey: not a character key. Ignoring.']); +// DebugMsg(['HandleKey: not a character key. Ignoring.']); Exit; end; diff --git a/USearch.pas b/USearch.pas index 0156d59..2859de4 100644 --- a/USearch.pas +++ b/USearch.pas @@ -24,7 +24,7 @@ interface uses glib2, gdk2, gtk2, SyncObjs, SysUtils, Types, Classes, Variants, GTKControls, GTKForms, GTKStdCtrls, GTKExtCtrls, GTKConsts, GTKView, GTKMenus, - UEngines, UGnome; + UEngines, UGnome, ULibc; type TFSearch = class(TGTKDialog) @@ -88,7 +88,7 @@ type FStartPath, FFileMask, FStringFind: string; FDontLeaveFS, FCaseSensitiveMask, FCaseSensitiveStrings, FSearchArchives: boolean; FBiggerThan, FSmallerThan: integer; // -1 = skip - FModifiedBetween1, FModifiedBetween2, FNotModifiedAfter: TDateTime; + FModifiedBetween1, FModifiedBetween2, FNotModifiedAfter: time_t; FModifiedLast, FModifiedNotLast: integer; FList: TList; procedure Execute; override; @@ -104,7 +104,7 @@ var implementation -uses Math, UMain, ULocale, UCoreUtils, ULibc, UCore, DateUtils, UViewer, UConfig, UVFSCore; +uses Math, UMain, ULocale, UCoreUtils, UCore, DateUtils, UViewer, UConfig, UVFSCore; type TFileListItem = class CRC: LongWord; @@ -700,16 +700,16 @@ begin i := i * Trunc(Power(1024, SmallerThanOptionMenu.ItemIndex)); FSmallerThan := i; end; - FModifiedBetween1 := -1; - FModifiedBetween2 := -1; - FNotModifiedAfter := -1; + FModifiedBetween1 := 0; + FModifiedBetween2 := 0; + FNotModifiedAfter := 0; if not FUseGnomeWidgets then begin if ModifiedBetweenRadioButton.Checked then begin - FModifiedBetween1 := StrToDateDef(ModifiedBetweenEntry1.Text, -1); - FModifiedBetween2 := StrToDateDef(ModifiedBetweenEntry2.Text, -1); + FModifiedBetween1 := StrTotimetDef(ModifiedBetweenEntry1.Text, 0); + FModifiedBetween2 := StrTotimetDef(ModifiedBetweenEntry2.Text, 0); end; if NotModifiedAfterRadioButton.Checked then - FNotModifiedAfter := StrToDateDef(NotModifiedAfterEntry.Text, -1); + FNotModifiedAfter := StrTotimetDef(NotModifiedAfterEntry.Text, 0); end else begin if ModifiedBetweenRadioButton.Checked then begin FModifiedBetween1 := ModifiedBetweenEntry1G.Time; diff --git a/tuxcmd.dpr b/tuxcmd.dpr index e355b49..de54d57 100644 --- a/tuxcmd.dpr +++ b/tuxcmd.dpr @@ -21,7 +21,7 @@ program tuxcmd; uses - {$IFDEF __FPC__} + {$IFDEF FPC} cthreads, cwstring, {$ENDIF} @@ -78,7 +78,7 @@ uses UTranslation_HU in 'translations/UTranslation_HU.pas'; -{$IFNDEF __FPC__} +{$IFNDEF FPC} {$R *.res} {$ENDIF} diff --git a/vfs/UVFSCore.pas b/vfs/UVFSCore.pas index 5ca80d5..e93fa11 100644 --- a/vfs/UVFSCore.pas +++ b/vfs/UVFSCore.pas @@ -19,10 +19,6 @@ *) unit UVFSCore; -{$IFDEF __FPC__} - {$M+} -{$ENDIF} - interface uses GTKForms, ULibc, Classes, uVFSprototypes, UEngines, UCoreUtils; @@ -78,7 +74,7 @@ type Extensions, Services: TOpenStringArray; // the list of the extensions plugin can handle constructor Create(PluginHandle: Pointer); destructor Destroy; override; - published + function VFSVersion: integer; function VFSName: PChar; function VFSDescription: PChar; @@ -302,7 +298,7 @@ begin memset(FGlobs, 0, SizeOf(FGlobs)); end; -{$IFNDEF KYLIX} +{ DebugMsg(['sizeof(TVFSItem) = ', sizeof(TVFSItem)]); DebugMsg(['sizeof(TVFSItem.sFileName) = ', sizeof(TVFSItem.sFileName)]); DebugMsg(['sizeof(TVFSItem.iSize) = ', sizeof(TVFSItem.iSize)]); @@ -314,8 +310,7 @@ begin DebugMsg(['sizeof(TVFSItem.iUID) = ', sizeof(TVFSItem.iUID)]); DebugMsg(['sizeof(TVFSItem.iGID) = ', sizeof(TVFSItem.iGID)]); DebugMsg(['sizeof(TVFSItem.ItemType) = ', sizeof(TVFSItem.ItemType)]); -{$ENDIF} - +} if @FSourcePlugin.FVFSInit <> nil then FSourcePlugin.FVFSInit(FGlobs, @VFSLogFunc); FPassword := ''; end; @@ -701,11 +696,9 @@ begin libc_free(P); FSourcePlugin.FVFSListClose(FGlobs); - {$WARNINGS OFF} if LocalList.Count > 0 then for i := 0 to LocalList.Count - 1 do FillDirFiles(LocalList[i], List, ALevel + 1); - {$WARNINGS ON} if FilesList.Count > 0 then for i := 0 to FilesList.Count - 1 do -- cgit v1.2.3