changeset 48:c977d637f038

pads2gpcb: decals/* writing implemented
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sat, 30 Jan 2016 17:31:20 +0000
parents 8fa304e2b7e1
children b3b7013d9228
files pads2gpcb/decals.c
diffstat 1 files changed, 36 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pads2gpcb/decals.c	Sat Jan 30 08:23:35 2016 +0000
+++ b/pads2gpcb/decals.c	Sat Jan 30 17:31:20 2016 +0000
@@ -255,6 +255,40 @@
 }
 
 static void
+write_decal_as_element()
+{
+	char *filename, *cp, *dp;
+	int c;
+	FILE *outf;
+
+	filename = malloc(strlen(current_decal->name) * 3 + 8);
+	if (!filename) {
+		perror("malloc for output file name");
+		exit(1);
+	}
+	strcpy(filename, "decals/");
+	dp = filename + 7;
+	for (cp = current_decal->name; *cp; ) {
+		c = *cp++;
+		if (isalnum(c) || c == '-' || c == '.')
+			*dp++ = c;
+		else {
+			sprintf(dp, "%%%02X", c);
+			dp += 3;
+		}
+	}
+	*dp = '\0';
+	outf = fopen(filename, "w");
+	if (!outf) {
+		perror(filename);
+		exit(1);
+	}
+	write_gpcb_element(outf, current_decal->body, 0, "", "", "", 0);
+	fclose(outf);
+	free(filename);
+}
+
+static void
 process_one_decal()
 {
 	int num_drawing_pieces, num_padstack_defs;
@@ -346,7 +380,8 @@
 			exit(1);
 		}
 		*current_decal->body = fpbody;
-		/* optional file output will go here */
+		if (write_decal_files)
+			write_decal_as_element();
 	} else {
 		printf("decal to gpcb fp conversion FAILED\n");
 		free(pins_array);