Mark Mark - 3 months ago 6
C Question

indent being odd -- fix or choose an alternative

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

Answer

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

Comments