indenting

This commit is contained in:
Vitor Santos Costa 2016-04-05 08:12:16 +01:00
parent 55a840e2d8
commit b89f6e55b4

View File

@ -25,7 +25,8 @@
*
*/
/*
* This file includes the interface to the console IO, tty style. Refer also to the readline library.
* This file includes the interface to the console IO, tty style. Refer also to
the readline library.
* @defgroup console Support for console-based interaction.
* @ingroup InputOutput
@ -40,9 +41,7 @@ static int ConsoleGetc( int);
static int ConsolePutc(int, int);
/* check if we read a newline or an EOF */
int
console_post_process_read_char(int ch, StreamDesc *s)
{
int console_post_process_read_char(int ch, StreamDesc *s) {
/* the character is also going to be output by the console handler */
console_count_output_char(ch, GLOBAL_Stream + StdErrStream);
if (ch == '\n') {
@ -60,21 +59,16 @@ console_post_process_read_char(int ch, StreamDesc *s)
return ch;
}
bool
is_same_tty(FILE *f1, FILE *f2)
{
bool is_same_tty(FILE *f1, FILE *f2) {
#if HAVE_TTYNAME
return(ttyname(fileno(f1)) == ttyname(fileno(f2)));
#else
return ttyname_r(fileno(f1), LOCAL_FileNameBuf, YAP_FILENAME_MAX - 1) ==
ttyname_r(fileno(f2), LOCAL_FileNameBuf, YAP_FILENAME_MAX - 1);
#endif
// assume a single console, for now
return true;
#endif
}
static Int
is_same_tty2 (USES_REGS1)
{ /* 'prompt(Atom) */
static Int is_same_tty2(USES_REGS1) { /* 'prompt(Atom) */
int sni = Yap_CheckStream(ARG1, Input_Stream_f, "put/2");
int sno = Yap_CheckStream(ARG2, Output_Stream_f, "put/2");
bool out = (GLOBAL_Stream[sni].status & Tty_Stream_f) &&
@ -85,17 +79,14 @@ is_same_tty2 (USES_REGS1)
return out;
}
void
Yap_ConsoleOps( StreamDesc *s, bool recursive )
{
void Yap_ConsoleOps(StreamDesc *s, bool recursive) {
if (!recursive)
Yap_DefaultStreamOps(s);
/* the putc routine only has to check it is putting out a newline */
s->stream_putc = ConsolePutc;
#if USE_READLINE
/* if a tty have a special routine to call readline */
if (( s->status & Readline_Stream_f) &&
trueGlobalPrologFlag(READLINE_FLAG) ) {
if ((s->status & Readline_Stream_f) && trueGlobalPrologFlag(READLINE_FLAG)) {
if (Yap_ReadlineOps(s))
return;
}
@ -104,17 +95,13 @@ Yap_ConsoleOps( StreamDesc *s, bool recursive )
}
/* static */
static int
ConsolePutc (int sno, int ch)
{
static int ConsolePutc(int sno, int ch) {
StreamDesc *s = &GLOBAL_Stream[sno];
#if MAC || _MSC_VER || defined(__MINGW32__)
if (ch == 10)
{
if (ch == 10) {
putc('\n', s->file);
LOCAL_newline = true;
}
else
} else
#endif
putc(ch, s->file);
console_count_output_char(ch, s);
@ -123,9 +110,7 @@ ConsolePutc (int sno, int ch)
/* send a prompt, and use the system for internal buffering. Speed is
not of the essence here !!! */
static int
ConsoleGetc(int sno)
{
static int ConsoleGetc(int sno) {
CACHE_REGS
register StreamDesc *s = &GLOBAL_Stream[sno];
int ch;
@ -179,16 +164,15 @@ Changes YAP input prompt for the .
*/
static Int
prompt1 ( USES_REGS1 )
{ /* prompt1(Atom) */
static Int prompt1(USES_REGS1) { /* prompt1(Atom) */
Term t = Deref(ARG1);
Atom a;
if (IsVarTerm(t) || !IsAtomTerm(t))
return (FALSE);
LOCAL_AtPrompt = a = AtomOfTerm(t);
if (strlen((char *)RepAtom(a)->StrOfAE) > MAX_PROMPT) {
Yap_Error(SYSTEM_ERROR_INTERNAL,t,"prompt %s is too long", RepAtom (a)->StrOfAE);
Yap_Error(SYSTEM_ERROR_INTERNAL, t, "prompt %s is too long",
RepAtom(a)->StrOfAE);
return (FALSE);
}
strncpy(LOCAL_Prompt, (char *)RepAtom(a)->StrOfAE, MAX_PROMPT);
@ -197,12 +181,11 @@ prompt1 ( USES_REGS1 )
/** @pred prompt(- _A_,+ _B_)
Changes YAP input prompt from _A_ to _B_, active on *next* standard input interaction.
Changes YAP input prompt from _A_ to _B_, active on *next* standard input
interaction.
*/
static Int
prompt ( USES_REGS1 )
{ /* prompt(Old,New) */
static Int prompt(USES_REGS1) { /* prompt(Old,New) */
Term t = Deref(ARG2);
Atom a;
if (!Yap_unify_constant(ARG1, MkAtomTerm(LOCAL_AtPrompt)))
@ -211,7 +194,8 @@ prompt ( USES_REGS1 )
return (FALSE);
a = AtomOfTerm(t);
if (strlen(RepAtom(a)->StrOfAE) > MAX_PROMPT) {
Yap_Error(SYSTEM_ERROR_INTERNAL,t,"prompt %s is too long", RepAtom (a)->StrOfAE);
Yap_Error(SYSTEM_ERROR_INTERNAL, t, "prompt %s is too long",
RepAtom(a)->StrOfAE);
return false;
}
strncpy(LOCAL_Prompt, (char *)RepAtom(LOCAL_AtPrompt)->StrOfAE, MAX_PROMPT);
@ -225,18 +209,14 @@ Make sure we have a prompt at this point, even if we have to
introduce a new line.
*/
static Int
ensure_prompting ( USES_REGS1 )
{ /* prompt(Old,New) */
static Int ensure_prompting(USES_REGS1) { /* prompt(Old,New) */
if (!LOCAL_newline) {
GLOBAL_Stream[2].stream_wputc(2, 10); // hack!
}
return true;
}
int
Yap_GetCharForSIGINT(void)
{
int Yap_GetCharForSIGINT(void) {
CACHE_REGS
int ch;
#if USE_READLINE
@ -247,22 +227,21 @@ Yap_GetCharForSIGINT(void)
fprintf(stderr, "Action (h for help): ");
ch = getc(stdin);
/* first process up to end of line */
while ((fgetc(stdin)) != '\n');
while ((fgetc(stdin)) != '\n')
;
}
LOCAL_newline = TRUE;
return ch;
}
void Yap_InitConsole(void) {
CACHE_REGS
LOCAL_newline = true;
Yap_InitCPred("prompt", 1, prompt1, SafePredFlag | SyncPredFlag);
Yap_InitCPred("prompt1", 1, prompt1, SafePredFlag | SyncPredFlag);
Yap_InitCPred ("$is_same_tty", 2, is_same_tty2, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("$is_same_tty", 2, is_same_tty2,
SafePredFlag | SyncPredFlag | HiddenPredFlag);
Yap_InitCPred("prompt", 2, prompt, SafePredFlag | SyncPredFlag);
Yap_InitCPred ("$ensure_prompting", 0, ensure_prompting, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$ensure_prompting", 0, ensure_prompting,
SafePredFlag | SyncPredFlag);
}