Re: xidle: parse options once, simplify code

2019-04-01 Thread Klemens Nanni
On Mon, Nov 26, 2018 at 06:40:05PM +0100, Klemens Nanni wrote:
> 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?
Found this X diff I still want to get rid of;  one last try but with all
the churn removed this time.

Any takers?

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 -  1.8
+++ xidle.c 1 Apr 2019 11:20:07 -
@@ -76,12 +76,9 @@ 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,9 +260,11 @@ parse_opts(int argc, char **argv, Displa
 
XrmInitialize();
 
-   /* Get display to open. */
+   /* Get command line values. */
XrmParseCommand(, fopts, sizeof(fopts) / sizeof(fopts[0]),
__progname, , argv);
+   if (argc > 1)
+   usage();
 
display = (getres(, rdb, "display", "Display") == True) ?
(char *)value.addr : NULL;
@@ -288,12 +287,6 @@ parse_opts(int argc, char **argv, Displa
XrmMergeDatabases(tdb, );
}
 
-   /* Get remaining command line values. */
-   XrmParseCommand(, opts, sizeof(opts) / sizeof(opts[0]),
-   __progname, , argv);
-   if (argc > 1) {
-   usage();
-   }
if (getres(, rdb, "area", "Area")) {
*area = strtonum(value.addr, 1, INT_MAX, );
if (errstr)
===
Stats: --- 11 lines 293 chars
Stats: +++ 4 lines 119 chars
Stats: -7 lines
Stats: -174 chars



Re: xidle: parse options once, simplify code

2018-11-26 Thread Klemens Nanni
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 -  1.8
+++ xidle.c 26 Nov 2018 17:37:30 -
@@ -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(, fopts, sizeof(fopts) / sizeof(fopts[0]),
+   /* Get command line values. */
+   XrmParseCommand(, opts, sizeof(opts) / sizeof(opts[0]),
__progname, , argv);
+   if (argc > 1)
+   usage();
 
-   display = (getres(, rdb, "display", "Display") == True) ?
-   (char *)value.addr : NULL;
+   display = getres(, 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, );
}
 
-   /* Get remaining command line values. */
-   XrmParseCommand(, opts, sizeof(opts) / sizeof(opts[0]),
-   __progname, , argv);
-   if (argc > 1) {
-   usage();
-   }
if (getres(, rdb, "area", "Area")) {
*area = strtonum(value.addr, 1, INT_MAX, );
if (errstr)
===
Stats: --- 26 lines 719 chars
Stats: +++ 11 lines 451 chars
Stats: -15 lines
Stats: -268 chars