[cups-devel] cups-devel Digest, Vol 6, Issue 9

Peng Liu liupengfiu at gmail.com
Wed May 14 12:12:10 PDT 2014


Hi,

I am developing a new filter. My system is Ubuntu, the newest version.  My
cups version is 1.7.0 .

How can I get the print file ?  Should I use some functions from CUPS, such
as  cupsFileStdin() ?

The attached is my filter source code.

Thanks,
Peng Liu.



On Wed, May 14, 2014 at 3:00 PM, <cups-devel-request at cups.org> wrote:

> Send cups-devel mailing list submissions to
>         cups-devel at cups.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://www.cups.org/mailman/listinfo/cups-devel
> or, via email, send a message with subject or body 'help' to
>         cups-devel-request at cups.org
>
> You can reach the person managing the list at
>         cups-devel-owner at cups.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of cups-devel digest..."
>
>
> Today's Topics:
>
>    1. Re: [UNKN] STR #4415: cups implicit class (Alok Pandey)
>    2. Re: [MOD] STR #4402: cups 1.7.2: build error on system
>       without dnssd/avahi (Andreas K. Hüttel)
>    3. Git mirror of 1.7.x *should* be working now... (Michael Sweet)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 13 May 2014 21:20:00 -0700 (PDT)
> From: Alok Pandey <noreply at cups.org>
> To: alok.padey at gmail.com
> Cc: alok.padey at gmail.com, cups-devel at cups.org
> Subject: Re: [cups-devel] [UNKN] STR #4415: cups implicit class
> Message-ID: <20140514042001.012361410FA at www.cups.org>
> Content-Type: text/plain
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
>
> DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK
> BELOW.
>
> [STR Unresolved]
>
> That means' cups do not have browse poll option in its latest versions ?
>
> If yes, then what alternate cups offers for printer Failover ?
>
> Link: https://www.cups.org/str.php?L4415
> Version: 1.4.2
> Fix Version: Will Not Fix
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.14 (GNU/Linux)
> Comment: GPGTools - https://gpgtools.org
>
> iQIcBAEBCgAGBQJTcu7wAAoJENujp6sI12Ij+fgQAIq3RPeR3zWHCq15ZUk8urxH
> JDzybsBPigLGpxrLZLmDmjHBG6cOoo4wx062zP/XBWy2hdO1qSnexxrAYbUwH63p
> WEeYMSwk41UFD3n96V5guHgQrj7AxGDo/tyzhYV1yhBs9rv3Jc39a4JpieE8b1ju
> yCYB5WSaye++95cMOT5f4aEn5y9K6EHhoPqFolioyRtdVP2IpPjgLJC5fBXp7RTA
> Z5zkp44mOVICdi9nUtCTTJ7EOUuURLXiFgTD5JGJo/ZB11EMH4WiDGkkCrB36brW
> 3c/1AJBNU+mOWbKmfBs77aV4DY+DnOjrXMMlybJaypmmcU0AkSDFREcyHEvHVFk6
> WB7N41x/bJG0ZE6u2iJraClOGUq9mAHVX3Ho+G+mR/wxMebLAD8FNHz3PhwvXVUM
> 04YOTquPA1kZzAaFCQTj7O+3mLdZ7IASTvq43ajckYhm6XPHgr7y3NMsMqII7bDX
> BeWA0DcxNZ7gtVbq+0KcevAK58C4ll5tOmJRCM25LPvSZaJbs7QFjPSq0TWaeyJh
> sSWqGciDcitiibLuhstQ/EaTQVYRIZnhno9vryqKL2nH/YwuPE22JD3dMzjtvLgc
> T8izW2qLcKY47oD+XXmVeRYmdQ/E3vezjHw2UXZ+u2h6Cf7d1OL7A+bAGJxRqIbl
> cnH8d/6Fz18GtbR/pcvu
> =iQvm
> -----END PGP SIGNATURE-----
>
>
>
> ------------------------------
>
> Message: 2
> Date: Wed, 14 May 2014 07:10:45 -0700 (PDT)
> From: Andreas K. Hüttel  <noreply at cups.org>
> To: jue at jue.li
> Cc: jue at jue.li, cups-devel at cups.org
> Subject: Re: [cups-devel] [MOD] STR #4402: cups 1.7.2: build error on
>         system  without dnssd/avahi
> Message-ID: <20140514141045.DBDA0141147 at www.cups.org>
> Content-Type: text/plain
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
>
> DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK
> BELOW.
>
> [STR Resolved]
>
> Care to update the git export, please? It would be great if we could
> backport the official fix.
>
> Link: https://www.cups.org/str.php?L4402
> Version: 1.7-current
> Fix Version: 2.0-current (r11871)
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.14 (GNU/Linux)
> Comment: GPGTools - https://gpgtools.org
>
> iQIcBAEBCgAGBQJTc3llAAoJENujp6sI12Ijq+QP/A5g6uwiCxcFm4uy8cFqXtUh
> n7etkBKZuQ/tXZGi1e9rQLht/GfDsEunAbXj693rbmajfdHtQIct4IGMLTDl79Ix
> nqH9WRDjwXsw/HaWAYEvlMM+LazMhGv63NlXr5ghUyEj+2RsRNpOAGLTHjWYGJmx
> T+LJPVkaNAwVJPQI0RE5dyTf/Fmjj2WlWk/cHylJSBwHdPA/DaEvksEThc+qs3aF
> LpSLWWQZUAlU0DkwCMFNUwuIOH5zomXVlpdcGRj+KZapENk9buJ3gWFQiPI23xXJ
> 3AUrP7dnnN79qwa99D33mzZI6KRa9HTX1epPykwgadrtxivIG5QN6vtlAoA6keEK
> nVgCSD8Hgxss8PdP1JmY68ewel8xLn7az7EVb2gy/MGoQQgtV/pqLYPnOU4rbM54
> 4pM72yo0jjKr58PYSM/WbiacQIhIi/g27Oi6FQd920KgMfxVPCEA4cG4mHQVzFIS
> DT0mNzxtLG/Wg4OqspniJiYc1ah45NjmzflbqmN+2D8cjGADe7qPS66LFgoupySr
> tqaDoaCiiy70pazVe3Pd2mzdCrLi14URfyvoq/F4WeJeOb/CSWQVvK+9rurAISs6
> StwDR8q1/YaHbau6kjx/kqTjhFNTaguKHhyLaiUfVJbJ1sz0BwVtwZUoQAyfiQtY
> i5qfl8d+2slL5HTyig+G
> =nFRQ
> -----END PGP SIGNATURE-----
>
>
>
> ------------------------------
>
> Message: 3
> Date: Wed, 14 May 2014 10:52:59 -0700
> From: Michael Sweet <msweet at apple.com>
> To: "The CUPS developer list." <cups-devel at cups.org>
> Subject: [cups-devel] Git mirror of 1.7.x *should* be working now...
> Message-ID: <BA9D82EB-8B0E-45B8-B8F7-A6AB68420CE6 at apple.com>
> Content-Type: text/plain; CHARSET=US-ASCII
>
> All,
>
> I *think* I have the Git mirror of the 1.7 branch of CUPS working now.
>  Please let me know if you experience any further issues.
>
> _________________________________________________________
> Michael Sweet, Senior Printing System Engineer, PWG Chair
>
>
>
> ------------------------------
>
> _______________________________________________
> cups-devel mailing list
> cups-devel at cups.org
> https://www.cups.org/mailman/listinfo/cups-devel
>
>
> End of cups-devel Digest, Vol 6, Issue 9
> ****************************************
>



