~arivigo/sline

7c628b70df7ac701ae85f4dfa14dfd6fdd04c732 — Ariadna Vigo 6 months ago 1a942fd
sline_test.c: showcasing sline_history_get()
1 files changed, 20 insertions(+), 2 deletions(-)

M sline_test.c
M sline_test.c => sline_test.c +20 -2
@@ 9,6 9,20 @@
#define HISTORY_SIZE 64
#define INIT_STR NULL /* Set to a literal string to test init strings */

static void
print_hist(void)
{
	int i;
	const char *entry;

	printf("History contains:\n");
	
	for (i = 0; (entry = sline_history_get(i)) != NULL; ++i) {
		if (strlen(entry) > 0) /* Avoid printing "current blank" */
			printf("%s\n", entry);
	}
}

int
main(void)
{


@@ 31,9 45,13 @@ main(void)
		if ((sline_stat = sline(buf, BUF_SIZE, INIT_STR)) < 0)
			goto exit;

		if (strncmp(buf, "exit", BUF_SIZE) == 0 
		    || strncmp(buf, "quit", BUF_SIZE) == 0)
		if (strncmp(buf, "hist", BUF_SIZE) == 0) {
			print_hist();
			continue;
		} else if (strncmp(buf, "exit", BUF_SIZE) == 0
		         || strncmp(buf, "quit", BUF_SIZE) == 0) {
			break;
		}

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