FreeCalypso > hg > freecalypso-tools
view libpwon/readconf.c @ 698:9ecbf1bf2e1b
fc-iram: added '+' to getopt magic string like in fc-xram
Both fc-iram and fc-xram now support secondary program invokation.
If the user needs to pass some options to the secondary program,
we don't want fc-iram or fc-xram to claim these options as its own,
thus we need to stop getopt() from reordering arguments. This fix
was already implemented in fc-xram a long time ago, but the issue
was overlooked when secondary program invokation ability was added
to fc-iram.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 31 Mar 2020 03:23:26 +0000 |
parents | 41b3e010808d |
children | 7d1df6d831e4 |
line wrap: on
line source
#include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> static char conf_file_pathname[] = "/opt/freecalypso/bootctrl.conf"; #define MAX_BOOTCTRL_CONF_LINE 510 char bootctrl_pwon_cmd[MAX_BOOTCTRL_CONF_LINE+1]; find_bootctrl_entry(soughtname) char *soughtname; { FILE *inf; char linebuf[MAX_BOOTCTRL_CONF_LINE+2]; int lineno; char *cp, *np; inf = fopen(conf_file_pathname, "r"); if (!inf) { perror(conf_file_pathname); return(-1); } for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { cp = index(linebuf, '\n'); if (!cp) { fprintf(stderr, "%s line %d: too long or missing newline\n", conf_file_pathname, lineno); fclose(inf); return(-1); } *cp = '\0'; for (cp = linebuf; isspace(*cp); cp++) ; if (*cp == '\0' || *cp == '#') continue; for (np = cp; *cp && !isspace(*cp); cp++) ; if (!*cp) { invalid_syntax: fprintf(stderr, "%s line %d: invalid syntax\n", conf_file_pathname, lineno); fclose(inf); return(-1); } *cp++ = '\0'; while (isspace(*cp)) cp++; if (*cp == '\0' || *cp == '#') goto invalid_syntax; if (!strcmp(np, soughtname)) { strcpy(bootctrl_pwon_cmd, cp); fclose(inf); return(0); } } fclose(inf); fprintf(stderr, "error: no \"%s\" entry found in %s\n", soughtname, conf_file_pathname); return(-1); }