Remove MG_ENABLE_DIRLIST

This commit is contained in:
Sergey Lyubka 2022-02-14 11:19:24 +00:00
parent 969b84043c
commit 5bc164de76
10 changed files with 35 additions and 33 deletions

View File

@ -241,7 +241,6 @@ Here is a list of build constants and their default values:
|MG_ENABLE_LOG | 1 | Enable `LOG()` macro |
|MG_ENABLE_MD5 | 0 | Use native MD5 implementation |
|MG_ENABLE_SSI | 1 | Enable serving SSI files by `mg_http_serve_dir()` |
|MG_ENABLE_DIRLIST | 0 | Enable directory listing |
|MG_ENABLE_CUSTOM_RANDOM | 0 | Provide custom RNG function `mg_random()` |
|MG_ENABLE_PACKED_FS | 0 | Enable embedded FS support |
|MG_ENABLE_FATFS | 0 | Enable embedded FAT FS support |

View File

@ -3900,9 +3900,17 @@ const char *mg_strstr(const struct mg_str haystack,
return NULL;
}
static bool is_digit(int c) {
return c >= '0' && c <= '9';
}
static bool is_space(int c) {
return c == ' ' || c == '\r' || c == '\n' || c == '\t';
}
struct mg_str mg_strstrip(struct mg_str s) {
while (s.len > 0 && isspace((int) *s.ptr)) s.ptr++, s.len--;
while (s.len > 0 && isspace((int) *(s.ptr + s.len - 1))) s.len--;
while (s.len > 0 && is_space((int) *s.ptr)) s.ptr++, s.len--;
while (s.len > 0 && is_space((int) *(s.ptr + s.len - 1))) s.len--;
return s;
}
@ -4115,14 +4123,14 @@ size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list ap) {
if (c == '#') x++, c = fmt[++i];
if (c == '-') minus++, c = fmt[++i];
if (c == '0') pad = '0', c = fmt[++i];
while (isdigit(c)) w *= 10, w += (size_t) (c - '0'), c = fmt[++i];
while (is_digit(c)) w *= 10, w += (size_t) (c - '0'), c = fmt[++i];
if (c == '.') {
c = fmt[++i];
if (c == '*') {
pr = (size_t) va_arg(ap, int);
c = fmt[++i];
} else {
while (isdigit(c)) pr *= 10, pr += (size_t) (c - '0'), c = fmt[++i];
while (is_digit(c)) pr *= 10, pr += (size_t) (c - '0'), c = fmt[++i];
}
}
while (c == 'h') c = fmt[++i]; // Treat h and hh as int
@ -4170,7 +4178,10 @@ size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list ap) {
if (n < len) buf[n] = '%';
n++;
} else {
abort(); // Unsupported format specifier
if (n < len) buf[n] = '%';
n++;
if (n < len) buf[n] = c;
n++;
}
i++;
} else {

View File

@ -121,7 +121,6 @@ extern "C" {
#include <time.h>
#define MG_PATH_MAX 128
#define MG_ENABLE_DIRLIST 1
#endif
@ -148,7 +147,6 @@ extern "C" {
#include <esp_system.h>
#define MG_PATH_MAX 128
#define MG_ENABLE_DIRLIST 1
#endif
@ -316,10 +314,6 @@ struct timeval {
#include <time.h>
#include <unistd.h>
#ifndef MG_ENABLE_DIRLIST
#define MG_ENABLE_DIRLIST 1
#endif
#endif
@ -409,10 +403,6 @@ typedef int socklen_t;
#define S_ISDIR(x) (((x) &_S_IFMT) == _S_IFDIR)
#endif
#ifndef MG_ENABLE_DIRLIST
#define MG_ENABLE_DIRLIST 1
#endif
#endif
@ -466,7 +456,7 @@ typedef int socklen_t;
#endif
#ifndef MG_ENABLE_DIRLIST
#define MG_ENABLE_DIRLIST 0
#define MG_ENABLE_DIRLIST 1
#endif
#ifndef MG_ENABLE_CUSTOM_RANDOM

View File

@ -18,6 +18,5 @@
#include <time.h>
#define MG_PATH_MAX 128
#define MG_ENABLE_DIRLIST 1
#endif

View File

@ -22,6 +22,5 @@
#include <esp_system.h>
#define MG_PATH_MAX 128
#define MG_ENABLE_DIRLIST 1
#endif

View File

@ -30,8 +30,4 @@
#include <time.h>
#include <unistd.h>
#ifndef MG_ENABLE_DIRLIST
#define MG_ENABLE_DIRLIST 1
#endif
#endif

View File

@ -86,8 +86,4 @@ typedef int socklen_t;
#define S_ISDIR(x) (((x) &_S_IFMT) == _S_IFDIR)
#endif
#ifndef MG_ENABLE_DIRLIST
#define MG_ENABLE_DIRLIST 1
#endif
#endif

View File

@ -50,7 +50,7 @@
#endif
#ifndef MG_ENABLE_DIRLIST
#define MG_ENABLE_DIRLIST 0
#define MG_ENABLE_DIRLIST 1
#endif
#ifndef MG_ENABLE_CUSTOM_RANDOM

View File

@ -81,9 +81,17 @@ const char *mg_strstr(const struct mg_str haystack,
return NULL;
}
static bool is_digit(int c) {
return c >= '0' && c <= '9';
}
static bool is_space(int c) {
return c == ' ' || c == '\r' || c == '\n' || c == '\t';
}
struct mg_str mg_strstrip(struct mg_str s) {
while (s.len > 0 && isspace((int) *s.ptr)) s.ptr++, s.len--;
while (s.len > 0 && isspace((int) *(s.ptr + s.len - 1))) s.len--;
while (s.len > 0 && is_space((int) *s.ptr)) s.ptr++, s.len--;
while (s.len > 0 && is_space((int) *(s.ptr + s.len - 1))) s.len--;
return s;
}
@ -296,14 +304,14 @@ size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list ap) {
if (c == '#') x++, c = fmt[++i];
if (c == '-') minus++, c = fmt[++i];
if (c == '0') pad = '0', c = fmt[++i];
while (isdigit(c)) w *= 10, w += (size_t) (c - '0'), c = fmt[++i];
while (is_digit(c)) w *= 10, w += (size_t) (c - '0'), c = fmt[++i];
if (c == '.') {
c = fmt[++i];
if (c == '*') {
pr = (size_t) va_arg(ap, int);
c = fmt[++i];
} else {
while (isdigit(c)) pr *= 10, pr += (size_t) (c - '0'), c = fmt[++i];
while (is_digit(c)) pr *= 10, pr += (size_t) (c - '0'), c = fmt[++i];
}
}
while (c == 'h') c = fmt[++i]; // Treat h and hh as int
@ -351,7 +359,10 @@ size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list ap) {
if (n < len) buf[n] = '%';
n++;
} else {
abort(); // Unsupported format specifier
if (n < len) buf[n] = '%';
n++;
if (n < len) buf[n] = c;
n++;
}
i++;
} else {

View File

@ -18,3 +18,4 @@
#define MG_PATH_MAX 100
#define MG_ENABLE_SOCKET 0
#define MG_ENABLE_DIRLIST 0