#!/bin/sh
# $Id: expand4,v 1.1 2000/03/31 23:00:01 dmetz Exp $
# crtd:  by  Derald Metzger  on  921120 $
# cmnt:  expand (untabify) a file using 4 spaces to replace each tab.
#                  Copyright (c) 1998, 1999 2000  Derald Metzger 
#   This file is part of the cfm pkg (GPL).
# $

tab_size=4  # Default tab size

usage="
usage:
  expand4 [-t <tabsize>] <file ...>

  expand4 is a wrapper for the unix expand cmd used to expand tabs
  to spaces. It defaults to 4 spaces per tab. expand4 will do 
  multiple files. Unlike the expand cmd it will also preserve the
  mode of the files.
"

while getopts t: c
do
  case $c in
    t) tab_size=$OPTARG ;;
    \?) $echo "$usage"; exit 2; ;;
  esac
done
shift `expr $OPTIND - 1`

if [ $# -lt 1 ]; then echo "### $base: insufficient args $usage"; exit 1; fi

for i
do
  mode=`stat $i|grep "Mode: ("|cut -d"(" -f2|cut -d/ -f1`
  base=`basename $i`
  expand -$tab_size $i >/tmp/${base}_$$
  mv /tmp/${base}_$$ $i
  chmod $mode $i
done
