Commits

Steven! Ragnarök committed 60333aa

Add background commands.

  • Participants
  • Parent commits 36d4d03

Comments (0)

Files changed (4)

  * StderrRedirect     ::= '2>' Arg
  * NetworkCommand     ::= NodeName':'Command
  * NodeName           ::= Value
+ * DataVariable       ::= #D:Value
  * // Not Yet Implemented //
- * DataVariable       ::= #D:Value
  * Chain              ::= AndedCommand | OrredCommand
  * AndedCommand       ::= '&&' Command
  * OrredCommand       ::= '||' Command
 ast_node *parse_redirect_list(void);
 ast_node *parse_redirect(void);
 ast_node *parse_network_command(int colonidx);
+ast_node *parse_background_key();
 
 
 /* Helper functions */
 int contains_colon(char *str);
 int is_special_token(void);
 int is_redirect_token(void);
+int is_background_key(void);
 void parser_error(void);
 
 

include/sh142types.h

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

src/interpreter.c

 	pid_t cmdpid;
 	char *argv[MAX_TOKEN_LENGTH];
 	FILE *stinf, *stoutf, *sterrf;
-	ast_node *redirect_list;
+	ast_node *redirect_list, *background_key = NULL;
 	ast_nodelist *arg, *redirect, *remaining_children;
 	remaining_children = command->children;
 	stinf = stoutf = sterrf = NULL;
 		redirect_list = NULL;
 	}
 
+	if (remaining_children != NULL && remaining_children->node->type == BACKGROUND_KEY) {
+		background_key = remaining_children->node;
+	}
+
 	/* Null-terminate the list as per execvp's documentation. */
 	argv[argc] = NULL;
 	cmdpid = fork();
 			exit(127);
 		}
 	} else {
-		waitpid(cmdpid, &cmdstats, 0);
+		if (background_key == NULL) {
+			waitpid(cmdpid, &cmdstats, 0);
+		}
 	}
-	return WEXITSTATUS(cmdstats);
+	if (background_key) {
+		return WEXITSTATUS(cmdstats);
+	} else {
+		return 0;
+	}
 }
 
 int interpret_negated_command(ast_node *command) {
 		}
 	}
 
+	/* Check for Background Key. */
+	if (tokens != NULL && is_background_key()) {
+		if (command->children == NULL) {
+			tail_child = command->children = malloc(sizeof(ast_nodelist));
+		} else {
+			tail_child->next = malloc(sizeof(ast_nodelist));
+			tail_child = tail_child->next;
+		}
+			tail_child->node = parse_background_key();
+			tail_child->next = NULL;
+	}
+
 	return command;
 }
 
 	return redirect;
 }
 
+ast_node *parse_background_key() {
+	strip_head();
+	ast_node *background_key = malloc(sizeof(ast_node));
+	background_key->type = BACKGROUND_KEY;
+	background_key->children = NULL;
+	return background_key;
+}
+
 
 ast_node *parse_arg() {
 	if (tokens == NULL || is_special_token()) {
 
 
 int is_special_token() {
-	/* Piggyback off redirect helper. */
-	if (is_redirect_token()) {
+	/* Piggyback off other helpers. */
+	if (is_redirect_token() || is_background_key()) {
 		return 1;
 	}
 
 	}
 }
 
+int is_background_key() {
+	if (strcmp(tokens->str, "&") == 0) {
+		return 1;
+	} else {
+		return 0;
+	}
+}
+
 void parser_error() {
 	fprintf(stderr, "Parser error\n");
 	return;