changeset 47:8fa304e2b7e1

pads2gpcb: parsing of -w options implemented
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sat, 30 Jan 2016 08:23:35 +0000
parents c81aba92cb5e
children c977d637f038
files pads2gpcb/globals.c pads2gpcb/globals.h pads2gpcb/main.c
diffstat 3 files changed, 44 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pads2gpcb/globals.c	Sat Jan 30 07:56:18 2016 +0000
+++ b/pads2gpcb/globals.c	Sat Jan 30 08:23:35 2016 +0000
@@ -1,3 +1,4 @@
 int input_units_global, input_units_current;
 struct part_decal *part_decal_list;
 struct part_type *part_type_list;
+int write_decal_files, write_parttype_files, write_final_elements;
--- a/pads2gpcb/globals.h	Sat Jan 30 07:56:18 2016 +0000
+++ b/pads2gpcb/globals.h	Sat Jan 30 08:23:35 2016 +0000
@@ -2,6 +2,7 @@
 extern int input_units_global, input_units_current;
 extern struct part_decal *part_decal_list;
 extern struct part_type *part_type_list;
+extern int write_decal_files, write_parttype_files, write_final_elements;
 
 /* readpads.c */
 extern char *input_filename;
--- a/pads2gpcb/main.c	Sat Jan 30 07:56:18 2016 +0000
+++ b/pads2gpcb/main.c	Sat Jan 30 08:23:35 2016 +0000
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <ctype.h>
 #include <string.h>
 #include <strings.h>
@@ -28,14 +29,50 @@
 	return(0);
 }
 
+static void
+process_write_option()
+{
+	extern char *optarg;
+
+	if (strlen(optarg) != 1) {
+inv:		fprintf(stderr, "usage error: invalid -w option\n");
+		exit(1);
+	}
+	switch (optarg[0]) {
+	case 'd':
+		write_decal_files = 1;
+		return;
+	case 'p':
+		write_parttype_files = 1;
+		return;
+	case 'e':
+		write_final_elements = 1;
+		return;
+	default:
+		goto inv;
+	}
+}
+
 main(argc, argv)
 	char **argv;
 {
-	if (argc != 2) {
-		fprintf(stderr, "usage: %s pads-file.asc\n", argv[0]);
-		exit(1);
-	}
-	input_filename = argv[1];
+	int c;
+	extern int optind;
+
+	while ((c = getopt(argc, argv, "w:")) != EOF)
+		switch (c) {
+		case 'w':
+			process_write_option();
+			continue;
+		default:
+		usage:
+			fprintf(stderr, "usage: %s [options] pads-file.asc\n",
+				argv[0]);
+			exit(1);
+		}
+	if (argc != optind + 1)
+		goto usage;
+	input_filename = argv[optind];
 	open_input_file();
 
 	/* parse the header line with the units specification */