]> git.ipfire.org Git - thirdparty/cups.git/blame - examples/testppdx.c
Remove all of the Subversion keywords from various source files.
[thirdparty/cups.git] / examples / testppdx.c
CommitLineData
a29fd7dd 1/*
503b54c9 2 * Test program for PPD data encoding example code.
a29fd7dd 3 *
503b54c9 4 * Compile with:
a29fd7dd 5 *
503b54c9 6 * gcc -o testppdx -D_PPD_DEPRECATED="" -g testppdx.c ppdx.c -lcups -lz
a29fd7dd 7 *
503b54c9 8 * Copyright 2012 by Apple Inc.
a29fd7dd 9 *
503b54c9
MS
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/".
a29fd7dd 15 *
503b54c9 16 * This file is subject to the Apple OS-Developed Software exception.
a29fd7dd
MS
17 */
18
19/*
20 * Include necessary headers...
21 */
22
23#include <stdio.h>
24#include <string.h>
25#include "ppdx.h"
26
27
28/*
29 * 'main()' - Read data from a test PPD file and write out new chunks.
30 */
31
32int /* O - Exit status */
33main(void)
34{
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 */
42
43
44 /*
45 * Open the PPD and get the data from it...
46 */
47
48 ppd = ppdOpenFile("testppdx.ppd");
49 data = ppdxReadData(ppd, "EXData", &datasize);
50
51 /*
52 * Open this source file and read it...
53 */
54
55 fp = fopen("testppdx.c", "r");
56 if (fp)
57 {
58 contsize = fread(contents, 1, sizeof(contents) - 1, fp);
59 fclose(fp);
60 contents[contsize] = '\0';
61 }
62 else
63 {
64 contents[0] = '\0';
65 contsize = 0;
66 }
67
68 /*
69 * Compare data...
70 */
71
72 if (data)
73 {
74 if (contsize != datasize)
75 {
76 fprintf(stderr, "ERROR: PPD has %ld bytes, test file is %ld bytes.\n",
77 (long)datasize, (long)contsize);
78 status = 1;
79 }
80 else if (strcmp(contents, data))
81 {
82 fputs("ERROR: PPD and test file are not the same.\n", stderr);
83 status = 1;
84 }
85
86 if (status)
87 {
88 if ((fp = fopen("testppdx.dat", "wb")) != NULL)
89 {
90 fwrite(data, 1, datasize, fp);
91 fclose(fp);
92 fputs("ERROR: See testppdx.dat for data from PPD.\n", stderr);
93 }
94 else
95 perror("Unable to open 'testppdx.dat'");
96 }
97
98 free(data);
99 }
100
101 printf("Encoding %ld bytes for PPD...\n", (long)contsize);
102
103 ppdxWriteData("EXData", contents, contsize);
104
105 return (1);
106}