// // Generate cocci file with // //BASE=~/linux //NEXT=~/linux/drivers/staging/hv //spatch.opt -include_headers -sp_file typedef_str -dir $(NEXT) -patch $(BASE) // // Applying a generated cocci file // //.cocci.patch: // spatch.opt -inplace -include_headers -sp_file $< -dir $(NEXT) -patch $(BASE) > $@ @initialize:python@ f = open("typedefs", 'r') d = dict() for line in f: (key, sep, name) = line.partition(':') d[key] = name f.close() @r@ identifier st; type typ; @@ typedef struct st { ... } typ ; @script: python@ st << r.st; typ << r.typ; @@ name = "gen/%s.cocci" % typ strname = d[typ] print name f = open(name, 'w') f.write( "@rm_%s@\n" % typ ) f.write( "@@\n" ) f.write( "-typedef struct %s\n" % st ) f.write( "+struct %s\n" % strname) f.write( "{...}\n" ) f.write( "-%s\n" % typ ) f.write( ";\n\n" ) f.write( "@fixtypedef_%s@\n" % typ ) f.write( "typedef %s;\n" % typ ) f.write( "@@\n" ) f.write( "-%s\n" % typ ) f.write( "+struct %s\n\n" % strname) f.write( "@fixstruct_%s@\n" % st ) f.write( "@@\n" ) f.write( "struct\n" ) f.write( "-%s\n" % st ) f.write( "+%s\n" % strname) f.close()