mostly indenting

This commit is contained in:
Vítor Santos Costa 2015-10-05 10:33:52 +01:00
parent e5fc818c37
commit 166d4892f9

View File

@ -360,7 +360,7 @@ Yap_InitStdStreams (void)
Int Int
PlIOError__ (const char *function, int lineno, const char *file, yap_error_number type, Term culprit, ...) PlIOError__ (const char *file, const char *function, int lineno, yap_error_number type, Term culprit, ...)
{ {
if (trueLocalPrologFlag(FILEERRORS_FLAG) == MkIntTerm(1) || if (trueLocalPrologFlag(FILEERRORS_FLAG) == MkIntTerm(1) ||
@ -373,7 +373,7 @@ PlIOError__ (const char *function, int lineno, const char *file, yap_error_numbe
format = va_arg(args, char *); format = va_arg(args, char *);
vsnprintf(who, 1023, format, args); vsnprintf(who, 1023, format, args);
va_end( args ); va_end( args );
Yap_Error__(function, lineno,file, type, culprit, who); Yap_Error__(file, function, lineno, type, culprit, who);
/* and fail */ /* and fail */
return FALSE; return FALSE;
} else { } else {
@ -1229,11 +1229,11 @@ binary_file(char *file_name)
#else #else
return(FALSE); return(FALSE);
#endif #endif
} }
static int static int
write_bom(int sno, StreamDesc *st) write_bom(int sno, StreamDesc *st)
{ {
/* dump encoding */ /* dump encoding */
switch (st->encoding) { switch (st->encoding) {
case ENC_ISO_UTF8: case ENC_ISO_UTF8:
@ -1278,12 +1278,12 @@ binary_file(char *file_name)
default: default:
return TRUE; return TRUE;
} }
} }
static void static void
check_bom(int sno, StreamDesc *st) check_bom(int sno, StreamDesc *st)
{ {
int ch; int ch;
@ -1407,11 +1407,11 @@ binary_file(char *file_name)
st->stream_gets = DefaultGets; st->stream_gets = DefaultGets;
return; return;
} }
} }
static bool static bool
initStream(int sno, FILE *fd, const char *name, Term file_name, encoding_t encoding, stream_flags_t flags, Atom open_mode ) initStream(int sno, FILE *fd, const char *name, Term file_name, encoding_t encoding, stream_flags_t flags, Atom open_mode )
{ {
StreamDesc *st = &GLOBAL_Stream[sno]; StreamDesc *st = &GLOBAL_Stream[sno];
st->status = flags; st->status = flags;
@ -1449,47 +1449,47 @@ binary_file(char *file_name)
#define OPEN_DEFS() \ #define OPEN_DEFS() \
PAR( "alias", isatom, OPEN_ALIAS), \ PAR( "alias", isatom, OPEN_ALIAS), \
PAR( "bom", boolean, OPEN_BOM ), \ PAR( "bom", boolean, OPEN_BOM ), \
PAR( "buffer", isatom, OPEN_BUFFER ), \ PAR( "buffer", isatom, OPEN_BUFFER ), \
PAR( "close_on_abort", boolean, OPEN_CLOSE_ON_ABORT ), \ PAR( "close_on_abort", boolean, OPEN_CLOSE_ON_ABORT ), \
PAR( "create", isatom, OPEN_CREATE ), \ PAR( "create", isatom, OPEN_CREATE ), \
PAR( "encoding", isatom, OPEN_ENCODING ), \ PAR( "encoding", isatom, OPEN_ENCODING ), \
PAR( "eof_action", isatom, OPEN_EOF_ACTION ), \ PAR( "eof_action", isatom, OPEN_EOF_ACTION ), \
PAR( "expand_filename", boolean, OPEN_EXPAND_FILENAME ), \ PAR( "expand_filename", boolean, OPEN_EXPAND_FILENAME ), \
PAR( "file_name", isatom, OPEN_FILE_NAME ), \ PAR( "file_name", isatom, OPEN_FILE_NAME ), \
PAR( "input", ok, OPEN_INPUT ), \ PAR( "input", ok, OPEN_INPUT ), \
PAR( "locale", isatom, OPEN_LOCALE ), \ PAR( "locale", isatom, OPEN_LOCALE ), \
PAR( "lock", isatom, OPEN_LOCK ), \ PAR( "lock", isatom, OPEN_LOCK ), \
PAR( "mode", isatom, OPEN_MODE ), \ PAR( "mode", isatom, OPEN_MODE ), \
PAR( "output", ok, OPEN_OUTPUT ), \ PAR( "output", ok, OPEN_OUTPUT ), \
PAR( "representation_errors", boolean, OPEN_REPRESENTATION_ERRORS ), \ PAR( "representation_errors", boolean, OPEN_REPRESENTATION_ERRORS ), \
PAR( "reposition", boolean, OPEN_REPOSITION ), \ PAR( "reposition", boolean, OPEN_REPOSITION ), \
PAR( "type", isatom, OPEN_TYPE ), \ PAR( "type", isatom, OPEN_TYPE ), \
PAR( "wait", boolean, OPEN_WAIT ), \ PAR( "wait", boolean, OPEN_WAIT ), \
PAR( NULL, ok, OPEN_END ) PAR( NULL, ok, OPEN_END )
#define PAR(x,y,z) z #define PAR(x,y,z) z
typedef enum open_enum_choices typedef enum open_enum_choices
{ {
OPEN_DEFS() OPEN_DEFS()
} open_choices_t; } open_choices_t;
#undef PAR #undef PAR
#define PAR(x,y,z) { x , y, z } #define PAR(x,y,z) { x , y, z }
static const param_t open_defs[] = static const param_t open_defs[] =
{ {
OPEN_DEFS() OPEN_DEFS()
}; };
#undef PAR #undef PAR
static Int static Int
do_open ( Term file_name, Term t2, Term tlist USES_REGS ) do_open ( Term file_name, Term t2, Term tlist USES_REGS )
{ /* '$open'(+File,+Mode,?Stream,-ReturnCode) */ { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
Atom open_mode; Atom open_mode;
int sno; int sno;
SMALLUNSGN s; SMALLUNSGN s;
@ -1676,7 +1676,7 @@ binary_file(char *file_name)
Term t = Yap_MkStream (sno); Term t = Yap_MkStream (sno);
return (Yap_unify (ARG3, t)); return (Yap_unify (ARG3, t));
} }
} }
static Int static Int
open3 ( USES_REGS1 ) open3 ( USES_REGS1 )
@ -1690,9 +1690,9 @@ open4 ( USES_REGS1 )
return do_open(Deref(ARG1), Deref(ARG2), Deref( ARG4 ) PASS_REGS ); return do_open(Deref(ARG1), Deref(ARG2), Deref( ARG4 ) PASS_REGS );
} }
static Int static Int
p_file_expansion (USES_REGS1) p_file_expansion (USES_REGS1)
{ /* '$file_expansion'(+File,-Name) */ { /* '$file_expansion'(+File,-Name) */
Term file_name = Deref(ARG1); Term file_name = Deref(ARG1);
/* we know file_name is bound */ /* we know file_name is bound */
@ -1703,11 +1703,11 @@ open4 ( USES_REGS1 )
if (!Yap_TrueFileName (RepAtom (AtomOfTerm (file_name))->StrOfAE, LOCAL_FileNameBuf, FALSE)) if (!Yap_TrueFileName (RepAtom (AtomOfTerm (file_name))->StrOfAE, LOCAL_FileNameBuf, FALSE))
return (PlIOError (EXISTENCE_ERROR_SOURCE_SINK,file_name,"absolute_file_name/3")); return (PlIOError (EXISTENCE_ERROR_SOURCE_SINK,file_name,"absolute_file_name/3"));
return(Yap_unify(ARG2,MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)))); return(Yap_unify(ARG2,MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))));
} }
static Int static Int
p_open_null_stream (USES_REGS1) p_open_null_stream (USES_REGS1)
{ {
Term t; Term t;
StreamDesc *st; StreamDesc *st;
int sno = GetFreeStreamD(); int sno = GetFreeStreamD();
@ -1741,9 +1741,9 @@ open4 ( USES_REGS1 )
UNLOCK(st->streamlock); UNLOCK(st->streamlock);
t = Yap_MkStream (sno); t = Yap_MkStream (sno);
return (Yap_unify (ARG1, t)); return (Yap_unify (ARG1, t));
} }
int int
Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags) Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
{ {
CACHE_REGS CACHE_REGS
@ -1762,11 +1762,11 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
at = AtomRead; at = AtomRead;
initStream(sno, fd, name, file_name, LOCAL_encoding, flags, at ); initStream(sno, fd, name, file_name, LOCAL_encoding, flags, at );
return sno; return sno;
} }
static int static int
CheckStream (Term arg, int kind, const char *msg) CheckStream (Term arg, int kind, const char *msg)
{ {
int sno = -1; int sno = -1;
arg = Deref (arg); arg = Deref (arg);
if (IsVarTerm (arg)) { if (IsVarTerm (arg)) {
@ -1787,11 +1787,13 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
sname = AtomUserOut; sname = AtomUserOut;
} }
} }
LOCK(GLOBAL_StreamDescLock); if ((sno = Yap_CheckAlias(sname)) < 0) {
if ((sno = Yap_CheckAlias(sname)) == -1) { UNLOCK(GLOBAL_Stream[sno].streamlock);
UNLOCK(GLOBAL_StreamDescLock);
Yap_Error(EXISTENCE_ERROR_STREAM, arg, msg); Yap_Error(EXISTENCE_ERROR_STREAM, arg, msg);
return -1; return -1;
} else {
LOCK(GLOBAL_Stream[sno].streamlock);
return sno;
} }
} else if (IsApplTerm (arg) && FunctorOfTerm (arg) == FunctorStream) { } else if (IsApplTerm (arg) && FunctorOfTerm (arg) == FunctorStream) {
arg = ArgOfTerm (1, arg); arg = ArgOfTerm (1, arg);
@ -1802,17 +1804,14 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
if (sno < 0) if (sno < 0)
{ {
Yap_Error(DOMAIN_ERROR_STREAM_OR_ALIAS, arg, msg); Yap_Error(DOMAIN_ERROR_STREAM_OR_ALIAS, arg, msg);
UNLOCK(GLOBAL_StreamDescLock);
return (-1); return (-1);
} }
if (GLOBAL_Stream[sno].status & Free_Stream_f) if (GLOBAL_Stream[sno].status & Free_Stream_f)
{ {
PlIOError(EXISTENCE_ERROR_STREAM, arg, msg); PlIOError(EXISTENCE_ERROR_STREAM, arg, msg);
UNLOCK(GLOBAL_StreamDescLock);
return (-1); return (-1);
} }
LOCK(GLOBAL_Stream[sno].streamlock); LOCK(GLOBAL_Stream[sno].streamlock);
UNLOCK(GLOBAL_StreamDescLock);
if ((GLOBAL_Stream[sno].status & kind) == 0) if ((GLOBAL_Stream[sno].status & kind) == 0)
{ {
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
@ -1823,19 +1822,19 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
return (-1); return (-1);
} }
return (sno); return (sno);
} }
int int
Yap_CheckStream (Term arg, int kind, const char *msg) Yap_CheckStream (Term arg, int kind, const char *msg)
{ {
return CheckStream(arg, kind, (char *)msg); return CheckStream(arg, kind, (char *)msg);
} }
static Int static Int
always_prompt_user( USES_REGS1 ) always_prompt_user( USES_REGS1 )
{ {
StreamDesc *s = GLOBAL_Stream+StdInStream; StreamDesc *s = GLOBAL_Stream+StdInStream;
s->status |= Promptable_Stream_f; s->status |= Promptable_Stream_f;
@ -1849,12 +1848,12 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
} else } else
Yap_ConsoleOps( s ); Yap_ConsoleOps( s );
return(TRUE); return(TRUE);
} }
static Int static Int
close1 (USES_REGS1) close1 (USES_REGS1)
{ /* '$close'(+GLOBAL_Stream) */ { /* '$close'(+GLOBAL_Stream) */
Int sno = CheckStream (ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f), "close/2"); Int sno = CheckStream (ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f), "close/2");
if (sno < 0) if (sno < 0)
return (FALSE); return (FALSE);
@ -1865,33 +1864,33 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
Yap_CloseStream(sno); Yap_CloseStream(sno);
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
return (TRUE); return (TRUE);
} }
#define CLOSE_DEFS() \ #define CLOSE_DEFS() \
PAR( "force", boolean, CLOSE_FORCE), \ PAR( "force", boolean, CLOSE_FORCE), \
PAR( NULL, ok, CLOSE_END ) PAR( NULL, ok, CLOSE_END )
#define PAR(x,y,z) z #define PAR(x,y,z) z
typedef enum close_enum_choices typedef enum close_enum_choices
{ {
CLOSE_DEFS() CLOSE_DEFS()
} close_choices_t; } close_choices_t;
#undef PAR #undef PAR
#define PAR(x,y,z) { x , y, z } #define PAR(x,y,z) { x , y, z }
static const param_t close_defs[] = static const param_t close_defs[] =
{ {
CLOSE_DEFS() CLOSE_DEFS()
}; };
#undef PAR #undef PAR
static Int static Int
close2 (USES_REGS1) close2 (USES_REGS1)
{ /* '$close'(+GLOBAL_Stream) */ { /* '$close'(+GLOBAL_Stream) */
Int sno = CheckStream (ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f), "close/2"); Int sno = CheckStream (ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f), "close/2");
Term tlist; Term tlist;
if (sno < 0) if (sno < 0)
@ -1908,12 +1907,12 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
Yap_CloseStream(sno); Yap_CloseStream(sno);
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
return (TRUE); return (TRUE);
} }
Term Term
read_line(int sno) read_line(int sno)
{ {
CACHE_REGS CACHE_REGS
Term tail; Term tail;
Int ch; Int ch;
@ -1923,41 +1922,41 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
} }
tail = read_line(sno); tail = read_line(sno);
return(MkPairTerm(MkIntTerm(ch),tail)); return(MkPairTerm(MkIntTerm(ch),tail));
} }
#define ABSOLUTE_FILE_NAME_DEFS() \ #define ABSOLUTE_FILE_NAME_DEFS() \
PAR( "extensions", ok, ABSOLUTE_FILE_NAME_EXTENSIONS), \ PAR( "extensions", ok, ABSOLUTE_FILE_NAME_EXTENSIONS), \
PAR( "relative_to", isatom, ABSOLUTE_FILE_NAME_RELATIVE_TO ), \ PAR( "relative_to", isatom, ABSOLUTE_FILE_NAME_RELATIVE_TO ), \
PAR( "access", isatom, ABSOLUTE_FILE_NAME_ACCESS ), \ PAR( "access", isatom, ABSOLUTE_FILE_NAME_ACCESS ), \
PAR( "file_type", is_file_type, ABSOLUTE_FILE_NAME_FILE_TYPE ), \ PAR( "file_type", is_file_type, ABSOLUTE_FILE_NAME_FILE_TYPE ), \
PAR( "file_errors", is_file_errors, ABSOLUTE_FILE_NAME_FILE_ERRORS ), \ PAR( "file_errors", is_file_errors, ABSOLUTE_FILE_NAME_FILE_ERRORS ), \
PAR( "solutions", issolutions, ABSOLUTE_FILE_NAME_SOLUTIONS ), \ PAR( "solutions", issolutions, ABSOLUTE_FILE_NAME_SOLUTIONS ), \
PAR( "expand", boolean, ABSOLUTE_FILE_NAME_EXPAND ), \ PAR( "expand", boolean, ABSOLUTE_FILE_NAME_EXPAND ), \
PAR( "verbose_file_search", boolean, ABSOLUTE_FILE_NAME_VERBOSE_FILE_SEARCH), \ PAR( "verbose_file_search", boolean, ABSOLUTE_FILE_NAME_VERBOSE_FILE_SEARCH), \
PAR( NULL, ok, ABSOLUTE_FILE_NAME_END ) PAR( NULL, ok, ABSOLUTE_FILE_NAME_END )
#define PAR(x,y,z) z #define PAR(x,y,z) z
typedef enum ABSOLUTE_FILE_NAME_enum_ typedef enum ABSOLUTE_FILE_NAME_enum_
{ {
ABSOLUTE_FILE_NAME_DEFS() ABSOLUTE_FILE_NAME_DEFS()
} absolute_file_name_choices_t; } absolute_file_name_choices_t;
#undef PAR #undef PAR
#define PAR(x,y,z) { x , y, z } #define PAR(x,y,z) { x , y, z }
static const param_t absolute_file_name_search_defs[] = static const param_t absolute_file_name_search_defs[] =
{ {
ABSOLUTE_FILE_NAME_DEFS() ABSOLUTE_FILE_NAME_DEFS()
}; };
#undef PAR #undef PAR
static Int abs_file_parameters ( USES_REGS1 ) static Int abs_file_parameters ( USES_REGS1 )
{ {
Term t[ABSOLUTE_FILE_NAME_END]; Term t[ABSOLUTE_FILE_NAME_END];
Term tlist = Deref(ARG1), tf; Term tlist = Deref(ARG1), tf;
/* get options */ /* get options */
@ -2003,7 +2002,7 @@ static Int abs_file_parameters ( USES_REGS1 )
} }
static Int get_abs_file_parameter ( USES_REGS1 ) static Int get_abs_file_parameter ( USES_REGS1 )
{ {
Term t = Deref(ARG1), topts = ARG2; Term t = Deref(ARG1), topts = ARG2;
/* get options */ /* get options */
/* done */ /* done */
@ -2027,9 +2026,9 @@ static Int get_abs_file_parameter ( USES_REGS1 )
} }
void void
Yap_InitPlIO (void) Yap_InitPlIO (void)
{ {
Int i; Int i;
Yap_stdin = stdin; Yap_stdin = stdin;
@ -2041,11 +2040,11 @@ static Int get_abs_file_parameter ( USES_REGS1 )
GLOBAL_Stream[i].status = Free_Stream_f; GLOBAL_Stream[i].status = Free_Stream_f;
} }
InitStdStreams(); InitStdStreams();
} }
void void
Yap_InitIOPreds(void) Yap_InitIOPreds(void)
{ {
/* here the Input/Output predicates */ /* here the Input/Output predicates */
Yap_InitCPred ("always_prompt_user", 0, always_prompt_user, SafePredFlag|SyncPredFlag); Yap_InitCPred ("always_prompt_user", 0, always_prompt_user, SafePredFlag|SyncPredFlag);
Yap_InitCPred ("close", 1, close1, SafePredFlag|SyncPredFlag); Yap_InitCPred ("close", 1, close1, SafePredFlag|SyncPredFlag);
@ -2070,4 +2069,4 @@ static Int get_abs_file_parameter ( USES_REGS1 )
Yap_InitReadline(); Yap_InitReadline();
Yap_InitSockets(); Yap_InitSockets();
Yap_InitSysPreds(); Yap_InitSysPreds();
} }