All of lore.kernel.org
 help / color / mirror / Atom feed
* Linux Coding style template
@ 2016-08-06 21:22 Charls D. Chap
  2016-08-07  4:39 ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Charls D. Chap @ 2016-08-06 21:22 UTC (permalink / raw)
  To: kernelnewbies

I want to transform some C source files. following Linux kernel coding style.

- Does script/Lindent STRICTLY follows all linux kernel coding style rules?
- What scripts/templates do you use/suggest for elegant code style
with the fact that
  we are talking about Linux Kernel Coding?


The GNU guys suggest indent with the following parameters:
-nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4
-cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai
-saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1

On the other hand:
Linux/script/Lindent contains:
-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1

Differences so far:
1)
indent with gnu parameters inserts a space on labels eg.
 err: vs
err:

2)
indent with gnu parameters inserts 26 spaces
#endif                                                        /*
something like this*/


So probably gnu site is outdated?


Also, I have noticed  that they both fail theyto leave the empty line
of a label empty
For example, err: code
to
err:
       code

What does the coding style suggests in this case?

Have you found, other cases such the above?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Linux Coding style template
  2016-08-06 21:22 Linux Coding style template Charls D. Chap
@ 2016-08-07  4:39 ` Greg KH
  2016-08-07 14:53   ` Charls D. Chap
  0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2016-08-07  4:39 UTC (permalink / raw)
  To: kernelnewbies

On Sun, Aug 07, 2016 at 12:22:03AM +0300, Charls D. Chap wrote:
> I want to transform some C source files. following Linux kernel coding style.
> 
> - Does script/Lindent STRICTLY follows all linux kernel coding style rules?
> - What scripts/templates do you use/suggest for elegant code style
> with the fact that
>   we are talking about Linux Kernel Coding?
> 
> 
> The GNU guys suggest indent with the following parameters:
> -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4
> -cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai
> -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1
> 
> On the other hand:
> Linux/script/Lindent contains:
> -npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1
> 
> Differences so far:
> 1)
> indent with gnu parameters inserts a space on labels eg.
>  err: vs
> err:
> 
> 2)
> indent with gnu parameters inserts 26 spaces
> #endif                                                        /*
> something like this*/
> 
> 
> So probably gnu site is outdated?

Probably, start with running Lindent, and then fix up the mess it leaves
by hand.  Shouldn't take more than a day to do it.

good luck!

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Linux Coding style template
  2016-08-07  4:39 ` Greg KH
@ 2016-08-07 14:53   ` Charls D. Chap
  2016-08-08  7:01     ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Charls D. Chap @ 2016-08-07 14:53 UTC (permalink / raw)
  To: kernelnewbies

On Sun, Aug 7, 2016 at 7:39 AM, Greg KH <greg@kroah.com> wrote:
> On Sun, Aug 07, 2016 at 12:22:03AM +0300, Charls D. Chap wrote:
>> I want to transform some C source files. following Linux kernel coding style.

My questions are more generic, i am interesting in an automatic way for
identation! And also, i am interesting to what kernel developers will
do in the following cases,  so i am  forwarding again the email.


please take a look to this example
width is 90, what a kernel developer will do? spliti in two lines, or
leave it us it is,
cause i think it's more readable, in this way
qq->run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
qq->vcpu, 0);


Also, have you find a way to tell indent not to indent, struct definitions?
In .h, when you have a huge structure definition, it's more readable,
to have it's struct friend one below the other, aligned!
struct kvm_mem_bank {
          struct list_head           list;
         u64                              guest_phys_addr;
         void                              *host_addr;
        u64                               size;
};

This also counts for variables initiliazation
int x = 0
char  *dog         = animal->dog->name;
char  *cat          = animal->cat->name;
char * elephant = animal->elephant->name;

Any ideas?



- Does script/Lindent STRICTLY follows all linux kernel coding style rules?
- What scripts/templates do you use/suggest for elegant code style
with the fact that
  we are talking about Linux Kernel Coding?


The GNU guys suggest indent with the following parameters:
-nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4
-cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai
-saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1

On the other hand:
Linux/script/Lindent contains:
-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1

Differences so far:
1)
indent with gnu parameters inserts a space on labels eg.
 err: vs
err:

2)
indent with gnu parameters inserts 26 spaces
#endif                                                          /*
something like this                 */


So probably gnu site is outdated?


Also, I have noticed  that they both fail theyto leave the empty line
of a label empty
For example, err: code
to
err:
       code

What does the coding style suggests in this case?

