Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iml-backup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
iml-backup
Commits
ff22cf44
Commit
ff22cf44
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
update ini.class
parent
a8294e6a
Branches
Branches containing commit
No related tags found
1 merge request
!127
7009 better safename for windows
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
vendor/ini.class.sh
+37
-9
37 additions, 9 deletions
vendor/ini.class.sh
with
37 additions
and
9 deletions
vendor/ini.class.sh
+
37
−
9
View file @
ff22cf44
...
...
@@ -6,6 +6,7 @@
#
# ----------------------------------------------------------------------
# 2024-02-04 v0.1 Initial version
# 2024-02-08 v0.2 add ini.varexport; improve replacements of quotes
# ======================================================================
INI_FILE
=
...
...
@@ -72,11 +73,8 @@ function ini.section(){
# param1 - name of the ini file
# param2 - name of the section in ini file
function
ini.keys
(){
local
myfile
=
$1
local
mysection
=
$2
test
-z
"
$myfile
"
&&
myfile
=
$INI_FILE
test
-z
"
$mysection
"
&&
mysection
=
$INI_SECTION
local
myfile
=
${
1
:-
$INI_FILE
}
local
mysection
=
${
2
:-
$INI_SECTION
}
ini.section
"
${
myfile
}
"
"
${
mysection
}
"
\
|
grep
"^[
\ \t
]*[^=]"
\
...
...
@@ -98,13 +96,43 @@ function ini.value(){
local
myfile
=
$1
local
mysection
=
$2
local
myvarname
=
$3
ini.section
"
${
myfile
}
"
"
${
mysection
}
"
\
local
out
out
=
$(
ini.section
"
${
myfile
}
"
"
${
mysection
}
"
\
|
grep
"^[
\ \t
]*
${
myvarname
}
[
\ \t
]*=.*"
\
|
cut
-f
2-
-d
"="
\
|
sed
-e
's,^\ *,,'
-e
's, *$,,'
\
-e
's,^",,g'
-e
's,"$,,g'
\
-e
"s,^',,g"
-e
"s,'
$,
,g"
|
sed
-e
's,^\ *,,'
-e
's, *$,,'
)
# if value does not end with [] than the last found value wins
grep
"
\[\]
$"
<<<
"myvarname"
>
/dev/null
&&
out
=
"echo
$out
| tail -1"
# delete quote chars on start and end
grep
'^".*"$'
<<<
"
$out
"
>
/dev/null
&&
out
=
$(
echo
"
$out
"
|
sed
-e
's,^"\(.*\)"$,\1,g'
)
grep
"^'.*'$"
<<<
"
$out
"
>
/dev/null
&&
out
=
$(
echo
"
$out
"
|
sed
-e
"s,^'
\(
.*
\)
'
$,
\1
,g"
)
echo
"
$out
"
fi
}
# Create bash code to export all variables as hash.
# Example: eval "$( ini.varexport "cfg_" "$inifile" )"
#
# param string prefix for the variables
# param string ini file to read
function
ini.varexport
(){
local
myprefix
=
"
$1
"
local
myfile
=
"
$2
"
local
var
=
for
mysection
in
$(
ini.sections
"
$myfile
"
)
;
do
var
=
"
${
myprefix
}${
mysection
}
"
echo
"declare -A
${
var
}
; "
echo
"export
${
var
}
; "
for
mykey
in
$(
ini.keys
"
$myfile
"
"
$mysection
"
)
;
do
value
=
"
$(
ini.value
"
$myfile
"
"
$mysection
"
"
$mykey
"
)
"
echo
${
var
}
[
$mykey
]=
"
\"
$value
\"
"
done
done
}
# ----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment