2004-02-23 Jeff Johnston <jjohnstn@redhat.com>
authorJeff Johnston <jjohnstn@redhat.com>
Mon, 23 Feb 2004 19:26:14 +0000 (19:26 +0000)
committerJeff Johnston <jjohnstn@redhat.com>
Mon, 23 Feb 2004 19:26:14 +0000 (19:26 +0000)
        * defs.h (nquery, yquery): New prototypes.
        * breakpoint.c (break_command_1): Use new nquery interface.
        * utils.c (defaulted_query, nquery, yquery): New functions.

gdb/ChangeLog
gdb/breakpoint.c
gdb/defs.h
gdb/utils.c

index 942be447eebd37fb5b60a3d8a4ff4595ca238401..3c0a192e740f4f0b7c44db02ee8bde0de85364fa 100644 (file)
@@ -1,3 +1,9 @@
+2004-02-23  Jeff Johnston  <jjohnstn@redhat.com>
+
+       * defs.h (nquery, yquery): New prototypes.
+       * breakpoint.c (break_command_1): Use new nquery interface.
+       * utils.c (defaulted_query, nquery, yquery): New functions.
+
 2004-02-23  Andrew Cagney  <cagney@redhat.com>
 
        * hppa-tdep.c (hppa_frame_align): New function.
        * sh-tdep.c (sh_analyze_prologue): Eliminate useless test of
        cache->uses_fp prior to setting it.
 
+>>>>>>> 1.5450
 2004-02-19  Fred Fish  <fnf@redhat.com>
 
        Fix for PR breakpoint/1558.
        type being greater than sizeof of host's LONGEST.  Always use
        unpack_long() unless format 'f' chosen.
 
+>>>>>>> 1.5419
 2004-02-19  Joel Brobecker  <brobecker@gnat.com>
 
        Committed by Elena Zannoni  <ezannoni@redhat.com>
index a4cfa461b3cfbb69e401454c4cd77c962c320d91..ca5aff52b9ff713e637c6e05243a3c7517be55e2 100644 (file)
@@ -5103,7 +5103,7 @@ break_command_1 (char *arg, int flag, int from_tty, struct breakpoint *pending_b
 
          error_output_message (NULL, err_msg);
          xfree (err_msg);
-         if (!query ("Make breakpoint pending on future shared library load? "))
+         if (!nquery ("Make breakpoint pending on future shared library load? "))
            return rc;
          copy_arg = xstrdup (addr_start);
          addr_string = &copy_arg;
index e6d2fec2649614e4f9389ce0d7229cba13e7b046..e49f9e0e5baafaff31b81d5c9af724695f498fc9 100644 (file)
@@ -405,6 +405,8 @@ extern void null_cleanup (void *);
 extern int myread (int, char *, int);
 
 extern int query (const char *, ...) ATTR_FORMAT (printf, 1, 2);
+extern int nquery (const char *, ...) ATTR_FORMAT (printf, 1, 2);
+extern int yquery (const char *, ...) ATTR_FORMAT (printf, 1, 2);
 
 extern void init_page_info (void);
 
index 34e67771b34a2a9179639d73386ce50cb910aba3..b92512302dd563a556ded599d0877ff768651a2a 100644 (file)
@@ -1335,6 +1335,145 @@ query (const char *ctlstr, ...)
 }
 \f
 
+/* This function supports the nquery() and yquery() functions.
+   Ask user a y-or-n question and return 0 if answer is no, 1 if
+   answer is yes, or default the answer to the specified default.
+   DEFCHAR is either 'y' or 'n' and refers to the default answer.
+   CTLSTR is the control string and should end in "? ".  It should
+   not say how to answer, because we do that.
+   ARGS are the arguments passed along with the CTLSTR argument to
+   printf.  */
+
+static int
+defaulted_query (const char *ctlstr, const char defchar, va_list args)
+{
+  int answer;
+  int ans2;
+  int retval;
+  int def_value;
+  char def_answer, not_def_answer;
+  char *y_string, *n_string;
+
+  /* Set up according to which answer is the default.  */
+  if (defchar == 'y')
+    {
+      def_value = 1;
+      def_answer = 'Y';
+      not_def_answer = 'N';
+      y_string = "[y]";
+      n_string = "n";
+    }
+  else
+    {
+      def_value = 0;
+      def_answer = 'N';
+      not_def_answer = 'Y';
+      y_string = "y";
+      n_string = "[n]";
+    }
+
+  if (query_hook)
+    {
+      return query_hook (ctlstr, args);
+    }
+
+  /* Automatically answer default value if input is not from a terminal.  */
+  if (!input_from_terminal_p ())
+    return def_value;
+
+  while (1)
+    {
+      wrap_here ("");          /* Flush any buffered output */
+      gdb_flush (gdb_stdout);
+
+      if (annotation_level > 1)
+       printf_filtered ("\n\032\032pre-%cquery\n", defchar);
+
+      vfprintf_filtered (gdb_stdout, ctlstr, args);
+      printf_filtered ("(%s or %s) ", y_string, n_string);
+
+      if (annotation_level > 1)
+       printf_filtered ("\n\032\032%cquery\n", defchar);
+
+      wrap_here ("");
+      gdb_flush (gdb_stdout);
+
+      answer = fgetc (stdin);
+      clearerr (stdin);                /* in case of C-d */
+      if (answer == EOF)       /* C-d */
+       {
+         retval = def_value;
+         break;
+       }
+      /* Eat rest of input line, to EOF or newline */
+      if (answer != '\n')
+       do
+         {
+           ans2 = fgetc (stdin);
+           clearerr (stdin);
+         }
+       while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');
+
+      if (answer >= 'a')
+       answer -= 040;
+      /* Check answer.  For the non-default, the user must specify
+         the non-default explicitly.  */
+      if (answer == not_def_answer)
+       {
+         retval = !def_value;
+         break;
+       }
+      /* Otherwise, for the default, the user may either specify
+         the required input or have it default by entering nothing.  */
+      if (answer == def_answer || answer == '\n' || 
+         answer == '\r' || answer == EOF)
+       {
+         retval = def_value;
+         break;
+       }
+      /* Invalid entries are not defaulted and require another selection.  */
+      printf_filtered ("Please answer %s or %s.\n",
+                      y_string, n_string);
+    }
+
+  if (annotation_level > 1)
+    printf_filtered ("\n\032\032post-%cquery\n", defchar);
+  return retval;
+}
+\f
+
+/* Ask user a y-or-n question and return 0 if answer is no, 1 if
+   answer is yes, or 0 if answer is defaulted.
+   Takes three args which are given to printf to print the question.
+   The first, a control string, should end in "? ".
+   It should not say how to answer, because we do that.  */
+
+int
+nquery (const char *ctlstr, ...)
+{
+  va_list args;
+
+  va_start (args, ctlstr);
+  return defaulted_query (ctlstr, 'n', args);
+  va_end (args);
+}
+
+/* Ask user a y-or-n question and return 0 if answer is no, 1 if
+   answer is yes, or 1 if answer is defaulted.
+   Takes three args which are given to printf to print the question.
+   The first, a control string, should end in "? ".
+   It should not say how to answer, because we do that.  */
+
+int
+yquery (const char *ctlstr, ...)
+{
+  va_list args;
+
+  va_start (args, ctlstr);
+  return defaulted_query (ctlstr, 'y', args);
+  va_end (args);
+}
+
 /* Print an error message saying that we couldn't make sense of a
    \^mumble sequence in a string or character constant.  START and END
    indicate a substring of some larger string that contains the
This page took 0.031667 seconds and 4 git commands to generate.