2010年10月16日星期六

[转载]让Blogspot支持语法高亮


让Blogspot支持语法高亮

语法高亮支持,几乎成了所有和计算机沾那么一点边的博主所必须的功能了。不过Blogger默认没有语法高亮支持。虽然如此,要加入语法高亮支持却并不困难。这主要得益于Blogger强大的模版编辑功能。

对Blogger的奉承话我就不多说了,开始讲解方法:

1. 下载语法高亮包(到这里)。

2. 下载并解压缩,我下载的版本是2.1.364,里面有三个目录:scripts,styles和src。

3. 把scripts里面的js文件上传到某个托管站。如果你和我一样穷的没有网站空间,你可以上传到Google Sites(Google Sites不支持外链,不过你可以上传到DropBox中)。其中最重要的文件是:shCore.js。其他都是各种语言的语法支持文件。你可以选择自己常用的上传。shLagacy.js可以不用上传。这个文件主要用来支持旧版高亮配置语法的。另外可以顺道把scripts里的clipboard.swf也上传了。

4. 上传styles里面的代码主题到托管空间。主要上传shCore.css,所有png文件和你想使用的主题文件。你想使用默认主题,上传:shThemeDefault.css就可以了。在上传shCore.css之前还需要做一件事,把191行,202行,207行,219行里的xxx.png,换成完整的图片地址,如下:
1#... {
2    ...
3    background-image:url('http://dl.dropbox.com/u/169xxxx/syntax_highlighter/magnifier.png')!important;
4    ...
5}
6/*其他类似*/

5. 打开博客后台,访问“Design” - “Edit HTML”,在<head>标签内加入下面的代码:
1<linkhref="http://dl.dropbox.com/u/169xxxx/syntax_highlighter/shCore.css"rel="stylesheet" type="text/css"></link>
2<linkhref="http://dl.dropbox.com/u/169xxxx/syntax_highlighter/shThemeDefault.css"rel="stylesheet" type="text/css"></link>
3<script language="javascript"src="http://dl.dropbox.com/u/169xxxx/syntax_highlighter/shCore.js">
4</script>
5<script language="javascript"src="http:/dl.dropbox.com/u/169xxxx/syntax_highlighter/shBrushJScript.js">
6</script>
在做出任何修改前,最好先备份默认模版,以防出错。

6.在</body>标签之前加入下面代码:
1<script type="text/javascript">
2    SyntaxHighlighter.config.bloggerMode = true;
3    SyntaxHighlighter.config.clipboardSwf = 'http://dl.dropbox.com/u/169xxxx/syntax_highlighter/clipboard.swf';
4    SyntaxHighlighter.all()
5</script>

7. 保存模版。
在撰写Blog的时候,可以这样:
<pre class="brush: js">
  alert('Hello world.');
  //Whatever code here
</pre>
会生成:
1alert('Hello world.');
2  //Whatever code here

关于语法高亮的安装和使用的更多详情,请参考项目wiki。额外参考:这里

update: 经过实践才发现Google Sites不支持外链。Orz,所以换成Dropbox了,测试似乎没有问题。请将文中的dropbox链接换成你自己的。

2010年10月6日星期三

[转载]ldd命令原理与使用

原文:http://hi.baidu.com/buptwangxin/blog/item/89542ecb655eba4ff31fe72c.html
  
作用:用来查看程序运行所需的共享库,常用来解决程序因缺少某个库文件而不能运行的一些问题。

