Archive for April, 2010

知道为什么beagle搜不到我想要的了

April 30, 2010

对任意一个文件,beagle在做索引的时候,会有一个maxFieldLength,默认值是10000,也就是说,一个文件里,索引完前10000 个单词之后,剩下的就会全部被丢弃。 …

这俩是干嘛的?

April 30, 2010

这俩看到出现的地方还挺多,应该是很重要的东西,不知道怎么用呢?

        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2";
        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/email_v2";

beagle-grep.sh为什么搜不到

April 28, 2010
在这个文件`android/packages/providers/ContactsProvider/src/com/android/providers/contacts/ContactsProvider2.java`里,用beagle搜不到`getDataMimeType`,不知是为什么?有时间看一下。

用beagle/grep让阅读海量源代码不再是难题

April 23, 2010

阅读源代码是一门技术活,有一个老外专门写了一本书,《Code Reading》,教人怎样阅读代码,用什么工具阅读代码等等。

我最早用过souce insight(界面挺漂亮,快捷键挺方便),后来用过开源的source navigator(那叫一个慢),对这些工具有一些不满意的地方:

  1. 有局限性。当代码变得复杂,比如C语言里用了很多宏,C++里用了很多继承的时候,用这些工具会找不到,或者找出来很多噪音,这时通常就没办法自己扩展了

  2. 不够快。尤其是当代码量变得庞大,我是说像Android的代码那样,快上两个G了,这些工具基本没法用了。至少是没法直接用,必须分而治之,针对自己感兴趣的部分代码创建不同的阅读项目,这又引出一个新的问题,你怎么能有信心目前看的这个东西跟别的代码项目没有关系呢?如果有关系,并且是很重要的,对你理解代码很有帮助的,那就会浪费时间了。总之让人没有安全感。

后来又使用了tags/cscope。这两个工具再加上grep对阅读不太大的代码库已经足够了,包括Linux Kernel。

但是当阅读Android的代码的时候,单独的grep或者cscope里的正则表达式匹配就不够了,代码库太大,搜索的时间很长。

这时候beagle就派上用场了。Beagle是Novell公司主导开发的开源软件,其中又用到了Apache的Lucene,可以用来做搜索引擎的技术。用beagle可以对任意的文本创建索引,以便加快搜索速度。类似的在Windows上有Live Search。但是beagle的好处在于,它除了有桌面图形界面之外,还有命令行接口!

配合beagle的索引功能,可以让搜索几乎任意大的代码库都只需要很短的时间。具体的配置是用beagle-build-index先生成一个索引,再用beagle-static-query把包含要搜索的字符串的文件列出来,最后再用grep精确定位到这些文件中包含要搜索的字符串的那些行上。

生成beagle索引的方法:

下面是我自己有beagle阅读源代码的具体办法:

首先,在代码库的最上层目录执行:

mkdir .beagle; beagle-build-index --recursive --deny-pattern .beagle --enable-deletion --target .beagle/ .

列出匹配文件的beagle命令是

beagle-static-query --add-static-backend "$beagle_dir" --backend none --max-hits 100000 "$longest_token"|sed -e 's!^file://!!'|grep -v '#'|sort -u|~/.my-beagle-filter

其中,$beagle_dir应该是你的代码库最上层目录下的.beagle文件夹的路径,$longest_token则是我自己处理过的要搜索的正则表达式中的最大的字符数字串,因为beagle建立索引的时候应该是只针对一个一个的单词进行创建的。

后面的那些sed/grep等的处理则是让beagle-static-query的输出变成Posix的路径。~/.my-beagle-filter做一些额外的处理,比如,在阅读Linux Kernel源代码的时候,如果只关注x86的架构,那么就可以在这里把别的架构的文件都过滤掉。

所有的这些配置都可以在http://windows-config.googlecode.com/svn/trunk里找到:

svn co http://windows-config.googlecode.com/svn/trunk

我一般把我的HOME目录里重要的配置文件全部放在上面这个svn上。所以~/.my-beagle-filter的内容您也可以在http://windows-config.googlecode.com/svn/trunk/.my-beagle-filter里看到,其他的以~开头的目录或者文件的路径也依此类推。

最后一步就是用grep针对匹配的文件进行精确的定位,这个脚本在~/bin/beagle-grep.sh

