changeset 39:242f73e61ef0

pads2gpcb: implemented parsing of the header line with units spec
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Mon, 11 Jan 2016 05:09:25 +0000
parents aa0539cc3d41
children 1c37bec20596
files pads2gpcb/main.c
diffstat 1 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pads2gpcb/main.c	Mon Jan 11 04:56:51 2016 +0000
+++ b/pads2gpcb/main.c	Mon Jan 11 05:09:25 2016 +0000
@@ -5,6 +5,29 @@
 #include <strings.h>
 #include "globals.h"
 
+static
+parse_header_line()
+{
+	char *cp;
+
+	if (strncmp(input_line_buf, "!PADS-POWERPCB-", 15))
+		return(-1);
+	cp = input_line_buf + 15;
+	while (isalnum(*cp) || *cp == '.')
+		cp++;
+	if (*cp++ != '-')
+		return(-1);
+	if (!strncmp(cp, "BASIC", 5))
+		input_units_global = 'B';
+	else if (!strncmp(cp, "MILS", 4))
+		input_units_global = 'I';
+	else if (!strncmp(cp, "METRIC", 6))
+		input_units_global = 'M';
+	else
+		return(-1);
+	return(0);
+}
+
 main(argc, argv)
 	char **argv;
 {
@@ -14,6 +37,18 @@
 	}
 	input_filename = argv[1];
 	open_input_file();
+
+	/* parse the header line with the units specification */
+	if (!get_input_line()) {
+invheader:	fprintf(stderr,
+		"error: %s does not begin with a recognized header line\n",
+			input_filename);
+		exit(1);
+	}
+	if (parse_header_line() < 0)
+		goto invheader;
+
+	/* process the body of the monster! */
 	while (get_input_line()) {
 		if (input_line_buf[0] != '*')
 			continue;