2013-08-27 15:14:44 +04:00
|
|
|
##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
|
|
|
## Gestion de fichiers de propriétés java
|
|
|
|
##@cooked nocomments
|
|
|
|
##@require base
|
|
|
|
uprovide javaproperties
|
|
|
|
urequire base
|
|
|
|
|
|
|
|
function read_property() {
|
|
|
|
# Lire la propriété $2 dans le fichier $1, et placer la valeur dans la
|
|
|
|
# variable $3. Si la propriété n'existe pas, prendre la valeur par défaut
|
|
|
|
# $4. Si $3=="", elle est construite à partir de $2 en remplaçant les '.'
|
|
|
|
# par '_'
|
|
|
|
# Retourner 1 si une erreur s'est produite (par exemple si le fichier
|
|
|
|
# n'existe pas ou n'est pas accessible en lecture)
|
|
|
|
[ -f "$1" -a -r "$1" ] || return 1
|
|
|
|
|
|
|
|
local __rp_name __rp_value __rp_found
|
|
|
|
# utiliser cawkrun pour que awk n'essaye pas de traiter les caractères en
|
|
|
|
# unicode (latin1 wrt utf-8)
|
|
|
|
__rp_value="$(<"$1" cawkrun name="$2" '
|
|
|
|
BEGIN {
|
|
|
|
found = 1
|
|
|
|
re_name = name
|
|
|
|
gsub(/\./, "\\.", re_name)
|
|
|
|
re_name = "^[ \t]*" re_name "[ \t]*="
|
|
|
|
}
|
|
|
|
$0 ~ re_name {
|
|
|
|
sub(re_name, "")
|
|
|
|
value = $0
|
|
|
|
sub(/^[ \t]*/, "", value)
|
|
|
|
while (substr(value, length(value), 1) == "\\") {
|
|
|
|
getline
|
|
|
|
sub(/^[ \t]*/, "")
|
|
|
|
value = substr(value, 1, length(value) - 1) $0
|
|
|
|
}
|
|
|
|
print value
|
|
|
|
found = 0
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
END { exit found }')" && __rp_found=1
|
|
|
|
if [ -n "$3" ]; then
|
|
|
|
__rp_name="$3"
|
|
|
|
else
|
|
|
|
__rp_name="${2//./_}"
|
|
|
|
fi
|
|
|
|
if [ -n "$__rp_found" ]; then
|
|
|
|
set_var "$__rp_name" "$(tooenc "$__rp_value" "$LATIN1")"
|
|
|
|
else
|
|
|
|
set_var "$__rp_name" "$4"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function write_property() {
|
|
|
|
# Ecrire la propriété $2 dans le fichier $1 avec la valeur $3.
|
|
|
|
# Retourner 1 si une erreur s'est produite (par exemple si le fichier
|
|
|
|
# n'existe pas ou n'est pas accessible en écriture)
|
|
|
|
[ -f "$1" -a -w "$1" ] || return 1
|
|
|
|
|
|
|
|
local status tmpfile
|
|
|
|
ac_set_tmpfile tmpfile
|
|
|
|
# utiliser cawkrun pour que awk n'essaye pas de traiter les caractères en
|
|
|
|
# unicode (utf-8 wrt latin1)
|
|
|
|
<"$1" >"$tmpfile" cawkrun name="$2" value="$(tooenc "$3" "" "$LATIN1")" '
|
|
|
|
function write_value() {
|
|
|
|
# XXX attention, le découpage n"est potentiellement pas fait
|
|
|
|
# correctement si la valeur contient des espaces
|
|
|
|
line = name "=" value
|
|
|
|
prefix = ""
|
|
|
|
max_len = 75
|
|
|
|
if (length(line) > max_len) {
|
|
|
|
do {
|
|
|
|
print prefix substr(line, 1, max_len) "\\"
|
|
|
|
line = substr(line, max_len + 1)
|
|
|
|
prefix = " "
|
|
|
|
max_len = 71
|
|
|
|
} while (length(line) > max_len)
|
|
|
|
}
|
|
|
|
print prefix line
|
|
|
|
}
|
|
|
|
BEGIN {
|
|
|
|
found = 0
|
|
|
|
re_name = name
|
|
|
|
gsub(/\./, "\\.", re_name)
|
|
|
|
re_name = "^[ \t]*" re_name "[ \t]*="
|
|
|
|
}
|
|
|
|
!found && $0 ~ re_name {
|
|
|
|
line = $0
|
|
|
|
while (substr(line, length(line), 1) == "\\") {
|
|
|
|
getline
|
|
|
|
line = line $0
|
|
|
|
}
|
|
|
|
write_value()
|
|
|
|
found = 1
|
|
|
|
next
|
|
|
|
}
|
|
|
|
{ print }
|
|
|
|
END { if (!found) write_value() }
|
|
|
|
' && cat "$tmpfile" >"$1"
|
|
|
|
status=$?
|
|
|
|
ac_clean "$tmpfile"
|
|
|
|
return $status
|
|
|
|
}
|
|
|
|
|
|
|
|
function write_properties() {
|
|
|
|
# Ecrire les propriétés $2..* dans le fichier $1. Les propriétés sont de la
|
|
|
|
# forme "name=value"
|
|
|
|
local __wp_propfile="$1"; shift
|
|
|
|
local __wp_prop __wp_name __wp_value
|
|
|
|
for __wp_prop in "$@"; do
|
|
|
|
splitvar "$__wp_prop" __wp_name __wp_value
|
|
|
|
write_property "$__wp_propfile" "$__wp_name" "$__wp_value"
|
|
|
|
done
|
|
|
|
}
|
2015-04-27 18:12:21 +04:00
|
|
|
|
|
|
|
function __norm_properties() {
|
|
|
|
_nl2lf |
|
|
|
|
grep -v $'^[ \t]*#' |
|
|
|
|
grep -v $'^[ \t]*$' |
|
|
|
|
csort -k1 -t= |
|
|
|
|
csed $'
|
|
|
|
s/\x80/\\\\u0080/g; s/\x81/\\\\u0081/g; s/\x82/\\\\u0082/g; s/\x83/\\\\u0083/g;
|
|
|
|
s/\x84/\\\\u0084/g; s/\x85/\\\\u0085/g; s/\x86/\\\\u0086/g; s/\x87/\\\\u0087/g;
|
|
|
|
s/\x88/\\\\u0088/g; s/\x89/\\\\u0089/g; s/\x8a/\\\\u008a/g; s/\x8b/\\\\u008b/g;
|
|
|
|
s/\x8c/\\\\u008c/g; s/\x8d/\\\\u008d/g; s/\x8e/\\\\u008e/g; s/\x8f/\\\\u008f/g;
|
|
|
|
s/\x90/\\\\u0090/g; s/\x91/\\\\u0091/g; s/\x92/\\\\u0092/g; s/\x93/\\\\u0093/g;
|
|
|
|
s/\x94/\\\\u0094/g; s/\x95/\\\\u0095/g; s/\x96/\\\\u0096/g; s/\x97/\\\\u0097/g;
|
|
|
|
s/\x98/\\\\u0098/g; s/\x99/\\\\u0099/g; s/\x9a/\\\\u009a/g; s/\x9b/\\\\u009b/g;
|
|
|
|
s/\x9c/\\\\u009c/g; s/\x9d/\\\\u009d/g; s/\x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d1/\\\\u00d1/g; s/\xd2/\\\\u00d2/g; s/\xd3/\\\\u00d3/g;
|
|
|
|
s/\xd4/\\\\u00d4/g; s/\xd5/\\\\u00d5/g; s/\xd6/\\\\u00d6/g; s/\xd7/\\\\u00d7/g;
|
|
|
|
s/\xd8/\\\\u00d8/g; s/\xd9/\\\\u00d9/g; s/\xda/\\\\u00da/g; s/\xdb/\\\\u00db/g;
|
|
|
|
s/\xdc/\\\\u00dc/g; s/\xdd/\\\\u00dd/g; s/\xde/\\\\u00de/g; s/\xdf/\\\\u00df/g;
|
|
|
|
s/\xe0/\\\\u00e0/g; s/\xe1/\\\\u00e1/g; s/\xe2/\\\\u00e2/g; s/\xe3/\\\\u00e3/g;
|
|
|
|
s/\xe4/\\\\u00e4/g; s/\xe5/\\\\u00e5/g; s/\xe6/\\\\u00e6/g; s/\xe7/\\\\u00e7/g;
|
|
|
|
s/\xe8/\\\\u00e8/g; s/\xe9/\\\\u00e9/g; s/\xea/\\\\u00ea/g; s/\xeb/\\\\u00eb/g;
|
|
|
|
s/\xec/\\\\u00ec/g; s/\xed/\\\\u00ed/g; s/\xee/\\\\u00ee/g; s/\xef/\\\\u00ef/g;
|
|
|
|
s/\xf0/\\\\u00f0/g; s/\xf1/\\\\u00f1/g; s/\xf2/\\\\u00f2/g; s/\xf3/\\\\u00f3/g;
|
|
|
|
s/\xf4/\\\\u00f4/g; s/\xf5/\\\\u00f5/g; s/\xf6/\\\\u00f6/g; s/\xf7/\\\\u00f7/g;
|
|
|
|
s/\xf8/\\\\u00f8/g; s/\xf9/\\\\u00f9/g; s/\xfa/\\\\u00fa/g; s/\xfb/\\\\u00fb/g;
|
|
|
|
s/\xfc/\\\\u00fc/g; s/\xfd/\\\\u00fd/g; s/\xfe/\\\\u00fe/g; s/\xff/\\\\u00ff/g;
|
|
|
|
''
|
|
|
|
s/\\u008[aA]/\\u008a/g; s/\\u008[bB]/\\u008b/g; s/\\u008[cC]/\\u008c/g; s/\\u008[dD]/\\u008d/g;
|
|
|
|
s/\\u008[eE]/\\u008e/g; s/\\u008[fF]/\\u008f/g; s/\\u009[aA]/\\u009a/g; s/\\u009[bB]/\\u009b/g;
|
|
|
|
s/\\u009[cC]/\\u009c/g; s/\\u009[dD]/\\u009d/g; s/\\u009[eE]/\\u009e/g; s/\\u009[fF]/\\u009f/g;
|
|
|
|
s/\\u00[aA]0/\\u00a0/g; s/\\u00[aA]1/\\u00a1/g; s/\\u00[aA]2/\\u00a2/g; s/\\u00[aA]3/\\u00a3/g;
|
|
|
|
s/\\u00[aA]4/\\u00a4/g; s/\\u00[aA]5/\\u00a5/g; s/\\u00[aA]6/\\u00a6/g; s/\\u00[aA]7/\\u00a7/g;
|
|
|
|
s/\\u00[aA]8/\\u00a8/g; s/\\u00[aA]9/\\u00a9/g; s/\\u00[aA][aA]/\\u00aa/g; s/\\u00[aA][bB]/\\u00ab/g;
|
|
|
|
s/\\u00[aA][cC]/\\u00ac/g; s/\\u00[aA][dD]/\\u00ad/g; s/\\u00[aA][eE]/\\u00ae/g; s/\\u00[aA][fF]/\\u00af/g;
|
|
|
|
s/\\u00[bB]0/\\u00b0/g; s/\\u00[bB]1/\\u00b1/g; s/\\u00[bB]2/\\u00b2/g; s/\\u00[bB]3/\\u00b3/g;
|
|
|
|
s/\\u00[bB]4/\\u00b4/g; s/\\u00[bB]5/\\u00b5/g; s/\\u00[bB]6/\\u00b6/g; s/\\u00[bB]7/\\u00b7/g;
|
|
|
|
s/\\u00[bB]8/\\u00b8/g; s/\\u00[bB]9/\\u00b9/g; s/\\u00[bB][aA]/\\u00ba/g; s/\\u00[bB][bB]/\\u00bb/g;
|
|
|
|
s/\\u00[bB][cC]/\\u00bc/g; s/\\u00[bB][dD]/\\u00bd/g; s/\\u00[bB][eE]/\\u00be/g; s/\\u00[bB][fF]/\\u00bf/g;
|
|
|
|
s/\\u00[cC]0/\\u00c0/g; s/\\u00[cC]1/\\u00c1/g; s/\\u00[cC]2/\\u00c2/g; s/\\u00[cC]3/\\u00c3/g;
|
|
|
|
s/\\u00[cC]4/\\u00c4/g; s/\\u00[cC]5/\\u00c5/g; s/\\u00[cC]6/\\u00c6/g; s/\\u00[cC]7/\\u00c7/g;
|
|
|
|
s/\\u00[cC]8/\\u00c8/g; s/\\u00[cC]9/\\u00c9/g; s/\\u00[cC][aA]/\\u00ca/g; s/\\u00[cC][bB]/\\u00cb/g;
|
|
|
|
s/\\u00[cC][cC]/\\u00cc/g; s/\\u00[cC][dD]/\\u00cd/g; s/\\u00[cC][eE]/\\u00ce/g; s/\\u00[cC][fF]/\\u00cf/g;
|
|
|
|
s/\\u00[dD]0/\\u00d0/g; s/\\u00[dD]1/\\u00d1/g; s/\\u00[dD]2/\\u00d2/g; s/\\u00[dD]3/\\u00d3/g;
|
|
|
|
s/\\u00[dD]4/\\u00d4/g; s/\\u00[dD]5/\\u00d5/g; s/\\u00[dD]6/\\u00d6/g; s/\\u00[dD]7/\\u00d7/g;
|
|
|
|
s/\\u00[dD]8/\\u00d8/g; s/\\u00[dD]9/\\u00d9/g; s/\\u00[dD][aA]/\\u00da/g; s/\\u00[dD][bB]/\\u00db/g;
|
|
|
|
s/\\u00[dD][cC]/\\u00dc/g; s/\\u00[dD][dD]/\\u00dd/g; s/\\u00[dD][eE]/\\u00de/g; s/\\u00[dD][fF]/\\u00df/g;
|
|
|
|
s/\\u00[eE]0/\\u00e0/g; s/\\u00[eE]1/\\u00e1/g; s/\\u00[eE]2/\\u00e2/g; s/\\u00[eE]3/\\u00e3/g;
|
|
|
|
s/\\u00[eE]4/\\u00e4/g; s/\\u00[eE]5/\\u00e5/g; s/\\u00[eE]6/\\u00e6/g; s/\\u00[eE]7/\\u00e7/g;
|
|
|
|
s/\\u00[eE]8/\\u00e8/g; s/\\u00[eE]9/\\u00e9/g; s/\\u00[eE][aA]/\\u00ea/g; s/\\u00[eE][bB]/\\u00eb/g;
|
|
|
|
s/\\u00[eE][cC]/\\u00ec/g; s/\\u00[eE][dD]/\\u00ed/g; s/\\u00[eE][eE]/\\u00ee/g; s/\\u00[eE][fF]/\\u00ef/g;
|
|
|
|
s/\\u00[fF]0/\\u00f0/g; s/\\u00[fF]1/\\u00f1/g; s/\\u00[fF]2/\\u00f2/g; s/\\u00[fF]3/\\u00f3/g;
|
|
|
|
s/\\u00[fF]4/\\u00f4/g; s/\\u00[fF]5/\\u00f5/g; s/\\u00[fF]6/\\u00f6/g; s/\\u00[fF]7/\\u00f7/g;
|
|
|
|
s/\\u00[fF]8/\\u00f8/g; s/\\u00[fF]9/\\u00f9/g; s/\\u00[fF][aA]/\\u00fa/g; s/\\u00[fF][bB]/\\u00fb/g;
|
|
|
|
s/\\u00[fF][cC]/\\u00fc/g; s/\\u00[fF][dD]/\\u00fd/g; s/\\u00[fF][eE]/\\u00fe/g; s/\\u00[fF][fF]/\\u00ff/g;
|
|
|
|
' |
|
|
|
|
awk '{ print gensub(/([^\\]):/, "\\1\\\\:", "g") }'
|
|
|
|
}
|
|
|
|
|
|
|
|
function norm_properties() {
|
|
|
|
# Normaliser un fichier de propriété: Les commentaires sont supprimés, les
|
|
|
|
# valeurs sont triées par ordre alphabétique, les caractères accentués sont
|
|
|
|
# remplacés par des caractères unicode \\uxxxx, les séquences unicodes sont
|
|
|
|
# transformées en minuscule.
|
|
|
|
[ -f "$1" -a -w "$1" ] || return 1
|
|
|
|
local status tmpfile
|
|
|
|
ac_set_tmpfile tmpfile
|
|
|
|
<"$1" >"$tmpfile" __norm_properties && cat "$tmpfile" >"$1"
|
|
|
|
status=$?
|
|
|
|
ac_clean "$tmpfile"
|
|
|
|
return $status
|
|
|
|
}
|