File: wrapawk

package info (click to toggle)
fakeroot 1.37.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,904 kB
  • sloc: sh: 5,430; ansic: 5,340; makefile: 199; perl: 14
file content (95 lines) | stat: -rw-r--r-- 3,577 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#Saluton Emacson! Bonvolu elekti -*- mode: awk; -*-. Dankon.

BEGIN{
  headerfile="wrapped.h";
  deffile="wrapdef.h";
  structfile="wrapstruct.h";
  tmpffile="wraptmpf.h";
  FS=";";
  WARNING="/* Automatically generated file. Do not edit. Edit wrapawk/wrapfunc.inp. */";
  print WARNING > headerfile;
  print "#ifndef WRAPPED_H" > headerfile;
  print "#define WRAPPED_H" > headerfile;
  print WARNING > deffile;
  print "#ifndef WRAPDEF_H" > deffile;
  print "#define WRAPDEF_H" > deffile;
  print WARNING > tmpffile;
  print "#ifndef WRAPTMPF_H" > tmpffile;
  print "#define WRAPTMPF_H" > tmpffile;
  print WARNING > structfile;
  print "#ifndef WRAPSTRUCT_H" > structfile;
  print "#define WRAPSTRUCT_H" > structfile;
  print "struct next_wrap_st next_wrap[]= {" > structfile;
}

/\/\*/{
}
/^(\#)/{
  print $0 > structfile;
  print $0 > tmpffile;
  print $0 > deffile;
  print $0 > headerfile;

}
/^[^\/].*;.*;.*;/{
  name=$1;
  ret=$2;
  argtype=$3;
  argname=$4;
  MACRO=$5;
  openat_extra=$6;
  if(openat_extra){
    print "  {(void(*))&next_" name ", \"" name "\"},"  > structfile;
    print "extern " ret " (*next_" name ")" openat_extra ";" > headerfile;
    print ret " (*next_" name ")" openat_extra "=tmp_" name ";"> deffile;

    print ret " tmp_" name,  openat_extra "{"           > tmpffile;
    print "  mode_t mode = 0;"                          > tmpffile;
    print "  if (flags & O_CREAT) {"                    > tmpffile;
    print "    va_list args;"                           > tmpffile;
    print "    va_start(args, flags);"                  > tmpffile;
    print "    mode = va_arg(args, int);"               > tmpffile;
    print "    va_end(args);"                           > tmpffile;
    print "  }"                                         > tmpffile;
    print "  load_library_symbols();"                   > tmpffile;
    print "  return  next_" name,  argname ";"          > tmpffile;
    print "}"                                           > tmpffile;
    print ""                                            > tmpffile;
  } else if(MACRO){
    print "  {(void(*))&NEXT_" MACRO "_NOARG, " name "_QUOTE},"  > structfile;
    print "extern " ret " (*NEXT_" MACRO "_NOARG)" argtype ";" > headerfile;
    print ret " (*NEXT_" MACRO "_NOARG)" argtype "=TMP_" MACRO ";"> deffile;
    
    print ret " TMP_" MACRO,  argtype "{"                 > tmpffile;
    print "  load_library_symbols();"                   > tmpffile;
    print "  return  NEXT_" MACRO "_NOARG "  argname ";"           > tmpffile;
    print "}"                                           > tmpffile;
    print ""                                            > tmpffile;
  } else {
    print "  {(void(*))&next_" name ", \"" name "\"},"  > structfile;
    print "extern " ret " (*next_" name ")" argtype ";" > headerfile;
    print ret " (*next_" name ")" argtype "=tmp_" name ";"> deffile;
    
    print ret " tmp_" name,  argtype "{"                 > tmpffile;
    print "  load_library_symbols();"                   > tmpffile;
    print "  return  next_" name,  argname ";"           > tmpffile;
    print "}"                                           > tmpffile;
    print ""                                            > tmpffile;
  }
}

/^ *$/{
  print > structfile;
  print > headerfile;
  print > deffile;  
  print > tmpffile;
}

END{
  print "  {NULL, NULL}," > structfile;
  print "};"              > structfile;
  print "#endif"          > structfile;
  print "#endif"          > tmpffile;
  print "#endif"          > deffile;
  print "#endif"          > headerfile;
}