一直比较懒,做事情都喜欢快速链接和自动化。
为方便调试程序,写了几个简单的Shell。
- 首先,genSrcFile帮助生成简单的程序框架。
- 然后,只需要通过输入pv/pc/px就可以完成编辑/编译/执行了,非常便于调试。
当然,对于稍微大点的程序,用make更合适。
#################################
0. /bin/genSrcFile - 生成source file,目前只有C,其它的如Cpp/Perl/Python可以根据需要扩展
#################################
#! /bin/bash
definedFileType='C or c'
if [ $# -lt 2 ]
then
echo "Usage: `basename $0` fileName fileType(${definedFileType})"
exit 1
fi
fileName=$1
fileType=$2
if [ -e "${fileName}.${fileType}" ]
then
echo "##################################################"
echo "# \"${fileName}.${fileType}\" already exists in `pwd`";
echo "##################################################"
echo "If you want to overwrite it, press Yes, otherwise, press anykey to backup"
read owOption
case "${owOption}" in
[Yy]|[Yy][Ee][Ss] ) echo "${fileName}.${fileType} would be overwritten.";;
*) destFile="${fileName}.${fileType}."`date +%s`
`mv "${fileName}.${fileType}" "${destFile}"`
if [ $? != 0 ]; then
echo "Error occurs during mv ${fileName}.${fileType}"
exit 1
fi;;
esac
fi
case "${fileType}" in
[Cc])
echo '#include
'>"${fileName}.${fileType}"
echo '#include '>>"${fileName}.${fileType}"
echo '#include '>>"${fileName}.${fileType}"
echo '#include '>>"${fileName}.${fileType}"
echo '#include '>>"${fileName}.${fileType}"
echo '#include '>>"${fileName}.${fileType}"
echo ''>>"${fileName}.${fileType}"
echo 'int main(int argc, char **argv) {'>>"${fileName}.${fileType}"
echo ' '>>"${fileName}.${fileType}"
echo ' exit(0);'>>"${fileName}.${fileType}"
echo '}'>>"${fileName}.${fileType}";;
*)
echo "FileType - \"${fileType}\" undefined, defined FileType up to now = \"${definedFileType}\""; exit 1;;
esac
#################################
1. /bin/pv - 在任何位置输入pv即可编辑当前程序
#################################
#! /bin/bash
if ! [ -f "${_CUR_PROGRAM_}" ]
then
echo "_CUR_PROGRAM_ ${_CUR_PROGRAM_} not exist"
exit 1
fi
vim ${_CUR_PROGRAM_}
#################################
2. /bin/pc - 用来帮助编译,可以指定参数
#################################
#! /bin/bash
if ! [ -f "${_CUR_PROGRAM_}" ]
then
echo "_CUR_PROGRAM_ ${_CUR_PROGRAM_} not exist"
exit 1
fi
PROG_FULL_PATH=${_CUR_PROGRAM_}
PROG_FULL_DIR=${_CUR_PROGRAM_%/*}
PROG_FULL_NAME=${_CUR_PROGRAM_##*/}
PROG_NAME=${PROG_FULL_NAME%.*}
cd "${PROG_FULL_DIR}" || {
echo "Failed to chdir to \"${PROG_FULL_DIR}\""
exit 1
}
gcc $@ ${_OPTION_CARY_} -o ${PROG_NAME} ${_CUR_PROGRAM_}
if [ $? == 0 ]
then
echo "gcc $@ ${_OPTION_CARY_} -o ${PROG_NAME} ${_CUR_PROGRAM_} executed successfully"
else
echo "Error during executing: gcc $@ ${_OPTION_CARY_} -o ${PROG_NAME} ${_CUR_PROGRAM_}"
fi
#################################
3. /bin/px - 它来帮我执行
#################################
#! /bin/bash
if ! [ -f "${_CUR_PROGRAM_}" ]
then
echo "_CUR_PROGRAM_ \"${_CUR_PROGRAM_}\" not exist"
exit 1
fi
PROG_FULL_PATH=${_CUR_PROGRAM_}
PROG_FULL_DIR=${_CUR_PROGRAM_%/*}
PROG_FULL_NAME=${_CUR_PROGRAM_##*/}
PROG_NAME=${PROG_FULL_NAME%.*}
if ! [ -x "${PROG_FULL_DIR}/${PROG_NAME}" ]
then
echo "PROG_NAME \"${PROG_FULL_DIR}/${PROG_NAME}\" not executable"
exit 1
fi
${PROG_FULL_DIR}/${PROG_NAME}
if [ $? != 0 ]
then
echo "Error occurs during run - \"${PROG_FULL_DIR}/${PROG_NAME}\""
exit 1
fi
阅读(700) | 评论(0) | 转发(0) |