 cat >> confdefs.h <<EOF
+ #define $ac_tr_func 1
+ EOF
+  
+ else
+   echo "$ac_t""no" 1>&4
+ fi
+ done
+ 
+ 		  for ac_func in shl_load
+ do
+ echo $ac_n "checking for $ac_func""... $ac_c" 1>&4
+ if eval "test \"`echo '${'ac_cv_func_$ac_func'+set}'`\" = set"; then
+   echo $ac_n "(cached) $ac_c" 1>&4
+ else
+   cat > conftest.$ac_ext <<EOF
+ #line 1340 "configure"
+ #include "confdefs.h"
+ #include <ctype.h> /* Arbitrary system header to define __stub macros. */
+ /* Override any gcc2 internal prototype to avoid an error.  */
+ char $ac_func(); 
+ 
+ int main() { return 0; }
+ int t() {
+ 
+ /* The GNU C library defines this for functions which it implements
+     to always fail with ENOSYS.  Some functions are actually named
+     something starting with __ and the normal name is an alias.  */
+ #if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+ choke me
+ #else
+ $ac_func();
+ #endif
+ 
+ ; return 0; }
+ EOF
+ if eval $ac_link; then
+   rm -rf conftest*
+   eval "ac_cv_func_$ac_func=yes"
+ else
+   rm -rf conftest*
+   eval "ac_cv_func_$ac_func=no"
+ fi
+ rm -f conftest*
+ 
+ fi
+ if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
+   echo "$ac_t""yes" 1>&4
+     ac_tr_func=HAVE_`echo $ac_func | tr 'a-z' 'A-Z'`
+   cat >> confdefs.h <<EOF
+ #define $ac_tr_func 1
+ EOF
+  
+ else
+   echo "$ac_t""no" 1>&4
+ fi
+ done
+ 
+ 	      fi
+ fi
+ 
+ # Check whether --enable-dlopen or --disable-dlopen was given.
+ enableval="$enable_dlopen"
+ if test -n "$enableval"; then
+   if test "$enableval" = "yes"; then
+ 		  echo $ac_n "checking for -ldl""... $ac_c" 1>&4
+ if eval "test \"`echo '${'ac_cv_lib_dl'+set}'`\" = set"; then
+   echo $ac_n "(cached) $ac_c" 1>&4
+ else
+   ac_save_LIBS="$LIBS"
+ LIBS="$LIBS -ldl "
+ cat > conftest.$ac_ext <<EOF
+ #line 1396 "configure"
+ #include "confdefs.h"
+ 
+ int main() { return 0; }
+ int t() {
+ dlopen()
+ ; return 0; }
+ EOF
+ if eval $ac_link; then
+   rm -rf conftest*
+   eval "ac_cv_lib_dl=yes"
+ else
+   rm -rf conftest*
+   eval "ac_cv_lib_dl=no"
+ fi
+ rm -f conftest*
+ LIBS="$ac_save_LIBS"
+ 
+ fi
+ if eval "test \"`echo '$ac_cv_lib_'dl`\" = yes"; then
+   echo "$ac_t""yes" 1>&4
+     ac_tr_lib=HAVE_LIB`echo dl | tr 'a-z' 'A-Z'`
+   cat >> confdefs.h <<EOF
+ #define $ac_tr_lib 1
+ EOF
+ 
+   LIBS="$LIBS -ldl"
+ 
+ else
+   echo "$ac_t""no" 1>&4
+ fi
+ 
+ 	          echo $ac_n "checking for -ldld""... $ac_c" 1>&4
+ if eval "test \"`echo '${'ac_cv_lib_dld'+set}'`\" = set"; then
+   echo $ac_n "(cached) $ac_c" 1>&4
+ else
+   ac_save_LIBS="$LIBS"
+ LIBS="$LIBS -ldld "
+ cat > conftest.$ac_ext <<EOF
+ #line 1435 "configure"
+ #include "confdefs.h"
+ 
+ int main() { return 0; }
+ int t() {
+ shl_load()
+ ; return 0; }
+ EOF
+ if eval $ac_link; then
+   rm -rf conftest*
+   eval "ac_cv_lib_dld=yes"
+ else
+   rm -rf conftest*
+   eval "ac_cv_lib_dld=no"
+ fi
+ rm -f conftest*
+ LIBS="$ac_save_LIBS"
+ 
+ fi
+ if eval "test \"`echo '$ac_cv_lib_'dld`\" = yes"; then
+   echo "$ac_t""yes" 1>&4
+     ac_tr_lib=HAVE_LIB`echo dld | tr 'a-z' 'A-Z'`
+   cat >> confdefs.h <<EOF
+ #define $ac_tr_lib 1
+ EOF
+ 
+   LIBS="$LIBS -ldld"
+ 
+ else
+   echo "$ac_t""no" 1>&4
+ fi
+ 
  	          for ac_func in dlopen
  do
  echo $ac_n "checking for $ac_func""... $ac_c" 1>&4
***************
*** 1246,1252 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1250 "configure"
  #include "confdefs.h"
  #include <ctype.h> /* Arbitrary system header to define __stub macros. */
  /* Override any gcc2 internal prototype to avoid an error.  */
--- 1470,1525 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1474 "configure"
! #include "confdefs.h"
! #include <ctype.h> /* Arbitrary system header to define __stub macros. */
! /* Override any gcc2 internal prototype to avoid an error.  */
! char $ac_func(); 
! 
! int main() { return 0; }
! int t() {
! 
! /* The GNU C library defines this for functions which it implements
!     to always fail with ENOSYS.  Some functions are actually named
!     something starting with __ and the normal name is an alias.  */
! #if defined (__stub_$ac_func) || defined (__stub___$ac_func)
! choke me
! #else
! $ac_func();
! #endif
! 
! ; return 0; }
! EOF
! if eval $ac_link; then
!   rm -rf conftest*
!   eval "ac_cv_func_$ac_func=yes"
! else
!   rm -rf conftest*
!   eval "ac_cv_func_$ac_func=no"
! fi
! rm -f conftest*
! 
! fi
! if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
!   echo "$ac_t""yes" 1>&4
!     ac_tr_func=HAVE_`echo $ac_func | tr 'a-z' 'A-Z'`
!   cat >> confdefs.h <<EOF
! #define $ac_tr_func 1
! EOF
!  
! else
!   echo "$ac_t""no" 1>&4
! fi
! done
! 
! 		  for ac_func in shl_load
! do
! echo $ac_n "checking for $ac_func""... $ac_c" 1>&4
! if eval "test \"`echo '${'ac_cv_func_$ac_func'+set}'`\" = set"; then
!   echo $ac_n "(cached) $ac_c" 1>&4
! else
!   cat > conftest.$ac_ext <<EOF
! #line 1523 "configure"
  #include "confdefs.h"
  #include <ctype.h> /* Arbitrary system header to define __stub macros. */
  /* Override any gcc2 internal prototype to avoid an error.  */
