annotate libpwon/readconf.c @ 990:f34261bb3355

pln-ppb-test: implement PPB erase
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Dec 2023 00:20:14 +0000
parents ab54957dbe35
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
571
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <ctype.h>
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdlib.h>
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <string.h>
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <strings.h>
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 static char conf_file_pathname[] = "/opt/freecalypso/bootctrl.conf";
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #define MAX_BOOTCTRL_CONF_LINE 510
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 char bootctrl_pwon_cmd[MAX_BOOTCTRL_CONF_LINE+1];
953
ab54957dbe35 libpwon: implement -Petmoff mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 736
diff changeset
12 int bootctrl_etmoff_mode;
571
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 find_bootctrl_entry(soughtname)
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char *soughtname;
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 FILE *inf;
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char linebuf[MAX_BOOTCTRL_CONF_LINE+2];
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int lineno;
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char *cp, *np;
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
736
7d1df6d831e4 libpwon: added -Pdtr and -Prts support for DUART28C
Mychaela Falconia <falcon@freecalypso.org>
parents: 571
diff changeset
22 if (bootctrl_check_duart28c(soughtname))
7d1df6d831e4 libpwon: added -Pdtr and -Prts support for DUART28C
Mychaela Falconia <falcon@freecalypso.org>
parents: 571
diff changeset
23 return(0);
953
ab54957dbe35 libpwon: implement -Petmoff mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 736
diff changeset
24 if (!strcmp(soughtname, "etmoff")) {
ab54957dbe35 libpwon: implement -Petmoff mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 736
diff changeset
25 bootctrl_etmoff_mode = 1;
ab54957dbe35 libpwon: implement -Petmoff mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 736
diff changeset
26 return(0);
ab54957dbe35 libpwon: implement -Petmoff mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 736
diff changeset
27 }
571
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 inf = fopen(conf_file_pathname, "r");
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (!inf) {
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 perror(conf_file_pathname);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return(-1);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 cp = index(linebuf, '\n');
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (!cp) {
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 fprintf(stderr,
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 "%s line %d: too long or missing newline\n",
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 conf_file_pathname, lineno);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 fclose(inf);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return(-1);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 *cp = '\0';
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 for (cp = linebuf; isspace(*cp); cp++)
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 ;
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (*cp == '\0' || *cp == '#')
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 continue;
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 for (np = cp; *cp && !isspace(*cp); cp++)
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 ;
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (!*cp) {
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 invalid_syntax: fprintf(stderr, "%s line %d: invalid syntax\n",
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 conf_file_pathname, lineno);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 fclose(inf);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return(-1);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 *cp++ = '\0';
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 while (isspace(*cp))
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 cp++;
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (*cp == '\0' || *cp == '#')
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 goto invalid_syntax;
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (!strcmp(np, soughtname)) {
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 strcpy(bootctrl_pwon_cmd, cp);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 fclose(inf);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return(0);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 fclose(inf);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 fprintf(stderr, "error: no \"%s\" entry found in %s\n", soughtname,
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 conf_file_pathname);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return(-1);
41b3e010808d libpwon started, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }