]> git.ipfire.org Git - thirdparty/cups.git/blame - examples/testppdx.c
Changelog.
[thirdparty/cups.git] / examples / testppdx.c
CommitLineData
2a5d90e4 1/*
2 * "$Id$"
3 *
4 * Test program for PPD data encoding example code.
5 *
6 * Compile with:
7 *
8 * gcc -o testppdx -D_PPD_DEPRECATED="" -g testppdx.c ppdx.c -lcups -lz
9 *
10 * Copyright 2012 by Apple Inc.
11 *
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
17 *
18 * This file is subject to the Apple OS-Developed Software exception.
19 *
20 * Contents:
21 *
22 * main() - Read data from a test PPD file and write out new chunks.
23 */
24
25/*
26 * Include necessary headers...
27 */
28
29#include <stdio.h>
30#include <string.h>
31#include "ppdx.h"
32
33
34/*
35 * 'main()' - Read data from a test PPD file and write out new chunks.
36 */
37
38int /* O - Exit status */
39main(void)
40{
41 int status = 0; /* Exit status */
42 FILE *fp; /* File to read */
43 char contents[8193], /* Contents of file */
44 *data; /* Data from PPD */
45 size_t contsize, /* File size */
46 datasize; /* Data size */
47 ppd_file_t *ppd; /* Test PPD */
48
49
50 /*
51 * Open the PPD and get the data from it...
52 */
53
54 ppd = ppdOpenFile("testppdx.ppd");
55 data = ppdxReadData(ppd, "EXData", &datasize);
56
57 /*
58 * Open this source file and read it...
59 */
60
61 fp = fopen("testppdx.c", "r");
62 if (fp)
63 {
64 contsize = fread(contents, 1, sizeof(contents) - 1, fp);
65 fclose(fp);
66 contents[contsize] = '\0';
67 }
68 else
69 {
70 contents[0] = '\0';
71 contsize = 0;
72 }
73
74 /*
75 * Compare data...
76 */
77
78 if (data)
79 {
80 if (contsize != datasize)
81 {
82 fprintf(stderr, "ERROR: PPD has %ld bytes, test file is %ld bytes.\n",
83 (long)datasize, (long)contsize);
84 status = 1;
85 }
86 else if (strcmp(contents, data))
87 {
88 fputs("ERROR: PPD and test file are not the same.\n", stderr);
89 status = 1;
90 }
91
92 if (status)
93 {
94 if ((fp = fopen("testppdx.dat", "wb")) != NULL)
95 {
96 fwrite(data, 1, datasize, fp);
97 fclose(fp);
98 fputs("ERROR: See testppdx.dat for data from PPD.\n", stderr);
99 }
100 else
101 perror("Unable to open 'testppdx.dat'");
102 }
103
104 free(data);
105 }
106
107 printf("Encoding %ld bytes for PPD...\n", (long)contsize);
108
109 ppdxWriteData("EXData", contents, contsize);
110
111 return (1);
112}
113
114
115/*
116 * End of "$Id$".
117 */