mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2025-11-23 06:59:51 -05:00
format code index to tab no space
This commit is contained in:
parent
0af8799a2d
commit
5aaf8d7625
11 changed files with 8896 additions and 8749 deletions
|
|
@ -7,34 +7,34 @@
|
|||
#include <string.h>
|
||||
|
||||
static void die_if_null(void *ptr) {
|
||||
if (!ptr) {
|
||||
perror("Failed to allocate memory");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (!ptr) {
|
||||
perror("Failed to allocate memory");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void *xzalloc(size_t size) {
|
||||
if (!size) {
|
||||
return NULL;
|
||||
}
|
||||
void *ptr = calloc(1, size);
|
||||
die_if_null(ptr);
|
||||
return ptr;
|
||||
if (!size) {
|
||||
return NULL;
|
||||
}
|
||||
void *ptr = calloc(1, size);
|
||||
die_if_null(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *xrealloc(void *ptr, size_t size) {
|
||||
if (!size) {
|
||||
free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
ptr = realloc(ptr, size);
|
||||
die_if_null(ptr);
|
||||
return ptr;
|
||||
if (!size) {
|
||||
free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
ptr = realloc(ptr, size);
|
||||
die_if_null(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
char *xstrdup(const char *str) {
|
||||
assert(str);
|
||||
char *copy = strdup(str);
|
||||
die_if_null(copy);
|
||||
return copy;
|
||||
assert(str);
|
||||
char *copy = strdup(str);
|
||||
die_if_null(copy);
|
||||
return copy;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,18 +47,17 @@ char *xstrdup(const char *str);
|
|||
* <ptr> before assigning the result.
|
||||
*/
|
||||
#define xstrdup_replace(ptr, str) \
|
||||
do { \
|
||||
free(ptr); \
|
||||
(ptr) = xstrdup(str); \
|
||||
} while (0)
|
||||
do { \
|
||||
free(ptr); \
|
||||
(ptr) = xstrdup(str); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Frees memory pointed to by <ptr> and sets <ptr> to NULL.
|
||||
* Does nothing if <ptr> is already NULL.
|
||||
*/
|
||||
#define zfree(ptr) \
|
||||
do { \
|
||||
free(ptr); \
|
||||
(ptr) = NULL; \
|
||||
} while (0)
|
||||
|
||||
do { \
|
||||
free(ptr); \
|
||||
(ptr) = NULL; \
|
||||
} while (0)
|
||||
|
|
|
|||
|
|
@ -11,71 +11,63 @@
|
|||
#include <pcre2.h>
|
||||
|
||||
void die(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
|
||||
fputc(' ', stderr);
|
||||
perror(NULL);
|
||||
} else {
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
|
||||
fputc(' ', stderr);
|
||||
perror(NULL);
|
||||
} else {
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void *ecalloc(size_t nmemb, size_t size) {
|
||||
void *p;
|
||||
void *p;
|
||||
|
||||
if (!(p = calloc(nmemb, size)))
|
||||
die("calloc:");
|
||||
return p;
|
||||
if (!(p = calloc(nmemb, size)))
|
||||
die("calloc:");
|
||||
return p;
|
||||
}
|
||||
|
||||
int fd_set_nonblock(int fd) {
|
||||
int flags = fcntl(fd, F_GETFL);
|
||||
if (flags < 0) {
|
||||
perror("fcntl(F_GETFL):");
|
||||
return -1;
|
||||
}
|
||||
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||
perror("fcntl(F_SETFL):");
|
||||
return -1;
|
||||
}
|
||||
int flags = fcntl(fd, F_GETFL);
|
||||
if (flags < 0) {
|
||||
perror("fcntl(F_GETFL):");
|
||||
return -1;
|
||||
}
|
||||
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||
perror("fcntl(F_SETFL):");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int regex_match(const char *pattern, const char *str) {
|
||||
int errnum;
|
||||
PCRE2_SIZE erroffset;
|
||||
pcre2_code *re = pcre2_compile(
|
||||
(PCRE2_SPTR)pattern,
|
||||
PCRE2_ZERO_TERMINATED,
|
||||
PCRE2_UTF, // 启用 UTF-8 支持
|
||||
&errnum, &erroffset, NULL
|
||||
);
|
||||
if (!re) {
|
||||
PCRE2_UCHAR errbuf[256];
|
||||
pcre2_get_error_message(errnum, errbuf, sizeof(errbuf));
|
||||
fprintf(stderr, "PCRE2 error: %s at offset %zu\n", errbuf, erroffset);
|
||||
return 0;
|
||||
}
|
||||
int errnum;
|
||||
PCRE2_SIZE erroffset;
|
||||
pcre2_code *re = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
|
||||
PCRE2_UTF, // 启用 UTF-8 支持
|
||||
&errnum, &erroffset, NULL);
|
||||
if (!re) {
|
||||
PCRE2_UCHAR errbuf[256];
|
||||
pcre2_get_error_message(errnum, errbuf, sizeof(errbuf));
|
||||
fprintf(stderr, "PCRE2 error: %s at offset %zu\n", errbuf, erroffset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(re, NULL);
|
||||
int ret = pcre2_match(
|
||||
re,
|
||||
(PCRE2_SPTR)str,
|
||||
strlen(str),
|
||||
0, 0,
|
||||
match_data,
|
||||
NULL
|
||||
);
|
||||
pcre2_match_data *match_data =
|
||||
pcre2_match_data_create_from_pattern(re, NULL);
|
||||
int ret =
|
||||
pcre2_match(re, (PCRE2_SPTR)str, strlen(str), 0, 0, match_data, NULL);
|
||||
|
||||
pcre2_match_data_free(match_data);
|
||||
pcre2_code_free(re);
|
||||
return ret >= 0;
|
||||
pcre2_match_data_free(match_data);
|
||||
pcre2_code_free(re);
|
||||
return ret >= 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
/* See LICENSE.dwm file for copyright and license details. */
|
||||
|
||||
|
||||
void die(const char *fmt, ...);
|
||||
void *ecalloc(size_t nmemb, size_t size);
|
||||
int fd_set_nonblock(int fd);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue