通过shell脚本生成C代码例程

来源:互联网 发布:周杰伦的淘宝店是什么 编辑:程序博客网 时间:2024/06/04 00:54

通过shell脚本生成C代码例程:


#!/bin/shtarget=$1BUILDER_VERSION_BRANCH=${VERSION_BRANCH}BUILDER_VERSION_MAJOR=${VERSION_MAJOR}BUILDER_VERSION_MINOR=${VERSION_MINOR}BUILDER_VERSION_EXTRA=${VERSION_EXTRA}BUILDER_VERSION_REVNO=${VERSION_REVNO}BUILDER_VERSION_STAGE=${VERSION_STAGE}BUILDER_CMPL_YEAR=`date +%Y | sed -e 's/^0//g'`BUILDER_CMPL_MONTH=`date +%m | sed -e 's/^0//g'`BUILDER_CMPL_DATE=`date +%d | sed -e 's/^0//g'`BUILDER_CMPL_TIME="`date +%T`"echo "/* Automatically generated file; DO NOT EDIT. */" > $targetecho "char *builder_version_branch(void)" >> $targetecho "{" >> $targetecho "   return \"${BUILDER_VERSION_BRANCH}\";" >> $targetecho "}" >> $targetecho "unsigned int builder_version_major(void)" >> $targetecho "{" >> $targetecho "  return ${BUILDER_VERSION_MAJOR};" >> $targetecho "}" >> $targetecho "unsigned int builder_version_minor(void)" >> $targetecho "{" >> $targetecho "  return ${BUILDER_VERSION_MINOR};" >> $targetecho "}" >> $targetecho "unsigned int builder_version_extra(void)" >> $targetecho "{" >> $targetecho "  return ${BUILDER_VERSION_EXTRA};" >> $targetecho "}" >> $targetecho "unsigned int builder_version_revno(void)" >> $targetecho "{" >> $targetecho "  return ${BUILDER_VERSION_REVNO};" >> $targetecho "}" >> $targetecho "char *builder_version_stage(void)" >> $targetecho "{" >> $targetecho "    return ${BUILDER_VERSION_STAGE};" >> $targetecho "}" >> $targetecho "unsigned int builder_cmpl_year(void)" >> $targetecho "{" >> $targetecho "  return ${BUILDER_CMPL_YEAR};" >> $targetecho "}" >> $targetecho "unsigned int builder_cmpl_month(void)" >> $targetecho "{" >> $targetecho "  return ${BUILDER_CMPL_MONTH};" >> $targetecho "}" >> $targetecho "unsigned int builder_cmpl_date(void)" >> $targetecho "{" >> $targetecho "  return ${BUILDER_CMPL_DATE};" >> $targetecho "}" >> $targetecho "char *builder_cmpl_time(void)" >> $targetecho "{" >> $targetecho "  return \"${BUILDER_CMPL_TIME}\";" >> $targetecho "}" >> $target

执行上面的shell。

./builder.sh abc.c

生成一下C代码:

/* Automatically generated file; DO NOT EDIT. */char *builder_version_branch(void){   return "";}unsigned int builder_version_major(void){        return ;}unsigned int builder_version_minor(void){        return ;}unsigned int builder_version_extra(void){        return ;}unsigned int builder_version_revno(void){        return ;}char *builder_version_stage(void){    return ;}unsigned int builder_cmpl_year(void){        return 2016;}unsigned int builder_cmpl_month(void){        return 8;}unsigned int builder_cmpl_date(void){        return 16;}char *builder_cmpl_time(void){        return "10:26:48";}




0 0
原创粉丝点击