#!/bin/bash # filename : chout #usage : chout string # composer: tick ares=`find -name '*.c'` ares="$ares `find -name '*.h'`" #ares="`find -name '*.c'` `find -name '*.h'` " 也是可以的啦 for arrs in $ares do if [ -f $arrs ] && (( `cat $arrs | grep -i $1 | wc -l` > 0 )); then echo "In file $arrs" cat $arrs | awk '{print "#"NR"\t"$0}' | grep -i $1 echo " " fi done 這個小小的工具可以幫你找到目錄下所有有你想找的字串的檔案 其實沒什麼,只是在我 debug 時很有用,和大家分享一下 Very Happy 例如你要找目錄下有 config_pbs 字串的(.c .h)檔案 就打入 chout config_pbs 就會找到了 現在的新版的LXR(0.9x)已經有支援CVS的功能了 不會安裝的人 可以參考這篇 http://www.linuxsir.org/bbs/showthread.php?t=246594 標題: [源碼閱讀] lxr Linux交叉索引 lxr: Linux Cross-Reference 0.31 (stable) for Debian 最近看源碼,找到這個工具,不知道對大家是否有用。 本文與README.Debian稍有出入 安裝perl 安裝Web服務器(apache2) 安裝glimpse(可選) 安裝目錄為 /var/lib/lxr 1) 建立目錄 - 源碼目錄 以2.6.15版本為例 假設源碼放在/usr/src/linux-2.6.15中,可以用 # cd /var/lib/lxr/source/ # ln /usr/src/linux-2.6.15 -s linux-2.6.15 當然也可以直接將源碼放到此目錄中。建立其它版本的源碼目錄,例 source |-- linux-0.11 |-- linux-1.0 |-- linux-2.2.25 |-- linux-2.4.27 `-- linux-2.6.15 創建文件versions,寫入版本的列表 代碼: linux-0.11 linux-1.0 linux-2.2.25 linux-2.4.27 linux-2.6.15 創建文件defversion,寫入顯示的默認版本 linux-2.6.15 - 索引目錄 建立這個目錄是為了方便管理文件 # mkdir /var/lib/lxr/databases # cd /var/lib/lxr/databases # mkdir linux-0.11 ... 2) 配置Web服務器 以apache2為例 創建文件 /etc/apache2/site-available/lxr 寫入: PHP 代碼: # Linux Cross Reference Stuff # 以http://hostname/lxr 建立訪問 # 允許/var/lib/lxr能被用戶訪問 Alias /lxr /var/lib/lxr Options All AllowOverride All # ln /etc/apache2/site-available/lxr -s /etc/apache2/site-enable/lxr 創建文件 /var/lib/lxr/http/.htaccess 寫入: PHP 代碼: SetHandler cgi-script 3) 配置LXR 修改配置文件 /var/lib/lxr/http/lxr.conf: PHP 代碼: # Configuration file. # Define typed variable "v", read valueset from file. # 版本列表的位置 variable: v, Version, [/var/lib/lxr/source/versions], [/var/lib/lxr/source/defversion] # Define typed variable "a". First value is default. # 顯示源碼的架構版本 variable: a, Architecture, (i386, alpha, m68k, mips, ppc, sparc, sparc64) # Define the base url for the LXR files. # 服務器的地址,地址最後必須包括 " / " baseurl:http://localhost/lxr/ # These are the templates for the HTML heading, directory listing and # footer, respectively. # 顯示網頁的格式 htmlhead: /var/lib/lxr/http/template-head htmltail: /var/lib/lxr/http/template-tail htmldir: /var/lib/lxr/http/template-dir # The source is here. # 源碼目錄位置 sourceroot: /var/lib/lxr/source/$v/ # 顯示源碼的名稱 srcrootname: $v # "#include " is mapped to this directory (in the LXR source # tree) incprefix: /include # The database files go here. # 放置lxr數據庫索引文件的目錄 dbdir: /var/lib/lxr/databases/$v/ # Glimpse can be found here. # glimpse安裝位置 glimpsebin: /usr/bin/glimpse # The power of regexps. This is pretty Linux-specific, but quite # useful. Tinker with it and see what it does. (How's that for # documentation?) map: /include/asm[^/]*/ /include/asm-$a/ map: /arch/[^/]+/ /arch/$a/ 4) 生成數據文件 # cd /var/lib/lxr/source 生成lxr的數據庫文件 # /var/lib/lxr/bin/genxref linux-2.6.15 # mv fileidx ../databases/linux-2.6.15/ # mv xref ../databases/linux-2.6.15/ 生成glimpse數據庫(參考glimpse --help生成其它數據) # glimpseindex -H . linux-2.6.15 # mv .g* ../databases/linux-2.6.15 允許數據文件可訪問 # chmod +r ../databases/linux-2.6.15/* # chmod +r ../databases/linux-2.6.15/.g* 5) 使用 重啟Web服務器,訪問 http://localhost/lxr/http/blurb.html *** 如果出現錯誤 - 確保Web訪問權限正確; - 能執行Perl腳本; - 查看error.log。 如果用diff markup出錯,對diff打補丁 // diff.path PHP 代碼: --- diff.old 1998-05-14 20:01:45.000000000 +0800 +++ diff 2006-03-13 22:00:39.000000000 +0800 @@ -130,7 +130,7 @@ } } - close(); + close(DIFF); print("

