summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWalter Harms <wharms@bfs.de>2021-06-26 22:55:46 +0200
committerWalter Harms <wharms@bfs.de>2021-06-26 22:55:46 +0200
commit2c57bc85c4cea7a159985a446e1f5f61a4c0f139 (patch)
treec6e387e5715d4cb57f1c3cbe4377f136f99b4435
parent9c51a2829f65ea03ef87376ca9561037d9262f6d (diff)
Add actual querying capabilities
The world is littered with broken grep commands because `xrdb -query` can only dump the database and doesn't implement this simple search feature. This patch adds a new `-get` option to search and print the content of a single property by name. Signed-off-by: Michele Guerini Rocco <rnhm...@inventati.org> Reviewed-by: Walter Harms <wharms@bfs.de> Signed-off-by: Walter Harms <wharms@bfs.de>
-rw-r--r--man/xrdb.man4
-rw-r--r--xrdb.c25
2 files changed, 28 insertions, 1 deletions
diff --git a/man/xrdb.man b/man/xrdb.man
index 7ed14fc..85c748b 100644
--- a/man/xrdb.man
+++ b/man/xrdb.man
@@ -251,6 +251,10 @@ option. The
option can be used to merge the contents of properties back into the input
resource file without damaging preprocessor commands.
.TP 8
+.B \-get \fIname\fP
+This option indicates that the current content of the property matching
+\fIname\fP should be printed onto the standard output.
+.TP 8
.B \-load
This option indicates that the input should be loaded as the new value
of the specified properties, replacing whatever was there (i.e.
diff --git a/xrdb.c b/xrdb.c
index 3f6e533..e93ce12 100644
--- a/xrdb.c
+++ b/xrdb.c
@@ -48,6 +48,7 @@
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include <X11/Xmu/SysUtil.h>
+#include <X11/Xresource.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
@@ -84,6 +85,7 @@
#define OPLOAD 4
#define OPMERGE 5
#define OPOVERRIDE 6
+#define OPGET 7
#define BACKUP_SUFFIX ".bak" /* for editing */
@@ -126,6 +128,7 @@ static char *editFile = NULL;
static const char *cpp_program = NULL;
static const char * const cpp_locations[] = { CPP };
static const char *backup_suffix = BACKUP_SUFFIX;
+static const char *resource_name = NULL;
static Bool dont_execute = False;
static Bool show_cpp = False;
static String defines;
@@ -786,6 +789,7 @@ Syntax(const char *errmsg)
" -nocpp do not use a preprocessor\n"
" -E show preprocessor command & processed input file\n"
" -query query resources\n"
+ " -get name get the content of a resource\n"
" -load load resources from file [default]\n"
" -override add in resources from file\n"
" -merge merge resources from file & sort\n"
@@ -984,6 +988,13 @@ main(int argc, char *argv[])
oper = OPQUERY;
continue;
}
+ else if (isabbreviation("-get", arg, 2)) {
+ oper = OPGET;
+ if (++i >= argc)
+ Syntax("-get requires an argument");
+ resource_name = argv[i];
+ continue;
+ }
else if (isabbreviation("-load", arg, 2)) {
oper = OPLOAD;
continue;
@@ -1284,7 +1295,19 @@ Process(int scrno, Bool doScreen, Bool execute)
}
else if (oper == OPQUERY) {
if (xdefs)
- printf("%s", xdefs); /* fputs broken in SunOS 4.0 */
+ fputs(xdefs, stdout);
+ }
+ else if (oper == OPGET) {
+ if (xdefs && resource_name != NULL) {
+ char *type = NULL;
+ XrmValue value;
+ XrmDatabase xrdb = XrmGetStringDatabase(xdefs);
+ Bool found = XrmGetResource(xrdb, resource_name,
+ resource_name, &type, &value);
+ if (found == True && value.addr != NULL)
+ printf("%s\n", value.addr);
+ XrmDestroyDatabase(xrdb);
+ }
}
else if (oper == OPREMOVE) {
if (xdefs)