加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

linux c代码批量宏展开

发布时间:2020-12-15 07:16:20 所属栏目:安全 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #!/bin/sh#expans all the macro in source fileINCLUDE=""#get all the header files directoryfunction get_include(){for file_t in `ls -l $1|gre

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

#!/bin/sh
#expans all the macro in source file

INCLUDE=""
#get all the header files directory
function get_include()
{
	for file_t in `ls -l $1|grep -E "^d|.([ch]|cpp)$"|awk '{print $8}'`
	do
		if [ -d $1"/"$file_t ] #the file is a dir
		then
			if [ "$file_t" == "include" ]
			then
				INCLUDE=$INCLUDE" -I./"$1"/"$file_t
			else
				get_include $1"/"$file_t
			fi
		fi
	done

	export CFLAGS=$INCLUDE
}

function macro_expansion()
{
	oldpath=$1
	newpath=$2
	if [ ! -d $newpath ]
	then
		mkdir $newpath
	fi

	if [ $? -gt 0 ]
	then
		exit
	fi

	if [ $3 -eq 0 ]
	then
		get_include $oldpath
		echo $CFLAGS
	fi
	
	for file_t in `ls -l $1|grep -E "^d|.([ch]|cpp)$"|awk '{print $8}'`
	do
        oldfile=$oldpath"/"$file_t
        newfile=$newpath"/"$file_t
		if [ -d $oldfile ] #the file is a dir
		then
			./expan_macro $oldfile $newfile 1
		else
			#echo $CFLAGS
			gcc -E $CFLAGS $oldfile -o $newfile 
		fi
	done
}

#Show help when script started without arguments
function showHelp()
{
	echo "Usage: $0 source_dir dst_dir flag(be 0 all the time)"
	echo "example:$0 src dst 0"
}

if [ ! $# -eq 3 ]
then
	showHelp
	exit
fi

macro_expansion $1 $2 $3

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读