#! /usr/bin/perl -w my $KERNEL_SOURCE_ROOT='/usr/src/linux-2.4.22/'; my $LOCAL_DIFF_DIR='/usr/src/linux-2.4.22-patched/'; local *BASE_TYPOS_FILE; my @word_list=(); open(BASE_TYPOS_FILE,'typos.base') || die("Can't find typo-list file\n"); while(my $word=) { $word =~ s/\r|\n//g; push @word_list,$word; } close(BASE_TYPOS_FILE); foreach my $word (@word_list) { my ($word,$replace,$comment)=split(/\|/,$word,3); if (!$comment) {$comment='';}; if ($word) { if ($word =~ m/^#+([^#]*)$/) { if ($comment) { print "'$1' => '$replace' ignored : $comment\n"; } } else { my $match=`egrep -r "$word" "$KERNEL_SOURCE_ROOT"`; if ($match) { print "'$word' => '$replace' : $comment\n"; foreach my $line (split/\n/,$match) { my ($matched_file,$matched_line)=split(/:/,$line,2); if ($matched_file =~ m/^$KERNEL_SOURCE_ROOT(.*)/) { $matched_file=$1; print "$matched_file\n"; my ($matched_dir,$matched_file)=($matched_file =~ m/^(.*\/)([^\/]+)$/); if (! -f "$LOCAL_DIFF_DIR/$matched_dir/$matched_file") { # Creating local dir : `mkdir -p "$LOCAL_DIFF_DIR/$matched_dir"`; # File has not been patched at all, copying it localy : `cp "$KERNEL_SOURCE_ROOT/$matched_dir/$matched_file" "$LOCAL_DIFF_DIR/$matched_dir/$matched_file"`; } local *FILE_TO_PATCH; local *PATCHED_FILE; open(FILE_TO_PATCH,"$LOCAL_DIFF_DIR/$matched_dir/$matched_file") || die("Can't open '$LOCAL_DIFF_DIR/$matched_dir/$matched_file' (file to patch)\n"); open(PATCHED_FILE,">$LOCAL_DIFF_DIR/$matched_dir/$matched_file.typodiff") || die("Can't write '$LOCAL_DIFF_DIR/$matched_dir/$matched_file.typodiff' (patched file)\n"); while(my $line=) { if ($line) { if ($replace =~ m/[^\\]?\$1/) { while($line =~ m/$word/) { my $tmp=$1; if ($tmp) { my $tmp_replace=$replace; $tmp_replace =~ s/([^\\]?)\$1/$1$tmp/; print " . $replace => $tmp_replace\n"; $line =~ s/$word/$tmp_replace/; } } } else { $line =~ s/$word/$replace/g; } } print PATCHED_FILE $line; } close(PATCHED_FILE); close(FILE_TO_PATCH); # Replace original by diffed file : `mv "$LOCAL_DIFF_DIR/$matched_dir/$matched_file.typodiff" "$LOCAL_DIFF_DIR/$matched_dir/$matched_file"`; } } } print "-----------------------------------------------\n"; } } } # diff -ur /usr/src/linux-2.4.22/ ./diff/ # Copyright \(c\)|Copyright (C)