/*	PF -- printer filter

Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 Ogochan .

This module is part of PF.

	PF is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves
any particular purpose or works at all, unless he says so in writing.
Refer to the GNU General Public License for full details. 

	Everyone is granted permission to copy, modify and redistribute
MACE, but only under the conditions described in the GNU General
Public License.  A copy of this license is supposed to have been given
to you along with PF so you can know your rights and
responsibilities.  It should be in a file named COPYING.  Among other
things, the copyright notice and this notice must be preserved on all
copies. 
*/
/*
#define		TRACE
*/

#include	<stdio.h>
#include	<string.h>
#include	"types.h"
#include	"pf.h"
#include	"debug.h"

extern	void
PrintSBCS_Direct(
	Char	ch)
{	word	code;

	code = CODE_Char(ch);
	PrintChar(CODE_LOWER(code));
}

extern	void
PrintDBCS_Direct(
	Char	ch)
{	word	code;

	code = CODE_Char(ch);
	PrintChar(CODE_UPPER(code));
	PrintChar(CODE_LOWER(code));
}

#include	"ESCP.h"
#include	"PCPR.h"
#include	"FMPR.h"
#include	"PS.h"
#include	"text.h"
	
static	PrinterClass	NULL_Printer = {
	NULL,
	NULL,
	NULL
};

PrinterClass	*Printers[] = {
	&ESCP,
	&PCPR,
	&FMPR,
	&PS,
	&TEXT,
	&NULL_Printer
};

extern	PrinterControl	*
SetPrinterType(
	char	*driver,
	int		LinePitch,
	int		PitchSBCS,
	int		PitchDBCS,
	int		PageLength,
	int		PageWidth,
	int		PageLines,
	int		LineWidth,
	int		TopMargineInLines,
	int		LeftMargine,
	int		TabWidth,
	Bool	fPrintPageHeader)
{
	char	*name
	,		*arg;
	PrinterControl	*ret;
	int		i;

dbgmsg(">SetPrinterType");
	name = driver;
	if		(  ( arg = strchr(driver,':') )  !=  NULL  ) {
		*arg = 0;
		arg ++;
	} else {
		arg = "";
	}
#ifdef	DEBUG
	fprintf(stderr,"name = [%s] arg = [%s]\n",name,arg);
#endif
	for	( i = 0 ; Printers[i]->name  !=  NULL ; i ++ ) {
		if		(  !strcmp(Printers[i]->name,name)  ) {
			break;
		}
	}
	if		(  Printers[i]->name  ==  NULL  ) {
		fprintf(stderr,"printer [%s] is not supported.\n",name);
		exit(1);
		ret = NULL;
	} else {
		ret = Printers[i]->Select(arg,LinePitch,PitchSBCS,PitchDBCS,
								  PageLength,PageWidth,PageLines,LineWidth,
								  TopMargineInLines,LeftMargine,
								  TabWidth,
								  fPrintPageHeader);
	}
dbgmsg("<SetPrinterType");
	return	(ret);
}
