From 6cb3e2db88fa91ae7bfe826ff110ec1bb8e7153e Mon Sep 17 00:00:00 2001 From: oldchaprk Date: Mon, 24 May 2021 14:33:46 +0200 Subject: [PATCH] Improved ini file default location detection Check for default ini file at the following locations in order of decreasing priority: * current directory * home directory (~/.fit2slf.ini) * program directory --- fit2gpx.pl | 6 +++++- fit2slf.pl | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) mode change 100755 => 100644 fit2gpx.pl mode change 100755 => 100644 fit2slf.pl diff --git a/fit2gpx.pl b/fit2gpx.pl old mode 100755 new mode 100644 index 6137676..274ad91 --- a/fit2gpx.pl +++ b/fit2gpx.pl @@ -16,7 +16,11 @@ #------------------------------------------------------------------------------ # Global variables definition (my $prog = basename($0)) =~ s/.pl$//i; -my $def_ini_file = $prog.".ini"; # default ini file +(my $fullprog = $0) =~ s/.pl$//i; +my $def_ini_file; # default ini file +if (-e $prog.".ini") { $def_ini_file = $prog.".ini"; } +elsif (-e $ENV{'HOME'}."/.".$prog.".ini") { $def_ini_file = $ENV{'HOME'}."/.".$prog.".ini"; } +else { $def_ini_file = $fullprog.".ini"; } my $indent = " " x 4; # default indent: 4 spaces my $timeoffs = 631065600; # sec since Garmin Epoch (1989-12-31 00:00:00 GMT) diff --git a/fit2slf.pl b/fit2slf.pl old mode 100755 new mode 100644 index 7a7f080..272993a --- a/fit2slf.pl +++ b/fit2slf.pl @@ -17,7 +17,11 @@ #------------------------------------------------------------------------------ # Global variables definition (my $prog = basename($0)) =~ s/.pl$//i; -my $def_ini_file = $prog.".ini"; # default ini file +(my $fullprog = $0) =~ s/.pl$//i; +my $def_ini_file; # default ini file +if (-e $prog.".ini") { $def_ini_file = $prog.".ini"; } +elsif (-e $ENV{'HOME'}."/.".$prog.".ini") { $def_ini_file = $ENV{'HOME'}."/.".$prog.".ini"; } +else { $def_ini_file = $fullprog.".ini"; } my $indent = " " x 2; # default indent: 2 spaces my $timeoffs = 631065600; # sec since Garmin Epoch (1989-12-31 00:00:00 GMT) @@ -1653,7 +1657,7 @@ sub PrintSlfEntry { printf " rotations=\"%.g\"", 0; # ??? printf " speed=\"%.4f\"", $speed; - printf " speedReference=\"%s\"", "sensor"; + printf " speedReference=\"%s\"", "sensor"; printf " speedTime=\"%g\"", 0; # ???