# HG changeset patch # User Mychaela Falconia # Date 1452488965 0 # Node ID 242f73e61ef06c2c97db8b285b5a65a3d678c1c3 # Parent aa0539cc3d412a7d837ac743e2c5109993eb600b pads2gpcb: implemented parsing of the header line with units spec diff -r aa0539cc3d41 -r 242f73e61ef0 pads2gpcb/main.c --- 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 #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;