Commits

Steven! Ragnarök committed 4fffd33

Add DATA path variable resolution to sh142.

  • Participants
  • Parent commits 8397a18

Comments (0)

Files changed (5)

include/interpreter.h

 #ifndef SH142TYPES
 #include "sh142types.h"
 #endif
+#include "path_lookup.h"
+#include "fifo.h"
 
-#include "fifo.h"
 /* The interpreter for the sh142 command shell. Works on a tree of ASTNodes */
 
 void interpret(ast_node *root);
 int interpret_var_assign(ast_node *var_assign);
 char *interpret_arg(ast_node *arg);
 char *interpret_variable(ast_node *variable);
+char *interpret_data_variable(ast_node* data_variable);
 char *interpret_value(ast_node *value);
 
 /* Variables for the Exit Status FIFO. */
  * Start              ::= Command | VarAssign | NetworkCommand
  * Command            ::= ['!'] Value [ ArgList ] [ RedirectList ] [ Chain ] [BackgroundKey]
  * ArgList            ::= Arg [ Arglist ]
- * Arg                ::= VariableExpression | Value
+ * Arg                ::= VariableExpression | DataVariable | Value
  * VariableExpression ::= [Arg]'$'Value[Arg]
  * VarAssign          ::= Value'='Arg
  * RedirectList       ::= Redirect [RedirectList]
 ast_node *parse_arg_list(void);
 ast_node *parse_arg(void);
 ast_node *parse_var_assign(int eqlidx);
+ast_node *parse_data_variable();
 ast_node *parse_variable_expression(void);
 ast_node *parse_value(void);
 ast_node *parse_redirect_list(void);

include/sh142types.h

 /* Different types of tokens!!!! */
 typedef enum {
 	VARASSIGN, VALUE, VARIABLE, COMMAND, ARGLIST, REDIRECTLIST, STDIN_REDIRECT,
-	STDOUT_REDIRECT, STDERR_REDIRECT
+	STDOUT_REDIRECT, STDERR_REDIRECT, DATA_VARIABLE
 } node_type;
 
 /* Since we have mutually recursive structures, we need to use forward

src/interpreter.c

 char *interpret_arg(ast_node *arg) {
 	if (arg->type == VARIABLE) {
 		return interpret_variable(arg);
+	} else if (arg->type == DATA_VARIABLE) {
+		return interpret_data_variable(arg);
 	} else {
 		return interpret_value(arg);
 	}
 	return value;
 }
 
+char *interpret_data_variable(ast_node *data_variable) {
+	return resolve_data(data_variable->token);
+}
+
 char *interpret_value(ast_node *value) {
 	return value->token;
 }
 		return parse_variable_expression();
 	}
 
+	if (tokens->str[0] == '#' && tokens->str[1] == 'D' && tokens->str[2] == ':') {
+		return parse_data_variable();
+	}
+
 	return parse_value();
 }
 
 	return variable;
 }
 
+ast_node *parse_data_variable() {
+	ast_node *data_variable;
+	int i, varlen = strlen(tokens->str);
+	data_variable = malloc(sizeof(ast_node));
+	data_variable->type = DATA_VARIABLE;
+	for (i = 0; i < varlen; i++) {
+	 data_variable->token[i] = tokens->str[i + 3];
+	}
+	return data_variable;
+}
+
 ast_node *parse_var_assign(int eqlidx) {
 	ast_node *var_assign = malloc(sizeof(ast_node));
 	ast_nodelist *varname = malloc(sizeof(ast_nodelist));
 }
 
 ast_node *parse_network_command(int colonidx) {
-	ast_node *network_command;
 	strlist *ssh_token, *hostname_token;
 	/* Insert new tokens for the ssh cmd and hostname. */
 	ssh_token = malloc(sizeof(strlist));