Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Wednesday, March 07, 2012

高亮 LXR 的代碼

資料來源:高亮 LXR 的代碼


LXR ── Linux Cross Refercence。Linux內核源碼閱讀和查詢的利器之一,不用多介紹了。LXR安裝後看到的源碼是沒有顏色的,用慣了語法高亮的編輯器,一下子看到滿屏的黑白代碼不免有點枯燥。於是給它裝了個可以顯示語法顏色的工具。
1、安裝google-code-prettify
項目地址是:http://code.google.com/p/google-code-prettify/
$ wget http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css
$ wget http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js
我把它們放到lxr的安裝目錄下面,lxr我放在web服務器的根目錄,所以就
2、修改lxr/http/template-head
這是lxr默認的html頭,在<head></head>標籤之間加上
1<link href="/lxr/prettify.css" type="text/css" rel="stylesheet" />
2<script type="text/javascript" src="/lxr/prettify.js"></script>
注意文件路徑,不在乎需要從遠方服務器讀取的話,也可以
1<link href='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css' rel='stylesheet' type='text/css'/>
2<script src='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js' type='text/javascript'></script>
這樣也可以讓google-code-prettify的維護者來自行維護這些腳本。
然後找到<body>標籤:
1<body bgcolor=white>
改為
1<body bgcolor=white onload='prettyPrint()'>
3、修改lxr/http/source
這是個perl腳本,查找字符串"<pre>",這有好幾處,都在printfile這個子函數裡面,改為
1<pre class=/"prettyprint/">
已經好了,這樣再看LXR裡面的代碼就可以看到漂亮的語法顏色了。效果圖:
2009-05-01 Update:
上面的效果圖有一個問題,就是代碼的行號也被渲染高亮了。這個可以通過給行號標識加上"nocode"這個prettifier提供的class來解決。對lxr/http/lib/LXR/Common.pm進行如下修改即可:
diff --git a/Common.pm b/Common.pm
index 9e23088..529d5a2 100755
--- a/Common.pm
+++ b/Common.pm
@@ -151,7 +151,7 @@ sub linetag {
$tag .= ' ' if $_[1] < 10;
$tag .= ' ' if $_[1] < 100;
$tag .= &fileref($_[1], $_[0], $_[1]).' ';
- $tag =~ s/<a/<a name=L$_[1]/;
+ $tag =~ s/<a/<a class="nocode" name=L$_[1]/;
# $_[1]++;
return($tag);
}
還可以在自己的css文件裡面重寫nocode這個class,例如加個方框啥的。

Ubuntu 環境下安裝 LXR

資料來源:Ubuntu 環境下安裝 LXR

由於項目需求,需要搭建一套代碼索引環境,經過網上查找,瞭解可以使用LXR (the Linux Cross Referencer)來做,同時網上有很多搭建方法,我嘗試學習,一步一步搭建環境,在這個過程中,遇到一些問題,記錄下來,分享給大家,方便大家順利完成LXR 搭建。 

環境:Ubuntu 10.10,新安裝的系統,具體搭建步驟如下(整個過程中基本都需要root權限): 

1.安裝apache2 
sudo apt-get install apache2 

2.安裝Glimplse 
. Glimplse 
# wget http://webglimpse.net/trial/glimpse-latest.tar.gz 
# tar xvzf glimpse-latest.tar.gz 
# cd glimpse-4.18.6 
# ./configure 
# make 

我在make 的時候報下面的錯

make[1]: flex: Command not found

make[1]: *** [lex.yy.c] Error 127

