On Fri, 24 May 2019, Christoph Böhmwalder wrote: > Hi, > > I'm trying to replace a function with a one-liner, where the one-liner > has a dependency on a header file that the function doesn't. > Now I want to include said header file iff it isn't already included > in the affected file. > In more concrete terms, this is my script: > > > @ find_linux_dcache_h @ > @@ > #include > > @ replace_simple_positive @ > expression den; > @@ > - simple_positive(den) > + (den->d_inode && !d_unhashed(den)) > > @ add_linux_dcache_h depends on !find_linux_dcache_h && ever > replace_simple_positive @ > @@ > #include <...> > + #include > > > So far so good, (almost) works just fine. The issue is that if the > rule gets matched in one file, it will include the header in every > other file as well, because the "depends on ever" clause is satisfied. > Is there a way to tell coccinelle "apply this rule to file X, but only > if another rule matched in the same file"? Do you have multiple file names on the command line? If so, this i not a good idea. It will try to process all of the files at once. Normally, you just run Coccinelle on a directory. Then it will process each file independently. You can do it in parallel as well, with the -j option. julia