Skip to content

Instantly share code, notes, and snippets.

@flatcap
Created July 2, 2018 20:59
Show Gist options
  • Save flatcap/deb551e5824c45748fa1cf2c87b3a52f to your computer and use it in GitHub Desktop.
Save flatcap/deb551e5824c45748fa1cf2c87b3a52f to your computer and use it in GitHub Desktop.
Transform struct Context members
@@
struct Context *c;
@@
- c->tagged
+ c->nr_tagged
@flatcap
Copy link
Author

flatcap commented Jul 2, 2018

Apply it by running: spatch --sp-file context.cocci sidebar.c

It'll output a diff, something like:

--- sidebar.c
+++ /tmp/cocci-output-21454-7a4ce7-sidebar.c
@@ -215,9 +215,9 @@ static const char *sidebar_format_str(ch
       if (!optional)
       {
         snprintf(fmt, sizeof(fmt), "%%%sd", prec);
-        snprintf(buf, buflen, fmt, c ? Context->tagged : 0);
+        snprintf(buf, buflen, fmt, c ? Context->nr_tagged : 0);
       }
-      else if ((c && Context->tagged == 0) || !c)
+      else if ((c && Context->nr_tagged == 0) || !c)
         optional = 0;
       break;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment