summaryrefslogtreecommitdiff
path: root/fixpaths
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2002-12-05 20:59:33 +1100
committerDamien Miller <djm@mindrot.org>2002-12-05 20:59:33 +1100
commitab1c12a11c0c05223405a814d39281b5b0b9b712 (patch)
tree029b70174bad312c5585237fb463483c4c7e9468 /fixpaths
parent1c9e688548a0f47fcfe41de43625f5b8a7d500dd (diff)
- (djm) PERL-free fixpaths from stuge-openssh-unix-dev@cdy.org
Diffstat (limited to 'fixpaths')
-rwxr-xr-xfixpaths49
1 files changed, 14 insertions, 35 deletions
diff --git a/fixpaths b/fixpaths
index 7e4178e4a..60a67990f 100755
--- a/fixpaths
+++ b/fixpaths
@@ -1,43 +1,22 @@
1#!/usr/bin/perl -w 1#!/bin/sh
2# 2#
3# fixpaths - substitute makefile variables into text files 3# fixpaths - substitute makefile variables into text files
4# Usage: fixpaths -Dsomething=somethingelse ...
4 5
5 6die() {
6$usage = "Usage: $0 [-Dstring=replacement] [[infile] ...]\n"; 7 echo $*
7 8 exit -1
8if (!defined(@ARGV)) { die ("$usage"); }
9
10# read in the command line and get some definitions
11while ($_=$ARGV[0], /^-/) {
12 if (/^-D/) {
13 # definition
14 shift(@ARGV);
15 if ( /-D(.*)=(.*)/ ) {
16 $def{"$1"}=$2;
17 } else {
18 die ("$usage$0: error in command line arguments.\n");
19 }
20 } else {
21 @cmd = split(//, $ARGV[0]); $opt = $cmd[1];
22 die ("$usage$0: unknown option '-$opt'\n");
23 }
24} # while parsing arguments
25
26if (!defined(%def)) {
27 die ("$0: nothing to do - no substitutions listed!\n");
28} 9}
29 10
30for $f (@ARGV) { 11test -n "`echo $1|grep -- -D`" || \
12 die $0: nothing to do - no substitutions listed!
13
14test -n "`echo $1|grep -- '-D[^=]\+=[^ ]\+'`" || \
15 die $0: error in command line arguments.
31 16
32 $f =~ /(.*\/)*(.*)$/; 17test -n "`echo $*|grep -- ' [^-]'`" || \
18 die Usage: $0 '[-Dstring=replacement] [[infile] ...]'
33 19
34 open(IN, "<$f") || die ("$0: input file $f missing!\n"); 20sed `echo $*|sed -e 's/-D\([^=]\+\)=\([^ ]*\)/-e s=\1=\2=g/g'`
35 while (<IN>) {
36 for $s (keys(%def)) {
37 s#$s#$def{$s}#;
38 } # for $s
39 print;
40 } # while <IN>
41} # for $f
42 21
43exit 0; 22exit 0