-- 
Thanks & Regards.
Peng Liu.
-------------- next part --------------
//========================================================================
//
// pdftopcl.cc
//
// Copyright 1997-2003 Glyph & Cog, LLC
// 
// Modified by Peng Liu 03/20/2014 add the function 
//========================================================================
#include <aconf.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <fcntl.h>
#include "parseargs.h"
#include "GString.h"
#include "gmem.h"
#include "GlobalParams.h"
#include "Object.h"
#include "Stream.h"
#include "Array.h"
#include "Dict.h"
#include "XRef.h"
#include "Catalog.h"
#include "Page.h"
#include "PDFDoc.h"
#include "PclOutputDev.h"
#include "CharTypes.h"
#include "UnicodeMap.h"
#include "Error.h"
#include "config.h"

#include <iostream>
#include <string>
#include <list>
#include "PdftotigerConf.h"

#include <exception>

#include "../../cups/cups.h"
#include "../../cups/ppd.h"


using namespace std;

using std::string;
void SaveAsPDF();
bool GetPPDAllSelectionValues();
//------------------------------------------------------------------------
// command line options
//------------------------------------------------------------------------

static int firstPage = 1;
static int lastPage = 0;
static GBool level1 = gFalse;
static GBool level1Sep = gFalse;
static GBool level2 = gFalse;
static GBool level2Sep = gFalse;
static GBool level3 = gFalse;
static GBool level3Sep = gFalse;
static GBool doEPS = gFalse;
static GBool doForm = gFalse;
#if OPI_SUPPORT
static GBool doOPI = gFalse;
#endif
static GBool noEmbedT1Fonts = gFalse;
static GBool noEmbedTTFonts = gFalse;
static GBool noEmbedCIDPSFonts = gFalse;
static GBool noEmbedCIDTTFonts = gFalse;
static GBool preload = gFalse;
static char paperSize[15] = "";
static int paperWidth = 0;
static int paperHeight = 0;
static GBool noCrop = gFalse;
static GBool expand = gFalse;
static GBool noShrink = gFalse;
static GBool noCenter = gFalse;
static GBool pageCrop = gFalse;
static GBool duplex = gFalse;
static char ownerPassword[33] = "\001";
static char userPassword[33] = "\001";
static GBool quiet = gFalse;
static char cfgFileName[256] = "";//global configuration file name
static GBool printVersion = gFalse;
static GBool printHelp = gFalse;
string pdftotigerCfgFileName = "";//global pdftotiger.conf configuration file name, must not be static type
PdftotigerConf* pdftotigerConf = NULL;//global pdftotiger.conf configuration file object, must not be static type
ppd_file_t *ppd;// add by peng liu on 03/21/2014 for ppd file reading.

