~emersion/mrsh

ref: 05502d67738447e78c1367c4322668a525d1da12 mrsh/basic.c -rw-r--r-- 609 bytes
05502d67emersion Add link to POSIX spec in README 3 years ago
                                                                                
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, state->input);
	if (l == -1 && errno) {
		fprintf(stderr, "%s\n", strerror(errno));
		return 0;
	}
	*line = _line;
	return l;
}