# HG changeset patch # User Mychaela Falconia # Date 1454138131 0 # Node ID 3bdb1b5ff3d0ab0ab068ff2eb0816596b9131df0 # Parent bf1be6c97c2854038ec27ce38ec22470efbf5d51 pads2gpcb: gpcb dimension output implemented diff -r bf1be6c97c28 -r 3bdb1b5ff3d0 pads2gpcb/Makefile --- a/pads2gpcb/Makefile Sat Jan 30 05:48:04 2016 +0000 +++ b/pads2gpcb/Makefile Sat Jan 30 07:15:31 2016 +0000 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 -OBJS= decals.o globals.o main.o rdunits.o readpads.o -HDRS= globals.h struct.h +OBJS= decals.o globals.o gpcbout.o main.o rdunits.o readpads.o +HDRS= globals.h gpcbout.h struct.h PROG= pads2gpcb BINDIR= /usr/local/bin diff -r bf1be6c97c28 -r 3bdb1b5ff3d0 pads2gpcb/gpcbout.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/gpcbout.c Sat Jan 30 07:15:31 2016 +0000 @@ -0,0 +1,79 @@ +#include +#include +#include +#include + +static char * +generate_decimal(dim, nfract, cp) + long dim; + int nfract; + char *cp; +{ + int i; + + *cp = '\0'; + for (i = 0; i < nfract; i++) { + *--cp = '0' + dim % 10; + dim /= 10; + } + *--cp = '.'; + do { + *--cp = '0' + dim % 10; + dim /= 10; + } while (dim); + return cp; +} + +static void +trim_decimal(str) + char *str; +{ + char *point, *cp; + + point = index(str, '.'); + if (!point) { + fprintf(stderr, + "BUG: gpcbout.c:trim_decimal(): no '.' found\n"); + exit(1); + } + cp = index(str, '\0'); + while (cp > point + 1) { + if (cp[-1] != '0') + break; + cp--; + } + if (cp == point + 1) + cp--; + *cp = '\0'; +} + +char * +output_gpcb_dimension(dim, buf) + long dim; + char *buf; +{ + int negative = 0; + int nfract; + char *unit_suffix, *outptr; + + if (dim == 0) + return "0"; + if (dim < 0) { + negative = 1; + dim = -dim; + } + if (dim % 254) { + nfract = 6; + unit_suffix = "mm"; + } else { + dim /= 254; + nfract = 2; + unit_suffix = "mil"; + } + outptr = generate_decimal(dim, nfract, buf + 12); + trim_decimal(outptr); + strcat(outptr, unit_suffix); + if (negative) + *--outptr = '-'; + return outptr; +} diff -r bf1be6c97c28 -r 3bdb1b5ff3d0 pads2gpcb/gpcbout.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/gpcbout.h Sat Jan 30 07:15:31 2016 +0000 @@ -0,0 +1,1 @@ +#define DIM_OUT_BUFSIZE 16