要注意的是,任何工具都是有局限的,比如我这套配置脚本,也有很大的局限性。但是目前它已经能满足我的大部分需要了。只是提醒大家千万不要过分的依赖任何某个特定的工具。如果某个工具你觉得好用,你就偷着乐吧;如果不好用的话,你得忍受,实在受不了的时候就千万别勉强了,该出手时就出手,写一个自己的工具出来,让大家都来用!

后记:比如我最近发现的一些局限性:

  1. beagle默认只会为长度小于30的词创建索引,如果长度超过30,它就没法进行搜索了。你可以用这个方法自己验证一下:

      mkdir tmpxx
      cd tmpxx
      for x in `seq 25 35`; do 
          for y in `seq $x`; do
              echo -n x
          done > hello.txt
          mkdir -p .beagle; beagle-build-index --recursive --deny-pattern .beagle --enable-deletion --target .beagle/ . >/dev/null 2>&1
          echo "for token length `cat hello.txt|wc -c`"; my-beagle `cat hello.txt`; echo 
      done
    

    至于为什么会这样的限制,就需要去看源代码才能弄明白了。但是我觉得意义不大,我可以肯定地说,如果我读的源代码里,一个变量名的长度超过30个字符,那这个变量名应该不会是很重要的变量,那种我需要做全局搜索的变量。

  2. beagle在我的系统(ubuntu 10.04 amd64)默认安装无法处理.xml文件;对java文件会把一些关键字全部过滤掉,而我不想它们被过滤。这时候需要修改/etc/beagle/external-filters.xml,加上这样的内容:

        <external-filters>
        <filter>
          <mimetype>text/x-java</mimetype>
          <extension>.java</extension>
          <command>cat</command>
          <arguments>%s</arguments>
        </filter>
        <filter>
          <mimetype>text/xml</mimetype>
          <extension>.xml</extension>
          <command>cat</command>
          <arguments>%s</arguments>
        </filter>
        </external-filters>
    

Android都能有哪些Intent

