]> SALOME platform Git repositories - tools/install.git/commitdiff
Salome HOME
Processing KERNEL7695:
authorvsr <vsr@opencascade.com>
Fri, 8 Apr 2005 12:14:37 +0000 (12:14 +0000)
committervsr <vsr@opencascade.com>
Fri, 8 Apr 2005 12:14:37 +0000 (12:14 +0000)
- indent setenva, setenvp, cleandup aliases/functions;
- comment setenva, setenvp, cleandup aliases/functions;
- optimize cleandup function
- for bash scripts exporta, exportp are used instead of setenva, setenvp

config_files/common.sh

index ea63d95a578658fcb9919ba768c7658ffecb1b44..7410799c69313ad6974ff44907332ada4fbef1c0 100755 (executable)
@@ -91,28 +91,140 @@ fi
 ### !!! writing salome.sh file !!! -> add global functions
 cat >> ${install_work}/$SHRC <<EOF
 export INSTALL_ROOT=${install_root}
-#$DELIM globals $DELIM
-setenvp() {
-    xenv=\$2:\`printenv \$1\`
-    out_var=\`echo \$xenv | awk -F: '{ n=0; r=1; s=\$1; x=0; for( i=2; i<=NF; i++ ){ v=\$i; t=1; if( v==s ) r=0; for( j=0; j<=n; j++ ){ if( keys[j]==v ){ t=0; break; } }; if( t ) keys[n++]=v; x=1; }; if( r ) printf "%s",s; if( x ) printf ":"; for( j=0; j<n; j++ ) { printf "%s",keys[j]; if( j<n-1 ) printf ":"; }; printf "\n"; }'\`
-    export \$1=\$out_var
-}
 
-setenva() {
-    xenv=\$2:\`printenv \$1\`
-    out_var=\`echo \$xenv | awk -F: '{ n=0; r=1; s=\$1; x=0; for( i=2; i<=NF; i++ ){ v=\$i; t=1; if( v==s ) r=0; for( j=0; j<=n; j++ ){ if( keys[j]==v ){ t=0; break; } }; if( t ) keys[n++]=v; x=1; }; for( j=0; j<n; j++ ) { printf "%s",keys[j]; if( j<n-1 ) printf ":"; }; if( r ) { if( x ) printf ":"; printf "%s",s; }; printf "\n"; }'\`
-    export \$1=\$out_var
+##########################################################################
+# Functions exporta and exportp are used to append/prepend correspondingly 
+# one directory or a set of directories separated by semicolon symbol (':')
+# to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
+# LD_RUN_PATH etc. 
+# The main purpose is to replace default setenv command behavior:
+# exporta, exportp also remove duplicated entries, shortening in that way
+# the environment variables.
+# If some directory being added is already included into the variable
+# nothing is done for it.
+# Note, that these functions work some slower that setenv command itself.
+#
+#### cleandup ###
+# appends/prepends set of directories (second parameter) 
+# to the another set of directories (first parameter) and
+# removes duplicated entries;
+# the third parameter defines the mode: 0 - append, 1 - prepend
+cleandup() {
+out_var=\`echo \$1 \$2 | awk -v dir=\$3 '{                   \\
+    na = split(\$2,a,":");                                \\
+    nb = split(\$1,b,":");                                \\
+    s = "" ;                                             \\
+    for(i=1;i<=nb;i++) {                                 \\
+       if(!(b[i] in ccc)) {                             \\
+           if(length(s)!=0)                             \\
+               s = sprintf("%s:",s);                    \\
+           s = sprintf("%s%s",s,b[i]);                  \\
+           ccc[b[i]];                                   \\
+       };                                               \\
+    };                                                   \\
+    s1 = "";                                             \\
+    for(i=1;i<=na;i++) {                                 \\
+       if(!(a[i] in ccc)) {                             \\
+           if(length(s1)!=0)                            \\
+               s1 = sprintf("%s:",s1);                  \\
+           s1 = sprintf("%s%s",s1,a[i]);                \\
+           ccc[a[i]];                                   \\
+       };                                               \\
+    };                                                   \\
+    if(dir)                                              \\
+       s = length(s) == 0 ? s1 : sprintf("%s:%s",s1,s); \\
+    else                                                 \\
+       s = length(s1) == 0 ? s : sprintf("%s:%s",s,s1); \\
+    printf("%s\n",s);                                    \\
+    }'\`
+echo \$out_var
+}
+### exporta ###
+# appends directory or set of directories, separated by ':' (second parameter)
+# to the variable (first parameter)
+exporta () { 
+xenv=\`printenv \$1\`
+out_var=\`cleandup \$xenv \$2 0\`
+export \$1=\$out_var
+}
+### exportp ###
+# prepends directory or set of directories, separated by ':' (second parameter)
+# to the variable (first parameter)
+exportp () { 
+xenv=\`printenv \$1\`
+out_var=\`cleandup \$xenv \$2 1\`
+export \$1=\$out_var
 }
+###########################################################################
+
 EOF
 ### !!! writing salome.csh file !!! -> add global aliases
 cat >> ${install_work}/$CSHRC <<EOF
 setenv INSTALL_ROOT ${install_root}
-#$DELIM globals $DELIM
-alias cleandup  "echo \!:1 | awk -F: '"'{ n=0; r=1; s=\$1; x=0; for( i=2; i<=NF; i++ ){ v=\$i; t=1; if( v==s ) r=0; for( j=0; j<=n; j++ ){ if( keys[j]==v ){ t=0; break; } }; if( t ) keys[n++]=v; x=1; }; if( r ) printf "%s",s; if( x ) printf ":"; for( j=0; j<n; j++ ) { printf "%s",keys[j]; if( j<n-1 ) printf ":"; }; printf "\n"; }'"'"
-alias cleandupr "echo \!:1 | awk -F: '"'{ n=0; r=1; s=\$1; x=0; for( i=2; i<=NF; i++ ){ v=\$i; t=1; if( v==s ) r=0; for( j=0; j<=n; j++ ){ if( keys[j]==v ){ t=0; break; } }; if( t ) keys[n++]=v; x=1; }; for( j=0; j<n; j++ ) { printf "%s",keys[j]; if( j<n-1 ) printf ":"; }; if( r ) { if( x ) printf ":"; printf "%s",s; }; printf "\n"; }'"'"
 
-alias setenva 'set a="\!:1" ; set b="'\!:2'":\`printenv \$a\` ; set b=\`cleandupr \$b\` ; setenv \$a \$b ; unset a, b'
-alias setenvp 'set a="\!:1" ; set b="'\!:2'":\`printenv \$a\` ; set b=\`cleandup  \$b\` ; setenv \$a \$b ; unset a, b'
+###########################################################################
+# Aliases setenva and setenvp are used to append/prepend correspondingly 
+# one directory or a set of directories separated by semicolon symbol (':')
+# to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
+# LD_RUN_PATH etc. 
+# The main purpose is to replace default setenv command behavior:
+# setenva, setenvp also remove duplicated entries, shortening in that way
+# the environment variables.
+# If some directory being added is already included into the variable
+# nothing is done for it.
+# Note, that these aliases work some slower that setenv command itself.
+#
+#### cleandup ###
+# appends/prepends set of directories (second parameter) 
+# to the another set of directories (first parameter) and
+# removes duplicated entries;
+# the third parameter defines the mode: 0 - append, 1 - prepend
+alias cleandup "echo \!:1 \!:2 | awk -v dir=\!:3         \\\\
+'"'{ na = split(\$2,a,":");                               \\\\
+     nb = split(\$1,b,":");                               \\\\
+     s = "" ;                                            \\\\
+     for(i=1;i<=nb;i++) {                                \\\\
+       if(!(b[i] in ccc)) {                             \\\\
+           if(length(s)!=0)                             \\\\
+               s = sprintf("%s:",s);                    \\\\
+           s = sprintf("%s%s",s,b[i]);                  \\\\
+           ccc[b[i]];                                   \\\\
+       };                                               \\\\
+    };                                                   \\\\
+    s1 = "";                                             \\\\
+    for(i=1;i<=na;i++) {                                 \\\\
+       if(!(a[i] in ccc)) {                             \\\\
+           if(length(s1)!=0)                            \\\\
+               s1 = sprintf("%s:",s1);                  \\\\
+           s1 = sprintf("%s%s",s1,a[i]);                \\\\
+           ccc[a[i]];                                   \\\\
+       };                                               \\\\
+    };                                                   \\\\
+    if(dir)                                              \\\\
+       s = length(s) == 0 ? s1 : sprintf("%s:%s",s1,s); \\\\
+    else                                                 \\\\
+       s = length(s1) == 0 ? s : sprintf("%s:%s",s,s1); \\\\
+    printf("%s\n",s);                                    \\\\
+    }'"'"
+### setenva ###
+# appends directory or set of directories, separated by ':' (second parameter)
+# to the variable (first parameter)
+alias setenva 'set a=\!:1 ; set b=\!:2 ;  \\
+               set c=\`printenv \$a\` ;      \\
+               set b=\`cleandup \$c \$b 0\` ; \\
+               setenv \$a \$b ;             \\
+               unset a, b, c'
+
+### setenvp ###
+# prepends directory or set of directories, separated by ':' (second parameter)
+# to the variable (first parameter)
+alias setenvp 'set a=\!:1 ; set b=\!:2 ;  \\
+               set c=\`printenv \$a\` ;      \\
+               set b=\`cleandup \$c \$b 1\` ; \\
+               setenv \$a \$b ;             \\
+               unset a, b, c'
+###########################################################################
+
 EOF
 ### !!! writing salome.csh file !!! -> set inital variables
 pre_vars="PATH LD_LIBRARY_PATH LD_RUN_PATH PYTHONPATH TCLLIBPATH"
@@ -127,13 +239,15 @@ done
 ### !!! writing salome.(c)sh files !!! -> dump products environment files, changing 'export' by 'setenv(a|p)' where necessary
 product_sequence="$2"
 for i in $product_sequence ; do
-    sed -e 's%^export\([[:blank:]]*\)PATH=\$[{]\?PATH[}]\?:\(.*\)%setenva\1PATH \2%g' -e 's%^export\([[:blank:]]*\)PATH=\(.*\):\$[{]\?PATH[}]\?%setenvp\1PATH \2%g' ${install_work}/env_${i}.sh > ${INSTALL_WORK}/_tmp1 2>/dev/null
-    sed -e 's%^export\([[:blank:]]*\)LD_LIBRARY_PATH=\$[{]\?LD_LIBRARY_PATH[}]\?:\(.*\)%setenva\1LD_LIBRARY_PATH \2%g' -e 's%^export\([[:blank:]]*\)LD_LIBRARY_PATH=\(.*\):\$[{]\?LD_LIBRARY_PATH[}]\?%setenvp\1LD_LIBRARY_PATH \2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
-    sed -e 's%^export\([[:blank:]]*\)PYTHONPATH=\$[{]\?PYTHONPATH[}]\?:\(.*\)%setenva\1PYTHONPATH \2%g' -e 's%^export\([[:blank:]]*\)PYTHONPATH=\(.*\):\$[{]\?PYTHONPATH[}]\?%setenvp\1PYTHONPATH \2%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
-    sed -e 's%^export\([[:blank:]]*\)LD_RUN_PATH=\$[{]\?LD_RUN_PATH[}]\?:\(.*\)%setenva\1LD_RUN_PATH \2%g' -e 's%^export\([[:blank:]]*\)LD_RUN_PATH=\(.*\):\$[{]\?LD_RUN_PATH[}]\?%setenvp\1LD_RUN_PATH \2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
+    sed -e 's%^export\([[:blank:]]*\)PATH=\$[{]\?PATH[}]\?:\(.*\)%exporta\1PATH \2%g' -e 's%^export\([[:blank:]]*\)PATH=\(.*\):\$[{]\?PATH[}]\?%exportp\1PATH \2%g' ${install_work}/env_${i}.sh > ${INSTALL_WORK}/_tmp1 2>/dev/null
+    sed -e 's%^export\([[:blank:]]*\)LD_LIBRARY_PATH=\$[{]\?LD_LIBRARY_PATH[}]\?:\(.*\)%exporta\1LD_LIBRARY_PATH \2%g' -e 's%^export\([[:blank:]]*\)LD_LIBRARY_PATH=\(.*\):\$[{]\?LD_LIBRARY_PATH[}]\?%exportp\1LD_LIBRARY_PATH \2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
+    sed -e 's%^export\([[:blank:]]*\)PYTHONPATH=\$[{]\?PYTHONPATH[}]\?:\(.*\)%exporta\1PYTHONPATH \2%g' -e 's%^export\([[:blank:]]*\)PYTHONPATH=\(.*\):\$[{]\?PYTHONPATH[}]\?%exportp\1PYTHONPATH \2%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
+    sed -e 's%^export\([[:blank:]]*\)LD_RUN_PATH=\$[{]\?LD_RUN_PATH[}]\?:\(.*\)%exporta\1LD_RUN_PATH \2%g' -e 's%^export\([[:blank:]]*\)LD_RUN_PATH=\(.*\):\$[{]\?LD_RUN_PATH[}]\?%exportp\1LD_RUN_PATH \2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
     cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/$SHRC 2>/dev/null
     
     sed -e 's%^export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
+    sed -e 's%^exporta \([[:alnum:]_[:blank:]]*\)%setenva \1%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
+    sed -e 's%^exportp \([[:alnum:]_[:blank:]]*\)%setenvp \1%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
     cat ${INSTALL_WORK}/_tmp1 >> ${install_work}/$CSHRC 2>/dev/null
 
     rm -f ${INSTALL_WORK}/_tmp1 ${INSTALL_WORK}/_tmp2