FreeCalypso > hg > ueda-linux
changeset 63:455a0051f9d2
pads2gpcb: PARTTYPE parsing implemented, compiles
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Sun, 31 Jan 2016 07:32:08 +0000 |
parents | 9d7e2937883d |
children | 6a1197106b6f |
files | pads2gpcb/Makefile pads2gpcb/decals.c pads2gpcb/parttype.c pads2gpcb/struct.h pads2gpcb/util.c |
diffstat | 5 files changed, 223 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/pads2gpcb/Makefile Sun Jan 31 05:30:33 2016 +0000 +++ b/pads2gpcb/Makefile Sun Jan 31 07:32:08 2016 +0000 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 -OBJS= decals.o globals.o gpcbout.o main.o rdunits.o readpads.o silkselect.o \ - writeelem.o +OBJS= decals.o globals.o gpcbout.o main.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/decals.c Sun Jan 31 05:30:33 2016 +0000 +++ b/pads2gpcb/decals.c Sun Jan 31 07:32:08 2016 +0000 @@ -592,3 +592,15 @@ process_one_decal(); } } + +struct part_decal * +find_decal_by_name(name) + char *name; +{ + struct part_decal *p; + + for (p = part_decal_list; p; p = p->next) + if (!strcmp(p->name, name)) + break; + return(p); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/parttype.c Sun Jan 31 07:32:08 2016 +0000 @@ -0,0 +1,188 @@ +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include "globals.h" +#include "struct.h" + +extern struct part_decal *find_decal_by_name(); +extern char *savestr(); + +static struct part_type *our_parttype; +static int ngates, nsignals; + +static void +enter_parttype() +{ + struct part_type *p, **pp; + char *name = input_line_fields[0]; + + for (pp = &part_type_list; p = *pp; pp = &p->next) + if (!strcmp(p->name, name)) { + fprintf(stderr, + "%s line %d: part type name \"%s\" already defined\n", + input_filename, input_lineno, name); + exit(1); + } + p = malloc(sizeof(struct part_type) + strlen(name) + 1); + if (!p) { + perror("malloc of struct part_type"); + exit(1); + } + bzero(p, sizeof(struct part_type)); + p->name = (char *)(p + 1); + strcpy(p->name, name); + *pp = p; + our_parttype = p; +} + +static void +find_decals() +{ + char *cp, *np; + struct part_decal *decal; + + for (cp = input_line_fields[1]; cp; cp = np) { + np = index(cp, ':'); + if (np) + *np++ = '\0'; + if (!*cp) + continue; + decal = find_decal_by_name(cp); + if (!decal) { + fprintf(stderr, +"%s line %d: part type definition refers to unknown decal name \"%s\"\n", + input_filename, input_lineno, cp); + exit(1); + } + if (our_parttype->ndecals >= MAX_DECALS_PER_PART_TYPE) { + fprintf(stderr, + "%s line %d: MAX_DECALS_PER_PART_TYPE exceeded\n", + input_filename, input_lineno); + exit(1); + } + our_parttype->decals[our_parttype->ndecals++] = decal; + } + if (!our_parttype->ndecals) { + fprintf(stderr, + "%s line %d: empty list of decals in part type def\n", + input_filename, input_lineno); + exit(1); + } +} + +static void +process_header_line() +{ + if (input_line_nfields < 6) { + fprintf(stderr, +"%s line %d: expected beginning of part type definition, wrong # of fields\n", + input_filename, input_lineno); + exit(1); + } + enter_parttype(); + printf("Processing part type %s\n", our_parttype->name); + find_decals(); + ngates = atoi(input_line_fields[3]); + nsignals = atoi(input_line_fields[4]); + our_parttype->num_alpha_pins = atoi(input_line_fields[5]); +} + +static void +get_line_internal() +{ + if (!get_input_line()) { + fprintf(stderr, + "error: EOF in the middle of a part type definition\n"); + exit(1); + } +} + +static void +process_one_gate_def() +{ + int gatepins; + + get_line_internal(); + parse_input_line_fields(); + if (input_line_nfields != 3 || strcmp(input_line_fields[0], "G")) { + fprintf(stderr, "%s line %d: expected gate def header line\n", + input_filename, input_lineno); + exit(1); + } + gatepins = atoi(input_line_fields[2]); + while (gatepins > 0) { + get_line_internal(); + parse_input_line_fields(); + gatepins -= input_line_nfields; + } +} + +static void +alloc_alpha_pins_array() +{ + our_parttype->alpha_pins = + malloc(sizeof(char *) * our_parttype->num_alpha_pins); + if (!our_parttype->alpha_pins) { + perror("malloc of alpha_pins array"); + exit(1); + } +} + +static void +read_alpha_pins() +{ + int idx, i; + + for (idx = 0; idx < our_parttype->num_alpha_pins; ) { + get_line_internal(); + parse_input_line_fields(); + for (i = 0; i < input_line_nfields; i++) { + if (idx >= our_parttype->num_alpha_pins) { + fprintf(stderr, + "%s line %d: alpha_pins array overflow\n", + input_filename, input_lineno); + exit(1); + } + our_parttype->alpha_pins[idx++] = + savestr(input_line_fields[i]); + } + } +} + +static void +process_one_parttype() +{ + int i; + + process_header_line(); + for (i = 0; i < ngates; i++) + process_one_gate_def(); + for (i = 0; i < nsignals; i++) + get_line_internal(); + if (our_parttype->num_alpha_pins) { + alloc_alpha_pins_array(); + read_alpha_pins(); + } +} + +process_parttype_section() +{ + for (;;) { + if (!get_input_line()) { + fprintf(stderr, "error: EOF in PARTTYPE 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_parttype(); + } +}
--- a/pads2gpcb/struct.h Sun Jan 31 05:30:33 2016 +0000 +++ b/pads2gpcb/struct.h Sun Jan 31 07:32:08 2016 +0000 @@ -65,7 +65,8 @@ struct part_type { char *name; int ndecals; - struct part_decals *decals[MAX_DECALS_PER_PART_TYPE]; + struct part_decal *decals[MAX_DECALS_PER_PART_TYPE]; + int num_alpha_pins; char **alpha_pins; struct part_type *next; };
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/util.c Sun Jan 31 07:32:08 2016 +0000 @@ -0,0 +1,19 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> + +char * +savestr(srcstr) + char *srcstr; +{ + char *buf; + + buf = malloc(strlen(srcstr) + 1); + if (!buf) { + perror("malloc in savestr"); + exit(1); + } + strcpy(buf, srcstr); + return(buf); +}