head     1.1;
branch   ;
access   ;
symbols  ;
locks    bin:1.1;
comment  @# @;


1.1
date     93.08.10.12.37.31;  author bin;  state Exp;
branches ;
next     ;


desc
@@



1.1
log
@Initial revision
@
text
@# cohtune - change a system initializer.

CMD=$0
ARGS=$*

CONF=${CONF-/etc/conf}

usage() {
	echo "Usage: [CONF=conf-dir] $CMD device [ tag new-text ] ..."
	echo "	Modify Space.c for the given device."
	echo "	Replace the line containing tag (not in comments) by new-text."
	echo "	Fail if there is not a unique line matching tag."
	exit 1
}

# tagline(file, tag) reports the line number in file which contains tag

tagline() {

	# LNO is list of matching line numbers
	LNO=`/bin/cgrep -n $2 < $1 | /bin/sed -e "s/:.*//" \
	  -e "s/^[ 	]*//"`

	# LCOUNT is number of matching line numbers
	LCOUNT=`/bin/echo $LNO | wc -w`

	if [ $LCOUNT -ne 1 ]; then
		echo "$CMD $ARGS:  Found $LCOUNT matches for $TAG, wanted 1."
		exit 1
	fi
}

# Need at lease three args.
if  [ $# -lt 3 ]
then
	usage
fi

DEVICE=$1

SPACE_FILE=$CONF/$DEVICE/Space.c

# Need conf/device/Space.c file.
if [ ! -f $SPACE_FILE ]
then
	echo "Can't find $SPACE_FILE"
	exit 1
fi

shift
while [ $# -gt 1 ]
do
	TAG=$1
	shift
	tagline $SPACE_FILE $TAG
	NEW_TEXT=$1
	shift

# Do replacement.

/bin/ed - +v $SPACE_FILE <<_EOF
$LNO
c
$NEW_TEXT
.
p
wq
_EOF

done
@
