/*
 * $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.
 *
 */

extern char *gettxt();
/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ident	"$Header: form.c 1.3 89/12/01 $@(#)nlp:cmd/lpstat/form.c	1.6"

#include "stdio.h"

#include "string.h"

#include "lp.h"
#include "form.h"
#include "access.h"

#define	WHO_AM_I	I_AM_LPSTAT
#include "oam.h"

#include "lpstat.h"


static void		putfline();

/**
 ** do_form()
 **/

void			do_form (list)
	char			**list;
{
	FORM			form;

	while (*list) {
		if (STREQU(NAME_ALL, *list))
			while (getform(NAME_ALL, &form, (FALERT *)0, (FILE **)0) != -1)
				putfline (&form);

		else if (getform(*list, &form, (FALERT *)0, (FILE **)0) != -1) {
#define	NAME_BUG_IN_GETFORM
#if	defined(NAME_BUG_IN_GETFORM)
			form.name = *list;
#endif
			putfline (&form);

		} else {
			LP_ERRMSG1 (ERROR, E_LP_NOFORM, *list);
			exit_rc = 1;
		}

		list++;
	}
	printsdn_unsetup ();
	return;
}

static void		putfline (pf)
	FORM			*pf;
{
	register MOUNTED	*pm;

	if(is_user_allowed_form(getname(), pf->name))
		PRINTF (gettxt("lpstat:102", "form %s is available to you"), pf->name);
	else
		PRINTF (gettxt("lpstat:103", "form %s is not available to you"), pf->name);
	for (pm = mounted_forms; pm->forward; pm = pm->forward)
		if (STREQU(pm->name, pf->name)) {
			if (pm->printers) {
				PRINTF (gettxt("lpstat:6", ", mounted on "));
				printlist_setup (0, 0, ",", "");
				printlist (stdout, pm->printers);
				printlist_unsetup();
			}
			break;
		}

	PRINTF ("\n");

	if (verbose) {

		printsdn_setup (gettxt("lpstat:18", "\tPage length: "), 0, 0);
		printsdn (stdout, pf->plen);

		printsdn_setup (gettxt("lpstat:19", "\tPage width: "), 0, 0);
		printsdn (stdout, pf->pwid);

		PRINTF (gettxt("lpstat:20", "\tNumber of pages: %d\n"), pf->np);

		printsdn_setup (gettxt("lpstat:21", "\tLine pitch: "), 0, 0);
		printsdn (stdout, pf->lpi);

		PRINTF (gettxt("lpstat:22", "\tCharacter pitch:"));
		if (pf->cpi.val == 9999)
			PRINTF (gettxt("lpstat:23", " compressed\n"));
		else {
			printsdn_setup (" ", 0, 0);
			printsdn (stdout, pf->cpi);
		}

		PRINTF (gettxt("lpstat:24", "\tCharacter set choice: %s%s\n"),
			(pf->chset? pf->chset : NAME_ANY),
			(pf->mandatory ? gettxt("lpstat:25", ",mandatory") : "")
		);

		PRINTF (gettxt("lpstat:26", "\tRibbon color: %s\n"),
			(pf->rcolor? pf->rcolor : NAME_ANY)
		);

		if (pf->comment)
			PRINTF (gettxt("lpstat:27", "\tComment:\n\t%s\n"), pf->comment);

	}
	return;
}

