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.

86 lines
2.5 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: lib/core-functions.in
  6. # Copyright (C) 2006 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. # translates a architecture name as of uname into the verbose t2 name
  18. #
  19. uname2arch()
  20. {
  21. sed -e s/i.86/x86/ -e s/ppc/powerpc/ -e s/x86_64/x86-64/ -e s/sh.$/sh/
  22. }
  23. # translates a architecture name os of t2 into the short uname name
  24. #
  25. arch2uname()
  26. {
  27. sed -e s/x86$/i386/ -e s/powerpc/ppc/ -e s/x86-64/x86_64/
  28. }
  29. # translate a architecture to the 32bit subset
  30. #
  31. arch2arch32()
  32. {
  33. sed -e s/[-_]*64// -e s/x86/i686/
  34. }
  35. # revert the order of the tokens
  36. get_reverted() {
  37. local queue=
  38. while [ $# -gt 0 ]; do
  39. queue="$1 $queue"
  40. shift
  41. done
  42. echo $queue
  43. }
  44. # This functions append, insert or remove values in variables:
  45. #
  46. # var_append PATH ":" "$HOME/bin"
  47. # var_insert CC_WRAPPER_INSERT " " "-O3"
  48. # var_remove CC_WRAPPER_INSERT " " "-O3"
  49. #
  50. # var_remove_regex CC_WRAPPER_INSERT " " "-O.*"
  51. #
  52. # var_insert_before_regex patchfiles " " "mypatch.diff" ".*\/foo.diff"
  53. #
  54. # 1st Parameter: Variable Name
  55. # 2nd Parameter: Delimiter Text
  56. # 3rd Parameter: Value (or regex)
  57. # 4th Parameter: regex for insert_before
  58. #
  59. var_append() {
  60. eval "[ \"\$$1\" ] && $1=\"\${$1}$2\"" || true
  61. eval "$1=\"\${$1}\$3\""
  62. }
  63. var_insert() {
  64. eval "[ \"\$$1\" ] && $1=\"$2\$$1\"" || true
  65. eval "$1=\"\$3\$$1\""
  66. }
  67. var_remove() {
  68. local a=${2//\/\\/}
  69. local b=${3//\/\\/}
  70. eval '[ "$'$1'" = "$3" ] && '$1'="" || true'
  71. eval $1'="${'$1'//$a$b$a/$2}"'
  72. eval $1'="${'$1'%$a$b}"'
  73. eval $1'="${'$1'#$b$a}"'
  74. }
  75. var_remove_regex() {
  76. eval "$1=\"\`echo \"\$$1\" | awk -- ' { split(\$0, a, \"$2\"); for (c1=c2=1; c1 in a; c1++) if ( a[c1] !~ /^$3\\\$/ ) b[c2++]=a[c1]; for (c1=1; c1 in b; c1++) printf \"%s%s\", (c1 > 0 ? \"$2\" : \"\"), b[c1]; }'\`\""
  77. }
  78. var_insert_before_regex() {
  79. eval "$1=\"\`echo \"\$$1\" | awk -- '{ split(\$0, a, \"$2\"); for (d=c1=c2=1; c1 in a; c1++) { if ( d && a[c1] ~ /^$4\\\$/ ) { b[c2++]=\"$3\"; d=0; } b[c2++]=a[c1]; } if (d) b[c2++]=\"$3\"; for (c1=1; c1 in b; c1++) printf \"%s%s\", (c1 > 0 ? \"$2\" : \"\"), b[c1]; }'\`\""
  80. }