Skip to main content



      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] Wed, 13 November 2019 21:40 Go to next message
Eclipse UserFriend
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 06:03 Go to previous messageGo to next message
Eclipse UserFriend
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 06:21 Go to previous message
Eclipse UserFriend
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: Tue Jun 24 06:42:05 EDT 2025

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

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

Back to the top