On Sun, Nov 11, 2018 at 06:07:10PM +0100, Klemens Nanni wrote:
> There's no point in parsing `-display' separately, just do it once and
> simplify the code while here.
> 
> This addresses two of cheloha's comments from my strtonum diff.
Ping.

Feedback? OK?

Index: xidle.c
===================================================================
RCS file: /cvs/xenocara/app/xidle/xidle.c,v
retrieving revision 1.8
diff -u -p -r1.8 xidle.c
--- xidle.c     11 Nov 2018 16:10:37 -0000      1.8
+++ xidle.c     26 Nov 2018 17:37:30 -0000
@@ -75,13 +75,10 @@ struct xinfo {
 
 struct xinfo x;
 
-static XrmOptionDescRec fopts[] = {
-       { "-display",   ".display",     XrmoptionSepArg,        (caddr_t)NULL },
-};
-
 static XrmOptionDescRec opts[] = {
        { "-area",      ".area",        XrmoptionSepArg,        (caddr_t)NULL },
        { "-delay",     ".delay",       XrmoptionSepArg,        (caddr_t)NULL },
+       { "-display",   ".display",     XrmoptionSepArg,        (caddr_t)NULL },
        { "-program",   ".program",     XrmoptionSepArg,        (caddr_t)NULL },
        { "-timeout",   ".timeout",     XrmoptionSepArg,        (caddr_t)NULL },
 
@@ -263,37 +260,25 @@ parse_opts(int argc, char **argv, Displa
 
        XrmInitialize();
 
-       /* Get display to open. */
-       XrmParseCommand(&rdb, fopts, sizeof(fopts) / sizeof(fopts[0]),
+       /* Get command line values. */
+       XrmParseCommand(&rdb, opts, sizeof(opts) / sizeof(opts[0]),
            __progname, &argc, argv);
+       if (argc > 1)
+               usage();
 
-       display = (getres(&value, rdb, "display", "Display") == True) ?
-           (char *)value.addr : NULL;
+       display = getres(&value, rdb, "display", "Display") ? value.addr : NULL;
 
-       *dpy = XOpenDisplay(display);
-       if (!*dpy) {
+       if (!(*dpy = XOpenDisplay(display)))
                errx(1, "Unable to open display %s", XDisplayName(display));
-       }
 
-       /* Get server resources database. */
-       p = XResourceManagerString(*dpy);
-       if (!p) {
-               /* Get screen resources database. */
-               p = XScreenResourceString(ScreenOfDisplay(*dpy,
-                   DefaultScreen(*dpy)));
-       }
-
-       if (p) {
+       /* Get resources database. */
+       if ((p = XResourceManagerString(*dpy)) ||
+           (p = XScreenResourceString(ScreenOfDisplay(*dpy,
+           DefaultScreen(*dpy))))) {
                tdb = XrmGetStringDatabase(p);
                XrmMergeDatabases(tdb, &rdb);
        }
 
-       /* Get remaining command line values. */
-       XrmParseCommand(&rdb, opts, sizeof(opts) / sizeof(opts[0]),
-           __progname, &argc, argv);
-       if (argc > 1) {
-               usage();
-       }
        if (getres(&value, rdb, "area", "Area")) {
                *area = strtonum(value.addr, 1, INT_MAX, &errstr);
                if (errstr)
===================================================================
Stats: --- 26 lines 719 chars
Stats: +++ 11 lines 451 chars
Stats: -15 lines
Stats: -268 chars

Reply via email to