Skip to content

Commit

Permalink
Apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Sep 1, 2022
1 parent 25d0799 commit d19242b
Show file tree
Hide file tree
Showing 103 changed files with 3,947 additions and 3,719 deletions.
18 changes: 6 additions & 12 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: AllDefinitions
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- __capability
BinPackArguments: true
Expand Down Expand Up @@ -90,18 +90,12 @@ IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
- Regex: '^<(.*)>'
Priority: 0
- Regex: '^"(.*)"'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '(.*)'
Priority: 2
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
Expand Down
209 changes: 104 additions & 105 deletions lwesp/src/api/lwesp_netconn.c

Large diffs are not rendered by default.

169 changes: 100 additions & 69 deletions lwesp/src/apps/cayenne/lwesp_cayenne.c

Large diffs are not rendered by default.

380 changes: 182 additions & 198 deletions lwesp/src/apps/http_server/lwesp_http_server.c

Large diffs are not rendered by default.

157 changes: 79 additions & 78 deletions lwesp/src/apps/http_server/lwesp_http_server_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,88 +41,89 @@ extern uint16_t http_fs_opened_files_cnt;
/**
* \brief Default index.html file including response headers
*/
static const uint8_t
responseData[] = ""
"HTTP/1.1 200 OK\r\n"
"Server: " HTTP_SERVER_NAME "\r\n"
"Content-Type: text/html\r\n"
"\r\n"
"<html>\n"
" <head>\n"
" <title><!--#title--></title>\n"
" <meta http-equiv=\"Refresh\" content=\"1\" />\n"
" <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js\"></script>\n"
" <script src=\"/js/js.js\" type=\"text/javascript\"></script>\n"
" <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css\" integrity=\"sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb\" crossorigin=\"anonymous\" />\n"
" <link rel=\"stylesheet\" type=\"text/css\" href=\"/css/style.css\" />\n"
" </head>\n"
" <body>\n"
" <div class=\"container\">\n"
" <h1>Welcome to web server hosted by ESP8266 Wi-Fi module!</h1>\n"
" </div>\n"
" <div id=\"maindiv\"></div>"
" <footer>\n"
" <div class=\"container\">\n"
" Copyright &copy; 2017. All rights reserved. Webserver is hosted on ESP8266.\n"
" </div>\n"
" </footer>\n"
" </body>\n"
"</html>\n";
static const uint8_t responseData[] =
""
"HTTP/1.1 200 OK\r\n"
"Server: " HTTP_SERVER_NAME "\r\n"
"Content-Type: text/html\r\n"
"\r\n"
"<html>\n"
" <head>\n"
" <title><!--#title--></title>\n"
" <meta http-equiv=\"Refresh\" content=\"1\" />\n"
" <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js\"></script>\n"
" <script src=\"/js/js.js\" type=\"text/javascript\"></script>\n"
" <link rel=\"stylesheet\" "
"href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css\" "
"integrity=\"sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb\" crossorigin=\"anonymous\" "
"/>\n"
" <link rel=\"stylesheet\" type=\"text/css\" href=\"/css/style.css\" />\n"
" </head>\n"
" <body>\n"
" <div class=\"container\">\n"
" <h1>Welcome to web server hosted by ESP8266 Wi-Fi module!</h1>\n"
" </div>\n"
" <div id=\"maindiv\"></div>"
" <footer>\n"
" <div class=\"container\">\n"
" Copyright &copy; 2017. All rights reserved. Webserver is hosted on ESP8266.\n"
" </div>\n"
" </footer>\n"
" </body>\n"
"</html>\n";

/**
* \brief Default CSS response besides bootstrap response
*/
static const uint8_t
responseData_css[] = ""
"HTTP/1.1 200 OK\r\n"
"Server: " HTTP_SERVER_NAME "\r\n"
"Content-Type: text/css\r\n"
"\r\n"
"html, body { margin: 0; padding: 0; color: blue; font-family: Arial, Tahoma; }\r\n"
"h1 { font-size: 22px; }\n"
"footer .container { width: 1000px; padding: 6px 3px; border: 1px solid #000000; font-size: 11px; }\n"
"footer { position: fixed; bottom: 0; width: 100%; background: brown; color: #DDDDDD; }\n"
"";
static const uint8_t responseData_css[] =
""
"HTTP/1.1 200 OK\r\n"
"Server: " HTTP_SERVER_NAME "\r\n"
"Content-Type: text/css\r\n"
"\r\n"
"html, body { margin: 0; padding: 0; color: blue; font-family: Arial, Tahoma; }\r\n"
"h1 { font-size: 22px; }\n"
"footer .container { width: 1000px; padding: 6px 3px; border: 1px solid #000000; font-size: 11px; }\n"
"footer { position: fixed; bottom: 0; width: 100%; background: brown; color: #DDDDDD; }\n"
"";

