use SWI version of CLIB

This commit is contained in:
Vítor Santos Costa 2011-03-10 11:05:53 +00:00
parent 014d903b4f
commit 3c5eb3ff7d
50 changed files with 642 additions and 3085 deletions

View File

@ -22,7 +22,7 @@ PLBASE=@prefix@
PLARCH=@ARCH@ PLARCH=@ARCH@
PLINCL=$(PLBASE)/include PLINCL=$(PLBASE)/include
PLLIBDIR=$(PLBASE)/share/Yap PLLIBDIR=$(PLBASE)/share/Yap
SOLIBDIR=$(PLLIBDIR) SOLIBDIR=$(PLBASE)/lib/Yap
PKGDOCDIR=$(PLBASE)/share/doc/packages PKGDOCDIR=$(PLBASE)/share/doc/packages
PKGEXDIR=$(PLBASE)/share/doc/packages/examples PKGEXDIR=$(PLBASE)/share/doc/packages/examples

View File

@ -874,7 +874,7 @@ int PL_unify_integer__LD(term_t t, intptr_t i ARG_LD)
{ {
CACHE_REGS CACHE_REGS
Term iterm = MkIntegerTerm(i); Term iterm = MkIntegerTerm(i);
return Yap_unify(Yap_GetFromSlot(i PASS_REGS),iterm); return Yap_unify(Yap_GetFromSlot(t PASS_REGS),iterm);
} }
extern int Yap_getInputStream(term_t t, IOSTREAM **s); extern int Yap_getInputStream(term_t t, IOSTREAM **s);

View File

@ -1,221 +0,0 @@
################################################################
# Makefile template for SWI-Prolog CLIB package
#
# This template is used by configure to create Makefile. See
# the file INSTALL for further installation instructions.
#
# License: LGPL
#
# Author: Jan Wielemaker (wielemak@science.uva.nl)
################################################################
.SUFFIXES: .tex .dvi .doc .pl
PL=../swipl.sh
PLBASE=/home/vsc/Yap/Prologs/pl-devel/lib/swipl-5.9.11
PLARCH=x86_64-linux
PLINCL=/home/vsc/Yap/Prologs/pl-devel/include
PKGDOC=$(PLBASE)/doc/packages
PCEHOME=../xpce
CC=../swipl-ld.sh
COFLAGS=-O2 -fno-strict-aliasing
CWFLAGS=-Wall
CMFLAGS=-fPIC
CIFLAGS=-I. -Imaildrop/rfc2045 -Imaildrop/rfc822
CFLAGS=$(COFLAGS) $(CWFLAGS) $(CMFLAGS) $(CIFLAGS) -DHAVE_CONFIG_H
LIBS=
NETLIBS=
CRYPTLIBS=-lcrypt
MIMELIBS=maildrop/rfc2045/librfc2045.a maildrop/rfc822/librfc822.a
PUBLICPL=swipl
DOCTOTEX=$(PCEHOME)/bin/doc2tex
PLTOTEX=$(PUBLICPL) -q -s pltotex.pl -g pltotex --
DOC=clib
TEX=$(DOC).tex process.tex uri.tex
DVI=$(DOC).dvi
PDF=$(DOC).pdf
RUNTEX=../../man/runtex
LD=../swipl-ld.sh
LDFLAGS=-shared
INSTALL=/usr/bin/install -c
INSTALL_PROGRAM=${INSTALL}
INSTALL_DATA=/usr/bin/install -c -m 644
LIBPL= random.pl unix.pl socket.pl cgi.pl memfile.pl filesex.pl mime.pl crypt.pl time.pl rlimit.pl streampool.pl streaminfo.pl process.pl prolog_server.pl sha.pl \
uri.pl
TARGETS= random.so unix.so socket.so cgi.so memfile.so files.so mime.so crypt.so time.so rlimit.so readutil.so streaminfo.so process.so \
sha4pl.so uri.so
UNXOBJ= error.o unix.o
SOCKOBJ= error.o socket.o nonblockio.o
CGIOBJ= error.o form.o cgi.o
CRYPTOBJ= error.o crypt.o md5.o md5passwd.o
MEMOBJ= error.o memfile.o
MIMEOBJ= error.o mime.o
TIMEOBJ= error.o time.o
FILESOBJ= error.o files.o
RLIMITOBJ= error.o rlimit.o
URIOBJ= uri.o
RANDOMOBJ= random.o
READUTILOBJ= readutil.o
PROCESSOBJ= error.o process.o
STREAMINFOOBJ= error.o streaminfo.o
SHAOBJ= error.o sha4pl.o sha1/sha1.o sha1/sha2.o \
sha1/hmac_sha1.o sha1/hmac_sha256.o
all: $(TARGETS)
random.so: $(RANDOMOBJ)
$(LD) $(LDFLAGS) -o $@ $(RANDOMOBJ)
unix.so: $(UNXOBJ)
$(LD) $(LDFLAGS) -o $@ $(UNXOBJ)
socket.so: $(SOCKOBJ)
$(LD) $(LDFLAGS) -o $@ $(SOCKOBJ) $(NETLIBS)
cgi.so: $(CGIOBJ)
$(LD) $(LDFLAGS) -o $@ $(CGIOBJ)
crypt.so: $(CRYPTOBJ)
$(LD) $(LDFLAGS) -o $@ $(CRYPTOBJ) $(CRYPTLIBS)
memfile.so: $(MEMOBJ)
$(LD) $(LDFLAGS) -o $@ $(MEMOBJ) $(LIBS)
mime.so: $(MIMEOBJ) $(MIMELIBS)
$(LD) $(LDFLAGS) -o $@ $(MIMEOBJ) $(MIMELIBS)
time.so: $(TIMEOBJ)
$(LD) $(LDFLAGS) -o $@ $(TIMEOBJ) $(LIBS)
files.so: $(FILESOBJ)
$(LD) $(LDFLAGS) -o $@ $(FILESOBJ) $(LIBS)
rlimit.so: $(RLIMITOBJ)
$(LD) $(LDFLAGS) -o $@ $(RLIMITOBJ) $(LIBS)
readutil.so: $(READUTILOBJ)
$(LD) $(LDFLAGS) -o $@ $(READUTILOBJ)
process.so: $(PROCESSOBJ)
$(LD) $(LDFLAGS) -o $@ $(PROCESSOBJ)
streaminfo.so: $(STREAMINFOOBJ)
$(LD) $(LDFLAGS) -o $@ $(STREAMINFOOBJ)
sha4pl.so: $(SHAOBJ)
$(LD) $(LDFLAGS) -o $@ $(SHAOBJ)
uri.so: $(URIOBJ)
$(LD) $(LDFLAGS) -o $@ $(URIOBJ)
socket.o: socket.c sockcommon.c
sha1/hmac_sha1.o:
$(CC) -c $(CFLAGS) -DUSE_SHA1 -o $@ sha1/hmac.c
sha1/hmac_sha256.o:
$(CC) -c $(CFLAGS) -DUSE_SHA256 -o $@ sha1/hmac.c
maildrop/rfc822/librfc822.a:
(cd maildrop/rfc822 && $(MAKE))
maildrop/rfc2045/librfc2045.a:
(cd maildrop/rfc2045 && $(MAKE))
install: $(TARGETS) $(LIBPL)
mkdir -p $(DESTDIR)$(PLBASE)/lib/$(PLARCH)
for f in $(TARGETS); do \
$(INSTALL_PROGRAM) $$f $(DESTDIR)$(PLBASE)/lib/$(PLARCH); \
done
mkdir -p $(DESTDIR)$(PLBASE)/library
for f in $(LIBPL); do \
$(INSTALL_DATA) $$f $(DESTDIR)$(PLBASE)/library; \
done
$(PL) -f none -g make -t halt
ln-install::
@$(MAKE) INSTALL_DATA='../ln-install' INSTALL_PROGRAM='../ln-install' install
rpm-install: install
html-install::
mkdir -p $(DESTDIR)$(PKGDOC)
$(INSTALL) -m 644 clib.html $(DESTDIR)$(PKGDOC)
pdf-install::
mkdir -p $(DESTDIR)$(PKGDOC)
$(INSTALL) -m 644 clib.pdf $(DESTDIR)$(PKGDOC)
uninstall::
(cd $(PLBASE)/lib/$(PLARCH) && rm -f $(TARGETS))
(cd $(PLBASE)/library && rm -f $(LIBPL))
$(PL) -f none -g make -t halt
################################################################
# Testing
################################################################
check: check-socket check-memfile check-unit check-process \
check-read check-uri check-cgi
torture: torture-socket
check-socket::
$(PL) -q -f test_socket.pl -F none -g test_socket,halt -t 'halt(1)'
torture-socket::
$(PL) -q -f stresssocket.pl -F none -g test,halt -t 'halt(1)'
check-memfile::
$(PL) -q -f test_memfile.pl -F none -g test_memfile,halt -t 'halt(1)'
check-unit::
$(PL) -q -f test.pl -g run_tests,halt -t 'halt(1)'
check-uri::
$(PL) -q -f test_uri.pl -g true -t test_uri
check-cgi::
$(PL) -q -f test_cgi.pl -g true -t test_cgi
check-process::
$(PL) -q -f test_process.pl -g true -t test_process
check-read::
$(PL) -q -f test_readutil.pl -g true -t test_readutil
################################################################
# Documentation
################################################################
pdf: $(PDF)
$(DVI): $(TEX)
$(RUNTEX) $(DOC)
$(PDF): $(TEX)
$(RUNTEX) --pdf $(DOC)
html: $(TEX)
latex2html $(DOC)
mv html/index.html clib.html
rm -r html
$(TEX): $(DOCTOTEX)
uri.tex: uri.pl
$(PLTOTEX) 'library(uri)'
process.tex: process.pl
$(PLTOTEX) 'library(process)'
.doc.tex:
$(DOCTOTEX) $*.doc > $*.tex
################################################################
# Clean
################################################################
clean:
rm -f $(OBJ) *~ *.o *% a.out core config.log sha1/*.o
rm -f $(TEX)
-(cd maildrop/rfc822 && $(MAKE) clean)
-(cd maildrop/rfc2045 && $(MAKE) clean)
distclean: clean
rm -f $(TARGETS) config.cache config.h config.status Makefile
rm -f clib.aux clib.log clib.out clib.toc
rm -rf html
-(cd maildrop/rfc822 && $(MAKE) distclean)
-(cd maildrop/rfc2045 && $(MAKE) distclean)

185
packages/clib/Makefile.in Executable file → Normal file
View File

@ -9,105 +9,24 @@
# Author: Jan Wielemaker (wielemak@science.uva.nl) # Author: Jan Wielemaker (wielemak@science.uva.nl)
################################################################ ################################################################
.SUFFIXES: .tex .dvi .doc .pl PACKAGE=clib
DOC=clib
PKGCFLAGS=-I$(srcdir) -I$(srcdir)/maildrop/rfc2045 -I$(srcdir)/maildrop/rfc822
include ../Makefile.defs
ifeq (@PROLOG_SYSTEM@,yap)
prefix = @prefix@
exec_prefix = @exec_prefix@
ROOTDIR = $(prefix)
EROOTDIR = @exec_prefix@
abs_top_builddir = @abs_top_builddir@
srcdir=@srcdir@
BINDIR = $(EROOTDIR)/bin
LIBDIR=@libdir@
YAPLIBDIR=@libdir@/Yap
SHAREDIR=$(ROOTDIR)/share/Yap
SHELL=@SHELL@
PL=@INSTALL_ENV@ $(DESTDIR)$(BINDIR)/yap $(DESTDIR)$(YAPLIBDIR)/startup.yss
LN_S=@LN_S@
#
#
DEFS=@DEFS@ -D_YAP_NOT_INSTALLED_=1
CC=@CC@
CFLAGS= @SHLIB_CFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I../.. -I$(srcdir)/../../include -I. -I$(srcdir)/maildrop/rfc2045 -I$(srcdir)/maildrop/rfc822 @CPPFLAGS@
MKINDEX=true
NETLIBS=@CLIB_NETLIBS@ NETLIBS=@CLIB_NETLIBS@
CRYPTLIBS=@CLIB_CRYPTLIBS@ CRYPTLIBS=@CLIB_CRYPTLIBS@
PTHREADLIBS=@CLIB_PTHREADS@
LD=@DO_SECOND_LD@ @SHLIB_LD@
LDFLAGS=@EXTRA_LIBS_FOR_SWIDLLS@ @LDFLAGS@
BINTARGET=$(DESTDIR)$(YAPLIBDIR)
PLTARGET=$(DESTDIR)$(SHAREDIR)
FINAL_BINTARGET=$(YAPLIBDIR)
FINAL_PLTARGET=$(SHAREDIR)
%.o: $(srcdir)/%.c
$(CC) -c $(CFLAGS) $< -o $@
sha1/%.o: $(srcdir)/sha1/%.c
$(CC) -c $(CFLAGS) $< -o $@
else # SWI
PL=@PL@
PLBASE=@PLBASE@
PLARCH=@PLARCH@
PLINCL=@PLINCL@
PKGDOC=$(PLBASE)/doc/packages
PCEHOME=../xpce
CC=@CC@
COFLAGS=@COFLAGS@
CWFLAGS=@CWFLAGS@
CMFLAGS=@CMFLAGS@
CIFLAGS=-I. -Imaildrop/rfc2045 -Imaildrop/rfc822
CFLAGS=$(COFLAGS) $(CWFLAGS) $(CMFLAGS) $(CIFLAGS) @DEFS@
LIBS=@LIBS@
NETLIBS=@NETLIBS@
CRYPTLIBS=@CRYPTLIBS@
PUBLICPL=swipl
DOCTOTEX=$(PCEHOME)/bin/doc2tex
PLTOTEX=$(PUBLICPL) -q -s pltotex.pl -g pltotex --
DOC=clib
TEX=$(DOC).tex process.tex uri.tex
DVI=$(DOC).dvi
PDF=$(DOC).pdf
RUNTEX=../../man/runtex
LD=@LD@
LDFLAGS=@LDSOFLAGS@
BINTARGET=$(DESTDIR)$(PLBASE)/lib/$(PLARCH)
PLTARGET=$(DESTDIR)$(PLBASE)/library
FINAL_BINTARGET=$(PLBASE)/lib/$(PLARCH)
FINAL_PLTARGET=$(PLBASE)/library
endif #YAP/SWI
MIMELIBS=maildrop/rfc2045/librfc2045.a maildrop/rfc822/librfc822.a MIMELIBS=maildrop/rfc2045/librfc2045.a maildrop/rfc822/librfc822.a
INSTALL=@INSTALL@ LIBPL= @CLIB_PLTARGETS@ streaminfo.pl process.pl prolog_server.pl sha.pl \
INSTALL_PROGRAM=@INSTALL_PROGRAM@ uri.pl
INSTALL_DATA=@INSTALL_DATA@
LIBPL= @CLIB_PLTARGETS@ $(srcdir)/streaminfo.pl $(srcdir)/process.pl \
$(srcdir)/prolog_server.pl $(srcdir)/sha.pl \
$(srcdir)/socket.pl \
$(srcdir)/uri.pl
TARGETS= @CLIB_TARGETS@ readutil.@SO@ streaminfo.@SO@ process.@SO@ \ TARGETS= @CLIB_TARGETS@ readutil.@SO@ streaminfo.@SO@ process.@SO@ \
sha4pl.@SO@ uri.@SO@ sha4pl.@SO@ uri.@SO@
UNXOBJ= error.o unix.o UNXOBJ= error.o unix.o
SOCKOBJ= error.o socket.o nonblockio.o SOCKOBJ= error.o socket.o nonblockio.o
CGIOBJ= error.o form.o cgi.o CGIOBJ= error.o form.o cgi.o
CRYPTOBJ= error.o crypt.o md5.o md5passwd.o @ENABLE_WINCONSOLE@ bsd-crypt.o CRYPTOBJ= error.o crypt.o md5.o md5passwd.o
MEMOBJ= error.o memfile.o MEMOBJ= error.o memfile.o
MIMEOBJ= error.o mime.o MIMEOBJ= error.o mime.o
TIMEOBJ= error.o time.o TIMEOBJ= error.o time.o
@ -124,38 +43,42 @@ SHAOBJ= error.o sha4pl.o sha1/sha1.o sha1/sha2.o \
all: $(TARGETS) all: $(TARGETS)
random.@SO@: $(RANDOMOBJ) random.@SO@: $(RANDOMOBJ)
$(LD) $(LDFLAGS) -o $@ $(RANDOMOBJ) $(LD) $(LDSOFLAGS) -o $@ $(RANDOMOBJ)
unix.@SO@: $(UNXOBJ) unix.@SO@: $(UNXOBJ)
$(LD) $(LDFLAGS) -o $@ $(UNXOBJ) $(LD) $(LDSOFLAGS) -o $@ $(UNXOBJ)
socket.@SO@: $(SOCKOBJ) socket.@SO@: $(SOCKOBJ)
$(LD) $(LDFLAGS) -o $@ $(SOCKOBJ) $(NETLIBS) $(PTHREADLIBS) $(LD) $(LDSOFLAGS) -o $@ $(SOCKOBJ) $(NETLIBS)
cgi.@SO@: $(CGIOBJ) cgi.@SO@: $(CGIOBJ)
$(LD) $(LDFLAGS) -o $@ $(CGIOBJ) $(PTHREADLIBS) $(LD) $(LDSOFLAGS) -o $@ $(CGIOBJ)
crypt.@SO@: $(CRYPTOBJ) crypt.@SO@: $(CRYPTOBJ)
$(LD) $(LDFLAGS) -o $@ $(CRYPTOBJ) $(CRYPTLIBS) $(PTHREADLIBS) $(LD) $(LDSOFLAGS) -o $@ $(CRYPTOBJ) $(CRYPTLIBS)
memfile.@SO@: $(MEMOBJ) memfile.@SO@: $(MEMOBJ)
$(LD) $(LDFLAGS) -o $@ $(MEMOBJ) $(LIBS) $(LD) $(LDSOFLAGS) -o $@ $(MEMOBJ) $(LIBS)
mime.@SO@: $(MIMEOBJ) $(MIMELIBS) mime.@SO@: $(MIMEOBJ) $(MIMELIBS)
$(LD) $(LDFLAGS) -o $@ $(MIMEOBJ) $(MIMELIBS) $(LD) $(LDSOFLAGS) -o $@ $(MIMEOBJ) $(MIMELIBS)
time.@SO@: $(TIMEOBJ) time.@SO@: $(TIMEOBJ)
$(LD) $(LDFLAGS) -o $@ $(TIMEOBJ) $(LIBS) $(PTHREADLIBS) $(LD) $(LDSOFLAGS) -o $@ $(TIMEOBJ) $(LIBS)
files.@SO@: $(FILESOBJ) files.@SO@: $(FILESOBJ)
$(LD) $(LDFLAGS) -o $@ $(FILESOBJ) $(LIBS) $(LD) $(LDSOFLAGS) -o $@ $(FILESOBJ) $(LIBS)
rlimit.@SO@: $(RLIMITOBJ) rlimit.@SO@: $(RLIMITOBJ)
$(LD) $(LDFLAGS) -o $@ $(RLIMITOBJ) $(LIBS) $(LD) $(LDSOFLAGS) -o $@ $(RLIMITOBJ) $(LIBS)
readutil.@SO@: $(READUTILOBJ) readutil.@SO@: $(READUTILOBJ)
$(LD) $(LDFLAGS) -o $@ $(READUTILOBJ) $(LD) $(LDSOFLAGS) -o $@ $(READUTILOBJ)
process.@SO@: $(PROCESSOBJ) process.@SO@: $(PROCESSOBJ)
$(LD) $(LDFLAGS) -o $@ $(PROCESSOBJ) $(LD) $(LDSOFLAGS) -o $@ $(PROCESSOBJ)
streaminfo.@SO@: $(STREAMINFOOBJ) streaminfo.@SO@: $(STREAMINFOOBJ)
$(LD) $(LDFLAGS) -o $@ $(STREAMINFOOBJ) $(LD) $(LDSOFLAGS) -o $@ $(STREAMINFOOBJ)
sha4pl.@SO@: $(SHAOBJ) sha4pl.@SO@: $(SHAOBJ)
$(LD) $(LDFLAGS) -o $@ $(SHAOBJ) $(LD) $(LDSOFLAGS) -o $@ $(SHAOBJ)
uri.@SO@: $(URIOBJ) uri.@SO@: $(URIOBJ)
$(LD) $(LDFLAGS) -o $@ $(URIOBJ) $(PTHREADLIBS) $(LD) $(LDSOFLAGS) -o $@ $(URIOBJ)
socket.o: $(srcdir)/socket.c $(srcdir)/sockcommon.c socket.o: $(srcdir)/socket.c $(srcdir)/sockcommon.c
sha1/sha1.o:
$(CC) -c $(CFLAGS) -DUSE_SHA1 -o $@ $(srcdir)/sha1/sha1.c
sha1/sha2.o:
$(CC) -c $(CFLAGS) -DUSE_SHA1 -o $@ $(srcdir)/sha1/sha2.c
sha1/hmac_sha1.o: sha1/hmac_sha1.o:
$(CC) -c $(CFLAGS) -DUSE_SHA1 -o $@ $(srcdir)/sha1/hmac.c $(CC) -c $(CFLAGS) -DUSE_SHA1 -o $@ $(srcdir)/sha1/hmac.c
sha1/hmac_sha256.o: sha1/hmac_sha256.o:
@ -167,16 +90,16 @@ maildrop/rfc2045/librfc2045.a:
(cd maildrop/rfc2045 && $(MAKE)) (cd maildrop/rfc2045 && $(MAKE))
install: $(TARGETS) $(LIBPL) install: $(TARGETS)
mkdir -p $(BINTARGET) mkdir -p $(DESTDIR)$(SOLIBDIR)
for f in $(TARGETS); do \ for f in $(TARGETS); do \
$(INSTALL_PROGRAM) $$f $(BINTARGET); \ $(INSTALL_PROGRAM) $$f $(DESTDIR)$(SOLIBDIR); \
done done
mkdir -p $(PLTARGET) mkdir -p $(DESTDIR)$(PLLIBDIR)
for f in $(LIBPL); do \ for f in $(LIBPL); do \
$(INSTALL_DATA) $$f $(PLTARGET); \ $(INSTALL_DATA) $(srcdir)/$$f $(DESTDIR)$(PLLIBDIR); \
done done
$(PL) -f none -g make -t halt ( cd $(srcdir) ; $(PL) -f none -g make -t halt )
ln-install:: ln-install::
@$(MAKE) INSTALL_DATA='../ln-install' INSTALL_PROGRAM='../ln-install' install @$(MAKE) INSTALL_DATA='../ln-install' INSTALL_PROGRAM='../ln-install' install
@ -192,8 +115,8 @@ pdf-install::
$(INSTALL) -m 644 clib.pdf $(DESTDIR)$(PKGDOC) $(INSTALL) -m 644 clib.pdf $(DESTDIR)$(PKGDOC)
uninstall:: uninstall::
(cd $(FINAL_BINTARGET) && rm -f $(TARGETS)) (cd $(PLBASE)/lib/$(PLARCH) && rm -f $(TARGETS))
(cd $(FINAL_PLTARGET) && rm -f $(LIBPL)) (cd $(PLBASE)/library && rm -f $(LIBPL))
$(PL) -f none -g make -t halt $(PL) -f none -g make -t halt
################################################################ ################################################################
@ -206,56 +129,42 @@ check: check-socket check-memfile check-unit check-process \
torture: torture-socket torture: torture-socket
check-socket:: check-socket::
$(PL) -q -f $(srcdir)/test_socket.pl -F none -g test_socket,halt -t 'halt(1)' ( cd $(srcdir) && $(PL) -q -f test_socket.pl -F none -g test_socket,halt -t 'halt(1)' )
torture-socket:: torture-socket::
$(PL) -q -f $(srcdir)/stresssocket.pl -F none -g test,halt -t 'halt(1)' ( cd $(srcdir) && $(PL) -q -f stresssocket.pl -F none -g test,halt -t 'halt(1)' )
check-memfile:: check-memfile::
$(PL) -q -f $(srcdir)/test_memfile.pl -F none -g test_memfile,halt -t 'halt(1)' ( cd $(srcdir) && $(PL) -q -f test_memfile.pl -F none -g test_memfile,halt -t 'halt(1)' )
check-unit:: check-unit::
$(PL) -q -f $(srcdir)/test.pl -g run_tests,halt -t 'halt(1)' ( cd $(srcdir) && $(PL) -q -f test.pl -g run_tests,halt -t 'halt(1)' )
check-uri:: check-uri::
$(PL) -q -f $(srcdir)/test_uri.pl -g true -t test_uri ( cd $(srcdir) && $(PL) -q -f test_uri.pl -g true -t test_uri )
check-cgi:: check-cgi::
$(PL) -q -f $(srcdir)/test_cgi.pl -g true -t test_cgi ( cd $(srcdir) && $(PL) -q -f test_cgi.pl -g true -t test_cgi )
check-process:: check-process::
$(PL) -q -f $(srcdir)/test_process.pl -g true -t test_process ( cd $(srcdir) && $(PL) -q -f test_process.pl -g true -t test_process )
check-read:: check-read::
$(PL) -q -f $(srcdir)/test_readutil.pl -g true -t test_readutil ( cd $(srcdir) && $(PL) -q -f test_readutil.pl -g true -t test_readutilw )
################################################################ ################################################################
# Documentation # Documentation
################################################################ ################################################################
pdf: $(PDF) TEXEXTRA=process.tex uri.tex filesex.tex
$(TEX): $(TEXEXTRA)
$(DVI): $(TEX)
$(RUNTEX) $(DOC)
$(PDF): $(TEX)
$(RUNTEX) --pdf $(DOC)
html: $(TEX)
latex2html $(DOC)
mv html/index.html clib.html
rm -r html
$(TEX): $(DOCTOTEX)
uri.tex: uri.pl uri.tex: uri.pl
$(PLTOTEX) 'library(uri)' $(PLTOTEX) 'library(uri)'
process.tex: process.pl process.tex: process.pl
$(PLTOTEX) 'library(process)' $(PLTOTEX) 'library(process)'
filesex.tex: filesex.pl
.doc.tex: $(PLTOTEX) 'library(filesex)'
$(DOCTOTEX) $*.doc > $*.tex
################################################################ ################################################################
# Clean # Clean

View File

@ -25,10 +25,11 @@ RANDOMOBJ= random.obj
SHAOBJ= error.obj sha4pl.obj sha1/sha1.obj sha1/sha2.obj \ SHAOBJ= error.obj sha4pl.obj sha1/sha1.obj sha1/sha2.obj \
sha1/hmac_sha1.obj sha1/hmac_sha256.obj sha1/hmac_sha1.obj sha1/hmac_sha256.obj
URIOBJ= uri.obj URIOBJ= uri.obj
FILESOBJ= error.obj files.obj
TIMELIBS= winmm.lib TIMELIBS= winmm.lib
all: socket.dll cgi.dll memfile.dll mime.dll time.dll readutil.dll \ all: socket.dll cgi.dll memfile.dll mime.dll time.dll readutil.dll \
random.dll crypt.dll sha4pl.dll process.dll uri.dll random.dll crypt.dll sha4pl.dll process.dll uri.dll files.dll
readutil.dll: $(READOBJ) readutil.dll: $(READOBJ)
$(LD) /dll /out:$@ $(LDFLAGS) $(READOBJ) $(PLLIB) $(LIBS) $(LD) /dll /out:$@ $(LDFLAGS) $(READOBJ) $(PLLIB) $(LIBS)
@ -52,12 +53,17 @@ sha4pl.dll: $(SHAOBJ)
$(LD) /dll /out:$@ $(LDFLAGS) $(SHAOBJ) $(PLLIB) $(LIBS) $(LD) /dll /out:$@ $(LDFLAGS) $(SHAOBJ) $(PLLIB) $(LIBS)
uri.dll: $(URIOBJ) uri.dll: $(URIOBJ)
$(LD) /dll /out:$@ $(LDFLAGS) $(URIOBJ) $(PLLIB) $(LIBS) $(LD) /dll /out:$@ $(LDFLAGS) $(URIOBJ) $(PLLIB) $(LIBS)
files.dll: $(FILESOBJ)
$(LD) /dll /out:$@ $(LDFLAGS) $(FILESOBJ) $(PLLIB) $(LIBS)
sha1/hmac_sha1.obj: sha1/hmac.c sha1/hmac_sha1.obj: sha1/hmac.c
$(CC) -I $(PLHOME)\include $(CFLAGS) /DUSE_SHA1 /Fo$@ sha1/hmac.c $(CC) -I $(PLHOME)\include $(CFLAGS) /DUSE_SHA1 /Fo$@ sha1/hmac.c
sha1/hmac_sha256.obj: sha1/hmac.c sha1/hmac_sha256.obj: sha1/hmac.c
$(CC) -I $(PLHOME)\include $(CFLAGS) /DUSE_SHA256 /Fo$@ sha1/hmac.c $(CC) -I $(PLHOME)\include $(CFLAGS) /DUSE_SHA256 /Fo$@ sha1/hmac.c
process.obj: win_error.c
files.obj: win_error.c
!IF "$(CFG)" == "rt" !IF "$(CFG)" == "rt"
install: idll install: idll
!ELSE !ELSE
@ -94,6 +100,7 @@ idll::
copy process.dll "$(BINDIR)" copy process.dll "$(BINDIR)"
copy sha4pl.dll "$(BINDIR)" copy sha4pl.dll "$(BINDIR)"
copy uri.dll "$(BINDIR)" copy uri.dll "$(BINDIR)"
copy files.dll "$(BINDIR)"
!IF "$(PDB)" == "true" !IF "$(PDB)" == "true"
copy socket.pdb "$(BINDIR)" copy socket.pdb "$(BINDIR)"
copy cgi.pdb "$(BINDIR)" copy cgi.pdb "$(BINDIR)"
@ -104,6 +111,7 @@ idll::
copy process.pdb "$(BINDIR)" copy process.pdb "$(BINDIR)"
copy sha4pl.pdb "$(BINDIR)" copy sha4pl.pdb "$(BINDIR)"
copy uri.pdb "$(BINDIR)" copy uri.pdb "$(BINDIR)"
copy files.pdb "$(BINDIR)"
!ENDIF !ENDIF
ilib:: ilib::
@ -118,6 +126,7 @@ ilib::
copy time.pl "$(PLBASE)\library" copy time.pl "$(PLBASE)\library"
copy sha.pl "$(PLBASE)\library" copy sha.pl "$(PLBASE)\library"
copy uri.pl "$(PLBASE)\library" copy uri.pl "$(PLBASE)\library"
copy filesex.pl "$(PLBASE)\library"
copy process.pl "$(PLBASE)\library" copy process.pl "$(PLBASE)\library"
$(MAKEINDEX) $(MAKEINDEX)
@ -132,6 +141,8 @@ uninstall::
del "$(BINDIR)\time.dll" del "$(BINDIR)\time.dll"
del "$(BINDIR)\readutil.dll" del "$(BINDIR)\readutil.dll"
del "$(BINDIR)\sha4pl.dll" del "$(BINDIR)\sha4pl.dll"
del "$(BINDIR)\uri.dll"
del "$(BINDIR)\files.dll"
del "$(PLBASE)\library\socket.pl" del "$(PLBASE)\library\socket.pl"
del "$(PLBASE)\library\cgi.pl" del "$(PLBASE)\library\cgi.pl"
del "$(PLBASE)\library\crypt.pl" del "$(PLBASE)\library\crypt.pl"
@ -141,6 +152,7 @@ uninstall::
del "$(PLBASE)\library\time.pl" del "$(PLBASE)\library\time.pl"
del "$(PLBASE)\library\sha.pl" del "$(PLBASE)\library\sha.pl"
del "$(PLBASE)\library\uri.pl" del "$(PLBASE)\library\uri.pl"
del "$(PLBASE)\library\filesex.pl"
del "$(PLBASE)\library\process.pl" del "$(PLBASE)\library\process.pl"
$(MAKEINDEX) $(MAKEINDEX)

4
packages/clib/bsd-crypt.c Executable file → Normal file
View File

@ -33,8 +33,6 @@
*/ */
/* JW: Added to make this file compile as-is for SWI-Prolog */ /* JW: Added to make this file compile as-is for SWI-Prolog */
#include <SWI-Prolog.h>
#define __RCSID(s) static char sccsid[] = s #define __RCSID(s) static char sccsid[] = s
#define DES_ONLY #define DES_ONLY
#define CRYPT_ONLY #define CRYPT_ONLY
@ -42,9 +40,7 @@ static int des_setkey(const char *key);
static int des_cipher(const char *in, char *out, long salt, int num_iter); static int des_cipher(const char *in, char *out, long salt, int num_iter);
#ifdef __WINDOWS__ #ifdef __WINDOWS__
#ifndef __MINGW32__
typedef __int32 int32_t; typedef __int32 int32_t;
#endif
#else #else
#include <sys/cdefs.h> #include <sys/cdefs.h>
#endif #endif

