顯示具有 Programming 標籤的文章。 顯示所有文章
顯示具有 Programming 標籤的文章。 顯示所有文章

2011/12/07

Linux Kernel Indent Rule.

This is the sample for programmer to reference. We can find the Linux Indent Rule in usr/src/linux-headers-2.6.32-35/scripts/Lindent And the indent rule is:
indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1
-npro, --ignore-profile
Do not read `.indent.pro' files.
-kr, --k-and-r-style
Use Kernighan & Ritchie coding style.
-in, --indent-leveln
Set indentation level to n spaces.
-tsn, --tab-sizen
Set tab size to n spaces.
-sob, --swallow-optional-blank-lines
Swallow optional blank lines.
-ln, --line-lengthn
Set maximum line length for non-comment lines to n.
-ss, --space-special-semicolon
On one-line for and while statements, force a blank before the semicolon.
-ncs, --no-space-after-casts
Do not put a space after cast operators.
-cpn, --else-endif-columnn
Put comments to the right of #else and #endif statements in column n.

Options

-bad, --blank-lines-after-declarations

Force blank lines after the declarations.
See BLANK LINES.
-bap, --blank-lines-after-procedures
Force blank lines after procedure bodies.
See BLANK LINES.
-bbb, --blank-lines-before-block-comments
Force blank lines before block comments.
See BLANK LINES.
-bbo, --break-before-boolean-operator
Prefer to break long lines before boolean operators.
See BREAKING LONG LINES.
-bc, --blank-lines-after-commas
Force newline after comma in declaration.
See DECLARATIONS.
-bl, --braces-after-if-line
Put braces on line after if, etc.
See STATEMENTS.
-blf, --braces-after-func-def-line
Put braces on line following function definition line.
See DECLARATIONS.
-blin, --brace-indentn
Indent braces n spaces.
See STATEMENTS.
-bls, --braces-after-struct-decl-line
Put braces on the line after struct declaration lines.
See DECLARATIONS.
-br, --braces-on-if-line
Put braces on line with if, etc.
See STATEMENTS.
-brf, --braces-on-func-def-line
Put braces on function definition line.
See DECLARATIONS.
-brs, --braces-on-struct-decl-line
Put braces on struct declaration line.
See DECLARATIONS.
-bs, --Bill-Shannon, --blank-before-sizeof
Put a space between sizeof and its argument.
See STATEMENTS.
-cn, --comment-indentationn
Put comments to the right of code in column n.
See COMMENTS.
-cbin, --case-brace-indentationn
Indent braces after a case label N spaces.
See STATEMENTS.
-cdn, --declaration-comment-columnn
Put comments to the right of the declarations in column n.
See COMMENTS.
-cdb, --comment-delimiters-on-blank-lines
Put comment delimiters on blank lines.
See COMMENTS.
-cdw, --cuddle-do-while
Cuddle while of do {} while; and preceding `}'.
See COMMENTS.
-ce, --cuddle-else
Cuddle else and preceding `}'.
See COMMENTS.
-cin, --continuation-indentationn
Continuation indent of n spaces.
See STATEMENTS.
-clin, --case-indentationn
Case label indent of n spaces.
See STATEMENTS.
-cpn, --else-endif-columnn
Put comments to the right of #else and #endif statements in column n.
See COMMENTS.
-cs, --space-after-cast
Put a space after a cast operator.
See STATEMENTS.
-dn, --line-comments-indentationn
Set indentation of comments not to the right of code to n spaces.
See COMMENTS.
-bfda, --break-function-decl-args
Break the line before all arguments in a declaration.
See DECLARATIONS.
-bfde, --break-function-decl-args
Break the line after the last argument in a declaration.
See DECLARATIONS.
-djn, --left-justify-declarations
If -cd 0 is used then comments after declarations are left justified behind the declaration.
See DECLARATIONS.
-din, --declaration-indentationn
Put variables in column n.
See DECLARATIONS.
-fc1, --format-first-column-comments
Format comments in the first column.
See COMMENTS.
-fca, --format-all-comments
Do not disable all formatting of comments.
See COMMENTS.
-gnu, --gnu-style
Use GNU coding style. This is the default.
See COMMON STYLES.
-hnl, --honour-newlines
Prefer to break long lines at the position of newlines in the input.
See BREAKING LONG LINES.
-in, --indent-leveln
Set indentation level to n spaces.
See INDENTATION.
-iln, --indent-labeln
Set offset for labels to column n.
See INDENTATION.
-ipn, --parameter-indentationn
Indent parameter types in old-style function definitions by n spaces.
See INDENTATION.
-kr, --k-and-r-style
Use Kernighan & Ritchie coding style.
See COMMON STYLES.
-ln, --line-lengthn
Set maximum line length for non-comment lines to n.
See BREAKING LONG LINES.
-lcn, --comment-line-lengthn
Set maximum line length for comment formatting to n.
See COMMENTS.
-linux, --linux-style
Use Linux coding style.
See COMMON STYLES.
-lp, --continue-at-parentheses
Line up continued lines at parentheses.
See INDENTATION.
-lps, --leave-preprocessor-space
Leave space between `#' and preprocessor directive.
See INDENTATION.
-nlps, --remove-preprocessor-space
Remove space between `#' and preprocessor directive.
See INDENTATION.
-nbad, --no-blank-lines-after-declarations
Do not force blank lines after declarations.
See BLANK LINES.
-nbap, --no-blank-lines-after-procedures
Do not force blank lines after procedure bodies.
See BLANK LINES.
-nbbo, --break-after-boolean-operator
Do not prefer to break long lines before boolean operators.
See BREAKING LONG LINES.
-nbc, --no-blank-lines-after-commas
Do not force newlines after commas in declarations.
See DECLARATIONS.
-nbfda, --dont-break-function-decl-args
Don't put each argument in a function declaration on a separate line.
See DECLARATIONS.
-ncdb, --no-comment-delimiters-on-blank-lines
Do not put comment delimiters on blank lines.
See COMMENTS.
-ncdw, --dont-cuddle-do-while
Do not cuddle } and the while of a do {} while;.
See STATEMENTS.
-nce, --dont-cuddle-else
Do not cuddle } and else.
See STATEMENTS.
-ncs, --no-space-after-casts
Do not put a space after cast operators.
See STATEMENTS.
-ndjn, --dont-left-justify-declarations
Comments after declarations are treated the same as comments after other statements.
See DECLARATIONS.
-nfc1, --dont-format-first-column-comments
Do not format comments in the first column as normal.
See COMMENTS.
-nfca, --dont-format-comments
Do not format any comments.
See COMMENTS.
-nhnl, --ignore-newlines
Do not prefer to break long lines at the position of newlines in the input.
See BREAKING LONG LINES.
-nip, --no-parameter-indentation
Zero width indentation for parameters.
See INDENTATION.
-nlp, --dont-line-up-parentheses
Do not line up parentheses.
See STATEMENTS.
-npcs, --no-space-after-function-call-names
Do not put space after the function in function calls.
See STATEMENTS.
-nprs, --no-space-after-parentheses
Do not put a space after every '(' and before every ')'.
See STATEMENTS.
-npsl, --dont-break-procedure-type
Put the type of a procedure on the same line as its name.
See DECLARATIONS.
-nsaf, --no-space-after-for
Do not put a space after every for.
See STATEMENTS.
-nsai, --no-space-after-if
Do not put a space after every if.
See STATEMENTS.
-nsaw, --no-space-after-while
Do not put a space after every while.
See STATEMENTS.
-nsc, --dont-star-comments
Do not put the `*' character at the left of comments.
See COMMENTS.
-nsob, --leave-optional-blank-lines
Do not swallow optional blank lines.
See BLANK LINES.
-nss, --dont-space-special-semicolon
Do not force a space before the semicolon after certain statements. Disables `-ss'.
See STATEMENTS.
-nut, --no-tabs
Use spaces instead of tabs.
See INDENTATION.
-nv, --no-verbosity
Disable verbose mode.
See MISCELLANEOUS OPTIONS.
-orig, --original
Use the original Berkeley coding style.
See COMMON STYLES.
-npro, --ignore-profile
Do not read `.indent.pro' files.
See INVOKING INDENT.
-pcs, --space-after-procedure-calls
Insert a space between the name of the procedure being called and the `('.
See STATEMENTS.
-pin, --paren-indentationn
Specify the extra indentation per open parentheses '(' when a statement is broken.See STATEMENTS.
-pmt, --preserve-mtime
Preserve access and modification times on output files.See MISCELLANEOUS OPTIONS.
-ppin, --preprocessor-indentationn
Specify the indentation for preprocessor conditional statements.See INDENTATION.
-prs, --space-after-parentheses
Put a space after every '(' and before every ')'.
See STATEMENTS.
-psl, --procnames-start-lines
Put the type of a procedure on the line before its name.
See DECLARATIONS.
-saf, --space-after-for
Put a space after each for.
See STATEMENTS.
-sai, --space-after-if
Put a space after each if.
See STATEMENTS.
-saw, --space-after-while
Put a space after each while.
See STATEMENTS.
-sbin, --struct-brace-indentationn
Indent braces of a struct, union or enum N spaces.
See STATEMENTS.
-sc, --start-left-side-of-comments
Put the `*' character at the left of comments.
See COMMENTS.
-sob, --swallow-optional-blank-lines
Swallow optional blank lines.
See BLANK LINES.
-ss, --space-special-semicolon
On one-line for and while statements, force a blank before the semicolon.
See STATEMENTS.
-st, --standard-output
Write to standard output.
See INVOKING INDENT.
-T

