view pads2gpcb/cmdline.c @ 94:73029295c4dd

ifctf-part-lib/uschem-symbols: added Si1032R.pinout and ipc-diode.pinout
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 24 Aug 2019 08:54:11 +0000
parents 959df5ddf7a2
children
line wrap: on
line source

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

long
cmdline_dim_arg(srcstr)
	char *srcstr;
{
	long accum;
	int sign = 1, mult;
	char *cp;
	int maxdec, ndec;

	cp = index(srcstr, 'm');
	if (!cp) {
inv:		fprintf(stderr, "invalid command line dimension input \"%s\"\n",
			srcstr);
		exit(1);
	}
	if (!strcmp(cp, "mm")) {
		mult = 1;
		maxdec = 6;
	} else if (!strcmp(cp, "mil")) {
		mult = 254;
		maxdec = 2;
	} else
		goto inv;

	cp = srcstr;
	if (*cp == '-') {
		cp++;
		sign = -1;
	}
	if (!isdigit(*cp))
		goto inv;
	for (accum = 0; isdigit(*cp); ) {
		accum *= 10;
		accum += *cp++ - '0';
	}
	if (*cp == '.') {
		cp++;
		for (ndec = 0; isdigit(*cp); ndec++) {
			if (ndec >= maxdec) {
				fprintf(stderr,
	"command line dimension input \"%s\": too many digits after '.'\n",
					srcstr);
				exit(1);
			}
			accum *= 10;
			accum += *cp++ - '0';
		}
	} else
		ndec = 0;
	if (*cp != 'm')
		goto inv;
	while (ndec < maxdec) {
		accum *= 10;
		ndec++;
	}
	return(accum * mult * sign);
}