#
# This script overcomes bugs in localize
#

# Run it like this:
#    find . -name "*.hrc" -exec ${SOURCES}/FixLocalizeErrors.sh '{}' \;
#    find . -name "*.src" -exec ${SOURCES}/FixLocalizeErrors.sh '{}' \;

# If gawk is found, use it, otherwise awk
# (Solaris' awk seems to have problems with this)
AWK=`which gawk`
[ ! -x "$AWK" -o -z "$AWK" ] && AWK=awk

${AWK} '{

# If there is no "Text" on the line, do not replace
if ( $0 !~ "[Tt][Ee][Xx][Tt]" )
  REPLACING=0
else # Now we have Text on the line...
# If there is backslash before ^M, start REPLACING...
if ( $0 ~ "[Tt][Ee][Xx][Tt].*\\[.*\\].*=.*\\\\[\r]?" )
  REPLACING=1

if ( REPLACING == 1 && $0 !~ "\\\\[\r]?$")
    sub (";[ \t\r]*$", "; \\", $0);

# Inch (") is merged like """ instead of "".
if ( $0 ~ "FUNIT_INCH" )
  sub ("\"\"\"", "\"\"", $0);

print
}' $1 >$1.pj
mv -f $1.pj $1
