FreeCalypso > hg > ueda-linux
annotate pads2gpcb/gpcbout.c @ 120:6ea9f0b2dbd2
m4-fp/btb.inc: Harwin M402M connector family added
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 05 Jul 2020 05:24:33 +0000 |
parents | 3bdb1b5ff3d0 |
children |
rev | line source |
---|---|
45
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 #include <stdio.h> |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 #include <stdlib.h> |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 #include <string.h> |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 #include <strings.h> |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 static char * |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 generate_decimal(dim, nfract, cp) |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 long dim; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 int nfract; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 char *cp; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 { |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 int i; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 *cp = '\0'; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 for (i = 0; i < nfract; i++) { |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 *--cp = '0' + dim % 10; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 dim /= 10; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 } |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 *--cp = '.'; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 do { |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 *--cp = '0' + dim % 10; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 dim /= 10; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 } while (dim); |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 return cp; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 } |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 static void |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 trim_decimal(str) |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 char *str; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 { |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 char *point, *cp; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 point = index(str, '.'); |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 if (!point) { |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 fprintf(stderr, |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 "BUG: gpcbout.c:trim_decimal(): no '.' found\n"); |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 exit(1); |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 } |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 cp = index(str, '\0'); |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 while (cp > point + 1) { |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 if (cp[-1] != '0') |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 break; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 cp--; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 } |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 if (cp == point + 1) |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 cp--; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 *cp = '\0'; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 } |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 char * |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 output_gpcb_dimension(dim, buf) |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 long dim; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 char *buf; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 { |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 int negative = 0; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 int nfract; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 char *unit_suffix, *outptr; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 if (dim == 0) |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 return "0"; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 if (dim < 0) { |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 negative = 1; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 dim = -dim; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 } |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 if (dim % 254) { |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 nfract = 6; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 unit_suffix = "mm"; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 } else { |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 dim /= 254; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 nfract = 2; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 unit_suffix = "mil"; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 } |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 outptr = generate_decimal(dim, nfract, buf + 12); |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 trim_decimal(outptr); |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 strcat(outptr, unit_suffix); |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 if (negative) |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 *--outptr = '-'; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 return outptr; |
3bdb1b5ff3d0
pads2gpcb: gpcb dimension output implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 } |