Script needed to align java/c/C++ code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script needed to align java/c/C++ code
# 1  
Old 06-09-2009
Script needed to align java/c/C++ code

Hi All,

Does anyone has script to align java/c/c++ code? or pls advice

I need it very badly...... :-(

Thanks in advance
# 2  
Old 06-09-2009
What exactly do you mean by align java/c/c++ code?
# 3  
Old 06-09-2009
If you mean "indenting", for C there's indent (works for C++ too). For Perl there's Perltidy
# 4  
Old 06-09-2009
I just need to correct the indent of each line as per java standards....

Say for eg if have a input like below :
Code:
#######
import java.util.Date;

public class Test {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Date OldDate = new Date("04/15/2008"); 
		Date TodaysDate = new Date();
	System.out.println("TodaysDate : " + TodaysDate.getTime()); 
	long mills_per_day = 1000 * 60 * 60 * 24;
	System.out.println("mills_per_day : " + mills_per_day);
		long day_diff = ( TodaysDate.getTime() - OldDate.getTime() ) / mills_per_day; 
		System.out.println("day_diff : " + day_diff);
String b2bi_errors1 = "errrrrrrrrrr";
		String clin = "2342345";
		String b2bi_errors = getQuotedString(b2bi_errors1 
			+ "; IOMSales400: CLIN "
		+ clin
			+ ": Transport CLINs require at least 2 " 
				+ "locations for proper pricing.");
//String ret = getDoubleQuotedString("String");
		System.out.println("Return String : " + b2bi_errors);
	String[] locationLabel = new String[1];
	}

	private static String getQuotedString(String string) {
String ret = "\"" + string + "\"";
		return ret;
	}
	
}
#######################

So, my duty is to align the indent of each line... like below
Code:
###########################
import java.util.Date;


public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Date OldDate = new Date("04/15/2008"); 
		Date TodaysDate = new Date();
		System.out.println("TodaysDate : " + TodaysDate.getTime()); 
		long mills_per_day = 1000 * 60 * 60 * 24;
		System.out.println("mills_per_day : " + mills_per_day);
		long day_diff = ( TodaysDate.getTime() - OldDate.getTime() ) / mills_per_day; 
		System.out.println("day_diff : " + day_diff);
		String b2bi_errors1 = "errrrrrrrrrr";
		String clin = "2342345";
		String b2bi_errors = getQuotedString(b2bi_errors1 
				+ "; IOMSales400: CLIN "
				+ clin
				+ ": Transport CLINs require at least 2 " 
				+ "locations for proper pricing.");
//		String ret = getDoubleQuotedString("String");
		System.out.println("Return String : " + b2bi_errors);
		String[] locationLabel = new String[1];
	}

	private static String getQuotedString(String string) {
		String ret = "\"" + string + "\"";
		return ret;
	}
	
}
#######################


Last edited by Franklin52; 06-09-2009 at 10:03 AM.. Reason: please add code tags
# 5  
Old 06-09-2009
if u r using vi editor

try this

there is command to alinment

1. escape (escape mode)
2. gg (goto first line)
3. shift+v (visual mode)
4. shift+g (goto to last line)
5. = (alinment)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing Username & password through shell script to java code

Hi, I have a shell script (script.sh) in which we are calling java code which asks for Username: Password: for authentication purpose currently we are passing the credential manually and run the script. but I am trying echo -e "user_id\npassword" | script.sh but its not... (1 Reply)
Discussion started by: rakeshtomar82
1 Replies

2. Shell Programming and Scripting

Shell script with Java code in Cron

Dear All, I have a shell script which has JAVA code inside it runs perfectly on command line. But while I set it on cron, all rest of the script runs but Java code doesnt. java -cp... (3 Replies)
Discussion started by: Deei
3 Replies

3. UNIX for Dummies Questions & Answers

Script Shell in java code

Hello, I try to run a script shell from a java program: but it runs only if i do :chmod 777 myShellScript in the terminal Please how can i insert chmod 777 in my java code without going through the terminal? Thank you (1 Reply)
Discussion started by: chercheur857
1 Replies

4. Programming

Script shell in java code

Hello, Please i want to insert this code in a java program because i need to call a java function inside the while: Please how can i do? thank you so much (9 Replies)
Discussion started by: chercheur857
9 Replies

5. Shell Programming and Scripting

Code java in script shell

Hello; Is it possible to insert Java code in a shell script, if so how please? Thank you (0 Replies)
Discussion started by: chercheur857
0 Replies

6. Programming

Script Shell in java code

Hello, This is my script shell: echo Mon premier script echo Liste des fichiers : ls -la exit 0 This is my code java: public class test { public static void main(String args) { try { Process process = Runtime.getRuntime().exec("sh script1.sh"); } catch... (2 Replies)
Discussion started by: chercheur857
2 Replies

7. Shell Programming and Scripting

Block of code replacement in Java source code through Unix script

Hi, I want to remove the following code from Source files (or replace the code with empty.) from all the source files in given directory. finally { if (null != hibernateSession && hibernateSession.isOpen()) { //hibernateSession.close(); } } It would be great if the script has... (2 Replies)
Discussion started by: hareeshram
2 Replies

8. Programming

date change shell script in java code

hi, I have a code to connect to a remote Linux server through windows using SSH, with host-name, username and password built in the code. I want to add a shell script in the code which should execute automatically without any user intervention. (as u know that date change requires you/us to be... (0 Replies)
Discussion started by: tarkan
0 Replies

9. Programming

can i have an optimal solution for this java code ? Facing Java heap space problem even at 3GB heaps

My desired output is run: for this 1 for this 2 for this 3 for this 4 for this 5 for this 1,2 1->2 for this 2,3 2->3 for this 3,4 3->4 for this 4,5 4->5 for this 1,2,3 1->2,3 (2 Replies)
Discussion started by: vaibhavkorde
2 Replies
Login or Register to Ask a Question