mostly indenting

This commit is contained in:
Vítor Santos Costa 2015-10-05 10:29:07 +01:00
parent a95b3e4fcd
commit 7885433ab5

View File

@ -1,4 +1,3 @@
/************************************************************************* /*************************************************************************
* * * *
* Yap Prolog * * Yap Prolog *
@ -89,13 +88,47 @@ void Yap_PrintPredName(PredEntry *ap) {
#endif #endif
bool Yap_Warning(const char *s, ...) { bool Yap_Warning(const char *s, ...) {
va_list args; CACHE_REGS
va_list ap;
va_start(args, s); PredEntry *pred;
fprintf(stderr, "warning: %s\n", s); bool rc;
va_end(args); Term ts[2];
const char *format;
char tmpbuf[MAXPATHLEN];
if (LOCAL_within_print_message) {
/* error within error */
fprintf(stderr, "%% WARNING WITHIN WARNING\n");
Yap_RestartYap(1);
}
LOCAL_DoingUndefp = true;
LOCAL_within_print_message = true;
pred = RepPredProp(PredPropByFunc(FunctorPrintMessage, PROLOG_MODULE)); // PROCEDURE_print_message2
if (pred->OpcodeOfPred == UNDEF_OPCODE) {
//fprintf(stderr, "warning message:\n");
//Yap_DebugPlWrite(twarning);
//fprintf(stderr, "\n");
LOCAL_DoingUndefp = false;
LOCAL_within_print_message = false;
return true; return true;
}
va_start(ap, s);
format = va_arg(ap, char *);
if (format != NULL) {
#if HAVE_VSNPRINTF
vsnprintf(tmpbuf, MAXPATHLEN-1, format, ap);
#else
(void)vsprintf(tmpbuf, format, ap);
#endif
} else
return false;
va_end(ap);
ts[0] = MkAtomTerm(AtomWarning);
ts[1] = MkAtomTerm(Yap_LookupAtom(tmpbuf));
rc = Yap_execute_pred(pred, ts, true PASS_REGS);
LOCAL_within_print_message = false;
return rc;
} }
bool Yap_PrintWarning(Term twarning) { bool Yap_PrintWarning(Term twarning) {
@ -113,9 +146,9 @@ bool Yap_PrintWarning(Term twarning) {
LOCAL_DoingUndefp = true; LOCAL_DoingUndefp = true;
LOCAL_within_print_message = true; LOCAL_within_print_message = true;
if (pred->OpcodeOfPred == UNDEF_OPCODE) { if (pred->OpcodeOfPred == UNDEF_OPCODE) {
fprintf(stderr, "warning message:\n"); //fprintf(stderr, "warning message:\n");
Yap_DebugPlWrite(twarning); //Yap_DebugPlWrite(twarning);
fprintf(stderr, "\n"); //fprintf(stderr, "\n");
LOCAL_DoingUndefp = false; LOCAL_DoingUndefp = false;
LOCAL_within_print_message = false; LOCAL_within_print_message = false;
return true; return true;
@ -248,50 +281,50 @@ static char tmpbuf[YAP_BUF_SIZE];
#undef END_ERRORS #undef END_ERRORS
#define BEGIN_ERROR_CLASSES() \ #define BEGIN_ERROR_CLASSES() \
static Term mkerrorct(yap_error_class_number c, Term *ts) { \ static Term mkerrorct(yap_error_class_number c, Term *ts) { \
switch (c) { switch (c) {
#define ECLASS(CL, A, B) \ #define ECLASS(CL, A, B) \
case CL: \ case CL: \
if (A == 0) \ if (A == 0) \
return MkAtomTerm(Yap_LookupAtom(A)); \ return MkAtomTerm(Yap_LookupAtom(A)); \
else { \ else { \
return Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom(A), B), B, ts); \ return Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom(A), B), B, ts); \
} }
#define END_ERROR_CLASSES() \ #define END_ERROR_CLASSES() \
} \ } \
} }
#define BEGIN_ERRORS() \ #define BEGIN_ERRORS() \
static Term mkerrort(yap_error_number e, Term *ts) { \ static Term mkerrort(yap_error_number e, Term *ts) { \
switch (e) { switch (e) {
#define E0(A, B) \ #define E0(A, B) \
case A: \ case A: \
return mkerrorct(B, ts); return mkerrorct(B, ts);
#define E(A, B, C) \ #define E(A, B, C) \
case A: \ case A: \
ts -= 1; \ ts -= 1; \
ts[0] = MkAtomTerm(Yap_LookupAtom(C)); \ ts[0] = MkAtomTerm(Yap_LookupAtom(C)); \
return mkerrorct(B, ts); return mkerrorct(B, ts);
#define E2(A, B, C, D) \ #define E2(A, B, C, D) \
case A: \ case A: \
ts -= 2; \ ts -= 2; \
ts[0] = MkAtomTerm(Yap_LookupAtom(C)); \ ts[0] = MkAtomTerm(Yap_LookupAtom(C)); \
ts[1] = MkAtomTerm(Yap_LookupAtom(D)); \ ts[1] = MkAtomTerm(Yap_LookupAtom(D)); \
return mkerrorct(B, ts); return mkerrorct(B, ts);
#define END_ERRORS() \ #define END_ERRORS() \
} \ } \
} }
#include "YapErrors.h" #include "YapErrors.h"
/** /**
* @brief Yap_Errorp * @brief Yap_Error
* This function handles errors in the C code. Check errors.yap for the * This function handles errors in the C code. Check errors.yap for the
*corresponding Prolog code. *corresponding Prolog code.
* *
@ -330,6 +363,8 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
Functor fun; Functor fun;
bool serious; bool serious;
Term tf, error_t, comment, culprit; Term tf, error_t, comment, culprit;
char *format;
char s[MAXPATHLEN];
/* disallow recursive error handling */ /* disallow recursive error handling */
if (LOCAL_PrologMode & InErrorMode) { if (LOCAL_PrologMode & InErrorMode) {
@ -371,6 +406,21 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
fprintf(stderr, "%% Continuation: %s\n", (char *)HR); fprintf(stderr, "%% Continuation: %s\n", (char *)HR);
error_exit_yap(1); error_exit_yap(1);
} }
va_start(ap, where);
format = va_arg(ap, char *);
if (format != NULL) {
#if HAVE_VSNPRINTF
(void)vsnprintf(s, MAXPATHLEN-1, format, ap);
#else
(void)vsprintf(s, format, ap);
#endif
//fprintf(stderr, "warning: ");
comment = MkAtomTerm(Yap_LookupAtom(s));
} else if (LOCAL_ErrorSay && LOCAL_ErrorSay[0])
comment = MkAtomTerm(Yap_LookupAtom( LOCAL_ErrorSay ) );
else
comment = TermNil;
va_end(ap);
if (P == (yamop *)(FAILCODE)) if (P == (yamop *)(FAILCODE))
return P; return P;
/* PURE_ABORT may not have set where correctly, BootMode may not have the data /* PURE_ABORT may not have set where correctly, BootMode may not have the data
@ -400,23 +450,7 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
where = TermNil; where = TermNil;
} }
} }
{
char *format;
va_start(ap, where);
format = va_arg(ap, char *);
if (format != NULL) {
#if HAVE_VSNPRINTF
(void)vsnprintf(tmpbuf, YAP_BUF_SIZE, format, ap);
#else
(void)vsprintf(tmpbuf, format, ap);
#endif
comment = MkAtomTerm(Yap_LookupAtom(tmpbuf));
} else {
tmpbuf[0] = '\0';
comment = TermNil;
}
va_end(ap);
}
if (LOCAL_PrologMode & BootMode) { if (LOCAL_PrologMode & BootMode) {
/* crash in flames! */ /* crash in flames! */
fprintf(stderr, "%% YAP Fatal Error: %s exiting....\n", tmpbuf); fprintf(stderr, "%% YAP Fatal Error: %s exiting....\n", tmpbuf);
@ -494,10 +528,6 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
MAX_ERROR_MSG_SIZE); MAX_ERROR_MSG_SIZE);
LOCAL_ErrorMessage = LOCAL_ErrorSay; LOCAL_ErrorMessage = LOCAL_ErrorSay;
} }
if (LOCAL_ErrorSay && LOCAL_ErrorSay[0])
comment = MkAtomTerm(Yap_LookupAtom( LOCAL_ErrorSay ) );
else
comment = TermNil;
} }
switch (type) { switch (type) {
case RESOURCE_ERROR_HEAP: case RESOURCE_ERROR_HEAP:
@ -523,7 +553,6 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
nt[1] = MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("e")),culprit), nt[1]); nt[1] = MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("e")),culprit), nt[1]);
} }
} }
Yap_DebugPlWrite(nt[1]);
/* disable active signals at this point */ /* disable active signals at this point */
LOCAL_Signals = 0; LOCAL_Signals = 0;
CalculateStackGap(PASS_REGS1); CalculateStackGap(PASS_REGS1);