FreeCalypso > hg > ueda-linux
changeset 65:2b71943a311b
pads2gpcb: PART section parsing implemented, compiles
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Sun, 31 Jan 2016 21:32:08 +0000 |
parents | 6a1197106b6f |
children | 68900e8dcda1 |
files | pads2gpcb/Makefile pads2gpcb/globals.c pads2gpcb/globals.h pads2gpcb/main.c pads2gpcb/partinst.c pads2gpcb/parttype.c pads2gpcb/struct.h |
diffstat | 7 files changed, 193 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/pads2gpcb/Makefile Sun Jan 31 07:37:09 2016 +0000 +++ b/pads2gpcb/Makefile Sun Jan 31 21:32:08 2016 +0000 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 -OBJS= decals.o globals.o gpcbout.o main.o parttype.o rdunits.o readpads.o \ - silkselect.o util.o writeelem.o +OBJS= decals.o globals.o gpcbout.o main.o partinst.o parttype.o rdunits.o \ + readpads.o silkselect.o util.o writeelem.o HDRS= globals.h gpcbout.h struct.h PROG= pads2gpcb BINDIR= /usr/local/bin
--- a/pads2gpcb/globals.c Sun Jan 31 07:37:09 2016 +0000 +++ b/pads2gpcb/globals.c Sun Jan 31 21:32:08 2016 +0000 @@ -1,5 +1,6 @@ int input_units_global, input_units_current; struct part_decal *part_decal_list; struct part_type *part_type_list; +struct part_instance *part_inst_list; int do_footprint_silk; int write_decal_files, write_parttype_files, write_final_elements;
--- a/pads2gpcb/globals.h Sun Jan 31 07:37:09 2016 +0000 +++ b/pads2gpcb/globals.h Sun Jan 31 21:32:08 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 struct part_instance *part_inst_list; extern int do_footprint_silk; extern int write_decal_files, write_parttype_files, write_final_elements;
--- a/pads2gpcb/main.c Sun Jan 31 07:37:09 2016 +0000 +++ b/pads2gpcb/main.c Sun Jan 31 21:32:08 2016 +0000 @@ -103,12 +103,10 @@ process_parttype_section(); goto loop; } -#if 0 if (!strcmp(input_line_starkw, "PART")) { process_part_section(); goto loop; } -#endif } exit(0); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/partinst.c Sun Jan 31 21:32:08 2016 +0000 @@ -0,0 +1,164 @@ +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include "globals.h" +#include "struct.h" + +extern struct part_type *find_parttype_by_name(); +extern struct part_decal *find_decal_by_name(); +extern long convert_input_dim(); + +static struct part_instance *our_part; + +static void +enter_part_inst() +{ + struct part_instance *p, **pp; + char *name = input_line_fields[0]; + + for (pp = &part_inst_list; p = *pp; pp = &p->next) + if (!strcmp(p->name, name)) { + fprintf(stderr, + "%s line %d: part instance \"%s\" already defined\n", + input_filename, input_lineno, name); + exit(1); + } + p = malloc(sizeof(struct part_instance) + strlen(name) + 1); + if (!p) { + perror("malloc of struct part_instance"); + exit(1); + } + bzero(p, sizeof(struct part_instance)); + p->name = (char *)(p + 1); + strcpy(p->name, name); + *pp = p; + our_part = p; +} + +static void +select_decal_by_name(decalname) + char *decalname; +{ + our_part->decal = find_decal_by_name(decalname); + if (!our_part->decal) { + fprintf(stderr, + "%s line %d: part instantiation refers to unknown decal name \"%s\"\n", + input_filename, input_lineno, decalname); + exit(1); + } +} + +static void +select_decal_by_number() +{ + char *strnum = input_line_fields[7]; + int num = atoi(strnum); + + if (num < 0 || num >= our_part->type->ndecals) { + fprintf(stderr, + "%s line %d: invalid decal number \"%s\" in PART line\n", + input_filename, input_lineno, strnum); + exit(1); + } + our_part->decal = our_part->type->decals[num]; +} + +static void +find_type_and_decal() +{ + char *typename = input_line_fields[1]; + char *decalname; + + decalname = index(typename, '@'); + if (decalname) + *decalname++; + our_part->type = find_parttype_by_name(typename); + if (!our_part->type) { + fprintf(stderr, + "%s line %d: part instantiation refers to unknown part type \"%s\"\n", + input_filename, input_lineno, typename); + exit(1); + } + if (decalname) + select_decal_by_name(decalname); + else + select_decal_by_number(); +} + +static void +one_attr_label() +{ + int i; + + /* just skip it for now */ + for (i = 0; i < 3; i++) { + if (!get_input_line()) { + fprintf(stderr, + "error: EOF when expecting a part label line\n"); + exit(1); + } + } +} + +static void +read_one_part() +{ + int num_attr_labels, i; + + if (input_line_nfields < 8 || input_line_nfields > 12) { + fprintf(stderr, + "%s line %d: expected beginning of part instance, wrong # of fields\n", + input_filename, input_lineno); + exit(1); + } + enter_part_inst(); + printf("Processing part instance %s\n", our_part->name); + find_type_and_decal(); + our_part->mark_x = convert_input_dim(input_line_fields[2]); + our_part->mark_y = -convert_input_dim(input_line_fields[3]); + our_part->ori = parse_input_angle_90s(input_line_fields[4]); + if (!strcmp(input_line_fields[6], "N")) + our_part->onbottom = 0; + else if (!strcmp(input_line_fields[6], "M")) + our_part->onbottom = 1; + else { + fprintf(stderr, "%s line %d: expected 'N' or 'M' in field 6\n", + input_filename, input_lineno); + exit(1); + } + if (input_line_nfields > 11) + num_attr_labels = atoi(input_line_fields[11]); + else + num_attr_labels = 0; + for (i = 0; i < num_attr_labels; i++) + one_attr_label(); +} + +static void +process_one_part() +{ + read_one_part(); +} + +process_part_section() +{ + input_units_current = input_units_global; + for (;;) { + if (!get_input_line()) { + fprintf(stderr, "error: EOF in PART section\n"); + exit(1); + } + if (input_line_buf[0] == '*') { + parse_starline(); + if (strcmp(input_line_starkw, "REMARK")) + break; + else + continue; + } + parse_input_line_fields(); + if (input_line_nfields) + process_one_part(); + } +}
--- a/pads2gpcb/parttype.c Sun Jan 31 07:37:09 2016 +0000 +++ b/pads2gpcb/parttype.c Sun Jan 31 21:32:08 2016 +0000 @@ -186,3 +186,15 @@ process_one_parttype(); } } + +struct part_type * +find_parttype_by_name(name) + char *name; +{ + struct part_type *p; + + for (p = part_type_list; p; p = p->next) + if (!strcmp(p->name, name)) + break; + return(p); +}
--- a/pads2gpcb/struct.h Sun Jan 31 07:37:09 2016 +0000 +++ b/pads2gpcb/struct.h Sun Jan 31 21:32:08 2016 +0000 @@ -70,3 +70,16 @@ char **alpha_pins; struct part_type *next; }; + +struct part_instance { + char *name; + char *newname; + struct part_type *type; + struct part_decal *decal; + long mark_x; + long mark_y; + int ori; + int onbottom; + struct footprint_body *body; + struct part_instance *next; +};