cscope 질문

badcodek의 이미지

안녕하세요, 현재 cscope 사용을 위해
find . \( -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.s' -o -name '*.S' \) > cscope.files
를 쓰는데요,
c 파일의 경우 해당 파일명의 o 파일이 있을때만 추가되도록 하는 스크립트 없을까요??

ymir의 이미지

대충 이런식으로 하면 되지 않을까 하네요...

#!/bin/bash
 
[ $# -eq 0 ] && TARGET=. || TARGET=$@
 
lookup_file()
{
	case "$1" in
	*.c)
		if [ -f ${1/%.c/.o} ] ; then
			echo $1
		fi
		;;
	*.cpp|*.cc|*.h|*.[sS])
		echo $1
		;;
	esac
}
 
lookup_dir()
{
	if [ -d $1 ] ; then
		for file in $1/*
		do
			if [ -d $file ] ; then
				lookup_dir $file
			elif [ -f $file ] ; then
				lookup_file $file
			fi		
		done
	elif [ -f $1 ] ; then
		lookup_file $file
	fi
}
 
lookup_dirs()
{
	until [ -z "$1" ]
	do
		lookup_dir ${1/%\//}
		shift
	done
}
 
lookup_dirs ${TARGET}
 
exit 0;

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

badcodek의 이미지

--

ymir의 이미지

생각나는 대로 대충 돌려봤을때는 잘 몰랐는데 파일이 많은 경우에는 많이 느리군요.
그냥 find 로 임시파일에 저장한 후에 그걸 읽어서 처리하는게 더 빠르네요. (대략 5~10배 정도)

$ find . -type f -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.s' -o -name '*.S' > cscope.tmp && while read -r line; do if [[ $line == *.c ]] ; then [ -f ${line/%.c/.o} ] && echo $line; else echo $line; fi; done < cscope.tmp > cscope.files

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』