<?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>Chunhao&#039;s Blog &#187; programming</title>
	<atom:link href="http://chunhao.net/blog/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://chunhao.net/blog</link>
	<description>Life happens. Love helps.</description>
	<lastBuildDate>Fri, 28 May 2021 12:36:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Tools for Reading Sources</title>
		<link>http://chunhao.net/blog/tools-for-reading-sources/</link>
		<comments>http://chunhao.net/blog/tools-for-reading-sources/#comments</comments>
		<pubDate>Thu, 21 May 2009 11:39:17 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Doxygen]]></category>
		<category><![CDATA[LXR]]></category>
		<category><![CDATA[LXRng]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[Source Navigator]]></category>

		<guid isPermaLink="false">http://chunhao.net/blog/?p=88</guid>
		<description><![CDATA[Hacking is a good method of learning. And the pre-stage of hacking is reading the source code. You might have this experience: facing a large amount of source code (generally dozens of files), you don&#8217;t know how to start, or you even don&#8217;t know how to read them. A good tool is very helpful for [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Hacking is a good method of learning. And the pre-stage of hacking is reading the source code. You might have this experience: facing a large amount of source code (generally dozens of files), you don&#8217;t know how to start, or you even don&#8217;t know how to read them. A good tool is very helpful for reading code. It can facilitate your understanding of the code and help you find out the things you want as soon as possible. I will introduce you some wonderful tools of browsing sources.</p>
<p>For me, the must-have feathers of a source browsing tool should be:</p>
<ol>
<li>Syntax highlighting</li>
<li>Friendly user interface</li>
<li>Identifier and function search</li>
</ol>
<p>If you are a Windows user, you might have heard about Source Insight, which is a non-free software. I haven&#8217;t used it, so I am not going to comment it.</p>
<p>For Linux user, the first tool I want to mention is <a href="http://sourcenav.sourceforge.net/">Source Navigator</a>. It is developed and supported by Red hat. It supports C, C++, Java, Tcl, FORTRAN and COBOL. It&#8217;s very powerful. But if you just want to browse sources, I don&#8217;t recommend you to use it. Since it GUI is developed in Tcl, an ancient programming language, the user interface is not very friendly. I bet you don&#8217;t like it.</p>
<p>Another wonderful software is <a href="http://www.doxygen.org">Doxygen</a>. Although it aims to generate documents various programming languages, including C++, C, Java, Objective-C, Python, IDL (Corba and Microsoft flavors), Fortran, VHDL, PHP, C#, and to some extent D, you can treat it as a source browsing tool. It can generate documents in HTML format. So you can read them via Firefox. If the source code is well commented following JavaDoc&#8217;s style, a beautiful documents describing classes, variables, functions could be generated. If the source code is not commented in JavaDoc&#8217;s style, the documents could also be generated, but it just have source codes, without these detailed description about classes, variables, and functions. Doxygen can also generate class-graphs, call-graphs and other similar graphs in UML style, which will help you understand the source.</p>
<p>The disadvantage of Doxygen is that its search result is somehow coarse-grained. It cannot distinguish variables from functions in search result. And it cannot differentiate definition, declaration and reference. So, if you are dealing with a huge project, you may find it uncomfortable to read source generated by Doxygen.</p>
<p>The ultimate tool, in my view, is <a href="http://sourceforge.net/projects/lxr">LXR</a>, which stand for Linux Corss Referencer. Specially, it may be the best choice for you to read Linux source code. Although, namely, LXR aim for Linux source code, it suitable for other projects written in C/C++, COBOL, Java, Perl. It is a web based tool and you can read the source code via Firefox. It uses a database to management cross references. So the search result is very accurate. And it can differentiate definition, declaration and reference.</p>
<p>LXR is famous for its difficulty on setup and configuration. And its user interface cannot be called &#8220;beautiful&#8221;. Luckily, the next generation, <a href="http://lxr.linux.no/">LXRng</a> (<a href="http://lxr.linux.no/linux">demo</a>) is available now. LXRng has a very beautiful and friendly user interface.  Moreover, setup and configuration for LXRng is much simpler than LXR. However, it seems that LXRng currently only support C language. If you need it for C++, you need a slight hack:</p>
<p>Locate to your LXRng&#8217;s installation directory, then open this file:</p>
<blockquote><p>lib/LXRng/Lang/C.pm</p></blockquote>
<p>Find the following code from this file:</p>
<pre lang="perl">sub pathexp {
    return qr/.[ch]$/;
}</pre>
<p>And change it into:</p>
<pre lang="perl">sub pathexp {
    return qr/.[ch]$|.cpp$/;
}</pre>
<p>Then LXRng should support the C++ files.</p>
<p>Doxygen and LXRng could satisfy most of your requirement. Maybe reading source from Firefox is strange and unfamiliar to you, but I think you will going to like it if you just have a try. If you have no idea about how to use them, just go to their websites, where you can find plenty of documents and toturials.</p>
]]></content:encoded>
			<wfw:commentRss>http://chunhao.net/blog/tools-for-reading-sources/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Unify the themes</title>
		<link>http://chunhao.net/blog/unify-the-themes/</link>
		<comments>http://chunhao.net/blog/unify-the-themes/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 15:02:45 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[other]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://chunhao.net/blog/?p=55</guid>
		<description><![CDATA[My site is based on various applications. The blog is based on WordPress, the wiki is based on Dokuwiki, the photo gallery the Simpleviewer. Other pages are written by hand. Originally, each part had its own theme. It&#8217;s hard to acces other parts directly from one part. For example, there are no links from my [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>My site is based on various applications. The blog is based on <a href="http://wordpress.org">WordPress</a>, the <a href="http://chunhao.net/wiki">wiki</a> is based on <a href="http://www.dokuwiki.org">Dokuwiki</a>, the photo gallery the <a href="http://www.airtightinteractive.com/simpleviewer/">Simpleviewer</a>. Other pages are written by hand.</p>
<p>Originally, each part had its own theme. It&#8217;s hard to acces other parts directly from one part. For example, there are no links from my blog or wiki to my homepage. I decided to change this. Eventually, the goal is achieved.</p>
<p>The theme of my blog is <a href="http://www.livetr.org/blue-pix/">blue-pix</a>. I like it for its briefness. The first thing I did is to port this theme on my home page. This work is pretty simple. I only changed the tags of the CSS file. Then, I modified the blog&#8217;s theme, added a link to homepage. The themes of homepage and blog was unified.</p>
<p>Next thing is my wiki. I have no idea about how to create template on dokuwiki at the beginning. When I refered to <a href="http://www.dokuwiki.org/devel:templates">this link</a>, I started my work. I did a lot of change on CSS and PHP files. Finally, my own template of dokuwiki was created. Now the themes of the whole site is unified, except for the photo gallery.</p>
<p>For the blog&#8217;s theme, blue-pix, I also did lots of modification. The originally version did not support widget, and it did not support Google Analytics and other things. It also did not support thread comments. Now, it works fine. If you are interested in this theme, just feel free to contact me.</p>
<p>I am not an expert on PHP, CSS, and HTML. However, I like hacking. All the problems are solved with the help of Google. I believe one sentence&#8211;don&#8217;t learn to hack, just hack to learn.</p>
<p>&#8212;&#8212;&#8212;&#8211;</p>
<p>Supplement:</p>
<p>Just now, I finished the modification of my <a href="http://chunhao.net/photos/">photo gallery</a>. Now, everything in my site are following the same theme!</p>
]]></content:encoded>
			<wfw:commentRss>http://chunhao.net/blog/unify-the-themes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to connect vim with gdb — using clewn</title>
		<link>http://chunhao.net/blog/how-to-connect-vim-with-gdb-using-clewn/</link>
		<comments>http://chunhao.net/blog/how-to-connect-vim-with-gdb-using-clewn/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 05:22:40 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://chunhao86.cn/blog/?p=6</guid>
		<description><![CDATA[First, I will show you the screen shot The screen of vim is divide into two sub windows, the top one can display the code and the bottom one shows the variable you want to watch. Well, this can be changed by you, you can split the window any way you like. You can use [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a title="screenshot3.png" href="http://chunhao.net/blog/wp-content/uploads/2008/03/screenshot3.png"><img src="http://chunhao.net/blog/wp-content/uploads/2008/03/screenshot3.thumbnail.png" alt="screenshot3.png" /></a></p>
<p><span class="postbody">First, I will show you the screen shot</span> The screen of vim is divide into two sub windows, the top one can display the code and the bottom one shows the variable you want to watch.  Well, this can be changed by you, you can split the window any way you like.  You can use C-B to make a break, and press R to run your program, and press S to step, and C-J to add the variable you want to watch. <span class="postbody"> You can download clewn here:</span></p>
<blockquote><p><span class="postbody"><a href="http://clewn.sourceforge.net/" target="_blank">http://clewn.sourceforge.net/</a></span></p></blockquote>
<p>How to install:  <span class="postbody">first of all, you should have your gvim installed,</span></p>
<blockquote>
<p align="left">sudo apt-get install vim-gnome</p>
</blockquote>
<p><span class="postbody">as well as gdb</span> And then download the source file of clewn; note here, not vimgdb.  And extract the file, then use your terminal to enter the clewn folder</p>
<blockquote><p>./configure make sudo make install</p></blockquote>
<p>Note here, may be some one will be suffered from the dependency problem during their installing. If your machine tell you that you need readline, then install libreadline5-dev</p>
<blockquote><p>sudo apt-get install libreadline5-dev</p></blockquote>
<p><span class="postbody"> And then, copy some files to ~/.vim you can refer my folder:</span></p>
<blockquote><p>cp /usr/local/share/vim/vimfiles/clewn.vim ~/.vim/plugin/</p>
<p>cp /usr/local/share/vim/vimfiles/doc/clewn.txt ~/.vim/doc/</p>
<p>cp /usr/local/share/vim/vimfiles/macros/clewn_mappings.vim ~/.vim/macros/</p>
<p>cp /usr/local/share/vim/vimfiles/syntax/gdbvar.vim ~/.vim/syntax/</p></blockquote>
<p>Then, every thing is done. You can write a small program to test.</p>
<pre lang="c">#include 

int main(int argc, char *argv[]) {
  int i;
  int s;
  s = 0;
  for (i = 0; i &lt; 10; ++i) {
    s = s + 1;
  }
}</pre>
<p><span class="postbody"> Save it as test.c , for example. And then,</span></p>
<blockquote><p>gcc -g -o test test.c</p></blockquote>
<p>If everything is right during compiling, then</p>
<blockquote><p>clewn -va test.c</p></blockquote>
<p><span class="postbody">Then, gdb is opened on your terminal, and your gvim is opened at the same time</span> Cool down now; input the following on your terminal(gdb):</p>
<blockquote><p>file test</p></blockquote>
<p>Now, you can debug your program on gvim.  <span class="postbody">For example, you can click the line you want to set break point. And then press CTRL+B, then, break point is set.</span> SHIFT+r（that is capital R）It will run and stop at your break point SHIFT+s（that is capital S）It will step And watch your variable, input following on gvim</p>
<blockquote><p>:split</p></blockquote>
<p><span class="postbody">Then the window will be split, and then click the variable you want to watch, and press C+J, then you can see the variable appears in another window.</span> <span class="postbody">To do this, you also can input the following on your terminal(gdb)</span></p>
<blockquote><p>createvar yourvar</p></blockquote>
<p>&#8220;youvar&#8221; represents the variable you want to watch.  Following is the default shortcuts</p>
<p>List of default key mappings:</p>
<blockquote>
<pre><span class="Special">        CTRL-Z</span>  send an interrupt to GDB and the program it is running
        B       info breakpoints
        L       info locals
        A       info args
        S       step
        I       stepi
        <span class="Special">CTRL-N</span>  next: next source line, skipping all function calls
        X       nexti
        F       finish
        R       run
        Q       quit
        C       continue
        W       where
        <span class="Special">CTRL-U</span>  up: go up one frame
        <span class="Special">CTRL-D</span>  down: go down one frame

<span class="PreProc">cursor position:</span><span class="Ignore"> ~</span>
        <span class="Special">CTRL-B</span>  set a breakpoint on the line where the cursor is located
        <span class="Special">CTRL-E</span>  clear all breakpoints on the line where the cursor is located

<span class="PreProc">mouse pointer position:</span><span class="Ignore"> ~</span>
        <span class="Special">CTRL-P</span>  print the value of the variable defined by the mouse pointer
                position
        <span class="Special">CTRL-X</span>  print the value that is referenced by the address whose
                value is that of the variable defined by the mouse pointer
                position
        <span class="Special">CTRL-K</span>  set a breakpoint at assembly address shown by mouse position
        <span class="Special">CTRL-H</span>  clear a breakpoint at assembly address shown by mouse position
        <span class="Special">CTRL-J</span>  add the selected variable at mouse position to the watched
                variables window</pre>
</blockquote>
<p>This is referred the official document, which is available here</p>
<blockquote><p><a href="http://clewn.sourceforge.net/" target="_blank"></a><a href="http://clewn.sourceforge.net/doc.html" target="_blank">http://clewn.sourceforge.net/doc.html</a></p></blockquote>
<p>Hope this will help you somewhat. If you have some new or better idea, please contact me.  chunhao86@gmail.com  Thanks</p>
]]></content:encoded>
			<wfw:commentRss>http://chunhao.net/blog/how-to-connect-vim-with-gdb-using-clewn/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
