comparison pads2gpcb/cmdline.c @ 75:959df5ddf7a2

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