[RFC,2/6] Add "help news"

Message ID 20200404145422.19917-3-tom@tromey.com
State Superseded
Headers show
Series
  • Some user-friendliness changes
Related show

Commit Message

Tom Tromey April 4, 2020, 2:54 p.m.
This adds a "help news" subcommand, which simply dumps the NEWS file.
The NEWS file is now installed.

gdb/ChangeLog
2020-03-28  Tom Tromey  <tom@tromey.com>

	* NEWS: Add entry.
	* data-directory/Makefile.in (GDB_FILES): New variable.
	(all): Add gdb-files.
	(gdb-files, install-gdb-files, uninstall-gdb-files): New targets.
	(install-only, uninstall): Update.
	* cli/cli-decode.c (help_news): New file.
	(help_cmd): Handle "news".
	(help_list): Mention "help news".
---
 gdb/ChangeLog                  | 11 +++++++++
 gdb/NEWS                       |  3 +++
 gdb/cli/cli-decode.c           | 41 ++++++++++++++++++++++++++++++++++
 gdb/data-directory/Makefile.in | 28 ++++++++++++++++++++---
 4 files changed, 80 insertions(+), 3 deletions(-)

-- 
2.17.2

Comments

Eli Zaretskii April 4, 2020, 4:15 p.m. | #1
> From: Tom Tromey <tom@tromey.com>

> Date: Sat,  4 Apr 2020 08:54:18 -0600

> Cc: Tom Tromey <tom@tromey.com>

> 

> This adds a "help news" subcommand, which simply dumps the NEWS file.

> The NEWS file is now installed.


Thanks.

> diff --git a/gdb/NEWS b/gdb/NEWS

> index 6657f6fadce..9d85e630e8c 100644

> --- a/gdb/NEWS

> +++ b/gdb/NEWS

> @@ -44,6 +44,9 @@

>  

>  * New commands

>  

> +help news

> +  Show this NEWS file.


This part is OK.

> +static void

> +help_news (struct ui_file *stream)

