backscratcher

 

summarize

Page history last edited by tbarron 1 yr ago

summarize

 


#!/usr/bin/perl
# ===========================================================================
# summarize
#
# @(#) scan a file and ignore uninteresting stuff
#
# Syntax:
#   summary --uninteresting <filename> <infile1> <infile2> ...
#
# History:
#   2006-07-19    tpb    created
#
# ===========================================================================
=head1 NAME

summarize - scan a file and ignore uninteresting stuff

=head1 SYNOPSIS

 summary --uninteresting <filename> <infile1> <infile2> ...

=head1 DESCRIPTION

This program applies Marcus Ranum's "Artificial Ignorance" technique
to an arbitrary list of files. (Ranum, 1997)

The list of "uninteresting" regular expressions to be ignored are read
from <filename> and then applied to each of the input files in turn.

=head1 REFERENCES

Ranum, M. (1997). artificial ignorance: how-to guide. Retrieved
2006-07-19 from http://www.ranum.com/security/computer_security/index.html.

=cut

# ===========================================================================
use strict;
use Getopt::Long;

# ===========================================================================
sub main
{
   my ($filename, $in, @uninteresting);

   GetOptions("-uninteresting=s" => $filename);

   @uninteresting = contents($filename);

   foreach $in (@ARGV)
   {
      summarize(@uninteresting, $in);
   }
}

# ===========================================================================
sub contents
{
   my ($filename, $line, @rval);

   ($filename) = @_;

   open(IN, "< $filename");
   while ($line = <IN>)
   {
      chomp($line);
      push(@rval, $line);
   }
   close(IN);

   return @rval;
}

# ===========================================================================
sub ignore
{
   my ($ignore, $ignref, $line, $rgx);

   ($ignref, $line) = @_;

   $ignore = 0;
   foreach $rgx (@{$ignref})
   {
      if ($line =~ /$rgx/)
      {
         $ignore = 1;
         last;
      }
   }

   return $ignore;
}

# ===========================================================================
{
   my @ignoreList;
   my $ignoreListDefined;

# ---------------------------------------------------------------------------
sub register_ignorable
{
   push(@ignoreList, @_);
   $ignoreListDefined = 1;
}
}

# ===========================================================================
sub summarize
{
   my ($filename, $ignore, $ignref, $line, $rgx);

   ($ignref, $filename) = @_;

   open(IN, "< $filename");
   while ($line = <IN>)
   {
      print("$line") if (!ignore($ignref, $line));
   }
   close(IN);
}

# ===========================================================================
main();

Comments (0)

You don't have permission to comment on this page.