OpenSDE Framework (without history before r20070)
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.

100 lines
2.2 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: lib/sde-config/pkgsel2awk.sh
  6. # Copyright (C) 2006 - 2007 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; version 2 of the License. A copy of the
  15. # GNU General Public License can be found in the file COPYING.
  16. # --- SDE-COPYRIGHT-NOTE-END ---
  17. # Convert a pkg selection rule into awk format
  18. #
  19. # Example:
  20. # pkgsel X python
  21. # Result: ( / [^/]*\/python / ) { $1="X"; }
  22. # pkgsel "O perl/*"
  23. # Result: ( / perl\/[^/]* / ) { $1="O"; }
  24. # pkgsel_parse < config/${config}/pkgsel
  25. # Result: creates pkgsel.awk output
  26. # pkgsel include file
  27. # Result: continues processing file specified
  28. pkgsel_pattern() {
  29. local pattern= xpattern=
  30. local address=
  31. for xpattern; do
  32. pattern="${xpattern#\!}"
  33. [ "$pattern" = "$xpattern" ]; neg=$?
  34. [ "${pattern}" = "${pattern//\//}" ] && pattern="*/$pattern"
  35. pattern="$( echo "$pattern" | sed \
  36. -e 's,[^a-zA-Z0-9_/\*+\-\[\]],,g' \
  37. -e 's,[/\.\+],\\\\&,g' \
  38. -e 's,\*,[^/]*,g' )"
  39. [ -z "$address" ] || address="$address &&"
  40. if [ $neg -eq 0 ]; then
  41. address="$address( \$5 ~ \"^${pattern}\$\" )"
  42. else
  43. address="$address( \$5 !~ \"^${pattern}\$\" )"
  44. fi
  45. done
  46. echo "$address"
  47. }
  48. pkgsel_parse() {
  49. local action patterlist
  50. local address first others
  51. sed -e '/^#/d;' -e '/^[ \t]*$/d;' "$@" | while read action patternlist ; do
  52. case "$action" in
  53. [xX])
  54. action='$1="X"' ;;
  55. [oO])
  56. action='$1="O"' ;;
  57. -)
  58. action='next' ;;
  59. =)
  60. action='$1=def' ;;
  61. include)
  62. pkgsel_parse $patternlist
  63. continue ;;
  64. *)
  65. echo '{ exit; }'
  66. continue ;;
  67. esac
  68. address=$( pkgsel_pattern "$patternlist" )
  69. echo "{ if ( $address ) { $action; } }"
  70. done
  71. }
  72. cat <<EOF
  73. {
  74. def=\$1 ;
  75. repo=\$4 ;
  76. pkg=\$5 ;
  77. \$5 = \$4 "/" \$5 ;
  78. \$4 = "placeholder" ;
  79. }
  80. EOF
  81. pkgsel_parse "$@"
  82. cat <<EOF
  83. {
  84. \$4=repo ;
  85. \$5=pkg ;
  86. print ;
  87. }
  88. EOF