| 19 |
#include "editor.h" |
#include "editor.h" |
| 20 |
#include "screen.h" |
#include "screen.h" |
| 21 |
#include "log.h" |
#include "log.h" |
| 22 |
|
#include "io.h" |
| 23 |
|
#include <ctype.h> |
| 24 |
|
#include <string.h> |
| 25 |
|
|
| 26 |
int article_post(SECTION_LIST *p_section, ARTICLE *p_article, ARTICLE_POST_TYPE type) |
#define STR_INPUT_LEN 74 |
| 27 |
|
|
| 28 |
|
int article_post(SECTION_LIST *p_section) |
| 29 |
|
{ |
| 30 |
|
EDITOR_DATA *p_editor_data; |
| 31 |
|
char title[BBS_article_title_max_len + 1] = ""; |
| 32 |
|
char title_input[STR_INPUT_LEN + 1] = ""; |
| 33 |
|
int sign_id = 0; |
| 34 |
|
long len; |
| 35 |
|
int ch; |
| 36 |
|
char *p, *q; |
| 37 |
|
|
| 38 |
|
if (p_section == NULL) |
| 39 |
|
{ |
| 40 |
|
log_error("NULL pointer error\n"); |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
p_editor_data = editor_data_load(""); |
| 44 |
|
if (p_editor_data == NULL) |
| 45 |
|
{ |
| 46 |
|
log_error("editor_data_load() error\n"); |
| 47 |
|
return -2; |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
// Set title and sign |
| 51 |
|
for (ch = 'T'; !SYS_server_exit;) |
| 52 |
|
{ |
| 53 |
|
clearscr(); |
| 54 |
|
moveto(21, 1); |
| 55 |
|
prints("发表文章于 %s[%s] 讨论区", p_section->stitle, p_section->sname); |
| 56 |
|
moveto(22, 1); |
| 57 |
|
prints("标题: %s", (title[0] == '\0' ? "[无]" : title)); |
| 58 |
|
moveto(23, 1); |
| 59 |
|
prints("使用第 [1;32m%d[m 个签名", sign_id); |
| 60 |
|
|
| 61 |
|
if (toupper(ch) != 'T') |
| 62 |
|
{ |
| 63 |
|
prints(" 按[1;32m0[m~[1;32m3[m选签名档(0表示不使用)"); |
| 64 |
|
|
| 65 |
|
moveto(24, 1); |
| 66 |
|
prints("[1;32mT[m改标题, [1;32mC[m取消, [1;32mEnter[m继续: "); |
| 67 |
|
iflush(); |
| 68 |
|
ch = 0; |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) |
| 72 |
|
{ |
| 73 |
|
switch (toupper(ch)) |
| 74 |
|
{ |
| 75 |
|
case CR: |
| 76 |
|
igetch_reset(); |
| 77 |
|
break; |
| 78 |
|
case 'T': |
| 79 |
|
moveto(24, 1); |
| 80 |
|
clrtoeol(); |
| 81 |
|
len = get_data(24, 1, "标题:", title_input, STR_INPUT_LEN, 1); |
| 82 |
|
for (p = title_input; *p == ' '; p++) |
| 83 |
|
; |
| 84 |
|
for (q = title_input + len; q > p && *(q - 1) == ' '; q--) |
| 85 |
|
; |
| 86 |
|
*q = '\0'; |
| 87 |
|
len = q - p; |
| 88 |
|
if (*p != '\0') |
| 89 |
|
{ |
| 90 |
|
memcpy(title, p, (size_t)len + 1); |
| 91 |
|
memcpy(title_input, title, (size_t)len + 1); |
| 92 |
|
} |
| 93 |
|
ch = 0; |
| 94 |
|
break; |
| 95 |
|
case 'C': |
| 96 |
|
clearscr(); |
| 97 |
|
moveto(1, 1); |
| 98 |
|
prints("取消..."); |
| 99 |
|
press_any_key(); |
| 100 |
|
goto cleanup; |
| 101 |
|
case '0': |
| 102 |
|
case '1': |
| 103 |
|
case '2': |
| 104 |
|
case '3': |
| 105 |
|
sign_id = ch - '0'; |
| 106 |
|
break; |
| 107 |
|
default: // Invalid selection |
| 108 |
|
continue; |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
break; |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
if (ch != CR || title[0] == '\0') |
| 115 |
|
{ |
| 116 |
|
continue; |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
for (ch = 'E'; !SYS_server_exit && toupper(ch) == 'E';) |
| 120 |
|
{ |
| 121 |
|
editor_display(p_editor_data); |
| 122 |
|
|
| 123 |
|
clearscr(); |
| 124 |
|
moveto(1, 1); |
| 125 |
|
prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: "); |
| 126 |
|
iflush(); |
| 127 |
|
|
| 128 |
|
for (ch = 0; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) |
| 129 |
|
{ |
| 130 |
|
switch (toupper(ch)) |
| 131 |
|
{ |
| 132 |
|
case CR: |
| 133 |
|
igetch_reset(); |
| 134 |
|
case 'S': |
| 135 |
|
break; |
| 136 |
|
case 'C': |
| 137 |
|
clearscr(); |
| 138 |
|
moveto(1, 1); |
| 139 |
|
prints("取消..."); |
| 140 |
|
press_any_key(); |
| 141 |
|
goto cleanup; |
| 142 |
|
case 'T': |
| 143 |
|
break; |
| 144 |
|
case 'E': |
| 145 |
|
break; |
| 146 |
|
default: // Invalid selection |
| 147 |
|
continue; |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
break; |
| 151 |
|
} |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
if (toupper(ch) != 'T') |
| 155 |
|
{ |
| 156 |
|
break; |
| 157 |
|
} |
| 158 |
|
} |
| 159 |
|
|
| 160 |
|
// editor_data_save(p_editor_data, p_data_new, data_new_len); |
| 161 |
|
log_common("Debug: post article\n"); |
| 162 |
|
|
| 163 |
|
cleanup: |
| 164 |
|
editor_data_cleanup(p_editor_data); |
| 165 |
|
|
| 166 |
|
return 0; |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
int article_modify(SECTION_LIST *p_section, ARTICLE *p_article) |
| 170 |
|
{ |
| 171 |
|
ARTICLE_CACHE cache; |
| 172 |
|
EDITOR_DATA *p_editor_data; |
| 173 |
|
|
| 174 |
|
if (p_section == NULL || p_article == NULL) |
| 175 |
|
{ |
| 176 |
|
log_error("NULL pointer error\n"); |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0) |
| 180 |
|
{ |
| 181 |
|
log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); |
| 182 |
|
return -2; |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
p_editor_data = editor_data_load(cache.p_data); |
| 186 |
|
if (p_editor_data == NULL) |
| 187 |
|
{ |
| 188 |
|
log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); |
| 189 |
|
return -2; |
| 190 |
|
} |
| 191 |
|
|
| 192 |
|
if (article_cache_unload(&cache) < 0) |
| 193 |
|
{ |
| 194 |
|
log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); |
| 195 |
|
return -2; |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
editor_display(p_editor_data); |
| 199 |
|
|
| 200 |
|
// editor_data_save(p_editor_data, p_data_new, data_new_len); |
| 201 |
|
log_common("Debug: modify article\n"); |
| 202 |
|
|
| 203 |
|
editor_data_cleanup(p_editor_data); |
| 204 |
|
|
| 205 |
|
return 0; |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
int article_reply(SECTION_LIST *p_section, ARTICLE *p_article) |
| 209 |
{ |
{ |
| 210 |
log_common("Debug: sid=%d aid=%d type=%d\n", |
ARTICLE_CACHE cache; |
| 211 |
p_section->sid, (p_article == NULL ? 0 : p_article->aid), type); |
EDITOR_DATA *p_editor_data; |
| 212 |
|
|
| 213 |
|
if (p_section == NULL || p_article == NULL) |
| 214 |
|
{ |
| 215 |
|
log_error("NULL pointer error\n"); |
| 216 |
|
} |
| 217 |
|
|
| 218 |
|
if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0) |
| 219 |
|
{ |
| 220 |
|
log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); |
| 221 |
|
return -2; |
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
p_editor_data = editor_data_load(cache.p_data); |
| 225 |
|
if (p_editor_data == NULL) |
| 226 |
|
{ |
| 227 |
|
log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); |
| 228 |
|
return -2; |
| 229 |
|
} |
| 230 |
|
|
| 231 |
|
if (article_cache_unload(&cache) < 0) |
| 232 |
|
{ |
| 233 |
|
log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); |
| 234 |
|
return -2; |
| 235 |
|
} |
| 236 |
|
|
| 237 |
|
editor_display(p_editor_data); |
| 238 |
|
|
| 239 |
|
// editor_data_save(p_editor_data, p_data_new, data_new_len); |
| 240 |
|
log_common("Debug: reply article\n"); |
| 241 |
|
|
| 242 |
|
editor_data_cleanup(p_editor_data); |
| 243 |
|
|
| 244 |
return 0; |
return 0; |
| 245 |
} |
} |