***************
*** 1302,1308 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1306 "configure"
  #include "confdefs.h"
  #include <$ac_hdr>
  EOF
--- 1575,1581 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1579 "configure"
  #include "confdefs.h"
  #include <$ac_hdr>
  EOF
***************
*** 1338,1344 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1342 "configure"
  #include "confdefs.h"
  #include <$ac_hdr>
  EOF
--- 1611,1617 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1615 "configure"
  #include "confdefs.h"
  #include <$ac_hdr>
  EOF
***************
*** 1374,1380 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1378 "configure"
  #include "confdefs.h"
  #include <$ac_hdr>
  EOF
--- 1647,1653 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1651 "configure"
  #include "confdefs.h"
  #include <$ac_hdr>
  EOF
***************
*** 1410,1416 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1414 "configure"
  #include "confdefs.h"
  #include <ctype.h> /* Arbitrary system header to define __stub macros. */
  /* Override any gcc2 internal prototype to avoid an error.  */
--- 1683,1689 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1687 "configure"
  #include "confdefs.h"
  #include <ctype.h> /* Arbitrary system header to define __stub macros. */
  /* Override any gcc2 internal prototype to avoid an error.  */
***************
*** 1459,1465 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1463 "configure"
  #include "confdefs.h"
  #include <ctype.h> /* Arbitrary system header to define __stub macros. */
  /* Override any gcc2 internal prototype to avoid an error.  */
--- 1732,1738 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1736 "configure"
  #include "confdefs.h"
  #include <ctype.h> /* Arbitrary system header to define __stub macros. */
  /* Override any gcc2 internal prototype to avoid an error.  */
***************
*** 1508,1514 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1512 "configure"
  #include "confdefs.h"
  #include <ctype.h> /* Arbitrary system header to define __stub macros. */
  /* Override any gcc2 internal prototype to avoid an error.  */
--- 1781,1787 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1785 "configure"
  #include "confdefs.h"
  #include <ctype.h> /* Arbitrary system header to define __stub macros. */
  /* Override any gcc2 internal prototype to avoid an error.  */
***************
*** 1557,1563 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1561 "configure"
  #include "confdefs.h"
  #include <ctype.h> /* Arbitrary system header to define __stub macros. */
  /* Override any gcc2 internal prototype to avoid an error.  */
--- 1830,1836 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1834 "configure"
  #include "confdefs.h"
  #include <ctype.h> /* Arbitrary system header to define __stub macros. */
  /* Override any gcc2 internal prototype to avoid an error.  */
***************
*** 1606,1612 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1610 "configure"
  #include "confdefs.h"
  #include <ctype.h> /* Arbitrary system header to define __stub macros. */
  /* Override any gcc2 internal prototype to avoid an error.  */
--- 1879,1885 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1883 "configure"
  #include "confdefs.h"
  #include <ctype.h> /* Arbitrary system header to define __stub macros. */
  /* Override any gcc2 internal prototype to avoid an error.  */
***************
*** 1653,1659 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1657 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #include <sys/time.h>
--- 1926,1932 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1930 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #include <sys/time.h>
***************
*** 1690,1696 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1694 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #include <$ac_hdr>
--- 1963,1969 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1967 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #include <$ac_hdr>
***************
*** 1729,1735 ****
    ac_save_LIBS="$LIBS"
  LIBS="$LIBS -ldir "
  cat > conftest.$ac_ext <<EOF
! #line 1733 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
--- 2002,2008 ----
    ac_save_LIBS="$LIBS"
  LIBS="$LIBS -ldir "
  cat > conftest.$ac_ext <<EOF
! #line 2006 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
***************
*** 1763,1769 ****
    ac_save_LIBS="$LIBS"
  LIBS="$LIBS -lx "
  cat > conftest.$ac_ext <<EOF
! #line 1767 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
--- 2036,2042 ----
    ac_save_LIBS="$LIBS"
  LIBS="$LIBS -lx "
  cat > conftest.$ac_ext <<EOF
! #line 2040 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
***************
*** 1796,1802 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1800 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #include <sys/wait.h>
--- 2069,2075 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 2073 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #include <sys/wait.h>
***************
*** 1836,1842 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1840 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #if STDC_HEADERS
--- 2109,2115 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 2113 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #if STDC_HEADERS
***************
*** 1867,1873 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1871 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #include <signal.h>
--- 2140,2146 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 2144 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #include <signal.h>
***************
*** 1902,1908 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 1906 "configure"
  #include "confdefs.h"
  #include <vfork.h>
  EOF
--- 2175,2181 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 2179 "configure"
  #include "confdefs.h"
  #include <vfork.h>
  EOF
***************
*** 1937,1943 ****
    ac_cv_func_vfork=no
  else
  cat > conftest.$ac_ext <<EOF
! #line 1941 "configure"
  #include "confdefs.h"
  /* Thanks to Paul Eggert for this test.  */
  #include <stdio.h>
--- 2210,2216 ----
    ac_cv_func_vfork=no
  else
  cat > conftest.$ac_ext <<EOF
! #line 2214 "configure"
  #include "confdefs.h"
  /* Thanks to Paul Eggert for this test.  */
  #include <stdio.h>
***************
*** 2069,2075 ****
      CFLAGS="$CFLAGS -Werror"
  fi
  cat > conftest.$ac_ext <<EOF
! #line 2073 "configure"
  #include "confdefs.h"
  
  #include <stdio.h>
--- 2342,2348 ----
      CFLAGS="$CFLAGS -Werror"
  fi
  cat > conftest.$ac_ext <<EOF
! #line 2346 "configure"
  #include "confdefs.h"
  
  #include <stdio.h>
