FreeCalypso > hg > ueda-linux
comparison pads2gpcb/rdunits.c @ 38:aa0539cc3d41
pads2gpcb project started, skeleton compiles
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 11 Jan 2016 04:56:51 +0000 |
parents | |
children | 43ba91b137e2 |
comparison
equal
deleted
inserted
replaced
37:ce887659d12e | 38:aa0539cc3d41 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <ctype.h> | |
4 #include "globals.h" | |
5 | |
6 long | |
7 convert_input_dim(srcstr) | |
8 char *srcstr; | |
9 { | |
10 long accum; | |
11 int sign = 1; | |
12 char *cp; | |
13 int maxdec, ndec; | |
14 | |
15 cp = srcstr; | |
16 if (*cp == '-') { | |
17 cp++; | |
18 sign = -1; | |
19 } | |
20 if (!isdigit(*cp)) { | |
21 inv: fprintf(stderr, "%s line %d: invalid dimension \"%s\"\n", | |
22 input_filename, input_lineno, srcstr); | |
23 exit(1); | |
24 } | |
25 for (accum = 0; isdigit(*cp); ) { | |
26 accum *= 10; | |
27 accum += *cp++ - '0'; | |
28 } | |
29 switch (input_units_current) { | |
30 case 'B': | |
31 maxdec = 0; | |
32 break; | |
33 case 'I': | |
34 maxdec = 2; | |
35 break; | |
36 case 'M': | |
37 maxdec = 6; | |
38 break; | |
39 } | |
40 if (*cp == '.') { | |
41 cp++; | |
42 for (ndec = 0; isdigit(*cp); ndec++) { | |
43 if (ndec >= maxdec) { | |
44 fprintf(stderr, | |
45 "%s line %d: dimension \"%s\": too many digits after '.'\n", | |
46 input_filename, input_lineno, srcstr); | |
47 exit(1); | |
48 } | |
49 accum *= 10; | |
50 accum += *cp++ - '0'; | |
51 } | |
52 } else | |
53 ndec = 0; | |
54 if (*cp) | |
55 goto inv; | |
56 while (ndec < maxdec) { | |
57 accum *= 10; | |
58 ndec++; | |
59 } | |
60 switch (input_units_current) { | |
61 case 'B': | |
62 if (accum % 3) { | |
63 fprintf(stderr, | |
64 "%s line %d: basic units dimension \"%s\" not divisible by 3\n", | |
65 input_filename, input_lineno, srcstr); | |
66 exit(1); | |
67 } | |
68 accum /= 3; | |
69 accum *= 2; | |
70 break; | |
71 case 'I': | |
72 accum *= 254; | |
73 break; | |
74 } | |
75 return(accum * sign); | |
76 } | |
77 | |
78 parse_input_angle_90s(srcstr) | |
79 char *srcstr; | |
80 { | |
81 unsigned long num; | |
82 char *cp; | |
83 | |
84 num = strtoul(srcstr, &cp, 10); | |
85 switch (num) { | |
86 case 0: | |
87 case 90: | |
88 case 180: | |
89 case 270: | |
90 break; | |
91 default: | |
92 return(-1); | |
93 } | |
94 if (*cp == '.') { | |
95 cp++; | |
96 while (*cp) | |
97 if (*cp++ != '0') | |
98 return(-1); | |
99 } else if (*cp) | |
100 return(-1); | |
101 return(num); | |
102 } |