Tell indent the name of typenames.

See DECLARATIONS.
-tsn, --tab-sizen
Set tab size to n spaces.
See INDENTATION.
-ut, --use-tabs
Use tabs. This is the default.
See INDENTATION.
-v, --verbose
Enable verbose mode.
See MISCELLANEOUS OPTIONS.
-version
Output the version number of indent.
See MISCELLANEOUS OPTIONS.

2011/11/10

[C/C++ basic] Preprocessing #if defined(SHAWN)

It's lot of usage same as #ifdef Like #if defined(...) When using #if defined(...) we can used logic AND/OR for preprocessing.

Sample 1:

#ifdef ABC
// do something
#elif DEF
// do something
#else
// do something else
#endif

Sample 1 above can be simply recoding as:

#if defined(ABC) || defined(DEF)
//do something
#else
// do something else
#endif

2011/11/04

[C/C++ basic] Preprocessing #ifdef, #elif, #else

Today I using C/C++ preprocessor to compile my code, But I have a little confuse about "is #elif can work correctly with #ifdef"?
#ifdef TEST_IFDEF
	printf("Test #ifdef");
#elif TEST_ELIF
	printf("Test #elif");
#else
	printf("Test #else");
#endif
And after my trying. It's work well :D

2011/09/26

[C/C++]switch-case with range?

