comparison loadtools/ltscript.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 6616f4e35579
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * This module contains the code that implements the loadtool scripting
3 * functionality: init-script setting and the exec command.
4 */
5
6 #include <sys/param.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <strings.h>
10 #include <stdlib.h>
11
12 extern char default_helpers_dir[];
13
14 loadtool_exec_script(script_name)
15 char *script_name;
16 {
17 char pathbuf[MAXPATHLEN], *openfname;
18 FILE *f;
19 char linebuf[512], *cp;
20 int lineno, retval = 0;
21
22 if (index(script_name, '/'))
23 openfname = script_name;
24 else {
25 sprintf(pathbuf, "%s/%s", default_helpers_dir, script_name);
26 openfname = pathbuf;
27 }
28 f = fopen(openfname, "r");
29 if (!f) {
30 perror(openfname);
31 return(-1);
32 }
33 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) {
34 cp = index(linebuf, '\n');
35 if (!cp) {
36 fprintf(stderr, "%s line %d: missing newline\n",
37 openfname, lineno);
38 fclose(f);
39 return(-1);
40 }
41 *cp = '\0';
42 retval = loadtool_dispatch_cmd(linebuf, 1);
43 if (retval)
44 break;
45 }
46 fclose(f);
47 return(retval);
48 }
49
50 cmd_exec(argc, argv)
51 char **argv;
52 {
53 return loadtool_exec_script(argv[1]);
54 }