April 23, 2010
146 matches for "public static final String" in buffer: Intent.java
    590:    public static final String ACTION_MAIN = "android.intent.action.MAIN";
    604:    public static final String ACTION_VIEW = "android.intent.action.VIEW";
    610:    public static final String ACTION_DEFAULT = ACTION_VIEW;
    621:    public static final String ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";
    629:    public static final String ACTION_EDIT = "android.intent.action.EDIT";
    640:    public static final String ACTION_INSERT_OR_EDIT = "android.intent.action.INSERT_OR_EDIT";
    649:    public static final String ACTION_PICK = "android.intent.action.PICK";
    666:    public static final String ACTION_CREATE_SHORTCUT = "android.intent.action.CREATE_SHORTCUT";
    673:    public static final String EXTRA_SHORTCUT_INTENT = "android.intent.extra.shortcut.INTENT";
    679:    public static final String EXTRA_SHORTCUT_NAME = "android.intent.extra.shortcut.NAME";
    685:    public static final String EXTRA_SHORTCUT_ICON = "android.intent.extra.shortcut.ICON";
    692:    public static final String EXTRA_SHORTCUT_ICON_RESOURCE =
    804:    public static final String ACTION_CHOOSER = "android.intent.action.CHOOSER";
    865:    public static final String ACTION_GET_CONTENT = "android.intent.action.GET_CONTENT";
    876:    public static final String ACTION_DIAL = "android.intent.action.DIAL";
    891:    public static final String ACTION_CALL = "android.intent.action.CALL";
    900:    public static final String ACTION_CALL_EMERGENCY = "android.intent.action.CALL_EMERGENCY";
    909:    public static final String ACTION_CALL_PRIVILEGED = "android.intent.action.CALL_PRIVILEGED";
    916:    public static final String ACTION_SENDTO = "android.intent.action.SENDTO";
    942:    public static final String ACTION_SEND = "android.intent.action.SEND";
    969:    public static final String ACTION_SEND_MULTIPLE = "android.intent.action.SEND_MULTIPLE";
    976:    public static final String ACTION_ANSWER = "android.intent.action.ANSWER";
    984:    public static final String ACTION_INSERT = "android.intent.action.INSERT";
    991:    public static final String ACTION_DELETE = "android.intent.action.DELETE";
    998:    public static final String ACTION_RUN = "android.intent.action.RUN";
   1005:    public static final String ACTION_SYNC = "android.intent.action.SYNC";
   1015:    public static final String ACTION_PICK_ACTIVITY = "android.intent.action.PICK_ACTIVITY";
   1024:    public static final String ACTION_SEARCH = "android.intent.action.SEARCH";
   1033:    public static final String ACTION_SYSTEM_TUTORIAL = "android.intent.action.SYSTEM_TUTORIAL";
   1045:    public static final String ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
   1052:    public static final String ACTION_ALL_APPS = "android.intent.action.ALL_APPS";
   1059:    public static final String ACTION_SET_WALLPAPER = "android.intent.action.SET_WALLPAPER";
   1067:    public static final String ACTION_BUG_REPORT = "android.intent.action.BUG_REPORT";
   1076:    public static final String ACTION_FACTORY_TEST = "android.intent.action.FACTORY_TEST";
   1085:    public static final String ACTION_CALL_BUTTON = "android.intent.action.CALL_BUTTON";
   1093:    public static final String ACTION_VOICE_COMMAND = "android.intent.action.VOICE_COMMAND";
   1102:    public static final String ACTION_SEARCH_LONG_PRESS = "android.intent.action.SEARCH_LONG_PRESS";
   1114:    public static final String ACTION_APP_ERROR = "android.intent.action.APP_ERROR";
   1122:    public static final String ACTION_POWER_USAGE_SUMMARY = "android.intent.action.POWER_USAGE_SUMMARY";
   1136:    public static final String ACTION_UPGRADE_SETUP = "android.intent.action.UPGRADE_SETUP";
   1143:    public static final String METADATA_SETUP_VERSION = "android.SETUP_VERSION";
   1156:    public static final String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
   1164:    public static final String ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
   1174:    public static final String ACTION_USER_PRESENT= "android.intent.action.USER_PRESENT";
   1187:    public static final String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
   1192:    public static final String ACTION_TIME_CHANGED = "android.intent.action.TIME_SET";
   1197:    public static final String ACTION_DATE_CHANGED = "android.intent.action.DATE_CHANGED";
   1208:    public static final String ACTION_TIMEZONE_CHANGED = "android.intent.action.TIMEZONE_CHANGED";
   1216:    public static final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED";
   1223:    public static final String ACTION_SYNC_STATE_CHANGED
   1236:    public static final String ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
   1242:    public static final String ACTION_CLOSE_SYSTEM_DIALOGS = "android.intent.action.CLOSE_SYSTEM_DIALOGS";
   1252:    public static final String ACTION_PACKAGE_INSTALL = "android.intent.action.PACKAGE_INSTALL";
   1268:    public static final String ACTION_PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED";
   1282:    public static final String ACTION_PACKAGE_REPLACED = "android.intent.action.PACKAGE_REPLACED";
   1300:    public static final String ACTION_PACKAGE_REMOVED = "android.intent.action.PACKAGE_REMOVED";
   1317:    public static final String ACTION_PACKAGE_CHANGED = "android.intent.action.PACKAGE_CHANGED";
   1333:    public static final String ACTION_PACKAGE_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";
   1348:    public static final String ACTION_PACKAGE_DATA_CLEARED = "android.intent.action.PACKAGE_DATA_CLEARED";
   1357:    public static final String ACTION_UID_REMOVED = "android.intent.action.UID_REMOVED";
   1363:    public static final String ACTION_WALLPAPER_CHANGED = "android.intent.action.WALLPAPER_CHANGED";
   1386:    public static final String ACTION_CONFIGURATION_CHANGED = "android.intent.action.CONFIGURATION_CHANGED";
   1394:    public static final String ACTION_LOCALE_CHANGED = "android.intent.action.LOCALE_CHANGED";
   1415:    public static final String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
   1424:    public static final String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";
   1434:    public static final String ACTION_BATTERY_OKAY = "android.intent.action.BATTERY_OKAY";
   1446:    public static final String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_POWER_CONNECTED";
   1458:    public static final String ACTION_POWER_DISCONNECTED =
   1471:    public static final String ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";
   1482:    public static final String ACTION_REQUEST_SHUTDOWN = "android.intent.action.ACTION_REQUEST_SHUTDOWN";
   1491:    public static final String ACTION_DEVICE_STORAGE_LOW = "android.intent.action.DEVICE_STORAGE_LOW";
   1499:    public static final String ACTION_DEVICE_STORAGE_OK = "android.intent.action.DEVICE_STORAGE_OK";
   1507:    public static final String ACTION_MANAGE_PACKAGE_STORAGE = "android.intent.action.MANAGE_PACKAGE_STORAGE";
   1515:    public static final String ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
   1524:    public static final String ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
   1531:    public static final String ACTION_MEDIA_REMOVED = "android.intent.action.MEDIA_REMOVED";
   1538:    public static final String ACTION_MEDIA_UNMOUNTED = "android.intent.action.MEDIA_UNMOUNTED";
   1545:    public static final String ACTION_MEDIA_CHECKING = "android.intent.action.MEDIA_CHECKING";
   1552:    public static final String ACTION_MEDIA_NOFS = "android.intent.action.MEDIA_NOFS";
   1561:    public static final String ACTION_MEDIA_MOUNTED = "android.intent.action.MEDIA_MOUNTED";
   1568:    public static final String ACTION_MEDIA_SHARED = "android.intent.action.MEDIA_SHARED";
   1575:    public static final String ACTION_MEDIA_BAD_REMOVAL = "android.intent.action.MEDIA_BAD_REMOVAL";
   1582:    public static final String ACTION_MEDIA_UNMOUNTABLE = "android.intent.action.MEDIA_UNMOUNTABLE";
   1590:    public static final String ACTION_MEDIA_EJECT = "android.intent.action.MEDIA_EJECT";
   1597:    public static final String ACTION_MEDIA_SCANNER_STARTED = "android.intent.action.MEDIA_SCANNER_STARTED";
   1604:    public static final String ACTION_MEDIA_SCANNER_FINISHED = "android.intent.action.MEDIA_SCANNER_FINISHED";
   1611:    public static final String ACTION_MEDIA_SCANNER_SCAN_FILE = "android.intent.action.MEDIA_SCANNER_SCAN_FILE";
   1619:    public static final String ACTION_MEDIA_BUTTON = "android.intent.action.MEDIA_BUTTON";
   1627:    public static final String ACTION_CAMERA_BUTTON = "android.intent.action.CAMERA_BUTTON";
   1636:    public static final String ACTION_GTALK_SERVICE_CONNECTED =
   1643:    public static final String ACTION_GTALK_SERVICE_DISCONNECTED =
   1650:    public static final String ACTION_INPUT_METHOD_CHANGED =
   1666:    public static final String ACTION_AIRPLANE_MODE_CHANGED = "android.intent.action.AIRPLANE_MODE";
   1695:    public static final String ACTION_PROVIDER_CHANGED =
   1710:    public static final String ACTION_HEADSET_PLUG =
   1748:    public static final String ACTION_NEW_OUTGOING_CALL =
   1759:    public static final String ACTION_REBOOT =
   1771:    public static final String ACTION_DOCK_EVENT =
   1786:    public static final String ACTION_REMOTE_INTENT =
   1798:    public static final String ACTION_PRE_BOOT_COMPLETED =
   1814:    public static final String CATEGORY_DEFAULT = "android.intent.category.DEFAULT";
   1826:    public static final String CATEGORY_BROWSABLE = "android.intent.category.BROWSABLE";
   1849:    public static final String CATEGORY_ALTERNATIVE = "android.intent.category.ALTERNATIVE";
   1858:    public static final String CATEGORY_SELECTED_ALTERNATIVE = "android.intent.category.SELECTED_ALTERNATIVE";
   1863:    public static final String CATEGORY_TAB = "android.intent.category.TAB";
   1868:    public static final String CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER";
   1875:    public static final String CATEGORY_INFO = "android.intent.category.INFO";
   1881:    public static final String CATEGORY_HOME = "android.intent.category.HOME";
   1886:    public static final String CATEGORY_PREFERENCE = "android.intent.category.PREFERENCE";
   1891:    public static final String CATEGORY_DEVELOPMENT_PREFERENCE = "android.intent.category.DEVELOPMENT_PREFERENCE";
   1896:    public static final String CATEGORY_EMBED = "android.intent.category.EMBED";
   1901:    public static final String CATEGORY_MONKEY = "android.intent.category.MONKEY";
   1905:    public static final String CATEGORY_TEST = "android.intent.category.TEST";
   1909:    public static final String CATEGORY_UNIT_TEST = "android.intent.category.UNIT_TEST";
   1914:    public static final String CATEGORY_SAMPLE_CODE = "android.intent.category.SAMPLE_CODE";
   1921:    public static final String CATEGORY_OPENABLE = "android.intent.category.OPENABLE";
   1926:    public static final String CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST =
   1934:    public static final String CATEGORY_CAR_DOCK = "android.intent.category.CAR_DOCK";
   1941:    public static final String CATEGORY_DESK_DOCK = "android.intent.category.DESK_DOCK";
   1953:    public static final String EXTRA_TEMPLATE = "android.intent.extra.TEMPLATE";
   1962:    public static final String EXTRA_TEXT = "android.intent.extra.TEXT";
   1968:    public static final String EXTRA_STREAM = "android.intent.extra.STREAM";
   1973:    public static final String EXTRA_EMAIL       = "android.intent.extra.EMAIL";
   1978:    public static final String EXTRA_CC       = "android.intent.extra.CC";
   1983:    public static final String EXTRA_BCC      = "android.intent.extra.BCC";
   1988:    public static final String EXTRA_SUBJECT  = "android.intent.extra.SUBJECT";
   1994:    public static final String EXTRA_INTENT = "android.intent.extra.INTENT";
   2000:    public static final String EXTRA_TITLE = "android.intent.extra.TITLE";
   2009:    public static final String EXTRA_INITIAL_INTENTS = "android.intent.extra.INITIAL_INTENTS";
   2015:    public static final String EXTRA_KEY_EVENT = "android.intent.extra.KEY_EVENT";
   2023:    public static final String EXTRA_KEY_CONFIRM = "android.intent.extra.KEY_CONFIRM";
   2030:    public static final String EXTRA_DONT_KILL_APP = "android.intent.extra.DONT_KILL_APP";
   2037:    public static final String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
   2045:    public static final String EXTRA_UID = "android.intent.extra.UID";
   2053:    public static final String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED";
   2061:    public static final String EXTRA_REPLACING = "android.intent.extra.REPLACING";
   2071:    public static final String EXTRA_ALARM_COUNT = "android.intent.extra.ALARM_COUNT";
   2080:    public static final String EXTRA_DOCK_STATE = "android.intent.extra.DOCK_STATE";
   2104:    public static final String METADATA_DOCK_HOME = "android.dock_home";
   2112:    public static final String EXTRA_BUG_REPORT = "android.intent.extra.BUG_REPORT";
   2121:    public static final String EXTRA_INSTALLER_PACKAGE_NAME
   2128:    public static final String EXTRA_REMOTE_INTENT_TOKEN =
   2135:    @Deprecated public static final String EXTRA_CHANGED_COMPONENT_NAME =
   2142:    public static final String EXTRA_CHANGED_COMPONENT_NAME_LIST =
   2151:    public static final String EXTRA_CLIENT_LABEL =
   2160:    public static final String EXTRA_CLIENT_INTENT =

