changeset 45:3bdb1b5ff3d0

pads2gpcb: gpcb dimension output implemented
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sat, 30 Jan 2016 07:15:31 +0000
parents bf1be6c97c28
children c81aba92cb5e
files pads2gpcb/Makefile pads2gpcb/gpcbout.c pads2gpcb/gpcbout.h
diffstat 3 files changed, 82 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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
 
--- /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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+
+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;
+}
--- /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