httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roy T. Fielding" <field...@liege.ICS.UCI.EDU>
Subject Style options with indent
Date Tue, 16 Jul 1996 05:02:47 GMT
Ben, stop using TABs -- all your examples are screwed up every time
I try to include them in a message, which is pretty stupid when you
are trying to get consensus on whitespace style.

I still intend to run indent on the code before making any large
enhancements to a file -- it just isn't worth the effort of reading
the code in its current form [I did the same to NCSA httpd back in '93,
but wasn't able to commit back then :)].  Below are the indent options.

> 1. Function declarations
> Note: Illustrated using 7a.
> 
> a) int
>    main(...)
> b) int main(...)

a) -psl -di0
b) -npsl -di0

> 2. Commas
> 
> a)      f(a, b);
> b)      f(a,b);

a) Forced by indent
b) [not an option]

> 3. Braces
> Note: Illustrated using 15a.
> 
> a1)     if(x) {
>             code;
>         } else {
>             code;
>         }
> a2)     if(x) {
>             code;
>         }
>         else {
>             code;
>         }
> b)      if(x)
>         {
>             code;
>         }
>         else
>         {
>             code;
>         }
> c)      if(x)
>             {
>             code;
>             }
>         else
>             {
>             code;
>             }

a1) -br -ce
a2) -br -nce
b)  -bl -nce
c)  [not an option]

> 4. For statements
> 
> a)      for(a ; b ; c)
> b)      for(a; b; c)

a) [not an option]
b) Forced by indent

> 5. Comment indentation
> 
> a)      code;
>         /* comment */
>         code;
> b)      code;
>     /* comment */
>         code;

a) -d0
b) -d1

> 6. Switches
> Note: Illustrated using 3a.
> 
> a)      switch(x) {
>         case a:
>             code;
>         case b:
>             code;
>         }
> b)      switch(x) {
>             case a:
>                 code;
>             case b:
>                 code;
>         }

a) -cli0
b) -cli1
c) -cli0.5   [half-indents, what Tony and I use]

> 7. Function declarations(2)
> Note: Illustrated using 1b.
> 
> a) int main(...)
> b) int main (...)

a) -npcs
b) -pcs [also affects uses]

> 8. Assignment
> 
> a)      a=b
> b)      a = b

a) [not an option]
b) Forced by indent

> 9. Arithmetic operators
> 
> a)      a+b
> b)      a + b

a) [not an option]
b) Forced by indent

> 10. Logical operators
> 
> a)      a<b
> b)      a < b

a) [not an option]
b) Forced by indent

> 11. Incrementation
> 
> a)      ++a
> b)      ++ a

a) Forced by indent
b) [not an option]

> 12. Function declarations(3)
> Note: Illustrated using 1b, 7a.
> 
> a) int main()
>    {
>         code;
>    }
> b) int main()
>         {
>         code;
>         }
> c) int main() {
>    }

a) Forced by indent
b) [not an option]
b) [not an option]

> 13. Null pointer tests
> 
> a) if(p == NULL)
> b) if(!p)

a) [not an option]
b) [not an option]

> 14. Capitalisation of enums
> 
> a) enum x { ONE, TWO };
> b) enum x { one, two };
> c) No rule.

a) [not an option]
b) [not an option]

> 15. Spaces after keywords
> 
> a) if(x)
> b) if (x)

a) [not an option]
b) Forced by indent

>         1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 DF
> 
> Chuck   b  a  b  b  b  b  a  b  b  b  a  a     a    4
> Randy   a  a  a2 a  a  a  b  b  b  b  a  a          3
> Paul    a  a  a1 b  a  b  a  b  b  b  a  a  a  a    4.5
> Ben     b  b  c  a  b  a  a  a  a  b  a  b  b  c  a 7
> RST     b  a  a2 b  a  a  b  b  b  b  a  a  b  c    1
> Mark    b  b  a  b  a  b  a  b  b  b  a  a          2
> David   a  a  b  a
> Alexei  b  a  a2 b  a  a  b  b  b  b  a  a  b  c    1
> Rasmus  b  a  a1 b  a  a  a  b  b  b  a  a          0.5
> Jim     a  a  a2 b  a  a  a  b  b     a  a          1
> Roy     b  a  b  b  a  b  a  b  b  b  a  a     b    2
> 
> Total   b  a  a2 b  a  a  a  b  b  b  a  a  b  c  a

Your list does not include indentation size, which was agreed to be 4

   -i4

In summary, this means

   indent infile.c outfile.c -i4 -npsl -di0 -br -nce -d0 -cli0 -npcs 

though -cli0.5 looks a lot better (to me) in the code I tested.
Of course, we would just put these in a .indent.pro file.

