/*
 ----------------------------------------------------------------
 |    Perlin Production Corporation, February-April 1993 (c).	|##
 |   WINDOW PACKAGE Source Code for SuperSoft C 1.2.3 compiler.	|##
 |    V e r s i o n  3.1 , part 14. LAST CHANGES: 01.06.1993.	|##
 ----------------------------------------------------------------##
  #################################################################

			LIST OF FUNCTIONS:
	w_puts
*/

#include "conio.h"
#include "wios.h"

char w_puts(string,wn)
char *string;
WINDOW *wn;
{
	register char *t;
	int i,n;

	if ( (mv_csr(wn->col,wn->row,wn)) == WENOERR )
	{
		wrt_esc(wn->bgrnd);
		n=wn->t_lgt - wn->col;	/* Max strlen in window */

		for (t=string ; n-- && *t ; t++ )
		{
			switch ( *t )
			{
				case '\n' :
				{
					if ( *(t+1) == '\r' ) t++;
				}
				case '\r' :
				{
					if (mv_csr( 0,(wn->row)+1,wn)!=WENOERR)
					{
						wrt_esc(NORM_VID);
						return (werrno);
					}
					n=wn->t_lgt;
					break;
		      		}
				case '\t' :
				{
					for ( i=8 ; n > 1 && i ; n--,i--)
					{
						++wn->col;
						putchar(BLANK);
					}
					break;
				}

			/* The next control symbols must have an echo-off */
			/*  effect in WIOS, but can be in the user string */

				case '\f' :
				{
					break;
				}
 				default   : { ++wn->col; putchar(*t); break; }
			}
		}
	}
	wrt_esc(NORM_VID);
	return (werrno);
}
