Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BasedOnStyle: LLVM
Language: Cpp

IndentWidth: 4
ContinuationIndentWidth: 8

ColumnLimit: 120

MaxEmptyLinesToKeep: 2

AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakBeforeMultilineStrings: true
12 changes: 12 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ ChangeLog:
AUTHORS: ChangeLog
( echo "Authors and contributors, in alphabetical order: "; echo; \
sed -r "s/^Author: (.*)/\1/;t;d" $< | sort -u ) > $@

if HAVE_CLANG_FORMAT

.PHONY: reformat

reformat:
@echo "Reformatting header files..."
@CLANG_FORMAT@ -style=file -i `find . -name "*.h"`
@echo "Reformatting C files..."
@CLANG_FORMAT@ -style=file -i `find . -name "*.c"`

endif
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ AC_CONFIG_SRCDIR([src/igmpproxy.c])
AC_CONFIG_HEADERS([config.h])
AC_PROG_CC_C99

AC_CHECK_PROGS(
[CLANG_FORMAT], [clang-format clang-format-4.0 clang-format-3.9],
[AC_MSG_ERROR([clang-format was not not found during configure.])]
)
AM_CONDITIONAL([HAVE_CLANG_FORMAT], [test -n "$CLANG_FORMAT"])

AC_CANONICAL_HOST
case $host_os in
linux*|uclinux*) os=linux;;
Expand Down
47 changes: 20 additions & 27 deletions src/callout.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,18 @@
**
*/


#include "igmpproxy.h"

/* the code below implements a callout queue */
static int id = 0;
static struct timeOutQueue *queue = 0; /* pointer to the beginning of timeout queue */
static struct timeOutQueue *queue = 0; /* pointer to the beginning of timeout queue */

struct timeOutQueue {
struct timeOutQueue *next; // Next event in queue
int id;
timer_f func; // function to call
void *data; // Data for function
int time; // Time offset for next event
struct timeOutQueue *next; // Next event in queue
int id;
timer_f func; // function to call
void *data; // Data for function
int time; // Time offset for next event
};

// Method for dumping the Queue to the log.
Expand All @@ -70,7 +69,6 @@ void free_all_callouts(void) {
}
}


/**
* elapsed_time seconds have passed; perform all the events that should
* happen.
Expand All @@ -90,7 +88,7 @@ void age_callout_queue(int elapsed_time) {
if (_queue == NULL)
_queue = ptr;
last = ptr;
}
}
}

queue = ptr;
Expand All @@ -103,7 +101,7 @@ void age_callout_queue(int elapsed_time) {
_queue = _queue->next;
my_log(LOG_DEBUG, 0, "About to call timeout %d (#%d)", ptr->id, i);
if (ptr->func)
ptr->func(ptr->data);
ptr->func(ptr->data);
free(ptr);
}
}
Expand All @@ -115,8 +113,7 @@ void age_callout_queue(int elapsed_time) {
int timer_nextTimer(void) {
if (queue) {
if (queue->time < 0) {
my_log(LOG_WARNING, 0, "timer_nextTimer top of queue says %d",
queue->time);
my_log(LOG_WARNING, 0, "timer_nextTimer top of queue says %d", queue->time);
return 0;
}
return queue->time;
Expand All @@ -131,7 +128,7 @@ int timer_nextTimer(void) {
* @param data - Pointer to the function data to supply...
*/
int timer_setTimer(int delay, timer_f action, void *data) {
struct timeOutQueue *ptr, *node, *prev;
struct timeOutQueue *ptr, *node, *prev;
int i = 0;

/* create a node */
Expand All @@ -144,7 +141,7 @@ int timer_setTimer(int delay, timer_f action, void *data) {
node->data = data;
node->time = delay;
node->next = 0;
node->id = ++id;
node->id = ++id;

prev = ptr = queue;

Expand All @@ -153,37 +150,33 @@ int timer_setTimer(int delay, timer_f action, void *data) {
/* if the queue is empty, insert the node and return */
if (!queue) {
queue = node;
}
else {
} else {
/* chase the pointer looking for the right place */
while (ptr) {
if (delay < ptr->time) {
// We found the correct node
node->next = ptr;
if (ptr == queue) {
queue = node;
}
else {
} else {
prev->next = node;
}
ptr->time -= node->time;
my_log(LOG_DEBUG, 0,
"Created timeout %d (#%d) - delay %d secs",
node->id, i, node->time);
my_log(LOG_DEBUG, 0, "Created timeout %d (#%d) - delay %d secs", node->id, i, node->time);
debugQueue();
return node->id;
} else {
// Continur to check nodes.
delay -= ptr->time; node->time = delay;
delay -= ptr->time;
node->time = delay;
prev = ptr;
ptr = ptr->next;
}
i++;
}
prev->next = node;
}
my_log(LOG_DEBUG, 0, "Created timeout %d (#%d) - delay %d secs",
node->id, i, node->time);
my_log(LOG_DEBUG, 0, "Created timeout %d (#%d) - delay %d secs", node->id, i, node->time);
debugQueue();

return node->id;
Expand Down Expand Up @@ -211,8 +204,8 @@ int timer_leftTimer(int timer_id) {
/**
* clears the associated timer. Returns 1 if succeeded.
*/
int timer_clearTimer(int timer_id) {
struct timeOutQueue *ptr, *prev;
int timer_clearTimer(int timer_id) {
struct timeOutQueue *ptr, *prev;
int i = 0;

if (!timer_id)
Expand Down Expand Up @@ -261,7 +254,7 @@ int timer_clearTimer(int timer_id) {
* debugging utility
*/
static void debugQueue(void) {
struct timeOutQueue *ptr;
struct timeOutQueue *ptr;

for (ptr = queue; ptr; ptr = ptr->next) {
my_log(LOG_DEBUG, 0, "(Id:%d, Time:%d) ", ptr->id, ptr->time);
Expand Down
Loading