1#Saluton Emacson! Bonvolu elekti -*- mode: awk; -*-. Dankon.
2
3BEGIN{
4  headerfile="wrapped.h";
5  deffile="wrapdef.h";
6  structfile="wrapstruct.h";
7  tmpffile="wraptmpf.h";
8  FS=";";
9  WARNING="/* Automatically generated file. Do not edit. Edit wrapawk_macosx/wrapfunc.inp. */";
10  print WARNING > headerfile;
11  print "#ifndef WRAPPED_H" > headerfile;
12  print "#define WRAPPED_H" > headerfile;
13  print "#define MY_GLUE2(a,b) a ## b"      > headerfile;
14  print "#define MY_DEF(a) MY_GLUE2(my_,a)" > headerfile;
15  print WARNING > deffile;
16  print "#ifndef WRAPDEF_H" > deffile;
17  print "#define WRAPDEF_H" > deffile;
18  print WARNING > tmpffile;
19  print "#ifndef WRAPTMPF_H" > tmpffile;
20  print "#define WRAPTMPF_H" > tmpffile;
21  print WARNING > structfile;
22  print "#ifndef WRAPSTRUCT_H" > structfile;
23  print "#define WRAPSTRUCT_H" > structfile;
24  print "typedef struct interpose_s {"      > structfile;
25  print "  void *new_func;"                 > structfile;
26  print "  void *orig_func;"                > structfile;
27  print "} interpose_t;"                    > structfile;
28  print "#define INTERPOSE(newf,oldf) \\"   > structfile;
29  print "  __attribute__((used)) static const interpose_t MY_GLUE2(_interpose_,oldf) \\" > structfile;
30  print "    __attribute__((section(\"__DATA,__interpose\"))) = {(void *)newf, (void *)oldf}" > structfile;
31  print ""                                  > structfile;
32}
33
34/\/\*/{
35}
36/^(\#)/{
37  print $0 > structfile;
38  print $0 > tmpffile;
39  print $0 > deffile;
40  print $0 > headerfile;
41
42}
43/^[^\/].*;.*;.*/{
44  name=$1;
45  ret=$2;
46  argtype=$3;
47  argname=$4;
48  MACRO=$5;
49  if(MACRO){
50    print "extern " ret " MY_DEF(" name ")" argtype " __attribute__((visibility(\"hidden\")));" > headerfile;
51    print "INTERPOSE(MY_DEF(" name "_RAW)," name "_RAW);"   > structfile;
52    print "#undef " name                      > deffile
53    print "#define " name " MY_DEF(" name "_RAW)" > deffile
54
55    print "extern " ret, name, argtype ";"              > tmpffile;
56    print "static __inline__ " ret " NEXT_" MACRO "_NOARG " argtype " __attribute__((always_inline));" > tmpffile;
57    print "static __inline__ " ret " NEXT_" MACRO "_NOARG " argtype " {" > tmpffile;
58    print "  return " name, argname ";"                 > tmpffile;
59    print "}"                                           > tmpffile;
60    print ""                                            > tmpffile;
61  } else {
62    print "extern " ret " my_" name, argtype " __attribute__((visibility(\"hidden\")));" > headerfile;
63    print "#undef " name                                > structfile;
64    print "INTERPOSE(my_" name "," name ");"            > structfile;
65    print "#define " name " my_" name                   > structfile
66    print "#define " name " my_" name                   > deffile
67
68    print "extern " ret, name, argtype ";"              > tmpffile;
69    if(argname){
70        print "static __inline__ " ret " next_" name, argtype " __attribute__((always_inline));" > tmpffile;
71        print "static __inline__ " ret " next_" name, argtype " {" > tmpffile;
72        print "  return " name, argname ";"             > tmpffile;
73        print "}"                                       > tmpffile;
74    }
75    print ""                                            > tmpffile;
76  }
77}
78
79/^ *$/{
80  print > structfile;
81  print > headerfile;
82  print > deffile;
83  print > tmpffile;
84}
85
86END{
87  print ""                > structfile;
88  print "struct next_wrap_st next_wrap[]= {" > structfile;
89  print "  {NULL, NULL}," > structfile;
90  print "};"              > structfile;
91  print "#endif"          > structfile;
92  print "#endif"          > tmpffile;
93  print "#endif"          > deffile;
94  print "#endif"          > headerfile;
95}
96