/[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.3 by sysadm, Fri Jun 13 12:01:27 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选签名档");
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    
89                                    if (*p != '\0')
90                                    {
91                                            memcpy(title, p, (size_t)len + 1);
92                                            memcpy(title_input, title, (size_t)len + 1);
93                                    }
94                                    if (title[0] != '\0') // title is valid
95                                    {
96                                            ch = 0;
97                                    }
98                                    break;
99                            case 'C':
100                                    clearscr();
101                                    moveto(1, 1);
102                                    prints("取消...");
103                                    press_any_key();
104                                    goto cleanup;
105                            case '0':
106                            case '1':
107                            case '2':
108                            case '3':
109                                    sign_id = ch - '0';
110                                    break;
111                            default: // Invalid selection
112                                    continue;
113                            }
114    
115                            break;
116                  }                  }
117                  p_editor_data = editor_data_load(cache.p_data);  
118                  if (p_editor_data == NULL)                  if (ch != CR)
119                  {                  {
120                          log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);                          continue;
                         return -2;  
121                  }                  }
122                  if (article_cache_unload(&cache) < 0)  
123                    for (ch = 'E'; !SYS_server_exit && toupper(ch) == 'E';)
124                  {                  {
125                          log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);                          editor_display(p_editor_data);
126                          return -2;  
127                            clearscr();
128                            moveto(1, 1);
129                            prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: ");
130                            iflush();
131    
132                            for (ch = 0; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME))
133                            {
134                                    switch (toupper(ch))
135                                    {
136                                    case CR:
137                                            igetch_reset();
138                                    case 'S':
139                                            break;
140                                    case 'C':
141                                            clearscr();
142                                            moveto(1, 1);
143                                            prints("取消...");
144                                            press_any_key();
145                                            goto cleanup;
146                                    case 'T':
147                                            break;
148                                    case 'E':
149                                            break;
150                                    default: // Invalid selection
151                                            continue;
152                                    }
153    
154                                    break;
155                            }
156                  }                  }
157                  break;          }
158          default:  
159                  log_error("Unsupported type=%d\n", type);          // editor_data_save(p_editor_data, p_data_new, data_new_len);
160                  return -1;          log_common("Debug: post article\n");
161    
162    cleanup:
163            editor_data_cleanup(p_editor_data);
164    
165            return 0;
166    }
167    
168    int article_modify(SECTION_LIST *p_section, ARTICLE *p_article)
169    {
170            ARTICLE_CACHE cache;
171            EDITOR_DATA *p_editor_data;
172    
173            if (p_section == NULL || p_article == NULL)
174            {
175                    log_error("NULL pointer error\n");
176            }
177    
178            if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0)
179            {
180                    log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
181                    return -2;
182            }
183            p_editor_data = editor_data_load(cache.p_data);
184            if (p_editor_data == NULL)
185            {
186                    log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
187                    return -2;
188            }
189            if (article_cache_unload(&cache) < 0)
190            {
191                    log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
192                    return -2;
193            }
194    
195            editor_display(p_editor_data);
196    
197            // editor_data_save(p_editor_data, p_data_new, data_new_len);
198    
199            editor_data_cleanup(p_editor_data);
200    
201            return 0;
202    }
203    
204    int article_reply(SECTION_LIST *p_section, ARTICLE *p_article)
205    {
206            ARTICLE_CACHE cache;
207            EDITOR_DATA *p_editor_data;
208    
209            if (p_section == NULL || p_article == NULL)
210            {
211                    log_error("NULL pointer error\n");
212            }
213    
214            if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0)
215            {
216                    log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
217                    return -2;
218            }
219            p_editor_data = editor_data_load(cache.p_data);
220            if (p_editor_data == NULL)
221            {
222                    log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
223                    return -2;
224            }
225            if (article_cache_unload(&cache) < 0)
226            {
227                    log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
228                    return -2;
229          }          }
230    
231          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