FreeCalypso > hg > fc-pcsc-tools
comparison simtool/script.c @ 1:2071b28cd0c7
simtool: first refactored version
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 11 Feb 2021 23:04:28 +0000 |
parents | |
children | 9c10afbb745a |
comparison
equal
deleted
inserted
replaced
0:f7145c77b7fb | 1:2071b28cd0c7 |
---|---|
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 cmd_exec(argc, argv) | |
11 char **argv; | |
12 { | |
13 FILE *f; | |
14 char linebuf[512], *cp; | |
15 int lineno, retval = 0; | |
16 | |
17 f = fopen(argv[1], "r"); | |
18 if (!f) { | |
19 perror(argv[1]); | |
20 return(-1); | |
21 } | |
22 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) { | |
23 cp = index(linebuf, '\n'); | |
24 if (!cp) { | |
25 fprintf(stderr, "%s line %d: missing newline\n", | |
26 argv[1], lineno); | |
27 fclose(f); | |
28 return(-1); | |
29 } | |
30 *cp = '\0'; | |
31 retval = simtool_dispatch_cmd(linebuf, 1); | |
32 if (retval) | |
33 break; | |
34 } | |
35 fclose(f); | |
36 return(retval); | |
37 } |