-
Notifications
You must be signed in to change notification settings - Fork 81
Introduce default format for code base. #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
It is a good idea to have just one consistent coding style in whole project, but I dislike your proposed code style where are too many spaces around parenthesis. E.g. spaces around void in |
434a986
to
b181619
Compare
Actually I don't mind which formatting style is to be used. There are even some defaults styles ( Just choose a style and we can stick to it. |
Try something like this?
|
AFAIK I would suggest having Having also |
BTW I already pushed another version of reformatted source code settings (based on the initial format settings) when writting #19 (comment) , so you might want to check, if you like it more. |
According to http://releases.llvm.org/3.9.0/tools/clang/docs/ClangFormatStyleOptions.html possible values are:
Already part of
Also part of
|
b181619
to
293bb10
Compare
You are right. (saw the
It was more meant to be explicit. I update the PR using these settings:
|
Signed-off-by: Victor Toni <[email protected]>
293bb10
to
4068ed9
Compare
src/ifvc.c
Outdated
} | ||
|
||
/* | ||
** Builds up a vector with the interface of the machine. Calls to the other functions of | ||
** Builds up a vector with the interface of the machine. Calls to the other | ||
*functions of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is badly wrapped comment. Such changes are really not acceptable.
4068ed9
to
5b47279
Compare
Changed the mentioned part manually so that future calls of |
src/confread.c
Outdated
if(bufPtr == readSize) { | ||
while (!finished) { | ||
// If readpointer is at the end of the buffer, we should read next | ||
// chunk... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same there
src/igmp.c
Outdated
for (i = 0; i < MAX_UPS_VIFS; i++) { | ||
if (-1 != upStreamIfIdx[i]) { | ||
// Check if the source address matches a valid address on upstream | ||
// vif. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
} | ||
} else { | ||
// Activate the route. | ||
int vifindex = checkVIF->index; | ||
my_log(LOG_DEBUG, 0, "Route activate request from %s to %s on VIF[%d]", | ||
inetFmt(src,s1), inetFmt(dst,s2), vifindex); | ||
my_log(LOG_DEBUG, 0, "Route activate request from %s to %s on VIF[%d]", inetFmt(src, s1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather let inetFmt(src, s1)
at second line after wrap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the result of automatic reformatting.
It can be changed either by having other formatting options (which would still look differently) or
it could be solved by using clang directives such as
int formatted_code;
// clang-format off
void unformatted_code ;
// clang-format on
void formatted_code_again;
I would prefer rather not introduce clang specific stuff into the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what does it mean? It means that automatic reformatting is not a perfect solution and has problems.
Therefore we should use it only as help tool, not enforcement, like here.
5b47279
to
60f7924
Compare
src/mcgroup.c
Outdated
@@ -71,17 +65,19 @@ static int joinleave( int Cmd, int UdpSock, struct IfDesc *IfDp, uint32_t mcasta | |||
* The join is bound to the UDP socket 'UdpSock', so if this socket is | |||
* closed the membership is dropped. | |||
* | |||
* @return 0 if the function succeeds, 1 if parameters are wrong or the join fails | |||
* @return 0 if the function succeeds, 1 if parameters are wrong or the join | |||
* fails |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
60f7924
to
0603abc
Compare
* To make reformatting reproducible `make reformat` was used. Signed-off-by: Victor Toni <[email protected]>
0603abc
to
dc5aa02
Compare
} else if (src == checkVIF->InAdr.s_addr) { | ||
my_log(LOG_NOTICE, 0, | ||
"Route activation request from %s for %s is " | ||
"from myself. Ignoring.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not split string into more multiline parts.
inetFmt(src, s1), inetFmt(dst, s2), i); | ||
my_log(LOG_NOTICE, 0, | ||
"The source address %s for group %s is " | ||
"from downstream VIF[%d]. Ignoring.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here (and on other places)
" -h Display this help screen\n" | ||
" -d Run in debug mode. Output all messages on stderr\n" | ||
" -v Be verbose. Give twice to see even debug messages.\n" | ||
"\n" PACKAGE_STRING "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here should be newline, after each "\n" to visually identify end of lines.
|
||
// Global vars... | ||
static int sighandled = 0; | ||
#define GOT_SIGINT 0x01 | ||
#define GOT_SIGHUP 0x02 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let that space here, to have visually aligned those #defines
) { | ||
my_log( LOG_ERR, errno, "failed to detach daemon" ); | ||
if (close(0) < 0 || close(1) < 0 || close(2) < 0 || open("/dev/null", 0) != 0 || dup2(0, 1) < 0 || | ||
dup2(0, 2) < 0 || setpgid(0, 0) < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previous wrapping to 3 lines was better. close() calls on one line, open+dup() on second line and setpgid() on third.
#define MAX_IP_PACKET_LEN 576 | ||
#define MIN_IP_HEADER_LEN 20 | ||
#define MAX_IP_HEADER_LEN 60 | ||
#define IP_HEADER_RAOPT_LEN 24 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And let those defines aligned as they were too
((uint8_t *)&InAdr.s_addr)[ 0 ], | ||
((uint8_t *)&InAdr.s_addr)[ 1 ], | ||
((uint8_t *)&InAdr.s_addr)[ 2 ], | ||
((uint8_t *)&InAdr.s_addr)[ 3 ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And line wrapping here was also better before reformatting
* queries. | ||
* | ||
* It might be better to send only a query on the interface the leave | ||
* was accepted on and remove only that interface from the route. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not good reformat. Second sentence is also part of FIXME, but after change is not visually anymore.
inetFmt(Dp->InAdr.s_addr,s1), | ||
inetFmt(allhosts_group,s2), | ||
conf->queryResponseInterval); | ||
my_log(LOG_DEBUG, 0, "Sent membership query from %s to %s. Delay: %d", inetFmt(Dp->InAdr.s_addr, s1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here also put inetFmt on second line
|
||
/******************************************************************************* | ||
* Opens config file specified by filename. | ||
******************************************************************************/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reformat (and on other places too) introduce inconsistency. As in other files is used just:
/**
* ...
* ...
*/
@ViToni seems that auto-reformat by robot/machine for everything does not work as expected. After automatic reformat it needs some manual work to fix some parts. So I do not think that "make reformat" target is a good idea. But, this is really an improvement for the code... so are you going to fix needed parts manually and finish this work in this pull request? |
The first commit introduces a new goal:
make reformat
based on clang-reformat (at least version 3.9 should be used).This target is optional.
The second commit contains all changes after the execution of this command.
In the future committers can normalize their code by simply using the make goal.