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

<channel>
	<title>肉夹馍与乌托邦 &#187; Diving in EECS</title>
	<atom:link href="http://blog.phio.me/category/diving-in-eecs/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.phio.me</link>
	<description>别想太多</description>
	<lastBuildDate>Sun, 31 Jul 2011 16:41:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Win7，Grub4DOS，Ubuntu</title>
		<link>http://blog.phio.me/2009/11/win7-ubuntu-grub4dos/</link>
		<comments>http://blog.phio.me/2009/11/win7-ubuntu-grub4dos/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 13:09:49 +0000</pubDate>
		<dc:creator>phio</dc:creator>
				<category><![CDATA[Diving in EECS]]></category>
		<category><![CDATA[grub]]></category>
		<category><![CDATA[grub4dos]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[win7]]></category>

		<guid isPermaLink="false">http://blog.phio.me/?p=192</guid>
		<description><![CDATA[装Win7有快两个月了吧，对于我这个没有用过Vista的人来说，Win7是很不错的： 界面好看 搜索功能强大 内置的那些微软的附加软件都很不错 最让我惊叹的是我的笔记本在装好以后，不小心用Windows Update装了一下驱动，居然根本不需要我再装除了显卡驱动意外的任何驱动了，这个太惊人了 另外，对于游戏，大型软件的支持也都不错，唯一可恨的是虚拟光驱ms还不能用。我装的64位系统，对于32位程序兼容也很不错 可是某天我想起来，自从装了Win7，MBR被覆盖以后，我的Ubuntu好像好久都没有进去玩过了，于是我就股沟了一下。得到这篇来自JavaEye的文章，看了以后直接操作： 1：先去下载grub4dos 2：解压grldr.mbr,grldr,menu.lst三个文件到C盘根目录，注意是根目录哦！ 3：然后以管理员模式运行cmd，输入bcdedit /create /d "grub" /application bootsector 会有一大串id，要记下，等下要用，然后： 4：bcdedit /set {id} device partition=c: 5：bcdedit /set {id} path \grldr.mbr 6：bcdedit /displayorder {id} /addlast 杯具发生在第5条命令，当我在我下到的grub4dos里面没有找到 \grub.mbr那个文件只有\grldr之后，我居然脑子一昏，直接把那个命令换成了 \grldr，启动之后，Win7的C盘的启动扇区被改成了grub…… 于是一个死循环出现了，当我在Grub命令行里使用 1. root (hd0,0) 2. chainloader +1 3. boot 来启动Win7的时候，它等于又一次引导了grub……试过很多办法，都不能打破这个死循环了。 于是，我想，就先用Ubuntu吧，我可不想再折腾着装系统了。晚上睡觉前，电脑一开，直接升级到9.10，一路next，很快我就用上了9.10 。在Linux底下，我自然而然地会减少上网时间，可能是以前在Linux下上网实在不是一件能带来快乐的事情，反而有很多时间玩玩技术，不错不错。可是终究有一天，我想用支付宝交电费了，终究必须用Windows了，于是我想，再折腾一下吧。 这个阶段的杯具在于我的光驱适时地坏掉了，Dell的光驱太牛了，刚好撑过保修期过了10几天就自我歇菜，骂娘都没的地方了。按以前的经验，只要把Win7的光盘搞进去再重新引导一下，都不需要安装或者最多运行几个命令，就可以修复那个启动扇区，可是我光驱没法用，grub引导iso半天没成功，就在我万念俱灰的时候，我看到了Win7的C盘下面躺着一个bootsect.bak，眼睛一亮。Google告诉我这个玩意是Win7安装的时候备份下来以前的pbr（partition boot record），可是我想，备份以前的干啥啊，应该是自己的PBR吧。于是乎想到了dd，同时为了防止杯具的再次发生，我先把grub安装到了MBR：grub-install /dev/sda。然后研究那个bootsect.mbr，先后使用以下命令： 1. file bootsect.bak //确认一下是不是启动记录，结果OK 2. [...]]]></description>
			<content:encoded><![CDATA[<p>装Win7有快两个月了吧，对于我这个没有用过Vista的人来说，Win7是很不错的：</p>
<ul>
<li> 界面好看</li>
<li>搜索功能强大</li>
<li>内置的那些微软的附加软件都很不错</li>
<li>最让我惊叹的是我的笔记本在装好以后，不小心用Windows Update装了一下驱动，居然根本不需要我再装除了显卡驱动意外的任何驱动了，这个太惊人了</li>
<li>另外，对于游戏，大型软件的支持也都不错，唯一可恨的是虚拟光驱ms还不能用。我装的64位系统，对于32位程序兼容也很不错</li>
</ul>
<p>可是某天我想起来，自从装了Win7，MBR被覆盖以后，我的Ubuntu好像好久都没有进去玩过了，于是我就股沟了一下。得到<a href="http://emcome.javaeye.com/blog/467011">这篇来自JavaEye的文章</a>，看了以后直接操作：</p>
<p><code><br />
1：先去下载grub4dos<br />
2：解压grldr.mbr,grldr,menu.lst三个文件到C盘根目录，注意是根目录哦！<br />
3：然后以管理员模式运行cmd，输入bcdedit /create /d "grub" /application bootsector<br />
会有一大串id，要记下，等下要用，然后：<br />
4：bcdedit /set {id} device partition=c:<br />
5：bcdedit /set {id} path \grldr.mbr<br />
6：bcdedit /displayorder {id} /addlast<br />
</code></p>
<p>杯具发生在第5条命令，当我在我下到的grub4dos里面没有找到 \grub.mbr那个文件只有\grldr之后，我居然脑子一昏，直接把那个命令换成了 \grldr，启动之后，Win7的C盘的启动扇区被改成了grub……<span id="more-192"></span></p>
<p>于是一个死循环出现了，当我在Grub命令行里使用<br />
<code><br />
1. root (hd0,0)<br />
2. chainloader +1<br />
3. boot<br />
</code><br />
来启动Win7的时候，它等于又一次引导了grub……试过很多办法，都不能打破这个死循环了。</p>
<p>于是，我想，就先用Ubuntu吧，我可不想再折腾着装系统了。晚上睡觉前，电脑一开，直接升级到9.10，一路next，很快我就用上了9.10 。在Linux底下，我自然而然地会减少上网时间，可能是以前在Linux下上网实在不是一件能带来快乐的事情，反而有很多时间玩玩技术，不错不错。可是终究有一天，我想用支付宝交电费了，终究必须用Windows了，于是我想，再折腾一下吧。</p>
<p>这个阶段的杯具在于我的光驱适时地坏掉了，Dell的光驱太牛了，刚好撑过保修期过了10几天就自我歇菜，骂娘都没的地方了。按以前的经验，只要把Win7的光盘搞进去再重新引导一下，都不需要安装或者最多运行几个命令，就可以修复那个启动扇区，可是我光驱没法用，grub引导iso半天没成功，就在我万念俱灰的时候，我看到了Win7的C盘下面躺着一个bootsect.bak，眼睛一亮。Google告诉我这个玩意是Win7安装的时候备份下来以前的<a href="http://en.wikipedia.org/wiki/Partition_Boot_Record">pbr（partition boot record）</a>，可是我想，备份以前的干啥啊，应该是自己的PBR吧。于是乎想到了dd，同时为了防止杯具的再次发生，我先把grub安装到了<a href="http://en.wikipedia.org/wiki/Master_boot_record">MBR</a>：<code>grub-install /dev/sda</code>。然后研究那个bootsect.mbr，先后使用以下命令：</p>
<p><code><br />
1. file bootsect.bak //确认一下是不是启动记录，结果OK<br />
2. ls -l bootsec.bak //看下是多大，得到是8192字节，不错不错<br />
3. dd -i /dev/sda1 -o win7_pbr.bak -bsize 512 -count 16 //备份C盘PBR<br />
4. dd -i bootsect.bak -o /dev/sda1 -bsize 512 -count 16 //强力重写C盘的PBR<br />
</code></p>
<p>忐忑不安地重启了机器……</p>
<p>Grub出现，OK；验证Linux启动，OK；重启，选择Grub认出来的那个Win7 label，哇，看见了久违的Starting Windows，GREAT！感谢Win7的bootsect.bak，感谢dd！此次事件，让我对Win7的好感又增加一些。不过最近一段时间，我基本都只用Ubuntu了，Windows只用来打游戏，付支付宝水电费账单，原因很简单，因为Ubuntu可以让我集中精力玩技术，嘿嘿。后来知道Win7有个easyBCD的程序，可以方便添加启动条目，可惜我已经用不到了。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.phio.me/2009/11/win7-ubuntu-grub4dos/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>一道位域笔试题</title>
		<link>http://blog.phio.me/2009/09/a-bitfield-problem/</link>
		<comments>http://blog.phio.me/2009/09/a-bitfield-problem/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 11:10:26 +0000</pubDate>
		<dc:creator>phio</dc:creator>
				<category><![CDATA[Diving in EECS]]></category>
		<category><![CDATA[abi]]></category>
		<category><![CDATA[bitfield]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[gcc]]></category>

		<guid isPermaLink="false">http://blog.phio.me/?p=152</guid>
		<description><![CDATA[首先声明：我根本不是个C高手，只是碰到这个问题，一路查下去才得到这些信息的。这篇帖子放在这里做个记录，也方便后来人参考。不知道里面有没有错误，欢迎批评指正。 我是在果冻的百合blog上看到这篇题目的，原题是在水源上。题目是这样的 #include &#60;stdio.h&#62; void main() { union { struct { unsigned short s1:3; unsigned short s2:3; unsigned short s3:3; }x; char c; }v; v.c=100; printf("%d\n",v.x.s3); } 问打印的结果是啥：A:4 B:0 C:3 D:6 100就是0&#215;64。乍看起来，100写成0110 0100，从左到右，依次把这些位分给s1，s2，s3，s3，分别是3，1，0。答案好像很明显。但其实，用我们最普通的32位x86机器跑gcc得到的结果是1，不是0。 细细考究起来，这里的问题还是很多的： 在计算机内存里面100这个十进制数的表示形式是什么样的？ 对于一个给定的二进制串，语言规则或者编译器是如何放置位域的？按照声明的顺序从左到右？还是反过来？按照其他的顺序？这个问题还隐含了另外一个问题，就是当一个字节的剩余比特位没办法放下一个完整的位域的时候，这个时候如何处理？ 先搞清楚第一个问题吧。查过Wikipedia以后，才知道这个术语叫做Bit numbering（应该是翻译为位序吧），和所谓字节序（Byte numbering或者Byte endianess）并不是一回事，也并不总是一致的。通常来说，小端机器总是用的是LSB 0 bit，而大端机器就得具体问题具体分析。把这个问题翻译为术语，就是说某个机器是LSB 0 bit numbering，还是MSB 0 bit numbering？通俗点说就是，从bit 0到bit 8，0&#215;64被表示为0110 0100还是0010 0110？ 第二个问题，这个涉及到语言标准和编译器实现细节，并不是那么容易一下子搞清楚的。那就先做两个想当然的假设吧：假设位域是按照声明的顺序从左到右放置的；假设当一个字节放不下一个位域的时候，从下一个字节借几位过来凑够一个位域。这样的话， 对于LSB 0 [...]]]></description>
			<content:encoded><![CDATA[<p>首先声明：我根本不是个C高手，只是碰到这个问题，一路查下去才得到这些信息的。这篇帖子放在这里做个记录，也方便后来人参考。不知道里面有没有错误，欢迎批评指正。</p>
<p>我是在<a href="http://bbs.nju.edu.cn/blogcon?userid=godzatnju&amp;file=1250578254" target="_blank">果冻的百合blog</a>上看到这篇题目的，原题是在<a href="http://bbs.sjtu.edu.cn/bbscon,board,C,file,M.1182866981.A.html" target="_blank">水源上</a>。题目是这样的</p>
<pre class="brush:c">#include &lt;stdio.h&gt;
void main()
{
     union
    {
          struct
         {
               unsigned short s1:3;
               unsigned short s2:3;
               unsigned short s3:3;
         }x;
         char c;
    }v;
    v.c=100;
    printf("%d\n",v.x.s3);
}</pre>
<p>问打印的结果是啥：<code>A:4 B:0 C:3 D:6<span id="more-152"></span><br />
</code></p>
<p>100就是0&#215;64。乍看起来，100写成0110 0100，从左到右，依次把这些位分给s1，s2，s3，s3，分别是3，1，0。答案好像很明显。但其实，用我们最普通的32位x86机器跑gcc得到的结果是1，不是0。</p>
<p>细细考究起来，这里的问题还是很多的：</p>
<ol>
<li><span style="background-color: #ffffff;">在计算机内存里面100这个十进制数的表示形式是什么样的？</span></li>
<li><span style="background-color: #ffffff;">对于一个给定的二进制串，语言规则或者编译器是如何放置位域的？按照声明的顺序从左到右？还是反过来？按照其他的顺序？这个问题还隐含了另外一个问题，就是当一个字节的剩余比特位没办法放下一个完整的位域的时候，这个时候如何处理？</span></li>
</ol>
<p>先搞清楚第一个问题吧。查过Wikipedia以后，才知道这个术语叫做<a href="http://en.wikipedia.org/wiki/Bit_numbering" target="_blank">Bit numbering</a>（应该是翻译为位序吧），和所谓字节序（Byte numbering或者<a href="http://en.wikipedia.org/wiki/Endianness" target="_blank">Byte endianess</a>）并不是一回事，也并不总是一致的。通常来说，小端机器总是用的是LSB 0 bit，而大端机器就得具体问题具体分析。把这个问题翻译为术语，就是说某个机器是<a href="http://en.wikipedia.org/wiki/Bit_numbering" target="_blank">LSB 0 bit numbering</a>，还是<a href="http://en.wikipedia.org/wiki/Bit_numbering">MSB 0 bit numbering</a>？通俗点说就是，从bit 0到bit 8，0&#215;64被表示为0110 0100还是0010 0110？</p>
<p>第二个问题，这个涉及到语言标准和编译器实现细节，并不是那么容易一下子搞清楚的。那就先做两个想当然的假设吧：假设位域是按照声明的顺序从左到右放置的；假设当一个字节放不下一个位域的时候，从下一个字节借几位过来凑够一个位域。这样的话，</p>
<ul>
<li><span style="background-color: #ffffff;">对于LSB 0 bit的机器，s1：001（LSB 0 bit的4），s2：001（4），s3：100（1）</span></li>
<li><span style="background-color: #ffffff;">对于MSB 0 bit的机器，s1：011（MSB 0 bit的3），s2：001（1），s3：000（0）</span></li>
</ul>
<p>这里还有个假设：借过来的那一位是个0，但事实证明那一位并不一定总为0。从题目来看，union v至少会占据2个字节，而那个赋值操作却只会初始化最低的那一个字节，另一个字节没有被初始化。</p>
<p>回到第二个问题。虽然我对语言标准是一抹黑，但我还是硬着头皮把<a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1336.pdf " target="_blank">C标准</a>给下下来了。用最原始的办法，搜索bitfield和bit-field，一个个看下去，还真是找到了和这个问题相关的那一段（P102，S6.7.2.1 Structureand union speciﬁers）：</p>
<blockquote><p>10    An implementation may allocate anyaddressable storage unit large enough to hold a bit-<span style="background-color: #ffffff; ">ﬁeld. If enough space remains, a bit-ﬁeld that immediately follows another bit-ﬁeld in a structure shall be packed into adjacent bits of the same unit. If insufﬁcient space remains, whether a bit-ﬁeld that does not ﬁt is put into the next unit or overlaps adjacent units is implementation-deﬁned. The order of allocation of bit-ﬁelds within a unit (high-order to low-order or low-order to high-order) is implementation-deﬁned. The alignment of the addressable storage unit is unspeciﬁed.</span></p></blockquote>
<p>从这段标准来看，第二个问题的两小问都是implementation-defined。那就简单了，翻开gcc的info，C Implementation-&gt;Structures unions enumerations and bit-fields implementation，发现这两个问题下面都有一行：“Determined by ABI.”。这个ABI是何物？Wikipedia告诉我们，它叫<a href="http://en.wikipedia.org/wiki/Application_binary_interface">Application Binary</a><a href="http://en.wikipedia.org/wiki/Application_binary_interface" target="_blank"> Interface</a>。我认为ABI应该是做处理器的写的吧，不该是gcc去弄吧，可是苦苦追寻居然在Intel的网站上找不到正式的关于ABI的文档，在Intel的Developer&#8217;s Manual也没有找到。倒是在SCO的网站上有这么<a href="www.sco.com/developers/devspecs/abi386-4.pdf" target="_blank">一个pdf</a>，是给x86的。x86-64的ABI好像是<a href="www.x86-64.org/documentation/abi-0.99.pdf" target="_blank">这个</a>。gcc的info里面提到的3.2以后的那个正式ABI在<a href="http://www.codesourcery.com/public/cxx-abi/" target="_blank">这里</a>。SCO的那个ABI确实很详细，里面各种乱七八糟的问题，包括alignment都有涉及。对于前面那些问题的解答在这个时候才真正地浮现出来了，我就不一个个抄出来了，太麻烦了。</p>
<p>最后一个问题就是当s1，s2，s3都是unsigned char的时候，有人发现结果和unsigned short是不一样的。这个就是到当一个位域可能会横跨一个storage unit的时候如何处理的问题。如果前面的文档都有读过的话，这个问题其实也不难解答。我得到的一个知识点就是位域前面的数据类型声明原来就是用来声明一个位域应该处于一个什么样的storage unit内。也就是说char位域要放在一个char“变量”里面，而short位域要放在一个short变量里面。如果s1，s2，s3都是unsigned char的时候，在s1和s2被安顿好以后，s3就放不下了。如果s3被声明为一个short的位域的话，它会紧挨着s1，s2继续放下去，也就是之前所猜想的那样。但是如果它是一个char位域的话，就不一样了，因为放置s1和s2的那个storage unit（是个char）放不下s3了，gcc会把s3放在下一个字节里面，这样的话，同样是一个LSB 0 bit机器，大家都是short的时候，s3应该是1，而大家都是char的时候，s3是0（假设没有被初始化的位都是0）。</p>
<p>好像要说的问题都说了，就此打住。这篇blog草稿打了很久，终于给写完了。嗯，最后再JW一下吧，这个题作为一道笔试题目，可以说是很不好的，答案不唯一，又只是考些边边角角的东西，但是一路跟踪下来，还是有不少收获的。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.phio.me/2009/09/a-bitfield-problem/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>一个优秀的程序员用等宽字体【zz】</title>
		<link>http://blog.phio.me/2007/03/post-070320-114427-533/</link>
		<comments>http://blog.phio.me/2007/03/post-070320-114427-533/#comments</comments>
		<pubDate>Tue, 20 Mar 2007 04:10:40 +0000</pubDate>
		<dc:creator>phio</dc:creator>
				<category><![CDATA[Programming Way]]></category>

		<guid isPermaLink="false">http://my.donews.com/phio/2007/03/20/post-070320-114427-533/</guid>
		<description><![CDATA[很早以前就观察到身边不少的程序员习惯比较差：编程时使用的分辨率是640×480的、或者是使用800×600的分辨率但是字体大小调得全屏只能显示十多行、或者是使用得Times New Roman/Tahoma/Arial来写代码，连空格都对不齐&#8230;.. 曾听到过这么种说法：判断是不是个熟手，看看他编程时的屏幕就知道了，呵呵，可见习惯的重要性。这里随便侃侃我比较认同的编程用桌面显示一般标准，最后提供一个不错的等宽字体收集网，看腻了SimSun和FixedSys又不喜欢Courier的朋友可以去看看，说不定会有意外的惊喜: ) 编程用桌面显示规范： 1. 视力不差的话，800×600以上，1024×768最优 2. 字体大小9pt至12pt最佳，保证全屏方式下一目24行以上，40行以下 3. 字体采用绝对的等宽字体，常用的有新宋体/ FixedSys / Courier New等 编程用字体选择标准： 1. 所有字符等宽 2. 简洁、清晰、规范的字符形体 3. 支持ASCII码为128以上的扩展字符集 4. 空白字符(ASCII: 0&#215;20)与其他字符等宽 5. &#8217;1&#8242;、&#8217;l'和&#8217;i'等三个字符易于区分 6. &#8217;0&#8242;、&#8217;o'和&#8217;O'等三个字符易于区分 7. 双引号、单引号的前后部分易于区分，最好是镜像对称的 8. 清晰的标点符号外形，尤其是大括符、圆括符和方括符 Monospace/Fixed Width Programmer&#8217;s Fonts: http://www.lowing.org/fonts/ zz from http://www.cnblogs.com/neoragex2002/archive/2005/06/06/169033.html]]></description>
			<content:encoded><![CDATA[<p>很早以前就观察到身边不少的程序员习惯比较差：编程时使用的分辨率是640×480的、或者是使用800×600的分辨率但是字体大小调得全屏只能显示十多行、或者是使用得Times New Roman/Tahoma/Arial来写代码，连空格都对不齐&#8230;.. 曾听到过这么种说法：判断是不是个熟手，看看他编程时的屏幕就知道了，呵呵，可见习惯的重要性。这里随便侃侃我比较认同的编程用桌面显示一般标准，最后提供一个不错的等宽字体收集网，看腻了SimSun和FixedSys又不喜欢Courier的朋友可以去看看，说不定会有意外的惊喜: )</p>
<p>编程用桌面显示规范：<br />
1. 视力不差的话，800×600以上，1024×768最优<br />
2. 字体大小9pt至12pt最佳，保证全屏方式下一目24行以上，40行以下<br />
3. 字体采用绝对的等宽字体，常用的有新宋体/ FixedSys / Courier New等</p>
<p>编程用字体选择标准：<br />
1. 所有字符等宽<br />
2. 简洁、清晰、规范的字符形体<br />
3. 支持ASCII码为128以上的扩展字符集<br />
4. 空白字符(ASCII: 0&#215;20)与其他字符等宽<br />
5. &#8217;1&#8242;、&#8217;l'和&#8217;i'等三个字符易于区分<br />
6. &#8217;0&#8242;、&#8217;o'和&#8217;O'等三个字符易于区分<br />
7. 双引号、单引号的前后部分易于区分，最好是镜像对称的<br />
8. 清晰的标点符号外形，尤其是大括符、圆括符和方括符</p>
<p>Monospace/Fixed Width Programmer&#8217;s Fonts: http://www.lowing.org/fonts/</p>
<p>zz from http://www.cnblogs.com/neoragex2002/archive/2005/06/06/169033.html</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.phio.me/2007/03/post-070320-114427-533/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Proxy Automatic Configuration File</title>
		<link>http://blog.phio.me/2006/12/fwawhukmvqsiqxxhmbxpbvclidamxlbchczo/</link>
		<comments>http://blog.phio.me/2006/12/fwawhukmvqsiqxxhmbxpbvclidamxlbchczo/#comments</comments>
		<pubDate>Sat, 09 Dec 2006 13:24:00 +0000</pubDate>
		<dc:creator>phio</dc:creator>
				<category><![CDATA[Diving in EECS]]></category>

		<guid isPermaLink="false">http://my.donews.com/phio/2006/12/09/fwaWhukMVQsIQxxHmBxPbVcLIDaMXlbcHcZO/</guid>
		<description><![CDATA[一个PAC文件其实就是一个文本文件，最简单的格式就是包含一个叫FindProxyForURL的JScript函数，IE通过传入两个变量来调用这个函数，一个是用户浏览的地址URL全路经，一个是这个URL中的主机名部分(host)。 这个FindProxyForURL函数有三种可能的字符串返回值，一是&#8221;DIRECT&#8221;，就是直接连接，不通过代理；二是&#8221;PROXY proxyaddr:port&#8221;，其中proxyaddr和port分别是代理的地址和代理的端口；三是&#8221;SOCKS socksaddr:port&#8221;，其中socksaddr和port分别是socks代理的地址和端口，一个自动代理文件可以是多个选择的组合，其中用分号(;)隔开，如： function FindProxyForURL(url,host) { if (host == &#8220;www.mydomain.com&#8221;) return &#8220;DIRECT&#8221;; return &#8220;PROXY myproxy:80; PROXY myotherproxy:8080; DIRECT&#8221;; } 下面是代理脚本可能用到的函数和说明（英文不好的朋友可以直接跳过去看应用）： PAC Helper Functions dnsDomainIs(host, domain) Returns true if the host is part of the specified domain, false otherwise. isInNet(hostname, Resolves the hostname and subnet IP, subnet mask) returns true if the hostname is within [...]]]></description>
			<content:encoded><![CDATA[<p>一个PAC文件其实就是一个文本文件，最简单的格式就是包含一个叫FindProxyForURL的JScript函数，IE通过传入两个变量来调用这个函数，一个是用户浏览的地址URL全路经，一个是这个URL中的主机名部分(host)。<br />
这个FindProxyForURL函数有三种可能的字符串返回值，一是&#8221;DIRECT&#8221;，就是直接连接，不通过代理；二是&#8221;PROXY proxyaddr:port&#8221;，其中proxyaddr和port分别是代理的地址和代理的端口；三是&#8221;SOCKS socksaddr:port&#8221;，其中socksaddr和port分别是socks代理的地址和端口，一个自动代理文件可以是多个选择的组合，其中用分号(;)隔开，如：<br />
function FindProxyForURL(url,host)<br />
{<br />
if (host == &#8220;www.mydomain.com&#8221;)<br />
return &#8220;DIRECT&#8221;;<br />
return &#8220;PROXY myproxy:80;<br />
PROXY myotherproxy:8080;<br />
DIRECT&#8221;;<br />
}<br />
<span id="more-96"></span><br />
下面是代理脚本可能用到的函数和说明（英文不好的朋友可以直接跳过去看应用）：<br />
PAC Helper Functions<br />
dnsDomainIs(host, domain) Returns true if the host is part of the specified domain, false otherwise.<br />
isInNet(hostname, Resolves the hostname and subnet IP, subnet mask) returns true if the hostname is within the subnet<br />
specified by the IP address and the subnet mask, false otherwise.<br />
isPlainHostName(host) Returns true if there are no dots in the hostname, false otherwise.<br />
isResolvable(host) Internet Explorer tries to resolve the hostname through DNS and returns true if successful, false otherwise.<br />
localHostOrDomainIs Returns true if the host matches (host, domain) the host portion of the domain, or if the host matches the host and domain portions of the domain, false otherwise. (Executed only for URLs in the local domain.)<br />
dnsDomainLevels(host) Returns the number of dots in the hostname.<br />
dnsResolve(host) Returns a string containing the IP address of the specified host.<br />
myIPAddress( ) Returns a string containing the local machine&#8217;s IP address.<br />
shExpMatch(url, shexp) Returns true if the supplied URL matches the specified shell expression, false otherwise.<br />
dateRange(parmList) Returns true if the current date falls within the dates specified in parmList, false otherwise.<br />
timeRange(parmList) Returns true if the current time falls within the times specified in parmList, false otherwise.<br />
weekdayRange(parmList) Returns true if today is within the days of the week specified in parmList, false otherwise.</p>
<p>下面是各个函数应用的例子：<br />
a、isPlainHostName(host)，本例演示判断是否为本地主机，如 http://myservername/<br />
的方式访问，如果是直接连接，否则使用代理<br />
function FindProxyForURL(url, host)<br />
{<br />
if (isPlainHostName(host))<br />
return &#8220;DIRECT&#8221;;<br />
else<br />
return &#8220;PROXY proxy:80&#8243;;<br />
}<br />
b、dnsDomainIs(host, &#8220;&#8221;)、localHostOrDomainIs(host, &#8220;&#8221;)，本例演示判断访问主机是否属于某个域和某个域名，如果属于.company.com域的主机名，而域名不是company.com和home.company.com的直接连接，否则使用代理访问。<br />
function FindProxyForURL(url, host)<br />
{<br />
if ((isPlainHostName(host) ││<br />
dnsDomainIs(host, &#8220;.company.com&#8221;)) &amp;&amp;<br />
!localHostOrDomainIs(host, &#8220;www.company.com&#8221;) &amp;&amp;<br />
!localHostOrDomainIs(host, &#8220;home.company.com&#8221;))<br />
return &#8220;DIRECT&#8221;;<br />
else<br />
return &#8220;PROXY proxy:80&#8243;;<br />
}<br />
c、isResolvable(host)，本例演示主机名能否被dns服务器解析，如果能直接访问，否则就通过代理访问。<br />
function FindProxyForURL(url, host)<br />
{<br />
if (isResolvable(host))<br />
return &#8220;DIRECT&#8221;;<br />
else<br />
return &#8220;PROXY proxy:80&#8243;;<br />
}<br />
d、isInNet(host, &#8220;&#8221;, &#8220;&#8221;)，本例演示访问IP是否在某个子网内，如果是就直接访问，否则就通过代理，例子演示访问清华IP段的主页不用代理。<br />
function FindProxyForURL(url, host)<br />
{<br />
if (isInNet(host, &#8220;166.111.0.0&#8243;, &#8220;255.255.0.0&#8243;))<br />
return &#8220;DIRECT&#8221;;<br />
else<br />
return &#8220;PROXY proxy:80&#8243;;<br />
}<br />
e、shExpMatch(host, &#8220;&#8221;)，本例演示根据主机域名来改变连接类型，本地主机、*.edu 、*.com分别用不同的连接方式。<br />
function FindProxyForURL(url, host)<br />
{<br />
if (isPlainHostName(host))<br />
return &#8220;DIRECT&#8221;;<br />
else if (shExpMatch(host, &#8220;*.com&#8221;))<br />
return &#8220;PROXY comproxy:80&#8243;;<br />
else if (shExpMatch(host, &#8220;*.edu&#8221;))<br />
return &#8220;PROXY eduproxy:80&#8243;;<br />
else<br />
return &#8220;PROXY proxy:80&#8243;;<br />
}<br />
f、url.substring()，本例演示根据不同的协议来选择不同的代理，http、https、ftp、gopher分别使用不同的代理。<br />
function FindProxyForURL(url, host)<br />
{<br />
if (url.substring(0, 5) == &#8220;http:&#8221;) {<br />
return &#8220;PROXY proxy:80&#8243;;<br />
}<br />
else if (url.substring(0, 4) == &#8220;ftp:&#8221;) {<br />
return &#8220;PROXY fproxy:80&#8243;;<br />
}<br />
else if (url.substring(0, 7) == &#8220;gopher:&#8221;) {<br />
return &#8220;PROXY gproxy&#8221;;<br />
}<br />
else if (url.substring(0, 6) == &#8220;https:&#8221;) {<br />
return &#8220;PROXY secproxy:8080&#8243;;<br />
}<br />
else {<br />
return &#8220;DIRECT&#8221;;<br />
}<br />
}<br />
g、dnsResolve(host)，本例演示判断访问主机是否某个IP，如果是就使用代理，否则直接连接。<br />
unction FindProxyForURL(url, host)<br />
{<br />
if (dnsResolve(host) == &#8220;166.111.8.237&#8243;) {<br />
return &#8220;PROXY secproxy:8080&#8243;;<br />
}<br />
else {<br />
return &#8220;PROXY proxy:80&#8243;;<br />
}<br />
}<br />
h、myIpAddress()，本例演示判断本地IP是否某个IP，如果是就使用代理，否则直接使用连接。<br />
function FindProxyForURL(url, host)<br />
{<br />
if (myIpAddress() == &#8220;166.111.8.238&#8243;) {<br />
return &#8220;PROXY proxy:80&#8243;;<br />
}<br />
else {<br />
return &#8220;DIRECT&#8221;;<br />
}<br />
}<br />
i、dnsDomainLevels(host)，本例演示访问主机的域名级数是几级，就是域名有几个点如果域名中有点，就通过代理访问，否则直接连接。<br />
function FindProxyForURL(url, host)<br />
{<br />
if (dnsDomainLevels(host) &gt; 0) { // if number of dots in host &gt; 0<br />
return &#8220;PROXY proxy:80&#8243;;<br />
}<br />
return &#8220;DIRECT&#8221;;<br />
}<br />
j、weekdayRange()，本例演示当前日期的范围来改变使用代理，如果是GMT时间周三到周六，使用代理连接，否则直接连接。<br />
function FindProxyForURL(url, host)<br />
{<br />
if(weekdayRange(&#8220;WED&#8221;, &#8220;SAT&#8221;, &#8220;GMT&#8221;))<br />
return &#8220;PROXY proxy:80&#8243;;<br />
else<br />
return &#8220;DIRECT&#8221;;<br />
}<br />
k、最后一个例子是演示随机使用代理，这样可以好好利用代理服务器。<br />
function FindProxyForURL(url,host)<br />
{<br />
return randomProxy();<br />
}<br />
function randomProxy()<br />
{<br />
switch( Math.floor( Math.random() * 5 ) )<br />
{<br />
case 0:<br />
return &#8220;PROXY proxy1:80&#8243;;<br />
break;<br />
case 1:<br />
return &#8220;PROXY proxy2:80&#8243;;<br />
break;<br />
case 2:<br />
return &#8220;PROXY proxy3:80&#8243;;<br />
break;<br />
case 3:<br />
return &#8220;PROXY proxy4:80&#8243;;<br />
break;<br />
case 4:<br />
return &#8220;PROXY proxy5:80&#8243;;<br />
break;<br />
}<br />
}<br />
网络中心给的那个自动配置脚本，我看了看，已经很好了，自己稍微改了一下，传到了百合邮箱上，要是有人要的话pm我。</p>
<p>源文档</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.phio.me/2006/12/fwawhukmvqsiqxxhmbxpbvclidamxlbchczo/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>感动与惭愧</title>
		<link>http://blog.phio.me/2006/11/nxquvjkpycfqoewkcrnuzbqnuchvvvrjthdo/</link>
		<comments>http://blog.phio.me/2006/11/nxquvjkpycfqoewkcrnuzbqnuchvvvrjthdo/#comments</comments>
		<pubDate>Wed, 22 Nov 2006 15:18:03 +0000</pubDate>
		<dc:creator>phio</dc:creator>
				<category><![CDATA[Programming Way]]></category>

		<guid isPermaLink="false">http://my.donews.com/phio/2006/11/22/NXquvJkpycFqoeWKCRNUzBQnUchVVVRJThdo/</guid>
		<description><![CDATA[在Bjarne Stroustrup 的个人主页看到B. S.的自我介绍，有种强烈的被震撼的感觉。做一个有点名气的人不难，在今天这样的日子里。可是做一个像他这样的大师却是难上加难。平实谦恭，但原则分明、思想犀利，崇尚优雅。无不自豪中也带着几分无奈和遗憾，呵呵，人若至此，又有何求？ I&#8217;m the College of Engineering Professor in Computer Science at Texas A&#38;M University; you can find specific academic and educational information on and through my TAMU homepage. I also retain a link to AT&#38;T Labs &#8211; Research as a member of the Information and Systems Software Research Lab. I designed and [...]]]></description>
			<content:encoded><![CDATA[<p>在<a href="http://www.research.att.com/~bs/">Bjarne Stroustrup 的个人主页</a>看到B. S.的自我介绍，有种强烈的被震撼的感觉。做一个有点名气的人不难，在今天这样的日子里。可是做一个像他这样的大师却是难上加难。平实谦恭，但原则分明、思想犀利，崇尚优雅。无不自豪中也带着几分无奈和遗憾，呵呵，人若至此，又有何求？</p>
<blockquote><p>
I&#8217;m the College of Engineering Professor in Computer Science at Texas A&amp;M University; you can find specific academic and educational information on and through my TAMU homepage. I also retain a link to AT&amp;T Labs &#8211; Research as a member of the Information and Systems Software Research Lab.</p>
<p>I designed and implemented the C++ programming language. I remain active in the ISO C++ standards committee working on C++0x.</p>
<p>Over the years, I have written a few books (including The C++ Programming Language and The Design and Evolution of C++.), written a lot of papers, and given some interviews.</p>
<p>Here is some biographical material, some frequently asked questions, some frequently asked questions about C++ style and technique and a C++ glossary.</p>
<p>These pages are permanently under construction. Constructive comments are most welcome.</p>
<p>I can be reached by email at bs at cs.tamu.edu or bs at research.att.com, and by paper mail at Department of Computer Science, TAMU 3112, College Station, TX 77843-3112, USA.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.phio.me/2006/11/nxquvjkpycfqoewkcrnuzbqnuchvvvrjthdo/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>差点被搞死</title>
		<link>http://blog.phio.me/2006/08/klffnutwmlqvpkswrwbfwvwzzlumyssvyfxw/</link>
		<comments>http://blog.phio.me/2006/08/klffnutwmlqvpkswrwbfwvwzzlumyssvyfxw/#comments</comments>
		<pubDate>Tue, 29 Aug 2006 09:19:24 +0000</pubDate>
		<dc:creator>phio</dc:creator>
				<category><![CDATA[Programming Way]]></category>

		<guid isPermaLink="false">http://my.donews.com/phio/2006/08/29/klffNUTWmLQvPkSwrWbfWVWZZLUmYSsvYfXw/</guid>
		<description><![CDATA[两天一直为一个小小的编码问题头疼,perl就是不能接收mysql返回的汉字,全部变成问号,奶奶的,差点恨死写DBI那个人.昨天上网上一天就是没有收获,加了一个IRC还被一群人无视,唔,好不郁闷. 没想到下午慢慢把返回的结果unpack出来,上网到处搜集各种解决方案,终于在吃饭前搞定了.等项目结束了,把其中遇到的所有的问题,还有解决的过程都写出来,记在这里,算作一种纪念,嘿嘿.谢谢俺老婆,一直静静地鼓励俺慢慢来,看着她在旁边,再多心事都不用烦心. 今天blog重新开张,开始log 咯. 落下的那段回忆呢,保留在另外的地方:-)]]></description>
			<content:encoded><![CDATA[<p>两天一直为一个小小的编码问题头疼,perl就是不能接收mysql返回的汉字,全部变成问号,奶奶的,差点恨死写DBI那个人.昨天上网上一天就是没有收获,加了一个IRC还被一群人无视,唔,好不郁闷.</p>
<p>没想到下午慢慢把返回的结果unpack出来,上网到处搜集各种解决方案,终于在吃饭前搞定了.等项目结束了,把其中遇到的所有的问题,还有解决的过程都写出来,记在这里,算作一种纪念,嘿嘿.谢谢俺老婆,一直静静地鼓励俺慢慢来,看着她在旁边,再多心事都不用烦心.</p>
<p>今天blog重新开张,开始log 咯. 落下的那段回忆呢,保留在另外的地方:-)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.phio.me/2006/08/klffnutwmlqvpkswrwbfwvwzzlumyssvyfxw/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Secure Voice over IP: Zfone</title>
		<link>http://blog.phio.me/2006/04/secure-voice-over-ip-zfone/</link>
		<comments>http://blog.phio.me/2006/04/secure-voice-over-ip-zfone/#comments</comments>
		<pubDate>Fri, 14 Apr 2006 12:54:41 +0000</pubDate>
		<dc:creator>phio</dc:creator>
				<category><![CDATA[Diving in EECS]]></category>

		<guid isPermaLink="false">http://my.donews.com/phio/2006/04/14/secure-voice-over-ip-zfone/</guid>
		<description><![CDATA[Philip R. Zimmermann has just released Zfone, a new product that takes a new approach to make a secure telephone for the Internet. Zfone lets you whisper in someone&#8217;s ear, even if their ear is a thousand miles away. Zimmermann因为在密码学方面的的先驱性贡献而获得了多项技术和人道主义者的奖项. 2003年, 他被列入 Heinz Nixdorf MuseumsForum Wall of Fame, 2001年被列入 CRN Industry Hall of Fame. 在2000年时, [...]]]></description>
			<content:encoded><![CDATA[<p>Philip R. Zimmermann has just released <a href="http://www.philzimmermann.com/EN/zfone/index.html">Zfone</a>, a new product that takes a new approach to make a secure telephone for the Internet. Zfone lets you whisper in someone&#8217;s ear, even if their ear is a thousand miles away.</p>
<p>Zimmermann因为在密码学方面的的先驱性贡献而获得了多项技术和人道主义者的奖项. 2003年, 他被列入 <a href="http://www.hnf.de/museum/update_WallOfFame_en.html" target="_blank">Heinz Nixdorf MuseumsForum Wall of Fame</a>, 2001年被列入 <a href="http://www.crn.com/sections/special/hof/hof01.asp?ArticleID=31279" target="_blank">CRN Industry Hall of Fame</a>. 在2000年时, 信息世界(InfoWorld) 提名他为电子商务中的 <a href="http://www.infoworld.com/articles/hn/xml/00/10/09/001009hnpz.xml" target="_blank">十佳创新者</a> . 1991年他荣获国际隐私保护组织(Privacy International)的Louis Brandeis奖, 1998年获可靠计算杂志(Secure Computing Magazine)终身成就奖, 并在1996年因有促进负责应用技术的社会责任感中计算机行业的Norbert Wiener奖. 1995年因 <a href="http://www.chrysler.com/design/design_influences/design_awards/1995/" target="_blank">设计创新获Chrysler奖</a>, Electronic Frontier Foundation的先锋奖, 1996 PC周刊IT杰出奖, 以及1996因为&#8221;最安全产品&#8221;而获最佳连接网络计算奖. 1994年，PGP被信息周刊选为十大最重要产品. 1995年, Newsweek提名Zimmermann为&#8221;网络50杰&#8221;, 50位Internet上最有影响力的人。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.phio.me/2006/04/secure-voice-over-ip-zfone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

