1
0
mirror of https://github.com/fumiama/CMoe-Counter.git synced 2025-02-08 23:09:33 +01:00

修复宏定义小错误,优化一点点性能

This commit is contained in:
源文雨 2021-09-11 23:16:10 +08:00
parent 2dca5dffe5
commit 53d70d3c1f
2 changed files with 12 additions and 9 deletions

19
cmoe.c
View File

@ -16,20 +16,21 @@ static void write2stdo(char* buf, uint32_t size, uint32_t content_len) {
fflush(stdout);
}
#define ADD_HERDER(h)\
#define ADD_HERDER(h) {\
strcpy(buf + offset, (h));\
offset += sizeof((h)) - 1;
#define ADD_HERDER_PARAM(h, p)\
offset += sizeof((h)) - 1;\
}
#define ADD_HERDER_PARAM(h, p) {\
sprintf(buf + offset, (h), (p));\
offset += strlen(buf + offset);
#define EXTNM_IS_NOT(name) (strcmp(filepath+extpos, name))
offset += strlen(buf + offset);\
}
static void headers(uint32_t content_len, const char* content_type, int no_cache) {
static void headers(uint32_t content_len, const char* content_type) {
char buf[1024];
uint32_t offset = 0;
ADD_HERDER(HTTP200 SERVER_STRING);
if(no_cache) ADD_HERDER(CACHE_CTRL);
ADD_HERDER(CACHE_CTRL);
ADD_HERDER_PARAM(CONTENT_TYPE, content_type);
ADD_HERDER_PARAM(CONTENT_LEN "\r\n", content_len);
write2stdo(buf, offset, content_len);
@ -145,7 +146,7 @@ static void return_count(char* name, char* theme) {
h = H_SMALL;
head = svg_small;
}
headers(get_content_len(isbig, len_type, cntstr), "image/svg+xml", 1);
headers(get_content_len(isbig, len_type, cntstr), "image/svg+xml");
fwrite(head, sizeof(svg_small)-1, 1, stdout);
for(int i = 0; i < 10; i++) {
printf(img_slot_front, w * i, w, h);
@ -213,7 +214,7 @@ int main(int argc, char **argv) {
add_user(name, 0, fp);
fclose(fp);
char* msg = "<P>Success.\r\n";
headers(strlen(msg), "text/html", 1);
headers(strlen(msg), "text/html");
fwrite(msg, strlen(msg), 1, stdout);
} else http_error(HTTP500, "Open File Error.");
} else http_error(HTTP400, "Name Exist.");

2
cmoe.h
View File

@ -3,6 +3,7 @@
#define DATFILE "dat.sp"
#define TOKEN "fumiama"
#define COUNTER_NAME_LEN 64
struct COUNTER {
char name[COUNTER_NAME_LEN];
@ -31,6 +32,7 @@ const uint16_t gbhl[] = {1550, 1702, 1870, 1778, 1618, 2370, 1830, 2234, 1914, 1
#define H_SMALL 100
#define W_BIG 68
#define H_BIG 150
const char svg_small[] =
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"450\" height=\"100\" version=\"1.1\">\n"
" <title>Moe Count</title>\n"