如果你使用有点”IDE“的环境,自动生成的东西一大堆,那这个就不必用啦。我从WINDOWS转入LINUX没多久,所以玩玩^_^.
不说废话啦,调用此脚本将实现:
1。生成c文件和相应的头文件
2。在生成的文件中自动生成注释
3。生成Makefile,此Makefile中导入一个配置文件.FelixInit内容是:
FELIXMAKESO=no
FELIXLIBNAME=libfelix.a
FELIXLIBALIAS=felix
FELIXLIBSONAME=libfelix.so
FELIXDEST=/root/programming/FelixAlg/lib
FELIXHEADER=/root/programming/FelixAlg/header
FELIXHOME=/root/programming
cc=gcc
CFLAGS=-g -I$(FELIXHEADER) -L$(FELIXDEST) -l$(FELIXLIBALIAS)
脚本文件如下:
#!/bin/bash
#a function to return a argument in argsi
function getargs()
{
j=2
tmpStr=$1
while test "$j" -le "$2"
do
index="`expr index "$tmpStr" ' '`"
j=$(($j+1))
len="`expr length "$tmpStr"`"
tmpStr=`expr substr "$tmpStr" "$(($index+1))" $len`
done
index=`expr index "$tmpStr" ' '`
if test "$index" = "0"
then
argsi=$tmpStr
else
argsi="`expr substr "$tmpStr" 1 $(($index-1))`"
fi
return 1
}
mainArgs=$*
#echo a:$mainArgs
input="n"
i=1
quitShowInput="you can alter the menu in menu_c.h"
#check arguments
while test "$i" -le $#
do
getargs "$mainArgs" "$i"
case $argsi in
-de)#file's description
i=$(($i+1))
getargs "$mainArgs" "$i"
description=$argsi;;
-a)#author
i=$(($i+1))
getargs "$mainArgs" "$i"
author=$argsi;;
-f)#filename
i=$(($i+1))
getargs "$mainArgs" "$i"
filename=$argsi;;
-h)#see helps
echo -e " usage:/nmakeCtmp -d [directory to input] -f [fileanme] -a [author] -de [file 's description]"
exit;;
-d)#object diretory
i=$(($i+1))
getargs "$mainArgs" "$i"
directory="$argsi"
if test -d "$directory"
then
echo "error:invalid directory"
exit
fi;;
-e)#edit it immediately
immedia=true
;;
-c)#add c file
addc=true
;;
*)
echo "errors:contain errors with arguments,makeCtmp -h to get helps"
exit
esac
i=$(($i+1))
done
if test -z $directory
then
directory="."
fi
cd $directory
if test -z $filename
then
echo "error:miss file name.print makeCtmp -h to get helps"
exit
fi
re=y
if test -f "$filename"
then
echo "error: file exists.replace it(y/n)?";
read re
fi
if test "$re" = "y"
then
#create makefile
makebody="include ~/.FelixInit/nobjects=${filename}.o/n/$(objects): ${filename}.h/n/t/$(cc) -c /$(CFLAGS) /$*.c /nclean:/n/trm *.o/ninstall:/$(objects)/n/tar rcs /$(FELIXDEST)//$(FELIXLIBNAME) /$^/n/tcp ${filename}.h /$(FELIXHEADER) "
echo -e $makebody>Makefile
comment="/**********************************/n*author:${author}/n*last update:`date`/n*description:/n*/n*/n*/n*/"
body="#ifndef ___`echo ${filename}|tr a-z A-Z`___/n#define ___`echo ${filename}|tr a-z A-Z`___/n/n/n/n/n#endif"
echo -e "$comment/n$body">${filename}.h
if [ "$addc" = "true" ]
then
cbody="${comment}/n#include /"${filename}.h/"/n"
echo -e $cbody>${filename}.c
fi
if [ "$immedia" = "true" ]
then
vi ${filename}.h ${filename}.c
fi
fi
不说废话啦,调用此脚本将实现:
1。生成c文件和相应的头文件
2。在生成的文件中自动生成注释
3。生成Makefile,此Makefile中导入一个配置文件.FelixInit内容是:
FELIXMAKESO=no
FELIXLIBNAME=libfelix.a
FELIXLIBALIAS=felix
FELIXLIBSONAME=libfelix.so
FELIXDEST=/root/programming/FelixAlg/lib
FELIXHEADER=/root/programming/FelixAlg/header
FELIXHOME=/root/programming
cc=gcc
CFLAGS=-g -I$(FELIXHEADER) -L$(FELIXDEST) -l$(FELIXLIBALIAS)
脚本文件如下:
#!/bin/bash
#a function to return a argument in argsi
function getargs()
{
j=2
tmpStr=$1
while test "$j" -le "$2"
do
index="`expr index "$tmpStr" ' '`"
j=$(($j+1))
len="`expr length "$tmpStr"`"
tmpStr=`expr substr "$tmpStr" "$(($index+1))" $len`
done
index=`expr index "$tmpStr" ' '`
if test "$index" = "0"
then
argsi=$tmpStr
else
argsi="`expr substr "$tmpStr" 1 $(($index-1))`"
fi
return 1
}
mainArgs=$*
#echo a:$mainArgs
input="n"
i=1
quitShowInput="you can alter the menu in menu_c.h"
#check arguments
while test "$i" -le $#
do
getargs "$mainArgs" "$i"
case $argsi in
-de)#file's description
i=$(($i+1))
getargs "$mainArgs" "$i"
description=$argsi;;
-a)#author
i=$(($i+1))
getargs "$mainArgs" "$i"
author=$argsi;;
-f)#filename
i=$(($i+1))
getargs "$mainArgs" "$i"
filename=$argsi;;
-h)#see helps
echo -e " usage:/nmakeCtmp -d [directory to input] -f [fileanme] -a [author] -de [file 's description]"
exit;;
-d)#object diretory
i=$(($i+1))
getargs "$mainArgs" "$i"
directory="$argsi"
if test -d "$directory"
then
echo "error:invalid directory"
exit
fi;;
-e)#edit it immediately
immedia=true
;;
-c)#add c file
addc=true
;;
*)
echo "errors:contain errors with arguments,makeCtmp -h to get helps"
exit
esac
i=$(($i+1))
done
if test -z $directory
then
directory="."
fi
cd $directory
if test -z $filename
then
echo "error:miss file name.print makeCtmp -h to get helps"
exit
fi
re=y
if test -f "$filename"
then
echo "error: file exists.replace it(y/n)?";
read re
fi
if test "$re" = "y"
then
#create makefile
makebody="include ~/.FelixInit/nobjects=${filename}.o/n/$(objects): ${filename}.h/n/t/$(cc) -c /$(CFLAGS) /$*.c /nclean:/n/trm *.o/ninstall:/$(objects)/n/tar rcs /$(FELIXDEST)//$(FELIXLIBNAME) /$^/n/tcp ${filename}.h /$(FELIXHEADER) "
echo -e $makebody>Makefile
comment="/**********************************/n*author:${author}/n*last update:`date`/n*description:/n*/n*/n*/n*/"
body="#ifndef ___`echo ${filename}|tr a-z A-Z`___/n#define ___`echo ${filename}|tr a-z A-Z`___/n/n/n/n/n#endif"
echo -e "$comment/n$body">${filename}.h
if [ "$addc" = "true" ]
then
cbody="${comment}/n#include /"${filename}.h/"/n"
echo -e $cbody>${filename}.c
fi
if [ "$immedia" = "true" ]
then
vi ${filename}.h ${filename}.c
fi
fi