> +{

> +  std::string news_name = std::string (gdb_datadir) + SLASH_STRING + "NEWS";

> +  gdb_file_up news_file = gdb_fopen_cloexec (news_name.c_str (), "r");


Is datadir the best place for NEWS?  Why not somewhere below docdir?
Eli Zaretskii April 4, 2020, 4:41 p.m. | #2
> Date: Sat, 04 Apr 2020 19:15:21 +0300

> From: Eli Zaretskii <eliz@gnu.org>

> Cc: gdb-patches@sourceware.org

> 

> > From: Tom Tromey <tom@tromey.com>

> > Date: Sat,  4 Apr 2020 08:54:18 -0600

> > Cc: Tom Tromey <tom@tromey.com>

> > 

> > This adds a "help news" subcommand, which simply dumps the NEWS file.

> > The NEWS file is now installed.

> 

> Thanks.


Btw, I don't see this subcommand described in the manual.  Should it
be?
Tom Tromey June 21, 2020, 8:23 p.m. | #3
>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:


>> +static void

>> +help_news (struct ui_file *stream)

>> +{

>> +  std::string news_name = std::string (gdb_datadir) + SLASH_STRING + "NEWS";

>> +  gdb_file_up news_file = gdb_fopen_cloexec (news_name.c_str (), "r");


Eli> Is datadir the best place for NEWS?  Why not somewhere below docdir?

I looked into this.  docdir does seem more correct according to the GNU
coding standards, but on the other hand, making it work properly seems
like a lot of work (adding a new setting and command line option) for
what amounts to a minor conformance thing.

So unless someone feels very strongly about it, I'm inclined to leave it
as is.

>> Btw, I don't see this subcommand described in the manual.  Should it

>> be?


Probably but where would be the best place to put it?

Tom
Eli Zaretskii June 22, 2020, 2:23 a.m. | #4
> From: Tom Tromey <tom@tromey.com>

> Cc: Tom Tromey <tom@tromey.com>,  gdb-patches@sourceware.org

> Date: Sun, 21 Jun 2020 14:23:13 -0600

> 

> >> Btw, I don't see this subcommand described in the manual.  Should it

> >> be?

> 

> Probably but where would be the best place to put it?


In "Help", I'd say.

Patch

diff --git a/gdb/NEWS b/gdb/NEWS
index 6657f6fadce..9d85e630e8c 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -44,6 +44,9 @@ 
 
 * New commands
 
+help news
+  Show this NEWS file.
+
 set exec-file-mismatch -- Set exec-file-mismatch handling (ask|warn|off).
 show exec-file-mismatch -- Show exec-file-mismatch handling (ask|warn|off).
   Set or show the option 'exec-file-mismatch'.  When GDB attaches to
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 7aecd9897e2..948350c7a7f 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1030,6 +1030,38 @@  apropos_cmd (struct ui_file *stream,
     }
 }
 
+/* Implement "help news".  */
+
+static void
+help_news (struct ui_file *stream)
+{
+  std::string news_name = std::string (gdb_datadir) + SLASH_STRING + "NEWS";
+  gdb_file_up news_file = gdb_fopen_cloexec (news_name.c_str (), "r");
+  if (news_file == nullptr)
+    perror_with_name (_("could not open the NEWS file"));
+
+  char buffer[1024];
+  size_t offset = 0;
+  while (true)
+    {
+      size_t nbytes = fread (&buffer[offset], 1, sizeof (buffer) - offset,
+			     news_file.get ());
+      if (nbytes == 0)
+	break;
+      size_t n_valid = offset + nbytes;
+      size_t newline;
+      for (newline = n_valid; newline > 0 && buffer[newline] != '\n'; --newline)
+	;
+      if (newline == 0)
+	error (_("NEWS file is malformed"));
+      buffer[newline] = '\0';
+      fputs_filtered (buffer, stream);
+      fputs_filtered ("\n", stream);
+      offset = n_valid - (newline + 1);
+      memmove (buffer, &buffer[newline + 1], offset);
+    }
+}
+
 /* This command really has to deal with two things:
    1) I want documentation on *this string* (usually called by
       "help commandname").
@@ -1058,6 +1090,12 @@  help_cmd (const char *command, struct ui_file *stream)
       return;
     }
 
+  if (strcmp (command, "news") == 0)
+    {
+      help_news (stream);
+      return;
+    }
+
   c = lookup_cmd (&command, cmdlist, "", 0, 0);
 
   if (c == 0)
@@ -1156,6 +1194,9 @@  Type \"help%s\" followed by a class name for a list of commands in ",
 
       fprintf_filtered (stream, "\n\
 Type \"help all\" for the list of all commands.");
+
+      fprintf_filtered (stream, "\n\
+Type \"help news\" to see what is new in GDB.");
     }
 
   fprintf_filtered (stream, "\nType \"help%s\" followed by %scommand name ",
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
index 68b794a353d..95258d184e7 100644
--- a/gdb/data-directory/Makefile.in
+++ b/gdb/data-directory/Makefile.in
@@ -139,6 +139,8 @@  SYSTEM_GDBINIT_FILES = \
 	elinos.py \
 	wrs-linux.py
 
+GDB_FILES = NEWS
+
 FLAGS_TO_PASS = \
 	"prefix=$(prefix)" \
 	"exec_prefix=$(exec_prefix)" \
@@ -172,7 +174,7 @@  FLAGS_TO_PASS = \
 	"RUNTESTFLAGS=$(RUNTESTFLAGS)"
 
 .PHONY: all
-all: stamp-syscalls stamp-python stamp-guile stamp-system-gdbinit
+all: stamp-syscalls stamp-python stamp-guile stamp-system-gdbinit gdb-files
 
 %.xml: @MAINTAINER_MODE_TRUE@ %.xml.in apply-defaults.xsl linux-defaults.xml.in
 	$(XSLTPROC) -o $(SYSCALLS_SRCDIR)/$@ $(SYSCALLS_SRCDIR)/apply-defaults.xsl\
@@ -234,6 +236,26 @@  uninstall-syscalls:
 	  done \
 	done
 
+gdb-files: $(addprefix $(srcdir)/../,$(GDB_FILES))
+	files='$(GDB_FILES)'; \
+	for file in $$files; do \
+	  cp $(srcdir)/../$$file .; \
+	done
+
+.PHONY: install-gdb-files
+install-gdb-files:
+	files='$(GDB_FILES)'; \
+	for file in $$files; do \
+	  $(INSTALL_DATA) $(srcdir)/../$$file  $(DESTDIR)$(GDB_DATADIR); \
+	done
+
+.PHONY: uninstall-gdb-files
+uninstall-gdb-files:
+	files='$(GDB_FILES)'; \
+	for file in $$files; do \
+	  rm -f $(DESTDIR)$(GDB_DATADIR)/$$file; \
+	done
+
 stamp-python: Makefile $(PYTHON_FILES)
 	rm -rf ./$(PYTHON_DIR)
 	files='$(PYTHON_FILES)' ; \
@@ -379,11 +401,11 @@  install: all
 
 .PHONY: install-only
 install-only: install-syscalls install-python install-guile \
-	install-system-gdbinit
+	install-system-gdbinit install-news
 
 .PHONY: uninstall
 uninstall: uninstall-syscalls uninstall-python uninstall-guile \
-	uninstall-system-gdbinit
+	uninstall-system-gdbinit uninstall-news
 
 .PHONY: clean
 clean: clean-syscalls clean-python clean-guile clean-system-gdbinit