Archives for: October 2009
dbus-send的基本用法
October 30th, 2009最近工作需要,研究了一下dbus-send命令。基本的命令形式是:
dbus-send --system --print-reply --dest=org.bluez /org/bluez/audio org.bluez.audio.Manager.CreateDevice string:'11:11:11:11:11:11'
其中:
- --system
- 将命令发向系统总线,也可使用--session
- --print-reply
- 打印返回结果
- --dest=org.bluez
- 服务名。用户可以用查询命令获得当前系统的所有服务名
- /org/bluez/audio
- 对象名。由服务定义
- org.bluez.audio.Manager.CreateDevice
- object.interface.Method
- string:'11:11:11:11:11'
- 参数。 类型:值 int32:123
dbus的一些基本服务
查看system bus上面挂载的services
dbus-send --system --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListActivatableNames
查看session bus上面挂载的services
dbus-send --session --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListActivatableNames
dbus的基本服务
dbus-send --system --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.Introspectable.Introspect
List service??
dbus-send --system --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames
Coco/R: A LL(1) parser generator
October 25th, 2009Link: http://www.scifac.ru.ac.za/coco/
最近,我发现一个LL(1)parser generator,它像antlr,但是好像简单一些。
平心而论,我对antlr的LL(k) parser很没有信心。根据以前的经验,如果lex+lemon只要200k的话,对应的antlr LL(k) parser要>1M. 不过通过阅读其他人的经验,好像LL(1)的实现其实要小巧和快速一些。可能antlr的实现有问题。因此我决定在试试Coco/R.
另外一个原因是Coco/R支持原生的多语言。我准备用ruby来试试LL(1)的c语言parser.
Coco/R的官方网站上提供了电子版的书籍 Compilers and Compiler Generators: An Introduction with C++
Ruby Binary File Process: BinData
October 23rd, 2009Link: http://bindata.rubyforge.org/
今天,我发现了一个很棒的用来处理binary数据的库:BinData.我用它写了一个将TI bts格式的文件转换为h4 binary文件的工具。
使用中发现以下诀窍:
对于数组: array, 定义长度必须是 :initial_length=> 5 or :dep_size. ( dep_size is name of size field )
LALR(1) vs LL(1)
October 22nd, 2009Link: http://compilers.iecc.com/comparch/article/95-11-234
今天我研究了一下语法分析算法,分别是LL(1)和LALR(1)。在comp.compiler上看到一个很有趣的争论,总结如下:
LALR(1) (yacc)
Pro:
语法自然简洁
语法表达力强
Con:
1,yacc容易出错,grammer文件需要各种hack来使yacc接受,
2,分析速度稍慢
3,错误恢复难
4,生成语法树难
LL(1) (handwrite recurise parser)
Pro:
容易实现
速度快
容易理解和维护
易于错误恢复
易于生成语法树
Con:
语法表现力差
为适合LL(1)语法,经常需要改写语法,导致语法不自然和难懂
Ruby/Perl Regex special chacter
October 21st, 2009Link: http://www.rubyist.net/~slagell/ruby/regexp.html
[] range specificication (e.g., [a-z] means a letter in the range a to z)
\w word character; same as [0-9A-Za-z_]
\W non-word character
\s space character; same as [ \t\n\r\f]
\S non-space character
\d digit character; same as [0-9]
\D non-digit character
\b backspace (0x08) (only if in a range specification)
\b word boundary (if not in a range specification)
\B non-word boundary
* zero or more repetitions of the preceding
+ one or more repetitions of the preceding
{m,n} at least m and at most n repetitions of the preceding
? at most one repetition of the preceding; same as {0,1}
| either preceding or next expression may match
() grouping
Unix env in Windows
October 20th, 2009I like bash of Linux and all small command. I have spend a lot of time to learn how to use them effectively. Windows' command is very naive, I hope I can find bash in Windows.
First choice is cygwin or mingw. But they are too heavy and a bit slow. And they are not compatible with other none-unix program. Furthermore, I can't use my favorite gvim in cygin envoriment since it has its xwin version gvim.
After googling "bash windows", I notice there are a link: bash for win32 and UnixUtils for win32. Combining them, I can get an Unix like environment satisfying me.
And here is a great wiki site contains information Bash_and_Windows
Bash for Win32
Filesystem Root and Driver map
It treat c:\ as root directory, mount other driver such as D:\ in //d/.
Install
Create tmp
You must create /tmp directory, ie c:\tmp for it.
Home Directory
Set envoriment HOME to indicate which directory is home. And copy .bashrc into home directory.
Using path as prompt
Add following line in .bashrc
PS1='\w\$'
Make bash visible in Windows Explorer Context Menu
Rational
HKEY_CLASSES_ROOT
|-Directory
|-shell
|-BashHere "&Bash Here"
|-command "C:\tools\bash.exe"
BashHere.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\BashHere]
@="&Bash Here"
[HKEY_CLASSES_ROOT\Directory\shell\BashHere\command]
@="c:\\Tools\\bash.exe"
Unix Utils
Install
Just put usr directory into c:/usr to simulate /usr
Make sure c:/usr/wbin is at the first position in system PATH environment variable to avoid using windows "find" command.
vncviewer in ubuntu
October 19th, 2009Today, I installed vncviewer in ubuntu. Since I used tightvncserver before, apt-get automaticly to select tightvncviewer for me. Unfortunatly, after I enter full-screen mode, it doesn't come back to normal mode any more. If you press F8, nothing appears.
After googles something, I remove tightvncserver and install xvnc4viewer and everything is ok now.
A little tips, for password, you must using
vncviewer -passwd passwd_file_name .....
passwd_file_name can be a file copy from server's ~/.vnc directory.
You can use
vncserver -list
vncserver -kill
command to query xvnc session and kill xvnc server session.