VC驿站

 找回密码
 加入驿站

QQ登录

只需一步,快速开始

搜索
查看: 856|回复: 0

[分享] 替换宏

[复制链接]
29_avatar_middle
在线会员 发表于 2015-11-23 16:18:36 | 显示全部楼层 |阅读模式
源码信息
源代码类型: 算法相关
源代码作者: -
编译器版本: 其他版本或编译器
代码注释: 部分注释
数据库种类:
预览图片: -
源代码简介: -
##########################################################################################
#         All copyright reserved!!
#Author     : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Date       : 2012-09-14
#Description: Go to the requaired path recursively replacing your log function with given
#             macro "SMAPS_DEBUG_LOGMSG".
#             Enjoy it!!!
#History    : 2012_09_14 just complete Ver0.01
##########################################################################################
##########################################################################################
# function definition part
##########################################################################################
PrintHintYN()
{
    echo 'Please make sure the following two points before you run this script'
    echo '(1) This script has 'x' athority.'
    echo '(2) Usage: Logmsg_replace.sh Key_word Module_name Execute_dir'
    echo 'Example ./logmsg_replace.sh MEM_DEBUG CID_FBM ~/src/smaps_core/memory_manager'
    echo 'Are you sure now?[y/n]'
}

IsYourLogFunc()
{
    GREP_RESULT=`grep -w -l "$2" $1`
    if [ -z "${GREP_RESULT}" ] ; then
        echo "0";
    else
        echo "1";
    fi
}
##########################################################################################
# main process part
##########################################################################################
#Show the hint
PrintHintYN
read VAR_YN
case $VAR_YN in
    n|N     ) exit 0
              ;;
    y|Y     ) echo "Execution time starts at `date`"
              echo '------------------------------------------------------------------'
              ;;
    *       ) exit 0
              ;;
esac
# variable definition
KEYWORD=$1
echo "KEYWORD=${KEYWORD}"
MODULE=$2
echo "MODULE=${MODULE}"
DIR=$3
echo "DIR=${DIR}"
FILES=`find $3`
FILES=${FILES#smaps_debug_logmsg_replace_script.sh}
echo "FILES=${FILES}"
BACKUP=/tmp/${KEYWORD}.bak
echo "BACKUP=${BACKUP}"
DIFF=/tmp/${KEYWORD}.diff
echo "DIFF=${DIFF}"
BASENAME=
echo "BASENAME=${BASENAME}"
HOST=`whoami`
echo "HOST=${HOST}"
#
find ${DIR} -name "*" -print -exec grep -n ${KEYWORD} {} \; > ${BACKUP/%bak/bak1}
#
/bin/rm -rf /tmp/${HOST} >& /dev/null
mkdir /tmp/${HOST} >& /dev/null
#
for FILE in ${FILES} ; do
    if [ -f "${FILE}" ] ; then
        echo "${FILE} is file"
        BASENAME=`basename ${FILE}`
        #Judge if this file contains your log function
        FUNC_RTN=$(IsYourLogFunc ${FILE} ${KEYWORD})
        echo "\${FUNC_RTN}=${FUNC_RTN}"
        if [ "${FUNC_RTN}" -eq "1" ] ; then
            echo "/bin/sed -e 's/${KEYWORD}(/SMAPS_DEBUG_LOGMSG( ${MODULE}, LOG_DEBUGA,/g' $FILE > /tmp/${HOST}/${BASENAME}1"
            /bin/sed -e "s/${KEYWORD}(/SMAPS_DEBUG_LOGMSG( ${MODULE}, LOG_DEBUGA,/g" $FILE > /tmp/${HOST}/${BASENAME}1
            echo "/bin/sed -e 's/SMAPS_DEBUG_LOGMSG( ${MODULE}, LOG_DEBUGA, \"\([^\"]*\)\"/SMAPS_DEBUG_LOGMSG( ${MODULE}, LOG_DEBUGA, \"\1\/n\"/g' /tmp/${HOST}/${BASENAME}1 > /tmp/${HOST}/${BASENAME}2"
            /bin/sed -e "s/SMAPS_DEBUG_LOGMSG( ${MODULE}, LOG_DEBUGA, \"\([^\"]*\)\"/SMAPS_DEBUG_LOGMSG( ${MODULE}, LOG_DEBUGA, \"\1\/n\"/g" /tmp/${HOST}/${BASENAME}1 > /tmp/${HOST}/${BASENAME}2
            echo "/bin/rm /tmp/${HOST}/${BASENAME}1"
            /bin/rm /tmp/${HOST}/${BASENAME}1
            echo "/bin/rm ${FILE}"
            /bin/rm ${FILE}
            echo "sed '/#include/a\#include "common_facility/debug_logger/smapsDebug.h"' /tmp/${HOST}/${BASENAME}2 | grep -n "common_facility/debug_logger/smapsDebug.h" | awk -F: '{print $1}'"
            LINE=`grep -n "#include" /tmp/${HOST}/${BASENAME}2 | awk -F: '{print $1}'`
            echo "LINE=$LINE"
            LAST_LINE=`echo ${LINE} | awk '{print $NF}'`
            echo "LAST_LINE=$LAST_LINE"
            echo "sed -e ${LAST_LINE},${LAST_LINE} a\#include \"common_facility/debug_logger/smapsDebug.h\" /tmp/${HOST}/${BASENAME}2 > /tmp/${HOST}/${BASENAME}.sed"
            sed -e "${LAST_LINE},${LAST_LINE} a\#include \"common_facility/debug_logger/smapsDebug.h\"" /tmp/${HOST}/${BASENAME}2 > /tmp/${HOST}/${BASENAME}.sed
            echo "/bin/rm /tmp/${HOST}/${BASENAME}2"
            /bin/rm /tmp/${HOST}/${BASENAME}2
            echo "cp /tmp/${HOST}/${BASENAME}.sed /tmp/${HOST}/${BASENAME}2"
            cp /tmp/${HOST}/${BASENAME}.sed /tmp/${HOST}/${BASENAME}2
            echo "cp /tmp/${HOST}/${BASENAME}2 ${FILE}"
            cp /tmp/${HOST}/${BASENAME}2 ${FILE}
        fi #IsYourLogFunc
    fi #is file
done
#Delete all temp files
echo "/bin/rm -rf /tmp/${HOST} >& /dev/null"
/bin/rm -rf /tmp/${HOST} >& /dev/null
#
find ${DIR} -name "*" -print -exec grep -n "SMAPS_DEBUG_LOGMSG" {} \; > ${BACKUP/%bak/bak2}
#
#diff -rcb ${BACKUP/%bak/bak1} ${BACKUP/%bak/bak2} > ${DIFF}
vimdiff ${BACKUP/%bak/bak1} ${BACKUP/%bak/bak2}
echo "As to the diff result, please refer to ${DIFF}"
#Return to shell commandline




上一篇:VC 2008 操作 sqlite3 数据库 示例
下一篇:vc 6.0 简单重叠IO串口通信源代码(详细注释)
您需要登录后才可以回帖 登录 | 加入驿站 qq_login

本版积分规则

关闭

站长提醒上一条 /2 下一条

QQ|小黑屋|手机版|VC驿站 ( 辽ICP备09019393号tongdun|网站地图wx_jqr

GMT+8, 2019-8-19 00:25

Powered by Discuz! X3.4

© 2009-2019 cctry.com

快速回复 返回顶部 返回列表