2007年4月19日 星期四

astyle

相信大家都了解Coding Style對於程式的可讀性有重大的影響,

然而可能沒有幾個人能真正的遵守好一個固定的Coding Style

Astyle 是一個跨平台的Coding Style Adjusting軟體,支援 C, C++, C#, and Java

它可以幫助各位輕易的把程式碼轉變成你所想要的格式。

default 支援 ANSI, GNU, K&R, Linux Java Code style

當然,你可以自行定義自已喜好的 Coding style

以下是我個人的使用例子

我個人喜好使用 java (--style=java) coding style,而且我不希望做完縮排後產生備份檔 (-n)

我的使用方法就變成了

astyle --style=java –n

如果我希望 default 就是我的喜好格式,

可以把我的 config 放入 ~/.astylerc

Example:

> cat ~/.astylerc

--style=java –n

>

2007年4月13日 星期五

chout: a small tool for debug. Hope you enjoy it. ^^


#!/bin/bash
# This software may be used and distributed according to the terms
# of the GNU General Public License (GPL), incorporated herein by reference.
# Drivers based on this skeleton fall under the GPL and must retain
# the authorship (implicit copyright) notice.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#filename: chout
#composer: Tick

if ! [[ "$CHOUT_DEBUG" ]];then
CHOUT_DEBUG=0
fi

function debug {
if (( $CHOUT_DEBUG!=0 ));then
echo [Chout Debug] $@
fi
}

function usage {
if (( $#==0 ));then
echo "USAGE: chout [-i] [- ] "
echo "Example: chout DEBUG <-- finding files contain DEBUG"
echo "Example: chout -name '*.pro' DEBUG <-- finding DEBUG from pro fil es"
echo "Example: chout -dir /tmp/ -type f DEBUG <-- all files in specific dire ctory"
echo "Example: chout -i DeBuG <-- ignore case"
echo "Other flags: -cmin -ctime"
echo "Please reference to \"man find\""
exit;
fi }

usage $@
ICASE=" "
DIR=" "
NAMEFLAG=" "
NAME=" "
TYPEFLAG=" "
TYPE=" "
CMINFLAG=" "
CMIN=" "
CTIMEFLAG=" "
CTIME=" "
ares=" "
while (( $# > 1 )) &&amp; ( [ "$1" == "-dir" ] || \
[ "$1" == "-i" ] || \
[ "$1" == "-name" ] || \
[ "$1" == "-type" ] || \
[ "$1" == "-ctime" ] || \
[ "$1" == "-cmin" ]);do

if [ "$1" == "-dir" ];then
shift
DIR="$1"
elif [ "$1" == "-type" ];then
shift
TYPEFLAG="-type"
TYPE="$1"
elif [ "$1" == "-name" ];then
shift
NAMEFLAG="-name"
NAME="$1"
elif [ "$1" == "-i" ];then
ICASE=" -i"
elif [ "$1" == "-ctime" ];then
shift
CTIMEFLAG="-ctime"
CTIME="$1"
elif [ "$1" == "-cmin" ];then
shift
CMINFLAG="-cmin"
CMIN="$1"
else
echo break time $@
break
fi
shift
done
usage $@

if [ "$ares" != " " ];then
echo -n ""
elif [ "$TYPEFLAG" == " " ] \
&& [ "$NAMEFLAG" == " " ] \
&& [ "$CTIMEFLAG" == " " ] \
&& [ "$CMINFLAG" == " " ] \
;then
debug DIR=$DIR
ares="`find ${DIR} -name '*.h'` `find ${DIR} -name '*.c'` `find ${DIR} -
name '*.cpp'`"
else
if [ "${NAME}" == " " ];then
ares=`find ${DIR} ${CTIMEFLAG} ${CTIME} ${CMINFLAG} ${CMIN} ${TYPEFLAG} ${TYPE}`
else
debug "find ${DIR} ${CTIMEFLAG} ${CTIME} ${CMINFLAG} ${CMIN} ${TYPEFLAG} ${TYPE} ${NAMEFLAG} \"${NAME}\""
ares=`find ${DIR} ${CTIMEFLAG} ${CTIME} ${CMINFLAG} ${CMIN} ${TYPEFLAG} ${TYPE} ${NAMEFLAG} "${NAME}"`
fi

fi

target=$1
shift

while (( $# > 0 ));do
target="$target "'*'"$1"
shift
done

debug "target is '$target'"

for arrs in $ares ;do

if (( `file $arrs | grep -e "text" -e "symbolic" | wc -l ` == 0 ));then
debug $arrs is binary
continue
fi
debug Try to parse $arrs
if [ -f $arrs ] && (( `cat $arrs | grep ${ICASE} "${target}" | wc -l` > 0 ));
then
echo "In file $arrs"
grep --color -n ${ICASE} "${target}" $arrs
#awk '{print NR":\t"$0}' $arrs | grep ${ICASE} $1 | sed -n "s/${target}/&/p"
echo " "
fi
done

2007年4月3日 星期二

Hello

Hello All,
Welcome to my Blog!
This is a place I put my notes of my interests.
I may write in chinese or English.

I enjoy linux (kernel) programming and playing ocarina a lot.
And therefore I named this blob as "Linux & Ocarina",
though I might put something else here.