2000-02-19 Philippe De Muyter <phdm@macqel.be>
[deliverable/binutils-gdb.git] / gdb / command.c
index fd8b8145288853df211ae0093e7961a46187ec0a..95965b2d7d668c04ff1e17c9ae500037fd91aa37 100644 (file)
@@ -1,5 +1,5 @@
 /* Handle lists of commands, their decoding and documentation, for GDB.
-   Copyright 1986, 1989, 1990, 1991, 1998 Free Software Foundation, Inc.
+   Copyright 1986, 1989, 1990, 1991, 1998, 2000 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include "value.h"
 #include <ctype.h>
 #include "gdb_string.h"
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+#ifdef UI_OUT
+#include "ui-out.h"
 #endif
 
-#ifdef HAVE_WAIT_H
-#include <wait.h>
-#else
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif
-#endif
+#include "gdb_wait.h"
 
-#include "wait.h"
+/* FIXME: this should be auto-configured!  */
+#ifdef __MSDOS__
+# define CANT_FORK
+#endif
 
 /* Prototypes for local functions */
 
@@ -42,7 +39,7 @@ static void undef_cmd_error PARAMS ((char *, char *));
 
 static void show_user PARAMS ((char *, int));
 
-static void show_user_1 PARAMS ((struct cmd_list_element *, GDB_FILE *));
+static void show_user_1 (struct cmd_list_element *, struct ui_file *);
 
 static void make_command PARAMS ((char *, int));
 
@@ -50,7 +47,7 @@ static void shell_escape PARAMS ((char *, int));
 
 static int parse_binary_operation PARAMS ((char *));
 
