ref: 44efa8a8a7969bbb4341b9d87ac8ab7e7ef92d4f mrsh/frontend/basic.c -rw-r--r-- 602 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* Basic, strictly POSIX interactive line interface */
#define _POSIX_C_SOURCE 200809L
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mrsh/shell.h>
#include <mrsh/parser.h>
#include "frontend.h"

void interactive_init(struct mrsh_state *state) {
	// no-op
}

size_t interactive_next(struct mrsh_state *state,
		char **line, const char *prompt) {
	fprintf(stderr, "%s", prompt);
	size_t n = 0;
	char *_line;
	ssize_t l = getline(&_line, &n, stdin);
	if (l == -1 && errno) {
		fprintf(stderr, "%s\n", strerror(errno));
		return 0;
	}
	*line = _line;
	return l;
}