comparison simtool/script.c @ 10:ddd767f6e15b

fc-simtool ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 07:11:25 +0000
parents
children
comparison
equal deleted inserted replaced
9:c9ef9e91dd8e 10:ddd767f6e15b
1 /*
2 * This module implements the exec command, which is our scripting facility.
3 */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <strings.h>
9
10 extern FILE *open_script_input_file();
11
12 cmd_exec(argc, argv)
13 char **argv;
14 {
15 FILE *f;
16 char linebuf[512], *cp;
17 int lineno, retval = 0;
18
19 f = open_script_input_file(argv[1]);
20 if (!f) {
21 perror(argv[1]);
22 return(-1);
23 }
24 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) {
25 cp = index(linebuf, '\n');
26 if (!cp) {
27 fprintf(stderr, "%s line %d: missing newline\n",
28 argv[1], lineno);
29 fclose(f);
30 return(-1);
31 }
32 *cp = '\0';
33 retval = simtool_dispatch_cmd(linebuf, 1);
34 if (retval)
35 break;
36 }
37 fclose(f);
38 return(retval);
39 }