github.com/hbdrawn/golang@v0.0.0-20141214014649-6b835209aba2/src/syscall/mksysnum_linux.pl (about)

     1  #!/usr/bin/env perl
     2  # Copyright 2009 The Go Authors. All rights reserved.
     3  # Use of this source code is governed by a BSD-style
     4  # license that can be found in the LICENSE file.
     5  
     6  use strict;
     7  
     8  my $command = "mksysnum_linux.pl ". join(' ', @ARGV);
     9  
    10  print <<EOF;
    11  // $command
    12  // MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT
    13  
    14  package syscall
    15  
    16  const(
    17  EOF
    18  
    19  sub fmt {
    20  	my ($name, $num) = @_;
    21  	$name =~ y/a-z/A-Z/;
    22  	print "	SYS_$name = $num;\n";
    23  }
    24  
    25  my $prev;
    26  while(<>){
    27  	if(/^#define __NR_(\w+)\s+([0-9]+)/){
    28  		$prev = $2;
    29  		fmt($1, $2);
    30  	}
    31  	elsif(/^#define __NR_(\w+)\s+\(\w+\+\s*([0-9]+)\)/){
    32  		fmt($1, $prev+$2)
    33  	}
    34  }
    35  
    36  print <<EOF;
    37  )
    38  EOF