Have you found, other cases such the above?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Linux Coding style template
  2016-08-07 14:53   ` Charls D. Chap
@ 2016-08-08  7:01     ` Greg KH
  2016-08-08 10:14       ` Charls D. Chap
  0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2016-08-08  7:01 UTC (permalink / raw)
  To: kernelnewbies

On Sun, Aug 07, 2016 at 05:53:15PM +0300, Charls D. Chap wrote:
> On Sun, Aug 7, 2016 at 7:39 AM, Greg KH <greg@kroah.com> wrote:
> > On Sun, Aug 07, 2016 at 12:22:03AM +0300, Charls D. Chap wrote:
> >> I want to transform some C source files. following Linux kernel coding style.
> 
> My questions are more generic, i am interesting in an automatic way for
> identation!

Why?  It's best to do it "by hand" after using a few basic indent rules,
as Lindent provides.

> And also, i am interesting to what kernel developers will
> do in the following cases

Why?

> please take a look to this example
> width is 90, what a kernel developer will do? spliti in two lines, or
> leave it us it is,
> cause i think it's more readable, in this way
> qq->run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
> qq->vcpu, 0);

That doesn't look readable at all, are you sure you ment it to look like
that?

> Also, have you find a way to tell indent not to indent, struct definitions?
> In .h, when you have a huge structure definition, it's more readable,
> to have it's struct friend one below the other, aligned!
> struct kvm_mem_bank {
>           struct list_head           list;
>          u64                              guest_phys_addr;
>          void                              *host_addr;
>         u64                               size;
> };

That's not aligned at all :(

> This also counts for variables initiliazation
> int x = 0
> char  *dog         = animal->dog->name;
> char  *cat          = animal->cat->name;
> char * elephant = animal->elephant->name;
> 
> Any ideas?

Don't do the above, it looks horrible.

> - Does script/Lindent STRICTLY follows all linux kernel coding style rules?

No, it gets you close.

> - What scripts/templates do you use/suggest for elegant code style
> with the fact that
>   we are talking about Linux Kernel Coding?

Use an editor with the proper settings and then fix it up by hand.

Or even better yet, just always write your code using the proper
settings.

> The GNU guys suggest indent with the following parameters:
> -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4
> -cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai
> -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1

Where do they say that?

> On the other hand:
> Linux/script/Lindent contains:
> -npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1

And the differnces are what?

> Differences so far:
> 1)
> indent with gnu parameters inserts a space on labels eg.
>  err: vs
> err:

Don't put a space.

> 2)
> indent with gnu parameters inserts 26 spaces
> #endif                                                          /*
> something like this                 */

That doesn't make sense, does it?

> So probably gnu site is outdated?

What gnu site?

You do know _why_ we have a coding style, right?  It's not about being
pedantic, it's about your brain.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Linux Coding style template
  2016-08-08  7:01     ` Greg KH
@ 2016-08-08 10:14       ` Charls D. Chap
  0 siblings, 0 replies; 5+ messages in thread
From: Charls D. Chap @ 2016-08-08 10:14 UTC (permalink / raw)
  To: kernelnewbies

Obviously I didn't mean that. Gmail's plain text had destroyed alignment...
anyway it doesn't matter, it's not even crucial
cheers

On Mon, Aug 8, 2016 at 10:01 AM, Greg KH <greg@kroah.com> wrote:
> On Sun, Aug 07, 2016 at 05:53:15PM +0300, Charls D. Chap wrote:
>> On Sun, Aug 7, 2016 at 7:39 AM, Greg KH <greg@kroah.com> wrote:
>> > On Sun, Aug 07, 2016 at 12:22:03AM +0300, Charls D. Chap wrote:
>> >> I want to transform some C source files. following Linux kernel coding style.
>>
>> My questions are more generic, i am interesting in an automatic way for
>> identation!
>
> Why?  It's best to do it "by hand" after using a few basic indent rules,
> as Lindent provides.
>
>> And also, i am interesting to what kernel developers will
>> do in the following cases
>
> Why?
>
>> please take a look to this example
>> width is 90, what a kernel developer will do? spliti in two lines, or
>> leave it us it is,
>> cause i think it's more readable, in this way
>> qq->run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
>> qq->vcpu, 0);
>
> That doesn't look readable at all, are you sure you ment it to look like
> that?
>
>> Also, have you find a way to tell indent not to indent, struct definitions?
>> In .h, when you have a huge structure definition, it's more readable,
>> to have it's struct friend one below the other, aligned!
>> struct kvm_mem_bank {
>>           struct list_head           list;
>>          u64                              guest_phys_addr;
>>          void                              *host_addr;
>>         u64                               size;
>> };
>
> That's not aligned at all :(
>
>> This also counts for variables initiliazation
>> int x = 0
>> char  *dog         = animal->dog->name;
>> char  *cat          = animal->cat->name;
>> char * elephant = animal->elephant->name;
>>
>> Any ideas?
>
> Don't do the above, it looks horrible.
>
>> - Does script/Lindent STRICTLY follows all linux kernel coding style rules?
>
> No, it gets you close.
>
>> - What scripts/templates do you use/suggest for elegant code style
>> with the fact that
>>   we are talking about Linux Kernel Coding?
>
> Use an editor with the proper settings and then fix it up by hand.
>
> Or even better yet, just always write your code using the proper
> settings.
>
>> The GNU guys suggest indent with the following parameters:
>> -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4
>> -cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai
>> -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1
>
> Where do they say that?
>
>> On the other hand:
>> Linux/script/Lindent contains:
>> -npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1
>
> And the differnces are what?
>
>> Differences so far:
>> 1)
>> indent with gnu parameters inserts a space on labels eg.
>>  err: vs
>> err:
>
> Don't put a space.
>
>> 2)
>> indent with gnu parameters inserts 26 spaces
>> #endif                                                          /*
>> something like this                 */
>
> That doesn't make sense, does it?
>
>> So probably gnu site is outdated?
>
> What gnu site?
>
> You do know _why_ we have a coding style, right?  It's not about being
> pedantic, it's about your brain.
>
> thanks,
>
> greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-08-08 10:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-06 21:22 Linux Coding style template Charls D. Chap
2016-08-07  4:39 ` Greg KH
2016-08-07 14:53   ` Charls D. Chap
2016-08-08  7:01     ` Greg KH
2016-08-08 10:14       ` Charls D. Chap

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.