~emersion/mrsh

4474b68ebe468d22bd39b05f7131faeccc61da00 — Simon Ser 3 months ago 2f5dcdd
shell: hide definitions of mrsh_{variable,function}
6 files changed, 19 insertions(+), 17 deletions(-)

M builtin/builtin.c
M builtin/unset.c
M include/mrsh/shell.h
M include/shell/shell.h
M shell/shell.c
M shell/task/task.c
M builtin/builtin.c => builtin/builtin.c +1 -0
@@ 5,6 5,7 @@
#include <string.h>
#include <ctype.h>
#include "builtin.h"
#include "shell/shell.h"

struct builtin {
	const char *name;

M builtin/unset.c => builtin/unset.c +2 -1
@@ 5,6 5,7 @@
#include <stdlib.h>
#include <string.h>
#include "builtin.h"
#include "shell/shell.h"

static const char unset_usage[] = "usage: unset [-fv] name...\n";



@@ 45,7 46,7 @@ int builtin_unset(struct mrsh_state *state, int argc, char *argv[]) {
		} else {
			struct mrsh_function *oldfn =
				mrsh_hashtable_del(&state->functions, argv[i]);
			mrsh_function_destroy(oldfn);
			function_destroy(oldfn);
		}
	}
	return 0;

M include/mrsh/shell.h => include/mrsh/shell.h +2 -13
@@ 66,17 66,6 @@ enum mrsh_variable_attrib {
	MRSH_VAR_ATTRIB_READONLY = 1 << 1,
};

struct mrsh_variable {
	char *value;
	uint32_t attribs;
};

struct mrsh_function {
	struct mrsh_command *body;
};

struct mrsh_job;

enum mrsh_branch_control {
	MRSH_BRANCH_BREAK,
	MRSH_BRANCH_CONTINUE,


@@ 93,6 82,8 @@ struct mrsh_call_frame {
	int nloops;
};

struct mrsh_job;

struct mrsh_state {
	int exit;
	int fd;


@@ 115,8 106,6 @@ struct mrsh_state {
	bool child; // true if we're not the main shell process
};

void mrsh_function_destroy(struct mrsh_function *fn);

struct mrsh_parser;

void mrsh_state_init(struct mrsh_state *state);

M include/shell/shell.h => include/shell/shell.h +11 -0
@@ 5,6 5,15 @@
#include "job.h"
#include "process.h"

struct mrsh_variable {
	char *value;
	uint32_t attribs; // enum mrsh_variable_attrib
};

struct mrsh_function {
	struct mrsh_command *body;
};

/**
 * A context holds state information and per-job information. A context is
 * guaranteed to be shared between all members of a job.


@@ 18,4 27,6 @@ struct context {
	bool background;
};

void function_destroy(struct mrsh_function *fn);

#endif

M shell/shell.c => shell/shell.c +2 -2
@@ 10,7 10,7 @@
#include "shell/shell.h"
#include "shell/process.h"

void mrsh_function_destroy(struct mrsh_function *fn) {
void function_destroy(struct mrsh_function *fn) {
	if (!fn) {
		return;
	}


@@ 55,7 55,7 @@ static void state_var_finish_iterator(const char *key, void *value,
}

static void state_fn_finish_iterator(const char *key, void *value, void *_) {
	mrsh_function_destroy((struct mrsh_function *)value);
	function_destroy((struct mrsh_function *)value);
}

static void call_frame_destroy(struct mrsh_call_frame *frame) {

M shell/task/task.c => shell/task/task.c +1 -1
@@ 247,7 247,7 @@ static int run_function_definition(struct context *ctx,
	fn->body = mrsh_command_copy(fnd->body);
	struct mrsh_function *old_fn =
		mrsh_hashtable_set(&ctx->state->functions, fnd->name, fn);
	mrsh_function_destroy(old_fn);
	function_destroy(old_fn);
	return 0;
}