日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言程序中注释的格式化,格式化C语言命令indent

發(fā)布時間:2023/12/1 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言程序中注释的格式化,格式化C语言命令indent 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

indent是linux下一個能力極強(qiáng)的代碼整理軟件,使用他,可以輕松的寫出代碼風(fēng)格十分精良的代碼。

但是indent的參數(shù)太多,使用起來不是很容易,怎么辦呢?

查看

/usr/src/linux-headers-/scripts/Lindent

文件 ,可以看到一行代碼:

indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs-cp1

這一行就是linux內(nèi)核使用indent整理代碼的格式,使用這條命令就可以實(shí)現(xiàn)風(fēng)格十分良好的C或C++代碼

其中-l80是每一行最多80個字母,超出會拆行,如果不喜歡可以使用更長的行字?jǐn)?shù)

使用的indent參數(shù) 值 含義

--blank-lines-after-declarations ?bad?變量聲明后加空行

--blank-lines-after-procedures ?bap?函數(shù)結(jié)束后加空行

--blank-lines-before-block-comments ?bbb?塊注釋前加空行

--break-before-boolean-operator ?bbo?較長的行,在邏輯運(yùn)算符前分行

--blank-lines-after-commas ?nbc?變量聲明中,逗號分隔的變量不分行

--braces-after-if-line ?bl?"if"和"{"分做兩行

--brace-indent 0 ?bli0 ?"{"不繼續(xù)縮進(jìn)

--braces-after-struct-decl-line ?bls?定義結(jié)構(gòu),"struct"和"{"分行

--comment-indentationn ?c33?語句后注釋開始于行33

--declaration-comment-columnn ?cd33?變量聲明后注釋開始于行33

--comment-delimiters-on-blank-lines ?ncdb?不將單行注釋變?yōu)閴K注釋

--cuddle-do-while ?ncdw ?"do ---while"的"while"和其前面的"}"另起一行

--cuddle-else ?nce?"else"和其前面的"}"另起一行

--case-indentation 0 ?cli0?switch中的case語句所進(jìn)0個空格

--else-endif-columnn ?cp33?#else, #endif后面的注釋開始于行33

--space-after-cast ?cs?在類型轉(zhuǎn)換后面加空格

--line-comments-indentation n ?d0?單行注釋(不從1列開始的),不向左縮進(jìn)

--break-function-decl-args ?nbfda?關(guān)閉:函數(shù)的參數(shù)一個一行

--declaration-indentationn ?di2?變量聲明,變量開始于2行,即不必對齊

--format-first-column-comments ?nfc1?不格式化起于第一行的注釋

--format-all-comments ?nfca?不開啟全部格式化注釋的開關(guān)

--honour-newlines ?hnl ?Prefer tobreak long lines at the position of newlines in the input.

--indent-leveln ?i4?設(shè)置縮進(jìn)多少字符,如果為tab的整數(shù)倍,用tab來縮進(jìn),否則用空格填充。

--parameter-indentationn ?ip5?舊風(fēng)格的函數(shù)定義中參數(shù)說明縮進(jìn)5個空格

--line-length 75 ?l75 ?非注釋行最長75

--continue-at-parentheses ?lp?續(xù)行從上一行出現(xiàn)的括號開始

--space-after-procedure-calls ?pcs?函數(shù)和"("之間插入一個空格

--space-after-parentheses ?nprs?在"("后")"前不插入空格

--procnames-start-lines ?psl?將函數(shù)名和返回類型放在兩行定義

--space-after-for ?saf ?for后面有空格

--space-after-if ?sai ?if后面有空格

--space-after-while ?saw?while后面有空格

--start-left-side-of-comments ?nsc?不在生成的塊注釋中加*

--swallow-optional-blank-lines ?nsob?不去掉可添加的空行

--space-special-semicolon ?nss?一行的for或while語句,在";"前不加空。

--tab-size ?ts4?一個tab為4個空格(要能整除"-in")

--use-tabs ?ut ?使用tab來縮進(jìn)

【轉(zhuǎn)貼】用indent 進(jìn)行代碼格式化

2009-03-27 12:01

indent常用的參數(shù)設(shè)置

以前的用法:indent-kr -cli4 -i4 -nut

改進(jìn)的用法:indent-kr -cli4 -nut -bl4 -bli0

注釋:

-kr, UseKernighan & Ritchie coding style.

-cli4,specifies the number of spaces that case labels should be indentedto the right of the containing switch statement.

-nut,不使用空格。

-bl4,大括號內(nèi)的縮進(jìn),這里為4個空格。

-bli0,“if”語句后大括號的縮進(jìn),一般設(shè)為“0”。

indent工具參數(shù)

indent是一個常用的Linux的C代碼格式化工具,但是參數(shù)太多,很難記憶,目前發(fā)現(xiàn)一組參數(shù),可以格式化為我常用的代碼格式。

