* configure.in src/tclspice.c src/frontend/terminal.c

src/frontend/terminal.h src/include/ngspice.h
  src/maths/cmaths/Makefile.am src/misc/alloc.c:
	stdout / stderr is now printed via the Tcl puts interface
This commit is contained in:
stefanjones 2003-04-09 08:58:31 +00:00
parent 867fa6bf02
commit 4022b693b6
7 changed files with 239 additions and 39 deletions

View File

@ -284,6 +284,33 @@ AC_CHECK_LIB(gc,GC_malloc,AC_DEFINE(HAVE_LIBGC) LIBS="$LIBS -lgc")
dnl Check for the asprintf function:
AC_CHECK_FUNCS(asprintf)
dnl Check for va_copy
AC_CACHE_CHECK([for va_copy], ac_cv_c_va_copy,
AC_TRY_LINK(
[#include <stdarg.h>],
[va_list ap1, ap2;
va_copy(ap1,ap2);
],
[ac_cv_c_va_copy="yes"],
[ac_cv_c_va_copy="no"])
)
if test "$ac_cv_c_va_copy" = "yes"
then
AC_DEFINE(HAVE_VA_COPY, 1, [Define if we have va_copy])
fi
AC_CACHE_CHECK([for __va_copy], ac_cv_c___va_copy,
AC_TRY_LINK(
[#include <stdarg.h>],
[va_list ap1, ap2;
__va_copy(ap1,ap2);
],
[ac_cv_c___va_copy="yes"],
[ac_cv_c___va_copy="no"])
)
if test "$ac_cv_c___va_copy" = "yes"
then
AC_DEFINE(HAVE___VA_COPY, 1, [Define if we have __va_copy])
fi
# Expand the prefix variable (this is really annoying!)
if eval "test x$prefix = xNONE"; then

View File

@ -33,6 +33,15 @@ Author: 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
#include "variable.h"
#include "terminal.h"
bool out_moremode = TRUE;
bool out_isatty = TRUE;
/* out_printf doesn't handle double arguments correctly, so we
sprintf into this buf and call out_send w/ it */
char out_pbuf[BSIZE_SP];
#ifndef TCL_MODULE
static char *motion_chars;
static char *clear_chars;
static char *home_chars;
@ -42,18 +51,12 @@ static char *cleol_chars;
#define DEF_SCRHEIGHT 24
#define DEF_SCRWIDTH 80
bool out_moremode = TRUE;
bool out_isatty = TRUE;
static int xsize, ysize;
static int xpos, ypos;
static bool noprint, nopause;
/* out_printf doesn't handle double arguments correctly, so we
sprintf into this buf and call out_send w/ it */
char out_pbuf[BSIZE_SP];
/* Start output... */
void
@ -328,3 +331,23 @@ term_cleol(void)
tputs(cleol_chars, 1, outfn);
#endif
}
#else
void out_init(void) {}
void outbufputc(void) {}
void promptreturn(void) {}
void term_clear(void) {}
void term_home(void) {}
void term_cleol(void) {}
void tcap_init(void) {}
void out_send(char *string) {tcl_printf(string);}
void
out_printf(char *fmt, char *s1, char *s2, char *s3, char *s4, char *s5,
char *s6, char *s7, char *s8, char *s9, char *s10) {
tcl_printf(fmt, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10);
}
#endif /* TCL_MODULE */

View File

@ -3,6 +3,8 @@
extern bool out_isatty;
#ifndef TCL_MODULE
void out_init(void);
void outbufputc(void);
void promptreturn(void);
@ -15,4 +17,28 @@ void term_home(void);
void term_cleol(void);
void tcap_init(void);
#else
extern int tcl_printf(const char *format, ...);
inline extern void out_init(void) {}
inline extern void outbufputc(void) {}
inline extern void promptreturn(void) {}
inline extern void term_clear(void) {}
inline extern void term_home(void) {}
inline extern void term_cleol(void) {}
inline extern void tcap_init(void) {}
inline extern void out_send(char *string) {tcl_printf(string);}
inline extern void
out_printf(char *fmt, char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8, char *s9, char *s10) {
tcl_printf(fmt, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10);
}
#endif
#endif

View File

@ -152,3 +152,16 @@ extern char *Lib_Path;
extern int ARCHme; /* My logical process number */
extern int ARCHsize; /* Total number of processes */
#ifdef TCL_MODULE
extern int tcl_printf(const char *format, ...);
extern int tcl_fprintf(FILE *f, const char *format, ...);
#undef printf
#define printf tcl_printf
#undef fprintf
#define fprintf tcl_fprintf
#endif

View File

@ -13,34 +13,6 @@ libcmaths_a_SOURCES = \
cmath4.c \
cmath4.h
noinst_PROGRAMS = test_cx_mag test_cx_j test_cx_ph
test_cx_ph_SOURCES = \
test_cx_ph.c
test_cx_ph_LDADD = \
libcmaths.a \
../../misc/libmisc.a \
@TCL_BUILD_LIB_SPEC@
test_cx_mag_SOURCES = \
test_cx_mag.c
test_cx_mag_LDADD = \
libcmaths.a \
../../misc/libmisc.a \
@TCL_BUILD_LIB_SPEC@
test_cx_j_SOURCES = \
test_cx_j.c
test_cx_j_LDADD = \
libcmaths.a \
../../misc/libmisc.a \
@TCL_BUILD_LIB_SPEC@
TESTS = test_cx_mag test_cx_j test_cx_ph
INCLUDES = -I$(top_srcdir)/src/include -I$(top_srcdir)/src/maths/poly
MAINTAINERCLEANFILES = Makefile.in

View File

@ -29,7 +29,7 @@ tmalloc(size_t num)
void *s;
/*saj*/
#ifdef TCL_MODULE
struct Tcl_Mutex *alloc;
Tcl_Mutex *alloc;
alloc = Tcl_GetAllocMutex();
#endif
if (!num)
@ -57,7 +57,7 @@ trealloc(void *ptr, size_t num)
void *s;
/*saj*/
#ifdef TCL_MODULE
struct Tcl_Mutex *alloc;
Tcl_Mutex *alloc;
alloc = Tcl_GetAllocMutex();
#endif
if (!num) {
@ -142,7 +142,7 @@ txfree(void *ptr)
{
/*saj*/
#ifdef TCL_MODULE
struct Tcl_Mutex *alloc;
Tcl_Mutex *alloc;
alloc = Tcl_GetAllocMutex();
Tcl_MutexLock(alloc);
#endif

View File

@ -57,6 +57,8 @@
/* run spicein background */
#include <pthread.h>
#include <stdarg.h> /* for va_copy() */
extern IFfrontEnd nutmeginfo;
extern struct comm spcp_coms[ ];
@ -81,8 +83,11 @@ static int ownVectors = 0;
/* save this each time called */
static Tcl_Interp *spice_interp=NULL;
#define save_interp() spice_interp = interp;
#define save_interp() \
do {\
if ((spice_interp = Tcl_GetMaster(interp)) == NULL)\
spice_interp = interp;\
} while(0)
/****************************************************************************/
/* BLT and data routines */
@ -1243,6 +1248,8 @@ int Spice_Init(Tcl_Interp *interp) {
Tcl_Eval(interp, "namespace eval " TCLSPICE_namespace " { }");
save_interp();
{
extern void DevInit();
int i;
@ -1323,3 +1330,135 @@ int Spice_Init(Tcl_Interp *interp) {
}
return TCL_OK;
}
/***************************************/
/* printf wrappers to redirect to puts */
/***************************************/
/* Contributed by Tim Edwards (tim@stravinsky.jhuapl.edu), 2003 */
/*----------------------------------------------------------------------*/
/* Deal with systems which don't define va_copy(). */
/*----------------------------------------------------------------------*/
#ifndef HAVE_VA_COPY
#ifdef HAVE___VA_COPY
#define va_copy(a, b) __va_copy(a, b)
#else
#define va_copy(a, b) a = b
#endif
#endif
/*------------------------------------------------------*/
/* Redefine the vfprintf() functions for use with tkcon */
/*------------------------------------------------------*/
int tcl_vfprintf(FILE *f, const char *fmt, va_list args_in)
{
va_list args;
static char outstr[128] = "puts -nonewline std";
char *outptr, *bigstr = NULL, *finalstr = NULL;
int i, nchars, result, escapes = 0;
if(f != stdout && f != stderr)
vfprintf(f,fmt,args_in);
strcpy (outstr + 19, (f == stderr) ? "err \"" : "out \"");
outptr = outstr;
va_copy(args, args_in);
nchars = vsnprintf(outptr + 24, 102, fmt, args);
va_end(args);
if (nchars >= 102)
{
va_copy(args, args_in);
bigstr = Tcl_Alloc(nchars + 26);
strncpy(bigstr, outptr, 24);
outptr = bigstr;
vsnprintf(outptr + 24, nchars + 2, fmt, args);
va_end(args);
}
else if (nchars == -1) nchars = 126;
for (i = 24; *(outptr + i) != '\0'; i++) {
if (*(outptr + i) == '\"' || *(outptr + i) == '[' ||
*(outptr + i) == ']' || *(outptr + i) == '\\')
escapes++;
}
if (escapes > 0)
{
finalstr = Tcl_Alloc(nchars + escapes + 26);
strncpy(finalstr, outptr, 24);
escapes = 0;
for (i = 24; *(outptr + i) != '\0'; i++)
{
if (*(outptr + i) == '\"' || *(outptr + i) == '[' ||
*(outptr + i) == ']' || *(outptr + i) == '\\')
{
*(finalstr + i + escapes) = '\\';
escapes++;
}
*(finalstr + i + escapes) = *(outptr + i);
}
outptr = finalstr;
}
*(outptr + 24 + nchars + escapes) = '\"';
*(outptr + 25 + nchars + escapes) = '\0';
result = Tcl_Eval(spice_interp, outptr);
if (bigstr != NULL) Tcl_Free(bigstr);
if (finalstr != NULL) Tcl_Free(finalstr);
return nchars;
}
/*----------------------------------------------------------------------*/
/* Reimplement fprintf() as a call to Tcl_Eval(). */
/*----------------------------------------------------------------------*/
int tcl_fprintf(FILE *f, const char *format, ...)
{
va_list ap;
int rtn;
va_start(ap, format);
rtn = tcl_vfprintf(f, format, ap);
va_end(ap);
return rtn;
}
/*----------------------------------------------------------------------*/
/* Reimplement fprintf() as a call to Tcl_Eval(). */
/*----------------------------------------------------------------------*/
int tcl_printf(const char *format, ...)
{
va_list ap;
int rtn;
va_start(ap, format);
rtn = tcl_vfprintf(stdout, format, ap);
va_end(ap);
return rtn;
}
/*------------------------------------------------------*/
/* Console output flushing which goes along with the */
/* routine tcl_vprintf() above. */
/*------------------------------------------------------*/
void tcl_stdflush(FILE *f)
{
Tcl_SavedResult state;
static char stdstr[] = "flush stdxxx";
char *stdptr = stdstr + 9;
Tcl_SaveResult(spice_interp, &state);
strcpy(stdptr, (f == stderr) ? "err" : "out");
Tcl_Eval(spice_interp, stdstr);
Tcl_RestoreResult(spice_interp, &state);
}