FreeCalypso > hg > ueda-linux
view pads2gpcb/rdunits.c @ 57:d0d330ae5b99
pads2gpcb/writeelem.c: ElementArc writing implemented
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Sun, 31 Jan 2016 02:36:02 +0000 |
parents | 43ba91b137e2 |
children |
line wrap: on
line source
#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, rounderr; 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) { printf( "warning: line %d basic units dimension \"%s\" not divisible by 3\n", input_lineno, srcstr); rounderr = 1; } else rounderr = 0; accum /= 3; accum *= 2; accum += rounderr; 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); }