[Cocci] Indentation problem with else branch of ternary operator ?:
Josh Triplett
josh at joshtriplett.org
Sun Jun 13 22:25:39 CEST 2010
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
More information about the Cocci
mailing list