--- lbbs/src/article_post.c 2025/06/12 12:14:28 1.1 +++ lbbs/src/article_post.c 2025/06/13 12:01:27 1.3 @@ -19,11 +19,220 @@ #include "editor.h" #include "screen.h" #include "log.h" +#include "io.h" +#include +#include -int article_post(SECTION_LIST *p_section, ARTICLE *p_article, ARTICLE_POST_TYPE type) +#define STR_INPUT_LEN 74 + +int article_post(SECTION_LIST *p_section) +{ + EDITOR_DATA *p_editor_data; + char title[BBS_article_title_max_len + 1] = ""; + char title_input[STR_INPUT_LEN + 1] = ""; + int sign_id = 0; + long len; + int ch; + char *p, *q; + + if (p_section == NULL) + { + log_error("NULL pointer error\n"); + } + + p_editor_data = editor_data_load(""); + if (p_editor_data == NULL) + { + log_error("editor_data_load() error\n"); + return -2; + } + + // Set title and sign + for (ch = 'T'; !SYS_server_exit;) + { + clearscr(); + moveto(21, 1); + prints("发表文章于 %s[%s] 讨论区", p_section->stitle, p_section->sname); + moveto(22, 1); + prints("使用标题: %s", (title[0] == '\0' ? "[正在设定主题]" : title)); + moveto(23, 1); + prints("使用第 %d 个签名", sign_id); + + if (toupper(ch) != 'T') + { + prints(" 按0~3选签名档"); + + moveto(24, 1); + prints("T改标题, C取消, Enter继续: "); + iflush(); + ch = 0; + } + + for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) + { + switch (toupper(ch)) + { + case CR: + igetch_reset(); + break; + case 'T': + moveto(24, 1); + clrtoeol(); + len = get_data(24, 1, "标题:", title_input, STR_INPUT_LEN, 1); + for (p = title_input; *p == ' '; p++) + ; + for (q = title_input + len; q > p && *(q - 1) == ' '; q--) + ; + *q = '\0'; + len = q - p; + + if (*p != '\0') + { + memcpy(title, p, (size_t)len + 1); + memcpy(title_input, title, (size_t)len + 1); + } + if (title[0] != '\0') // title is valid + { + ch = 0; + } + break; + case 'C': + clearscr(); + moveto(1, 1); + prints("取消..."); + press_any_key(); + goto cleanup; + case '0': + case '1': + case '2': + case '3': + sign_id = ch - '0'; + break; + default: // Invalid selection + continue; + } + + break; + } + + if (ch != CR) + { + continue; + } + + for (ch = 'E'; !SYS_server_exit && toupper(ch) == 'E';) + { + editor_display(p_editor_data); + + clearscr(); + moveto(1, 1); + prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: "); + iflush(); + + for (ch = 0; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) + { + switch (toupper(ch)) + { + case CR: + igetch_reset(); + case 'S': + break; + case 'C': + clearscr(); + moveto(1, 1); + prints("取消..."); + press_any_key(); + goto cleanup; + case 'T': + break; + case 'E': + break; + default: // Invalid selection + continue; + } + + break; + } + } + } + + // editor_data_save(p_editor_data, p_data_new, data_new_len); + log_common("Debug: post article\n"); + +cleanup: + editor_data_cleanup(p_editor_data); + + return 0; +} + +int article_modify(SECTION_LIST *p_section, ARTICLE *p_article) +{ + ARTICLE_CACHE cache; + EDITOR_DATA *p_editor_data; + + if (p_section == NULL || p_article == NULL) + { + log_error("NULL pointer error\n"); + } + + if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0) + { + log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); + return -2; + } + p_editor_data = editor_data_load(cache.p_data); + if (p_editor_data == NULL) + { + log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); + return -2; + } + if (article_cache_unload(&cache) < 0) + { + log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); + return -2; + } + + editor_display(p_editor_data); + + // editor_data_save(p_editor_data, p_data_new, data_new_len); + + editor_data_cleanup(p_editor_data); + + return 0; +} + +int article_reply(SECTION_LIST *p_section, ARTICLE *p_article) { - log_common("Debug: sid=%d aid=%d type=%d\n", - p_section->sid, (p_article == NULL ? 0 : p_article->aid), type); + ARTICLE_CACHE cache; + EDITOR_DATA *p_editor_data; + + if (p_section == NULL || p_article == NULL) + { + log_error("NULL pointer error\n"); + } + + if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0) + { + log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); + return -2; + } + p_editor_data = editor_data_load(cache.p_data); + if (p_editor_data == NULL) + { + log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); + return -2; + } + if (article_cache_unload(&cache) < 0) + { + log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); + return -2; + } + + editor_display(p_editor_data); + + // editor_data_save(p_editor_data, p_data_new, data_new_len); + + editor_data_cleanup(p_editor_data); return 0; }