home *** CD-ROM | disk | FTP | other *** search
- /***( disp.c )******************************************************************
- * *
- * Written: Brent Faulkner - June 15, 1989 *
- * Updated: Brent Faulkner - June 15, 1989 *
- * *
- ********************************************************************************
- * *
- * Contents: bdisp_p() - buffer a printf type format on the current page *
- * and pad it with spaces *
- * center_p() - buffer a
- * disp_p() - buffer a printf type format on the current page *
- * fdisp_p() - buffer a field on the current page *
- * *
- *******************************************************************************/
- /* include files */
- #include <stdio.h>
- #include <bench.h>
- #include "prt.h"
-
- /*
- * Put a printf type format into the page buffer
- * and pad it with spaces.
- */
- #ifdef ANSI
- int bdisp_p(int line, int col, int attr, int cnt, char *va_alist, ...)
- #else
- int bdisp_p(line, col, attr, cnt, va_alist)
- int line;
- int col;
- int attr;
- int cnt;
- va_dcl
- #endif
- {
- va_list ap;
- char *fmt;
- int ret;
-
- #ifdef ANSI
- va_start(ap, va_alist);
- fmt = va_alist;
- #else
- va_start(ap);
- fmt = va_arg(ap, char *);
- #endif
-
- vsprintf(vprtbuff, fmt, ap);
- va_end(ap);
-
- ret = fdisp_p(line, col, attr, cnt, vprtbuff);
- rephoriz_p(line, col + ret, P_NORMAL, cnt - ret, ' ');
-
- return(ret);
- }
-
- /*
- * Put a printf type string into the buffer centred in a given width
- */
- #ifdef ANSI
- int center_p(int line, int col, int attr, int width, char *va_alist, ...)
- #else
- int center_p(line, col, attr, width, va_alist)
- int line;
- int col;
- int attr;
- int width;
- va_dcl
- #endif
- {
- va_list ap;
- char *fmt;
- int len;
-
- #ifdef ANSI
- va_start(ap, va_alist);
- fmt = va_alist;
- #else
- va_start(ap);
- fmt = va_arg(ap, char *);
- #endif
-
- vsprintf(vprtbuff, fmt, ap);
- va_end(ap);
-
- len = strlen(vprtbuff);
-
- col += (width - len) / 2;
-
- col += fdisp_p(line, col, attr, len, vprtbuff);
-
- return(width);
- }
-
- /*
- * Put a printf type format into the page buffer
- */
- #ifdef ANSI
- int disp_p(int line, int col, int attr, char *va_alist, ...)
- #else
- int disp_p(line, col, attr, va_alist)
- int line;
- int col;
- int attr;
- va_dcl
- #endif
- {
- va_list ap;
- char *fmt;
-
- #ifdef ANSI
- va_start(ap, va_alist);
- fmt = va_alist;
- #else
- va_start(ap);
- fmt = va_arg(ap, char *);
- #endif
-
- vsprintf(vprtbuff, fmt, ap);
- va_end(ap);
-
- for(fmt = vprtbuff; *fmt != '\0'; fmt++)
- poke_p(line, col++, attr, *fmt);
-
- return((int)(fmt - vprtbuff));
- }
-
- /*
- * Put a string into the page buffer but stop at a '\0' or len characters
- * Return number of characters output
- */
- int xdisp_p(line, col, attr, str)
- int line;
- int col;
- int attr;
- char *str;
- {
- fdisp_p(line, col, attr, strlen(str), str);
- }
-
- /*
- * Put a string into the page buffer but stop at a '\0' or len characters
- * Return number of characters output
- */
- int fdisp_p(line, col, attr, len, str)
- int line;
- int col;
- int attr;
- int len;
- char *str;
- {
- int i;
- char *ptr = str;
-
- for(i = 0; i < len && *str; i++)
- poke_p(line, col + i, attr, *str++);
-
- return((int)(str - ptr));
- }
-
- /*
- * Put a string into the current page buffer and pad it to a given width
- */
- int ndisp_p(line, col, attr, cnt, str)
- int line;
- int col;
- int attr;
- int cnt;
- char *str;
- {
- int ret;
-
- ret = fdisp_p(line, col, attr, cnt, str);
- rephoriz_p(line, col + ret, attr, cnt - ret, ' ');
-
- return(cnt);
- }
-