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.

xmlfiles.sh 939B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. inc_xmlfiles=true
  3. unicat(){
  4. # convert XML files to UTF-8
  5. for file in "$@"; do
  6. enc="$(sed -nr 'bA; :Q q; :A s:^.*<\?.*encoding="([^"]+)".*$:\1:p; tQ' "$file")"
  7. iconv -f "${enc:-UTF-8}" -t "UTF-8" "$file"
  8. done
  9. }
  10. include_xml(){
  11. # include second level elements of a given XML file
  12. # this emulates the behaviour of the original
  13. # build script which wasn't able to load top
  14. # level elements from any file
  15. file="$1"
  16. if [ -f "$file" ]; then
  17. unicat "$file" \
  18. | sed -r ':X; $bY; N; bX; :Y;
  19. s:<(\?[xX][mM][lL]|!DOCTYPE)[[:space:]]+[^>]+>::g
  20. s:<[^!][^>]*>::;
  21. s:</[^>]*>([^<]*((<[^>]+/>|<!([^>]|<[^>]*>)*>|<\?[^>]+>)[^<]*)*)?$:\1:;'
  22. fi
  23. }
  24. get_attributes(){
  25. # get attributes of top level element in a given
  26. # XHTML file
  27. file="$1"
  28. sed -rn ':X; N; $!bX;
  29. s;^.*<[\n\t\r ]*([xX]|[xX]?[hH][tT])[mM][lL][\n\t\r ]+([^>]*)>.*$;\2;p' \
  30. "$file"
  31. }