make[1]: Leaving directory `/usr/local/src/glimpse-4.18.6/dynfilters'

make: *** [build-sub] Error 2

在編譯之前,首先看看你的機器上是否已經安裝了flex,因為編譯glimpse的時候需要這個軟件。如果沒有的話,那麼進行安裝:
sudo apt-get install flex
 

執行 

# make 
# sudo make install 

3.安裝lxr 
sudo apt-get install lxr 

4. 對文件做映射 
在/etc/apache2/httpd.conf 在裡面添加以下內容: 
Alias /lxr /usr/share/lxr 
<Directory /usr/share/lxr> 
Options All 
AllowOverride All 
</Directory> 
這樣可以達到http://localhost/lxr/ =>/usr/share/lxr 

5. 在/usr/share/lxr/http下創建文件 .htaccess, 並寫入一下內容
<Files ~ (search|source|ident|diff|find)$> 
SetHandler cgi-script 
</Files> 

6.啟動apache2 
sudo /etc/init.d/apache2 restart 

7. 下載linux 源代碼 
linux內核源碼下載地址http://www.kernel.org/,我下載了2.6.39.4版本的linux 源碼,默認下載到/home/beaver(beaver是我的用戶名,根據大家的機器而定)/Downloads,解壓後為linux-2.6.39.4 

創建/usr/share/lxr/source/XX  目錄 (XX為版本號) 
mkdir /usr/share/lxr/source/2.6.39.4 
然後在/usr/share/lxr/source/2.6.39.4下創建linux符號連接 
ln -s /home/beaver/Downloads/linux-2.6.39.4 /usr/share/lxr/source/2.6.39.4/linux 
                  (源碼地址) 

8. 創建/usr/share/lxr/source/versions 文件,這裡記錄所有要看的版本,內容是 
2.6.39.4 
2.6.22(可有可無) 
要保證2.6.39.4 =>/usr/share/lxr/source/2.6.39.4 
創建/usr/share/lxr/source/defversion 文件,這裡記錄缺省要看的版本,內容是 
2.6.39.4 
之所以是這兩個文件,見/usr/share/lxr/http/lxr.conf裡的相關設置 

9. 建立索引 
cd /usr/share/lxr/source/2.6.39.4/ 
生成關鍵字交叉索引數據庫 
sudo genxref linux 
接下來要等待一段比較長的時間,因為它要掃瞄文件。這樣會在當前目錄生成fileidx和xref 
接下來,生成freetext交叉索引數據庫: 
sudo glimpseindex -H /usr/share/lxr/source/2.6.39.4/ /usr/share/lxr/source/2.6.39.4/linux 
(需要等待一段時間) 
之所以是這個目錄(/usr/share/lxr/source/2.6.39.4/),見/usr/share/lxr/http/lxr.conf裡的相關設置(database項) 

10.修改屬性,使任何人都可以讀取改文件 
sudo chmod +r -R /usr/share/lxr/source/2.6.39.4/* 
sudo chmod +r /usr/share/lxr/source/2.6.39.4/.glimpse*  (注意:這句命令必須執行,否則在 file search 的時候會出現警告:Warning: Could not open .glimpse_filenames) 

11.啟動apache,查看源碼 
sudo /etc/init.d/apache2 restart 
http://localhost/lxr/http/blurb.html //成功查看源碼 
閱讀的時候可以看到頁面頂部有 
~ [ source navigation ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~ 
source navigation是用戶查看頁面的界面 
identifier search是查找某個變量名、結構名、函數名的界面 
freetext search是查找任何字符串的界面 
file search查找某個文件 


參考文件: 
http://blog.sina.com.cn/s/blog_6c6d405f0100oq6l.html 
http://www.linuxsir.org/bbs/showthread.php?t=246594 
http://linux.chinaunix.net/techdoc/system/2006/12/21/946450.shtml 
http://yp.oss.org.cn/software/show_resource.php?resource_id=1044 
http://wenku.baidu.com/view/7d3c0471f242336c1eb95e13.html 
收藏: 
http://blog.csdn.net/fengyanhui/article/details/6320117 

Thursday, March 01, 2012

An important note about Notes

平常就有在使用 ubuntu notes 的習慣, 今天想說到 web 介面去看一些 note, 不料, 怎麼沒有 notes 的介面呢?
後來找一找, 去 ubuntu blog 看到這個標題 An important note about Notes , 點進去看後, 沒想到 ubuntu 居然把 web 介面的 notes 移掉了...害我現在在 iPad or iPhone 上都不能看了!
有人知道有軟體可以在 iOS 上看嗎?