make comterp in server mode handle multi-line comments
Brought to you by:
johnston
|
From: <ivt...@li...> - 2000-02-10 17:35:05
|
Patch: ivtools-000210-johnston-018
For: ivtools-0.8
Author: joh...@us...
This is an intermediate patch to ivtools-0.8. To apply, cd to the
top-level directory of the ivtools source tree (the directory with src
and config subdirs), and apply like this:
patch -p0 <ThisFile
Summary of Changes:
- modify lexical scanner to preserve token state between invocations.
This fixes a problem with multi-line comments when comterp is in
server (when comterp is receiving input strings one at a time from an
external source). However, this does not fix the problem with
multi-line strings when comterp is in server mode, which will require
a better solution for preserving more of the token state (i.e. the
partial token buffer) between invocations. This is also a necessary
step in preserving parallel use of one lexical scanner by more than
one comterp in the same program.
- fix another problem in server-mode comterp. Part of making
server-mode work was figuring out how to return from the depths of the
lexical scanner in the middle of an expression, when an expression
continues across multiple-lines, but the capability to retrieve a new
line (or string) is external to the parser/scanner. To make this work
I made up the convention that if the input function (the function
pointer with an fgets signature passed to the parser/scanner C
routines) returns a null string (a string that begins with '\000'),
return out of the scanner and parser, yet assume there is more to
come. When that function (ComTerpServ::s_fgets) was going to return
the null string, it still traversed the entire input buffer, which is
huge by default.
- change signature of accept() used in utils/sockets.cc to use an
unsigned instead of signed int* as the third argument. This seems to
be more the recent standard.
Index: ComUtil/_lexscan.c
diff -c ComUtil/_lexscan.c:1.1 ComUtil/_lexscan.c:1.2
*** ComUtil/_lexscan.c:1.1 Thu Feb 10 02:57:59 2000
--- src/ComUtil/_lexscan.c Thu Feb 10 02:57:59 2000
***************
*** 1,4 ****
--- 1,5 ----
/*
+ * Copyright (c) 2000 IET Inc.
* Copyright (c) 1993-1995 Vectaport Inc.
* Copyright (c) 1989 Triple Vision, Inc.
*
***************
*** 149,154 ****
--- 150,157 ----
BOOLEAN long_num = FALSE; /* Indicates long integer to be used */
unsigned token_state = TOK_WHITESPACE;
/* Internal token state variable */
+ static unsigned token_state_save = TOK_WHITESPACE;
+ /* variable to save token state between calls */
unsigned begcmt_len = /* Number of characters in comment beginning */
(begcmt != NULL ? strlen(begcmt) : 0 );
unsigned endcmt_len = /* Number of characters in comment ending */
***************
*** 172,177 ****
--- 175,182 ----
*toktype = TOK_NONE;
*toklen = 0;
*tokstart = 0;
+ token_state = token_state_save;
+ token_state_save = TOK_WHITESPACE;
/* Initialize if linenumber is 0 */
if( *linenum == 0 ) {
***************
*** 291,296 ****
--- 296,307 ----
/* Reset pointer to front of buffer */
*bufptr = 0;
CURR_CHAR = buffer[0];
+ if (CURR_CHAR == '\0') {
+ if (token_state == TOK_COMMENT)
+ token_state_save = token_state;
+ *linenum--;
+ return FUNCOK;
+ }
/* Echo source line if so desired */
#if 0
Index: ComTerp/comterpserv.c
diff -c ComTerp/comterpserv.c:1.1 ComTerp/comterpserv.c:1.2
*** ComTerp/comterpserv.c:1.1 Thu Feb 10 02:58:01 2000
--- src/ComTerp/comterpserv.c Thu Feb 10 02:58:01 2000
***************
*** 99,105 ****
/* copy characters until n-1 characters are transferred, */
/* the input buffer is exhausted, or a newline is found. */
! for (outpos = 0; outpos < n-1 && inpos < bufsize-1 && instr[inpos] != '\n';)
outstr[outpos++] = instr[inpos++];
/* copy the newline character if there is room */
--- 99,105 ----
/* copy characters until n-1 characters are transferred, */
/* the input buffer is exhausted, or a newline is found. */
! for (outpos = 0; outpos < n-1 && inpos < bufsize-1 && instr[inpos] != '\n' && instr[inpos] != '\0';)
outstr[outpos++] = instr[inpos++];
/* copy the newline character if there is room */
Index: ComTerp/comterpserv.h
diff -c ComTerp/comterpserv.h:1.1 ComTerp/comterpserv.h:1.2
*** ComTerp/comterpserv.h:1.1 Thu Feb 10 02:58:01 2000
--- src/ComTerp/comterpserv.h Thu Feb 10 02:58:01 2000
***************
*** 60,66 ****
// execute a buffer of postfix tokens and return the value.
virtual int runfile(const char*);
! // run interpreter on command read from a file.
void add_defaults();
// add a default list of ComFunc objects to this interpreter.
--- 60,66 ----
// execute a buffer of postfix tokens and return the value.
virtual int runfile(const char*);
! // run interpreter on commands read from a file.
void add_defaults();
// add a default list of ComFunc objects to this interpreter.
Index: utils_ivtools/sockets.cc
diff -c utils_ivtools/sockets.cc:1.1 utils_ivtools/sockets.cc:1.2
*** utils_ivtools/sockets.cc:1.1 Thu Feb 10 02:58:39 2000
--- src/utils/sockets.cc Thu Feb 10 02:58:39 2000
***************
*** 98,104 ****
int data_fd;
if ((data_fd = accept(Psocket_fd,
(struct sockaddr *)&Pclient_addr,
! (int *)&Palen)) < 0) {
// we can break out of accept if the system call was interrupted
#ifndef ERESTART /* ERESTART not defined on some systems */
if (errno != EINTR) {
--- 98,104 ----
int data_fd;
if ((data_fd = accept(Psocket_fd,
(struct sockaddr *)&Pclient_addr,
! (unsigned int *)&Palen)) < 0) {
// we can break out of accept if the system call was interrupted
#ifndef ERESTART /* ERESTART not defined on some systems */
if (errno != EINTR) {
|