]>
git.ipfire.org Git - thirdparty/cups.git/blob - examples/testppdx.c
2 * Test program for PPD data encoding example code.
6 * gcc -o testppdx -D_PPD_DEPRECATED="" -g testppdx.c ppdx.c -lcups -lz
8 * Copyright 2012 by Apple Inc.
10 * These coded instructions, statements, and computer programs are the
11 * property of Apple Inc. and are protected by Federal copyright
12 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
13 * which should have been included with this file. If this file is
14 * file is missing or damaged, see the license at "http://www.cups.org/".
16 * This file is subject to the Apple OS-Developed Software exception.
20 * Include necessary headers...
29 * 'main()' - Read data from a test PPD file and write out new chunks.
32 int /* O - Exit status */
35 int status
= 0; /* Exit status */
36 FILE *fp
; /* File to read */
37 char contents
[8193], /* Contents of file */
38 *data
; /* Data from PPD */
39 size_t contsize
, /* File size */
40 datasize
; /* Data size */
41 ppd_file_t
*ppd
; /* Test PPD */
45 * Open the PPD and get the data from it...
48 ppd
= ppdOpenFile("testppdx.ppd");
49 data
= ppdxReadData(ppd
, "EXData", &datasize
);
52 * Open this source file and read it...
55 fp
= fopen("testppdx.c", "r");
58 contsize
= fread(contents
, 1, sizeof(contents
) - 1, fp
);
60 contents
[contsize
] = '\0';
74 if (contsize
!= datasize
)
76 fprintf(stderr
, "ERROR: PPD has %ld bytes, test file is %ld bytes.\n",
77 (long)datasize
, (long)contsize
);
80 else if (strcmp(contents
, data
))
82 fputs("ERROR: PPD and test file are not the same.\n", stderr
);
88 if ((fp
= fopen("testppdx.dat", "wb")) != NULL
)
90 fwrite(data
, 1, datasize
, fp
);
92 fputs("ERROR: See testppdx.dat for data from PPD.\n", stderr
);
95 perror("Unable to open 'testppdx.dat'");
101 printf("Encoding %ld bytes for PPD...\n", (long)contsize
);
103 ppdxWriteData("EXData", contents
, contsize
);