FreeCalypso > hg > freecalypso-tools
comparison libpwon/readconf.c @ 571:41b3e010808d
libpwon started, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 02 Feb 2020 17:40:25 +0000 |
parents | |
children | 7d1df6d831e4 |
comparison
equal
deleted
inserted
replaced
570:fb3deb215cb0 | 571:41b3e010808d |
---|---|
1 #include <ctype.h> | |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 #include <string.h> | |
5 #include <strings.h> | |
6 | |
7 static char conf_file_pathname[] = "/opt/freecalypso/bootctrl.conf"; | |
8 | |
9 #define MAX_BOOTCTRL_CONF_LINE 510 | |
10 | |
11 char bootctrl_pwon_cmd[MAX_BOOTCTRL_CONF_LINE+1]; | |
12 | |
13 find_bootctrl_entry(soughtname) | |
14 char *soughtname; | |
15 { | |
16 FILE *inf; | |
17 char linebuf[MAX_BOOTCTRL_CONF_LINE+2]; | |
18 int lineno; | |
19 char *cp, *np; | |
20 | |
21 inf = fopen(conf_file_pathname, "r"); | |
22 if (!inf) { | |
23 perror(conf_file_pathname); | |
24 return(-1); | |
25 } | |
26 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { | |
27 cp = index(linebuf, '\n'); | |
28 if (!cp) { | |
29 fprintf(stderr, | |
30 "%s line %d: too long or missing newline\n", | |
31 conf_file_pathname, lineno); | |
32 fclose(inf); | |
33 return(-1); | |
34 } | |
35 *cp = '\0'; | |
36 for (cp = linebuf; isspace(*cp); cp++) | |
37 ; | |
38 if (*cp == '\0' || *cp == '#') | |
39 continue; | |
40 for (np = cp; *cp && !isspace(*cp); cp++) | |
41 ; | |
42 if (!*cp) { | |
43 invalid_syntax: fprintf(stderr, "%s line %d: invalid syntax\n", | |
44 conf_file_pathname, lineno); | |
45 fclose(inf); | |
46 return(-1); | |
47 } | |
48 *cp++ = '\0'; | |
49 while (isspace(*cp)) | |
50 cp++; | |
51 if (*cp == '\0' || *cp == '#') | |
52 goto invalid_syntax; | |
53 if (!strcmp(np, soughtname)) { | |
54 strcpy(bootctrl_pwon_cmd, cp); | |
55 fclose(inf); | |
56 return(0); | |
57 } | |
58 } | |
59 fclose(inf); | |
60 fprintf(stderr, "error: no \"%s\" entry found in %s\n", soughtname, | |
61 conf_file_pathname); | |
62 return(-1); | |
63 } |