OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [tools/] [update/] [word-replace.in] - Blame information for rev 847

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
#!@PERL@
2
#
3
#  $Id: word-replace.in,v 1.2 2001-09-27 12:02:54 chris Exp $
4
#
5
 
6
eval "exec @PERL@ -S $0 $*"
7
    if $running_under_some_shell;
8
 
9
require 'getopts.pl';
10
&Getopts("p:vh");               # help, pattern file, verbose,
11
 
12
if ($opt_h || ! $opt_p) {
13
    print STDERR <
14
word-replace
15
 
16
   Replace *words* with patterns.   Pattern file specifies which patterns
17
   to replace on each line.  All patterns are wrapped with perl \\b regexp
18
   specifiers.
19
 
20
Usage: $0       [-v] -p pattern-file files to replace
21
 
22
    -v          -- possibly more verbose
23
    -p file     -- pattern file
24
    -h          -- help
25
 
26
    anything else == this help message
27
 
28
Pattern file looks like this:
29
 
30
# Example:
31
# ignores all lines with beginning with # or not exactly 2 fields
32
_Dorky_Name  rtems_dorky_name           # comments, and blank lines are cool
33
_Dorky_Name2 rtems_dorky_name2          # comments, and blank lines are cool
34
NO_MORE_HELP
35
    exit 0;
36
}
37
 
38
$verbose = $opt_v;
39
$pattern_file = $opt_p;
40
 
41
# make standard outputs unbuffered (so the '.'s come out ok)
42
$oldfh = select(STDERR); $| = 1; select($oldfh);
43
$oldfh = select(STDOUT); $| = 1; select($oldfh);
44
 
45
# pull in the patterns
46
open(PATTERNS, "<$pattern_file") ||
47
    die "could not open $pattern_file: $!, crapped out at";
48
 
49
foreach ()
50
{
51
    chop;
52
    s/#.*//;
53
    next if /^$/;
54
    ($orig, $new, $junk, @rest) = split;
55
    next if ( ! $orig || ! $new || $junk); # <2 or >2 patterns
56
    die "pattern appears 2x: '$orig' in '$pattern_file'--" if defined($patterns{$orig});
57
    $patterns{$orig} = $new;
58
}
59
close PATTERNS;
60
 
61
# walk thru each line in each file
62
foreach $file (@ARGV)
63
{
64
    print "$file\t";
65
 
66
    open (INFILE, "<$file") ||
67
        die "could not open input file $file: $!";
68
 
69
    $outfile = $file . ".fixed";;
70
    open (OUTFILE, ">$outfile") ||
71
        die "could not open output file $outfile: $!";
72
 
73
    while ()
74
    {
75
        study;                  # maybe make s/// faster
76
        foreach $key (keys %patterns)
77
        {
78
            if ( s/\b$key\b/$patterns{$key}/ge )
79
            {
80
                print ".";
81
            }
82
        }
83
        print OUTFILE $_;
84
    }
85
    print "\n";
86
    close INFILE;
87
    close OUTFILE;
88
}
89
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.