update PLStream to improvements in the interface.

This commit is contained in:
Vítor Santos Costa 2010-05-04 15:17:08 +01:00
parent 0740495d77
commit 9ff4bbfbfe
7 changed files with 160 additions and 59 deletions

View File

@ -19,7 +19,7 @@ LIBDIR=@libdir@/Yap
#
#
CC=@CC@
CFLAGS= @CFLAGS@ $(YAP_EXTRAS) $(DEFS) -D_YAP_NOT_INSTALLED_=1 -I$(srcdir) -I../.. -I$(srcdir)/../../include -I$(srcdir)/uxnt
CFLAGS= @CFLAGS@ $(YAP_EXTRAS) $(DEFS) -D_YAP_NOT_INSTALLED_=1 -I$(srcdir) -I../.. -I$(srcdir)/../../include
#
#
# You shouldn't need to change what follows.
@ -48,17 +48,19 @@ HEADERS=$(srcdir)/atoms.h $(srcdir)/pl-buffer.h $(srcdir)/pl-ctype.h \
$(srcdir)/pl-yap.h @ENABLE_WINCONSOLE@ $(srcdir)/uxnt/dirent.h $(srcdir)/uxnt/utf8.h $(srcdir)/pl-utf8.c $(srcdir)/uxnt/uxnt.h
C_SOURCES=$(srcdir)/pl-buffer.c $(srcdir)/pl-ctype.c \
$(srcdir)/pl-error.c \
$(srcdir)/pl-file.c $(srcdir)/pl-files.c $(srcdir)/pl-os.c \
$(srcdir)/pl-file.c $(srcdir)/pl-files.c \
$(srcdir)/pl-glob.c \
$(srcdir)/pl-os.c \
$(srcdir)/pl-privitf.c \
$(srcdir)/pl-stream.c $(srcdir)/pl-string.c \
$(srcdir)/pl-table.c \
$(srcdir)/pl-text.c \
$(srcdir)/pl-utils.c \
$(srcdir)/pl-util.c \
$(srcdir)/pl-yap.c @ENABLE_WINCONSOLE@ $(srcdir)/popen.c $(srcdir)/uxnt/uxnt.c
OBJS=pl-buffer.o pl-ctype.o pl-error.o \
pl-file.o pl-files.o pl-os.o pl-privitf.o \
pl-file.o pl-files.o pl-glob.o pl-os.o pl-privitf.o \
pl-stream.o pl-string.o pl-table.o \
pl-text.o pl-utils.o pl-utf8.o \
pl-text.o pl-util.o pl-utf8.o \
pl-yap.o @ENABLE_WINCONSOLE@ uxnt.o
SOBJS=plstream@SHLIB_SUFFIX@

View File

@ -4308,6 +4308,8 @@ static void
init_yap_extras()
{
initCharTypes();
initFiles();
initGlob();
PL_register_extensions(PL_predicates_from_file);
fileerrors = TRUE;
SinitStreams();

View File

@ -977,6 +977,35 @@ PRED_IMPL("mark_executable", 1, mark_executable, 0)
}
/*******************************
* PUBLISH PREDICATES *
*******************************/
BeginPredDefs(files)
PRED_DEF("swi_working_directory", 2, working_directory, 0)
PRED_DEF("swi_access_file", 2, access_file, 0)
PRED_DEF("swi_time_file", 2, time_file, 0)
PRED_DEF("swi_size_file", 2, size_file, 0)
PRED_DEF("swi_read_link", 3, read_link, 0)
PRED_DEF("swi_exists_file", 1, exists_file, 0)
PRED_DEF("swi_exists_directory", 1, exists_directory, 0)
PRED_DEF("swi_tmp_file", 2, tmp_file, 0)
PRED_DEF("swi_tmp_file_stream", 3, tmp_file_stream, 0)
PRED_DEF("swi_delete_file", 1, delete_file, 0)
PRED_DEF("swi_delete_directory", 1, delete_directory, 0)
PRED_DEF("swi_make_directory", 1, make_directory, 0)
PRED_DEF("swi_same_file", 2, same_file, 0)
PRED_DEF("swi_rename_file", 2, rename_file, 0)
PRED_DEF("swi_is_absolute_file_name", 1, is_absolute_file_name, 0)
PRED_DEF("swi_file_base_name", 2, file_base_name, 0)
PRED_DEF("swi_file_directory_name", 2, file_directory_name, 0)
PRED_DEF("swi_file_name_extension", 3, file_name_extension, 0)
PRED_DEF("swi_prolog_to_os_filename", 2, prolog_to_os_filename, 0)
PRED_DEF("swi_$mark_executable", 1, mark_executable, 0)
PRED_DEF("swi_$absolute_file_name", 2, absolute_file_name, 0)
EndPredDefs
/*******************************
* INIT *
*******************************/
@ -984,33 +1013,6 @@ PRED_IMPL("mark_executable", 1, mark_executable, 0)
void
initFiles(void)
{
PL_register_extensions(PL_predicates_from_files);
}
/*******************************
* PUBLISH PREDICATES *
*******************************/
BeginPredDefs(files)
PRED_DEF("working_directory", 2, working_directory, 0)
PRED_DEF("access_file", 2, access_file, 0)
PRED_DEF("time_file", 2, time_file, 0)
PRED_DEF("size_file", 2, size_file, 0)
PRED_DEF("read_link", 3, read_link, 0)
PRED_DEF("exists_file", 1, exists_file, 0)
PRED_DEF("exists_directory", 1, exists_directory, 0)
PRED_DEF("tmp_file", 2, tmp_file, 0)
PRED_DEF("tmp_file_stream", 3, tmp_file_stream, 0)
PRED_DEF("delete_file", 1, delete_file, 0)
PRED_DEF("delete_directory", 1, delete_directory, 0)
PRED_DEF("make_directory", 1, make_directory, 0)
PRED_DEF("same_file", 2, same_file, 0)
PRED_DEF("rename_file", 2, rename_file, 0)
PRED_DEF("is_absolute_file_name", 1, is_absolute_file_name, 0)
PRED_DEF("file_base_name", 2, file_base_name, 0)
PRED_DEF("file_directory_name", 2, file_directory_name, 0)
PRED_DEF("file_name_extension", 3, file_name_extension, 0)
PRED_DEF("prolog_to_os_filename", 2, prolog_to_os_filename, 0)
PRED_DEF("$mark_executable", 1, mark_executable, 0)
PRED_DEF("$absolute_file_name", 2, absolute_file_name, 0)
EndPredDefs

