2010年2月9日星期二

Hacking FreeBSD to change manual page width

I don't like the fixed width of manual pages, since I have such a wide terminal, but the man pages only occupied the left part.
By inspecting the process launched, it seems like that there are several processes related:
sh -c (cd /usr/share/man/en.UTF-8 ; /usr/bin/zcat /usr/share/man/en.UTF-8/man1/ls.1.gz | /usr/bin/tbl | /usr/bin/groff -S -Wall -mtty-char -man -Tutf8 | /usr/bin/col | less)
I tried to skip the most processes, and simplify the calling sequence, and finally I found that the most important process is groff.
After unzipped the ls.1.gz, I found that there's no clear marks of line ending. This encouraged me, since this makes possible to adjust the output width in later steps.
I did some experiments, and I found that the -man and -Tutf8 arguments are critical to the page width. I read the man page of groff, and found that if -Tutf8 is specified, then groff use grotty as postprocessor. I turned to the man page of grotty, but found nothing useful. However, the man page of groff_man supplied useful information: -rIN seems hopeful.
However, when I tried -rIN=130, the output is nothing different from the original. Finally, I turned to Google, and found this post: http://www.cygwin.com/ml/cygwin/2004-11/msg01003.html
So I know that first I should use -rLL and -rLT, and secondly I should use 130n instead of 130.
After adding these to the command line, the output looked like what I wanted. I want to automate the process, so I tried a method similar to the one in the post: changing the source of man by hand.
I greped and found /usr/src/gnu/usr.bin/man/Makefile.inc is the source of the command arguments. However, changing this is not so easy, since it would be interpreted by sed, and then by sh. So I changed /usr/src/gnu/usr.bin/man/lib/config.h instead. With some experiments, finally it worked. I added  -rLL=`echo $MANWIDTH`n -rLT=`echo $MANWIDTH`n into #define NROFF.
The last thing to do is to set MANWIDTH. I Googled about finding terminal width, and found this:
http://markmail.org/message/3gui7ymobsj65mje#query:get%20terminal%20width+page:1+mid:t6hhk3dmnfjyg52b+state:results
It is said that `tput cols` would do the work, and really it worked.
So I added setenv MANWIDTH `tput cols` into ~/.cshrc, and everything worked like a charm~
Now I can fully utilize my screen width!~

2010年2月7日星期日

关于func_get_args()的小错

今天帮同学部署一个小网站,用了php,还有ajax。结果在他们本机调试很好,我弄到服务器上面,就出了问题:
Fatal error: func_get_args(): Can't be used as a function parameter in ...
这个很奇怪,搜了一下,貌似其实是php的一个限制(bug?),可以参见http://bugs.php.net/bug.php?id=34120
貌似是实现的问题,func_get_args()这个东西不能直接用在函数的参数里面(其实文档这么说,用作第一个参数还是可以的…… 第二个就不行了)。必须要先把它赋给一个变量,然后再作为函数参数。
For example,根据文档,这两个都不行:
a(func_get_args(0));
b(1, func_get_args(0));

但其实,第一个是可以的,第二个会出上面那个错。
改成
$x=func_get_args(0);
a($x);
b(1,$x);
就可以了。
同学说他们的php是5.3.1,服务器上是5.2.12,大概5.3搞定了这个事情吧……

2010年2月3日星期三

终于有图标了

如果你用的是Unix类系统,并且还是非标准桌面(例如LXDE一类……)
并且发现,你启动file-roller,pcmanx,nautilus等的图标都很奇怪或者没有
那么可能是这个问题:系统不知道用啥图标,或者找不到图标
去/usr/local/share/icons(Linux同学们可能没有local)
看看有哪几个是有不少图片的,并且有index.theme的,可能就可以作为图标主题
然后在~/.gtkrc-2.0里面加上:
gtk-icon-theme-name="<目录名>"
就会有图标了……
如果试了都不成,就去装gnome-icons-这个样子的软件包再看看吧……
之前我发现是gnome-settings-daemon运行之后就会有图标
但是我又不喜欢一切都由gnome控制面板一类的设置,gtk-chtheme多好
终于pcmanfm启动的时候,给了个提示,解决了问题……
PS. PCManFM作者还写了PCManX,貌似和LXDE还有关系,真nb……

2009年12月14日星期一

通过IPv6方式访问blogspot的方法

既然GFW短期之内还不会延伸到IPv6上,而GFW对blogspot的封禁看来会一直持续下去,这里给出一个通过IPv6访问blogspot的方法:
在你已经通了IPv6的情况下,其实很简单:在上blogspot的时候,把代理设为ipv6.google.com,端口为80,协议为HTTP。
当然,总是改代理很麻烦。因此可以用各种插件来达到自动切换代理,比如我用的FoxyProxy:
装好之后,在选项里,新建代理服务器,在第二页输入ipv6.google.com和80,在第三页新增URL模板,名字随便起,URL模板写*blogspot.com*,选白名单/通配符,确定,就可以了。也可以再加一个模板,*blogger.com*。
假如大家都会用这个办法了,那原来的Live Space就可以考虑不更新了……

2009年11月19日星期四

利用 bcdedit 解决 Vista 启动问题

