~emersion/mrsh

4c5c4caf4a1c38baeb75adf5420736ea01daed11 — Emerson Ferreira 3 years ago 5d139b3
Implement true, false builtins
5 files changed, 20 insertions(+), 0 deletions(-)

M builtin/builtin.c
A builtin/false.c
A builtin/true.c
M include/builtin.h
M meson.build
M builtin/builtin.c => builtin/builtin.c +2 -0
@@ 20,8 20,10 @@ static const struct builtin builtins[] = {
	{ "cd", builtin_cd, false },
	{ "eval", builtin_eval, true },
	{ "exit", builtin_exit, true },
	{ "false", builtin_false, false },
	{ "set", builtin_set, true },
	{ "times", builtin_times, true },
	{ "true", builtin_true, false },
};

static int builtin_compare(const void *_a, const void *_b) {

A builtin/false.c => builtin/false.c +7 -0
@@ 0,0 1,7 @@
#include <mrsh/shell.h>
#include <stdlib.h>
#include "builtin.h"

int builtin_false(struct mrsh_state *state, int argc, char *argv[]) {
	return EXIT_FAILURE;
}

A builtin/true.c => builtin/true.c +7 -0
@@ 0,0 1,7 @@
#include <mrsh/shell.h>
#include <stdlib.h>
#include "builtin.h"

int builtin_true(struct mrsh_state *state, int argc, char *argv[]) {
	return EXIT_SUCCESS;
}

M include/builtin.h => include/builtin.h +2 -0
@@ 16,6 16,8 @@ int builtin_eval(struct mrsh_state *state, int argc, char *argv[]);
int builtin_source(struct mrsh_state *state, int argc, char *argv[]);
int builtin_times(struct mrsh_state *state, int argc, char *argv[]);
int builtin_set(struct mrsh_state *state, int argc, char *argv[]);
int builtin_true(struct mrsh_state *state, int argc, char *argv[]);
int builtin_false(struct mrsh_state *state, int argc, char *argv[]);

const char *print_options(struct mrsh_state *state);


M meson.build => meson.build +2 -0
@@ 41,6 41,8 @@ lib_mrsh = library(
		'builtin/set.c',
		'builtin/source.c',
		'builtin/times.c',
		'builtin/true.c',
		'builtin/false.c',
		'hashtable.c',
		'parser/parser.c',
		'parser/program.c',