FreeCalypso > hg > ueda-linux
changeset 38:aa0539cc3d41
pads2gpcb project started, skeleton compiles
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 11 Jan 2016 04:56:51 +0000 |
parents | ce887659d12e |
children | 242f73e61ef0 |
files | .hgignore pads2gpcb/Makefile pads2gpcb/globals.c pads2gpcb/globals.h pads2gpcb/main.c pads2gpcb/rdunits.c pads2gpcb/readpads.c pads2gpcb/struct.h |
diffstat | 8 files changed, 302 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Sun Aug 16 01:51:12 2015 +0000 +++ b/.hgignore Mon Jan 11 04:56:51 2016 +0000 @@ -12,3 +12,5 @@ ^ueda/unet-utils/unet2pcb$ ^ueda/utils/cutelements$ ^ueda/utils/instfileelem$ + +^pads2gpcb/pads2gpcb$
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/Makefile Mon Jan 11 04:56:51 2016 +0000 @@ -0,0 +1,16 @@ +CC= gcc +CFLAGS= -O2 +OBJS= globals.o main.o rdunits.o readpads.o +PROG= pads2gpcb +BINDIR= /usr/local/bin + +all: ${PROG} + +${PROG}: ${OBJS} + ${CC} -o $@ ${OBJS} + +install: + install -c -o bin -g bin -m 755 ${PROG} ${BINDIR} + +clean: + rm -f *.o a.out core errs ${PROG}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/globals.c Mon Jan 11 04:56:51 2016 +0000 @@ -0,0 +1,3 @@ +int input_units_global, input_units_current; +struct part_decal *part_decal_list; +struct part_type *part_type_list;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/globals.h Mon Jan 11 04:56:51 2016 +0000 @@ -0,0 +1,11 @@ +/* globals.c */ +extern int input_units_global, input_units_current; +extern struct part_decal *part_decal_list; +extern struct part_type *part_type_list; + +/* readpads.c */ +extern char *input_filename; +extern int input_lineno; +extern char input_line_buf[], input_line_starkw[]; +extern char *input_line_fields[]; +extern int input_line_nfields;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/main.c Mon Jan 11 04:56:51 2016 +0000 @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include "globals.h" + +main(argc, argv) + char **argv; +{ + if (argc != 2) { + fprintf(stderr, "usage: %s pads-file.asc\n", argv[0]); + exit(1); + } + input_filename = argv[1]; + open_input_file(); + while (get_input_line()) { + if (input_line_buf[0] != '*') + continue; + parse_starline(); +#if 0 +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; + } +#endif + } + exit(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/rdunits.c Mon Jan 11 04:56:51 2016 +0000 @@ -0,0 +1,102 @@ +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include "globals.h" + +long +convert_input_dim(srcstr) + char *srcstr; +{ + long accum; + int sign = 1; + char *cp; + int maxdec, ndec; + + cp = srcstr; + if (*cp == '-') { + cp++; + sign = -1; + } + if (!isdigit(*cp)) { +inv: fprintf(stderr, "%s line %d: invalid dimension \"%s\"\n", + input_filename, input_lineno, srcstr); + exit(1); + } + for (accum = 0; isdigit(*cp); ) { + accum *= 10; + accum += *cp++ - '0'; + } + switch (input_units_current) { + case 'B': + maxdec = 0; + break; + case 'I': + maxdec = 2; + break; + case 'M': + maxdec = 6; + break; + } + if (*cp == '.') { + cp++; + for (ndec = 0; isdigit(*cp); ndec++) { + if (ndec >= maxdec) { + fprintf(stderr, + "%s line %d: dimension \"%s\": too many digits after '.'\n", + input_filename, input_lineno, srcstr); + exit(1); + } + accum *= 10; + accum += *cp++ - '0'; + } + } else + ndec = 0; + if (*cp) + goto inv; + while (ndec < maxdec) { + accum *= 10; + ndec++; + } + switch (input_units_current) { + case 'B': + if (accum % 3) { + fprintf(stderr, + "%s line %d: basic units dimension \"%s\" not divisible by 3\n", + input_filename, input_lineno, srcstr); + exit(1); + } + accum /= 3; + accum *= 2; + break; + case 'I': + accum *= 254; + break; + } + return(accum * sign); +} + +parse_input_angle_90s(srcstr) + char *srcstr; +{ + unsigned long num; + char *cp; + + num = strtoul(srcstr, &cp, 10); + switch (num) { + case 0: + case 90: + case 180: + case 270: + break; + default: + return(-1); + } + if (*cp == '.') { + cp++; + while (*cp) + if (*cp++ != '0') + return(-1); + } else if (*cp) + return(-1); + return(num); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/readpads.c Mon Jan 11 04:56:51 2016 +0000 @@ -0,0 +1,92 @@ +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <strings.h> + +char *input_filename; +int input_lineno; +char input_line_buf[1024], input_line_starkw[64]; + +#define MAX_FIELDS 63 +char *input_line_fields[MAX_FIELDS+1]; +int input_line_nfields; + +static FILE *inf; + +open_input_file() +{ + inf = fopen(input_filename, "r"); + if (!inf) { + perror(input_filename); + exit(1); + } + return(0); +} + +get_input_line() +{ + char *cp; + + if (!fgets(input_line_buf, sizeof input_line_buf, inf)) + return(0); + input_lineno++; + cp = index(input_line_buf, '\n'); + if (!cp) { + fprintf(stderr, "%s line %d: missing newline\n", + input_filename, input_lineno); + exit(1); + } + *cp = '\0'; + if (cp > input_line_buf && cp[-1] == '\r') + *--cp = '\0'; + return(1); +} + +parse_starline() +{ + char *cp, *srcstr; + + srcstr = input_line_buf + 1; + cp = index(srcstr, '*'); + if (!cp) { + fprintf(stderr, "%s line %d: opening '*' but no closing '*'\n", + input_filename, input_lineno); + exit(1); + } + *cp = '\0'; + if (strlen(srcstr) + 1 > sizeof input_line_starkw) { + fprintf(stderr, "%s line %d: star keyword is too long\n", + input_filename, input_lineno); + exit(1); + } + strcpy(input_line_starkw, srcstr); + *cp = '*'; +} + +parse_input_line_fields() +{ + char *cp; + int n; + + cp = input_line_buf; + for (n = 0; ; ) { + while (isspace(*cp)) + cp++; + if (!*cp) + break; + if (n >= MAX_FIELDS) { + fprintf(stderr, + "%s line %d: number of fields exceeds limit\n", + input_filename, input_lineno); + exit(1); + } + input_line_fields[n++] = cp; + while (*cp && !isspace(*cp)) + cp++; + if (*cp) + *cp++ = '\0'; + } + input_line_fields[n] = 0; + input_line_nfields = n; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pads2gpcb/struct.h Mon Jan 11 04:56:51 2016 +0000 @@ -0,0 +1,39 @@ +struct footprint_pad { + long x1; + long y1; + long x2; + long y2; + long thickness; + long clearance; + long mask; + int is_square; +}; + +struct footprint_body { + size_t copysize; + int src_units; + int npins; + struct footprint_pad *pins; + long mark_x; + long mark_y; + long refdes_x; + long refdes_y; + long refdes_dir; + long refdes_scale; +}; + +struct part_decal { + char *name; + struct footprint_body *fpbody; + struct part_decal *next; +}; + +#define MAX_DECALS_PER_PART_TYPE 16 + +struct part_type { + char *name; + int ndecals; + struct part_decals *decals[MAX_DECALS_PER_PART_TYPE]; + char **alpha_pins; + struct part_type *next; +};