﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-编程自动化</title><link>http://www.cppblog.com/AutomateProgram/</link><description>当音乐和传说在深夜中沉寂后，程序的每个字符还在跳动！</description><language>zh-cn</language><lastBuildDate>Fri, 03 Apr 2026 17:25:46 GMT</lastBuildDate><pubDate>Fri, 03 Apr 2026 17:25:46 GMT</pubDate><ttl>60</ttl><item><title>python中字符串操作--截取，查找，替换</title><link>http://www.cppblog.com/AutomateProgram/archive/2018/01/12/215472.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Fri, 12 Jan 2018 08:04:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2018/01/12/215472.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/215472.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2018/01/12/215472.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/215472.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/215472.html</trackback:ping><description><![CDATA[<div><br />python中字符串操作--截取，查找，替换<br /></div><div></div><div>&nbsp; &nbsp; python中，对字符串的操作是最常见的，python对字符串操作有自己特殊的处理方式。<br /></div><div>字符串的截取<br /></div><div></div><div>python中对于字符串的索引是比较特别的，来感受一下：<br /></div><div></div><div></div><div></div><div>字符串的查找<br /></div><div></div><div>查找当前字符串中，是否包含另外的字符串。<br /></div><div></div><div>我们可以使用 index，或者find来进行查找，find和index的区别是，如果使用的是index的话，字符串查找中，如果找不到相应的字符串，会抛出一个ValueError的异常。<br /></div><div></div><div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->s&nbsp;=&nbsp;<span style="color: #800000; ">'</span><span style="color: #800000; ">123456789</span><span style="color: #800000; ">'</span><br />s.index(<span style="color: #800000; ">'</span><span style="color: #800000; ">23</span><span style="color: #800000; ">'</span>)<br /><span style="color: #008000; ">#</span><span style="color: #008000; ">输出：1</span><span style="color: #008000; "><br /></span>s.find(<span style="color: #800000; ">'</span><span style="color: #800000; ">23</span><span style="color: #800000; ">'</span>)<br /><span style="color: #008000; ">#</span><span style="color: #008000; ">输出：1</span><span style="color: #008000; "><br /></span>s.index(<span style="color: #800000; ">'</span><span style="color: #800000; ">s</span><span style="color: #800000; ">'</span>)<br /><span style="color: #008000; ">#</span><span style="color: #008000; ">输出</span><span style="color: #008000; "><br /></span>Traceback&nbsp;(most&nbsp;recent&nbsp;call&nbsp;last):<br />&nbsp;&nbsp;File&nbsp;<span style="color: #800000; ">"</span><span style="color: #800000; ">&lt;stdin&gt;</span><span style="color: #800000; ">"</span>,&nbsp;line&nbsp;1,&nbsp;<span style="color: #0000FF; ">in</span>&nbsp;&lt;module&gt;<br />ValueError:&nbsp;substring&nbsp;<span style="color: #0000FF; ">not</span>&nbsp;found<br />s.find(<span style="color: #800000; ">'</span><span style="color: #800000; ">s</span><span style="color: #800000; ">'</span>)<br /><span style="color: #008000; ">#</span><span style="color: #008000; ">输出&nbsp;-1</span></div></div><div></div><div><br /><br />分割字符串<br /></div><div></div><div>总是有很多特殊字符，可以用来分割字符串。数据库中经常把一组照片放在一个字段中，比如<br /></div><div>img1.jpg@@@img2.jpg@@@img3.jpg</div><div></div><div>需要把不定长的照片都取出来，就需要同特殊字符把字符串分开，得到不同的照片。<br /></div><div></div><div>分割的命令为split<br /></div><div></div><div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->s&nbsp;=&nbsp;<span style="color: #800000; ">'</span><span style="color: #800000; ">img1.jpg@@@img2.jpg@@@img3.jpg</span><span style="color: #800000; ">'</span><br />s.split(<span style="color: #800000; ">'</span><span style="color: #800000; ">@@@</span><span style="color: #800000; ">'</span>)<br /><span style="color: #008000; ">#</span><span style="color: #008000; ">结果为一个数值：['img1.jpg',&nbsp;'img2.jpg',&nbsp;'img3.jpg']</span><span style="color: #008000; "><br /></span>&lt;/code&gt;&lt;/pre&gt;<br /><span style="color: #008000; ">#</span><span style="color: #008000; ">##&nbsp;字符串格式化</span><span style="color: #008000; "><br /></span>Python&nbsp;支持格式化字符串的输出&nbsp;。尽管这样可能会用到非常复杂的表达式，但最基本的用法是将一个值插入到一个有字符串格式符&nbsp;%s&nbsp;的字符串中。<br />在&nbsp;Python&nbsp;中，字符串格式化使用与&nbsp;C&nbsp;中&nbsp;sprintf&nbsp;函数一样的语法。<br />&lt;pre&gt;&lt;code&gt;<br /><span style="color: #008000; ">#</span><span style="color: #008000; ">!/usr/bin/python</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">print</span>&nbsp;<span style="color: #800000; ">"</span><span style="color: #800000; ">My&nbsp;name&nbsp;is&nbsp;%s&nbsp;and&nbsp;weight&nbsp;is&nbsp;%d&nbsp;kg!</span><span style="color: #800000; ">"</span>&nbsp;%&nbsp;(<span style="color: #800000; ">'</span><span style="color: #800000; ">Zara</span><span style="color: #800000; ">'</span>,&nbsp;21)&nbsp;<br /><span style="color: #008000; ">#</span><span style="color: #008000; ">以上实例输出结果：&nbsp;My&nbsp;name&nbsp;is&nbsp;Zara&nbsp;and&nbsp;weight&nbsp;is&nbsp;21&nbsp;kg!</span></div></div><div></div><div><br /></div><div></div><div></div><div>字符串Template化<br /></div><div></div><div>在python中Template可以将字符串的格式固定下来，重复利用。</div><div></div><div>Template属于string中的一个类，要使用他的话可以用以下方式调用：<br /></div><div></div><div><span style="white-space: pre;">	</span>from string import Template<br /></div><div></div><div>我们使用以下代码：<br /></div><div></div><div><span style="white-space: pre;">	</span>&gt;&gt;&gt; s = Template('There&nbsp; ${moneyType} is&nbsp; ${money}')</div><div><span style="white-space: pre;">	</span>&gt;&gt;&gt; print s.substitute(moneyType = 'Dollar',money=12)<br /></div><div></div><div>运行结果显示&#8220;There&nbsp; Dollar is&nbsp; 12&#8221;</div><div></div><div>这样我们就可以替换其中的数据了。<br /><div>更多入门教程可以参考：[http://www.bugingcode.com/python_start/] (http://www.bugingcode.com/python_start/)</div><br /><br /></div><div></div><img src ="http://www.cppblog.com/AutomateProgram/aggbug/215472.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2018-01-12 16:04 <a href="http://www.cppblog.com/AutomateProgram/archive/2018/01/12/215472.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>正则表达式入门-python代码</title><link>http://www.cppblog.com/AutomateProgram/archive/2018/01/12/215471.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Fri, 12 Jan 2018 07:13:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2018/01/12/215471.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/215471.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2018/01/12/215471.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/215471.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/215471.html</trackback:ping><description><![CDATA[<div></div><div><h3><br />题记<br /><br /></h3></div><div></div><div>&nbsp; &nbsp; 本文介绍了Python对于正则表达式的支持，包括正则表达式基础以及Python正则表达式标准库的完整介绍及使用示例。</div><div></div><div>&nbsp; &nbsp; 正则表达式在很多的应用中都有使用到，特别是在网络爬虫中格式化html后取出自己需要的属性，在字符串的匹配和查找中也有很多的应用。</div><div></div><div>&nbsp; &nbsp; 本文主要使用python对正则表达式进行说明，并配合合适的代码。</div><div></div><div><h3>如何匹配手机号码<br /><br /></h3></div><div></div><div>正则表达式的规则，一开始看的时候，会感觉规则太多太乱，毫无规律可寻，看完了几个例子以后，慢慢的发现一些常用的表达式以后，写起后面的规则就容易得多了。</div><div></div><div>这里以如何匹配手机电话号码为例子</div><div></div><div>最简单的手机规律为11个数字，正则表达式为：<br /></div><div></div><div>&nbsp; &nbsp;&nbsp;<span style="background-color: #eeeeee; font-size: 13px;">\d{</span><span style="background-color: #eeeeee; font-size: 13px;">11</span><span style="background-color: #eeeeee; font-size: 13px;">}<br /><br /></span></div><div></div><div>这样我们就认为凡事字符串中有11位数字就认为是手机号码，但是现实中还有另外一些规则，12345678912这也是11个数字，但是我们现在并不会认为他是手机号码，所以进一步的把规则写细了。</div><div></div><div></div><div>我们还可以进一步的细分为，13x开头，14x开头，17(13678)开头，18x开头，后面再带8位的数字，还有另一种情况是170的情况，其中第四位为[0589]中的一个数，再带7位数字。</div><div>表达式可以写为：<br /></div><div></div><div>&nbsp; &nbsp;&nbsp;<span style="background-color: #eeeeee; font-size: 13px;">(</span><span style="background-color: #eeeeee; font-size: 13px;">13</span><span style="background-color: #eeeeee; font-size: 13px;">\d</span><span style="background-color: #eeeeee; font-size: 13px;">|</span><span style="background-color: #eeeeee; font-size: 13px;">14</span><span style="background-color: #eeeeee; font-size: 13px;">[</span><span style="background-color: #eeeeee; font-size: 13px;">57</span><span style="background-color: #eeeeee; font-size: 13px;">]</span><span style="background-color: #eeeeee; font-size: 13px;">|</span><span style="background-color: #eeeeee; font-size: 13px;">15</span><span style="background-color: #eeeeee; font-size: 13px;">[</span><span style="background-color: #eeeeee; font-size: 13px;">^</span><span style="background-color: #eeeeee; font-size: 13px;">4</span><span style="background-color: #eeeeee; font-size: 13px;">,\D]</span><span style="background-color: #eeeeee; font-size: 13px;">|</span><span style="background-color: #eeeeee; font-size: 13px;">17</span><span style="background-color: #eeeeee; font-size: 13px;">[</span><span style="background-color: #eeeeee; font-size: 13px;">13678</span><span style="background-color: #eeeeee; font-size: 13px;">]</span><span style="background-color: #eeeeee; font-size: 13px;">|</span><span style="background-color: #eeeeee; font-size: 13px;">18</span><span style="background-color: #eeeeee; font-size: 13px;">\d)\d{</span><span style="background-color: #eeeeee; font-size: 13px;">8</span><span style="background-color: #eeeeee; font-size: 13px;">}</span><span style="background-color: #eeeeee; font-size: 13px;">|</span><span style="background-color: #eeeeee; font-size: 13px;">170</span><span style="background-color: #eeeeee; font-size: 13px;">[0</span><span style="background-color: #eeeeee; font-size: 13px;">589</span><span style="background-color: #eeeeee; font-size: 13px;">]\d{</span><span style="background-color: #eeeeee; font-size: 13px;">7</span><span style="background-color: #eeeeee; font-size: 13px;">}</span></div><div></div><div></div><div><h3>正则表达式语法</h3></div><div></div><div>我们刚才用到的\d 在正则表达式中，代表着数字的意思，还可以用[0-9]来表示一个数字。语法比较多，但是常用的并不是很多，图中表示的是常见的语法。<br /></div><div></div><div>字符串匹配：<br /><br /></div><div></div><div></div><div>| 语法&nbsp; &nbsp; &nbsp; &nbsp; | 含义&nbsp; &nbsp; |&nbsp;</div><div>| --------&nbsp; &nbsp;| :-----:&nbsp; &nbsp;|&nbsp;</div><div>| \d&nbsp; &nbsp; &nbsp; &nbsp; | 数字&nbsp; &nbsp; &nbsp; |&nbsp;</div><div>| \D&nbsp; &nbsp; &nbsp; &nbsp; | 非数字&nbsp; &nbsp; &nbsp; |</div><div>| \s&nbsp; &nbsp; &nbsp; &nbsp; | 空白符&nbsp; &nbsp; &nbsp; |</div><div>| \S&nbsp; &nbsp; &nbsp; &nbsp; | 非空白符&nbsp; &nbsp; &nbsp; |</div><div>| \w&nbsp; &nbsp; &nbsp; &nbsp; | 单词字符&nbsp; &nbsp; &nbsp; |</div><div>| \W&nbsp; &nbsp; &nbsp; &nbsp; | 非单词字符&nbsp; &nbsp; &nbsp; |<br /><br /></div><div></div><div></div><div>数量匹配：<br /><br /></div><div></div><div></div><div>| 语法&nbsp; &nbsp; &nbsp; &nbsp; | 含义&nbsp; &nbsp; |&nbsp;</div><div>| --------&nbsp; &nbsp;| :-----:&nbsp; &nbsp;|&nbsp;</div><div>| *&nbsp; &nbsp; &nbsp; &nbsp; | 匹配前面字符0次到无限次&nbsp; &nbsp; &nbsp; &nbsp;|&nbsp;</div><div>| +&nbsp; &nbsp; &nbsp; &nbsp; | 匹配前面字符1次到无限次&nbsp; &nbsp; &nbsp; &nbsp;|</div><div>| ？&nbsp; &nbsp; &nbsp; &nbsp; | 匹配前面字符0到1次&nbsp; &nbsp; &nbsp; |</div><div>|{m}&nbsp; &nbsp; &nbsp; &nbsp; | 匹配前面字符m次&nbsp; &nbsp; &nbsp; |</div><div>| {m,n}&nbsp; &nbsp; &nbsp; &nbsp; | 匹配前面字符m到n次&nbsp; &nbsp; &nbsp; |</div><div></div><div></div><div>匹配边界：</div><div></div><div>| 语法&nbsp; &nbsp; &nbsp; &nbsp; | 含义&nbsp; &nbsp; |&nbsp;</div><div>| --------&nbsp; &nbsp;| :-----:&nbsp; &nbsp;|&nbsp;</div><div>| ^&nbsp; &nbsp; &nbsp; &nbsp;| 匹配字符串开头&nbsp; &nbsp; &nbsp; &nbsp;|&nbsp;</div><div>| $&nbsp; &nbsp; &nbsp; &nbsp; | 匹配字符串末尾&nbsp; &nbsp; &nbsp; &nbsp;|<br /><br /></div><div></div><div></div><div></div><div>图中的表达式都有专门的例子介绍，可以大概的看看，需要用到的时候在专门来进行查询。</div><div></div><div><h3>python中的re模块</h3></div><div></div><div>在python中，有专门的模块来负责正则表达式，就是re模块。</div><div></div><div><h3>字符串是否匹配规则</h3></div><div></div><div>比如在用户注册里，我们要求用户输入的手机号码，符合手机号码的规律，可以用正则表达式来限制。</div><div></div><div>查看字符串中</div><div>是否有符合要求的字符串，还是以刚才的手机号码为例：</div><div></div><div></div><div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->&nbsp; &nbsp;&nbsp;<span style="color: #0000FF; ">import</span>&nbsp;re<br />&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;=&nbsp;<span style="color: #800000; ">'</span><span style="color: #800000; ">15259340987</span><span style="color: #800000; ">'</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;将正则表达式编译成Pattern对象</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;pattern&nbsp;=&nbsp;re.compile(<span style="color: #800000; ">'</span><span style="color: #800000; ">152\d{8}</span><span style="color: #800000; ">'</span>)<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;使用Pattern匹配文本，获得匹配结果，无法匹配时将返回None</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;match&nbsp;=&nbsp;pattern.match(str)<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;match:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;使用Match获得分组信息</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">print</span>&nbsp;match.group()</div></div><div></div><div></div><div></div><div><br />这里可以看出正则表达式，用的是<br /></div><div></div><div>&nbsp; &nbsp;&nbsp;<span style="background-color: #eeeeee; font-size: 13px;">re.compile(</span><span style="font-size: 13px; color: #800000;">'</span><span style="font-size: 13px; color: #800000;">152\d{8}</span><span style="font-size: 13px; color: #800000;">'</span><span style="background-color: #eeeeee; font-size: 13px;">)</span><br /></div><div></div><div>这个表达式比<br /></div><div></div><div>&nbsp; &nbsp;<span style="background-color: #eeeeee; font-size: 13px;">&nbsp;(</span><span style="background-color: #eeeeee; font-size: 13px;">13</span><span style="background-color: #eeeeee; font-size: 13px;">\d</span><span style="background-color: #eeeeee; font-size: 13px;">|</span><span style="background-color: #eeeeee; font-size: 13px;">14</span><span style="background-color: #eeeeee; font-size: 13px;">[</span><span style="background-color: #eeeeee; font-size: 13px;">57</span><span style="background-color: #eeeeee; font-size: 13px;">]</span><span style="background-color: #eeeeee; font-size: 13px;">|</span><span style="background-color: #eeeeee; font-size: 13px;">15</span><span style="background-color: #eeeeee; font-size: 13px;">[</span><span style="background-color: #eeeeee; font-size: 13px;">^</span><span style="background-color: #eeeeee; font-size: 13px;">4</span><span style="background-color: #eeeeee; font-size: 13px;">,\D]</span><span style="background-color: #eeeeee; font-size: 13px;">|</span><span style="background-color: #eeeeee; font-size: 13px;">17</span><span style="background-color: #eeeeee; font-size: 13px;">[</span><span style="background-color: #eeeeee; font-size: 13px;">13678</span><span style="background-color: #eeeeee; font-size: 13px;">]</span><span style="background-color: #eeeeee; font-size: 13px;">|</span><span style="background-color: #eeeeee; font-size: 13px;">18</span><span style="background-color: #eeeeee; font-size: 13px;">\d)\d{</span><span style="background-color: #eeeeee; font-size: 13px;">8</span><span style="background-color: #eeeeee; font-size: 13px;">}</span><span style="background-color: #eeeeee; font-size: 13px;">|</span><span style="background-color: #eeeeee; font-size: 13px;">170</span><span style="background-color: #eeeeee; font-size: 13px;">[0</span><span style="background-color: #eeeeee; font-size: 13px;">589</span><span style="background-color: #eeeeee; font-size: 13px;">]\d{</span><span style="background-color: #eeeeee; font-size: 13px;">7</span><span style="background-color: #eeeeee; font-size: 13px;">}</span><br /></div><div></div><div>是严格非常多的，他只匹配，152开头的手机号码，当然表达式可以根据你自己的需要来选择，这里只是给一个实例。</div><div></div><div><h3>找出所有符合规则的字符串<br /></h3></div><div></div><div><br />在网页爬虫中，我们需要找出网页的说有链接，用正则匹配就非常容易做到，查看网页源代码中的html，带有网页链接的代码为<br /></div><div></div><div>&nbsp; &nbsp;&nbsp;<span style="background-color: #eeeeee; font-size: 13px;">href</span><span style="background-color: #eeeeee; font-size: 13px;">=</span><span style="font-size: 13px; color: #800000;">"</span><span style="font-size: 13px; color: #800000;">http://tech.sina.com.cn/t/2017-08-17/doc-ifykcppx8531845.shtml</span><span style="font-size: 13px; color: #800000;">"</span><br /></div><div></div><div>正则表达式可以写成：<br /></div><div></div><div>&nbsp; &nbsp;&nbsp;<span style="background-color: #eeeeee; font-size: 13px;">href</span><span style="background-color: #eeeeee; font-size: 13px;">=</span><span style="font-size: 13px; color: #800000;">"</span><span style="font-size: 13px; color: #800000;">(.*?)</span><span style="font-size: 13px; color: #800000;">"</span><br /></div><div></div><div></div><div>python代码为：<br /></div><div></div><div></div><div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->&nbsp; &nbsp;&nbsp;<span style="color: #0000FF; ">import</span>&nbsp;re<br />&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;=&nbsp;<span style="color: #800000; ">'</span><span style="color: #800000; ">href="http://tech.sina.com.cn/t/2017-08-17/doc-ifykcppx8531845.shtml"</span><span style="color: #800000; ">'</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;匹配</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;links&nbsp;=&nbsp;re.findall(<span style="color: #800000; ">'</span><span style="color: #800000; ">href="(.*?)"</span><span style="color: #800000; ">'</span>,&nbsp;str)<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>&nbsp;link&nbsp;<span style="color: #0000FF; ">in</span>&nbsp;links:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">print</span>&nbsp;link<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;输出为：&nbsp;</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;http://tech.sina.com.cn/t/2017-08-17/doc-ifykcppx8531845.shtml</span></div></div><div></div><div></div><div></div><div></div><div><br />找出了所有需要的链接。</div><div></div><div><h3>re模块中重要的接口</h3></div><div></div><div><ul><li>re.compile(pattern, flags=0)</li></ul></div><div></div><div>&nbsp; &nbsp; 这个方法是Pattern类的工厂方法，用于将字符串形式的正则表达式编译为Pattern对象。 第二个参数flag是匹配模式，取值可以使用按位或运算符'|'表示同时生效，比如re.I | re.M。另外，你也可以在regex字符串中指定模式，比如re.compile('pattern', re.I | re.M)与re.compile('(?im)pattern')是等价的。&nbsp;</div><div></div><div>&nbsp; &nbsp; 语句</div><div></div><div><span style="white-space:pre">	</span>prog = re.compile(pattern)</div><div><span style="white-space:pre">	</span>result = prog.match(string)</div><div><span style="white-space:pre">	</span>和</div><div><span style="white-space:pre">	</span></div><div><span style="white-space:pre">	</span>result = re.match(pattern, string)</div><div>&nbsp; &nbsp; 等价，第二种写法较为方便。</div><div></div><div></div><div><ul><li>re.search(pattern, string, flags=0)</li></ul></div><div></div><div></div><div>&nbsp; &nbsp; 这个方法用于查找字符串中可以匹配成功的子串。从string的pos下标处起尝试匹配pattern，如果pattern结束时仍可匹配，则返回一个Match对象；若无法匹配，则将pos加1后重新尝试匹配；直到pos=endpos时仍无法匹配则返回None。&nbsp;</div><div><span style="white-space:pre">	</span>pos和endpos的默认值分别为0和len(string))；re.search()无法指定这两个参数，参数flags用于编译pattern时指定匹配模式。&nbsp;</div><div></div><div></div><div><ul><li>re.match(pattern, string, flags=0)</li></ul></div><div></div><div>&nbsp; &nbsp; 这个方法将从string的pos下标处起尝试匹配pattern；如果pattern结束时仍可匹配，则返回一个Match对象；如果匹配过程中pattern无法匹配，或者匹配未结束就已到达endpos，则返回None。&nbsp;</div><div><span style="white-space:pre">	</span>pos和endpos的默认值分别为0和len(string)；re.match()无法指定这两个参数，参数flags用于编译pattern时指定匹配模式。&nbsp;</div><div><span style="white-space:pre">	</span>注意：这个方法并不是完全匹配。当pattern结束时若string还有剩余字符，仍然视为成功。想要完全匹配，可以在表达式末尾加上边界匹配符'$'。&nbsp;</div><div></div><div></div><div><ul><li>re.split(pattern, string, maxsplit=0, flags=0)</li></ul></div><div></div><div><span style="white-space:pre">	</span>按照能够匹配的子串将string分割后返回列表。maxsplit用于指定最大分割次数，不指定将全部分割。&nbsp;</div><div></div><div></div><div><ul><li>re.findall(pattern, string, flags=0)</li></ul></div><div></div><div><span style="white-space:pre">	</span>搜索string，以列表形式返回全部能匹配的子串。&nbsp;</div><div></div><div><ul><li>re.sub(pattern, repl, string, count=0, flags=0)</li></ul></div><div></div><div>&nbsp; &nbsp; 使用repl替换string中每一个匹配的子串后返回替换后的字符串。&nbsp;</div><div><span style="white-space:pre">	</span>当repl是一个字符串时，可以使用\id或\g&lt;id&gt;、\g&lt;name&gt;引用分组，但不能使用编号0。&nbsp;</div><div><span style="white-space:pre">	</span>当repl是一个方法时，这个方法应当只接受一个参数（Match对象），并返回一个字符串用于替换（返回的字符串中不能再引用分组）。&nbsp;</div><div><span style="white-space:pre">	</span>count用于指定最多替换次数，不指定时全部替换。&nbsp;</div><div></div><div><h3>常用的正则表达式语句</h3></div><div></div><div><ul><li>匹配邮箱：\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}</li><li>匹配中文：[\u4e00-\u9fa5]</li><li>匹配IP（IPV4）：(\d+)\.(\d+)\.(\d+)\.(\d+)</li><li>匹配身份证：\d{15}|\d{17}[0-9Xx]</li><li>匹配手机号：(13\d|14[57]|15[^4,\D]|17[13678]|18\d)\d{8}|170[0589]\d{7}</li></ul></div><div></div><div></div><div></div><div></div><div></div><div></div><div><h3>正则表达式工具<br /><br /></h3></div><div></div><div>正则表达式语法比较复杂，开始没有经验的话，调试起来比较麻烦，现在网上有很多的正则表达式工具，能帮助我们快速的进行试验。有客户端的工具也有web工具，用起来都较为方便。</div><div></div><div>用的较多的是RegexBuddy这一款工具，如图，他可以自动的生成各种语言版本的正则表达式的例子：</div><div>如下</div><div></div><div><img src="http://images.cnblogs.com/cnblogs_com/bugingcode/1146958/o_RegexBuddy.png" width="686" height="586" alt="" /></div><div></div><div>更多入门教程可以参考：<a href="http://www.bugingcode.com/python_start/">http://www.bugingcode.com/python_start/</a></div><div></div><img src ="http://www.cppblog.com/AutomateProgram/aggbug/215471.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2018-01-12 15:13 <a href="http://www.cppblog.com/AutomateProgram/archive/2018/01/12/215471.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>你应该知道的推荐算法--皮尔逊公式介绍和意义</title><link>http://www.cppblog.com/AutomateProgram/archive/2014/07/23/207759.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Wed, 23 Jul 2014 08:08:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2014/07/23/207759.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/207759.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2014/07/23/207759.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/207759.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/207759.html</trackback:ping><description><![CDATA[<p align="center" style="text-align:center"><span style="font-size:15.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">皮尔逊公式</span></p>  <p style="text-indent:24.0pt;"><strong><span style="font-size:12.0pt;font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;"></span></strong></p><p style="text-indent:24.0pt;"><strong><span style="font-size:12.0pt;font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">前言</span></strong></p>  <p style="text-indent:21.0pt;"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">在很多推荐算法的地方，涉及到了很多关于数学的公式，如果简单的应用这些公式，那当然较为的简单，当如果有真正的理解这些公式里面隐含着的道理那就要下一定的苦功夫。</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">我们这里不从皮尔逊的公式讲起，我们从物物的推荐开始。</span></p>  <p style="text-indent:24.0pt;"><strong><span style="font-size:12.0pt;font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">问题</span></strong></p>  <p style="text-indent:21.0pt;"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">这里以音乐的推荐为例子，对于音乐的推荐很多人都在做，比较好解释清楚。给你一首歌曲让你推荐10首相识的歌曲。推荐的数据来源是这样子的。每个人都会通过搜索歌曲来听他们自己喜欢的歌曲。这样歌曲就能有一些相关的特性了，关于数据的问题我们等下再进一步的说明。</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">如果我们不按数学的方法来思考这个问题的话，平常的人我们会怎样来解决这个问题呢？我们是这样想的，某一首音乐，他会存在不同的用户中，如果这些用户也存在着某些歌曲，我们就可以计算这首歌曲中在不同的用户中还存在了多少歌曲，这些歌曲的个数是多少，就可以有一个排序，这就是我们要的相识歌曲。</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">我们简单的用数学来描述一下：</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">假设有两个人甲，乙，三首歌曲A B C，如果甲有这首歌就标记为1，没有的话就标记为零</span></p>  <p align="center" style="text-align:center;text-indent:21.0pt;"><span style=" font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">&nbsp;&nbsp; A B C </span></p>  <p align="center" style="text-align:center;text-indent:21.0pt;"><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">甲 1 1 1 </span></p>  <p align="center" style="text-align:center;text-indent:21.0pt;"><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">乙 0 1 0&nbsp;</span></p><p align="center" style="text-align:center;text-indent:21.0pt;"><span style="font-family: 微软雅黑, sans-serif; font-size: 12pt;"> </span></p>  <p align="left" style="text-indent: 21pt;"><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">按照我们的算法</span></p>  <p align="left" style="text-indent: 21pt;"><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">在甲用户中</span></p>  <p align="left" style="text-indent: 21pt;"><span style=" font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">Dict[A][B]=1</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">，Dict[A][C]=1</span></p>  <p align="left" style="text-indent: 21pt;"><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">乙用户没有A</span></p>  <p align="left" style="text-indent: 21pt;"><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">这样歌曲A和B、C都相识，而且相识度都一样为1。眨眼看上去这种算法，很完美，非常的完美，因为平时我们聊起推荐系统的时候，时不时的一开口就让你这样做了。真的无懈可击了当然不是这样，让我们再看一次数据，你会发现，其实A,C&nbsp;&nbsp;&nbsp; 的数据是一样一样的，理论上我们会觉得A，跟C的相识度是最高的，但是他的相识度却和B一样，这开起来是不合理的，但这是为什么呢。</span></p>  <p align="left">&nbsp;</p>  <p align="center" style="text-align:center;"><img src="http://www.cppblog.com/images/cppblog_com/automateprogram/p1.png" width="65" height="122" alt="" /><br /></p>  <p style="text-indent:24.0pt;"><strong><span style="font-size:12.0pt;font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">改进</span></strong></p>  <p align="left" style="text-indent: 21pt;"><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">回想一下如果进一步的假设，用1来标记喜欢，用0来标记不喜欢的话，我们这一种算法其实是没有考虑不喜欢这个因素的。很多人都认为不能这样假设，我告诉你，其实这是数据的问题，如果我们把使用的数据能够满足这里的假设，完全是可以采用的。</span></p>  <p align="left" style="text-indent: 21pt;"><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">这里我想说的是，我并不认为我们使用的第一个算法，有多大的问题，只是想说的是，这种算法还不完美，还可以有改进的空间，这不就是我们一直所拥有的理念，把事情改变的更好。</span></p>  <p align="left" style="text-indent: 21pt;"><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">进一步的再说：如果我们的数据不仅是1和0呢，用户对歌曲有打分了，怎么办呢？</span></p>  <p align="center" style="text-align:center;text-indent:21.0pt;"><span style=" font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">&nbsp; A B C</span></p>  <p align="center" style="text-align:center;text-indent:21.0pt;"><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">甲 3 4 3</span></p>  <p align="center" style="text-align:center;text-indent:21.0pt;"><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">乙 0 2 0</span></p>  <p style="text-indent:21.0pt;"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">当然很多人会说，算法也可以哦，字典里的数据跟着变Dict[A][B]=3，Dict[A][C]=3，但是有个问题不知道有没有注意到，每个人对打分的理解是不一样的，有的人觉得3分就是很好听的歌曲，而有的人要觉得4分才是很好听的歌曲，也就是说，每个人打分的标准不一样，导致了打出的分数和比人比较的时候是不一样的，但自己的标准大部分的时间是不会变的。</span></p>  <p style="text-indent:24.0pt;"><strong><span style="font-size:12.0pt;font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">皮尔逊公式</span></strong></p>  <p style="text-indent:21.0pt;"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">这里我们需要一种算法。能够概括这些情况的。这就是皮尔逊公式。</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.9pt;background:white"><span style="font-size:10.5pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;">假设有两个变量X、Y，那么两变量间的皮尔逊相关系数可通过以下公式计算：</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.9pt;background:white"><span style="font-size:10.5pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;">公式一：<br /><br /> &nbsp;<img src="http://www.cppblog.com/images/cppblog_com/automateprogram/p2.gif" width="519" height="51" alt="" /></span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.9pt;background:white"><span style="font-size:10.5pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;">皮尔逊相关系数计算公式</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.9pt;background:white"><span style="font-size:10.5pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;">公式二：<br /><br /> &nbsp;<img src="http://www.cppblog.com/images/cppblog_com/automateprogram/p3.gif" width="315" height="56" alt="" /></span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.9pt;background:white"><span style="font-size:10.5pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;">皮尔逊相关系数计算公式</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.9pt;background:white"><span style="font-size:10.5pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;">公式三：<br /><br /> &nbsp;<img src="http://www.cppblog.com/images/cppblog_com/automateprogram/p4.gif" width="221" height="59" alt="" /></span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.9pt;background:white"><span style="font-size:10.5pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;">皮尔逊相关系数计算公式</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.9pt;background:white"><span style="font-size:10.5pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;">公式四：<br /><br /> &nbsp;<img src="http://www.cppblog.com/images/cppblog_com/automateprogram/p5.gif" width="303" height="95" alt="" /></span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.9pt;background:white"><span style="font-size:10.5pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;">皮尔逊相关系数计算公式</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.9pt;background:white">&nbsp;</p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.9pt;background:white"><span style="font-size:10.5pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;">以上列出的四个公式等价，其中E是数学期望，cov表示协方差，N表示变量取值的个数。</span></p>  <p><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">皮尔逊算法过于复杂，如果要有点理解的话，可以使用把维数降到二维，这样就跟余弦定理有点相识了，相识度就是两条直线的夹角，角度为0的时候，皮尔逊的值为1，就是最相识的，如果角度为180度，代表两个牛马不相干，皮尔逊的值为-1。</span></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/automateprogram/p6.png" width="556" height="288" alt="" /><br /></p>  <p style="text-indent:24.0pt;"><strong><span style="font-size:12.0pt;font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">总结</span></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">很多时候，以前牛逼的数学家已经给了我们很多很好用的数学公式，只是如果没有真正去用过的话，我们并不知道他所涉及的原理。好好的研究数学公式，他会给给我们的算法带来一定的优化作用。关于公式的优化比较难了，以前的数学家给了我们很多的想法，而能够优化的就是我们的数据，如何取数据，这里主要的是，那个数据离用户的行为越近，离你使用的数学模型越近，那个数据就越好用。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">参考：</span></p>  <p style="text-indent:21.0pt"><a href="http://lobert.iteye.com/blog/2024999"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">http://lobert.iteye.com/blog/2024999</span></a></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">http://zh.wikipedia.org/wiki/%E7%9A%AE%E5%B0%94%E9%80%8A%E7%A7%AF%E7%9F%A9%E7%9B%B8%E5%85%B3%E7%B3%BB%E6%95%B0</span></p><img src ="http://www.cppblog.com/AutomateProgram/aggbug/207759.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2014-07-23 16:08 <a href="http://www.cppblog.com/AutomateProgram/archive/2014/07/23/207759.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sphinx下的lua客户端</title><link>http://www.cppblog.com/AutomateProgram/archive/2014/05/04/206814.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Sun, 04 May 2014 08:30:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2014/05/04/206814.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/206814.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2014/05/04/206814.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/206814.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/206814.html</trackback:ping><description><![CDATA[一直想写个lua的sphinx(coreseek)下的客户端，以后通过<span style="font-size: 13px; font-family: verdana, Arial, helvetica, sans-seriff; color: #4b4b4b; line-height: 20px; background-color: #ffffff">OpenResty来调用，就不用通过php或者python间接的调用，影响并发的效率。<br /><br />终于五一的时候，歇了一些，一口气把他写完了，但是只是能用，并没有太多的错误处理。<br /><br />代码在github上：<a href="https://github.com/nd791899/sphinx-lua">https://github.com/nd791899/sphinx-lua</a><br /><br /><br /><pre style="box-sizing: border-box; margin-bottom: 0px; font-size: 15px; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-variant: normal; white-space: pre-wrap; text-transform: none; word-spacing: 0px; font-weight: normal; color: rgb(51,51,51); font-style: normal; margin-top: 0px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">sphinx lua client
使用lua连接sphinx的服务端，提交搜索请求。
这个版本还有很多东西都是测试的，没有错误的处理。
下一个版本是集成的ngx_lua上

