Posts

regexec(3)'s usage:Match Results with Subexpressions

http://www.gnu.org/software/libc/manual/html_node/Regexp-Subexpressions.html#Regexp-Subexpressions An example program: #include <stdio.h> #include <sys/types.h> #include <regex.h> /* 取子串的函数 */ static char* substr(const char*str,                 unsigned start, unsigned end) {         unsigned n = end - start;         static char stbuf[256];         strncpy(stbuf, str + start, n);         stbuf[n] = 0;         return stbuf; } /* 主程序 */ int main(int argc, char** argv) {         int x, z, lno = 0, cflags = REG_EXTENDED;         char ebuf[128], lbuf[256];         regex_t reg;         regmatch_t pm[10];         const size_t nmatch = 10;         /* 编译正则表达式*/         z = regcomp(&reg, "(reg|regular)[ ]?(ex|expression)", cflags);         /* 逐行处理输入的数据 */         while(fgets(lbuf, sizeof(lbuf), stdin))         {                 ++lno;                 if ((z = strlen(lbuf)) > 0 && lbuf[z-1]                                 == '\n')            

sed处理多行技巧的应用

sed -i -e  ' #找到有下面这段字的行 /在这段时间内被修正或解决的bug/ { #读入下面一行 N #如果下面一行以</ul>开头 /\n<\/ul>/ { #就替换一下 s/在这段时间内被修正或解决的bug/bug在这段时间被标记为重复/ } }' *

Starcraft, Cedega and TLS

I have tried to play starcraft in Linux using Wine. But the speed was unacceptable. I've heard from others that wine works for them. However, it doesn't work here. So I tried cedega days ago. The result is quite satisfactory! I don't need to return to Windows to play starcraft any more. Yesterday I looked into the details of accessing thread local storage. I wrote a small kernel module to get the base address of insmod process's tls segment, and then print the value of AT_SYSINFO #include <linux/init.h> #include <linux/module.h> #include <asm/desc.h> static int __init mod_init(void) {         int i=0, a=0, b=0, h, l;         int *ptr=(int *)get_cpu_gdt_table(0);         for(; i<28; i++){                 l = *ptr++;                 h = *ptr++;                 if (i==6){                         b = h;                         a = l;                 }                 printk("0x%08x", h);                 printk(" %08x", l);          

screen, gdb, vdso and gentoo

Screen的中文乱码问题有了一点新进展。今天我了解到,如果使用中文,但使用gb字符集的时候,中文是正常的。UTF-8则是乱码。这对于解决这个问题应该有所帮助。 今天在Planet Larry上看到一篇blog,对我很有帮助。那里面提到一个gdb的初始加载文件,类似.bashrc。有很多有用的功能。比如在断点停住的时候,可以显示寄存器,堆栈等的内容和要执行的指令的上下文的反汇编。作者对这个文件加了点改进可以显示不同的颜色。 http://gnurbs.blogsome.com/2006/12/22/colorizing-mamons-gdbinit/ 用了这个东西,基本可以抛弃emacs+gdb的组合了。毕竟emacs-23现在和gdb配合使用,我感觉还不是很稳定。 还看了这一篇文章, http://www.win.tue.nl/%7Eaeb/linux/lk/lk-4.html 不过里面最后一个例程应该是有点问题,改成这样就行了: #include <stdio.h> int pid; int main() {         __asm__ __volatile__(                 "movl $20, %%eax        \n\t"                 "movl $0xffffe400, %%ebx \n\t"                 "call *%%ebx            \n\t"                 "movl %%eax, %0         \n\t"                 : "=r"(pid)                 :                 : "ax", "bx"         );         printf("pid is %d\n", pid);         return 0; } 最后,今天发展了一个gentoo用户。基本上我帮他装的。有两点感觉: 1. 复制livecd安装真的很方便,很快 2. 一般Linux用户,特别是英文不怎么好的用户,安装gentoo,

screen: RAW_PUTCHAR()

如果screen的caption里有日期,星期,比如: caption always "%{= kw}%-w%{= BW}%n %t%{-}%+w %-= @%H - %LD %d %LM - %c" 而且使用的又是中文locale 那么日期星期会乱码 大概看了一下源代码,发觉应该和display.c里的RAW_PUTCHAR()有关

龙芯电脑的预定确认信

尊敬的客户您好: 首先向您表示诚挚的祝贺和由衷的谢意!我谨代表江苏中科龙梦科技有限公司,对您的积极参与表示感谢,同时很荣幸地通知您,您被我公司选择作为首批次龙芯福珑迷你电脑用户。您拥有选择和拒绝购买的权利。 为了表达对一直以来支持和鼓励我公司不断取得进步的朋友们的谢意,同时也为了龙芯事业的稳步发展,我公司在相对公平公正的基础上,对首批次福珑迷你电脑使用者进行了简单有效的选择,您是其中一位。希望龙芯福珑迷你电脑能在您手中物尽其用,如果您有任何问题,可以随时与我们取得联系,我们将尽可能帮助您解决。 另外,请购买者务必确定您的地址、联系方式是正确有效的,如因此出现的任何问题,我公司将不负责任。另外请注意,目前我公司尚未开通资金帐号,请不要急于打款,具体的返款措施,我们将于后期公布。 在此回执的客户我们将正式登记记录 , 正式生效 .       江苏中科龙梦科技有限公司市场部 http://www.lemote.com                               2006.12.08

Godon's picture

Image
龙芯的照片 这是个2C,不是最近卖的2E 我发email预定了2E,想看看能不能移植Gentoo过去,不过没有给我 也罢,就先摆弄2C玩玩看吧