#!/usr/bin/gawk -f # # This file is part of the LibreOffice project. # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # This file incorporates work covered by the following license notice: # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed # with this work for additional information regarding copyright # ownership. The ASF licenses this file to you under the Apache # License, Version 2.0 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.apache.org/licenses/LICENSE-2.0 . # # Usage: gawk -f currency-check.awk *.xml # Check any # ...[$xxx-...]... # against every # xxx # definition of the same XML file and output symbols if no match was found. # For formatindex="12" to formatindex="15" and for formatindex="17" it is # checked if the used currency symbol is the usedInCompatibleFormatCodes # currency symbol as it is needed by the number formatter. # Also generates output if the generic currency symbol (UTF8 string 0xC2A4) # is used instead of a real currency symbol. # Author: Eike Rathke BEGIN { file = "" } file != FILENAME { if ( file ) checkIt() file = FILENAME line = 0 nFormats = 0 nCurrencies = 0 bFormatAuto = 0 sReplaceFrom = "" sReplaceTo = "" sMatchReplace = "" sRefCurrencyFromLocale = "" crlf = 0 } { ++line # If run under Unix a CrLf spoils ...$ line end checks. DOS line endings # are boo anyways. if ( /\x0D$/ ) { print "Error: not Unix line ending in line " line crlf = 1 exit(1) } if ( $1 ~ /^|$)/ ) { if ( $0 ~ /replaceFrom="\[CURRENCY\]"/ ) { sReplaceFrom = "\\[CURRENCY\\]" sMatchReplace = "^.*" sReplaceFrom } for ( j=2; j<=NF; ++j ) { if ( $j ~ /^replaceTo="/ ) { l = 12 if ( $j ~ />$/ ) ++l if ( $j ~ /\/>$/ ) ++l sReplaceTo = substr( $j, 12, length($j)-l ) } } } else if ( $1 ~ /^|$)/ ) { if ( $0 ~ /usage="CURRENCY"/ ) { if ( $0 ~ /formatindex="1[23457]"/ ) bFormatAuto = 1 else bFormatAuto = 0 } } else if ( $0 ~ /^[[:blank:]]*.*\[\$.*-[0-9a-fA-F]+\]/ || (sMatchReplace && $0 ~ sMatchReplace ) ) { if ( sReplaceFrom ) gsub( sReplaceFrom, sReplaceTo ) split( $0, arr, /<|>/ ) split( arr[3], code, /(\[\$)|(-[0-9a-fA-F]+\])/ ) for ( j in code ) { if ( code[j] && code[j] !~ /\#|0|\[NatNum/ ) { FormatLine[nFormats] = file " line " line FormatAuto[nFormats] = bFormatAuto Formats[nFormats++] = code[j] } } bFormatAuto = 0 } else if ( $1 ~ /^|$)/ ) { for ( j=2; j<=NF; ++j ) { if ( $j ~ /^ref="/ ) { l = 6 if ( $j ~ />$/ ) ++l if ( $j ~ /\/>$/ ) ++l locale = substr( $j, 6, length($j)-l ) sRefCurrencyFromLocale = file oldfile = file oldline = line file = locale ".xml" line = 0 while ( (getline 0 ) { ++line getCurrencyParams() } close( file ) if ( !line ) print "ref locale not available: " file \ " (from " oldfile " line " oldline ")" file = oldfile line = oldline sRefCurrencyFromLocale = "" } } } else getCurrencyParams() } END { if ( file && !crlf ) checkIt() } function getCurrencyParams() { # Assumes that each element is on a line on its own! if ( $1 ~ /^|$)/ ) { if ( $0 ~ /default="true"/ ) SymbolDefault[nCurrencies] = 1 else SymbolDefault[nCurrencies] = 0 if ( $0 ~ /usedInCompatibleFormatCodes="true"/ ) SymbolCompati[nCurrencies] = 1 else SymbolCompati[nCurrencies] = 0 } else if ( $0 ~ /^[[:blank:]]*/ ) { split( $0, arr, /<|>/ ) if ( sRefCurrencyFromLocale ) IDLine[nCurrencies] = file " line " line \ " (referenced from " sRefCurrencyFromLocale ")" else IDLine[nCurrencies] = file " line " line IDs[nCurrencies] = arr[3] } else if ( $0 ~ /^[[:blank:]]*/ ) { split( $0, arr, /<|>/ ) if ( sRefCurrencyFromLocale ) SymbolLine[nCurrencies] = file " line " line \ " (referenced from " sRefCurrencyFromLocale ")" else SymbolLine[nCurrencies] = file " line " line Symbols[nCurrencies] = arr[3] } else if ( $0 ~ /^[[:blank:]]*/ ) { split( $0, arr, /<|>/ ) if ( sRefCurrencyFromLocale ) BankSymbolLine[nCurrencies] = file " line " line \ " (referenced from " sRefCurrencyFromLocale ")" else BankSymbolLine[nCurrencies] = file " line " line BankSymbols[nCurrencies] = arr[3] } else if ( $1 ~ /^<\/Currency>/ ) { ++nCurrencies } } function checkIt() { bad = 0 for ( j=0; j