mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-10-26 12:25:09 +03: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 <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIBREADLINE
|
#ifdef HAVE_LIBREADLINE
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
#ifdef HAVE_LIBHISTORY
|
#ifdef HAVE_LIBHISTORY
|
||||||
@ -31,6 +37,10 @@
|
|||||||
|
|
||||||
#include "private/shell.h"
|
#include "private/shell.h"
|
||||||
|
|
||||||
|
#ifndef STDIN_FILENO
|
||||||
|
#define STDIN_FILENO 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: Improvement/cleanups for the XML shell
|
* TODO: Improvement/cleanups for the XML shell
|
||||||
* - allow to shell out an editor on a subpart
|
* - allow to shell out an editor on a subpart
|
||||||
@ -1047,37 +1057,39 @@ xmllintShellPwd(xmllintShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer,
|
|||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
xmllintShellReadline(char *prompt) {
|
xmllintShellReadline(char *prompt) {
|
||||||
#ifdef HAVE_LIBREADLINE
|
char buf[501];
|
||||||
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 *ret;
|
char *ret;
|
||||||
int len;
|
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)
|
if (prompt != NULL)
|
||||||
fprintf(stdout, "%s", prompt);
|
fprintf(stdout, "%s", prompt);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
if (!fgets(line_read, 500, stdin))
|
if (!fgets(buf, 500, stdin))
|
||||||
return(NULL);
|
return(NULL);
|
||||||
line_read[500] = 0;
|
buf[500] = 0;
|
||||||
len = strlen(line_read);
|
len = strlen(buf);
|
||||||
ret = (char *) malloc(len + 1);
|
ret = (char *) malloc(len + 1);
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
memcpy (ret, line_read, len + 1);
|
memcpy (ret, buf, len + 1);
|
||||||
}
|
}
|
||||||
return(ret);
|
return(ret);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
50
xmlcatalog.c
50
xmlcatalog.c
@ -16,6 +16,8 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIBREADLINE
|
#ifdef HAVE_LIBREADLINE
|
||||||
@ -30,6 +32,10 @@
|
|||||||
#include <libxml/catalog.h>
|
#include <libxml/catalog.h>
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
|
|
||||||
|
#ifndef STDIN_FILENO
|
||||||
|
#define STDIN_FILENO 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(LIBXML_CATALOG_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
|
#if defined(LIBXML_CATALOG_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
|
||||||
static int shell = 0;
|
static int shell = 0;
|
||||||
static int sgml = 0;
|
static int sgml = 0;
|
||||||
@ -63,37 +69,39 @@ static char *filename = NULL;
|
|||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
xmlShellReadline(const char *prompt) {
|
xmlShellReadline(const char *prompt) {
|
||||||
#ifdef HAVE_LIBREADLINE
|
char buf[501];
|
||||||
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 *ret;
|
char *ret;
|
||||||
int len;
|
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)
|
if (prompt != NULL)
|
||||||
fprintf(stdout, "%s", prompt);
|
fprintf(stdout, "%s", prompt);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
if (!fgets(line_read, 500, stdin))
|
if (!fgets(buf, 500, stdin))
|
||||||
return(NULL);
|
return(NULL);
|
||||||
line_read[500] = 0;
|
buf[500] = 0;
|
||||||
len = strlen(line_read);
|
len = strlen(buf);
|
||||||
ret = (char *) malloc(len + 1);
|
ret = (char *) malloc(len + 1);
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
memcpy (ret, line_read, len + 1);
|
memcpy (ret, buf, len + 1);
|
||||||
}
|
}
|
||||||
return(ret);
|
return(ret);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usershell(void) {
|
static void usershell(void) {
|
||||||
|
Loading…
Reference in New Issue
Block a user