]>
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 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
14 * Include necessary headers...
23 * 'main()' - Read data from a test PPD file and write out new chunks.
26 int /* O - Exit status */
29 int status
= 0; /* Exit status */
30 FILE *fp
; /* File to read */
31 char contents
[8193], /* Contents of file */
32 *data
; /* Data from PPD */
33 size_t contsize
, /* File size */
34 datasize
; /* Data size */
35 ppd_file_t
*ppd
; /* Test PPD */
39 * Open the PPD and get the data from it...
42 ppd
= ppdOpenFile("testppdx.ppd");
43 data
= ppdxReadData(ppd
, "EXData", &datasize
);
46 * Open this source file and read it...
49 fp
= fopen("testppdx.c", "r");
52 contsize
= fread(contents
, 1, sizeof(contents
) - 1, fp
);
54 contents
[contsize
] = '\0';
68 if (contsize
!= datasize
)
70 fprintf(stderr
, "ERROR: PPD has %ld bytes, test file is %ld bytes.\n",
71 (long)datasize
, (long)contsize
);
74 else if (strcmp(contents
, data
))
76 fputs("ERROR: PPD and test file are not the same.\n", stderr
);
82 if ((fp
= fopen("testppdx.dat", "wb")) != NULL
)
84 fwrite(data
, 1, datasize
, fp
);
86 fputs("ERROR: See testppdx.dat for data from PPD.\n", stderr
);
89 perror("Unable to open 'testppdx.dat'");
95 printf("Encoding %ld bytes for PPD...\n", (long)contsize
);
97 ppdxWriteData("EXData", contents
, contsize
);