pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkg_alternatives, Darwin and locale





Joerg Sonnenberger wrote:
On Sun, Jul 20, 2008 at 04:26:47AM +0200, Christian Biere wrote:
+cat "${userfile}" __CONF_FILE__ __DB_FILE__ 2>/dev/null | \
+{
+    while read line
+    do
+        line="${line##\#*}"
+ prog="${line%%\ *}" + if [ X != "X${prog}" ] && [ -x "${prog}" ]
+        then exec ${line} "${@}"
+        fi
+    done

Can you make this awk please? read is horrible slow for larger files...

Joerg



Sorry - there's a problem in that last patch (__CONF_FILES__ comes before $userfile). See attached for a corrected one.

Louis
--- pkgtools/pkg_alternatives/files/wrapper.sh.orig     2008-07-21 
08:17:07.000000000 -0400
+++ pkgtools/pkg_alternatives/files/wrapper.sh  2008-07-21 14:41:04.000000000 
-0400
@@ -44,18 +44,20 @@
 else
     userfile=~/.pkg_alternatives/${wrapper}
 fi
-alternatives=$(cat ${userfile} __CONF_FILE__ __DB_FILE__ 2>/dev/null | \
-               grep -v "^#" | tr ' ' '¬')
 
-found=
-for a in ${alternatives}; do
-    prog=$(echo ${a} | cut -d '¬' -f 1)
-    if [ -x ${prog} ]; then
-        found=$(echo ${a} | tr '¬' ' ')
-       break
-    fi
+files=__DB_FILE__
+for f in __CONF_FILE__ $userfile ;do
+  [ -f "$f" ] && files="$f $files"
 done
 
+found=$(awk '!/^[      ]*#/{
+  f = "if [ -x " $1 " ] ; then echo " $0 " ;fi " | getline found 
+  if ( f == 1 ) {
+    print found
+    exit
+  }
+}' $files )
+
 if [ -z "${found}" ]; then
     echo "${progname}: no alternatives found" 1>&2
     exit 1


Home | Main Index | Thread Index | Old Index