mirror of
https://github.com/GNOME/libxml2.git
synced 2025-01-18 14:33:59 +08:00
shell: Only use readline on terminals
Should fix xmllint shell tests.
This commit is contained in:
parent
d04e152d9c
commit
6cc2387e1a
52
shell.c
52
shell.c
@ -12,6 +12,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBREADLINE
|
||||
#include <readline/readline.h>
|
||||
#ifdef HAVE_LIBHISTORY
|
||||
@ -31,6 +37,10 @@
|
||||
|
||||
#include "private/shell.h"
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* TODO: Improvement/cleanups for the XML shell
|
||||
* - allow to shell out an editor on a subpart
|
||||
@ -1047,37 +1057,39 @@ xmllintShellPwd(xmllintShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer,
|
||||
*/
|
||||
static char *
|
||||
xmllintShellReadline(char *prompt) {
|
||||
#ifdef HAVE_LIBREADLINE
|
||||
char *line_read;
|
||||
|
||||
/* Get a line from the user. */
|
||||
line_read = readline (prompt);
|
||||
|
||||
#ifdef HAVE_LIBHISTORY
|
||||
/* If the line has any text in it, save it on the history. */
|
||||
if (line_read && *line_read)
|
||||
add_history (line_read);
|
||||
#endif
|
||||
|
||||
return (line_read);
|
||||
#else
|
||||
char line_read[501];
|
||||
char buf[501];
|
||||
char *ret;
|
||||
int len;
|
||||
|
||||
#ifdef HAVE_LIBREADLINE
|
||||
if (isatty(STDIN_FILENO)) {
|
||||
char *line_read;
|
||||
|
||||
/* Get a line from the user. */
|
||||
line_read = readline (prompt);
|
||||
|
||||
#ifdef HAVE_LIBHISTORY
|
||||
/* If the line has any text in it, save it on the history. */
|
||||
if (line_read && *line_read)
|
||||
add_history (line_read);
|
||||
#endif
|
||||
|
||||
return (line_read);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (prompt != NULL)
|
||||
fprintf(stdout, "%s", prompt);
|
||||
fflush(stdout);
|
||||
if (!fgets(line_read, 500, stdin))
|
||||
if (!fgets(buf, 500, stdin))
|
||||
return(NULL);
|
||||
line_read[500] = 0;
|
||||
len = strlen(line_read);
|
||||
buf[500] = 0;
|
||||
len = strlen(buf);
|
||||
ret = (char *) malloc(len + 1);
|
||||
if (ret != NULL) {
|
||||
memcpy (ret, line_read, len + 1);
|
||||
memcpy (ret, buf, len + 1);
|
||||
}
|
||||
return(ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
50
xmlcatalog.c
50
xmlcatalog.c
@ -16,6 +16,8 @@
|
||||
#ifdef _WIN32
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBREADLINE
|
||||
@ -30,6 +32,10 @@
|
||||
#include <libxml/catalog.h>
|
||||
#include <libxml/parser.h>
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
#if defined(LIBXML_CATALOG_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
|
||||
static int shell = 0;
|
||||
static int sgml = 0;
|
||||
@ -63,37 +69,39 @@ static char *filename = NULL;
|
||||
*/
|
||||
static char *
|
||||
xmlShellReadline(const char *prompt) {
|
||||
#ifdef HAVE_LIBREADLINE
|
||||
char *line_read;
|
||||
|
||||
/* Get a line from the user. */
|
||||
line_read = readline (prompt);
|
||||
|
||||
#ifdef HAVE_LIBHISTORY
|
||||
/* If the line has any text in it, save it on the history. */
|
||||
if (line_read && *line_read)
|
||||
add_history (line_read);
|
||||
#endif
|
||||
|
||||
return (line_read);
|
||||
#else
|
||||
char line_read[501];
|
||||
char buf[501];
|
||||
char *ret;
|
||||
int len;
|
||||
|
||||
#ifdef HAVE_LIBREADLINE
|
||||
if (isatty(STDIN_FILENO)) {
|
||||
char *line_read;
|
||||
|
||||
/* Get a line from the user. */
|
||||
line_read = readline (prompt);
|
||||
|
||||
#ifdef HAVE_LIBHISTORY
|
||||
/* If the line has any text in it, save it on the history. */
|
||||
if (line_read && *line_read)
|
||||
add_history (line_read);
|
||||
#endif
|
||||
|
||||
return (line_read);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (prompt != NULL)
|
||||
fprintf(stdout, "%s", prompt);
|
||||
fprintf(stdout, "%s", prompt);
|
||||
fflush(stdout);
|
||||
if (!fgets(line_read, 500, stdin))
|
||||
if (!fgets(buf, 500, stdin))
|
||||
return(NULL);
|
||||
line_read[500] = 0;
|
||||
len = strlen(line_read);
|
||||
buf[500] = 0;
|
||||
len = strlen(buf);
|
||||
ret = (char *) malloc(len + 1);
|
||||
if (ret != NULL) {
|
||||
memcpy (ret, line_read, len + 1);
|
||||
memcpy (ret, buf, len + 1);
|
||||
}
|
||||
return(ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void usershell(void) {
|
||||
|
Loading…
Reference in New Issue
Block a user