#include <stdio.h>
#include <string.h>
#include "ppdx.h"
int
main(void)
{
int status = 0;
FILE *fp;
char contents[8193],
*data;
size_t contsize,
datasize;
ppd_file_t *ppd;
ppd = ppdOpenFile("testppdx.ppd");
data = ppdxReadData(ppd, "EXData", &datasize);
fp = fopen("testppdx.c", "r");
if (fp)
{
contsize = fread(contents, 1, sizeof(contents) - 1, fp);
fclose(fp);
contents[contsize] = '\0';
}
else
{
contents[0] = '\0';
contsize = 0;
}
if (data)
{
if (contsize != datasize)
{
fprintf(stderr, "ERROR: PPD has %ld bytes, test file is %ld bytes.\n",
(long)datasize, (long)contsize);
status = 1;
}
else if (strcmp(contents, data))
{
fputs("ERROR: PPD and test file are not the same.\n", stderr);
status = 1;
}
if (status)
{
if ((fp = fopen("testppdx.dat", "wb")) != NULL)
{
fwrite(data, 1, datasize, fp);
fclose(fp);
fputs("ERROR: See testppdx.dat for data from PPD.\n", stderr);
}
else
perror("Unable to open 'testppdx.dat'");
}
free(data);
}
printf("Encoding %ld bytes for PPD...\n", (long)contsize);
ppdxWriteData("EXData", contents, contsize);
return (1);
}