Depending on the source language, you could try out GNU indent. It can do a large number of things relating to the indentation of source code, though it might be more complex than you need.
For example, if I give the following program to indent -di0 <inputfile>
#include <stdio.h>
int main(int argc, char **argv)
{
int i;
int j;
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10; j++)
{
printf("x");
}
}
}
It will replace it with:
#include <stdio.h>
int
main(int argc, char **argv)
{
int i;
int j;
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
printf("x");
}
}
}
Or, if you need something stupid simple, there is the expand/unexpand
commands.