1
0
mirror of https://github.com/fumiama/CMoe-Counter.git synced 2025-02-10 07:48:30 +01:00

优化显示长度

This commit is contained in:
fumiama 2022-03-02 17:18:50 +08:00
parent d29ecb28c5
commit 8b0eb7c10b

11
cmoe.c
View File

@ -89,7 +89,7 @@ static uint32_t get_content_len(int isbig, uint16_t* len_type, char* cntstr) {
+ (sizeof(img_slot_front) + sizeof(img_slot_rear) - 1) * 10 + (sizeof(img_slot_front) + sizeof(img_slot_rear) - 1) * 10
+ 16 + isbig + 16 + isbig
+ sizeof(svg_tail) - 1; + sizeof(svg_tail) - 1;
for(int i = 0; i < 10; i++) { for(int i = 0; cntstr[i]; i++) {
len += len_type[cntstr[i] - '0']; len += len_type[cntstr[i] - '0'];
} }
return len; return len;
@ -118,6 +118,9 @@ static void return_count(char* name, char* theme) {
char cntstr[11]; char cntstr[11];
sprintf(cntstr, "%010u", d->count); sprintf(cntstr, "%010u", d->count);
free(spb); free(spb);
int cntstrstart = 9;
while(cntstr[cntstrstart] != '0') cntstrstart--;
if(cntstrstart > 1) cntstrstart--; // 保留 2 位 0
int isbig = 0; int isbig = 0;
char** theme_type = mb; char** theme_type = mb;
uint16_t* len_type = mbl; uint16_t* len_type = mbl;
@ -140,9 +143,9 @@ static void return_count(char* name, char* theme) {
h = H_SMALL; h = H_SMALL;
head = svg_small; head = svg_small;
} }
headers(get_content_len(isbig, len_type, cntstr), "image/svg+xml"); headers(get_content_len(isbig, len_type, cntstr+cntstrstart), "image/svg+xml");
write(1, head, sizeof(svg_small)-1); write(1, head, sizeof(svg_small)-1);
for(int i = 0; i < 10; i++) { for(int i = cntstrstart; i < 10; i++) {
printf(img_slot_front, w * i, w, h); printf(img_slot_front, w * i, w, h);
int n = cntstr[i] - '0'; int n = cntstr[i] - '0';
fwrite(theme_type[n], len_type[n], 1, stdout); fwrite(theme_type[n], len_type[n], 1, stdout);
@ -182,7 +185,7 @@ static int name_exist(char* name) {
} }
#define QS (argv[2]) #define QS (argv[2])
//Usage: cmoe method query_string // Usage: cmoe method query_string
int main(int argc, char **argv) { int main(int argc, char **argv) {
if(argc == 3) { if(argc == 3) {
char* name = strstr(QS, "name="); char* name = strstr(QS, "name=");