前一段时间,把系统原来的还原分区(一个NTFS)清了,在那里装了FreeBSD 8/amd64。之后发现,FreeBSD的分区引导记录很不行,他只找活动分区启动,而不管自己是哪个分区的引导记录(大概也不知道……),所以从原来的BSD切换到新装的很麻烦,要手动改活动分区。于是就装了个grub4dos,折腾了半天终于好了。装完之后,尝试新菜单,发现Vista进不去了…… 提示大概是这样的:\Windows\system32\winload.exe 文件未找到或者已损坏 错误0xc000000e。试了一下,发现Vista启动菜单里面其他的项目也用不了了。
想了一下,多半是干掉那个还原分区之后,Windows所在的分区成了第一个Windows能够认出来的分区,于是这个Boot Loader分不清楚了,不能在老地方找到这个文件了……
先尝试把那个新装了BSD的分区类型改成NTFS,结果Windows还是不认…… 改回去之后,我想只好手动修改启动数据库了。Vista的启动数据库,不像XP就是根目录下面有一个boot.ini,而是在根目录下面\Boot\BCD这个文件里面,还是个二进制文件…… Windows就给了一个bcdedit来弄。
因为进不了Vista,我尝试着用虚拟机里的XP来跑。这个虚拟机同时也把主机的真实硬盘作为第二块硬盘挂在上面。
启动虚拟机,尝试了一下,bcdedit竟然能用,于是拷到WinXP这边来。主机Vista所在的盘在虚拟机里面是D盘,所以在运行bcdedit的时候,后面都要加上/store d:\boot\BCD 。
改的过程其实很少。bcdedit原来那些命令也都能用。
命令里面某一项的GUID,可以通过直接运行 bcdedit /store d:\boot\BCD 来了解,最上面{xxxxxxxx-.....}那个就是了,一串很长的十六进制数。默认项这个可以用{default}代替。
首先,把默认项指定成Vista(原来是老BSD):
bcdedit /store d:\boot\BCD /default <Vista项的GUID>
然后设置默认项设备为分区d(一开始我设了c,结果还是不行…… Windows还是把那个算进去了么……)
bcdedit /store d:\boot\BCD /set {default} device partition=D:
bcdedit /store d:\boot\BCD /set {default} osdevice partition=D:
这就好了。
效果不用重启都能看见。还是利用虚拟机,qemu或者VirtualBox都可以,直接挂主机硬盘,Vista果然跑起来了…… 不过一会儿就蓝屏了……

2009年9月17日星期四

WordPress 多层菜单

下了个主题,发现只支持一级菜单……
去网上,先找了一个Multi-level Navigation插件,但是主题不配合……
继续找,找到那么一篇文章:
WordPress Multi-Level Drop Down menu using jQuery | SEOAdsenseThemes.com
弄到WP里面去,竟然就好了……
其实就是加:
<script type='text/javascript'>
jQuery(document).ready(function() {
jQuery("#dropmenu ul").css({display: "none"}); // Opera Fix
jQuery("#dropmenu li").hover(function(){
jQuery(this).find('ul:first').css({visibility: "visible",display: "none"}).show(268);
},function(){
jQuery(this).find('ul:first').css({visibility: "hidden"});
});
});

</script>
<style type="text/css">
#dropmenu, #dropmenu ul {list-style-type:none; list-style-position:outside; position:relative;z-index:300; width:100%;}
</style>
到HTML页面的head部分里面,然后把原来的
<?php wp_list_pages('title_li=&depth=10'); ?>
换成
<ul id="dropmenu">
<?php wp_list_pages('sort_column=menu_order&title_li='); ?>
</ul>
就行了……

2009年6月2日星期二

gdb的出错消息

一直以来,运行gdb,之后输入 attach <PID>,会收到一些错误消息:
> gdb
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd".
(gdb) attach 7590
Attaching to process 7590
/usr/src/gnu/usr.bin/gdb/libgdb/../../../../contrib/gdb/gdb/solib-svr4.c:1443: internal-error: legacy_fetch_link_map_offsets called without legacy link_map support enabled.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n

/usr/src/gnu/usr.bin/gdb/libgdb/../../../../contrib/gdb/gdb/solib-svr4.c:1443: internal-error: legacy_fetch_link_map_offsets called without legacy link_map support enabled.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n
Reading symbols from /usr/local/kde4/bin/dolphin...(no debugging symbols found)...done.
....
Loaded symbols for /usr/local/kde4/lib/libkfontinst.so.5
Reading symbols from /libexec/ld-elf.so.1...done.
Loaded symbols for /libexec/ld-elf.so.1
[Switching to Thread 0x2dd6b260 (LWP 100239)]
0x29be3243 in select () from /lib/libc.so.7
(gdb)
一直也不知道是什么道理…… 今天去网上查,终于看见一个说法:
需要attach的话,只能运行 gdb -p <PID> <exec file>
也就是说,要提供原来的可执行文件,才能attach到一个现有process……
我试了一下,的确好了:
> gdb -p 7590 /usr/local/kde4/bin/dolphin
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd"...(no debugging symbols found)...
Attaching to program: /usr/local/kde4/bin/dolphin, process 7590
Reading symbols from /usr/local/kde4/lib/libkio.so.7...(no debugging symbols found)...done.
Loaded symbols for /usr/local/kde4/lib/libkio.so.7
......
Reading symbols from /libexec/ld-elf.so.1...done.
Loaded symbols for /libexec/ld-elf.so.1
[Switching to Thread 0x2dd6b260 (LWP 100239)]
0x29be3243 in select () from /lib/libc.so.7
(gdb)
貌似这个问题,在GDB里面很早就修正了。FreeBSD随系统自带的GDB还是6.1.1,ports里倒是提供了一个6.6,但是不支持调试多线程的程序…… 不知道啥时候这个事情能够解决……