Page MenuHomeDevCentral

D4017.diff
No OneTemporary

D4017.diff

diff --git a/.clang-format b/.clang-format
--- a/.clang-format
+++ b/.clang-format
@@ -1,64 +1,24 @@
---
-Language: Cpp
-# BasedOnStyle: LLVM
+BasedOnStyle: LLVM
+Language: Cpp
+
AccessModifierOffset: -4
-AlignAfterOpenBracket: true
-AlignEscapedNewlinesLeft: false
-AlignOperands: true
-AlignTrailingComments: true
-AllowAllParametersOfDeclarationOnNextLine: true
-AllowShortBlocksOnASingleLine: false
-AllowShortCaseLabelsOnASingleLine: false
-AllowShortIfStatementsOnASingleLine: false
-AllowShortLoopsOnASingleLine: false
-AllowShortFunctionsOnASingleLine: All
-AlwaysBreakAfterDefinitionReturnType: false
-AlwaysBreakTemplateDeclarations: false
-AlwaysBreakBeforeMultilineStrings: false
-BreakBeforeBinaryOperators: None
-BreakBeforeTernaryOperators: true
-BreakConstructorInitializersBeforeComma: false
-BinPackParameters: true
-BinPackArguments: true
-ColumnLimit: 80
-ConstructorInitializerAllOnOneLineOrOnePerLine: false
-ConstructorInitializerIndentWidth: 4
-DerivePointerAlignment: false
-ExperimentalAutoDetectBinPacking: false
-IndentCaseLabels: false
-IndentWrappedFunctionNames: false
-IndentFunctionDeclarationAfterType: false
-MaxEmptyLinesToKeep: 1
-KeepEmptyLinesAtTheStartOfBlocks: true
-NamespaceIndentation: None
+
+AlignTrailingComments:
+ Kind: Leave
+
+AllowShortFunctionsOnASingleLine: Empty
+
+BinPackArguments: false
+BinPackLongBracedList: false
+
+ColumnLimit: 100
+
+IndentWidth: 4
ObjCBlockIndentWidth: 4
-ObjCSpaceAfterProperty: false
-ObjCSpaceBeforeProtocolList: true
-PenaltyBreakBeforeFirstCallParameter: 19
-PenaltyBreakComment: 300
-PenaltyBreakString: 1000
-PenaltyBreakFirstLessLess: 120
-PenaltyExcessCharacter: 1000000
-PenaltyReturnTypeOnItsOwnLine: 60
-PointerAlignment: Right
-SpacesBeforeTrailingComments: 1
-Cpp11BracedListStyle: true
-Standard: Cpp11
-IndentWidth: 4
-TabWidth: 8
-UseTab: Never
-BreakBeforeBraces: Attach
-SpacesInParentheses: false
-SpacesInSquareBrackets: false
-SpacesInAngles: false
-SpaceInEmptyParentheses: false
-SpacesInCStyleCastParentheses: false
-SpaceAfterCStyleCast: false
-SpacesInContainerLiterals: true
-SpaceBeforeAssignmentOperators: true
-ContinuationIndentWidth: 4
-CommentPragmas: '^ IWYU pragma:'
-ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
-SpaceBeforeParens: ControlStatements
-DisableFormat: false
-...
+
+SortIncludes:
+ Enabled: false
+SortUsingDeclarations: Never
+
+TabWidth: 4
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,7 @@
DOXYGEN=doxygen
GNU_MAKE=gmake
MAKE=${GNU_MAKE}
+REFORMAT=clang-format -i
RMDIR=rm -rf
# -------------------------------------------------------------
@@ -34,6 +35,8 @@
clean: clean-build clean-doc
+reformat: reformat-src reformat-tests
+
# -------------------------------------------------------------
# Build targets
#
@@ -51,6 +54,12 @@
${BUILD}/pkgIndex.tcl:
(cd src && $(MAKE) pkg)
+reformat-src:
+ find src -type f \( -name '*.c' -o -name '*.h' \) | xargs $(REFORMAT)
+
+reformat-tests:
+ find tests -type f \( -name '*.c' -o -name '*.h' \) | xargs $(REFORMAT)
+
# -------------------------------------------------------------
# Documentation targets
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/rabbitmq-tcl.h b/src/rabbitmq-tcl.h
--- a/src/rabbitmq-tcl.h
+++ b/src/rabbitmq-tcl.h
@@ -36,24 +36,20 @@
int amqp_will_be_non_blocking_operation(amqp_connection_state_t connection);
-int call_mq_command(int connectionNumber, Tcl_Interp *tclInterpreter,
- char *command, int argc, Tcl_Obj *const argv[]);
+int call_mq_command(int connectionNumber, Tcl_Interp *tclInterpreter, char *command, int argc,
+ Tcl_Obj *const argv[]);
ClientData get_mq_command_context(int commandNumber);
char *get_version_string();
-int mq_bindqueue(int connectionNumber, Tcl_Interp *tclInterpreter, int argc,
- Tcl_Obj *const argv[]);
-static int mq_command(ClientData clientData, Tcl_Interp *tclInterpreter,
- int argc, Tcl_Obj *const argv[]);
-int mq_connect(int connectionNumber, Tcl_Interp *tclInterpreter, int argc,
- Tcl_Obj *const argv[]);
+int mq_bindqueue(int connectionNumber, Tcl_Interp *tclInterpreter, int argc, Tcl_Obj *const argv[]);
+static int mq_command(ClientData clientData, Tcl_Interp *tclInterpreter, int argc,
+ Tcl_Obj *const argv[]);
+int mq_connect(int connectionNumber, Tcl_Interp *tclInterpreter, int argc, Tcl_Obj *const argv[]);
int mq_connected(int connectionNumber, Tcl_Interp *tclInterpreter);
int mq_disconnect(int connectionNumber, Tcl_Interp *tclInterpreter);
-int mq_get(int connectionNumber, Tcl_Interp *tclInterpreter, int argc,
- Tcl_Obj *const argv[]);
-int mq_publish(int connectionNumber, Tcl_Interp *tclInterpreter, int argc,
- Tcl_Obj *const argv[]);
+int mq_get(int connectionNumber, Tcl_Interp *tclInterpreter, int argc, Tcl_Obj *const argv[]);
+int mq_publish(int connectionNumber, Tcl_Interp *tclInterpreter, int argc, Tcl_Obj *const argv[]);
int mq_usage(Tcl_Interp *tclInterpreter);
int mq_version(Tcl_Interp *tclInterpreter);
diff --git a/src/rabbitmq-tcl.c b/src/rabbitmq-tcl.c
--- a/src/rabbitmq-tcl.c
+++ b/src/rabbitmq-tcl.c
@@ -123,8 +123,7 @@
* @param[out] rcpReply The AMQP RPC reply
* @return 1 if an error occured, 0 if not
*/
-int amqp_get_error(amqp_connection_state_t connection,
- amqp_rpc_reply_t *rpcReply) {
+int amqp_get_error(amqp_connection_state_t connection, amqp_rpc_reply_t *rpcReply) {
amqp_rpc_reply_t reply = amqp_get_rpc_reply(connection);
rpcReply = &reply;
return reply.reply_type != AMQP_RESPONSE_NORMAL;
@@ -141,8 +140,8 @@
* @param[in] rcpReply The AMQP RPC reply
* @return TCL_ERROR
*/
-int tcl_amqp_error(Tcl_Interp *tclInterpreter, const char *errorContext,
- amqp_rpc_reply_t rpcReply, int connectionNumber) {
+int tcl_amqp_error(Tcl_Interp *tclInterpreter, const char *errorContext, amqp_rpc_reply_t rpcReply,
+ int connectionNumber) {
char *error;
if (rpcReply.reply_type == AMQP_RESPONSE_NORMAL) {
@@ -152,32 +151,36 @@
error = malloc(1024 * sizeof(char));
if (rpcReply.reply_type == AMQP_RESPONSE_NONE) {
- sprintf(error, "%s a broker error occurred, but with an unexpected RPC "
- "reply type. Please report this bug as issue.",
+ sprintf(error,
+ "%s a broker error occurred, but with an unexpected RPC "
+ "reply type. Please report this bug as issue.",
errorContext);
} else if (rpcReply.reply_type == AMQP_RESPONSE_LIBRARY_EXCEPTION) {
- sprintf(error, "%s %s", errorContext,
- amqp_error_string2(rpcReply.library_error));
+ sprintf(error, "%s %s", errorContext, amqp_error_string2(rpcReply.library_error));
} else if (rpcReply.reply_type == AMQP_RESPONSE_SERVER_EXCEPTION) {
if (rpcReply.reply.id == AMQP_CONNECTION_CLOSE_METHOD) {
- amqp_connection_close_t *m =
- (amqp_connection_close_t *)rpcReply.reply.decoded;
+ amqp_connection_close_t *m = (amqp_connection_close_t *)rpcReply.reply.decoded;
sprintf(error,
"%s a server connection error %d occurred, message: %.*s",
- errorContext, m->reply_code, (int)m->reply_text.len,
+ errorContext,
+ m->reply_code,
+ (int)m->reply_text.len,
(char *)m->reply_text.bytes);
// Marks the connection as disconnected
brokerConnections[connectionNumber].connected = 0;
} else if (rpcReply.reply.id == AMQP_CHANNEL_CLOSE_METHOD) {
- amqp_channel_close_t *m =
- (amqp_channel_close_t *)rpcReply.reply.decoded;
- sprintf(error, "%s a server channel error %d occurred: %.*s",
- errorContext, m->reply_code, (int)m->reply_text.len,
+ amqp_channel_close_t *m = (amqp_channel_close_t *)rpcReply.reply.decoded;
+ sprintf(error,
+ "%s a server channel error %d occurred: %.*s",
+ errorContext,
+ m->reply_code,
+ (int)m->reply_text.len,
(char *)m->reply_text.bytes);
} else {
sprintf(error,
"%s an unknown server error occurred, method id 0x%08X",
- errorContext, rpcReply.reply.id);
+ errorContext,
+ rpcReply.reply.id);
}
}
@@ -199,8 +202,8 @@
* @param[in] argv The command arguments
* @return TCL_OK, TCL_ERROR, TCL_RETURN, TCL_BREAK or TCL_CONTINUE
*/
-static int mq_command(ClientData clientData, Tcl_Interp *tclInterpreter,
- int argc, Tcl_Obj *const argv[]) {
+static int mq_command(ClientData clientData, Tcl_Interp *tclInterpreter, int argc,
+ Tcl_Obj *const argv[]) {
int connectionNumber;
char *command;
struct command_context *context;
@@ -225,7 +228,7 @@
argv += 2;
#ifdef USE_E4C
- int result; // TCL_OK or TCL_ERROR
+ int result; // TCL_OK or TCL_ERROR
volatile int status = 1; // will be 0 if an exception occurs
const e4c_signal_mapping *old_mappings;
@@ -238,8 +241,7 @@
try {
// We can't return inside a try/catch block, so we store the result
// in a variable. We'll return it after restoring the signal table.
- result = call_mq_command(connectionNumber, tclInterpreter, command,
- argc, argv);
+ result = call_mq_command(connectionNumber, tclInterpreter, command, argc, argv);
} catch (RuntimeException) {
// If an exception occurs, tcl_exception will print the exception
// message (e.g. "segmentation violation" if we've got a SIGSEGV).
@@ -252,8 +254,7 @@
return result;
#else
- return call_mq_command(connectionNumber, tclInterpreter, command, argc,
- argv);
+ return call_mq_command(connectionNumber, tclInterpreter, command, argc, argv);
#endif
}
@@ -267,8 +268,8 @@
* @param[in] argv The command arguments
* @return TCL_OK, TCL_ERROR, TCL_RETURN, TCL_BREAK or TCL_CONTINUE
*/
-int call_mq_command(int connectionNumber, Tcl_Interp *tclInterpreter,
- char *command, int argc, Tcl_Obj *const argv[]) {
+int call_mq_command(int connectionNumber, Tcl_Interp *tclInterpreter, char *command, int argc,
+ Tcl_Obj *const argv[]) {
if (strcmp(command, "bindqueue") == 0) {
return mq_bindqueue(connectionNumber, tclInterpreter, argc, argv);
} else if (strcmp(command, "connect") == 0) {
@@ -294,9 +295,10 @@
* @param[out] tclInterpreter The interpreter to send command result to
*/
int mq_usage(Tcl_Interp *tclInterpreter) {
- return tcl_error(tclInterpreter, "Usage: mq "
- "<bindqueue|connect|connected|disconnect|"
- "get|publish|version>");
+ return tcl_error(tclInterpreter,
+ "Usage: mq "
+ "<bindqueue|connect|connected|disconnect|"
+ "get|publish|version>");
}
/**
@@ -319,8 +321,7 @@
* @param[in] argv The command arguments
* @return TCL_OK on success, TCL_ERROR if already connected or can't connect
*/
-int mq_connect(int connectionNumber, Tcl_Interp *tclInterpreter, int argc,
- Tcl_Obj *const argv[]) {
+int mq_connect(int connectionNumber, Tcl_Interp *tclInterpreter, int argc, Tcl_Obj *const argv[]) {
char *host, *hostPortExpression, *user, *pass, *vhost;
int port, status;
@@ -375,8 +376,7 @@
// Logins to the broker
// No heartbeat, unlimited channels, 128K (131072) frame size
- result = amqp_login(conn, vhost, 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, user,
- pass);
+ result = amqp_login(conn, vhost, 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, user, pass);
if (result.reply_type != AMQP_RESPONSE_NORMAL) {
return tcl_error(tclInterpreter, "Can't login to the broker.");
}
@@ -384,8 +384,7 @@
// Opens a first channel
amqp_channel_open(conn, 1);
if (amqp_get_error(conn, &result)) {
- return tcl_amqp_error(tclInterpreter, "Can't open a channel:", result,
- connectionNumber);
+ return tcl_amqp_error(tclInterpreter, "Can't open a channel:", result, connectionNumber);
}
// We're connected. All is good.
@@ -412,20 +411,17 @@
// event if an error occurs during disconnect.
brokerConnections[connectionNumber].connected = 0;
- amqp_connection_state_t conn =
- brokerConnections[connectionNumber].connection;
+ amqp_connection_state_t conn = brokerConnections[connectionNumber].connection;
result = amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS);
if (result.reply_type != AMQP_RESPONSE_NORMAL) {
- return tcl_amqp_error(tclInterpreter,
- "An error occured closing channel:", result,
- connectionNumber);
+ return tcl_amqp_error(
+ tclInterpreter, "An error occured closing channel:", result, connectionNumber);
}
result = amqp_connection_close(conn, AMQP_REPLY_SUCCESS);
if (result.reply_type != AMQP_RESPONSE_NORMAL) {
- return tcl_amqp_error(tclInterpreter,
- "An error occured closing connection:", result,
- connectionNumber);
+ return tcl_amqp_error(
+ tclInterpreter, "An error occured closing connection:", result, connectionNumber);
}
amqp_destroy_connection(conn);
@@ -449,8 +445,7 @@
/**
* mq get <queue> [-noack]
*/
-int mq_get(int connectionNumber, Tcl_Interp *tclInterpreter, int argc,
- Tcl_Obj *const argv[]) {
+int mq_get(int connectionNumber, Tcl_Interp *tclInterpreter, int argc, Tcl_Obj *const argv[]) {
char *queue;
char *argument;
char *error;
@@ -490,8 +485,8 @@
// Gets message from specified queue (basic.get operation)
result = amqp_basic_get(conn, 1, amqp_cstring_bytes(queue), noAck);
if (amqp_get_error(conn, &result)) {
- return tcl_amqp_error(tclInterpreter, "Can't get message from queue:",
- result, connectionNumber);
+ return tcl_amqp_error(
+ tclInterpreter, "Can't get message from queue:", result, connectionNumber);
}
if (!amqp_will_be_non_blocking_operation(conn)) {
@@ -501,14 +496,12 @@
result = amqp_read_message(conn, 1, &message, 0);
if (amqp_get_error(conn, &result)) {
- return tcl_amqp_error(tclInterpreter, "Can't read message:", result,
- connectionNumber);
+ return tcl_amqp_error(tclInterpreter, "Can't read message:", result, connectionNumber);
}
if (&(message.body)) {
messageBody = malloc(message.body.len + 1024);
- sprintf(messageBody, "%.*s", (int)message.body.len,
- (char *)message.body.bytes);
+ sprintf(messageBody, "%.*s", (int)message.body.len, (char *)message.body.bytes);
// Cleans up
amqp_destroy_message(&message);
@@ -557,39 +550,43 @@
// Declares the exchange
exchangeType = BROKER_DEFAULT_EXCHANGE_TYPE;
- amqp_exchange_declare(conn, 1, amqp_cstring_bytes(exchange),
- amqp_cstring_bytes(exchangeType), 0, 0, 0, 0,
+ amqp_exchange_declare(conn,
+ 1,
+ amqp_cstring_bytes(exchange),
+ amqp_cstring_bytes(exchangeType),
+ 0,
+ 0,
+ 0,
+ 0,
amqp_empty_table);
if (amqp_get_error(conn, &result)) {
- return tcl_amqp_error(tclInterpreter, "Can't declare exchange:", result,
- connectionNumber);
+ return tcl_amqp_error(tclInterpreter, "Can't declare exchange:", result, connectionNumber);
}
// Declares a new temporary queue
- queueResult = amqp_queue_declare(conn, 1, amqp_empty_bytes, 0, 0, 0, 1,
- amqp_empty_table);
+ queueResult = amqp_queue_declare(conn, 1, amqp_empty_bytes, 0, 0, 0, 1, amqp_empty_table);
if (amqp_get_error(conn, &result)) {
- return tcl_amqp_error(tclInterpreter, "Can't declare queue:", result,
- connectionNumber);
+ return tcl_amqp_error(tclInterpreter, "Can't declare queue:", result, connectionNumber);
}
queueName = amqp_bytes_malloc_dup(queueResult->queue);
if (queueName.bytes == NULL) {
- return tcl_error(tclInterpreter,
- "Out of memory while copying queue name.");
+ return tcl_error(tclInterpreter, "Out of memory while copying queue name.");
}
// Binds it to the specified exchange
- amqp_queue_bind(conn, 1, queueName, amqp_cstring_bytes(exchange),
- amqp_cstring_bytes(bindingKey), amqp_empty_table);
+ amqp_queue_bind(conn,
+ 1,
+ queueName,
+ amqp_cstring_bytes(exchange),
+ amqp_cstring_bytes(bindingKey),
+ amqp_empty_table);
if (amqp_get_error(conn, &result)) {
- return tcl_amqp_error(tclInterpreter, "Can't bind queue:", result,
- connectionNumber);
+ return tcl_amqp_error(tclInterpreter, "Can't bind queue:", result, connectionNumber);
}
// Stores queue name as result
- Tcl_SetObjResult(tclInterpreter,
- Tcl_NewStringObj(queueName.bytes, queueName.len));
+ Tcl_SetObjResult(tclInterpreter, Tcl_NewStringObj(queueName.bytes, queueName.len));
return TCL_OK;
}
@@ -605,8 +602,7 @@
* @param[in] argv The command arguments
* @return TCL_OK on success, TCL_ERROR if already connected or can't connect
*/
-int mq_publish(int connectionNumber, Tcl_Interp *tclInterpreter, int argc,
- Tcl_Obj *const argv[]) {
+int mq_publish(int connectionNumber, Tcl_Interp *tclInterpreter, int argc, Tcl_Obj *const argv[]) {
int i;
amqp_connection_state_t conn;
amqp_rpc_reply_t result;
@@ -614,7 +610,7 @@
int contentParsed = 0;
int targetParsed = 0;
int routingKeyParsed = 0;
- int mustRouteToQueue = 0; // -mandatory
+ int mustRouteToQueue = 0; // -mandatory
int mustImmediatelyDeliverToConsumer = 0; // -immediate
// Parses arguments
@@ -622,8 +618,7 @@
argument = Tcl_GetString(argv[i]);
if (strcmp(argument, "-key") == 0) {
if (argc < i + 2) {
- return tcl_error(tclInterpreter,
- "Required routing key argument missing.");
+ return tcl_error(tclInterpreter, "Required routing key argument missing.");
}
routingKey = Tcl_GetString(argv[++i]);
routingKeyParsed = 1;
@@ -633,15 +628,13 @@
mustImmediatelyDeliverToConsumer = 1;
} else if (strcmp(argument, "-exchange") == 0) {
if (argc < i + 2) {
- return tcl_error(tclInterpreter,
- "Required exchange argument missing.");
+ return tcl_error(tclInterpreter, "Required exchange argument missing.");
}
exchange = Tcl_GetString(argv[++i]);
targetParsed = 1;
} else if (strcmp(argument, "-queue") == 0) {
if (argc < i + 2) {
- return tcl_error(tclInterpreter,
- "Required queue argument missing.");
+ return tcl_error(tclInterpreter, "Required queue argument missing.");
}
exchange = BROKER_DEFAULT_EXCHANGE;
routingKey = Tcl_GetString(argv[++i]);
@@ -666,8 +659,7 @@
}
if (!contentParsed) {
- return tcl_error(tclInterpreter,
- "Required message content argument missing.");
+ return tcl_error(tclInterpreter, "Required message content argument missing.");
}
// Ensures we're connected
@@ -677,22 +669,26 @@
// Sends the message and checks the result
conn = brokerConnections[connectionNumber].connection;
- amqp_basic_publish(conn, 1, amqp_cstring_bytes(exchange),
- amqp_cstring_bytes(routingKey), mustRouteToQueue,
- mustImmediatelyDeliverToConsumer, NULL,
+ amqp_basic_publish(conn,
+ 1,
+ amqp_cstring_bytes(exchange),
+ amqp_cstring_bytes(routingKey),
+ mustRouteToQueue,
+ mustImmediatelyDeliverToConsumer,
+ NULL,
amqp_cstring_bytes(content));
if (amqp_get_error(conn, &result)) {
- return tcl_amqp_error(tclInterpreter, "Can't publish message:", result,
- connectionNumber);
+ return tcl_amqp_error(tclInterpreter, "Can't publish message:", result, connectionNumber);
}
#ifdef DEBUG
char *debugMessage = malloc(1024 * sizeof(char) + sizeof(content));
- sprintf(
- debugMessage,
- "Message published to exchange '%s', routing key '%s'. Content: '%s'.",
- exchange, routingKey, content);
+ sprintf(debugMessage,
+ "Message published to exchange '%s', routing key '%s'. Content: '%s'.",
+ exchange,
+ routingKey,
+ content);
Tcl_SetResult(tclInterpreter, debugMessage, TCL_STATIC);
#endif
@@ -766,7 +762,9 @@
sprintf(commandName, "mq%d", i);
}
- Tcl_CreateObjCommand(tclInterpreter, commandName, mq_command,
+ Tcl_CreateObjCommand(tclInterpreter,
+ commandName,
+ mq_command,
get_mq_command_context(i),
(Tcl_CmdDeleteProc *)NULL);
diff --git a/tests/strutils.test.c b/tests/strutils.test.c
--- a/tests/strutils.test.c
+++ b/tests/strutils.test.c
@@ -39,8 +39,7 @@
}
static void test_str_replace(void **state) {
- assert_string_equal("alpha:1234",
- str_replace("5000", "1234", "alpha:5000"));
+ assert_string_equal("alpha:1234", str_replace("5000", "1234", "alpha:5000"));
assert_string_equal("alpha:1234", str_replace("", "", "alpha:1234"));
assert_string_equal("alpha", str_replace(":1234", "", "alpha:1234"));
assert_string_equal("", str_replace("5000", "1234", ""));
diff --git a/tests/test.c b/tests/test.c
--- a/tests/test.c
+++ b/tests/test.c
@@ -35,10 +35,12 @@
int main(void) {
const UnitTest tests[] = {
// netutils
- unit_test(test_get_host), unit_test(test_get_port),
+ unit_test(test_get_host),
+ unit_test(test_get_port),
// strutils
- unit_test(test_strpos), unit_test(test_str_replace),
+ unit_test(test_strpos),
+ unit_test(test_str_replace),
// helper functions
unit_test(test_is_mq_connected),

File Metadata

Mime Type
text/plain
Expires
Mon, Mar 23, 13:13 (14 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3556089
Default Alt Text
D4017.diff (22 KB)

Event Timeline