View File

@ -286,6 +286,7 @@ typedef struct PL_local_data {
occurs_check_t occurs_check; /* Unify and occurs check */
} prolog_flag;
void * glob_info; /* pl-glob.c */
IOENC encoding; /* default I/O encoding */
struct
@ -297,6 +298,18 @@ typedef struct PL_local_data {
int rand_initialised; /* have we initialised random? */
} os;
struct
{ int64_t pending; /* PL_raise() pending signals */
int current; /* currently processing signal */
int is_sync; /* current signal is synchronous */
record_t exception; /* Pending exception from signal */
#ifdef O_PLMT
simpleMutex sig_lock; /* lock delivery and processing */
#endif
} signal;
int critical; /* heap is being modified */
struct
{ term_t term; /* exception term */
term_t bin; /* temporary handle for exception */
@ -578,6 +591,9 @@ extern word notImplemented(char *name, int arity);
/**** stuff from pl-ctype.c ****/
extern void initCharTypes(void);
/**** stuff from pl-glob.c ****/
extern void initGlob(void);
/**** stuff from pl-os.c ****/
extern void cleanupOs(void);
extern void PL_clock_wait_ticks(long waited);

View File

@ -0,0 +1,96 @@
#include "pl-incl.h"
#include "pl-ctype.h"
#ifndef HAVE_STRICMP
int
stricmp(const char *s1, const char *s2)
{ while(*s1 && makeLower(*s1) == makeLower(*s2))
s1++, s2++;
return makeLower(*s1) - makeLower(*s2);
}
#endif
bool
stripostfix(char *s, char *e)
{ int ls = strlen(s);
int le = strlen(e);
if ( ls >= le )
return stricmp(&s[ls-le], e) == 0;
return FALSE;
}
#if !defined(HAVE_MBSCOLL) || !defined(HAVE_MBCASESCOLL)
static void
wstolower(wchar_t *w, size_t len)
{ wchar_t *e = &w[len];
for( ; w<e; w++ )
*w = towlower(*w);
}
static int
int_mbscoll(const char *s1, const char *s2, int icase)
{ size_t l1 = strlen(s1);
size_t l2 = strlen(s2);
wchar_t *w1;
wchar_t *w2;
int ml1, ml2;
mbstate_t mbs;
int rc;
if ( l1 < 1024 && (w1 = alloca(sizeof(wchar_t)*(l1+1))) )
{ ml1 = FALSE;
} else
{ w1 = PL_malloc(sizeof(wchar_t)*(l1+1));
ml1 = TRUE;
}
if ( l2 < 1024 && (w2 = alloca(sizeof(wchar_t)*(l2+1))) )
{ ml2 = FALSE;
} else
{ w2 = PL_malloc(sizeof(wchar_t)*(l2+1));
ml2 = TRUE;
}
memset(&mbs, 0, sizeof(mbs));
if ( mbsrtowcs(w1, &s1, l1+1, &mbs) == (size_t)-1 )
{ rc = -2;
goto out;
}
if ( mbsrtowcs(w2, &s2, l2+1, &mbs) == (size_t)-1 )
{ rc = 2;
goto out;
}
if ( icase )
{ wstolower(w1, l1);
wstolower(w2, l2);
}
rc = wcscoll(w1, w2);
out:
if ( ml1 ) PL_free(w1);
if ( ml2 ) PL_free(w2);
return rc;
}
#endif
#ifndef HAVE_MBSCOLL
int
mbscoll(const char *s1, const char *s2)
{ return int_mbscoll(s1, s2, FALSE);
}
#endif
#ifndef HAVE_MBSCASECOLL
int
mbscasecoll(const char *s1, const char *s2)
{ return int_mbscoll(s1, s2, TRUE);
}
#endif

View File

@ -1,25 +0,0 @@
#include "pl-incl.h"
#include "pl-ctype.h"
#ifndef HAVE_STRICMP
int
stricmp(const char *s1, const char *s2)
{ while(*s1 && makeLower(*s1) == makeLower(*s2))
s1++, s2++;
return makeLower(*s1) - makeLower(*s2);
}
#endif
bool
stripostfix(char *s, char *e)
{ int ls = strlen(s);
int le = strlen(e);
if ( ls >= le )
return stricmp(&s[ls-le], e) == 0;
return FALSE;
}

View File

@ -198,7 +198,7 @@ switch(n->type)
int
_PL_unify_atomic(term_t t, PL_atomic_t a)
{
return YAP_Unify(YAP_GetFromSlot(t), (YAP_Term)a);
return PL_unify_atom(t, a);
}
word lookupAtom(const char *s, size_t len)
@ -588,3 +588,11 @@ PL_unify_chars(term_t t, int flags, size_t len, const char *s)
return rc;
}
X_API int PL_handle_signals(void)
{
if ( !LD || LD->critical || !LD->signal.pending )
return 0;
fprintf(stderr,"PL_handle_signals not implemented\n");
return 0;
}