PCDATA?

April 11, 2010
#PCDATA是xml-dtd的一个关键字,为Parsed Character Data的缩写。

在linux(ubuntu 10.04 x86-64)下用firefox看chm电子书

April 11, 2010

很简单,装一个chmreader的插件。

但又不简单,因为firefox插件网站上默认的chmreader的版本是win32,x86的?反 正x86-64的装上是用不了的。

这时需要直接上sourceforge chmreader的开发主页上,拿到它的支持x86-64版本
的插件,再把它用unzip解开,把里面支持的firefox最高版本从3.0.改成我现在 的firefox版本,3.6.

再用zip压缩回去。装上,就可以用了。

用这个方法阅读比起在windows下用微软自带的软件来,有很多好处:

  1. firefox可以轻易的调整显示缩放。有些chm文件默认字体太小了,在ie系统底
    下再怎么调也调不到足够大。而且还需要用鼠标点出菜单、对话框,挺麻烦。用
    firefox直接用鼠标中键+Ctrl滚动,就可以放大。再加上NoSquint的插件,可以
    记住缩放的设置(否则的话,每次打开一个新的chm页面,缩放又回到无的状态。)

  2. firefox可以用其他的插件操作页面,比如AllInOne Gesture。

呵呵。

Hello World

April 6, 2010
某程序员对书法十分感兴趣,退休后决定在这方面有所建树。于是花重金购买了上等的文房四宝。一日,饭后突生雅兴,一番磨墨拟纸,并点上了上好的檀香,颇有王羲之风范,又具颜真卿气势,定神片刻,泼墨挥毫,郑重地写下一行字:hello world

怎样管理你的msn space上的blog(怎样删除)

April 5, 2010
奶奶的,太不容易了

先进你的blog,比如http://thomasbhj.spaces.live.com/blog/,然后点
“summary”,就会出现让你删除博文的操作了。