view pads2gpcb/main.c @ 81:6e43956e740d

beginning of BOM utils refactoring: seqrefdes code factored out
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 23 Feb 2017 19:15:48 +0000
parents be1fe110b6ab
children
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "globals.h"

extern long cmdline_dim_arg();

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;
{
	int c;
	char *main_output;
	extern int optind;
	extern char *optarg;

	while ((c = getopt(argc, argv, "c:fm:s:x:y:")) != EOF)
		switch (c) {
		case 'c':
			clearance_setting = cmdline_dim_arg(optarg);
			continue;
		case 'f':
			write_footprint_files = 1;
			continue;
		case 'm':
			soldermask_delta = cmdline_dim_arg(optarg);
			continue;
		case 's':
			do_footprint_silk = 1;
			select_drawlevel_for_silk(atoi(optarg));
			continue;
		case 'x':
			output_x_offset = cmdline_dim_arg(optarg);
			continue;
		case 'y':
			output_y_offset = cmdline_dim_arg(optarg);
			continue;
		default:
		usage:
			fprintf(stderr,
			"usage: %s [options] pads-file.asc [output.pcb]\n",
				argv[0]);
			exit(1);
		}
	if (argc < optind + 1 || argc > optind + 2)
		goto usage;
	input_filename = argv[optind];
	main_output = argv[optind+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;
		parse_starline();
loop:		if (!strcmp(input_line_starkw, "PARTDECAL")) {
			process_partdecal_section();
			goto loop;
		}
		if (!strcmp(input_line_starkw, "PARTTYPE")) {
			process_parttype_section();
			goto loop;
		}
		if (!strcmp(input_line_starkw, "PART")) {
			process_part_section();
			goto loop;
		}
	}
	if (main_output)
		write_elements_pcb(main_output);
	exit(0);
}