|
@@ -21,7 +21,9 @@
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
|
|
+#include <unistd.h>
|
|
|
#include <sys/types.h>
|
|
#include <sys/types.h>
|
|
|
|
|
+#include <sys/wait.h>
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
#include <errno.h>
|
|
@@ -36,6 +38,7 @@
|
|
|
char *psave;
|
|
char *psave;
|
|
|
struct klist_node names_list = KLIST_NODE_INIT(&names_list);
|
|
struct klist_node names_list = KLIST_NODE_INIT(&names_list);
|
|
|
|
|
|
|
|
|
|
+extern char *line_buffer;
|
|
|
extern char *line_eof;
|
|
extern char *line_eof;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -44,6 +47,7 @@ __arch_templ static int new_var(char *p, struct arch *);
|
|
|
__arch_templ static int set_name(char *p, struct arch *);
|
|
__arch_templ static int set_name(char *p, struct arch *);
|
|
|
__arch_templ static int math_set_name(char *p, struct arch *);
|
|
__arch_templ static int math_set_name(char *p, struct arch *);
|
|
|
__arch_templ static int declare_object(char *p, struct arch *);
|
|
__arch_templ static int declare_object(char *p, struct arch *);
|
|
|
|
|
+__arch_templ static int interp_in_interp(char *p, struct arch *);
|
|
|
|
|
|
|
|
__arch_templ int cstyle_declare(char *p, struct arch *);
|
|
__arch_templ int cstyle_declare(char *p, struct arch *);
|
|
|
|
|
|
|
@@ -85,6 +89,13 @@ __arch_templ int arch_do_keyword(char *p, struct arch *arch_fn) {
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
|
|
+ case '`':
|
|
|
|
|
+ /* running code in another interpreter */
|
|
|
|
|
+
|
|
|
|
|
+ interp_in_interp(p, arch_fn);
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
case '+':
|
|
case '+':
|
|
|
case '-':
|
|
case '-':
|
|
|
if (!math_set_name(p, arch_fn))
|
|
if (!math_set_name(p, arch_fn))
|
|
@@ -462,4 +473,95 @@ skip: attr = getattrmask(p, declare_attrtab);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+static int iini_run(char *interp_path, char *code) {
|
|
|
|
|
+ int pid, stat;
|
|
|
|
|
+
|
|
|
|
|
+ /* we use the command-line '-c' */
|
|
|
|
|
+
|
|
|
|
|
+ printf("\nRun %s as interpreter-in-interpreter: \n", interp_path);
|
|
|
|
|
+
|
|
|
|
|
+ if (!(pid = fork())) {
|
|
|
|
|
+ /* child */
|
|
|
|
|
+
|
|
|
|
|
+ execl(interp_path, interp_path, "-c", code, NULL);
|
|
|
|
|
+
|
|
|
|
|
+ error("execl: %s\n", strerror(errno));
|
|
|
|
|
+
|
|
|
|
|
+ exit(generic_error("interp-in-interp failed", psave, lno));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ waitpid(pid, &stat, 0);
|
|
|
|
|
+
|
|
|
|
|
+ printf("\n");
|
|
|
|
|
+
|
|
|
|
|
+ if (WIFEXITED(stat))
|
|
|
|
|
+ printf("%s exited normally with status %d\n", interp_path, WEXITSTATUS(stat));
|
|
|
|
|
+
|
|
|
|
|
+ else if (WIFSIGNALED(stat))
|
|
|
|
|
+ error("%s terminated by signal %d%s\n", interp_path, WTERMSIG(stat),
|
|
|
|
|
+
|
|
|
|
|
+#ifdef WCOREDUMP
|
|
|
|
|
+ WCOREDUMP(stat) ? " (core dumped)" : ""
|
|
|
|
|
+#else
|
|
|
|
|
+ ""
|
|
|
|
|
+#endif
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+static int interp_in_interp(char *p, struct arch *arch_fn) {
|
|
|
|
|
+ int type, out;
|
|
|
|
|
+ char *interp, *code, *end;
|
|
|
|
|
+
|
|
|
|
|
+ /* first get the interpreter name */
|
|
|
|
|
+
|
|
|
|
|
+ p++;
|
|
|
|
|
+ _skip_spaces(p);
|
|
|
|
|
+
|
|
|
|
|
+ if (!getword(p, &type, &out))
|
|
|
|
|
+ exit(generic_error("interpreter name required", psave, lno));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ interp = strndup(p + 1, out);
|
|
|
|
|
+
|
|
|
|
|
+ p += out + 2;
|
|
|
|
|
+ _skip_spaces(p);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (!getword(p, &type, &out) || out != '{')
|
|
|
|
|
+ exit(generic_error("start mark '{' required", psave, lno));
|
|
|
|
|
+
|
|
|
|
|
+ /* get the end mark '}' */
|
|
|
|
|
+
|
|
|
|
|
+ end = read_code_block(p);
|
|
|
|
|
+
|
|
|
|
|
+ _skip_spaces(end);
|
|
|
|
|
+
|
|
|
|
|
+ /* ; -> next_line */
|
|
|
|
|
+ end++;
|
|
|
|
|
+
|
|
|
|
|
+ p++;
|
|
|
|
|
+
|
|
|
|
|
+ code = strndup(p, end - p - 1);
|
|
|
|
|
+
|
|
|
|
|
+ /* now let's do something interesting */
|
|
|
|
|
+
|
|
|
|
|
+ iini_run(interp, code);
|
|
|
|
|
+
|
|
|
|
|
+ free(code);
|
|
|
|
|
+ free(interp);
|
|
|
|
|
+
|
|
|
|
|
+ _skip_spaces(end);
|
|
|
|
|
+
|
|
|
|
|
+ /* this, parse_line will not bark. */
|
|
|
|
|
+ line_buffer = end;
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|