-bad -bap-bbb -bbo -nbc -bl -bli0 -bls -c33 -cd33 -ncdb -ncdw -nce -cli0-cp33 -cs -d0 -nbfda-nfc1-nfca -hnl -ip5 -l75 -lp -pcs -nprs -saf -sai -saw -nsc -nsob -nss-i4 -ts4 -ut

保存在~/.indent.pro,就是默認(rèn)的indent參數(shù)了。

3.5. 用 indent進(jìn)行代碼格式化

一個范例,勝過前言萬語。用 indent 格式化代碼,再從格式化前后的格式變化, 來學(xué)習(xí)格式化規(guī)范。

可以用不同的參數(shù)調(diào)用 indent,

3.5.1. introduce indent

What is Indent

The `indent' program can be used to make code easier to read. Itcan also convert from one style. of writing C to another.

Download

Current Version: GNU indent 2.2.7。 Download:

3.5.2. Indent參數(shù)規(guī)范

我們參照GNU,Kernighan & Ritchie,Berkeley風(fēng)格,制定了自己風(fēng)格:

indent命令參數(shù):

-bad -bap -bbb -bbo -nbc -bl -bli0 -bls -c33 -cd33 -ncdb -ncdw -nce-cli0 -cp33 -cs -d0 -nbfda -di2 -nfc1 -nfca -hnl -ip5 -l75 -lp -pcs-nprs -psl -saf -sai -saw -nsc -nsob -nss -i4 -ts4 -ut

indent配置文件

如上參數(shù)可寫入用戶目錄下的文件:".indent.pro",作為運(yùn)行indent的確 省參數(shù)。

indent配置說明

表 1.Indent代碼格式化說明

使用的indent參數(shù)

含義

--blank-lines-after-declarations

bad

變量聲明后加空行

--blank-lines-after-procedures

bap

函數(shù)結(jié)束后加空行

--blank-lines-before-block-comments

bbb

塊注釋前加空行

--break-before-boolean-operator

bbo

較長的行,在邏輯運(yùn)算符前分行

--blank-lines-after-commas

nbc

變量聲明中,逗號分隔的變量不分行

--braces-after-if-line

bl

"if"和"{"分做兩行

--brace-indent 0

bli0

"{"不繼續(xù)縮進(jìn)

--braces-after-struct-decl-line

bls

定義結(jié)構(gòu),"struct"和"{"分行

--comment-indentationn

c33

語句后注釋開始于行33

--declaration-comment-columnn

cd33

變量聲明后注釋開始于行33

--comment-delimiters-on-blank-lines

ncdb

不將單行注釋變?yōu)閴K注釋

--cuddle-do-while

ncdw

"do --- while"的"while"和其前面的"}"另起一行

--cuddle-else

nce

"else"和其前面的"}" 另起一行

--case-indentation 0

cli0

switch中的case語句所進(jìn)0個空格

--else-endif-columnn

cp33

#else, #endif后面的注釋開始于行33

--space-after-cast

cs

在類型轉(zhuǎn)換后面加空格

--line-comments-indentation n

d0

單行注釋(不從1列開始的),不向左縮進(jìn)

--break-function-decl-args

nbfda

關(guān)閉:函數(shù)的參數(shù)一個一行

--declaration-indentationn

di2

變量聲明,變量開始于2行,即不必對齊

--format-first-column-comments

nfc1

不格式化起于第一行的注釋

--format-all-comments

nfca

不開啟全部格式化注釋的開關(guān)

--honour-newlines

hnl

Prefer to break long lines at the position of newlines in theinput.

--indent-leveln

i4

設(shè)置縮進(jìn)多少字符,如果為tab的整數(shù)倍,用tab來縮進(jìn),否則用 空格填充。

--parameter-indentationn

ip5

舊風(fēng)格的函數(shù)定義中參數(shù)說明縮進(jìn)5個空格

--line-length 75

l75

非注釋行最長75

--continue-at-parentheses

lp

續(xù)行從上一行出現(xiàn)的括號開始

--space-after-procedure-calls

pcs

函數(shù)和"("之間插入一個空格

--space-after-parentheses

nprs

在"("后")"前不插入空格

--procnames-start-lines

psl

將函數(shù)名和返回類型放在兩行定義

--space-after-for

saf

for后面有空格

--space-after-if

sai

if后面有空格

--space-after-while

saw

while后面有空格

--start-left-side-of-comments

nsc

不在生成的塊注釋中加*

--swallow-optional-blank-lines

nsob

不去掉可添加的空行

--space-special-semicolon

nss

一行的for或while語句,在";"前不加空。

--tab-size

ts4

一個tab為4個空格(要能整除"-in")

--use-tabs

ut

使用tab來縮進(jìn)

總結(jié)

以上是生活随笔為你收集整理的c语言程序中注释的格式化,格式化C语言命令indent的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。