summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2014-03-31 22:15:02 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2014-03-31 22:15:02 +0800
commitb40071dc32d8f681bb745a9062f4ca4f030dad4f (patch)
treedd3a9af0bbcc207f603ea3a93f10d8a1b32660b1
parente01078caf052436873eb93fc122984ac169433b1 (diff)
downloadpttbbs-b40071dc32d8f681bb745a9062f4ca4f030dad4f.tar
pttbbs-b40071dc32d8f681bb745a9062f4ca4f030dad4f.tar.gz
pttbbs-b40071dc32d8f681bb745a9062f4ca4f030dad4f.tar.bz2
pttbbs-b40071dc32d8f681bb745a9062f4ca4f030dad4f.tar.lz
pttbbs-b40071dc32d8f681bb745a9062f4ca4f030dad4f.tar.xz
pttbbs-b40071dc32d8f681bb745a9062f4ca4f030dad4f.tar.zst
pttbbs-b40071dc32d8f681bb745a9062f4ca4f030dad4f.zip
Remove calendar.
After 10 month we're ready to go. git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5981 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/include/config.h2
-rw-r--r--pttbbs/include/proto.h9
-rw-r--r--pttbbs/mbbsd/Makefile2
-rw-r--r--pttbbs/mbbsd/calendar.c349
-rw-r--r--pttbbs/mbbsd/mbbsd.c6
-rw-r--r--pttbbs/mbbsd/stuff.c62
-rw-r--r--pttbbs/mbbsd/user.c10
-rw-r--r--pttbbs/mbbsd/var.c1
8 files changed, 67 insertions, 374 deletions
diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h
index 8bcfa22c..60768882 100644
--- a/pttbbs/include/config.h
+++ b/pttbbs/include/config.h
@@ -385,7 +385,7 @@
#endif
#ifndef NUMVIEWFILE
-#define NUMVIEWFILE (15) /* 進站畫面最多數 */
+#define NUMVIEWFILE (14) /* 進站畫面最多數 */
#endif
#ifndef LOGINATTEMPTS
diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h
index 0ac0464a..1a45dbe2 100644
--- a/pttbbs/include/proto.h
+++ b/pttbbs/include/proto.h
@@ -634,6 +634,9 @@ unsigned DBCS_StringHash(const char *s);
int getdata(int line, int col, const char *prompt, char *buf, int len, int echo);
int getdata_str(int line, int col, const char *prompt, char *buf, int len, int echo, const char *defaultstr);
int getdata_buf(int line, int col, const char *prompt, char *buf, int len, int echo);
+int ParseDate(const char *date, int *year, int *month, int *day);
+int ParseDateTime(const char *date, int *year, int *month, int *day,
+ int *hour, int *min, int *sec);
#ifndef CRITICAL_MEMORY
#define MALLOC(p) malloc(p)
@@ -829,12 +832,6 @@ void pwcuInitGuestPerm (void);
void pwcuInitGuestInfo (void);
int pwcuInitAdminPerm (void);
-/* calendar */
-int calendar(void);
-int ParseDate(const char *date, int *year, int *month, int *day);
-int ParseDateTime(const char *date, int *year, int *month, int *day,
- int *hour, int *min, int *sec);
-
int verify_captcha(const char *reason);
#endif
diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile
index d7074298..8838a563 100644
--- a/pttbbs/mbbsd/Makefile
+++ b/pttbbs/mbbsd/Makefile
@@ -16,7 +16,7 @@ TALKOBJS = friend.o talk.o ccw.o
UTILOBJS = stuff.o kaede.o convert.o name.o syspost.o cache.o cal.o
UIOBJS = menu.o vtuikit.o psb.o
PAGEROBJS= more.o pmore.o
-PLUGOBJS = calendar.o ordersong.o angel.o timecap.o
+PLUGOBJS = ordersong.o angel.o timecap.o
CHESSOBJS= chess.o chc.o chc_tab.o ch_go.o ch_gomo.o ch_dark.o ch_reversi.o
GAMEOBJS = chicken.o gamble.o
OBJS:= admin.o assess.o edit.o xyz.o var.o vote.o voteboard.o \
diff --git a/pttbbs/mbbsd/calendar.c b/pttbbs/mbbsd/calendar.c
deleted file mode 100644
index 340ae76f..00000000
--- a/pttbbs/mbbsd/calendar.c
+++ /dev/null
@@ -1,349 +0,0 @@
-/* $Id$ */
-#include "bbs.h"
-
-// TODO deprecate this file.
-
-typedef struct event_t {
- int year, month, day, days;
- int color;
- char *content;
- struct event_t *next;
-} event_t;
-
-static int
-MonthDay(int m, int leap)
-{
- int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-
- assert(1<=m && m<=12);
- return leap && m == 2 ? 29 : day[m - 1];
-}
-
-static int
-Days(int y, int m, int d)
-{
- int i, w;
-
- w = 1 + 365 * (y - 1)
- + ((y - 1) / 4) - ((y - 1) / 100) + ((y - 1) / 400)
- + d - 1;
- for (i = 1; i < m; i++)
- w += MonthDay(i, is_leap_year(y));
- return w;
-}
-
-/**
- * return 1 if date and time is invalid
- */
-int ParseDateTime(const char *date, int *year, int *month, int *day,
- int *hour, int *min, int *sec)
-{
- char *y, *m, *d, *hh, *mm, *ss;
- char buf[128];
- char *strtok_pos;
-
- strlcpy(buf, date, sizeof(buf));
- y = strtok_r(buf, "/", &strtok_pos); if (!y) return 1;
- m = strtok_r(NULL, "/", &strtok_pos);if (!m) return 1;
- d = strtok_r(NULL, " ", &strtok_pos); if (!d) return 1;
-
- if (hour) {
- hh = strtok_r(NULL, ":", &strtok_pos);
- if (!hh) return 1;
- *hour = atoi(hh);
- }
- if (min ) {
- mm = strtok_r(NULL, ":", &strtok_pos);
- if (!mm) return 1;
- *min = atoi(mm);
- }
- if (sec ) {
- ss = strtok_r(NULL, "", &strtok_pos);
- if (!ss) return 1;
- *sec = atoi(ss);
- }
-
- *year = atoi(y);
- *month = atoi(m);
- *day = atoi(d);
-
- if (hour && (*hour < 0 || *hour > 23)) return 1;
- if (min && (*min < 0 || *min > 59)) return 1;
- if (sec && (*sec < 0 || *sec > 59)) return 1;
-
- if (*year < 1 || *month < 1 || *month > 12 ||
- *day < 1 || *day > MonthDay(*month, is_leap_year(*year)))
- return 1;
- return 0;
-}
-
-/**
- * return 1 if date is invalid
- */
-int ParseDate(const char *date, int *year, int *month, int *day)
-{
- return ParseDateTime(date, year, month, day, NULL, NULL, NULL);
-}
-
-/**
- * return 1 if date is invalid
- */
-static int
-ParseEventDate(const char *date, event_t * t)
-{
- int retval = ParseDate(date, &t->year, &t->month, &t->day);
- if (retval)
- return retval;
- t->days = Days(t->year, t->month, t->day);
- return retval;
-}
-
-static int
-ParseColor(const char *color)
-{
- struct {
- char *str;
- int val;
- } c[] = {
- { "black", 0 },
- { "red", 1 },
- { "green", 2 },
- { "yellow", 3 },
- { "blue", 4 },
- { "magenta", 5 },
- { "cyan", 6 },
- { "white", 7 }
- };
- int i;
-
- for (i = 0; (unsigned)i < sizeof(c) / sizeof(c[0]); i++)
- if (strcasecmp(color, c[i].str) == 0)
- return c[i].val;
- return 7;
-}
-
-static void
-InsertEvent(event_t * head, event_t * t)
-{
- event_t *p;
-
- for (p = head; p->next && p->next->days < t->days; p = p->next);
- t->next = p->next;
- p->next = t;
-}
-
-static void
-FreeEvent(event_t * e)
-{
- event_t *n;
-
- while (e) {
- n = e->next;
- free(e->content); /* from strdup() */
- free(e);
- e = n;
- }
-}
-
-static event_t *
-ReadEvent(int today)
-{
- FILE *fp;
- char buf[PATHLEN];
- event_t head;
-
- head.next = NULL;
- sethomefile(buf, cuser.userid, "calendar");
- fp = fopen(buf, "r");
- if (fp) {
- while (fgets(buf, sizeof(buf), fp)) {
- char *date, *color, *content;
- event_t *t;
- char *strtok_pos;
-
- if (buf[0] == '#')
- continue;
-
- date = strtok_r(buf, " \t\n", &strtok_pos);
- color = strtok_r(NULL, " \t\n", &strtok_pos);
- content = strtok_r(NULL, "\n", &strtok_pos);
- if (!date || !color || !content)
- continue;
-
- t = malloc(sizeof(event_t));
- if (ParseEventDate(date, t) || t->days < today) {
- free(t);
- continue;
- }
- t->color = ParseColor(color) + 30;
- for (; *content == ' ' || *content == '\t'; content++);
- t->content = strdup(content);
- InsertEvent(&head, t);
- }
- fclose(fp);
- }
- return head.next;
-}
-
-static char **
-AllocCalBuffer(int line, int len)
-{
- int i;
- char **p;
-
- p = malloc(sizeof(char *) * line);
- p[0] = malloc(sizeof(char) * line * len);
- for (i = 1; i < line; i++)
- p[i] = p[i - 1] + len;
- return p;
-}
-
-static void
-FreeCalBuffer(char **buf)
-{
- free(buf[0]);
- free(buf);
-}
-
-#define CALENDAR_COLOR ANSI_COLOR(0;30;47)
-#define HEADER_COLOR ANSI_COLOR(1;44)
-#define HEADER_SUNDAY_COLOR ANSI_COLOR(31)
-#define HEADER_DAY_COLOR ANSI_COLOR(33)
-
-static int
-GenerateCalendar(char **buf, int y, int m, int today, event_t * e)
-{
- char *week_str[7] = {"日", "一", "二", "三", "四", "五", "六"};
- char *month_color[12] = {
- ANSI_COLOR(1;32), ANSI_COLOR(1;33), ANSI_COLOR(1;35), ANSI_COLOR(1;36),
- ANSI_COLOR(1;32), ANSI_COLOR(1;33), ANSI_COLOR(1;35), ANSI_COLOR(1;36),
- ANSI_COLOR(1;32), ANSI_COLOR(1;33), ANSI_COLOR(1;35), ANSI_COLOR(1;36)
- };
- char *month_str[12] = {
- "一月 ", "二月 ", "三月 ", "四月 ", "五月 ", "六月 ",
- "七月 ", "八月 ", "九月 ", "十月 ", "十一月", "十二月"
- };
-
- char *p, attr1[16], *attr2;
- int i, d, w, line = 0, first_day = Days(y, m, 1);
-
-
- /* week day banner */
- p = buf[line];
- p += sprintf(p, " %s%s%s%s", HEADER_COLOR, HEADER_SUNDAY_COLOR,
- week_str[0], HEADER_DAY_COLOR);
- for (i = 1; i < 7; i++)
- p += sprintf(p, " %s", week_str[i]);
- p += sprintf(p, ANSI_RESET);
-
- /* indent for first line */
- p = buf[++line];
- p += sprintf(p, " %s", CALENDAR_COLOR);
- for (i = 0, w = first_day % 7; i < w; i++)
- p += sprintf(p, " ");
-
- /* initial event */
- for (; e && e->days < first_day; e = e->next);
-
- d = MonthDay(m, is_leap_year(y));
- for (i = 1; i <= d; i++, w = (w + 1) % 7) {
- attr1[0] = 0;
- attr2 = "";
- while (e && e->days == first_day + i - 1) {
- sprintf(attr1, ANSI_COLOR(1;%d), e->color);
- attr2 = CALENDAR_COLOR;
- e = e->next;
- }
- if (today == first_day + i - 1) {
- strlcpy(attr1, ANSI_COLOR(1;37;42), sizeof(attr1));
- attr2 = CALENDAR_COLOR;
- }
- p += sprintf(p, "%s%2d%s", attr1, i, attr2);
-
- if (w == 6) {
- p += sprintf(p, ANSI_RESET);
- p = buf[++line];
- /* show month */
- if (line >= 2 && line <= 4)
- p += sprintf(p, "%s%2.2s\33[m %s", month_color[m - 1],
- month_str[m - 1] + (line - 2) * 2,
- CALENDAR_COLOR);
- else if (i < d)
- p += sprintf(p, " %s", CALENDAR_COLOR);
- } else
- *p++ = ' ';
- }
-
- /* fill up the last line */
- if (w) {
- for (w = 7 - w; w; w--)
- p += sprintf(p, w == 1 ? " " : " ");
- p += sprintf(p, ANSI_RESET);
- }
- return line + 1;
-}
-
-int
-calendar(void)
-{
- char **buf;
- struct tm snow;
- int i, y, m, today, lines = 0;
- event_t *head = NULL, *e = NULL;
-
- /* initialize date */
- localtime4_r(&now, &snow);
- today = Days(snow.tm_year + 1900, snow.tm_mon + 1, snow.tm_mday);
- y = snow.tm_year + 1900, m = snow.tm_mon + 1;
-
- /* read event */
- head = e = ReadEvent(today);
-
- /* generate calendar */
- buf = AllocCalBuffer(22, 256);
- for (i = 0; i < 22; i++)
- sprintf(buf[i], "%24s", "");
- for (i = 0; i < 3; i++) {
- lines += GenerateCalendar(buf + lines, y, m, today, e) + 1;
- if (m == 12)
- y++, m = 1;
- else
- m++;
- }
-
- /* output */
- clear();
- outc('\n');
- for (i = 0; i < 22; i++) {
- outs(buf[i]);
- if (i == 0) {
- prints("\t" ANSI_COLOR(1;37)
- "現在是 %d.%02d.%02d %2d:%02d:%02d%cm" ANSI_RESET,
- snow.tm_year + 1900, snow.tm_mon + 1, snow.tm_mday,
- (snow.tm_hour == 0 || snow.tm_hour == 12) ?
- 12 : snow.tm_hour % 12, snow.tm_min, snow.tm_sec,
- snow.tm_hour >= 12 ? 'p' : 'a');
- } else if (i >= 2 && e) {
- prints("\t" ANSI_COLOR(1;37)
- "(尚有 " ANSI_COLOR(%d) "%3d"
- ANSI_COLOR(37) " 天)"
- ANSI_RESET " %02d/%02d %s",
- e->color, e->days - today,
- e->month, e->day, e->content);
- e = e->next;
- }
- outc('\n');
- }
- FreeEvent(head);
- FreeCalBuffer(buf);
- i = vmsg("行事曆將於2013/06後擇期取消。要檢視現有行事曆請按 e。");
- i = tolower(((unsigned char)i) & 0xFF);
- if (i == 'e')
- {
- char fpath[PATHLEN];
- setuserfile(fpath, "calendar");
- more(fpath, YEA);
- }
- return 0;
-}
-
diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c
index 1c26aec3..e48cf0e0 100644
--- a/pttbbs/mbbsd/mbbsd.c
+++ b/pttbbs/mbbsd/mbbsd.c
@@ -1291,12 +1291,6 @@ user_login(void)
// simply ignore it.
break;
- case '@':
- // since only one special now, let's write directly...
- if (strcmp(fn, "@calendar") == 0)
- calendar();
- break;
-
default:
// use NA+pause or YEA?
more(fn, YEA);
diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c
index a0bbf412..e5529e80 100644
--- a/pttbbs/mbbsd/stuff.c
+++ b/pttbbs/mbbsd/stuff.c
@@ -452,6 +452,68 @@ DBCS_StringHash(const char *s)
return fnv1a_32_dbcs_strcase(s, FNV1_32_INIT);
}
+static int
+MonthDay(int m, int leap)
+{
+ int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+
+ assert(1<=m && m<=12);
+ return leap && m == 2 ? 29 : day[m - 1];
+}
+
+/**
+ * return 1 if date and time is invalid
+ */
+int ParseDateTime(const char *date, int *year, int *month, int *day,
+ int *hour, int *min, int *sec)
+{
+ char *y, *m, *d, *hh, *mm, *ss;
+ char buf[128];
+ char *strtok_pos;
+
+ strlcpy(buf, date, sizeof(buf));
+ y = strtok_r(buf, "/", &strtok_pos); if (!y) return 1;
+ m = strtok_r(NULL, "/", &strtok_pos);if (!m) return 1;
+ d = strtok_r(NULL, " ", &strtok_pos); if (!d) return 1;
+
+ if (hour) {
+ hh = strtok_r(NULL, ":", &strtok_pos);
+ if (!hh) return 1;
+ *hour = atoi(hh);
+ }
+ if (min ) {
+ mm = strtok_r(NULL, ":", &strtok_pos);
+ if (!mm) return 1;
+ *min = atoi(mm);
+ }
+ if (sec ) {
+ ss = strtok_r(NULL, "", &strtok_pos);
+ if (!ss) return 1;
+ *sec = atoi(ss);
+ }
+
+ *year = atoi(y);
+ *month = atoi(m);
+ *day = atoi(d);
+
+ if (hour && (*hour < 0 || *hour > 23)) return 1;
+ if (min && (*min < 0 || *min > 59)) return 1;
+ if (sec && (*sec < 0 || *sec > 59)) return 1;
+
+ if (*year < 1 || *month < 1 || *month > 12 ||
+ *day < 1 || *day > MonthDay(*month, is_leap_year(*year)))
+ return 1;
+ return 0;
+}
+
+/**
+ * return 1 if date is invalid
+ */
+int ParseDate(const char *date, int *year, int *month, int *day)
+{
+ return ParseDateTime(date, year, month, day, NULL, NULL, NULL);
+}
+
/* AIDS */
aidu_t fn2aidu(char *fn)
{
diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c
index ae986a9c..ef0e346f 100644
--- a/pttbbs/mbbsd/user.c
+++ b/pttbbs/mbbsd/user.c
@@ -53,7 +53,6 @@ u_loginview(void)
{
int i, in;
unsigned int pbits = cuser.loginview;
- int ical = -1, has_cal = 0;
do {
vs_hdr("設定進站畫面");
@@ -62,18 +61,9 @@ u_loginview(void)
// ignore those without file name
if (!*loginview_file[i][0])
continue;
- if (strcasecmp(loginview_file[i][0], "@calendar") == 0) {
- ical = i;
- has_cal = pbits & (1 << ical);
- if (!has_cal)
- continue;
- }
prints(" %c. %-20s %-15s \n", 'A' + i,
loginview_file[i][1], ((pbits >> i) & 1 ? "ˇ" : "X"));
}
- // XXX calendar must be last item.
- if (i == ical + 1 && !has_cal)
- i--;
in = i; // max i
i = vmsgf("請按 [A-%c] 切換設定,按 [Return] 結束:", 'A'+in-1);
diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c
index 13a07471..ae7a8e76 100644
--- a/pttbbs/mbbsd/var.c
+++ b/pttbbs/mbbsd/var.c
@@ -179,7 +179,6 @@ char * const loginview_file[NUMVIEWFILE][2] = {
{"etc/history", "歷史上的今天"},
{"etc/topboardman", "精華區排行榜"},
{"etc/topboard.tmp", "看板人氣排行榜"},
- {"@calendar", "個人行事曆"},
{NULL, NULL}
};