[go: up one dir, main page]

Menu

[2a4c1e]: / helper  Maximize  Restore  History

Download this file

125 lines (114 with data), 2.8 kB

#!/bin/bash

source ~/.develrc
projectPath=${OOOARK}
projectName=oooark

function usage {
cat << EOF
Options:
	c
		create a new class
	d
		generate doxygen documentation
	f
		format source code
	r
		refactor
	t
		generate tags for stl, project libraries, and local code
	u
		display usage
	v
		view documentation	
	x
		make a distribution
Examples:
	Format all of the source code: 
		$0 -f
EOF
}

if [ $# == 0 ]
then
	usage
fi

while getopts "c:difrtun:p:vx" opt; do
	case ${opt} in
		c) class=${OPTARG} 
			echo helper: creating class ${class}		
			if ! ( test $firstName ) ; then echo first name:; read firstName; fi
			if ! ( test $lastName ) ; then echo last name:; read lastName; fi
			if ! ( test $email ); then echo email:; read email; fi
			echo namespace:; read namespace
			year=$(date +%G)
			cp ${projectPath}/templates/template.cpp ${class}.cpp
			cp ${projectPath}/templates/template.hpp ${class}.hpp
			find . -regex ".*${class}.\(cpp\|hpp\)" \
			-exec sed -i "
			s/@CLASS@/${class}/g; 
			s/@FIRSTNAME@/${firstName}/g;
			s/@LASTNAME@/${lastName}/g;
			s/@EMAIL@/${email}/g;
			s/@YEAR@/${year}/g;
			s/@NAMESPACE@/${namespace}/g;" {} \;
			;;
		d) echo helper: generating doxygen documentaion
			doxygen ${projectPath}/doc/Doxyfile
			;;
		f) echo helper: formatting source code
			astyle --style=ansi $(find . -regex '.*\.\(cpp\|c\|cc\|h\|hpp\)')
			rm -f $(find . -regex '.*\.orig')
			;;
		r) echo helper: refactoring
			echo -n "original name: "; read orig
			echo -n "new name: "; read new
			find . -regex '.*\.\(cpp\|c\|cc\|h\|hpp\|.am\)' \
				-exec sed -i "s|$orig|$new|g" {} \;
			find . -regex '.*CMake.*' \
				-exec sed -i "s|$orig|$new|g" {} \;

			;;
		t) echo helper: generating tags
			vimrc=~/.vimrc
			tagFile="~/.vim/tags/${projectPath}Tags"

			# Create the directory
			if [ -f ~/.vim/tags ] 
			then
				rm ~/.vim/tags
			fi
			mkdir -p ~/.vim/tags

			# Generate the tags
			ctags -RV --language-force=C++ --c++-kinds=+p --fields=+iaS \
				--extra=+q -f ~/.vim/tags/${projectName}Tags \
				/usr/include/qt4/* \
				/usr/include/pango* \
				/usr/include/gtk* \
				/usr/include/cairo* \
				/usr/include/boost/numeric \
				/usr/include/boost/asio \
				/usr/include/osg* \
				/usr/include/Serial* \
				/usr/include/JSBSim

			ctags -RV --c++-kinds=+p --fields=+iaS \
				--extra=+q -f ${projectPath}/tags \
				${projectPath} 

			# Add tags to .vimrc
			if grep -q "set tags+=$tagFile" $vimrc; then
				echo "Tags found in .vimrc"
			else
				echo "set tags+=$tagFile" >> $vimrc
				echo "I added them to .vimrc"
			fi
			;;
		u) usage
			;;
		v) echo helper: viewing documentation
			firefox ${ath}/doc/html/index.html
			;;
		x) echo helper: packaing a distribution
			git clean -dxf
			./autogen.sh
			make distcheck
			;;
		?) usage
			;;
	esac
done

# vim:ts=4:sw=4