diff options
Diffstat (limited to 'UCoreUtils.pas')
| -rw-r--r-- | UCoreUtils.pas | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/UCoreUtils.pas b/UCoreUtils.pas index b0ea388..c204d4e 100644 --- a/UCoreUtils.pas +++ b/UCoreUtils.pas @@ -21,7 +21,7 @@ unit UCoreUtils; interface -uses gtk2, gdk2, glib2, SysUtils, Classes, ULibc, GTKClasses, UEngines; +uses gtk2, gdk2, glib2, lazglib2, SysUtils, Classes, ULibc, GTKClasses, UEngines; type PIntArray = ^TIntArray; @@ -35,7 +35,7 @@ const ConstERRSpawn = 26; ConstURIIllegalCharacters = '%:@/'; function FormatSize(Value: Int64; Base: integer; OverrideSizeFormat: integer = -1): string; -function FormatDate(Value: time_t; const FormatTime, FormatDate: boolean; OverrideTimeFormat: integer = -1; OverrideDateFormat: integer = -1; OverrideDateTimeFormat: integer = -1; OverrideCustomDateFormat: string = ''; OverrideCustomTimeFormat: string = ''): string; +function FormatDate(Value: time_t; const DoFormatTime, DoFormatDate: boolean; OverrideTimeFormat: integer = -1; OverrideDateFormat: integer = -1; OverrideDateTimeFormat: integer = -1; OverrideCustomDateFormat: string = ''; OverrideCustomTimeFormat: string = ''): string; function StripDate(Value: time_t): time_t; function IncludeLeadingDot(s: string): string; @@ -117,6 +117,7 @@ function EnsureUTF8String(s: PChar): PChar; overload; function Min(Val1, Val2: longint): longint; function XORStr(const s: string; Key: byte): string; +function CLAMP(x, MinX, MaxX: integer): integer; function FindCommonRoot(BasePath, DestPath: string): string; function BuildRelativePath(BasePath, DestPath: string): string; @@ -164,7 +165,7 @@ begin if f < 0 then f := ConfSizeFormat; case f of 0 : begin // System default formatting - p := g_strdup_printf('%''llu', Int64(Value div Base)); + p := g_strdup_printf('%''llu', [Int64(Value div Base)]); if p = nil then begin DebugMsg(['FormatSize(0): sprintf() failed, using old format function.']); Result := FormatFloat('###,###,##0', Value div Base); @@ -188,16 +189,16 @@ begin 5 : begin // 123kB - Grouped if (Value >= 1024*1024*1024) or (Base = 1024*1024*1024) then begin x := Value / (1024*1024*1024); - p := g_strdup_printf(PChar('%''.' + IntToStr(ConfSizeGroupPrecision) + 'f GB'), x); + p := g_strdup_printf(PChar('%''.' + IntToStr(ConfSizeGroupPrecision) + 'f GB'), [x]); end else if (Value >= 1024*1024) or (Base = 1024*1024) then begin x := Value / (1024*1024); - p := g_strdup_printf(PChar('%''.' + IntToStr(ConfSizeGroupPrecision) + 'f MB'), x); + p := g_strdup_printf(PChar('%''.' + IntToStr(ConfSizeGroupPrecision) + 'f MB'), [x]); end else if (Value >= 1024) or (Base = 1024) then begin x := Value / 1024; - p := g_strdup_printf(PChar('%''.' + IntToStr(ConfSizeGroupPrecision) + 'f kB'), x); - end else p := g_strdup_printf('%d', Value); + p := g_strdup_printf(PChar('%''.' + IntToStr(ConfSizeGroupPrecision) + 'f kB'), [x]); + end else p := g_strdup_printf('%d', [Value]); if p = nil then begin DebugMsg(['FormatSize(5): g_strdup_printf() failed, using old format function.']); s := '###,###,##0'; @@ -227,7 +228,7 @@ begin end; (********************************************************************************************************************************) -function FormatDate(Value: time_t; const FormatTime, FormatDate: boolean; OverrideTimeFormat: integer = -1; OverrideDateFormat: integer = -1; OverrideDateTimeFormat: integer = -1; OverrideCustomDateFormat: string = ''; OverrideCustomTimeFormat: string = ''): string; +function FormatDate(Value: time_t; const DoFormatTime, DoFormatDate: boolean; OverrideTimeFormat: integer = -1; OverrideDateFormat: integer = -1; OverrideDateTimeFormat: integer = -1; OverrideCustomDateFormat: string = ''; OverrideCustomTimeFormat: string = ''): string; var DateString, TimeString: string; DateFormat, TimeFormat: string; CustDateFormat, CustTimeFormat: string; @@ -254,7 +255,7 @@ begin time_tm := localtime(@Value); - if FormatDate then begin + if DoFormatDate then begin case df of 0: DateFormat := '%x'; // System format 1: DateFormat := '%Y-%m-%d'; // 2008-06-24 @@ -281,7 +282,7 @@ begin libc_free(Buf); end; - if FormatTime then begin + if DoFormatTime then begin case tf of 0: TimeFormat := '%X'; // System format 1: TimeFormat := '%I:%M %P'; // 01:11 pm @@ -304,15 +305,15 @@ begin TimeString := String(StrToUTF8(Buf)); libc_free(Buf); end; - - if FormatDate and FormatTime then begin + + if DoFormatDate and DoFormatTime then begin case dtf of 0: Result := Format('%s %s', [DateString, TimeString]); else Result := Format('%s %s', [TimeString, DateString]); end; end else - if FormatTime then Result := TimeString else - if FormatDate then Result := DateString; + if DoFormatTime then Result := TimeString else + if DoFormatDate then Result := DateString; end; function StripDate(Value: time_t): time_t; @@ -400,13 +401,13 @@ end; (********************************************************************************************************************************) function GetHomePath: string; begin - Result := PgcharToString(g_get_home_dir); + Result := String(g_get_home_dir); end; (********************************************************************************************************************************) function GetUserName: string; begin - Result := PgcharToString(g_get_user_name); + Result := String(g_get_user_name); end; (********************************************************************************************************************************) @@ -416,7 +417,7 @@ begin s := malloc(65536); memset(s, 0, 65536); ULibc.gethostname(s, 65536); - Result := PgcharToString(strdup(s)); + Result := String(strdup(s)); libc_free(s); end; @@ -820,7 +821,7 @@ const Authors : array[0..1] of PChar = ('Tomáš Bžatek <tbzatek@users.sourcefo 'Sewon Jang <jangblue@gmail.com> - Korean'; var AboutBox: PGtkWidget; begin - if (libGnomeUI2Handle = nil) or (@gnome_about_new = nil) + if (libGnomeUI2Handle = nil) or (gnome_about_new = nil) then Application.MessageBox(Format(LANGAboutString, [ConstAboutVersion, ConstAboutBuildDate])) else begin AboutBox := gnome_about_new('Tux Commander', nil, 'Copyright © 2002-2024 Tomáš Bžatek', @@ -841,7 +842,7 @@ begin List := g_list_append(List, AppIcon48.FPixbuf); List := g_list_append(List, AppIcon64.FPixbuf); List := g_list_append(List, AppIcon128.FPixbuf); - gtk_window_set_default_icon_list(List); + gtk_window_set_default_icon_list(GLIB2.PGList(List)); g_list_free(List); end; @@ -1124,9 +1125,9 @@ begin case VType of vtPointer: begin {$IFDEF CPU64} - P := g_strdup_printf('%.16p', VPointer); + P := g_strdup_printf('%.16p', [VPointer]); {$ELSE} - P := g_strdup_printf('%.8p', VPointer); + P := g_strdup_printf('%.8p', [VPointer]); {$ENDIF} Write(ErrOutput, P); g_free(P); @@ -1143,9 +1144,7 @@ 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; @@ -1603,11 +1602,9 @@ begin DebugMsg(['*** StrToUTF8: error converting "', s, '" to UTF-8 (read ', bytes_read, ', written ', bytes_written, '): ', m]); g_error_free(error); end; - if @g_filename_display_name <> nil then begin - nss := g_filename_display_name(ns); - Result := strdup(nss); // PPC compatibility - g_free(nss); - end else Result := strdup(ns); // PPC compatibility + nss := g_filename_display_name(ns); + Result := strdup(nss); // PPC compatibility + g_free(nss); g_free(ns); end; @@ -1629,8 +1626,7 @@ end; function EnsureUTF8String(s: PChar): PChar; begin - Result := s; - if @g_filename_display_name <> nil then Result := g_filename_display_name(s); + Result := g_filename_display_name(s); end; @@ -1847,17 +1843,24 @@ end; (********************************************************************************************************************************) +function CLAMP(x, MinX, MaxX: integer): integer; +begin + if x<MinX then + Result:=MinX + else if x>MaxX then + Result:=MaxX + else + Result:=x; +end; initialization -{$IFDEF FPC} // Set path separators only to a standard Unix slash -- otherwise all path functions will treat ending backslash as a delimiter, // causing problems with directory names ending with a backslash (it's a valid character in Unix). // Kylix behaves fine, only forward slash is honored. AllowDirectorySeparators := ['/']; -{$ENDIF} InternalLockInit(True); SetupSignals; |
