@@ 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);
}