/[LeafOK_CVS]/lbbs/src/article_post.c
ViewVC logotype

Diff of /lbbs/src/article_post.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 by sysadm, Thu Jun 12 12:53:49 2025 UTC Revision 1.4 by sysadm, Fri Jun 13 12:17:21 2025 UTC
# Line 19  Line 19 
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  {  {
         ARTICLE_CACHE cache;  
30          EDITOR_DATA *p_editor_data;          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          log_common("Debug: sid=%d aid=%d type=%d\n",          if (p_section == NULL)
39                             p_section->sid, (p_article == NULL ? 0 : p_article->aid), type);          {
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          switch (type)          // Set title and sign
51            for (ch = 'T'; !SYS_server_exit;)
52          {          {
53          case ARTICLE_POST_NEW:                  clearscr();
54                  p_editor_data = editor_data_load("");                  moveto(21, 1);
55                  if (p_editor_data == NULL)                  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("使用第 %d 个签名", sign_id);
60    
61                    if (toupper(ch) != 'T')
62                  {                  {
63                          log_error("editor_data_load() error\n");                          prints("    按0~3选签名档(0表示不使用)");
64                          return -2;  
65                            moveto(24, 1);
66                            prints("T改标题, C取消, Enter继续: ");
67                            iflush();
68                            ch = 0;
69                  }                  }
70                  break;  
71          case ARTICLE_POST_EDIT:                  for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME))
         case ARTICLE_POST_REPLY:  
                 if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0)  
72                  {                  {
73                          log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);                          switch (toupper(ch))
74                          return -2;                          {
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                  p_editor_data = editor_data_load(cache.p_data);  
114                  if (p_editor_data == NULL)                  if (ch != CR || title[0] == '\0')
115                  {                  {
116                          log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);                          continue;
                         return -2;  
117                  }                  }
118                  if (article_cache_unload(&cache) < 0)  
119                    for (ch = 'E'; !SYS_server_exit && toupper(ch) == 'E';)
120                  {                  {
121                          log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);                          editor_display(p_editor_data);
122                          return -2;  
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                  break;          }
154          default:  
155                  log_error("Unsupported type=%d\n", type);          // editor_data_save(p_editor_data, p_data_new, data_new_len);
156                  return -1;          log_common("Debug: post article\n");
157    
158    cleanup:
159            editor_data_cleanup(p_editor_data);
160    
161            return 0;
162    }
163    
164    int article_modify(SECTION_LIST *p_section, ARTICLE *p_article)
165    {
166            ARTICLE_CACHE cache;
167            EDITOR_DATA *p_editor_data;
168    
169            if (p_section == NULL || p_article == NULL)
170            {
171                    log_error("NULL pointer error\n");
172            }
173    
174            if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0)
175            {
176                    log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
177                    return -2;
178            }
179            p_editor_data = editor_data_load(cache.p_data);
180            if (p_editor_data == NULL)
181            {
182                    log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
183                    return -2;
184            }
185            if (article_cache_unload(&cache) < 0)
186            {
187                    log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
188                    return -2;
189            }
190    
191            editor_display(p_editor_data);
192    
193            // editor_data_save(p_editor_data, p_data_new, data_new_len);
194    
195            editor_data_cleanup(p_editor_data);
196    
197            return 0;
198    }
199    
200    int article_reply(SECTION_LIST *p_section, ARTICLE *p_article)
201    {
202            ARTICLE_CACHE cache;
203            EDITOR_DATA *p_editor_data;
204    
205            if (p_section == NULL || p_article == NULL)
206            {
207                    log_error("NULL pointer error\n");
208            }
209    
210            if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0)
211            {
212                    log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
213                    return -2;
214            }
215            p_editor_data = editor_data_load(cache.p_data);
216            if (p_editor_data == NULL)
217            {
218                    log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
219                    return -2;
220            }
221            if (article_cache_unload(&cache) < 0)
222            {
223                    log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
224                    return -2;
225          }          }
226    
227          editor_display(p_editor_data);          editor_display(p_editor_data);


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1