#!/usr/bin/perl

use strict;
use warnings;

while (<>) {
    if (m:^(.*\w_PROC.*\s=\s\d+,?)(.*)$:) {
        my $enum = $1;
        my $params = $2;

        die "cannot parse $params" unless
            $params =~ m,/\*\s*(autogen|skipgen)\s+(autogen|skipgen)\s+(?:priority:(low|high))?(?:\| ((?:read|write)stream)\@(\d+))?\s*\*/,;

        my $genserver = $1;
        my $genclient = $2;
        my $priority = $3;
        my $stream = $4;
        my $paramnum = $5;

        my $generate;
        if ($genserver eq "autogen" &&
            $genclient eq "autogen") {
            $generate = "both";
        } elsif ($genserver eq "autogen") {
            $generate = "server";
        } elsif ($genclient eq "autogen") {
            $generate = "client";
        } else {
            $generate = "none";
        }

        print "    /**\n";
        print "     * \@generate: $generate\n";
        if (defined $priority) {
            print "     * \@priority: $priority\n";
        }
        if (defined $stream) {
            print "     * \@$stream: $paramnum\n";
        }
        print "     */\n";
        print "$enum\n";
        if ($enum =~ /0,?\s*$/) {
            print "\n\n";
        }
    } else {
        print;
    }
}
