annotate pads2gpcb/cmdline.c @ 111:31d87f3d6a94

HEADER10_Shrouded.fp created
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 11 Jun 2020 05:35:43 +0000
parents 959df5ddf7a2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
75
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 #include <stdio.h>
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 #include <stdlib.h>
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 #include <ctype.h>
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4 #include <string.h>
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <strings.h>
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 long
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8 cmdline_dim_arg(srcstr)
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 char *srcstr;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 {
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11 long accum;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12 int sign = 1, mult;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13 char *cp;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14 int maxdec, ndec;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 cp = index(srcstr, 'm');
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17 if (!cp) {
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18 inv: fprintf(stderr, "invalid command line dimension input \"%s\"\n",
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 srcstr);
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 exit(1);
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 }
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22 if (!strcmp(cp, "mm")) {
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 mult = 1;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 maxdec = 6;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25 } else if (!strcmp(cp, "mil")) {
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26 mult = 254;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 maxdec = 2;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 } else
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 goto inv;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 cp = srcstr;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 if (*cp == '-') {
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 cp++;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 sign = -1;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35 }
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 if (!isdigit(*cp))
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 goto inv;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 for (accum = 0; isdigit(*cp); ) {
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 accum *= 10;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 accum += *cp++ - '0';
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41 }
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 if (*cp == '.') {
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43 cp++;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 for (ndec = 0; isdigit(*cp); ndec++) {
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
45 if (ndec >= maxdec) {
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
46 fprintf(stderr,
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
47 "command line dimension input \"%s\": too many digits after '.'\n",
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
48 srcstr);
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
49 exit(1);
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
50 }
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
51 accum *= 10;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
52 accum += *cp++ - '0';
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
53 }
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
54 } else
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
55 ndec = 0;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
56 if (*cp != 'm')
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
57 goto inv;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
58 while (ndec < maxdec) {
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
59 accum *= 10;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
60 ndec++;
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
61 }
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
62 return(accum * mult * sign);
959df5ddf7a2 pads2gpcb: command line dimension input implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
63 }