#!/usr/bin/perl

my $in_if = 0;

while(<STDIN>)
{
  chomp;

  if($_ =~ /^type_/ or $_ =~ /^allow.*process.transition/)
  {
    next;
  }
  if($in_if > 0 and $_ =~ /^}/)
  {
    if(not $_ =~ /else/)
    {
      $in_if--;
    }
    next;
  }
  if($_ =~ /^if/)
  {
    $in_if++;
    next;
  }

  if($_ =~ /^type .*domain/ && not $_ =~ /^type unconfined_t/)
  {
    $_ =~ s/^type //;
    $_ =~ s/,.*$//;
    print "typealias unconfined_t alias $_;\n";
    next;
  }
  if($_ =~ /^type .*file_type/ && not $_ =~ /^type device_t/)
  {
    $_ =~ s/^type //;
    $_ =~ s/,.*$//;
    print "typealias device_t alias $_;\n";
    next;
  }
  if($_ =~ /^type .*device_type/ && not $_ =~ /^type null_device_t/)
  {
    $_ =~ s/^type //;
    $_ =~ s/,.*$//;
    print "typealias null_device_t alias $_;\n";
    next;
  }
  if($_ =~ /^type .*port_type/ && not $_ =~ /^type xserver_port_t/)
  {
    $_ =~ s/^type //;
    $_ =~ s/,.*$//;
    print "typealias xserver_port_t alias $_;\n";
    next;
  }
  if($_ =~ /^type .*sysctl_type/ && not $_ =~ /^type sysctl_t/)
  {
    $_ =~ s/^type //;
    $_ =~ s/,.*$//;
    print "typealias sysctl_t alias $_;\n";
    next;
  }
  print "$_\n";
}
