summaryrefslogtreecommitdiffstats
path: root/mbbsd/announce.c
diff options
context:
space:
mode:
Diffstat (limited to 'mbbsd/announce.c')
-rw-r--r--mbbsd/announce.c1122
1 files changed, 590 insertions, 532 deletions
diff --git a/mbbsd/announce.c b/mbbsd/announce.c
index 5eb58ef6..3e8700bf 100644
--- a/mbbsd/announce.c
+++ b/mbbsd/announce.c
@@ -1,21 +1,23 @@
-/* $Id: announce.c,v 1.12 2002/06/19 13:20:27 lwms Exp $ */
+/* $Id: announce.c,v 1.13 2002/07/05 17:10:26 in2 Exp $ */
#include "bbs.h"
-static void g_showmenu(gmenu_t *pm) {
- static char *mytype = "編 選 絲路之旅";
- char *title, ch;
- int n, max;
- item_t *item;
+static void
+g_showmenu(gmenu_t * pm)
+{
+ static char *mytype = "編 選 絲路之旅";
+ char *title, ch;
+ int n, max;
+ item_t *item;
showtitle("精華文章", pm->mtitle);
prints(" \033[1;36m編號 標 題%56s\033[m", mytype);
-
- if(pm->num) {
+
+ if (pm->num) {
n = pm->page;
max = n + p_lines;
- if(max > pm->num)
+ if (max > pm->num)
max = pm->num;
- while(n < max) {
+ while (n < max) {
item = pm->item[n++];
title = item->title;
ch = title[1];
@@ -34,35 +36,37 @@ static void g_showmenu(gmenu_t *pm) {
"\033[31m(enter/→)\033[30m讀取資料 \033[m");
}
-static FILE *go_cmd(item_t *node, int *sock) {
+static FILE *
+go_cmd(item_t * node, int *sock)
+{
struct sockaddr_in sin;
struct hostent *host;
- char *site;
- FILE *fp;
-
+ char *site;
+ FILE *fp;
+
*sock = socket(AF_INET, SOCK_STREAM, 0);
-
- if(*sock < 0) {
+
+ if (*sock < 0) {
syslog(LOG_ERR, "socket(): %m");
return NULL;
}
memset((char *)&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(node->X.G.port);
-
+
host = gethostbyname(site = node->X.G.server);
- if(host == NULL)
+ if (host == NULL)
sin.sin_addr.s_addr = inet_addr(site);
else
memcpy(&sin.sin_addr.s_addr, host->h_addr, host->h_length);
-
- if(connect(*sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+
+ if (connect(*sock, (struct sockaddr *) & sin, sizeof(sin)) < 0) {
syslog(LOG_ERR, "connect(): %m");
return NULL;
}
fp = fdopen(*sock, "r+");
- if(fp != NULL) {
- setbuf(fp, (char *) 0);
+ if (fp != NULL) {
+ setbuf(fp, (char *)0);
fprintf(fp, "%s\r\n", node->X.G.path);
fflush(fp);
} else
@@ -70,12 +74,14 @@ static FILE *go_cmd(item_t *node, int *sock) {
return fp;
}
-static char *nextfield(char *data, char *field) {
- register int ch;
-
- while((ch = *data)) {
+static char *
+nextfield(char *data, char *field)
+{
+ register int ch;
+
+ while ((ch = *data)) {
data++;
- if((ch == '\t') || (ch == '\r' && *data == '\n'))
+ if ((ch == '\t') || (ch == '\r' && *data == '\n'))
break;
*field++ = ch;
}
@@ -83,90 +89,94 @@ static char *nextfield(char *data, char *field) {
return data;
}
-static FILE* my_open(char* path) {
- FILE* ans = 0;
- char buf[80];
- struct stat st;
+static FILE *
+my_open(char *path)
+{
+ FILE *ans = 0;
+ char buf[80];
+ struct stat st;
- if(stat(path, &st) == 0 && st.st_mtime < now - 3600 * 24 * 7) {
+ if (stat(path, &st) == 0 && st.st_mtime < now - 3600 * 24 * 7) {
return fopen(path, "w");
}
-
- if((ans = fopen(path, "r+"))) {
+ if ((ans = fopen(path, "r+"))) {
fclose(ans);
return 0;
/*
- return directly due to currutmp->pager > 1 mode (real copy)
- */
+ * return directly due to currutmp->pager > 1 mode (real copy)
+ */
fgets(buf, 80, ans);
- if(!strncmp(buf, str_author1, strlen(str_author1)) ||
- *buf == '0' || *buf == '1') {
+ if (!strncmp(buf, str_author1, strlen(str_author1)) ||
+ *buf == '0' || *buf == '1') {
fclose(ans);
return 0;
}
-
rewind(ans);
} else
ans = fopen(path, "w");
return ans;
}
-static jmp_buf jbuf;
+static jmp_buf jbuf;
-static void isig(int sig) {
+static void
+isig(int sig)
+{
longjmp(jbuf, 1);
}
#define PROXY_HOME "proxy/"
-static void go_proxy(char* fpath, item_t *node, int update) {
- char *ptr, *str, *server;
- int ch;
- static FILE *fo;
-
+static void
+go_proxy(char *fpath, item_t * node, int update)
+{
+ char *ptr, *str, *server;
+ int ch;
+ static FILE *fo;
+
strcpy(fpath, PROXY_HOME);
ptr = fpath + sizeof(PROXY_HOME) - 1;
str = server = node->X.G.server;
- while((ch = *str)) {
+ while ((ch = *str)) {
str++;
- if(ch == '.') {
- if(!strcmp(str, "edu.tw"))
+ if (ch == '.') {
+ if (!strcmp(str, "edu.tw"))
break;
- } else if(ch >= 'A' && ch <= 'Z') {
+ } else if (ch >= 'A' && ch <= 'Z') {
ch |= 0x20;
}
*ptr++ = ch;
}
*ptr = '\0';
mkdir(fpath, 0755);
-
+
*ptr++ = '/';
str = node->X.G.path;
- while((ch = *str)) {
+ while ((ch = *str)) {
str++;
- if(ch == '/') {
+ if (ch == '/') {
ch = '.';
}
*ptr++ = ch;
}
*ptr = '\0';
-
+
/* expire proxy data */
-
- if((fo = update ? fopen(fpath, "w") : my_open(fpath))) {
- FILE *fp;
- char buf[512];
- int sock;
-
- if(fo == NULL)
+
+ if ((fo = update ? fopen(fpath, "w") : my_open(fpath))) {
+ FILE *fp;
+ char buf[512];
+ int sock;
+
+ if (fo == NULL)
return;
-
+
outmsg("★ 建立 proxy 資料連線中 ... ");
refresh();
-
+
sock = -1;
- if(setjmp(jbuf)) {
- if(sock != -1)
+ if (setjmp(jbuf)) {
+ if (sock != -1)
close(sock);
fseek(fo, 0, SEEK_SET);
fwrite("", 0, 0, fo);
@@ -174,7 +184,6 @@ static void go_proxy(char* fpath, item_t *node, int update) {
alarm(0);
return;
}
-
signal(SIGALRM, isig);
alarm(5);
fp = go_cmd(node, &sock);
@@ -182,17 +191,16 @@ static void go_proxy(char* fpath, item_t *node, int update) {
str = node->title;
ch = str[1];
- if(ch == (char) 0xbc &&
- !(HAS_PERM(PERM_SYSOP) && currutmp->pager > 1)) {
+ if (ch == (char)0xbc &&
+ !(HAS_PERM(PERM_SYSOP) && currutmp->pager > 1)) {
fprintf(fo, "作者: %s (連線精華區)\n標題: %s\n時間: %s\n",
server, str + 3, ctime(&now)
);
}
-
- while(fgets(buf, 511, fp)) {
- if(!strcmp(buf, ".\r\n"))
+ while (fgets(buf, 511, fp)) {
+ if (!strcmp(buf, ".\r\n"))
break;
- if((ptr = strstr(buf, "\r\n")))
+ if ((ptr = strstr(buf, "\r\n")))
strcpy(ptr, "\n");
fputs(buf, fo);
}
@@ -201,46 +209,50 @@ static void go_proxy(char* fpath, item_t *node, int update) {
}
}
-static void g_additem(gmenu_t *pm, item_t *myitem) {
- if(pm->num < MAX_ITEMS) {
- item_t *newitem = (item_t *)malloc(sizeof(item_t));
-
+static void
+g_additem(gmenu_t * pm, item_t * myitem)
+{
+ if (pm->num < MAX_ITEMS) {
+ item_t *newitem = (item_t *) malloc(sizeof(item_t));
+
memcpy(newitem, myitem, sizeof(item_t));
pm->item[(pm->num)++] = newitem;
}
}
-static void go_menu(gmenu_t *pm, item_t *node, int update) {
- FILE *fp;
- char buf[512], *ptr, *title;
- item_t item;
- int ch;
-
+static void
+go_menu(gmenu_t * pm, item_t * node, int update)
+{
+ FILE *fp;
+ char buf[512], *ptr, *title;
+ item_t item;
+ int ch;
+
go_proxy(buf, node, update);
pm->num = 0;
- if((fp = fopen(buf, "r"))) {
+ if ((fp = fopen(buf, "r"))) {
title = item.title;
- while(fgets(buf, 511, fp)) {
+ while (fgets(buf, 511, fp)) {
ptr = buf;
ch = *ptr++;
- if(ch != '0' && ch != '1')
+ if (ch != '0' && ch != '1')
continue;
-
+
strcpy(title, "□ ");
- if(ch == '1')
- title[1] = (char) 0xbd;
+ if (ch == '1')
+ title[1] = (char)0xbd;
ptr = nextfield(ptr, title + 3);
- if(!*ptr)
+ if (!*ptr)
continue;
title[sizeof(item.title) - 1] = '\0';
ptr = nextfield(ptr, item.X.G.path);
- if(!*ptr)
+ if (!*ptr)
continue;
ptr = nextfield(ptr, item.X.G.server);
- if(!*ptr)
+ if (!*ptr)
continue;
nextfield(ptr, buf);
@@ -252,12 +264,14 @@ static void go_menu(gmenu_t *pm, item_t *node, int update) {
}
}
-static int g_searchtitle(gmenu_t* pm, int rev) {
- static char search_str[30] = "";
- int pos;
-
- if(getdata(b_lines - 1, 1,"[搜尋]關鍵字:", search_str, sizeof(search_str), DOECHO))
- if(!*search_str)
+static int
+g_searchtitle(gmenu_t * pm, int rev)
+{
+ static char search_str[30] = "";
+ int pos;
+
+ if (getdata(b_lines - 1, 1, "[搜尋]關鍵字:", search_str, sizeof(search_str), DOECHO))
+ if (!*search_str)
return pm->now;
str_lower(search_str, search_str);
@@ -266,17 +280,19 @@ static int g_searchtitle(gmenu_t* pm, int rev) {
pos = pm->now;
do {
pos += rev;
- if(pos == pm->num)
+ if (pos == pm->num)
pos = 0;
- else if(pos < 0)
+ else if (pos < 0)
pos = pm->num - 1;
- if(strstr_lower(pm->item[pos]->title, search_str))
+ if (strstr_lower(pm->item[pos]->title, search_str))
return pos;
- } while(pos != pm->now);
+ } while (pos != pm->now);
return pm->now;
}
-static void g_showhelp() {
+static void
+g_showhelp()
+{
clear();
outs("\033[36m【 " BBSNAME "連線精華區使用說明 】\033[m\n\n"
"[←][q] 離開到上一層目錄\n"
@@ -296,24 +312,26 @@ static void g_showhelp() {
#define PATHLEN 256
-static char paste_fname[200];
+static char paste_fname[200];
-static void load_paste() {
- struct stat st;
- FILE *fp;
-
- if(!*paste_fname)
+static void
+load_paste()
+{
+ struct stat st;
+ FILE *fp;
+
+ if (!*paste_fname)
setuserfile(paste_fname, "paste_path");
- if(stat(paste_fname, &st) == 0 && st.st_mtime > paste_time &&
- (fp = fopen(paste_fname, "r"))) {
- int i;
+ if (stat(paste_fname, &st) == 0 && st.st_mtime > paste_time &&
+ (fp = fopen(paste_fname, "r"))) {
+ int i;
fgets(paste_path, PATHLEN, fp);
i = strlen(paste_path) - 1;
- if(paste_path[i] == '\n')
+ if (paste_path[i] == '\n')
paste_path[i] = 0;
fgets(paste_title, STRLEN, fp);
i = strlen(paste_title) - 1;
- if(paste_title[i] == '\n')
+ if (paste_title[i] == '\n')
paste_title[i] = 0;
fscanf(fp, "%d", &paste_level);
paste_time = st.st_mtime;
@@ -321,18 +339,20 @@ static void load_paste() {
}
}
-static char copyfile[PATHLEN];
-static char copytitle[TTLEN+1];
-static char copyowner[IDLEN + 2];
+static char copyfile[PATHLEN];
+static char copytitle[TTLEN + 1];
+static char copyowner[IDLEN + 2];
-void a_copyitem(char* fpath, char* title, char* owner, int mode) {
+void
+a_copyitem(char *fpath, char *title, char *owner, int mode)
+{
strcpy(copyfile, fpath);
strcpy(copytitle, title);
- if(owner)
+ if (owner)
strcpy(copyowner, owner);
else
*copyowner = 0;
- if(mode) {
+ if (mode) {
outmsg("檔案標記完成。[注意] 拷貝後才能刪除原文!");
igetch();
}
@@ -340,50 +360,56 @@ void a_copyitem(char* fpath, char* title, char* owner, int mode) {
#define FHSZ sizeof(fileheader_t)
-static void a_loadname(menu_t *pm) {
- char buf[PATHLEN];
- int len;
-
+static void
+a_loadname(menu_t * pm)
+{
+ char buf[PATHLEN];
+ int len;
+
setadir(buf, pm->path);
- len = get_records(buf, pm->header, FHSZ, pm->page+1, p_lines);
- if(len < p_lines)
- bzero(&pm->header[len], FHSZ*(p_lines-len));
+ len = get_records(buf, pm->header, FHSZ, pm->page + 1, p_lines);
+ if (len < p_lines)
+ bzero(&pm->header[len], FHSZ * (p_lines - len));
}
-static void a_timestamp(char *buf, time_t *time) {
- struct tm *pt = localtime(time);
-
+static void
+a_timestamp(char *buf, time_t * time)
+{
+ struct tm *pt = localtime(time);
+
sprintf(buf, "%02d/%02d/%02d", pt->tm_mon + 1, pt->tm_mday, (pt->tm_year + 1900) % 100);
}
-static void a_showmenu(menu_t *pm) {
- char *title, *editor;
- int n;
- fileheader_t *item;
- char buf[PATHLEN];
- time_t dtime;
+static void
+a_showmenu(menu_t * pm)
+{
+ char *title, *editor;
+ int n;
+ fileheader_t *item;
+ char buf[PATHLEN];
+ time_t dtime;
showtitle("精華文章", pm->mtitle);
prints(" \033[1;36m編號 標 題%56s\033[0m",
"編 選 日 期");
- if(pm->num) {
+ if (pm->num) {
setadir(buf, pm->path);
a_loadname(pm);
- for(n = 0; n < p_lines && pm->page + n < pm->num; n++) {
+ for (n = 0; n < p_lines && pm->page + n < pm->num; n++) {
item = &pm->header[n];
title = item->title;
editor = item->owner;
- /* Ptt 把時間改為取檔案時間
- dtime = atoi(&item->filename[2]);
- */
- sprintf(buf,"%s/%s",pm->path,item->filename);
+ /*
+ * Ptt 把時間改為取檔案時間 dtime = atoi(&item->filename[2]);
+ */
+ sprintf(buf, "%s/%s", pm->path, item->filename);
dtime = dasht(buf);
a_timestamp(buf, &dtime);
- prints("\n%6d%c %-47.46s%-13s[%s]", pm->page+n+1,
- (item->filemode & FILE_BM) ?'X':
- (item->filemode & FILE_HIDE) ?')':'.',
- title, editor,
+ prints("\n%6d%c %-47.46s%-13s[%s]", pm->page + n + 1,
+ (item->filemode & FILE_BM) ? 'X' :
+ (item->filemode & FILE_HIDE) ? ')' : '.',
+ title, editor,
buf);
}
} else
@@ -399,38 +425,44 @@ static void a_showmenu(menu_t *pm) {
"\033[31m(enter/→)\033[30m讀取資料 \033[m");
}
-static int a_searchtitle(menu_t *pm, int rev) {
- static char search_str[40] = "";
- int pos;
-
+static int
+a_searchtitle(menu_t * pm, int rev)
+{
+ static char search_str[40] = "";
+ int pos;
+
getdata(b_lines - 1, 1, "[搜尋]關鍵字:", search_str, sizeof(search_str), DOECHO);
-
- if(!*search_str)
+
+ if (!*search_str)
return pm->now;
-
+
str_lower(search_str, search_str);
-
+
rev = rev ? -1 : 1;
pos = pm->now;
do {
pos += rev;
- if(pos == pm->num)
+ if (pos == pm->num)
pos = 0;
- else if(pos < 0)
+ else if (pos < 0)
pos = pm->num - 1;
- if(pos < pm->page || pos >= pm->page + p_lines) {
+ if (pos < pm->page || pos >= pm->page + p_lines) {
pm->page = pos - pos % p_lines;
a_loadname(pm);
}
- if(strstr_lower(pm->header[pos - pm->page].title, search_str))
+ if (strstr_lower(pm->header[pos - pm->page].title, search_str))
return pos;
- } while(pos != pm->now);
+ } while (pos != pm->now);
return pm->now;
}
-enum {NOBODY, MANAGER, SYSOP};
+enum {
+ NOBODY, MANAGER, SYSOP
+};
-static void a_showhelp(int level) {
+static void
+a_showhelp(int level)
+{
clear();
outs("\033[36m【 " BBSNAME "公佈欄使用說明 】\033[m\n\n"
"[←][q] 離開到上一層目錄\n"
@@ -442,17 +474,16 @@ static void a_showhelp(int level) {
"[##] 移到該選項\n"
"[F][U] 將文章寄回 Internet 郵箱/"
"將文章 uuencode 後寄回郵箱\n");
- if(level >= MANAGER) {
+ if (level >= MANAGER) {
outs("\n\033[36m【 板主專用鍵 】\033[m\n"
- "[H] 切換為 公開/會員/板主 才能閱\讀\n"
+ "[H] 切換為 公開/會員/板主 才能閱\讀\n"
"[n/g/G] 收錄精華文章/開闢目錄/建立連線\n"
"[m/d/D] 移動/刪除文章/刪除一個範圍的文章\n"
"[f/T/e] 編輯標題符號/修改文章標題/內容\n"
"[c/p/a] 拷貝/粘貼/附加文章\n"
"[^P/^A] 粘貼/附加已用't'標記文章\n");
}
-
- if(level >= SYSOP) {
+ if (level >= SYSOP) {
outs("\n\033[36m【 站長專用鍵 】\033[m\n"
"[l] 建 symbolic link\n"
"[N] 查詢檔名\n");
@@ -460,11 +491,13 @@ static void a_showhelp(int level) {
pressanykey();
}
-static int AnnounceSelect() {
- static char xboard[20];
- char buf[20];
- char fpath[256];
- boardheader_t *bp;
+static int
+AnnounceSelect()
+{
+ static char xboard[20];
+ char buf[20];
+ char fpath[256];
+ boardheader_t *bp;
move(2, 0);
clrtoeol();
@@ -476,9 +509,9 @@ static int AnnounceSelect() {
completeboard_compar,
completeboard_permission,
completeboard_getname);
- if(*buf)
+ if (*buf)
strcpy(xboard, buf);
- if(*xboard && (bp = getbcache(getbnum(xboard)))) {
+ if (*xboard && (bp = getbcache(getbnum(xboard)))) {
setapath(fpath, xboard);
setutmpmode(ANNOUNCE);
a_menu(xboard, fpath,
@@ -488,57 +521,58 @@ static int AnnounceSelect() {
return FULLUPDATE;
}
-void gem(char* maintitle, item_t* path, int update) {
- gmenu_t me;
- int ch;
- char fname[PATHLEN];
-
+void
+gem(char *maintitle, item_t * path, int update)
+{
+ gmenu_t me;
+ int ch;
+ char fname[PATHLEN];
+
strncpy(me.mtitle, maintitle, 40);
me.mtitle[40] = 0;
go_menu(&me, path, update);
-
+
/* 精華區-tree 中部份結構屬於 cuser ==> BM */
-
+
me.level = 0;
me.page = 9999;
me.now = 0;
- for(;;) {
- if(me.now >= me.num && me.num > 0)
+ for (;;) {
+ if (me.now >= me.num && me.num > 0)
me.now = me.num - 1;
- else if(me.now < 0)
+ else if (me.now < 0)
me.now = 0;
-
- if(me.now < me.page || me.now >= me.page + p_lines) {
+
+ if (me.now < me.page || me.now >= me.page + p_lines) {
me.page = me.now - (me.now % p_lines);
g_showmenu(&me);
}
ch = cursor_key(2 + me.now - me.page, 0);
- if(ch == 'q' || ch == 'Q' || ch == KEY_LEFT)
+ if (ch == 'q' || ch == 'Q' || ch == KEY_LEFT)
break;
-
- if(ch >= '0' && ch <= '9') {
- if((ch = search_num(ch, me.num)) != -1)
+
+ if (ch >= '0' && ch <= '9') {
+ if ((ch = search_num(ch, me.num)) != -1)
me.now = ch;
me.page = 9999;
continue;
}
-
- switch(ch) {
+ switch (ch) {
case KEY_UP:
case 'k':
- if(--me.now < 0)
+ if (--me.now < 0)
me.now = me.num - 1;
break;
case KEY_DOWN:
case 'j':
- if(++me.now >= me.num)
+ if (++me.now >= me.num)
me.now = 0;
break;
case KEY_PGUP:
case 'b':
- if(me.now >= p_lines)
+ if (me.now >= p_lines)
me.now -= p_lines;
- else if(me.now > 0)
+ else if (me.now > 0)
me.now = 0;
else
me.now = me.num - 1;
@@ -546,9 +580,9 @@ void gem(char* maintitle, item_t* path, int update) {
case ' ':
case KEY_PGDN:
case Ctrl('F'):
- if(me.now < me.num - p_lines)
+ if (me.now < me.num - p_lines)
me.now += p_lines;
- else if(me.now < me.num - 1)
+ else if (me.now < me.num - 1)
me.now = me.num - 1;
else
me.now = 0;
@@ -563,7 +597,7 @@ void gem(char* maintitle, item_t* path, int update) {
me.page = 9999;
break;
case 'N':
- if(HAS_PERM(PERM_SYSOP)) {
+ if (HAS_PERM(PERM_SYSOP)) {
go_proxy(fname, me.item[me.now], 0);
move(b_lines - 1, 0);
outs(fname);
@@ -574,21 +608,21 @@ void gem(char* maintitle, item_t* path, int update) {
case 'c':
case 'C':
case Ctrl('C'):
- if(me.now < me.num) {
- item_t *node = me.item[me.now];
- char *title = node->title;
- int mode = title[1];
+ if (me.now < me.num) {
+ item_t *node = me.item[me.now];
+ char *title = node->title;
+ int mode = title[1];
load_paste();
- if(mode == (char) 0xbc || ch == Ctrl('C')) {
- if(mode == (char) 0xbc)
+ if (mode == (char)0xbc || ch == Ctrl('C')) {
+ if (mode == (char)0xbc)
go_proxy(fname, node, 0);
- if(ch == Ctrl('C') && *paste_path && paste_level) {
- char newpath[PATHLEN];
- fileheader_t item;
+ if (ch == Ctrl('C') && *paste_path && paste_level) {
+ char newpath[PATHLEN];
+ fileheader_t item;
strcpy(newpath, paste_path);
- if(mode == (char) 0xbc) {
+ if (mode == (char)0xbc) {
stampfile(newpath, &item);
unlink(newpath);
Link(fname, newpath);
@@ -597,19 +631,19 @@ void gem(char* maintitle, item_t* path, int update) {
strcpy(item.owner, cuser.userid);
sprintf(item.title, "%s%.72s",
(currutmp->pager > 1) ? "" :
- (mode == (char) 0xbc) ? "◇ " : "◆ ",
+ (mode == (char)0xbc) ? "◇ " : "◆ ",
title + 3);
strcpy(strrchr(newpath, '/') + 1, ".DIR");
append_record(newpath, &item, FHSZ);
- if(++me.now >= me.num)
+ if (++me.now >= me.num)
me.now = 0;
break;
}
- if(mode == (char) 0xbc) {
+ if (mode == (char)0xbc) {
a_copyitem(fname,
title + ((currutmp->pager > 1) ? 3 : 0),
0, 1);
- if(ch == 'C' && *paste_path) {
+ if (ch == 'C' && *paste_path) {
setutmpmode(ANNOUNCE);
a_menu(paste_title, paste_path, paste_level);
}
@@ -636,39 +670,39 @@ void gem(char* maintitle, item_t* path, int update) {
case KEY_RIGHT:
case 'r':
case 'R':
- if(me.now < me.num) {
- item_t *node = me.item[me.now];
- char *title = node->title;
- int mode = title[1];
- int update = (ch == 'R') ? 1 : 0;
+ if (me.now < me.num) {
+ item_t *node = me.item[me.now];
+ char *title = node->title;
+ int mode = title[1];
+ int update = (ch == 'R') ? 1 : 0;
title += 3;
- if(mode == (char) 0xbc) {
- int more_result;
+ if (mode == (char)0xbc) {
+ int more_result;
go_proxy(fname, node, update);
strcpy(vetitle, title);
- while((more_result = more(fname, YEA))) {
- if(more_result == 1) {
- if(--me.now < 0) {
+ while ((more_result = more(fname, YEA))) {
+ if (more_result == 1) {
+ if (--me.now < 0) {
me.now = 0;
break;
}
- } else if(more_result == 3) {
- if(++me.now >= me.num) {
+ } else if (more_result == 3) {
+ if (++me.now >= me.num) {
me.now = me.num - 1;
break;
}
} else
break;
node = me.item[me.now];
- if(node->title[1] != (char) 0xbc)
+ if (node->title[1] != (char)0xbc)
break;
go_proxy(fname, node, update);
strcpy(vetitle, title);
}
- } else if(mode == (char) 0xbd) {
+ } else if (mode == (char)0xbd) {
gem(title, node, update);
}
me.page = 9999;
@@ -676,16 +710,18 @@ void gem(char* maintitle, item_t* path, int update) {
break;
}
}
- for(ch = 0; ch < me.num; ch++)
+ for (ch = 0; ch < me.num; ch++)
free(me.item[ch]);
}
-static void a_forward(char *path, fileheader_t *pitem, int mode) {
- fileheader_t fhdr;
-
+static void
+a_forward(char *path, fileheader_t * pitem, int mode)
+{
+ fileheader_t fhdr;
+
strcpy(fhdr.filename, pitem->filename);
strcpy(fhdr.title, pitem->title);
- switch(doforward(path, &fhdr, mode)) {
+ switch (doforward(path, &fhdr, mode)) {
case 0:
outmsg(msg_fwd_ok);
break;
@@ -698,20 +734,21 @@ static void a_forward(char *path, fileheader_t *pitem, int mode) {
}
}
-static void a_additem(menu_t *pm, fileheader_t *myheader) {
- char buf[PATHLEN];
-
+static void
+a_additem(menu_t * pm, fileheader_t * myheader)
+{
+ char buf[PATHLEN];
+
setadir(buf, pm->path);
- if(append_record(buf, myheader, FHSZ) == -1)
+ if (append_record(buf, myheader, FHSZ) == -1)
return;
pm->now = pm->num++;
-
- if(pm->now >= pm->page + p_lines) {
+
+ if (pm->now >= pm->page + p_lines) {
pm->page = pm->now - ((pm->page == 10000 && pm->now > p_lines / 2) ?
(p_lines / 2) : (pm->now % p_lines));
- }
-
- /*Ptt*/
+ }
+ /* Ptt */
strcpy(pm->header[pm->now - pm->page].filename, myheader->filename);
}
@@ -720,80 +757,81 @@ static void a_additem(menu_t *pm, fileheader_t *myheader) {
#define ADDGOPHER 2
#define ADDLINK 3
-static void a_newitem(menu_t *pm, int mode) {
- static char *mesg[4] = {
- "[新增文章] 請輸入標題:", /* ADDITEM */
- "[新增目錄] 請輸入標題:", /* ADDGROUP */
- "[新增連線] 請輸入標題:", /* ADDGOPHER */
- "請輸入標題:" /* ADDLINK */
+static void
+a_newitem(menu_t * pm, int mode)
+{
+ static char *mesg[4] = {
+ "[新增文章] 請輸入標題:", /* ADDITEM */
+ "[新增目錄] 請輸入標題:", /* ADDGROUP */
+ "[新增連線] 請輸入標題:", /* ADDGOPHER */
+ "請輸入標題:" /* ADDLINK */
};
- char fpath[PATHLEN], buf[PATHLEN], lpath[PATHLEN];
- fileheader_t item;
- int d;
+ char fpath[PATHLEN], buf[PATHLEN], lpath[PATHLEN];
+ fileheader_t item;
+ int d;
strcpy(fpath, pm->path);
- switch(mode) {
+ switch (mode) {
case ADDITEM:
stampfile(fpath, &item);
- strcpy(item.title, "◇ "); /* A1BA */
+ strcpy(item.title, "◇ "); /* A1BA */
break;
-
+
case ADDGROUP:
stampdir(fpath, &item);
- strcpy(item.title, "◆ "); /* A1BB */
+ strcpy(item.title, "◆ "); /* A1BB */
break;
case ADDGOPHER:
bzero(&item, sizeof(item));
- strcpy(item.title, "☉ "); /* A1BB */
- if(!getdata(b_lines - 2, 1, "輸入URL位址:",
- item.filename+2,61, DOECHO))
+ strcpy(item.title, "☉ "); /* A1BB */
+ if (!getdata(b_lines - 2, 1, "輸入URL位址:",
+ item.filename + 2, 61, DOECHO))
return;
break;
case ADDLINK:
stamplink(fpath, &item);
if (!getdata(b_lines - 2, 1, "新增連線:", buf, 61, DOECHO))
return;
- if(invalid_pname(buf)) {
+ if (invalid_pname(buf)) {
unlink(fpath);
outs("目的地路徑不合法!");
igetch();
return;
}
-
item.title[0] = 0;
- for(d = 0; d <= 3; d++) {
- switch(d) {
+ for (d = 0; d <= 3; d++) {
+ switch (d) {
case 0:
sprintf(lpath, BBSHOME "/man/boards/%c/%s/%s",
currboard[0], currboard, buf);
break;
case 1:
sprintf(lpath, "%s%s/%c/%s",
- BBSHOME, "/man/boards/" , buf[0], buf);
+ BBSHOME, "/man/boards/", buf[0], buf);
break;
case 2:
sprintf(lpath, "%s%s%s",
- BBSHOME, "/" , buf);
+ BBSHOME, "/", buf);
break;
case 3:
sprintf(lpath, "%s%s%s",
- BBSHOME, "/etc/" , buf);
+ BBSHOME, "/etc/", buf);
break;
}
- if(dashf(lpath)) {
- strcpy(item.title, "☆ "); /* A1B3 */
+ if (dashf(lpath)) {
+ strcpy(item.title, "☆ "); /* A1B3 */
break;
} else if (dashd(lpath)) {
- strcpy(item.title, "★ "); /* A1B4 */
+ strcpy(item.title, "★ "); /* A1B4 */
break;
}
- if(!HAS_PERM(PERM_BBSADM) && d==1)
+ if (!HAS_PERM(PERM_BBSADM) && d == 1)
break;
}
-
- if(!item.title[0]) {
+
+ if (!item.title[0]) {
unlink(fpath);
outs("目的地路徑不合法!");
igetch();
@@ -801,17 +839,16 @@ static void a_newitem(menu_t *pm, int mode) {
}
}
- if(!getdata(b_lines - 1, 1, mesg[mode], &item.title[3], 55, DOECHO)) {
- if(mode == ADDGROUP)
+ if (!getdata(b_lines - 1, 1, mesg[mode], &item.title[3], 55, DOECHO)) {
+ if (mode == ADDGROUP)
rmdir(fpath);
- else if(mode != ADDGOPHER)
+ else if (mode != ADDGOPHER)
unlink(fpath);
return;
}
-
- switch(mode) {
+ switch (mode) {
case ADDITEM:
- if(vedit(fpath, 0, NULL) == -1) {
+ if (vedit(fpath, 0, NULL) == -1) {
unlink(fpath);
pressanykey();
return;
@@ -819,7 +856,7 @@ static void a_newitem(menu_t *pm, int mode) {
break;
case ADDLINK:
unlink(fpath);
- if(symlink(lpath, fpath) == -1) {
+ if (symlink(lpath, fpath) == -1) {
outs("無法建立 symbolic link");
igetch();
return;
@@ -827,7 +864,7 @@ static void a_newitem(menu_t *pm, int mode) {
break;
case ADDGOPHER:
strcpy(item.date, "70");
- strncpy(item.filename, "H.",2);
+ strncpy(item.filename, "H.", 2);
break;
}
@@ -835,54 +872,56 @@ static void a_newitem(menu_t *pm, int mode) {
a_additem(pm, &item);
}
-static void a_pasteitem(menu_t *pm, int mode) {
- char newpath[PATHLEN];
- char buf[PATHLEN];
- char ans[2];
- int i;
- fileheader_t item;
+static void
+a_pasteitem(menu_t * pm, int mode)
+{
+ char newpath[PATHLEN];
+ char buf[PATHLEN];
+ char ans[2];
+ int i;
+ fileheader_t item;
move(b_lines - 1, 1);
- if(copyfile[0]) {
- if(dashd(copyfile)) {
- for(i = 0; copyfile[i] && copyfile[i] == pm->path[i]; i++);
- if(!copyfile[i]) {
+ if (copyfile[0]) {
+ if (dashd(copyfile)) {
+ for (i = 0; copyfile[i] && copyfile[i] == pm->path[i]; i++);
+ if (!copyfile[i]) {
outs("將目錄拷進自己的子目錄中,會造成無窮迴圈!");
igetch();
return;
}
}
- if(mode) {
+ if (mode) {
sprintf(buf, "確定要拷貝[%s]嗎(Y/N)?[N] ", copytitle);
getdata(b_lines - 1, 1, buf, ans, sizeof(ans), LCECHO);
} else
- ans[0]='y';
- if(ans[0] == 'y') {
+ ans[0] = 'y';
+ if (ans[0] == 'y') {
strcpy(newpath, pm->path);
- if(*copyowner) {
- char* fname = strrchr(copyfile, '/');
+ if (*copyowner) {
+ char *fname = strrchr(copyfile, '/');
- if(fname)
+ if (fname)
strcat(newpath, fname);
else
return;
- if(access(pm->path, X_OK | R_OK | W_OK))
+ if (access(pm->path, X_OK | R_OK | W_OK))
mkdir(pm->path, 0755);
memset(&item, 0, sizeof(fileheader_t));
strcpy(item.filename, fname + 1);
memcpy(copytitle, "◎", 2);
- if(HAS_PERM(PERM_BBSADM))
+ if (HAS_PERM(PERM_BBSADM))
Link(copyfile, newpath);
else {
sprintf(buf, "/bin/cp %s %s", copyfile, newpath);
system(buf);
}
- } else if(dashf(copyfile)) {
+ } else if (dashf(copyfile)) {
stampfile(newpath, &item);
memcpy(copytitle, "◇", 2);
sprintf(buf, "/bin/cp %s %s", copyfile, newpath);
- } else if(dashd(copyfile)) {
+ } else if (dashd(copyfile)) {
stampdir(newpath, &item);
memcpy(copytitle, "◆", 2);
sprintf(buf, "/bin/cp -r %s/* %s/.D* %s", copyfile, copyfile,
@@ -894,7 +933,7 @@ static void a_pasteitem(menu_t *pm, int mode) {
}
strcpy(item.owner, *copyowner ? copyowner : cuser.userid);
strcpy(item.title, copytitle);
- if(!*copyowner)
+ if (!*copyowner)
system(buf);
a_additem(pm, &item);
copyfile[0] = '\0';
@@ -905,36 +944,38 @@ static void a_pasteitem(menu_t *pm, int mode) {
}
}
-static void a_appenditem(menu_t *pm, int isask) {
- char fname[PATHLEN];
- char buf[ANSILINELEN];
- char ans[2] = "y";
- FILE *fp, *fin;
+static void
+a_appenditem(menu_t * pm, int isask)
+{
+ char fname[PATHLEN];
+ char buf[ANSILINELEN];
+ char ans[2] = "y";
+ FILE *fp, *fin;
move(b_lines - 1, 1);
- if(copyfile[0]) {
- if(dashf(copyfile)) {
+ if (copyfile[0]) {
+ if (dashf(copyfile)) {
sprintf(fname, "%s/%s", pm->path,
- pm->header[pm->now-pm->page].filename);
- if(dashf(fname)) {
- if(isask) {
+ pm->header[pm->now - pm->page].filename);
+ if (dashf(fname)) {
+ if (isask) {
sprintf(buf, "確定要將[%s]附加於此嗎(Y/N)?[N] ",
copytitle);
getdata(b_lines - 2, 1, buf, ans, sizeof(ans), LCECHO);
}
- if(ans[0] == 'y') {
- if((fp = fopen(fname, "a+"))) {
- if((fin = fopen(copyfile, "r"))) {
+ if (ans[0] == 'y') {
+ if ((fp = fopen(fname, "a+"))) {
+ if ((fin = fopen(copyfile, "r"))) {
memset(buf, '-', 74);
buf[74] = '\0';
fprintf(fp, "\n> %s <\n\n", buf);
- if(isask)
+ if (isask)
getdata(b_lines - 1, 1,
"是否收錄簽名檔部份(Y/N)?[Y] ",
ans, sizeof(ans), LCECHO);
- while(fgets(buf, sizeof(buf), fin)) {
- if((ans[0] == 'n' ) &&
- !strcmp(buf, "--\n"))
+ while (fgets(buf, sizeof(buf), fin)) {
+ if ((ans[0] == 'n') &&
+ !strcmp(buf, "--\n"))
break;
fputs(buf, fp);
}
@@ -958,56 +999,57 @@ static void a_appenditem(menu_t *pm, int isask) {
}
}
-static int a_pastetagpost(menu_t *pm, int mode) {
- fileheader_t fhdr;
- int ans = 0, ent=0, tagnum;
- char title[TTLEN + 1]= "◇ ";
- char dirname[200],buf[200];
+static int
+a_pastetagpost(menu_t * pm, int mode)
+{
+ fileheader_t fhdr;
+ int ans = 0, ent = 0, tagnum;
+ char title[TTLEN + 1] = "◇ ";
+ char dirname[200], buf[200];
setbdir(dirname, currboard);
tagnum = TagNum;
- if (!tagnum) return ans;
-
- while (tagnum--)
- {
- EnumTagFhdr (&fhdr, dirname, ent++);
- setbfile (buf, currboard, fhdr.filename);
-
- if (dashf (buf))
- {
- strncpy(title+3, fhdr.title, TTLEN-3);
- title[TTLEN] = '\0';
- a_copyitem(buf, title, 0, 0);
- if(mode)
- {
- mode--;
- a_pasteitem(pm,0);
- }
- else a_appenditem(pm, 0);
- ++ans;
- UnTagger (tagnum);
- }
+ if (!tagnum)
+ return ans;
+ while (tagnum--) {
+ EnumTagFhdr(&fhdr, dirname, ent++);
+ setbfile(buf, currboard, fhdr.filename);
+
+ if (dashf(buf)) {
+ strncpy(title + 3, fhdr.title, TTLEN - 3);
+ title[TTLEN] = '\0';
+ a_copyitem(buf, title, 0, 0);
+ if (mode) {
+ mode--;
+ a_pasteitem(pm, 0);
+ } else
+ a_appenditem(pm, 0);
+ ++ans;
+ UnTagger(tagnum);
+ }
};
return ans;
-}
+}
-static void a_moveitem(menu_t *pm) {
- fileheader_t *tmp;
- char newnum[4];
- int num, max, min;
- char buf[PATHLEN];
- int fail;
+static void
+a_moveitem(menu_t * pm)
+{
+ fileheader_t *tmp;
+ char newnum[4];
+ int num, max, min;
+ char buf[PATHLEN];
+ int fail;
sprintf(buf, "請輸入第 %d 選項的新次序:", pm->now + 1);
- if(!getdata(b_lines - 1, 1, buf, newnum, sizeof(newnum), DOECHO))
+ if (!getdata(b_lines - 1, 1, buf, newnum, sizeof(newnum), DOECHO))
return;
num = (newnum[0] == '$') ? 9999 : atoi(newnum) - 1;
- if(num >= pm->num)
+ if (num >= pm->num)
num = pm->num - 1;
- else if(num < 0)
+ else if (num < 0)
num = 0;
setadir(buf, pm->path);
min = num < pm->now ? num : pm->now;
@@ -1015,137 +1057,146 @@ static void a_moveitem(menu_t *pm) {
tmp = (fileheader_t *) calloc(max + 1, FHSZ);
fail = 0;
- if(get_records(buf, tmp, FHSZ, 1, min) != min)
+ if (get_records(buf, tmp, FHSZ, 1, min) != min)
fail = 1;
- if(num > pm->now) {
- if(get_records(buf, &tmp[min], FHSZ, pm->now+2, max-min) != max-min)
+ if (num > pm->now) {
+ if (get_records(buf, &tmp[min], FHSZ, pm->now + 2, max - min) != max - min)
fail = 1;
- if(get_records(buf, &tmp[max], FHSZ, pm->now+1, 1) != 1)
+ if (get_records(buf, &tmp[max], FHSZ, pm->now + 1, 1) != 1)
fail = 1;
} else {
- if(get_records(buf, &tmp[min], FHSZ, pm->now+1, 1) != 1)
+ if (get_records(buf, &tmp[min], FHSZ, pm->now + 1, 1) != 1)
fail = 1;
- if(get_records(buf, &tmp[min+1], FHSZ, num+1, max-min) != max-min)
+ if (get_records(buf, &tmp[min + 1], FHSZ, num + 1, max - min) != max - min)
fail = 1;
}
- if(!fail)
+ if (!fail)
substitute_record(buf, tmp, FHSZ * (max + 1), 1);
pm->now = num;
free(tmp);
}
-static void a_delrange(menu_t *pm) {
- char fname[256];
+static void
+a_delrange(menu_t * pm)
+{
+ char fname[256];
- sprintf(fname,"%s/.DIR",pm->path);
+ sprintf(fname, "%s/.DIR", pm->path);
del_range(0, NULL, fname);
pm->num = get_num_records(fname, FHSZ);
}
-static void a_delete(menu_t *pm) {
- char fpath[PATHLEN], buf[PATHLEN], cmd[PATHLEN];
- char ans[4];
- fileheader_t backup;
+static void
+a_delete(menu_t * pm)
+{
+ char fpath[PATHLEN], buf[PATHLEN], cmd[PATHLEN];
+ char ans[4];
+ fileheader_t backup;
sprintf(fpath, "%s/%s", pm->path, pm->header[pm->now - pm->page].filename);
setadir(buf, pm->path);
-
- if(pm->header[pm->now - pm->page].filename[0] == 'H' &&
- pm->header[pm->now - pm->page].filename[1] == '.') {
+
+ if (pm->header[pm->now - pm->page].filename[0] == 'H' &&
+ pm->header[pm->now - pm->page].filename[1] == '.') {
getdata(b_lines - 1, 1, "您確定要刪除此精華區連線嗎(Y/N)?[N] ",
ans, sizeof(ans), LCECHO);
- if(ans[0] != 'y')
+ if (ans[0] != 'y')
return;
- if(delete_record(buf, FHSZ, pm->now + 1) == -1)
+ if (delete_record(buf, FHSZ, pm->now + 1) == -1)
return;
} else if (dashl(fpath)) {
getdata(b_lines - 1, 1, "您確定要刪除此 symbolic link 嗎(Y/N)?[N] ",
ans, sizeof(ans), LCECHO);
- if(ans[0] != 'y')
+ if (ans[0] != 'y')
return;
- if(delete_record(buf, FHSZ, pm->now + 1) == -1)
+ if (delete_record(buf, FHSZ, pm->now + 1) == -1)
return;
unlink(fpath);
- } else if(dashf(fpath)) {
+ } else if (dashf(fpath)) {
getdata(b_lines - 1, 1, "您確定要刪除此檔案嗎(Y/N)?[N] ", ans,
sizeof(ans), LCECHO);
- if(ans[0] != 'y')
+ if (ans[0] != 'y')
+ return;
+ if (delete_record(buf, FHSZ, pm->now + 1) == -1)
return;
- if(delete_record(buf, FHSZ, pm->now + 1) == -1)
- return;
setbpath(buf, "deleted");
stampfile(buf, &backup);
strcpy(backup.owner, cuser.userid);
- strcpy(backup.title,pm->header[pm->now - pm->page].title + 2);
+ strcpy(backup.title, pm->header[pm->now - pm->page].title + 2);
- sprintf(cmd, "mv -f %s %s", fpath,buf);
+ sprintf(cmd, "mv -f %s %s", fpath, buf);
system(cmd);
- setbdir(buf, "deleted");
- append_record(buf, &backup, sizeof(backup));
+ setbdir(buf, "deleted");
+ append_record(buf, &backup, sizeof(backup));
} else if (dashd(fpath)) {
- getdata(b_lines - 1, 1, "您確定要刪除整個目錄嗎(Y/N)?[N] ", ans,
+ getdata(b_lines - 1, 1, "您確定要刪除整個目錄嗎(Y/N)?[N] ", ans,
sizeof(ans), LCECHO);
- if(ans[0] != 'y')
+ if (ans[0] != 'y')
return;
- if(delete_record(buf, FHSZ, pm->now + 1) == -1)
+ if (delete_record(buf, FHSZ, pm->now + 1) == -1)
return;
- setapath(buf, "deleted");
- stampdir(buf, &backup);
+ setapath(buf, "deleted");
+ stampdir(buf, &backup);
- sprintf(cmd, "rm -rf %s;/bin/mv -f %s %s",buf,fpath,buf);
- system(cmd);
+ sprintf(cmd, "rm -rf %s;/bin/mv -f %s %s", buf, fpath, buf);
+ system(cmd);
- strcpy(backup.owner, cuser.userid);
- strcpy(backup.title,pm->header[pm->now - pm->page].title +2);
- setapath(buf, "deleted");
- setadir(buf,buf);
- append_record(buf, &backup, sizeof(backup));
- } else { /* Ptt 損毀的項目 */
+ strcpy(backup.owner, cuser.userid);
+ strcpy(backup.title, pm->header[pm->now - pm->page].title + 2);
+ setapath(buf, "deleted");
+ setadir(buf, buf);
+ append_record(buf, &backup, sizeof(backup));
+ } else { /* Ptt 損毀的項目 */
getdata(b_lines - 1, 1, "您確定要刪除此損毀的項目嗎(Y/N)?[N] ",
ans, sizeof(ans), LCECHO);
- if(ans[0] != 'y')
+ if (ans[0] != 'y')
return;
- if(delete_record(buf, FHSZ, pm->now + 1) == -1)
+ if (delete_record(buf, FHSZ, pm->now + 1) == -1)
return;
}
pm->num--;
}
-static void a_newtitle(menu_t *pm) {
- char buf[PATHLEN];
- fileheader_t item;
+static void
+a_newtitle(menu_t * pm)
+{
+ char buf[PATHLEN];
+ fileheader_t item;
memcpy(&item, &pm->header[pm->now - pm->page], FHSZ);
- strcpy(buf,item.title + 3);
- if(getdata_buf(b_lines - 1, 1, "新標題:", buf, 60, DOECHO)) {
+ strcpy(buf, item.title + 3);
+ if (getdata_buf(b_lines - 1, 1, "新標題:", buf, 60, DOECHO)) {
strcpy(item.title + 3, buf);
setadir(buf, pm->path);
substitute_record(buf, &item, FHSZ, pm->now + 1);
}
}
-static void a_hideitem(menu_t *pm) {
- fileheader_t *item=&pm->header[pm->now - pm->page];
- char buf[PATHLEN];
- if(item->filemode&FILE_BM)
- {
- item->filemode &= ~FILE_BM;
- item->filemode &= ~FILE_HIDE;
- }
- else if(item->filemode&FILE_HIDE)
- item->filemode |= FILE_BM;
- else item->filemode |= FILE_HIDE;
+static void
+a_hideitem(menu_t * pm)
+{
+ fileheader_t *item = &pm->header[pm->now - pm->page];
+ char buf[PATHLEN];
+ if (item->filemode & FILE_BM) {
+ item->filemode &= ~FILE_BM;
+ item->filemode &= ~FILE_HIDE;
+ } else if (item->filemode & FILE_HIDE)
+ item->filemode |= FILE_BM;
+ else
+ item->filemode |= FILE_HIDE;
setadir(buf, pm->path);
substitute_record(buf, item, FHSZ, pm->now + 1);
}
-static void a_editsign(menu_t *pm) {
- char buf[PATHLEN];
- fileheader_t item;
+static void
+a_editsign(menu_t * pm)
+{
+ char buf[PATHLEN];
+ fileheader_t item;
memcpy(&item, &pm->header[pm->now - pm->page], FHSZ);
sprintf(buf, "%c%c", item.title[0], item.title[1]);
- if(getdata_buf(b_lines - 1, 1, "符號", buf, 5, DOECHO)) {
+ if (getdata_buf(b_lines - 1, 1, "符號", buf, 5, DOECHO)) {
item.title[0] = buf[0] ? buf[0] : ' ';
item.title[1] = buf[1] ? buf[1] : ' ';
item.title[2] = buf[2] ? buf[2] : ' ';
@@ -1154,40 +1205,42 @@ static void a_editsign(menu_t *pm) {
}
}
-static void a_showname(menu_t *pm) {
- char buf[PATHLEN];
- int len;
- int i;
- int sym;
+static void
+a_showname(menu_t * pm)
+{
+ char buf[PATHLEN];
+ int len;
+ int i;
+ int sym;
move(b_lines - 1, 1);
sprintf(buf, "%s/%s", pm->path, pm->header[pm->now - pm->page].filename);
- if(dashl(buf)) {
+ if (dashl(buf)) {
prints("此 symbolic link 名稱為 %s\n",
pm->header[pm->now - pm->page].filename);
- if((len = readlink(buf, buf, PATHLEN-1)) >= 0) {
+ if ((len = readlink(buf, buf, PATHLEN - 1)) >= 0) {
buf[len] = '\0';
- for(i = 0; BBSHOME[i] && buf[i] == BBSHOME[i]; i++);
- if(!BBSHOME[i] && buf[i] == '/') {
- if(HAS_PERM(PERM_BBSADM))
+ for (i = 0; BBSHOME[i] && buf[i] == BBSHOME[i]; i++);
+ if (!BBSHOME[i] && buf[i] == '/') {
+ if (HAS_PERM(PERM_BBSADM))
sym = 1;
else {
sym = 0;
- for(i++; BBSHOME "/man"[i] && buf[i] == BBSHOME "/man"[i];
- i++);
- if(!BBSHOME "/man"[i] && buf[i] == '/')
+ for (i++; BBSHOME "/man"[i] && buf[i] == BBSHOME "/man"[i];
+ i++);
+ if (!BBSHOME "/man"[i] && buf[i] == '/')
sym = 1;
}
- if(sym) {
+ if (sym) {
pressanykey();
move(b_lines - 1, 1);
- prints("此 symbolic link 指向 %s\n", &buf[i+1]);
+ prints("此 symbolic link 指向 %s\n", &buf[i + 1]);
}
}
}
- } else if(dashf(buf))
+ } else if (dashf(buf))
prints("此文章名稱為 %s", pm->header[pm->now - pm->page].filename);
- else if(dashd(buf))
+ else if (dashd(buf))
prints("此目錄名稱為 %s", pm->header[pm->now - pm->page].filename);
else
outs("此項目已損毀, 建議將其刪除!");
@@ -1195,9 +1248,11 @@ static void a_showname(menu_t *pm) {
}
#if 0
-static char *a_title;
+static char *a_title;
-static void atitle() {
+static void
+atitle()
+{
showtitle("精華文章", a_title);
outs("[←]離開 [→]閱\讀 [^P]發表文章 [b]備忘錄 [d]刪除 [q]精華區 "
"[TAB]文摘 [h]elp\n\033[7m 編號 日 期 作 者 "
@@ -1205,81 +1260,81 @@ static void atitle() {
}
#endif
-static int isvisible_man(menu_t *me)
+static int
+isvisible_man(menu_t * me)
{
- fileheader_t *fhdr = &me->header[me->now-me->page];
- if( me->level<MANAGER && ((fhdr->filemode & FILE_BM) ||
- ((fhdr->filemode & FILE_HIDE) &&
- hbflcheck(currbid, currutmp->uid))))
- return 0;
- return 1;
+ fileheader_t *fhdr = &me->header[me->now - me->page];
+ if (me->level < MANAGER && ((fhdr->filemode & FILE_BM) ||
+ ((fhdr->filemode & FILE_HIDE) &&
+ hbflcheck(currbid, currutmp->uid))))
+ return 0;
+ return 1;
}
-int a_menu(char *maintitle, char *path, int lastlevel) {
- static char Fexit;
- menu_t me;
- char fname[PATHLEN];
- int ch, returnvalue = FULLUPDATE;
-
+int
+a_menu(char *maintitle, char *path, int lastlevel)
+{
+ static char Fexit;
+ menu_t me;
+ char fname[PATHLEN];
+ int ch, returnvalue = FULLUPDATE;
+
trans_buffer[0] = 0;
-
+
Fexit = 0;
- me.header = (fileheader_t *)calloc(p_lines, FHSZ);
+ me.header = (fileheader_t *) calloc(p_lines, FHSZ);
me.path = path;
strcpy(me.mtitle, maintitle);
setadir(fname, me.path);
me.num = get_num_records(fname, FHSZ);
-
+
/* 精華區-tree 中部份結構屬於 cuser ==> BM */
-
- if(!(me.level = lastlevel)) {
- char *ptr;
-
- if((ptr = strrchr(me.mtitle, '[')))
+
+ if (!(me.level = lastlevel)) {
+ char *ptr;
+
+ if ((ptr = strrchr(me.mtitle, '[')))
me.level = is_BM(ptr + 1);
}
-
me.page = 9999;
me.now = 0;
- for(;;) {
- if(me.now >= me.num)
+ for (;;) {
+ if (me.now >= me.num)
me.now = me.num - 1;
- if(me.now < 0)
+ if (me.now < 0)
me.now = 0;
- if(me.now < me.page || me.now >= me.page + p_lines) {
+ if (me.now < me.page || me.now >= me.page + p_lines) {
me.page = me.now - ((me.page == 10000 && me.now > p_lines / 2) ?
(p_lines / 2) : (me.now % p_lines));
a_showmenu(&me);
}
-
ch = cursor_key(2 + me.now - me.page, 0);
-
- if(ch == 'q' || ch == 'Q' || ch == KEY_LEFT)
+
+ if (ch == 'q' || ch == 'Q' || ch == KEY_LEFT)
break;
-
- if(ch >= '1' && ch <= '9') {
- if((ch = search_num(ch, me.num)) != -1)
+
+ if (ch >= '1' && ch <= '9') {
+ if ((ch = search_num(ch, me.num)) != -1)
me.now = ch;
me.page = 10000;
continue;
}
-
- switch(ch) {
+ switch (ch) {
case KEY_UP:
case 'k':
- if(--me.now < 0)
+ if (--me.now < 0)
me.now = me.num - 1;
break;
-
+
case KEY_DOWN:
case 'j':
- if(++me.now >= me.num)
+ if (++me.now >= me.num)
me.now = 0;
break;
case KEY_PGUP:
case Ctrl('B'):
- if(me.now >= p_lines)
+ if (me.now >= p_lines)
me.now -= p_lines;
else if (me.now > 0)
me.now = 0;
@@ -1290,9 +1345,9 @@ int a_menu(char *maintitle, char *path, int lastlevel) {
case ' ':
case KEY_PGDN:
case Ctrl('F'):
- if(me.now < me.num - p_lines)
+ if (me.now < me.num - p_lines)
me.now += p_lines;
- else if(me.now < me.num - 1)
+ else if (me.now < me.num - 1)
me.now = me.num - 1;
else
me.now = 0;
@@ -1307,7 +1362,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) {
me.page = 9999;
break;
case '$':
- me.now = me.num -1;
+ me.now = me.num - 1;
break;
case 'h':
a_showhelp(me.level);
@@ -1330,98 +1385,100 @@ int a_menu(char *maintitle, char *path, int lastlevel) {
case 'e':
case 'E':
- sprintf(fname, "%s/%s", path, me.header[me.now-me.page].filename);
- if(dashf(fname) && me.level >= MANAGER) {
+ sprintf(fname, "%s/%s", path, me.header[me.now - me.page].filename);
+ if (dashf(fname) && me.level >= MANAGER) {
*quote_file = 0;
- if(vedit(fname, NA, NULL) != -1) {
- char fpath[200];
- fileheader_t fhdr;
+ if (vedit(fname, NA, NULL) != -1) {
+ char fpath[200];
+ fileheader_t fhdr;
strcpy(fpath, path);
stampfile(fpath, &fhdr);
unlink(fpath);
Rename(fname, fpath);
- strcpy(me.header[me.now-me.page].filename, fhdr.filename);
- strcpy(me.header[me.now-me.page].owner, cuser.userid);
+ strcpy(me.header[me.now - me.page].filename, fhdr.filename);
+ strcpy(me.header[me.now - me.page].owner, cuser.userid);
setadir(fpath, path);
- substitute_record(fpath, me.header+me.now-me.page,
- sizeof(fhdr), me.now + 1);
+ substitute_record(fpath, me.header + me.now - me.page,
+ sizeof(fhdr), me.now + 1);
}
me.page = 9999;
}
break;
case 'c':
- if(me.now < me.num) {
- if(!isvisible_man(&me)) break;
+ if (me.now < me.num) {
+ if (!isvisible_man(&me))
+ break;
sprintf(fname, "%s/%s", path,
- me.header[me.now-me.page].filename);
- a_copyitem(fname, me.header[me.now-me.page].title, 0, 1);
+ me.header[me.now - me.page].filename);
+ a_copyitem(fname, me.header[me.now - me.page].title, 0, 1);
me.page = 9999;
break;
}
-
case '\n':
case '\r':
case KEY_RIGHT:
case 'r':
- if(me.now < me.num) {
- fileheader_t *fhdr = &me.header[me.now-me.page];
- if(!isvisible_man(&me)) break;
+ if (me.now < me.num) {
+ fileheader_t *fhdr = &me.header[me.now - me.page];
+ if (!isvisible_man(&me))
+ break;
sprintf(fname, "%s/%s", path, fhdr->filename);
- if(*fhdr->filename == 'H' && fhdr->filename[1] == '.') {
- item_t item;
+ if (*fhdr->filename == 'H' && fhdr->filename[1] == '.') {
+ item_t item;
strcpy(item.X.G.server, fhdr->filename + 2);
strcpy(item.X.G.path, "1/");
item.X.G.port = 70;
gem(fhdr->title, &item, (ch == 'R') ? 1 : 0);
} else if (dashf(fname)) {
- int more_result;
+ int more_result;
- while((more_result = more(fname, YEA))) {
+ while ((more_result = more(fname, YEA))) {
/* Ptt 範本精靈 plugin */
- if(currstat == EDITEXP || currstat == OSONG) {
- char ans[4];
+ if (currstat == EDITEXP || currstat == OSONG) {
+ char ans[4];
move(22, 0);
clrtoeol();
- getdata(22, 1,
- currstat == EDITEXP ?
- "要把範例 Plugin 到文章嗎?[y/N]":
+ getdata(22, 1,
+ currstat == EDITEXP ?
+ "要把範例 Plugin 到文章嗎?[y/N]" :
"確定要點這首歌嗎?[y/N]",
ans, sizeof(ans), LCECHO);
- if(ans[0]=='y') {
- strcpy(trans_buffer,fname);
+ if (ans[0] == 'y') {
+ strcpy(trans_buffer, fname);
Fexit = 1;
- if(currstat == OSONG){
- log_file(FN_USSONG,fhdr->title);
+ if (currstat == OSONG) {
+ log_file(FN_USSONG, fhdr->title);
}
free(me.header);
return FULLUPDATE;
}
}
- if(more_result == 1) {
- if(--me.now < 0) {
+ if (more_result == 1) {
+ if (--me.now < 0) {
me.now = 0;
break;
}
- } else if(more_result == 3) {
- if(++me.now >= me.num) {
+ } else if (more_result == 3) {
+ if (++me.now >= me.num) {
me.now = me.num - 1;
break;
}
} else
break;
- if(!isvisible_man(&me)) break;
+ if (!isvisible_man(&me))
+ break;
sprintf(fname, "%s/%s", path,
- me.header[me.now-me.page].filename);
- if(!dashf(fname))
+ me.header[me.now - me.page].filename);
+ if (!dashf(fname))
break;
}
- } else if(dashd(fname)) {
- a_menu(me.header[me.now-me.page].title, fname, me.level);
+ } else if (dashd(fname)) {
+ a_menu(me.header[me.now - me.page].title, fname, me.level);
/* Ptt 強力跳出recursive */
- if(Fexit) {
+ if (Fexit) {
free(me.header);
return FULLUPDATE;
}
@@ -1432,10 +1489,10 @@ int a_menu(char *maintitle, char *path, int lastlevel) {
case 'F':
case 'U':
- sprintf(fname, "%s/%s", path, me.header[me.now-me.page].filename);
- if(me.now < me.num && HAS_PERM(PERM_BASIC) && dashf(fname)) {
- a_forward(path, &me.header[me.now-me.page], ch /*== 'U'*/);
- /*By CharlieL*/
+ sprintf(fname, "%s/%s", path, me.header[me.now - me.page].filename);
+ if (me.now < me.num && HAS_PERM(PERM_BASIC) && dashf(fname)) {
+ a_forward(path, &me.header[me.now - me.page], ch /* == 'U' */ );
+ /* By CharlieL */
} else
outmsg("無法轉寄此項目");
@@ -1445,10 +1502,10 @@ int a_menu(char *maintitle, char *path, int lastlevel) {
break;
}
- if(me.level >= MANAGER) {
- int page0 = me.page;
+ if (me.level >= MANAGER) {
+ int page0 = me.page;
- switch(ch) {
+ switch (ch) {
case 'n':
a_newitem(&me, ADDITEM);
me.page = 9999;
@@ -1462,7 +1519,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) {
me.page = 9999;
break;
case 'p':
- a_pasteitem(&me,1);
+ a_pasteitem(&me, 1);
me.page = 9999;
break;
case 'f':
@@ -1471,7 +1528,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) {
break;
case Ctrl('P'):
a_pastetagpost(&me, -1);
- returnvalue = DIRCHANGED;
+ returnvalue = DIRCHANGED;
me.page = 9999;
break;
case Ctrl('A'):
@@ -1487,16 +1544,16 @@ int a_menu(char *maintitle, char *path, int lastlevel) {
me.page = page0;
break;
}
-
- if(me.num)
- switch(ch) {
+
+ if (me.num)
+ switch (ch) {
case 'm':
a_moveitem(&me);
me.page = 9999;
break;
case 'D':
- /* Ptt me.page = -1;*/
+ /* Ptt me.page = -1; */
a_delrange(&me);
me.page = 9999;
break;
@@ -1504,7 +1561,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) {
a_delete(&me);
me.page = 9999;
break;
- case 'H':
+ case 'H':
a_hideitem(&me);
me.page = 9999;
break;
@@ -1514,9 +1571,8 @@ int a_menu(char *maintitle, char *path, int lastlevel) {
break;
}
}
-
- if(me.level == SYSOP) {
- switch(ch) {
+ if (me.level == SYSOP) {
+ switch (ch) {
case 'l':
a_newitem(&me, ADDLINK);
me.page = 9999;
@@ -1532,9 +1588,11 @@ int a_menu(char *maintitle, char *path, int lastlevel) {
return returnvalue;
}
-static char *mytitle = BBSNAME "佈告欄";
+static char *mytitle = BBSNAME "佈告欄";
-int Announce() {
+int
+Announce()
+{
setutmpmode(ANNOUNCE);
a_menu(mytitle, "man",
((HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_ANNOUNCE)) ? SYSOP :