absolute_filename ^#%@%
This commit is contained in:
106
os/iopreds.c
106
os/iopreds.c
@@ -102,6 +102,31 @@ FILE *Yap_stdin;
|
||||
FILE *Yap_stdout;
|
||||
FILE *Yap_stderr;
|
||||
|
||||
static Term gethdir(Term t) {
|
||||
Atom aref = AtomOfTerm( t );
|
||||
char *s= RepAtom( aref )->StrOfAE;
|
||||
size_t nsz;
|
||||
|
||||
s = strncpy(LOCAL_FileNameBuf, RepAtom( aref )->StrOfAE, MAXPATHLEN-1);
|
||||
if (!s) {
|
||||
return false;
|
||||
}
|
||||
if (TermDot == t) {
|
||||
return TermEmptyAtom;
|
||||
}
|
||||
nsz = strlen(s);
|
||||
if (!Yap_dir_separator(s[nsz-1])) {
|
||||
#if _WIN32
|
||||
s[nsz] = '\\';
|
||||
#else
|
||||
s[nsz] = '/';
|
||||
#endif
|
||||
s[nsz+1] = '\0';
|
||||
}
|
||||
return
|
||||
MkAtomTerm(Yap_LookupAtom( s ) );
|
||||
}
|
||||
|
||||
static bool issolutions(Term t) {
|
||||
if (t == TermFirst || t == TermAll)
|
||||
return true;
|
||||
@@ -1355,10 +1380,11 @@ do_open(Term file_name, Term t2,
|
||||
/* get options */
|
||||
xarg *args = Yap_ArgListToVector(tlist, open_defs, OPEN_END);
|
||||
if (args == NULL) {
|
||||
if (LOCAL_Error_TYPE)
|
||||
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term,
|
||||
"option handling in open/3");
|
||||
return FALSE;
|
||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG)
|
||||
LOCAL_Error_TYPE = DOMAIN_ERROR_OPEN_OPTION;
|
||||
Yap_Error( LOCAL_Error_TYPE, LOCAL_Error_Term, "option handling in open/3" );
|
||||
}
|
||||
}
|
||||
/* done */
|
||||
sno = GetFreeStreamD();
|
||||
@@ -1384,8 +1410,12 @@ do_open(Term file_name, Term t2,
|
||||
: false) ||
|
||||
trueGlobalPrologFlag(OPEN_EXPANDS_FILENAME_FLAG);
|
||||
// expand file name?
|
||||
fname = Yap_AbsoluteFile(fname, LOCAL_FileNameBuf, ok);
|
||||
fname = Yap_AbsoluteFile(fname, ok);
|
||||
if (fname) {
|
||||
st->name = Yap_LookupAtom(fname);
|
||||
} else {
|
||||
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, ARG1, NULL);
|
||||
}
|
||||
|
||||
// Skip scripts that start with !#/.. or similar
|
||||
bool script = (args[OPEN_SCRIPT].used
|
||||
@@ -1432,6 +1462,9 @@ do_open(Term file_name, Term t2,
|
||||
}
|
||||
if ((fd = fopen(fname, io_mode)) == NULL ||
|
||||
(!(flags & Binary_Stream_f) && binary_file(fname))) {
|
||||
strncpy( LOCAL_FileNameBuf, fname,MAXPATHLEN);
|
||||
free( (void *)fname );
|
||||
fname = LOCAL_FileNameBuf;
|
||||
UNLOCK(st->streamlock);
|
||||
if (errno == ENOENT)
|
||||
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s: %s", fname,
|
||||
@@ -1829,8 +1862,15 @@ static Int close2(USES_REGS1) { /* '$close'(+GLOBAL_Stream) */
|
||||
}
|
||||
xarg *args =
|
||||
Yap_ArgListToVector((tlist = Deref(ARG2)), close_defs, CLOSE_END);
|
||||
if (args == NULL)
|
||||
if (args == NULL) {
|
||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG)
|
||||
LOCAL_Error_TYPE = DOMAIN_ERROR_CLOSE_OPTION;
|
||||
Yap_Error( LOCAL_Error_TYPE, LOCAL_Error_Term, NULL );
|
||||
}
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
// if (args[CLOSE_FORCE].used) {
|
||||
// }
|
||||
Yap_CloseStream(sno);
|
||||
@@ -1854,8 +1894,8 @@ Term read_line(int sno) {
|
||||
PAR("access", isatom, ABSOLUTE_FILE_NAME_ACCESS), \
|
||||
PAR("expand", booleanFlag, ABSOLUTE_FILE_NAME_EXPAND), \
|
||||
PAR("extensions", ok, ABSOLUTE_FILE_NAME_EXTENSIONS), \
|
||||
PAR("file_type", is_file_type, ABSOLUTE_FILE_NAME_FILE_TYPE), \
|
||||
PAR("file_errors", is_file_errors, ABSOLUTE_FILE_NAME_FILE_ERRORS), \
|
||||
PAR("file_type", is_file_type, ABSOLUTE_FILE_NAME_FILE_TYPE), \
|
||||
PAR("glob", ok, ABSOLUTE_FILE_NAME_GLOB), \
|
||||
PAR("relative_to", isatom, ABSOLUTE_FILE_NAME_RELATIVE_TO), \
|
||||
PAR("solutions", issolutions, ABSOLUTE_FILE_NAME_SOLUTIONS), \
|
||||
@@ -1884,19 +1924,28 @@ static Int abs_file_parameters(USES_REGS1) {
|
||||
/* get options */
|
||||
xarg *args = Yap_ArgListToVector(tlist, absolute_file_name_search_defs,
|
||||
ABSOLUTE_FILE_NAME_END);
|
||||
if (args == NULL)
|
||||
return FALSE;
|
||||
if (args == NULL) {
|
||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG)
|
||||
LOCAL_Error_TYPE = DOMAIN_ERROR_ABSOLUTE_FILE_NAME_OPTION;
|
||||
Yap_Error( LOCAL_Error_TYPE, LOCAL_Error_Term, NULL );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/* done */
|
||||
if (args[ABSOLUTE_FILE_NAME_EXTENSIONS].used)
|
||||
if (args[ABSOLUTE_FILE_NAME_EXTENSIONS].used) {
|
||||
t[ABSOLUTE_FILE_NAME_EXTENSIONS] =
|
||||
args[ABSOLUTE_FILE_NAME_EXTENSIONS].tvalue;
|
||||
else
|
||||
} else {
|
||||
t[ABSOLUTE_FILE_NAME_EXTENSIONS] = TermNil;
|
||||
if (args[ABSOLUTE_FILE_NAME_RELATIVE_TO].used)
|
||||
}
|
||||
if (args[ABSOLUTE_FILE_NAME_RELATIVE_TO].used) {
|
||||
t[ABSOLUTE_FILE_NAME_RELATIVE_TO] =
|
||||
args[ABSOLUTE_FILE_NAME_RELATIVE_TO].tvalue;
|
||||
else
|
||||
t[ABSOLUTE_FILE_NAME_RELATIVE_TO] = TermEmptyAtom;
|
||||
gethdir( args[ABSOLUTE_FILE_NAME_RELATIVE_TO].tvalue );
|
||||
} else {
|
||||
t[ABSOLUTE_FILE_NAME_RELATIVE_TO] =
|
||||
gethdir( TermDot );
|
||||
}
|
||||
if (args[ABSOLUTE_FILE_NAME_FILE_TYPE].used)
|
||||
t[ABSOLUTE_FILE_NAME_FILE_TYPE] = args[ABSOLUTE_FILE_NAME_FILE_TYPE].tvalue;
|
||||
else
|
||||
@@ -1937,28 +1986,11 @@ static Int get_abs_file_parameter(USES_REGS1) {
|
||||
Term t = Deref(ARG1), topts = ARG2;
|
||||
/* get options */
|
||||
/* done */
|
||||
if (t == TermExtensions)
|
||||
return Yap_unify(ARG3, ArgOfTerm(ABSOLUTE_FILE_NAME_EXTENSIONS + 1, topts));
|
||||
if (t == TermRelativeTo)
|
||||
return Yap_unify(ARG3,
|
||||
ArgOfTerm(ABSOLUTE_FILE_NAME_RELATIVE_TO + 1, topts));
|
||||
if (t == TermFileType)
|
||||
return Yap_unify(ARG3, ArgOfTerm(ABSOLUTE_FILE_NAME_FILE_TYPE + 1, topts));
|
||||
if (t == TermAccess)
|
||||
return Yap_unify(ARG3, ArgOfTerm(ABSOLUTE_FILE_NAME_ACCESS + 1, topts));
|
||||
if (t == TermFileErrors)
|
||||
return Yap_unify(ARG3,
|
||||
ArgOfTerm(ABSOLUTE_FILE_NAME_FILE_ERRORS + 1, topts));
|
||||
if (t == TermSolutions)
|
||||
return Yap_unify(ARG3, ArgOfTerm(ABSOLUTE_FILE_NAME_SOLUTIONS + 1, topts));
|
||||
if (t == TermGlob)
|
||||
return Yap_unify(ARG3, ArgOfTerm(ABSOLUTE_FILE_NAME_GLOB + 1, topts));
|
||||
if (t == TermExpand)
|
||||
return Yap_unify(ARG3, ArgOfTerm(ABSOLUTE_FILE_NAME_EXPAND + 1, topts));
|
||||
if (t == TermVerboseFileSearch)
|
||||
return Yap_unify(
|
||||
ARG3, ArgOfTerm(ABSOLUTE_FILE_NAME_VERBOSE_FILE_SEARCH + 1, topts));
|
||||
Yap_Error(DOMAIN_ERROR_ABSOLUTE_FILE_NAME_OPTION, ARG2, NULL);
|
||||
int i = Yap_ArgKey( AtomOfTerm( t ), absolute_file_name_search_defs,
|
||||
ABSOLUTE_FILE_NAME_END );
|
||||
if (i >= 0)
|
||||
return Yap_unify(ARG3, ArgOfTerm(i + 1, topts));
|
||||
Yap_Error(DOMAIN_ERROR_ABSOLUTE_FILE_NAME_OPTION, ARG1, NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ bool Yap_InitReadline(Term enable) {
|
||||
#endif
|
||||
rl_outstream = stderr;
|
||||
using_history();
|
||||
const char *s = Yap_AbsoluteFile("~/.YAP.history", NULL, true);
|
||||
const char *s = Yap_AbsoluteFile("~/.YAP.history", true);
|
||||
if (!read_history(s)) {
|
||||
FILE *f = fopen(s, "w");
|
||||
if (f) {
|
||||
|
||||
@@ -639,23 +639,23 @@ static bool complete_processing(FEnv *fe, TokEntry *tokstart) {
|
||||
CurrentModule = fe->cmod;
|
||||
if (CurrentModule == TermProlog)
|
||||
CurrentModule = PROLOG_MODULE;
|
||||
if (fe->vp)
|
||||
if (fe->t && fe->vp)
|
||||
v1 = get_variables(fe, tokstart);
|
||||
else
|
||||
v1 = 0L;
|
||||
if (fe->np)
|
||||
if (fe->t && fe->np)
|
||||
v2 = get_varnames(fe, tokstart);
|
||||
else
|
||||
v2 = 0L;
|
||||
if (fe->sp)
|
||||
if (fe->t && fe->sp)
|
||||
v3 = get_singletons(fe, tokstart);
|
||||
else
|
||||
v3 = 0L;
|
||||
if (fe->tcomms)
|
||||
if (fe->t && fe->tcomms)
|
||||
vc = LOCAL_Comments;
|
||||
else
|
||||
vc = 0L;
|
||||
if (fe->tp)
|
||||
if (fe->t && fe->tp)
|
||||
tp = get_stream_position(fe, tokstart );
|
||||
else
|
||||
tp = 0L;
|
||||
@@ -679,22 +679,22 @@ static bool complete_clause_processing(FEnv *fe, TokEntry
|
||||
CurrentModule = fe->cmod;
|
||||
if (CurrentModule == TermProlog)
|
||||
CurrentModule = PROLOG_MODULE;
|
||||
if (fe->vp)
|
||||
if (fe->t && fe->vp)
|
||||
v_vp = get_variables(fe, tokstart);
|
||||
else
|
||||
v_vp = 0L;
|
||||
if (fe->np)
|
||||
if (fe->t && fe->np)
|
||||
v_vnames = get_varnames(fe, tokstart);
|
||||
else
|
||||
v_vnames = 0L;
|
||||
if (trueLocalPrologFlag(SINGLE_VAR_WARNINGS_FLAG)) {
|
||||
if (fe->t && trueLocalPrologFlag(SINGLE_VAR_WARNINGS_FLAG)) {
|
||||
warn_singletons(fe, tokstart);
|
||||
}
|
||||
if (fe->tcomms)
|
||||
if (fe->t && fe->tcomms)
|
||||
v_comments = LOCAL_Comments;
|
||||
else
|
||||
v_comments = 0L;
|
||||
if (fe->tp)
|
||||
if (fe->t && fe->tp)
|
||||
v_pos = get_stream_position(fe, tokstart );
|
||||
else
|
||||
v_pos = 0L;
|
||||
@@ -813,7 +813,9 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) {
|
||||
return YAP_PARSING;
|
||||
}
|
||||
if (LOCAL_tokptr->Tok == eot_tok && LOCAL_tokptr->TokInfo == TermNl) {
|
||||
LOCAL_ErrorMessage = "Empty clause";
|
||||
char *out = malloc( strlen("Empty clause" + 1 ) );
|
||||
strcpy( out, "Empty clause" );
|
||||
LOCAL_ErrorMessage = out;
|
||||
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
||||
LOCAL_Error_Term = TermEof;
|
||||
return YAP_PARSING_ERROR;
|
||||
@@ -878,7 +880,8 @@ static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) {
|
||||
} else {
|
||||
Term terr = Yap_syntax_error(fe->toklast, inp_stream);
|
||||
if (ParserErrorStyle == TermError) {
|
||||
LOCAL_ErrorMessage = "SYNTAX ERROR";
|
||||
LOCAL_ErrorMessage = NULL;
|
||||
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
||||
Yap_Error(SYNTAX_ERROR, terr, LOCAL_ErrorMessage);
|
||||
return YAP_PARSING_FINISHED;
|
||||
} else {
|
||||
@@ -933,7 +936,7 @@ Term Yap_read_term(int inp_stream, Term opts, int nargs) {
|
||||
#endif
|
||||
|
||||
parser_state_t state = YAP_START_PARSING;
|
||||
while (state != YAP_PARSING_FINISHED) {
|
||||
while (true) {
|
||||
switch (state) {
|
||||
case YAP_START_PARSING:
|
||||
state = initParser(opts, &fe, &re, inp_stream, nargs);
|
||||
@@ -951,21 +954,26 @@ Term Yap_read_term(int inp_stream, Term opts, int nargs) {
|
||||
state = parseError(&re, &fe, inp_stream);
|
||||
break;
|
||||
case YAP_PARSING_FINISHED:
|
||||
break;
|
||||
{
|
||||
CACHE_REGS
|
||||
bool done;
|
||||
if (fe.reading_clause)
|
||||
done = complete_clause_processing(&fe, LOCAL_tokptr);
|
||||
else
|
||||
done = complete_processing(&fe, LOCAL_tokptr);
|
||||
if (!done) {
|
||||
state = YAP_PARSING_ERROR;
|
||||
fe.t = 0;
|
||||
break;
|
||||
}
|
||||
#if EMACS
|
||||
first_char = tokstart->TokPos;
|
||||
#endif /* EMACS */
|
||||
return fe.t;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
CACHE_REGS
|
||||
if (fe.reading_clause &&
|
||||
!complete_clause_processing(&fe, LOCAL_tokptr))
|
||||
fe.t = 0;
|
||||
else if (!fe.reading_clause && !complete_processing(&fe, LOCAL_tokptr))
|
||||
fe.t = 0;
|
||||
}
|
||||
#if EMACS
|
||||
first_char = tokstart->TokPos;
|
||||
#endif /* EMACS */
|
||||
return fe.t;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Int
|
||||
@@ -1113,11 +1121,11 @@ static Int read_clause2(USES_REGS1) {
|
||||
* + The `syntax_errors` flag controls response to syntactic errors, the
|
||||
*default is `dec10`.
|
||||
*
|
||||
* The next two options are called implicitly:plwae
|
||||
* The next two options are called implicitly:
|
||||
*
|
||||
* + The `module` option is initialized to the current source module, by
|
||||
*default.
|
||||
* + The `tons` option is set from the single var flag
|
||||
* + The `singletons` option is set from the single var flag
|
||||
*/
|
||||
static Int read_clause(
|
||||
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
||||
|
||||
17
os/streams.c
17
os/streams.c
@@ -567,6 +567,11 @@ static Int cont_stream_property(USES_REGS1) { /* current_stream */
|
||||
args = Yap_ArgListToVector(Deref(ARG2), stream_property_defs,
|
||||
STREAM_PROPERTY_END);
|
||||
if (args == NULL) {
|
||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG)
|
||||
LOCAL_Error_TYPE = DOMAIN_ERROR_STREAM_PROPERTY_OPTION;
|
||||
Yap_Error( LOCAL_Error_TYPE, LOCAL_Error_Term, NULL );
|
||||
}
|
||||
cut_fail();
|
||||
}
|
||||
LOCK(GLOBAL_StreamDescLock);
|
||||
@@ -628,8 +633,13 @@ static Int stream_property(USES_REGS1) { /* Init current_stream */
|
||||
cut_fail();
|
||||
}
|
||||
args = Yap_ArgListToVector(Deref(ARG2), stream_property_defs,
|
||||
STREAM_PROPERTY_END);
|
||||
STREAM_PROPERTY_END);
|
||||
if (args == NULL) {
|
||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG)
|
||||
LOCAL_Error_TYPE = DOMAIN_ERROR_STREAM_PROPERTY_OPTION;
|
||||
Yap_Error( LOCAL_Error_TYPE, LOCAL_Error_Term, NULL );
|
||||
}
|
||||
UNLOCK(GLOBAL_Stream[i].streamlock);
|
||||
cut_fail();
|
||||
}
|
||||
@@ -682,6 +692,11 @@ static bool do_set_stream(int sno,
|
||||
|
||||
args = Yap_ArgListToVector(opts, set_stream_defs, SET_STREAM_END);
|
||||
if (args == NULL) {
|
||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG)
|
||||
LOCAL_Error_TYPE = DOMAIN_ERROR_SET_STREAM_OPTION;
|
||||
Yap_Error( LOCAL_Error_TYPE, LOCAL_Error_Term, NULL );
|
||||
}
|
||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||
return false;
|
||||
}
|
||||
|
||||
2740
os/sysbits.c
2740
os/sysbits.c
File diff suppressed because it is too large
Load Diff
@@ -114,7 +114,7 @@ int Yap_growtrail_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
|
||||
|
||||
bool Yap_IsAbsolutePath(const char *p);
|
||||
Atom Yap_TemporaryFile(const char *prefix, int *fd);
|
||||
const char *Yap_AbsoluteFile(const char *spec, char *tmp, bool expand);
|
||||
const char *Yap_AbsoluteFile(const char *spec, bool expand);
|
||||
|
||||
typedef enum mem_buf_source {
|
||||
MEM_BUF_CODE = 1,
|
||||
|
||||
Reference in New Issue
Block a user