comparison serial/baud_parse.c @ 40:8f505d413815

serial: full baud/spenh argument parsing implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 20 Mar 2021 20:23:24 +0000
parents
children
comparison
equal deleted inserted replaced
39:61a8ac93764f 40:8f505d413815
1 /*
2 * This module handles the parsing of the baud rate and speed enhancement
3 * command line argument.
4 */
5
6 #include <ctype.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 unsigned baud_base, baud_spenh, spenh_host_max;
11
12 void
13 parse_baud_spenh_arg(arg)
14 char *arg;
15 {
16 char *cp;
17
18 if (!isdigit(*arg)) {
19 inv: fprintf(stderr,
20 "error: invalid baud/spenh selection argument \"%s\"\n",
21 arg);
22 exit(1);
23 }
24 baud_base = strtoul(arg, &cp, 10);
25 if (!*cp)
26 return;
27 if (*cp++ != ',')
28 goto inv;
29 if (!isdigit(*cp))
30 goto inv;
31 baud_spenh = strtoul(cp, &cp, 10);
32 if (!*cp) {
33 spenh_host_max = 1;
34 return;
35 }
36 if (*cp++ != ',')
37 goto inv;
38 if (!isdigit(*cp) || cp[1])
39 goto inv;
40 spenh_host_max = *cp - '0';
41 switch (spenh_host_max) {
42 case 1:
43 case 2:
44 case 4:
45 case 8:
46 break;
47 default:
48 fprintf(stderr,
49 "error: speed enhancement multiplier can only be 1, 2, 4 or 8\n");
50 exit(1);
51 }
52 }