Differences between revisions 20 and 23 (spanning 3 versions)
Revision 20 as of 2006-05-15 14:57:22
Size: 14434
Editor: jnan
Comment:
Revision 23 as of 2006-05-23 04:55:18
Size: 14737
Editor: jnan
Comment:
Deletions are marked like this. Additions are marked like this.
Line 55: Line 55:
== GCC ==
  * ./configure --target=arm-elf --prefix=/opt/gcc-3.4.6-arm
Line 58: Line 61:
  * vim7 config
    * ./configure --with-features=huge --enable-cscope --enable-multibyte --enable-xim --enable-fontset --enable-gui=gnome2
Line 144: Line 150:
== CRAMFS ==
Compressed ROM filesystem
  * [http://en.wikipedia.org/wiki/Cramfs]

TableOfContents

1. 关于我

个人信息

http://blog.woodpecker.org.cn/planet/images/someone.png

Jick Nan

邮件

[email protected]

主页

http://jick.nan.googlepages.com

Blog

[http://my.donews.com/jnan/ 梦南录]

2. C

2.1. Coding Style

2.1.1. Indentation

  • 8-char indent
  • If you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.
  • Don't put multiple statements on a single line unless you have something to hide.
  • Get a decent editor, and don't leave whitespace at the end of lines.

2.1.2. Breaking long lines and strings

  • Coding style is all about readability and maintainabilty using commonly avaible tools.
  • The limit on the length of lines is 80 colums and this is a hard limit.

2.1.3. Placing braces

  • The preferred way, as shown to us by the prophets Kernighan and Ritchie, is to put the opening brace last on the line, and put the closing brace first.
  • namely function have the opening brace at the begining of the next line.

2.1.4. Naming

  • C is a Spartan language, and so should your naming be.
  • GLOBAL variables (to be used only if you _really_need them) need to have descriptive name, as do global functions.
  • LOCAL variable name should be short, and to the point.

2.1.5. Fuctions

  • Fuctions should be short and sweet, and do just one thind.
  • Another measure of the functions is the number of local variables, They shouldn't exceed 5-10, or you're doing something wrong.

2.1.6. Centralized exiting of functions

  • About gogo statement.

2.1.7. Commenting

  • Comments are good, but there is also a demage of over-commenting.
  • Generally, you want your comments to tell WHAT your code does, not HOW.

2.1.8. You've made a mess of it

  • About GNU Emacs and GNU indent.
  • 'indent' is not a fix for bad programing.

2.1.9. Data structures

  • Data structures that have visibility outside the single-threaded environment they are created and destoryed in should always have reference counts.
  • Locking is _not_ a replacement for reference counting.
  • If another thread can find your data structure, and you don't have a reference count on it, you almost certainly have a bug.

2.1.10. Macros, Enums, Inline functions and RTL

  • Names of macros defining contants and labels in enums are capitalized.
  • Enums are preferred when defining serval related constants.
  • Generally, inline functions are preferable to macros resembling functions.
  • Macros with multiple statements should be enclosed in a do-while block.

2.2. malloc, calloc, free

  • 一个严重的错误:释放不是通过调用 malloc, calloc 得到的指针所指向的存储空间。
  • 使用已释放空间同样是错误的。

3. GNU Tools

3.1. GCC

  • ./configure --target=arm-elf --prefix=/opt/gcc-3.4.6-arm

3.2. Vim

3.2.1. Edit a file

3.2.1.1. Move around quickly

  • If you set the incsearch option, Vim will show the first match for the pattern, while you are still typing it. This quickly shows a typo in the pattern.

  • If you set hlsearch option, Vim will highlight all matches for the pattern with a yellow background. :nohlsearch will close it.

  • If you see a specific word and want to search for other occurrences of the same word, use the * command to grab the word from under the cursor and search for the next one, while # search for the previous one.

  • In structured text(C/C++)
    • % can jump to many different matching items. It is very useful to check if() and {} constructs are balanced properly.

    • Use [{ to jump back to the "{" at the start of the current code block, and ]} for '}'.

    • Use gd to jump from the use of variable to its local declaration.

  • 可视(visual)模式,用于选定文本块;可以在正常模式下输入v(小写)来按字符选定,输入V(大写)来按行选定,或输入Ctrl-V来按方块选定。

  • `.(跳转到最近修改过的位置)

  • ZQ(无条件退出)

  • ZZ(存盘退出)

  • ga(显示光标下的字符在当前使用的 encoding 下的内码)

  • guw(光标下的单词变为小写)

  • gUw(光标下的单词变为大写)

  • :TOhtml (根据 Vim 的语法加亮的方式生成 HTML 代码)

  • K (显示光标下单词的 man 手册页)

  • 将当前行提到页首:zt,页尾:zb

  • gg 定位到文件开头,G 定位到文件的结尾。

3.2.1.2. Don't type it twice

  • If you want to change one word into another in the whole file, you can use the :s(substitute) command.

    • 去掉所有的行尾空格:“:%s/\s\+$//”。

    • 去掉所有的空白行:“:%s/\(\s*\n\)\+/\r/”。

    • 去掉所有的“//”注释:“:%s!\s*//.*!!”。

    • 去掉所有的“/* */”注释:“:%s!\s*/\*\_.\{-}\*/\s*! !g”。

  • If you want to change one word into another only a few locations, a quick method is to use the * command to find the next occurrence of the word and use cw to change the word. Then type n to find the next word and .(dot) to repeat the cw command.

  • CTRL-N can auto complete function and variable names. Vim looks up words in the file you are editing, and also in #include'd files.

  • Vim has a mechanism to record a macro. You type qa to start recording into register 'a'. Then you type your commands as usual and finally hit q again to stop recording. When you want to repeat the recorded commands you type @a.

  • 寄存器
    • 除了有一个无名寄存器外,Vim 还有一大堆有名的寄存器,可以通过“"”(参见“:help "”)或“Ctrl-R”(参见“:help i_CTRL-R”和“:help c_CTRL-R”)加寄存器名(字母、数字和某些特殊字符,参见“:help registers”;“无名”寄存器的名字是“"”)来访问。比如,你先使用“"ayy”复制了一行,然后使用“dd”删掉了一行,然后移动光标到要复制到的位置,就可以使用“"aP”把先前复制的内容粘贴上去了。
    • 在使用 X Window 系统时,有两个特殊的寄存器是需要注意一下的:“"*”访问的寄存器是 X 的主选择区域(primary selection),“"+”访问的寄存器是 X 的剪贴板(clipboard)。
    • 还有一个很特殊的“寄存器”:“=”。在插入模式或命令模式中,键入“Ctrl-R=”,Vim 会提示你输入一个表达式,普通的整数运算在此完全有效。

3.2.1.3. Fix it when it's wrong

  • It's normal to make errors while typing, this can be corrected with abbreviations: :abbr Lunix Linux.

  • The same mechanism can be used to type a long word with just a few characters: :abbr pn pinguin.

  • To find errors in your text Vim has a clever hightlighting mechanism. This was actually meant to be used to do syntax hightlighting of programs, but it can catch and highlight errors as well.
  • Modeline for C coding style(see above): /* vim:shiftwidth=8:tabstop=8:filetype=c:norl: */

    • 把光标移到要重新格式化的文本开头,使用gq命令后面跟一个光标移动命令确定重新格式化的范围。比如gq}(格式化一段),gq5j(格式化 5 行),gqG(格式化至文件末尾)。

  • :set list 查看所有不可见字符; :set nolist 关闭

  • A more complex example: English text.

3.2.2. Edit more files

3.2.2.1. A file seldom comes alone

  • Tag mechanism works for jumping between files.
    • :tag 关键字(跳转到与“关键字”匹配的标记处)
    • :tselect [关键字](显示与“关键字”匹配的标记列表,输入数字跳转到指定的标记)
    • :tjump [关键字](类似于“:tselect”,但当匹配项只有一个时直接跳转至标记处而不再显示列表)
    • :tn(跳转到下一个匹配的标记处)
    • :tp(跳转到上一个匹配的标记处)
    • Ctrl-](跳转到与光标下的关键字匹配的标记处;除“关键字”直接从光标位置自动获得外,功能与“:tags”相同)
    • g](与“Ctrl-]”功能类似,但使用的命令是“:tselect”)
    • g Ctrl-](与“Ctrl-]”功能类似,但使用的命令是“:tjump”)
    • Ctrl-T(跳转回上次使用以上命令跳转前的位置)
  • Another powerful mechanism is to find all occurrences of a name in a group of files, using the :grep command. Vim makes a list of all matches, and jumps to the first one. The :cn command takes you to each next match.

  • Positions the cursor on the name of the function in your file and type [i: Vim will show a list of all matches for the function name in the included files.

  • In vim you can split the text erea in several parts to edit different files.
    • :split 上下分屏; :vsplit 左右分屏。

  • There are more uses of multiple window. The preview-tag mechanism is a very good example.
  • 可以使用“gf”命令方便地跳转到光标下的文件名所代表的文件中。使用“Ctrl-O”(参见“:help CTRL-O”)可返回到原先的文件中。

3.2.2.2. Let's work together

  • Select some structured text in a list and sort it: !sort.

  • 如果想把外部命令执行的结果插入到当前编辑的缓冲区中,可以考虑使用“:r!”。
  • 当使用可视模式选中文本行后然后键入“:!”(命令行上将出现“:'<,'>!”,表示命令的范围是选定的文本),或者使用“:%!”(表示命令的范围是整个缓冲区中的文本),Vim 在执行后面的命令时,将把命令范围里的文本行作为后面执行的命令标准输入,并用命令执行后的标准输出替换当前缓冲区中的这些文本行。

    • 要对所有的非空行进行编号,只需要“:%!nl”;要对包含空行的所有行进行编号?OK,“:%!nl -ba”。

3.2.2.3. Text is structured

  • One of the simpler things is to speed up the edit-compile-fix cycle. Vim has the :make command, which starts your compilations, catches the errors it produces and lets you jump to the error locations to fix the problems.

    • :cn(显示下一个错误)
    • :cp(显示上一个错误)
    • :cl(列出所有的错误及其编号)
    • :cc(跳转到指定编号的错误)
    • :copen(打开快速修订窗口,在其中显示所有错误,可在错误上双击鼠标或按回车键跳转至该错误)

3.2.3. Sharpen the saw

3.2.3.1. Make it a habit

  • You need to learn new commands and turn them into a habit.

3.2.4. Task

3.2.4.1. Editing in hex mode

  1. vim -b NSLU2?_v23R29.bin
  2. :%!xxd
  3. When completed, :%!xxd -r

3.3. CVS

4. File System

4.1. CRAMFS

Compressed ROM filesystem

4.2. Ext3

  • 稳定,中庸

4.3. JFS

  • JFS is the lowest CPU-usage FS.

4.4. ReiserFS

  • It's the only filesystem that supports shrinking a filesystem now
  • Nothing here will shake my own choice of ReiserFS for most general purpose filesystems, it has a good performance on real world benchmarks, and is the most mature of the journalling file systems presented.(simonw)

4.5. XFS

Technical Specifications:

  • Journaled 64-bit filesystem with guaranteed filesystem consistency.
  • Online Administration: XFS supports filesystem growth for mounted volumes, allows filesystem "freeze" and "thaw" operations to support volume level snapshots, and provides an online file defragmentation utility.
  • Quotas: XFS supports user and group quotas. XFS considers quota information as filesystem metadata and uses journaling to avoid the need for lengthy quota consistency checks after a crash.
  • XFS supports the ACL semantics and interfaces described in the draft POSIX 1003.1e standard.

XFS appears to be the most appropriate filesystem to install on a file server for home or small-business needs :

  • It uses the maximum capacity of your server hard disk(s)
  • It's the quickest FS to create, mount and unmount
  • It's the quickest FS for operations on large files (>500MB)

  • This FS gets a good place for operations on a large number of small to moderate-size files and directories
  • It constitutes a good CPU vs time compromise for large directory listing or file search

5. Samba

5.1. CIFS 修改之主要目的

  • 简化与精练 SMB 协议中一些比较混乱的部分
  • 增加 unicode 支持
  • 改善文件锁
  • 支持硬连接
  • 彻底消除对 NetBIOS 的依赖
  • Linux 增强 SMB-Unix 非 Windows 的文件类型(如:符号连接)

6. Misc

6.1. Opera Browser

For Opera 9 Beta

  • Multi-tab: Ctrl-t:new Ctrl-w:close '1':previous '2':forward Ctrl-Tab: switch
  • Resize with only one key press, using '0', '9'
  • Reopen with Ctrl-z
  • Fastest speed
  • Mouse Genust: don't used, but it's really cool!
  • Content blocker
  • Site preference
  • F9: 激活快捷键。如在编辑区,需要先激活。
  • Q: 上一个链接 A: 下一个链接 W: 上一个标题 S: 下一个标题 E: 上一句 D: 下一句
  • Shift + ← ↑ → ↓ : 定位超链接
  • Ctrl + L 聚焦到地址栏
  • Z: 后退 X: 前进
  • Ctrl + Enter 自动已保存的输入密码
  • Ctrl + B: 打开剪贴板中的地址(不用聚焦到地址栏)Ctrl + shift + B: 在后台打开剪贴板中的地址

6.2. IRC channel

  • irc.freenode.net
    • #nslu2-general // for end-user
    • #nslu2-linux // for core development
    • #openslug

7. 反馈

欢迎大家对我说三道四哪

jick_nan (last edited 2009-12-25 07:12:35 by localhost)