source: rtems/doc/tools/word-replace2 @ 14228b6c

Last change on this file since 14228b6c was a65194b, checked in by Joel Sherrill <joel.sherrill@…>, on 05/01/00 at 16:59:15

Removed file rendered obsolete by rtemsdoc-4.5.0-rc-3.diff from
Ralf Corsepius <corsepiu@…>.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#!/usr/bin/perl
2#
3#  $Id$
4#
5
6eval "exec /usr/local/bin/perl -S $0 $*"
7    if $running_under_some_shell;
8
9require 'getopts.pl';
10&Getopts("p:vh");               # help, pattern file, verbose,
11
12if ($opt_h || ! $opt_p) {
13    print STDERR <<NO_MORE_HELP;
14word-replace2
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
20Usage: $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
28Pattern 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
34NO_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
46open(PATTERNS, "<$pattern_file") ||
47    die "could not open $pattern_file: $!, crapped out at";
48
49
50
51foreach (<PATTERNS>)
52{
53    chop;
54    s/#.*//;
55    next if /^$/;
56    ($orig, $new, $junk, @rest) = split;
57    next if ( ! $orig || ! $new || $junk); # <2 or >2 patterns
58    die "pattern appears 2x: '$orig' in '$pattern_file'--" if defined($patterns{$orig});
59    $patterns{$orig} = $new;
60}
61close PATTERNS;
62# walk thru each line in each file
63
64$infile = '-' ;
65$outfile = '-' ;
66
67if ( $#ARGV > -1 )
68{
69  $infile = "@ARGV[0]" ;
70  shift @ARGV ;
71}
72
73if ( $#ARGV > -1 )
74{
75  $outfile = "@ARGV[0]" ;
76  shift @ARGV ;
77}
78
79open (INFILE, "<$infile") ||
80        die "could not open input file $infile: $!";
81$line = join('',<INFILE>) ;
82close INFILE;
83
84
85print STDERR "$outfile\t";
86
87open (OUTFILE, ">$outfile") ||
88        die "could not open output file $outfile: $!";
89
90foreach $key (keys %patterns)
91{
92  if ( $line =~ s/\b$key\b/$patterns{$key}/ge )
93  {
94    print STDERR "." ;
95  }
96}
97
98print OUTFILE $line ;
99
100print STDERR "\n";
101close OUTFILE;
Note: See TracBrowser for help on using the repository browser.