FreeCalypso > hg > fc-sim-tools
comparison libcommon/script.c @ 14:b7ee2e85686b
command dispatch and scripting factored out into libcommon
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 07:34:35 +0000 |
parents | simtool/script.c@ddd767f6e15b |
children |
comparison
equal
deleted
inserted
replaced
13:7c26eac6ab00 | 14:b7ee2e85686b |
---|---|
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 } |