LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-12-2008, 02:40 PM   #1
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Rep: Reputation: 40
help with 'indent' formatting of C source


Hi group.

I have this on running debate about how a C source file SHOULD BE formatted. So I use indent to format it to my specs. Right now I can't get it to the way I want it. For example, this is the output
from indent:
int
Quit (
)
{
gettimeofday ( &Timer, '\0' );
localtime_r ( &Timer.tv_sec, &Time );
fprintf ( stderr, "%.2d:%.2d:%.2d.%.4d ", ( int )Time.tm_hour,
( int )Time.tm_min, ( int )Time.tm_sec,
( int )Timer.tv_usec / 100 );;
printf ( "\x1B[1;34;40m" "Exiting" "\x1B[0;0;0m" "\x1B[K\n" );
exit ( 0 );
}
I would like it to look like this:
int
Quit ( ) {
gettimeofday ( &Timer, '\0' );
localtime_r ( &Timer.tv_sec, &Time );
fprintf ( stderr, "%.2d:%.2d:%.2d.%.4d ",
( int )Time.tm_hour,
( int )Time.tm_min, ( int )Time.tm_sec,
( int )Timer.tv_usec / 100 );;
printf ( "\x1B[1;34;40m" "Exiting" "\x1B[0;0;0m" "\x1B[K\n" );
exit ( 0 ); }
My indent.pro looks like this:
-nsai
-nsaf
-nut
-bc
-bad
-bap
-bbb
-br
-cli2
-bfde
-ppi 3
-nsai
-nsaf
-prs
-nce
-ncdw
-bl
-nsaw
-nbc
-nbad
-nbap
-nbbb
-ncdb
-ncs
-nip
-brs
-prs
Any ideas??

Last edited by MrUmunhum; 10-12-2008 at 02:45 PM.
 
Old 10-12-2008, 04:48 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You should put code inside [ code ]...[ /code ] blocks to preserve the indentation when posting code segments. The .profile.pro options you posted result in:
Code:
 indent ind1 -st
int
Quit (
 )
{
  gettimeofday ( &Timer, '\0' );
  localtime_r ( &Timer.tv_sec, &Time );
  fprintf ( stderr, "%.2d:%.2d:%.2d.%.4d ", ( int )Time.tm_hour,
            ( int )Time.tm_min, ( int )Time.tm_sec,
            ( int )Timer.tv_usec / 100 );;
  printf ( "\x1B[1;34;40m" "Exiting" "\x1B[0;0;0m" "\x1B[K\n" );
  exit ( 0 );
}
There is a -br and -bl option handling braces. I can't imagine why anyone would want the closing brace on the last line of code. Unless you have a very small block contained on one line of code.

Last edited by jschiwal; 10-12-2008 at 04:50 PM.
 
Old 10-13-2008, 01:17 PM   #3
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Original Poster
Rep: Reputation: 40
That is exactly what I want.

Quote:
Originally Posted by jschiwal View Post
You should put code inside [ code ]...[ /code ] blocks to preserve the indentation when posting code segments. The .profile.pro options you posted result in:
Code:
 indent ind1 -st
int
Quit (
 )
{
  gettimeofday ( &Timer, '\0' );
  localtime_r ( &Timer.tv_sec, &Time );
  fprintf ( stderr, "%.2d:%.2d:%.2d.%.4d ", ( int )Time.tm_hour,
            ( int )Time.tm_min, ( int )Time.tm_sec,
            ( int )Timer.tv_usec / 100 );;
  printf ( "\x1B[1;34;40m" "Exiting" "\x1B[0;0;0m" "\x1B[K\n" );
  exit ( 0 );
}
There is a -br and -bl option handling braces. I can't imagine why anyone would want the closing brace on the last line of code. Unless you have a very small block contained on one line of code.
Thanks for the comments. I will use the code keyword from now on.

The -br and -bl does what I want for IFs, that is good. But I do want what you can't image. I am dyslexic and do not see thing the same as you do.
The lone brackets confuse my eyes, they just cause visual interference.
Using your example, here is what I want:
Code:
int
Quit( )  {

  gettimeofday( &Timer, '\0' );
  localtime_r( &Timer.tv_sec, &Time );
  fprintf( stderr, "%.2d:%.2d:%.2d.%.4d ", (int) Time.tm_hour,
            (int) Time.tm_min, (int) Time.tm_sec,
            (int) Timer.tv_usec / 100 );;
  printf( "\x1B[1;34;40m" "Exiting" "\x1B[0;0;0m" "\x1B[K\n" );
  exit ( 0 );  }
Note the brackets have two spaces before them.

I am beginning to think I need to run the output through an AWK or SED program?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't stop NVU formatting source code (even though I've disabled it) gogul2k Linux - Software 0 09-14-2007 05:21 AM
indent phoenix7 Linux - Software 6 08-30-2005 12:14 PM
A more sensible editor with indent Haraldsh Linux - Software 2 11-12-2004 06:49 AM
no indent jesus_edu Linux - Newbie 0 04-13-2004 10:45 AM
indent chrismiceli Linux - General 1 05-12-2003 07:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration