#!/bin/sh # Read .java files in source directory, # copying lines from the first line matching # the start pattern to the end of the file # to a file of the same name in the target directory # # Designed to be used to remove license header and imports from # annotation, enum, and other java files in the JDO api project # for import into the FrameMaker specification # # Tested on cygwin, Linux, and Mac # USAGE="behead " if [ $# -ne 2 ] then echo $USAGE exit -1 fi SRCDIR=$1 TARGETDIR=$2 for FILE in `ls $SRCDIR/*.java` do ROOT=`basename $FILE .java` OUTFILE=${TARGETDIR}/${ROOT}.txt # get appropriate start point for this file type if [ `grep -c "public enum" $FILE` -gt 0 ] then STARTPATTERN="public enum" elif [ `grep -c "public class" $FILE` -gt 0 ] then STARTPATTERN="public class" elif [ `grep -c "public interface" $FILE` -gt 0 ] then STARTPATTERN="public interface" elif [ `grep -c "^@" $FILE` -gt 0 ] then STARTPATTERN="^@" else echo "Warning: no start point found for copying lines from $FILE" continue fi STARTINDEX=`grep --max-count=1 -n "${STARTPATTERN}" $FILE | cut -d: -f1 ` ENDINDEX=`wc -l $FILE | sed -e "s/^ *//" | cut -f1 -d" " ` NUMLINES=`expr $ENDINDEX - $STARTINDEX + 1` echo Copying ${NUMLINES} lines from $FILE to $OUTFILE # Workaround for Frame bug: Add blank line at beginning tail -n ${NUMLINES} $FILE | sed -e "1H" -e "1g" > ${OUTFILE} done