| 1 |
#!/usr/bin/gawk -f |
| 2 |
# -*- Mode: awk; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 3 |
# |
| 4 |
# This file is part of the LibreOffice project. |
| 5 |
# |
| 6 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 7 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 |
|
| 10 |
# Usage: gawk -f list-dateacceptancepattern.awk *.xml [--sep [--html]] |
| 11 |
# |
| 12 |
# Outputs three lists of locales, one with DateAcceptancePattern elements |
| 13 |
# defined, one with inherited LC_FORMAT elements and thus date patterns, and |
| 14 |
# one where no DateAcceptancePattern are defined. |
| 15 |
# |
| 16 |
# If --sep is given, display date separator for each locale. |
| 17 |
# If --html is given as the last parameter, format output suitable for |
| 18 |
# inclusion in HTML. |
| 19 |
|
| 20 |
BEGIN { |
| 21 |
html = 0 |
| 22 |
if (ARGV[ARGC-1] == "--html") { |
| 23 |
html = 1 |
| 24 |
--ARGC |
| 25 |
} |
| 26 |
sep = 0 |
| 27 |
if (ARGV[ARGC-1] == "--sep") { |
| 28 |
sep = 1 |
| 29 |
--ARGC |
| 30 |
} |
| 31 |
file = "" |
| 32 |
offlocale = 0 |
| 33 |
offpatterncount = 1 |
| 34 |
offinherit = 2 |
| 35 |
offbequeath = 3 |
| 36 |
offdatesep = 4 |
| 37 |
offdateformat = 5 |
| 38 |
offpatterns = 6 |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
file != FILENAME { |
| 43 |
if (file) |
| 44 |
endFile() |
| 45 |
file = FILENAME |
| 46 |
patterncount = 0 |
| 47 |
inherited = "" |
| 48 |
formatelement = 0 |
| 49 |
datesep = "" |
| 50 |
dateformat = "" |
| 51 |
} |
| 52 |
|
| 53 |
/<DateAcceptancePattern>/ { |
| 54 |
split( $0, a, /<|>/ ) |
| 55 |
patterns[patterncount++] = a[3] |
| 56 |
} |
| 57 |
|
| 58 |
# pattern inherited as well |
| 59 |
/<LC_FORMAT[^>]* ref="[^>"]+"[^>]*>/ { |
| 60 |
split( $0, a, /.* ref="|"/ ) |
| 61 |
inherited = a[2] |
| 62 |
} |
| 63 |
|
| 64 |
/<FormatElement[^>]* formatindex="21"[^>]*>/ { formatelement = 1 } |
| 65 |
/<FormatCode>/ { |
| 66 |
if (formatelement) |
| 67 |
{ |
| 68 |
formatelement = 0 |
| 69 |
split( $0, a, /<|>/ ) |
| 70 |
split( a[3], b, /[0-9A-Za-z\[~\]]+/ ) |
| 71 |
datesep = b[2] |
| 72 |
dateformat = a[3] |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
END { |
| 78 |
if (file) |
| 79 |
endFile() |
| 80 |
|
| 81 |
fillAllInherited() |
| 82 |
|
| 83 |
PROCINFO["sorted_in"] = "@ind_str_asc" |
| 84 |
|
| 85 |
if (html) |
| 86 |
print "<p>" |
| 87 |
else |
| 88 |
print "" |
| 89 |
printLine( "Trailing + indicates that another locale inherits from this." ) |
| 90 |
if (sep) |
| 91 |
printLine( "Appended is the locale's date separator and edit format code." ) |
| 92 |
printLine("") |
| 93 |
printLine( "Locales with explicit DateAcceptancePattern elements:" ) |
| 94 |
if (html) |
| 95 |
{ |
| 96 |
print "<ul>" |
| 97 |
for (i in LocaleList) |
| 98 |
{ |
| 99 |
if (LocaleList[i][offpatterns][0]) |
| 100 |
{ |
| 101 |
print " <li> " getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) |
| 102 |
print " <ul>" |
| 103 |
for (p = 0; p < LocaleList[i][offpatterncount]; ++p) |
| 104 |
{ |
| 105 |
print " <li> " LocaleList[i][offpatterns][p] |
| 106 |
} |
| 107 |
print " </ul>" |
| 108 |
} |
| 109 |
} |
| 110 |
print "</ul>" |
| 111 |
print "\n<p>" |
| 112 |
} |
| 113 |
else |
| 114 |
{ |
| 115 |
for (i in LocaleList) |
| 116 |
{ |
| 117 |
if (LocaleList[i][offpatterns][0]) |
| 118 |
{ |
| 119 |
print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) |
| 120 |
for (p = 0; p < LocaleList[i][offpatterncount]; ++p) |
| 121 |
{ |
| 122 |
print " " LocaleList[i][offpatterns][p] |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
print "\n" |
| 127 |
} |
| 128 |
|
| 129 |
printLine( "Locales inheriting patterns:" ) |
| 130 |
if (html) |
| 131 |
{ |
| 132 |
for (i in LocaleList) |
| 133 |
{ |
| 134 |
if (LocaleList[i][offinherit] && LocaleList[i][offpatterncount]) |
| 135 |
print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) " " |
| 136 |
} |
| 137 |
print "\n<p>" |
| 138 |
} |
| 139 |
else |
| 140 |
{ |
| 141 |
for (i in LocaleList) |
| 142 |
{ |
| 143 |
if (LocaleList[i][offinherit] && LocaleList[i][offpatterncount]) |
| 144 |
print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) |
| 145 |
} |
| 146 |
print "\n" |
| 147 |
} |
| 148 |
|
| 149 |
printLine( "Locales without explicit DateAcceptancePattern elements:" ) |
| 150 |
printLine( "(one implicit full date pattern is always generated)" ) |
| 151 |
if (html) |
| 152 |
{ |
| 153 |
print "<p>" |
| 154 |
for (i in LocaleList) |
| 155 |
{ |
| 156 |
if (!LocaleList[i][offpatterncount]) |
| 157 |
print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) " " |
| 158 |
} |
| 159 |
} |
| 160 |
else |
| 161 |
{ |
| 162 |
for (i in LocaleList) |
| 163 |
{ |
| 164 |
if (!LocaleList[i][offpatterncount]) |
| 165 |
print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
function printLine( text ) { |
| 172 |
print text |
| 173 |
if (html) |
| 174 |
print "<br>" |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
function endFile( locale ) { |
| 179 |
locale = getLocale( file) |
| 180 |
LocaleList[locale][offlocale] = locale |
| 181 |
LocaleList[locale][offpatterncount] = patterncount |
| 182 |
LocaleList[locale][offdatesep] = datesep |
| 183 |
LocaleList[locale][offdateformat] = dateformat |
| 184 |
if (patterncount) |
| 185 |
{ |
| 186 |
for ( i=0; i<patterncount; ++i ) |
| 187 |
{ |
| 188 |
LocaleList[locale][offpatterns][i] = patterns[i] |
| 189 |
} |
| 190 |
} |
| 191 |
else if (inherited) |
| 192 |
LocaleList[locale][offinherit] = inherited |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
function getLocale( file, tmp ) { |
| 197 |
tmp = file |
| 198 |
gsub( /.*\//, "", tmp ) |
| 199 |
gsub( /\.xml/, "", tmp ) |
| 200 |
return tmp |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
function fillInherited( locale ) { |
| 205 |
LocaleList[locale][offbequeath] = 1 |
| 206 |
if (!LocaleList[locale][offpatterncount] && LocaleList[locale][offinherit]) |
| 207 |
LocaleList[locale][offpatterncount] = fillInherited( LocaleList[locale][offinherit]) |
| 208 |
return LocaleList[locale][offpatterncount] |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
function fillAllInherited( i ) { |
| 213 |
for (i in LocaleList) |
| 214 |
{ |
| 215 |
LocaleList[i][offbequeath] = 0 |
| 216 |
} |
| 217 |
for (i in LocaleList) |
| 218 |
{ |
| 219 |
if (!LocaleList[i][offpatterncount] && LocaleList[i][offinherit]) |
| 220 |
LocaleList[i][offpatterncount] = fillInherited( LocaleList[i][offinherit]) |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
function getInheritance( str, locale ) { |
| 226 |
if (LocaleList[locale][offbequeath]) |
| 227 |
str = str " +" |
| 228 |
if (LocaleList[locale][offinherit]) |
| 229 |
str = getInheritance( str " = " LocaleList[locale][offinherit], LocaleList[locale][offinherit]) |
| 230 |
else if (sep) |
| 231 |
str = str "\t'" LocaleList[locale][offdatesep] "' (" LocaleList[locale][offdateformat] ")" |
| 232 |
return str |
| 233 |
} |
| 234 |
|
| 235 |
# vim:set shiftwidth=4 softtabstop=4 expandtab: |