1、首先ldd不是一个可执行程序,而只是一个shell脚本
2、
ldd能够显示可执行模块的dependency,其原理是通过设置一系列的环境变量,如下:LD_TRACE_LOADED_OBJECTS、
LD_WARN、LD_BIND_NOW、LD_LIBRARY_VERSION、LD_VERBOSE等。当
LD_TRACE_LOADED_OBJECTS环境变量不为空时,任何可执行程序在运行时,它都会只显示模块的dependency,而程序并不真正执
行。要不你可以在shell终端测试一下,如下:
(1) export LD_TRACE_LOADED_OBJECTS=1
(2) 再执行任何的程序,如ls等,看看程序的运行结果
3、
ldd显示可执行模块的dependency的工作原理,其实质是通过ld-linux.so(elf动态库的装载器)来实现的。我们知道,ld-
linux.so模块会先于executable模块程序工作,并获得控制权,因此当上述的那些环境变量被设置时,ld-linux.so选择了显示可执
行模块的dependency。
4、实际上可以直接执行ld-linux.so模块,如:/lib/ld-linux.so.2 --list program(这相当于ldd program)
ldd命令使用方法(摘自ldd --help)
名称    ldd - 打印共享库的依赖关系
大纲    ldd [选项]... 文件...
描述    ldd 输出在命令行上指定的每个程序或共享库需要的共享库。
选项
--version
打印ldd的版本号
-v --verbose
打印所有信息,例如包括符号的版本信息
-d --data-relocs
执行符号重部署,并报告缺少的目标对象(只对ELF格式适用)
-r --function-relocs
对目标对象和函数执行重新部署,并报告缺少的目标对象和函数(只对ELF格式适用)
--help 用法信息
注意:
ldd的标准版本与glibc2一起提供。Libc5与老版本以前提供,在一些系统中还存在。在libc5版本中长选项不支持。另一方面,glibc2版本不支持-V选项,只提供等价的--version选项。
如果命令行中给定的库名字包含'/',这个程序的libc5版本将使用它作为库名字;否则它将在标准位置搜索库。运行一个当前目录下的共享库,加前缀"./"。
错误:
ldd不能工作在a.out格式的共享库上。
ldd不能工作在一些非常老的a.out程序上,这些程序在支持ldd的编译器发行前已经创建。如果你在这种类型的程序上使用ldd,程序将尝试argc = 0的运行方式,其结果不可预知。



!!说明:ldd程序是shell脚本,可以拷贝到其它环境、系统(arm)直接运行!!

2010年10月4日星期一

TQ2440 sound card (uda1341)

Transplant the uda1341 driver to s3c2440 (tq2440 board).

First,let's analysis the source code of uda1341 driver.
sound/soc/s3c24xx/s3c24xx_uda134x.c
 242static struct s3c24xx_uda134x_platform_data *s3c24xx_uda134x_l3_pins;
 290static int s3c24xx_uda134x_probe(struct platform_device *pdev)
 291{
 292        int ret;
 293
 294        printk(KERN_INFO "S3C24XX_UDA134X SoC Audio driver\n");
 295
 296        s3c24xx_uda134x_l3_pins = pdev->dev.platform_data;
   /*here the probe() only take the platform_data from platform_device, and the corresponding type is s3c24xx_uda134x_paltform_data, and search the source we find that it is defined in include/sound/s3c24xx_uda134x.h */
 297        if (s3c24xx_uda134x_l3_pins == NULL) {
 298                printk(KERN_ERR "S3C24XX_UDA134X SoC Audio: "
 299                       "unable to find platform data\n");
 300                return -ENODEV;
 301        }
 302        s3c24xx_uda134x.power = s3c24xx_uda134x_l3_pins->power;
 303        s3c24xx_uda134x.model = s3c24xx_uda134x_l3_pins->model;
 304
 305        if (s3c24xx_uda134x_setup_pin(s3c24xx_uda134x_l3_pins->l3_data,
 306                                      "data") < 0)
 307                return -EBUSY;
 308        if (s3c24xx_uda134x_setup_pin(s3c24xx_uda134x_l3_pins->l3_clk,
 309                                      "clk") < 0) {
 310                gpio_free(s3c24xx_uda134x_l3_pins->l3_data);
 311                return -EBUSY;
 312        }
 313        if (s3c24xx_uda134x_setup_pin(s3c24xx_uda134x_l3_pins->l3_mode,
 314                                      "mode") < 0) {
 315                gpio_free(s3c24xx_uda134x_l3_pins->l3_data);
 316                gpio_free(s3c24xx_uda134x_l3_pins->l3_clk);
 317                return -EBUSY;
 318        }
 319
 320        s3c24xx_uda134x_snd_device = platform_device_alloc("soc-audio", -1);
 321        if (!s3c24xx_uda134x_snd_device) {
 322                printk(KERN_ERR "S3C24XX_UDA134X SoC Audio: "
 323                       "Unable to register\n");
 324                return -ENOMEM;
 325        }
 326
 327        platform_set_drvdata(s3c24xx_uda134x_snd_device,
 328                             &s3c24xx_uda134x_snd_devdata);
 329        s3c24xx_uda134x_snd_devdata.dev = &s3c24xx_uda134x_snd_device->dev;
 330        ret = platform_device_add(s3c24xx_uda134x_snd_device);
 331        if (ret) {
 332                printk(KERN_ERR "S3C24XX_UDA134X SoC Audio: Unable to add\n");
 333                platform_device_put(s3c24xx_uda134x_snd_device);
 334        }
 335
 336        return ret;
 337}


