home *** CD-ROM | disk | FTP | other *** search
- /* ==( mip/wdisp.c )== */
- /* ----------------------------------------------- */
- /* Pro-C Copyright (C) 1988 - 1990 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written Geo 26-Aug-88 */
- /* Modified Geo 18-Jul-90 See comments below */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
- /*
- * Modifications
- *
- * 18-Jul-90 Geo - Overhauled
- * 4-Jan-89 Geo - Added xdisp_w, fast no vararg'd disp_w
- * 25-Oct-89 Geo - 1.32 Merge
- */
-
- /*
- * Display functions
- * usually vararg'd
- */
-
- # include <stdio.h>
- # include <bench.h>
-
- extern char *sysbase; /* wbase.c */
-
- /*
- * Global Vararg display buffer
- * Note when this is used - xdisp must be called to display
- * as it in turn does not use this buffer
- */
- char vdispbuff[W_PHY_WIDTH+1];
-
- /*
- * Varags disp_w - allows printf expressions to be used into the window
- * return the number of characters output
- */
- # ifdef UNIX
- int disp_w(row, col, attr, va_alist)
- int row, col, attr;
- va_dcl
- # else
- int CDECL disp_w(int row, int col, int attr, char *va_alist, ...)
- # endif
- {
- va_list ap;
- register char *fmt;
-
- # ifdef UNIX
- va_start(ap);
- fmt = va_arg(ap, char *);
- # else
- va_start(ap, va_alist);
- fmt = va_alist;
- # endif
-
- # ifdef WDEBUG
- if (fmt == vdispbuff)
- fprintf(stderr, "\r\ndisp_w(): called with target vdispbuffer\r\n");
- # endif
-
- vsprintf(vdispbuff, fmt, ap);
- va_end(ap);
-
- /* Add to our Screen Output buffer */
- for (fmt = vdispbuff; *fmt != '\0'; fmt++)
- {
- # ifndef WDEBUG
- if (fmt != vdispbuff)
- ADDPOKE(attr, *fmt);
- else
- # endif
- poke_w(row, col++, attr, *fmt);
- }
-
- /* Watcom C 70 required this cast ! - Geo */
- return((int)(fmt - (char *)vdispbuff));
- }
-
-
- /*
- * Display string but stop either at a '\0' or len characters
- * Return number of characters output
- */
- int fdisp_w(row, col, attr, len, str)
- int row, col, attr, len;
- char *str;
- {
- register char *ptr = str;
- int i = 0;
-
- /* Geo -> get rid of i (use --len) */
- for ( ; i < len && *ptr; i++, ptr++)
- {
- # ifndef WDEBUG
- /* First set up sysbase */
- if (ptr != str)
- ADDPOKE(attr, *ptr);
- else
- # endif
- poke_w(row, col++, attr, *ptr);
-
- }
- return((int)(ptr - str));
- }
-
- /*
- * Display '\0' terminated string
- * Return number of characters output
- */
- int xdisp_w(row, col, attr, str)
- int row, col, attr;
- char *str;
- {
- register char *ptr = str;
-
- for ( ; *ptr; ptr++)
- {
- # ifndef WDEBUG
- /* First set up sysbase */
- if (ptr != str)
- ADDPOKE(attr, *ptr);
- else
- # endif
- poke_w(row, col++, attr, *ptr);
- }
- return((int)(ptr - str));
- }
-
- /*
- * Display string and set rest of string to normal spaces
- * Returns number of chars output from the string
- * Requires a '\0' terminated string
- */
- # ifdef UNIX
- int bdisp_w(row, col, attr, cnt, va_alist)
- int row, col, attr, cnt;
- va_dcl
- # else
- int CDECL bdisp_w(int row, int col, int attr, int cnt, char *va_alist, ...)
- # endif
- {
- va_list ap;
- char *fmt;
- int ret;
-
- # ifdef UNIX
- va_start(ap);
- fmt = va_arg(ap, char *);
- # else
- va_start(ap, va_alist);
- fmt = va_alist;
- # endif
-
- # ifdef WDEBUG
- if (fmt == vdispbuff)
- fprintf(stderr, "\r\nbdisp_w(): called with target vdispbuffer\r\n");
- # endif
-
- vsprintf(vdispbuff, fmt, ap);
- va_end(ap);
-
- /* Add to our Screen Output buffer */
- ret = fdisp_w(row, col, attr, cnt, vdispbuff);
- rephoriz_w(row, col + ret, NORMAL, cnt - ret, ' ');
-
- return(ret);
- }
-
- /*
- * Display string and pad to cnt characters
- * Will always output cnt characters
- */
- int ndisp_w(row, col, attr, cnt, str)
- int row, col, attr, cnt;
- char *str;
- {
- int ret;
-
- ret = fdisp_w(row, col, attr, cnt, str);
- rephoriz_w(row, col + ret, attr, cnt - ret, ' ');
-
- return(cnt);
- }
-
- /*
- * Centres a text string within a given width
- */
- # ifdef UNIX
- int center_w(row, col, attr, width, va_alist)
- int row, col, attr, width;
- va_dcl
- # else
- int CDECL center_w(int row, int col, int attr, int width, char *va_alist, ...)
- # endif
- {
- va_list ap;
- char *fmt;
-
- # ifdef UNIX
- va_start(ap);
- fmt = va_arg(ap, char *);
- # else
- va_start(ap, va_alist);
- fmt = va_alist;
- # endif
-
- vsprintf(vdispbuff, fmt, ap);
- va_end(ap);
-
- col += (width - strlen(vdispbuff)) >> 1;
-
- xdisp_w(row, col, attr, vdispbuff);
-
- return(width);
- }
-
-