Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | # |
| 3 | # fixpaths - substitute makefile variables into text files |
| 4 | |
| 5 | |
Damien Miller | 886c63a | 2000-01-20 23:13:36 +1100 | [diff] [blame] | 6 | $usage = "Usage: $0 [-x<file dot-suffix>] [-Dstring=replacement] [[infile] ...]\n"; |
| 7 | |
| 8 | $ext="out"; |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 9 | |
| 10 | if (!defined(@ARGV)) { die ("$usage"); } |
| 11 | |
| 12 | # read in the command line and get some definitions |
| 13 | while ($_=$ARGV[0], /^-/) { |
Damien Miller | 886c63a | 2000-01-20 23:13:36 +1100 | [diff] [blame] | 14 | if (/^-[Dx]/) { |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 15 | # definition |
| 16 | shift(@ARGV); |
| 17 | if ( /-D(.*)=(.*)/ ) { |
| 18 | $def{"$1"}=$2; |
Damien Miller | 886c63a | 2000-01-20 23:13:36 +1100 | [diff] [blame] | 19 | } elsif ( /-x\s*(\w+)/ ) { |
| 20 | $ext=$1; |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 21 | } else { |
| 22 | die ("$usage$0: error in command line arguments.\n"); |
| 23 | } |
| 24 | } else { |
Damien Miller | 3ef692a | 2000-04-20 07:33:24 +1000 | [diff] [blame] | 25 | @cmd = split(//, $ARGV[0]); $opt = $cmd[1]; |
| 26 | die ("$usage$0: unknown option '-$opt'\n"); |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 27 | } |
| 28 | } # while parsing arguments |
| 29 | |
| 30 | if (!defined(%def)) { |
| 31 | die ("$0: nothing to do - no substitutions listed!\n"); |
| 32 | } |
| 33 | |
| 34 | for $f (@ARGV) { |
| 35 | |
| 36 | $f =~ /(.*\/)*(.*)$/; |
Damien Miller | 886c63a | 2000-01-20 23:13:36 +1100 | [diff] [blame] | 37 | $of = $2.".$ext"; |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 38 | |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 39 | open(IN, "<$f") || die ("$0: input file $f missing!\n"); |
Ben Lindstrom | dbcea87 | 2000-11-08 01:07:51 +0000 | [diff] [blame] | 40 | open(OUT, ">$of") || die ("$0: cannot create output file $of: $!\n"); |
| 41 | while (<IN>) { |
| 42 | for $s (keys(%def)) { |
| 43 | s#$s#$def{$s}#; |
| 44 | } # for $s |
| 45 | print OUT; |
| 46 | } # while <IN> |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 47 | } # for $f |
| 48 | |
| 49 | exit 0; |