<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Here comes the Sun &#187; c</title>
	<atom:link href="http://sunng.info/blog/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://sunng.info/blog</link>
	<description>47% users on this site use *nix</description>
	<lastBuildDate>Sat, 04 Feb 2012 13:08:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Bash Color Support for Bti</title>
		<link>http://sunng.info/blog/2010/10/bash-color-support-for-bti/</link>
		<comments>http://sunng.info/blog/2010/10/bash-color-support-for-bti/#comments</comments>
		<pubDate>Sun, 31 Oct 2010 02:14:07 +0000</pubDate>
		<dc:creator>sunng</dc:creator>
				<category><![CDATA[装备]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[foss]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[opensource]]></category>

		<guid isPermaLink="false">http://sunng.info/blog/2010/10/bash-color-support-for-bti/</guid>
		<description><![CDATA[Bti is well known as a command line twitter/identica/statusnet client, by Greg Kroah-Hartman. I have been using this tool in CLI environment for a long time, found it difficult for human to parse output by eyes. So I forked it &#8230; <a href="http://sunng.info/blog/2010/10/bash-color-support-for-bti/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/gregkh/bti">Bti</a> is well known as a command line twitter/identica/statusnet client, by <a href="http://github.com/gregkh">Greg Kroah-Hartman</a>.</p>
<p>I have been using this tool in CLI environment for a long time, found it difficult for human to parse output by eyes. So I forked it and added this bash color support, to provide some highlight on tweets.<br />
<a href="http://www.flickr.com/photos/40741608@N08/5130529830/" title="bti-bash-color by 贝小塔, on Flickr"><img src="http://farm2.static.flickr.com/1346/5130529830_a1f8eaf793.jpg" width="416" height="500" alt="bti-bash-color" /></a></p>
<p>To enable color support, add an option <i>&#8211;auto-color</i> to bti command, or append <i>auto-color=yes</i> to your configuration file($HOME/.bti)</p>
<p>I have sent pull request to Greg, hope the patch can be merged into master. Before approved, you can check out <a href="http://github.com/sunng87/bti">my fork</a> and compile it yourself. (If liboauth not found, find it <a href="http://liboauth.sourceforge.net/">here</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://sunng.info/blog/2010/10/bash-color-support-for-bti/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redis Data Struct</title>
		<link>http://sunng.info/blog/2010/10/redis-data-struct/</link>
		<comments>http://sunng.info/blog/2010/10/redis-data-struct/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 14:23:13 +0000</pubDate>
		<dc:creator>sunng</dc:creator>
				<category><![CDATA[手艺]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[redis]]></category>

		<guid isPermaLink="false">http://sunng.info/blog/2010/10/redis-data-struct/</guid>
		<description><![CDATA[Redis的几个核心数据结构定义在redis.h和dict.h中。Redis服务器总的数据结构里的根节点是redisServer，下面包含一个redisDb结构数组。数组的大小定义在redis.conf中的databases项，客户端可以通过select命令选择相应的DB。 一个redisDb定义了redis数据库的基本数据结构，redisDb结构定义如下 typedef struct redisDb &#123; &#160; &#160; dict *dict; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; /* The keyspace for this DB */ &#160; &#160; dict *expires; &#160; &#160; &#160; &#160; &#160; &#160; &#160;/* Timeout of keys with &#8230; <a href="http://sunng.info/blog/2010/10/redis-data-struct/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://redis.io">Redis</a>的几个核心数据结构定义在redis.h和dict.h中。Redis服务器总的数据结构里的根节点是redisServer，下面包含一个redisDb结构数组。数组的大小定义在redis.conf中的databases项，客户端可以通过select命令选择相应的DB。</p>
<p>一个redisDb定义了redis数据库的基本数据结构，redisDb结构定义如下</p>
<div class="codecolorer-container c twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> redisDb <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; dict <span style="color: #339933;">*</span>dict<span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* The keyspace for this DB */</span><br />
&nbsp; &nbsp; dict <span style="color: #339933;">*</span>expires<span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">/* Timeout of keys with a timeout set */</span><br />
&nbsp; &nbsp; dict <span style="color: #339933;">*</span>blocking_keys<span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">/* Keys with clients waiting for data (BLPOP) */</span><br />
&nbsp; &nbsp; dict <span style="color: #339933;">*</span>io_keys<span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">/* Keys with clients waiting for VM I/O */</span><br />
&nbsp; &nbsp; dict <span style="color: #339933;">*</span>watched_keys<span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* WATCHED keys for MULTI/EXEC CAS */</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> id<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> redisDb<span style="color: #339933;">;</span></div></div>
<p>其中</p>
<ul>
<li>dict 用于存储键值的哈希表结构</li>
<li>expires 用于存储键、过期时间的哈希表结构</li>
<li>blocking_keys 用于存储键、阻塞数据的哈希表结构。目前仅仅在阻塞式的blpop brpop中使用。</li>
<li>io_keys 存储等待将数据从swap读出的key （vmThreadedIOCompletedJob, dontWaitForSwappedKey, waitForSwappedKey）</li>
<li>watched_keys 用于支持<a href="http://code.google.com/p/redis/wiki/MultiExecCommand#Check_and_Set_%28CAS%29_transactions_using_WATCH">WATCH</a>命令，实现乐观锁功能</li>
<li>id 数据库编号</li>
</ul>
<p>dict结构定义在dict.h中，主要的定义有：</p>
<div class="codecolorer-container c twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> dictEntry <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>key<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>val<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">struct</span> dictEntry <span style="color: #339933;">*</span>next<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> dictEntry<span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> dictht <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; dictEntry <span style="color: #339933;">**</span>table<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> size<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> sizemask<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> used<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> dictht<span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> dict <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; dictType <span style="color: #339933;">*</span>type<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>privdata<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; dictht ht<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> rehashidx<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* rehashing not in progress if rehashidx == -1 */</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> iterators<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* number of iterators currently running */</span><br />
<span style="color: #009900;">&#125;</span> dict<span style="color: #339933;">;</span></div></div>
<p>每个dict中包含两个dictht结构，用来在rehash的时候进行数据交换。rehashidx用于记录rehash的进程，值是当前rehash的table索引。dictht中table二维数组，以hash值为索引。size是哈希表的大小，初始值是4，随着rehash的进行，变成大于size的最小2<sup>n</sup>。sizemask是size-1，用来与哈希值做&#038;运算。</p>
<p>redis在引如virtual memory之前，就是以这样的数据结构运行在内存中的。</p>
]]></content:encoded>
			<wfw:commentRss>http://sunng.info/blog/2010/10/redis-data-struct/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualize call tree of a C function</title>
		<link>http://sunng.info/blog/2010/09/visualize-call-tree-of-a-c-function/</link>
		<comments>http://sunng.info/blog/2010/09/visualize-call-tree-of-a-c-function/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 15:55:19 +0000</pubDate>
		<dc:creator>sunng</dc:creator>
				<category><![CDATA[把戏]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[dot]]></category>
		<category><![CDATA[foss]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://sunng.info/blog/2010/09/visualize-call-tree-of-a-c-function/</guid>
		<description><![CDATA[Requirement You want to visualize a call hierarchy of a C function. Solution Utilities you need are listed below: GNU cflow cflow2vcg graphviz Take &#8216;rdbSaveBackground&#8217; (redis/rdb.c) for example: cflow --format=posix --omit-arguments --level-indent='0=\t' --level-indent='1=\t' --level-indent=start='\t' -m 'rdbSaveBackground' ~/osprojects/redis/src/rdb.c &#124; cflow2dot &#124; &#8230; <a href="http://sunng.info/blog/2010/09/visualize-call-tree-of-a-c-function/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>Requirement</h3>
<p>You want to visualize a call hierarchy of a C function.</p>
<h3>Solution</h3>
<p>Utilities you need are listed below:</p>
<ul>
<li><a href="http://www.gnu.org/software/cflow/">GNU cflow</a></li>
<li><a href="http://cflow2vcg.sourceforge.net/">cflow2vcg</a></li>
<li>graphviz</li>
</ul>
<p>Take &#8216;rdbSaveBackground&#8217; (<a href="http://github.com/antirez/redis/blob/master/src/rdb.c">redis/rdb.c</a>) for example:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cflow <span style="color: #660033;">--format</span>=posix <span style="color: #660033;">--omit-arguments</span> <span style="color: #660033;">--level-indent</span>=<span style="color: #ff0000;">'0=\t'</span> <span style="color: #660033;">--level-indent</span>=<span style="color: #ff0000;">'1=\t'</span> <span style="color: #660033;">--level-indent</span>=<span style="color: #007800;">start</span>=<span style="color: #ff0000;">'\t'</span> <span style="color: #660033;">-m</span> <span style="color: #ff0000;">'rdbSaveBackground'</span> ~<span style="color: #000000; font-weight: bold;">/</span>osprojects<span style="color: #000000; font-weight: bold;">/</span>redis<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>rdb.c <span style="color: #000000; font-weight: bold;">|</span> cflow2dot <span style="color: #000000; font-weight: bold;">|</span> dot <span style="color: #660033;">-Tjpg</span> <span style="color: #660033;">-o</span> rdb.jpg</div></div>
<p>Output:<br />
<a href="http://www.flickr.com/photos/40741608@N08/5020142591/" title="visualization of a call tree by 贝小塔, on Flickr"><img src="http://farm5.static.flickr.com/4111/5020142591_7b34a52e3c.jpg" width="500" height="98" alt="visualization of a call tree" /></a></p>
<p>Source: <a href="http://unixdiary.blogspot.com/2006/05/using-cflow.html">unix diary</a></p>
<p>The post is brought to you by <a href="http://fedorahosted.org/lekhonee">lekhonee</a> v0.7</p>
]]></content:encoded>
			<wfw:commentRss>http://sunng.info/blog/2010/09/visualize-call-tree-of-a-c-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lua script for Geany to view manpage of functions</title>
		<link>http://sunng.info/blog/2010/09/lua-script-for-geany-to-view-manpage-of-functions/</link>
		<comments>http://sunng.info/blog/2010/09/lua-script-for-geany-to-view-manpage-of-functions/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 07:37:18 +0000</pubDate>
		<dc:creator>sunng</dc:creator>
				<category><![CDATA[装备]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[foss]]></category>
		<category><![CDATA[geany]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lua]]></category>

		<guid isPermaLink="false">http://sunng.info/blog/2010/09/lua-script-for-geany-to-view-manpage-of-functions/</guid>
		<description><![CDATA[Requirement When editing when Geany, you need some document of system library functions at hand. So you want to browse manpage at any time. Solution Just two lines: sel=geany.selection&#40;&#41; geany.launch&#40;'rxvt-unicode', '-e', 'man', sel&#41; http://gist.github.com/591279 Install Make sure you have geany-plugin-lua &#8230; <a href="http://sunng.info/blog/2010/09/lua-script-for-geany-to-view-manpage-of-functions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>Requirement</h3>
<p>When editing when Geany, you need some document of system library functions at hand. So you want to browse manpage at any time.</p>
<h3>Solution</h3>
<p>Just two lines:</p>
<div class="codecolorer-container lua twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="lua codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sel<span style="color: #66cc66;">=</span>geany<span style="color: #66cc66;">.</span>selection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
geany<span style="color: #66cc66;">.</span>launch<span style="color: #66cc66;">&#40;</span><span style="color: #ff6666;">'rxvt-unicode'</span><span style="color: #66cc66;">,</span> <span style="color: #ff6666;">'-e'</span><span style="color: #66cc66;">,</span> <span style="color: #ff6666;">'man'</span><span style="color: #66cc66;">,</span> sel<span style="color: #66cc66;">&#41;</span></div></div>
<p><a href="http://gist.github.com/591279">http://gist.github.com/591279</a></p>
<h3>Install</h3>
<p>Make sure you have geany-plugin-lua installed:<br />
<i>sudo apt-get install geany-plugin-lua</i></p>
<p>Create a lua source file named &#8216;ShowMan.lua&#8217; in <i>~/.config/geany/plugins/geanylua/</i>  . If the direcotry does not exist, you should create it first.</p>
<p>Copy two lines of lua code into this file, save and close.</p>
<p>Create a file named hotkeys.cfg in <i>~/.config/geany/plugins/geanylua/</i>, add following content:<br />
<i>ShowMan.lua</i></p>
<p>Restart geany, then open Preferences->Keybindings, Lua Script-> ShowMan, bind a key, for example, Alt+m</p>
<h3>Usage</h3>
<p>Select the function name, and press Alt+m (or from menu Tools->Lua Scripts->ShowMan), then you see the terminal and the manpage.</p>
<p><a href="http://www.flickr.com/photos/40741608@N08/5017060556/" title="geany-lua-manpage by 贝小塔, on Flickr"><img src="http://farm5.static.flickr.com/4127/5017060556_ca89e90517.jpg" width="500" height="313" alt="geany-lua-manpage" /></a></p>
<p>The post is brought to you by <a href="http://fedorahosted.org/lekhonee">lekhonee</a> v0.7</p>
]]></content:encoded>
			<wfw:commentRss>http://sunng.info/blog/2010/09/lua-script-for-geany-to-view-manpage-of-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GUI Debugging tools</title>
		<link>http://sunng.info/blog/2010/09/gui-debugging-tools/</link>
		<comments>http://sunng.info/blog/2010/09/gui-debugging-tools/#comments</comments>
		<pubDate>Sat, 18 Sep 2010 09:38:34 +0000</pubDate>
		<dc:creator>sunng</dc:creator>
				<category><![CDATA[装备]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[foss]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://sunng.info/blog/2010/09/gui-debugging-tools/</guid>
		<description><![CDATA[想了解一个C程序的运行，打算用gdb来单步看一下流程，发现直接用gdb不太方便，然后模仿偶像用emacs的gdb支持(M-x gdb)。但是境界实在是比不上偶像，emacs的操作都还不熟练。最后选择了geany。geany是一个简单的C/C++ IDE，它有一个geanygdb插件可以帮助你在geany的图形界面里调试。 但是最近安装在仓库里的geanygdb插件有一些问题，会导致很高的CPU占用。不过这个问题被报告在这里，现在已经修复了。因为新版本还没有release，所以如果急着用的话，可以从svn签出代码： svn co https://geany-plugins.svn.sourceforge.net/svnroot/geany-plugins/trunk/geany-plugins 然后执行： cd geany-plugins ./autogen.sh ./configure cd geanygdb make sudo make install 重启geany，打开plugin manager，看到geanygdb的版本已经变成0.20就可以使用了。 geany现在还不支持ctags，是因为它内部有一套自己的tags实现。代码导航可以用过上下文菜单 Go to tag Definition 或者 Go to tag Declaration 实现，最好是到Preference中给这两个命令设置一个快捷键，比如Ctrl+]，再对Navigate back 设置一个Ctrl+t，就如同vim+ctags一样了。 实际上在GNOME桌面还有一个专门的GDB图形界面，叫做Nemiver。Nemiver对gdb的常用命令都有快捷键操作，把鼠标移动到代码上还可以查看变量的值，效果和eclipse调试java程序一样，非常强大。 The post is brought to you &#8230; <a href="http://sunng.info/blog/2010/09/gui-debugging-tools/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>想了解一个C程序的运行，打算用gdb来单步看一下流程，发现直接用gdb不太方便，然后模仿偶像用emacs的gdb支持(M-x gdb)。但是境界实在是比不上偶像，emacs的操作都还不熟练。最后选择了geany。<a href="http://www.geany.org">geany</a>是一个简单的C/C++ IDE，它有一个geanygdb插件可以帮助你在geany的图形界面里调试。</p>
<p>但是最近安装在仓库里的geanygdb插件有一些问题，会导致很高的CPU占用。不过这个问题被报告在<a href="http://sourceforge.net/tracker/?func=detail&amp;aid=3019827&amp;group_id=222729&amp;atid=1056532">这里</a>，现在已经修复了。因为新版本还没有release，所以如果急着用的话，可以从svn签出代码：<br />
<i>svn co https://geany-plugins.svn.sourceforge.net/svnroot/geany-plugins/trunk/geany-plugins</i><br />
然后执行：</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> geany-plugins<br />
.<span style="color: #000000; font-weight: bold;">/</span>autogen.sh<br />
.<span style="color: #000000; font-weight: bold;">/</span>configure<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> geanygdb<br />
<span style="color: #c20cb9; font-weight: bold;">make</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></div></div>
<p>重启geany，打开plugin manager，看到geanygdb的版本已经变成0.20就可以使用了。</p>
<p>geany现在还不支持ctags，是因为它内部有一套自己的tags实现。代码导航可以用过上下文菜单 Go to tag Definition 或者 Go to tag Declaration 实现，最好是到Preference中给这两个命令设置一个快捷键，比如Ctrl+]，再对Navigate back 设置一个Ctrl+t，就如同vim+ctags一样了。</p>
<p>实际上在GNOME桌面还有一个专门的GDB图形界面，叫做<a href="http://projects.gnome.org/nemiver/">Nemiver</a>。Nemiver对gdb的常用命令都有快捷键操作，把鼠标移动到代码上还可以查看变量的值，效果和eclipse调试java程序一样，非常强大。</p>
<p>The post is brought to you by <a href="http://fedorahosted.org/lekhonee">lekhonee</a> v0.7</p>
]]></content:encoded>
			<wfw:commentRss>http://sunng.info/blog/2010/09/gui-debugging-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python读取二进制文件</title>
		<link>http://sunng.info/blog/2009/02/python%e8%af%bb%e5%8f%96%e4%ba%8c%e8%bf%9b%e5%88%b6%e6%96%87%e4%bb%b6/</link>
		<comments>http://sunng.info/blog/2009/02/python%e8%af%bb%e5%8f%96%e4%ba%8c%e8%bf%9b%e5%88%b6%e6%96%87%e4%bb%b6/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 10:36:22 +0000</pubDate>
		<dc:creator>sunng</dc:creator>
				<category><![CDATA[手艺]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.classicning.com/blog/?p=10</guid>
		<description><![CDATA[Python里虽然可以通过&#8217;b'的标记来区别普通文件和二进制文件，但是依然是把二进制文件当作普通文本处理。要读写二进制文件，需要用struct库来作pack和unpack。 比如我最近拿到一个如下数据结构的二进制文件 [codesyntax lang="c" lines="fancy"] struct DEMTYPE { int row; int col; float xmin; float ymin; float xmax; float ymax; float size; float vmin; float vmax; float scale; float *data; }; [/codesyntax] 其中data是一个长度为row*col的数组。要读取这样一个二进制文件，可以用这样的代码 [codesyntax lang="python" lines="fancy"] row, col, xmin, ymin, &#8230; <a href="http://sunng.info/blog/2009/02/python%e8%af%bb%e5%8f%96%e4%ba%8c%e8%bf%9b%e5%88%b6%e6%96%87%e4%bb%b6/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Python里虽然可以通过&#8217;b'的标记来区别普通文件和二进制文件，但是依然是把二进制文件当作普通文本处理。要读写二进制文件，需要用struct库来作pack和unpack。</p>
<p>比如我最近拿到一个如下数据结构的二进制文件</p>
<p>[codesyntax lang="c" lines="fancy"]<br />
struct DEMTYPE {<br />
	int row;<br />
	int col;<br />
	float xmin;<br />
	float ymin;<br />
	float xmax;<br />
	float ymax;<br />
	float size;<br />
	float vmin;<br />
	float vmax;<br />
	float scale;<br />
	float *data;<br />
};<br />
[/codesyntax]</p>
<p>其中data是一个长度为row*col的数组。要读取这样一个二进制文件，可以用这样的代码<br />
[codesyntax lang="python" lines="fancy"]<br />
row, col, xmin, ymin, xmax, ymax, size, vmin, vmax, scale = \<br />
        struct.unpack(&#8216;&lt;2i8f&#8217;, datastring[:(4*2+4*8)])<br />
vdata = struct.unpack(&#8216;&lt;&#8217;+str(row*col)+&#8217;f', datastring[(4*2+4*8):])<br />
[/codesyntax]<br />
核心是unpack的第一个参数，用来标识二进制数据的格式，其中&lt;表示little-endian，i表示整型数，f表示单精度浮点数，数字是量词。</p>
<p>更详细的说明可以看manual：<br />
<a href="http://docs.python.org/library/struct.html" target="_blank">http://docs.python.org/library/struct.html</a></p>
<p>好吧，我承认我写这个是来测试highlight插件的。</p>
]]></content:encoded>
			<wfw:commentRss>http://sunng.info/blog/2009/02/python%e8%af%bb%e5%8f%96%e4%ba%8c%e8%bf%9b%e5%88%b6%e6%96%87%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

