diff --git a/C/alloc.c b/C/alloc.c index 9b28dbee3..2677d0e43 100644 --- a/C/alloc.c +++ b/C/alloc.c @@ -12,7 +12,7 @@ * Last rev: * * mods: * * comments: allocating space * -* version:$Id: alloc.c,v 1.28 2002-11-18 17:56:30 vsc Exp $ * +* version:$Id: alloc.c,v 1.29 2002-11-19 17:10:42 vsc Exp $ * *************************************************************************/ #ifdef SCCS static char SccsId[] = "%W% %G%"; @@ -1071,11 +1071,11 @@ Yap_InitMemory(int Trail, int Heap, int Stack) #ifdef DEBUG #if SIZEOF_INT_P!=SIZEOF_INT - if (output_msg) { + if (Yap_output_msg) { fprintf(stderr, "HeapBase = %p GlobalBase = %p\n LocalBase = %p TrailTop = %p\n", Yap_HeapBase, Yap_GlobalBase, Yap_LocalBase, Yap_TrailTop); #else - if (output_msg) { + if (Yap_output_msg) { fprintf(stderr, "HeapBase = %x GlobalBase = %x\n LocalBase = %x TrailTop = %x\n", (UInt) Yap_HeapBase, (UInt) Yap_GlobalBase, (UInt) Yap_LocalBase, (UInt) Yap_TrailTop); diff --git a/C/c_interface.c b/C/c_interface.c index dabb4fe88..600c5d8c4 100644 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -1024,7 +1024,7 @@ X_API void YAP_SetOutputMessage(void) { #if DEBUG - output_msg = TRUE; + Yap_output_msg = TRUE; #endif } diff --git a/C/init.c b/C/init.c index 1bbe1ca37..7dbe8dcc8 100644 --- a/C/init.c +++ b/C/init.c @@ -52,6 +52,8 @@ static char SccsId[] = "%W% %G%"; #define LOGFILE "logfile" +int Yap_output_msg = FALSE; + #ifdef MACC STATIC_PROTO(void InTTYLine, (char *)); #endif @@ -402,7 +404,7 @@ InitDebug(void) for (i = 1; i < 20; ++i) Yap_Option[i] = 0; - if (output_msg) { + if (Yap_output_msg) { char ch; #if HAVE_ISATTY @@ -967,9 +969,6 @@ InitCodes(void) heap_regs->term_prolog = MkAtomTerm(Yap_LookupAtom("prolog")); heap_regs->term_refound_var = MkAtomTerm(Yap_LookupAtom("$I_FOUND_THE_VARIABLE_AGAIN")); heap_regs->dyn_array_list = NULL; -#if DEBUG - heap_regs->debugger_output_msg = FALSE; -#endif heap_regs->n_of_file_aliases = 0; heap_regs->file_aliases = NULL; heap_regs->foreign_code_loaded = NULL; diff --git a/C/iopreds.c b/C/iopreds.c index aead5930f..61e8de078 100644 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -819,7 +819,9 @@ extern void add_history (const char *); static char *ttyptr = NULL; -static char *_line = (char *) NULL; + + +static char *myrl_line = (char *) NULL; static int cur_out_sno = 2; @@ -879,8 +881,8 @@ ReadlineGetc(int sno) while (ttyptr == NULL) { /* Only sends a newline if we are at the start of a line */ - if (_line != NULL && _line != (char *) EOF) - free (_line); + if (myrl_line != NULL && myrl_line != (char *) EOF) + free (myrl_line); rl_instream = Stream[sno].u.file.file; rl_outstream = Stream[cur_out_sno].u.file.file; /* window of vulnerability opened */ @@ -894,20 +896,20 @@ ReadlineGetc(int sno) console_count_output_char(ch,Stream+StdErrStream,StdErrStream); } Yap_PrologMode |= ConsoleGetcMode; - _line = readline (Prompt); + myrl_line = readline (Prompt); } else { Yap_PrologMode |= ConsoleGetcMode; - _line = readline (NULL); + myrl_line = readline (NULL); } } else { if (ReadlinePos != ReadlineBuf) { ReadlinePos[0] = '\0'; ReadlinePos = ReadlineBuf; Yap_PrologMode |= ConsoleGetcMode; - _line = readline (ReadlineBuf); + myrl_line = readline (ReadlineBuf); } else { Yap_PrologMode |= ConsoleGetcMode; - _line = readline (NULL); + myrl_line = readline (NULL); } } /* Do it the gnu way */ @@ -927,11 +929,11 @@ ReadlineGetc(int sno) newline=FALSE; strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT); /* window of vulnerability closed */ - if (_line == NULL || _line == (char *) EOF) + if (myrl_line == NULL || myrl_line == (char *) EOF) return(console_post_process_read_char(EOF, s, sno)); - if (_line[0] != '\0' && _line[1] != '\0') - add_history (_line); - ttyptr = _line; + if (myrl_line[0] != '\0' && myrl_line[1] != '\0') + add_history (myrl_line); + ttyptr = myrl_line; } if (*ttyptr == '\0') { ttyptr = NIL; @@ -950,18 +952,18 @@ Yap_GetCharForSIGINT(void) { int ch; #if HAVE_LIBREADLINE - if ((Yap_PrologMode & ConsoleGetcMode) && _line != (char *) NULL) { - ch = _line[0]; - free(_line); - _line = NULL; + if ((Yap_PrologMode & ConsoleGetcMode) && myrl_line != (char *) NULL) { + ch = myrl_line[0]; + free(myrl_line); + myrl_line = NULL; } else { - _line = readline ("Action (h for help): "); - if (_line == (char *)NULL || _line == (char *)EOF) { + myrl_line = readline ("Action (h for help): "); + if (myrl_line == (char *)NULL || myrl_line == (char *)EOF) { ch = EOF; } else { - ch = _line[0]; - free(_line); - _line = NULL; + ch = myrl_line[0]; + free(myrl_line); + myrl_line = NULL; } } #else @@ -2788,6 +2790,8 @@ syntax_error (TokEntry * tokptr) ts[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("string"),1),1,&t0); } break; + case Error_tok: + break; case Ponctuation_tok: { char s[2]; @@ -2804,12 +2808,13 @@ syntax_error (TokEntry * tokptr) *error = TermNil; end = tokptr->TokPos; break; + } else if (tokptr->Tok != Ord (Error_tok)) { + ts[1] = MkIntegerTerm(tokptr->TokPos); + *error = + MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("-"),2),2,ts),TermNil); + error = RepPair(*error)+1; + count++; } - ts[1] = MkIntegerTerm(tokptr->TokPos); - *error = - MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("-"),2),2,ts),TermNil); - error = RepPair(*error)+1; - count++; tokptr = tokptr->TokNext; } tf[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("read"),1),1,&ARG2); diff --git a/C/parser.c b/C/parser.c index adeeac43d..1502a11d6 100644 --- a/C/parser.c +++ b/C/parser.c @@ -504,6 +504,9 @@ ParseTerm(int prio) NextToken; break; + case Error_tok: + FAIL; + case Ponctuation_tok: switch ((int) Yap_tokptr->TokInfo) { case '(': diff --git a/C/scanner.c b/C/scanner.c index 6ee135839..468a54c8e 100644 --- a/C/scanner.c +++ b/C/scanner.c @@ -573,6 +573,11 @@ token(void) Yap_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)"; break; } + if (ch == 10 && yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) { + /* in ISO a new line terminates a string */ + Yap_ErrorMessage = "layout character \n inside quotes"; + break; + } if (ch == quote) { my_get_quoted_ch(); if (ch != quote) @@ -585,7 +590,6 @@ token(void) switch (ch) { case 10: /* don't add characters */ - printf("I am here\n"); my_get_quoted_ch(); break; case 'a': @@ -865,6 +869,23 @@ Yap_tokenizer(int (*Nxtch) (int), int (*QuotedNxtch) (int)) t->TokInfo = (Term) TokenInfo; t->TokPos = TokenPos; t->TokNext = NIL; + if (Yap_ErrorMessage) { + /* insert an error token to inform the system on what happened */ + TokEntry *e = (TokEntry *) AllocScannerMemory(sizeof(TokEntry)); + if (e == NULL) { + Yap_ErrorMessage = "not enough stack space to read in term"; + p->TokInfo = eot_tok; + /* serious error now */ + return(l); + } + p->TokNext = e; + e->Tok = Error_tok; + e->TokInfo = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage)); + e->TokPos = TokenPos; + e->TokNext = NIL; + Yap_ErrorMessage = NULL; + p = e; + } } while (kind != eot_tok); return (l); } @@ -1308,6 +1329,11 @@ Yap_fast_tokenizer(void) Yap_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)"; break; } + if (ch == 10 && yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) { + /* in ISO a new line terminates a string */ + Yap_ErrorMessage = "layout character \n inside quotes"; + break; + } if (ch == quote) { my_fgetch(); if (ch != quote) @@ -1569,6 +1595,23 @@ Yap_fast_tokenizer(void) t->TokPos = TokenPos; t->TokNext = NIL; Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage); + if (Yap_ErrorMessage) { + /* insert an error token to inform the system on what happened */ + TokEntry *e = (TokEntry *) AllocScannerMemory(sizeof(TokEntry)); + if (e == NULL) { + Yap_ErrorMessage = "not enough stack space to read in term"; + p->TokInfo = eot_tok; + /* serious error now */ + return(l); + } + p->TokNext = e; + e->Tok = Error_tok; + e->TokInfo = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage)); + e->TokPos = TokenPos; + e->TokNext = NIL; + Yap_ErrorMessage = NULL; + p = e; + } } while (kind != eot_tok); return (l); } diff --git a/H/yapio.h b/H/yapio.h index a99ce0520..de33a8d11 100644 --- a/H/yapio.h +++ b/H/yapio.h @@ -172,9 +172,15 @@ extern char Yap_FileNameBuf[YAP_FILENAME_MAX], Yap_FileNameBuf2[YAP_FILENAME_MAX typedef YP_FILE *YP_File; -enum TokenKinds - { Name_tok, Number_tok, Var_tok, String_tok, Ponctuation_tok, - eot_tok }; +enum TokenKinds { + Name_tok, + Number_tok, + Var_tok, + String_tok, + Ponctuation_tok, + Error_tok, + eot_tok +}; typedef struct TOKEN { unsigned char Tok; diff --git a/m4/Yap.h.m4 b/m4/Yap.h.m4 index ad0e1cd96..284062658 100644 --- a/m4/Yap.h.m4 +++ b/m4/Yap.h.m4 @@ -10,7 +10,7 @@ * File: Yap.h.m4 * * mods: * * comments: main header file for YAP * -* version: $Id: Yap.h.m4,v 1.37 2002-11-18 18:17:13 vsc Exp $ * +* version: $Id: Yap.h.m4,v 1.38 2002-11-19 17:10:45 vsc Exp $ * *************************************************************************/ #include "config.h" @@ -778,8 +778,6 @@ typedef struct opcode_tab_entry { #define MAX_ERROR_MSG_SIZE 256 extern char Yap_ErrorSay[MAX_ERROR_MSG_SIZE]; -/********************* how to write a Prolog term ***********************/ - /********* Prolog may be in several modes *******************************/ typedef enum { @@ -801,6 +799,11 @@ extern int Yap_CritLocks; extern char **Yap_argv; extern int Yap_argc; +#ifdef DEBUG +/************** Debugging Support ***************************/ +extern int Yap_output_msg; +#endif + /******************* number of modules ****************************/ #define MaxModules 256