changeset 7726:bf3b4aa1ab09

* lib/yesno.c [!ENABLE_NLS]: Don't include getline.h. (yesno) [!ENABLE_NLS]: Don't invoke getline or rpmatch. This is for the benefit of gzip, which doesn't do i18n.
author Paul Eggert <eggert@cs.ucla.edu>
date Thu, 14 Dec 2006 18:47:36 +0000
parents 4ca3b4452773
children 9711a2d74170
files ChangeLog lib/yesno.c
diffstat 2 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-12-14  Paul Eggert  <eggert@cs.ucla.edu>
+
+	* lib/yesno.c [!ENABLE_NLS]: Don't include getline.h.
+	(yesno) [!ENABLE_NLS]: Don't invoke getline or rpmatch.
+	This is for the benefit of gzip, which doesn't do i18n.
+
 2006-12-12  Jim Meyering  <jim@meyering.net>
 
 	* m4/acl.m4 (gl_ACL_GET_FILE): Fix logic error.
--- a/lib/yesno.c
+++ b/lib/yesno.c
@@ -24,7 +24,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include "getline.h"
+#if ENABLE_NLS
+# include "getline.h"
+#endif
 
 /* Return true if we read an affirmative line from standard input.  */
 
@@ -33,10 +35,12 @@
 bool
 yesno (void)
 {
+  bool yes;
+
+#if ENABLE_NLS
   char *response = NULL;
   size_t response_size = 0;
   ssize_t response_len = getline (&response, &response_size, stdin);
-  bool yes;
 
   if (response_len <= 0)
     yes = false;
@@ -47,5 +51,14 @@
     }
 
   free (response);
+#else
+  /* Test against "^[yY]", hardcoded to avoid requiring getline,
+     regex, and rpmatch.  */
+  int c = getchar ();
+  yes = (c == 'y' || c == 'Y');
+  while (c != '\n' && c != EOF)
+    c = getchar ();
+#endif
+
   return yes;
 }