#include <stdio.h>
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <libraries/reqbase.h>
extern struct reqFileRequester reqreq;
extern struct FILE *infile, *printer, *cfile;
extern  void *ArpBase, *ReqBase, *mw, *OpenLibrary(), *OpenWindow();
extern struct  IntuitionBase  *IntuitionBase;

#define PRINTERNAME (UBYTE *) "PAR:"

ULONG NO_REQLIB = 0L;  /* flag for existence of req.library */

struct IntuiText fbody = {
	1,0,
	JAM1|COMPLEMENT,
	30,5,
	NULL,
	(UBYTE *) "Well...",
	NULL
	};

struct IntuiText ok = {
	1,0,
	JAM1|COMPLEMENT,
	6,3,
	NULL,
	(UBYTE *)	"Whoops!",
	NULL
	};

void close_all(why, error)
UBYTE *why;
long error;
{
	if(error)
		{
		fbody.IText = why;
		AutoRequest(IntuitionBase->ActiveWindow, &fbody, &ok, &ok,\
						NULL, NULL, 380L, 50L);
		}

	if(printer)
		fclose(printer);
	if(infile)
		fclose(infile);
	if(cfile)
		fclose(cfile);


	if(mw)
		CloseWindowSafely(mw,NULL);
	if(IntuitionBase)
		CloseLibrary(IntuitionBase);
	if(ArpBase)
		CloseLibrary(ArpBase);
	if(ReqBase)
		{
		PurgeFiles(&reqreq);
		CloseLibrary(ReqBase);
		}

	exit(0L);
}

void open_all()
{
	IntuitionBase = OpenLibrary("intuition.library",0L);
	if(!IntuitionBase)
		exit(FALSE);

	ArpBase = OpenLibrary("arp.library",0L);
	if(!ArpBase)
		close_all("FATAL ERROR: no arp.library!", 1L);

	ReqBase = OpenLibrary("req.library", 0L);
		if(!ReqBase)
		close_all("FATAL ERROR: no req.library!", 1L);

	return;
}

/* help coded 17 Oct 1990 by hoover
	supply online help to user
*/

void help()
{
	printf("---------------------------------------------------------------\n");
	printf("Usage: Print [options] {switches} file1 ... fileN\n");
	printf("---------------------------------------------------------------\n");
	printf("Supported options that take an argument:\n");
	printf("---------------------------------------------------------------\n");
	printf("-i n   \t indent text with n spaces        \t (Default:   8)\n");
	printf("-t n   \t convert each tab to n spaces     \t (Default:   3)\n");
	printf("-u n   \t national char set after printing \t (Default:   2)\n");
	printf("-l n   \t number of lines per page         \t (Default:  72)\n");
	printf("-o n   \t offset of paper top to head (mm) \t (Default:   0)\n");
	printf("-f file\t read printer commands from file  \t (Default: OFF)\n");
	printf("---------------------------------------------------------------\n");
	printf("Options that do not expect an argument:\n");
	printf("-B   \t switch to 10 CPI\n");
	printf("-M   \t switch to 12 CPI (DEFAULT)\n");
	printf("-S   \t switch to 15 CPI\n");
	printf("-F   \t print name of file (DEFAULT OFF)\n");
	printf("-P   \t pagenumbering on (DEFAULT OFF)\n");
	printf("-Q   \t switch to letter quality (DEFAULT ON)\n");
	printf("-D   \t switch to high speed mode (draft)\n");
	printf("-V   \t copy processed files to stdout\n");
	printf("-N   \t be NICE and print in quiet mode (DEFAULT OFF)\n");
	printf("-R   \t Don't reset printer after printing (DEFAULT OFF)\n");
	printf("-T   \t Don't transform any characters (DEFAULT OFF)\n");
	printf("-8   \t Switch to Jammed Print mode (8LPI) (DEFAULT OFF)\n");
	exit(0L);
}


