Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

indent utility help

Status
Not open for further replies.

ezeke1

Programmer
Mar 20, 2003
41
US
I'm using the indent utility to reformat c source files and I notice that the options you provide to the utility affects the whole file. I'm wondering if its possible to only format certain sections of code instead of formatting all the code in the input file.

For example I have a source file called test.c with the following code
Code:
struct _MYSTRUCT {
int          i;
int          j;
}MYSTRUCT;

void main()
{
struct MYSTRUCT         ST;
}

After running this command
Code:
indent -i3 test.c

This is the reformatted source file
Code:
struct _MYSTRUCT {
int i;
int j;
}MYSTRUCT;

void main()
{
  struct MYSTRUCT ST;
}
There are multiple tabs after each of my variable declarations and I would like it to remain that way but after running this file through indent, I not only get the indents of 3 spaces that I ask for, but I also lose the tab spaces after the variable declarations. Is it possible to use indent the beginning of each line only?

Thank you in advance
 
There may be a way to do what you want using indent, but I don't know it.

However, you may want to look into using a text editor like Vim or Emacs to format your code. Each of those has pretty powerful facilities for automatic indentation. It may require learning a new "language" to get the scheme you want, but it's probably possible to get them to automatically do virtually anything you want to do.
 
You may also consider the standard cb utility.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top