-.\" $OpenBSD: config.8,v 1.74 2021/11/02 22:26:46 kn Exp $
+.\" $OpenBSD: config.8,v 1.75 2021/11/20 03:13:37 jcs Exp $
.\" $NetBSD: config.8,v 1.10 1996/08/31 20:58:16 mycroft Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\"
.\" from: @(#)config.8 8.2 (Berkeley) 4/19/94
.\"
-.Dd $Mdocdate: November 2 2021 $
+.Dd $Mdocdate: November 20 2021 $
.Dt CONFIG 8
.Os
.Sh NAME
For kernel modification, the options are as follows:
.Bl -tag -width Ds
.It Fl c Ar cmdfile
-Read commands from the specified file instead of the standard input.
+Read commands and answers from the specified file instead of the standard
+input.
Save and quit automatically when the end of file is reached.
.It Fl e
Allows the modification of kernel device configuration (see
-/* $OpenBSD: main.c,v 1.62 2021/01/26 18:23:49 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.63 2021/11/20 03:13:37 jcs Exp $ */
/* $NetBSD: main.c,v 1.22 1997/02/02 21:12:33 thorpej Exp $ */
/*
char *sflag = NULL;
char *bflag = NULL;
char *startdir;
-char *cmdfile;
+char *cmdfile = NULL;
+FILE *cmdfp = NULL;
int
main(int argc, char *argv[])
#ifdef MAKE_BOOTSTRAP
errx(1, "UKC not available in this binary");
#else
+ if (cmdfile != NULL) {
+ cmdfp = fopen(cmdfile, "r");
+ if (cmdfp == NULL)
+ err(1, "open %s", cmdfile);
+ }
return (ukc(argv[0], outfile, uflag, fflag));
#endif
}
-/* $OpenBSD: misc.c,v 1.10 2019/05/14 13:44:25 tedu Exp $ */
+/* $OpenBSD: misc.c,v 1.11 2021/11/20 03:13:37 jcs Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
ask_cmd(cmd_t *cmd)
{
char lbuf[100];
+ extern FILE *cmdfp;
/* Get input */
- if (fgets(lbuf, sizeof lbuf, stdin) == NULL)
+ if (fgets(lbuf, sizeof lbuf, cmdfp ? cmdfp : stdin) == NULL) {
+ if (cmdfp) {
+ cmd->cmd[0] = '\0';
+ return -1;
+ }
errx(1, "eof");
+ }
+ if (cmdfp)
+ printf("%s", lbuf);
return parse_cmd(cmd, lbuf);
}
int
ask_yn(const char *str)
{
+ extern FILE *cmdfp;
int ch, first;
printf("%s [n] ", str);
fflush(stdout);
- first = ch = getchar();
- if (verbose) {
+ first = ch = getc(cmdfp ? cmdfp : stdin);
+ if (verbose || (cmdfp && ch != EOF)) {
printf("%c", ch);
fflush(stdout);
}
while (ch != '\n' && ch != EOF) {
- ch = getchar();
+ ch = getc(cmdfp ? cmdfp : stdin);
if (verbose) {
printf("%c\n", ch);
fflush(stdout);
- }
+ } else if (cmdfp)
+ putchar('\n');
}
if (ch == EOF || first == EOF)
errx(1, "eof");
-/* $OpenBSD: ukcutil.c,v 1.25 2019/09/06 21:30:31 cheloha Exp $ */
+/* $OpenBSD: ukcutil.c,v 1.26 2021/11/20 03:13:37 jcs Exp $ */
/*
* Copyright (c) 1999-2001 Mats O Jansson. All rights reserved.
pdev(val);
}
-int
-config_fromfile(const char *cmdfile) {
- FILE *fp;
- cmd_t cmd;
- int i;
-
- fp = fopen(cmdfile, "r");
- if (fp == NULL)
- err(1, "open %s", cmdfile);
-
- /* Set up command table pointer */
- cmd.table = cmd_table;
-
- /* Edit cycle */
- do {
- char lbuf[100];
-
- /* Get input */
- if (fgets(lbuf, sizeof lbuf, fp) == NULL)
- break;
- parse_cmd(&cmd, lbuf);
-
- if (cmd.cmd[0] == '\0')
- continue;
- for (i = 0; cmd_table[i].cmd != NULL; i++)
- if (strstr(cmd_table[i].cmd, cmd.cmd) ==
- cmd_table[i].cmd)
- break;
-
- /* Check for valid command */
- if (cmd_table[i].cmd == NULL) {
- printf("Invalid command '%s'\n", cmd.cmd);
- exit(1);
- }
- strlcpy(cmd.cmd, cmd_table[i].cmd, sizeof cmd.cmd);
-
- /* Call function */
- cmd_table[i].fcn(&cmd);
-
- } while (1);
- return 1;
-}
-
int
config(void)
{
/* Set up command table pointer */
cmd.table = cmd_table;
- if (cmdfile != NULL) {
- return config_fromfile(cmdfile);
- }
-
- printf("Enter 'help' for information\n");
+ if (cmdfile == NULL)
+ printf("Enter 'help' for information\n");
/* Edit cycle */
do {
+ char lbuf[100];
+
again:
- printf("ukc> ");
- fflush(stdout);
+ /* Get input */
+ if (cmdfile == NULL) {
+ printf("ukc> ");
+ fflush(stdout);
+ }
ask_cmd(&cmd);
- if (cmd.cmd[0] == '\0')
+ if (cmd.cmd[0] == '\0') {
+ if (cmdfile != NULL)
+ return 1;
goto again;
+ }
for (i = 0; cmd_table[i].cmd != NULL; i++)
if (strstr(cmd_table[i].cmd, cmd.cmd) ==
cmd_table[i].cmd)
/* Check for valid command */
if (cmd_table[i].cmd == NULL) {
+ if (cmdfile == NULL) {
+ printf("Invalid command '%s'\n", cmd.cmd);
+ exit(1);
+ }
printf("Invalid command '%s'. Try 'help'.\n", cmd.cmd);
continue;
} else