]> git.ipfire.org Git - thirdparty/systemd.git/blob - coccinelle/strempty.cocci
meson: Use configure_file when version-tag is specified
[thirdparty/systemd.git] / coccinelle / strempty.cocci
1 @@
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 */
11 position 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 };
16 expression s;
17 @@
18 (
19 - s@p ?: ""
20 + strempty(s)
21 |
22 - s@p ? s : ""
23 + strempty(s)
24 )
25
26 @@
27 position p : script:python() { p[0].current_element != "strempty" };
28 expression s;
29 @@
30 - if (!s@p)
31 - s = "";
32 + s = strempty(s);
33
34 @@
35 position p : script:python() { p[0].current_element != "strnull" };
36 expression s;
37 @@
38 (
39 - s@p ?: "(null)"
40 + strnull(s)
41 |
42 - s@p ? s : "(null)"
43 + strnull(s)
44 )
45
46 @@
47 position p : script:python() { p[0].current_element != "strnull" };
48 expression s;
49 @@
50 - if (!s@p)
51 - s = "(null)";
52 + s = strnull(s);
53
54 @@
55 position p : script:python() { p[0].current_element != "strna" };
56 expression s;
57 @@
58 (
59 - s@p ?: "n/a"
60 + strna(s)
61 |
62 - s@p ? s : "n/a"
63 + strna(s)
64 )
65
66 @@
67 position p : script:python() { p[0].current_element != "strna" };
68 expression s;
69 @@
70 - if (!s@p)
71 - s = "n/a";
72 + s = strna(s);