chiark / gitweb /
[PATCH] sync with latest version of klibc (0.107)
[elogind.git] / klibc / klibc / syscalls.pl
1 #!/usr/bin/perl
2 ($arch, $file) = @ARGV;
3
4 if (!open(FILE, "< $file")) {
5     print STDERR "$file: $!\n";
6     exit(1);
7 }
8
9 while ( defined($line = <FILE>) ) {
10     chomp $line;
11     $line =~ s/\s*\#.*$//;      # Strip comments and trailing blanks
12     next unless $line;
13
14     if ( $line =~ /^\s*(\<[^\>]+\>\s+|)([^\(\<\>]+[^\@\:A-Za-z0-9_])([A-Za-z0-9_]+)(|\@[A-Za-z0-9_]+)(|\:\:[A-Za-z0-9_]+)\s*\(([^\:\)]*)\)\s*$/ ) {
15         $archs = $1;
16         $type  = $2;
17         $sname = $3;
18         $stype = $4;
19         $fname = $5;
20         $argv  = $6;
21
22         $doit = 1;
23         if ( $archs ne '' ) {
24             die "$0: Internal error"
25                 unless ( $archs =~ /^\<(|\!)([^\>\!]+)\>/ );
26             $not = $1;
27             $list = $2;
28
29             $doit = ($not eq '') ? 0 : 1;
30
31             @list = split(/,/, $list);
32             foreach  $a ( @list ) {
33                 if ( $a eq $arch ) {
34                     $doit = ($not eq '') ? 1 : 0;
35                     last;
36                 }
37             }
38         }
39         next if ( ! $doit );
40
41         $type =~ s/\s*$//;
42
43         $stype =~ s/^\@/_/;
44
45         if ( $fname eq '' ) {
46             $fname = $sname;
47         } else {
48             $fname =~ s/^\:\://;
49         }
50
51         @args = split(/\s*\,\s*/, $argv);
52
53         open(OUT, "> syscalls/${fname}.c")
54             or die "$0: Cannot open syscalls/${fname}.c\n";
55
56         if ( $fname eq "rt_sigaction") {
57             print OUT "#ifdef __x86_64__\n\n";
58             print OUT "struct sigaction;\n\n";
59             print OUT "#endif\n\n"
60         }
61
62         print OUT "#include \"syscommon.h\"\n\n";
63         
64         if ( $fname ne $sname ) {
65             print OUT "#undef __NR_${fname}\n";
66             print OUT "#define __NR_${fname} __NR_${sname}\n\n";
67         }
68
69         print OUT "_syscall", scalar(@args), $stype, "(", $type, ',', $fname;
70
71         $i = 0;
72         foreach $arg ( @args ) {
73             print OUT ",", $arg, ",a",$i++;
74         }
75         print OUT ");\n";
76         close(OUT);
77     } else {
78         print STDERR "$file:$.: Could not parse input\n";
79         exit(1);
80     }
81 }