Browse Source

Update source code format details

bel 9 years ago
parent
commit
9a69a05905
8 changed files with 120 additions and 33 deletions
  1. 5 0
      .clang-format
  2. 10 3
      include/CivetServer.h
  3. 5 2
      include/civetweb.h
  4. 8 2
      src/CivetServer.cpp
  5. 65 19
      src/civetweb.c
  6. 8 2
      src/main.c
  7. 15 4
      test/public_server.c
  8. 4 1
      test/shared.c

+ 5 - 0
.clang-format

@@ -11,7 +11,12 @@ Language: Cpp
 
 AccessModifierOffset: 2
 AlignAfterOpenBracket: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
 AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
 BinPackArguments: false
 BinPackParameters: false
 BreakBeforeBraces: Linux

+ 10 - 3
include/CivetServer.h

@@ -23,7 +23,9 @@ class CivetServer;
 class CIVETWEB_API CivetException : public std::runtime_error
 {
 	  public:
-	CivetException(const std::string &msg) : std::runtime_error(msg) {}
+	CivetException(const std::string &msg) : std::runtime_error(msg)
+	{
+	}
 };
 
 /**
@@ -36,7 +38,9 @@ class CIVETWEB_API CivetHandler
 	/**
 	 * Destructor
 	 */
-	virtual ~CivetHandler() {}
+	virtual ~CivetHandler()
+	{
+	}
 
 	/**
 	 * Callback method for GET request.
@@ -123,7 +127,10 @@ class CIVETWEB_API CivetServer
 	 *
 	 * @return the context or 0 if not running.
 	 */
-	const struct mg_context *getContext() const { return context; }
+	const struct mg_context *getContext() const
+	{
+		return context;
+	}
 
 	/**
 	 * addHandler(const std::string &, CivetHandler *)

+ 5 - 2
include/civetweb.h

@@ -309,8 +309,11 @@ CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx,
 typedef int (*mg_websocket_connect_handler)(const struct mg_connection *,
                                             void *);
 typedef void (*mg_websocket_ready_handler)(struct mg_connection *, void *);
-typedef int (*mg_websocket_data_handler)(
-    struct mg_connection *, int, char *, size_t, void *);
+typedef int (*mg_websocket_data_handler)(struct mg_connection *,
+                                         int,
+                                         char *,
+                                         size_t,
+                                         void *);
 typedef void (*mg_websocket_close_handler)(const struct mg_connection *,
                                            void *);
 

+ 8 - 2
src/CivetServer.cpp

@@ -105,7 +105,10 @@ CivetServer::CivetServer(const char **options,
 		                     "Possible problem binding to port.");
 }
 
-CivetServer::~CivetServer() { close(); }
+CivetServer::~CivetServer()
+{
+	close();
+}
 
 void CivetServer::closeHandler(const struct mg_connection *conn)
 {
@@ -330,4 +333,7 @@ CivetServer::CivetConnection::CivetConnection()
 	postDataLen = 0;
 }
 
-CivetServer::CivetConnection::~CivetConnection() { free(postData); }
+CivetServer::CivetConnection::~CivetConnection()
+{
+	free(postData);
+}

+ 65 - 19
src/civetweb.c

@@ -458,7 +458,10 @@ typedef int SOCKET;
 #endif
 
 static CRITICAL_SECTION global_log_file_lock;
-static DWORD pthread_self(void) { return GetCurrentThreadId(); }
+static DWORD pthread_self(void)
+{
+	return GetCurrentThreadId();
+}
 
 static int pthread_key_create(
     pthread_key_t *key,
@@ -484,7 +487,10 @@ static int pthread_setspecific(pthread_key_t key, void *value)
 }
 
 #ifdef ENABLE_UNUSED_PTHREAD_FUNCTIONS
-static void *pthread_getspecific(pthread_key_t key) { return TlsGetValue(key); }
+static void *pthread_getspecific(pthread_key_t key)
+{
+	return TlsGetValue(key);
+}
 #endif
 
 #if defined(__MINGW32__)
@@ -688,10 +694,22 @@ mg_realloc_ex(void *memory, size_t newsize, const char *file, unsigned line)
 
 #else
 
-static __inline void *mg_malloc(size_t a) { return malloc(a); }
-static __inline void *mg_calloc(size_t a, size_t b) { return calloc(a, b); }
-static __inline void *mg_realloc(void *a, size_t b) { return realloc(a, b); }
-static __inline void mg_free(void *a) { free(a); }
+static __inline void *mg_malloc(size_t a)
+{
+	return malloc(a);
+}
+static __inline void *mg_calloc(size_t a, size_t b)
+{
+	return calloc(a, b);
+}
+static __inline void *mg_realloc(void *a, size_t b)
+{
+	return realloc(a, b);
+}
+static __inline void mg_free(void *a)
+{
+	free(a);
+}
 
 #endif
 
@@ -1216,7 +1234,9 @@ static void mg_set_thread_name(const char *name)
 		               sizeof(info) / sizeof(ULONG_PTR),
 		               (ULONG_PTR *)&info);
 	}
-	__except(EXCEPTION_EXECUTE_HANDLER) {}
+	__except(EXCEPTION_EXECUTE_HANDLER)
+	{
+	}
 #elif defined(__MINGW32__)
 /* No option known to set thread name for MinGW */
 #endif
