Disable use of libedit if it is not installed on the machine
This commit is contained in:
@ -18,10 +18,19 @@
|
|||||||
# Date Who Description
|
# Date Who Description
|
||||||
# 13/06/14 Mark Riddoch Initial implementation of MaxScale
|
# 13/06/14 Mark Riddoch Initial implementation of MaxScale
|
||||||
# client program
|
# client program
|
||||||
|
# 18/06/14 Mark Riddoch Addition of conditional for histedit
|
||||||
|
|
||||||
|
ifeq ($(wildcard /usr/include/histedit.h), )
|
||||||
|
HISTLIB=
|
||||||
|
HISTFLAG=
|
||||||
|
else
|
||||||
|
HISTLIB=-ledit
|
||||||
|
HISTFLAG=-DHISTORY
|
||||||
|
endif
|
||||||
|
|
||||||
CC=cc
|
CC=cc
|
||||||
|
|
||||||
CFLAGS=-c -Wall -g
|
CFLAGS=-c -Wall -g $(HISTFLAG)
|
||||||
|
|
||||||
SRCS= maxadmin.c
|
SRCS= maxadmin.c
|
||||||
|
|
||||||
@ -29,7 +38,7 @@ HDRS=
|
|||||||
|
|
||||||
OBJ=$(SRCS:.c=.o)
|
OBJ=$(SRCS:.c=.o)
|
||||||
|
|
||||||
LIBS=-ledit
|
LIBS=$(HISTLIB)
|
||||||
|
|
||||||
all: maxadmin
|
all: maxadmin
|
||||||
|
|
||||||
|
@ -46,7 +46,9 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifdef HISTORY
|
||||||
#include <histedit.h>
|
#include <histedit.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static int connectMaxScale(char *hostname, char *port);
|
static int connectMaxScale(char *hostname, char *port);
|
||||||
static int setipaddress(struct in_addr *a, char *p);
|
static int setipaddress(struct in_addr *a, char *p);
|
||||||
@ -54,6 +56,7 @@ static int authMaxScale(int so, char *user, char *password);
|
|||||||
static int sendCommand(int so, char *cmd);
|
static int sendCommand(int so, char *cmd);
|
||||||
static void DoSource(int so, char *cmd);
|
static void DoSource(int so, char *cmd);
|
||||||
|
|
||||||
|
#ifdef HISTORY
|
||||||
static char *
|
static char *
|
||||||
prompt(EditLine *el __attribute__((__unused__)))
|
prompt(EditLine *el __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
@ -61,17 +64,22 @@ prompt(EditLine *el __attribute__((__unused__)))
|
|||||||
|
|
||||||
return prompt;
|
return prompt;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
EditLine *el = NULL;
|
|
||||||
int i, num, rv, fatal = 0;
|
int i, num, rv, fatal = 0;
|
||||||
|
#ifdef HISTORY
|
||||||
char *buf;
|
char *buf;
|
||||||
|
EditLine *el = NULL;
|
||||||
Tokenizer *tok;
|
Tokenizer *tok;
|
||||||
History *hist;
|
History *hist;
|
||||||
HistEvent ev;
|
HistEvent ev;
|
||||||
const LineInfo *li;
|
const LineInfo *li;
|
||||||
|
#else
|
||||||
|
char buf[1024];
|
||||||
|
#endif
|
||||||
char *hostname = "localhost";
|
char *hostname = "localhost";
|
||||||
char *port = "6603";
|
char *port = "6603";
|
||||||
char *user = "admin";
|
char *user = "admin";
|
||||||
@ -196,7 +204,7 @@ char *cmd;
|
|||||||
}
|
}
|
||||||
|
|
||||||
(void) setlocale(LC_CTYPE, "");
|
(void) setlocale(LC_CTYPE, "");
|
||||||
|
#ifdef HISTORY
|
||||||
hist = history_init(); /* Init the builtin history */
|
hist = history_init(); /* Init the builtin history */
|
||||||
/* Remember 100 events */
|
/* Remember 100 events */
|
||||||
history(hist, &ev, H_SETSIZE, 100);
|
history(hist, &ev, H_SETSIZE, 100);
|
||||||
@ -227,12 +235,19 @@ char *cmd;
|
|||||||
|
|
||||||
while ((buf = el_gets(el, &num)) != NULL && num != 0)
|
while ((buf = el_gets(el, &num)) != NULL && num != 0)
|
||||||
{
|
{
|
||||||
|
#else
|
||||||
|
while (printf("MaxScale> ") && fgets(buf, 1024, stdin) != NULL)
|
||||||
|
{
|
||||||
|
num = strlen(buf);
|
||||||
|
#endif
|
||||||
/* Strip trailing \n\r */
|
/* Strip trailing \n\r */
|
||||||
for (i = num - 1; buf[i] == '\r' || buf[i] == '\n'; i--)
|
for (i = num - 1; buf[i] == '\r' || buf[i] == '\n'; i--)
|
||||||
buf[i] = 0;
|
buf[i] = 0;
|
||||||
|
|
||||||
|
#ifdef HISTORY
|
||||||
li = el_line(el);
|
li = el_line(el);
|
||||||
history(hist, &ev, H_ENTER, buf);
|
history(hist, &ev, H_ENTER, buf);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!strcasecmp(buf, "quit"))
|
if (!strcasecmp(buf, "quit"))
|
||||||
{
|
{
|
||||||
@ -240,10 +255,14 @@ char *cmd;
|
|||||||
}
|
}
|
||||||
else if (!strcasecmp(buf, "history"))
|
else if (!strcasecmp(buf, "history"))
|
||||||
{
|
{
|
||||||
|
#ifdef HISTORY
|
||||||
for (rv = history(hist, &ev, H_LAST); rv != -1;
|
for (rv = history(hist, &ev, H_LAST); rv != -1;
|
||||||
rv = history(hist, &ev, H_PREV))
|
rv = history(hist, &ev, H_PREV))
|
||||||
fprintf(stdout, "%4d %s\n",
|
fprintf(stdout, "%4d %s\n",
|
||||||
ev.num, ev.str);
|
ev.num, ev.str);
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "History not supported in this version.\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (!strncasecmp(buf, "source", 6))
|
else if (!strncasecmp(buf, "source", 6))
|
||||||
{
|
{
|
||||||
@ -255,9 +274,11 @@ char *cmd;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HISTORY
|
||||||
el_end(el);
|
el_end(el);
|
||||||
tok_end(tok);
|
tok_end(tok);
|
||||||
history_end(hist);
|
history_end(hist);
|
||||||
|
#endif
|
||||||
close(so);
|
close(so);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user