include/sound/s3c24xx_uda134x.h
   1#ifndef _S3C24XX_UDA134X_H_
   2#define _S3C24XX_UDA134X_H_ 1
   3
   4#include <sound/uda134x.h>
   5
   6struct s3c24xx_uda134x_platform_data {
   7        int l3_clk;
   8        int l3_mode;
   9        int l3_data;
   /*the three member above is a l3 interface, and we must register io port to them.*/
  10        void (*power) (int);
  11        int model;
   /*the model is used to identify different types of uda134x, and the Marco is defined in include/sound/uda134x.h */
  12};
  13
  14#endif

include/sound/uda134x.h
   1/*
   2 * uda134x.h  --  UDA134x ALSA SoC Codec driver
   3 *
   4 * Copyright 2007 Dension Audio Systems Ltd.
   5 * Author: Zoltan Devai
   6 *
   7 * This program is free software; you can redistribute it and/or modify
   8 * it under the terms of the GNU General Public License version 2 as
   9 * published by the Free Software Foundation.
  10 */
  11
  12#ifndef _UDA134X_H
  13#define _UDA134X_H
  14
  15#include <sound/l3.h>
  16
  17struct uda134x_platform_data {
  18        struct l3_pins l3;
  19        void (*power) (int);
  20        int model;
  21#define UDA134X_UDA1340 1
  22#define UDA134X_UDA1341 2
  23#define UDA134X_UDA1344 3
  24#define UDA134X_UDA1345 4
  25};
  26
  27#endif /* _UDA134X_H */
  28
Next, initialize the platform_device in mach-s3c2440/tq2440.c (your board specified file)

/*for sound car UDA 1341*/
#include <sound/s3c24xx_uda134x.h>

/*for sound card uda1341*/
static struct s3c24xx_uda134x_platform_data tq2440_uda1341_platform_data = {
.l3_clk = S3C2410_GPB(4),
.l3_mode = S3C2410_GPB(2),
.l3_data = S3C2410_GPB(3),
.model = UDA134X_UDA1341,
};
static struct platform_device tq2440_device_uda1341 = {
.name = "s3c24xx_uda1341",/*the name must be confronted to the driver*/
.id = 0,
.dev = {
.platform_data = &tq2440_uda1341_platform_data,
}
};

static struct platform_device *tq2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&tq2440_device_dm9000, //for DM9000//
&s3c_device_usbgadget, //for s3c USB device, the struct already included in plat/devs.h
&s3c_device_ac97, //for s3c AC97
&tq2440_device_uda1341 //for soundcard uda1341
};

And don't forget to enable the uda134x driver in the kernel configure.


After compiling the the kernel, if you built it as a module, and then just run “modprobe snd-soc-s3c24xx-uda134x”.By the way, if you need oss support, for example, mplayer was built without alsa support, you can load oss module with the command “modprobe snd-pcm-oss”.