1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 03:55:04 +03:00

shell: Only use readline on terminals

Should fix xmllint shell tests.
This commit is contained in:
Nick Wellnhofer 2024-07-24 11:42:39 +02:00
parent d04e152d9c
commit 6cc2387e1a
2 changed files with 61 additions and 41 deletions

30
shell.c
View File

@ -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,7 +1057,12 @@ xmllintShellPwd(xmllintShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer,
*/
static char *
xmllintShellReadline(char *prompt) {
char buf[501];
char *ret;
int len;
#ifdef HAVE_LIBREADLINE
if (isatty(STDIN_FILENO)) {
char *line_read;
/* Get a line from the user. */
@ -1060,24 +1075,21 @@ xmllintShellReadline(char *prompt) {
#endif
return (line_read);
#else
char line_read[501];
char *ret;
int len;
}
#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
}
/**

View File

@ -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,7 +69,12 @@ static char *filename = NULL;
*/
static char *
xmlShellReadline(const char *prompt) {
char buf[501];
char *ret;
int len;
#ifdef HAVE_LIBREADLINE
if (isatty(STDIN_FILENO)) {
char *line_read;
/* Get a line from the user. */
@ -76,24 +87,21 @@ xmlShellReadline(const char *prompt) {
#endif
return (line_read);
#else
char line_read[501];
char *ret;
int len;
}
#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
}
static void usershell(void) {