Changed scripts/Config to grab the version from lib/libsde.in instead of lib/functions.in
[opensde-nopast.git] / lib / core-functions.in
blob22e092c004e7e644bc9cd671dfb878d119e1d321
1 #!/bin/bash
2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # Filename: lib/core-functions.in
6 # Copyright (C) 2006 - 2008 The OpenSDE Project
7 # Copyright (C) 2004 - 2006 The T2 SDE Project
8 # Copyright (C) 1998 - 2003 Clifford Wolf
10 # More information can be found in the files COPYING and README.
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 ---
18 # translates a architecture name as of uname into the verbose t2 name
20 uname2arch()
22 sed -e s/i.86/x86/ -e s/ppc/powerpc/ -e s/x86_64/x86-64/ -e s/sh.$/sh/
25 # translates a architecture name os of t2 into the short uname name
27 arch2uname()
29 sed -e s/x86$/i386/ -e s/powerpc/ppc/ -e s/x86-64/x86_64/
32 # translate a architecture to the 32bit subset
34 arch2arch32()
36 sed -e s/[-_]*64// -e s/x86/i686/
39 # revert the order of the tokens
40 get_reverted() {
41 local queue=
42 while [ $# -gt 0 ]; do
43 queue="$1 $queue"
44 shift
45 done
46 echo $queue
49 # This functions append, insert or remove values in variables:
51 # var_append PATH ":" "$HOME/bin"
52 # var_insert CC_WRAPPER_INSERT " " "-O3"
53 # var_remove CC_WRAPPER_INSERT " " "-O3"
55 # var_remove_regex CC_WRAPPER_INSERT " " "-O.*"
57 # var_insert_before_regex patchfiles " " "mypatch.diff" ".*\/foo.diff"
59 # 1st Parameter: Variable Name
60 # 2nd Parameter: Delimiter Text
61 # 3rd Parameter: Value (or regex)
62 # 4th Parameter: regex for insert_before
64 var_append() {
65 eval "[ \"\$$1\" ] && $1=\"\${$1}$2\"" || true
66 eval "$1=\"\${$1}\$3\""
68 var_insert() {
69 eval "[ \"\$$1\" ] && $1=\"$2\$$1\"" || true
70 eval "$1=\"\$3\$$1\""
72 var_remove() {
73 local a=${2//\/\\/}
74 local b=${3//\/\\/}
75 eval '[ "$'$1'" = "$3" ] && '$1'= || true'
76 eval $1'="${'$1'//$a$b$a/$2}"'
77 eval $1'="${'$1'%$a$b}"'
78 eval $1'="${'$1'#$b$a}"'
80 var_remove_regex() {
81 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]; }'\`\""
83 var_insert_before_regex() {
84 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]; }'\`\""