bool cstringEndWith(char *src, char *end)//whether a cstring end with another cstring.
{
	if(strlen(src)<strlen(end))//src is shorter than end.
		return false;
	char *p = src + strlen(src) - strlen(end);//set p point to the last strlen(end) charactors of src.
	if(0 == strcmp(p,end))
		return true;//p equal end.
	else
		return false;//p not equal end.
}

int main(int argc, char *argv[]) {

	fprintf(stderr,"tracking code if any exception happened: begin.\n"); 

	char mystring [100];
	fgets (mystring , 100 , stdin); 
	fprintf(stderr,"tracking stdin: %s \n", mystring); 



	int fd = -1;

	setbuf(stderr, NULL);

	if (argc < 6 || argc > 7) {
		return 1;
	}

	if (argc == 7) {
		fd = open(argv[6], O_RDONLY);
		if (fd < 0) {
			return 1;
		}
	} else {
		fd = 0;
	}
	fprintf(stderr,"tracking code if any exception happened:output argv begin.\n"); 
	fprintf(stderr,"argv[0]:%s argv[1]:%s argv[2]:%s argv[3]:%s argv[4]:%s argv[5]:%s  argv[6]:%s /n",argv[0],argv[1],argv[2],argv[3],argv[4],argv[5],argv[6]); 
	fprintf(stderr,"tracking code if any exception happened:output argv end.\n"); 
	try
	{


		// this filter input is pdf so you can able to download in tmp folder 
		SaveAsPDF();
		fprintf(stderr,"tracking code if any exception happened: after SaveAsPDF.\n"); 

		ppd = ppdOpenFile(getenv("PPD")); //This will give the current ppd file used by the printer

		fprintf(stderr,"tracking code if any exception happened: after ppdOpenFile.\n"); 
		//num_options = cupsParseOptions(argv[5], 0, &options);

		//errno = 0;
		/********************add my code*******************************************************************/     
		// fit your code exactlly here
		//claim variables
		PDFDoc *pdfDoc; //pdf object
		PclOutputDev *pclOut; 
		char *pdfFileName; //pdf file name read from argv
		char *prnFileName; //prn file name read from argv
		int exitCode =99; //program exit cod


		//check parameters  


		pdftotigerCfgFileName.assign("pdftotiger.conf");//read config filename
		fprintf(stderr,"tracking code if any exception happened: after pdftotigerCfgFileName.\n"); 

		pdfFileName =argv[3];  

		fprintf(stderr,"tracking code if any exception happened:output pdffilename begin.\n"); 

		fprintf(stderr,"%s/n",argv[6]); 
		fprintf(stderr,"tracking code if any exception happened:output pdffilename end.\n"); 

		string pdftotigerfilename("pdftotiger.prn");
		prnFileName = const_cast<char*>(pdftotigerfilename.c_str());
		fprintf(stderr,"tracking code if any exception happened: after pdftotigerfilename.\n"); 

		//set pdftotiger config according to 'pdftotiger.conf' specified by cmd argv
		//if pdftotigerCfgFileName is "", PdftotigerConf will be initialized by default setting.
		pdftotigerConf = new PdftotigerConf(pdftotigerCfgFileName);          

		fprintf(stderr,"tracking code if any exception happened: after PdftotigerConf.\n"); 

		//set global config
		globalParams = new GlobalParams(cfgFileName);// read config file name
		fprintf(stderr,"tracking code if any exception happened: after new GlobalParams.\n"); 
#if HAVE_SPLASH
		globalParams->setupBaseFonts(NULL);
		fprintf(stderr,"tracking code if any exception happened: after setupBaseFonts.\n"); 
#endif
		globalParams->setDPIMultiple(100 / 20);
		fprintf(stderr,"tracking code if any exception happened: after setDPIMultiple.\n"); 
		if (quiet) {
			globalParams->setErrQuiet(quiet); 
		}
		fprintf(stderr,"tracking code if any exception happened: after quiet.\n"); 

		//set pdfDoc
		pdfDoc = new PDFDoc(new GString(pdfFileName), NULL, NULL);//create pdf object using pdf file name


		fprintf(stderr,"tracking code if any exception happened: after PDFDoc.\n"); 
		if (!pdfDoc->isOk())
		{//create pdf object fail
			exitCode = 1;
			goto err2;
		}

		//add by Peng Liu  to get all options from front page.
		GetPPDAllSelectionValues();
		fprintf(stderr,"tracking code if any exception happened: after GetPPDAllSelectionValues.\n"); 

		//write tiger file
		pclOut = new PclOutputDev(prnFileName, pdfDoc);


		fprintf(stderr,"tracking code if any exception happened: after PclOutputDev.\n"); 

		pclOut->startDoc(pdfDoc->getXRef());
		fprintf(stderr,"tracking code if any exception happened: after startDoc.\n"); 

		if (pclOut->isOk())
		{  
			fprintf(stderr,"tracking code if any exception happened: after isOk.\n"); 

			pdfDoc->displayPages(pclOut, 1, pdfDoc->getNumPages(), 100, 100, 0,gFalse, gTrue, gFalse);
			fprintf(stderr,"tracking code if any exception happened: after displayPages.\n"); 

		}
		else 
		{
			delete pclOut;
			exitCode = 2;
			goto err2;
		}
		delete pclOut;


		// clean up
		exitCode = 0;
err2:
		delete pdfDoc;
err1:
		delete globalParams;
err0:

		// check for memory leaks
		Object::memCheck(stderr);
		gMemReport(stderr);

		/********************add my code ********************************************************************/     

		if (ppd) {
			ppdClose(ppd);
		}

		if(fd!=0)
			close(fd);

		return exitCode;
		//return 0;

	}
	catch(exception& e)
	{
		//cout << "Main Function exception happened: " <<e.what() << '\n';
		fprintf(stderr,"%s %s","Main Function exception happened",e.what()); 
		if (ppd) {
			ppdClose(ppd);
		}

		if(fd!=0)
			close(fd);

		return 0;
	}
}