-static void print_doc_line PARAMS ((GDB_FILE *, char *));
+static void print_doc_line (struct ui_file *, char *);
 
 static struct cmd_list_element *find_cmd PARAMS ((char *command,
                                                  int len,
@@ -388,7 +385,7 @@ delete_cmd (name, list)
 void
 help_cmd (command, stream)
      char *command;
-     GDB_FILE *stream;
+     struct ui_file *stream;
 {
   struct cmd_list_element *c;
   extern struct cmd_list_element *cmdlist;
@@ -453,7 +450,7 @@ help_list (list, cmdtype, class, stream)
      struct cmd_list_element *list;
      char *cmdtype;
      enum command_class class;
-     GDB_FILE *stream;
+     struct ui_file *stream;
 {
   int len;
   char *cmdtype1, *cmdtype2;
@@ -494,7 +491,7 @@ Command name abbreviations are allowed if unambiguous.\n",
 /* Print only the first line of STR on STREAM.  */
 static void
 print_doc_line (stream, str)
-     GDB_FILE *stream;
+     struct ui_file *stream;
      char *str;
 {
   static char *line_buffer = 0;
@@ -520,7 +517,11 @@ print_doc_line (stream, str)
   line_buffer[p - str] = '\0';
   if (islower (line_buffer[0]))
     line_buffer[0] = toupper (line_buffer[0]);
+#ifdef UI_OUT
+  ui_out_text (uiout, line_buffer);
+#else
   fputs_filtered (line_buffer, stream);
+#endif
 }
 
 /*
@@ -545,7 +546,7 @@ help_cmd_list (list, class, prefix, recurse, stream)
      enum command_class class;
      char *prefix;
      int recurse;
-     GDB_FILE *stream;
+     struct ui_file *stream;
 {
   register struct cmd_list_element *c;
 
@@ -1363,17 +1364,79 @@ do_setshow_command (arg, from_tty, c)
     }
   else if (c->type == show_cmd)
     {
+#ifdef UI_OUT
+      struct cleanup *old_chain;
+      struct ui_stream *stb;
+      int quote;
+
+      stb = ui_out_stream_new (uiout);
+      old_chain = make_cleanup ((make_cleanup_func) ui_out_stream_delete, stb);
+#endif /* UI_OUT */
+
       /* Print doc minus "show" at start.  */
       print_doc_line (gdb_stdout, c->doc + 5);
 
-      fputs_filtered (" is ", gdb_stdout);
-      wrap_here ("    ");
+#ifdef UI_OUT
+      ui_out_text (uiout, " is ");
+      ui_out_wrap_hint (uiout, "    ");
+      quote = 0;
       switch (c->var_type)
        {
        case var_string:
          {
            unsigned char *p;
 
+           if (*(unsigned char **) c->var)
+             fputstr_filtered (*(unsigned char **) c->var, '"', stb->stream);
+           quote = 1;
+         }
+         break;
+       case var_string_noescape:
+       case var_filename:
+       case var_enum:
+         if (*(char **) c->var)
+           fputs_filtered (*(char **) c->var, stb->stream);
+         quote = 1;
+         break;
+       case var_boolean:
+         fputs_filtered (*(int *) c->var ? "on" : "off", stb->stream);
+         break;
+       case var_uinteger:
+         if (*(unsigned int *) c->var == UINT_MAX)
+           {
+             fputs_filtered ("unlimited", stb->stream);
+             break;
+           }
+         /* else fall through */
+       case var_zinteger:
+         fprintf_filtered (stb->stream, "%u", *(unsigned int *) c->var);
+         break;
+       case var_integer:
+         if (*(int *) c->var == INT_MAX)
+           {
+             fputs_filtered ("unlimited", stb->stream);
+           }
+         else
+           fprintf_filtered (stb->stream, "%d", *(int *) c->var);
+         break;
+
+       default:
+         error ("gdb internal error: bad var_type in do_setshow_command");
+       }
+      if (quote)
+       ui_out_text (uiout, "\"");
+      ui_out_field_stream (uiout, "value", stb);
+      if (quote)
+       ui_out_text (uiout, "\"");
+      ui_out_text (uiout, ".\n");
+      do_cleanups (old_chain);
+#else
+      fputs_filtered (" is ", gdb_stdout);
+      wrap_here ("    ");
+      switch (c->var_type)
+       {
+       case var_string:
+         {
            fputs_filtered ("\"", gdb_stdout);
            if (*(unsigned char **) c->var)
              fputstr_filtered (*(unsigned char **) c->var, '"', gdb_stdout);
@@ -1414,10 +1477,13 @@ do_setshow_command (arg, from_tty, c)
          error ("gdb internal error: bad var_type in do_setshow_command");
        }
       fputs_filtered (".\n", gdb_stdout);
+#endif
     }
   else
     error ("gdb internal error: bad cmd_type in do_setshow_command");
   (*c->function.sfunc) (NULL, from_tty, c);
+  if (c->type == set_cmd && set_hook)
+    set_hook (c);
 }
 
 /* Show all the settings in a list of show commands.  */
@@ -1428,10 +1494,31 @@ cmd_show_list (list, from_tty, prefix)
      int from_tty;
      char *prefix;
 {
+#ifdef UI_OUT
+  ui_out_list_begin (uiout, "showlist");
+#endif
   for (; list != NULL; list = list->next)
     {
       /* If we find a prefix, run its list, prefixing our output by its
          prefix (with "show " skipped).  */
+#ifdef UI_OUT
+      if (list->prefixlist && !list->abbrev_flag)
+       {
+         ui_out_list_begin (uiout, "optionlist");
+         ui_out_field_string (uiout, "prefix", list->prefixname + 5);
+         cmd_show_list (*list->prefixlist, from_tty, list->prefixname + 5);
+         ui_out_list_end (uiout);
+       }
+      if (list->type == show_cmd)
+       {
+         ui_out_list_begin (uiout, "option");
+         ui_out_text (uiout, prefix);
+         ui_out_field_string (uiout, "name", list->name);
+         ui_out_text (uiout, ":  ");
+         do_setshow_command ((char *) NULL, from_tty, list);
+         ui_out_list_end (uiout);
+       }
+#else
       if (list->prefixlist && !list->abbrev_flag)
        cmd_show_list (*list->prefixlist, from_tty, list->prefixname + 5);
       if (list->type == show_cmd)
@@ -1441,7 +1528,11 @@ cmd_show_list (list, from_tty, prefix)
          fputs_filtered (":  ", gdb_stdout);
          do_setshow_command ((char *) NULL, from_tty, list);
        }
+#endif
     }
+#ifdef UI_OUT
+  ui_out_list_end (uiout);
+#endif
 }
 
 /* ARGSUSED */
@@ -1451,9 +1542,29 @@ shell_escape (arg, from_tty)
      int from_tty;
 {
 #ifdef CANT_FORK
-  /* FIXME: what about errors (I don't know how GO32 system() handles
-     them)?  */
-  system (arg);
+  /* If ARG is NULL, they want an inferior shell, but `system' just
+     reports if the shell is available when passed a NULL arg.  */
+  int rc = system (arg ? arg : "");
+
+  if (!arg)
+    arg = "inferior shell";
+
+  if (rc == -1)
+    {
+      fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", arg,
+                         safe_strerror (errno));
+      gdb_flush (gdb_stderr);
+    }
+  else if (rc)
+    {
+      fprintf_unfiltered (gdb_stderr, "%s exited with status %d\n", arg, rc);
+      gdb_flush (gdb_stderr);
+    }
+#ifdef __DJGPP__
+  /* Make sure to return to the directory GDB thinks it is, in case the
+     shell command we just ran changed it.  */
+  chdir (current_directory);
+#endif
 #else /* Can fork.  */
   int rc, status, pid;
   char *p, *user_shell;
@@ -1510,7 +1621,7 @@ make_command (arg, from_tty)
 static void
 show_user_1 (c, stream)
      struct cmd_list_element *c;
-     GDB_FILE *stream;
+     struct ui_file *stream;
 {
   register struct command_line *cmdlines;
 
@@ -1521,12 +1632,17 @@ show_user_1 (c, stream)
   fputs_filtered (c->name, stream);
   fputs_filtered (":\n", stream);
 
+#ifdef UI_OUT
+  print_command_lines (uiout, cmdlines, 1);
+  fputs_filtered ("\n", stream);
+#else
   while (cmdlines)
     {
       print_command_line (cmdlines, 4, stream);
       cmdlines = cmdlines->next;
     }
   fputs_filtered ("\n", stream);
+#endif
 }
 
 /* ARGSUSED */
This page took 0.026421 seconds and 4 git commands to generate.