This commit is contained in:
Vitor Santos Costa
2018-06-07 18:05:45 +01:00
parent 54c6b8c041
commit 59534a04f6
8 changed files with 196 additions and 45 deletions

View File

@@ -2121,7 +2121,12 @@ PREDEFINED = \
LOCAL_ARRAY_ARRAY(A, B, C,D):="A B[C][D]"\ LOCAL_ARRAY_ARRAY(A, B, C,D):="A B[C][D]"\
LOCAL_INIT(A, B, C, D):="A B[C][D]"\ LOCAL_INIT(A, B, C, D):="A B[C][D]"\
LOCAL_INITF(A, B, C):=" A B; C"\ LOCAL_INITF(A, B, C):=" A B; C"\
LOCAL_INIT_RESTORE(A,B,C,D):="A B; C; D;"\ LOCAL_INIT_RESTORE(A,B,C,D):="A B; C; D;" \
USES_REGS:="" \
USES_REGS1:="void" \
PASS_REGS:="" \
PASS_REGS1:="" \
Yap_InitCPred(Name,Arity,CF,Flags):="/// @cpred Name Arity CF" \
PREG:=Yap_REGS.P_ PREG:=Yap_REGS.P_
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this

View File

@@ -5,8 +5,8 @@
} }
.adjust-right { .adjust-right {
margin-left: 30px !important; margin-left: 20px !important;
font-size: 1.15em !important; font-size: 1.00em !important;
} }
/* DOXYGEN Code Styles - These are from doxygen but can be changed to fit the theme /* DOXYGEN Code Styles - These are from doxygen but can be changed to fit the theme

View File

@@ -36,21 +36,22 @@ $( document ).ready(function() {
$("div.summary > a").addClass("btn btn-default btn-xs"); $("div.summary > a").addClass("btn btn-default btn-xs");
$("table.fieldtable").addClass("table"); $("table.fieldtable").addClass("table");
$(".fragment").addClass("well"); $(".fragment").addClass("well");
$(".memitem").addClass("panel panel-default"); $(".memitem").addClass("card text-center");
$(".memproto").addClass("panel-heading"); $(".memproto").addClass("card-title text-center");
$(".memdoc").addClass("panel-body"); $(".memdoc").addClass("card-body text-right);
$("span.mlabel").addClass("label label-info"); // $("span.mlabel").addClass("card-link label-info");
$("table.memberdecls").addClass("table"); $("table.memberdecls").addClass("table");
$("[class^=memitem]").addClass("active"); $("[class^=memitem]").addClass("active");
$("div.ah").addClass("btn btn-default"); $("div.ah").addClass("btn btn-default");
$("span.mlabels").addClass("pull-right"); $("span.mlabels").addClass("pull-right");
$("table.mlabels").css("width", "100%") $("span.mlabels").css("width", "100%")
$("td.mlabels-right").addClass("pull-right"); $("td.mlabels-right").addClass("pull-right");
$("div.ttc").addClass("panel panel-primary"); $("div.ttc").addClass("panel panel-primary");
$("div.ttname").addClass("panel-heading"); //$("div.ttname").addClass("panel-heading");
$("div.ttname a").css("color", 'white'); $("div.ttname a").css("color", 'white');
$("div.ttdef,div.ttdoc,div.ttdeci").addClass("panel-body"); $("div.ttdef,div.ttdoc,div.ttdeci").addClass("panel-body");
@@ -119,4 +120,4 @@ $( document ).ready(function() {
$(this).siblings('.memItemRight').remove(); $(this).siblings('.memItemRight').remove();
} }
}); });
}); });

View File

@@ -109,21 +109,6 @@ This example is equivalent to using the delete_file/1 predicate:
~~~~~ ~~~~~
*/
/** @pred directory_files(+ _Dir_,+ _List_)
Given a directory _Dir_, directory_files/2 procedures a
listing of all files and directories in the directory:
~~~~~
?- directory_files('.',L), writeq(L).
['Makefile.~1~','sys.so','Makefile','sys.o',x,..,'.']
~~~~~
The predicates uses the `dirent` family of routines in Unix
environments, and `findfirst` in WIN32.
*/ */
/** @pred environ(? _EnvVar_,+ _EnvValue_) /** @pred environ(? _EnvVar_,+ _EnvValue_)
@@ -452,13 +437,6 @@ delete_dirfiles([F|Fs], File, Ignore) :-
delete_file(TrueF, off, on, Ignore), delete_file(TrueF, off, on, Ignore),
delete_dirfiles(Fs, File, Ignore). delete_dirfiles(Fs, File, Ignore).
directory_files(File, FileList) :-
directory_files(File, FileList, on).
directory_files(File, FileList, Ignore) :-
list_directory(File, FileList, Error),
handle_system_internal(Error, Ignore, directory_files(File, FileList)).
handle_system_internal(Error, _Ignore, _G) :- var(Error), !. handle_system_internal(Error, _Ignore, _G) :- var(Error), !.
handle_system_internal(Error, off, G) :- atom(Error), !, handle_system_internal(Error, off, G) :- atom(Error), !,
throw(error(system_internal(Error),G)). throw(error(system_internal(Error),G)).
@@ -708,7 +686,75 @@ get_shell(Shell, '/c') :-
get_shell('/bin/sh','-c'). get_shell('/bin/sh','-c').
system :- system :-
default_shell(Command), default_shell(C/** @pred directory_files(+ _Dir_,+ _List_)a
Given a directory _Dir_, directory_files/2 procedures a
listing of all files and directories in the directory:
~~~~~
?- directory_files('.',L), writeq(L).
['Makefile.~1~','sys.so','Makefile','sys.o',x,..,'.']
~~~~~
The predicates uses the/** @pred directory_files(+ _Dir_,+ _List_)a
Given a directory _Dir_, directory_files/2 procedures a
listing of all files and directories in the directory:
~~~~~
?- directory_files('.',L), writeq(L).
['Makefile.~1~','sys.so','Makefile','sys.o',x,..,'.']
~~~~~
The predicates uses the/** @pred directory_files(+ _Dir_,+ _List_)a
Given a directory _Dir_, directory_files/2 procedures a
listing of all files and directories in the directory:
~~~~~
?- directory_files('.',L), writeq(L).
['Makefile.~1~','sys.so','Makefile','sys.o',x,..,'.']
~~~~~
The predicates uses the `dirent` family of routines in Unix
environments, and `findfirst` in WIN32.
*/
`dirent` family of routines in Unix
environments, and `findfirst` in WIN32.
*/
`dirent` family of routines in Unix
environments, and `findfirst` in WIN32.
*/
ommand),/** @pred directory_files(+ _Dir_,+ _List_)a
Given a directory _Dir_, directory_files/2 procedures a
listing of all files and directories in the directory:
~~~~~
?- directory_files('.',L), writeq(L).
['Makefile.~1~','sys.so','Makefile','sys.o',x,..,'.']
~~~~~
The predicates uses the/** @pred directory_files(+ _Dir_,+ _List_)a
Given a directory _Dir_, directory_files/2 procedures a
listing of all files and directories in the directory:
~~~~~
?- directory_files('.',L), writeq(L).
['Makefile.~1~','sys.so','Makefile','sys.o',x,..,'.']
~~~~~
The predicates uses the
*/
do_system(Command, _Status, Error), do_system(Command, _Status, Error),
handle_system_internal(Error, off, system). handle_system_internal(Error, off, system).
@@ -812,5 +858,22 @@ Passes command _S_ to the Bourne shell (on UNIX environments) or the
current command interpreter in WIN32 environments. current command interpreter in WIN32 environments.
*/ */
/** @pred directory_files(+ _Dir_,+ _List_)a
Given a directory _Dir_, directory_files/2 procedures a
listing of all files and directories in the directory:
~~~~~
?- directory_files('.',L), writeq(L).
['Makefile.~1~','sys.so','Makefile','sys.o',x,..,'.']
~~~~~
The predicates uses the `dirent` family of routines in Unix
environments, and `findfirst` in WIN32.
*/
directory_files(X,Y) :=
list_directory(X,Y).
/** @} */ /** @} */

