#!/bin/perl #==============================================================================# package CFILTER; #==============================================================================# #------------------------------------------------------------------------------# sub new { #------------------------------------------------------------------------------# my ($class, @data) = @_; my $ref = {}; bless $ref, $class; CFILTER::init($ref,@data); return $ref; } #------------------------------------------------------------------------------# sub init { #------------------------------------------------------------------------------# my ($ref,@data) = @_; %$ref = (%$ref, "comment", "", "nline", ""); if(@data) { %$ref = (%$ref, @data);}; } #------------------------------------------------------------------------------# sub cfilter { #------------------------------------------------------------------------------# my ($ref, @lines) = @_; my @olines = (); my $i; for($i=0;$i<=$#lines;$i++) { my @as = split('',$lines[$i]); my $j; for($j=0;$j<=$#as;$j++) { if($as[$j] eq '\\') { $$ref{'nline'} .= $as[$j].$as[$j +1]; $j++; } elsif($$ref{'comment'} eq '"') { $$ref{'nline'} .= $as[$j]; if($as[$j] eq '"') { $$ref{'comment'} = ""; } } elsif(($$ref{'comment'} eq "\n")&&($as[$j] eq "\n")) { $$ref{'nline'} .= $as[$j]; $$ref{'comment'} = ""; } elsif(($$ref{'comment'} eq "*/") &&($as[$j] eq '*')&&($as[$j +1] eq '/')) { $j++; $$ref{'comment'} = ""; } elsif($$ref{'comment'}) { } elsif($as[$j] eq "\"") { $$ref{'nline'} .= $as[$j]; $$ref{'comment'} = "\""; } elsif(($as[$j] eq '/')&&($as[$j +1] eq '*')) { $j++; $$ref{'comment'}="*/"; } elsif(($as[$j] eq '/')&&($as[$j +1] eq '/')) { $j++; $$ref{'comment'}="\n"; } else { $$ref{'nline'} .= $as[$j]; } } if($$ref{'nline'}) { push(@olines,$$ref{'nline'}); $$ref{'nline'} = ""; } } @olines; } 1;