FreeCalypso > hg > freecalypso-hwlab
annotate simtool/script.c @ 142:74c5dc7408e9
uicc/Makefile: add install
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 04 Feb 2021 05:06:28 +0000 |
parents | b391204d3cd5 |
children |
rev | line source |
---|---|
123
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the exec command, which is our scripting facility. |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdlib.h> |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <string.h> |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <strings.h> |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 cmd_exec(argc, argv) |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 char **argv; |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 { |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 FILE *f; |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 char linebuf[512], *cp; |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int lineno, retval = 0; |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 f = fopen(argv[1], "r"); |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 if (!f) { |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 perror(argv[1]); |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 return(-1); |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 } |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) { |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 cp = index(linebuf, '\n'); |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (!cp) { |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 fprintf(stderr, "%s line %d: missing newline\n", |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 argv[1], lineno); |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 fclose(f); |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(-1); |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 *cp = '\0'; |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 retval = simtool_dispatch_cmd(linebuf, 1); |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (retval) |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 break; |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 fclose(f); |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 return(retval); |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |