SWI file_name builtins.
This commit is contained in:
parent
9efbc0fce8
commit
efc65fdb28
31
C/iopreds.c
31
C/iopreds.c
@ -6594,36 +6594,6 @@ Yap_StringToTerm(char *s,Term *tp)
|
||||
return t;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_file_base_name (void)
|
||||
{ /* file_base_name(Stream,N) */
|
||||
Term t = Deref(ARG1);
|
||||
Atom at;
|
||||
if (IsVarTerm(t)) {
|
||||
Yap_Error(INSTANTIATION_ERROR, t, "file_base_name/2");
|
||||
return FALSE;
|
||||
}
|
||||
if (!IsAtomTerm(t)) {
|
||||
Yap_Error(TYPE_ERROR_ATOM, t, "file_base_name/2");
|
||||
return FALSE;
|
||||
}
|
||||
at = AtomOfTerm(t);
|
||||
if (IsWideAtom(at)) {
|
||||
wchar_t *c = RepAtom(at)->WStrOfAE;
|
||||
Int i = wcslen(c);
|
||||
while (i && !Yap_dir_separator((int)c[--i]));
|
||||
return Yap_unify(ARG2, MkAtomTerm(Yap_LookupWideAtom(c+i)));
|
||||
} else {
|
||||
char *c = RepAtom(at)->StrOfAE;
|
||||
Int i = strlen(c);
|
||||
while (i && !Yap_dir_separator((int)c[--i]));
|
||||
if (Yap_dir_separator((int)c[i])) {
|
||||
i++;
|
||||
}
|
||||
return Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(c+i)));
|
||||
}
|
||||
}
|
||||
|
||||
Term
|
||||
Yap_TermToString(Term t, char *s, unsigned int sz, int flags)
|
||||
{
|
||||
@ -6756,7 +6726,6 @@ Yap_InitIOPreds(void)
|
||||
Yap_InitCPred ("$has_readline", 0, p_has_readline, SafePredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$toupper", 2, p_toupper, SafePredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$tolower", 2, p_tolower, SafePredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("file_base_name", 2, p_file_base_name, SafePredFlag|HiddenPredFlag);
|
||||
|
||||
CurrentModule = SYSTEM_MODULE;
|
||||
Yap_InitCPred ("swi_format", 3, p_swi_format, SyncPredFlag);
|
||||
|
26
C/sysbits.c
26
C/sysbits.c
@ -2325,31 +2325,6 @@ p_mv (void)
|
||||
}
|
||||
|
||||
|
||||
/* find the directory info from a file name */
|
||||
static Int
|
||||
p_file_directory_name (void)
|
||||
{
|
||||
Term t1 = Deref(ARG1);
|
||||
char *chp;
|
||||
|
||||
if (IsVarTerm(t1)) {
|
||||
Yap_Error(INSTANTIATION_ERROR, t1, "first arg of file_directory_name/2");
|
||||
return FALSE;
|
||||
}
|
||||
if (!IsAtomTerm(t1)) {
|
||||
Yap_Error(TYPE_ERROR_ATOM, t1, "first arg of file_directory_name/2");
|
||||
return FALSE;
|
||||
}
|
||||
TrueFileName (RepAtom(AtomOfTerm(t1))->StrOfAE, NULL, Yap_FileNameBuf, FALSE);
|
||||
chp = Yap_FileNameBuf+strlen(Yap_FileNameBuf);
|
||||
while (!dir_separator(*--chp) && chp != Yap_FileNameBuf);
|
||||
if (chp == Yap_FileNameBuf) {
|
||||
return Yap_unify(MkAtomTerm(AtomDot),ARG2);
|
||||
}
|
||||
*chp = '\0';
|
||||
return Yap_unify(MkAtomTerm(Yap_LookupAtom(Yap_FileNameBuf)),ARG2);
|
||||
}
|
||||
|
||||
/* Change the working directory */
|
||||
static Int
|
||||
p_cd (void)
|
||||
@ -3324,7 +3299,6 @@ Yap_InitSysPreds(void)
|
||||
Yap_InitCPred ("$first_signal", 1, p_first_signal, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$host_type", 1, p_host_type, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$continue_signals", 0, p_continue_signals, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("file_directory_name", 2, p_file_directory_name, SafePredFlag);
|
||||
Yap_InitCPred ("$env_separator", 1, p_env_separator, SafePredFlag);
|
||||
Yap_InitCPred ("$unix", 0, p_unix, SafePredFlag);
|
||||
Yap_InitCPred ("$win32", 0, p_win32, SafePredFlag);
|
||||
|
18
pl/boot.yap
18
pl/boot.yap
@ -1359,6 +1359,20 @@ b_getval(GlobalVariable, Val) :-
|
||||
'$do_error'(existence_error(variable, GlobalVariable),b_getval(GlobalVariable, Val))
|
||||
).
|
||||
|
||||
access_file(File, Mode) :- swi_access_file(File, Mode).
|
||||
time_file(File, Time) :- swi_time_file(File, Time).
|
||||
access_file(File, Mode) :-
|
||||
swi_access_file(File, Mode).
|
||||
expand_file_name(Exp, Matches) :-
|
||||
swi_expand_file_name(Exp, Matches).
|
||||
file_base_name(File, Base) :-
|
||||
swi_file_base_name(File, Base).
|
||||
file_directory_name(File, Dir) :-
|
||||
swi_file_directory_name(File, Dir).
|
||||
file_name_extension(File, Name, Extension) :-
|
||||
swi_file_name_extension(File, Name, Extension).
|
||||
prolog_to_os_filename(Prolog, OS) :-
|
||||
swi_prolog_to_os_filename(Prolog, OS).
|
||||
time_file(File, Time) :-
|
||||
swi_time_file(File, Time).
|
||||
working_directory(OLD, NEW) :-
|
||||
swi_working_directory(OLD, NEW).
|
||||
|
||||
|
@ -1030,43 +1030,3 @@ make :-
|
||||
fail.
|
||||
make.
|
||||
|
||||
file_name_extension(A1,A2,F) :-
|
||||
var(F),
|
||||
nonvar(A1), nonvar(A2), !,
|
||||
atom_codes(A2, S2),
|
||||
(
|
||||
S2 = [0'.|_] %'
|
||||
;
|
||||
A2 = ''
|
||||
->
|
||||
atom_concat(A1, A2, F)
|
||||
;
|
||||
atom_concat([A1, '.', A2], F)
|
||||
).
|
||||
file_name_extension(A1,A2,F) :-
|
||||
var(F), !,
|
||||
'$do_error'(instantiation_error,file_name_extension(A1,A2,F)).
|
||||
file_name_extension(A1,A2,F) :-
|
||||
nonvar(A2), !,
|
||||
atom_codes(F, S),
|
||||
atom_codes(A2, S2),
|
||||
'$file_name_extension'(S, S1, E2),
|
||||
(
|
||||
S2 = [0'.|E2] %'
|
||||
->
|
||||
true
|
||||
;
|
||||
S2 = E2
|
||||
),
|
||||
atom_codes(A1, S1).
|
||||
file_name_extension(A1,A2,F) :-
|
||||
atom_codes(F, S),
|
||||
'$file_name_extension'(S, S1, S2),
|
||||
atom_codes(A2, S2),
|
||||
atom_codes(A1, S1).
|
||||
|
||||
'$file_name_extension'(S, S1, S2) :-
|
||||
lists:append(S1, [0'.|S2], S),
|
||||
\+ lists:append(_, [0'.|_], S2), !.
|
||||
'$file_name_extension'(S, S, []).
|
||||
|
||||
|
19
pl/yio.yap
19
pl/yio.yap
@ -1181,25 +1181,6 @@ with_output_to(Output, Command) :-
|
||||
atom_codes(Char, [Code]),
|
||||
'$codes_to_chars'(String0, String, Chars).
|
||||
|
||||
prolog_to_os_filename(Prolog, OS) :-
|
||||
'$undefined'(swi_prolog_to_os_filename(Prolog, OS), system),
|
||||
'$current_module'(Old, system),
|
||||
load_foreign_files([libplstream], [], initIO),
|
||||
'$current_module'(system, Old),
|
||||
fail.
|
||||
prolog_to_os_filename(Prolog, OS) :-
|
||||
system:swi_prolog_to_os_filename(Prolog, OS).
|
||||
|
||||
|
||||
expand_file_name(Exp, Matches) :-
|
||||
'$undefined'(swi_expand_file_name(Exp, Matches), system),
|
||||
'$current_module'(Old, system),
|
||||
load_foreign_files([libplstream], [], initIO),
|
||||
'$current_module'(system, Old),
|
||||
fail.
|
||||
expand_file_name(Exp, Matches) :-
|
||||
system:swi_expand_file_name(Exp, Matches).
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user