What follows is given into the public domain
by the author, Philip Campbell, October 30, 1998.
On my system, it's /usr/local/bin/number.diald.rules.

#!/usr/bin/perl

$show_all_lines = 1;  # 0 to output only rules.

$location_of_diald_conf = '/etc';
$name_of_diald_conf = 'diald.conf';
$number_of_digits = 2;  # For rule numbers.

$pattern_to_get_diald_filter_locations_from_diald_conf = '.*filter';

@filter_files = &form_list_of_filter_files;

# You could start here with
# @filter_files = ("path to your filter file");

&count_through_list_of_filter_files(@filter_files);
# Done.  Output has erupted from STDOUT.


sub count_through_list_of_filter_files {
  local (@filter_files, $indent, $rule) = @_;
  $indent = " " x ($number_of_digits + 1);
  while ($#filter_files > -1) {
    $_ = shift(@filter_files);
    # print "$_\n";
    open(FILTER, $_) || die("Can't open filter\n\t$_\n\t");
    while (!eof(FILTER)) {
      $_ = <FILTER>;
      if (&its_a_rule($_)) {
        $rule += 1;
        printf "%${number_of_digits}d %s", $rule, $_; }
      elsif ($show_all_lines) { print $indent, $_; } }
    close(FILTER); } }

sub form_list_of_filter_files {
  local ($path_to_diald_conf, @filter_files);
  $path_to_diald_conf = "$location_of_diald_conf/$name_of_diald_conf";
  open(DIALD_CONF, "$path_to_diald_conf")
   || die("Can't open diald.conf: $path_to_diald_conf\n\t");
  while (!eof(DIALD_CONF)) {
    $_ = <DIALD_CONF>;
    # print "$_\n";
    next unless
(/$pattern_to_get_diald_filter_locations_from_diald_conf/io);
    next if (/^#/);
    next unless (s/^include //io);
    s/\s+$//o;
    next if (/\s/o);
    # print "$_\n";
    push (@filter_files, $_); }
  close(DIALD_CONF);
  if ($#filter_files < 0) { die("Can't find filter file names"
   . "\n\tin $path_to_diald_conf\n\t"); }
  @filter_files; }

sub its_a_rule {
  local ($_, $count_it) = @_;
  $count_it = 1;  # This line is a rule.
  if (/^#/o) { $count_it = 0; }  # Not a rule.
  if (/^\s*$/o) { $count_it = 0; }  # Not a rule.
  $count_it; }



-
To unsubscribe from this list: send the line "unsubscribe linux-diald" in
the body of a message to [EMAIL PROTECTED]

Reply via email to