##@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 } gsub(/\\:/, ":", value) gsub(/\\=/, "=", value) 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 _setv "$__rp_name" "$(tooenc "$__rp_value" "$LATIN1")" else _setv "$__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 gsub(/:/, "\\:", value) gsub(/=/, "\\=", value) 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 } function __norm_properties() { echo '# -*- coding: iso-8859-1 -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=iso-8859-1' _nl2lf | cgrep -v $'^[ \t]*#' | cgrep -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/\x9e/\\\\u009E/g; s/\x9f/\\\\u009F/g; s/\xa0/\\\\u00A0/g; s/\xa1/\\\\u00A1/g; s/\xa2/\\\\u00A2/g; s/\xa3/\\\\u00A3/g; s/\xa4/\\\\u00A4/g; s/\xa5/\\\\u00A5/g; s/\xa6/\\\\u00A6/g; s/\xa7/\\\\u00A7/g; s/\xa8/\\\\u00A8/g; s/\xa9/\\\\u00A9/g; s/\xaa/\\\\u00AA/g; s/\xab/\\\\u00AB/g; s/\xac/\\\\u00AC/g; s/\xad/\\\\u00AD/g; s/\xae/\\\\u00AE/g; s/\xaf/\\\\u00AF/g; s/\xb0/\\\\u00B0/g; s/\xb1/\\\\u00B1/g; s/\xb2/\\\\u00B2/g; s/\xb3/\\\\u00B3/g; s/\xb4/\\\\u00B4/g; s/\xb5/\\\\u00B5/g; s/\xb6/\\\\u00B6/g; s/\xb7/\\\\u00B7/g; s/\xb8/\\\\u00B8/g; s/\xb9/\\\\u00B9/g; s/\xba/\\\\u00BA/g; s/\xbb/\\\\u00BB/g; s/\xbc/\\\\u00BC/g; s/\xbd/\\\\u00BD/g; s/\xbe/\\\\u00BE/g; s/\xbf/\\\\u00BF/g; s/\xc0/\\\\u00C0/g; s/\xc1/\\\\u00C1/g; s/\xc2/\\\\u00C2/g; s/\xc3/\\\\u00C3/g; s/\xc4/\\\\u00C4/g; s/\xc5/\\\\u00C5/g; s/\xc6/\\\\u00C6/g; s/\xc7/\\\\u00C7/g; s/\xc8/\\\\u00C8/g; s/\xc9/\\\\u00C9/g; s/\xca/\\\\u00CA/g; s/\xcb/\\\\u00CB/g; s/\xcc/\\\\u00CC/g; s/\xcd/\\\\u00CD/g; s/\xce/\\\\u00CE/g; s/\xcf/\\\\u00CF/g; s/\xd0/\\\\u00D0/g; s/\xd1/\\\\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 }