1) 不能含有 [..] 单词
2) 不能含有 | 单词
2012年1月9日星期一
2011年10月13日星期四
gdb调试的常用命令
gdb
file ./srl #调用可执行程序
set args -inputfile test.txt #设置参数
break SRL/srl.cpp:1105 #在srl.cpp的1105行设置断点
run #运行程序
print iNumSent #查看变量值
next (n)单步执行, 如有函数调用, 不会进入
step (s) 单步执行, 如有函数调用, 会进入
continue (c) 恢复继续执行, 程序结束或至个断点为止
disable 使所有的断点无效
disable 1使断点1无效
enable同样的道理
condition SRL/srl.cpp:1105 iNumSent==5, 设置条件断点
condition SRL/srl.cpp:1105, 取消条件断点
file ./srl #调用可执行程序
set args -inputfile test.txt #设置参数
break SRL/srl.cpp:1105 #在srl.cpp的1105行设置断点
run #运行程序
print iNumSent #查看变量值
next (n)单步执行, 如有函数调用, 不会进入
step (s) 单步执行, 如有函数调用, 会进入
continue (c) 恢复继续执行, 程序结束或至个断点为止
disable 使所有的断点无效
disable 1使断点1无效
enable同样的道理
condition SRL/srl.cpp:1105 iNumSent==5, 设置条件断点
condition SRL/srl.cpp:1105, 取消条件断点
2011年10月3日星期一
AB血型的特质(本人觉得还是蛮贴切的)
转自http://www.douban.com/group/topic/7276992/
AB血型.此血型属极端血型,仅占全世界总人口的5%。此血型的人,待人真诚、嫉恶如仇、不攀附权贵、比较理性、多才多艺、有不屈不挠的精神,绝大多人都能成就大业。如周恩来总理、比尔盖茨、李嘉诚、爱因斯坦等等均是此血型。
我对AB血型的人的总结:
排斥复杂的人际关系,不管与谁都会保持一定距离,喜欢孤独。
追求合理性,对不公正和不公平的事情极为反感,守时,也比较守信用。
无论对自己还是对人类社会都有很强的批判精神,不盲从传统,从自己独特的视角看问题,几乎不会去追随任何流行和时尚的东西,甚至很反感那些肤浅的东西。
很难与大的群体融为一体,对喊口号,大合唱和团体操这些东西很排斥,对生日之歌尤其感到肉麻,觉得那些东西很不自然,很扭曲。不喜欢和很多人在一起吃饭、聊天,因为人越多,就越是低级趣味。
爱好和平,非常不喜欢与人争斗,遇到很棘手的问题往往会逃之夭夭,这一点容易被别人指责为没有责任感或鸵鸟政策,但AB型的更加信奉三十六计走为上。
具有一个敏感而丰富的心灵,对音乐、艺术和宗教有很强的解读能力。对人间世事也有很敏锐的洞察力,常常有一些惊世骇俗的言语,被人们认为太偏激。
认同人类精神和灵性方面的优越感,所以对那些作曲家、艺术家、哲学家和科学家比较崇拜。AB血型的人非常不认可权力和财富方面的优越感,觉得那些 富豪和政客没有什么了不起,甚至很鄙视那些人,认为那些人只是欲望方面的成功,那是一种很低层次上的成功,这种成功还不如不成功。
这种血型的人大都是比较灵性的,对物质的东西比较淡薄。
讨厌矫揉造作的东西,不太遵守那些虚伪的道德和礼仪,在穿着方面有着自己的喜好和判断而显得另类,总的来说人比较叛逆。
做事缺乏持久力,因为AB型的人意欲相对薄弱,人也容易疲劳。
对自己的内在素质有很强的优越感,这种优越感来自与他人的比较,AB型的人基本都是自我感觉良好,对别人的评价其实就是对整个人类的评价不高,甚至相当尖刻。但他们不会有让别人当面难堪的言行,因为这种血型的人比较没有攻击性。
由于不擅长与人争斗,在残酷的生存竞争中,AB型的人明显缺乏斗志而居于下风,他们倾向于道家那种清静无为的思想。
AB血型.此血型属极端血型,仅占全世界总人口的5%。此血型的人,待人真诚、嫉恶如仇、不攀附权贵、比较理性、多才多艺、有不屈不挠的精神,绝大多人都能成就大业。如周恩来总理、比尔盖茨、李嘉诚、爱因斯坦等等均是此血型。
我对AB血型的人的总结:
排斥复杂的人际关系,不管与谁都会保持一定距离,喜欢孤独。
追求合理性,对不公正和不公平的事情极为反感,守时,也比较守信用。
无论对自己还是对人类社会都有很强的批判精神,不盲从传统,从自己独特的视角看问题,几乎不会去追随任何流行和时尚的东西,甚至很反感那些肤浅的东西。
很难与大的群体融为一体,对喊口号,大合唱和团体操这些东西很排斥,对生日之歌尤其感到肉麻,觉得那些东西很不自然,很扭曲。不喜欢和很多人在一起吃饭、聊天,因为人越多,就越是低级趣味。
爱好和平,非常不喜欢与人争斗,遇到很棘手的问题往往会逃之夭夭,这一点容易被别人指责为没有责任感或鸵鸟政策,但AB型的更加信奉三十六计走为上。
具有一个敏感而丰富的心灵,对音乐、艺术和宗教有很强的解读能力。对人间世事也有很敏锐的洞察力,常常有一些惊世骇俗的言语,被人们认为太偏激。
认同人类精神和灵性方面的优越感,所以对那些作曲家、艺术家、哲学家和科学家比较崇拜。AB血型的人非常不认可权力和财富方面的优越感,觉得那些 富豪和政客没有什么了不起,甚至很鄙视那些人,认为那些人只是欲望方面的成功,那是一种很低层次上的成功,这种成功还不如不成功。
这种血型的人大都是比较灵性的,对物质的东西比较淡薄。
讨厌矫揉造作的东西,不太遵守那些虚伪的道德和礼仪,在穿着方面有着自己的喜好和判断而显得另类,总的来说人比较叛逆。
做事缺乏持久力,因为AB型的人意欲相对薄弱,人也容易疲劳。
对自己的内在素质有很强的优越感,这种优越感来自与他人的比较,AB型的人基本都是自我感觉良好,对别人的评价其实就是对整个人类的评价不高,甚至相当尖刻。但他们不会有让别人当面难堪的言行,因为这种血型的人比较没有攻击性。
由于不擅长与人争斗,在残酷的生存竞争中,AB型的人明显缺乏斗志而居于下风,他们倾向于道家那种清静无为的思想。
2011年7月1日星期五
对.gz文件内容进行排序
gunzip < run1.out.gz | LC_ALL=C sort > run1.out.sorted
gunzip < run1.out.gz | LC_ALL=C sort -T $_TMP_DIR > run1.out.sorted
gunzip < run1.out.gz | LC_ALL=C sort -T $_TMP_DIR > run1.out.sorted
zlib的使用
zlib 下载
http://www.zlib.net/
也可以通过命令安装
sudo apt-get install zlib1g-dev zlib1g-dbg zlib1g
读取gz压缩文件与读取普通 文件的方法基本一致..更详细的使用方法可参考zlib自带的example.c
在eclipse下, 编译通过但是链接出错, 解决的方法是:
In Project Properties -> CGG++ linker ->libraries, add just "z".
class CGZFileReader
{
public:
CGZFileReader( const char* pszFName );
~CGZFileReader( );
public:
bool fnReadNextSentence( char *pszLine, int* piLength );
private:
gzFile m_fIn;
};
/*
* gzfilereader.cpp
*
* Created on: 1 Jul 2011
*/
/* user-defined headers */
#include "gzfilereader.h"
/* standard headers */
#include
#include
CGZFileReader::CGZFileReader( const char* pszFName )
{
m_fIn = gzopen( pszFName, "r" );
if ( m_fIn == NULL )
{
printf( "ERROR in CGZFileReader::CGZFileReader: FILE %s not found!\n", pszFName );
return;
}
}
CGZFileReader::~CGZFileReader( )
{
if ( m_fIn != NULL )
gzclose( m_fIn );
}
bool CGZFileReader::fnReadNextSentence( char *pszLine, int* piLength )
{
if ( gzeof( m_fIn ) == true )
return false;
int iLen;
pszLine[ 0 ] = '\0';
gzgets( m_fIn, pszLine, 10001 );
iLen = strlen( pszLine );
while ( iLen > 0 && pszLine[ iLen - 1 ] > 0 && pszLine[ iLen -1 ] < 33 )
{
pszLine[ iLen - 1 ] = '\0';
iLen--;
}
if ( piLength != NULL )
(*piLength) = iLen;
return true;
}
class CGZFileWriter
{
public:
CGZFileWriter( const char *pszFName, const char *pszModel );
~CGZFileWriter( );
public:
void fnWrite( const char *pszLine );
void fnWriteLine( const char *pszLine );
private:
gzFile m_fOut;
};
/*
* gzfilewriter.cpp
*
* Created on: 1 Jul 2011
*/
/* user-defined headers */
#include "gzfilewriter.h"
/* standard headers */
#include
CGZFileWriter::CGZFileWriter( const char *pszFName, const char *pszModel )
{
m_fOut = gzopen( pszFName, pszModel );
if ( m_fOut == NULL )
{
printf( "ERROR in CGZFileWriter::CGZFileWriter: cann't write FILE %s!\n", pszFName );
return;
}
}
CGZFileWriter::~CGZFileWriter( )
{
if ( m_fOut != NULL )
gzclose( m_fOut );
}
void CGZFileWriter::fnWrite( const char *pszLine )
{
gzprintf( m_fOut, "%s", pszLine );
}
void CGZFileWriter::fnWriteLine( const char *pszLine )
{
gzprintf( m_fOut, "%s\n", pszLine );
}
http://www.zlib.net/
也可以通过命令安装
sudo apt-get install zlib1g-dev zlib1g-dbg zlib1g
读取gz压缩文件与读取普通 文件的方法基本一致..更详细的使用方法可参考zlib自带的example.c
在eclipse下, 编译通过但是链接出错, 解决的方法是:
In Project Properties -> CGG++ linker ->libraries, add just "z".
class CGZFileReader
{
public:
CGZFileReader( const char* pszFName );
~CGZFileReader( );
public:
bool fnReadNextSentence( char *pszLine, int* piLength );
private:
gzFile m_fIn;
};
/*
* gzfilereader.cpp
*
* Created on: 1 Jul 2011
*/
/* user-defined headers */
#include "gzfilereader.h"
/* standard headers */
#include
#include
CGZFileReader::CGZFileReader( const char* pszFName )
{
m_fIn = gzopen( pszFName, "r" );
if ( m_fIn == NULL )
{
printf( "ERROR in CGZFileReader::CGZFileReader: FILE %s not found!\n", pszFName );
return;
}
}
CGZFileReader::~CGZFileReader( )
{
if ( m_fIn != NULL )
gzclose( m_fIn );
}
bool CGZFileReader::fnReadNextSentence( char *pszLine, int* piLength )
{
if ( gzeof( m_fIn ) == true )
return false;
int iLen;
pszLine[ 0 ] = '\0';
gzgets( m_fIn, pszLine, 10001 );
iLen = strlen( pszLine );
while ( iLen > 0 && pszLine[ iLen - 1 ] > 0 && pszLine[ iLen -1 ] < 33 )
{
pszLine[ iLen - 1 ] = '\0';
iLen--;
}
if ( piLength != NULL )
(*piLength) = iLen;
return true;
}
class CGZFileWriter
{
public:
CGZFileWriter( const char *pszFName, const char *pszModel );
~CGZFileWriter( );
public:
void fnWrite( const char *pszLine );
void fnWriteLine( const char *pszLine );
private:
gzFile m_fOut;
};
/*
* gzfilewriter.cpp
*
* Created on: 1 Jul 2011
*/
/* user-defined headers */
#include "gzfilewriter.h"
/* standard headers */
#include
CGZFileWriter::CGZFileWriter( const char *pszFName, const char *pszModel )
{
m_fOut = gzopen( pszFName, pszModel );
if ( m_fOut == NULL )
{
printf( "ERROR in CGZFileWriter::CGZFileWriter: cann't write FILE %s!\n", pszFName );
return;
}
}
CGZFileWriter::~CGZFileWriter( )
{
if ( m_fOut != NULL )
gzclose( m_fOut );
}
void CGZFileWriter::fnWrite( const char *pszLine )
{
gzprintf( m_fOut, "%s", pszLine );
}
void CGZFileWriter::fnWriteLine( const char *pszLine )
{
gzprintf( m_fOut, "%s\n", pszLine );
}
2011年6月28日星期二
CSet模板类
template < typename itemType >
int fnCompare( itemType *pitem1, itemType *pitem2 )
{
return pitem1->fnCompare( pitem2 );
};
template
class CSet
{
public:
int m_iMaxNumItems;
int m_iNumIncrementalItems;
int m_iNumItems;
itemType **m_paItems;
public:
CSet( int iMaxNumItems, int iNumIncrementalItems )
{
m_iMaxNumItems = iMaxNumItems;
m_iNumIncrementalItems = iNumIncrementalItems;
m_iNumItems = 0;
int I;
m_paItems = new itemType * [ m_iMaxNumItems ];
for( I = 0; I < m_iMaxNumItems; I ++ )
{
m_paItems[ I ] = NULL;
}
}
~CSet( )
{
int I;
for( I = 0; I < m_iNumItems; I ++ )
{
delete m_paItems[ I ];
m_paItems[ I ] = NULL;
}
delete [] m_paItems;
}
void fnClear( void )
{
int I;
for( I = 0; I < m_iNumItems; I ++ ){
delete m_paItems[ I ];
m_paItems[ I ] = NULL;
}
m_iNumItems = 0;
}
bool fnInsert( itemType *pItem )
{
if( m_iNumItems == 0
|| ( m_iNumItems < m_iMaxNumItems && fnCompare( m_paItems[ m_iNumItems - 1 ], pItem ) ) )
{
m_paItems[ m_iNumItems ] = pItem;
m_iNumItems++;
return true;
}
int I;
//insert the item
int iB, iE, iM;
float fC = -1;
iB = 0;
iE = m_iNumItems - 1;
iM = (iB + iE ) / 2;
do{
if( iE < iB )
break;
iM = (iB + iE ) / 2;
fC = fnCompare( m_paItems[ iM ], pItem );
if( fC == 0 )
{
iE = iM;
break;
}
if( fC < 0 )
iE = iM - 1;
if( fC > 0 )
iB = iM + 1;
}while( true );
if( fC > 0 )
iM ++;//iM is the position need to insert
if( m_iMaxNumItems == m_iNumItems )
{ //when the table is full
if( m_iNumIncrementalItems <= 0 )
{ //no incremental items are allowed
if ( iM >= m_iNumItems )
return false;//
delete m_paItems[ m_iNumItems - 1 ];
for( I = m_iNumItems - 2; I >= iM; I-- )
{
m_paItems[ I + 1 ] = m_paItems[ I ];
}
m_paItems[ I + 1 ] = pItem;
return true;
}
else
{ //incremental items are allowed
//increase the table size
itemType **paNewItems = new itemType * [ m_iMaxNumItems + m_iNumIncrementalItems ];
for( I = 0; I < m_iMaxNumItems; I ++ )
{
paNewItems[ I ] = m_paItems[ I ];
}
for( I = m_iMaxNumItems; I < m_iMaxNumItems + m_iNumIncrementalItems; I ++ )
paNewItems[ I ] = NULL;
delete [] m_paItems;
m_paItems = paNewItems;
m_iMaxNumItems += m_iNumIncrementalItems;
}
}
for( I = m_iNumItems - 1; I >= iM; I -- )
{
m_paItems[ I + 1 ] = m_paItems[ I ];
}
m_paItems[ I + 1 ] = pItem;
m_iNumItems ++;
return true;
}
bool fnDelete( int iBeginItemID, int iNumDeleteItems )
{
int I;
if( ( iBeginItemID < 0 )
|| ( iBeginItemID >= m_iNumItems )
|| ( iNumDeleteItems < 0 ) )
return false;
if( ( iBeginItemID + iNumDeleteItems ) > m_iNumItems )
iNumDeleteItems = m_iNumItems - iBeginItemID;
for( I = 0; I < iNumDeleteItems; I ++ ){
delete m_paItems[ iBeginItemID + I ];
m_paItems[ iBeginItemID + I ] = NULL;
}
for( I = iBeginItemID; I < m_iNumItems - iNumDeleteItems; I ++ ){
m_paItems[ I ] = m_paItems[ I + iNumDeleteItems ];
m_paItems[ I + iNumDeleteItems ] = NULL;
}
m_iNumItems -= iNumDeleteItems;
return true;
}
};
实例化CSet的类itemType需要实现fnCompare( itemType pitem2 )方法.
int fnCompare( itemType *pitem1, itemType *pitem2 )
{
return pitem1->fnCompare( pitem2 );
};
template
class CSet
{
public:
int m_iMaxNumItems;
int m_iNumIncrementalItems;
int m_iNumItems;
itemType **m_paItems;
public:
CSet( int iMaxNumItems, int iNumIncrementalItems )
{
m_iMaxNumItems = iMaxNumItems;
m_iNumIncrementalItems = iNumIncrementalItems;
m_iNumItems = 0;
int I;
m_paItems = new itemType * [ m_iMaxNumItems ];
for( I = 0; I < m_iMaxNumItems; I ++ )
{
m_paItems[ I ] = NULL;
}
}
~CSet( )
{
int I;
for( I = 0; I < m_iNumItems; I ++ )
{
delete m_paItems[ I ];
m_paItems[ I ] = NULL;
}
delete [] m_paItems;
}
void fnClear( void )
{
int I;
for( I = 0; I < m_iNumItems; I ++ ){
delete m_paItems[ I ];
m_paItems[ I ] = NULL;
}
m_iNumItems = 0;
}
bool fnInsert( itemType *pItem )
{
if( m_iNumItems == 0
|| ( m_iNumItems < m_iMaxNumItems && fnCompare( m_paItems[ m_iNumItems - 1 ], pItem ) ) )
{
m_paItems[ m_iNumItems ] = pItem;
m_iNumItems++;
return true;
}
int I;
//insert the item
int iB, iE, iM;
float fC = -1;
iB = 0;
iE = m_iNumItems - 1;
iM = (iB + iE ) / 2;
do{
if( iE < iB )
break;
iM = (iB + iE ) / 2;
fC = fnCompare( m_paItems[ iM ], pItem );
if( fC == 0 )
{
iE = iM;
break;
}
if( fC < 0 )
iE = iM - 1;
if( fC > 0 )
iB = iM + 1;
}while( true );
if( fC > 0 )
iM ++;//iM is the position need to insert
if( m_iMaxNumItems == m_iNumItems )
{ //when the table is full
if( m_iNumIncrementalItems <= 0 )
{ //no incremental items are allowed
if ( iM >= m_iNumItems )
return false;//
delete m_paItems[ m_iNumItems - 1 ];
for( I = m_iNumItems - 2; I >= iM; I-- )
{
m_paItems[ I + 1 ] = m_paItems[ I ];
}
m_paItems[ I + 1 ] = pItem;
return true;
}
else
{ //incremental items are allowed
//increase the table size
itemType **paNewItems = new itemType * [ m_iMaxNumItems + m_iNumIncrementalItems ];
for( I = 0; I < m_iMaxNumItems; I ++ )
{
paNewItems[ I ] = m_paItems[ I ];
}
for( I = m_iMaxNumItems; I < m_iMaxNumItems + m_iNumIncrementalItems; I ++ )
paNewItems[ I ] = NULL;
delete [] m_paItems;
m_paItems = paNewItems;
m_iMaxNumItems += m_iNumIncrementalItems;
}
}
for( I = m_iNumItems - 1; I >= iM; I -- )
{
m_paItems[ I + 1 ] = m_paItems[ I ];
}
m_paItems[ I + 1 ] = pItem;
m_iNumItems ++;
return true;
}
bool fnDelete( int iBeginItemID, int iNumDeleteItems )
{
int I;
if( ( iBeginItemID < 0 )
|| ( iBeginItemID >= m_iNumItems )
|| ( iNumDeleteItems < 0 ) )
return false;
if( ( iBeginItemID + iNumDeleteItems ) > m_iNumItems )
iNumDeleteItems = m_iNumItems - iBeginItemID;
for( I = 0; I < iNumDeleteItems; I ++ ){
delete m_paItems[ iBeginItemID + I ];
m_paItems[ iBeginItemID + I ] = NULL;
}
for( I = iBeginItemID; I < m_iNumItems - iNumDeleteItems; I ++ ){
m_paItems[ I ] = m_paItems[ I + iNumDeleteItems ];
m_paItems[ I + iNumDeleteItems ] = NULL;
}
m_iNumItems -= iNumDeleteItems;
return true;
}
};
实例化CSet的类itemType需要实现fnCompare( itemType pitem2 )方法.
2011年6月26日星期日
内存泄漏检测
Linux下C++代码内存泄漏检测:
valgrind --leak-check=full ./parser
之前需要安装valgrind (sudo apt-get install valgrind)
mac上安装valgrind可参考
http://valgrind.org/downloads/repository.html
valgrind --leak-check=full ./parser
之前需要安装valgrind (sudo apt-get install valgrind)
mac上安装valgrind可参考
http://valgrind.org/downloads/repository.html
The Current (3.0 and later) Repository
To check out code from the current repository (anonymous, read-only SVN access), do this:
svn co svn://svn.valgrind.org/valgrind/trunk valgrind
To build the checked out code, follow the instructions in the
README file that the checkout should give you. Alternatively, the following should work: cd valgrind
./autogen.sh
./configure --prefix=...
make
make install
To do the checkout, you'll need a Subversion client, version 1.1.0 or later. Versions prior to 1.1.0 do not properly handle the symbolic links in our tree.
To do the build, you'll need automake version 1.10 or later and a compatible version of autoconf (e.g. 2.68). These should come as standard on any non-ancient Linux distribution.
订阅:
博文 (Atom)