测试的数据：
1	qq音乐	据国外媒体报道，谷歌将巨资收购百度，	2010-04-01 22:20:07	1	2
2	qq	4月1日消息，	2010-04-01 23:25:48	1	3
3	死都要上！Opera Mini 体验版抢先试用	Opera	2010-04-01 12:01:00	2	3


测试的结果
Query 'qq' retrieved 2 of 2 matches.

Query stats:

        'qq' found 2 times in 2 documents


Matches:



1. doc_id=2, weight=499999
attrs:
group_id        3
date_added      1270135548


2. doc_id=1, weight=499998
attrs:
group_id        2
date_added      1270131607</pre><br /></span><img src ="http://www.cppblog.com/AutomateProgram/aggbug/206814.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2014-05-04 16:30 <a href="http://www.cppblog.com/AutomateProgram/archive/2014/05/04/206814.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>crontab下执行python脚本不成功，出现错误</title><link>http://www.cppblog.com/AutomateProgram/archive/2014/03/25/206323.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Tue, 25 Mar 2014 03:06:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2014/03/25/206323.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/206323.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2014/03/25/206323.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/206323.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/206323.html</trackback:ping><description><![CDATA[<p style="text-indent:21.0pt;"><span style="font-family:宋体;">crontab执行不成功的排除步骤：<br />&nbsp; &nbsp; 1.看下crontab的日志</span>/var/log/cron，看脚本有没有执行<br />&nbsp; &nbsp; &nbsp;2.是不是脚本路径问题，因为crontab跟我们的默认路径是不一样的。<br />&nbsp; &nbsp; &nbsp;3.自己的log日志的排除<br /><br /><span style="font-family:宋体;">&nbsp; &nbsp; 碰到了一个比较奇怪的问题，用</span>shell<span style="font-family:宋体;">命令直接执行</span> python xxx.py<span style="font-family:宋体;">的时候是正常的，但是用</span>crontab<span style="font-family:宋体;">执行的时候，</span> <span style="font-family:宋体;">没有任何的反映，到</span>/var/log/cron<span style="font-family:宋体;">的</span>crontab<span style="font-family:宋体;">日志里去看，发现是有执行的，排除了</span>crontab<span style="font-family:宋体;">的问题，进一步想应该是</span>python<span style="font-family:宋体;">的问题了，直接把日志打开看下</span></p>  <p>xxsh &gt;&gt; /tmp/test.txt 2&gt;&amp;1</p>  <p><span style="font-family:宋体;">错误日志：</span></p>  <p>Traceback (most recent call last):</p>  <p>&nbsp; File "", line 8, in ?</p>  <p>&nbsp;&nbsp;&nbsp; import tui_pb2</p>  <p>&nbsp; File ", line 4, in ?</p>  <p>&nbsp;&nbsp;&nbsp; from google.protobuf import descriptor as _descriptor</p>  <p>ImportError: No module named google.protobuf</p>  <p>&nbsp;</p>  <p style="text-indent:21.0pt;"><span style="font-family:宋体;">模块没有安装，但是</span>shell<span style="font-family:宋体;">执行的时候没有出现这个问题呀，想了下，我把</span>python<span style="font-family:宋体;">升级到</span>2.7<span style="font-family:宋体;">了，现在有两个</span>python<span style="font-family:宋体;">的版本，看了一下代码的头</span></p>  <p>#! /usr/bin/python</p>  <p>#-*- coding:utf-8 -*-</p>  <p>&nbsp;</p>  <p>/usr/bin/python &#8211;V</p>  <p>Python 2.4.3</p>  <p style="text-indent:21.0pt;"><span style="font-family:宋体;">这就是问题所在了，我用</span>crontab<span style="font-family:宋体;">调用的是</span>Python 2.4.3<span style="font-family:宋体;">，当然就缺少模块了。把路径改过来就</span>ok<span style="font-family:宋体;">了，或者</span>shell<span style="font-family:宋体;">直接带</span>python<span style="font-family:宋体;">的真是路径。</span></p><img src ="http://www.cppblog.com/AutomateProgram/aggbug/206323.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2014-03-25 11:06 <a href="http://www.cppblog.com/AutomateProgram/archive/2014/03/25/206323.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql判断字段中是否存在中文字符（sql语句）</title><link>http://www.cppblog.com/AutomateProgram/archive/2014/01/13/205342.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Mon, 13 Jan 2014 07:19:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2014/01/13/205342.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/205342.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2014/01/13/205342.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/205342.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/205342.html</trackback:ping><description><![CDATA[原文地址：<a href="http://blog.csdn.net/dengyue701/article/details/7261071">http://blog.csdn.net/dengyue701/article/details/7261071<br /><br /><div>一种简单的做法就是判断 字符的个数</div><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 18px;">使用length与char_length两个函数</span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 18px;"></span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">length:&nbsp;&nbsp; 是计算字段的长度一个汉字是算三个字符,一个数字或字母算一个字符</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">char_length:不管汉字还是数字或者是字母都算是一个字符</p><br /><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 18px;">长度相同则字段中无汉字，不相同则肯定有汉字</span></p></a><img src ="http://www.cppblog.com/AutomateProgram/aggbug/205342.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2014-01-13 15:19 <a href="http://www.cppblog.com/AutomateProgram/archive/2014/01/13/205342.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用itms-services协议 在线安装 ipa支持ios7.1</title><link>http://www.cppblog.com/AutomateProgram/archive/2013/12/20/204914.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Fri, 20 Dec 2013 08:04:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2013/12/20/204914.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/204914.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2013/12/20/204914.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/204914.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/204914.html</trackback:ping><description><![CDATA[对于ios7.1以下的设备方法在网上已经很多了，最近大家都碰到了一个问题就是原有的方式并不支持ios7.1。<br />google了一下才发现plist必须使用https。<br /><a href="https://discussions.apple.com/thread/5385948?start=0&amp;tstart=0">https://discussions.apple.com/thread/5385948?start=0&amp;tstart=0</a><br />这个是为什么呢？<img src ="http://www.cppblog.com/AutomateProgram/aggbug/204914.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2013-12-20 16:04 <a href="http://www.cppblog.com/AutomateProgram/archive/2013/12/20/204914.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于ios越狱开发的那些事--iosopendev</title><link>http://www.cppblog.com/AutomateProgram/archive/2013/11/18/204303.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Mon, 18 Nov 2013 02:34:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2013/11/18/204303.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/204303.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2013/11/18/204303.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/204303.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/204303.html</trackback:ping><description><![CDATA[<p align="center" style="text-align:center"><strong><span style="font-size:18.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">关于ios越狱开发的那些事</span></strong></p>  <p align="center" style="text-align:center"><strong><span style="font-size:8.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">iosopendev</span></strong><strong><span style="font-size:8.0pt;font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">的安装和使用</span></strong></p>  <p align="center" style="text-align:center"><strong>&nbsp;</strong></p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">人们总是寻求着简便的方法，来追求工作的效率，这样很多的工具就出来了。在前篇Theos的介绍中，我们需要编写makefile文件，还有很多工作自己需要去做。有没有一种简便的方法能够快捷如模板一样的东西，帮我们完成很多的工作吧，这个工具就是iOSOpenDev。<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></p><p class="MsoNormal"><span lang="EN-US"><a href="http://www.cnblogs.com/mengshu-lbq/archive/2013/01/28/2879866.html"><strong><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;
color:windowtext;text-decoration:none;text-underline:none">IOS OpenDev</span></strong><strong><span lang="EN-US" style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;
color:windowtext;text-decoration:none;text-underline:none"><span lang="EN-US">下载与安装</span></span></strong></a></span><strong><span lang="EN-US" style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;"><o:p></o:p></span></strong></p><p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">&nbsp;</span></p><p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">1.</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">下载地址<span lang="EN-US">&nbsp;<a href="http://iosopendev.com/download/" target="_blank"><span style="color:windowtext;
text-decoration:none;text-underline:none">http://iosopendev.com/download/</span></a><o:p></o:p></span></span></p><p class="MsoNormal"><a name="_GoBack" style="width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat;"></a><span lang="EN-US" style="font-family:
&quot;微软雅黑&quot;,&quot;sans-serif&quot;">2.&nbsp;</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">安装的过程中，如果出现错误的话，可以参考：<span lang="EN-US"><a href="https://github.com/kokoabim/iOSOpenDev/wiki/Troubleshoot" target="_blank"><span style="color:windowtext;text-decoration:none;text-underline:
none">https://github.com/kokoabim/iOSOpenDev/wiki/Troubleshoot</span></a><o:p></o:p></span></span></p><p class="MsoNormal"><span style="font-family: 微软雅黑, sans-serif;">当然有时候出现的提示不知道是什么问题的话，可以将以上的问题都<span lang="EN-US">FIX</span>下，<span lang="EN-US">FIX</span>一个再安装一下看看，<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal"><span style="font-family: 微软雅黑, sans-serif;">正如本人在安装的过程中，出现如下的错误：<br /><br /></span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->Jan&nbsp;28&nbsp;14:20:30&nbsp;xxxmatoMacBookinstalld[2020]:&nbsp;PackageKit:&nbsp;Install&nbsp;Failed:&nbsp;Error&nbsp;Domain=PKInstallErrorDomain&nbsp;Code=112&nbsp;"An&nbsp;error&nbsp;occurred&nbsp;while&nbsp;running&nbsp;scripts&nbsp;from&nbsp;the&nbsp;package&nbsp;&#8220;iOSOpenDev-1.5.pkg&#8221;."&nbsp;UserInfo=0x7fc17a5291f0&nbsp;{NSFilePath=./postinstall,&nbsp;NSURL=file:<span style="color: #008000; ">//</span><span style="color: #008000; ">localhost/Users/xxxx/Downloads/iOSOpenDev-1.5.pkg#iodsetup.pkg,&nbsp;PKInstallPackageIdentifier=com.iosopendev.iosopendev15.iod-setup.pkg,&nbsp;NSLocalizedDescription=An&nbsp;error&nbsp;occurred&nbsp;while&nbsp;running&nbsp;scripts&nbsp;from&nbsp;the&nbsp;package&nbsp;&#8220;iOSOpenDev-1.5.pkg&#8221;.}&nbsp;{</span><span style="color: #008000; "><br /></span>NSFilePath&nbsp;=&nbsp;"./postinstall";<br />NSLocalizedDescription&nbsp;=&nbsp;"An&nbsp;error&nbsp;occurred&nbsp;while&nbsp;running&nbsp;scripts&nbsp;from&nbsp;the&nbsp;package&nbsp;\U201ciOSOpenDev-1.5.pkg\U201d.";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSURL&nbsp;=&nbsp;"file://localhost/Users/xxxx/Downloads/iOSOpenDev-1.5.pkg#iodsetup.pkg";<br />PKInstallPackageIdentifier&nbsp;=&nbsp;"com.iosopendev.iosopendev15.iod-setup.pkg";<br />&nbsp;&nbsp;&nbsp;&nbsp;}</div><p class="MsoNormal"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">按照<span lang="EN-US">&nbsp;https://github.com/kokoabim/iOSOpenDev/wiki/Troubleshoot
&nbsp;</span>中的<span lang="EN-US">Xcode License </span>问题，<span lang="EN-US">FIX</span>下，<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" style="text-indent:24.0pt"><span lang="EN-US" style="font-size:8.0pt">&nbsp;</span></p><p class="MsoNormal" align="left" style="line-height: 13.5pt;"><span lang="EN-US" style="font-size:9.0pt;font-family:Courier;mso-bidi-font-family:
Courier;color:purple;mso-font-kerning:0pt">1</span><span lang="EN-US" style="font-size: 9pt; font-family: Courier;">. Download https:</span><span lang="EN-US" style="font-size:9.0pt;font-family:Courier;mso-bidi-font-family:Courier;
color:green;mso-font-kerning:0pt">//github.com/downloads/kokoabim/iOSOpenDev/xcode-license.tar.gz
and extract xcode-license out of it.</span><span lang="EN-US" style="font-size:
9.0pt;font-family:Courier;mso-bidi-font-family:Courier;color:purple;mso-font-kerning:
0pt">2</span><span lang="EN-US" style="font-size: 9pt; font-family: Courier;">. Open Terminal,
go to the directory where the </span><span lang="EN-US" style="font-size:9.0pt;
font-family:Courier;mso-bidi-font-family:Courier;color:blue;mso-font-kerning:
0pt">file</span><span lang="EN-US" style="font-size: 9pt; font-family: Courier;"> was extracted
to and run: ./xcode-license<o:p></o:p></span></p><p class="MsoNormal">





<span style="font-size:12.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;mso-bidi-font-family:
&quot;Times New Roman&quot;;mso-bidi-theme-font:minor-bidi;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">2.然后重新安装就可以了。<br /><br /></span></p><div><img src="http://www.cppblog.com/images/cppblog_com/automateprogram/1.png" width="432" height="309" alt="" /></div><p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">3.</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">所有方案都试过了，还是有问题的话：<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">可以给<span lang="EN-US">&nbsp;&nbsp;</span></span><span lang="EN-US"><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#100;&#101;&#118;&#64;&#105;&#111;&#115;&#111;&#112;&#101;&#110;&#100;&#101;&#118;&#46;&#99;&#111;&#109;&#63;&#115;&#117;&#98;&#106;&#101;&#99;&#116;&#61;&#105;&#79;&#83;&#79;&#112;&#101;&#110;&#68;&#101;&#118;&#37;&#50;&#48;&#73;&#110;&#115;&#116;&#97;&#108;&#108;&#101;&#114;&#37;&#50;&#48;&#76;&#111;&#103;"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;color:windowtext;text-decoration:none;
text-underline:none">dev@iosopendev.com</span></a></span><span lang="EN-US" style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">&nbsp;</span><span style="font-family:
&quot;微软雅黑&quot;,&quot;sans-serif&quot;">发邮件，别忘了带上日志（<span lang="EN-US">command </span>＋<span lang="EN-US"> L, </span>调出日志）<span lang="EN-US">&nbsp;<o:p></o:p></span></span></p><p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">4.</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">如果编译的时候出现如下的错误：<br /></span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->target&nbsp;specifies&nbsp;product&nbsp;type&nbsp;&#8216;com.apple.product-type.library.dynamic&#8217;,&nbsp;but&nbsp;there&#8217;s&nbsp;no&nbsp;such&nbsp;product&nbsp;type&nbsp;<span style="color: #0000FF; ">for</span>&nbsp;the&nbsp;&#8216;iphoneos&#8217;&nbsp;platform</div><p class="MsoNormal"><br /></p><p class="MsoNormal"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">可以重启下机器看看。一般是因为刚安装完<span lang="EN-US">IOS Open-DEV</span>还没有重启的缘故。<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:Times;
mso-fareast-font-family:&quot;Times New Roman&quot;;mso-bidi-font-family:&quot;Times New Roman&quot;;
mso-font-kerning:0pt">&nbsp;</span></p><p class="MsoNormal"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">好了，基本上的搭建已经完成了。我们来完成前面一篇文章的<span lang="EN-US">helloworld</span>的程序吧。<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal">





<span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">打开<span lang="EN-US">xcode</span>，建立一个<span lang="EN-US">logos tweak</span>工程：<br /></span><img src="http://www.cppblog.com/images/cppblog_com/automateprogram/2.jpg" width="448" height="309" alt="" /><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;"><br /><br /></span><span style="font-size:12.0pt;font-family:宋体;
mso-ascii-font-family:Cambria;mso-ascii-theme-font:minor-latin;mso-fareast-theme-font:
minor-fareast;mso-hansi-font-family:Cambria;mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:&quot;Times New Roman&quot;;mso-bidi-theme-font:minor-bidi;
mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">生成了如下的工程：</span><span style="font-family: 微软雅黑, sans-serif;"><br /></span></p><br /><img src="http://www.cppblog.com/images/cppblog_com/automateprogram/3.png" width="276" height="352" alt="" /><br /><br /><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">编写</span><span style="font-size:12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;Times New Roman&quot;;">helloworld_1.xm</span><span style="font-size: 12.0pt;font-family:宋体;Times New Roman&quot;;">文件，跟上次的代码一模样。<br /><br /></span><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#import&lt;UIKit/UIKit.h&gt;<br />%hookSpringBoard<br />-(<span style="color: #0000FF; ">void</span>)applicationDidFinishLaunching:(id)application&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;%orig;<br />UIAlertView&nbsp;*alert&nbsp;=&nbsp;[[UIAlertViewalloc]&nbsp;initWithTitle:@"Welcome"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message:@"Welcome&nbsp;to&nbsp;漂漂&nbsp;iPhone!"<br /><span style="color: #0000FF; ">delegate</span>:nil<br />cancelButtonTitle:@"Thanks"<br />otherButtonTitles:nil];<br />&nbsp;&nbsp;&nbsp;&nbsp;[alert&nbsp;show];<br />&nbsp;&nbsp;&nbsp;&nbsp;[alert&nbsp;release];<br />}<br />%end</div><span style="font-size: 12.0pt;font-family:宋体;Times New Roman&quot;;"><br /></span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">添加必须的库文件：如图<br /></span><img src="http://www.cppblog.com/images/cppblog_com/automateprogram/4.jpg" width="266" height="78" alt="" /><br /><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">编译文件，生成</span><span style="font-size:12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;Times New Roman&quot;;">deb</span><span style="font-size: 12pt; font-family: 宋体;">文件<br /></span><img src="http://www.cppblog.com/images/cppblog_com/automateprogram/5.jpg" width="241" height="335" alt="" /><br /><br /><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">在当前目录下的</span><span style="font-size:12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;Times New Roman&quot;;">Packages</span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">下生成了</span><span style="font-size:12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;Times New Roman&quot;;">deb</span><span style="font-size: 12pt; font-family: 宋体;">文件<br /></span><img src="http://www.cppblog.com/images/cppblog_com/automateprogram/6xx.jpg" width="382" height="108" alt="" /><br /><br /><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">总体看上来</span><span style="font-size:12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;Times New Roman&quot;;">iosopendev</span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">简化了之前的很多东西，使得</span><span style="font-size:12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;Times New Roman&quot;;">ios</span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">的越狱开发规范话了很多。关于</span><span style="font-size:12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;Times New Roman&quot;;">hook</span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">的东西就介绍到这边，还有很多的东西需要学习才能达到所谓的入门。</span><img src ="http://www.cppblog.com/AutomateProgram/aggbug/204303.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2013-11-18 10:34 <a href="http://www.cppblog.com/AutomateProgram/archive/2013/11/18/204303.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于ios越狱开发的那些事--Theos开发</title><link>http://www.cppblog.com/AutomateProgram/archive/2013/11/11/204205.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Mon, 11 Nov 2013 03:16:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2013/11/11/204205.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/204205.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2013/11/11/204205.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/204205.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/204205.html</trackback:ping><description><![CDATA[<p align="center" style="text-align:center"><strong><span style="font-size:18.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">关于ios越狱开发的那些事</span></strong></p>  <p>&nbsp;</p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">也许吧，每每接触某些新东西的时候，都有点犯晕吧，这不是应该要的。</span></p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">第一次接触ios越狱开发，也是这样吧。这篇主要是从无到有的说一下ios越狱的开发，网上很多的教程大部门都比较旧了吧，放在新设备上总是出现这样那样的问题，使人很是头疼。</span></p>  <p style="text-indent:24.0pt">&nbsp;</p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">从windows转到mac下开发，总有这个那个的不适应。习惯了vs的开发，突然用起了xcode难免有些为难，不是说xcode不好，两者都是非常好用的工具。</span></p>  <p style="text-indent:24.0pt">&nbsp;</p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">当然了，开发</span><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">越狱程序和日常开发的iOS程序很相似，不过，越狱程序能做更强大的事情。你的设备也必须是要越狱的，你就能够hook到apple提供的几乎所有的类了，厉害吧，这样我们就能够控制iPhone/iPad的功能了。</span></p>  <p style="text-indent:24.0pt"><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">怎么开发呢，iPhone发展到这个阶段，开发已经非常的成熟了，在做一些事情的时候我们可以依靠现有的工具，这里主要介绍Theos。</span></p>  <p style="text-indent:24.0pt">Theos<span style="font-family:宋体;">是</span><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">@DHowett</span><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">大神搞的，大幅简化了编写越狱程序的流程。DHowett介绍了如何再Mac和Linux上开发iOS越狱程序，本文将只介绍如何在Mac上开发。</span></p>  <p style="margin:0cm;margin-bottom:.0001pt"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">地址在：</span><a href="https://github.com/DHowett/theos"><span style="font-size: 12.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">https://github.com/DHowett/theos</span></a><span style="font-size:12.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">有空自己去膜拜一下呗。</span></p>  <p style="text-indent:24.0pt">&nbsp;</p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">Theos</span><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">能做到什么程度呢，生成一个框架，编译生成deb，这已经是相当的方便了，相当的逆天。</span></p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">首先，准备工作要做好，配置Theos的工作环境吧。</span></p>  <p style="text-indent:24.0pt">&nbsp;</p>  <p style="text-indent:24.0pt"><strong><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">1.</span></strong><strong><span style="font-size:16.0pt;font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">给xcode安装command line tools</span></strong></p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">从10.8开始xcode的command line tools就要自己安装了，如果没安装的话，会出现各种问题，比如gcc没有安装，等等各种诡异的问题。新手很是害怕。</span></p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">自己到官网搜索下载吧：</span></p>  <p style="margin:0cm;margin-bottom:.0001pt"><a href="https://developer.apple.com/downloads/index.action?=Command%20Line%20Tools%20%28OS%20X%20Mountain%20Lion%29">https://developer.apple.com/downloads/index.action?=Command%20Line%20Tools%20%28OS%20X%20Mountain%20Lion%29</a></p>  <p style="margin:0cm;margin-bottom:.0001pt">&nbsp;</p>  <p style="margin:0cm;margin-bottom:.0001pt">&nbsp;</p>  <p style="text-indent:24.0pt"><strong><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">2.</span></strong><strong><span style="font-size:16.0pt;font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">还需要MacPorts</span></strong></p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">那啥是MacPorts呢，</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;background:white;">Mac</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Kaiti SC Bold&quot;; background:white;">下面除了用</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;; background:white;">dmg</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Mongolian Baiti&quot;;background:white;">、</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;; background:white;">pkg</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Kaiti SC Bold&quot;;background:white;">来安装软件外</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Microsoft Yi Baiti&quot;; background:white;">，</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Kaiti SC Bold&quot;;background:white;">比较方便的还有用</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;; background:white;">MacPorts</span><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;;Kaiti SC Bold&quot;;background:white;">来帮助你安装其他应用程序</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Microsoft Yi Baiti&quot;;background:white;">，</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Kaiti SC Bold&quot;;background:white;">跟</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;; background:white;">BSD</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Kaiti SC Bold&quot;;background:white;">中的</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;; background:white;">ports</span><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;;Kaiti SC Bold&quot;;background:white;">道理一样</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Mongolian Baiti&quot;;background:white;">。</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;; background:white;">MacPorts</span><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;;Kaiti SC Bold&quot;;background:white;">就像</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;background:white;">apt-get</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Mongolian Baiti&quot;; background:white;">、</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;; background:white;">yum</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Kaiti SC Bold&quot;;background:white;">一样</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Microsoft Yi Baiti&quot;; background:white;">，</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Kaiti SC Bold&quot;;background:white;">可以快速安装些软件</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Mongolian Baiti&quot;; background:white;">。经常用linux服务器的人就非常的熟悉了吧，总是用这么些好人，已经替我想好了很多的东西。那为什么需要这个</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">MacPorts</span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">，因为我们要打包deb，需要用到dpkg。我们想很快的安装dpkg，就选择了port。</span></p>  <p style="text-indent:24.0pt">&nbsp;</p>  <p style="margin-top:0cm;margin-right:0cm;margin-bottom:15.0pt;margin-left: 0cm;line-height:21.0pt;background:white;vertical-align:baseline"><span style="font-size:12.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">MacPorts</span><span style="font-size:12.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">的安装</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:21.0pt;background:white; vertical-align:baseline"><span style="font-size:12.0pt;font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">&nbsp;&nbsp;&nbsp; </span><span style="font-size:12.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">对于新手还是访问官方网站http://www.macports.org/install.php，这里提供有dmg，下载</span><a href="http://distfiles.macports.org/MacPorts/MacPorts-1.9.2-10.6-SnowLeopard.dmg"><span style="font-size:12.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;border:none windowtext 1.0pt;padding:0cm">MacPorts-1.9.2-10.6-SnowLeopard.dmg</span></a><span style="font-size:12.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">，下一步下一步安装即可。当然MacPorts要根据mac的版本进行下载。这里下载的是SnowLeopard版本的。</span></p>  <p style="text-indent:24.0pt">&nbsp;</p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">好了，大部分需要的环境都已经搞定了。那就继续吧。</span></p>  <p style="text-indent:24.0pt">&nbsp;</p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">Theos</span><span style="font-family: &quot;微软雅黑&quot;,&quot;sans-serif&quot;">的配置</span></p>  <p style="text-indent:24.0pt"><strong><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Hiragino Sans GB W3&quot;;">1</span></strong><strong><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Hiragino Sans GB W3&quot;;">．设置环境变量</span></strong></p>  <p align="left"><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">建议把theos安装在/opt/theos， 打开terminal然后输入</span></p>  <div style="border:solid #CCCCCC 1.0pt;padding:5.0pt 8.0pt 5.0pt 8.0pt;background:#F8F8F8"><pre style="line-height: 14.25pt; border: none; padding: 0cm; background-position: initial initial; background-repeat: initial initial;"><code><span style="font-family: 'Andale Mono'; border: 1pt none windowtext; padding: 0cm;">export THEOS=/opt/theos</span></code></pre></div>  <p align="left" style="text-indent: 24pt;"><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">通过在命令行执行 echo $THEOS可以看到这个变量是否正确设置。每次你打开terminal都需要重新设置一下。</span></p>  <p align="left" style="text-indent: 24pt;">&nbsp;</p>  <p align="left" style="line-height: 18pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"><strong><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;">2</span></strong><strong><span style="font-size: 16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;">．下载theos</span></strong></p>  <p align="left" style="text-indent: 24pt;"><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">在ternimal中输入：</span></p>  <div style="border:solid #CCCCCC 1.0pt;padding:5.0pt 8.0pt 5.0pt 8.0pt;background:#F8F8F8"><pre style="line-height: 14.25pt; border: none; padding: 0cm; background-position: initial initial; background-repeat: initial initial;"><code><span style="font-family: 'Andale Mono'; border: 1pt none windowtext; padding: 0cm;">svn co http://svn.howett.net/svn/theos/trunk $THEOS</span></code></pre></div>  <p align="left" style="text-indent: 24pt;">&nbsp;</p>  <p align="left"><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">会把theos下载到Step2所设置的目录中，会提示你输入admin的密码。</span></p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">这个一下子就能下载完成了。</span></p>  <p style="text-indent:24.0pt">&nbsp;</p>  <h4><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;">3</span><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;">．下载ldid</span></h4>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">ldid</span><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">的作用是模拟给iPhone签名的流程，使得你能够在真实的设备上安装越狱的apps/hacks。</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">你可以在很多地方都找得到这个tool，不过DHowett在他的dropbox中给大家存了一份。</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">通过下面的命令下载：</span></p>  <div style="border:solid #CCCCCC 1.0pt;padding:5.0pt 8.0pt 5.0pt 8.0pt;background:#F8F8F8">  <p align="left" style="line-height: 14.25pt; border: none; padding: 0cm; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: 10pt; font-family: 'Andale Mono'; border: 1pt none windowtext; padding: 0cm;">curl -s http://dl.dropbox.com/u/3157793/ldid &gt; ~/Desktop/ldidchmod +x ~/Desktop/ldid mv ~/Desktop/ldid $THEOS/bin/ldid</span></p>  </div>  <h4><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;">4</span><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;">． 安装dkpg</span></h4>  <p align="left"><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">Dpkg</span><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">能够把你的app打包成Debian Package,可以分发的Cydia的存储目录中。</span></p>  <div style="border:solid #CCCCCC 1.0pt;padding:5.0pt 8.0pt 5.0pt 8.0pt;background:#F8F8F8"><pre style="line-height: 14.25pt; border: none; padding: 0cm; background-position: initial initial; background-repeat: initial initial;"><code><span style="font-family: 'Andale Mono'; border: 1pt none windowtext; padding: 0cm;">sudo port install dpkg.</span></code></pre></div>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">呵呵，这样Theos的配置就算是ok了，来试一下是不是配置正确呢。</span></p>  <h4><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;; color:#333333">创建新的项目</span></h4>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">theos</span><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">使用一个叫做nic(new instance tool)的工具来创建新的工程。执行下面的命令：</span></p>  <div style="border:solid #CCCCCC 1.0pt;padding:5.0pt 8.0pt 5.0pt 8.0pt;background:#F8F8F8"><pre style="line-height: 14.25pt; border: none; padding: 0cm; background-position: initial initial; background-repeat: initial initial;"><code><span style="font-family: 'Andale Mono'; border: 1pt none windowtext; padding: 0cm;">$THEOS/bin/nic.pl </span></code></pre></div>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">就可以开始创建。下面是一个创建jailbroken 应用程序的例子：</span></p>  <div style="border:solid #CCCCCC 1.0pt;padding:5.0pt 8.0pt 5.0pt 8.0pt;background:#F8F8F8"><pre style="line-height: 14.25pt; border: none; padding: 0cm; background-position: initial initial; background-repeat: initial initial;"><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->author$&nbsp;$THEOS/bin/nic.pl&nbsp;<br />NIC&nbsp;1.0&nbsp;-&nbsp;New&nbsp;Instance&nbsp;Creator&nbsp;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&nbsp;&nbsp;&nbsp;[1.]&nbsp;iphone/application&nbsp;&nbsp;&nbsp;<br />[2.]&nbsp;iphone/library&nbsp;&nbsp;<br />[3.]&nbsp;iphone/preference_bundle&nbsp;&nbsp;<br />[4.]&nbsp;iphone/tool&nbsp;&nbsp;&nbsp;<br />[5.]&nbsp;iphone/tweak&nbsp;Choose&nbsp;a&nbsp;Template&nbsp;(required):&nbsp;1&nbsp;<br />Project&nbsp;Name&nbsp;(required):&nbsp;firstdemo&nbsp;Package&nbsp;Name&nbsp;<br />[com.yourcompany.firstdemo]:&nbsp;&nbsp;<br />Author/Maintainer&nbsp;Name&nbsp;[Author&nbsp;Name]:&nbsp;&nbsp;<br />Instantiating&nbsp;iphone/application&nbsp;<span style="color: #0000FF; ">in</span>&nbsp;firstdemo/&#8230;&nbsp;Done.</div></pre></div>  <p align="left"><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">简单的命令，就创建了一个基本的越狱程序firtdemo,它除了常规的文件外，还包含了Makefile，以及control文件（当在Cydia中时，显示的关于程序的信息）。</span></p>  <p style="text-indent:24.0pt"><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">这样就在当前文件夹下面建立了一个</span><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">firtdemo</span><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">的文件夹，里面有些代码的框架了。</span></p>  <p style="text-indent:24.0pt">&nbsp;</p>  <p><strong><span style="font-size: 16pt; font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">那就试试身手吧</span></strong></p>  <p><strong>&nbsp;</strong></p>  <p align="left" style="margin-left: 24pt;"><span style="font-family: 微软雅黑, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">在这个demo中，我们将要hook Springboard的init方法，然后在iphone启动时显示一个UIAlertView。这个demo不是最酷的，但是这里所使用的方法和模式，可以用来给任何class的任何method打补丁。如图：<img border="0" width="312" height="468" src="file:///C:/Users/tongbu/AppData/Local/Temp/msohtmlclip1/01/clip_image001.png" alt="未命名:Users:tongbu:tblab:越狱开发:IMG_0947.PNG" v:shapes="图片_x0020_1" /><img src="http://www.cppblog.com/images/cppblog_com/automateprogram/IMG_0947.PNG" width="320" height="480" alt="" /></span></p>  <h4><strong>&nbsp;</strong></h4>  <h4><strong><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;border:none windowtext 1.0pt;padding:0cm;font-weight:normal">1</span></strong><strong><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;border:none windowtext 1.0pt;padding:0cm;font-weight:normal">． 准备工作</span></strong></h4>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">你首先还需要下载Saurik的libsubstrate.dylib，然后copy到/opt/theos/lib</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><a href="http://www.mediafire.com/?2upm53uzzj0488u"><span style="font-size:12.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;color:#DD0000; border:none windowtext 1.0pt;padding:0cm">下载libsubsrate.dylib</span></a></p>  <p><span style="font-family: 微软雅黑, sans-serif;"><br /> <br /> </span></p>  <h4><strong><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;border:none windowtext 1.0pt;padding:0cm;font-weight:normal">2</span></strong><strong><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;border:none windowtext 1.0pt;padding:0cm;font-weight:normal">．iOS 头文件</span></strong></h4>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">很可能theos本身就自带了你所需要的头文件，但是，如果你编译程序的时候提示你头文件相关的问题，那你就需要准备相关的头文件了。要么从设备上dump头文件，要么google，建议你先google一下，看其他人有没已经提供了这些头文件。</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">一旦你有这些头文件，记得把它们放在/opt/theos/include。</span></p>  <p>&nbsp;</p>  <h4><strong><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;border:none windowtext 1.0pt;padding:0cm;font-weight:normal">3</span></strong><strong><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;border:none windowtext 1.0pt;padding:0cm;font-weight:normal">． 创建项目</span></strong></h4>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">执行 $THEOS/bin/nic.pl</span></p>  <div style="border:solid #CCCCCC 1.0pt;padding:5.0pt 8.0pt 5.0pt 8.0pt;background:#F8F8F8"><pre style="line-height: 14.25pt; border: none; padding: 0cm;"><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->author$&nbsp;$THEOS/bin/nic.pl&nbsp;<br />NIC&nbsp;1.0&nbsp;-&nbsp;New&nbsp;Instance&nbsp;Creator&nbsp;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&nbsp;<br />[1.]&nbsp;iphone/application&nbsp;&nbsp;&nbsp;<br />[2.]&nbsp;iphone/library&nbsp;&nbsp;&nbsp;<br />[3.]&nbsp;iphone/preference_bundle&nbsp;&nbsp;&nbsp;<br />[4.]&nbsp;iphone/tool&nbsp;&nbsp;&nbsp;<br />[5.]&nbsp;iphone/tweak&nbsp;Choose&nbsp;a&nbsp;Template&nbsp;(required):</div></pre></div>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">这里，需要选择5，demo例子如下：</span></p>  <div style="border:solid #CCCCCC 1.0pt;padding:5.0pt 8.0pt 5.0pt 8.0pt;background:#F8F8F8"><pre style="line-height: 14.25pt; border: none; padding: 0cm;"><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->author$&nbsp;$THEOS/bin/nic.pl&nbsp;<br />NIC&nbsp;1.0&nbsp;-&nbsp;New&nbsp;Instance&nbsp;Creator&nbsp;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&nbsp;<br />[1.]&nbsp;iphone/application&nbsp;&nbsp;&nbsp;<br />[2.]&nbsp;iphone/library&nbsp;&nbsp;&nbsp;<br />[3.]&nbsp;iphone/preference_bundle&nbsp;&nbsp;&nbsp;<br />[4.]&nbsp;iphone/tool&nbsp;&nbsp;&nbsp;<br />[5.]&nbsp;iphone/tweak&nbsp;Choose&nbsp;a&nbsp;Template&nbsp;(required):&nbsp;1&nbsp;<br />Project&nbsp;Name&nbsp;(required):&nbsp;firstdemo&nbsp;Package&nbsp;Name<br />[com.yourcompany.firstdemo]:&nbsp;&nbsp;<br />Author/Maintainer&nbsp;Name&nbsp;[Author&nbsp;Name]:&nbsp;&nbsp;<br />Instantiating&nbsp;iphone/application&nbsp;<span style="color: #0000FF; ">in</span>&nbsp;firstdemo<br />/&#8230;&nbsp;Done.</div></pre></div>  <p>&nbsp;</p>  <h4><strong><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;border:none windowtext 1.0pt;padding:0cm;font-weight:normal">4 The Tweak File</span></strong></h4>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">一旦你创建了项目，你会发现Theos生成了一个叫做Tweak.xm的文件，这是个特殊的文件，hook的相关代码就将写在这个文件。</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">默认的所有代码都是被注释起来的。</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><strong><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; border: 1pt none windowtext; padding: 0cm;">%hook </span></strong><strong><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; border: 1pt none windowtext; padding: 0cm;">和 %end</span></strong></p>  <div style="border:solid #CCCCCC 1.0pt;padding:5.0pt 8.0pt 5.0pt 8.0pt;background:#F8F8F8"><pre style="line-height: 14.25pt; border: none; padding: 0cm; background-position: initial initial; background-repeat: initial initial;"><code><span style="font-family: 'Andale Mono'; border: 1pt none windowtext; padding: 0cm;">%hook Springboard // overwrite methods here %end </span></code></pre></div>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">%hook</span><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">后面跟的是你要hook的类名称，以一个%end结尾。上面的代码说明我们会hook Springboard类里面的method。</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><strong><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; border: 1pt none windowtext; padding: 0cm;">%orig</span></strong></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">当在一个method内部的时候，%orig会调用原来的方法（original method)。你甚至可以给原来的method传递参数，例如：%orig(arg1,arg2)。如果你不调用%orig，原来的方法就绝对不会被调用。所以，如果你hook了SpringBoard的init方法，但是没有调用%orig。那么你的iphone就将不可用，除非你通过ssh删除你的app。</span></p>  <p><a name="_GoBack"></a>&nbsp;</p>  <h4><span style="font-size:16.0pt;font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;">5 Hooking into Springboard</span></h4>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">打开Tweak.xm，然后加上代码：</span></p>  <div style="border:solid #CCCCCC 1.0pt;padding:5.0pt 8.0pt 5.0pt 8.0pt;background:#F8F8F8"><pre style="line-height: 14.25pt; border: none; padding: 0cm; background-position: initial initial; background-repeat: initial initial;"><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#import&lt;SpringBoard/SpringBoard.h&gt;&nbsp;&nbsp;<br />%hook&nbsp;SpringBoard&nbsp;<br />&nbsp;-(<span style="color: #0000FF; ">void</span>)applicationDidFinishLaunching:(id)application&nbsp;{&nbsp;<br />%orig;&nbsp;<br />&nbsp;UIAlertView&nbsp;*alert&nbsp;=&nbsp;[[UIAlertViewalloc]&nbsp;<br />initWithTitle:@"Welcome"&nbsp;&nbsp;message:@"Welcome&nbsp;to&nbsp;your&nbsp;iPhone&nbsp;Brandon!"&nbsp;&nbsp;<br /><span style="color: #0000FF; ">delegate</span>:nilcancelButtonTitle:@"Thanks"&nbsp;&nbsp;<br />otherButtonTitles:nil]&nbsp;<br />[alert&nbsp;show];&nbsp;<br />[alert&nbsp;release];<br />&nbsp;}&nbsp;<br />&nbsp;%end&nbsp;</div></pre></div>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">首先，import头文件 Springboard.h，这可以让我们可以访问springboard。然后，我们告诉预处理器hook Springboard class。</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">这里覆盖的method是applicationDidFinishLaunching：方法，当Springboard启动时，就会被执行。注意我们调用了%orig。</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">最后，显示一个UIAlertView。</span></p>  <p><span style="font-family: 微软雅黑, sans-serif;"><br /> <br /> </span></p>  <h4><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;; color:#333333">6 </span><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;color:#333333">添加Framework</span></h4>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">如果你直接编译，，会得到如下的提示信息：</span></p>  <div style="border:solid #CCCCCC 1.0pt;padding:5.0pt 8.0pt 5.0pt 8.0pt;background:#F8F8F8"><pre style="line-height: 14.25pt; border: none; padding: 0cm; background-position: initial initial; background-repeat: initial initial;"><code><span style="font-family: 'Andale Mono'; border: 1pt none windowtext; padding: 0cm;">Tweak.xm: In function &#8216;objc_object* $_ungrouped$SpringBoard$init(SpringBoard*, objc_selector*)&#8217;: Tweak.xm:6: error: declaration of &#8216;objc_object* self&#8217; shadows a parameter </span></code></pre></div>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">那是因为我们依靠UIKit framework来显示alert,所以需要在Makefile中加上如下一行：</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">WelcomeWagon_FRAMEWORKS = UIKit</span></p>  <p><span style="font-family: 微软雅黑, sans-serif;"><br /> <br /> </span></p>  <h4><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;;Times New Roman&quot;; color:#333333">7 Building, Packaging, Installing.</span></h4>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif;">在前面的系列中介绍了如何编译，打包和安装，依次执行下面的命令即可。</span></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><strong><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; border: 1pt none windowtext; padding: 0cm;">make, make package,</span></strong></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><strong><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; border: 1pt none windowtext; padding: 0cm;">make package</span></strong><strong><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; border: 1pt none windowtext; padding: 0cm;">以后就生成了一个deb。</span></strong></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><strong><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; border: 1pt none windowtext; padding: 0cm;">自己拷过去安装吧，当然你的iPhone必须越狱的环境和一些必要的插件。把包拷贝到手机里用dpkg命令安装和卸载。</span></strong></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><strong><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; border: 1pt none windowtext; padding: 0cm;">Dpkg&#8211;i</span></strong></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><strong><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; border: 1pt none windowtext; padding: 0cm;">dpkg&#8211;r</span></strong></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><strong>&nbsp;</strong></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><strong><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; border: 1pt none windowtext; padding: 0cm;">这些成功了吧。：）。</span></strong></p>  <p style="margin:0cm;margin-bottom:.0001pt;line-height:18.0pt;background:white"><strong>&nbsp;</strong></p>  <p><span style="font-family:&quot;微软雅黑&quot;,&quot;sans-serif&quot;">参考文档：http://wufawei.com/2013/08/iOS-jailbroken-programming-1/</span></p><img src ="http://www.cppblog.com/AutomateProgram/aggbug/204205.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2013-11-11 11:16 <a href="http://www.cppblog.com/AutomateProgram/archive/2013/11/11/204205.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用ReadProcessMemory进程间通讯</title><link>http://www.cppblog.com/AutomateProgram/archive/2013/07/11/201687.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Thu, 11 Jul 2013 06:23:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2013/07/11/201687.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/201687.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2013/07/11/201687.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/201687.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/201687.html</trackback:ping><description><![CDATA[<p>原文地址：<a href="http://timke.blog.163.com/blog/static/10158730620103124547256/">http://timke.blog.163.com/blog/static/10158730620103124547256/</a><br /><br /><strong>最近在写个程序的时候需要在进程间通讯，具体需求是这样。<br /></strong></p>
<p>1.主要有两个进程：一个进程作为被请求进程，我们称为 SERVER 进程；另一个进程是请求进程，称为 CLIENG 进程。</p>
<p>2.SERVER 进程提供一些服务，其完成计算功能；而 CLIENT 进程需要在它执行完计算之后将结果取会。<br /><br />由于计算结果可能是一个结构，也可能是一个复杂的数据，所以通过消息来在进程传递信息是有限的。<br />另一方面一般是单方向的通讯，实际上这里的需求有一个双向性，看下图：<br /><br /><img alt="进程间通讯-WriteProcessMemory和ReadProcessMemory - timke - Yes,It is!" src="http://www.cppblog.com/images/cppblog_com/windcsn/ProcessComm.JPG" /><br /><br /></p>
<p>这里两个进程都可以有自己的窗口，因此实际上我们可以通过消息来通知对方。但仔细一想，请求服务通过windows消息是没有问题的，<br />通知结果通过消息是不妥当的，实际上我们需要在请求服务完以后立即得到执行结果，而使用windows消息可能有时间上的问题，而且同步非常麻烦。</p>
<p>想要的结果是在 CLIENT 请求服务以后立即得到返回结果，但我们可以改变一下思路就容易多了：结果不是有 SERVER 返回，而由 CLIENG 自己去获取。<br />这样，我们可以在请求消息的时候使用 SendMessage 来发送这个请求。这是必须的， SendMessage 发送消息是同步的方式，必须等到消息处理完毕之后才返回，<br />而这正是我们想要的结果。那么 CLIENT 怎么样才能获得 SERVER 进程的结果来。<br /></p>
<p><br />我们知道， WINDOWS 下每个进程都有自己的地址空间，一般情况下一个进程访问你一个进程的地址是不正确的，最简单的是提示该地址无效，<br />程序崩溃。当然还是有很多中方式来读取对方进程的地址空间上的数据。<br /><br /></p>
<p>1．可以做一个 DLL ，利用注入 DLL 的方式，来将该 DLL 注入到远程进程的地址空间上，然后通过 DLL 的 API 来读取。这个方式有点麻烦，还必须写一个 DLL ，还要注入 DLL 。</p>
<p>2．使用 WriteProcessMemory 和 ReadProcessMemory 来读写远程进程的内存。这种方式相对比较简单，<br />其有一个参数远程进程的 HANDLE 指示你需要读写哪个进程的内存。当然，使用这两个函数是需要远程进程的地址空间的，这个地址是通过 VirtualAllocEx 来分配的，<br />其通过 VirtualFreeEx 来释放。这两个 API 也有一个进程句柄参数。<br /></p>
<p>有人问，为什么不使用 WM_COPYDATA 来传递大块数据？好，该消息是可以传递大块数据，但我们的应用中需要消息的双向，所以这里使用 WM_COPYDATA 是不合适的。</p>
<p>&nbsp;</p>
<p><strong>下面我们看一下具体步骤：</strong></p>
<p>1．&nbsp; 找到对方进程的窗口。</p>
<p>2．&nbsp; 找到他的进程 ID</p>
<p>3．&nbsp; 使用 PROCESS_VM_OPERATION| PROCESS_VM_WRITE|PROCESS_VM_READ 标志来打开该进程，得到该继承的 HANDLE 。</p>
<p>4．&nbsp; 使用 VirtualAllocEx 来在该进程上分配适当大小的内存，得到一个地址，这个地址是远程进程的，通过不同的方式来修改该地址上的值是无效的。</p>
<p>5．&nbsp; 如果需要传递一些参数到远程进程，我们可以在该内存上写一些内容，通过 WriteProcessMemory 来完成</p>
<p>6．&nbsp; 使用 SendMessage 来发送请求服务消息，同时将上面分配的内存地址作为参数传递给远程进程。</p>
<p>7．&nbsp; 远程进程得到指定消息后处理该消息，取得参数，计算结果，将结果写到指定的地址。由于这个地址是远程进程自己的地址空间，其操作这块内存的方法没有什么特别之处。</p>
<p>8．&nbsp; SendMessage 消息返回， CLIENT 知道后，从上面的内存地址中读取返回结果；这里必须使用 ReadProcessMemory 来读取。好了，整个过程结束。</p>
<p>9．&nbsp; 调用 VritualFreeEx 将上面的内存释放。</p>
<p>这里需要强调两点：</p>
<p>1．&nbsp; 打开进程的时候必须设置对虚拟内存可操作、可写、可读，如果只是可写，那么 ReadProcessMemory 将读取不正确。</p>
<p>2．&nbsp; 必须释放该内存。</p>
<p><br /></p>
<p>下面是部分程序：</p>
<p>CLIENT 程序：</p>
<p>&nbsp;</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 56.1%; padding-right: 5px; height: 934px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">HANDLE&nbsp;hProcess&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;NULL;<br />&nbsp;&nbsp;&nbsp;&nbsp;DWORD&nbsp;dwProcessId&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;HWND&nbsp;hServerWnd&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;::FindWindow(NULL,</span><span style="color: #000000">"</span><span style="color: #000000">CompareServer</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(hServerWnd&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;NULL)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">Need&nbsp;create&nbsp;the&nbsp;process</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;::GetWindowThreadProcessId(hServerWnd,</span><span style="color: #000000">&amp;</span><span style="color: #000000">dwProcessId);<br />&nbsp;&nbsp;&nbsp;&nbsp;hProcess&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;OpenProcess(PROCESS_VM_OPERATION</span><span style="color: #000000">|</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROCESS_VM_WRITE</span><span style="color: #000000">|</span><span style="color: #000000">PROCESS_VM_READ,FALSE,dwProcessId);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(hProcess&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;NULL)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;MyInfo&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pMyInfo&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;NULL;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;pMyInfo&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(MyInfo&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">)VirtualAllocEx(hProcess,NULL,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(MyInfo),MEM_COMMIT,PAGE_READWRITE);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(pMyInfo&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;NULL)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;;<br />&nbsp;&nbsp;&nbsp;&nbsp;MyInfo&nbsp;myInfo;<br />&nbsp;&nbsp;&nbsp;&nbsp;myInfo.blue&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">20.01</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;myInfo.red&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">3333</span><span style="color: #000000">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;WriteProcessMemory(hProcess,pMyInfo,</span><span style="color: #000000">&amp;</span><span style="color: #000000">myInfo,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(MyInfo),NULL);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;MsgStruct&nbsp;msgStruct;<br />&nbsp;&nbsp;&nbsp;&nbsp;msgStruct.dwAddrMem&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(DWORD)pMyInfo;<br />&nbsp;&nbsp;&nbsp;&nbsp;msgStruct.dwMenLen&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(MyInfo);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;COPYDATASTRUCT&nbsp;cps;<br />&nbsp;&nbsp;&nbsp;&nbsp;cps.cbData&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(MsgStruct);<br />&nbsp;&nbsp;&nbsp;&nbsp;cps.lpData&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(LPBYTE)&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">msgStruct;<br />&nbsp;&nbsp;&nbsp;&nbsp;cps.dwData&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;SIZE_T&nbsp;dwRead</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;MyInfo&nbsp;myInfo2;<br />&nbsp;&nbsp;&nbsp;&nbsp;::SendMessage(hServerWnd,WM_COPYDATA,(WPARAM)m_hWnd,(LPARAM)</span><span style="color: #000000">&amp;</span><span style="color: #000000">cps);<br />&nbsp;&nbsp;&nbsp;&nbsp;BOOL&nbsp;bRet&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;::ReadProcessMemory(hProcess,pMyInfo,</span><span style="color: #000000">&amp;</span><span style="color: #000000">myInfo2,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(MyInfo),</span><span style="color: #000000">&amp;</span><span style="color: #000000">dwRead);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;dwRead&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;GetLastError();<br />&nbsp;&nbsp;&nbsp;&nbsp;m_log.Format(</span><span style="color: #000000">"</span><span style="color: #000000">red&nbsp;=%.2f,blue=%.2f</span><span style="color: #000000">"</span><span style="color: #000000">,myInfo2.blue,myInfo2.red);<br />&nbsp;&nbsp;&nbsp;&nbsp;TRACE(m_log);<br />&nbsp;&nbsp;&nbsp;&nbsp;VirtualFreeEx(hProcess,pMyInfo,</span><span style="color: #000000">0</span><span style="color: #000000">,MEM_RELEASE);<br />&nbsp;&nbsp;&nbsp;&nbsp;UpdateData(FALSE);</span></div>
<p><br />SERVER 程序：</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 56.17%; padding-right: 5px; height: 661px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">LRESULT&nbsp;&nbsp;&nbsp;&nbsp;CMyWindow::OnCompareImage(HWND&nbsp;hWnd,WPARAM&nbsp;wParam,LPARAM&nbsp;lParam)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(wParam&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(MyInfo))&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;MyInfo&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pMyInfo&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(MyInfo&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">)lParam;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;sprintf(m_strLog,</span><span style="color: #000000">"</span><span style="color: #000000">client:red=%.2f,blue=%.2f</span><span style="color: #000000">"</span><span style="color: #000000">,pMyInfo</span><span style="color: #000000">-&gt;</span><span style="color: #000000">red,pMyInfo</span><span style="color: #000000">-&gt;</span><span style="color: #000000">blue);<br />&nbsp;&nbsp;&nbsp;&nbsp;::TextOut(GetDC(hWnd),</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">50</span><span style="color: #000000">,m_strLog,strlen(m_strLog));<br />&nbsp;&nbsp;&nbsp;&nbsp;pMyInfo</span><span style="color: #000000">-&gt;</span><span style="color: #000000">blue&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1.0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;pMyInfo</span><span style="color: #000000">-&gt;</span><span style="color: #000000">red&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2.0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}<br /><br />LRESULT&nbsp;&nbsp;&nbsp;&nbsp;CMyWindow::OnCopyData(HWND&nbsp;hWnd,WPARAM&nbsp;wParam,LPARAM&nbsp;lParam)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;PCOPYDATASTRUCT&nbsp;&nbsp;&nbsp;&nbsp;lpcds;<br />&nbsp;&nbsp;&nbsp;&nbsp;lpcds&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(PCOPYDATASTRUCT)lParam;<br />&nbsp;&nbsp;&nbsp;&nbsp;MsgStruct&nbsp;msgStruct;<br />&nbsp;&nbsp;&nbsp;&nbsp;memcpy(</span><span style="color: #000000">&amp;</span><span style="color: #000000">msgStruct,lpcds</span><span style="color: #000000">-&gt;</span><span style="color: #000000">lpData,lpcds</span><span style="color: #000000">-&gt;</span><span style="color: #000000">cbData);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(msgStruct.dwMenLen</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(MyInfo))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;MyInfo&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pMyInfo&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(MyInfo&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">)msgStruct.dwAddrMem;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;temp[</span><span style="color: #000000">100</span><span style="color: #000000">];<br />&nbsp;&nbsp;&nbsp;&nbsp;sprintf(temp,</span><span style="color: #000000">"</span><span style="color: #000000">client:red=%.2f,blue=%.2f</span><span style="color: #000000">"</span><span style="color: #000000">,pMyInfo</span><span style="color: #000000">-&gt;</span><span style="color: #000000">red,pMyInfo</span><span style="color: #000000">-&gt;</span><span style="color: #000000">blue);<br />&nbsp;&nbsp;&nbsp;&nbsp;::TextOut(GetDC(hWnd),</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">50</span><span style="color: #000000">,temp,strlen(temp));<br />&nbsp;&nbsp;&nbsp;&nbsp;pMyInfo</span><span style="color: #000000">-&gt;</span><span style="color: #000000">blue&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1.0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;pMyInfo</span><span style="color: #000000">-&gt;</span><span style="color: #000000">red&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2.0</span><span style="color: #000000">;<br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div>
<p><br /><br /><br /></p><img src ="http://www.cppblog.com/AutomateProgram/aggbug/201687.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2013-07-11 14:23 <a href="http://www.cppblog.com/AutomateProgram/archive/2013/07/11/201687.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模拟iTunes的登陆，并获取用户的名称</title><link>http://www.cppblog.com/AutomateProgram/archive/2013/07/05/201527.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Fri, 05 Jul 2013 03:47:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2013/07/05/201527.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/201527.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2013/07/05/201527.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/201527.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/201527.html</trackback:ping><description><![CDATA[关于iTunes的研究到处都可以见到，<br />这里根据看雪的文章 <a href="http://bbs.pediy.com/showthread.php?t=168303">http://bbs.pediy.com/showthread.php?t=168303</a>&nbsp;，<br />简单的用c#代码模拟iTunes账号的登陆（只考虑成功的情况），并获取账号里的信息，关于解析plist的库现已有多个库可用，<br />采用的是iphone-plist-net，地址在：<a href="http://code.google.com/p/iphone-plist-net/">http://code.google.com/p/iphone-plist-net/</a>&nbsp;上。<br /><br />模拟登陆最重要的是post 什么数据到 哪个url上，<br />通过跟踪，这里是主要的数据<br /><br />url地址：p3-buy.itunes.apple.com<br />post的数据为：<br />(Request-Line):GET <a>/WebObjects/MZFinance.woa/wa/authenticate?appleId=<span style="color: red">xxx</span>&amp;password=<span style="color: red">xxx</span>&amp;attempt=1&amp;machineName=&amp;why=purchase&amp;guid=4AEF365B.CF847F94.08E11EF5.FDD88C5B.09DA8172.65FAFEFB.6A193139&amp;Pod=3&amp;PRH=3</a> HTTP/1.1<br />Cache-Control:no-cache<br />Referer:http://itunes.apple.com/cn/<br />Accept-Language:zh-cn, zh;q=0.75, en-us;q=0.50, en;q=0.25<br />X-Apple-Tz:28800<br />X-Apple-Store-Front:143465-19,12<br />Host:p3-buy.itunes.apple.com<br />Connection:Close<br /><br />post后返回的是plist格式的字符，里面包含了用户的信息。<br /><br />C#简单的代码如下： 
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;strInfo&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;GetiTunesData(</span><span style="color: #000000">"</span><span style="color: #000000">https://p3-buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/authenticate?appleId=asdfasdf@asdf.co&amp;password=qweqweqwe&amp;attempt=1&amp;machineName=&amp;why=purchase&amp;guid=4AEF365B.CF847F94.08E11EF5.FDD88C5B.09DA8172.65FAFEFB.6A193139&amp;Pod=3&amp;PRH=3</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stream&nbsp;s&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;MemoryStream(Encoding.UTF8.GetBytes(strInfo));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PListRoot&nbsp;root&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;PListRoot.Load(s);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PListDict&nbsp;dic&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(PListDict)root.Root;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PListDict&nbsp;accountInfo&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(PListDict)dic[</span><span style="color: #000000">"</span><span style="color: #000000">accountInfo</span><span style="color: #000000">"</span><span style="color: #000000">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PListDict&nbsp;address&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(PListDict)accountInfo[</span><span style="color: #000000">"</span><span style="color: #000000">address</span><span style="color: #000000">"</span><span style="color: #000000">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;firstName&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;((PListString)address[</span><span style="color: #000000">"</span><span style="color: #000000">firstName</span><span style="color: #000000">"</span><span style="color: #000000">]).Value;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;lastName&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;((PListString)address[</span><span style="color: #000000">"</span><span style="color: #000000">lastName</span><span style="color: #000000">"</span><span style="color: #000000">]).Value;</span></div><br />这里可以知道，plist的很多字段，这里字段以后用来购买软件。<br /><br /><br /><img src ="http://www.cppblog.com/AutomateProgram/aggbug/201527.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2013-07-05 11:47 <a href="http://www.cppblog.com/AutomateProgram/archive/2013/07/05/201527.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何注入代码到exe中使用OD进行操作</title><link>http://www.cppblog.com/AutomateProgram/archive/2013/07/02/201461.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Tue, 02 Jul 2013 07:38:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2013/07/02/201461.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/201461.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2013/07/02/201461.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/201461.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/201461.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/AutomateProgram/archive/2013/07/02/201461.html'>阅读全文</a><img src ="http://www.cppblog.com/AutomateProgram/aggbug/201461.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2013-07-02 15:38 <a href="http://www.cppblog.com/AutomateProgram/archive/2013/07/02/201461.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>打造智能的vim</title><link>http://www.cppblog.com/AutomateProgram/archive/2013/06/13/200981.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Thu, 13 Jun 2013 03:42:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2013/06/13/200981.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/200981.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2013/06/13/200981.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/200981.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/200981.html</trackback:ping><description><![CDATA[<span style="font-size: 24pt"><br /><strong>Vundle介绍</strong><br /><br /></span><span style="font-size: 14pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 14pt">Vim插件也越来越多，如何才能有效地管理这些插件，快速搭建/恢复自己熟悉的工作环境，是每一个使用vim应该思考的问题</span>
<p><span style="font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;vundle的出现使得管理这些插件变得非常方便快捷</span><br /><br /><br /><span style="font-size: 24pt"><strong>Vundle安装</strong><br /><br /><br /></span></p>
<p><span style="font-size: 14pt">安装：apt-get install vim exuberant-ctags git</span></p>
<p><span style="font-size: 14pt">修改.vimrc</span></p>
<p><span style="font-size: 14pt">打开vim在命令模式下键入:BundleInstall开始下载安装<br /><br /></span></p>
<p><br /><span style="font-size: 24pt;"><strong>Vundle简单命令</strong></span><br /><br /><br /></p>
<p><span style="font-size: 14pt">打开vim,执行如下命令：</span></p>
<p><span style="font-size: 14pt">安装更新插件 :BundleInstall</span><br /><span style="font-size: 14pt">卸载不在列表中的插件:BundleClean</span><br /><span style="font-size: 14pt">:BundleSearch<br /><br /><br /></span></p>
<p><span style="font-size: 24pt;"><strong>较好的vimrc</strong></span><br /><br /><br /></p>
<p><span style="font-size: 14pt">fisadev/fisa-vim-config</span><br /><a href="https://github.com/fisadev/fisa-vim-config"><span style="font-size: 14pt">https://github.com/fisadev/fisa-vim-config</span></a><br /><span style="font-size: 14pt">依赖项安装：</span><br /><span style="font-size: 14pt">sudo apt-get install vim exuberant-ctags git</span><br /><span style="font-size: 14pt">sudo pip install dbgp vim-debug pep8 flake8 pyflakes</span></p>
<p><span style="font-size: 14pt">pip安装</span><br /><span style="font-size: 14pt">wget </span><a href="http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg"><span style="font-size: 14pt">http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg</span></a><br /><span style="font-size: 14pt">sh setuptools-0.6c11-py2.7.egg</span></p>
<p><span style="font-size: 14pt">wget </span><a href="http://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz"><span style="font-size: 14pt">http://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz</span></a><br /><span style="font-size: 14pt">tar zxf pip-1.2.1.tar.gz</span><br /><span style="font-size: 14pt">cd pip-1.2.1</span><br /><span style="font-size: 14pt">python setup.py install</span></p>
<p><span style="font-size: 14pt">:BundleInstall 安装</span><br /></p>
<p><br />&nbsp;</p><img src ="http://www.cppblog.com/AutomateProgram/aggbug/200981.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2013-06-13 11:42 <a href="http://www.cppblog.com/AutomateProgram/archive/2013/06/13/200981.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenResty的安装和在nginx中使用lua直接访问mysql达到数据接口的统一</title><link>http://www.cppblog.com/AutomateProgram/archive/2013/03/21/198685.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Thu, 21 Mar 2013 08:53:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2013/03/21/198685.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/198685.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2013/03/21/198685.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/198685.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/198685.html</trackback:ping><description><![CDATA[<p>OpenResty 它打包了标准的 Nginx 核心，很多的常用的第三方模块，以及它们的大多数依赖项。</p>
<p>如果需要nginx的第三方库的时候，可以考虑OpenResty，可以少掉很多安装的麻烦，OpenResty基本上安装了常用的nginx第三方库。</p>
<p>OpenResty的安装：</p>
<p>安装nginx 中 rewrite模块等需要的插件：</p>
<p>apt-get install libreadline-dev libpcre3-dev libssl-dev perl build-essential<br />下载最新版的OpenResty<br /><a href="http://openresty.org/">http://openresty.org/</a><br />wget <a href="http://openresty.org/download/ngx_openresty-1.2.7.1.tar.gz">http://openresty.org/download/ngx_openresty-1.2.7.1.tar.gz</a><br />tar -xvf nngx_openresty-1.2.7.1.tar.gz<br />mv nngx_openresty-1.2.7.1 /usr/local/openresty-1.2.7.1<br />cd openresty-1.2.7.1<br />./configure --with-luajit --prefix=/usr/local/openresty<br />make &amp;　make install</p>
<p>这样基本就可以把nginx基本的第三方库安装进去</p>
<p>在/to/nginx/conf 下修改配置文件nginx.config</p>
<p>location /hello { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default_type 'text/plain'; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; content_by_lua 'ngx.say("hello, lua")'; <br />}</p>
<p>/to/nginx/sbin/nginx&nbsp;&nbsp; #启动nginx</p>
<p>或者/to/nginx/sbin/nginx &#8211;s reload #重启nginx<br />访问localhost/hello<br />会出现&#8220;hello,lua&#8221;</p>
<p>让nginx 中的nginx_lua_module支持mysql 和memcache<br />下载<br /><a href="https://github.com/agentzh/lua-resty-memcached">https://github.com/agentzh/lua-resty-memcached</a><br /><a href="https://github.com/agentzh/lua-resty-mysql">https://github.com/agentzh/lua-resty-mysql</a><br /></p>
<p>对于访问接口的统一有很多的处理方式，这里介绍使用nginx lua 访问mysql并用memcache缓存起来。<br /></p>
<p>&nbsp;</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">location&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">getXxxInfo&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default_type&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">text/plain</span><span style="color: #000000">'</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content_by_lua&nbsp;</span><span style="color: #000000">'<br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">--</span><span style="color: #000000">先从memcache提取数据<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;args&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;ngx.req.get_uri_args()<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;args[</span><span style="color: #000000">"</span><span style="color: #000000">appleid</span><span style="color: #000000">"</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;nil&nbsp;then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;end<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;memcached&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;require&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">resty.memcached</span><span style="color: #000000">"</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;memc,&nbsp;err&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;memcached:</span><span style="color: #0000ff">new</span><span style="color: #000000">()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;not&nbsp;memc&nbsp;then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(</span><span style="color: #000000">"</span><span style="color: #000000">failed&nbsp;to&nbsp;instantiate&nbsp;memc:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;err)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memc:set_timeout(</span><span style="color: #000000">1000</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">--</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;sec<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;ok,&nbsp;err&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;memc:connect(</span><span style="color: #000000">"</span><span style="color: #000000">192.168.40.xxx</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">11211</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;not&nbsp;ok&nbsp;then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(</span><span style="color: #000000">"</span><span style="color: #000000">failed&nbsp;to&nbsp;connect:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;err)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;res,&nbsp;flags,&nbsp;err&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;memc:</span><span style="color: #0000ff">get</span><span style="color: #000000">(</span><span style="color: #000000">args[<span style="color: #000000">"</span><span style="color: #000000">appleid</span><span style="color: #000000">"</span><span style="color: #000000">]&nbsp;)</span><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;err&nbsp;then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(</span><span style="color: #000000">"</span><span style="color: #000000">failed&nbsp;to&nbsp;get&nbsp;dog:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;err)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">--</span><span style="color: #000000">数据不在memcache中&nbsp;从数据库提取并放到memcache<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;not&nbsp;res&nbsp;then<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;mysql&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;require&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">resty.mysql</span><span style="color: #000000">"</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;db,&nbsp;err&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;mysql:</span><span style="color: #0000ff">new</span><span style="color: #000000">()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;not&nbsp;db&nbsp;then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(</span><span style="color: #000000">"</span><span style="color: #000000">failed&nbsp;to&nbsp;instantiate&nbsp;mysql:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;err)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;db:set_timeout(</span><span style="color: #000000">1000</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">--</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;sec<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;ok,&nbsp;err,&nbsp;errno,&nbsp;sqlstate&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;db:connect{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">xxx.xxx.xx.xxx</span><span style="color: #000000">"</span><span style="color: #000000">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">3306</span><span style="color: #000000">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;database&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">xxxx</span><span style="color: #000000">"</span><span style="color: #000000">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">root</span><span style="color: #000000">"</span><span style="color: #000000">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">xxxx</span><span style="color: #000000">"</span><span style="color: #000000">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max_packet_size&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1024</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1024</span><span style="color: #000000">&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;not&nbsp;ok&nbsp;then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(</span><span style="color: #000000">"</span><span style="color: #000000">failed&nbsp;to&nbsp;connect:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;err,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;errno,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;sqlstate)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">--</span><span style="color: #000000">ngx.say(</span><span style="color: #000000">"</span><span style="color: #000000">connected&nbsp;to&nbsp;mysql.</span><span style="color: #000000">"</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sql&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">select&nbsp;*&nbsp;from&nbsp;xxx&nbsp;where&nbsp;xxx&nbsp;=&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">..args[</span><span style="color: #000000">"</span><span style="color: #000000">xxx</span><span style="color: #000000">"</span><span style="color: #000000">]<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res,&nbsp;err,&nbsp;errno,&nbsp;sqlstate&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;db:query(sql)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;not&nbsp;res&nbsp;then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(</span><span style="color: #000000">"</span><span style="color: #000000">bad&nbsp;result:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;err,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;errno,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;sqlstate,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">.</span><span style="color: #000000">"</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;cjson&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;require&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">cjson</span><span style="color: #000000">"</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(cjson.encode(res))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;ok,&nbsp;err&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;memc:</span><span style="color: #0000ff">set</span><span style="color: #000000">(args[</span><span style="color: #000000">"</span><span style="color: #000000">xxxx</span><span style="color: #000000">"</span><span style="color: #000000">],&nbsp;cjson.encode(res))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;not&nbsp;ok&nbsp;then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(</span><span style="color: #000000">"</span><span style="color: #000000">failed&nbsp;to&nbsp;set&nbsp;dog:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;err)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local&nbsp;ok,&nbsp;err&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;db:set_keepalive(</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">100</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;not&nbsp;ok&nbsp;then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(</span><span style="color: #000000">"</span><span style="color: #000000">failed&nbsp;to&nbsp;set&nbsp;keepalive:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;err)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.say(res)<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memc:set_keepalive(</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">100</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">;</span><span style="color: #000000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span></div>
<p><br />&nbsp;</p><img src ="http://www.cppblog.com/AutomateProgram/aggbug/198685.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2013-03-21 16:53 <a href="http://www.cppblog.com/AutomateProgram/archive/2013/03/21/198685.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用coreseek python数据源的基类建立sql server 的搜索引擎</title><link>http://www.cppblog.com/AutomateProgram/archive/2013/03/14/198425.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Thu, 14 Mar 2013 09:38:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2013/03/14/198425.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/198425.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2013/03/14/198425.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/198425.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/198425.html</trackback:ping><description><![CDATA[<span style="text-align: left; text-transform: none; background-color: #ffffff; text-indent: 0px; display: inline !important; font: 13px/12px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; float: none; letter-spacing: normal; color: #000000; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"><br />coreseek为了扩展，增加了python数据源功能，从而得以无限扩展Coreseek/Sphinx的数据获取功能。<br /><br />这样做的话，coreseek就非常灵活，基本上可以对所有的数据建立搜索引擎，只要有自己的python数据源基类。<br /><br />这里配一下 <span style="text-align: left; text-transform: none; background-color: #ffffff; text-indent: 0px; display: inline !important; font: 13px/17px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; float: none; letter-spacing: normal; color: #000000; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">Microsoft SQL Server</span> 和 python基类的写法：<br /><br />csft_python.conf<br /><br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000"><br />python<br />{<br />&nbsp;&nbsp;&nbsp;path&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/to</span><span style="color: #000000">/</span><span style="color: #000000">coreseek</span><span style="color: #000000">-</span><span style="color: #000000">3.2</span><span style="color: #000000">.</span><span style="color: #000000">14</span><span style="color: #000000">/</span><span style="color: #000000">testpack</span><span style="color: #000000">/</span><span style="color: #000000">etc</span><span style="color: #000000">/</span><span style="color: #000000">pysource<br />&nbsp;&nbsp;&nbsp;path&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/to</span><span style="color: #000000">/</span><span style="color: #000000">coreseek</span><span style="color: #000000">-</span><span style="color: #000000">3.2</span><span style="color: #000000">.</span><span style="color: #000000">14</span><span style="color: #000000">/</span><span style="color: #000000">testpack</span><span style="color: #000000">/</span><span style="color: #000000">etc</span><span style="color: #000000">/</span><span style="color: #000000">pysource</span><span style="color: #000000">/</span><span style="color: #000000">csft_demo_pymssql&nbsp;&nbsp;&nbsp;&nbsp;#BSD、Linux环境下设置<br />}<br /><br /><br />source&nbsp;python_demo<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;type&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;python<br />&nbsp;&nbsp;&nbsp;&nbsp;name&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;csft_demo_pymssql.MainSource<br />&nbsp;&nbsp;&nbsp;&nbsp;#name&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;MainSource<br />}<br /><br />index&nbsp;python_demo<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;source&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;python_demo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#对应的source名称<br />&nbsp;&nbsp;&nbsp;&nbsp;path&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;var</span><span style="color: #000000">/</span><span style="color: #000000">data</span><span style="color: #000000">/</span><span style="color: #000000">python_demo<br />&nbsp;&nbsp;&nbsp;&nbsp;#docinfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">extern</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;mlock&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;morphology&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;none<br />&nbsp;&nbsp;&nbsp;&nbsp;min_word_len&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;html_strip&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;#charset_dictpath&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">usr</span><span style="color: #000000">/</span><span style="color: #000000">local</span><span style="color: #000000">/</span><span style="color: #000000">mmseg3</span><span style="color: #000000">/</span><span style="color: #000000">etc</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;#BSD、Linux环境下设置，</span><span style="color: #000000">/</span><span style="color: #000000">符号结尾<br />&nbsp;&nbsp;&nbsp;&nbsp;#charset_dictpath&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;etc</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#Windows环境下设置，</span><span style="color: #000000">/</span><span style="color: #000000">符号结尾<br />&nbsp;&nbsp;&nbsp;&nbsp;charset_type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;utf</span><span style="color: #000000">-</span><span style="color: #000000">8</span><span style="color: #000000"><br />}<br /><br />indexer<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;mem_limit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;128M<br />}<br /><br />searchd<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;listen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">9353</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;read_timeout&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">5</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;max_children&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">30</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;max_matches&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1000</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;seamless_rotate&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;preopen_indexes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;unlink_old&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;pid_file&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;var</span><span style="color: #000000">/</span><span style="color: #000000">log</span><span style="color: #000000">/</span><span style="color: #000000">searchd_python.pid<br />&nbsp;&nbsp;&nbsp;&nbsp;log&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;var</span><span style="color: #000000">/</span><span style="color: #000000">log</span><span style="color: #000000">/</span><span style="color: #000000">searchd_python.log<br />&nbsp;&nbsp;&nbsp;&nbsp;query_log&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;var</span><span style="color: #000000">/</span><span style="color: #000000">log</span><span style="color: #000000">/</span><span style="color: #000000">query_python.log<br />}<br /><br /><br /></span></div><br /><br />/to/coreseek-3.2.14/testpack/etc/pysource/csft_demo_pymssql<br /><br />下的__init__.py<br /><br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#&nbsp;</span><span style="color: #000000">-*-</span><span style="color: #000000">&nbsp;coding:&nbsp;UTF</span><span style="color: #000000">-</span><span style="color: #000000">8</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-*-</span><span style="color: #000000"><br /><br /><br />from&nbsp;os&nbsp;import&nbsp;path<br />import&nbsp;os<br />import&nbsp;sys<br />import&nbsp;pymssql<br />import&nbsp;datetime<br /><br /></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;MainSource(</span><span style="color: #0000ff">object</span><span style="color: #000000">):<br />&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;__init__(self,&nbsp;conf):<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.conf&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;&nbsp;conf<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.idx&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.data&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;[]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.conn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;None<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.cur&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;None<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;GetScheme(self):&nbsp;&nbsp;#获取结构，docid、文本、整数<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(</span><span style="color: #000000">'</span><span style="color: #000000">id</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;,&nbsp;{</span><span style="color: #000000">'</span><span style="color: #000000">docid</span><span style="color: #000000">'</span><span style="color: #000000">:True,&nbsp;}&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(</span><span style="color: #000000">'</span><span style="color: #000000">xx</span><span style="color: #000000">'</span><span style="color: #000000">,&nbsp;{&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">type</span><span style="color: #000000">'</span><span style="color: #000000">:</span><span style="color: #000000">'</span><span style="color: #000000">text</span><span style="color: #000000">'</span><span style="color: #000000">}&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(</span><span style="color: #000000">'</span><span style="color: #000000">xx1</span><span style="color: #000000">'</span><span style="color: #000000">,&nbsp;{</span><span style="color: #000000">'</span><span style="color: #000000">type</span><span style="color: #000000">'</span><span style="color: #000000">:</span><span style="color: #000000">'</span><span style="color: #000000">integer</span><span style="color: #000000">'</span><span style="color: #000000">}&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;GetFieldOrder(self):&nbsp;#字段的优先顺序<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;[(</span><span style="color: #000000">'</span><span style="color: #000000">name</span><span style="color: #000000">'</span><span style="color: #000000">)]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;Connected(self):&nbsp;&nbsp;&nbsp;#如果是数据库，则在此处做数据库连接<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;self.conn</span><span style="color: #000000">==</span><span style="color: #000000">None:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.conn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pymssql.connect(host</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">192.168.40.105</span><span style="color: #000000">'</span><span style="color: #000000">,&nbsp;user</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">sa</span><span style="color: #000000">'</span><span style="color: #000000">,&nbsp;password</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">987654321sa</span><span style="color: #000000">'</span><span style="color: #000000">,&nbsp;database</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">xxx</span><span style="color: #000000">'</span><span style="color: #000000">,&nbsp;as_dict</span><span style="color: #000000">=</span><span style="color: #000000">True,charset</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">cp936</span><span style="color: #000000">'</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.cur&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;self.conn.cursor()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sql&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">SELECT&nbsp;top&nbsp;12&nbsp;id,xx,xx1&nbsp;FROM&nbsp;tbxx</span><span style="color: #000000">'</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.cur.execute(sql)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.data&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;[&nbsp;row&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;row&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;self.cur]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pass<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;NextDocument(self):&nbsp;&nbsp;&nbsp;#取得每一个文档记录的调用<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;self.idx&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;len(self.data):<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">try</span><span style="color: #000000">:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;self.data[self.idx]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.docid&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;self.id&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;item[</span><span style="color: #000000">0</span><span style="color: #000000">]&nbsp;#</span><span style="color: #000000">'</span><span style="color: #000000">docid</span><span style="color: #000000">'</span><span style="color: #000000">:True<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.xx&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;item[</span><span style="color: #000000">1</span><span style="color: #000000">].encode(</span><span style="color: #000000">'</span><span style="color: #000000">utf-8</span><span style="color: #000000">'</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.xx1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.idx&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;True<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;except:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;False<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;False<br /><br /></span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;__name__&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">__main__</span><span style="color: #000000">"</span><span style="color: #000000">:&nbsp;&nbsp;&nbsp;&nbsp;#直接访问演示部分<br />&nbsp;&nbsp;&nbsp;&nbsp;conf&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;{}<br />&nbsp;&nbsp;&nbsp;&nbsp;source&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;MainSource(conf)<br />&nbsp;&nbsp;&nbsp;&nbsp;source.Connected()<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;source.NextDocument():<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">id=%d,&nbsp;subject=%s</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;(source.docid,&nbsp;source.xx)<br />&nbsp;&nbsp;&nbsp;&nbsp;pass<br />#eof<br /></span></div><br /><br /><br /><br /><br /><br /><br />参考地址：<a href="http://www.coreseek.cn/products-install/python/">http://www.coreseek.cn/products-install/python/</a><br /><br /><br /><br /><br /></span><img src ="http://www.cppblog.com/AutomateProgram/aggbug/198425.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2013-03-14 17:38 <a href="http://www.cppblog.com/AutomateProgram/archive/2013/03/14/198425.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>python和c#通用一致的des加密采用CBC和PKCS7</title><link>http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197017.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Sun, 06 Jan 2013 06:28:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197017.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/197017.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197017.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/197017.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/197017.html</trackback:ping><description><![CDATA[在python下可以下载pydes 下载地址为&nbsp;<a href="http://pydes.sourceforge.net/">http://pydes.sourceforge.net/</a><br /><br />在c#下实现des加密较为简单，如下：
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System;<br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Collections.Generic;<br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Linq;<br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Text;<br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.Security.Cryptography;<br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;System.IO;<br /><br /></span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;des<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;Program<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Main(</span><span style="color: #0000ff">string</span><span style="color: #000000">[]&nbsp;args)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;ss&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;EncryptDES(</span><span style="color: #000000">"</span><span style="color: #000000">1123</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">12345678</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;aa&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;DecryptDES(ss,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">12345678</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">默认密钥向量</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;iv&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">1234567812345678</span><span style="color: #000000">"</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;summary&gt;</span><span style="color: #008000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;DES加密字符串<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;/summary&gt;</span><span style="color: #008000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;param&nbsp;name="encryptString"&gt;</span><span style="color: #008000">待加密的字符串</span><span style="color: #808080">&lt;/param&gt;</span><span style="color: #008000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;param&nbsp;name="encryptKey"&gt;</span><span style="color: #008000">加密密钥,要求为8位</span><span style="color: #808080">&lt;/param&gt;</span><span style="color: #008000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;returns&gt;</span><span style="color: #008000">加密成功返回加密后的字符串，失败返回源串</span><span style="color: #808080">&lt;/returns&gt;</span><span style="color: #808080"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;EncryptDES(</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;encryptString,&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;encryptKey)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">try</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[]&nbsp;rgbKey&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Encoding.UTF8.GetBytes(encryptKey.Substring(</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">8</span><span style="color: #000000">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[]&nbsp;rgbIV&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Encoding.UTF8.GetBytes(iv);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[]&nbsp;inputByteArray&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Encoding.UTF8.GetBytes(encryptString);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DESCryptoServiceProvider&nbsp;dCSP&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;DESCryptoServiceProvider();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dCSP.Mode&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;CipherMode.CBC;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dCSP.Padding&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;PaddingMode.PKCS7;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MemoryStream&nbsp;mStream&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;MemoryStream();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CryptoStream&nbsp;cStream&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;CryptoStream(mStream,&nbsp;dCSP.CreateEncryptor(rgbKey,&nbsp;rgbIV),&nbsp;CryptoStreamMode.Write);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cStream.Write(inputByteArray,&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;inputByteArray.Length);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cStream.FlushFinalBlock();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;Convert.ToBase64String(mStream.ToArray());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">catch</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;encryptString;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;summary&gt;</span><span style="color: #008000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;DES解密字符串<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;/summary&gt;</span><span style="color: #008000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;param&nbsp;name="decryptString"&gt;</span><span style="color: #008000">待解密的字符串</span><span style="color: #808080">&lt;/param&gt;</span><span style="color: #008000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;param&nbsp;name="decryptKey"&gt;</span><span style="color: #008000">解密密钥,要求为8位,和加密密钥相同</span><span style="color: #808080">&lt;/param&gt;</span><span style="color: #008000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">&nbsp;</span><span style="color: #808080">&lt;returns&gt;</span><span style="color: #008000">解密成功返回解密后的字符串，失败返源串</span><span style="color: #808080">&lt;/returns&gt;</span><span style="color: #808080"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;DecryptDES(</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;decryptString,&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;decryptKey)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">try</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[]&nbsp;rgbKey&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Encoding.UTF8.GetBytes(decryptKey.Substring(</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">8</span><span style="color: #000000">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[]&nbsp;rgbIV&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Encoding.UTF8.GetBytes(iv);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[]&nbsp;inputByteArray&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Convert.FromBase64String(decryptString);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DESCryptoServiceProvider&nbsp;dCSP&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;DESCryptoServiceProvider();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dCSP.Mode&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;CipherMode.CBC;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dCSP.Padding&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;PaddingMode.PKCS7;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MemoryStream&nbsp;mStream&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;MemoryStream();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CryptoStream&nbsp;cStream&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;CryptoStream(mStream,&nbsp;dCSP.CreateDecryptor(rgbKey,&nbsp;rgbIV),&nbsp;CryptoStreamMode.Write);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cStream.Write(inputByteArray,&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;inputByteArray.Length);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cStream.FlushFinalBlock();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;Encoding.UTF8.GetString(mStream.ToArray());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">catch</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;decryptString;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span></div><br />python的实现如下：<br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000">#</span><span style="color: #008000">coding:utf-8</span><span style="color: #008000"><br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;binascii<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;base64<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;pyDes<br /><br /></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;DES:<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">#</span><span style="color: #008000">IV必须是&nbsp;8&nbsp;字节长度的十六进制数</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;iv&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">'</span><span style="color: #800000">1234567812345678</span><span style="color: #800000">'</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">#</span><span style="color: #008000">key加密密钥长度，24字节</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;key&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">'</span><span style="color: #800000">12345678</span><span style="color: #800000">'</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">def</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">__init__</span><span style="color: #000000">(self,&nbsp;iv,&nbsp;key):<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.iv&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;iv<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.key&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;key<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">def</span><span style="color: #000000">&nbsp;encrypt(self,&nbsp;data):<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pyDes.triple_des(self.key,&nbsp;pyDes.CBC,&nbsp;self.iv,&nbsp;pad</span><span style="color: #000000">=</span><span style="color: #000000">None,&nbsp;padmode</span><span style="color: #000000">=</span><span style="color: #000000">pyDes.PAD_PKCS5)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;k.encrypt(data)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;base64.encodestring(d)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;d<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">def</span><span style="color: #000000">&nbsp;decrypt(self,&nbsp;data):<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pyDes.triple_des(self.key,&nbsp;pyDes.CBC,&nbsp;self.iv,&nbsp;pad</span><span style="color: #000000">=</span><span style="color: #000000">None,&nbsp;padmode</span><span style="color: #000000">=</span><span style="color: #000000">pyDes.PAD_PKCS5)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;base64.decodestring(data)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;k.decrypt(data)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;d<br /></span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">__name__</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">'</span><span style="color: #800000">__main__</span><span style="color: #800000">'</span><span style="color: #000000">:<br />&nbsp;&nbsp;&nbsp;&nbsp;data&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">1123</span><span style="color: #800000">"</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;des&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;DES(</span><span style="color: #800000">'</span><span style="color: #800000">12345678</span><span style="color: #800000">'</span><span style="color: #000000">,</span><span style="color: #800000">'</span><span style="color: #800000">1234567812345678</span><span style="color: #800000">'</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;encryptdata&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;des.encrypt(data.encode(</span><span style="color: #800000">'</span><span style="color: #800000">utf-8</span><span style="color: #800000">'</span><span style="color: #000000">))<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">print</span><span style="color: #000000">&nbsp;&nbsp;encryptdata<br />&nbsp;&nbsp;&nbsp;&nbsp;decryptdata&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;des.decrypt(encryptdata)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">print</span><span style="color: #000000">&nbsp;decryptdata</span></div><br /><br /><img src ="http://www.cppblog.com/AutomateProgram/aggbug/197017.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2013-01-06 14:28 <a href="http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197017.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在python中调用.so动态库函数，获取hashab的计算结果</title><link>http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197010.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Sun, 06 Jan 2013 03:49:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197010.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/197010.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197010.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/197010.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/197010.html</trackback:ping><description><![CDATA[在网上下载了hashab的动态so库，要计算hashab的结果。这里使用python进行so连接库的调用，并使用calcHashAB 函数得出结果<br /><br />代码如下：
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#</span><span style="color: #000000">!/</span><span style="color: #000000">usr</span><span style="color: #000000">/</span><span style="color: #000000">bin</span><span style="color: #000000">/</span><span style="color: #000000">python<br />import&nbsp;cgi,&nbsp;cgitb<br />import&nbsp;ctypes<br /><br />print&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">Content-type:&nbsp;text/html\n\n</span><span style="color: #000000">"</span><span style="color: #000000"><br /><br />form&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;cgi.FieldStorage()<br />name&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;form.getvalue(</span><span style="color: #000000">'</span><span style="color: #000000">name</span><span style="color: #000000">'</span><span style="color: #000000">)<br />print&nbsp;name<br /><br />lib_handle&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;ctypes.CDLL(</span><span style="color: #000000">'</span><span style="color: #000000">./libhashab.so</span><span style="color: #000000">'</span><span style="color: #000000">)<br />calcHashAB&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;lib_handle.calcHashAB<br />target&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">f</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">57</span><span style="color: #000000"><br />sha1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">d1baa8ab45a9c34c1446</span><span style="color: #000000">"</span><span style="color: #000000"><br />uuid&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">4ba1aced491cf4dd11bd</span><span style="color: #000000">"</span><span style="color: #000000"><br />rnd_bytes&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">ABCDEFGHIJKLMNOPQRSTUVW</span><span style="color: #000000">"</span><span style="color: #000000"><br />calcHashAB(target,sha1,uuid,rnd_bytes)<br />print&nbsp;target</span></div><br />并把它放在cgi下就可以通过web进行访问。<img src ="http://www.cppblog.com/AutomateProgram/aggbug/197010.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2013-01-06 11:49 <a href="http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197010.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在ubuntu下使用apache cgi运行python脚本并获取get参数</title><link>http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197009.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Sun, 06 Jan 2013 03:42:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197009.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/197009.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197009.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/197009.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/197009.html</trackback:ping><description><![CDATA[编辑py文件，如hello.py
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#</span><span style="color: #000000">!/</span><span style="color: #000000">usr</span><span style="color: #000000">/</span><span style="color: #000000">bin</span><span style="color: #000000">/</span><span style="color: #000000">python<br />import&nbsp;cgi,&nbsp;cgitb<br /><br />print&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">Content-type:&nbsp;text/html\n\n</span><span style="color: #000000">"</span><span style="color: #000000"><br /><br />form&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;cgi.FieldStorage()<br />name&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;form.getvalue(</span><span style="color: #000000">'</span><span style="color: #000000">name</span><span style="color: #000000">'</span><span style="color: #000000">)<br />print&nbsp;name</span></div><br />把hello.py放在<span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; display: inline !important; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; float: none; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"><span class="Apple-converted-space">&nbsp;</span>/usr/lib/cgi-bin<span class="Apple-converted-space">&nbsp;并赋予可执行的权限 <span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; display: inline !important; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; float: none; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">chmod a+x helloworld.py</span><br /><br />重启apache2 <span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; display: inline !important; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; float: none; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">/etc/init.d/apache2 restart</span><br /><br /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; display: inline !important; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; float: none; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">在浏览器地址栏里输入：http://localhost/cgi-bin/hello.py<br /><br /><span style="widows: 2; text-transform: none; text-indent: 0px; display: inline !important; font: medium Simsun; white-space: normal; orphans: 2; float: none; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">qq</span><br /><br />参考地址：<a href="http://hi.baidu.com/pc_10/item/d5fe7972fbcc8145ee1e53c3">http://hi.baidu.com/pc_10/item/d5fe7972fbcc8145ee1e53c3</a><br /><a href="http://www.tutorialspoint.com/python/python_cgi_programming.htm">http://www.tutorialspoint.com/python/python_cgi_programming.htm</a><br /></span><br /></span></span><img src ="http://www.cppblog.com/AutomateProgram/aggbug/197009.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2013-01-06 11:42 <a href="http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197009.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>coreseek sphinx 搜索引擎  error connection to x.x failed (errno=0, msg=)问题的查找和解决</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/12/26/196682.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Wed, 26 Dec 2012 07:56:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/12/26/196682.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/196682.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/12/26/196682.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/196682.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/196682.html</trackback:ping><description><![CDATA[每次部署一台新的服务器的时候总是能碰到这个那个问题，很是烦人。<br /><br />在新的服务器重新架设了一个coreseek （sphinx） 搜索引擎结果出现了&nbsp;error connection to x.x failed (errno=0, msg=)<br />一开始从iptables，防火墙查找，都没有结果。<br /><br />后来看了看sphinxapi.php的代码，原来是fsockopen无法使用，查看了一下php.ini，果然被禁用了，disable_functions = ... fsockopen<br />去掉就可以使用了。<img src ="http://www.cppblog.com/AutomateProgram/aggbug/196682.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-12-26 15:56 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/12/26/196682.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在google go语言 golang中，html5，使用websocket，建立一个最简单的高并发web聊天室</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/12/20/196481.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Thu, 20 Dec 2012 07:32:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/12/20/196481.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/196481.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/12/20/196481.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/196481.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/196481.html</trackback:ping><description><![CDATA[这个程序简单，使用google go语言 golang和html5的websocket建立一个简单的web聊天程序。<br /><br />程序如下：
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;&nbsp;1</span>&nbsp;<span style="color: #000000">package&nbsp;main<br /></span><span style="color: #008080">&nbsp;&nbsp;2</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;&nbsp;3</span>&nbsp;<span style="color: #000000">import&nbsp;(<br /></span><span style="color: #008080">&nbsp;&nbsp;4</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">code.google.com/p/go.net/websocket</span><span style="color: #000000">"</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;&nbsp;5</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;&nbsp;6</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">fmt</span><span style="color: #000000">"</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;&nbsp;7</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">io</span><span style="color: #000000">"</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;&nbsp;8</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">net/http</span><span style="color: #000000">"</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;&nbsp;9</span>&nbsp;<span style="color: #000000">)<br /></span><span style="color: #008080">&nbsp;10</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;11</span>&nbsp;<span style="color: #000000">func&nbsp;Echo(ws&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">websocket.Conn)&nbsp;{<br /></span><span style="color: #008080">&nbsp;12</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;13</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;err&nbsp;error<br /></span><span style="color: #008080">&nbsp;14</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;15</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;mail&nbsp;:</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;ws.Config().Location.Query().Get(</span><span style="color: #000000">"</span><span style="color: #000000">mail</span><span style="color: #000000">"</span><span style="color: #000000">)<br /></span><span style="color: #008080">&nbsp;16</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;mailto&nbsp;:</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;ws.Config().Location.Query().Get(</span><span style="color: #000000">"</span><span style="color: #000000">mailto</span><span style="color: #000000">"</span><span style="color: #000000">)<br /></span><span style="color: #008080">&nbsp;17</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;18</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;fmt.Printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s,&nbsp;%s\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;mail,&nbsp;mailto)<br /></span><span style="color: #008080">&nbsp;19</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;20</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;mailmap[mail]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;ws<br /></span><span style="color: #008080">&nbsp;21</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;22</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;fmt.Printf(</span><span style="color: #000000">"</span><span style="color: #000000">%v\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;ws)<br /></span><span style="color: #008080">&nbsp;23</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;24</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;msgconnect&nbsp;:</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;mail&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;connect&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;25</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;fmt.Println(</span><span style="color: #000000">"</span><span style="color: #000000">server:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;msgconnect)<br /></span><span style="color: #008080">&nbsp;26</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;27</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;err&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;websocket.Message.Send(ws,&nbsp;msgconnect);&nbsp;err&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;nil&nbsp;{<br /></span><span style="color: #008080">&nbsp;28</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fmt.Println(</span><span style="color: #000000">"</span><span style="color: #000000">Can't&nbsp;send</span><span style="color: #000000">"</span><span style="color: #000000">)<br /></span><span style="color: #008080">&nbsp;29</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;30</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">&nbsp;31</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;32</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;{<br /></span><span style="color: #008080">&nbsp;33</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;reply&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;34</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;35</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;err&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;websocket.Message.Receive(ws,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">reply);&nbsp;err&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;nil&nbsp;{<br /></span><span style="color: #008080">&nbsp;36</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fmt.Println(</span><span style="color: #000000">"</span><span style="color: #000000">Can't&nbsp;receive</span><span style="color: #000000">"</span><span style="color: #000000">)<br /></span><span style="color: #008080">&nbsp;37</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;38</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">&nbsp;39</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;40</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fmt.Println(</span><span style="color: #000000">"</span><span style="color: #000000">Received&nbsp;back&nbsp;from&nbsp;client:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;reply)<br /></span><span style="color: #008080">&nbsp;41</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;42</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wst,&nbsp;err1&nbsp;:</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;mailmap[mailto]<br /></span><span style="color: #008080">&nbsp;43</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">err1&nbsp;{<br /></span><span style="color: #008080">&nbsp;44</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg&nbsp;:</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;mailto&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;not&nbsp;connect&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;45</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fmt.Println(</span><span style="color: #000000">"</span><span style="color: #000000">server:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;msg)<br /></span><span style="color: #008080">&nbsp;46</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;47</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;err&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;websocket.Message.Send(ws,&nbsp;msg);&nbsp;err&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;nil&nbsp;{<br /></span><span style="color: #008080">&nbsp;48</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fmt.Println(</span><span style="color: #000000">"</span><span style="color: #000000">Can't&nbsp;send</span><span style="color: #000000">"</span><span style="color: #000000">)<br /></span><span style="color: #008080">&nbsp;49</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;50</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">&nbsp;51</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;52</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">&nbsp;53</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;54</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg&nbsp;:</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;mail&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">:</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;reply<br /></span><span style="color: #008080">&nbsp;55</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fmt.Println(</span><span style="color: #000000">"</span><span style="color: #000000">Sending&nbsp;to&nbsp;client:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;msg)<br /></span><span style="color: #008080">&nbsp;56</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;57</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;err&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;websocket.Message.Send(wst,&nbsp;msg);&nbsp;err&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;nil&nbsp;{<br /></span><span style="color: #008080">&nbsp;58</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fmt.Println(</span><span style="color: #000000">"</span><span style="color: #000000">Can't&nbsp;send</span><span style="color: #000000">"</span><span style="color: #000000">)<br /></span><span style="color: #008080">&nbsp;59</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;60</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">&nbsp;61</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">&nbsp;62</span>&nbsp;<span style="color: #000000">}<br /></span><span style="color: #008080">&nbsp;63</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;64</span>&nbsp;<span style="color: #000000"></span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;网页客户端</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;65</span>&nbsp;<span style="color: #008000"></span><span style="color: #000000">func&nbsp;Client(w&nbsp;http.ResponseWriter,&nbsp;r&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">http.Request)&nbsp;{<br /></span><span style="color: #008080">&nbsp;66</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;html&nbsp;:</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;`</span><span style="color: #000000">&lt;!</span><span style="color: #000000">doctype&nbsp;html</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;67</span>&nbsp;<span style="color: #000000"></span><span style="color: #000000">&lt;!</span><span style="color: #000000">doctype&nbsp;html</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;68</span>&nbsp;<span style="color: #000000"></span><span style="color: #000000">&lt;</span><span style="color: #000000">html</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;69</span>&nbsp;<span style="color: #000000"></span><span style="color: #000000">&lt;</span><span style="color: #000000">head</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;70</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">meta&nbsp;http</span><span style="color: #000000">-</span><span style="color: #000000">equiv</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">Content-Type</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;content</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">text/html;&nbsp;charset=utf-8</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;71</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">title</span><span style="color: #000000">&gt;</span><span style="color: #000000">golang&nbsp;websocket&nbsp;chatroom</span><span style="color: #000000">&lt;/</span><span style="color: #000000">title</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;72</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">script&nbsp;src</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">http://img3.douban.com/js/packed_jquery.min6301986802.js</span><span style="color: #000000">"</span><span style="color: #000000">&gt;&lt;/</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;73</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">&nbsp;74</span>&nbsp;<span style="color: #000000"></span><span style="color: #000000">&lt;/</span><span style="color: #000000">head</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;75</span>&nbsp;<span style="color: #000000"></span><span style="color: #000000">&lt;</span><span style="color: #000000">body</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;76</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">h1</span><span style="color: #000000">&gt;</span><span style="color: #000000">WebSocket&nbsp;chat&nbsp;with&nbsp;server&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">h1</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;77</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">div&nbsp;id</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">log</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;style</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">height:&nbsp;300px;overflow-y:&nbsp;scroll;border:&nbsp;1px&nbsp;solid&nbsp;#CCC;</span><span style="color: #000000">"</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;78</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">div</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;79</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">div</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;80</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">&nbsp;81</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">p</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;82</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mail:&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">input&nbsp;id</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">mail</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;type</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">text</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;value</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">automate@qq.com</span><span style="color: #000000">"</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;83</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">p</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;84</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;85</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">p</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;86</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mailto:&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">input&nbsp;id</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">mailto</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;type</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">text</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;value</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">program@qq.com</span><span style="color: #000000">"</span><span style="color: #000000">&gt;&lt;</span><span style="color: #000000">button&nbsp;onclick</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">connectto();</span><span style="color: #000000">"</span><span style="color: #000000">&gt;</span><span style="color: #000000">Connect&nbsp;to</span><span style="color: #000000">&lt;/</span><span style="color: #000000">button</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;87</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">p</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;88</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;89</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">&nbsp;90</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;91</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">p</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;92</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Message:&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">input&nbsp;id</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">msg</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;type</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">text</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;value</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">Hello,&nbsp;world!</span><span style="color: #000000">"</span><span style="color: #000000">&gt;&lt;</span><span style="color: #000000">button&nbsp;onclick</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">sendto();</span><span style="color: #000000">"</span><span style="color: #000000">&gt;</span><span style="color: #000000">Send&nbsp;Message</span><span style="color: #000000">&lt;/</span><span style="color: #000000">button</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;93</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">p</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;94</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;95</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;96</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">&nbsp;97</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">div</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;98</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">&nbsp;99</span>&nbsp;<span style="color: #000000"></span><span style="color: #000000">&lt;/</span><span style="color: #000000">body</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">100</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">101</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">102</span>&nbsp;<span style="color: #000000"></span><span style="color: #000000">&lt;</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">103</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">104</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">105</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">106</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">107</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;connectto()&nbsp;{<br /></span><span style="color: #008080">108</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;mail&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;document.getElementById(</span><span style="color: #000000">'</span><span style="color: #000000">mail</span><span style="color: #000000">'</span><span style="color: #000000">).value;<br /></span><span style="color: #008080">109</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(mail);<br /></span><span style="color: #008080">110</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">111</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;mailto&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;document.getElementById(</span><span style="color: #000000">'</span><span style="color: #000000">mailto</span><span style="color: #000000">'</span><span style="color: #000000">).value;<br /></span><span style="color: #008080">112</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(mailto);<br /></span><span style="color: #008080">113</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">114</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;url&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">ws://127.0.0.1:8001/chatroom?mailto=</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;mailto&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&amp;mail=</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;mail;<br /></span><span style="color: #008080">115</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">116</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ws&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;WebSocket(url);<br /></span><span style="color: #008080">117</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">118</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ws.onopen&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;function(e){<br /></span><span style="color: #008080">119</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(</span><span style="color: #000000">"</span><span style="color: #000000">onopen</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">120</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.dir(e);<br /></span><span style="color: #008080">121</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br /></span><span style="color: #008080">122</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">123</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ws.onmessage&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;function(e){<br /></span><span style="color: #008080">124</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(</span><span style="color: #000000">"</span><span style="color: #000000">onmessage</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">125</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.dir(e);<br /></span><span style="color: #008080">126</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(</span><span style="color: #000000">'</span><span style="color: #000000">#log</span><span style="color: #000000">'</span><span style="color: #000000">).append(</span><span style="color: #000000">'</span><span style="color: #000000">&lt;p&gt;</span><span style="color: #000000">'</span><span style="color: #000000">+</span><span style="color: #000000">e.data</span><span style="color: #000000">+</span><span style="color: #000000">'</span><span style="color: #000000">&lt;p&gt;</span><span style="color: #000000">'</span><span style="color: #000000">);<br /></span><span style="color: #008080">127</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(</span><span style="color: #000000">'</span><span style="color: #000000">#log</span><span style="color: #000000">'</span><span style="color: #000000">).</span><span style="color: #0000ff">get</span><span style="color: #000000">(</span><span style="color: #000000">0</span><span style="color: #000000">).scrollTop&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;$(</span><span style="color: #000000">'</span><span style="color: #000000">#log</span><span style="color: #000000">'</span><span style="color: #000000">).</span><span style="color: #0000ff">get</span><span style="color: #000000">(</span><span style="color: #000000">0</span><span style="color: #000000">).scrollHeight;<br /></span><span style="color: #008080">128</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br /></span><span style="color: #008080">129</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">130</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ws.onclose&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;function(e){<br /></span><span style="color: #008080">131</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(</span><span style="color: #000000">"</span><span style="color: #000000">onclose</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">132</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.dir(e);<br /></span><span style="color: #008080">133</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br /></span><span style="color: #008080">134</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">135</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ws.onerror&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;function(e){<br /></span><span style="color: #008080">136</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(</span><span style="color: #000000">"</span><span style="color: #000000">onerror</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">137</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.dir(e);<br /></span><span style="color: #008080">138</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br /></span><span style="color: #008080">139</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">140</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">141</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br /></span><span style="color: #008080">142</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">143</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;sendto()&nbsp;{<br /></span><span style="color: #008080">144</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;mail&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;document.getElementById(</span><span style="color: #000000">'</span><span style="color: #000000">mail</span><span style="color: #000000">'</span><span style="color: #000000">).value;<br /></span><span style="color: #008080">145</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;msg&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;document.getElementById(</span><span style="color: #000000">'</span><span style="color: #000000">msg</span><span style="color: #000000">'</span><span style="color: #000000">).value;<br /></span><span style="color: #008080">146</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(</span><span style="color: #000000">'</span><span style="color: #000000">#log</span><span style="color: #000000">'</span><span style="color: #000000">).append(</span><span style="color: #000000">'</span><span style="color: #000000">&lt;p&nbsp;style="color:red;"&gt;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;mail&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;:&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">+</span><span style="color: #000000">msg</span><span style="color: #000000">+</span><span style="color: #000000">'</span><span style="color: #000000">&lt;p&gt;</span><span style="color: #000000">'</span><span style="color: #000000">);<br /></span><span style="color: #008080">147</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(</span><span style="color: #000000">'</span><span style="color: #000000">#log</span><span style="color: #000000">'</span><span style="color: #000000">).</span><span style="color: #0000ff">get</span><span style="color: #000000">(</span><span style="color: #000000">0</span><span style="color: #000000">).scrollTop&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;$(</span><span style="color: #000000">'</span><span style="color: #000000">#log</span><span style="color: #000000">'</span><span style="color: #000000">).</span><span style="color: #0000ff">get</span><span style="color: #000000">(</span><span style="color: #000000">0</span><span style="color: #000000">).scrollHeight;<br /></span><span style="color: #008080">148</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">149</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ws.send(msg);<br /></span><span style="color: #008080">150</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br /></span><span style="color: #008080">151</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">152</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">&lt;/</span><span style="color: #000000">script</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">153</span>&nbsp;<span style="color: #000000"></span><span style="color: #000000">&lt;/</span><span style="color: #000000">html</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">154</span>&nbsp;<span style="color: #000000">`<br /></span><span style="color: #008080">155</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;io.WriteString(w,&nbsp;html)<br /></span><span style="color: #008080">156</span>&nbsp;<span style="color: #000000">}<br /></span><span style="color: #008080">157</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">158</span>&nbsp;<span style="color: #000000">var&nbsp;mailmap&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;make(map[</span><span style="color: #0000ff">string</span><span style="color: #000000">]</span><span style="color: #000000">*</span><span style="color: #000000">websocket.Conn,&nbsp;</span><span style="color: #000000">10</span><span style="color: #000000">)<br /></span><span style="color: #008080">159</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">160</span>&nbsp;<span style="color: #000000">func&nbsp;main()&nbsp;{<br /></span><span style="color: #008080">161</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">162</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;fmt.Println(</span><span style="color: #000000">"</span><span style="color: #000000">listen&nbsp;on&nbsp;port&nbsp;8001</span><span style="color: #000000">"</span><span style="color: #000000">)<br /></span><span style="color: #008080">163</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;fmt.Println(</span><span style="color: #000000">"</span><span style="color: #000000">visit&nbsp;http://127.0.0.1:8001/chat&nbsp;with&nbsp;web&nbsp;browser(recommend:&nbsp;chrome)</span><span style="color: #000000">"</span><span style="color: #000000">)<br /></span><span style="color: #008080">164</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">165</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;http.Handle(</span><span style="color: #000000">"</span><span style="color: #000000">/</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;websocket.Handler(Echo))<br /></span><span style="color: #008080">166</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;http.HandleFunc(</span><span style="color: #000000">"</span><span style="color: #000000">/chat</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;Client)<br /></span><span style="color: #008080">167</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;err&nbsp;:</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;http.ListenAndServe(</span><span style="color: #000000">"</span><span style="color: #000000">:8001</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;nil)<br /></span><span style="color: #008080">168</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">169</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;err&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;nil&nbsp;{<br /></span><span style="color: #008080">170</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;panic(</span><span style="color: #000000">"</span><span style="color: #000000">ListenAndServe:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;err.Error())<br /></span><span style="color: #008080">171</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">172</span>&nbsp;<span style="color: #000000">}<br /></span><span style="color: #008080">173</span>&nbsp;<span style="color: #000000"></span></div><br />运行<a href="http://127.0.0.1:8001/chat">http://127.0.0.1:8001/chat</a><br />在两个不同的浏览器下 互给用户名，连接后就可以开始聊天<br /><br />如下图：<br /><br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/automateprogram/ww.jpg" width="1228" height="587" /><br /><br /><img src ="http://www.cppblog.com/AutomateProgram/aggbug/196481.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-12-20 15:32 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/12/20/196481.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vs2005编译 lua 源代码 和lua的入门使用</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/12/14/196254.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Fri, 14 Dec 2012 07:36:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/12/14/196254.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/196254.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/12/14/196254.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/196254.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/196254.html</trackback:ping><description><![CDATA[<br />到<a style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(159,159,159); word-spacing: 0px; text-decoration: underline; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" href="http://www.lua.org/ftp/">http://www.lua.org/ftp/</a>&nbsp;下载源代码，解压出src文件夹<br /><br /><br /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; display: inline !important; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; float: none; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">编译分三步：</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; display: inline !important; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; float: none; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">1：编译静态库</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; display: inline !important; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; float: none; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">打开vs2003-文件-新建-项目-vc++项目-windows控制台项目，输入名称（我这里输入lualib）,单击确定，在左边选择应用程序设置，然后在右边选择静态库，单击完成，把源文件和头文件里的文件全部删掉，右键源文件-添加-添加现有项，把src中除了lua.c、lua.h、luac.c以为的文件全部选上打开 编译后生成了一个Lualib.lib文件<br /></span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; display: inline !important; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; float: none; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">2：编译lua解释器</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; display: inline !important; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; float: none; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">打开vs2003-文件-新建-项目-vc++项目-windows控制台项目，输入名称（我这里输入lua）,单击完成。把源文件和头文件里的文件全部删掉，右键源文件-添加-添加现有项，把src中lua.c、lua.h打开，右键lua-项目依赖，选择lua取决于lualib，确定编译后生成lua.exe。<br /></span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; display: inline !important; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; float: none; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">3：编译luac编译器</span><br style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; display: inline !important; font: 14px/21px tahoma, helvetica, arial; white-space: normal; orphans: 2; float: none; letter-spacing: normal; color: rgb(69,69,69); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">打开vs2003-文件-新建-项目-vc++项目-windows控制台项目，输入名称（我这里输入luac）,单击完成。把源文件和头文件里的文件全部删掉，右键源文件-添加-添加现有项，把src中luac.c 打开，右键luac-项目依赖，选择luac取决于lualib，确定编译后生成luac.exe。<br /><br />在这里可以下载到我编译好的 <a href="/Files/AutomateProgram/luaForTB.rar">下载<br /><br />参考地址：http://hi.baidu.com/meakhella/item/f291a5b99a27f6e04ec7fd57<br /></a></span><img src ="http://www.cppblog.com/AutomateProgram/aggbug/196254.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-12-14 15:36 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/12/14/196254.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>golang go语言 http包 和 高并发下的websocket</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/12/14/196251.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Fri, 14 Dec 2012 07:07:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/12/14/196251.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/196251.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/12/14/196251.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/196251.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/196251.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 用golang 建立起一个http server 非常的简单，只要简单的几行代码：&nbsp; Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->package&nbsp;main&nbsp;import&nbsp;(&nbsp;&nbsp;&nbs...&nbsp;&nbsp;<a href='http://www.cppblog.com/AutomateProgram/archive/2012/12/14/196251.html'>阅读全文</a><img src ="http://www.cppblog.com/AutomateProgram/aggbug/196251.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-12-14 15:07 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/12/14/196251.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c#(csharp .net)下使用json</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/09/13/190502.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Thu, 13 Sep 2012 04:01:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/09/13/190502.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/190502.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/09/13/190502.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/190502.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/190502.html</trackback:ping><description><![CDATA[<br />到<br /><a href="http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html">http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html</a><br />下载json.cs<br /><br />使用如下：
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;jsonText&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">[{\</span><span style="color: #000000">"</span><span style="color: #000000">name\</span><span style="color: #000000">"</span><span style="color: #000000">:\</span><span style="color: #000000">"</span><span style="color: #000000">123</span><span style="color: #000000">\</span><span style="color: #000000">"</span><span style="color: #000000">,\</span><span style="color: #000000">"</span><span style="color: #000000">name2\</span><span style="color: #000000">"</span><span style="color: #000000">:[{\</span><span style="color: #000000">"</span><span style="color: #000000">ip\</span><span style="color: #000000">"</span><span style="color: #000000">:-456e8}]},{\</span><span style="color: #000000">"</span><span style="color: #000000">name\</span><span style="color: #000000">"</span><span style="color: #000000">:\</span><span style="color: #000000">"</span><span style="color: #000000">123</span><span style="color: #000000">\</span><span style="color: #000000">"</span><span style="color: #000000">,\</span><span style="color: #000000">"</span><span style="color: #000000">name2\</span><span style="color: #000000">"</span><span style="color: #000000">:[{\</span><span style="color: #000000">"</span><span style="color: #000000">ip\</span><span style="color: #000000">"</span><span style="color: #000000">:-456e1}]}]</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ArrayList&nbsp;listInfo&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(ArrayList)JSON.JsonDecode(jsonText);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ArrayList&nbsp;listTo&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ArrayList();<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;listInfo.Count;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_317_652_Open_Image" onclick="this.style.display='none'; Codehighlighter1_317_652_Open_Text.style.display='none'; Codehighlighter1_317_652_Closed_Image.style.display='inline'; Codehighlighter1_317_652_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_317_652_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_317_652_Closed_Text.style.display='none'; Codehighlighter1_317_652_Open_Image.style.display='inline'; Codehighlighter1_317_652_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_317_652_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_317_652_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hashtable&nbsp;hInfo&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(Hashtable)listInfo[i];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listTo.Add(hInfo);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;name&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">string</span><span style="color: #000000">)hInfo[</span><span style="color: #000000">"</span><span style="color: #000000">name</span><span style="color: #000000">"</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ArrayList&nbsp;aname2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(ArrayList)hInfo[</span><span style="color: #000000">"</span><span style="color: #000000">name2</span><span style="color: #000000">"</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hashtable&nbsp;hname2ip&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(Hashtable)aname2[</span><span style="color: #000000">0</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;ip1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">double</span><span style="color: #000000">)hname2ip[</span><span style="color: #000000">"</span><span style="color: #000000">ip</span><span style="color: #000000">"</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;toJson&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">""</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;toJson&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;JSON.JsonEncode(listTo);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(toJson);</span></div><br /><br />更多使用可以参考<br /><a href="http://www.json.org/">http://www.json.org/</a>&nbsp;的使用。<br /><img src ="http://www.cppblog.com/AutomateProgram/aggbug/190502.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-09-13 12:01 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/09/13/190502.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql账号权限管理和账号设置</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/06/14/178780.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Thu, 14 Jun 2012 04:02:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/06/14/178780.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/178780.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/06/14/178780.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/178780.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/178780.html</trackback:ping><description><![CDATA[<div style="layout-grid:  15.6pt none" class="Section0">
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 15pt; font-weight: bold; mso-spacerun: 'yes'">一．</span><span style="font-style: normal; font-family: 'Verdana'; font-size: 15pt; font-weight: bold; mso-spacerun: 'yes'">权限查看</span><span style="font-family: 'Times New Roman'; font-size: 15pt; font-weight: bold; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 15pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: 'Verdana'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">mysql&gt;&nbsp;show&nbsp;grants&nbsp;for&nbsp;<font face="Times New Roman">&#8216;</font><font face="Verdana">root</font><font face="Times New Roman">&#8217;</font><font face="Verdana">@'localhost</font><font face="Times New Roman">&#8217;&nbsp;</font><font face="Verdana">;</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Verdana'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">+<font face="Times New Roman">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</font><font face="Verdana">-+</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Verdana'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">|&nbsp;Grants&nbsp;for&nbsp;root@localhost&nbsp;|</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Verdana'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">+<font face="Times New Roman">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</font><font face="Verdana">-+</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Verdana'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">|&nbsp;GRANT&nbsp;ALL&nbsp;PRIVILEGES&nbsp;ON&nbsp;*.*&nbsp;TO&nbsp;<font face="Times New Roman">&#8216;</font><font face="Verdana">root</font><font face="Times New Roman">&#8217;</font><font face="Verdana">@'localhost</font><font face="Times New Roman">&#8217;&nbsp;</font><font face="Verdana">WITH&nbsp;GRANT&nbsp;OPTION&nbsp;|</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Verdana'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">+<font face="Times New Roman">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</font><font face="Verdana">-+</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">二．</span><span style="font-style: normal; font-family: 'Verdana'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">权限设置</span><span style="font-family: 'Times New Roman'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">1.</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">创建账号或者赋予权限</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;privileges&nbsp;(columns)&nbsp;ON&nbsp;what&nbsp;TO&nbsp;user&nbsp;IDENTIFIED&nbsp;BY&nbsp;"password"&nbsp;WITH&nbsp;GRANT&nbsp;OPTION</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT语句的语法看上去像这样：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;privileges&nbsp;(columns)&nbsp;ON&nbsp;what&nbsp;TO&nbsp;user&nbsp;IDENTIFIED&nbsp;BY&nbsp;"password"&nbsp;WITH&nbsp;GRANT&nbsp;OPTION</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">要使用该语句，你需要填写下列部分：&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">privileges</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;授予用户的权限，下表列出可用于GRANT语句的权限指定符：&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　权限指定符&nbsp;权限允许的操作&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Alter</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　　　修改表和索引&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Create</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　&nbsp;创建数据库和表&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Delete</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　&nbsp;删除表中已有的记录&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Drop</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　&nbsp;抛弃（删除）数据库和表&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">INDEX</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　&nbsp;创建或抛弃索引&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Insert</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　&nbsp;向表中插入新行&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">REFERENCE</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　未用&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Select</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　　　&nbsp;检索表中的记录&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">Update</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　&nbsp;修改现存表记录&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">FILE</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　　　读或写服务器上的文件&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">PROCESS</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　&nbsp;查看服务器中执行的线程信息或杀死线程&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">RELOAD</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　重载授权表或清空日志、主机缓存或表缓存。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">SHUTDOWN</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　&nbsp;关闭服务器&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">ALL</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　　　所有；ALL&nbsp;PRIVILEGES同义词&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">USAGE</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　　　特殊的&#8220;无权限&#8221;权限</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　上表显示在第一组的权限指定符适用于数据库、表和列，第二组数管理权限。一般，这些被相对严格地授权，因为它们允许用户影响服务器的操作。第三组权限特殊，ALL意味着&#8220;所有权限&#8221;，UASGE意味着无权限，即创建用户，但不授予权限。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">columns</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　权限运用的列，它是可选的，并且你只能设置列特定的权限。如果命令有多于一个列，应该用逗号分开它们。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">what</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;　　权限运用的级别。权限可以是全局的（适用于所有数据库和所有表）、特定数据库（适用于一个数据库中的所有表）或特定表的。可以通过指定一个columns字句是权限是列特定的。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">user&nbsp;</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　&nbsp;　权限授予的用户，它由一个用户名和主机名组成。在MySQL中，你不仅指定谁能连接，还有从哪里连接。这允许你让两个同名用户从不同地方连接。&nbsp;MySQL让你区分他们，并彼此独立地赋予权限。MySQL中的一个用户名就是你连接服务器时指定的用户名，该名字不必与你的Unix登录名或&nbsp;Windows名联系起来。缺省地，如果你不明确指定一个名字，客户程序将使用你的登录名作为MySQL用户名。这只是一个约定。你可以在授权表中将该名&nbsp;字改为nobody，然后以nobody连接执行需要超级用户权限的操作。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">password&nbsp;</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　&nbsp;　赋予用户的口令，它是可选的。如果你对新用户没有指定IDENTIFIED&nbsp;BY子句，该用户不赋给口令（不安全）。对现有用户，任何你指定的口令将代替老口令。如果你不指定口令，老口令保持不变，当你用IDENTIFIED&nbsp;BY时，口令字符串用改用口令的字面含义，GRANT将为你编码口令，不要你用SET&nbsp;PASSWORD&nbsp;那样使用password()函数。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">WITH&nbsp;GRANT&nbsp;OPTION</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">子句是可选的。如果你包含它，用户可以授予权限通过GRANT语句授权给其它用户。你可以用该子句给与其它用户授权的能力。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">注意：</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">用户名、口令、数据库和表名在授权表记录中是大小写敏感的，主机名和列名不是。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　一般地，你可以通过询问几个简单的问题来识别GRANT语句的种类：&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　谁能连接，从那儿连接？&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　用户应该有什么级别的权限，他们适用于什么？&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　用户应该允许管理权限吗？&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　下面就讨论一些例子。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　1.1&nbsp;谁能连接，从那儿连接？&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　你可以允许一个用户从特定的或一系列主机连接。有一个极端，如果你知道降职从一个主机连接，你可以将权限局限于单个主机：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;boris@localhost&nbsp;IDENTIFIED&nbsp;BY&nbsp;"ruby"</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;fred@res.mars.com&nbsp;IDENTIFIED&nbsp;BY&nbsp;"quartz"</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　(samp_db.*意思是&#8220;samp_db数据库的所有表)另一个极端是，你可能有一个经常旅行并需要能从世界各地的主机连接的用户max。在这种情况下，你可以允许他无论从哪里连接：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;max@%&nbsp;IDENTIFIED&nbsp;BY&nbsp;"diamond"&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　&#8220;%&#8221;字符起通配符作用，与LIKE模式匹配的含义相同。在上述语句中，它意味着&#8220;任何主机&#8221;。所以max和max@%等价。这是建立用户最简单的方法，但也是最不安全的。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　其中，你可以允许一个用户从一个受限的主机集合访问。例如，要允许mary从snake.net域的任何主机连接，用一个%.snake.net主机指定符：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;mary@.snake.net&nbsp;IDENTIFIED&nbsp;BY&nbsp;"quartz";&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　如果你喜欢，用户标识符的主机部分可以用IP地址而不是一个主机名来给定。你可以指定一个IP地址或一个包含模式字符的地址，而且，从MySQL&nbsp;3.23，你还可以指定具有指出用于网络号的位数的网络掩码的IP号：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;boris@192.168.128.3&nbsp;IDENTIFIED&nbsp;BY&nbsp;"ruby"&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;fred@192.168.128.%&nbsp;IDENTIFIED&nbsp;BY&nbsp;"quartz"&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db.*&nbsp;TO&nbsp;rex@192.168.128.0/17&nbsp;IDENTIFIED&nbsp;BY&nbsp;"ruby"</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　第一个例子指出用户能从其连接的特定主机，第二个指定对于C类子网192.168.128的IP模式，而第三条语句中，192.168.128.0/17指定一个17位网络号并匹配具有192.168.128头17位的IP地址。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　1.2&nbsp;用户应该有什么级别的权限和它们应该适用于什么？</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　你可以授权不同级别的权限，全局权限是最强大的，因为它们适用于任何数据库。要使ethel成为可做任何事情的超级用户，包括能授权给其它用户，发出下列语句：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;ALL&nbsp;ON&nbsp;*.*&nbsp;TO&nbsp;ethel@localhost&nbsp;IDENTIFIED&nbsp;BY&nbsp;"coffee"&nbsp;WITH&nbsp;GRANT&nbsp;OPTION</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　ON子句中的*.*意味着&#8220;所有数据库、所有表&#8221;。从安全考虑，我们指定ethel只能从本地连接。限制一个超级用户可以连接的主机通常是明智的，因为它限制了试图破解口令的主机。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　&nbsp;　有些权限（FILE、PROCESS、RELOAD和SHUTDOWN）是管理权限并且只能用"ON&nbsp;*.*"全局权限指定符授权。如果你愿意，你可以授权这些权限，而不授权数据库权限。例如，下列语句设置一个flush用户，他只能发出flush语句。&nbsp;这可能在你需要执行诸如清空日志等的管理脚本中会有用：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;RELOAD&nbsp;ON&nbsp;*.*&nbsp;TO&nbsp;flushl@localhost&nbsp;IDENTIFIED&nbsp;BY&nbsp;"flushpass"&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　一般地，你想授权管理权限，吝啬点，因为拥有它们的用户可以影响你的服务器的操作。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">数据库级权限适用于一个特定数据库中的所有表，它们可通过使用ON&nbsp;db_name.*子句授予：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;ALL&nbsp;ON&nbsp;samp_db&nbsp;TO&nbsp;bill@racer.snake.net&nbsp;INDETIFIED&nbsp;BY&nbsp;"rock"&nbsp;GRANT&nbsp;Select&nbsp;ON&nbsp;samp_db&nbsp;TO&nbsp;ro_user@%&nbsp;INDETIFIED&nbsp;BY&nbsp;"rock"</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　第一条语句向bill授权samp_db数据库中所有表的权限，第二条创建一个严格限制访问的用户ro_user（只读用户），只能访问samp_db数据库中的所有表，但只有读取，即用户只能发出Select语句。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　你可以列出一系列同时授予的各个权限。例如，如果你想让用户能读取并能修改现有数据库的内容，但不能创建新表或删除表，如下授予这些权限：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;Select,Insert,Delete,Update&nbsp;ON&nbsp;samp_db&nbsp;TO&nbsp;bill@snake.net&nbsp;INDETIFIED&nbsp;BY&nbsp;"rock"</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　对于更精致的访问控制，你可以在各个表上授权，或甚至在表的每个列上。当你想向用户隐藏一个表的部分时，或你想让一个用户只能修改特定的列时，列特定权限非常有用。如：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;Select&nbsp;ON&nbsp;samp_db.member&nbsp;TO&nbsp;bill@localhost&nbsp;INDETIFIED&nbsp;BY&nbsp;"rock"</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　GRANT&nbsp;Update&nbsp;(expiration)&nbsp;ON&nbsp;samp_db.&nbsp;member&nbsp;TO&nbsp;bill@localhost&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　第一条语句授予对整个member表的读权限并设置了一个口令，第二条语句增加了Update权限，当只对expiration列。没必要再指定口令，因为第一条语句已经指定了。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　如果你想对多个列授予权限，指定一个用逗号分开的列表。例如，对assistant用户增加member表的地址字段的Update权限，使用如下语句，新权限将加到用户已有的权限中：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;Update&nbsp;(street,city,state,zip)&nbsp;ON&nbsp;samp_db&nbsp;TO&nbsp;assistant@localhost&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">1.3&nbsp;用户应该被允许管理权限吗？</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　&nbsp;　你可以允许一个数据库的拥有者通过授予数据库上的所有拥有者权限来控制数据库的访问，在授权时，指定WITH&nbsp;GRANT&nbsp;OPTION。例如：如果你想让alicia能从big.corp.com域的任何主机连接并具有sales数据库中所有表的管理员权限，你可以用如下&nbsp;GRANT语句：&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">GRANT&nbsp;ALL&nbsp;ON&nbsp;sales.*&nbsp;TO&nbsp;alicia@%.big.corp.com&nbsp;INDETIFIED&nbsp;BY&nbsp;"applejuice"&nbsp;WITH&nbsp;GRANT&nbsp;OPTION</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　&nbsp;　在效果上WITH&nbsp;GRANT&nbsp;OPTION子句允许你把访问授权的权利授予另一个用户。要注意，拥有GRANT权限的两个用户可以彼此授权。如果你只给予了第一个用户Select权&nbsp;限，而另一个用户有GRANT加上Select权限，那么第二个用户可以是第一个用户更&#8220;强大&#8221;。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">常见语句：</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">常见账号，并赋予权限</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">GRANT&nbsp;SELECT,INSERT,UPDATE,DELETE,CREATE,DROP&nbsp;ON&nbsp;</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">db1</span><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">.*&nbsp;TO&nbsp;'linpp'@'192.168.40.111'&nbsp;IDENTIFIED&nbsp;BY&nbsp;'qq';</span><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">进一步赋予权限</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">GRANT&nbsp;SELECT&nbsp;ON&nbsp;</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">db2</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">.*&nbsp;TO&nbsp;'linpp'@'192.168.40.111';</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">2.</span><span style="font-style: normal; font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">撤权并删除用户</span><span style="font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">要取消一个用户的权限，使用REVOKE语句。REVOKE的语法非常类似于GRANT语句，除了TO用FROM取代并且没有INDETIFED&nbsp;BY和WITH&nbsp;GRANT&nbsp;OPTION子句：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">REVOKE&nbsp;privileges&nbsp;(columns)&nbsp;ON&nbsp;what&nbsp;FROM&nbsp;user&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　user部分必须匹配原来GRANT语句的你想撤权的用户的user部分。privileges部分不需匹配，你可以用GRANT语句授权，然后用REVOKE语句只撤销部分权限。&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　REVOKE语句只删除权限，而不删除用户。即使你撤销了所有权限，在user表中的用户记录依然保留，这意味着用户仍然可以连接服务器。要完全删除一个用户，你必须用一条Delete语句明确从user表中删除用户记录：&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">%mysql&nbsp;-u&nbsp;root&nbsp;mysqlmysql&gt;Delete&nbsp;FROM&nbsp;user&nbsp;-&gt;Where&nbsp;User="user_name"&nbsp;and&nbsp;Host="host_name";mysql&gt;FLUSH&nbsp;PRIVILEGES;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">从ip为 * 以后限制ip 可先删除账号，在构建有ip限制的用户，用户权限不会改变，或者直接修改user表的host<br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">　　Delete语句删除用户记录，而FLUSH语句告诉服务器重载授权表。（当你使用GRANT和REVOKE语句时，表自动重载，而你直接修改授权表时不是。）</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">常见语句：</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">&nbsp;REVOKE&nbsp;UPDATE&nbsp;ON&nbsp;</span><span style="font-family: '宋体'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">db1</span><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'">.*&nbsp;FROM&nbsp;'linpp'@'192.168.40.111';</span><span style="font-family: 'Times New Roman'; font-size: 12pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">三.</span><span style="font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">mysql&nbsp;修改密码</span><span style="font-family: '宋体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">use&nbsp;mysql</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">u</span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">pdate&nbsp;user&nbsp;set&nbsp;password=password('你的密码')&nbsp;where&nbsp;User='root';</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: '宋体'; font-size: 12pt; font-weight: normal; mso-spacerun: 'yes'">flush&nbsp;privileges;</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">四．</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">涉及到账号和权限的表</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">User</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">每一行就是一个用户账号以及用户的全部权限</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">Db</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">每一行包含了某些用户在数据库级权限</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">Host</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">每一行包含了用户从指定主机登陆过来时它在一个数据库里的所有权限，这个条目会与db表里的条目合并起来使用。虽然它是作为授权表罗列出来的，但是你无法使用grant,revoke等命令修改这个主机表，你只能手动添加和删除其中的条目。</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">建议你不要动这张表。</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">Tables_priv</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">每一行宝航了指定用户和表的表级别上的权限，也包括了视图和权限在内。</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">Columms_priv </span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">每一行指定了用户和列的列的级别上的权限。</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">Procs_priv</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">每一行包含了指定用户和存储程序的权限。</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p></div><!--EndFragment-->  <img src ="http://www.cppblog.com/AutomateProgram/aggbug/178780.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-06-14 12:02 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/06/14/178780.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>windows 下生成和解析plist文件(c++ create parser plist)</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/06/05/177664.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Tue, 05 Jun 2012 09:09:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/06/05/177664.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/177664.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/06/05/177664.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/177664.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/177664.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 大师：https://github.com/animetrics/PlistCpp发布了多个平台，生成和解析plist文件，这里只给出windows平台下的应用。下载使用方法如下：read a plist from disk whose root node is adictionary:map&lt;string, boost::any&gt; dict; Plist::readP...&nbsp;&nbsp;<a href='http://www.cppblog.com/AutomateProgram/archive/2012/06/05/177664.html'>阅读全文</a><img src ="http://www.cppblog.com/AutomateProgram/aggbug/177664.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-06-05 17:09 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/06/05/177664.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>kindle(6寸) txt 转pdf(c# 使用iText转换txt为pdf)</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/05/02/173450.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Wed, 02 May 2012 03:47:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/05/02/173450.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/173450.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/05/02/173450.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/173450.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/173450.html</trackback:ping><description><![CDATA[<p><font style="background-color: #cce8cf">网上关于c#有很多关于使用itext转换txt为pdf的教程，最近在使用kindle看书发现txt的字体不够大，在网上找了好多软件要吗不好用要吗要收费，所以决定自己写一个。<br /><br />其实，核心代码没几行：<br /><a href="/Files/AutomateProgram/TxtToPdf--Kindle.rar">exe下载<br /></a></p>
<p>&nbsp;</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;doTXTtoPDFWork()<br /><img id="Codehighlighter1_38_2119_Open_Image" onclick="this.style.display='none'; Codehighlighter1_38_2119_Open_Text.style.display='none'; Codehighlighter1_38_2119_Closed_Image.style.display='inline'; Codehighlighter1_38_2119_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_38_2119_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_38_2119_Closed_Text.style.display='none'; Codehighlighter1_38_2119_Open_Image.style.display='inline'; Codehighlighter1_38_2119_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_38_2119_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_38_2119_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">try</span><span style="color: #000000"><br /><img id="Codehighlighter1_68_1993_Open_Image" onclick="this.style.display='none'; Codehighlighter1_68_1993_Open_Text.style.display='none'; Codehighlighter1_68_1993_Closed_Image.style.display='inline'; Codehighlighter1_68_1993_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_68_1993_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_68_1993_Closed_Text.style.display='none'; Codehighlighter1_68_1993_Open_Image.style.display='inline'; Codehighlighter1_68_1993_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_68_1993_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_68_1993_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iTextSharp.text.Rectangle&nbsp;c6&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;iTextSharp.text.Rectangle(</span><span style="color: #000000">480</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">600</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Document&nbsp;document&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Document(c6);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;pdfSavePath&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;txtPath.Substring(</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;txtPath.Length&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">3</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pdfSavePath&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">pdf</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PdfWriter&nbsp;writer&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;PdfWriter.GetInstance(document,&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;FileStream(pdfSavePath,&nbsp;FileMode.Create));</span><span style="color: #008000">//</span><span style="color: #008000">创建Writer实例</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.Open();<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.AddAuthor(</span><span style="color: #000000">"</span><span style="color: #000000">androidxiamen</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.AddCreationDate();<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.AddCreator("厦门同步网络有限公司");<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.AddKeywords("移动互联网");<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.AddProducer();<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.AddSubject("kindle&nbsp;6&nbsp;寸");<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.AddTitle("明朝那些事");</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BaseFont&nbsp;bfHei&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;BaseFont.CreateFont(</span><span style="color: #000000">@"</span><span style="color: #000000">C:\WINDOWS\Fonts\simhei.ttf</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;BaseFont.IDENTITY_H,&nbsp;BaseFont.NOT_EMBEDDED);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iTextSharp.text.Font&nbsp;font&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;iTextSharp.text.Font(bfHei,&nbsp;</span><span style="color: #000000">20</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">float</span><span style="color: #000000">&nbsp;titleLineHeight&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;45f;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">float</span><span style="color: #000000">&nbsp;normalLineHeight&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;20f;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Paragraph&nbsp;pBlank&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Paragraph(</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;font);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pBlank.Leading&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;normalLineHeight;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StreamReader&nbsp;sr&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;StreamReader(txtPath,&nbsp;GetEncoding(txtPath));<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;line&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">""</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;((line&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;sr.ReadLine())&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1525_1882_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1525_1882_Open_Text.style.display='none'; Codehighlighter1_1525_1882_Closed_Image.style.display='inline'; Codehighlighter1_1525_1882_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1525_1882_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1525_1882_Closed_Text.style.display='none'; Codehighlighter1_1525_1882_Open_Image.style.display='inline'; Codehighlighter1_1525_1882_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1525_1882_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1525_1882_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(line&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">""</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1583_1655_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1583_1655_Open_Text.style.display='none'; Codehighlighter1_1583_1655_Closed_Image.style.display='inline'; Codehighlighter1_1583_1655_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1583_1655_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1583_1655_Closed_Text.style.display='none'; Codehighlighter1_1583_1655_Open_Image.style.display='inline'; Codehighlighter1_1583_1655_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1583_1655_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1583_1655_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.Add(pBlank);</span><span style="color: #008000">//</span><span style="color: #008000">空行</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Chunk&nbsp;chnk4&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Chunk(line,&nbsp;font);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img id="Codehighlighter1_1768_1776_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1768_1776_Open_Text.style.display='none'; Codehighlighter1_1768_1776_Closed_Image.style.display='inline'; Codehighlighter1_1768_1776_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1768_1776_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1768_1776_Closed_Text.style.display='none'; Codehighlighter1_1768_1776_Open_Image.style.display='inline'; Codehighlighter1_1768_1776_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.Add(GetPTxt(</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Chunk[]&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1768_1776_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1768_1776_Open_Text"><span style="color: #000000">{&nbsp;chnk4&nbsp;}</span></span><span style="color: #000000">,&nbsp;normalLineHeight));<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curLine</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UpdateUIPro();<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sr.Close();<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.Close();<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UpdateUIFinish();<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">catch</span><span style="color: #000000"><br /><img id="Codehighlighter1_2025_2095_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2025_2095_Open_Text.style.display='none'; Codehighlighter1_2025_2095_Closed_Image.style.display='inline'; Codehighlighter1_2025_2095_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_2025_2095_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_2025_2095_Closed_Text.style.display='none'; Codehighlighter1_2025_2095_Open_Image.style.display='inline'; Codehighlighter1_2025_2095_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_2025_2095_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_2025_2095_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show(</span><span style="color: #000000">"</span><span style="color: #000000">哦，出现了未知的情况，我已经快挂了！！</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></div>
<p><br /><br /><br /><a href="/Files/AutomateProgram/TxtToPdf.rar">源代码下载<br /><br /><br /></a></font></p><img src ="http://www.cppblog.com/AutomateProgram/aggbug/173450.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-05-02 11:47 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/05/02/173450.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>StreamReader 和文件乱码(转)</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/05/02/173446.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Wed, 02 May 2012 03:22:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/05/02/173446.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/173446.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/05/02/173446.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/173446.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/173446.html</trackback:ping><description><![CDATA[原文地址：<a href="http://www.cnblogs.com/LoveJenny/archive/2012/02/08/2343297.html">http://www.cnblogs.com/LoveJenny/archive/2012/02/08/2343297.html</a><br /><br /><br /><br /><br />获取文章的编码格式:<br /><br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;Encoding&nbsp;GetEncoding(</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;filePath)<br /><img id="Codehighlighter1_60_2478_Open_Image" onclick="this.style.display='none'; Codehighlighter1_60_2478_Open_Text.style.display='none'; Codehighlighter1_60_2478_Closed_Image.style.display='inline'; Codehighlighter1_60_2478_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_60_2478_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_60_2478_Closed_Text.style.display='none'; Codehighlighter1_60_2478_Open_Image.style.display='inline'; Codehighlighter1_60_2478_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_60_2478_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_60_2478_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(filePath&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">)<br /><img id="Codehighlighter1_108_183_Open_Image" onclick="this.style.display='none'; Codehighlighter1_108_183_Open_Text.style.display='none'; Codehighlighter1_108_183_Closed_Image.style.display='inline'; Codehighlighter1_108_183_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_108_183_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_108_183_Closed_Text.style.display='none'; Codehighlighter1_108_183_Open_Image.style.display='inline'; Codehighlighter1_108_183_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_108_183_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_108_183_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">throw</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ArgumentNullException(</span><span style="color: #000000">"</span><span style="color: #000000">filePath</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encoding&nbsp;encoding1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Encoding.Default;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(File.Exists(filePath))<br /><img id="Codehighlighter1_287_2438_Open_Image" onclick="this.style.display='none'; Codehighlighter1_287_2438_Open_Text.style.display='none'; Codehighlighter1_287_2438_Closed_Image.style.display='inline'; Codehighlighter1_287_2438_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_287_2438_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_287_2438_Closed_Text.style.display='none'; Codehighlighter1_287_2438_Open_Image.style.display='inline'; Codehighlighter1_287_2438_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_287_2438_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_287_2438_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">try</span><span style="color: #000000"><br /><img id="Codehighlighter1_325_2194_Open_Image" onclick="this.style.display='none'; Codehighlighter1_325_2194_Open_Text.style.display='none'; Codehighlighter1_325_2194_Closed_Image.style.display='inline'; Codehighlighter1_325_2194_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_325_2194_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_325_2194_Closed_Text.style.display='none'; Codehighlighter1_325_2194_Open_Image.style.display='inline'; Codehighlighter1_325_2194_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_325_2194_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_325_2194_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;(FileStream&nbsp;stream1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;FileStream(filePath,&nbsp;FileMode.Open,&nbsp;FileAccess.Read))<br /><img id="Codehighlighter1_453_2176_Open_Image" onclick="this.style.display='none'; Codehighlighter1_453_2176_Open_Text.style.display='none'; Codehighlighter1_453_2176_Closed_Image.style.display='inline'; Codehighlighter1_453_2176_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_453_2176_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_453_2176_Closed_Text.style.display='none'; Codehighlighter1_453_2176_Open_Image.style.display='inline'; Codehighlighter1_453_2176_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_453_2176_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_453_2176_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(stream1.Length&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_527_2154_Open_Image" onclick="this.style.display='none'; Codehighlighter1_527_2154_Open_Text.style.display='none'; Codehighlighter1_527_2154_Closed_Image.style.display='inline'; Codehighlighter1_527_2154_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_527_2154_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_527_2154_Closed_Text.style.display='none'; Codehighlighter1_527_2154_Open_Image.style.display='inline'; Codehighlighter1_527_2154_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_527_2154_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_527_2154_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;(StreamReader&nbsp;reader1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;StreamReader(stream1,&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">))<br /><img id="Codehighlighter1_648_2128_Open_Image" onclick="this.style.display='none'; Codehighlighter1_648_2128_Open_Text.style.display='none'; Codehighlighter1_648_2128_Closed_Image.style.display='inline'; Codehighlighter1_648_2128_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_648_2128_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_648_2128_Closed_Text.style.display='none'; Codehighlighter1_648_2128_Open_Image.style.display='inline'; Codehighlighter1_648_2128_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_648_2128_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_648_2128_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">[]&nbsp;chArray1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">[</span><span style="color: #000000">1</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader1.Read(chArray1,&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;encoding1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;reader1.CurrentEncoding;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader1.BaseStream.Position&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(encoding1&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;Encoding.UTF8)<br /><img id="Codehighlighter1_1005_2098_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1005_2098_Open_Text.style.display='none'; Codehighlighter1_1005_2098_Closed_Image.style.display='inline'; Codehighlighter1_1005_2098_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1005_2098_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1005_2098_Closed_Text.style.display='none'; Codehighlighter1_1005_2098_Open_Image.style.display='inline'; Codehighlighter1_1005_2098_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1005_2098_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1005_2098_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[]&nbsp;buffer1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;encoding1.GetPreamble();<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(stream1.Length&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;buffer1.Length)<br /><img id="Codehighlighter1_1195_1877_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1195_1877_Open_Text.style.display='none'; Codehighlighter1_1195_1877_Closed_Image.style.display='inline'; Codehighlighter1_1195_1877_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1195_1877_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1195_1877_Closed_Text.style.display='none'; Codehighlighter1_1195_1877_Open_Image.style.display='inline'; Codehighlighter1_1195_1877_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1195_1877_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1195_1877_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[]&nbsp;buffer2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[buffer1.Length];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream1.Read(buffer2,&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;buffer2.Length);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;num1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;num1&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;buffer2.Length;&nbsp;num1</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1492_1839_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1492_1839_Open_Text.style.display='none'; Codehighlighter1_1492_1839_Closed_Image.style.display='inline'; Codehighlighter1_1492_1839_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1492_1839_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1492_1839_Closed_Text.style.display='none'; Codehighlighter1_1492_1839_Open_Image.style.display='inline'; Codehighlighter1_1492_1839_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1492_1839_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1492_1839_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(buffer2[num1]&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;buffer1[num1])<br /><img id="Codehighlighter1_1618_1797_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1618_1797_Open_Text.style.display='none'; Codehighlighter1_1618_1797_Closed_Image.style.display='inline'; Codehighlighter1_1618_1797_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1618_1797_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1618_1797_Closed_Text.style.display='none'; Codehighlighter1_1618_1797_Open_Image.style.display='inline'; Codehighlighter1_1618_1797_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1618_1797_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1618_1797_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;encoding1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Encoding.Default;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img id="Codehighlighter1_1956_2064_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1956_2064_Open_Text.style.display='none'; Codehighlighter1_1956_2064_Closed_Image.style.display='inline'; Codehighlighter1_1956_2064_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1956_2064_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1956_2064_Closed_Text.style.display='none'; Codehighlighter1_1956_2064_Open_Image.style.display='inline'; Codehighlighter1_1956_2064_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1956_2064_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1956_2064_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;encoding1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Encoding.Default;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">catch</span><span style="color: #000000">&nbsp;(Exception&nbsp;exception1)<br /><img id="Codehighlighter1_2257_2302_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2257_2302_Open_Text.style.display='none'; Codehighlighter1_2257_2302_Closed_Image.style.display='inline'; Codehighlighter1_2257_2302_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_2257_2302_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_2257_2302_Closed_Text.style.display='none'; Codehighlighter1_2257_2302_Open_Image.style.display='inline'; Codehighlighter1_2257_2302_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_2257_2302_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_2257_2302_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">throw</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(encoding1&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">)<br /><img id="Codehighlighter1_2359_2424_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2359_2424_Open_Text.style.display='none'; Codehighlighter1_2359_2424_Closed_Image.style.display='inline'; Codehighlighter1_2359_2424_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_2359_2424_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_2359_2424_Closed_Text.style.display='none'; Codehighlighter1_2359_2424_Open_Image.style.display='inline'; Codehighlighter1_2359_2424_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_2359_2424_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_2359_2424_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;encoding1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Encoding.UTF8;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;encoding1;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><br /><br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Main()<br /><img id="Codehighlighter1_26_648_Open_Image" onclick="this.style.display='none'; Codehighlighter1_26_648_Open_Text.style.display='none'; Codehighlighter1_26_648_Closed_Image.style.display='inline'; Codehighlighter1_26_648_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_26_648_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_26_648_Closed_Text.style.display='none'; Codehighlighter1_26_648_Open_Image.style.display='inline'; Codehighlighter1_26_648_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_26_648_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_26_648_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;List</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;lstFilePath&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;List</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000">()<br /><img id="Codehighlighter1_82_204_Open_Image" onclick="this.style.display='none'; Codehighlighter1_82_204_Open_Text.style.display='none'; Codehighlighter1_82_204_Closed_Image.style.display='inline'; Codehighlighter1_82_204_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_82_204_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_82_204_Closed_Text.style.display='none'; Codehighlighter1_82_204_Open_Image.style.display='inline'; Codehighlighter1_82_204_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_82_204_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_82_204_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">H:\\TestText\\ansi.txt</span><span style="color: #000000">"</span><span style="color: #000000">,<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">H:\\TestText\\unicode.txt</span><span style="color: #000000">"</span><span style="color: #000000">,<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">H:\\TestText\\utf8.txt</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">foreach</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;filePath&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;lstFilePath)<br /><img id="Codehighlighter1_258_646_Open_Image" onclick="this.style.display='none'; Codehighlighter1_258_646_Open_Text.style.display='none'; Codehighlighter1_258_646_Closed_Image.style.display='inline'; Codehighlighter1_258_646_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_258_646_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_258_646_Closed_Text.style.display='none'; Codehighlighter1_258_646_Open_Image.style.display='inline'; Codehighlighter1_258_646_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_258_646_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_258_646_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;(StreamReader&nbsp;reader&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;StreamReader(filePath,&nbsp;GetEncoding(filePath)))<br /><img id="Codehighlighter1_356_640_Open_Image" onclick="this.style.display='none'; Codehighlighter1_356_640_Open_Text.style.display='none'; Codehighlighter1_356_640_Closed_Image.style.display='inline'; Codehighlighter1_356_640_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_356_640_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_356_640_Closed_Text.style.display='none'; Codehighlighter1_356_640_Open_Image.style.display='inline'; Codehighlighter1_356_640_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_356_640_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_356_640_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(</span><span style="color: #000000">"</span><span style="color: #000000">读取文件</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;filePath);<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(reader.ReadToEnd());<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(</span><span style="color: #000000">"</span><span style="color: #000000">当前编码：</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;reader.CurrentEncoding.EncodingName);<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(</span><span style="color: #000000">"</span><span style="color: #000000">************************************************************</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span></div><br /><br /><br /><br /><img src ="http://www.cppblog.com/AutomateProgram/aggbug/173446.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-05-02 11:22 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/05/02/173446.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql在windows下的编译和调试(vs2008)</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/04/15/171449.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Sun, 15 Apr 2012 02:37:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/04/15/171449.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/171449.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/04/15/171449.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/171449.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/171449.html</trackback:ping><description><![CDATA[<div style="layout-grid:  15.6pt none" class="Section0">
<p style="text-align: center; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 24pt; mso-spacerun: 'yes'">mysql<font face="宋体"><span style="font-size: 24pt">在</span></font><font face="Times New Roman"><span style="font-size: 24pt">windows</span></font><font face="宋体"><span style="font-size: 24pt">下的编译和调试</span></font></span><span style="font-family: '宋体'; font-size: 24pt; mso-spacerun: 'yes'">(vs2008)</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 18pt; mso-spacerun: 'yes'"><strong>环境准备<br /></strong><br /></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">1.下载<font face="Times New Roman">mysql</font><font face="宋体">源代码：</font></span><span><a href="http://dev.mysql.com/downloads/mysql/#downloads"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 10.5pt; text-decoration: underline; mso-spacerun: 'yes'">http://dev.mysql.com/downloads/mysql/#downloads</span></a></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">这里最新的版本是</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">5.5.23</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">如下：<br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: justify; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: 'Arial';background: rgb(255,255,255); color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'; mso-shading: rgb(255,255,255)"><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/automateprogram/1.JPG" width="558" height="301" /><br />2.安装<font face="Arial">CMake</font></span><span style="font-style: normal; font-family: 'Arial';background: rgb(255,255,255); color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'; mso-shading: rgb(255,255,255)"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: 'Arial';background: rgb(255,255,255); color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'; mso-shading: rgb(255,255,255)">下载地址：</span><span><a href="http://www.cmake.org/cmake/resources/software.html"><span style="font-style: normal; font-family: 'Arial';background: rgb(255,255,255); color: rgb(0,0,255); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'; mso-shading: rgb(255,255,255)">http://www.cmake.org/cmake/resources/software.html</span></a></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">编译器<font face="Times New Roman">,&nbsp;</font><font face="宋体">记得</font><font face="Times New Roman">Linux</font><font face="宋体">下的&nbsp;</font><font face="Times New Roman">make</font><font face="宋体">么，&nbsp;没错这个就是他哥，进阶版。</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;<br /><br />3.</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">安装<font face="Times New Roman">GNUWin32&nbsp;Bison</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: 'Arial';background: rgb(255,255,255); color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'; mso-shading: rgb(255,255,255)">下载地址为：</span><span><a href="http://gnuwin32.sourceforge.net/packages/bison.htm"><span style="font-style: normal; font-family: 'Arial';background: rgb(255,255,255); color: rgb(0,0,255); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'; mso-shading: rgb(255,255,255)">http://gnuwin32.sourceforge.net/packages/bison.htm</span></a></span><span style="font-style: normal; font-family: 'Arial';background: rgb(255,255,255); color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'; mso-shading: rgb(255,255,255)">，</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;同样安装路径最好为英文，并且不要有空格。安装后将<font face="Times New Roman">bin</font><font face="宋体">路径添加到系统环境变量。<br /></font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: '宋体'; font-size: 18pt; mso-spacerun: 'yes'">编译</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">进入<font face="Times New Roman">mysql</font><font face="宋体">的根目录下，输入</font><font face="Times New Roman">cmake&nbsp;.&nbsp;-G&nbsp;"Visual&nbsp;Studio&nbsp;9&nbsp;2008"</font><font face="宋体">，正常的话会有</font><font face="Times New Roman">XXX&nbsp;done</font><font face="宋体">什么的</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;<br /><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">成功的话会有<font face="Times New Roman">MySQL.sln</font><font face="宋体">和一大堆</font><font face="Times New Roman">.vcproj</font><font face="宋体">文件，打开</font><font face="Times New Roman">MySQL.sln</font><font face="宋体">，就可以看到整个解决方案<br /><br /></font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">在编译之前，建议打开<font face="Times New Roman">sql/sql_locale.cc</font><font face="宋体">文件，将其用</font><font face="Times New Roman">utf-8</font><font face="宋体">格式再保存一遍，不然编译过程当中会有大量错误。</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;<br /><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">应该就可以编译成功。<br /><br /></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">到</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">sql/debug&nbsp;<font face="宋体">下执行<br /></font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">mysqld-debug&nbsp;--debug&nbsp;&#8211;-standalone</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;<br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><br />应该会出现错误，提示你</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">mysqld.cc<font face="宋体">中的某个断言有问题，把那段注解掉重新编译。<br /><br /></font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">编译完以后继续</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">mysqld-debug&nbsp;--debug&nbsp;&#8211;-standalone<br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><br />发现还是起不来</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">mysqld<font face="宋体">的进程。</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">查看<font face="Times New Roman">log</font><font face="宋体">文件</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">mysqld.exe:&nbsp;Table&nbsp;'mysql.plugin'&nbsp;doesn't&nbsp;exist</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">120414&nbsp;11:34:08&nbsp;[ERROR]&nbsp;Can't&nbsp;open&nbsp;the&nbsp;mysql.plugin&nbsp;table.&nbsp;Please&nbsp;run&nbsp;mysql_upgrade&nbsp;to&nbsp;create&nbsp;it.</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">120414&nbsp;11:34:08&nbsp;InnoDB:&nbsp;!!!!!!!!&nbsp;UNIV_DEBUG&nbsp;switched&nbsp;on&nbsp;!!!!!!!!!</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">120414&nbsp;11:34:08&nbsp;InnoDB:&nbsp;The&nbsp;InnoDB&nbsp;memory&nbsp;heap&nbsp;is&nbsp;disabled</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">120414&nbsp;11:34:08&nbsp;InnoDB:&nbsp;Mutexes&nbsp;and&nbsp;rw_locks&nbsp;use&nbsp;Windows&nbsp;interlocked&nbsp;functions</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">120414&nbsp;11:34:08&nbsp;InnoDB:&nbsp;Compressed&nbsp;tables&nbsp;use&nbsp;zlib&nbsp;1.2.3</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">120414&nbsp;11:34:08&nbsp;InnoDB:&nbsp;Initializing&nbsp;buffer&nbsp;pool,&nbsp;size&nbsp;=&nbsp;128.0M</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">120414&nbsp;11:34:08&nbsp;InnoDB:&nbsp;Completed&nbsp;initialization&nbsp;of&nbsp;buffer&nbsp;pool</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">120414&nbsp;11:34:08&nbsp;InnoDB:&nbsp;highest&nbsp;supported&nbsp;file&nbsp;format&nbsp;is&nbsp;Barracuda.</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">InnoDB:&nbsp;The&nbsp;log&nbsp;sequence&nbsp;number&nbsp;in&nbsp;ibdata&nbsp;files&nbsp;does&nbsp;not&nbsp;match</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">InnoDB:&nbsp;the&nbsp;log&nbsp;sequence&nbsp;number&nbsp;in&nbsp;the&nbsp;ib_logfiles!</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">120414&nbsp;11:34:08&nbsp;&nbsp;InnoDB:&nbsp;Database&nbsp;was&nbsp;not&nbsp;shut&nbsp;down&nbsp;normally!</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">InnoDB:&nbsp;Starting&nbsp;crash&nbsp;recovery.</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">InnoDB:&nbsp;Reading&nbsp;tablespace&nbsp;information&nbsp;from&nbsp;the&nbsp;.ibd&nbsp;files...</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">InnoDB:&nbsp;Restoring&nbsp;possible&nbsp;half-written&nbsp;data&nbsp;pages&nbsp;from&nbsp;the&nbsp;doublewrite</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">InnoDB:&nbsp;buffer...</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">120414&nbsp;11:34:09&nbsp;&nbsp;InnoDB:&nbsp;Waiting&nbsp;for&nbsp;the&nbsp;background&nbsp;threads&nbsp;to&nbsp;start</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">120414&nbsp;11:34:10&nbsp;InnoDB:&nbsp;1.1.8&nbsp;started;&nbsp;log&nbsp;sequence&nbsp;number&nbsp;1595675</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">120414&nbsp;11:34:10&nbsp;[ERROR]&nbsp;Fatal&nbsp;error:&nbsp;Can't&nbsp;open&nbsp;and&nbsp;lock&nbsp;privilege&nbsp;tables:&nbsp;Table&nbsp;'mysql.host'&nbsp;doesn't&nbsp;exist<br /><br /></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">意思是<font face="Times New Roman">mysl</font><font face="宋体">下的表没有建立，很奇怪这个不知道是什么原因，我是到别的地方拷贝了</font><font face="Times New Roman">mysql</font><font face="宋体">下的文件放到</font><font face="Times New Roman">sql/data/mysql</font><font face="宋体">下<br /><br /><br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/automateprogram/2.JPG" width="557" height="195" /></font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p><br />
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><br />如果没有什么意外</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">执行</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">mysqld-debug&nbsp;--debug&nbsp;&#8211;-standalone</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">就可以建立启动</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">mysqld<font face="宋体">进程了。</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">使用<font face="Times New Roman">vs2008</font><font face="宋体">进行调试</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">测试<font face="Times New Roman">---</font><font face="宋体">》附加到进程<br /></font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/automateprogram/3.JPG" width="558" height="359" /><br /><br />选择<font face="Times New Roman">mysqld</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">定位到</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">\client\Debug<font face="宋体">，执行命令</font><font face="Times New Roman">&#8220;mysql&nbsp;-u&nbsp;root&nbsp;-p&#8221;,</font><font face="宋体">进入</font><font face="Times New Roman">mysql</font><font face="宋体">客户端，</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">在这边下断点：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/automateprogram/4.JPG" width="558" height="165" /><br />在</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">mysql&nbsp;</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">客户端下：</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;show&nbsp;authors;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/automateprogram/5.JPG" width="183" height="28" /><br />就可以进入断点进行调试：<br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/automateprogram/6.JPG" width="547" height="157" /><br /><br /></span>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p>参考地址：<br /><a href="http://qa.taobao.com/?p=9699">http://qa.taobao.com/?p=9699</a><br /><a href="http://likydba.sinaapp.com/?p=578">http://likydba.sinaapp.com/?p=578</a><br /><a href="http://www.cnblogs.com/yuemenglong/archive/2011/06/14/2080262.html">http://www.cnblogs.com/yuemenglong/archive/2011/06/14/2080262.html</a><br /></o:p></span>
<p>&nbsp;</p></div><!--EndFragment--> <img src ="http://www.cppblog.com/AutomateProgram/aggbug/171449.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-04-15 10:37 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/04/15/171449.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Apache 日志过滤功能(转) 日志屏蔽，减少日志量。</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/02/14/165570.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Tue, 14 Feb 2012 07:50:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/02/14/165570.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/165570.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/02/14/165570.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/165570.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/165570.html</trackback:ping><description><![CDATA[原文地址：<a href="http://blog.sina.com.cn/s/blog_551393a90100p4tx.html">http://blog.sina.com.cn/s/blog_551393a90100p4tx.html</a><br /><br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="text-align: left; line-height: 21px; font-family: simsun; color: rgb(70,70,70); font-size: 14px" class="Apple-style-span">LoadModule setenvif_module modules/mod_setenvif.so<br />SetEnvIf Request_URI "^/enterprise/main\.php.*$" dontlog<br />CustomLog d:/logs/%Y%m%d.log combined env=!dontlog<br />参考资料：<br /><a style="color: rgb(118,95,71); text-decoration: none" href="http://www.unibetter.com/deerchao/zhengzhe-biaodashi-jiaocheng-se.htm" target="_blank">正则表达式30分钟入门教程</a><br /><a style="color: rgb(118,95,71); text-decoration: none" href="http://man.chinaunix.net/newsoft/Apache2.2_chinese_manual/env.html" target="_blank">Apache的环境变量</a><br />转载内容：<br />为了提高系统的访问速度，需要减少Apache日志操作，下面是Apache日志过滤的参考样例：<br /># filter the localhost visit<br />SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog<br /># filter some special directories<br />SetEnvIf Request_URI "^/system/.*$" dontlog<br />SetEnvIf Request_URI "^/export/.*$" dontlog<br />SetEnvIf Request_URI "^/resources/.*$" dontlog<br /># filter the intranet visit<br />SetEnvIf Remote_Addr "211\.167\.51\.199" dontlog<br /># filter the google bot<br />SetEnvIf Remote_Addr "66\.249\.6[4-9]\.[0-9]+" dontlog<br />SetEnvIf Remote_Addr "66\.249\.[7-8][0-9]\.[0-9]+" dontlog<br />SetEnvIf Remote_Addr "66\.249\.9[0-5]\.[0-9]+" dontlog<br /># filter the microsoft bot: 65.52.0.0 - 65.55.255.255<br />SetEnvIf Remote_Addr "65\.5[2-5]\.[0-9]+\.[0-9]+" dontlog<br />CustomLog logs/access_log common env=!dontlog</span></span><img src ="http://www.cppblog.com/AutomateProgram/aggbug/165570.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-02-14 15:50 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/02/14/165570.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在windows中编译sphinx1.10beta--coreseek(类似)(翻译)</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/02/13/165470.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Mon, 13 Feb 2012 03:50:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/02/13/165470.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/165470.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/02/13/165470.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/165470.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/165470.html</trackback:ping><description><![CDATA[<p>在windows中编译sphinx1.10beta <br /><br /></p>
<p>原文地址：<a href="http://blog.aulin.no/compiling-sphinx-110beta-on-windows">http://blog.aulin.no/compiling-sphinx-110beta-on-windows</a><br /><br />下面是引导大家如何在windows上编译sphinx 1.10beta</p>
<p>1. 下载sphinx源码(<a href="http://sphinxsearch.com/downloads/sphinx-1.10-beta.tar.gz">http://sphinxsearch.com/downloads/sphinx-1.10-beta.tar.gz</a>)<br />&nbsp;&nbsp;&nbsp; 注：最新版本在：<a href="http://sphinxsearch.com/downloads/archive/">http://sphinxsearch.com/downloads/archive/</a> 下<br />&nbsp;<br />2. 因为sphinx使用到MySQL, LibExpat and LibIConv,因此在编译之前需要配置这些库：<br />&nbsp;&nbsp; 下载MySQL的开发环境<a href="http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.52-win32.msi/from/http://mysql.borsen.dk/">http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.52-win32.msi/from/http://mysql.borsen.dk/</a>，安装开发组件<br />&nbsp;&nbsp; 下载LibExpat(<a href="http://garr.dl.sourceforge.net/project/expat/expat_win32/2.0.1/expat-win32bin-2.0.1.exe">http://garr.dl.sourceforge.net/project/expat/expat_win32/2.0.1/expat-win32bin-2.0.1.exe</a>)<br />&nbsp;&nbsp; 下载LibIConv (<a href="http://netcologne.dl.sourceforge.net/project/gnuwin32/libiconv/1.9.2-1/libiconv-1.9.2-1.exe">http://netcologne.dl.sourceforge.net/project/gnuwin32/libiconv/1.9.2-1/libiconv-1.9.2-1.exe</a>)<br />&nbsp;&nbsp; <br />3. 在shpinx.h中可以配置和移除sphinx需要的组件,如可以移除对PostgreSQL 的支持</p>
<p>4. 在visual studiao 08 中打开 Sphinx08.sln </p>
<p>5. 添加mysql 的include路径(C:\Program Files (x86)\MySQL\MySQL Server 5.1\include) to all projects (右击 - Properties - Configuration Properties - C/C++ - General - Additional Include Directories).</p>
<p>6. 添加mysql的lib路径(C:\Program Files (x86)\MySQL\MySQL Server 5.1\lib\opt) to all projects excluding "libsphinx" (右击 - Properties - Configuration Properties - Linker - General - Additional Library Directories)</p>
<p>7. 在除了libsphinx的所有工程中，添加LibExpat的路径(C:\Program Files (x86)\Expat 2.0.1\Bin)(右击 - Properties - Configuration Properties - Linker - General - Additional Library Directories)</p>
<p>8. 在除了libsphinx的所有工程中，添加LibIConv 的路径(C:\Program Files (x86)\GnuWin32\lib)(右击 - Properties - Configuration Properties - Linker - General - Additional Library Directories)</p>
<p>9. 编译Build! (F6)</p><img src ="http://www.cppblog.com/AutomateProgram/aggbug/165470.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-02-13 11:50 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/02/13/165470.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Nginx模块开发入门</title><link>http://www.cppblog.com/AutomateProgram/archive/2012/01/05/163629.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Thu, 05 Jan 2012 07:12:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2012/01/05/163629.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/163629.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2012/01/05/163629.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/163629.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/163629.html</trackback:ping><description><![CDATA[<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">到<font face="Times New Roman">nginx.org</font><font face="宋体">上，下载对应的</font><font face="Times New Roman">nginx</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">测试<font face="Times New Roman">nginx</font><font face="宋体">是否可以安装<br /><br /></font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">./configure<br /><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">如果出现<br /><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">./configure:&nbsp;error:&nbsp;the&nbsp;HTTP&nbsp;rewrite&nbsp;module&nbsp;requires&nbsp;the&nbsp;PCRE&nbsp;library.</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">You&nbsp;can&nbsp;either&nbsp;disable&nbsp;the&nbsp;module&nbsp;by&nbsp;using&nbsp;--without-http_rewrite_module</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">option,&nbsp;or&nbsp;install&nbsp;the&nbsp;PCRE&nbsp;library&nbsp;into&nbsp;the&nbsp;system,&nbsp;or&nbsp;build&nbsp;the&nbsp;PCRE&nbsp;library</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">statically&nbsp;from&nbsp;the&nbsp;source&nbsp;with&nbsp;nginx&nbsp;by&nbsp;using&nbsp;--with-pcre=&lt;path&gt;&nbsp;option.<br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br />执行<font face="Times New Roman">:<br /><br /></font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">sudo&nbsp;aptitude&nbsp;install&nbsp;libpcre3-dev<br /><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">如果还缺少其他包，继续安装。</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">直到</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">./configure<font face="宋体">没有错误<br /><br /></font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">sudo&nbsp;make</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">sudo&nbsp;make&nbsp;install<br /><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">启动<font face="Times New Roman">nginx</font><font face="宋体">，</font><font face="Times New Roman">sudo&nbsp;/usr/local/nginx/sbin/nginx</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">另外启动一个命名窗口：<br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br />安装<font face="Times New Roman">curl<br /><br /></font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">sudo&nbsp;apt-get&nbsp;install&nbsp;curl</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">执行<font face="Times New Roman">curl&nbsp;-i&nbsp;http://localhost<br /><br /></font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">或者用浏览器</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">访问</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">http://localhost/</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">就可以看到<font face="Times New Roman">welcome&nbsp;to&nbsp;nginx</font><font face="宋体">的欢迎字幕&nbsp;表示安装成功</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p><!--EndFragment--><br /><br />
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">加载<font face="Times New Roman">Empty&nbsp;Gif</font><font face="宋体">插件</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p><!--EndFragment--><br />
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">在</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">http://www.evanmiller.org/</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">网站中</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">有篇文章</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">http://www.evanmiller.org/nginx-modules-guide.html</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">介绍了</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">nginx<font face="宋体">的开发，比较全面，但较老，如果要详细了解</font><font face="Times New Roman">nginx</font><font face="宋体">的模块开发，还得熟悉</font><font face="Times New Roman">nginx</font><font face="宋体">的源代码。</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: 'Arial'; color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">Empty&nbsp;Gif</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">较为简单，主要的功能就是浏览器访问某个地址，返回一个</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">gif<font face="宋体">图片。</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p><!--EndFragment--><br />
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">如何编译：</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">Empty&nbsp;Gif</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">使用到了图片库，先安装<br /><br /></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '宋体'; font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">sudo&nbsp;apt-get&nbsp;install&nbsp;libmagickwand-dev</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;<br /><br /></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p><a href="/Files/AutomateProgram/evanmiller-nginx_circle_gif-f7b6b5c.zip"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">下载</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">Empty&nbsp;Gif</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">代码</span></a><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /><br /></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">安装</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">nginx模块的一般步骤如下：</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: '微软雅黑'; color: rgb(0,0,0); font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">1、</span><span style="font-style: normal; font-family: '微软雅黑'; color: rgb(0,0,0); font-size: 9.5pt; font-weight: normal; mso-spacerun: 'yes'">编写模块config文件，这个文件需要放在和模块源代码文件放在同一目录下。文件内容如下：</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">ngx_addon_name=<font face="宋体">模块完整名称</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">HTTP_MODULES="$HTTP_MODULES&nbsp;<font face="宋体">模块完整名称</font><font face="Times New Roman">"</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">NGX_ADDON_SRCS="$NGX_ADDON_SRCS&nbsp;$ngx_addon_dir/<font face="宋体">源代码文件名</font><font face="Times New Roman">"</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">编写</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">源代码</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">文件，放在同一个目录下<br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><br />2、</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">进入<font face="Times New Roman">Nginx</font><font face="宋体">源代码，使用命令编译安装<br /></font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><br />&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">./configure&nbsp;--prefix=<font face="宋体">安装目录&nbsp;</font><font face="Times New Roman">--add-module=</font><font face="宋体">模块源代码文件目录</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">--with-debug</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">make</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">sudo&nbsp;make&nbsp;install</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;<br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><br />3、</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">修改<font face="Times New Roman">nginx</font><font face="宋体">的配置文件<br /></font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt; margin-left: 42pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br />location&nbsp;/circles&nbsp;{</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt; margin-left: 42pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;circle_gif;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt; margin-left: 42pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /><br /></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">4<font face="宋体">、启动</font><font face="Times New Roman">nginx<br /><br /></font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">sudo&nbsp;&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">/usr/local/nginx/sbin/nginx&nbsp;-c&nbsp;/usr/local/nginx/conf/nginx.conf</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;<br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><br />在浏览器中输入</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span><a href="http://192.168.239.132/circles/ffffff/000000/20.gif"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 10.5pt; text-decoration: underline; mso-spacerun: 'yes'">http://</span><span style="font-family: '宋体'; color: rgb(0,0,255); font-size: 10.5pt; text-decoration: underline; mso-spacerun: 'yes'">localhost</span><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 10.5pt; text-decoration: underline; mso-spacerun: 'yes'">/circles/ffffff/000000/20.gif</span></a></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;<br /><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">就可以看到</span></p><!--EndFragment--><br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/automateprogram/123.JPG" /><br /><br /><br />
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">其中</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">url<font face="宋体">的格式如下：<br /><br /></font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">/circles/ffffff/000000/20.gif</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">/circles/&lt;background&nbsp;color&gt;/&lt;foreground&nbsp;color&gt;/&lt;size&gt;.gif<br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><br />模块是如何注册</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-style: normal; font-family: 'Arial'; color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">在</span><span><a href="http://nginx.net/"><span style="font-style: normal; font-family: 'Arial'; color: rgb(0,0,255); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">nginx</span></a></span><span style="font-style: normal; font-family: 'Arial'; color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">代码的<font face="Arial">auto</font><font face="宋体">目录中，有一个名为</font><font face="Arial">sources</font><font face="宋体">的文件，根据编译选项（</font><font face="Arial">configure</font><font face="宋体">的参数）的不同，</font><font face="Arial">m4</font><font face="宋体">宏变量</font><font face="Arial">HTTP_MODULES</font><font face="宋体">的值会发生变化：</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Arial'; color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">如果指定了使用<font face="Arial">empty&nbsp;gif</font><font face="宋体">模块（默认就是使用了），则最终</font><font face="Arial">m4</font><font face="宋体">宏变量</font><font face="Arial">HTTP_MODULES</font><font face="宋体">的值可能如下：</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Arial'; color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'"><br />HTTP_MODULES="ngx_http_module&nbsp;/</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Arial'; color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx_http_core_module&nbsp;/</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Arial'; color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx_http_log_module&nbsp;/</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Arial'; color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx_http_upstream_module&nbsp;/</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Arial'; color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx_http_empty_gif_module&nbsp;"</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><br /></span><span style="font-style: normal; font-family: 'Arial'; color: rgb(51,51,51); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">注意：这里的<font face="Arial">ngx_http_empty_gif_module</font><font face="宋体">字符串对应了</font><font face="Arial">ngx_http_empty_gif_module.c</font><font face="宋体">文件中的</font><font face="Arial">Module</font><font face="宋体">主结构变量名。</font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;<br /><br /><br /></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">参考文章：</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span><a href="http://www.evanmiller.org/"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 10.5pt; text-decoration: underline; mso-spacerun: 'yes'">http://www.evanmiller.org/</span></a></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span><a href="http://www.evanmiller.org/nginx-modules-guide.html"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 10.5pt; text-decoration: underline; mso-spacerun: 'yes'">http://www.evanmiller.org/nginx-modules-guide.html</span></a></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span><a href="http://www.162cm.com/p/ngx_ext.html"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 10.5pt; text-decoration: underline; mso-spacerun: 'yes'">http://www.162cm.com/p/ngx_ext.html</span></a></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span><a href="http://www.codinglabs.org/html/intro-of-nginx-module-development.html"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 10.5pt; text-decoration: underline; mso-spacerun: 'yes'">http://www.codinglabs.org/html/intro-of-nginx-module-development.html</span></a></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span><a href="http://blog.csdn.net/conezxy/article/details/1869130"><span style="font-family: 'Times New Roman'; color: rgb(0,0,255); font-size: 10.5pt; text-decoration: underline; mso-spacerun: 'yes'">http://blog.csdn.net/conezxy/article/details/1869130</span></a></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;<br /><a href="http://ri0day.blogbus.com/logs/61820056.html">http://ri0day.blogbus.com/logs/61820056.html</a><br /><br /></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">在</span><span><a href="http://wiki.nginx.org/3rdPartyModules"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">http://wiki.nginx.org/3rdPartyModules</span></a></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">中有很多关于第三方模块的开发，国人</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">agentzh</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">在这方面做了大量的工作。</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p><!--EndFragment--><br /><br /><br /><img src ="http://www.cppblog.com/AutomateProgram/aggbug/163629.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2012-01-05 15:12 <a href="http://www.cppblog.com/AutomateProgram/archive/2012/01/05/163629.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>stl 中 map入门和使用方法简要说明</title><link>http://www.cppblog.com/AutomateProgram/archive/2011/09/23/156657.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Fri, 23 Sep 2011 15:02:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2011/09/23/156657.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/156657.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2011/09/23/156657.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/156657.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/156657.html</trackback:ping><description><![CDATA[<span style="line-height: 20px; widows: 2; text-transform: none; background-color: rgb(255,255,255); font-variant: normal; font-style: normal; text-indent: 0px; font-family: verdana, Arial, helvetica, sans-seriff; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(75,75,75); font-size: 13px; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"> 
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">原文地址：<a href="http://www.cnblogs.com/TianFang/archive/2006/12/30/607859.html">http://www.cnblogs.com/TianFang/archive/2006/12/30/607859.html</a><br />1。目录</span></p>
<ol style="box-sizing: border-box; margin-left: 2em"><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">map简介</span></li><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">map的功能</span></li><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">使用map</span></li><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">在map中插入元素</span></li><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">查找并获取map中的元素</span></li><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">从map中删除元素</span></li></ol>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">2。map简介</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">map是一类</span><span style="box-sizing: border-box; color: red">关联式容器</span><span style="color: red">。它的特点是</span><span style="box-sizing: border-box; color: red">增加和删除节点对迭代器的影响很小</span><span style="color: red">，除了那个操作节点，对其他的节点都没有什么影响。对于迭代器来说，可以修改实值，而不能修改key。</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">3。map的功能</span></p>
<ol style="box-sizing: border-box; margin-left: 2em"><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">自动建立Key － value的对应。key 和 value可以是任意你需要的类型。</span></li><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">根据key值快速查找记录，查找的复杂度基本是Log(N)，如果有1000个记录，最多查找10次，1,000,000个记录，最多查找20次。</span></li><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">快速插入Key - Value 记录。</span></li><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">快速删除记录</span></li><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">根据Key 修改value记录。</span></li><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">遍历所有记录。</span></li></ol>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">4。使用map</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">使用map得包含map类所在的头文件</span><br style="box-sizing: border-box" /><span style="color: red">#include &lt;map&gt; //注意，STL头文件没有扩展名.h</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">map对象是模板类，需要关键字和存储对象两个模板参数：</span><br style="box-sizing: border-box" /><span style="color: red">std:map&lt;int, string&gt; personnel;</span><br style="box-sizing: border-box" /><span style="color: red">这样就定义了一个用int作为索引,并拥有相关联的指向string的指针.</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">为了使用方便，可以对模板类进行一下类型定义，</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px 11pt"><span style="color: red">typedef map&lt;int, CString&gt; UDT_MAP_INT_CSTRING;</span><span class="Apple-converted-space">&nbsp;</span><br style="box-sizing: border-box" /><span style="color: red">UDT_MAP_INT_CSTRING enumMap;</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">5。在map中插入元素</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">改变map中的条目非常简单，因为map类已经对[]操作符进行了重载</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px 11pt"><span style="color: red">enumMap[1] = "One";</span><br style="box-sizing: border-box" /><span style="color: red">enumMap[2] = "Two";</span><br style="box-sizing: border-box" /><span style="color: red">.....</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">这样非常直观，但存在一个性能的问题。</span><span style="box-sizing: border-box; color: red">插入2时,先在enumMap中查找主键为2的项，没发现，然后将一个新的对象插入enumMap，键是2，值是一个空字符串，插入完成后，将字符串赋为"Two"</span><span style="color: red">; 该方法会将每个值都赋为缺省值，然后再赋为显示的值，如果元素是类对象，则开销比较大。我们可以用以下方法来避免开销：</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px 11pt"><span style="color: red">enumMap.</span><span style="box-sizing: border-box; color: red">insert</span><span style="color: red">(map&lt;int, CString&gt; :: value_type(2, "Two"))</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">6。查找并获取map中的元素</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">下标操作符给出了获得一个值的最简单方法：</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px 11pt"><span style="color: red">CString tmp = enumMap[2];</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">但是,</span><span style="box-sizing: border-box; color: red">只有当map中有这个键的实例时才对</span><span style="color: red">，否则会自动插</span><span style="box-sizing: border-box; color: red">入一个实例，值为初始化值</span><span style="color: red">。</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">我们可以使用Find()和Count()方法来发现一个键是否存在。</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">查找map中是否包含某个关键字条目用</span><span style="box-sizing: border-box; color: red">find()</span><span style="color: red">方法，传入的参数是要查找的key，在这里需要提到的是begin()和end()两个成员，分别代表map对象中第一个条目和最后一个条目，这两个数据的类型是iterator.</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px 11pt"><span style="color: red">int nFindKey = 2;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//要查找的Key</span><br style="box-sizing: border-box" /><span style="color: red">//定义一个条目变量(实际是指针)</span><br style="box-sizing: border-box" /><span style="color: red">UDT_MAP_INT_CSTRING::iterator it= enumMap.find(nFindKey);&nbsp;</span><br style="box-sizing: border-box" /><span style="color: red">if(it == enumMap.end()) {</span><br style="box-sizing: border-box" /><span style="color: red">&nbsp;&nbsp;&nbsp;&nbsp;//没找到</span><br style="box-sizing: border-box" /><span style="color: red">}</span><br style="box-sizing: border-box" /><span style="color: red">else {</span><br style="box-sizing: border-box" /><span style="color: red">&nbsp;&nbsp;&nbsp;&nbsp;//找到</span><br style="box-sizing: border-box" /><span style="color: red">}</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">通过map对象的方法获取的iterator数据类型是一个std::pair对象，包括两个数据 iterator-&gt;first 和 iterator-&gt;second 分别代表关键字和存储的数据</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">7。从map中删除元素</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">移除某个map中某个条目用</span><span style="box-sizing: border-box; color: red">erase()</span></p>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="color: red">该成员方法的定义如下</span></p>
<ol style="box-sizing: border-box; margin-left: 2em"><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">iterator erase(iterator it); //通过一个条目对象删除</span></li><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">iterator erase(iterator first, iterator last);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//删除一个范围</span></li><li style="box-sizing: border-box; list-style-type: disc; font-size: 12px"><span style="color: red">size_type erase(const Key&amp; key); //通过关键字删除</span></li></ol>
<p style="box-sizing: border-box; text-indent: 0px; margin: 0px auto 10px"><span style="box-sizing: border-box; color: red">clear()</span><span style="color: red">就相当于 enumMap.erase(enumMap.begin(), enumMap.end());</span></p></span><img src ="http://www.cppblog.com/AutomateProgram/aggbug/156657.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2011-09-23 23:02 <a href="http://www.cppblog.com/AutomateProgram/archive/2011/09/23/156657.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MySQL中索引入门建立和优化（1）explain的使用和说明</title><link>http://www.cppblog.com/AutomateProgram/archive/2011/09/19/156219.html</link><dc:creator>漂漂</dc:creator><author>漂漂</author><pubDate>Mon, 19 Sep 2011 06:10:00 GMT</pubDate><guid>http://www.cppblog.com/AutomateProgram/archive/2011/09/19/156219.html</guid><wfw:comment>http://www.cppblog.com/AutomateProgram/comments/156219.html</wfw:comment><comments>http://www.cppblog.com/AutomateProgram/archive/2011/09/19/156219.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AutomateProgram/comments/commentRss/156219.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AutomateProgram/services/trackbacks/156219.html</trackback:ping><description><![CDATA[<p><font style="background-color: #cce8cf">&nbsp;&nbsp;&nbsp; 原文地址：<br /><br />explain显示了mysql如何使用索引来处理select语句以及连接表。可以帮助选择更好的索引和写出更优化的查询语句。<br /><br />&nbsp;&nbsp;&nbsp;&nbsp; 使用方法，在select语句前加上explain就可以了：<br />如：explain select surname,first_name form a,b where a.id=b.id<br /><br />分析结果形式如下：<br /><br /><br />EXPLAIN列的解释：<br />table<br />显示这一行的数据是关于哪张表的<br /><br />type<br />这是重要的列，显示连接使用了何种类型。从最好到最差的连接类型为const、eq_reg、ref、range、indexhe和ALL<br /><br />possible_keys<br />显示可能应用在这张表中的索引。如果为空，没有可能的索引。可以为相关的域从WHERE语句中选择一个合适的语句<br /><br />key<br />实际使用的索引。如果为NULL，则没有使用索引。很少的情况下，MYSQL会选择优化不足的索引。这种情况下，可以在SELECT语句中使用USE INDEX（indexname）来强制使用一个索引或者用IGNORE INDEX（indexname）来强制MYSQL忽略索引<br /><br />key_len<br />使用的索引的长度。在不损失精确性的情况下，长度越短越好<br /><br />ref<br />显示索引的哪一列被使用了，如果可能的话，是一个常数<br /><br />rows<br />MYSQL认为必须检查的用来返回请求数据的行数<br /><br />Extra<br />关于MYSQL如何解析查询的额外信息。将在表4.3中讨论，但这里可以看到的坏的例子是Using temporary和Using filesort，意思MYSQL根本不能使用索引，结果是检索会很慢<br />extra列返回的描述的意义<br /><br />Distinct<br />一旦MYSQL找到了与行相联合匹配的行，就不再搜索了<br /><br />Not exists<br />&nbsp;<br />MYSQL优化了LEFT JOIN，一旦它找到了匹配LEFT JOIN标准的行，<br />就不再搜索了<br /><br />Range checked for each<br />Record（index map:#）<br />&nbsp;<br />没有找到理想的索引，因此对于从前面表中来的每一个<br />行组合，MYSQL检查使用哪个索引，并用它来从表中返回行。<br />这是使用索引的最慢的连接之一<br />Using filesort<br />&nbsp;<br />看到这个的时候，查询就需要优化了。MYSQL需要进行额外的步骤<br />来发现如何对返回的行排序。它根据连接类型以及存储排序键值和<br />匹配条件的全部行的行指针来排序全部行<br /><br />Using index<br />&nbsp;<br />列数据是从仅仅使用了索引中的信息而没有读取实际的行动的表返回的，<br />这发生在对表的全部的请求列都是同一个索引的部分的时候<br /><br />Using temporary<br />&nbsp;<br />看到这个的时候，查询需要优化了。<br />这里，MYSQL需要创建一个临时表来存储结果，<br />这通常发生在对不同的列集进行ORDER BY上，而不是GROUP BY上<br /><br />Where used<br />&nbsp;<br />使用了WHERE从句来限制哪些行将与下一张表匹配或者是返回给用户。<br />如果不想返回表中的全部行，并且连接类型ALL或index，这就会发生，<br />或者是查询有问题<br />&nbsp;<br />不同连接类型的解释（按照效率高低的顺序排序）<br />system<br />表只有一行：system表。这是const连接类型的特殊情况<br /><br />const<br />&nbsp;<br />表中的一个记录的最大值能够匹配这个查询（索引可以是主键或惟一索引）。因为只有一行，这个值实际就是常数，因为MYSQL先读这个值然后把它当做常数来对待<br /><br />eq_ref<br />&nbsp;<br />在连接中，MYSQL在查询时，从前面的表中，对每一个记录的联合都从表中读取一个记录，它在查询使用了索引为主键或惟一键的全部时使用<br /><br />ref<br />&nbsp;<br />这个连接类型只有在查询使用了不是惟一或主键的键或者是这些类型的部分（比如，利用最左边前缀）时发生。对于之前的表的每一个行联合，全部记录都将从表中读出。这个类型严重依赖于根据索引匹配的记录多少&#8212;越少越好<br /><br />range<br />&nbsp;<br />这个连接类型使用索引返回一个范围中的行，比如使用&gt;或&lt;查找东西时发生的情况<br /><br />index<br />&nbsp;<br />这个连接类型对前面的表中的每一个记录联合进行完全扫描（比ALL更好，因为索引一般小于表数据）<br /><br />ALL<br /><br />这个连接类型对于前面的每一个记录联合进行完全扫描，这一般比较糟糕，应该尽量避免<br /><br />ppt地址：<br /><a href="http://www.slideshare.net/sky000/mysql-explain">http://www.slideshare.net/sky000/mysql-explain</a><br /><br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="line-height: 18px; font-family: Arial; font-size: 14px; font-weight: bold" class="Apple-style-span">MySQL之Explain</span></span><br />原文地址：<a href="http://hi.baidu.com/thinkinginlamp/blog/item/eef0cd119239db17b8127b6f.html">http://hi.baidu.com/thinkinginlamp/blog/item/eef0cd119239db17b8127b6f.html</a><br /><br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="line-height: 20px; font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px" class="Apple-style-span">前记：很多东西看似简单，那是因为你并未真正了解它。<br style="line-height: normal" /><br style="line-height: normal" />Explain命令用于查看执行效果。虽然这个命令只能搭配select类型语句使用，如果你想查看update，delete类型语句中的索引效果，也不是太难的事情，只要保持条件不变，把类型转换成select就行了。<br style="line-height: normal" /><br style="line-height: normal" />explain的语法如下：<br style="line-height: normal" /><br style="line-height: normal" /><font style="line-height: normal" face="宋体">explain [extended] select ... from ... where ...</font><br style="line-height: normal" /><br style="line-height: normal" />如果使用了extended，那么在执行完explain语句后，可以使用show warnings语句查询相应的优化信息。<br style="line-height: normal" /><br style="line-height: normal" />==============================================================<br style="line-height: normal" /><br style="line-height: normal" /><a style="line-height: normal; color: rgb(0,0,0)" href="http://www.maatkit.org/doc/mk-visual-explain.html" target="_blank">mk-visual-explain</a>工具扩展了explain，它提供了一种更直观的树形表现形式，使用方法很简单：<br style="line-height: normal" /><br style="line-height: normal" /><font style="line-height: normal" face="宋体">mk-visual-explain &lt;file_containing_explain_output&gt;<br style="line-height: normal" />mk-visual-explain -c &lt;file_containing_query&gt;<br style="line-height: normal" />mysql -e "explain select * from mysql.user" | mk-visual-explain</font><br style="line-height: normal" /><br style="line-height: normal" />也可以在MySQL命令行里通过设置pager的方式来执行：<br style="line-height: normal" /><br style="line-height: normal" /><font style="line-height: normal" face="宋体">mysql&gt; pager mk-visual-explain<br style="line-height: normal" />mysql&gt; explain [extended] select ... from ... where ...</font><br style="line-height: normal" /><br style="line-height: normal" />==============================================================<br style="line-height: normal" /><br style="line-height: normal" />进入正题，为了让例子更具体化，我们先来建一个表，插入一点测试数据：<br style="line-height: normal" /><font style="line-height: normal" face="宋体"><br style="line-height: normal" />CREATE TABLE IF NOT EXISTS `article` (<br style="line-height: normal" />`id` int(10) unsigned NOT NULL AUTO_INCREMENT,<br style="line-height: normal" />`author_id` int(10) unsigned NOT NULL,<br style="line-height: normal" />`category_id` int(10) unsigned NOT NULL,<br style="line-height: normal" /></font><font style="line-height: normal" face="宋体">`views` int(10) unsigned NOT NULL,<br style="line-height: normal" /></font><font style="line-height: normal" face="宋体">`comments` int(10) unsigned NOT NULL,</font><br style="line-height: normal" /><font style="line-height: normal" face="宋体">`title` varbinary(255) NOT NULL,<br style="line-height: normal" />`content` text NOT NULL,<br style="line-height: normal" />PRIMARY KEY (`id`)<br style="line-height: normal" />);<br style="line-height: normal" /><br style="line-height: normal" />INSERT INTO `article`<br style="line-height: normal" />(`author_id`, `category_id`</font><font style="line-height: normal" face="宋体">, `views`,</font><font style="line-height: normal" face="宋体"><span class="Apple-converted-space">&nbsp;</span>`comments`,<span class="Apple-converted-space">&nbsp;</span></font><font style="line-height: normal" face="宋体">`title`, `content`) VALUES<br style="line-height: normal" />(1, 1,<span class="Apple-converted-space">&nbsp;</span></font><font style="line-height: normal" face="宋体">1,<span class="Apple-converted-space">&nbsp;</span></font><font style="line-height: normal" face="宋体">1,<span class="Apple-converted-space">&nbsp;</span></font><font style="line-height: normal" face="宋体">'1', '1'),<br style="line-height: normal" />(2, 2, 2,<span class="Apple-converted-space">&nbsp;</span></font><font style="line-height: normal" face="宋体">2,<span class="Apple-converted-space">&nbsp;</span></font><font style="line-height: normal" face="宋体">'2', '2');</font><br style="line-height: normal" /><br style="line-height: normal" />缺省只建了一个主键，没有建其他的索引。测试时，如果你时间充裕，应该尽可能插入多一点的测试数据，怎么说也应该保证几千条。如果数据量过少，可能会影响MySQL在索引选择上的判断。如此一来，一旦产品上线，数据量增加。索引往往不会按照你的预想工作。<br style="line-height: normal" /><br style="line-height: normal" />下面让我们设置一个任务：查询category_id为1且comments大于1的情况下，views最多的article_id。<br style="line-height: normal" /><br style="line-height: normal" />问题很简单，SQL也很简单：<br style="line-height: normal" /><br style="line-height: normal" /><font style="line-height: normal" face="宋体">SELECT author_id<br style="line-height: normal" />FROM `article`<br style="line-height: normal" />WHERE category_id = 1 AND comments &gt; 1<br style="line-height: normal" />ORDER BY views DESC<br style="line-height: normal" />LIMIT 1</font><br style="line-height: normal" /><br style="line-height: normal" />下面让我们用explain命令查看索引效果：<br style="line-height: normal" /><br style="line-height: normal" /><font style="line-height: normal" face="宋体"><code style="line-height: normal" class="sql"><span style="line-height: normal" class="syntax"><span style="line-height: normal" class="syntax_alpha syntax_alpha_reservedWord">EXPLAIN SELECT author_id<br style="line-height: normal" />FROM `article`<br style="line-height: normal" />WHERE category_id = 1<br style="line-height: normal" />AND comments &gt; 1<br style="line-height: normal" />ORDER BY views DESC<br style="line-height: normal" />LIMIT 1</span></span></code><br style="line-height: normal" /></font><br style="line-height: normal" />这时explain部分结果如下：<br style="line-height: normal" /><br style="line-height: normal" /><font style="line-height: normal" face="宋体">type: ALL<br style="line-height: normal" />key: NULL<br style="line-height: normal" />Extra: Using where; Using filesort</font><br style="line-height: normal" /><br style="line-height: normal" />显示数据库进行了全表扫描，没有用到索引，并且在过程中文件排序。这样的结果肯定是糟糕的，下面让我们通过建立索引优化一下它：<br style="line-height: normal" /><font style="line-height: normal" face="宋体"><br style="line-height: normal" />ALTER TABLE `article` ADD INDEX x ( `category_id` , `comments`, `views` ) ;</font><br style="line-height: normal" /><br style="line-height: normal" />这时explain部分结果如下：<br style="line-height: normal" /><br style="line-height: normal" /><font style="line-height: normal" face="宋体">type: range<br style="line-height: normal" />key: x<br style="line-height: normal" />Extra: Using where; Using filesort</font><br style="line-height: normal" /><br style="line-height: normal" />虽然不再是全表扫描了，但是仍然存在文件排序。一般来说，文件排序都是由于ORDER BY语句一起的，而我们已经把views字段放到了联合索引里面，为什么没有效果呢？这是因为按照BTree的工作原理，先排序category_id，如果遇到相同的category_id则再排序comments，如果遇到相同的comments则再排序views。当comments字段在联合索引里处于中间位置时，因为comments &gt; 1条件是一个范围值（所谓range），MySQL目前无法利用索引再对后面的views部分进行检索，如果换成是是comments in ('a', 'b', 'c')这样的多等情况则可以，关于这一点，在High Performance MySQL一书中专门有过叙述，名为Avoiding Multiple Range Conditions，在复合索引里，仅仅只能保存一个range类型的查询字段，并且要放到复合索引的末尾，否则，range类型查询字段后面的索引无效。详细的介绍大家可以自己查阅。从这个意义上来说，此时的category_id, comments, views复合索引的效果不会比category_id, comments复合索引的效果好。<br style="line-height: normal" /><br style="line-height: normal" />文件排序是否会引起性能问题要视数据分布情况而定。这里有一个案例可供参考：<a style="line-height: normal; color: rgb(0,0,0)" href="http://www.mysqlperformanceblog.com/2007/02/16/using-index-for-order-by-vs-restricting-number-of-rows/" target="_blank">Using index for ORDER BY vs restricting number of rows.</a><br style="line-height: normal" /><br style="line-height: normal" />多数情况下应该避免出现它。此时可以这样设置索引：<br style="line-height: normal" /><br style="line-height: normal" /><font style="line-height: normal" face="宋体">ALTER TABLE `article` ADD INDEX y ( `category_id` , `views` ) ;</font><br style="line-height: normal" /><br style="line-height: normal" />这时explain部分结果如下：<br style="line-height: normal" /><br style="line-height: normal" /><font style="line-height: normal" face="宋体">type: range<br style="line-height: normal" />key: x<br style="line-height: normal" />Extra: Using where; Using filesort</font><br style="line-height: normal" /><br style="line-height: normal" />很奇怪，系统无视我们刚建立的y索引，还使用x索引。导致仍然存在文件排序。<br style="line-height: normal" /><br style="line-height: normal" />如果你也出现了类似的情况，可以使用强制索引：<br style="line-height: normal" /><br style="line-height: normal" /><font style="line-height: normal" face="宋体">EXPLAIN SELECT author_id<br style="line-height: normal" />FROM `article`<br style="line-height: normal" />FORCE INDEX ( y )<br style="line-height: normal" />WHERE category_id = 1<br style="line-height: normal" />AND comments &gt; 1<br style="line-height: normal" />ORDER BY views DESC<br style="line-height: normal" />LIMIT 1</font><br style="line-height: normal" /><br style="line-height: normal" />这时explain部分结果如下：<br style="line-height: normal" /><br style="line-height: normal" /><font style="line-height: normal" face="宋体">type: ref<br style="line-height: normal" />key: y<br style="line-height: normal" />Extra: Using where<br style="line-height: normal" /><br style="line-height: normal" /></font>也可以删除x索引，那样系统会自动使用y索引（有时候MySQL比较傻，所以你得会使用FORCE INDEX）。<br style="line-height: normal" /><br style="line-height: normal" />后记：Explain的type显示的是访问类型，是较为重要的一个指标，结果值从好到坏依次是：<br style="line-height: normal" /><br style="line-height: normal" />system &gt; const &gt; eq_ref &gt; ref &gt; fulltext &gt; ref_or_null &gt; index_merge &gt; unique_subquery &gt; index_subquery &gt; range &gt; index &gt; ALL<br style="line-height: normal" /><br style="line-height: normal" />一般来说，得保证查询至少达到range级别，最好能达到ref，否则就可能会出现性能问题。<br style="line-height: normal" /><br style="line-height: normal" />Explain的Extra信息也相当重要，如果此信息显示Using filesort或者Using temporary的话，噩梦即将开始，不过也不尽然，比如说在一个WHERE ... ORDER BY ... 类型的查询里，很多时候我们无法创建一个兼顾WHERE和ORDER BY的索引，此时如果按照WHERE来确定索引，那么在ORDER BY时，就必然会引起Using filesort，文件排序是好是坏需要仔细判断，说白了就是看是先过滤再排序划算，还是先排序再过滤划算，正确答案取决与数据分布的情况，具体的情况可以参考<a style="line-height: normal; color: rgb(0,0,0)" href="http://www.mysqlperformanceblog.com/2007/02/16/using-index-for-order-by-vs-restricting-number-of-rows/" target="_blank">Using index for ORDER BY vs restricting number of rows</a>。<br style="line-height: normal" /><br style="line-height: normal" />Explain具体含义参见此链接：<a style="line-height: normal; color: rgb(0,0,0)" href="http://dev.mysql.com/doc/refman/5.1/en/using-explain.html" target="_blank">http://dev.mysql.com/doc/refman/5.1/en/using-explain.html</a></span></span><br /><br /></font></p><img src ="http://www.cppblog.com/AutomateProgram/aggbug/156219.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AutomateProgram/" target="_blank">漂漂</a> 2011-09-19 14:10 <a href="http://www.cppblog.com/AutomateProgram/archive/2011/09/19/156219.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>