There is an interesting discussed after today study group. Is C/C++ support switch-case with range of integer!? Let see a example :
//===================
switch (a)
{
	case 1 ... 10:
		//do somthing
		break;

	case 11 ... 20:
		//do somthing
		break;
	default:
		//do something 
		break;
}
//===================
This is successfully with gcc compiler. But not done with VC++ That's because Standard C doesn't support switch-case with range. I found the answer from http://c-faq.com/misc/nonconstcase.html If using gcc with option -pedantic, then will be error occur when compile like below: warning: range expressions in switch statements are non-standard unless you are clarify what are you doing, and understand the code portable issue. DONOT using switch-case with range! (my own suggestion...)

2011/04/11

Bash Introduction (4/12)

4/12 Present in Alphanetworks.

 

 

2011/02/13

The chr() in Ruby.

Cause I have to write bytes string using Ruby.

I  collation some rules of chr() to clarify my mind.

At first. create new file.

file = File.new("helloRuby", "w+")

 

There are three way to get the same result :

file.write(65.chr)

file.write(Integer(0x41).chr)

file.write("A")

upon three all get the hexdump result like :

00000000  41                                                |A|


And if using String.hex , ruby will write the string of hex number to file

file.write("A".hex)

00000000  31 30                                             |10|

 

Then, if I want to write the real hex byte to file.

I can using

file.write("A".hex.chr)

file.write(Integer(10).chr)

00000000  0a 0a                                             |..|


Important note :

chr() of Number form and chr() of String form will get the different result !

 

2010/01/19

off_t 是32bit 還是64bit呢?

檔案位置的最大值受限於 off_t 資料型別本身的大小.
多數機器架構會定義為C的long 資料型別
若有需要將 off_t 由 32 bits 轉成 64bits
只要在 CPPFLAG 中加入 D_FILE_OFFSET_BITS=64 即可

ex:
CPPFLAG += -D_FILE_OFFSET_BITS=64

2010/01/14

[Programming] Difference of Struct Define between C and C++

今天和 Evan 一起找 Bug 時發現了一個被我忽略的 C/C++ 小細節,

在 C++ 中, 當宣告了一個 struct 後,

可以直接用這個結構來做為型態名稱,

例如:

struct sample_struct
{

char buffer[10];
int i, j, k;
};

在 C++ 裡, 可以直接使用

sample_struct test;


而在 C 語言中較為嚴謹, 需要在每個變數宣告之前加入關鍵字 struct :

struct sample_struct test;

若直接在 C 裡用 sample_struct test; 編譯時會看見 ERROR 唷!