diff --git a/elkscmd/basic/host.c b/elkscmd/basic/host.c index 063980bde..4256b0cac 100644 --- a/elkscmd/basic/host.c +++ b/elkscmd/basic/host.c @@ -54,11 +54,12 @@ float adjust(float f) { // for float testing compatibility, use same FP formatting routines on host for now // floats have approx 7 sig figs, 15 for double -#if __ia16__ +#if __ia16__ || defined(__WATCOMC__) #include -__STDIO_PRINT_FLOATS; // link in libc printf float support char *host_floatToStr(float f, char *buf) { + __STDIO_PRINT_FLOATS; // link in libc printf float support + sprintf(buf, "%.*g", MATH_PRECISION, (double)f); return buf; } diff --git a/libc/include/sys/weaken.h b/libc/include/sys/weaken.h index eca7eaccc..497961e87 100644 --- a/libc/include/sys/weaken.h +++ b/libc/include/sys/weaken.h @@ -3,13 +3,25 @@ #ifdef __GNUC__ /* return address of weak version of passed symbol */ -#define _weaken(sym) __extension__ ({ \ +#define _weakaddr(sym) __extension__ ({ \ + extern __typeof__(sym) sym __attribute__((__weak__)); \ + sym; }) + +#define _weakfn(sym) __extension__ ({ \ extern __typeof__(sym) sym __attribute__((__weak__)); \ sym; }) #endif #ifdef __WATCOMC__ -#define _weaken(sym) (sym) /* FIXME weak symbols not yet implemented */ + +#if defined(__COMPACT__) || defined(__LARGE__) +/* FIXME: this can fail if weak symbol happens to fall at address zero of segment! */ +#define _weakaddr(sym) (((unsigned long)sym) & 0xFFFF) +#else +#define _weakaddr(sym) (sym) +#endif + +#define _weakfn(sym) (sym) #endif #endif diff --git a/libc/stdio/Makefile b/libc/stdio/Makefile index c7ed51e90..737efb256 100644 --- a/libc/stdio/Makefile +++ b/libc/stdio/Makefile @@ -55,6 +55,9 @@ all: $(LIB) $(LIB): $(LIBOBJS) $(RM) $@ +ifeq "$(COMPILER)" "watcom" + fixomf -w dtostr_,ptostr_ vfprintf.obj +endif $(AR) $(ARFLAGS_SUB) $@ $(LIBOBJS) clean: diff --git a/libc/stdio/vfprintf.c b/libc/stdio/vfprintf.c index 5bc71f715..36992c5e3 100644 --- a/libc/stdio/vfprintf.c +++ b/libc/stdio/vfprintf.c @@ -218,16 +218,14 @@ vfprintf(FILE *op, const char *fmt, va_list ap) case 'k': /* Pticks */ usproc: l = lval? va_arg(ap, unsigned long) : (unsigned long)va_arg(ap, unsigned int); -#ifndef __WATCOMC__ if (*fmt == 'k') { - if (_weaken(ptostr)) { - (_weaken(ptostr))(l, ptmp); + if (_weakaddr(ptostr)) { + (_weakfn(ptostr))(l, ptmp); preci = -1; goto printit; } /* if precision timing not linked in, display as unsigned */ } -#endif ptmp = ultostr(l, radix); if( hash && radix == 8 ) { width = strlen(ptmp)+1; pad='0'; } goto printit; @@ -258,9 +256,9 @@ vfprintf(FILE *op, const char *fmt, va_list ap) case 'g': case 'E': case 'G': - if (_weaken(dtostr)) + if (_weakaddr(dtostr)) { - (_weaken(dtostr))(va_arg(ap, double), *fmt, preci, ptmp); + (_weakfn(dtostr))(va_arg(ap, double), *fmt, preci, ptmp); preci = -1; goto printit; }