public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Stephanos Ioannidis <root@stephanos.io>
To: gdb-patches@sourceware.org
Cc: Stephanos Ioannidis <root@stephanos.io>
Subject: [PATCH 2/2] gdb: Resolve local source-highlight data directory
Date: Tue,  2 Jun 2020 15:53:22 +0900	[thread overview]
Message-ID: <20200602065322.74600-3-root@stephanos.io> (raw)
In-Reply-To: <20200602065322.74600-1-root@stephanos.io>

The source-highlight data directory, which contains the input language
and output format definition files, is currently resolved by the
source-highlight library as one of the following:

 * Path specified by the environment variable SOURCE_HIGHLIGHT_DATADIR
 * Path specified by the source-highlight configuration file under HOME
 * Internally hard-coded path based on the installation prefix

This is less than ideal because users need to install a copy of the
source-highlight program on their system, and either manually set the
SOURCE_HIGHLIGHT_DATADIR environment variable to the path of the
directory containing the source-highlight data files or provide a
source-highlight configuration file under HOME that specifies the data
directory path.

This patch adds the logic to resolve, when exists, the path of the
source-highlight data directory embedded in the gdb data directory,
such that the source code syntax highlighting feature can function
independent of the host system dependencies and configurations.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
---
 gdb/source-cache.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 0561a26737..aa1b5b3dc7 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -35,6 +35,7 @@
 #undef close
 #include <sstream>
 #include <srchilite/sourcehighlight.h>
+#include <srchilite/settings.h>
 #include <srchilite/langmap.h>
 #endif
 
@@ -194,6 +195,21 @@ source_cache::ensure (struct symtab *s)
 	    {
 	      if (highlighter == nullptr)
 		{
+		  /* Configure source-highlight data directory path to the GDB
+		   * local data directory path unless it is missing */
+		  std::string datadir = gdb_datadir + "/source-highlight";
+
+		  struct stat st;
+		  static srchilite::Settings settings;
+
+		  if (stat (datadir.c_str (), &st) == 0
+		      && S_ISDIR (st.st_mode))
+		    {
+		      settings.setGlobalDataDir(datadir);
+		    }
+
+		  /* Create a highlighter instance that outputs the ANSI
+		   * escape code-based color output */
 		  highlighter = new srchilite::SourceHighlight ("esc.outlang");
 		  highlighter->setStyleFile ("esc.style");
 		}
-- 
2.26.2


      parent reply	other threads:[~2020-06-02  6:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-02  6:53 [PATCH 0/2] Support installing " Stephanos Ioannidis
2020-06-02  6:53 ` [PATCH 1/2] gdb: Install " Stephanos Ioannidis
2020-06-02  6:53 ` Stephanos Ioannidis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200602065322.74600-3-root@stephanos.io \
    --to=root@stephanos.io \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).