/* $Id: htytype.c,v 2.3 91/09/03 17:39:40 annette Exp $ */
/****************************************************************/
/* htytype.c:  program to set HTY driver port type (DCE/DTE)	*/
/****************************************************************/
/*																*/
/*                 Confidential Information                     */
/*      Limited Distribution to Authorized Persons Only         */
/*     Created 1988 and Protected as an Unpublished Work        */
/*          Under the U.S. Copyright Act of 1976.               */
/*         Copyright (c) 1989, Systech Corporation              */
/*                  All Rights Reserved                         */
/*																*/
/*	THIS SOFTWARE IS LICENSED BY AND IS THE	CONFIDENTIAL AND 	*/
/*	PROPRIETARY PROPERTY OF SYSTECH COMPUTER CORPORATION AND 	*/
/*	MAY NOT, WITHOUT THE PRIOR WRITTEN CONSENT OF SYSTECH 		*/
/*	COMPUTER CORPORATION, BE REPRODUCED, USED OR DISCLOSED 		*/
/*	EXCEPT IN ACCORDANCE WITH A SYSTECH COMPUTER CORPORATION 	*/
/*	SOFTWARE LICENSE AGREEMENT.									*/
/****************************************************************/
/*																*/
/*	This program displays or sets the port type for an hty		*/
/*	port.  Ports may be configured as either DCE or DTE 		*/
/*	devices with respect to the DCD signal.  The pinouts 		*/
/*	on the DB-25s are configured for DCE but the HPS hty ports 	*/
/*	both drive and receive the DCD signal.  This allows you to 	*/
/*	add a null modem cable and change the personality of the 	*/
/*	port.														
/*																*/
/*	The primary difference is whether the host driver should 	*/
/*	look at changes on the DCD line or not.  A DTE device 		*/
/*	cares about the incoming state of the DCD line.  A DCE 		*/
/*	device drives the DCD line so it does not care about 		*/
/*	the incoming state of the line.								*/
/*																*/
/*	HPS hty ports default to the DTE configuration.				*/
/*																*/
/*	Invoke this program as follows:								*/
/*		htytype dce			# set stdin type to DCE				*/
/*		htytype dte			# set stdin type to DTE				*/
/*		htytype				# display current type of stdin		*/
/*																*/
/****************************************************************/

#include <stdio.h>
#include "hps.types.h"
#include "hps.iocb.h"
#include "hps.ioctl.h"			/* Need to include defines for TCSET/GET */


extern int errno;

main(argc, argv)
int argc;
char *argv[];
{
	if (argc == 1)
		print_type(argv[0]);
	else
		if (argc == 2)
			set_type(argv[1], argv[0]);
		else
			usage(argv[0]);
}

print_type(pname)
char *pname;
{
	int type;
	int result;

	if (result = ioctl(0, TCGETTYPE, &type) < 0)
		error(pname);
	else
		if (type)
			printf("Port configured as DCE device\n");
		else
			printf("Port configured as DTE device\n");
}

set_type(type_string, pname)
char *type_string;
char *pname;
{
	int result;

	if (strncmp(type_string, "dce", 3) == 0)
		if (result = ioctl(0, TCSETDCE, 0) < 0)
			error(pname);
		else
			print_type(pname);
	else
		if (strncmp(type_string, "dte", 3) == 0)
			if (result = ioctl(0, TCSETDTE, 0) < 0)
				error(pname);
			else
				print_type(pname);
		else
			usage(pname);
}

usage(pname)
char *pname;
{
	fprintf(stderr, "%s: usage: %s [dce|dte]\n", pname, pname);
}

error(pname)
char *pname;
{
	if (errno)
		perror(pname);
	fprintf(stderr, "%s: Caution: htytype applies only to hty ports.\n", pname);
}

/*
 * MODIFICATION HISTORY:
 *
 * $Log:	htytype.c,v $
 * Revision 1.1.2.1  92/06/24  13:53:46  marker
 * Branch RISCOS_5_01_2_FIXES off of trunk.
 * 
 * Revision 2.3  91/09/03  17:39:40  annette
 * Changed error message handling.
 * INTERNAL
 * 
 * Revision 2.2  91/01/10  17:23:47  dave
 * Modify header; add footer.
 * COSMETIC
 * 
 */
