view ueda/uschem-print/papersize.c @ 38:aa0539cc3d41

pads2gpcb project started, skeleton compiles
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Mon, 11 Jan 2016 04:56:51 +0000
parents cd92449fdb51
children
line wrap: on
line source

#include <stdio.h>
#include <ctype.h>
#include <strings.h>

extern int printsize_x, printsize_y;

struct paper_size_kwtab {
	char	*keyword;
	int	xdim;
	int	ydim;
} paper_sizes[] = {
	{"letter", 792, 612},
	{"legal", 1008, 612},
	{"ledger", 1224, 792},
	{"tabloid", 1224, 792},
	{"11x17", 1224, 792},
	{"A", 792, 612},
	{"B", 1224, 792},
	{"C", 1584, 1224},
	{"D", 2448, 1584},
	{"E", 3168, 2448},
	{NULL, 0, 0}
};

set_paper_size(str)
	char *str;
{
	struct paper_size_kwtab *kwp;
	register char *cp, *np;

	for (kwp = paper_sizes; kwp->keyword; kwp++)
		if (!strcmp(str, kwp->keyword)) {
			printsize_x = kwp->xdim;
			printsize_y = kwp->ydim;
			return;
		}

	cp = str;
	if (!isdigit(*cp)) {
inv:		fprintf(stderr,
		"uschem-print: -P %s: invalid paper size specification\n",
			str);
		exit(1);
	}
	for (np = cp; isdigit(*cp); cp++)
		;
	if (*cp++ != 'x')
		goto inv;
	printsize_x = atoi(np);
	if (!isdigit(*cp))
		goto inv;
	for (np = cp; isdigit(*cp); cp++)
		;
	if (*cp)
		goto inv;
	printsize_y = atoi(np);
}