--- lbbs/src/article_post.c 2025/06/15 04:46:19 1.17 +++ lbbs/src/article_post.c 2025/06/21 02:15:18 1.22 @@ -14,17 +14,15 @@ * * ***************************************************************************/ -#define _POSIX_C_SOURCE 200809L - -#include "article_post.h" #include "article_cache.h" -#include "editor.h" -#include "screen.h" +#include "article_post.h" #include "bbs.h" -#include "log.h" +#include "database.h" +#include "editor.h" #include "io.h" +#include "log.h" #include "lml.h" -#include "database.h" +#include "screen.h" #include "user_priv.h" #include #include @@ -110,6 +108,9 @@ int article_post(const SECTION_LIST *p_s { switch (toupper(ch)) { + case KEY_NULL: + case KEY_TIMEOUT: + goto cleanup; case CR: igetch_reset(); break; @@ -173,6 +174,9 @@ int article_post(const SECTION_LIST *p_s { switch (toupper(ch)) { + case KEY_NULL: + case KEY_TIMEOUT: + goto cleanup; case CR: igetch_reset(); case 'S': @@ -201,6 +205,11 @@ int article_post(const SECTION_LIST *p_s } } + if (SYS_server_exit) // Do not save data on shutdown + { + goto cleanup; + } + content = malloc(ARTICLE_CONTENT_MAX_LEN); if (content == NULL) { @@ -474,7 +483,7 @@ int article_modify(const SECTION_LIST *p content[ARTICLE_CONTENT_MAX_LEN - 1] = '\0'; // Remove control sequence - len_content = ctrl_seq_filter(content); + len_content = str_filter(content, 0); p_editor_data = editor_data_load(content); if (p_editor_data == NULL) @@ -506,6 +515,9 @@ int article_modify(const SECTION_LIST *p { switch (toupper(ch)) { + case KEY_NULL: + case KEY_TIMEOUT: + goto cleanup; case CR: igetch_reset(); case 'S': @@ -526,6 +538,11 @@ int article_modify(const SECTION_LIST *p } } + if (SYS_server_exit) // Do not save data on shutdown + { + goto cleanup; + } + // Allocate buffers in big size content = malloc(ARTICLE_CONTENT_MAX_LEN); if (content == NULL) @@ -722,7 +739,7 @@ int article_reply(const SECTION_LIST *p_ p_article_new->title[0] = '\0'; snprintf(title_input, sizeof(title_input), "Re: %s", p_article->title); - len = split_line(title_input, TITLE_INPUT_MAX_LEN, &eol, &display_len); + len = split_line(title_input, TITLE_INPUT_MAX_LEN, &eol, &display_len, 0); title_input[len] = '\0'; db = db_open(); @@ -764,7 +781,7 @@ int article_reply(const SECTION_LIST *p_ { mysql_close(db); db = NULL; - + clearscr(); moveto(1, 1); prints("该主题谢绝回复"); @@ -815,19 +832,24 @@ int article_reply(const SECTION_LIST *p_ content_f[len] = '\0'; // Remove control sequence - len = ctrl_seq_filter(content_f); + len = str_filter(content_f, 0); len = snprintf(content, ARTICLE_CONTENT_MAX_LEN, "\n\n【 在 %s (%s) 的大作中提到: 】\n", p_article->username, p_article->nickname); - quote_content_lines = split_data_lines(content_f, ARTICLE_QUOTE_LINE_MAX_LEN, line_offsets, ARTICLE_QUOTE_MAX_LINES + 1); + quote_content_lines = split_data_lines(content_f, ARTICLE_QUOTE_LINE_MAX_LEN, line_offsets, ARTICLE_QUOTE_MAX_LINES + 1, 0); for (i = 0; i < quote_content_lines; i++) { memcpy(content + len, ": ", 2); // quote line prefix len += 2; memcpy(content + len, content_f + line_offsets[i], (size_t)(line_offsets[i + 1] - line_offsets[i])); len += (line_offsets[i + 1] - line_offsets[i]); + if (content[len - 1] != '\n') // Appennd \n if not exist + { + content[len] = '\n'; + len++; + } } if (content[len - 1] != '\n') // Appennd \n if not exist { @@ -881,6 +903,9 @@ int article_reply(const SECTION_LIST *p_ { switch (toupper(ch)) { + case KEY_NULL: + case KEY_TIMEOUT: + goto cleanup; case CR: igetch_reset(); break; @@ -938,6 +963,9 @@ int article_reply(const SECTION_LIST *p_ { switch (toupper(ch)) { + case KEY_NULL: + case KEY_TIMEOUT: + goto cleanup; case CR: igetch_reset(); case 'S': @@ -966,6 +994,11 @@ int article_reply(const SECTION_LIST *p_ } } + if (SYS_server_exit) // Do not save data on shutdown + { + goto cleanup; + } + content = malloc(ARTICLE_CONTENT_MAX_LEN); if (content == NULL) {