@@ -1229,7 +1249,9 @@ static void mg_set_thread_name(const char *name)
 #endif
 }
 #else /* !defined(NO_THREAD_NAME) */
-void mg_set_thread_name(const char *threadName) {}
+void mg_set_thread_name(const char *threadName)
+{
+}
 #endif
 
 #if defined(MG_LEGACY_INTERFACE)
@@ -1249,7 +1271,10 @@ const char **mg_get_valid_option_names(void)
 }
 #endif
 
-const struct mg_option *mg_get_valid_options(void) { return config_options; }
+const struct mg_option *mg_get_valid_options(void)
+{
+	return config_options;
+}
 
 static int is_file_in_memory(struct mg_connection *conn,
                              const char *path,
@@ -1360,7 +1385,10 @@ static char *mg_strndup(const char *ptr, size_t len)
 	return p;
 }
 
-static char *mg_strdup(const char *str) { return mg_strndup(str, strlen(str)); }
+static char *mg_strdup(const char *str)
+{
+	return mg_strndup(str, strlen(str));
+}
 
 static const char *mg_strcasestr(const char *big_str, const char *small_str)
 {
@@ -1608,7 +1636,10 @@ static struct mg_connection *fc(struct mg_context *ctx)
 	return &fake_connection;
 }
 
-const char *mg_version(void) { return CIVETWEB_VERSION; }
+const char *mg_version(void)
+{
+	return CIVETWEB_VERSION;
+}
 
 const struct mg_request_info *
 mg_get_request_info(const struct mg_connection *conn)
@@ -5008,7 +5039,10 @@ int mg_modify_passwords_file(const char *fname,
 }
 
 
-static int is_valid_port(unsigned long port) { return port < 0xffff; }
+static int is_valid_port(unsigned long port)
+{
+	return port < 0xffff;
+}
 
 
 static int mg_inet_pton(int af, const char *src, void *dst, size_t dstlen)
@@ -5948,8 +5982,11 @@ static int parse_http_message(char *buf, int len, struct mg_request_info *ri)
  * buffer (which marks the end of HTTP request). Buffer buf may already
  * have some data. The length of the data is stored in nread.
  * Upon every read operation, increase nread by the number of bytes read. */
