~arivigo/sline

ref: 0.4.0 sline/sline_test.c -rw-r--r-- 687 bytes
c2a72b29Ariadna Vigo sline 0.4.0 10 months 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
28
29
30
31
32
33
34
35
36
37
38
39
/* See LICENSE for copyright and license details. */

#include <stddef.h>
#include <stdio.h>

#include "sline.h"

#define BUF_SIZE 64
#define HISTORY_SIZE 64

int
main(void)
{
	char buf[BUF_SIZE];
	int cnt, sline_stat;

	if (sline_setup(HISTORY_SIZE) < 0) {
		fprintf(stderr, "sline: %s", sline_errmsg());
		return -1;
	}

	cnt = 0;
	while (feof(stdin) == 0) {
		/* Comment line below to use the default prompt. */
		sline_set_prompt("%d> ", cnt++);

		if ((sline_stat = sline(buf, BUF_SIZE)) < 0)
			goto exit;

		printf("Input was: %s\n", buf);
	}

exit:
	if (sline_stat < 0 && sline_err != SLINE_ERR_EOF)
		fprintf(stderr, "sline: %s.\n", sline_errmsg());
	sline_end();

	return 0;
}