Hi,

I encountered a slight indentation problem in output code using the
ternary operator.  I wrote this semantic patch:

@@
identifier displayname;
@@
(
-XDisplayName(NULL)
+getenv("DISPLAY")
|
-XDisplayName(displayname)
+displayname ? displayname : getenv("DISPLAY")
)

And I applied it to this code:

int
main(int argc, char *argv[])
{
// ...
    dpy = XOpenDisplay (displayname);
    if (!dpy) {
        fprintf (stderr, "%s:  unable to open display \"%s\"\n",
                 ProgramName, XDisplayName (displayname));
        Exit (1);
    }
    screenno = DefaultScreen (dpy);
// ...
}

I ended up with this patch:

@@ -143,7 +143,7 @@ main(int argc, char *argv[])
     dpy = XOpenDisplay (displayname);
     if (!dpy) {
        fprintf (stderr, "%s:  unable to open display \"%s\"\n",
-                ProgramName, XDisplayName (displayname));
+                ProgramName, displayname ? displayname :getenv("DISPLAY"));
        Exit (1);
     }
     screenno = DefaultScreen (dpy);

Note the lack of a space between ':' and getenv.

- Josh Triplett
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to