<?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/"
	>

<channel>
	<title>闪灵屋</title>
	<atom:link href="http://blog.esuraid.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.esuraid.com</link>
	<description>夙睿德团队(SuRaid)的技术博客</description>
	<pubDate>Fri, 11 Dec 2009 10:38:54 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>IAR STM32: Failed to load flash loader的问题</title>
		<link>http://blog.esuraid.com/index.php/2009/12/iar-stm32-failed-to-load-flash-loader%e7%9a%84%e9%97%ae%e9%a2%98/</link>
		<comments>http://blog.esuraid.com/index.php/2009/12/iar-stm32-failed-to-load-flash-loader%e7%9a%84%e9%97%ae%e9%a2%98/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 10:38:48 +0000</pubDate>
		<dc:creator>lyg</dc:creator>
		
		<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://blog.esuraid.com/?p=467</guid>
		<description><![CDATA[ 
其出错码包括:
The debugging session could not be started.
Either the debugger initialization failed,or else the file
&#8230;&#8230;was corrupt or of an unsupported format.There might be more information in the Debug Log window
http://www.manley.com.cn/web/Service.asp
原因可能不一样,我碰到的是当我从从mainley下载其演示程序后（5.30版本），在IAR5.30.1版本上运行时出现的错误。
需要在其debug选项中将driver由st_link改成Third-party driver。然后在third-party driver选项卡中将IAR debuger driver关联到STM32DriverV5.dll(比如我的：C:\Manley\Drivers\STLink\STM32DriverV5.dll）
重新编译即可。
希望对遇到相似情况的人有所帮助

&#160;
]]></description>
			<content:encoded><![CDATA[<p><span class="Apple-style-span" style="font-family: Arial; line-height: 18px; "> </span></p>
<div class="date" style="font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: 18px; margin-top: 5px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; color: rgb(102, 102, 102); "><span class="Apple-style-span" style="color: rgb(0, 0, 0); "><span class="Apple-style-span" style="line-height: normal; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: medium;"><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-size: 14px; line-height: 20px; ">其出错码包括:<br style="line-height: normal; " /></p>
<p style="line-height: normal; ">The debugging session could not be started.</p>
<p style="line-height: normal; ">Either the debugger initialization failed,or else the file</p>
<p style="line-height: normal; ">&#8230;&#8230;was corrupt or of an unsupported format.There might be more information in the Debug Log window</p>
<p style="line-height: normal; "><a href="http://www.manley.com.cn/web/Service.asp">http://www.manley.com.cn/web/Service.asp</a></p>
<p style="line-height: normal; ">原因可能不一样,我碰到的是当我从从mainley下载其演示程序后（5.30版本），在IAR5.30.1版本上运行时出现的错误。</p>
<p style="line-height: normal; ">需要在其debug选项中将driver由st_link改成Third-party driver。然后在third-party driver选项卡中将IAR debuger driver关联到STM32DriverV5.dll(比如我的：C:\Manley\Drivers\STLink\STM32DriverV5.dll）</p>
<p style="line-height: normal; ">重新编译即可。</p>
<p style="line-height: normal; ">希望对遇到相似情况的人有所帮助</p>
<p></span></span></span></div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.esuraid.com/index.php/2009/12/iar-stm32-failed-to-load-flash-loader%e7%9a%84%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
		</item>
		<item>
		<title>使用新版本Python(&gt;=2.6)可能遇到如下错误，在动态链接的时候，ERROR: Failure: ImportError (DLL load failed: 找不到指定的模块。)</title>
		<link>http://blog.esuraid.com/index.php/2009/08/pythondllhell/</link>
		<comments>http://blog.esuraid.com/index.php/2009/08/pythondllhell/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 09:29:23 +0000</pubDate>
		<dc:creator>lyg</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<category><![CDATA[未分类]]></category>

		<category><![CDATA[编程语言]]></category>

		<category><![CDATA[dll]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[failure]]></category>

		<category><![CDATA[load]]></category>

		<category><![CDATA[模块，找不到]]></category>

		<guid isPermaLink="false">http://blog.suraid.cn/index.php/2009/08/%e4%bd%bf%e7%94%a8%e6%96%b0%e7%89%88%e6%9c%acpython26%e5%8f%af%e8%83%bd%e9%81%87%e5%88%b0%e5%a6%82%e4%b8%8b%e9%94%99%e8%af%af%ef%bc%8c%e5%9c%a8%e5%8a%a8%e6%80%81%e9%93%be%e6%8e%a5%e7%9a%84/</guid>
		<description><![CDATA[ERROR: Failure: ImportError (DLL load failed: 找不到指定的模块。)
&#160;
如果遇到此种之错误，或是类似，那么
Traceback (most recent call last):   
&#160; File &#34;D:\Tools\Building\Python\lib\site-packages\nose-0.11.1-py2.6.egg\nose\loader.py&#34;, line 379, in loadTestsF    
&#160;&#160;&#160; addr.filename, addr.module)    
&#160; File &#34;D:\Tools\Building\Python\lib\site-packages\nose-0.11.1-py2.6.egg\nose\importer.py&#34;, line 39, in importFro    
&#160;&#160;&#160; return self.importFromDir(dir_path, fqname)    
&#160; File &#34;D:\Tools\Building\Python\lib\site-packages\nose-0.11.1-py2.6.egg\nose\importer.py&#34;, line 86, in importFro   [...]]]></description>
			<content:encoded><![CDATA[<p>ERROR: Failure: ImportError (DLL load failed: 找不到指定的模块。)</p>
<p>&nbsp;</p>
<p>如果遇到此种之错误，或是类似，那么</p>
<p>Traceback (most recent call last):   <br />
&nbsp; File &quot;D:\Tools\Building\Python\lib\site-packages\nose-0.11.1-py2.6.egg\nose\loader.py&quot;, line 379, in loadTestsF    <br />
&nbsp;&nbsp;&nbsp; addr.filename, addr.module)    <br />
&nbsp; File &quot;D:\Tools\Building\Python\lib\site-packages\nose-0.11.1-py2.6.egg\nose\importer.py&quot;, line 39, in importFro    <br />
&nbsp;&nbsp;&nbsp; return self.importFromDir(dir_path, fqname)    <br />
&nbsp; File &quot;D:\Tools\Building\Python\lib\site-packages\nose-0.11.1-py2.6.egg\nose\importer.py&quot;, line 86, in importFro    <br />
&nbsp;&nbsp;&nbsp; mod = load_module(part_fqname, fh, filename, desc)    <br />
&nbsp; File &quot;D:\svn\hgsubversion\tests\test_fetch_renames.py&quot;, line 4, in &lt;module&gt;    <br />
&nbsp;&nbsp;&nbsp; import test_util    <br />
&nbsp; File &quot;D:\svn\hgsubversion\tests\test_util.py&quot;, line 20, in &lt;module&gt;    <br />
&nbsp;&nbsp;&nbsp; from hgsubversion import util    <br />
&nbsp; File &quot;D:\svn\hgsubversion\hgsubversion\__init__.py&quot;, line 40, in &lt;module&gt;    <br />
&nbsp;&nbsp;&nbsp; from svn import core    <br />
&nbsp; File &quot;D:\Tools\Building\Python\lib\site-packages\svn\core.py&quot;, line 19, in &lt;module&gt;    <br />
&nbsp;&nbsp;&nbsp; from libsvn.core import *    <br />
&nbsp; File &quot;D:\Tools\Building\Python\lib\site-packages\libsvn\core.py&quot;, line 5, in &lt;module&gt;</p>
<p>ERROR: Failure: ImportError (DLL load failed: 找不到指定的模块。)</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>比如此时，最后一条语句</p>
<p>&nbsp; File &quot;D:\Tools\Building\Python\lib\site-packages\libsvn\core.py&quot;, line 5, in &lt;module&gt;</p>
<p>表明当中的dll文件找不到，一般是不小心吧不应该命名成pyd的文件命名成了pyd。</p>
<p>&nbsp;</p>
<p>比如当前libsvn下包含了如下文件</p>
<p>卷序列号为 284E-138E   <br />
D:.    <br />
&nbsp;&nbsp;&nbsp; client.py    <br />
&nbsp;&nbsp;&nbsp; client.pyc    <br />
&nbsp;&nbsp;&nbsp; core.py    <br />
&nbsp;&nbsp;&nbsp; core.pyc    <br />
&nbsp;&nbsp;&nbsp; delta.py    <br />
&nbsp;&nbsp;&nbsp; delta.pyc    <br />
&nbsp;&nbsp;&nbsp; diff.py    <br />
&nbsp;&nbsp;&nbsp; fs.py    <br />
&nbsp;&nbsp;&nbsp; libsvn_swig_py-1.dll    <br />
&nbsp;&nbsp;&nbsp; ra.py    <br />
&nbsp;&nbsp;&nbsp; ra.pyc    <br />
&nbsp;&nbsp;&nbsp; repos.py    <br />
&nbsp;&nbsp;&nbsp; wc.py    <br />
&nbsp;&nbsp;&nbsp; wc.pyc    <br />
&nbsp;&nbsp;&nbsp; _client.pyd    <br />
&nbsp;&nbsp;&nbsp; _core.pyd    <br />
&nbsp;&nbsp;&nbsp; _delta.pyd    <br />
&nbsp;&nbsp;&nbsp; _diff.pyd    <br />
&nbsp;&nbsp;&nbsp; _fs.pyd    <br />
&nbsp;&nbsp;&nbsp; _ra.pyd    <br />
&nbsp;&nbsp;&nbsp; _repos.pyd    <br />
&nbsp;&nbsp;&nbsp; _wc.pyd    <br />
&nbsp;&nbsp;&nbsp; __init__.py    <br />
&nbsp;&nbsp;&nbsp; __init__.pyc</p>
<p>&nbsp;</p>
<p>这个是可以正常运行的文件结构</p>
<p>其中.pyd文件结尾的文件其实均是dll文件，只是rename了</p>
<p>但是为何&nbsp;&nbsp;&nbsp; libsvn_swig_py-1.dll却没有重命名呢？</p>
<p>这里是有一个问题在里面的。。</p>
<p>首先。凡是已pyd 文件结尾为的都是.py文件里面直接import的</p>
<p>比如_core.pyd 在 core.py 里面有 import _core 这样的语句</p>
<p>而所有dll文件是不会直接被python调用的，所以必须添加到PATH路径里面，就是说只能够间接被.pyd文件应用，而不能直接被.pyd直接引用。</p>
<p>&nbsp;</p>
<p>因此，如果下载的包中，诸如_core.dll _fs.dll 这种以_开头的大约是要被py文件引用的，所以要重命名为.pyd文件</p>
<p>而诸如libsvn_swig_py-1.dll文件则不能命名为.pyd文件后缀，同时这些文件所处的路径要添加到PATH中，否则会找不到。。</p>
<p>&nbsp;</p>
<p><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "></p>
<p>还有一个重要问题，就是程序的位不匹配，比如32为之于64为，这也是要重点考虑的，所以</p>
<p>在这种情况之下，要使用32位的，因为很多app都没有64位版本。。。。。</p>
<p>除非可以确定整个程序链都是64位的，这样才可以使用64位的程序</p>
<p>比如我就在这里遇到麻烦了，我用的subversion是64位的，python是64为的，</p>
<p>可是有一个东西不是，那就是subversion python bind 不是，所以无法正常的运行，也会出现这种load错误</p>
<p>就是说动态链接库也要是64位的才能够正常工作，dll hell</p>
<p></span></p>
<p>综上所述，就是这样子了。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.esuraid.com/index.php/2009/08/pythondllhell/feed/</wfw:commentRss>
		</item>
		<item>
		<title>人性化的emacs shortcut</title>
		<link>http://blog.esuraid.com/index.php/2009/08/%e4%ba%ba%e6%80%a7%e5%8c%96%e7%9a%84emacs-shortcut/</link>
		<comments>http://blog.esuraid.com/index.php/2009/08/%e4%ba%ba%e6%80%a7%e5%8c%96%e7%9a%84emacs-shortcut/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 15:21:49 +0000</pubDate>
		<dc:creator>lyg</dc:creator>
		
		<category><![CDATA[emacs]]></category>

		<category><![CDATA[未分类]]></category>

		<category><![CDATA[编辑器]]></category>

		<category><![CDATA[binding]]></category>

		<category><![CDATA[modern]]></category>

		<category><![CDATA[shortcuts]]></category>

		<category><![CDATA[shortuct]]></category>

		<category><![CDATA[standard]]></category>

		<category><![CDATA[win32]]></category>

		<category><![CDATA[Windows]]></category>

		<category><![CDATA[xemacs]]></category>

		<category><![CDATA[人性化]]></category>

		<category><![CDATA[大都来用]]></category>

		<category><![CDATA[好用]]></category>

		<category><![CDATA[常用]]></category>

		<category><![CDATA[快捷键]]></category>

		<category><![CDATA[标准]]></category>

		<category><![CDATA[通用]]></category>

		<guid isPermaLink="false">http://blog.suraid.cn/index.php/2009/08/%e4%ba%ba%e6%80%a7%e5%8c%96%e7%9a%84emacs-shortcut/</guid>
		<description><![CDATA[http://code.google.com/p/ergoemacs
&#160;
这个网页上有这个快捷键模版
]]></description>
			<content:encoded><![CDATA[<p><a title="http://code.google.com/p/ergoemacs" href="http://code.google.com/p/ergoemacs">http://code.google.com/p/ergoemacs</a></p>
<p>&nbsp;</p>
<p>这个网页上有这个快捷键模版</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.esuraid.com/index.php/2009/08/%e4%ba%ba%e6%80%a7%e5%8c%96%e7%9a%84emacs-shortcut/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C++中不可继承的类</title>
		<link>http://blog.esuraid.com/index.php/2009/08/orphan-class/</link>
		<comments>http://blog.esuraid.com/index.php/2009/08/orphan-class/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 14:43:00 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
		
		<category><![CDATA[C/C++]]></category>

		<category><![CDATA[原创]]></category>

		<category><![CDATA[编程语言]]></category>

		<category><![CDATA[class]]></category>

		<guid isPermaLink="false">http://blog.suraid.cn/index.php/2009/08/orphan-class/</guid>
		<description><![CDATA[如何让C++中的类变得不可继承呢？最笨的办法就是人为约定喽~呵呵~再仔细想一想可能会想到如下用法：

class A
&#123;
private:
    A&#40;&#41;&#123;&#125;
public:
    static A * Create&#40;&#41;;
&#125;;

这有点像singleton的使用方法，但是这种模式用在不可继承的类上面就显得有点不伦不类了。我甚至还见有人用template来实现这个，真是鸡肋鸡肋。。。下面介绍两种方法，个人觉得还是比较漂亮的~（以下代码就懒的讲解了，大家自己看吧） 

class COrphanTag
&#123;
protected:
    COrphanTag&#40;&#41;&#123;&#125;
&#125;;
&#160;
class COnly : private virtual COrphanTag
&#123;
public:
    COnly&#40;&#41;&#123;&#125;
&#125;;
&#160;
class CMore : public COnly
&#123;
public:
    CMore&#40;&#41;&#123;&#125;
&#125;;
&#160;
int main&#40;void&#41;
&#123;
    COnly only;
    return 0;
&#125;

但是这个程序在VC6下是可以正常编译通过的，哎，没办法，必须顺着微软来啊，那我们再改改： 

class COnly;
class COrphanTag
&#123;
private:
    COrphanTag&#40;&#41;&#123;&#125;
  [...]]]></description>
			<content:encoded><![CDATA[<p>如何让C++中的类变得不可继承呢？最笨的办法就是人为约定喽~呵呵~再仔细想一想可能会想到如下用法：</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> A
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
    A<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    <span style="color: #0000ff;">static</span> A <span style="color: #000040;">*</span> Create<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>这有点像singleton的使用方法，但是这种模式用在不可继承的类上面就显得有点不伦不类了。我甚至还见有人用template来实现这个，真是鸡肋鸡肋。。。下面介绍两种方法，个人觉得还是比较漂亮的~（以下代码就懒的讲解了，大家自己看吧） </p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> COrphanTag
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
    COrphanTag<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">class</span> COnly <span style="color: #008080;">:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">virtual</span> COrphanTag
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    COnly<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">class</span> CMore <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> COnly
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    CMore<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    COnly only<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>但是这个程序在VC6下是可以正常编译通过的，哎，没办法，必须顺着微软来啊，那我们再改改： </p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> COnly<span style="color: #008080;">;</span>
<span style="color: #0000ff;">class</span> COrphanTag
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
    COrphanTag<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">friend</span> <span style="color: #0000ff;">class</span> COnly<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">class</span> COnly <span style="color: #008080;">:</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">virtual</span> COrphanTag
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    COnly<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">class</span> CMore <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> COnly
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    CMore<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    COnly only<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>嗯，这样就可以了，大家都能成功的报错了吧~但是如果有人使用如下的多继承那就无语了： </p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> CMore <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> COnly, <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">virtual</span> COrphanTag
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    CMore<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>毕竟C++没有JAVA中final那种东西啊。。。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.esuraid.com/index.php/2009/08/orphan-class/feed/</wfw:commentRss>
		</item>
		<item>
		<title>likely,unlikely宏与GCC内建函数__builtin_expect()</title>
		<link>http://blog.esuraid.com/index.php/2009/06/gcc-likely/</link>
		<comments>http://blog.esuraid.com/index.php/2009/06/gcc-likely/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 12:41:44 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[转载]]></category>

		<category><![CDATA[gcc]]></category>

		<category><![CDATA[likely]]></category>

		<category><![CDATA[unlikely]]></category>

		<guid isPermaLink="false">http://blog.suraid.cn/index.php/2009/06/gcc-likely/</guid>
		<description><![CDATA[在读linux/kernel/fork.c的时候遇到了unlikely宏定义，一路追踪，最后找到了GCC内建函数__builtin_expect(),查阅GCC手册，发现其定义如下： 
long __builtin_expect (long exp, long c)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [Built-in Function]    You may use __builtin_expect to provide the compiler with branch prediction    information. In general, you should prefer to use actual profile feedback for this    (‘-fprofile-arcs’), as programmers are notoriously bad at predicting how their    [...]]]></description>
			<content:encoded><![CDATA[<p>在读linux/kernel/fork.c的时候遇到了unlikely宏定义，一路追踪，最后找到了GCC内建函数__builtin_expect(),查阅GCC手册，发现其定义如下： </p>
<p><strong>long __builtin_expect (long exp, long c)</strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [Built-in Function]    <br />You may use __builtin_expect to provide the compiler with branch prediction    <br />information. In general, you should prefer to use actual profile feedback for this    <br />(‘-fprofile-arcs’), as programmers are notoriously bad at predicting how their    <br />programs actually perform. However, there are applications in which this data is    <br />hard to collect.    <br />The return value is the value of exp, which should be an integral expression. The    <br />value of c must be a compile-time constant. The semantics of the built-in are that it    <br />is expected that exp == c. For example:    <br />if (__builtin_expect (x, 0))    <br />foo ();    <br />would indicate that we do not expect to call foo, since we expect x to be zero. Since    <br />you are limited to integral expressions for exp, you should use constructions such as    <br />if (__builtin_expect (ptr != NULL, 1))    <br />error ();    <br />when testing pointer or floating-point values. </p>
<p>大致是说，由于大部分程序员在分支预测方面做得很糟糕，所以GCC提供了这个内建函数来帮助程序员处理分支预测，优化程序。其第一个参数exp为一个整型表达式，这个内建函数的返回值也是这个exp,而c为一个编译期常量，这个函数的语义是：你期望exp表达式的值等于常量c，从而GCC为你优化程序，将符合这个条件的分支放在合适的地方。 </p>
<p>因为这个程序只提供了整型表达式，所以如果你要优化其他类型的表达式，可以采用指针的形式。 </p>
<p>unlikely的定义如下： </p>
<p>#define unlikely(x)&#160; __builtin_expect(!!(x), 0) </p>
<p>也就是说我们期望表达式x的值为0，从而如果我们用 </p>
<p>……. </p>
<p>if(unlikely(x)){ </p>
<p>bar(); </p>
<p>}   <br />来测试条件的话，我们就不期望bar()函数执行，所以该宏的名字用unlikely也就是不太可能来表示。 </p>
<p>likely宏与次类似. </p>
<p>说到底__builtin_expect函数就是为了优化可能性大的分支程序。 </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.esuraid.com/index.php/2009/06/gcc-likely/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CUnit使用简介</title>
		<link>http://blog.esuraid.com/index.php/2009/06/cunit/</link>
		<comments>http://blog.esuraid.com/index.php/2009/06/cunit/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 08:17:00 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
		
		<category><![CDATA[CUnit]]></category>

		<category><![CDATA[原创]]></category>

		<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://blog.suraid.cn/index.php/2009/06/cunit/</guid>
		<description><![CDATA[一、介绍
继Junit CppUnit的成功后， c语言环境下也出现了开发源码的白盒测试用例CUnit。CUnit以静态库的形式提供给用户使用，用户编写程序的时候直接链接此静态库就可以了。它提供了一个简单的单元测试框架，并且为常用的数据类型提供了丰富的断言语句支持。
二、结构框架
在CUnit的主页上可以看到对他结构的简单描述
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Test Registry    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#124;    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#124;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#124;    &#160;&#160;&#160;&#160;&#160; Suite &#8216;1&#8242;&#160;&#160;&#160;&#160;&#160; . . . .&#160;&#160;&#160;&#160;&#160;&#160; Suite &#8216;N&#8217;    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#124;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#124;    &#160;&#160; &#8212;&#8212;&#8212;&#8212;&#8212;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;&#8212;&#8212;    &#160;&#160; &#124;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#124;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#124;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#124;   [...]]]></description>
			<content:encoded><![CDATA[<h3>一、介绍</h3>
<p>继Junit CppUnit的成功后， c语言环境下也出现了开发源码的白盒测试用例CUnit。CUnit以静态库的形式提供给用户使用，用户编写程序的时候直接链接此静态库就可以了。它提供了一个简单的单元测试框架，并且为常用的数据类型提供了丰富的断言语句支持。</p>
<h3>二、结构框架</h3>
<p>在CUnit的主页上可以看到对他结构的简单描述</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Test Registry    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; |    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; |&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; |    <br />&#160;&#160;&#160;&#160;&#160; Suite &#8216;1&#8242;&#160;&#160;&#160;&#160;&#160; . . . .&#160;&#160;&#160;&#160;&#160;&#160; Suite &#8216;N&#8217;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; |&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; |    <br />&#160;&#160; &#8212;&#8212;&#8212;&#8212;&#8212;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;&#8212;&#8212;    <br />&#160;&#160; |&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; |&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; |&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; |    <br />Test &#8216;11&#8242; &#8230; Test &#8216;1M&#8217;&#160;&#160;&#160;&#160; Test &#8216;N1&#8242; &#8230; Test &#8216;NM&#8217;</p>
<p>CUnit的测试是单线程启动,只能注册一个测试用例Test Registry，测试用例下可以注册多个测试套件Suite，每个套件下可以注册多个测试函数Test，每个测试函数里又可以写多个断言ASSERT。</p>
<p> <span id="more-455"></span>
<p>&#160;</p>
<h3>三、测试模式</h3>
<p>下面是四种测试模式：    <br />1 Automated Output to xml file Non-interactive     <br />2 Basic Flexible programming interface Non-interactive     <br />3 Console Console interface (ansi C) Interactive     <br />4 Curses Graphical interface (Unix) Interact</p>
<p>注意1，2是没有交互功能的，4是Unix下的。</p>
<p>Windows下的Basic模式灵活性比较大一点，比如你可以选择如下运行模式：   <br />CU_BRM_NORMAL&#160;&#160;&#160; /**&lt; 正常模式 - 打印错误和运行总结 [默认] */    <br />CU_BRM_SILENT&#160;&#160;&#160;&#160;&#160; /**&lt; 安静模式 - 只打印框架错误信息 */    <br />CU_BRM_VERBOSE&#160; /**&lt; 冗余模式 - 输出详细的运行结果 */</p>
<p>还可以指定遇见错误时的动作：   <br />CUEA_IGNORE&#160;&#160;&#160;&#160;&#160;&#160;&#160; /**&lt; 当出现错误时继续往下运行 */    <br />CUEA_FAIL&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; /**&lt; 当有错误出现时停止(stop) */    <br />CUEA_ABORT&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; /**&lt; 当错误出现时应用程序终止(exit) */</p>
<p>第一种Automated运行以后会自动生成一个xml文件，通过dtd和xsl文件的辅助可以在浏览器中显示出测试结果。</p>
<p>第三种Console个人认为目前的功能还不是很强大，主要功能就是可以分别执行测试套件suite程序，但是操作起来十分的不方便。</p>
<h3>四、测试基本流程</h3>
<p>使用CUnit进行测试的基本流程如下所示：   <br />1．书写待测试的函数（如果有必要，需要写suite的init/cleanup函数）    <br />2．初始化Test Registry - CU_initialize_registry()    <br />3．把测试套件（Test Suites）加入到Test Registry - CU_add_suite()    <br />4．加入测试用例（Test Case）到测试套件当中 - CU_add_test()    <br />5．使用适当的接口来运行测试测试程序，例如 CU_console_run_tests()    <br />6．清除Test Registry - CU_cleanup_registry()</p>
<h3>五、测试框架的安装</h3>
<p>没有CUnit源码去<a href="http://sourceforge.net/projects/cunit/">http://sourceforge.net/projects/cunit/</a>去下一份,笔者使用的是CUnit-2.1-0，安装十分的方便，Unix下只需要configure, make, make install就行了，Windows下也有相应的VC工程目录，这里就不再獒述了，需要注意的是，源代码里的Example使用了废弃的CUnit函数命名，所以编译的时候需要加一个USE_DEPRECATED_CUNIT_NAMES预定义。</p>
<h3>六、具体使用</h3>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* test.c */</span>
<span style="color: #993333;">int</span> maxi<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> j<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> i <span style="color: #339933;">&gt;</span> j <span style="color: #339933;">?</span> i <span style="color: #339933;">:</span> j<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* testcase.c */</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;assert.h&gt;</span>
<span style="color: #339933;">#include &lt;CUnit/CUnit.h&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * 待测试的函数
 */</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">int</span> maxi<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * 测试函数
 * 必须满足签名式 void func(void)
*/</span>
<span style="color: #993333;">void</span> testIQJ<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    CU_ASSERT_EQUAL<span style="color: #009900;">&#40;</span>maxi<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    CU_ASSERT_EQUAL<span style="color: #009900;">&#40;</span>maxi<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,-</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> testIGJ<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    CU_ASSERT_EQUAL<span style="color: #009900;">&#40;</span>maxi<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    CU_ASSERT_EQUAL<span style="color: #009900;">&#40;</span>maxi<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    CU_ASSERT_EQUAL<span style="color: #009900;">&#40;</span>maxi<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,-</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> testILJ<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    CU_ASSERT_EQUAL<span style="color: #009900;">&#40;</span>maxi<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    CU_ASSERT_EQUAL<span style="color: #009900;">&#40;</span>maxi<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    CU_ASSERT_EQUAL<span style="color: #009900;">&#40;</span>maxi<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * 测试函数信息的结构体
 * 当然也可以使用 CU_add_test()
 * 注意必须以 CU_TEST_INFO_NULL 结尾
 */</span>
CU_TestInfo testcases<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#123;</span><span style="color: #ff0000;">&quot;Testing i equals j:&quot;</span><span style="color: #339933;">,</span> testIQJ<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span><span style="color: #ff0000;">&quot;Testing i greater than j:&quot;</span><span style="color: #339933;">,</span> testIGJ<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span><span style="color: #ff0000;">&quot;Testing i less than j:&quot;</span><span style="color: #339933;">,</span> testILJ<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    CU_TEST_INFO_NULL
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * 测试套件初始化函数，对测试函数中的资源进行初始化
 * 返回0为成功，如果返回失败则此套件下的测试均不运行
 */</span>
<span style="color: #993333;">int</span> suite_init<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * 测试套件销毁函数，对测试函数中的资源进行销毁
 * 返回0为成功，如果返回失败不影响测试，只会报测试套件运行错误
 */</span>
<span style="color: #993333;">int</span> suite_clean<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
* 测试套件信息的结构体
* 当然也可以使用 CU_add_suite()
* 注意必须以 CU_SUITE_INFO_NULL 结尾
* 如不需要初始化或者最终化函数则可以传NULL
*/</span>
CU_SuiteInfo suites<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#123;</span><span style="color: #ff0000;">&quot;Testing the function maxi:&quot;</span><span style="color: #339933;">,</span> suite_init<span style="color: #339933;">,</span> suite_clean<span style="color: #339933;">,</span> testcases<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    CU_SUITE_INFO_NULL
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * 增加到Registry中
 */</span>
<span style="color: #993333;">void</span> AddTests<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    assert<span style="color: #009900;">&#40;</span>NULL <span style="color: #339933;">!=</span> CU_get_registry<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    assert<span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>CU_is_test_running<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>CUE_SUCCESS <span style="color: #339933;">!=</span> CU_register_suites<span style="color: #009900;">&#40;</span>suites<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Register suites failed - %s &quot;</span><span style="color: #339933;">,</span> CU_get_error_msg<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        exit<span style="color: #009900;">&#40;</span>EXIT_FAILURE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* main.c */</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
<span style="color: #339933;">#include &lt;assert.h&gt;</span>
<span style="color: #339933;">#include &lt;CUnit/Basic.h&gt;</span>
<span style="color: #339933;">#include &lt;CUnit/Automated.h&gt;</span>
<span style="color: #339933;">#include &lt;CUnit/Console.h&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> AddTests<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* 为Basic模式使用 */</span>
    CU_BasicRunMode mode <span style="color: #339933;">=</span> CU_BRM_VERBOSE<span style="color: #339933;">;</span>
    CU_ErrorAction error_action <span style="color: #339933;">=</span> CUEA_IGNORE<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
&nbsp;
    setvbuf<span style="color: #009900;">&#40;</span>stdout<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> _IONBF<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>argc <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>strcmp<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;-i&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            error_action <span style="color: #339933;">=</span> CUEA_IGNORE<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>strcmp<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;-f&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            error_action <span style="color: #339933;">=</span> CUEA_FAIL<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>strcmp<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;-A&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            error_action <span style="color: #339933;">=</span> CUEA_ABORT<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>strcmp<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;-s&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            mode <span style="color: #339933;">=</span> CU_BRM_SILENT<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>strcmp<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;-n&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            mode <span style="color: #339933;">=</span> CU_BRM_NORMAL<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>strcmp<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;-v&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            mode <span style="color: #339933;">=</span> CU_BRM_VERBOSE<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>strcmp<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;-e&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Usage: BasicTest [options]<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
                <span style="color: #ff0000;">&quot;Options: -i ignore framework errors [default].<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
                <span style="color: #ff0000;">&quot; -f fail on framework error.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
                <span style="color: #ff0000;">&quot; -A abort on framework error.<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
                <span style="color: #ff0000;">&quot; -s silent mode - no output to screen.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
                <span style="color: #ff0000;">&quot; -n normal mode - standard output to screen.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
                <span style="color: #ff0000;">&quot; -v verbose mode - max output to screen [default].<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
                <span style="color: #ff0000;">&quot; -e print expected test results and exit.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
                <span style="color: #ff0000;">&quot; -h print this message and exit.<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* 初始化registry */</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> CUE_SUCCESS <span style="color: #339933;">!=</span> CU_initialize_registry<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> CU_get_error<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #808080; font-style: italic;">/* 增加测试套件suite */</span>
        AddTests<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/* 用不同模式运行 */</span>
        <span style="color: #808080; font-style: italic;">/*CU_basic_set_mode(mode);
        CU_basic_run_tests();*/</span>
&nbsp;
        CU_automated_run_tests<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/*CU_console_run_tests();*/</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/* 清除registry */</span>
        CU_cleanup_registry<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.esuraid.com/index.php/2009/06/cunit/feed/</wfw:commentRss>
		</item>
		<item>
		<title>单件(Singleton)模式的实现</title>
		<link>http://blog.esuraid.com/index.php/2009/06/singleton/</link>
		<comments>http://blog.esuraid.com/index.php/2009/06/singleton/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 02:21:00 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
		
		<category><![CDATA[C/C++]]></category>

		<category><![CDATA[原创]]></category>

		<category><![CDATA[设计模式]]></category>

		<category><![CDATA[c]]></category>

		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://blog.suraid.cn/index.php/2009/06/singleton/</guid>
		<description><![CDATA[熟悉设计模式的朋友一定知道著名的Singleton吧，如果不知道的话那就先去拜读一下GoF的大作吧，我在这里就不详细介绍了。
直接给大家共享出我们的实现方法，使用的是C++的template。
&#160;

// singleton.h
#ifndef _SINGLETON_H_
#define _SINGLETON_H_
&#160;
template&#60;class T&#62; class Singleton
&#123;
    protected:
        Singleton&#40;&#41; &#123;&#125;
        Singleton&#40; const Singleton &#38; &#41; &#123;&#125;
        Singleton &#38;operator = &#40;Singleton &#38;&#41; &#123;&#125;
&#160;
        static T* [...]]]></description>
			<content:encoded><![CDATA[<p>熟悉设计模式的朋友一定知道著名的Singleton吧，如果不知道的话那就先去拜读一下GoF的大作吧，我在这里就不详细介绍了。</p>
<p>直接给大家共享出我们的实现方法，使用的是C++的template。</p>
<p>&#160;</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// singleton.h</span>
<span style="color: #339900;">#ifndef _SINGLETON_H_</span>
<span style="color: #339900;">#define _SINGLETON_H_</span>
&nbsp;
<span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> T<span style="color: #000080;">&gt;</span> <span style="color: #0000ff;">class</span> Singleton
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
        Singleton<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
        Singleton<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Singleton <span style="color: #000040;">&amp;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
        Singleton <span style="color: #000040;">&amp;</span>operator <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>Singleton <span style="color: #000040;">&amp;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0000ff;">static</span> T<span style="color: #000040;">*</span> pInst<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
        <span style="color: #0000ff;">static</span> T<span style="color: #000040;">*</span> GetInstance<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>pInst<span style="color: #008000;">&#41;</span>
                <span style="color: #0000ff;">return</span> pInst<span style="color: #008080;">;</span>
            pInst <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> T<span style="color: #008080;">;</span>
            <span style="color: #0000ff;">return</span> pInst<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> ReleaseInstance<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>pInst<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0000dd;">delete</span> pInst<span style="color: #008080;">;</span>
                pInst <span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008080;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> T<span style="color: #000080;">&gt;</span> T <span style="color: #000040;">*</span>Singleton<span style="color: #000080;">&lt;</span>T<span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">pInst</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #339900;">#endif</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// suraid.h</span>
<span style="color: #339900;">#ifndef _SURAID_H_</span>
<span style="color: #339900;">#define _SURAID_H_</span>
&nbsp;
<span style="color: #339900;">#include &quot;singleton.h&quot;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Suraid <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> Singleton<span style="color: #000080;">&lt;</span>Texture<span style="color: #000080;">&gt;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>     
        Suraid<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #339900;">#endif</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// main.cpp</span>
<span style="color: #339900;">#include &quot;suraid.h&quot;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    Suraid<span style="color: #000040;">*</span> suraid <span style="color: #000080;">=</span> Suraid<span style="color: #008080;">::</span><span style="color: #007788;">GetInstance</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>代码应该很清晰了吧，这样实现的好处就是很方便，想使用单件的时候只要简单的继承一下就好了，但是也有一个缺点，通常我们理解的singleton都是不让实例化的，因为只能实例化一次，但是由于template的特性，构造函数无法申明成protected，也就导致可以实例化类，在使用的过程中要多加注意。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.esuraid.com/index.php/2009/06/singleton/feed/</wfw:commentRss>
		</item>
		<item>
		<title>[原创]ecshop 分析(4) 添加自己的模板</title>
		<link>http://blog.esuraid.com/index.php/2009/04/%e5%8e%9f%e5%88%9becshop-%e5%88%86%e6%9e%903-%e6%b7%bb%e5%8a%a0%e8%87%aa%e5%b7%b1%e7%9a%84%e6%a8%a1%e6%9d%bf/</link>
		<comments>http://blog.esuraid.com/index.php/2009/04/%e5%8e%9f%e5%88%9becshop-%e5%88%86%e6%9e%903-%e6%b7%bb%e5%8a%a0%e8%87%aa%e5%b7%b1%e7%9a%84%e6%a8%a1%e6%9d%bf/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 12:01:58 +0000</pubDate>
		<dc:creator>Tommy</dc:creator>
		
		<category><![CDATA[Web开发]]></category>

		<category><![CDATA[ecshop]]></category>

		<category><![CDATA[原创]]></category>

		<category><![CDATA[创建]]></category>

		<category><![CDATA[模板]]></category>

		<guid isPermaLink="false">http://blog.suraid.cn/index.php/2009/04/ecshop-analysis-3html/</guid>
		<description><![CDATA[上次我们主要讨论了关于模板的问题，最后我们留下了一个问题——cache的问题。我觉得这个问题到目前位置先不要讨论好，再往后一点我们再来分析这个问题。到现在我们知道了模板的一些操作了，但是我们还是很郁闷，因为我们只是在ecshop的前台框架的控制之下。那么我们如何能够脱离出来呢？如果我们能做到自己添加属于自己或者可以放自己想要放的东西的模板，那么应该算是到了一个更高的台阶来看ecshop了。
要做到添加一个模板就必须做到前台可以显示这个模板，后台可以编辑这个模板。下面我们一步一步教大家怎么添加一个属于自己的模板。在添加之前我们先稍微分析一下，对以一个模板，在前台一定有一个php文件和它对应（很显然这个php文件就是实现给这个模板文件传送数据的）。并且在后台可以编辑这个模板对于的模块，也就是在模板管理——设置模板中有你加的模板的选项。下面我们来添加一个home模板。首先在根目录下新建home.dwt和home.php。然后将index.dwt和index.php中的内容分别拷贝到home.dwt和home.php中。对于这个模板的内容完全由你自己决定，你的内容就会决定你要怎么修改home.dwt和home.php。当然这个模板的内容是受限制的，首先要home这个模板的候选的库文件是存在的。这个是什么意思呢？这句话的意思就是对于每个模板文件，可以调用的库文件是固定的，并且这些可以调用的库文件在文件admin/includes/lib_templete.php中定义的。首先要在后台将home这个模板放入到可设置内容的模板中，部分代码如下： 
  

/* 可以设置内容的模板 */
$template_files = array&#40;
'home.dwt',
'index.dwt',
'zhiku.dwt',
'article.dwt',
'article_cat.dwt',
'brand.dwt',
'category.dwt',
'user_clips.dwt',
'compare.dwt',
'gallery.dwt',

在上面的代码中就将home.dwt加入到后台的可编辑模板中，这个时候你就可以在后台的模板管理-&#62;设置模板中编辑home模板了。但是到这里我们发现一个很小的问题，那就是这个home模板在后台是显示成什么名字。其实这个很简单，只要在文件language/zh_cn/admin/template.php中添加$_LANG['template_files']['home'] = &#8216;home模板&#8217;;这样的语句，那么在后台看到的home模板的名称就是“home模板”，当然这里也可以设置成其他的名称。在上面我们有说到每个模板可以调用的库文件是固定的，既然说是固定的，那应该是哪些呢？就拿index来说吧，在文件admin/includes/lib_templete.php中有下面这样的代码：

'index' =&#62; array&#40;
'/library/ur_here.lbi' =&#62; 0,
'/library/search_form.lbi' =&#62; 0,
'/library/member.lbi' =&#62; 0,
'/library/new_articles.lbi' =&#62; 0,
'/library/success_article.lbi' =&#62; 0,
'/library/dynamic_article.lbi' =&#62; 0,
'/library/school_article.lbi' =&#62; 0,
'/library/category_tree.lbi' =&#62; 0,
'/library/top10.lbi' =&#62; 0,
'/library/invoice_query.lbi' =&#62; 0,
'/library/recommend_best.lbi' =&#62; 3,
'/library/recommend_new.lbi' =&#62; 3,
'/library/recommend_hot.lbi' =&#62; 3,
'/library/recommend_promotion.lbi' =&#62; 4,
'/library/group_buy.lbi' =&#62; 3,
'/library/auction.lbi' =&#62; 3,
'/library/brands.lbi' =&#62; 0,
'/library/promotion_info.lbi' =&#62; 0,
'/library/cart.lbi' =&#62; 0,
'/library/order_query.lbi' =&#62; 0,
'/library/email_list.lbi' =&#62; 0,
'/library/vote_list.lbi' =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>上次我们主要讨论了关于模板的问题，最后我们留下了一个问题——cache的问题。我觉得这个问题到目前位置先不要讨论好，再往后一点我们再来分析这个问题。到现在我们知道了模板的一些操作了，但是我们还是很郁闷，因为我们只是在ecshop的前台框架的控制之下。那么我们如何能够脱离出来呢？如果我们能做到自己添加属于自己或者可以放自己想要放的东西的模板，那么应该算是到了一个更高的台阶来看ecshop了。
<p>要做到添加一个模板就必须做到前台可以显示这个模板，后台可以编辑这个模板。下面我们一步一步教大家怎么添加一个属于自己的模板。在添加之前我们先稍微分析一下，对以一个模板，在前台一定有一个php文件和它对应（很显然这个php文件就是实现给这个模板文件传送数据的）。并且在后台可以编辑这个模板对于的模块，也就是在模板管理——设置模板中有你加的模板的选项。下面我们来添加一个home模板。首先在根目录下新建home.dwt和home.php。然后将index.dwt和index.php中的内容分别拷贝到home.dwt和home.php中。对于这个模板的内容完全由你自己决定，你的内容就会决定你要怎么修改home.dwt和home.php。当然这个模板的内容是受限制的，首先要home这个模板的候选的库文件是存在的。这个是什么意思呢？这句话的意思就是对于每个模板文件，可以调用的库文件是固定的，并且这些可以调用的库文件在文件admin/includes/lib_templete.php中定义的。首先要在后台将home这个模板放入到可设置内容的模板中，部分代码如下： </p>
<p>  <span id="more-446"></span>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* 可以设置内容的模板 */</span>
<span style="color: #000088;">$template_files</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">'home.dwt'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'index.dwt'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'zhiku.dwt'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'article.dwt'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'article_cat.dwt'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'brand.dwt'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'category.dwt'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'user_clips.dwt'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'compare.dwt'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'gallery.dwt'</span><span style="color: #339933;">,</span></pre></div></div>

<p>在上面的代码中就将home.dwt加入到后台的可编辑模板中，这个时候你就可以在后台的模板管理-&gt;设置模板中编辑home模板了。但是到这里我们发现一个很小的问题，那就是这个home模板在后台是显示成什么名字。其实这个很简单，只要在文件language/zh_cn/admin/template.php中添加$_LANG['template_files']['home'] = &#8216;home模板&#8217;;这样的语句，那么在后台看到的home模板的名称就是“home模板”，当然这里也可以设置成其他的名称。在上面我们有说到每个模板可以调用的库文件是固定的，既然说是固定的，那应该是哪些呢？就拿index来说吧，在文件admin/includes/lib_templete.php中有下面这样的代码：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'index'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">'/library/ur_here.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/search_form.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/member.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/new_articles.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/success_article.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/dynamic_article.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/school_article.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/category_tree.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/top10.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/invoice_query.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/recommend_best.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/recommend_new.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/recommend_hot.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/recommend_promotion.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/group_buy.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/auction.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/brands.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/promotion_info.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/cart.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/order_query.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/email_list.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'/library/vote_list.lbi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span></pre></div></div>

<p>那么这边枚举到的库文件，对于index.dwt都可以调用的。依葫芦画瓢，home.dwt需要调用哪些库文件，那么就对应上面这个写就是了，相信大家都有这个水平。好的，到目前为止一个模板文件添加成功了，那么它在浏览器中的显示就要通过后台的设置模板来确定了。好的，添加一个自己的模板我就说到这里，我们下期继续讨论ecshop。Thanks！！！</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.esuraid.com/index.php/2009/04/%e5%8e%9f%e5%88%9becshop-%e5%88%86%e6%9e%903-%e6%b7%bb%e5%8a%a0%e8%87%aa%e5%b7%b1%e7%9a%84%e6%a8%a1%e6%9d%bf/feed/</wfw:commentRss>
		</item>
		<item>
		<title>[转]Chrome启动参数方案</title>
		<link>http://blog.esuraid.com/index.php/2009/04/%e8%bd%acchrome%e5%90%af%e5%8a%a8%e5%8f%82%e6%95%b0%e6%96%b9%e6%a1%88/</link>
		<comments>http://blog.esuraid.com/index.php/2009/04/%e8%bd%acchrome%e5%90%af%e5%8a%a8%e5%8f%82%e6%95%b0%e6%96%b9%e6%a1%88/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 16:59:58 +0000</pubDate>
		<dc:creator>lyg</dc:creator>
		
		<category><![CDATA[Chrome]]></category>

		<category><![CDATA[浏览器]]></category>

		<category><![CDATA[Startup Swtiches]]></category>

		<guid isPermaLink="false">http://blog.suraid.cn/?p=443</guid>
		<description><![CDATA[下面是常用的一些启动参数：
&#8211;user-data-dir=UserDataDir&#160;&#160; 自定义用户数据目录
&#8211;start-maximized&#160;&#160; 启动就最大化
&#8211;no-sandbox&#160;&#160; 取消沙盒模式
&#8211;single-process&#160;&#160; 单进程运行
&#8211;process-per-tab&#160;&#160; 每个标签使用单独进程
&#8211;process-per-site&#160;&#160; 每个站点使用单独进程
&#8211;in-process-plugins&#160;&#160; 插件不启用单独进程
&#8211;disable-popup-blocking&#160;&#160; 禁用弹出拦截
&#8211;disable-javascript&#160;&#160; 禁用JavaScript
&#8211;disable-java&#160;&#160; 禁用Java
&#8211;disable-plugins&#160;&#160; 禁用插件
&#8211;disable-images&#160;&#160; 禁用图像
&#160;
A Complete list to Google Chrome Startup Switches&#8230;
see below
&#160;
-disable-hang-monitor
-disable-metrics
-disable-metrics-reporting
-assert-test
-renderer-assert-test
-crash-test
-renderer-crash-test
-renderer-startup-dialog
-plugin-startup-dialog
-testshell-startup-dialog
-plugin-launcher
-channeltesting-channel
-homepagestart-renderers-manuallyrenderer
-renderer-pathplugin
-single-process
-process-per-tab
-process-per-site
-in-process-plugins
-no-sandbox
-safe-plugins
-trusted-plugins
-test-sandbox
-user-data-dir
-appupload-file
-dom-automation
-plugin-pathjs-flags
-geoidlangdebug-children
-wait-for-debugger-children
-log-filter-prefix
-enable-logging
-dump-histograms-on-exit
-disable-logging
-remote-shell-port
-uninstallomnibox-popup-count
-automation-channel
-restore-last-session
-record-mode
-playback-mode
-no-events
-hide-icons
-show-icons
-make-default-browser
-proxy-server
-dns-log-details
-dns-prefetch-disable
-debug-print
-allow-all-activex
-disable-dev-tools
-always-enable-dev-tools
-memory-model
-tab-count-to-load-on-session-restore
-memory-profile
-enable-file-cookies
-start-maximized
-enable-watchdogfirst-run
-message-loop-strategy
-message-loop-histogrammer
-importsilent-dump-on-dcheck
-disable-prompt-on-repost
-disable-popup-blocking
-disable-javascript
-disable-java
-disable-plugins
-disable-images
-use-lf-heap
-new-http
&#160;
本文来源于谷歌Chrome中文站 http://www.downdig.com/chrome , 原文地址： http://www.downdig.com/chrome/?p=88&#160;
]]></description>
			<content:encoded><![CDATA[<div>下面是常用的一些启动参数：<br />
&ndash;user-data-dir=UserDataDir&nbsp;&nbsp; 自定义用户数据目录<br />
&ndash;start-maximized&nbsp;&nbsp; 启动就最大化<br />
&ndash;no-sandbox&nbsp;&nbsp; 取消沙盒模式<br />
&ndash;single-process&nbsp;&nbsp; 单进程运行<br />
&ndash;process-per-tab&nbsp;&nbsp; 每个标签使用单独进程<br />
&ndash;process-per-site&nbsp;&nbsp; 每个站点使用单独进程<br />
&ndash;in-process-plugins&nbsp;&nbsp; 插件不启用单独进程<br />
&ndash;disable-popup-blocking&nbsp;&nbsp; 禁用弹出拦截<br />
&ndash;disable-javascript&nbsp;&nbsp; 禁用JavaScript<br />
&ndash;disable-java&nbsp;&nbsp; 禁用Java<br />
&ndash;disable-plugins&nbsp;&nbsp; 禁用插件<br />
&ndash;disable-images&nbsp;&nbsp; 禁用图像<br />
&nbsp;</div>
<div>A Complete list to Google Chrome Startup Switches&#8230;<br />
see below<br />
&nbsp;</div>
<div>-disable-hang-monitor<br />
-disable-metrics<br />
-disable-metrics-reporting<br />
-assert-test<br />
-renderer-assert-test<br />
-crash-test<br />
-renderer-crash-test<br />
-renderer-startup-dialog<br />
-plugin-startup-dialog<br />
-testshell-startup-dialog<br />
-plugin-launcher<br />
-channeltesting-channel<br />
-homepagestart-renderers-manuallyrenderer<br />
-renderer-pathplugin<br />
-single-process<br />
-process-per-tab<br />
-process-per-site<br />
-in-process-plugins<br />
-no-sandbox<br />
-safe-plugins<br />
-trusted-plugins<br />
-test-sandbox<br />
-user-data-dir<br />
-appupload-file<br />
-dom-automation<br />
-plugin-pathjs-flags<br />
-geoidlangdebug-children<br />
-wait-for-debugger-children<br />
-log-filter-prefix<br />
-enable-logging<br />
-dump-histograms-on-exit<br />
-disable-logging<br />
-remote-shell-port<br />
-uninstallomnibox-popup-count<br />
-automation-channel<br />
-restore-last-session<br />
-record-mode<br />
-playback-mode<br />
-no-events<br />
-hide-icons<br />
-show-icons<br />
-make-default-browser<br />
-proxy-server<br />
-dns-log-details<br />
-dns-prefetch-disable<br />
-debug-print<br />
-allow-all-activex<br />
-disable-dev-tools<br />
-always-enable-dev-tools<br />
-memory-model<br />
-tab-count-to-load-on-session-restore<br />
-memory-profile<br />
-enable-file-cookies<br />
-start-maximized<br />
-enable-watchdogfirst-run<br />
-message-loop-strategy<br />
-message-loop-histogrammer<br />
-importsilent-dump-on-dcheck<br />
-disable-prompt-on-repost<br />
-disable-popup-blocking<br />
-disable-javascript<br />
-disable-java<br />
-disable-plugins<br />
-disable-images<br />
-use-lf-heap<br />
-new-http<br />
&nbsp;<br />
本文来源于谷歌Chrome中文站 <a href="http://www.downdig.com/chrome">http://www.downdig.com/chrome</a> , 原文地址： <a href="http://www.downdig.com/chrome/?p=88">http://www.downdig.com/chrome/?p=88</a>&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.esuraid.com/index.php/2009/04/%e8%bd%acchrome%e5%90%af%e5%8a%a8%e5%8f%82%e6%95%b0%e6%96%b9%e6%a1%88/feed/</wfw:commentRss>
		</item>
		<item>
		<title>[原]Faint, 现在俺知道咋将一个历史的版本变成trunk了</title>
		<link>http://blog.esuraid.com/index.php/2009/04/%e5%8e%9ffaint-%e7%8e%b0%e5%9c%a8%e4%bf%ba%e7%9f%a5%e9%81%93%e5%92%8b%e5%b0%86%e4%b8%80%e4%b8%aa%e5%8e%86%e5%8f%b2%e7%9a%84%e7%89%88%e6%9c%ac%e5%8f%98%e6%88%90trunk%e4%ba%86/</link>
		<comments>http://blog.esuraid.com/index.php/2009/04/%e5%8e%9ffaint-%e7%8e%b0%e5%9c%a8%e4%bf%ba%e7%9f%a5%e9%81%93%e5%92%8b%e5%b0%86%e4%b8%80%e4%b8%aa%e5%8e%86%e5%8f%b2%e7%9a%84%e7%89%88%e6%9c%ac%e5%8f%98%e6%88%90trunk%e4%ba%86/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 12:21:15 +0000</pubDate>
		<dc:creator>lyg</dc:creator>
		
		<category><![CDATA[版本控制]]></category>

		<guid isPermaLink="false">http://blog.suraid.cn/?p=440</guid>
		<description><![CDATA[&#160;最近我遇到一个问题，因为我将那个Subversion 的trunk改得乱糟糟的，想改回去都郁闷，一个一个改，还怕改不对，有没有一种方法直接将一个历史的版本覆盖当前的trunk呢？我研究了n久之后，现在终于找到方法了，faint，很郁闷，没有一条直接的命令可以实现这个东东，但是我们可以简介的实现：）
这个方法就是：
大家听好啦，我觉得这个会非常有用的，呵呵，其实我以前经常碰到这个问题，但是变动不大，所以就手动改回去了，现在，手动改回去似乎很麻烦，所以需要一种自动的方法来实现这个目的，。
我在网上找啊找的找，就是没有找到，faint，现在，我找到了，请原谅我这么啰嗦，实在太激动了，而且我万年难得写一篇博客，所以，：）
下面进入正题
其实就是通过merge实现，怎么实现呢？
通过TSVN的文档可以知道，它有三个选项
faint，其实你右键也可以找到这三个选项，因为鄙人用的是英文版的，懒啊，不装中文包的后果，虽然我经常与这三个选项照面，但是总是随意选取一个就处理，额，不经过大脑的表现，但是上一次，我认真的看了一下这三个选项，并一一尝试，后来发觉第三个选项有点诡异：）
&#160;
Merge two different trees
This is a more general case of the reintegrate method. What you are asking  Subversion to do is: &#8220;Calculate the changes necessary to get  [FROM] the head revision of the trunk [TO] the head revision of the branch, and  apply those changes to my working copy (of the [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;最近我遇到一个问题，因为我将那个Subversion 的trunk改得乱糟糟的，想改回去都郁闷，一个一个改，还怕改不对，有没有一种方法直接将一个历史的版本覆盖当前的trunk呢？我研究了n久之后，现在终于找到方法了，faint，很郁闷，没有一条直接的命令可以实现这个东东，但是我们可以简介的实现：）</p>
<p>这个方法就是：</p>
<p>大家听好啦，我觉得这个会非常有用的，呵呵，其实我以前经常碰到这个问题，但是变动不大，所以就手动改回去了，现在，手动改回去似乎很麻烦，所以需要一种自动的方法来实现这个目的，。</p>
<p>我在网上找啊找的找，就是没有找到，faint，现在，我找到了，请原谅我这么啰嗦，实在太激动了，而且我万年难得写一篇博客，所以，：）</p>
<p>下面进入正题</p>
<p>其实就是通过merge实现，怎么实现呢？</p>
<p>通过TSVN的文档可以知道，它有三个选项</p>
<p>faint，其实你右键也可以找到这三个选项，因为鄙人用的是英文版的，懒啊，不装中文包的后果，虽然我经常与这三个选项照面，但是总是随意选取一个就处理，额，不经过大脑的表现，但是上一次，我认真的看了一下这三个选项，并一一尝试，后来发觉第三个选项有点诡异：）</p>
<p>&nbsp;</p>
<p><span class="term">Merge two different trees</span></p>
<p>This is a more general case of the reintegrate method. What you are asking  Subversion to do is: &ldquo;<span class="quote">Calculate the changes necessary to get  [FROM] the head revision of the trunk [TO] the head revision of the branch, and  apply those changes to my working copy (of the trunk).</span>&rdquo; The net result is  that trunk now looks exactly like the branch.</p>
<p>If your server/repository does not support merge-tracking then this is the  only way to merge a branch back to trunk. Another use case occurs when you are  using vendor branches and you need to merge the changes following a new vendor  drop into your trunk code. For more information read the chapter &nbsp;<a class="ulink" target="_top" href="http://svnbook.red-bean.com/en/1.5/svn.advanced.vendorbr.html"><em class="citetitle">vendor branches</em> </a>in the Subversion Book.&nbsp;</p>
<p>就是说找 目录x的第Vx个版本 与 目录y的第Vy个版本 &nbsp;之间的差异，然后把这个差异应用到 你要施加改变的目录上。那么给定如下命令 ， 当然目录x的第Vx个版本是基，</p>
<p>那么我们已trunk目录的HEAD vesion为基，以一个trunk历史的版本为Vy，然后吧他们之间的差异应用到trunk上么，那么提交之后trunk的HEAD就变成了这个历史的版本啦：）</p>
<p>相当于</p>
<p>x +( y -x) = y , x就是当前的trunk y就是历史的版本</p>
<p>mmm，游戏结束</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.esuraid.com/index.php/2009/04/%e5%8e%9ffaint-%e7%8e%b0%e5%9c%a8%e4%bf%ba%e7%9f%a5%e9%81%93%e5%92%8b%e5%b0%86%e4%b8%80%e4%b8%aa%e5%8e%86%e5%8f%b2%e7%9a%84%e7%89%88%e6%9c%ac%e5%8f%98%e6%88%90trunk%e4%ba%86/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