View File

@@ -1048,7 +1048,6 @@ X_API void init_sys(void) {
#endif #endif
YAP_UserCPredicate("datime", datime, 2); YAP_UserCPredicate("datime", datime, 2);
YAP_UserCPredicate("mktime", sysmktime, 8); YAP_UserCPredicate("mktime", sysmktime, 8);
YAP_UserCPredicate("list_directory", list_directory, 3);
YAP_UserCPredicate("file_property", file_property, 7); YAP_UserCPredicate("file_property", file_property, 7);
YAP_UserCPredicate("unlink", p_unlink, 2); YAP_UserCPredicate("unlink", p_unlink, 2);
YAP_UserCPredicate("rmdir", p_rmdir, 2); YAP_UserCPredicate("rmdir", p_rmdir, 2);

View File

@@ -27,6 +27,16 @@ static char SccsId[] = "%W% %G%";
#include "sysbits.h" #include "sysbits.h"
#include "yapio.h" #include "yapio.h"
#if HAVE_DIRENT_H
#include <dirent.h>
#endif
#if HAVE_DIRECT_H
#include <direct.h>
#endif
#if defined(__MINGW32__) || _MSC_VER
#include <io.h>
#include <windows.h>
#endif
#if _MSC_VER || defined(__MINGW32__) #if _MSC_VER || defined(__MINGW32__)
#define SYSTEM_STAT _stat #define SYSTEM_STAT _stat
#else #else
@@ -624,6 +634,78 @@ static Int file_directory_name(USES_REGS1) { /* file_directory_name(Stream,N) */
return Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(s))); return Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(s)));
} }
/* Return a list of files for a directory */
static Int list_directory(USES_REGS1) {
Term tf = MkAtomTerm(Yap_LookupAtom("[]"));
yhandle_t sl = Yap_InitSlot(tf);
char *buf = (char *)AtomName(AtomOfTerm(ARG1));
#if defined(__MINGW32__) || _MSC_VER
struct _finddata_t c_file;
char bs[BUF_SIZE];
long hFile;
bs[0] = '\0';
#if HAVE_STRNCPY
strncpy(bs, buf, BUF_SIZE);
#else
strcpy(bs, buf);
#endif
#if HAVE_STRNCAT
strncat(bs, "/*", BUF_SIZE);
#else
strcat(bs, "/*");
#endif
if ((hFile = _findfirst(bs, &c_file)) == -1L) {
return (Yap_Unify(ARD2, tf));
}
YAP_PutInSlot(sl, YAP_MkPairTerm(YAP_MkAtomTerm(YAP_LookupAtom(c_file.name)),
YAP_GetFromSlot(sl)));
while (_findnext(hFile, &c_file) == 0) {
YAP_Term ti = YAP_MkAtomTerm(YAP_LookupAtom(c_file.name));
YAP_PutInSlot(sl, YAP_MkPairTerm(ti, YAP_GetFromSlot(sl)));
}
_findclose(hFile);
#else
#if __ANDROID__
{
const char *dirName = buf + strlen("/assets/");
AAssetManager *mgr = GLOBAL_VFS->priv[0].mgr;
AAssetDir *de;
const char *dp;
if ((de = AAssetManager_openDir(mgr, dirName)) == NULL) {
return (YAP_Unify(ARD3, YAP_MkIntTerm(errno)));
}
while ((dp = AAssetDir_getNextFileName(de))) {
YAP_Term ti = YAP_MkAtomTerm(YAP_LookupAtom(dp));
YAP_PutInSlot(sl, YAP_MkPairTerm(ti, YAP_GetFromSlot(sl)));
}
AAssetDir_close(de);
}
#endif
#if HAVE_OPENDIR
{
DIR *de;
struct dirent *dp;
if ((de = opendir(buf)) == NULL) {
return (YAP_unify(ARG3, MkIntegerTerm(errno)));
}
while ((dp = readdir(de))) {
Term ti = Yap_MkAtomTerm(Yap_LookupAtom(dp->d_name));
Yap_PutInSlot(sl, MkPairTerm(ti, Yap_GetFromSlot(sl)));
}
closedir(de);
}
#endif /* HAVE_OPENDIR */
#endif
tf = Yap_GetFromSlot(sl);
return Yap_unify(ARG2, tf);
}
static Int same_file(USES_REGS1) { static Int same_file(USES_REGS1) {
char *f1 = RepAtom(AtomOfTerm(Deref(ARG1)))->StrOfAE; char *f1 = RepAtom(AtomOfTerm(Deref(ARG1)))->StrOfAE;
char *f2 = RepAtom(AtomOfTerm(Deref(ARG2)))->StrOfAE; char *f2 = RepAtom(AtomOfTerm(Deref(ARG2)))->StrOfAE;
@@ -714,4 +796,5 @@ void Yap_InitFiles(void) {
Yap_InitCPred("file_size", 2, file_size, SafePredFlag | SyncPredFlag); Yap_InitCPred("file_size", 2, file_size, SafePredFlag | SyncPredFlag);
Yap_InitCPred("file_name_extension", 3, file_name_extension, Yap_InitCPred("file_name_extension", 3, file_name_extension,
SafePredFlag | SyncPredFlag); SafePredFlag | SyncPredFlag);
YAP_InitPredt("list_directory", list_directory, 2, SyncPredFlag);
} }

View File

@@ -159,12 +159,12 @@ Similar to `bagof( _T_, _G_, _L_)` but sorts list
_L_ and keeping only one copy of each element. Again, assuming the _L_ and keeping only one copy of each element. Again, assuming the
same clauses as in the examples above, the reply to the query same clauses as in the examples above, the reply to the query
~~~~~ ~~~
setof(X,a(X,Y),L). setof(X,a(X,Y),L).
~~~~~ ~~~
would be: would be:
~~~~~ ~~~
X = _32 X = _32
Y = 1 Y = 1
L = [1,2]; L = [1,2];
@@ -172,7 +172,7 @@ X = _32
Y = 2 Y = 2
L = [2]; L = [2];
no no
~~~~~ ~~~
@@ -202,7 +202,7 @@ For each set of possible instances of the free variables occurring in
_T_ satisfying _G_. Again, assuming the same clauses as in the _T_ satisfying _G_. Again, assuming the same clauses as in the
examples above, the reply to the query examples above, the reply to the query
~~~~~ ~~~
bagof(X,a(X,Y),L). bagof(X,a(X,Y),L).
would be: would be:
@@ -213,7 +213,7 @@ X = _32
Y = 2 Y = 2
L = [2]; L = [2];
no no
~~~~~ ~~~
*/ */
@@ -272,17 +272,17 @@ Similar to `findall( _T_, _G_, _L_)` but eliminate
repeated elements. Thus, assuming the same clauses as in the above repeated elements. Thus, assuming the same clauses as in the above
example, the reply to the query example, the reply to the query
~~~~~ ~~~
all(X,a(X,Y),L). all(X,a(X,Y),L).
~~~~~ ~~~
would be: would be:
~~~~~ ~~~
X = _32 X = _32
Y = _33 Y = _33
L = [2,1]; L = [2,1];
no no
~~~~~ ~~~
Note that all/3 will fail if no answers are found. Note that all/3 will fail if no answers are found.

View File

@@ -32,7 +32,7 @@
). ).
/** /**
* @defgroup ypp Yap PreProcessing * @defgroup Ypp Yap PreProcessing
* @{ * @{
* @ingroup library * @ingroup library
* *