1 /* Copyright 2013 Akira Ohta (akohta001@gmail.com)
2 This file is part of ntch.
4 The ntch is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 The ntch is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with ntch. If not, see <http://www.gnu.org/licenses/>.
20 #include <sys/types.h>
28 #include "nt_string.h"
29 #include "_2ch/_2ch.h"
30 #include "utils/nt_std_t.h"
31 #include "utils/text.h"
32 #include "utils/file.h"
36 static BOOL read_editor(FILE *fp, nt_write_data_handle h_write_data,
37 char *buf_reuse, size_t buf_len);
39 BOOL disp_editor2(const char *file_name)
44 sprintf(buf, "%s %s", EDITOR_CMD, file_name);
46 if (WIFSIGNALED(ret) &&
47 (WTERMSIG(ret) == SIGINT ||
48 WTERMSIG(ret) == SIGQUIT))
53 BOOL nt_link_cmp(nt_link_tp l, nt_link_tp r, nt_compare_fn cmp_func)
59 if(0 != cmp_func(lp->data, rp->data))
63 }while(l != lp || r != rp);
64 return (l == lp && r == rp);
67 nt_link_tp disp_editor3(nt_link_tp text_list)
77 sprintf(fname, "%s/txt%d.tmp", LOG_PATH, pid);
79 tmp_fp = fopen(fname, "w");
84 if(!nt_write_text_file(fname, text_list))
88 sprintf(buf, "%s %s", EDITOR_CMD, fname);
90 if (WIFSIGNALED(ret) &&
91 (WTERMSIG(ret) == SIGINT ||
92 WTERMSIG(ret) == SIGQUIT))
95 out_linkp = nt_read_text_file(fname);
99 if(nt_link_cmp(out_linkp, text_list, nt_link_wcscmp_fnc)){
100 nt_all_link_free(out_linkp, free);
107 BOOL disp_editor(nt_write_data_handle h_write_data)
114 const char *name, *mail;
116 assert(h_write_data);
118 name = nt_write_data_get_name(h_write_data);
119 mail = nt_write_data_get_mail(h_write_data);
123 sprintf(fname, "%s/msg%d.tmp", LOG_PATH, pid);
124 tmp_fp = fopen(fname, "w");
128 strcpy(buf, "name: ");
133 if(len > fwrite(buf, sizeof(char), len, tmp_fp))
136 sprintf(buf, "mail: %s\n\n",
137 (mail) ? mail : "sage");
139 if(len > fwrite(buf, sizeof(char), len, tmp_fp))
142 fprintf(tmp_fp, "Please write your message here\n");
145 sprintf(buf, "%s %s", EDITOR_CMD, fname);
147 if (WIFSIGNALED(ret) &&
148 (WTERMSIG(ret) == SIGINT ||
149 WTERMSIG(ret) == SIGQUIT))
152 tmp_fp = fopen(fname, "r");
156 if(!read_editor(tmp_fp, h_write_data, buf, sizeof(buf)))
160 nt_write_data_set_status_msg(h_write_data, NT_INFO_WRITE_MSG_SUCCESS);
172 BOOL read_editor(FILE *fp, nt_write_data_handle h_write_data,
173 char *buf_reuse, size_t buf_len)
181 while(fgets(buf_reuse, buf_len, fp)){
182 if(buf_reuse[0] == '\n' ||
183 buf_reuse[0] == '\0')
185 cptr = strchr(buf_reuse, ':');
190 cptr2 = nt_trim2(buf_reuse, buf2, sizeof(buf2));
194 if(0 == strcmp(cptr2, "name")){
195 nt_write_data_set_name(h_write_data,cptr+1);
197 // free(writep->name);
198 //writep->name = nt_trim(cptr+1);
199 }else if(0 == strcmp(cptr2, "mail")){
200 nt_write_data_set_mail(h_write_data,cptr+1);
202 // free(writep->mail);
203 //writep->mail = nt_trim(cptr+1);
206 /* Read message to send */
209 while(fgets(buf_reuse+offset, buf_len-offset, fp)){
210 nread = strlen(buf_reuse+offset);
213 len = strlen(buf_reuse);
215 nt_write_data_set_status_msg(h_write_data, NT_ERR_MSG_WRITE_MSG_LENGTH);
218 if(!strcmp(buf_reuse, "Please write your message here\n")){
219 nt_write_data_set_status_msg(h_write_data, NT_ERR_MSG_WRITE_MSG_ABORTED);
222 //cptr = malloc(len+1);
224 //writep->msg = cptr;
225 nt_write_data_set_msg(h_write_data, buf_reuse);