Here are the indent options that haven't been mentioned by vote.

     -bacc,-nbacc
               If -bacc is specified,  a  blank  line  is  forced
               around  every  conditional compilation block.  For
               example, in front of every #ifdef and after  every
               #endif.   Other blank lines surrounding these will
               be swallowed.  Default: -nbacc.

     -bad,-nbad
               If -bad is specified, a blank line is forced after
               every block of declarations.  Default: -nbad.
 
     -bap,-nbap
               If -bap is specified, a blank line is forced after
               every procedure body.  Default:  -nbap.
 
     -bbb,-nbbb
               If -bbb is  specified,  a  blank  line  is  forced
               before every block comment.  Default:  -nbbb.
 
     -bc,-nbc    If -bc is specified, then a  NEWLINE  is  forced
               after each comma in a declaration.  -nbc turns off
               this option.  Default: -bc.

     -bs,-nbs
          Enable (disable) the forcing of a blank  after  sizeof.
          Some people believe that sizeof should appear as though
          it were a procedure call (-nbs, the default)  and  some
          people  believe  that  since  sizeof is an operator, it
          should always be treated that  way  and  should  always
          have a blank after it.
 
     -cn   The column in which comments on code start.
           Default:  -c33.
 
     -cdn  The column in which comments  on  declarations  start.
          The  default is for these comments to start in the same
          column as those on code.
 
     -cdb,-ncdb
          Enable (disable) the placement of comment delimiters on
          blank  lines.   With this option enabled, comments look
          like this:
          /*
          * this is a comment
          */
 
          Rather than like this:
 
          /* this is a comment */
 
          This only affects block comments, not comments to the  right
          of code. Default:  -cdb.
 
     -cin  Sets the continuation indent to be  the  value  of  n.
          Continuation lines will be indented the value of n from
          the beginning of  the  first  line  of  the  statement.
          Parenthesized  expressions have extra indentation added
          to indicate the nesting, unless -lp is in effect.  - ci
          defaults to the same value as -i.
 
     -dj,-ndj
          -dj left justifies declarations.  -ndj indents declara-
          tions the same as code.  Default:  -ndj.
 
     -ei,-nei
          If -ei is enabled, ifs following elses  will  have  the
          same  indentation  as the preceding if statement. If it
          is disabled, ifs following elses will be  indented  one
          extra level. Default:  -ei.
 
     -eei,-neei
          If -eei is specified, an  extra  expression  indent  is
          applied on continuation lines of the expression part of
          if() and while().  These  continuation  lines  will  be
          indented  one extra level - twice instead of just once.
          This is to avoid the confusion  between  the  continued
          expression  and  the statement that follows the if() or
          while().  Default: -neei.
 
     -fc1,-nfc1
          Enables (disables)  the  formatting  of  comments  that
          start  in  column 1.  Often, comments whose leading `/'
          is in column 1 have been carefully  hand  formatted  by
          the  programmer.   In such cases, -nfc1 should be used.
          Default:  -fc1.
 
     -ip,-nip
          Enables  (disables)  the   indentation   of   parameter
          declarations from the left margin.  Default:  -ip .
 
     -ln   Maximum length of an output line with a trailing  com-
          ment.  Default:  -l78.
 
     -lcn  Sets the line length for  block  comments  to  n.   It
          defaults  to being the same as the usual line length as
          specified with -l.
 
     -lp,-nlp
          Lines up code surrounded by parenthesis in continuation
          lines.   If  a line has a left parenthesis which is not
          closed on that line, then continuation  lines  will  be
          lined  up to start at the character position just after
          the left parenthesis.  For example, here is how a piece
          of continued code looks with -nlp in effect:
               p1 = first_procedure(second_procedure(p2, p3),
                              third_procedure(p4, p5));
 
          With -lp in effect (the default) the code  looks  some-
          what clearer:
               p1 = first_procedure(second_procedure(p2, p3),
                                      third_procedure(p4, p5));
 
          Inserting a couple more NEWLINE characters we get:
               p1 = first_procedure(second_procedure(p2,
                                                  p3),
                                      third_procedure(p4,
                                                p5));
 
          This example was generated with -lp.
 
     -sc,-nsc
          Enables (disables) the placement of asterisks (`*'s) at
          the left edge of all comments. Default:  -sc.
 
     -sob,-nsob
          If -sob is  specified,  indent  will  swallow  optional
          blank  lines.   You  can  use  this to get rid of blank
          lines after declarations.  Default:  -nsob.
 
     -T typename
          Add typename to the list of type keywords.  Names accu-
          mulate:   -T can be specified more than once.  You need
          to specify all the typenames that appear in  your  pro-
          gram  that  are  defined  by typedefs - nothing will be
          harmed if you miss a few, but the program won't be for-
          matted  as  nicely  as  it  should.  This sounds like a
          painful thing to have to do, but it is really a symptom
          of  a  problem in C:  typedef causes a syntactic change
          in the language and indent cannot find all typedefs.
 
[Actually, we probably won't need -T since we don't indent declarations].

.....Roy

Mime
View raw message