FreeCalypso > hg > ueda-linux
changeset 75:959df5ddf7a2
pads2gpcb: command line dimension input implemented
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Feb 2016 02:09:25 +0000 |
parents | 58f11f06d831 |
children | f673b6ad2a78 |
files | pads2gpcb/Makefile pads2gpcb/cmdline.c |
diffstat | 2 files changed, 66 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/pads2gpcb/Makefile Mon Feb 01 00:45:24 2016 +0000 +++ b/pads2gpcb/Makefile Mon Feb 01 02:09:25 2016 +0000 @@ -1,7 +1,8 @@ CC= gcc CFLAGS= -O2 -OBJS= decals.o fpmanip.o globals.o gpcbout.o main.o mainoutput.o partinst.o \ - parttype.o rdunits.o readpads.o silkselect.o util.o writeelem.o +OBJS= cmdline.o decals.o fpmanip.o globals.o gpcbout.o main.o mainoutput.o \ + partinst.o parttype.o rdunits.o readpads.o silkselect.o util.o \ + writeelem.o HDRS= globals.h gpcbout.h struct.h PROG= pads2gpcb BINDIR= /usr/local/bin
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/cmdline.c Mon Feb 01 02:09:25 2016 +0000 @@ -0,0 +1,63 @@ +#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); +}