summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-16 17:41:13 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-16 17:41:13 +0800
commitdf16c8a460ca1f045be0b0c8fc789b76a6338224 (patch)
tree43496be6b7fd75cf435160cdb592a94b3addf94e
parent1b162d305b32d23c79f7d483344167f86c2a7f59 (diff)
downloadpttbbs-df16c8a460ca1f045be0b0c8fc789b76a6338224.tar
pttbbs-df16c8a460ca1f045be0b0c8fc789b76a6338224.tar.gz
pttbbs-df16c8a460ca1f045be0b0c8fc789b76a6338224.tar.bz2
pttbbs-df16c8a460ca1f045be0b0c8fc789b76a6338224.tar.lz
pttbbs-df16c8a460ca1f045be0b0c8fc789b76a6338224.tar.xz
pttbbs-df16c8a460ca1f045be0b0c8fc789b76a6338224.tar.zst
pttbbs-df16c8a460ca1f045be0b0c8fc789b76a6338224.zip
- prepare for text-only editing
- message update for modified post git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3694 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/proto.h1
-rw-r--r--mbbsd/bbs.c22
-rw-r--r--mbbsd/edit.c91
3 files changed, 99 insertions, 15 deletions
diff --git a/include/proto.h b/include/proto.h
index 502d04b6..247b47cd 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -222,6 +222,7 @@ int dice_main(void);
/* edit */
int vedit(char *fpath, int saveheader, int *islocal);
+int vedit2(char *fpath, int saveheader, int *islocal, int textOnly);
void write_header(FILE *fp, char *mytitle);
void addsignature(FILE *fp, int ifuseanony);
void auto_backup(void);
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index 2d068841..5443770b 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -1483,18 +1483,17 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct)
#endif // EDITPOST_SMARTMERGE
+#ifdef EXP_EDITPOST_TEXTONLY
+ // experimental: "text only" editing
+ if (vedit2(fpath, 0, NULL, 1) == -1)
+ break;
+#else
if (vedit(fpath, 0, NULL) == -1)
break;
+#endif
newmt = dasht(genbuf);
- if (newmt != oldmt)
- {
- move(b_lines-7, 0);
- clrtobot();
- outs(ANSI_COLOR(1;33) "▲ 檔案已被修改過! ▲" ANSI_RESET "\n\n");
- }
-
#ifdef EDITPOST_SMARTMERGE
// only merge if file is enlarged and modified
@@ -1514,6 +1513,10 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct)
if (canDoSmartMerge)
{
canDoSmartMerge = 0; // only try merge once
+
+ move(b_lines-7, 0);
+ clrtobot();
+ outs(ANSI_COLOR(1;33) "▲ 檔案已被修改過! ▲" ANSI_RESET "\n\n");
outs("進行自動合併 [Smart Merge]...\n");
// smart merge
@@ -1545,6 +1548,11 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct)
if (oldmt != newmt)
{
int c = 0;
+
+ move(b_lines-7, 0);
+ clrtobot();
+ outs(ANSI_COLOR(1;31) "▲ 檔案已被修改過! ▲" ANSI_RESET "\n\n");
+
outs("可能是您在編輯的過程中有人進行推文或修文。\n"
"您可以選擇直接覆蓋\檔案(y)、放棄(n),\n"
" 或是" ANSI_COLOR(1)"重新編輯" ANSI_RESET
diff --git a/mbbsd/edit.c b/mbbsd/edit.c
index d9151031..b44f8c70 100644
--- a/mbbsd/edit.c
+++ b/mbbsd/edit.c
@@ -157,6 +157,7 @@ typedef struct editor_internal_t {
char raw_mode :1;
char *searched_string;
+ char *sitesig_string;
char *(*substr_fp) ();
struct editor_internal_t *prev;
@@ -303,6 +304,8 @@ edit_buffer_destructor(void)
if (curr_buf->searched_string != NULL)
free(curr_buf->searched_string);
+ if (curr_buf->sitesig_string != NULL)
+ free(curr_buf->sitesig_string);
}
static inline void
@@ -1057,15 +1060,27 @@ delete_char(void)
}
static void
-load_file(FILE * fp)
+load_file(FILE * fp, off_t offSig)
{
char buf[WRAPMARGIN + 2];
int indent_mode0 = curr_buf->indent_mode;
+ size_t szread = 0;
assert(fp);
curr_buf->indent_mode = 0;
while (fgets(buf, sizeof(buf), fp))
- insert_string(buf);
+ {
+ szread += strlen(buf);
+ if (offSig < 0 || szread <= offSig)
+ {
+ insert_string(buf);
+ }
+ else
+ {
+ // this is the site sig
+ break;
+ }
+ }
curr_buf->indent_mode = indent_mode0;
}
@@ -1105,7 +1120,7 @@ read_tmpbuf(int n)
if (n != 0 && n != 5 && more(fp_tmpbuf, NA) != -1)
getdata(b_lines - 1, 0, "確定讀入嗎(Y/N)?[Y]", ans, sizeof(ans), LCECHO);
if (*ans != 'n' && (fp = fopen(fp_tmpbuf, "r"))) {
- load_file(fp);
+ load_file(fp, -1);
fclose(fp);
while (curr_buf->curr_window_line >= b_lines) {
curr_buf->curr_window_line--;
@@ -1385,10 +1400,16 @@ check_quote(void)
}
/* 檔案處理:讀檔、存檔、標題、簽名檔 */
+off_t loadsitesig(const char *fname);
+
static void
-read_file(const char *fpath)
+read_file(const char *fpath, int splitSig)
{
- FILE *fp;
+ FILE *fp;
+ off_t offSig = -1;
+
+ if (splitSig)
+ offSig = loadsitesig(fpath);
if ((fp = fopen(fpath, "r")) == NULL) {
int fd;
@@ -1399,7 +1420,7 @@ read_file(const char *fpath)
indigestion(4);
abort_bbs(0);
}
- load_file(fp);
+ load_file(fp, offSig);
fclose(fp);
}
@@ -1483,6 +1504,48 @@ write_header(FILE * fp, char *mytitle) // FIXME unused
fprintf(fp, "標題: %s\n時間: %s\n", mytitle, ctime4(&now));
}
+off_t
+loadsitesig(const char *fname)
+{
+ int fd = 0;
+ off_t sz = 0, ret = -1;
+ char *start, *sp;
+
+ sz = dashs(fname);
+ if (sz < 1)
+ return -1;
+ fd = open(fname, O_RDONLY);
+ if (fd < 0)
+ return -1;
+ start = (char*)mmap(NULL, sz, PROT_READ, MAP_SHARED, fd, 0);
+ if (start)
+ {
+ sp = start + sz - 4 - 1; // 4 = \n--\n
+ while (sp > start)
+ {
+ if ((*sp == '\n' && strncmp(sp, "\n--\n", 4) == 0) ||
+ (*sp == '\r' && strncmp(sp, "\r--\r", 4) == 0) )
+ {
+ size_t szSig = sz - (sp-start+1);
+ ret = sp - start + 1;
+ // allocate string
+ curr_buf->sitesig_string = (char*) malloc (szSig + 1);
+ if (curr_buf->sitesig_string)
+ {
+ memcpy(curr_buf->sitesig_string, sp+1, szSig);
+ curr_buf->sitesig_string[szSig] = 0;
+ }
+ break;
+ }
+ sp --;
+ }
+ munmap(start, sz);
+ }
+
+ close(fd);
+ return ret;
+}
+
void
addsignature(FILE * fp, int ifuseanony)
{
@@ -1689,6 +1752,12 @@ write_file(char *fpath, int saveheader, int *islocal, char *mytitle)
if (!aborted) {
if (islocal)
*islocal = local_article;
+
+ if (curr_buf->sitesig_string)
+ {
+ fprintf(fp, curr_buf->sitesig_string);
+ }
+
if (currstat == POSTING || currstat == SMAIL)
{
addsignature(fp, curr_buf->ifuseanony);
@@ -2697,7 +2766,7 @@ phone_mode_filter(char ch)
/* 編輯處理:主程式、鍵盤處理 */
int
-vedit(char *fpath, int saveheader, int *islocal)
+vedit2(char *fpath, int saveheader, int *islocal, int textOnly)
{
char last = 0; /* the last key you press */
int ch, tmp;
@@ -2727,7 +2796,7 @@ vedit(char *fpath, int saveheader, int *islocal)
curr_buf->firstline = curr_buf->lastline = alloc_line(WRAPMARGIN);
if (*fpath) {
- read_file(fpath);
+ read_file(fpath, textOnly);
}
if (*quote_file) {
@@ -3344,5 +3413,11 @@ vedit(char *fpath, int saveheader, int *islocal)
exit_edit_buffer();
}
+int
+vedit(char *fpath, int saveheader, int *islocal)
+{
+ return vedit2(fpath, saveheader, islocal, 0);
+}
+
/* vim:sw=4:nofoldenable
*/