View File

@ -29,8 +29,12 @@
#include "clib.h" #include "clib.h"
#include "form.h" #include "form.h"
#ifdef __WINDOWS__ /* strtoll is C99, but it is only 2011 ... */
#define strtoll(s,e,b) _strtoi64(s,e,b)
#endif
static int static int
isinteger(const char *s, long *val, size_t len) isinteger(const char *s, long long *val, size_t len)
{ char *e; { char *e;
if ( len == (size_t)-1 ) if ( len == (size_t)-1 )
@ -38,7 +42,7 @@ isinteger(const char *s, long *val, size_t len)
if ( len == 0 ) if ( len == 0 )
return FALSE; return FALSE;
*val = strtol(s, &e, 10); *val = strtoll(s, &e, 10);
if ( e == s+len ) if ( e == s+len )
return TRUE; return TRUE;
@ -70,13 +74,13 @@ add_to_form(const char *name, size_t nlen,
{ term_t head = PL_new_term_ref(); { term_t head = PL_new_term_ref();
term_t tail = (term_t) closure; term_t tail = (term_t) closure;
term_t val = PL_new_term_ref(); term_t val = PL_new_term_ref();
long vl; long long vl;
double vf; double vf;
int rc; int rc;
atom_t aname = 0; atom_t aname = 0;
if ( isinteger(value, &vl, len) ) if ( isinteger(value, &vl, len) )
rc = PL_put_integer(val, vl); rc = PL_put_int64(val, vl);
else if ( isfloat(value, &vf, len) ) else if ( isfloat(value, &vf, len) )
rc = PL_put_float(val, vf); rc = PL_put_float(val, vf);
else else
@ -103,13 +107,13 @@ mp_add_to_form(const char *name, size_t nlen,
{ term_t head = PL_new_term_ref(); { term_t head = PL_new_term_ref();
term_t tail = (term_t) closure; term_t tail = (term_t) closure;
term_t val = PL_new_term_ref(); term_t val = PL_new_term_ref();
long vl; long long vl;
double vf; double vf;
int rc; int rc;
atom_t aname = 0; atom_t aname = 0;
if ( isinteger(value, &vl, len) ) if ( isinteger(value, &vl, len) )
rc = PL_put_integer(val, vl); rc = PL_put_int64(val, vl);
else if ( isfloat(value, &vf, len) ) else if ( isfloat(value, &vf, len) )
rc = PL_put_float(val, vf); rc = PL_put_float(val, vf);
else else

View File

@ -35,3 +35,48 @@
:- use_module(library(shlib)). :- use_module(library(shlib)).
:- use_foreign_library(foreign(cgi), install_cgi). :- use_foreign_library(foreign(cgi), install_cgi).
/** <module> Read CGI parameters
Below is a very simple CGI script that prints the passed parameters. To
test it, compile this program using the command below, copy it to your
cgi-bin directory (or make it otherwise known as a CGI-script) and try
the query =|http://myhost.mydomain/cgi-bin/cgidemo?hello=world|=
==
% swipl -o cgidemo --goal=main --toplevel=halt -c cgidemo.pl
==
==
:- use_module(library(cgi)).
main :-
set_stream(current_output, encoding(utf8)),
cgi_get_form(Arguments),
format('Content-type: text/html; charset=UTF-8~n~n', []),
format('<html>~n', []),
format('<head>~n', []),
format('<title>Simple SWI-Prolog CGI script</title>~n', []),
format('</head>~n~n', []),
format('<body>~n', []),
format('<p>', []),
print_args(Arguments),
format('</body>~n</html>~n', []).
print_args([]).
print_args([A0|T]) :-
A0 =.. [Name, Value],
format('<b>~w</b>=<em>~w</em><br>~n', [Name, Value]),
print_args(T).
==
*/
%% cgi_get_form(-Form)
%
% Decodes standard input and the environment variables to obtain a
% list of arguments passed to the CGI script. This predicate both
% deals with the CGI *GET* method as well as the *POST* method. If
% the data cannot be obtained, an existence_error exception is
% raised.
%
% @param Form is a list of Name(Value) terms.

View File

@ -186,43 +186,7 @@ controlling terminal.
\input{process.tex} \input{process.tex}
\input{filesex.tex}
\section{File manipulation library}
The \pllib{files} library provides additional operations on files from
SWI-Prolog. It is currently very incomplete.
\begin{description}
\predicate{set_time_file}{3}{+File, -OldTimes, +NewTimes}
Query and set POSIX time attributes of a file. Both \arg{OldTimes}
and \arg{NewTimes} are lists of option-terms. Times are represented
in SWI-Prolog's standard floating point numbers. New times may
be specified as \const{now} to indicate the current time. Defined
options are:
\begin{description}
\termitem{access}{Time}
Describes the time of last access of the file. This value can be
read and written.
\termitem{modified}{Time}
Describes the time the contents of the file was last modified.
This value can be read and written.
\termitem{changed}{Time}
Describes the time the file-structure itself was changed by adding
(link()) or removing (unlink()) names.
\end{description}
Here are some example queries. The first retrieves the access-time,
while the second sets the last-modified time to the current time.
\begin{code}
?- set_time_file(foo, [acess(Access)], []).
?- set_time_file(foo, [], [modified(now)]).
\end{code}
\end{description}
\section{Socket library} \section{Socket library}
@ -366,7 +330,7 @@ to deal switch stream to non-blocking mode using:
\begin{code} \begin{code}
... ...
tcp_fcntl(Stream, setfl. nonblock), tcp_fcntl(Stream, setfl, nonblock),
... ...
\end{code} \end{code}
@ -378,17 +342,18 @@ end-of-input, at_end_of_stream/1 succeeds.
\predicate{tcp_host_to_address}{2}{?HostName, ?Address} \predicate{tcp_host_to_address}{2}{?HostName, ?Address}
Translate between a machines host-name and it's (IP-)address. If Translate between a machines host-name and it's (IP-)address. If
\arg{HostName} is an atom, it is resolved using \arg{HostName} is an atom, it is resolved using
\funcref{gethostbyname}{} and the IP-number is unified to \arg{Address} \funcref{getaddrinfo}{} and the IP-number is unified to \arg{Address}
using a term of the format \term{ip}{Byte1, Byte2, Byte3, Byte4}. using a term of the format \term{ip}{Byte1, Byte2, Byte3, Byte4}.
Otherwise, if \arg{Address} is bound to a \functor{ip}{4} term, it Otherwise, if \arg{Address} is bound to a \functor{ip}{4} term, it
is resolved by \funcref{gethostbyaddr}{} and the canonical hostname is resolved by \funcref{gethostbyaddr}{} and the canonical hostname
is unified with \arg{HostName}. is unified with \arg{HostName}.\footnote{This function should support
more functionality provided by \funcref{gethostbyaddr}{}, probably
by adding an option-list.}
\predicate{gethostname}{1}{-Hostname} \predicate{gethostname}{1}{-Hostname}
Return the official fully qualified name of this host. This is achieved Return the canonical fully qualified name of this host. This is achieved
by calling gethostname() followed by gethostbyname() and return the by calling \funcref{gethostname}{} and return the canonical name
official name of the host (\const{h_name}) of the structure returned returned by \funcref{getaddrinfo}{}.
by the latter function.
\end{description} \end{description}
@ -930,9 +895,14 @@ is closed. This is used to realise open_chars_stream/2 in
library(charsio). library(charsio).
\end{description} \end{description}
\predicate{size_memory_file}{2}{+Handle, -Bytes} \predicate{size_memory_file}{2}{+Handle, -Size}
Return the content-length of the memory-file it \arg{Bytes}. The Return the content-length of the memory-file it characters in the
file should be closed and contain data. current encoding of the memory file. The file should be closed and
contain data.
\predicate{size_memory_file}{2}{+Handle, -Size, +Encoding}
Return the content-length of the memory-file it characters in the given
\arg{Encoding}. The file should be closed and contain data.
\predicate{atom_to_memory_file}{2}{+Atom, -Handle} \predicate{atom_to_memory_file}{2}{+Atom, -Handle}
Turn an atom into a read-only memory-file containing the (shared) Turn an atom into a read-only memory-file containing the (shared)
@ -972,13 +942,12 @@ on the next pass through a call- or redo-port of the Prolog engine,
or a call to the PL_handle_signals() routine from SWI-Prolog. \arg{Id} or a call to the PL_handle_signals() routine from SWI-Prolog. \arg{Id}
is unified with a reference to the timer. is unified with a reference to the timer.
The resolution of the alarm depends on the underlying implementation. On The resolution of the alarm depends on the underlying implementation,
Unix systems it is based on setitimer(), on Windows on timeSetEvent() which is based on pthread_cond_timedwait() (on Windows on the pthread
using a resolution specified at 50 milliseconds.\bug{The maximum time emulation thereof). Long-running foreign predicates that do not call
for timeSetEvent() used by the Windows application is 1000 seconds. PL_handle_signals() may further delay the alarm. The relation to
Calling with a higher time value raises a \const{resource_error} blocking system calls (sleep, reading from slow devices, etc.) is
exception.} Long-running foreign predicates that do not call undefined and varies between implementations.
PL_handle_signals() may further delay the alarm.
\arg{Options} is a list of \term{\arg{Name}}{Value} terms. Defined \arg{Options} is a list of \term{\arg{Name}}{Value} terms. Defined
options are: options are:
@ -1030,10 +999,9 @@ executed as in once/1. If \arg{Goal} doesn't complete within \arg{Time}
seconds (wall time), exit using the exception seconds (wall time), exit using the exception
\const{time_limit_exceeded}. See catch/3. \const{time_limit_exceeded}. See catch/3.
Please note that this predicate uses alarm/4 and therefore is \emph{not} Please note that this predicate uses alarm/4 and therefore its effect on
capable to break out of long running goals such as sleep/1, blocking I/O long-running foreign code and system calls is undefined. Blocking I/O
or other long-running (foreign) predicates. Blocking I/O can be handled can be handled using the timeout option of read_term/3.
using the timeout option of read_term/3.
\end{description} \end{description}

View File

@ -1,155 +0,0 @@
/* config.h.in. Generated from configure.in by autoheader. */
/* Define if building universal (internal helper macro) */
#undef AC_APPLE_UNIVERSAL_BUILD
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
systems. This function is required for `alloca.c' support on those systems.
*/
#undef CRAY_STACKSEG_END
/* Define to 1 if using `alloca.c'. */
#undef C_ALLOCA
/* "Define if _XOPEN_SOURCE is needed" */
#undef DEFINE_XOPEN_SOURCE
/* Define to 1 if you have `alloca', as a function or macro. */
#undef HAVE_ALLOCA
/* Define to 1 if you have the <alloca.h> header file. */
#undef HAVE_ALLOCA_H
/* Define to 1 if you have the `crypt' function. */
#undef HAVE_CRYPT
/* Define to 1 if you have the <crypt.h> header file. */
#undef HAVE_CRYPT_H
/* Define to 1 if you have the <execinfo.h> header file. */
#undef HAVE_EXECINFO_H
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define to 1 if you have the `getrlimit' function. */
#undef HAVE_GETRLIMIT
/* Define of h_errno is provided */
#undef HAVE_H_ERRNO
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `crypt' library (-lcrypt). */
#undef HAVE_LIBCRYPT
/* "Define if you have the nsl library (-lnsl)." */
#undef HAVE_LIBNSL
/* "Define if you have the socket library (-lsocket)." */
#undef HAVE_LIBSOCKET
/* Define to 1 if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <netinet/tcp.h> header file. */
#undef HAVE_NETINET_TCP_H
/* Define to 1 if you have the `setitimer' function. */
#undef HAVE_SETITIMER
/* Define to 1 if you have the `setsid' function. */
#undef HAVE_SETSID
/* Define to 1 if the system has the type `socklen_t'. */
#undef HAVE_SOCKLEN_T
/* Define to 1 if the system has the type `ssize_t'. */
#undef HAVE_SSIZE_T
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the `strerror' function. */
#undef HAVE_STRERROR
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/resource.h> header file. */
#undef HAVE_SYS_RESOURCE_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <sys/wait.h> header file. */
#undef HAVE_SYS_WAIT_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the `utime' function. */
#undef HAVE_UTIME
/* Define to 1 if you have the <utime.h> header file. */
#undef HAVE_UTIME_H
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
automatically deduced at runtime.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
#undef STACK_DIRECTION
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
# undef WORDS_BIGENDIAN
# endif
#endif
/* Define for multi-thread support */
#undef _REENTRANT

View File

@ -1,830 +0,0 @@
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by configure, which was
generated by GNU Autoconf 2.64. Invocation command line was
$ ./configure --prefix=/home/vsc/Yap/Prologs/pl-devel --prefix=/home/vsc/Yap/Prologs/pl-devel
## --------- ##
## Platform. ##
## --------- ##
hostname = xato
uname -m = x86_64
uname -r = 2.6.32-22-generic
uname -s = Linux
uname -v = #33-Ubuntu SMP Wed Apr 28 13:28:05 UTC 2010
/usr/bin/uname -p = unknown
/bin/uname -X = unknown
/bin/arch = unknown
/usr/bin/arch -k = unknown
/usr/convex/getsysinfo = unknown
/usr/bin/hostinfo = unknown
/bin/machine = unknown
/usr/bin/oslevel = unknown
/bin/universe = unknown
PATH: /home/vsc/Yap/Prologs/pl-devel/bin
PATH: /home/vsc/bin
PATH: /usr/local/sbin
PATH: /usr/local/bin
PATH: /usr/sbin
PATH: /usr/bin
PATH: /sbin
PATH: /bin
PATH: /usr/games
PATH: /home/vsc/lgtsvn/xml
PATH: /home/vsc/lgtsvn/scripts
PATH: /home/vsc/lgtsvn/integration
## ----------- ##
## Core tests. ##
## ----------- ##
configure:2285: checking for gmake
configure:2312: result: make
configure:2328: checking for etags
configure:2344: found /usr/bin/etags
configure:2355: result: etags
configure:2404: checking for a BSD-compatible install
configure:2472: result: /usr/bin/install -c
configure:2531: checking for gcc
configure:2558: result: ../swipl-ld.sh
configure:2787: checking for C compiler version
configure:2796: ../swipl-ld.sh --version >&5
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
configure:2807: $? = 0
configure:2796: ../swipl-ld.sh -v >&5
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
configure:2807: $? = 0
configure:2796: ../swipl-ld.sh -V >&5
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
... rest of stderr output deleted ...
configure:2807: $? = 1
configure:2796: ../swipl-ld.sh -qversion >&5
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
... rest of stderr output deleted ...
configure:2807: $? = 1
configure:2829: checking for C compiler default output file name
configure:2851: ../swipl-ld.sh conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.00 sec, 37,800 bytes
% halt
configure:2855: $? = 0
configure:2892: result: a.out
configure:2908: checking whether the C compiler works
configure:2917: ./a.out
configure:2921: $? = 0
configure:2936: result: yes
configure:2943: checking whether we are cross compiling
configure:2945: result: no
configure:2948: checking for suffix of executables
configure:2955: ../swipl-ld.sh -o conftest conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.00 sec, 37,800 bytes
% halt
configure:2959: $? = 0
configure:2981: result:
configure:2987: checking for suffix of object files
configure:3009: ../swipl-ld.sh -c conftest.c >&5
configure:3013: $? = 0
configure:3034: result: o
configure:3038: checking whether we are using the GNU C compiler
configure:3057: ../swipl-ld.sh -c conftest.c >&5
configure:3057: $? = 0
configure:3066: result: yes
configure:3075: checking whether ../swipl-ld.sh accepts -g
configure:3095: ../swipl-ld.sh -c -g conftest.c >&5
configure:3095: $? = 0
configure:3136: result: yes
configure:3153: checking for ../swipl-ld.sh option to accept ISO C89
configure:3217: ../swipl-ld.sh -c -g -O2 conftest.c >&5
configure:3217: $? = 0
configure:3230: result: none needed
configure:3251: checking for library containing strerror
configure:3282: ../swipl-ld.sh -o conftest -g -O2 conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.00 sec, 37,800 bytes
% halt
configure:3282: $? = 0
configure:3299: result: none required
configure:3312: checking how to run the C preprocessor
configure:3343: ../swipl-ld.sh -E conftest.c
configure:3343: $? = 0
configure:3357: ../swipl-ld.sh -E conftest.c
conftest.c:9:28: error: ac_nonexistent.h: No such file or directory
gcc -E returned code 256
*** /home/vsc/Yap/Prologs/pl-devel/src/../src/swipl-ld exit status 1
configure:3357: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h. */
| #include <ac_nonexistent.h>
configure:3382: result: ../swipl-ld.sh -E
configure:3402: ../swipl-ld.sh -E conftest.c
configure:3402: $? = 0
configure:3416: ../swipl-ld.sh -E conftest.c
conftest.c:9:28: error: ac_nonexistent.h: No such file or directory
gcc -E returned code 256
*** /home/vsc/Yap/Prologs/pl-devel/src/../src/swipl-ld exit status 1
configure:3416: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h. */
| #include <ac_nonexistent.h>
configure:3445: checking for grep that handles long lines and -e
configure:3503: result: /bin/grep
configure:3508: checking for egrep
configure:3570: result: /bin/grep -E
configure:3575: checking for ANSI C header files
configure:3595: ../swipl-ld.sh -c -g -O2 conftest.c >&5
configure:3595: $? = 0
configure:3668: ../swipl-ld.sh -o conftest -g -O2 conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.01 sec, 37,800 bytes
% halt
configure:3668: $? = 0
configure:3668: ./conftest
configure:3668: $? = 0
configure:3679: result: yes
configure:3693: checking for sys/types.h
configure:3693: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:3693: $? = 0
configure:3693: result: yes
configure:3693: checking for sys/stat.h
configure:3693: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:3693: $? = 0
configure:3693: result: yes
configure:3693: checking for stdlib.h
configure:3693: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:3693: $? = 0
configure:3693: result: yes
configure:3693: checking for string.h
configure:3693: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:3693: $? = 0
configure:3693: result: yes
configure:3693: checking for memory.h
configure:3693: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:3693: $? = 0
configure:3693: result: yes
configure:3693: checking for strings.h
configure:3693: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:3693: $? = 0
configure:3693: result: yes
configure:3693: checking for inttypes.h
configure:3693: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:3693: $? = 0
configure:3693: result: yes
configure:3693: checking for stdint.h
configure:3693: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:3693: $? = 0
configure:3693: result: yes
configure:3693: checking for unistd.h
configure:3693: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:3693: $? = 0
configure:3693: result: yes
configure:3708: checking for working alloca.h
configure:3725: ../swipl-ld.sh -o conftest -fPIC conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.00 sec, 37,800 bytes
% halt
configure:3725: $? = 0
configure:3733: result: yes
configure:3741: checking for alloca
configure:3778: ../swipl-ld.sh -o conftest -fPIC conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.00 sec, 37,800 bytes
% halt
configure:3778: $? = 0
configure:3786: result: yes
configure:3896: checking whether byte ordering is bigendian
configure:3911: ../swipl-ld.sh -c -fPIC conftest.c >&5
conftest.c:22: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'a'
gcc returned code 256
*** /home/vsc/Yap/Prologs/pl-devel/src/../src/swipl-ld exit status 1
configure:3911: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_ALLOCA_H 1
| #define HAVE_ALLOCA 1
| /* end confdefs.h. */
| #ifndef __APPLE_CC__
| not a universal capable compiler
| #endif
| typedef int dummy;
|
configure:3956: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:3956: $? = 0
configure:3974: ../swipl-ld.sh -c -fPIC conftest.c >&5
conftest.c: In function 'main':
conftest.c:28: error: 'not' undeclared (first use in this function)
conftest.c:28: error: (Each undeclared identifier is reported only once
conftest.c:28: error: for each function it appears in.)
conftest.c:28: error: expected ';' before 'big'
gcc returned code 256
*** /home/vsc/Yap/Prologs/pl-devel/src/../src/swipl-ld exit status 1
configure:3974: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_ALLOCA_H 1
| #define HAVE_ALLOCA 1
| /* end confdefs.h. */
| #include <sys/types.h>
| #include <sys/param.h>
|
| int
| main ()
| {
| #if BYTE_ORDER != BIG_ENDIAN
| not big endian
| #endif
|
| ;
| return 0;
| }
configure:4102: result: no
configure:4131: checking for socket
configure:4131: ../swipl-ld.sh -o conftest -fPIC conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.00 sec, 37,800 bytes
% halt
configure:4131: $? = 0
configure:4131: result: yes
configure:4181: checking for gethostent
configure:4181: ../swipl-ld.sh -o conftest -fPIC conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.00 sec, 37,800 bytes
% halt
configure:4181: $? = 0
configure:4181: result: yes
configure:4233: checking for crypt in -lcrypt
configure:4258: ../swipl-ld.sh -o conftest -fPIC conftest.c -lcrypt >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.01 sec, 37,800 bytes
% halt
configure:4258: $? = 0
configure:4267: result: yes
configure:4281: checking for crypt
configure:4281: ../swipl-ld.sh -o conftest -fPIC conftest.c -lcrypt >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.01 sec, 37,800 bytes
% halt
configure:4281: $? = 0
configure:4281: result: yes
configure:4292: checking "Configuring MIME libraries"
configure:4315: result: "Done"
configure:4318: checking h_errno
configure:4337: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4337: $? = 0
configure:4341: result: yes
configure:4352: checking malloc.h usability
configure:4352: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4352: $? = 0
configure:4352: result: yes
configure:4352: checking malloc.h presence
configure:4352: ../swipl-ld.sh -E conftest.c
configure:4352: $? = 0
configure:4352: result: yes
configure:4352: checking for malloc.h
configure:4352: result: yes
configure:4352: checking alloca.h usability
configure:4352: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4352: $? = 0
configure:4352: result: yes
configure:4352: checking alloca.h presence
configure:4352: ../swipl-ld.sh -E conftest.c
configure:4352: $? = 0
configure:4352: result: yes
configure:4352: checking for alloca.h
configure:4352: result: yes
configure:4352: checking for unistd.h
configure:4352: result: yes
configure:4352: checking sys/time.h usability
configure:4352: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4352: $? = 0
configure:4352: result: yes
configure:4352: checking sys/time.h presence
configure:4352: ../swipl-ld.sh -E conftest.c
configure:4352: $? = 0
configure:4352: result: yes
configure:4352: checking for sys/time.h
configure:4352: result: yes
configure:4352: checking fcntl.h usability
configure:4352: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4352: $? = 0
configure:4352: result: yes
configure:4352: checking fcntl.h presence
configure:4352: ../swipl-ld.sh -E conftest.c
configure:4352: $? = 0
configure:4352: result: yes
configure:4352: checking for fcntl.h
configure:4352: result: yes
configure:4352: checking utime.h usability
configure:4352: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4352: $? = 0
configure:4352: result: yes
configure:4352: checking utime.h presence
configure:4352: ../swipl-ld.sh -E conftest.c
configure:4352: $? = 0
configure:4352: result: yes
configure:4352: checking for utime.h
configure:4352: result: yes
configure:4366: checking execinfo.h usability
configure:4366: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4366: $? = 0
configure:4366: result: yes
configure:4366: checking execinfo.h presence
configure:4366: ../swipl-ld.sh -E conftest.c
configure:4366: $? = 0
configure:4366: result: yes
configure:4366: checking for execinfo.h
configure:4366: result: yes
configure:4366: checking sys/resource.h usability
configure:4366: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4366: $? = 0
configure:4366: result: yes
configure:4366: checking sys/resource.h presence
configure:4366: ../swipl-ld.sh -E conftest.c
configure:4366: $? = 0
configure:4366: result: yes
configure:4366: checking for sys/resource.h
configure:4366: result: yes
configure:4366: checking crypt.h usability
configure:4366: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4366: $? = 0
configure:4366: result: yes
configure:4366: checking crypt.h presence
configure:4366: ../swipl-ld.sh -E conftest.c
configure:4366: $? = 0
configure:4366: result: yes
configure:4366: checking for crypt.h
configure:4366: result: yes
configure:4380: checking for sys/types.h
configure:4380: result: yes
configure:4380: checking sys/wait.h usability
configure:4380: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4380: $? = 0
configure:4380: result: yes
configure:4380: checking sys/wait.h presence
configure:4380: ../swipl-ld.sh -E conftest.c
configure:4380: $? = 0
configure:4380: result: yes
configure:4380: checking for sys/wait.h
configure:4380: result: yes
configure:4380: checking for sys/stat.h
configure:4380: result: yes
configure:4393: checking netinet/tcp.h usability
configure:4393: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4393: $? = 0
configure:4393: result: yes
configure:4393: checking netinet/tcp.h presence
configure:4393: ../swipl-ld.sh -E conftest.c
configure:4393: $? = 0
configure:4393: result: yes
configure:4393: checking for netinet/tcp.h
configure:4393: result: yes
configure:4407: checking for setsid
configure:4407: ../swipl-ld.sh -o conftest -fPIC conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.00 sec, 37,800 bytes
% halt
configure:4407: $? = 0
configure:4407: result: yes
configure:4407: checking for strerror
configure:4407: ../swipl-ld.sh -o conftest -fPIC conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.00 sec, 37,800 bytes
% halt
configure:4407: $? = 0
configure:4407: result: yes
configure:4407: checking for setitimer
configure:4407: ../swipl-ld.sh -o conftest -fPIC conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.00 sec, 37,800 bytes
% halt
configure:4407: $? = 0
configure:4407: result: yes
configure:4407: checking for utime
configure:4407: ../swipl-ld.sh -o conftest -fPIC conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.00 sec, 37,800 bytes
% halt
configure:4407: $? = 0
configure:4407: result: yes
configure:4407: checking for getrlimit
configure:4407: ../swipl-ld.sh -o conftest -fPIC conftest.c >&5
% /home/vsc/Yap/Prologs/pl-devel/library/listing compiled into prolog_listing 0.00 sec, 37,800 bytes
% halt
configure:4407: $? = 0
configure:4407: result: yes
configure:4417: checking for socklen_t
configure:4417: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4417: $? = 0
configure:4417: ../swipl-ld.sh -c -fPIC conftest.c >&5
conftest.c: In function 'main':
conftest.c:50: error: expected expression before ')' token
gcc returned code 256
*** /home/vsc/Yap/Prologs/pl-devel/src/../src/swipl-ld exit status 1
configure:4417: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_ALLOCA_H 1
| #define HAVE_ALLOCA 1
| #define HAVE_LIBCRYPT 1
| #define HAVE_CRYPT 1
| #define HAVE_H_ERRNO 1
| #define HAVE_MALLOC_H 1
| #define HAVE_ALLOCA_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_SYS_TIME_H 1
| #define HAVE_FCNTL_H 1
| #define HAVE_UTIME_H 1
| #define HAVE_EXECINFO_H 1
| #define HAVE_SYS_RESOURCE_H 1
| #define HAVE_CRYPT_H 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_WAIT_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_NETINET_TCP_H 1
| #define HAVE_SETSID 1
| #define HAVE_STRERROR 1
| #define HAVE_SETITIMER 1
| #define HAVE_UTIME 1
| #define HAVE_GETRLIMIT 1
| /* end confdefs.h. */
|
| #include <sys/types.h>
| #include <sys/socket.h>
|
|
| int
| main ()
| {
| if (sizeof ((socklen_t)))
| return 0;
| ;
| return 0;
| }
configure:4417: result: yes
configure:4431: checking for ssize_t
configure:4431: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4431: $? = 0
configure:4431: ../swipl-ld.sh -c -fPIC conftest.c >&5
conftest.c: In function 'main':
conftest.c:51: error: expected expression before ')' token
gcc returned code 256
*** /home/vsc/Yap/Prologs/pl-devel/src/../src/swipl-ld exit status 1
configure:4431: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_ALLOCA_H 1
| #define HAVE_ALLOCA 1
| #define HAVE_LIBCRYPT 1
| #define HAVE_CRYPT 1
| #define HAVE_H_ERRNO 1
| #define HAVE_MALLOC_H 1
| #define HAVE_ALLOCA_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_SYS_TIME_H 1
| #define HAVE_FCNTL_H 1
| #define HAVE_UTIME_H 1
| #define HAVE_EXECINFO_H 1
| #define HAVE_SYS_RESOURCE_H 1
| #define HAVE_CRYPT_H 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_WAIT_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_NETINET_TCP_H 1
| #define HAVE_SETSID 1
| #define HAVE_STRERROR 1
| #define HAVE_SETITIMER 1
| #define HAVE_UTIME 1
| #define HAVE_GETRLIMIT 1
| #define HAVE_SOCKLEN_T 1
| /* end confdefs.h. */
|
| #include <sys/types.h>
| #include <sys/socket.h>
|
|
| int
| main ()
| {
| if (sizeof ((ssize_t)))
| return 0;
| ;
| return 0;
| }
configure:4431: result: yes
configure:4446: checking _XOPEN_SOURCE
configure:4463: ../swipl-ld.sh -c -fPIC conftest.c >&5
configure:4463: $? = 0
configure:4467: result: yes
configure:4610: creating ./config.status
## ---------------------- ##
## Running config.status. ##
## ---------------------- ##
This file was extended by config.status, which was
generated by GNU Autoconf 2.64. Invocation command line was
CONFIG_FILES =
CONFIG_HEADERS =
CONFIG_LINKS =
CONFIG_COMMANDS =
$ ./config.status
on xato
config.status:846: creating Makefile
config.status:846: creating config.h
config.status:1012: config.h is unchanged
## ---------------- ##
## Cache variables. ##
## ---------------- ##
ac_cv_c_bigendian=no
ac_cv_c_compiler_gnu=yes
ac_cv_env_CC_set=
ac_cv_env_CC_value=
ac_cv_env_CFLAGS_set=
ac_cv_env_CFLAGS_value=
ac_cv_env_CPPFLAGS_set=
ac_cv_env_CPPFLAGS_value=
ac_cv_env_CPP_set=
ac_cv_env_CPP_value=
ac_cv_env_LDFLAGS_set=
ac_cv_env_LDFLAGS_value=
ac_cv_env_LIBS_set=
ac_cv_env_LIBS_value=
ac_cv_env_build_alias_set=
ac_cv_env_build_alias_value=
ac_cv_env_host_alias_set=
ac_cv_env_host_alias_value=
ac_cv_env_target_alias_set=
ac_cv_env_target_alias_value=
ac_cv_func_alloca_works=yes
ac_cv_func_crypt=yes
ac_cv_func_gethostent=yes
ac_cv_func_getrlimit=yes
ac_cv_func_setitimer=yes
ac_cv_func_setsid=yes
ac_cv_func_socket=yes
ac_cv_func_strerror=yes
ac_cv_func_utime=yes
ac_cv_header_alloca_h=yes
ac_cv_header_crypt_h=yes
ac_cv_header_execinfo_h=yes
ac_cv_header_fcntl_h=yes
ac_cv_header_inttypes_h=yes
ac_cv_header_malloc_h=yes
ac_cv_header_memory_h=yes
ac_cv_header_netinet_tcp_h=yes
ac_cv_header_stdc=yes
ac_cv_header_stdint_h=yes
ac_cv_header_stdlib_h=yes
ac_cv_header_string_h=yes
ac_cv_header_strings_h=yes
ac_cv_header_sys_resource_h=yes
ac_cv_header_sys_stat_h=yes
ac_cv_header_sys_time_h=yes
ac_cv_header_sys_types_h=yes
ac_cv_header_sys_wait_h=yes
ac_cv_header_unistd_h=yes
ac_cv_header_utime_h=yes
ac_cv_lib_crypt_crypt=yes
ac_cv_objext=o
ac_cv_path_EGREP='/bin/grep -E'
ac_cv_path_GREP=/bin/grep
ac_cv_prog_CPP='../swipl-ld.sh -E'
ac_cv_prog_ETAGS=etags
ac_cv_prog_MAKE=make
ac_cv_prog_ac_ct_CC=../swipl-ld.sh
ac_cv_prog_cc_c89=
ac_cv_prog_cc_g=yes
ac_cv_search_strerror='none required'
ac_cv_type_socklen_t=yes
ac_cv_type_ssize_t=yes
ac_cv_working_alloca_h=yes
## ----------------- ##
## Output variables. ##
## ----------------- ##
ALLOCA=''
CC='../swipl-ld.sh'
CFLAGS='-fPIC'
CIFLAGS=''
CMFLAGS='-fPIC'
COFLAGS='-O2 -fno-strict-aliasing'
CPP='../swipl-ld.sh -E'
CPPFLAGS=''
CRYPTLIBS='-lcrypt '
CWFLAGS='-Wall'
DEFS='-DHAVE_CONFIG_H'
ECHO_C=''
ECHO_N='-n'
ECHO_T=''
EGREP='/bin/grep -E'
ETAGS='etags'
EXEEXT=''
GREP='/bin/grep'
INSTALL_DATA='/usr/bin/install -c -m 644'
INSTALL_PROGRAM='${INSTALL}'
INSTALL_SCRIPT='${INSTALL}'
LD='../swipl-ld.sh'
LDFLAGS=''
LDSOFLAGS='-shared'
LIBOBJS=''
LIBS=''
LTLIBOBJS=''
MAKE='make'
NETLIBS=''
OBJEXT='o'
PACKAGE_BUGREPORT=''
PACKAGE_NAME=''
PACKAGE_STRING=''
PACKAGE_TARNAME=''
PACKAGE_URL=''
PACKAGE_VERSION=''
PATH_SEPARATOR=':'
PL='../swipl.sh'
PLARCH='x86_64-linux'
PLBASE='/home/vsc/Yap/Prologs/pl-devel/lib/swipl-5.9.11'
PLINCL='/home/vsc/Yap/Prologs/pl-devel/include'
PLLD='../swipl-ld.sh'
PLLIBS='-lgmp -lrt -lreadline -lncurses -lm -lrt -ldl '
PLTARGETS='random.pl unix.pl socket.pl cgi.pl memfile.pl filesex.pl mime.pl crypt.pl time.pl rlimit.pl streampool.pl'
SHELL='/bin/bash'
SO='so'
TARGETS='random.so unix.so socket.so cgi.so memfile.so files.so mime.so crypt.so time.so rlimit.so'
ac_ct_CC='../swipl-ld.sh'
bindir='${exec_prefix}/bin'
build_alias=''
datadir='${datarootdir}'
datarootdir='${prefix}/share'
docdir='${datarootdir}/doc/${PACKAGE}'
dvidir='${docdir}'
exec_prefix='${prefix}'
host_alias=''
htmldir='${docdir}'
includedir='${prefix}/include'
infodir='${datarootdir}/info'
libdir='${exec_prefix}/lib'
libexecdir='${exec_prefix}/libexec'
localedir='${datarootdir}/locale'
localstatedir='${prefix}/var'
mandir='${datarootdir}/man'
oldincludedir='/usr/include'
pdfdir='${docdir}'
prefix='/home/vsc/Yap/Prologs/pl-devel'
program_transform_name='s,x,x,'
psdir='${docdir}'
sbindir='${exec_prefix}/sbin'
sharedstatedir='${prefix}/com'
sysconfdir='${prefix}/etc'
target_alias=''
## ----------- ##
## confdefs.h. ##
## ----------- ##
/* confdefs.h */
#define PACKAGE_NAME ""
#define PACKAGE_TARNAME ""
#define PACKAGE_VERSION ""
#define PACKAGE_STRING ""
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""
#define STDC_HEADERS 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRING_H 1
#define HAVE_MEMORY_H 1
#define HAVE_STRINGS_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_UNISTD_H 1
#define HAVE_ALLOCA_H 1
#define HAVE_ALLOCA 1
#define HAVE_LIBCRYPT 1
#define HAVE_CRYPT 1
#define HAVE_H_ERRNO 1
#define HAVE_MALLOC_H 1
#define HAVE_ALLOCA_H 1
#define HAVE_UNISTD_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_FCNTL_H 1
#define HAVE_UTIME_H 1
#define HAVE_EXECINFO_H 1
#define HAVE_SYS_RESOURCE_H 1
#define HAVE_CRYPT_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_WAIT_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_NETINET_TCP_H 1
#define HAVE_SETSID 1
#define HAVE_STRERROR 1
#define HAVE_SETITIMER 1
#define HAVE_UTIME 1
#define HAVE_GETRLIMIT 1
#define HAVE_SOCKLEN_T 1
#define HAVE_SSIZE_T 1
#define DEFINE_XOPEN_SOURCE 1
configure: exit 0

View File

@ -73,7 +73,10 @@ AC_CHECK_HEADERS(execinfo.h sys/resource.h crypt.h)
AC_CHECK_HEADERS(sys/types.h sys/wait.h sys/stat.h) AC_CHECK_HEADERS(sys/types.h sys/wait.h sys/stat.h)
AC_CHECK_HEADERS(netinet/tcp.h) AC_CHECK_HEADERS(netinet/tcp.h)
AC_CHECK_FUNCS(setsid strerror setitimer utime getrlimit) AC_CHECK_SIZEOF(long, 4)
AC_CHECK_SIZEOF(long long, 8)
AC_CHECK_FUNCS(setsid strerror setitimer utime getrlimit vfork)
AC_CHECK_TYPES(socklen_t, [], [], AC_CHECK_TYPES(socklen_t, [], [],
[ [
#include <sys/types.h> #include <sys/types.h>

View File

@ -33,8 +33,6 @@
[ crypt/2 [ crypt/2
]). ]).
:- use_module(library(shlib)).
:- use_foreign_library(foreign(crypt), install_crypt). :- use_foreign_library(foreign(crypt), install_crypt).
% crypt(+Passwd, ?Encripted). % crypt(+Passwd, ?Encripted).

0
packages/clib/demo/cgidemo.pl Executable file → Normal file
View File

View File

@ -57,6 +57,7 @@ pl_error(const char *pred, int arity, const char *msg, int id, ...)
switch(err) switch(err)
{ case ENOMEM: { case ENOMEM:
case EAGAIN: /* fork(); might be other resource */
rc = PL_unify_term(formal, rc = PL_unify_term(formal,
CompoundArg("resource_error", 1), CompoundArg("resource_error", 1),
AtomArg("no_memory")); AtomArg("no_memory"));
@ -85,7 +86,7 @@ pl_error(const char *pred, int arity, const char *msg, int id, ...)
break; break;
} }
case ERR_ARGTYPE: case ERR_ARGTYPE:
{ int argn = va_arg(args, int); { int argn = va_arg(args, int); /* argument position (unused) */
term_t actual = va_arg(args, term_t); term_t actual = va_arg(args, term_t);
atom_t expected = PL_new_atom(va_arg(args, const char*)); atom_t expected = PL_new_atom(va_arg(args, const char*));

View File

@ -1,11 +1,10 @@
/* $Id$ /* Part of SWI-Prolog
Part of SWI-Prolog
Author: Jan Wielemaker Author: Jan Wielemaker
E-mail: jan@swi.psy.uva.nl E-mail: J.Wielemaker@cs.vu.nl
WWW: http://www.swi-prolog.org WWW: http://www.swi-prolog.org
Copyright (C): 1985-2002, University of Amsterdam Copyright (C): 2002-2010, University of Amsterdam
Vu University Amsterdam
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
@ -40,10 +39,43 @@
#endif #endif
#include <errno.h> #include <errno.h>
#ifdef __WINDOWS__
#define MAKE_FUNCTORS 1
#include <windows.h>
#include "win_error.c"
#define statstruct struct _stati64
#define statfunc _wstati64
/*#define HAVE_UTIME 1: Broken ...*/
#ifdef HAVE_UTIME
#include <sys/utime.h>
#define utimestruct _utimbuf
#define utimefunc _wutime
#endif
#define FCHAR wchar_t
#define PL_get_file_name PL_get_file_nameW
#else /*__WINDOWS__*/
#define statstruct struct stat
#define statfunc stat
#define utimestruct struct utimbuf
#define utimefunc utime
#define FCHAR char
#endif /*__WINDOWS__*/
static functor_t FUNCTOR_access1; static functor_t FUNCTOR_access1;
static functor_t FUNCTOR_modified1; static functor_t FUNCTOR_modified1;
static functor_t FUNCTOR_changed1; static functor_t FUNCTOR_changed1;
static atom_t ATOM_now; static atom_t ATOM_now;
static atom_t ATOM_hard;
static atom_t ATOM_symbolic;
/*******************************
* TIME *
*******************************/
static int static int
add_time_option(term_t list, functor_t f, time_t time) add_time_option(term_t list, functor_t f, time_t time)
@ -116,13 +148,13 @@ set_file_time(+Spec, -Old, +New)
static foreign_t static foreign_t
pl_set_time_file(term_t spec, term_t old, term_t new) pl_set_time_file(term_t spec, term_t old, term_t new)
{ char *name; { FCHAR *name;
struct stat sbuf; statstruct sbuf;
if ( !PL_get_file_name(spec, &name, 0) ) if ( !PL_get_file_name(spec, &name, 0) )
return FALSE; return FALSE;
if ( stat(name, &sbuf) ) if ( statfunc(name, &sbuf) )
return pl_error(NULL, 0, NULL, ERR_ERRNO, errno, "stat", "file", spec); return pl_error(NULL, 0, NULL, ERR_ERRNO, errno, "stat", "file", spec);
add_time_option(old, FUNCTOR_access1, sbuf.st_atime); add_time_option(old, FUNCTOR_access1, sbuf.st_atime);
@ -132,7 +164,7 @@ pl_set_time_file(term_t spec, term_t old, term_t new)
if ( !PL_get_nil(new) ) if ( !PL_get_nil(new) )
#ifdef HAVE_UTIME #ifdef HAVE_UTIME
{ struct utimbuf tbuf; { utimestruct tbuf;
if ( !get_time_option(new, FUNCTOR_access1, if ( !get_time_option(new, FUNCTOR_access1,
sbuf.st_atime, &tbuf.actime) ) sbuf.st_atime, &tbuf.actime) )
@ -141,7 +173,7 @@ pl_set_time_file(term_t spec, term_t old, term_t new)
sbuf.st_mtime, &tbuf.modtime) ) sbuf.st_mtime, &tbuf.modtime) )
return FALSE; return FALSE;
if ( utime(name, &tbuf) != 0 ) if ( utimefunc(name, &tbuf) != 0 )
return pl_error(NULL, 0, NULL, ERR_ERRNO, errno, "set_time", "file", spec); return pl_error(NULL, 0, NULL, ERR_ERRNO, errno, "set_time", "file", spec);
} }
#else #else
@ -152,12 +184,77 @@ pl_set_time_file(term_t spec, term_t old, term_t new)
} }
/*******************************
* LINK *
*******************************/
static foreign_t
pl_link_file(term_t from, term_t to, term_t how)
{ FCHAR *fname, *tname;
atom_t hname;
if ( !PL_get_file_name(from, &fname, PL_FILE_OSPATH) ||
!PL_get_file_name(to, &tname, PL_FILE_OSPATH) )
return FALSE;
if ( !PL_get_atom(how, &hname) )
return pl_error(NULL, 0, NULL, ERR_TYPE, how, "atom");
#ifdef __WINDOWS__
if ( hname == ATOM_hard )
{ if ( !CreateHardLinkW(tname, fname, NULL) )
return win_error("CreateHardLink");
} else if ( hname == ATOM_symbolic )
{ static int (*symlink)(wchar_t *new, wchar_t *existing, DWORD flags);
static int fetched = FALSE;
if ( !fetched )
{ HMODULE hmod = GetModuleHandle("kernel32.dll");
void *addr = GetProcAddress(hmod, "CreateSymbolicLink");
symlink = addr;
fetched = TRUE;
}
if ( !symlink )
return pl_error(NULL, 0, NULL, ERR_DOMAIN, how, "link_type");
if ( !(*symlink)(tname, fname, 0) )
return win_error("CreateSymbolicLink");
} else
return pl_error(NULL, 0, NULL, ERR_DOMAIN, how, "link_type");
#else /*__WINDOWS__*/
if ( hname == ATOM_hard )
{ if ( link(fname, tname) != 0 )
return pl_error(NULL, 0, NULL, ERR_ERRNO, errno, "link", "file", to);
} else if ( hname == ATOM_symbolic )
{ if ( symlink(fname, tname) != 0 )
return pl_error(NULL, 0, NULL, ERR_ERRNO, errno, "link", "file", to);
} else
return pl_error(NULL, 0, NULL, ERR_DOMAIN, how, "link_type");
#endif /*__WINDOWS__*/
return TRUE;
}
install_t install_t
install_files() install_files()
{ FUNCTOR_access1 = PL_new_functor(PL_new_atom("access"), 1); { FUNCTOR_access1 = PL_new_functor(PL_new_atom("access"), 1);
FUNCTOR_modified1 = PL_new_functor(PL_new_atom("modified"), 1); FUNCTOR_modified1 = PL_new_functor(PL_new_atom("modified"), 1);
FUNCTOR_changed1 = PL_new_functor(PL_new_atom("changed"), 1); FUNCTOR_changed1 = PL_new_functor(PL_new_atom("changed"), 1);
ATOM_now = PL_new_atom("now"); ATOM_now = PL_new_atom("now");
ATOM_hard = PL_new_atom("hard");
ATOM_symbolic = PL_new_atom("symbolic");
#ifdef __WINDOWS__
win_init_errors();
#endif
PL_register_foreign("set_time_file", 3, pl_set_time_file, 0); PL_register_foreign("set_time_file", 3, pl_set_time_file, 0);
PL_register_foreign("link_file", 3, pl_link_file, 0);
} }

View File

@ -1,11 +1,10 @@
/* $Id /* Part of SWI-Prolog
Part of SWI-Prolog
Author: Jan Wielemaker Author: Jan Wielemaker
E-mail: jan@swi.psy.uva.nl E-mail: J.Wielemaker@cs.vu.nl
WWW: http://www.swi-prolog.org WWW: http://www.swi-prolog.org
Copyright (C): 1985-2002, University of Amsterdam Copyright (C): 2002-2010, University of Amsterdam
Vu University Amsterdam
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
@ -30,11 +29,174 @@
*/ */
:- module(files_ex, :- module(files_ex,
[ set_time_file/3 [ set_time_file/3, % +File, -OldTimes, +NewTimes
link_file/3, % +OldPath, +NewPath, +Type
relative_file_name/3, % +AbsPath, +RelTo, -RelPath
directory_file_path/3, % +Dir, +File, -Path
copy_file/2, % +From, +To
make_directory_path/1 % +Directory
]). ]).
/** <module> Extended operations on files
This module provides additional operations on files. This covers both
more obscure and possible non-portable low-level operations and
high-level utilities.
*/
:- use_foreign_library(foreign(files), install_files). :- use_foreign_library(foreign(files), install_files).
% set_time_file(+File, -OldTimes, +NewTimes) %% set_time_file(+File, -OldTimes, +NewTimes) is det.
% %
% Query and set POSIX time attributes of a file. Both OldTimes and
% NewTimes are lists of option-terms. Times are represented in
% SWI-Prolog's standard floating point numbers. New times may be
% specified as =now= to indicate the current time. Defined options
% are:
%
% * access(Time)
% Describes the time of last access of the file. This value
% can be read and written.
%
% * modified(Time)
% Describes the time the contents of the file was last
% modified. This value can be read and written.
%
% * changed(Time)
% Describes the time the file-structure itself was changed by
% adding (link()) or removing (unlink()) names.
%
% Below are some example queries. The first retrieves the
% access-time, while the second sets the last-modified time to the
% current time.
%
% ==
% ?- set_time_file(foo, [acess(Access)], []).
% ?- set_time_file(foo, [], [modified(now)]).
% ==
%
% @bug Setting times does not work on Windows.
%% link_file(+OldPath, +NewPath, +Type) is det.
%
% Create a link in the filesystem from NewPath to OldPath. Type
% defines the type of link and is one of =hard= or =symbolic=.
%
% With some limitations, these functions also work on Windows.
% First of all, the unerlying filesystem must support links. This
% requires NTFS. Second, symbolic links are only supported in
% Vista and later.
%
% @error domain_error(link_type, Type) if the requested link-type
% is unknown or not supported on the target OS.
%% relative_file_name(+Path:atom, +RelTo:atom, -RelPath:atom) is det.
%
% True when RelPath is a relative path to AbsPath, relative to
% RelTo. Path and RelTo are first handed to absolute_file_name/2,
% which makes the absolute *and* canonical. Below is an example:
%
% ==
% ?- relative_file_name('/home/janw/nice',
% '/home/janw/deep/dir/file', Path).
% Path = '../../nice'.
% ==
%
% @param All paths must be in canonical POSIX notation, i.e.,
% using / to separate segments in the path. See
% prolog_to_os_filename/2.
% @bug This predicate is defined as a _syntactical_ operation.
relative_file_name(Path, RelTo, RelPath) :-
absolute_file_name(Path, AbsPath),
absolute_file_name(RelTo, AbsRelTo),
atomic_list_concat(PL, /, AbsPath),
atomic_list_concat(RL, /, AbsRelTo),
delete_common_prefix(PL, RL, PL1, PL2),
to_dot_dot(PL2, DotDot, PL1),
atomic_list_concat(DotDot, /, RelPath).
delete_common_prefix([H|T01], [H|T02], T1, T2) :- !,
delete_common_prefix(T01, T02, T1, T2).
delete_common_prefix(T1, T2, T1, T2).
to_dot_dot([], Tail, Tail).
to_dot_dot([_], Tail, Tail) :- !.
to_dot_dot([_|T0], ['..'|T], Tail) :-
to_dot_dot(T0, T, Tail).
%% directory_file_path(+Directory, +File, -Path) is det.
%% directory_file_path(?Directory, ?File, +Path) is det.
%
% True when Path is the full path-name for File in Dir. This is
% comparable to atom_concat(Directory, File, Path), but it ensures
% there is exactly one / between the two parts. Notes:
%
% * In mode (+,+,-), if File is given and absolute, Path
% is unified to File.
% * Mode (-,-,+) uses file_directory_name/2 and file_base_name/2
directory_file_path(Dir, File, Path) :-
nonvar(Dir), nonvar(File), !,
( is_absolute_file_name(File)
-> Path = File
; sub_atom(Dir, _, _, 0, /)
-> atom_concat(Dir, File, Path)
; atomic_list_concat([Dir, /, File], Path)
).
directory_file_path(Dir, File, Path) :-
nonvar(Path), !,
( nonvar(Dir)
-> ( sub_atom(Dir, _, _, 0, /)
-> atom_concat(Dir, File, Path)
; atom_concat(Dir, /, TheDir),
atom_concat(TheDir, File, Path)
)
; nonvar(File)
-> atom_concat(Dir, File, Path)
; file_directory_name(Path, Dir),
file_base_name(Path, File)
).
directory_file_path(_, _, _) :-
throw(error(instantiation_error(_), _)).
%% copy_file(From, To) is det.
%
% Copy a file into a new file or directory. The data is copied as
% binary data.
copy_file(From, To) :-
destination_file(To, From, Dest),
setup_call_cleanup(open(Dest, write, Out, [type(binary)]),
copy_from(From, Out),
close(Out)).
copy_from(File, Stream) :-
setup_call_cleanup(open(File, read, In, [type(binary)]),
copy_stream_data(In, Stream),
close(In)).
destination_file(Dir, File, Dest) :-
exists_directory(Dir), !,
atomic_list_concat([Dir, File], /, Dest).
destination_file(Dest, _, Dest).
%% make_directory_path(+Dir) is det.
%
% Create Dir and all required components (like mkdir -p). Can
% raise various file-specific exceptions.
make_directory_path(Dir) :-
make_directory_path_2(Dir), !.
make_directory_path(Dir) :-
permission_error(create, directory, Dir).
make_directory_path_2(Dir) :-
exists_directory(Dir), !.
make_directory_path_2(Dir) :-
Dir \== (/), !,
file_directory_name(Dir, Parent),
make_directory_path_2(Parent),
make_directory(Dir).

View File

@ -5,21 +5,12 @@
################################################################ ################################################################
CC=@CC@ CC=@CC@
CFLAGS=@CFLAGS@ @DEFS@ CFLAGS=@MAILDROP_CFLAGS@ @DEFS@
LIBS=@LIBS@ LIBS=@LIBS@
AR=@AR@ AR=@AR@
RANLIB=@RANLIB@ RANLIB=@RANLIB@
ifeq (@PROLOG_SYSTEM@,yap)
srcdir=@srcdir@ srcdir=@srcdir@
SHLIB_CFLAGS=@SHLIB_CFLAGS@
%.o: $(srcdir)/%.c
$(CC) -c $(CFLAGS) -I$(srcdir) -I$(srcdir)/.. -I../../../.. $(SHLIB_CFLAGS) $< -o $@
endif
OBJ= rfc2045.o rfc2045acchk.o rfc2045acprep.o \ OBJ= rfc2045.o rfc2045acchk.o rfc2045acprep.o \
rfc2045appendurl.o rfc2045cdecode.o rfc2045decode.o \ rfc2045appendurl.o rfc2045cdecode.o rfc2045decode.o \
rfc2045enomem.o \ rfc2045enomem.o \
@ -34,13 +25,18 @@ librfc2045.a: $(OBJ)
$(AR) r librfc2045.a $(OBJ) $(AR) r librfc2045.a $(OBJ)
$(RANLIB) librfc2045.a $(RANLIB) librfc2045.a
#
# find out how to generate .o files from $(scrdir)
#
%.o: $(srcdir)/%.c
$(CC) -c $(CFLAGS) $< -o $@
################################################################ ################################################################
# Clean # Clean
################################################################ ################################################################
clean: clean:
rm -f $(OBJ) *~ *.o *% a.out core config.log librfc2045.a rm -f $(OBJ) *~ *.o *% a.out core config.log
distclean: clean distclean: clean
rm -f Makefile config.status config.h librfc2045.a rm -f Makefile config.status config.h librfc2045.a

View File

@ -1,105 +0,0 @@
/* config.h.in. Generated from configure.in by autoheader. */
/* Define if gethostname() is provided */
#undef HAS_GETHOSTNAME
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <sys/wait.h> header file. */
#undef HAVE_SYS_WAIT_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Specify package */
#undef RFC2045PKG
/* Specify version */
#undef RFC2045VER
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Enable extensions on AIX 3, Interix. */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
#endif
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# undef _GNU_SOURCE
#endif
/* Enable threading extensions on Solaris. */
#ifndef _POSIX_PTHREAD_SEMANTICS
# undef _POSIX_PTHREAD_SEMANTICS
#endif
/* Enable extensions on HP NonStop. */
#ifndef _TANDEM_SOURCE
# undef _TANDEM_SOURCE
#endif
/* Enable general extensions on Solaris. */
#ifndef __EXTENSIONS__
# undef __EXTENSIONS__
#endif
/* Define to 1 if on MINIX. */
#undef _MINIX
/* Define to 2 if the system does not provide POSIX.1 features except with
this defined. */
#undef _POSIX_1_SOURCE
/* Define to 1 if you need to in order for `stat' and other things to work. */
#undef _POSIX_SOURCE
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Define to `long int' if <sys/types.h> does not define. */
#undef off_t
/* Define to `int' if <sys/types.h> does not define. */
#undef pid_t
/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t

View File

@ -1,10 +0,0 @@
/*
** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
** distribution information.
*/
/* $Id$ */
#define RFC2045CHARSET "us-ascii"
#define RFC2045MIMEMSG "This is a MIME-formatted message. If you see this text it means that your\nE-mail software does not support MIME-formatted messages.\n"

View File

@ -23,7 +23,7 @@
/* $Id$ */ /* $Id$ */
#if HAS_GETHOSTNAME||HAVE_GETHOSTNAME #if HAS_GETHOSTNAME
#else #else

View File

@ -1 +0,0 @@
timestamp for config.h

View File

@ -5,21 +5,12 @@
################################################################ ################################################################
CC=@CC@ CC=@CC@
CFLAGS=@CFLAGS@ @DEFS@ CFLAGS=@MAILDROP_CFLAGS@ @DEFS@
LIBS=@LIBS@ LIBS=@LIBS@
AR=@AR@ AR=@AR@
RANLIB=@RANLIB@ RANLIB=@RANLIB@
ifeq (@PROLOG_SYSTEM@,yap)
srcdir=@srcdir@ srcdir=@srcdir@
SHLIB_CFLAGS=@SHLIB_CFLAGS@
%.o: $(srcdir)/%.c
$(CC) -c $(CFLAGS) -I../../../.. $(SHLIB_CFLAGS) $< -o $@
endif
OBJ= rfc822.o rfc822_getaddr.o rfc822_getaddrs.o \ OBJ= rfc822.o rfc822_getaddr.o rfc822_getaddrs.o \
rfc822_mkdate.o rfc822_parsedt.o rfc2047u.o \ rfc822_mkdate.o rfc822_parsedt.o rfc2047u.o \
rfc2047.o imapsubj.o imaprefs.o rfc2047.o imapsubj.o imaprefs.o
@ -32,12 +23,18 @@ librfc822.a: $(OBJ)
$(RANLIB) librfc822.a $(RANLIB) librfc822.a
#
# find out how to generate .o files from $(scrdir)
#
%.o: $(srcdir)/%.c
$(CC) -c $(CFLAGS) $< -o $@
################################################################ ################################################################
# Clean # Clean
################################################################ ################################################################
clean: clean:
rm -f $(OBJ) *~ *.o *% a.out core config.log librfc822.a rm -f $(OBJ) *~ *.o *% a.out core config.log
distclean: clean distclean: clean
rm -f Makefile config.status config.h librfc822.a rm -f Makefile config.status config.h librfc822.a

View File

@ -1,108 +0,0 @@
/* config.h.in. Generated from configure.in by autoheader. */
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Whether we have libunicode.a */
#undef HAVE_LIBUNICODE
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the `strcasecmp' function. */
#undef HAVE_STRCASECMP
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the `strncasecmp' function. */
#undef HAVE_STRNCASECMP
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
#undef TM_IN_SYS_TIME
/* Enable extensions on AIX 3, Interix. */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
#endif
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# undef _GNU_SOURCE
#endif
/* Enable threading extensions on Solaris. */
#ifndef _POSIX_PTHREAD_SEMANTICS
# undef _POSIX_PTHREAD_SEMANTICS
#endif
/* Enable extensions on HP NonStop. */
#ifndef _TANDEM_SOURCE
# undef _TANDEM_SOURCE
#endif
/* Enable general extensions on Solaris. */
#ifndef __EXTENSIONS__
# undef __EXTENSIONS__
#endif
/* Whether daylight savings time offset is set via the altzone variable */
#undef USE_TIME_ALTZONE
/* Whether daylight savings time offset is set via the tm_isdst member */
#undef USE_TIME_DAYLIGHT
/* Whether time offset is specified via the tm_gmtoff member */
#undef USE_TIME_GMTOFF
/* Define to 1 if on MINIX. */
#undef _MINIX
/* Define to 2 if the system does not provide POSIX.1 features except with
this defined. */
#undef _POSIX_1_SOURCE
/* Define to 1 if you need to in order for `stat' and other things to work. */
#undef _POSIX_SOURCE
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t

View File

@ -1 +0,0 @@
timestamp for config.h

View File

@ -305,39 +305,68 @@ open_memory_file(term_t handle, term_t mode, term_t stream)
static foreign_t static foreign_t
size_memory_file(term_t handle, term_t size) size_memory_file(term_t handle, term_t sizeh, term_t encoding)
{ memfile *m; { memfile *m;
if ( get_memfile(handle, &m) ) if ( get_memfile(handle, &m) )
{ if ( m->stream && !m->atom ) { if ( m->stream && !m->atom )
return alreadyOpen(handle, "size"); return alreadyOpen(handle, "size");
if ( m->data ) if ( m->data )
{ if ( m->size == NOSIZE ) { IOENC size_enc = m->encoding;
{ switch( m->encoding ) size_t size;
if ( encoding )
{ if ( !get_encoding(encoding, &size_enc) )
return FALSE;
} else
size_enc = m->encoding;
if ( m->size != NOSIZE && size_enc == m->encoding )
{ size = m->size;
} else
{ switch( size_enc )
{ case ENC_ISO_LATIN_1: { case ENC_ISO_LATIN_1:
case ENC_OCTET: case ENC_OCTET:
m->size = m->data_size; size = m->data_size;
break; break;
case ENC_WCHAR: case ENC_WCHAR:
m->size = m->data_size / sizeof(wchar_t); size = m->data_size / sizeof(wchar_t);
break; break;
case ENC_UTF8: case ENC_UTF8:
m->size = PL_utf8_strlen(m->data, m->data_size); size = PL_utf8_strlen(m->data, m->data_size);
break; break;
default: default:
assert(0); assert(0);
return FALSE; return FALSE;
} }
if ( size_enc == m->encoding )
m->size = size;
} }
return PL_unify_integer(size, m->size);
return PL_unify_int64(sizeh, size);
} else } else
return PL_unify_integer(size, 0); { return PL_unify_integer(sizeh, 0);
}
} }
return FALSE; return FALSE;
} }
static foreign_t
size_memory_file2(term_t handle, term_t size)
{ return size_memory_file(handle, size, 0);
}
static foreign_t
size_memory_file3(term_t handle, term_t size, term_t encoding)
{ return size_memory_file(handle, size, encoding);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
utf8_position_memory_file(+MF, -Here, -Size) utf8_position_memory_file(+MF, -Here, -Size)
@ -478,13 +507,10 @@ memory_file_to_codes3(term_t handle, term_t atom, term_t encoding)
install_t install_t
install_memfile() install_memfile()
{ { if ( PL_query(PL_QUERY_VERSION) <= 50505 )
#if !_YAP_NOT_INSTALLED_
if ( PL_query(PL_QUERY_VERSION) <= 50505 )
{ PL_warning("Requires SWI-Prolog version 5.5.6 or later"); { PL_warning("Requires SWI-Prolog version 5.5.6 or later");
return; return;
} }
#endif
FUNCTOR_memory_file1 = PL_new_functor(PL_new_atom("$memory_file"), 1); FUNCTOR_memory_file1 = PL_new_functor(PL_new_atom("$memory_file"), 1);
MKATOM(encoding); MKATOM(encoding);
@ -503,7 +529,8 @@ if ( PL_query(PL_QUERY_VERSION) <= 50505 )
PL_register_foreign("new_memory_file", 1, new_memory_file, 0); PL_register_foreign("new_memory_file", 1, new_memory_file, 0);
PL_register_foreign("free_memory_file", 1, free_memory_file, 0); PL_register_foreign("free_memory_file", 1, free_memory_file, 0);
PL_register_foreign("size_memory_file", 2, size_memory_file, 0); PL_register_foreign("size_memory_file", 2, size_memory_file2, 0);
PL_register_foreign("size_memory_file", 3, size_memory_file3, 0);
PL_register_foreign("open_memory_file", 3, open_memory_file, 0); PL_register_foreign("open_memory_file", 3, open_memory_file, 0);
PL_register_foreign("open_memory_file", 4, open_memory_file4, 0); PL_register_foreign("open_memory_file", 4, open_memory_file4, 0);
PL_register_foreign("atom_to_memory_file", 2, atom_to_memory_file, 0); PL_register_foreign("atom_to_memory_file", 2, atom_to_memory_file, 0);

View File

@ -1,512 +0,0 @@
/* $Id$
Part of SWI-Prolog
Author: Jan Wielemaker
E-mail: J.Wielemaker@uva.nl
WWW: http://www.swi-prolog.org
Copyright (C): 1985-2009, University of Amsterdam
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <SWI-Stream.h>
#include <SWI-Prolog.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include "error.h"
#define streq(s,q) (strcmp((s), (q)) == 0)
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Memory-files
make_memory_file(-Handle)
free_memory_file(+Handle)
open_memory_file(+Handle, +Mode, -Stream)
size_memory_file(+Handle, -Size)
memory_file_to_codes(+Handle, -Codes)
memory_file_to_atom(+Handle, -Atom)
atom_to_memory_file(+Atom, -Handle)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
static functor_t FUNCTOR_memory_file1;
static atom_t ATOM_encoding;
static atom_t ATOM_unknown;
static atom_t ATOM_octet;
static atom_t ATOM_ascii;
static atom_t ATOM_iso_latin_1;
static atom_t ATOM_text;
static atom_t ATOM_utf8;
static atom_t ATOM_unicode_be;
static atom_t ATOM_unicode_le;
static atom_t ATOM_wchar_t;
static atom_t ATOM_read;
static atom_t ATOM_write;
static atom_t ATOM_free_on_close;
#define MEMFILE_MAGIC 0x5624a6b3L
#define NOSIZE ((size_t)-1)
typedef struct
{ long magic; /* MEMFILE_MAGIC */
IOENC encoding; /* encoding of the data */
int free_on_close; /* free if it is closed */
char *data; /* data of the file */
size_t data_size; /* byte-size of data */
size_t size; /* size in characters */
IOSTREAM *stream; /* Stream hanging onto it */
atom_t atom; /* Created from atom */
} memfile;
static int
unify_memfile(term_t handle, memfile *f)
{ return PL_unify_term(handle,
PL_FUNCTOR, FUNCTOR_memory_file1,
PL_POINTER, f);
}
static int
get_memfile(term_t handle, memfile **f)
{ if ( PL_is_functor(handle, FUNCTOR_memory_file1) )
{ term_t a = PL_new_term_ref();
void *ptr;
_PL_get_arg(1, handle, a);
if ( PL_get_pointer(a, &ptr) )
{ memfile *m = ptr;
if ( m->magic == MEMFILE_MAGIC )
{ *f = ptr;
return TRUE;
}
return pl_error(NULL, 0, NULL, ERR_EXISTENCE,
"memory_file", handle);
}
}
return pl_error(NULL, 0, NULL, ERR_ARGTYPE, 1,
handle, "memory_file");
}
static foreign_t
new_memory_file(term_t handle)
{ memfile *m = calloc(1, sizeof(*m));
if ( !m )
return pl_error(NULL, 0, NULL, ERR_ERRNO, errno,
"create", "memory_file", handle);
m->magic = MEMFILE_MAGIC;
m->encoding = ENC_UTF8;
m->data = 0;
m->size = 0;
if ( unify_memfile(handle, m) )
return TRUE;
m->magic = 0;
free(m);
return FALSE;
}
static int
destroy_memory_file(memfile *m)
{ if ( m->stream )
Sclose(m->stream);
if ( m->atom )
PL_unregister_atom(m->atom);
else if ( m->data )
Sfree(m->data); /* MS-Windows: malloc by other DLL! */
m->magic = 0;
free(m);
return TRUE;
}
static foreign_t
free_memory_file(term_t handle)
{ memfile *m;
if ( get_memfile(handle, &m) )
return destroy_memory_file(m);
return FALSE;
}
static void
closehook(void *closure)
{ memfile *m = closure;
m->stream = NULL;
if ( m->free_on_close )
destroy_memory_file(m);
}
static foreign_t
alreadyOpen(term_t handle, const char *op)
{ return pl_error(NULL, 0, "already open",
ERR_PERMISSION, handle, op, "memory_file");
}
static struct encname
{ IOENC code;
atom_t *name;
} encoding_names[] =
{ { ENC_UNKNOWN, &ATOM_unknown },
{ ENC_OCTET, &ATOM_octet },
{ ENC_ASCII, &ATOM_ascii },
{ ENC_ISO_LATIN_1, &ATOM_iso_latin_1 },
{ ENC_ANSI, &ATOM_text },
{ ENC_UTF8, &ATOM_utf8 },
{ ENC_UNICODE_BE, &ATOM_unicode_be },
{ ENC_UNICODE_LE, &ATOM_unicode_le },
{ ENC_WCHAR, &ATOM_wchar_t },
{ ENC_UNKNOWN, NULL },
};
IOENC
atom_to_encoding(atom_t a)
{ struct encname *en;
for(en=encoding_names; en->name; en++)
{ if ( *en->name == a )
return en->code;
}
return ENC_UNKNOWN;
}
static int
get_encoding(term_t t, IOENC *enc)
{ atom_t en;
if ( PL_get_atom(t, &en) )
{ IOENC encoding;
if ( (encoding = atom_to_encoding(en)) == ENC_UNKNOWN )
return pl_error(NULL, 0, NULL, ERR_DOMAIN, t, "encoding");
*enc = encoding;
return TRUE;
}
return pl_error(NULL, 0, NULL, ERR_TYPE, t, "encoding");
}
static foreign_t
open_memory_file4(term_t handle, term_t mode, term_t stream, term_t options)
{ memfile *m;
char *x;
atom_t iom;
IOSTREAM *fd;
IOENC encoding;
int free_on_close = FALSE;
if ( !get_memfile(handle, &m) )
return FALSE;
if ( m->stream )
return alreadyOpen(handle, "open");
if ( !PL_get_atom(mode, &iom) )
return pl_error("open_memory_file", 3, NULL, ERR_ARGTYPE, 2,
mode, "io_mode");
encoding = m->encoding;
if ( options )
{ term_t tail = PL_copy_term_ref(options);
term_t head = PL_new_term_ref();
while(PL_get_list(tail, head, tail))
{ int arity;
atom_t name;
if ( PL_get_name_arity(head, &name, &arity) && arity == 1 )
{ term_t arg = PL_new_term_ref();
_PL_get_arg(1, head, arg);
if ( name == ATOM_encoding )
{ if ( !get_encoding(arg, &encoding) )
return FALSE;
} else if ( name == ATOM_free_on_close )
{ if ( !PL_get_bool(arg, &free_on_close) )
return pl_error("open_memory_file", 4, NULL, ERR_TYPE,
arg, "boolean");
}
} else
return pl_error("open_memory_file", 4, NULL, ERR_TYPE, head, "option");
}
if ( !PL_get_nil(tail) )
return pl_error("open_memory_file", 4, NULL, ERR_TYPE, tail, "list");
}
if ( iom == ATOM_write )
{ x = "w";
if ( m->atom )
return pl_error("open_memory_file", 3, NULL, ERR_PERMISSION,
handle, "write", "memory_file");
if ( m->data )
{ Sfree(m->data);
m->data = NULL;
}
m->data_size = 0;
m->size = NOSIZE; /* don't know */
m->encoding = encoding;
} else if ( iom == ATOM_read )
{ x = "r";
m->free_on_close = free_on_close;
} else
{ return pl_error("open_memory_file", 3, NULL, ERR_DOMAIN,
mode, "io_mode");
}
if ( !(fd = Sopenmem(&m->data, &m->data_size, x)) )
return pl_error("open_memory_file", 3, NULL, ERR_ERRNO, errno,
"create", "memory_file", handle);
fd->close_hook = closehook;
fd->closure = m;
fd->encoding = encoding;
m->stream = fd;
return PL_unify_stream(stream, fd);
}
static foreign_t
open_memory_file(term_t handle, term_t mode, term_t stream)
{ return open_memory_file4(handle, mode, stream, 0);
}
static foreign_t
size_memory_file(term_t handle, term_t size)
{ memfile *m;
if ( get_memfile(handle, &m) )
{ if ( m->stream && !m->atom )
return alreadyOpen(handle, "size");
if ( m->data )
{ if ( m->size == NOSIZE )
{ switch( m->encoding )
{ case ENC_ISO_LATIN_1:
case ENC_OCTET:
m->size = m->data_size;
break;
case ENC_WCHAR:
m->size = m->data_size / sizeof(wchar_t);
break;
case ENC_UTF8:
m->size = PL_utf8_strlen(m->data, m->data_size);
break;
default:
assert(0);
return FALSE;
}
}
return PL_unify_integer(size, m->size);
} else
return PL_unify_integer(size, 0);
}
return FALSE;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
utf8_position_memory_file(+MF, -Here, -Size)
Given MF is a UTF-8 encoded memory file, unify here with the
byte-position of the read-pointer and Size with the total size of the
memory file in bytes. This is a bit hacky predicate, but the information
is easily available at low cost, while it is very valuable for producing
answers in content-length computation of the HTTP server. See
http_wrapper.pl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
static foreign_t
utf8_position(term_t handle, term_t here, term_t size)
{ memfile *m;
if ( !get_memfile(handle, &m) )
return FALSE;
if ( m->encoding != ENC_UTF8 )
return pl_error(NULL, 0, "no UTF-8 encoding",
ERR_PERMISSION, handle, "utf8_position", "memory_file");
if ( !PL_unify_integer(size, m->data_size) )
return FALSE;
if ( m->stream )
{ IOPOS *op = m->stream->position;
long p;
m->stream->position = NULL;
p = Stell(m->stream);
m->stream->position = op;
return PL_unify_integer(here, p);
} else
return PL_unify_integer(here, 0);
}
static foreign_t
atom_to_memory_file(term_t atom, term_t handle)
{ atom_t a;
if ( PL_get_atom(atom, &a) )
{ memfile *m = calloc(1, sizeof(*m));
if ( !m )
return pl_error(NULL, 0, NULL, ERR_ERRNO, errno, "create", "memory_file", handle);
m->atom = a;
PL_register_atom(m->atom);
m->magic = MEMFILE_MAGIC;
if ( (m->data = (char *)PL_atom_nchars(a, &m->size)) )
{ m->encoding = ENC_ISO_LATIN_1;
m->data_size = m->size;
} else if ( (m->data = (char *)PL_atom_wchars(a, &m->size)) )
{ m->encoding = ENC_WCHAR;
m->data_size = m->size * sizeof(wchar_t);
} else if ( PL_blob_data(a, &m->size, NULL) )
{ m->data = PL_blob_data(a, &m->data_size, NULL);
m->encoding = ENC_OCTET;
m->size = m->data_size;
}
if ( unify_memfile(handle, m) )
return TRUE;
else
{ PL_unregister_atom(m->atom);
m->magic = 0;
free(m);
return FALSE;
}
} else
{ return pl_error(NULL, 0, NULL, ERR_ARGTYPE, 1,
atom, "atom");
}
}
static foreign_t
memory_file_to_text(term_t handle, term_t atom, term_t encoding, int flags)
{ memfile *m;
if ( get_memfile(handle, &m) )
{ IOENC enc;
if ( encoding )
{ if ( !get_encoding(encoding, &enc) )
return FALSE;
} else
enc = m->encoding;
if ( m->stream )
return alreadyOpen(handle, "to_atom");
if ( m->data )
{ switch(enc)
{ case ENC_ISO_LATIN_1:
case ENC_OCTET:
return PL_unify_chars(atom, flags, m->data_size, m->data);
case ENC_WCHAR:
return PL_unify_wchars(atom, flags, m->data_size/sizeof(wchar_t), (pl_wchar_t*)m->data);
case ENC_UTF8:
return PL_unify_chars(atom, flags|REP_UTF8, m->data_size, m->data);
default:
assert(0);
}
} else
return PL_unify_chars(atom, flags, 0, "");
}
return FALSE;
}
static foreign_t
memory_file_to_atom2(term_t handle, term_t atom)
{ return memory_file_to_text(handle, atom, 0, PL_ATOM);
}
static foreign_t
memory_file_to_atom3(term_t handle, term_t atom, term_t encoding)
{ return memory_file_to_text(handle, atom, encoding, PL_ATOM);
}
static foreign_t
memory_file_to_codes2(term_t handle, term_t atom)
{ return memory_file_to_text(handle, atom, 0, PL_CODE_LIST);
}
static foreign_t
memory_file_to_codes3(term_t handle, term_t atom, term_t encoding)
{ return memory_file_to_text(handle, atom, encoding, PL_CODE_LIST);
}
#define MKATOM(n) ATOM_ ## n = PL_new_atom(#n);
install_t
install_memfile()
{ if ( PL_query(PL_QUERY_VERSION) <= 50505 )
{ PL_warning("Requires SWI-Prolog version 5.5.6 or later");
return;
}
FUNCTOR_memory_file1 = PL_new_functor(PL_new_atom("$memory_file"), 1);
MKATOM(encoding);
MKATOM(unknown);
MKATOM(octet);
MKATOM(ascii);
MKATOM(iso_latin_1);
MKATOM(text);
MKATOM(utf8);
MKATOM(unicode_be);
MKATOM(unicode_le);
MKATOM(wchar_t);
MKATOM(read);
MKATOM(write);
MKATOM(free_on_close);
PL_register_foreign("new_memory_file", 1, new_memory_file, 0);
PL_register_foreign("free_memory_file", 1, free_memory_file, 0);
PL_register_foreign("size_memory_file", 2, size_memory_file, 0);
PL_register_foreign("open_memory_file", 3, open_memory_file, 0);
PL_register_foreign("open_memory_file", 4, open_memory_file4, 0);
PL_register_foreign("atom_to_memory_file", 2, atom_to_memory_file, 0);
PL_register_foreign("memory_file_to_atom", 2, memory_file_to_atom2, 0);
PL_register_foreign("memory_file_to_codes", 2, memory_file_to_codes2,0);
PL_register_foreign("memory_file_to_atom", 3, memory_file_to_atom3, 0);
PL_register_foreign("memory_file_to_codes", 3, memory_file_to_codes3,0);
PL_register_foreign("utf8_position_memory_file", 3, utf8_position, 0);
}

View File

@ -33,6 +33,7 @@
[ new_memory_file/1, % -Handle [ new_memory_file/1, % -Handle
free_memory_file/1, % +Handle free_memory_file/1, % +Handle
size_memory_file/2, % +Handle, -Size size_memory_file/2, % +Handle, -Size
size_memory_file/3, % +Handle, -Size, +Encoding
open_memory_file/3, % +Handle, +Mode, -Stream open_memory_file/3, % +Handle, +Mode, -Stream
open_memory_file/4, % +Handle, +Mode, -Stream, +Options open_memory_file/4, % +Handle, +Mode, -Stream, +Options
atom_to_memory_file/2, % +Atom, -Handle atom_to_memory_file/2, % +Atom, -Handle
@ -42,9 +43,4 @@
memory_file_to_codes/3, % +Handle, -CodeList, +Encoding memory_file_to_codes/3, % +Handle, -CodeList, +Encoding
utf8_position_memory_file/3 % +Handle, -Here, -Size utf8_position_memory_file/3 % +Handle, -Here, -Size
]). ]).
:- expects_dialect(swi).
:- use_module(library(shlib)).
:- use_foreign_library(foreign(memfile)). :- use_foreign_library(foreign(memfile)).

View File

@ -86,8 +86,8 @@ static functor_t FUNCTOR_filename1;
struct dbuf struct dbuf
{ char *buf; { char *buf;
int size; size_t size;
int allocated; size_t allocated;
}; };
static int static int

95
packages/clib/nonblockio.c Executable file → Normal file
View File

@ -127,6 +127,13 @@ leave the details to this function.
#include <malloc.h> #include <malloc.h>
#endif #endif
#ifdef __WINDOWS__
#define GET_ERRNO WSAGetLastError()
#define GET_H_ERRNO WSAGetLastError()
#else
#define GET_ERRNO errno
#define GET_H_ERRNO h_errno
#endif
#ifndef __WINDOWS__ #ifndef __WINDOWS__
#define closesocket(n) close((n)) /* same on Unix */ #define closesocket(n) close((n)) /* same on Unix */
@ -823,21 +830,13 @@ socket_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
for(i=0; i<n; i++) for(i=0; i<n; i++)
{ if ( s[i] ) { if ( s[i] )
{ { __try
#if __MINGW32__
{ if ( s[i]->magic != PLSOCK_MAGIC )
{ goto nosocket;
}
}
#else
__try
{ if ( s[i]->magic != PLSOCK_MAGIC ) { if ( s[i]->magic != PLSOCK_MAGIC )
{ goto nosocket; { goto nosocket;
} }
} __except(EXCEPTION_EXECUTE_HANDLER) } __except(EXCEPTION_EXECUTE_HANDLER)
{ goto nosocket; { goto nosocket;
} }
#endif
doRequest(s[i]); doRequest(s[i]);
} }
@ -1088,7 +1087,7 @@ nbio_fcntl(nbio_sock_t socket, int op, int arg)
{ if ( op == F_SETFL && arg == O_NONBLOCK ) { if ( op == F_SETFL && arg == O_NONBLOCK )
s->flags |= PLSOCK_NONBLOCK; s->flags |= PLSOCK_NONBLOCK;
} else } else
nbio_error(errno, TCP_ERRNO); nbio_error(GET_ERRNO, TCP_ERRNO);
return rc; return rc;
} }
@ -1333,13 +1332,13 @@ freeSocket(plsocket *s)
*******************************/ *******************************/
#ifdef __WINDOWS__ #ifdef __WINDOWS__
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The code in BILLY_GETS_BETTER is, according to various documents the The code in BILLY_GETS_BETTER is, according to various documents the
right code, but it doesn't work, so we do it by hand. right code, but it doesn't work, so we do it by hand.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#ifdef BILLY_GETS_BETTER #ifdef BILLY_GETS_BETTER
static const char * static const char *
WinSockError(unsigned long eno) WinSockError(unsigned long eno)
{ char buf[1024]; { char buf[1024];
@ -1421,10 +1420,10 @@ WinSockError(unsigned long error)
{ WSANOTINITIALISED, "Socket layer not initialised" }, { WSANOTINITIALISED, "Socket layer not initialised" },
/* WinSock 2 errors */ /* WinSock 2 errors */
{ WSAHOST_NOT_FOUND, "Host not found" }, { WSAHOST_NOT_FOUND, "Host not found" },
{ WSANO_DATA, "Valid name, no data record of requested type" },
{ 0, NULL } { 0, NULL }
}; };
char tmp[100]; char tmp[100];
for(ep=edefs; ep->string; ep++) for(ep=edefs; ep->string; ep++)
{ if ( ep->index == (int)error ) { if ( ep->index == (int)error )
return ep->string; return ep->string;
@ -1475,7 +1474,6 @@ nbio_error(int code, nbio_error_map mapid)
if ( code == EPLEXCEPTION ) if ( code == EPLEXCEPTION )
return FALSE; return FALSE;
switch( mapid ) switch( mapid )
{ case TCP_HERRNO: { case TCP_HERRNO:
map = h_errno_codes; map = h_errno_codes;
@ -1483,7 +1481,6 @@ nbio_error(int code, nbio_error_map mapid)
default: default:
map = NULL; map = NULL;
} }
{ {
#ifdef __WINDOWS__ #ifdef __WINDOWS__
msg = WinSockError(code); msg = WinSockError(code);
@ -1609,7 +1606,7 @@ nbio_socket(int domain, int type, int protocol)
assert(initialised); assert(initialised);
if ( (sock = socket(domain, type , protocol)) < 0) if ( (sock = socket(domain, type , protocol)) < 0)
{ nbio_error(errno, TCP_ERRNO); { nbio_error(GET_ERRNO, TCP_ERRNO);
return -1; return -1;
} }
if ( !(s=allocSocket(sock)) ) /* register it */ if ( !(s=allocSocket(sock)) ) /* register it */
@ -1647,15 +1644,7 @@ nbio_closesocket(nbio_sock_t socket)
Sclose(s->output); Sclose(s->output);
} }
} else } else
{ { freeSocket(s);
#ifdef __WINDOWS__
if ( true(s, PLSOCK_CONNECT) )
{ if ( s->socket >= 0 )
shutdown(s->socket, SD_SEND);
}
#endif
freeSocket(s);
} }
return 0; return 0;
@ -1681,7 +1670,7 @@ nbio_setopt(nbio_sock_t socket, nbio_option opt, ...)
if( setsockopt(s->socket, SOL_SOCKET, SO_REUSEADDR, if( setsockopt(s->socket, SOL_SOCKET, SO_REUSEADDR,
(const char *)&val, sizeof(val)) == -1 ) (const char *)&val, sizeof(val)) == -1 )
{ nbio_error(h_errno, TCP_HERRNO); { nbio_error(GET_H_ERRNO, TCP_HERRNO);
rc = -1; rc = -1;
} else } else
rc = 0; rc = 0;
@ -1697,7 +1686,7 @@ nbio_setopt(nbio_sock_t socket, nbio_option opt, ...)
#endif #endif
if ( setsockopt(s->socket, IPPROTO_TCP, TCP_NODELAY, if ( setsockopt(s->socket, IPPROTO_TCP, TCP_NODELAY,
(const char *)&val, sizeof(val)) == -1 ) (const char *)&val, sizeof(val)) == -1 )
{ nbio_error(h_errno, TCP_HERRNO); { nbio_error(GET_H_ERRNO, TCP_HERRNO);
rc = -1; rc = -1;
} else } else
{ rc = 0; { rc = 0;
@ -1713,7 +1702,7 @@ nbio_setopt(nbio_sock_t socket, nbio_option opt, ...)
if ( setsockopt(s->socket, SOL_SOCKET, SO_BROADCAST, if ( setsockopt(s->socket, SOL_SOCKET, SO_BROADCAST,
(const char *)&val, sizeof(val)) == -1 ) (const char *)&val, sizeof(val)) == -1 )
{ nbio_error(h_errno, TCP_HERRNO); { nbio_error(GET_H_ERRNO, TCP_HERRNO);
rc = -1; rc = -1;
} else } else
rc = 0; rc = 0;
@ -1803,6 +1792,8 @@ nbio_get_port(term_t Port, int *port)
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Convert a term Host:Port to a socket address. Port is either an integer Convert a term Host:Port to a socket address. Port is either an integer
or the name of a registered port (e.g. 'smtp'). or the name of a registered port (e.g. 'smtp').
(*) TBD: Supply the port/service here too, simplifying the rest
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
int int
@ -1818,13 +1809,18 @@ nbio_get_sockaddr(term_t Address, struct sockaddr_in *addr)
_PL_get_arg(1, Address, arg); _PL_get_arg(1, Address, arg);
if ( PL_get_atom_chars(arg, &hostName) ) if ( PL_get_atom_chars(arg, &hostName) )
{ struct hostent *host; { struct addrinfo hints;
struct addrinfo *res;
if( !(host = gethostbyname(hostName)) ) memset(&hints, 0, sizeof(hints));
return nbio_error(h_errno, TCP_HERRNO); hints.ai_family = AF_INET;
if ( (int)sizeof(addr->sin_addr) < host->h_length ) if ( getaddrinfo(hostName, NULL, &hints, &res) != 0) /* see (*) */
return PL_warning("Oops, host address too long!"); return nbio_error(GET_H_ERRNO, TCP_HERRNO);
memcpy(&addr->sin_addr, host->h_addr, host->h_length); assert(res->ai_family == AF_INET);
memcpy(&addr->sin_addr,
&((struct sockaddr_in*)res->ai_addr)->sin_addr,
sizeof(addr->sin_addr));
freeaddrinfo(res);
} else if ( !nbio_get_ip(arg, &addr->sin_addr) ) } else if ( !nbio_get_ip(arg, &addr->sin_addr) )
{ return pl_error(NULL, 0, NULL, ERR_ARGTYPE, 1, arg, "atom|ip/4"); { return pl_error(NULL, 0, NULL, ERR_ARGTYPE, 1, arg, "atom|ip/4");
} }
@ -1908,7 +1904,8 @@ nbio_bind(nbio_sock_t socket, struct sockaddr *my_addr, size_t addrlen)
#else #else
if ( bind(s->socket, my_addr, addrlen) ) if ( bind(s->socket, my_addr, addrlen) )
#endif #endif
{ nbio_error(errno, TCP_ERRNO); {
nbio_error(GET_ERRNO, TCP_ERRNO);
return -1; return -1;
} }
@ -1946,12 +1943,12 @@ nbio_connect(nbio_sock_t socket,
#else /*!__WINDOWS__*/ #else /*!__WINDOWS__*/
for(;;) for(;;)
{ if ( connect(s->socket, serv_addr, addrlen) ) { if ( connect(s->socket, serv_addr, addrlen) )
{ if ( need_retry(errno) ) { if ( need_retry(GET_ERRNO) )
{ if ( PL_handle_signals() < 0 ) { if ( PL_handle_signals() < 0 )
return -1; return -1;
continue; continue;
} }
nbio_error(errno, TCP_ERRNO); nbio_error(GET_ERRNO, TCP_ERRNO);
return -1; return -1;
} else } else
break; break;
@ -2007,13 +2004,13 @@ nbio_accept(nbio_sock_t master, struct sockaddr *addr, socklen_t *addrlen)
slave = accept(m->socket, addr, addrlen); slave = accept(m->socket, addr, addrlen);
if ( slave == SOCKET_ERROR ) if ( slave == SOCKET_ERROR )
{ if ( need_retry(errno) ) { if ( need_retry(GET_ERRNO) )
{ if ( PL_handle_signals() < 0 ) { if ( PL_handle_signals() < 0 )
return -1; return -1;
continue; continue;
} else } else
{ nbio_error(errno, TCP_ERRNO); { nbio_error(GET_ERRNO, TCP_ERRNO);
return -1; return -1;
} }
} else } else
@ -2041,7 +2038,7 @@ nbio_listen(nbio_sock_t socket, int backlog)
return -1; return -1;
if( listen(s->socket, backlog) == -1 ) if( listen(s->socket, backlog) == -1 )
{ nbio_error(errno, TCP_ERRNO); { nbio_error(GET_ERRNO, TCP_ERRNO);
return -1; return -1;
} }
@ -2103,7 +2100,7 @@ nbio_read(int socket, char *buf, size_t bufSize)
n = recv(s->socket, buf, bufSize, 0); n = recv(s->socket, buf, bufSize, 0);
if ( n == -1 && need_retry(errno) ) if ( n == -1 && need_retry(GET_ERRNO) )
{ if ( PL_handle_signals() < 0 ) { if ( PL_handle_signals() < 0 )
{ errno = EPLEXCEPTION; { errno = EPLEXCEPTION;
return -1; return -1;
@ -2175,7 +2172,7 @@ nbio_write(nbio_sock_t socket, char *buf, size_t bufSize)
n = send(s->socket, str, len, 0); n = send(s->socket, str, len, 0);
if ( n < 0 ) if ( n < 0 )
{ if ( need_retry(errno) ) { if ( need_retry(GET_ERRNO) )
{ if ( PL_handle_signals() < 0 ) { if ( PL_handle_signals() < 0 )
{ errno = EPLEXCEPTION; { errno = EPLEXCEPTION;
return -1; return -1;
@ -2213,12 +2210,6 @@ nbio_close_input(nbio_sock_t socket)
if ( (sock=s->socket) < 0 ) if ( (sock=s->socket) < 0 )
{ s->error = WSAECONNRESET; { s->error = WSAECONNRESET;
rc = -1; rc = -1;
} else if ( shutdown(sock, SD_RECEIVE) == SOCKET_ERROR )
{ DEBUG(1, Sdprintf("shutdown(%d=%d, SD_RECEIVE) failed: %s\n",
socket, s->socket,
WinSockError(WSAGetLastError())));
Sseterr(s->input, SIO_FERR, WinSockError(WSAGetLastError()));
rc = -1;
} }
} }
#endif #endif
@ -2252,14 +2243,6 @@ nbio_close_output(nbio_sock_t socket)
if ( (sock=s->socket) < 0 ) if ( (sock=s->socket) < 0 )
{ s->error = WSAECONNRESET; { s->error = WSAECONNRESET;
rc = -1; rc = -1;
} else if ( shutdown(sock, SD_SEND) == SOCKET_ERROR )
{ const char *msg;
msg = WinSockError(WSAGetLastError());
Sseterr(s->output, SIO_FERR, msg);
DEBUG(1, Sdprintf("shutdown(%d=%d, SD_SEND) failed: %s\n",
socket, s->socket, msg));
rc = -1;
} }
#endif #endif
} }
@ -2330,7 +2313,7 @@ nbio_recvfrom(int socket, void *buf, size_t bufSize, int flags,
n = recvfrom(s->socket, buf, bufSize, flags, from, fromlen); n = recvfrom(s->socket, buf, bufSize, flags, from, fromlen);
if ( n == -1 && need_retry(errno) ) if ( n == -1 && need_retry(GET_ERRNO) )
{ if ( PL_handle_signals() < 0 ) { if ( PL_handle_signals() < 0 )
{ errno = EPLEXCEPTION; { errno = EPLEXCEPTION;
return -1; return -1;

View File

@ -48,7 +48,7 @@
#include <io.h> #include <io.h>
#include <winsock2.h> #include <winsock2.h>
typedef size_t socklen_t; #include <ws2tcpip.h>
#else /*__WINDOWS__*/ #else /*__WINDOWS__*/

108
packages/clib/process.c Executable file → Normal file
View File

@ -79,6 +79,22 @@ static functor_t FUNCTOR_eq2; /* =/2 */
#define DEBUG(g) (void)0 #define DEBUG(g) (void)0
#endif #endif
#ifdef __WINDOWS__
#include <windows.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
typedef DWORD pid_t;
typedef wchar_t echar; /* environment character */
#ifndef CREATE_BREAKAWAY_FROM_JOB
#define CREATE_BREAKAWAY_FROM_JOB 0x1000000
#endif
#else
typedef char echar;
#endif
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ISSUES: ISSUES:
- Deal with child errors (no cwd, cannot execute, etc.) - Deal with child errors (no cwd, cannot execute, etc.)
@ -145,19 +161,6 @@ resource_error(const char *resource)
* ADMIN * * ADMIN *
*******************************/ *******************************/
#ifdef __WINDOWS__
#include <windows.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#ifndef __MINGW32__
typedef DWORD pid_t;
#endif
typedef wchar_t echar; /* environment character */
#else
typedef char echar;
#endif
typedef enum std_type typedef enum std_type
{ std_std, { std_std,
std_null, std_null,
@ -653,57 +656,7 @@ win_init()
} }
static atom_t #include "win_error.c"
WinError()
{ int id = GetLastError();
char *msg;
static WORD lang;
static lang_initialised = 0;
if ( !lang_initialised )
lang = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK);
again:
if ( FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
FORMAT_MESSAGE_IGNORE_INSERTS|
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, /* source */
id, /* identifier */
lang,
(LPTSTR) &msg,
0, /* size */
NULL) ) /* arguments */
{ atom_t a = PL_new_atom(msg);
LocalFree(msg);
lang_initialised = 1;
return a;
} else
{ if ( lang_initialised == 0 )
{ lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
lang_initialised = 1;
goto again;
}
return PL_new_atom("Unknown Windows error");
}
}
static int
win_error(const char *op)
{ atom_t msg = WinError();
term_t ex = PL_new_term_ref();
PL_unify_term(ex, PL_FUNCTOR, FUNCTOR_error2,
PL_FUNCTOR, FUNCTOR_system_error2,
PL_CHARS, op,
PL_ATOM, msg,
PL_VARIABLE);
return PL_raise_exception(ex);
}
typedef struct arg_string typedef struct arg_string
@ -1073,6 +1026,9 @@ do_create_process(p_options *info)
break; break;
} }
if ( info->detached )
flags |= CREATE_BREAKAWAY_FROM_JOB;
memset(&si, 0, sizeof(si)); memset(&si, 0, sizeof(si));
si.cb = sizeof(si); si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES; si.dwFlags = STARTF_USESTDHANDLES;
@ -1318,13 +1274,16 @@ wait_success(atom_t name, pid_t pid)
} }
#ifndef HAVE_VFORK
#define vfork fork
#endif
static int static int
do_create_process(p_options *info) do_create_process(p_options *info)
{ int pid; { int pid;
if ( !(pid=fork()) ) /* child */ if ( !(pid=vfork()) ) /* child */
{ int fd; { int fd;
int rc;
PL_cleanup_fork(); PL_cleanup_fork();
@ -1379,21 +1338,18 @@ do_create_process(p_options *info)
} }
if ( info->envp ) if ( info->envp )
rc = execve(info->exe, info->argv, info->envp); execve(info->exe, info->argv, info->envp);
else else
rc = execv(info->exe, info->argv); execv(info->exe, info->argv);
if ( rc ) perror(info->exe);
{ perror(info->exe);
exit(1); exit(1);
} } else if ( pid < 0 ) /* parent */
{ term_t exe = PL_new_term_ref(); { term_t exe = PL_new_term_ref();
PL_put_atom_chars(exe, info->exe); PL_put_atom_chars(exe, info->exe);
return pl_error(NULL, 0, "execv", ERR_ERRNO, errno, "exec", "process", exe); return pl_error(NULL, 0, "fork", ERR_ERRNO, errno, "fork", "process", exe);
} } else
} else /* parent */
{ if ( info->pipes > 0 && info->pid == 0 ) { if ( info->pipes > 0 && info->pid == 0 )
{ IOSTREAM *s; { IOSTREAM *s;
process_context *pc = PL_malloc(sizeof(*pc)); process_context *pc = PL_malloc(sizeof(*pc));
@ -1462,7 +1418,7 @@ Basic process creation interface takes
* List of arguments * List of arguments
* standard streams % std, null, pipe(S) * standard streams % std, null, pipe(S)
* Working directory * Working directory
* detached % Unix * detached
* window % Windows * window % Windows
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

View File

@ -43,9 +43,6 @@
:- use_module(library(shlib)). :- use_module(library(shlib)).
:- use_module(library(lists)). :- use_module(library(lists)).
:- use_module(library(option)). :- use_module(library(option)).
:- use_module(library(error)).
:- use_module(library(maplist)).
:- use_foreign_library(foreign(process)). :- use_foreign_library(foreign(process)).
@ -154,8 +151,15 @@ user:file_search_path(path, Dir) :-
% * process(-PID) % * process(-PID)
% Unify PID with the process id of the created process. % Unify PID with the process id of the created process.
% * detached(+Bool) % * detached(+Bool)
% If =true=, detach the process from the terminal (Unix only) % In Unix: If =true=, detach the process from the terminal
% Currently mapped to setsid(); % Currently mapped to setsid();
% In Windows: If =true=, detach the process from the current
% job via the CREATE_BREAKAWAY_FROM_JOB flag. In Vista and beyond,
% processes launched from the shell directly have the 'compatibility
% assistant' attached to them automatically unless they have a UAC
% manifest embedded in them. This means that you will get a
% permission denied error if you try and assign the newly-created
% PID to a job you create yourself.
% * window(+Bool) % * window(+Bool)
% If =true=, create a window for the process (Windows only) % If =true=, create a window for the process (Windows only)
% %

View File

@ -39,7 +39,7 @@
/* Include files where endian defines and byteswap functions may reside */ /* Include files where endian defines and byteswap functions may reside */
#if defined(__sun__) #if defined(__sun__)
# include <sys/isa_defs.h> # include <sys/isa_defs.h>
#elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ ) || defined( __DragonFly__ ) #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ )
# include <sys/endian.h> # include <sys/endian.h>
#elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \ #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \
defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ ) defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ )

View File

@ -224,10 +224,10 @@ pl_hmac_sha(term_t key, term_t data, term_t mac, term_t options)
unsigned char digest[SHA2_MAX_DIGEST_SIZE]; unsigned char digest[SHA2_MAX_DIGEST_SIZE];
if ( !PL_get_nchars(key, &keylen, &skey, if ( !PL_get_nchars(key, &keylen, &skey,
CVT_ATOM|CVT_STRING|CVT_LIST|CVT_EXCEPTION|BUF_RING) ) CVT_ATOM|CVT_STRING|CVT_LIST|CVT_EXCEPTION) )
return FALSE; return FALSE;
if ( !PL_get_nchars(data, &datalen, &sdata, if ( !PL_get_nchars(data, &datalen, &sdata,
CVT_ATOM|CVT_STRING|CVT_LIST|CVT_EXCEPTION|BUF_RING) ) CVT_ATOM|CVT_STRING|CVT_LIST|CVT_EXCEPTION) )
return FALSE; return FALSE;
if ( !sha_options(options, &opts) ) if ( !sha_options(options, &opts) )

View File

@ -1,271 +0,0 @@
/* $Id$
Part of SWI-Prolog
Author: Jan Wielemaker
E-mail: J.Wielemaker@cs.vu.nl
WWW: http://www.swi-prolog.org
Copyright (C): 1985-2009, University of Amsterdam
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#define _ISOC99_SOURCE
#define USE_SHA256 1
#include <SWI-Prolog.h>
#include "error.h"
#include "sha1/sha1.h"
#include "sha1/sha2.h"
#include "sha1/hmac.h"
#include <assert.h>
static atom_t ATOM_sha1;
static atom_t ATOM_sha224;
static atom_t ATOM_sha256;
static atom_t ATOM_sha384;
static atom_t ATOM_sha512;
static atom_t ATOM_algorithm;
typedef enum
{ ALGORITHM_SHA1,
ALGORITHM_SHA224,
ALGORITHM_SHA256,
ALGORITHM_SHA384,
ALGORITHM_SHA512
} sha_algorithm;
typedef struct
{ sha_algorithm algorithm;
size_t digest_size;
term_t algorithm_term;
} optval;
#define CONTEXT_MAGIC (~ 0x53484163L)
struct context
{ int magic;
optval opts;
union {
sha1_ctx sha1;
sha2_ctx sha2;
} context;
};
static int
sha_options(term_t options, optval *result)
{ term_t opts = PL_copy_term_ref(options);
term_t opt = PL_new_term_ref();
/* defaults */
memset(result, 0, sizeof(*result));
result->algorithm = ALGORITHM_SHA1;
result->digest_size = SHA1_DIGEST_SIZE;
while(PL_get_list(opts, opt, opts))
{ atom_t aname;
int arity;
if ( PL_get_name_arity(opt, &aname, &arity) && arity == 1 )
{ term_t a = PL_new_term_ref();
_PL_get_arg(1, opt, a);
if ( aname == ATOM_algorithm )
{ atom_t a_algorithm;
result->algorithm_term = a;
if ( !PL_get_atom(a, &a_algorithm) )
return pl_error(NULL, 0, NULL, ERR_TYPE, a, "algorithm");
if ( a_algorithm == ATOM_sha1 )
{ result->algorithm = ALGORITHM_SHA1;
result->digest_size = SHA1_DIGEST_SIZE;
} else if ( a_algorithm == ATOM_sha224 )
{ result->algorithm = ALGORITHM_SHA224;
result->digest_size = SHA224_DIGEST_SIZE;
} else if ( a_algorithm == ATOM_sha256 )
{ result->algorithm = ALGORITHM_SHA256;
result->digest_size = SHA256_DIGEST_SIZE;
} else if ( a_algorithm == ATOM_sha384 )
{ result->algorithm = ALGORITHM_SHA384;
result->digest_size = SHA384_DIGEST_SIZE;
} else if ( a_algorithm == ATOM_sha512 )
{ result->algorithm = ALGORITHM_SHA512;
result->digest_size = SHA512_DIGEST_SIZE;
} else
return pl_error(NULL, 0, NULL, ERR_DOMAIN, a, "algorithm");
}
} else
{ return pl_error(NULL, 0, NULL, ERR_TYPE, opt, "option");
}
}
if ( !PL_get_nil(opts) )
return pl_error("sha_hash", 1, NULL, ERR_TYPE, opts, "list");
return TRUE;
}
static foreign_t
pl_sha_hash(term_t from, term_t hash, term_t options)
{ char *data;
size_t datalen;
optval opts;
unsigned char hval[SHA2_MAX_DIGEST_SIZE];
if ( !sha_options(options, &opts) )
return FALSE;
if ( !PL_get_nchars(from, &datalen, &data,
CVT_ATOM|CVT_STRING|CVT_LIST|CVT_EXCEPTION) )
return FALSE;
if ( opts.algorithm == ALGORITHM_SHA1 )
{ sha1((unsigned char*)hval,
(unsigned char*)data, (unsigned long)datalen);
} else
{ sha2((unsigned char*)hval, (unsigned long) opts.digest_size,
(unsigned char*)data, (unsigned long)datalen);
}
return PL_unify_list_ncodes(hash, opts.digest_size, (char*)hval);
}
static foreign_t
pl_sha_new_ctx(term_t ctx, term_t options)
{ struct context c;
optval *op = &(c.opts);
if ( !sha_options(options, op) )
return FALSE;
c.magic = CONTEXT_MAGIC;
if ( op->algorithm == ALGORITHM_SHA1 )
{ sha1_begin(&(c.context.sha1));
} else
{ sha2_begin((unsigned long) op->digest_size, &(c.context.sha2));
}
/* NB: the context size depends on the digest size */
/* (e. g., sha512_ctx is twice as long as sha256_ctx) */
/* so there're extra data. It will do no harm, though. */
/* . */
return PL_unify_string_nchars(ctx, sizeof(c), (char*)&c);
}
static foreign_t
pl_sha_hash_ctx(term_t old_ctx, term_t from, term_t new_ctx, term_t hash)
{ char *data;
size_t datalen;
struct context *cp;
size_t clen;
unsigned char hval[SHA2_MAX_DIGEST_SIZE];
if ( !PL_get_nchars(from, &datalen, &data,
CVT_ATOM|CVT_STRING|CVT_LIST|CVT_EXCEPTION) )
return FALSE;
if ( !PL_get_string_chars(old_ctx, (char **)&cp, &clen) )
return FALSE;
if ( clen != sizeof (*cp)
|| cp->magic != CONTEXT_MAGIC ) {
return pl_error(NULL, 0, "Invalid OldContext passed",
ERR_DOMAIN, old_ctx, "algorithm");
}
if ( cp->opts.algorithm == ALGORITHM_SHA1 )
{ sha1_ctx *c1p = &(cp->context.sha1);
sha1_hash((unsigned char*)data, (unsigned long)datalen, c1p);
if ( !PL_unify_string_nchars(new_ctx, sizeof(*cp), (char*)cp) )
return FALSE;
sha1_end((unsigned char *)hval, c1p);
} else
{ sha2_ctx *c1p = &(cp->context.sha2);
sha2_hash((unsigned char*)data, (unsigned long)datalen, c1p);
if ( !PL_unify_string_nchars(new_ctx, sizeof(*cp), (char*)cp) )
return FALSE;
sha2_end((unsigned char *)hval, c1p);
}
/* . */
return PL_unify_list_ncodes(hash, cp->opts.digest_size, (char*)hval);
}
static foreign_t
pl_hmac_sha(term_t key, term_t data, term_t mac, term_t options)
{ char *sdata, *skey;
size_t datalen, keylen;
optval opts;
unsigned char digest[SHA2_MAX_DIGEST_SIZE];
if ( !PL_get_nchars(key, &keylen, &skey,
CVT_ATOM|CVT_STRING|CVT_LIST|CVT_EXCEPTION) )
return FALSE;
if ( !PL_get_nchars(data, &datalen, &sdata,
CVT_ATOM|CVT_STRING|CVT_LIST|CVT_EXCEPTION) )
return FALSE;
if ( !sha_options(options, &opts) )
return FALSE;
switch(opts.algorithm)
{ case ALGORITHM_SHA1:
hmac_sha1((unsigned char*)skey, (unsigned long)keylen,
(unsigned char*)sdata, (unsigned long)datalen,
digest, (unsigned long)opts.digest_size);
break;
case ALGORITHM_SHA256:
hmac_sha256((unsigned char*)skey, (unsigned long)keylen,
(unsigned char*)sdata, (unsigned long)datalen,
digest, (unsigned long)opts.digest_size);
break;
default:
return pl_error(NULL, 0, "HMAC-SHA only for SHA-1 and SHA-256",
ERR_DOMAIN, opts.algorithm_term, "algorithm");
}
return PL_unify_list_ncodes(mac, opts.digest_size, (char*)digest);
}
#define MKATOM(n) ATOM_ ## n = PL_new_atom(#n);
install_t
install_sha4pl()
{ MKATOM(sha1); /* =160 */
MKATOM(sha224);
MKATOM(sha256);
MKATOM(sha384);
MKATOM(sha512);
MKATOM(algorithm);
PL_register_foreign("sha_hash", 3, pl_sha_hash, 0);
PL_register_foreign("sha_new_ctx", 2, pl_sha_new_ctx, 0);
PL_register_foreign("sha_hash_ctx", 4, pl_sha_hash_ctx, 0);
PL_register_foreign("hmac_sha", 4, pl_hmac_sha, 0);
}

View File

@ -109,20 +109,43 @@ tcp_unify_socket(term_t Socket, int id)
static foreign_t static foreign_t
pl_host_to_address(term_t Host, term_t Ip) pl_host_to_address(term_t Host, term_t Ip)
{ struct in_addr ip; { struct in_addr ip;
struct hostent *host;
char *host_name; char *host_name;
if ( PL_get_atom_chars(Host, &host_name) ) if ( PL_get_atom_chars(Host, &host_name) )
{ if ( (host = gethostbyname(host_name)) ) { struct addrinfo hints;
{ if ( sizeof(ip) == host->h_length ) struct addrinfo *res;
{ memcpy(&ip, host->h_addr, host->h_length);
return nbio_unify_ip4(Ip, ntohl(ip.s_addr)); memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
if ( getaddrinfo(host_name, NULL, &hints, &res) == 0 )
{ int rc;
switch( res->ai_family )
{ case AF_INET:
{ struct sockaddr_in *addr = (struct sockaddr_in*)res->ai_addr;
rc = nbio_unify_ip4(Ip, ntohl(addr->sin_addr.s_addr));
break;
}
case AF_INET6:
{ rc = PL_warning("tcp_host_to_address/2: IPv6 address not supported");
break;
}
default:
assert(0);
}
freeaddrinfo(res);
return rc;
} else } else
return PL_warning("tcp_host_to_address/2: length mismatch in address"); { return nbio_error(h_errno, TCP_HERRNO);
} else }
return nbio_error(h_errno, TCP_HERRNO);
} else if ( nbio_get_ip(Ip, &ip) ) } else if ( nbio_get_ip(Ip, &ip) )
{ if ( (host = gethostbyaddr((char *)&ip, sizeof(ip), AF_INET)) ) { struct hostent *host;
if ( (host = gethostbyaddr((char *)&ip, sizeof(ip), AF_INET)) )
return PL_unify_atom_chars(Host, host->h_name); return PL_unify_atom_chars(Host, host->h_name);
else else
return nbio_error(h_errno, TCP_HERRNO); return nbio_error(h_errno, TCP_HERRNO);
@ -278,6 +301,7 @@ udp_receive(term_t Socket, term_t Data, term_t From, term_t options)
if ( (n=nbio_recvfrom(socket, buf, sizeof(buf), flags, if ( (n=nbio_recvfrom(socket, buf, sizeof(buf), flags,
(struct sockaddr*)&sockaddr, &alen)) == -1 ) (struct sockaddr*)&sockaddr, &alen)) == -1 )
return nbio_error(errno, TCP_ERRNO); return nbio_error(errno, TCP_ERRNO);
if ( !PL_unify_chars(Data, as, n, buf) ) if ( !PL_unify_chars(Data, as, n, buf) )
return FALSE; return FALSE;
@ -412,7 +436,6 @@ pl_accept(term_t Master, term_t Slave, term_t Peer)
} }
static foreign_t static foreign_t
pl_gethostname(term_t name) pl_gethostname(term_t name)
{ static atom_t hname; { static atom_t hname;
@ -421,12 +444,18 @@ pl_gethostname(term_t name)
{ char buf[256]; { char buf[256];
if ( gethostname(buf, sizeof(buf)) == 0 ) if ( gethostname(buf, sizeof(buf)) == 0 )
{ struct hostent *he; { struct addrinfo *res;
struct addrinfo hints;
if ( (he = gethostbyname(buf)) ) memset(&hints, 0, sizeof(hints));
hname = PL_new_atom(he->h_name); hints.ai_flags = AI_CANONNAME;
if ( getaddrinfo(buf, NULL, &hints, &res) == 0 )
hname = PL_new_atom(res->ai_canonname);
else else
hname = PL_new_atom(buf); hname = PL_new_atom(buf);
freeaddrinfo(res);
} else } else
{ return nbio_error(h_errno, TCP_HERRNO); { return nbio_error(h_errno, TCP_HERRNO);
} }

View File

@ -36,7 +36,7 @@
dispatch_stream_pool/1, % +TimeOut dispatch_stream_pool/1, % +TimeOut
stream_pool_main_loop/0 stream_pool_main_loop/0
]). ]).
%:- use_module(library(quintus)). :- use_module(library(quintus)).
:- meta_predicate :- meta_predicate
add_stream_to_pool(+, :). add_stream_to_pool(+, :).

View File

@ -1,120 +0,0 @@
/* $Id$
Part of SWI-Prolog
Author: Jan Wielemaker
E-mail: jan@swi.psy.uva.nl
WWW: http://www.swi-prolog.org
Copyright (C): 1985-2002, University of Amsterdam
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
As a special exception, if you link this library with other files,
compiled with a Free Software compiler, to produce an executable, this
library does not by itself cause the resulting executable to be covered
by the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.
*/
:- module(stream_pool,
[ add_stream_to_pool/2, % +Stream, :Goal
delete_stream_from_pool/1, % +Stream
close_stream_pool/0,
dispatch_stream_pool/1, % +TimeOut
stream_pool_main_loop/0
]).
:- use_module(library(quintus)).
:- meta_predicate
add_stream_to_pool(+, :).
:- volatile
pool/2. % sockets don't survive a saved-state
:- dynamic
pool/2. % Stream, Action
% add_stream_to_pool(+Stream :Goal)
%
% Call Goal whenever there is input on Stream.
add_stream_to_pool(Stream, Action) :-
strip_module(Action, Module, Plain),
register_stream(Stream, Module:Plain).
register_stream(Stream, Goal) :-
assert(pool(Stream, Goal)).
% delete_stream_from_pool(+Stream)
%
% Retract stream from the pool
delete_stream_from_pool(Stream) :-
retractall(pool(Stream, _)).
% close_stream_pool
close_stream_pool :-
( retract(pool(Stream, _)),
close(Stream, [force(true)]),
fail
; true
).
% dispatch_stream_pool(+TimeOut)
%
% Wait for input on one or more streams and handle that. Wait for
% at most TimeOut seconds (0 means infinite).
dispatch_stream_pool(Timeout) :-
findall(S, pool(S, _), Pool),
catch(wait_for_input(Pool, Ready, Timeout), E, true),
debug(tcp, 'Select ~w --> ~w (E=~w)', [Pool, Ready, E]),
( var(E)
-> actions(Ready)
; E = error(existence_error(stream, Stream), _)
-> delete_stream_from_pool(Stream)
).
actions([]).
actions([H|T]) :-
action(H),
actions(T).
action(Stream) :-
pool(Stream, Action),
( catch(Action, E, true)
-> ( var(E)
-> true
; print_message(error, E)
)
; print_message(warning,
goal_failed(Action, stream_pool))
).
% stream_pool_main_loop
%
% Keep handling input from the streams in the pool until they have
% all died away.
stream_pool_main_loop :-
pool(_, _), !,
( current_prolog_flag(windows, true)
-> dispatch_stream_pool(1) % so we can break out easily
; dispatch_stream_pool(0)
),
stream_pool_main_loop.
stream_pool_main_loop.

View File

@ -122,8 +122,6 @@ test(sha512, [true(Atom='cf83e135 7eefb8bd f1542850 d66d8007 d620e405 0b5715dc 8
:- begin_tests(rfc2202, [condition(current_prolog_flag(bounded, false))]). :- begin_tests(rfc2202, [condition(current_prolog_flag(bounded, false))]).
:- use_module(library(sha)).
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HMAC SHA-1 from http://www.ipa.go.jp/security/rfc/RFC2202EN.html HMAC SHA-1 from http://www.ipa.go.jp/security/rfc/RFC2202EN.html
HMAC SHA-2 from http://www.faqs.org/rfcs/rfc4231.html HMAC SHA-2 from http://www.faqs.org/rfcs/rfc4231.html

View File

@ -121,6 +121,15 @@ encoding(enc-1) :- % Encode to UTF-8
close(In), close(In),
free_memory_file(MF), free_memory_file(MF),
phrase(utf8_codes(String), Codes). phrase(utf8_codes(String), Codes).
encoding(enc-2) :-
String = [97, 254, 500],
new_memory_file(MF),
open_memory_file(MF, write, Out, [encoding(utf8)]),
format(Out, '~s', [String]),
close(Out),
size_memory_file(MF, Size, octet),
phrase(utf8_codes(String), Codes),
length(Codes, Size).
/******************************* /*******************************

View File

@ -62,8 +62,8 @@ test(cwd, [true, condition(\+current_prolog_flag(windows, true))]) :-
cwd(Tmp) cwd(Tmp)
]), ]),
read_process(Out, CWD0), read_process(Out, CWD0),
system:normalize_space(atom(CWD), CWD0), normalize_space(atom(CWD), CWD0),
system:swi_same_file(CWD, Tmp). same_file(CWD, Tmp).
test(cwd, [true, condition(current_prolog_flag(windows, true))]) :- test(cwd, [true, condition(current_prolog_flag(windows, true))]) :-
tmp_dir(Tmp), tmp_dir(Tmp),
getenv('COMSPEC', Shell), getenv('COMSPEC', Shell),
@ -72,8 +72,8 @@ test(cwd, [true, condition(current_prolog_flag(windows, true))]) :-
cwd(Tmp) cwd(Tmp)
]), ]),
read_process(Out, CWD0), read_process(Out, CWD0),
system:normalize_space(atom(CWD), CWD0), normalize_space(atom(CWD), CWD0),
system:swi_same_file(CWD, Tmp). same_file(CWD, Tmp).
tmp_dir(Dir) :- tmp_dir(Dir) :-
getenv('TEMP', Dir), !. getenv('TEMP', Dir), !.

View File

@ -35,10 +35,10 @@
client/1 % +Address client/1 % +Address
]). ]).
%:- asserta(user:file_search_path(foreign, '.')). :- asserta(user:file_search_path(foreign, '.')).
:- use_module(library(socket)). :- use_module(socket).
%:- use_module(user:socket). % debugging :- use_module(user:socket). % debugging
:- use_module(streampool). :- use_module(streampool).
:- use_module(library(debug)). :- use_module(library(debug)).
@ -182,6 +182,7 @@ reply(T, _, T).
receive_loop(Socket, Queue) :- receive_loop(Socket, Queue) :-
repeat, repeat,
writeln(hellorec),
udp_receive(Socket, Data, From, [as(atom)]), udp_receive(Socket, Data, From, [as(atom)]),
thread_send_message(Queue, got(Data, From)), thread_send_message(Queue, got(Data, From)),
Data == quit, !, Data == quit, !,
@ -210,7 +211,9 @@ run_udp :-
thread_get_message(got(X, _)), thread_get_message(got(X, _)),
udp_send(S, 'quit', localhost:Port, []), udp_send(S, 'quit', localhost:Port, []),
thread_get_message(got(Q, _)), thread_get_message(got(Q, _)),
writeln(hello2),
thread_join(ThreadId, Exit), thread_join(ThreadId, Exit),
writeln(hello2),
tcp_close_socket(S), tcp_close_socket(S),
assertion(X=='hello world'), assertion(X=='hello world'),
assertion(Q=='quit'), assertion(Q=='quit'),

View File

@ -1,297 +0,0 @@
/* $Id$
Part of SWI-Prolog
Author: Jan Wielemaker
E-mail: jan@swi.psy.uva.nl
WWW: http://www.swi-prolog.org
Copyright (C): 1985-2002, University of Amsterdam
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
As a special exception, if you link this library with other files,
compiled with a Free Software compiler, to produce an executable, this
library does not by itself cause the resulting executable to be covered
by the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.
*/
:- module(test_socket,
[ test_socket/0,
server/1, % +Port
client/1 % +Address
]).
%:- asserta(user:file_search_path(foreign, '.')).
:- use_module(library(socket)).
%:- use_module(user:socket). % debugging
:- use_module(streampool).
:- use_module(library(debug)).
test_socket :-
test_udp,
test_tcp.
test_tcp :-
make_server(Port, Socket),
thread_create(run_server(Socket), Server, []),
client(localhost:Port),
thread_join(Server, Status),
( Status == true
-> true
; format(user_error, 'Server exit-status: ~w~n', [Status]),
fail
).
/*******************************
* SERVER *
*******************************/
server(Port) :-
make_server(Port, Socket),
run_server(Socket).
run_server(Socket) :-
tcp_open_socket(Socket, In, _Out),
add_stream_to_pool(In, accept(Socket)),
stream_pool_main_loop.
make_server(Port, Socket) :-
tcp_socket(Socket),
tcp_bind(Socket, Port),
tcp_listen(Socket, 5).
accept(Socket) :-
tcp_accept(Socket, Slave, Peer),
debug(connection, 'connect(~p)', [Peer]),
tcp_open_socket(Slave, In, Out),
add_stream_to_pool(In, client(In, Out, Peer)).
client(In, Out, Peer) :-
read(In, Term),
( Term == end_of_file
-> debug(connection, 'close(~p)', [Peer]),
close(In),
close(Out)
; ( catch(action(Term, In, Out), E, true)
-> ( var(E)
-> true
; tcp_send(Out, exception(E))
)
; tcp_send(Out, no)
)
).
/*******************************
* ACTION *
*******************************/
action(echo(X), _In, Out) :-
tcp_send(Out, X).
action(wait(X), _In, Out) :-
sleep(X),
tcp_send(Out, yes).
action(slow_read, In, Out) :-
sleep(2),
read(In, Term),
tcp_send(Out, Term).
action(quit, _In, Out) :-
close_stream_pool,
tcp_send(Out, quitted).
/*******************************
* CLIENT SIDE *
*******************************/
:- dynamic
client/2.
client(Address) :-
tcp_socket(S),
tcp_connect(S, Address),
tcp_open_socket(S, In, Out),
asserta(client(In, Out)),
test,
retract(client(In, Out)),
close(Out),
close(In).
echo(echo-1) :-
X = 'Hello World',
client(In, Out),
tcp_send(Out, echo(X)),
tcp_reply(In, X).
echo(echo-2) :-
findall(A, between(0, 100000, A), X),
client(In, Out),
tcp_send(Out, echo(X)),
tcp_reply(In, X).
slow(slow-1) :-
client(In, Out),
tcp_send(Out, wait(2)),
tcp_reply(In, yes).
slow(slow-1) :-
client(In, Out),
tcp_send(Out, slow_read),
findall(A, between(0, 100000, A), X),
tcp_send(Out, X),
tcp_reply(In, X).
quit(quit-1) :-
client(In, Out),
tcp_send(Out, quit),
tcp_reply(In, quitted).
/*******************************
* UTIL *
*******************************/
tcp_send(Out, Term) :-
format(Out, '~q.~n', [Term]),
flush_output(Out).
tcp_reply(In, Reply) :-
read(In, Term),
reply(Term, In, Reply).
reply(exception(E), _, _) :-
throw(E).
reply(T, _, T).
/*******************************
* UDP *
*******************************/
receive_loop(Socket, Queue) :-
repeat,
udp_receive(Socket, Data, From, [as(atom)]),
thread_send_message(Queue, got(Data, From)),
Data == quit, !,
tcp_close_socket(Socket).
receiver(Port, ThreadId) :-
thread_self(Me),
udp_socket(S),
tcp_bind(S, Port),
thread_create(receive_loop(S, Me), ThreadId, []).
test_udp :-
format(user_error, 'Running test set "udp"', []),
( catch(run_udp, E, true)
-> ( var(E)
-> format(user_error, ' . done~n', [])
; print_message(error, E)
)
; format(user_error, 'FAILED~n', [])
).
run_udp :-
receiver(Port, ThreadId),
udp_socket(S),
udp_send(S, 'hello world', localhost:Port, []),
thread_get_message(got(X, _)),
udp_send(S, 'quit', localhost:Port, []),
thread_get_message(got(Q, _)),
thread_join(ThreadId, Exit),
tcp_close_socket(S),
assertion(X=='hello world'),
assertion(Q=='quit'),
assertion(Exit==true), !.
/*******************************
* TEST MAIN-LOOP *
*******************************/
testset(echo).
testset(slow).
testset(quit).
:- dynamic
failed/1,
blocked/2.
test :-
retractall(failed(_)),
retractall(blocked(_,_)),
forall(testset(Set), runtest(Set)),
report_blocked,
report_failed.
report_blocked :-
findall(Head-Reason, blocked(Head, Reason), L),
( L \== []
-> format('~nThe following tests are blocked:~n', []),
( member(Head-Reason, L),
format(' ~p~t~40|~w~n', [Head, Reason]),
fail
; true
)
; true
).
report_failed :-
findall(X, failed(X), L),
length(L, Len),
( Len > 0
-> format('~n*** ~w tests failed ***~n', [Len]),
fail
; format('~nAll tests passed~n', [])
).
runtest(Name) :-
format('Running test set "~w" ', [Name]),
flush,
functor(Head, Name, 1),
nth_clause(Head, _N, R),
clause(Head, _, R),
( catch(Head, Except, true)
-> ( var(Except)
-> put(.), flush
; Except = blocked(Reason)
-> assert(blocked(Head, Reason)),
put(!), flush
; test_failed(R, Except)
)
; test_failed(R, fail)
),
fail.
runtest(_) :-
format(' done.~n').
test_failed(R, Except) :-
clause(Head, _, R),
functor(Head, Name, 1),
arg(1, Head, TestName),
clause_property(R, line_count(Line)),
clause_property(R, file(File)),
( Except == failed
-> format('~N~w:~d: Test ~w(~w) failed~n',
[File, Line, Name, TestName])
; message_to_string(Except, Error),
format('~N~w:~d: Test ~w(~w):~n~t~8|ERROR: ~w~n',
[File, Line, Name, TestName, Error])
),
assert(failed(Head)).
blocked(Reason) :-
throw(blocked(Reason)).

View File

@ -41,7 +41,6 @@
call_with_time_limit/2 % +Time, :Callable call_with_time_limit/2 % +Time, :Callable
]). ]).
:- use_module(library(lists)). :- use_module(library(lists)).
:- use_module(library(shlib)).
:- set_prolog_flag(generate_debug_info, false). :- set_prolog_flag(generate_debug_info, false).
:- meta_predicate :- meta_predicate

6
packages/clib/unix.c Executable file → Normal file
View File

@ -30,7 +30,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h>u #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <fcntl.h> #include <fcntl.h>
#include <assert.h> #include <assert.h>
@ -247,11 +247,7 @@ pl_environ(term_t l)
term_t vt = PL_new_term_ref(); term_t vt = PL_new_term_ref();
functor_t FUNCTOR_equal2 = PL_new_functor(PL_new_atom("="), 2); functor_t FUNCTOR_equal2 = PL_new_functor(PL_new_atom("="), 2);
#if HAVE__NSGETENVIRON
for(e = _NSGetEnviron(); *e; e++)
#else
for(e = environ; *e; e++) for(e = environ; *e; e++)
#endif
{ char *s = strchr(*e, '='); { char *s = strchr(*e, '=');
if ( !s ) if ( !s )

9
packages/clib/uri.c Executable file → Normal file
View File

@ -487,6 +487,7 @@ add_decoded_range_charbuf(charbuf *cb, const range *r, int flags)
static int static int
add_normalized_range_charbuf(charbuf *cb, const range *r, int iri, int flags) add_normalized_range_charbuf(charbuf *cb, const range *r, int iri, int flags)
{ const pl_wchar_t *s = r->start; { const pl_wchar_t *s = r->start;
while(s<r->end) while(s<r->end)
{ int c; { int c;
@ -797,11 +798,13 @@ uri_is_global(term_t URI)
const pl_wchar_t *end = &s[len]; const pl_wchar_t *end = &s[len];
range r; range r;
fill_flags();
e = skip_not(s, end, L":/?#"); e = skip_not(s, end, L":/?#");
if ( e > s && e[0] == ':' ) if ( e > s && e[0] == ':' )
{ r.start = s; { r.start = s;
r.end = e; r.end = e;
if ( range_is_unreserved(&r, TRUE, CH_SCHEME) ) if ( range_is_unreserved(&r, FALSE, CH_SCHEME) )
return TRUE; return TRUE;
} }
} }
@ -1148,11 +1151,11 @@ normalize_in_charbuf(charbuf *cb, uri_component_ranges *ranges, int iri)
} }
if ( ranges->query.start ) if ( ranges->query.start )
{ add_charbuf(cb, '?'); { add_charbuf(cb, '?');
add_range_charbuf(cb, &ranges->query, iri, ESC_QUERY); add_range_charbuf(cb, &ranges->query, iri, ESC_QVALUE);
} }
if ( ranges->fragment.start ) if ( ranges->fragment.start )
{ add_charbuf(cb, '#'); { add_charbuf(cb, '#');
add_range_charbuf(cb, &ranges->fragment, iri, ESC_FRAGMENT); add_range_charbuf(cb, &ranges->fragment, iri, ESC_QVALUE);
} }
return TRUE; return TRUE;

View File

@ -46,9 +46,6 @@
uri_file_name/2, % ?URI, ?Path uri_file_name/2, % ?URI, ?Path
uri_iri/2 % ?URI, ?IRI uri_iri/2 % ?URI, ?IRI
]). ]).
:- use_module(library(shlib)).
:- use_foreign_library(foreign(uri)). :- use_foreign_library(foreign(uri)).
/** <module> Process URIs /** <module> Process URIs

@ -1 +1 @@
Subproject commit 77744ad3a901eb97cafd95c1e0ac1b89d3859b18 Subproject commit f14257c46e7fd6eecbce420140eee40a5d24141a

@ -1 +1 @@
Subproject commit 352c64eb476378b70eba93aa0a664f6d54dad0d9 Subproject commit 4cc990c4b86fe767a1eb8453e60607e15f0bc706