Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sources.sh 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/sh
  2. inc_sources=true
  3. [ -z "$inc_xmlfiles" ] && . "$basedir/build/xmlfiles.sh"
  4. validate_tagmap(){
  5. tagmap="$basedir/tagmap"
  6. sed -rn 's;^(.*\.xml) +.*$;\1;p' "$tagmap" |while read fn; do
  7. [ -f "$fn" ] || touch -cd@0 "$tagmap"
  8. done
  9. }
  10. map_tags(){
  11. grep -l '</tag>' "$@" \
  12. | while read xml; do
  13. printf '%s ' "$xml"
  14. unicat "$xml" \
  15. | sed -rn '# Normalise XML (strip comments, unify white-spaces)
  16. :X; $bY; N; bX; :Y;
  17. s;[\n\t ]+; ;g;
  18. s; ?([</>]) ?;\1;g
  19. s;<!([^>]|<[^>]*>)*>;;g
  20. # Loop over <tags> section
  21. s;.*<tags( [^>])?>(.+)</tags>.*;\2;
  22. tK; b; :K;
  23. # Collect new format tags
  24. /<tag key="[^"]+"(\/>|>[^<]*<\/tag>)/{
  25. H; s;.*<tag key="([^"]+)"(/>|>[^<]*</tag>).*;\1;
  26. x; s;(.*)<tag key="([^"]+)"(/>|>[^<]*</tag>);\1;
  27. bK;
  28. }
  29. # Collect old format tags
  30. /<tag( [^>]+)?>([^<]+)<\/tag>/{
  31. H; s;.*<tag( [^>]+)?>([^<]+)</tag>.*;\2;
  32. x; s;(.*)<tag( [^>]+)?>([^<]+)</tag>;\1;
  33. bK;
  34. }
  35. H;x;
  36. # Loop end
  37. # delete junk (non-tag content in the tags section)
  38. s;\n+[^\n]*$;;
  39. # normalise tagnames
  40. y;ABCDEFGHIJKLMNOPQRSTUVWXYZ;abcdefghijklmnopqrstuvwxyz;
  41. s;[-_+ /];;g
  42. # put tags in one line and print
  43. s;(\n|$); ;g; p;
  44. '
  45. done
  46. }
  47. tagging_sourceglobs(){
  48. # read a .sources file and glob up referenced xml files for processing in list_sources
  49. sourcesfile="$1"
  50. [ -f "$sourcesfile" ] && grep ':\[.*\]$' "$sourcesfile" \
  51. | while read line; do
  52. glob="${line%:\[*\]}"
  53. tags="$(printf %s "$line" \
  54. | sed -r 's;^.+:\[(.*)\]$;\1;;
  55. y;ABCDEFGHIJKLMNOPQRSTUVWXYZ;abcdefghijklmnopqrstuvwxyz;
  56. s;[-_+ /];;g
  57. s;,; ;g
  58. ')"
  59. sourcefiles="$(printf '%s\n' "$basedir/"${glob}*.[a-z][a-z].xml)"
  60. for tag in $tags; do
  61. sourcefiles="$(printf '%s\n' "$sourcefiles" |grep -Ff "$basedir/tools/tagmaps/${tag}.map")"
  62. done
  63. printf '%s\n' "$sourcefiles"
  64. done \
  65. | sed -rn 's;^(.+).[a-z]{2}.xml$;\1;p' \
  66. | sort -u
  67. }
  68. legacy_sourceglobs(){
  69. # read a .sources file and glob up referenced
  70. # source files for processing in list_sources
  71. sourcesfile="$1"
  72. if [ -f "$sourcesfile" ]; then
  73. sed -rn 's;:global$;*.[a-z][a-z].xml;gp' "$sourcesfile" \
  74. | while read glob; do
  75. echo "$basedir/"$glob
  76. done \
  77. | sed -rn 's:\.[a-z]{2}\.xml( |$):\n:gp' \
  78. | sort -u
  79. fi
  80. }
  81. [ -z "$inc_misc" ] && . "$basedir/build/misc.sh"
  82. sourceglobs(){
  83. if [ "$legacyglobs" = true ]; then
  84. legacy_sourceglobs "$@"
  85. elif [ -f "$1" ] && ! egrep -q '^.+:\[.*\]$' "$1"; then
  86. debug "WARNING! File in legacy format: $1"
  87. legacy_sourceglobs "$@"
  88. else
  89. tagging_sourceglobs "$@"
  90. fi
  91. }
  92. list_sources(){
  93. # read a .sources file and generate a list
  94. # of all referenced xml files with preference
  95. # for a given language
  96. sourcesfile="$1"
  97. lang="$2"
  98. # Optional 3rd parameter: preglobbed list of source files
  99. # can lead to speed gain in some cases
  100. [ "$#" -ge 3 ] && \
  101. sourceglobs="$3" \
  102. || sourceglobs="$(sourceglobs "$sourcesfile")"
  103. for base in $sourceglobs; do
  104. echo "${base}".[a-z][a-z].xml "${base}".en.[x]ml "${base}.${lang}".[x]ml
  105. done |sed -rn 's;^(.* )?([^ ]+\.[a-z]{2}\.xml).*$;\2;p'
  106. }
  107. auto_sources(){
  108. # import elements from source files, add file name
  109. # attribute to first element included from each file
  110. sourcesfile="$1"
  111. lang="$2"
  112. list_sources "$sourcesfile" "$lang" \
  113. | while read source; do
  114. printf '\n### filename="%s" ###\n%s' "$source" "$(include_xml "$source")"
  115. done \
  116. | sed -r ':X; N; $!bX;
  117. s;\n### (filename="[^\n"]+") ###\n[^<]*(<![^>]+>[^<]*)*(<([^/>]+/)*([^/>]+))(/?>);\2\3 \1\6;g;
  118. '
  119. }
  120. lang_sources(){
  121. sourcesfile="$1"
  122. lang="$2"
  123. list_sources "$sourcesfile" "$lang"
  124. }
  125. cast_refglobs(){
  126. true
  127. }
  128. cast_langglob(){
  129. true
  130. }