Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Formatting braces nested statements in a macro call
Formatting braces nested statements in a macro call [message #1817015] Thu, 14 November 2019 02:40 Go to next message
johan zahri is currently offline johan zahriFriend
Messages: 4
Registered: April 2019
Junior Member
Hi,
Eclipse is formatting my code as follows:
error_t BAPP_APLO_process_login(BAPP_INSE_Request_p req) {

	BAPP_COLO_iprintfln("Service login is called by req no %d!", req->rn);
	BAPP_COST_trycatch_context_p ctx = NULL;

	initial_try(&ctx);
	exec(ctx,
			{ BAPP_COLO_iprintfln("Try is working!"); BAPP_COLO_iprintfln("Try is working another line!"); BAPP_COLO_iprintfln("Try is woring one more time!"); });
	catch_errno(ctx, errno_args(ENOMEM, EINVAL, 0),
			{ BAPP_COLO_iprintfln("Caught an error!"); });
	finally(&ctx);

	return BAPP_OK;
}


Is there a way for me to tell eclipse to format it as such:
error_t BAPP_APLO_process_login(BAPP_INSE_Request_p req) {

	BAPP_COLO_iprintfln("Service login is called by req no %d!", req->rn);
	BAPP_COST_trycatch_context_p ctx = NULL;

	initial_try(&ctx);
	exec(ctx,
 	{ 
            BAPP_COLO_iprintfln("Try is working!"); 
            BAPP_COLO_iprintfln("Try is working another line!"); 
            BAPP_COLO_iprintfln("Try is woring one more time!"); 
        });
	catch_errno(ctx, errno_args(ENOMEM, EINVAL, 0),
			{ BAPP_COLO_iprintfln("Caught an error!"); });
	finally(&ctx);

	return BAPP_OK;
}


Thanks,
Johan
Re: Formatting braces nested statements in a macro call [message #1817522 is a reply to message #1817015] Mon, 25 November 2019 11:03 Go to previous messageGo to next message
johan zahri is currently offline johan zahriFriend
Messages: 4
Registered: April 2019
Junior Member
Ugly n crude way of working around this without the hassle of coding for formats etc is to insert dummy comment lines in between statements. For nested statements will look dead ugly. If anyone has a work around would really appreciate it :-D
error_t BAPP_APLO_process_login(BAPP_INSE_Request_p req) {

	BAPP_COLO_iprintfln("Service login is called by req no %d!", req->rn);
	BAPP_COST_trycatch_context_p ctx = NULL;

	initial_try(&ctx);
	exec(ctx,
 	{ 
//
            BAPP_COLO_iprintfln("Try is working!"); 
//here is the ugly part
            if (1) {
//BAPP_COLO_iprintfln stmt should indent further.. but can't...
            BAPP_COLO_iprintfln("Try is working another line!"); 
//
            }
//nested statements look very ugly 
            BAPP_COLO_iprintfln("Try is woring one more time!"); 
//
        });
	catch_errno(ctx, errno_args(ENOMEM, EINVAL, 0),
	{ 
//
	    BAPP_COLO_iprintfln("Caught an error!"); 
//
	});
	finally(&ctx);

	return BAPP_OK;
}
Re: Formatting braces nested statements in a macro call [message #1817523 is a reply to message #1817522] Mon, 25 November 2019 11:21 Go to previous message
johan zahri is currently offline johan zahriFriend
Messages: 4
Registered: April 2019
Junior Member
Another solution is to add /**/ before each statement and add tabs in the comment accordingly (rolling eyes)
	exec(ctx,
		{
		/**/BAPP_COLO_dprintfln("Tests for selecting users!");
		/**/
		/**/if (test_select_users(con, &row_count)) {
		/*	*/BAPP_COLO_eprintfln("Tests for selecting users failed");
		/*	*/asprintf(&buff, "%s, test_select_users returned row_count: %d",
		/*		*/BAPP_ERROR_DESC_USER_NOT_FOUND, row_count);
		/*	*/throw_signal_code_with_simple_string_data(ctx, BAPP_ERROR_CODE_USER_NOT_FOUND, buff);
		/**/} else {
		/**/
		/**/if (row_count > 0) {
		/*  */ko = test_delete_users(con);
		/*  */if (ko) {
		/*   */asprintf(&buff, "%s, test_delete_users returned error: %d",
		/*		*/BAPP_ERROR_DESC_UNABLE_TO_DELETE_DB_ROW, ko);
		/*  */throw_signal_code_with_simple_string_data(ctx, BAPP_ERROR_CODE_UNABLE_TO_DELETE_DB_ROW, buff);
		/*	*/}
		/**/}
		//
		}
		/**/BAPP_COLO_dprintfln("do other things using db!");
//
		});
Previous Topic:some macro could not be resolved but CDT can explore the macro expansion in linux kernel code
Next Topic:Adding common "include" to Settings
Goto Forum:
  


Current Time: Fri Mar 29 09:39:39 GMT 2024

Powered by FUDForum. Page generated in 0.02304 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top