Diff markup

\n", --------------------------------------------- 0.94-cvs for Debian 版本特性: - 使用數據庫而不再使用數據文件,更新索引時只檢查修改過的文件, 而不用重新建立全部索引; - 目標支持多種編程語言而不只是C,ASM; - 支持CVS - 支持swish-e索引 因為此版本用到數據庫,如果是從網站上下載的lxr安裝文件,要注意的是 mysql 5.0中 'release'為保留字,lxr建立的表中恰好有它,如果不改 代碼的話,運行會出錯;如果不會改代碼,最好就用mysql4或postgres。 # apt-get install lxr-cvs - 安裝mod_perl libapahce2-mod-perl - 安裝數據庫 mysql, postgresql - 安裝perl-數據庫接口 libdbd-mysql-perl (mysql), libdbd-pg-perl (postgre) 1) 建立目錄 - 源碼目錄 方法同上 這個版本的目錄可放在任意位置(stable版的好像也可以) 所以我放在/usr/src中的目錄就不改動了 - 索引目錄 存放用glimpse或swish生成的索引文件 # cd /var/lib/lxr-cvs # mkdir databases(存放glimpse生成的索引) # mkdir index(存放swish生成的索引) 2) 建立數據庫 MySQL: # mysql -u root 執行 ==> \. /usr/share/doc/lxr-cvs/examples/initdb-mysql Postgresql: # su postgres 創建用戶 lxr $ createuser lxr 創建數據庫 $ createdb -U lxr lxr 建立數據庫 $ psql -U lxr lxr 執行 ==> \i /usr/share/doc/lxr-cvs/examples/initdb-postgres 3) 配置Web服務器 創建文件 /etc/apache2/site-available/lxr-cvs 寫入: PHP 代碼: Alias /lxr /var/lib/lxr-cvs AllowOverride All 如果不用mod_perl,將Alias 改為 ScriptAlias # ln /etc/apache2/site-available/lxr-cvs -s /etc/apache2/site-enable/lxr-cvs # cp /usr/share/doc/lxr/cvs/examples/htaccess /var/lib/lxr-cvs/lxr/.htaccess 如果不用mod_perl # cp /usr/share/doc/lxr/cvs/examples/htaccess_cgi /var/lib/lxr-cvs/lxr/.htaccess htaccess_cgi PHP 代碼: Options Indexes ExecCGI FollowSymlinks order deny,allow deny from all deny from all SetHandler cgi-script ForceType text/html htaccess PHP 代碼: Options Indexes ExecCGI FollowSymlinks order deny,allow SetHandler perl-script # Apache 2 PerlHandler ModPerl::Registry # Apache 1.3: uncomment next line and comment the previous line #PerlHandler Apache::Registry PerlSetEnv PERL5LIB lib ForceType text/html PerlSendHeader On 4) 修改 lxr 配置文件. (/etc/lxr-cvs/lxr.conf) PHP 代碼: 服務器的地址要標明,因為這個版本是根據地址來生成訪問頁面的。 'baseurl' => 'http://hostname/lxr', 如果不加上別名,會用不了localhost來訪問 'baseurl_aliases' => [ 'http://localhost/lxr' ], 根據數據庫類型來選擇perl接口 # For mysql, the format is dbi:mysql:dbname= # for Postgres, it is dbi:Pg:dbname= # for Oracle, it is dbi:Oracle:host=localhost;sid=DEVMMS;port=1521 'dbname' => 'dbi:Pg:dbname=lxr', (postgres) 源碼目錄 'sourceroot' => '/usr/src', 顯示名稱 'sourcerootname' => 'LXR $v', 數據庫用戶和密碼 'dbpass' => 'foo', 'dbuser' => 'lxr', 使用glimpse索引 'glimpsedir' => '/var/lib/lxr-cvs/databases', 使用swish-e索引 'swishdir' => '/var/lib/lxr-cvs/index/', 5) 建立交叉索引 # genxref --url=http://hostname/lxr --allversions (全部) 或 # genxref --url=http://hostname/lxr --version=linux-2.X.Y 這個時間會很久,大概一個2.X的要2∼3小時吧 在瀏覽器中 http://localhost/lxr/source 如果查看少於兩個字符或名稱含有'-'的目錄無法打開 對Common.pm打補丁(/usr/share/perl5/LXR/) PHP 代碼: --- Common.pm.old 2005-05-05 07:19:33.000000000 +0800 +++ Common.pm 2006-03-13 22:12:11.000000000 +0800 @@ -539,9 +539,9 @@ if(defined $path) { # First suppress anything after a dodgy character - $path =~ s!(^[w_+-,.%^/]+).*!$1!; + $path =~ s!(^[w_+-,.%^/]+).*!$1!; # Clean out /../ - while ($path =~ m!/../!) { + while ($path =~ m!/../!) { $path = s!/../!/!g; } }