#define PDF_FILE "/tmp/pdftotiger.pdf"
void SaveAsPDF() {


	FILE *fpto = NULL;
	char ch;
	fpto = fopen(PDF_FILE, "w");
	/* copy the file */
	if (!fpto) {

		perror("fopen");

		return;
	}

	try 
	{
		while (!feof(stdin)) {
			ch = fgetc(stdin);
			if (ferror(stdin)) {
				exit(1);
			}
			if (!feof(stdin))
				fputc(ch, fpto);
			if (ferror(fpto)) {
				exit(1);
			}
		}
		fclose(fpto);
	}	
	catch(exception& e)
	{
		//cout << "SaveAsPDF Function exception happened: " <<e.what() << '\n';
		fprintf(stderr,"%s %s","SaveAsPDF Function exception happened",e.what()); 
		fclose(fpto);
	}
}
//where choiceName is the name of the option.And this function will return the index of the option selected. add by peng liu on 03/21/14.
string getPPDSelectionIndex(const char * choiceName,
							ppd_file_t * ppd) {
								ppd_choice_t * choice;
								ppd_option_t * option;
								choice = ppdFindMarkedChoice(ppd, choiceName);
								if (choice == NULL) {
									if ((option = ppdFindOption(ppd, choiceName)) == NULL)
										return "";
									if ((choice = ppdFindChoice(option, option->defchoice)) == NULL)
										return "";
								}

								//return atoi(choice->choice);
								return (choice->choice);
}
/****************************************************************************************************************************
creator:Peng Liu 
Date: 23 Apr,2014
Descript: Get all options from font page and reserve these options to one global list variable.
****************************************************************************************************************************/
bool GetPPDAllSelectionValues()
{
	string t_conName;
	string t_conValue;

	try
	{
		t_conName="apersource";
		t_conValue=getPPDSelectionIndex("PaperSrc", ppd);
		if(t_conValue!="")
		{
			SConfig t_config(t_conName,t_conValue);
			m_Configs.push_back(t_config);//add it to list<SConfig>   
		}

		t_conName="epduplexmode";
		t_conValue=getPPDSelectionIndex("DuplexMode", ppd);
		if(t_conValue!="")
		{
			SConfig t_config(t_conName,t_conValue);
			m_Configs.push_back(t_config);//add it to list<SConfig>   
		}

		t_conName="papersize";
		t_conValue=getPPDSelectionIndex("PageSize", ppd);
		if(t_conValue!="")
		{
			SConfig t_config(t_conName,t_conValue);
			m_Configs.push_back(t_config);//add it to list<SConfig>   
		}

		t_conName="resolutiondpi";
		t_conValue=getPPDSelectionIndex("Resolution", ppd);
		if(t_conValue!="")
		{
			SConfig t_config(t_conName,t_conValue);
			m_Configs.push_back(t_config);//add it to list<SConfig>   
		}

		t_conName="brailleforce";
		t_conValue=getPPDSelectionIndex("Brailleforce", ppd);
		if(t_conValue!="")
		{
			SConfig t_config(t_conName,t_conValue);
			m_Configs.push_back(t_config);//add it to list<SConfig>   
		}

		t_conName="inkquality";
		t_conValue=getPPDSelectionIndex("InkQuality", ppd);
		if(t_conValue!="")
		{
			SConfig t_config(t_conName,t_conValue);
			m_Configs.push_back(t_config);//add it to list<SConfig>   
		}

		t_conName="embquality";
		t_conValue=getPPDSelectionIndex("Emboss", ppd);
		if(t_conValue!="")
		{
			SConfig t_config(t_conName,t_conValue);
			m_Configs.push_back(t_config);//add it to list<SConfig>   
		}

		t_conName="mediatype";
		t_conValue=getPPDSelectionIndex("MediaType", ppd);
		if(t_conValue!="")
		{
			SConfig t_config(t_conName,t_conValue);
			m_Configs.push_back(t_config);//add it to list<SConfig>   
		}


		t_conName="orientation";
		t_conValue=getPPDSelectionIndex("Orientation", ppd);
		if(t_conValue!="")
		{
			SConfig t_config(t_conName,t_conValue);
			m_Configs.push_back(t_config);//add it to list<SConfig>   
		}

		t_conName="printmode";
		t_conValue=getPPDSelectionIndex("PrintMode", ppd);
		if(t_conValue!="")
		{
			SConfig t_config(t_conName,t_conValue);
			m_Configs.push_back(t_config);//add it to list<SConfig>   
		}

		return true;
	}
	catch(exception& e)
	{
		//cout << "GetPPDAllSelectionValues Function exception happened: " <<e.what() << '\n';
		fprintf(stderr,"%s %s","GetPPDAllSelectionValues Function exception happened",e.what()); 
		return false;
	}
}





More information about the cups mailing list