File: [Platon] / cpdf / cpdf.c (download)
Revision 1.15, Tue Feb 11 20:10:30 2003 UTC (21 years, 2 months ago) by lynx
Changes since 1.14: +6 -9
lines
improved reading and working with objects
remove read bug from get_startxref() if PDF uses \r\n as a newline.
better reading streams.
AND MANY MANY MORE! :))) but you still cant use it :-D
|
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <vga.h>
#include <vgagl.h>
#include <unistd.h>
#include <fcntl.h>
#include <getopt.h>
#include <mcheck.h>
#include "parse.h"
#include "cpdf.h"
#include "svga.h"
/* $Platon: cpdf/cpdf.c,v 1.14 2002/12/23 02:40:05 lynx Exp $ */
static struct option lopt[] = {
{"mode", required_argument, 0, 'm'},
{"page", required_argument, 0, 'p'},
{0, 0, 0, 0}
};
void loop(void);
void usage(char *prg)
{
printf("Usage: %s <file> [-mode mode] [-page page]\n", prg);
exit(errno);
}
int main(int argc, char **argv)
{
char c;
int mode = G800x600x64K, in = 0;
int p = 0;
if (argc == 1)
usage(argv[0]);
while ((c =
getopt_long(argc - 1, &argv[1], "m:p:", lopt,
&in)) != -1) {
switch (c) {
case 'm':
if (argv[optind + 1] == NULL)
usage(argv[0]);
if ((mode =
vga_getmodenumber(argv[optind + 1])) == -1) {
fprintf(stderr,
"Unsupported mode %s! Using default.\n",
argv[optind + 1]);
if ((mode = vga_getdefaultmode()) == -1) {
fprintf(stderr,
"SVGALIB_DEFAULT_MODE variable is empty!\n");
usage(argv[0]);
}
}
break;
case 'p':
p = atoi(optarg);
break;
default:
fprintf(stderr, "%s", strerror(errno));
exit(errno);
}
}
if ((fp = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "Can't open %s: %s\n", argv[1],
strerror(errno));
exit(errno);
}
{
char ispdf[5];
fread(ispdf, sizeof(ispdf), sizeof(char), fp);
if (strncmp(ispdf, "%PDF-", sizeof(ispdf)) != 0) {
fprintf(stderr, "%s is not PDF document!\n",
argv[1]);
exit(errno);
}
}
#ifndef DEBUG
printf("Using %s mode\n", vga_getmodename(mode));
vga_init();
vga_setmode(mode);
gl_setcontextvga(mode);
physicalscreen = gl_allocatecontext();
gl_getcontext(physicalscreen);
gl_setcontextvgavirtual(mode);
virtualscreen = gl_allocatecontext();
gl_getcontext(virtualscreen);
gl_setcontext(virtualscreen);
gl_clearscreen(0xFFFFFFFF);
{
char *i;
i = vga_getmodename(mode) + 1;
screen.x = (int) strtoul(i, NULL, 10);
i = (char *) strchr(i, 'x') + 1;
screen.y = (int) strtoul(i, NULL, 10);
i = (char *) strchr(i, 'x') + 1;
if (*i == '2' && *(i + 1) == '\0')
screen.color = 2;
if (*i == '1' && *(i + 1) == '6' && *(i + 2) == '\0')
screen.color = 16;
if (!strncmp(i, "256", 3))
screen.color = 256;
if (!strncmp(i, "32K", 3))
screen.color = K32;
if (!strncmp(i, "64K", 3))
screen.color = K64;
if (!strncmp(i, "16M", 3))
screen.color = M16;
}
#endif
parse_pdf();
current_page = p;
loop();
vga_setmode(TEXT);
fclose(fp);
exit(0);
}
void loop(void)
{
while (page_tree[current_page]) {
render();
current_page++;
}
return;
}
Platon Group <platon@platon.org> http://platon.org/
|