/**
* \brief Default static javascript file
*
* Script will write a paragraph using jQuery to main div
*/
static const uint8_t
responseData_js1[] = ""
"HTTP/1.1 200 OK\r\n"
"Server: " HTTP_SERVER_NAME "\r\n"
"Content-Type: text/javascript\r\n"
"\r\n"
"jQuery(document).ready(function() {\n"
" jQuery(\"#maindiv\").append(\"<p>This paragraphs was written using jQuery</p>\");\n"
"})\n";
static const uint8_t responseData_js1[] =
""
"HTTP/1.1 200 OK\r\n"
"Server: " HTTP_SERVER_NAME "\r\n"
"Content-Type: text/javascript\r\n"
"\r\n"
"jQuery(document).ready(function() {\n"
" jQuery(\"#maindiv\").append(\"<p>This paragraphs was written using jQuery</p>\");\n"
"})\n";
#endif /* HTTP_USE_DEFAULT_STATIC_FILES */

/**
* \brief Default 404 file
*/
static const uint8_t
responseData_404[] = ""
"HTTP/1.1 404 Not Found\r\n"
"Server: " HTTP_SERVER_NAME "\r\n"
"Content-Type: text/html\r\n"
"\r\n"
"<html><body><h1>404 Page not found!</h1></body></html>\n";
static const uint8_t responseData_404[] = ""
"HTTP/1.1 404 Not Found\r\n"
"Server: " HTTP_SERVER_NAME "\r\n"
"Content-Type: text/html\r\n"
"\r\n"
"<html><body><h1>404 Page not found!</h1></body></html>\n";

