#ident	"$Header: flavours.c 1.10 89/08/07 $"

/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

/*
 * system V streams flavor module.
 * This can be pushed on top of the raw console driver.
 *
 */

/*
 * $Log:	flavours.c,v $
 */

#include "sys/types.h"
#include "sys/param.h"
#include "sys/sysmacros.h"
#include "sys/errno.h"
#include "sys/stropts.h"
#include "sys/session.h"
#include "sys/stream.h"
#include "sys/strid.h"
#include "sys/mutex.h"
#include "sys/intctl.h"

int 	nodev();
int	flopen();
int	flclose();
int	flwput();
int	flrput();

int	debug_char = 0x06;	/* ^F */
int	flav_flag = 0;		/* Flavours enable flag; 0=off, 1=on */

static struct module_info flm_info = 
	{STRID_FL, "flavours", 0, INFPSZ, 512, 256};
static struct qinit flrinit = {
	flrput, NULL, flopen, flclose, NULL, &flm_info, NULL };
static struct qinit flwinit = {
	flwput, NULL, flopen, flclose, NULL, &flm_info, NULL };

struct streamtab flinfo = {
	&flrinit, &flwinit, NULL, NULL };


/*ARGSUSED*/
flopen(q, dev, flag, sflag)
queue_t	*q;
dev_t	dev;
int	flag;
int	sflag;
{
	return (1);
}

/*ARGSUSED*/
flclose(q, flag)
queue_t	*q;
int	flag;
{
}

/*
 * Read side put procedure.
 */

flwput(q,bp)
queue_t	*q;
mblk_t	*bp;
{
	/*
	 * unconditionaly pass data on - never queue.
	 */
	putnext(q,bp);
}
	
/*
 * Read side put procedure.
 */
flrput(q,bp)
queue_t	*q;
mblk_t	*bp;
{
	extern	void		qdelchar();
	extern			debugit();
	unsigned char		*p;
	static	unsigned char	flav_on;

	if (bp->b_datap->db_type != M_DATA) {
		putnext(q,bp);
		return;
	} 
	if (flav_flag) {
		for (p = bp->b_rptr; p<bp->b_wptr; p++) { 
			if (*p == debug_char) { 
				flav_on = 1; 
				qdelchar(bp, &p);
			} else if (flav_on) {
				flav_on = 0;
				debugit((char)(*p&0x7f));
				qdelchar(bp, &p);
			}
		}
	}
	if (bp->b_rptr < bp->b_wptr) {
		putnext(q,bp);
	} else {
		freemsg(bp);
	}
}
