]> git.ipfire.org Git - thirdparty/systemd.git/blame - coccinelle/strempty.cocci
man: fix incorrectly placed full stop
[thirdparty/systemd.git] / coccinelle / strempty.cocci
CommitLineData
de896126 1@@
e4ff0393
FS
2/* Avoid running this transformation on the strempty function itself and
3 * on the "make_expression" macro in src/libsystemd/sd-bus/bus-convenience.c.
4 * As Coccinelle's Location object doesn't support macro "detection", use
5 * a pretty horrifying combo of specifying a file and a special "something_else"
6 * position element, which is, apparently, the default value of
7 * "current_element" before it's set (according to the source code), thus
8 * matching any "top level" position, including macros. Let's hope we never
9 * introduce a function called "something_else"...
10 */
11position p : script:python() {
12 not (p[0].current_element == "strempty" or
13 (p[0].file == "src/libsystemd/sd-bus/bus-convenience.c" and
14 p[0].current_element == "something_else"))
15};
de896126
DM
16expression s;
17@@
60d9959d
FS
18(
19- s@p ?: ""
de896126 20+ strempty(s)
60d9959d
FS
21|
22- s@p ? s : ""
de896126 23+ strempty(s)
60d9959d
FS
24)
25
ad5d4b17 26@@
60d9959d 27position p : script:python() { p[0].current_element != "strempty" };
ad5d4b17
LP
28expression s;
29@@
60d9959d 30- if (!s@p)
ad5d4b17
LP
31- s = "";
32+ s = strempty(s);
60d9959d 33
ad5d4b17 34@@
60d9959d 35position p : script:python() { p[0].current_element != "strnull" };
ad5d4b17
LP
36expression s;
37@@
60d9959d
FS
38(
39- s@p ?: "(null)"
ad5d4b17 40+ strnull(s)
60d9959d
FS
41|
42- s@p ? s : "(null)"
ad5d4b17 43+ strnull(s)
60d9959d
FS
44)
45
ad5d4b17 46@@
60d9959d 47position p : script:python() { p[0].current_element != "strnull" };
ad5d4b17
LP
48expression s;
49@@
60d9959d 50- if (!s@p)
ad5d4b17
LP
51- s = "(null)";
52+ s = strnull(s);
60d9959d 53
ad5d4b17 54@@
60d9959d 55position p : script:python() { p[0].current_element != "strna" };
ad5d4b17
LP
56expression s;
57@@
60d9959d
FS
58(
59- s@p ?: "n/a"
ad5d4b17 60+ strna(s)
60d9959d
FS
61|
62- s@p ? s : "n/a"
ad5d4b17 63+ strna(s)
60d9959d
FS
64)
65
ad5d4b17 66@@
60d9959d 67position p : script:python() { p[0].current_element != "strna" };
ad5d4b17
LP
68expression s;
69@@
60d9959d 70- if (!s@p)
ad5d4b17
LP
71- s = "n/a";
72+ s = strna(s);