From 68559d4f760dbcc88ce880e2e5ebbed82f7dc9ec Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Mon, 17 Sep 2018 13:57:57 -0600 Subject: [PATCH] tcl: use the system version, initial work only on linux for now --- cde/programs/dtdocbook/instant/Imakefile | 4 +- cde/programs/dtdocbook/instant/general.h | 6 --- cde/programs/dtdocbook/instant/main.c | 60 ++++++++++------------ cde/programs/dtdocbook/instant/translate.c | 11 +++- cde/programs/dtdocbook/instant/util.c | 14 ++--- 5 files changed, 44 insertions(+), 51 deletions(-) diff --git a/cde/programs/dtdocbook/instant/Imakefile b/cde/programs/dtdocbook/instant/Imakefile index 9330fd4d..8314e0dd 100644 --- a/cde/programs/dtdocbook/instant/Imakefile +++ b/cde/programs/dtdocbook/instant/Imakefile @@ -2,10 +2,10 @@ XCOMM $XConsortium: Imakefile /main/6 1996/11/29 11:06:09 rswiston $ XLATESRC = $(DTSVCSRC)/DtUtil2 -INCLUDES = -I../lib/tptregexp -I../tcl -I$(XLATESRC) +INCLUDES = -I../lib/tptregexp -I$(XLATESRC) -I/usr/include/tcl DEPLIBS = $(DEPDTSVCLIB) LOCAL_LIBRARIES = $(DTSVCLIB) $(TTLIB) $(XMLIB) $(XTOOLLIB) $(XLIB) \ --L../lib/tptregexp -ltptregexp ../tcl/libtcl.a +-L../lib/tptregexp -ltptregexp -ltcl #if defined(SunArchitecture) EXTRA_LIBRARIES = -lsocket -lnsl -lgen -lm #else diff --git a/cde/programs/dtdocbook/instant/general.h b/cde/programs/dtdocbook/instant/general.h index c2f360e8..413e9aab 100644 --- a/cde/programs/dtdocbook/instant/general.h +++ b/cde/programs/dtdocbook/instant/general.h @@ -324,9 +324,3 @@ void PrintElemTree(Element_t *); void PrintStats(Element_t *); void PrintIDList(); -/* ----- other declarations ----- */ - -#ifdef ultrix -#define strdup(s) strcpy((char *)malloc(strlen(s)+1), s) -#endif - diff --git a/cde/programs/dtdocbook/instant/main.c b/cde/programs/dtdocbook/instant/main.c index 09554a49..8297cf2a 100644 --- a/cde/programs/dtdocbook/instant/main.c +++ b/cde/programs/dtdocbook/instant/main.c @@ -111,19 +111,19 @@ extern void Browse(); static int TclPrintLocation(ClientData clientData, Tcl_Interp *interp, int argc, - char *argv[]); + const char *argv[]); static int DefaultOutputString(ClientData clientData, Tcl_Interp *interp, int argc, - char *argv[]); + const char *argv[]); static int CompareI18NStrings(ClientData clientData, Tcl_Interp *interp, int argc, - char *argv[]); + const char *argv[]); static int TclReadLocaleStrings(ClientData clientData, Tcl_Interp *interp, int argc, - char *argv[]); + const char *argv[]); char *GetOutFileBaseName(); char * @@ -356,12 +356,11 @@ static char *UnEscapeI18NChars( static int DefaultOutputString(ClientData clientData, Tcl_Interp *interp, int argc, - char *argv[]) + const char *argv[]) { -#define LOCAL_BUFFER_LENGTH 128 - char *string, *pString, *pArgv; - char localBuffer[LOCAL_BUFFER_LENGTH]; - int retCode, stringLength; + char *string = NULL, *pString = NULL; + const char *pArgv = NULL; + int retCode = 0, stringLength = 0; if (argc < 2) { Tcl_SetResult(interpreter, "Missing string to output", TCL_VOLATILE); @@ -377,12 +376,8 @@ static int DefaultOutputString(ClientData clientData, pArgv = argv[1]; stringLength = (2 * strlen(pArgv)) + 3; - /* try to use automatic buffer; use malloc if string is too large */ - if (stringLength <= LOCAL_BUFFER_LENGTH) { - string = localBuffer; - } else { - string = malloc(stringLength); - } + string = malloc(stringLength); + memset(string, 0, stringLength); pString = string; @@ -409,10 +404,7 @@ static int DefaultOutputString(ClientData clientData, /* put the string to the output */ retCode = Tcl_VarEval(interpreter, "puts -nonewline ", string, 0); - /* free the string if we're not using the automatic buffer */ - if (string != localBuffer) { - free(string); - } + free(string); /* and ripple up any error code we got from the "puts" */ return retCode; @@ -422,7 +414,7 @@ static int DefaultOutputString(ClientData clientData, static int CompareI18NStrings(ClientData clientData, Tcl_Interp *interp, int argc, - char *argv[]) + const char *argv[]) { int ret_val, len; char *ret_string, *cp; @@ -492,7 +484,7 @@ static int CompareI18NStrings(ClientData clientData, static int TclPrintLocation(ClientData clientData, Tcl_Interp *interp, int argc, - char *argv[]) + const char *argv[]) { if (argc > 1) { Tcl_SetResult(interpreter, "Too many arguments", TCL_VOLATILE); @@ -918,26 +910,26 @@ EscapeI18NChars( static char * ReadLocaleStrings(char *file_name, int *ret_code) { -int fd; -char *pBuf; -char *i18nBuf; -off_t size; -struct stat stat_buf; + int fd; + char *pBuf; + char *i18nBuf; + off_t size; + struct stat stat_buf; fd = open(file_name, O_RDONLY); if (fd == -1) { *ret_code = 1; - return ""; + return NULL; } fstat(fd, &stat_buf); size = stat_buf.st_size; - pBuf = malloc(size+1); - pBuf[size] = 0; + pBuf = Tcl_Alloc(size+1); + memset(pBuf, 0, size+1); if (read(fd, pBuf, size) != size) { *ret_code = 2; - return ""; + return NULL; } i18nBuf = EscapeI18NChars(pBuf); @@ -952,10 +944,10 @@ struct stat stat_buf; static int TclReadLocaleStrings(ClientData clientData, Tcl_Interp *interp, int argc, - char *argv[]) { -char *pBuf; -int ret_code; -char errorBuf[512]; + const char *argv[]) { + char *pBuf; + int ret_code; + char errorBuf[512]; if (argc > 2) { Tcl_SetResult(interpreter, "Too many arguments", TCL_VOLATILE); diff --git a/cde/programs/dtdocbook/instant/translate.c b/cde/programs/dtdocbook/instant/translate.c index 987c459d..70e68bd9 100644 --- a/cde/programs/dtdocbook/instant/translate.c +++ b/cde/programs/dtdocbook/instant/translate.c @@ -207,7 +207,7 @@ ExpandVariables( if (*ip == VDELIM && *(ip+1) == L_CURLY && *(ip+2) != '_') { ip++; ip++; /* point at variable name */ - len + 2; + len += 2; vp = vbuf; /* Look for matching (closing) curly. (watch for nesting) * We store the variable content in a tmp buffer, so we don't @@ -294,9 +294,16 @@ CallInterpreter( ) { int result; - char line[20]; int recursive; +#if 0 + if (ib) + { + fprintf(stderr, "JET: %s: IB = '%s'\n", __FUNCTION__, + ib); + } +#endif + /* save the value of this "e" to be used by Tcl_PrintLocation in * the case of a user error */ diff --git a/cde/programs/dtdocbook/instant/util.c b/cde/programs/dtdocbook/instant/util.c index fa726e0f..f4b081e2 100644 --- a/cde/programs/dtdocbook/instant/util.c +++ b/cde/programs/dtdocbook/instant/util.c @@ -525,7 +525,7 @@ OutputString( int track_pos ) { - char c, *sdata, *cp; + char c = 0, *sdata, *cp; static int char_pos; /* remembers our character position */ static int interp_pos; /* like char_pos but when output is to interp */ int *ppos; /* points to appropriate line position var */ @@ -678,8 +678,8 @@ static int CheckOutputBuffer( */ int FFlush(FILE *stream) { -if (stream) return fflush(stream); -return 0; + if (stream) return fflush(stream); + return 0; } @@ -722,8 +722,8 @@ int Putc( if (result != TCL_OK) { fprintf(stderr, "interpreter error \"%s\" at line %d executing:\n", - interpreter->result, - interpreter->errorLine); + Tcl_GetStringResult(interpreter), + Tcl_GetErrorLine(interpreter)); fprintf(stderr, "\"%s\"\n", commandBuf); return EOF; } @@ -787,8 +787,8 @@ int FPuts( if (result != TCL_OK) { fprintf(stderr, "interpreter error \"%s\" at line %d executing:\n", - interpreter->result, - interpreter->errorLine); + Tcl_GetStringResult(interpreter), + Tcl_GetErrorLine(interpreter)); fprintf(stderr, "\"%s\"\n", pBuff); if (pBuff != commandBuf) free(pBuff); return EOF; -- 2.25.1