comparison loadtools/ltscript.c @ 29:dacf45e3d20f

loadtool: scripting functionality implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 04 May 2013 07:15:51 +0000
parents
children 358785799844
comparison
equal deleted inserted replaced
28:768a3d012931 29:dacf45e3d20f
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 retval = loadtool_dispatch_cmd(linebuf, 1);
42 if (retval)
43 break;
44 }
45 fclose(f);
46 return(retval);
47 }
48
49 cmd_exec(argc, argv)
50 char **argv;
51 {
52 return loadtool_exec_script(argv[1]);
53 }