~emersion/mrsh

ca1b90e32d8f2e4a0afbaefa666cb973c47d1155 — emersion 3 years ago 9d7255e
shell: add docs to private header
2 files changed, 31 insertions(+), 10 deletions(-)

M include/shell.h
M shell/process.c
M include/shell.h => include/shell.h +29 -10
@@ 6,13 6,37 @@ struct context {
	int stdout_fileno;
};

/**
 * This struct is used to track child processes.
 */
struct process {
	pid_t pid;
	bool finished;
	int stat;
};

struct task;
#define TASK_STATUS_WAIT -1
#define TASK_STATUS_ERROR -2

struct task_interface;

/**
 * Tasks abstract away operations that need to be done by the shell. When the
 * shell executes a command, it walks the AST and translates it to a tree of
 * tasks to execute.
 *
 * Tasks are required for operations that are executed in parallel without
 * subshells. POSIX allows for instance nested pipelines:
 *
 *   echo abc | { cat | cat; } | cat
 *
 * In this case the shell should not block before executing the last `cat`
 * command.
 */
struct task {
	const struct task_interface *impl;
	int status; // last task status
};

struct task_interface {
	/**


@@ 31,17 55,12 @@ struct task_interface {
	void (*destroy)(struct task *task);
};

#define TASK_STATUS_WAIT -1
#define TASK_STATUS_ERROR -2

struct task {
	const struct task_interface *impl;
	int status; // last task status
};

enum tilde_expansion {
	// Don't perform tilde expansion at all
	TILDE_EXPANSION_NONE,
	// Only expand at the begining of words
	TILDE_EXPANSION_NAME,
	// Expand at the begining of words and after semicolons
	TILDE_EXPANSION_ASSIGNMENT,
};



@@ 82,7 101,7 @@ struct task *task_token_create(struct mrsh_token **token_ptr,
	enum tilde_expansion tilde_expansion);

/**
 * Performs tilde expansion.
 * Performs tilde expansion. It leaves the string as-is in case of error.
 */
void expand_tilde(struct mrsh_state *state, char **str_ptr);
/**

M shell/process.c => shell/process.c +2 -0
@@ 3,6 3,8 @@
#include <sys/wait.h>
#include "shell.h"

// TODO: don't use a global
// TODO: use a linked list instead
static struct mrsh_array running_processes = {0};

void process_init(struct process *proc, pid_t pid) {