#!/bin/sh

#  Copyright (C) 2000 artofcode LLC.  All rights reserved.
#
#  This file is part of GNU Ghostscript.
# 
#  GNU Ghostscript is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
#  to anyone for the consequences of using it or for whether it serves any
#  particular purpose or works at all, unless he says so in writing.  Refer
#  to the GNU General Public License for full details.
# 
#  Everyone is granted permission to copy, modify and redistribute GNU
#  Ghostscript, but only under the conditions described in the GNU General
#  Public License.  A copy of this license is supposed to have been given
#  to you along with GNU Ghostscript so you can know your rights and
#  responsibilities.  It should be in a file named COPYING.  Among other
#  things, the copyright notice and this notice must be preserved on all
#  copies.

# $Id: gsindent,v 1.3.2.1 2001/11/02 23:05:44 giles Exp $

# This script formats C source code per the Ghostscript C style guide.
# The perl invocations work around a bug in GNU indent.

if [ $# -ne 0 ]; then
    for f in $*
    do
	$0 < $f > /tmp/$$
	cp -p $f $f.bak
	if ( test ! -e $f~ ) then cp -p $f $f~; fi
	mv /tmp/$$ $f
    done
    exit
fi
exec \
perl -pe 's{(#.*/\*)(\*.*)}{$1&$2}' | \
indent \
--blank-lines-after-declarations \
--no-blank-lines-after-procedures \
--leave-optional-blank-lines \
--braces-on-if-line \
--indent-level4 \
--case-indentation4 \
--no-space-after-function-call-names \
--dont-star-comments \
--declaration-indentation0 \
--procnames-start-lines \
--continue-at-parentheses \
--cuddle-else \
--no-space-after-casts \
--leave-preprocessor-space \
- | \
perl -pe 's{(#.*/\*)&(\*.*)}{$1$2}'