-static int read_request(
-    FILE *fp, struct mg_connection *conn, char *buf, int bufsiz, int *nread)
+static int read_request(FILE *fp,
+                        struct mg_connection *conn,
+                        char *buf,
+                        int bufsiz,
+                        int *nread)
 {
 	int request_len, n = 0;
 	struct timespec last_action_time = {0, 0};
@@ -8027,7 +8064,10 @@ static int is_websocket_protocol(const struct mg_connection *conn)
 #endif /* !USE_WEBSOCKET */
 
 
-static int isbyte(int n) { return n >= 0 && n <= 255; }
+static int isbyte(int n)
+{
+	return n >= 0 && n <= 255;
+}
 
 
 static int parse_net(const char *spec, uint32_t *net, uint32_t *mask)
@@ -8588,8 +8628,11 @@ static void deprecated_websocket_ready_wrapper(struct mg_connection *conn,
 }
 
 
-static int deprecated_websocket_data_wrapper(
-    struct mg_connection *conn, int bits, char *data, size_t len, void *cbdata)
+static int deprecated_websocket_data_wrapper(struct mg_connection *conn,
+                                             int bits,
+                                             char *data,
+                                             size_t len,
+                                             void *cbdata)
 {
 	struct mg_callbacks *pcallbacks = (struct mg_callbacks *)cbdata;
 	if (pcallbacks->websocket_data) {
@@ -9900,8 +9943,11 @@ void mg_close_connection(struct mg_connection *conn)
 }
 
 
-struct mg_connection *mg_connect_client(
-    const char *host, int port, int use_ssl, char *ebuf, size_t ebuf_len)
+struct mg_connection *mg_connect_client(const char *host,
+                                        int port,
+                                        int use_ssl,
+                                        char *ebuf,
+                                        size_t ebuf_len)
 {
 	static struct mg_context fake_ctx;
 	struct mg_connection *conn = NULL;

+ 8 - 2
src/main.c

@@ -157,7 +157,10 @@ static struct mg_option main_config_options[] = {
     {"icon", CONFIG_TYPE_STRING, NULL},
     {NULL, CONFIG_TYPE_UNKNOWN, NULL}};
 
-static void WINCDECL signal_handler(int sig_num) { g_exit_flag = sig_num; }
+static void WINCDECL signal_handler(int sig_num)
+{
+	g_exit_flag = sig_num;
+}
 
 static NO_RETURN void die(const char *fmt, ...)
 {
@@ -2265,7 +2268,10 @@ int main(int argc, char *argv[])
 	           openFile:[NSString stringWithUTF8String:g_config_file]
 	    withApplication:@"TextEdit"];
 }
-- (void)shutDown { [NSApp terminate:nil]; }
+- (void)shutDown
+{
+	[NSApp terminate:nil];
+}
 @end
 
 

+ 15 - 4
test/public_server.c

@@ -1182,9 +1182,14 @@ void _ck_assert_msg(int cond, const char *file, int line, const char *expr, ...)
 	chk_failed++;
 }
 
-void _mark_point(const char *file, int line) { chk_ok++; }
+void _mark_point(const char *file, int line)
+{
+	chk_ok++;
+}
 
-void tcase_fn_start(const char *fname, const char *file, int line) {}
+void tcase_fn_start(const char *fname, const char *file, int line)
+{
+}
 void suite_add_tcase(Suite *s, TCase *tc){};
 void _tcase_add_test(TCase *tc,
                      TFun tf,
@@ -1193,8 +1198,14 @@ void _tcase_add_test(TCase *tc,
                      int allowed_exit_value,
                      int start,
                      int end){};
-TCase *tcase_create(const char *name) { return NULL; };
-Suite *suite_create(const char *name) { return NULL; };
+TCase *tcase_create(const char *name)
+{
+	return NULL;
+};
+Suite *suite_create(const char *name)
+{
+	return NULL;
+};
 void tcase_set_timeout(TCase *tc, double timeout){};
 
 #endif

+ 4 - 1
test/shared.c

@@ -33,7 +33,10 @@
 
 static char s_test_directory[1024] = {'\0'};
 
-const char *get_test_directory(void) { return s_test_directory; }
+const char *get_test_directory(void)
+{
+	return s_test_directory;
+}
 
 void set_test_directory(const char *const path)
 {