package modules::parameters; # $Id: parameters.pm,v 1.3 2003/02/03 11:36:55 prigaux Exp $







use common;
use modules;


sub parameters {
  my ($module) = @_;

  if (!$::isStandalone && !$::testing) {
      modules::extract_modules('/tmp', $module);
      $module = "/tmp/$module.o";
  }

  my @parameters;
  foreach (common::join_lines(run_program::get_stdout('modinfo', '-p', $module))) {
      chomp;
      next if /^warning:/;
      (my $name, $_) = /(\S+)\s+(.*)/s or warn "modules::parameters::get_options_name($module): unknown line\n";

      my $c_types = 'int|string|short|byte|char|long';
      my ($is_a_number, $description, $min, $max) = (0, '', 1, 1);
      if (/^($c_types) array \(min = (\d+), max = (\d+)\),?\s*(.*)/s) {
	  $_ = $4;
	  
	  ($is_a_number, $min, $max) = ($1 ne 'string', $2, $3) if $1 ne 'char'; 
      } elsif (/^($c_types),?\s*(.*)/s) {
	  $_ = $2;
	  
	  $is_a_number = $1 ne 'string' if $1 ne 'char';
      } else {
	  
      }
      if (/^description "(.*)",?\s*/s) {
	  ($description, $_) = ($1, $2);
      }
      

	 my $format = $min == 1 && $max == 1 ?
		($is_a_number ? N("a number") : '') :
		$min == $max ? 
		($is_a_number ? N("%d comma separated numbers", $min) : N("%d comma separated strings", $min)) :
		$min == 1 ?
		($is_a_number ? N("comma separated numbers") : N("comma separated strings")) :
		''; 
    push @parameters, [ $name, $format, $description ];
  }
  @parameters;
}

1;
