PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/i18npool/source/localedata/data/list-dateacceptancepattern.awk

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