File adtrack2-configfile.patch of Package adtrack2

diff -Nurp adtrack2-2.4.24/adt2ext2.pas adtrack2-2.4.24-configfile/adt2ext2.pas
--- adtrack2-2.4.24/adt2ext2.pas	2019-09-09 00:00:00.000000000 +0000
+++ adtrack2-2.4.24-configfile/adt2ext2.pas	2020-11-12 12:33:28.902240694 +0000
@@ -75,7 +75,7 @@ uses
 {$ELSE}
   SDL_Timer,
 {$ENDIF}
-  StrUtils,
+  StrUtils,SysUtils,
   AdT2opl3,AdT2unit,AdT2sys,AdT2extn,AdT2ext4,AdT2ext5,AdT2text,AdT2pack,AdT2keyb,
   TxtScrIO,StringIO,DialogIO,ParserIO;
 
@@ -1651,38 +1651,85 @@ begin
     check_rgb('color'+ExpStrL(Num2str(temp,10),2,'0'),rgb_color[temp]);
 end;
 
+function FixPath(str: String): String;
+
+var
+  idx: Longint;
+
+begin
+  For idx := 1 to Length(str) do
+    If str[idx] in ['/','\'] then
+      str[idx] := PATHDELIM;
+  If (Length(str) > 0) and (str[Length(str)] <> PATHDELIM) and
+     (str[Length(str)] <> ':') then
+    str := str + PATHDELIM;
+  FixPath := str;
+end;
+
+const
+  config_name: String[12] = 'adtrack2.ini';
+
 var
   txtf: Text;
   idx: Byte;
+  config_file: String;
   config_found_flag: Boolean;
+{$IFDEF UNIX}
+  home_str: String;
+{$ENDIF}
 
 begin { process_config_file }
 {$IFDEF GO32V2}
   _last_debug_str_ := _debug_str_;
   _debug_str_ := 'ADT2EXT2.PAS:process_config_file';
 {$ENDIF}
-  config_found_flag := FALSE;
+  config_file := config_name;
+  config_found_flag := TRUE;
   Write('Reading configuration file ... ');
-  {$i-}
-  Assign(txtf,'adtrack2.ini');
-  Reset (txtf);
-  {$i+}
-  If (IOresult <> 0) then
+  If NOT FileExists(config_name) then
+    begin
+{$IFDEF UNIX}
+      home_str := GetEnvironmentVariable('HOME');
+      If (home_str <> '') and FileExists(FixPath(home_str)+'.config/'+config_name) then
+        config_file := FixPath(home_str)+'.config/'+config_name
+      else
+{$ENDIF}
+{$IFDEF WINDOWS}
+        If (GetEnvironmentVariable('APPDATA') <> '') and FileExists(FixPath(GetEnvironmentVariable('APPDATA'))+config_name) then
+          config_file := FixPath(GetEnvironmentVariable('APPDATA'))+config_name
+        else
+          If (GetEnvironmentVariable('ALLUSERSPROFILE') <> '') and FileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'))+config_name) then
+            config_file := FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'))+config_name
+          else
+{$ENDIF}
+            If FileExists(PathOnly(ParamStr(0))+config_name) then
+              config_file := PathOnly(ParamStr(0))+config_name
+            else
+{$IFDEF UNIX}
+              If FileExists('/etc/'+config_name) then
+                config_file := '/etc/'+config_name
+              else
+{$ENDIF}
+                config_found_flag := FALSE;
+    end;
+
+  If config_found_flag then
     begin
       {$i-}
-      Assign(txtf,PathOnly(ParamStr(0))+'adtrack2.ini');
+      Assign(txtf,config_file);
       Reset (txtf);
       {$i+}
-      If (IOresult <> 0) then WriteLn('not found!')
-      else begin
-             config_found_flag := TRUE;
-             WriteLn('ok');
-        end;
-    end
-  else begin
-         config_found_flag := TRUE;
-         WriteLn('ok');
-       end;
+      If (IOresult <> 0) then
+        begin
+          WriteLn('not found!');
+          config_found_flag := FALSE;
+        end
+      else WriteLn('ok');
+    end
+  else begin
+         WriteLn('not found!');
+         config_found_flag := FALSE;
+       end;
 
   If config_found_flag then
     begin
openSUSE Build Service is sponsored by