网上淘来,一个可以生成规格化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
阅读(1827) | 评论(0) | 转发(1) |