gnu indent: how to avoid extra indent?

Discussion in 'C Programming' started by dt, Nov 15, 2006.

  1. dt

    dt Guest

    Greetings,

    I'm having some trouble understanding the plethora of options
    available for GNU indent for my C code.

    Except for the function's opening {, I want all code to line
    up under the opening { of the block it resides in.

    Let me explain with an example. I'm using this command,

    gindent -npro -kr -bl -bli4 -nce < ncmp.c > ncmp2.c

    and ncmp2.c is neatly formatted like this,

    int32_t dcrp_oidncmp(dcroid_t * a, dcroid_t * b, size_t n)
    {
    size_t i;
    size_t szA = OID_LEN(a);
    size_t szB = OID_LEN(b);

    if (n == 0)
    {
    return 0;
    }
    else if (szB == 0)
    {
    return 1;
    }
    else
    {
    for (i = 0; i < n && i < szA && i < szB; i++)
    {
    if (OID_AT(a, i) > OID_AT(b, i))
    return 1;
    else if (OID_AT(a, i) < OID_AT(b, i))
    return -1;
    }
    return 0;
    }
    }

    However, notice the extra indention of code for inner blocks;
    I want output to omit that extra indention, like this output,

    int32_t dcrp_oidncmp(dcroid_t * a, dcroid_t * b, size_t n)
    {
    size_t i;
    size_t szA = OID_LEN(a);
    size_t szB = OID_LEN(b);

    if (n == 0)
    {
    return 0;
    }
    else if (szB == 0)
    {
    return 1;
    }
    else
    {
    for (i = 0; i < n && i < szA && i < szB; i++)
    {
    if (OID_AT(a, i) > OID_AT(b, i))
    return 1;
    else if (OID_AT(a, i) < OID_AT(b, i))
    return -1;
    }
    return 0;
    }
    }

    Except for the function's opening {, all code is lined up
    under the opening { of the block it resides in.

    I don't seem to see any options that turn off this extra
    indent. How do I do this? Any ideas?

    Regards,

    David

    --
    Posted via a free Usenet account from http://www.teranews.com
    dt, Nov 15, 2006
    #1
    1. Advertising

  2. dt

    santosh Guest

    dt wrote:
    > Greetings,
    >
    > I'm having some trouble understanding the plethora of options
    > available for GNU indent for my C code.

    [snip]

    As your question deals with GNU indent, try posting to comp.os.linux or
    similar groups. Maybe even comp.programming.
    santosh, Nov 15, 2006
    #2
    1. Advertising

  3. dt

    CBFalconer Guest

    dt wrote:
    >
    > I'm having some trouble understanding the plethora of options
    > available for GNU indent for my C code.


    Whether or not you use DJGPP, download ind229b.zip from the djgpp
    site (www.delorie.com) and extract the man and info sections. The
    info pages are best. If you are using a *IX system you will
    probably need to convert the line endings, which unzip can do.

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>
    CBFalconer, Nov 15, 2006
    #3
  4. dt wrote:

    > I don't seem to see any options that turn off this extra
    > indent. How do I do this? Any ideas?


    The syntax for indent is pretty arcane, I would say "baroque", and I
    don't care for it. I can't answer your question directly, but here is
    the "indent.pro" I use. Let me know if you like the results better than
    the default or the switches you use:

    -bad -bap -bbo -bc -br -brs -ncdb -ce -ci4 -cli4
    -cp33 -di4 -fc1 -fca -hnl -i4 -ip4 -l75 -lp -npcs -nprs -npsl
    -saf -sai -saw -sc -nsob -nss -ts4 -nut -c4
    james of tucson, Dec 31, 2006
    #4
  5. dt

    CBFalconer Guest

    james of tucson wrote:
    > dt wrote:
    >
    >> I don't seem to see any options that turn off this extra
    >> indent. How do I do this? Any ideas?

    >
    > The syntax for indent is pretty arcane, I would say "baroque", and I
    > don't care for it. I can't answer your question directly, but here is
    > the "indent.pro" I use. Let me know if you like the results better than
    > the default or the switches you use:
    >
    > -bad -bap -bbo -bc -br -brs -ncdb -ce -ci4 -cli4
    > -cp33 -di4 -fc1 -fca -hnl -i4 -ip4 -l75 -lp -npcs -nprs -npsl
    > -saf -sai -saw -sc -nsob -nss -ts4 -nut -c4


    And here is the one I use on indent 2.2.9

    -kr -l66 -i3 -bad -di16 -lc66 -nce -ncs -cbi0 -bbo -pmt -psl -ts1
    -cdw


    --
    Some informative links:
    <http://members.fortunecity.com/nnqweb/> (newusers)
    <http://www.catb.org/~esr/faqs/smart-questions.html>
    <http://www.caliburn.nl/topposting.html>
    <http://www.netmeister.org/news/learn2quote.html>
    <http://cfaj.freeshell.org/google/> (taming google)
    CBFalconer, Dec 31, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter

    1 day gnu, whole life gnu?

    Peter, Jan 10, 2005, in forum: Java
    Replies:
    3
    Views:
    340
    John C. Bollinger
    Jan 10, 2005
  2. Peter
    Replies:
    17
    Views:
    603
    Chris Smith
    Jan 13, 2005
  3. Markus Elfring
    Replies:
    2
    Views:
    370
    Markus Elfring
    Feb 23, 2005
  4. GNU indent styles

    , Mar 23, 2006, in forum: C++
    Replies:
    10
    Views:
    686
    Phlip
    Mar 25, 2006
  5. Jonathan M. Rose

    Options for GNU Indent

    Jonathan M. Rose, Jul 13, 2007, in forum: C Programming
    Replies:
    2
    Views:
    726
    Jonathan M. Rose
    Jul 17, 2007
Loading...

Share This Page