AW: [PATCH] xrdb: Add actual querying capabilities to -query
Walter Harms
wharms at bfs.de
Sun Jun 20 12:46:13 UTC 2021
Hi,
thx for the patch.
NTL it is better for the general look if you use a name
for sign-off that is more easy to pronounce.
for a starter:
yes, i think we can drop support for solaris 4 :)
IMHO, the idea is good. I am struggling a bit with
reusing the query option but thats not a showstopper.
Lets see if a discussion comes up and if no one objects
ping me next WE.
re,
wh
________________________________________
Von: xorg-devel <xorg-devel-bounces at lists.x.org> im Auftrag von rnhmjoj <rnhmjoj at inventati.org>
Gesendet: Sonntag, 20. Juni 2021 13:28
An: xorg-devel at lists.x.org
Betreff: [PATCH] xrdb: Add actual querying capabilities to -query
Hi all,
I've opened a pull request on gitlab[1] months ago, but apparently
it hasn't been noticed, so I'm sending the patch here too. It's a
pretty simple change to xrdb but I think it's very useful: I've been
using it for a while and it simplified my shell scripts a lot.
[1]: https://gitlab.freedesktop.org/xorg/app/xrdb/-/merge_requests/2
--- ORIGINAL PATCH HERE ---
The world is littered with broken grep commands because `xrdb -query`
can only dump the database and doesn't implement this simple search feature.
Things I tested:
- `xrdb -query` without arguments works the same as before
- `xrdb -query prop` prints the value of `prop` when it exists in the
resource database.
- `xrdb -query prop` doesn't print anything when `prop` doesn't exist
in the resource database.
- `xrdb -query prop` doesn't leak any memory. I run it in valgrind
with the `--leak-check=full` option.
PS: I think Sun took care of the fputs thing by now.
Signed-off-by: rnhmjoj <rnhmjoj at inventati.org>
---
xrdb.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/xrdb.c b/xrdb.c
index 3f6e533..4b69363 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>
@@ -126,6 +127,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 *query_property = NULL;
static Bool dont_execute = False;
static Bool show_cpp = False;
static String defines;
@@ -785,7 +787,7 @@ Syntax(const char *errmsg)
" -cpp filename preprocessor to use [%s]\n"
" -nocpp do not use a preprocessor\n"
" -E show preprocessor command & processed input file\n"
- " -query query resources\n"
+ " -query [property] query resources\n"
" -load load resources from file [default]\n"
" -override add in resources from file\n"
" -merge merge resources from file & sort\n"
@@ -982,6 +984,8 @@ main(int argc, char *argv[])
}
else if (isabbreviation("-query", arg, 2)) {
oper = OPQUERY;
+ if (i+1 < argc && argv[i+1][0] != '-')
+ query_property = argv[++i];
continue;
}
else if (isabbreviation("-load", arg, 2)) {
@@ -1283,8 +1287,18 @@ Process(int scrno, Bool doScreen, Bool execute)
printf("%s\n", defines.val);
}
else if (oper == OPQUERY) {
- if (xdefs)
- printf("%s", xdefs); /* fputs broken in SunOS 4.0 */
+ if (xdefs && query_property != NULL) {
+ char *type = NULL;
+ XrmValue value;
+ XrmDatabase xrdb = XrmGetStringDatabase(xdefs);
+ Bool found = XrmGetResource(xrdb, query_property,
+ query_property, &type, &value);
+ if (found == True && value.addr != NULL)
+ printf("%s\n", value.addr);
+ XrmDestroyDatabase(xrdb);
+ }
+ else if (xdefs)
+ fputs(xdefs, stdout);
}
else if (oper == OPREMOVE) {
if (xdefs)
--
2.31.1
_______________________________________________
xorg-devel at lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel
More information about the xorg-devel
mailing list