/**
* \brief List of dummy files for output on user request
*/
const http_fs_file_table_t
http_fs_static_files[] = {
const http_fs_file_table_t http_fs_static_files[] = {
#if HTTP_USE_DEFAULT_STATIC_FILES
{"/index.html", responseData, sizeof(responseData) - 1},
{"/index.shtml", responseData, sizeof(responseData) - 1},
{"/css/style.css", responseData_css, sizeof(responseData_css) - 1},
{"/js/js.js", responseData_js1, sizeof(responseData_js1) - 1},
{"/index.html", responseData, sizeof(responseData) - 1},
{"/index.shtml", responseData, sizeof(responseData) - 1},
{"/css/style.css", responseData_css, sizeof(responseData_css) - 1},
{"/js/js.js", responseData_js1, sizeof(responseData_js1) - 1},
#endif /* HTTP_USE_DEFAULT_STATIC_FILES */
{"/404.html", responseData_404, sizeof(responseData_404) - 1},
{"/404.html", responseData_404, sizeof(responseData_404) - 1},
};

/**
Expand All @@ -137,14 +138,14 @@ http_fs_data_open_file(const http_init_t* hi, http_fs_file_t* file, const char*
uint8_t i, res;

file->fptr = 0;
if (hi != NULL && hi->fs_open != NULL) { /* Is user defined file system ready? */
file->rem_open_files = &http_fs_opened_files_cnt; /* Set pointer to opened files */
res = hi->fs_open(file, path); /* Try to read file from user file system */
if (hi != NULL && hi->fs_open != NULL) { /* Is user defined file system ready? */
file->rem_open_files = &http_fs_opened_files_cnt; /* Set pointer to opened files */
res = hi->fs_open(file, path); /* Try to read file from user file system */
if (res) {
++http_fs_opened_files_cnt; /* Increase number of opened files */
++http_fs_opened_files_cnt; /* Increase number of opened files */

file->is_static = 0; /* File is not static */
return 1; /* File is opened! */
file->is_static = 0; /* File is not static */
return 1; /* File is opened! */
}
}

Expand All @@ -157,7 +158,7 @@ http_fs_data_open_file(const http_init_t* hi, http_fs_file_t* file, const char*

file->size = http_fs_static_files[i].size;
file->data = (uint8_t*)http_fs_static_files[i].data;
file->is_static = 1; /* Set to 0 for testing purposes */
file->is_static = 1; /* Set to 0 for testing purposes */
return 1;
}
}
Expand All @@ -177,25 +178,25 @@ uint32_t
http_fs_data_read_file(const http_init_t* hi, http_fs_file_t* file, void** buff, size_t btr, size_t* br) {
uint32_t len;

len = file->size - file->fptr; /* Calculate remaining length */
if (buff == NULL) { /* If there is no buffer */
if (file->is_static) { /* Check static file */
return len; /* Simply return difference */
len = file->size - file->fptr; /* Calculate remaining length */
if (buff == NULL) { /* If there is no buffer */
if (file->is_static) { /* Check static file */
return len; /* Simply return difference */
} else if (hi != NULL && hi->fs_read != NULL) { /* Check for read function */
return hi->fs_read(file, NULL, 0); /* Call a function for dynamic file check */
return hi->fs_read(file, NULL, 0); /* Call a function for dynamic file check */
}
return 0; /* No bytes to read */
return 0; /* No bytes to read */
}

len = LWESP_MIN(btr, len); /* Get number of bytes we can read */
if (file->is_static) { /* Is file static? */
*buff = (void*)&file->data[file->fptr]; /* Set a new address pointer only */
} else if (hi != NULL && hi->fs_read != NULL) {
len = hi->fs_read(file, *buff, len); /* Read and return number of bytes read */
len = hi->fs_read(file, *buff, len); /* Read and return number of bytes read */
} else {
return 0;
}
file->fptr += len; /* Incrase current file pointer */
file->fptr += len; /* Incrase current file pointer */
if (br != NULL) {
*br = len;
}
Expand All @@ -210,8 +211,8 @@ http_fs_data_read_file(const http_init_t* hi, http_fs_file_t* file, void** buff,
void
http_fs_data_close_file(const http_init_t* hi, http_fs_file_t* file) {
if (!file->is_static && hi != NULL && hi->fs_close != NULL) {
if (hi->fs_close(file)) { /* Close file handle */
--http_fs_opened_files_cnt; /* Decrease number of files opened */
if (hi->fs_close(file)) { /* Close file handle */
--http_fs_opened_files_cnt; /* Decrease number of files opened */
}
}
}
22 changes: 11 additions & 11 deletions lwesp/src/apps/http_server/lwesp_http_server_fs_fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#if !__DOXYGEN__

#include "ff.h" /* Include FATFS file system file */
#include "ff.h" /* Include FATFS file system file */

/* File system object handle */
static FATFS fs;
Expand Down Expand Up @@ -76,12 +76,12 @@ http_fs_open(http_fs_file_t* file, const char* path) {
* set required parameters for file length
*/
if (f_open(fil, fs_path, FA_READ) == FR_OK) {
file->arg = fil; /* Set user file argument to FATFS file structure */
file->size = f_size(fil); /* Set file length, most important part */
file->arg = fil; /* Set user file argument to FATFS file structure */
file->size = f_size(fil); /* Set file length, most important part */
return 1;
}

lwesp_mem_free(fil); /* We failed, free memory */
lwesp_mem_free(fil); /* We failed, free memory */
return 0;
}

Expand All @@ -97,8 +97,8 @@ http_fs_read(http_fs_file_t* file, void* buff, size_t btr) {
FIL* fil;
UINT br;

fil = file->arg; /* Get file argument */
if (fil == NULL) { /* Check if argument is valid */
fil = file->arg; /* Get file argument */
if (fil == NULL) { /* Check if argument is valid */
return 0;
}

Expand Down Expand Up @@ -129,12 +129,12 @@ uint8_t
http_fs_close(http_fs_file_t* file) {
FIL* fil;

fil = file->arg; /* Get file argument */
if (fil == NULL) { /* Check if argument is valid */
fil = file->arg; /* Get file argument */
if (fil == NULL) { /* Check if argument is valid */
return 0;
}

f_close(fil); /* Close file */
f_close(fil); /* Close file */

/*
* At this step, check if we are last opened file
Expand All @@ -143,9 +143,9 @@ http_fs_close(http_fs_file_t* file) {
if (*file->rem_open_files == 1) {
f_mount(NULL, "SD:", 1);
}
lwesp_mem_free(fil); /* Free user argument */
lwesp_mem_free(fil); /* Free user argument */

return 1; /* Close was successful */
return 1; /* Close was successful */
}

#endif /* !__DOXYGEN__ */
26 changes: 12 additions & 14 deletions lwesp/src/apps/http_server/lwesp_http_server_fs_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ http_fs_read(http_fs_file_t* file, void* buff, size_t btr) {
FILE* fil;
uint32_t br;

fil = file->arg; /* Get file argument */
if (fil == NULL) { /* Check if argument is valid */
fil = file->arg; /* Get file argument */
if (fil == NULL) { /* Check if argument is valid */
return 0;
}

Expand All @@ -84,11 +84,11 @@ http_fs_read(http_fs_file_t* file, void* buff, size_t btr) {
*/
if (buff == NULL) {
uint32_t s, e;
s = ftell(fil); /* Get current position */
fseek(fil, 0, SEEK_END); /* Go to the end */
e = ftell(fil); /* Get end position */
fseek(fil, s, SEEK_SET); /* Set back to current position */
return e - s; /* Return difference in positions */
s = ftell(fil); /* Get current position */
fseek(fil, 0, SEEK_END); /* Go to the end */
e = ftell(fil); /* Get end position */
fseek(fil, s, SEEK_SET); /* Set back to current position */
return e - s; /* Return difference in positions */
}

/* Read the file and return read length */
Expand All @@ -105,19 +105,17 @@ uint8_t
http_fs_close(http_fs_file_t* file) {
FILE* fil;

fil = file->arg; /* Get file argument */
if (fil == NULL) { /* Check if argument is valid */
fil = file->arg; /* Get file argument */
if (fil == NULL) { /* Check if argument is valid */
return 0;
}

fclose(fil); /* Close file */
fclose(fil); /* Close file */

/*
* At this step, check if we are last opened file
* and unmount system if necessary
*/
if (*file->rem_open_files == 1) {

}
return 1; /* Close was successful */
if (*file->rem_open_files == 1) {}
return 1; /* Close was successful */
}

0 comments on commit d19242b

Please sign in to comment.