#!/usr/bin/perl

if($#ARGV==-1){
    print qx{ls /usr/include | grep -P "\.h\$"};
}
elsif($#ARGV==0){
    $cont=0;
    $file = shift @ARGV;
    @file = qx(cat /usr/include/$file);
    for (@file){
        if(/\/\*(.*)/){
            if(/\/\*(.*)\*\//){
                $comments[$cont]=$1;
                $cont++;
                next;
            }
            $comments[$cont]=$1;
            $inComm=1;
        }
        elsif($inComm==1){
            if(/(.*)\*\//){
                $inComm=0;
                $comments[$cont] .= $1;
                $cont++;
            }
            else{
               $comments[$cont] .= $_; 
            }
        }
    }
    print join "\n",sort({length $b <=> length $a || $a cmp $b} @comments);
=pod
    for(sort({length $b <=> length $a || $a cmp $b} @comments)){
        print $_."\n";
    }
=cut
}
else{
    die "troppi parametri";
}