***************
*** 2100,2106 ****
  
  echo $ac_n "checking "for type uchar"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2104 "configure"
  #include "confdefs.h"
  
  #include <sys/types.h>
--- 2373,2379 ----
  
  echo $ac_n "checking "for type uchar"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2377 "configure"
  #include "confdefs.h"
  
  #include <sys/types.h>
***************
*** 2127,2133 ****
  
  echo $ac_n "checking "whether we need extern int errno"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2131 "configure"
  #include "confdefs.h"
  
  #include <sys/types.h>
--- 2400,2406 ----
  
  echo $ac_n "checking "whether we need extern int errno"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2404 "configure"
  #include "confdefs.h"
  
  #include <sys/types.h>
***************
*** 2198,2204 ****
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 2202 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #include <signal.h>
--- 2471,2477 ----
    echo $ac_n "(cached) $ac_c" 1>&4
  else
    cat > conftest.$ac_ext <<EOF
! #line 2475 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #include <signal.h>
***************
*** 2232,2238 ****
    echo "$ac_t"""assuming Posix signals"" 1>&4
  else
  cat > conftest.$ac_ext <<EOF
! #line 2236 "configure"
  #include "confdefs.h"
  
  #include <stdio.h>
--- 2505,2511 ----
    echo "$ac_t"""assuming Posix signals"" 1>&4
  else
  cat > conftest.$ac_ext <<EOF
! #line 2509 "configure"
  #include "confdefs.h"
  
  #include <stdio.h>
***************
*** 2272,2278 ****
    true
  else
  cat > conftest.$ac_ext <<EOF
! #line 2276 "configure"
  #include "confdefs.h"
  
  #ifdef TIME_WITH_SYS_TIME
--- 2545,2551 ----
    true
  else
  cat > conftest.$ac_ext <<EOF
! #line 2549 "configure"
  #include "confdefs.h"
  
  #ifdef TIME_WITH_SYS_TIME
***************
*** 2324,2330 ****
      CFLAGS="$CFLAGS -Werror"
  fi
  cat > conftest.$ac_ext <<EOF
! #line 2328 "configure"
  #include "confdefs.h"
  
  #include <sys/wait.h>
--- 2597,2603 ----
      CFLAGS="$CFLAGS -Werror"
  fi
  cat > conftest.$ac_ext <<EOF
! #line 2601 "configure"
  #include "confdefs.h"
  
  #include <sys/wait.h>
***************
*** 2353,2359 ****
  
  echo $ac_n "checking "for tagged lvalues"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2357 "configure"
  #include "confdefs.h"
  
  
--- 2626,2632 ----
  
  echo $ac_n "checking "for tagged lvalues"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2630 "configure"
  #include "confdefs.h"
  
  
***************
*** 2484,2490 ****
  
  echo $ac_n "checking "_data_start"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2488 "configure"
  #include "confdefs.h"
  extern int _data_start;
  int main() { return 0; }
--- 2757,2763 ----
  
  echo $ac_n "checking "_data_start"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2761 "configure"
  #include "confdefs.h"
  extern int _data_start;
  int main() { return 0; }
***************
*** 2508,2514 ****
  
  echo $ac_n "checking "_data"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2512 "configure"
  #include "confdefs.h"
  extern int _data;
  int main() { return 0; }
--- 2781,2787 ----
  
  echo $ac_n "checking "_data"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2785 "configure"
  #include "confdefs.h"
  extern int _data;
  int main() { return 0; }
***************
*** 2601,2607 ****
  	echo $ac_n "checking "what kind of static linking is required"""... $ac_c" 1>&4
  
  cat > conftest.$ac_ext <<EOF
! #line 2605 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
--- 2874,2880 ----
  	echo $ac_n "checking "what kind of static linking is required"""... $ac_c" 1>&4
  
  cat > conftest.$ac_ext <<EOF
! #line 2878 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
***************
*** 2633,2639 ****
  
  echo $ac_n "checking "foreign C-interface"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2637 "configure"
  #include "confdefs.h"
  
  #include <stdio.h>
--- 2906,2912 ----
  
  echo $ac_n "checking "foreign C-interface"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2910 "configure"
  #include "confdefs.h"
  
  #include <stdio.h>
***************
*** 2666,2672 ****
  
  if test "$ac_foreign" != "yes"; then
  cat > conftest.$ac_ext <<EOF
! #line 2670 "configure"
  #include "confdefs.h"
  
  #include <rld.h>
--- 2939,2945 ----
  
  if test "$ac_foreign" != "yes"; then
  cat > conftest.$ac_ext <<EOF
! #line 2943 "configure"
  #include "confdefs.h"
  
  #include <rld.h>
***************
*** 2721,2727 ****
  rm -rf conftest*
  echo $ac_n "checking "BSD a.out based loading"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2725 "configure"
  #include "confdefs.h"
  
  #include <stdio.h>
