4 files changed, 38 insertions(+), 57 deletions(-)
M Makefile
D history.c
D history.h
M sline.c
M Makefile => Makefile +2 -4
@@ 4,7 4,7 @@
include config.mk
-SRC = history.c sline.c strlcpy.c
+SRC = sline.c strlcpy.c
OBJ = ${SRC:.c=.o}
MAN = man/sline.3 man/sline_end.3 man/sline_errmsg.3 man/sline_history_get.3 \
man/sline_setup.3 man/sline_set_prompt.3 man/sline_version.3
@@ 19,9 19,7 @@ options:
@echo "CC = ${CC}"
@echo
-history.o: strlcpy.h
-
-sline.o: history.h sline.h strlcpy.h
+sline.o: sline.h strlcpy.h
strlcpy.o: strlcpy.h
D history.c => history.c +0 -40
@@ 1,40 0,0 @@
-/* See LICENSE for copyright and license details. */
-
-#include <string.h>
-
-#include "history.h"
-#include "strlcpy.h"
-
-#define HISTORY_SIZE 50
-
-char *history[HISTORY_SIZE];
-int hist_top, hist_pos;
-size_t hist_entry_size;
-
-void
-history_next(void)
-{
- if (strlen(history[hist_top]) == 0)
- return;
-
- ++hist_top;
- if (hist_top >= HISTORY_SIZE)
- history_rotate();
-}
-
-void
-history_rotate(void)
-{
- int i;
-
- for (i = 1; i < HISTORY_SIZE; ++i)
- strlcpy(history[i - 1], history[i], hist_entry_size);
-
- --hist_top;
-}
-
-void
-history_set(int pos, const char *input)
-{
- strlcpy(history[pos], input, hist_entry_size);
-}
D history.h => history.h +0 -11
@@ 1,11 0,0 @@
-/* See LICENSE for copyright and license details. */
-
-#define HISTORY_SIZE 50
-
-void history_next(void);
-void history_rotate(void);
-void history_set(int pos, const char *input);
-
-extern char *history[HISTORY_SIZE];
-extern int hist_top, hist_pos;
-extern size_t hist_entry_size;
M sline.c => sline.c +36 -2
@@ 7,11 7,11 @@
#include <termios.h>
#include <unistd.h>
-#include "history.h"
#include "sline.h"
#include "strlcpy.h"
#define CURSOR_BUF_SIZE 16 /* Used for cursor movement directives */
+#define HISTORY_SIZE 50
#define SLINE_PROMPT_DEFAULT "> "
#define SLINE_PROMPT_SIZE 32
#define UTF8_BYTES 4
@@ 53,8 53,14 @@ static void chr_delete(char *buf, size_t size, int bsmode);
static void chr_ins(char *buf, size_t size, const char *utf8);
static void chr_return(const char *buf);
+static void history_next(void);
+static void history_rotate(void);
+static void history_set(int pos, const char *input);
+
static char sline_prompt[SLINE_PROMPT_SIZE];
-static size_t pos, buf_i;
+static char *history[HISTORY_SIZE];
+static size_t hist_entry_size, pos, buf_i;
+static int hist_top, hist_pos;
static int sline_history = 1; /* History feature on by default */
static struct termios old, term;
@@ 409,6 415,34 @@ chr_return(const char *buf)
}
}
+static void
+history_next(void)
+{
+ if (strlen(history[hist_top]) == 0)
+ return;
+
+ ++hist_top;
+ if (hist_top >= HISTORY_SIZE)
+ history_rotate();
+}
+
+static void
+history_rotate(void)
+{
+ int i;
+
+ for (i = 1; i < HISTORY_SIZE; ++i)
+ strlcpy(history[i - 1], history[i], hist_entry_size);
+
+ --hist_top;
+}
+
+static void
+history_set(int pos, const char *input)
+{
+ strlcpy(history[pos], input, hist_entry_size);
+}
+
/* Public sline API subroutines follow */
int