缩进是奇怪的

编程入门 行业动态 更新时间:2024-10-10 06:13:49
缩进是奇怪的 - 修复或选择替代方案(indent being odd — fix or choose an alternative)

我正在使用参数-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1 ,除了两个障碍外,一切都很好:

1)在mytype_t * my;类的语句中,它往往会在*后添加一个额外的空格mytype_t * my; ,即

void my_function(my_type *ptr)

变成

void my_function(my_type * ptr)

2)它在&符号之后放置额外的空格,如(uint16_t *) & q->drops ie

stats->drops = (uint16_t *) &q->drops

变成

stats->drops = (uint16_t *) & q->drops

使用-nss或不使用-ss运行indent不能解决问题。

有没有办法告诉indent不要这样做? 如果没有, indent的替代方法是什么?

谢谢。

% indent -T my_type -T uint16_t

I'm running indent with arguments -npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1, all is good except two obstacles:

1) It tends to put an extra space after * in statements like mytype_t * my;, i.e.

void my_function(my_type *ptr)

turns into

void my_function(my_type * ptr)

2) It places extra space after & symbol in expressions like (uint16_t *) & q->drops i.e.

stats->drops = (uint16_t *) &q->drops

turns into

stats->drops = (uint16_t *) & q->drops

Running indent with -nss or without -ss does not solve the problem.

Is there a way to tell indent not to do this? If not, what are the alternatives to indent ?

Thanks.

SOLUTION

% indent -T my_type -T uint16_t

最满意答案

从man indent :

您必须使用'-T'选项告诉缩进程序中由typedef定义的所有类型名称。 '-T'可以多次指定,并且使用指定的所有名称。 例如,如果您的程序包含

typedef unsigned long CODE_ADDR; typedef enum {red, blue, green} COLOR;

你会使用选项-T CODE_ADDR -T COLOR 。

所以似乎indent不知道stdint.h类型,所以你必须通过传递-T uint16_t -T mytype_t让它知道你正在使用它们

From man indent:

You must use the '-T' option to tell indent the name of all the typenames in your program that are defined by typedef. '-T' can be specified more than once, and all names specified are used. For example, if your program contains

typedef unsigned long CODE_ADDR; typedef enum {red, blue, green} COLOR;

you would use the options -T CODE_ADDR -T COLOR.

So it seems like indent doesn't know about the stdint.h types, so you have to let it know you are using them by passing -T uint16_t -T mytype_t

更多推荐

本文发布于:2023-08-07 00:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457323.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:奇怪

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!