--- 2994,3000 ----
  rm -rf conftest*
  echo $ac_n "checking "BSD a.out based loading"""... $ac_c" 1>&4
  cat > conftest.$ac_ext <<EOF
! #line 2998 "configure"
  #include "confdefs.h"
  
  #include <stdio.h>
diff -c -r +new-file src/configure.in src/configure.in
*** src/configure.in	Tue Apr 25 14:52:10 1995
--- src/configure.in	Wed Apr 26 15:30:07 1995
***************
*** 94,103 ****
  fi
  AC_CHECK_LIB(elf, main)
  AC_CHECK_LIB(m, main)
! AC_ARG_ENABLE(dlopen, [  --enable-dlopen	  Provide shared-lib interface],
  	      if test "$enableval" = "yes"; then
  		  AC_CHECK_LIB(dl, dlopen)
  	          AC_CHECK_FUNCS(dlopen)
  	      fi)
  
  echo "	LIBS=$LIBS"
--- 94,112 ----
  fi
  AC_CHECK_LIB(elf, main)
  AC_CHECK_LIB(m, main)
! AC_ARG_ENABLE(shared, [  --enable-shared	  Provide shared-lib interface],
  	      if test "$enableval" = "yes"; then
  		  AC_CHECK_LIB(dl, dlopen)
+ 	          AC_CHECK_LIB(dld, shl_load)
  	          AC_CHECK_FUNCS(dlopen)
+ 		  AC_CHECK_FUNCS(shl_load)
+ 	      fi)
+ AC_ARG_ENABLE(dlopen, [  --enable-dlopen	  Provide shared-lib interface (old)],
+ 	      if test "$enableval" = "yes"; then
+ 		  AC_CHECK_LIB(dl, dlopen)
+ 	          AC_CHECK_LIB(dld, shl_load)
+ 	          AC_CHECK_FUNCS(dlopen)
+ 		  AC_CHECK_FUNCS(shl_load)
  	      fi)
  
  echo "	LIBS=$LIBS"
diff -c -r +new-file src/pl-ext.c src/pl-ext.c
*** src/pl-ext.c	Tue Apr 18 14:29:12 1995
--- src/pl-ext.c	Wed Apr 26 15:30:08 1995
***************
*** 1,4 ****
! /*  pl-ext.c,v 1.31 1995/04/18 12:29:12 jan Exp
  
      Copyright (c) 1990 Jan Wielemaker. All rights reserved.
      See ../LICENCE to find out about your rights.
--- 1,4 ----
! /*  pl-ext.c,v 1.32 1995/04/26 13:30:08 jan Exp
  
      Copyright (c) 1990 Jan Wielemaker. All rights reserved.
      See ../LICENCE to find out about your rights.
***************
*** 268,274 ****
  #else
    ADD("$load_foreign",		5, pl_load_foreign,	TRANSPARENT|TRACE_ME),
  #endif
! #if HAVE_DLOPEN
    ADD("open_shared_object",	2, pl_open_shared_object,	TRACE_ME),
    ADD("close_shared_object",	1, pl_close_shared_object,	TRACE_ME),
    ADD("call_shared_object_function",
--- 268,274 ----
  #else
    ADD("$load_foreign",		5, pl_load_foreign,	TRANSPARENT|TRACE_ME),
  #endif
! #if defined(HAVE_DLOPEN) || defined(HAVE_SHL_LOAD)
    ADD("open_shared_object",	2, pl_open_shared_object,	TRACE_ME),
    ADD("close_shared_object",	1, pl_close_shared_object,	TRACE_ME),
    ADD("call_shared_object_function",
diff -c -r +new-file src/pl-incl.h src/pl-incl.h
*** src/pl-incl.h	Fri Apr 21 11:08:20 1995
--- src/pl-incl.h	Wed Apr 26 15:30:10 1995
***************
*** 1,4 ****
! /*  pl-incl.h,v 1.42 1995/04/21 09:08:20 jan Exp
  
      Copyright (c) 1990 Jan Wielemaker. All rights reserved.
      See ../LICENCE to find out about your rights.
--- 1,4 ----
! /*  pl-incl.h,v 1.43 1995/04/26 13:30:10 jan Exp
  
      Copyright (c) 1990 Jan Wielemaker. All rights reserved.
      See ../LICENCE to find out about your rights.
***************
*** 857,863 ****
  #    ifdef DATA_AT_0X2
  #      define PTR_TO_NUM_OFFSET	  0x20000000L
  #    else
! #      ifdef DATA_AT_OX1
  #        define PTR_TO_NUM_OFFSET 0x10000000L
  #      else
  #        define PTR_TO_NUM_OFFSET 0x0L
--- 857,863 ----
  #    ifdef DATA_AT_0X2
  #      define PTR_TO_NUM_OFFSET	  0x20000000L
  #    else
! #      ifdef DATA_AT_0X1
  #        define PTR_TO_NUM_OFFSET 0x10000000L
  #      else
  #        define PTR_TO_NUM_OFFSET 0x0L
diff -c -r +new-file src/pl-load.c src/pl-load.c
*** src/pl-load.c	Mon Apr 24 18:06:16 1995
--- src/pl-load.c	Wed Apr 26 15:30:11 1995
***************
*** 1,4 ****
! /*  pl-load.c,v 1.25 1995/04/24 16:06:16 jan Exp
  
      Copyright (c) 1990 Jan Wielemaker. All rights reserved.
      See ../LICENCE to find out about your rights.
--- 1,4 ----
! /*  pl-load.c,v 1.26 1995/04/26 13:30:11 jan Exp
  
      Copyright (c) 1990 Jan Wielemaker. All rights reserved.
      See ../LICENCE to find out about your rights.
***************
*** 804,812 ****
  		 *     DLOPEN() AND FRIENDS	*
  		 *******************************/
  
! #ifdef HAVE_DLOPEN
  
  #include <dlfcn.h>
  typedef int (*dl_funcptr)();
  
  typedef struct dl_entry *DlEntry;
--- 804,843 ----
  		 *     DLOPEN() AND FRIENDS	*
  		 *******************************/
  
! #ifdef HAVE_DLOPEN			/* sysvr4, elf binaries */
  
  #include <dlfcn.h>
+ 
+ #ifndef RTLD_GLOBAL			/* solaris defines this */
+ #define RTLD_GLOBAL 0
+ #endif
+ 
+ #endif HAVE_DLOPEN
+ 
+ #ifdef HAVE_SHL_LOAD			/* HPUX */
+ 
+ #include <dl.h>
+ #define dlopen(path, flags) shl_load((path), (flags), 0L)
+ #define dlclose(handle)	    shl_unload((handle))
+ #define dlerror() OsError()
+ 
+ void *
+ dlsym(shl_t handle, const char *name)
+ { void *value;
+ 
+   if ( shl_findsym(&handle, name, TYPE_PROCEDURE, &value) < 0 )
+     return NULL;
+ 
+   return value;
+ }
+ 
+ #define RTLD_LAZY	BIND_DEFERRED
+ #define RTLD_GLOBAL	0
+ 
+ #endif
+ 
+ #if defined(HAVE_DLOPEN) || defined(HAVE_SHL_LOAD)
+ 
  typedef int (*dl_funcptr)();
  
  typedef struct dl_entry *DlEntry;
***************
*** 820,829 ****
  int	dl_plid;			/* next id to give */
  DlEntry dl_head;			/* loaded DL's */
  DlEntry dl_tail;			/* end of this chain */
- 
- #ifndef RTLD_GLOBAL			/* solaris defines this */
- #define RTLD_GLOBAL 0
- #endif
  
  word
  pl_open_shared_object(Word file, Word plhandle)
--- 851,856 ----
diff -c -r +new-file src/pl-setup.c src/pl-setup.c
*** src/pl-setup.c	Tue Apr 18 14:29:41 1995
--- src/pl-setup.c	Wed Apr 26 15:30:13 1995
***************
*** 153,159 ****
  #if defined(O_FOREIGN) || defined(O_MACH_FOREIGN) || defined(O_AIX_FOREIGN)
    CSetFeature("load_foreign",  "true");
  #endif
! #ifdef HAVE_DLOPEN
    CSetFeature("open_shared_object", "true");
  #endif
  #ifdef O_DLL
--- 153,159 ----
  #if defined(O_FOREIGN) || defined(O_MACH_FOREIGN) || defined(O_AIX_FOREIGN)
    CSetFeature("load_foreign",  "true");
  #endif
! #if defined(HAVE_DLOPEN) || defined(HAVE_SLH_LOAD)
    CSetFeature("open_shared_object", "true");
  #endif
  #ifdef O_DLL
diff -c -r +new-file src/pl-stream.c src/pl-stream.c
*** src/pl-stream.c	Tue Apr 18 14:29:44 1995
--- src/pl-stream.c	Wed Apr 26 15:30:14 1995
***************
*** 1,4 ****
! /*  pl-stream.c,v 1.3 1995/04/18 12:29:44 jan Exp
  
      Copyright (c) 1990 Jan Wielemaker. All rights reserved.
      See ../LICENCE to find out about your rights.
--- 1,4 ----
! /*  pl-stream.c,v 1.4 1995/04/26 13:30:14 jan Exp
  
      Copyright (c) 1990 Jan Wielemaker. All rights reserved.
      See ../LICENCE to find out about your rights.
***************
*** 21,26 ****
--- 21,27 ----
  #define _MAKE_DLL
  #undef _export
  #include "pl-stream.h"
+ #include <sys/types.h>
  #include <errno.h>
  #ifdef HAVE_MALLOC_H
  #include <malloc.h>
diff -c -r +new-file src/pl-wic.c src/pl-wic.c
*** src/pl-wic.c	Tue Apr 18 14:29:51 1995
--- src/pl-wic.c	Wed Apr 26 15:30:16 1995
***************
*** 1,4 ****
! /*  pl-wic.c,v 1.28 1995/04/18 12:29:51 jan Exp
  
      Copyright (c) 1990 Jan Wielemaker. All rights reserved.
      See ../LICENCE to find out about your rights.
--- 1,4 ----
! /*  pl-wic.c,v 1.29 1995/04/26 13:30:16 jan Exp
  
      Copyright (c) 1990 Jan Wielemaker. All rights reserved.
      See ../LICENCE to find out about your rights.
***************
*** 1868,1874 ****
      clause = (Clause) numToPointer(*ref);
    
      if ( !inCore(clause) || !isClause(clause) )
!       return warning("$qlf_assert_claue/1: Invalid reference");
  
      if ( clause->procedure != currentProc )
      { closeProcedureWic(s);
--- 1868,1874 ----
      clause = (Clause) numToPointer(*ref);
    
      if ( !inCore(clause) || !isClause(clause) )
!       return warning("$qlf_assert_clause/1: Invalid reference");
  
      if ( clause->procedure != currentProc )
      { closeProcedureWic(s);
diff -c -r +new-file src/test/mmap.c src/test/mmap.c
*** src/test/mmap.c	Fri Feb 17 11:38:28 1995
--- src/test/mmap.c	Wed Apr 26 15:30:37 1995
***************
*** 1,4 ****
! /*  mmap.c,v 1.3 1995/02/17 10:38:28 jan Exp
  
      Designed and implemented by Jan Wielemaker
      E-mail: jan@swi.psy.uva.nl
--- 1,4 ----
! /*  mmap.c,v 1.4 1995/04/26 13:30:37 jan Exp
  
      Designed and implemented by Jan Wielemaker
      E-mail: jan@swi.psy.uva.nl
***************
*** 181,187 ****
      else if ( (low & 0xf0000000L) == 0x20000000L )
        seghigh = 0x40000000L;
      else if ( (low & 0xf0000000L) == 0x40000000L )
!       seghigh = 0x80000000L;
    } else
      seghigh = 0x20000000L;
  
--- 181,187 ----
      else if ( (low & 0xf0000000L) == 0x20000000L )
        seghigh = 0x40000000L;
      else if ( (low & 0xf0000000L) == 0x40000000L )
!       seghigh = 0x50000000L;
    } else
      seghigh = 0x20000000L;
  
                                                                                    F DIFF-1.000;1                      	diff-1.9.3-1.9.4.gz
F DIFF-1.001;1                      	diff-1.8.9-1.8.10
F DIFF-1.002;1                      	diff-1.8.7-1.8.8.gz
F DIFF-1.003;1                      	diff-1.8.6-1.8.7.gz
F DIFF-1.004;1                      	diff-1.8.5-1.8.6.gz
F DIFF-1.005;1                      	diff-1.8.4-1.8.5.gz
F DIFF-1.006;1                      	diff-1.8.3-1.8.4.gz
F DIFF-1.007;1                      	diff-1.8.2-1.8.3.gz
F DIFF-1.008;1                      	diff-1.8.10-1.8.11.gz
F DIFF-1.009;1                      	diff-1.8.1-1.8.2.gz
F DIFF-1.010;1                      	diff-1.7.2-1.8.0.gz
F DIFF-1.011;1                      	diff-1.7.1-1.7.2.gz
F DIFF-1.6;1                        	diff-1.6.17b-1.6.18.gz
F DIFF-1.7;1                        	diff-1.7.0-1.7.1
F DIFF-1.8;1                        	diff-1.8.0-1.8.1
F DIFF-1.9;1                        	diff-1.9.2-1.9.3.gz
F DIFF-2.0;1                        	diff-2.0.0-2.0.1.gz
F DIFF-2.000;1                      	diff-2.1.8-2.1.9.gz
F DIFF-2.001;1                      	diff-2.1.5-2.1.7
F DIFF-2.002;1                      	diff-2.1.5-2.1.6.gz
F DIFF-2.003;1                      	diff-2.1.4-2.1.5.gz
F DIFF-2.004;1                      	diff-2.1.2-2.1.3.gz
F DIFF-2.005;1                      	diff-2.1.1-2.1.2.gz
F DIFF-2.006;1                      	diff-2.0.9-2.1.0.gz
F DIFF-2.007;1                      	diff-2.0.7-2.0.8.gz
F DIFF-2.008;1                      	diff-2.0.6-2.0.7.gz
F DIFF-2.009;1                      	diff-2.0.2-2.0.3
F DIFF-2.010;1                      	diff-2.0.1-2.0.2.gz
F DIFF-2.1;1                        	diff-2.1.0-2.1.1.gz
F DIFF-PL-.000;1                    	diff-pl-1.9.4-1.9.5-alpha.gz
F DIFF-PL-.001;1                    	diff-pl-1.9.0-1.9.1.gz
F DIFF-PL-.8;1                      	diff-pl-1.8.8-pl-1.9.0.gz
F DIFF-PL-.9;1                      	diff-pl-1.9.5-alpha.tar.gz
F PL-2.0;1                          	pl-2.0.8-2.0.9
                                                                                                   ;; Run compiler as inferior of Emacs, and parse its error messages.
;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY.  No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing.  Refer to the GNU Emacs General Public
;; License for full details.

;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License.   A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities.  It should be in a
;; file named COPYING.  Among other things, the copyright notice
;; and this notice must be preserved on all copies.

(provide 'compile)

(defvar compilation-process nil
  "Process created by compile command, or nil if none exists now.
Note that the process may have been \"deleted\" and still
be the value of this variable.")

(defvar compilation-error-list nil
  "List of error message descriptors for visiting erring functions.
Each error descriptor is a list of length two.
Its car is a marker pointing to an error message.
Its cadr is a marker pointing to the text of the line the message is about,
  or nil if that is not interesting.
The value may be t instead of a list;
this means that the buffer of error messages should be reparsed
the next time the list of errors is wanted.")

(defvar compilation-parsing-end nil
  "Position of end of buffer when last error messages parsed.")

(defvar compilation-error-message nil
  "Message to print when no more matches for compilation-error-regexp are found")

;; The filename excludes colons to avoid confusion when error message
;; starts with digits.
(defvar compilation-error-regexp
  "\\([^ :\n]+\\(: *\\|, line \\|(\\)[0-9]+\\)\\|\\([0-9]+ *of *[^ \n]+\\)"
  "Regular expression for filename/linenumber in error in compilation log.")

(defun compile (command)
  "Compile the program including the current buffer.  Default: run `make'.
Runs COMMAND, a shell command, in a separate process asynchronously
with output going to the buffer *compilation*.
You can then use the command \\[next-error] to find the next error message
and move to the source code that caused it."
  (interactive (list (read-string "Compile command: " compile-command)))
  (setq compile-command command)
  (compile1 compile-command "No more errors"))

(defun grep (command)
  "Run grep, with user-specified args, and collect output in a buffer.
While grep runs asynchronously, you can use the \\[next-error] command
to find the text that grep hits refer to."
  (interactive "sRun grep (with args): ")
  (compile1 (concat "grep -n " command " /dev/null")
	    "No more grep hits" "grep"))

(defun compile1 (command error-message &optional name-of-mode)
  (save-some-buffers)
  (if compilation-process
      (if (or (not (eq (process-status compilation-process) 'run))
	      (yes-or-no-p "A compilation process is running; kill it? "))
	  (condition-case ()
	      (let ((comp-proc compilation-process))
		(interrupt-process comp-proc)
		(sit-for 1)
		(delete-process comp-proc))
	    (error nil))
	(error "Cannot have two compilation processes")))
  (setq compilation-process nil)
  (compilation-forget-errors)
  (setq compilation-error-list t)
  (setq compilation-error-message error-message)
  (setq compilation-process
	(start-process "compilation" "*compilation*"
		       shell-file-name
		       "-c" (concat "exec " command)))
  (with-output-to-temp-buffer "*compilation*"
    (princ "cd ")
    (princ default-directory)
    (terpri)
    (princ command)
    (terpri))
  (let ((regexp compilation-error-regexp))
    (save-excursion
      (set-buffer "*compilation*")
      (make-local-variable 'compilation-error-regexp)
      (setq compilation-error-regexp regexp)))
  (set-process-sentinel compilation-process 'compilation-sentinel)
  (let* ((thisdir default-directory)
	 (outbuf (process-buffer compilation-process))
	 (outwin (get-buffer-window outbuf)))
    (if (eq outbuf (current-buffer))
	(goto-char (point-max)))
    (save-excursion
      (set-buffer outbuf)
      (buffer-flush-undo outbuf)
      (let ((start (save-excursion (set-buffer outbuf) (point-min))))
	(set-window-start outwin start)
	(or (eq outwin (selected-window))
	    (set-window-point outwin start)))
      (setq default-directory thisdir)
      (fundamental-mode)
      (setq mode-name (or name-of-mode "Compilation"))
      ;; Make log buffer's mode line show process state
      (setq mode-line-process '(": %s")))))

;; Called when compilation process changes state.

(defun compilation-sentinel (proc msg)
  (cond ((null (buffer-name (process-buffer proc)))
	 ;; buffer killed
	 (set-process-buffer proc nil))
	((memq (process-status proc) '(signal exit))
	 (let* ((obuf (current-buffer))
		omax opoint)
	   ;; save-excursion isn't the right thing if
	   ;;  process-buffer is current-buffer
	   (unwind-protect
	       (progn
		 ;; Write something in *compilation* and hack its mode line,
		 (set-buffer (process-buffer proc))
		 (setq omax (point-max) opoint (point))
		 (goto-char (point-max))
		 (insert ?\n mode-name " " msg)
		 (forward-char -1)
		 (insert " at "
			 (substring (current-time-string) 0 -5))
		 (forward-char 1)
		 (setq mode-line-process
		       (concat ": "
			       (symbol-name (process-status proc))))
		 ;; If buffer and mode line will show that the process
		 ;; is dead, we can delete it now.  Otherwise it
		 ;; will stay around until M-x list-processes.
		 (delete-process proc))
	     (setq compilation-process nil)
	     ;; Force mode line redisplay soon
	     (set-buffer-modified-p (buffer-modified-p)))
	   (if (and opoint (< opoint omax))
	       (goto-char opoint))
	   (set-buffer obuf)))))

(defun kill-compilation ()
  "Kill the process made by the \\[compile] command."
  (interactive)
  (if compilation-process
      (interrupt-process compilation-process)))

(defun kill-grep ()
  "Kill the process made by the \\[grep] command."
  (interactive)
  (if compilation-process
      (interrupt-process compilation-process)))

(defun next-error (&optional argp)
  "Visit next compilation error message and corresponding source code.
This operates on the output from the \\[compile] command.
If all preparsed error messages have been processed,
the error message buffer is checked for new ones.
A non-nil argument (prefix arg, if interactive)
means reparse the error message buffer and start at the first error."
  (interactive "P")
  (if (or (eq compilation-error-list t)
	  argp)
      (progn (compilation-forget-errors)
	     (setq compilation-parsing-end 1)))
  (if compilation-error-list
      nil
    (save-excursion
      (switch-to-buffer "*compilation*")
      (set-buffer-modified-p nil)
      (compilation-parse-errors)))
  (let ((next-error (car compilation-error-list)))
    (if (null next-error)
	(error (concat compilation-error-message
		       (if (and compilation-process
				(eq (process-status compilation-process)
				    'run))
			   " yet" ""))))
    (setq compilation-error-list (cdr compilation-error-list))
    (if (null (car (cdr next-error)))
	nil
      (switch-to-buffer (marker-buffer (car (cdr next-error))))
      (goto-char (car (cdr next-error)))
      (set-marker (car (cdr next-error)) nil))
    (let* ((pop-up-windows t)
	   (w (display-buffer (marker-buffer (car next-error)))))
      (set-window-point w (car next-error))
      (set-window-start w (car next-error)))
    (set-marker (car next-error) nil)))

;; Set compilation-error-list to nil, and
;; unchain the markers that point to the error messages and their text,
;; so that they no longer slow down gap motion.
;; This would happen anyway at the next garbage collection,
;; but it is better to do it right away.
(defun compilation-forget-errors ()
  (if (eq compilation-error-list t)
      (setq compilation-error-list nil))
  (while compilation-error-list
    (let ((next-error (car compilation-error-list)))
      (set-marker (car next-error) nil)
      (if (car (cdr next-error))
	  (set-marker (car (cdr next-error)) nil)))
    (setq compilation-error-list (cdr compilation-error-list))))

(defun compilation-parse-errors ()
  "Parse the current buffer as error messages.
This makes a list of error descriptors, compilation-error-list.
For each source-file, line-number pair in the buffer,
the source file is read in, and the text location is saved in compilation-error-list.
The function next-error, assigned to \\[next-error], takes the next error off the list
and visits its location."
  (setq compilation-error-list nil)
  (message "Parsing error messages...")
  (let (text-buffer
	last-filename last-linenum)
    ;; Don't reparse messages already seen at last parse.
    (goto-char compilation-parsing-end)
    ;; Don't parse the first two lines as error messages.
    ;; This matters for grep.
    (if (bobp)
	(forward-line 2))
    (while (re-search-forward compilation-error-regexp nil t)
      (let (linenum filename
	    error-marker text-marker)
	;; Extract file name and line number from error message.
	(save-restriction
	  (narrow-to-region (match-beginning 0) (match-end 0))
	  (goto-char (point-max))
	  (skip-chars-backward "[0-9]")
	  ;; If it's a lint message, use the last file(linenum) on the line.
	  ;; Normally we use the first on the line.
	  (if (= (preceding-char) ?\()
	      (progn
		(narrow-to-region (point-min) (1+ (buffer-size)))
		(end-of-line)
		(re-search-backward compilation-error-regexp)
		(skip-chars-backward "^ \t\n")
		(narrow-to-region (point) (match-end 0))
		(goto-char (point-max))
		(skip-chars-backward "[0-9]")))
	  ;; Are we looking at a "filename-first" or "line-number-first" form?
	  (if (looking-at "[0-9]")
	      (progn
		(setq linenum (read (current-buffer)))
		(goto-char (point-min)))
	    ;; Line number at start, file name at end.
	    (progn
	      (goto-char (point-min))
	      (setq linenum (read (current-buffer)))
	      (goto-char (point-max))
	      (skip-chars-backward "^ \t\n")))
	  (setq filename (compilation-grab-filename)))
	;; Locate the erring file and line.
	(if (and (equal filename last-filename)
		 (= linenum last-linenum))
	    nil
	  (beginning-of-line 1)
	  (setq error-marker (point-marker))
	  ;; text-buffer gets the buffer containing this error's file.
	  (if (not (equal filename last-filename))
	      (setq text-buffer
		    (and (file-exists-p (setq last-filename filename))
			 (find-file-noselect filename))
		    last-linenum 0))
	  (if text-buffer
	      ;; Go to that buffer and find the erring line.
	      (save-excursion
		(set-buffer text-buffer)
		(if (zerop last-linenum)
		    (progn
		      (goto-char 1)
		      (setq last-linenum 1)))
		(forward-line (- linenum last-linenum))
		(setq last-linenum linenum)
		(setq text-marker (point-marker))
		(setq compilation-error-list
		      (cons (list error-marker text-marker)
			    compilation-error-list)))))
	(forward-line 1)))
    (setq compilation-parsing-end (point-max)))
  (message "Parsing error messages...done")
  (setq compilation-error-list (nreverse compilation-error-list)))

(defun compilation-grab-filename ()
  "Return a string which is a filename, starting at point.
Ignore quotes and parentheses around it, as well as trailing colons."
  (if (eq (following-char) ?\")
      (save-restriction
	(narrow-to-region (point)
			  (progn (forward-sexp 1) (point)))
	(goto-char (point-min))
	(read (current-buffer)))
    (buffer-substring (point)
		      (progn
			(skip-chars-forward "^ :,\n\t(")
			(point)))))

(define-key ctl-x-map "`" 'next-error)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ;;; Interface to SWI-Prolog
;;; Author: Jan Wielemaker, SWI, University of Amsterdam
;;; E-mail: jan@swi.psy.uva.nl

;;; This package forms a layer around the Quintus-Prolog interface.  It
;;; should be used together with the Prolog library 'emacs_interface.pl'.

;;; It implements hooks that allow SWI-Prolog to give compilation-warnings
;;; back to EMACS, so the user can step through them using the normal
;;; ^X` command

;;; Usage:
;;;
;;;     Put the following lines in your ~/.emacs:
;;;
;;;	(autoload 'run-prolog "swi-prolog" "Run an inferior prolog process" t)
;;;	(autoload 'prolog-mode "swi-prolog" "SWI-Prolog mode" t)

;;; Notes:
;;;
;;; As far as I was able to figure out, the Quintus Prolog GNU-Emacs lisp
;;; interface can be distributed under the normal GNU general public licence
;;;
;;; This file is distributed confirm the GNU general public licence.


(defconst qplisp-directory "/usr/local/Emacs19/lib/emacs/site-lisp/qplisp"
  "Directory with all the quintus interface files")
(defvar run-prolog-command "pl"
  "Command to start SWI-Prolog")
(defconst prolog-warning-buffer "*compilation*"
  "SWI-Prolog buffer for warnings")

;;; Get the Quintus EMACS library in your load path

(setq load-path (cons qplisp-directory load-path))
(load-library "qprolog-mode")

;;; "compile.el" that comes with Emacs19 does not seem to work very well.
;;; Especially, error messages are not parsed correctly. It might be the
;;; case that errors are treated somewhat differently in Emacs19. Jan?
;;;
(load-library "compile18")

(setq prolog-prompt-pattern "^[0-9]+ \\?- ")


;;; Prolog Mode popup windows (Manfred Aben)
;;;

(require 'easymenu)

(defvar prolog-menu nil
  "Popup menu with the available commands for SWI-prolog mode")

(setq prolog-menu
      '("Prolog"
	["Start SWI-Prolog" 		run-prolog 			t]
	["Interrupt Prolog" 		interrupt-prolog 		t]
	" "
	["Consult this file"  	       	prolog-compile-buffer-only	t]
	["Reconsult modified files"    	prolog-recompile 	        t]
	"  "
	["Go to next error" 	       	next-error 			t]
	"   "
	["Previous query"		prolog-previous-command 	t]
	["Next query" 			prolog-next-command 		t]
	"    "
	["Find source file of this term" find-definition       		t]
	["Find other source files"     	find-more-definition 		t]
	"     "
	["Select clause" 		mark-clause 		        t]
	["Delete clause" 		kill-clause 			t]
	["Indent clause" 		prolog-indent-clause 		t]
	))


(or (fboundp 'old-prolog-mode)
    (fset 'old-prolog-mode
	  (symbol-function 'prolog-mode)))

(defun prolog-mode ()
  "Major mode for editing files of prolog code.
 The following commands are available:
\\{prolog-mode-map}."
  (interactive)
  ;;; HACK; Q-prolog-mode complains about "mark not active"
  (set-mark (beginning-of-buffer))
  (old-prolog-mode)
  (easy-menu-define menu-bar-swi-prolog1-commands
      prolog-mode-map
      "SWI-Prolog mode commands"
    prolog-menu))

(defun prolog-compilation-start (dir)
  "Clear *compilation* buffer"
  (save-excursion
    (set-buffer (get-buffer-create prolog-warning-buffer))
    (erase-buffer)
    (setq default-directory dir)
    (compilation-forget-errors)
    (setq compilation-error-list t)
    (setq compilation-error-message "No more SWI-Prolog errors")
    (insert "cd " dir)
    (newline)
    (insert "SWI-Prolog warnings")
    (newline)))


(defun prolog-compilation-finish ()
  "Finish prolog-compilation"
  (save-excursion
    (set-buffer prolog-warning-buffer)
    (end-of-buffer)
    (newline 2)
    (insert "Compilation finished at " (current-time-string))
    (newline)
    (setq compilation-parsing-end 1)))


(defun prolog-compilation-warning (file line msg)
  "Put a prolog error-message in *compilation*"
  (save-excursion
    (set-buffer prolog-warning-buffer)
    (end-of-buffer)
    (display-buffer (current-buffer))
    (insert file ":" line ": " msg)
    (newline)))


;;; STARTING PROLOG
;;; This function is a modified version of run-prolog in qprolog-mode.el

(defun run-prolog (command)
  "Run an inferior SWI-Prolog process, input and output via buffer
*prolog*."
  (interactive (list (read-string "Run prolog: " run-prolog-command)))
  (setq run-prolog-command command)
  (ensure-prolog-syntax)
  (qprequire 'shell)
  (get-prolog-exec-and-flags (concat command startup-jcl))
  (switch-to-buffer-other-window (apply 'make-comint "prolog"
					*prolog-executable* nil  
					*prolog-flags*))
  (set-process-filter (get-process "prolog") 'prolog-process-filter)
  (sleep-for 2)
  (inferior-prolog-mode)
  (local-set-key "\t" 'prolog-dabbrev-atom)
  (local-set-key "\C-d" 'prolog-complete-atom)
  (local-set-key "\C-c\C-n" 'prolog-next-command)
  (local-set-key "\C-c\C-p" 'prolog-previous-command)
  
  (easy-menu-define menu-bar-swi-prolog2-commands
      inferior-prolog-mode-map
      "SWI-Prolog mode commands"
    prolog-menu))

;;; ATOM COMPLETION

(defvar *prolog-start-completion* nil
  "Start of prolog completion")
(defvar *prolog-end-completion* nil
  "End of prolog completion")
(defvar *prolog-atom-completions* nil
  "Collect-list for prolog completions")
(defvar *prolog-completion-process-mark* nil
  "Process mark when starting completion")

(defun prolog-completion-backward-word ()
  (interactive)
  (backward-word 1)
  (backward-char 1)
  (if (looking-at "_")
      (prolog-completion-backward-word)
      (forward-char 1)))


(defun prolog-completion-sofar ()
  (setq *prolog-end-completion* (point))
  (let ((end (point)))
    (save-excursion
      (backward-char 1)
      (cond ((looking-at "[a-zA-Z0-9_]\\b")
	     (prolog-completion-backward-word)
	     (setq *prolog-start-completion* (point))
	     (setq *prolog-completion-process-mark*
		   (marker-position (process-mark
				     (get-buffer-process "*prolog*"))))
	     (buffer-substring (point) end))
	    (t nil)))))

(defun prolog-complete-atom-with (extended unique)
  (cond ((eq *prolog-end-completion* (point))
	 (kill-region *prolog-start-completion* *prolog-end-completion*)
	 (insert extended)
	 (setq *saved-prolog-process-mark* *prolog-completion-process-mark*)
	 (if (not un