FreeCalypso > hg > freecalypso-sw
annotate loadtools/ltscript.c @ 814:1c0c8f93bd60
aci: psa_util.c done
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Sun, 05 Apr 2015 08:09:28 +0000 |
parents | 358785799844 |
children |
rev | line source |
---|---|
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module contains the code that implements the loadtool scripting |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * functionality: init-script setting and the exec command. |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 */ |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <sys/param.h> |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdio.h> |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <string.h> |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <strings.h> |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <stdlib.h> |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 extern char default_helpers_dir[]; |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 loadtool_exec_script(script_name) |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 char *script_name; |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 { |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 char pathbuf[MAXPATHLEN], *openfname; |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 FILE *f; |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 char linebuf[512], *cp; |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 int lineno, retval = 0; |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 if (index(script_name, '/')) |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 openfname = script_name; |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 else { |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 sprintf(pathbuf, "%s/%s", default_helpers_dir, script_name); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 openfname = pathbuf; |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 } |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 f = fopen(openfname, "r"); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 if (!f) { |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 perror(openfname); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 return(-1); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 } |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) { |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 cp = index(linebuf, '\n'); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 if (!cp) { |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 fprintf(stderr, "%s line %d: missing newline\n", |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 openfname, lineno); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 fclose(f); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 return(-1); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 } |
31
358785799844
loadtool scripting: cosmetic buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
41 *cp = '\0'; |
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 retval = loadtool_dispatch_cmd(linebuf, 1); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 if (retval) |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 break; |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 } |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 fclose(f); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 return(retval); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 } |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 cmd_exec(argc, argv) |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 char **argv; |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 { |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 return loadtool_exec_script(argv[1]); |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 } |