Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1068993
  • 博文数量: 135
  • 博客积分: 10182
  • 博客等级: 上将
  • 技术积分: 1565
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-07 16:05
文章分类

全部博文(135)

文章存档

2011年(5)

2010年(20)

2009年(3)

2008年(16)

2007年(91)

分类: LINUX

2007-04-21 19:06:36

网上淘来,一个可以生成规格化c,cpp,makefile,shell等文件的脚本,相当不错,我修改了一下自用。

#!/bin/bash
# Filename   : template
# Description: Create a template based on [c | c++ | Makefile | bash | README]
# Author     : ly44770
# Version    : 1.0
# Date       : 2007.4.21

create_c()
{
cat >> $1 << EOF
/*********************************************************************
 * CEAL
 * All rights reserved.
 * Filename   : $TARGET
 * Description:
 * Author     : ly44770
 * Version    :
 * Date       : `date +%Y.%m.%d`
 **********************************************************************/

/*
 * Function   :
 * Description:
 * Parameters :
 * Return     :
 */

EOF
}

create_readme()
{
cat >> $1 << EOF
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#                                                           #
#                        README                             #
#                        ly44770                            #
#                       `date +%Y.%m.%d`                    #
#                                                           #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
EOF
}

create_makefile()
{
cat >> $1 << EOF
# Makefile
 
# Compiler
CC=/usr/local/arm/2.95.3/bin/arm-linux-gcc

# Options
CFLAGS=-D__KERNEL__ -D__MODULE -I -O -Wall

# Source files
SRC=

# Target file
TARGET=

# Run
\$(TARGET): \$(SRC)
    \$(CC) \$(CFLAGS) \$^ -o \$@

# Clean
.PHONY: clean
clean:
    rm -f \$(TARGET)
EOF
}

create_shell()
{
cat >> $1 << EOF
#!/bin/bash
# # Filename   : $TARGET
# Description:
# Author     : ly44770
# Version    :
# Date       : `date +%y.%m.%d`

EOF
    chmod +x $1
}

# First, get parameters and handle error.
if [ $# != 1 ]; then
    echo "Usage: `basename $0` [filename]"
    echo "Support:"
    echo "        [*.c(h|cpp) | Makefile | bash | README]"
    exit 1
else
    TARGET=$1
fi

# Second, create template in terms of TARGET name.
# *.c   --- c program template
# *.cpp --- c++ program template
# other --- bash shell program template
case $TARGET in
*.c|*.cpp|*.h)
    create_c $TARGET
    ;;

README)
    create_readme $TARGET
    ;;

Makefile)
    create_makefile $TARGET
    ;;

*)
    create_shell $TARGET
    ;;
esac


阅读(1795) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~