diff options
author | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-02-11 14:03:31 +0800 |
---|---|---|
committer | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-02-11 14:03:31 +0800 |
commit | 88d56fb4ea83fc56a9799eb5134006b07589b5b6 (patch) | |
tree | e3177c53d51a04349f3630defd033ec4a44bf590 | |
parent | 21ff1ecf3d29680e3d26113eb7caf9f55f0ba5db (diff) | |
download | pttbbs-88d56fb4ea83fc56a9799eb5134006b07589b5b6.tar pttbbs-88d56fb4ea83fc56a9799eb5134006b07589b5b6.tar.gz pttbbs-88d56fb4ea83fc56a9799eb5134006b07589b5b6.tar.bz2 pttbbs-88d56fb4ea83fc56a9799eb5134006b07589b5b6.tar.lz pttbbs-88d56fb4ea83fc56a9799eb5134006b07589b5b6.tar.xz pttbbs-88d56fb4ea83fc56a9799eb5134006b07589b5b6.tar.zst pttbbs-88d56fb4ea83fc56a9799eb5134006b07589b5b6.zip |
train
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@654 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | mbbsd/page.c | 180 | ||||
-rw-r--r-- | util/Makefile | 4 | ||||
-rwxr-xr-x | util/railway_wrapper.pl | 119 |
3 files changed, 229 insertions, 74 deletions
diff --git a/mbbsd/page.c b/mbbsd/page.c index 9c01eb6d..e1bcd052 100644 --- a/mbbsd/page.c +++ b/mbbsd/page.c @@ -1,27 +1,26 @@ -/* $Id: page.c,v 1.10 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id: page.c,v 1.11 2003/02/11 06:03:31 victor Exp $ */ #include "bbs.h" #define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} -static void -filt_railway(char *fpath) -{ - char buf[256], tmppath[32]; - FILE *fp = fopen(fpath, "w"), *tp; +#define TITLE "\033[1;37;45m 火車查詢系統 \033[1;44;33m原作者:Heat\033[m" - snprintf(tmppath, sizeof(tmppath), "%s.railway", fpath); - if (!fp || !(tp = fopen(tmppath, "r"))) // XXX fclose(fp) if tp fail - return; +void +print_station(const char *addr[6][100], int path, int *line, int *num) +{ + int i; + char genbuf[128]; - while (fgets(buf, 255, tp)) { - if (strstr(buf, "INLINE")) - continue; - if (strstr(buf, "LINK")) - break; - fprintf(fp, "%s", buf); - } - fclose(fp); - fclose(tp); - unlink(tmppath); + *num = 0; + move(*line,0); + do{ + for(i=0; i<7 && addr[path - 1][*num]!=NULL; i++){ + sprintf(genbuf, " %2d.%-6s", (*num)+1, addr[path - 1][*num]); + (*num)++; + outs(genbuf); + } + outs("\n"); + (*line)++; + }while(i==7); } int @@ -29,94 +28,131 @@ main_railway() { fileheader_t mhdr; char genbuf[200]; - int from, to, time_go, time_reach; + int from, to, time_go, time_reach, date, path; + int line, station_num; char tt[2], type[2]; char command[256], buf[8]; - char *addr[] = { - "基隆", "八堵", "七堵", "五堵", "汐止", "南港", "松山", "台北", "萬華", - "板橋", "樹林", "山佳", "鶯歌", "桃園", "內壢", "中壢", "埔心", "楊梅", - "湖口", "新豐", "竹北", "新竹", "香山", "崎頂", "竹南", "造橋", "豐富", - "談文", "大山", "後龍", "龍港", "白沙屯", "新埔", "通霄", "苑裡", - "日南", "大甲", "臺中港", "清水", "沙鹿", "龍井", "大肚", "追分", - "苗栗", "南勢", "銅鑼", "三義", "勝興", "泰安", "后里", "豐原", "潭子", - "台中", "烏日", "成功\", "彰化", "花壇", "員林", "永靖", "社頭", - "田中", "二水", "林內", "石榴", "斗六", "斗南", "石龜", "大林", - "民雄", "嘉義", "水上", "南靖", "後壁", "新營", "柳營", "林鳳營", - "隆田", "拔林", "善化", "新市", "永康", "台南", "保安", "中洲", - "大湖", "路竹", "岡山", "橋頭", "楠梓", "左營", "高雄", "鳳山", - "九曲堂", "屏東", NULL, NULL - }; + static const char *addr[6][100] = { + { + "基隆", "八堵", "七堵", "五堵", "汐止", "南港", "松山", "台北", "萬華", + "板橋", "樹林", "山佳", "鶯歌", "桃園", "內壢", "中壢", "埔心", "楊梅", + "湖口", "新豐", "竹北", "新竹", "香山", "崎頂", "竹南", "造橋", "豐富", + "談文", "大山", "後龍", "龍港", "白沙屯", "新埔", "通霄", "苑裡", + "日南", "大甲", "臺中港", "清水", "沙鹿", "龍井", "大肚", "追分", + "苗栗", "南勢", "銅鑼", "三義", "勝興", "泰安", "后里", "豐原", "潭子", + "台中", "烏日", "成功\", "彰化", "花壇", "員林", "永靖", "社頭", + "田中", "二水", "林內", "石榴", "斗六", "斗南", "石龜", "大林", + "民雄", "嘉義", "水上", "南靖", "後壁", "新營", "柳營", "林鳳營", + "隆田", "拔林", "善化", "新市", "永康", "台南", "保安", "中洲", + "大湖", "路竹", "岡山", "橋頭", "楠梓", "左營", "高雄", "鳳山", + "九曲堂", "屏東", NULL + }, + { + "樹林", "板橋", "萬華", "台北", "松山", "南港", "汐止", "基隆", "八堵", + "暖暖", "四腳亭", "瑞芳", "侯硐", "三貂嶺", "牡丹", "雙溪", "貢寮", + "福隆", "石城", "大里", "大溪", "龜山", "外澳", "頭城", "頂埔", "礁溪", + "四城", "宜蘭", "二結", "中里", "羅東", "冬山", "新馬", "蘇澳新站", + "蘇澳", "永樂", "東澳", "南澳", "武塔", "漢本", "和平", "和仁", "崇德", + "新城", "景美", "北埔", "花蓮", "吉安", "志學", "平和", "壽豐", "豐田", + "溪口", "南平", "鳳林", "萬榮", "光復", "大富", "富源", "瑞北", "瑞穗", + "三民", "玉里", "安通", "東里", "東竹", "富里", "池上", "海瑞", "關山", + "月美", "瑞和", "瑞源", "鹿野", "山里", "台東", NULL + }, + { + "高雄", "鳳山", "後庄", "九曲堂", "六塊厝", "屏東", "歸來", "麟洛", + "西勢", "竹田", "潮州", "崁頂", "南州", "鎮安", "林邊", "佳冬", "東海", + "枋寮", "加祿", "內獅", "枋山", "古莊", "大武", "瀧溪", "多良", "金崙", + "太麻里", "知本", "康樂", "台東", NULL + }, + { + "八堵", "暖暖", "四腳亭", "瑞芳", "侯硐", "三貂嶺", "大華", "十分", + "望古", "嶺腳", "平溪", "菁桐", NULL + }, + { + "新竹", "竹中", "上員", "榮華", "竹東", "橫山", "九讚頭", "合興", "南河", + "內灣", NULL + }, + { + "台中", "烏日", "成功\", "彰化", "花壇", "員林", "永靖", "社頭", "田中", + "二水", "源泉", "濁水", "龍泉", "集集", "水里", "車埕", NULL + } + }; setutmpmode(RAIL_WAY); clear(); move(0, 25); - prints("\033[1;37;45m 火車查詢系統 \033[1;44;33m作者:Heat\033[m"); + prints(TITLE); move(1, 0); - outs("\033[1;33m\n" - " 1.基隆 16.中壢 31.龍港 46.銅鑼 61.田中 76.林鳳營 91.高雄\n" - " 2.八堵 17.埔心 32.白沙屯 47.三義 62.二水 77.隆田 92.鳳山\n" - " 3.七堵 18.楊梅 33.新埔 48.勝興 63.林內 78.拔林 93.九曲堂\n" - " 4.五堵 19.湖口 34.通霄 49.泰安 64.石榴 79.善化 94.屏東\n" - " 5.汐止 20.新豐 35.苑裡 50.后里 65.斗六 80.新市\n" - " 6.南港 21.竹北 36.日南 51.豐原 66.斗南 81.永康\n" - " 7.松山 22.新竹 37.大甲 52.潭子 67.石龜 82.台南\n" - " 8.台北 23.香山 38.臺中港 53.台中 68.大林 83.保安\n" - " 9.萬華 24.崎頂 39.清水 54.烏日 69.民雄 84.中洲\n" - "10.板橋 25.竹南 40.沙鹿 55.成功\ 70.嘉義 85.大湖\n" - "11.樹林 26.造橋 41.龍井 56.彰化 71.水上 86.路竹\n" - "12.山佳 27.豐富 42.大肚 57.花壇 72.南靖 87.岡山\n" - "13.鶯歌 28.談文 43.追分 58.員林 73.後壁 88.橋頭\n" - "14.桃園 29.大山 44.苗栗 59.永靖 74.新營 89.楠梓\n" - "15.內壢 30.後龍 45.南勢 60.社頭 75.柳營 90.左營\033[m"); - getdata(17, 0, "\033[1;35m你確定要搜尋嗎?[y/n]:\033[m", buf, 2, LCECHO); + getdata(3, 0, "\033[1;35m你確定要搜尋嗎?[y/n]:\033[m", buf, 2, LCECHO); if (buf[0] != 'y' && buf[0] != 'Y') return 0; + outs("\033[1;33m1.西部幹線(含台中線) 2.東部幹線(含北迴線)\n"); + outs("\033[1;33m3.南迴線 4.平溪線 5.內灣線 6.集集線\n"); while (1) - if (getdata(18, 0, "\033[1;35m請輸入起站(1-94):\033[m", buf, 3, LCECHO) && - (from = atoi(buf)) >= 1 && from <= 94) + if (getdata(7, 0, "\033[1;35m請選擇路線(1-6):\033[m", buf, 2, LCECHO) && + (path = atoi(buf)) >= 1 && path <= 6) break; + + clear(); + move(0, 25); + prints(TITLE); + line = 3; + print_station(addr, path, &line, &station_num); + sprintf(genbuf, "\033[1;35m請輸入起站(1-%d):\033[m", station_num); while (1) - if (getdata(18, 40, "\033[1;35m請輸入目的地(1-94):\033[m", - buf, 3, LCECHO) && - (to = atoi(buf)) >= 1 && to <= 94) - break; + if (getdata(line, 0, genbuf, buf, 3, LCECHO) && (from = atoi(buf)) >= 1 && from <= station_num) + break; + sprintf(genbuf, "\033[1;35m請輸入終站(1-%d):\033[m", station_num); + while (1) + if (getdata(line, 40, genbuf, buf, 3, LCECHO) && (to = atoi(buf)) >= 1 && to <= station_num) + break; + line++; + while (1) - if (getdata(19, 0, "\033[1;35m請輸入時間區段(0-23) 由:\033[m", + if (getdata(line, 0, "\033[1;35m請輸入時間區段(0-23) 由:\033[m", buf, 3, LCECHO) && (time_go = atoi(buf)) >= 0 && time_go <= 23) break; while (1) - if (getdata(19, 40, "\033[1;35m到:\033[m", buf, 3, LCECHO) && + if (getdata(line, 40, "\033[1;35m到:\033[m", buf, 3, LCECHO) && (time_reach = atoi(buf)) >= 0 && time_reach <= 23) break; + line++; + if (path<=3){ while (1) - if (getdata(20, 0, "\033[1;35m想查詢 1:對號快車 2:普通平快\033[m", - type, 2, LCECHO) && (type[0] == '1' || type[0] == '2')) - break; + if (getdata(line, 0, "\033[1;35m想查詢 1:對號快車 2:普通平快\033[m", + type, 2, LCECHO) && (type[0] == '1' || type[0] == '2')) + break; + line++; + } while (1) - if (getdata(21, 0, "\033[1;35m欲查詢 1:出發時間 2:到達時間\033[m", + if (getdata(line, 0, "\033[1;35m欲查詢 1:出發時間 2:到達時間\033[m", tt, sizeof(tt), LCECHO) && (tt[0] == '1' || tt[0] == '2')) break; + line++; + while (1) + if (getdata(line, 0, "\033[1;35m請輸入欲查詢日期(0-29)天後\033[m", + buf, 3, LCECHO) && (date = atoi(buf))>=0 && date<=29) + break; + line++; + sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mhdr); strlcpy(mhdr.owner, "Ptt搜尋器", sizeof(mhdr.owner)); strncpy(mhdr.title, "火車時刻搜尋結果", TTLEN); - snprintf(command, sizeof(command), "echo \"from-station=%s&to-station=%s" - "&from-time=%02d00&to-time=%02d00&tt=%s&type=%s\" | " - "lynx -dump -post_data " - "\"http://www.railway.gov.tw/cgi-bin/timetk.cgi\" > %s.railway", - addr[from - 1], addr[to - 1], time_go, time_reach, + snprintf(command, sizeof(command), "echo \"path=%d from-station=%s to-station=%s" + " from-time=%02d to-time=%02d tt=%s type=%s date=%d\" | /home/bbs/bin/railway_wrapper.pl > %s", + path, addr[path - 1][from - 1], addr[path - 1][to - 1], time_go, time_reach, (tt[0] == '1') ? "start" : "arriv", - (type[0] == '1') ? "fast" : "slow", genbuf); + (type[0] == '1') ? "fast" : "slow", date, genbuf); system(command); - filt_railway(genbuf); sethomedir(genbuf, cuser.userid); if (append_record(genbuf, &mhdr, sizeof(mhdr)) == -1) return -1; - hpressanykey("\033[1;31m我們會把搜尋結果很快就寄給你唷 ^_^\033[m"); + hpressanykey("\033[1;31m我們會把搜尋結果很快地寄給你唷 ^_^\033[m"); return 0; } diff --git a/util/Makefile b/util/Makefile index 8e0479e4..06a4e471 100644 --- a/util/Makefile +++ b/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.22 2002/11/08 21:16:25 in2 Exp $ +# $Id: Makefile,v 1.23 2003/02/11 06:03:31 victor Exp $ BBSHOME?=$(HOME) OSTYPE!=uname @@ -35,7 +35,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ toplazyBM.sh toplazyBBM.sh dailybackup.pl tarqueue.pl waterball.pl \ - filtermail.pl getbackup.pl udnnews.pl rebuildaloha.pl + filtermail.pl getbackup.pl udnnews.pl rebuildaloha.pl railway_wrapper.pl all: $(PROGS) diff --git a/util/railway_wrapper.pl b/util/railway_wrapper.pl new file mode 100755 index 00000000..b6885173 --- /dev/null +++ b/util/railway_wrapper.pl @@ -0,0 +1,119 @@ +#!/usr/bin/perl +# +# 您可以使用這個檔案應付鐵路局網址的異動 +# 或是以擅於字串處理的 perl 修正以下程式碼 :) +# +#VictorHsieh 2003.02.11 + +use lib '/home/bbs/bin'; +use LocalVars; +use vars qw/ %opt %station_num @arg $command $addr/; +use strict; + +$addr = "http://passenger.tra.gov.tw/ap/index.asp"; + +@arg = split ' ', <STDIN>; +map { /(.+)=(.+)/ and $opt{$1} = $2 } grep /.+=.+/, @arg; + +station_init(); +translate(); + +$command = "MIval=Train_Time&encode=Big5&action=on"; +map { $command .= "&$_=$opt{$_}"} keys %opt; +exec "$LYNX -dump -assume_charset=big5 -nolist \"$addr?$command\""; + +# 將 page.c 中的格式轉為鐵路局所使用的格式 +sub translate{ + change_opt('from-station', 'Station1'); + change_opt('to-station', 'Station2'); + change_opt('from-time', 'From_Time'); + change_opt('to-time', 'To_Time'); + change_opt('type', 'Type'); + change_opt('tt', 'Time'); + change_opt('date','Departure_Date'); + change_opt('path', 'line'); +} + +# 轉換參數的表示法 +sub change_opt{ + my ($old, $new) = @_; + if(defined $opt{$old}){ + if( $old =~ /station/ ){ + $opt{$old} = $station_num{$opt{$old}}; + } + elsif( $old =~ /type/ ){ + $opt{$old} = ($opt{$old} eq 'fast')? 'F' : 'S'; + } + elsif( $old =~ /tt/ ){ + $opt{$old} = ($opt{$old} eq 'start')? 'D' : 'A'; + } + elsif( $old =~ /date/ ){ + my ($sec, $min, $hour, $mday, $mon, $year) = gmtime; + $mday = $mday + $opt{$old}; + $mon++; + $opt{$old} = join '/', + ($year+1900, + ($mon>9)? $mon : "0$mon", + ($mday>9)? $mday : "0$mday"); + } + elsif( $old =~ /path/ ){ + my @line = qw/ mainwest maineast mainsouth pin innerbay gg/; + $opt{$old} = $line[$opt{$old}-1]; + } + + $opt{$new} = $opt{$old} and delete $opt{$old}; + } +} + +# 各站代碼對應 +sub station_init{ + %station_num = ( + "基隆" => 1001, "八堵" => 1002, "七堵" => 1003, "五堵" => 1004, + "汐止" => 1005, "南港" => 1006, "松山" => 1007, "台北" => 1008, + "萬華" => 1009, "板橋" => 1011, "樹林" => 1012, "山佳" => 1013, + "鶯歌" => 1014, "桃園" => 1015, "內壢" => 1016, "中壢" => 1017, + "埔心" => 1018, "楊梅" => 1019, "富岡" => 1020, "湖口" => 1021, + "新豐" => 1022, "竹北" => 1023, "新竹" => 1025, "香山" => 1026, + "崎頂" => 1027, "竹南" => 1028, "談文" => 1102, "大山" => 1104, + "後龍" => 1105, "龍港" => 1106, "白沙屯" => 1107, "新埔" => 1108, + "通霄" => 1109, "苑裡" => 1110, "日南" => 1111, "大甲" => 1112, + "臺中港" => 1113, "清水" => 1114, "沙鹿" => 1115, "龍井" => 1116, + "大肚" => 1117, "追分" => 1118, "彰化" => 1120, "花壇" => 1202, + "員林" => 1203, "永靖" => 1204, "社頭" => 1205, "田中" => 1206, + "二水" => 1207, "林內" => 1208, "石榴" => 1209, "斗六" => 1210, + "斗南" => 1211, "石龜" => 1212, "大林" => 1213, "民雄" => 1214, + "嘉義" => 1215, "水上" => 1217, "南靖" => 1218, "後壁" => 1219, + "新營" => 1220, "柳營" => 1221, "林鳳營" => 1222, "隆田" => 1223, + "拔林" => 1224, "善化" => 1225, "新市" => 1226, "永康" => 1227, + "台南" => 1228, "保安" => 1229, "中洲" => 1230, "大湖" => 1231, + "路竹" => 1232, "岡山" => 1233, "橋頭" => 1234, "楠梓" => 1235, + "左營" => 1236, "高雄" => 1238, "大橋" => 1239, "造橋" => 1302, + "豐富" => 1304, "苗栗" => 1305, "南勢" => 1307, "銅鑼" => 1308, + "三義" => 1310, "泰安" => 1314, "后里" => 1315, "豐原" => 1317, + "潭子" => 1318, "台中" => 1319, "烏日" => 1320, "成功\" => 1321, + "大慶" => 1322, "太原" => 1323, "鳳山" => 1402, "後庄" => 1403, + "九曲堂" => 1404, "六塊厝" => 1405, "屏東" => 1406, "吉安" => 1602, + "志學" => 1604, "平和" => 1605, "壽豐" => 1606, "豐田" => 1607, + "溪口" => 1608, "南平" => 1609, "鳳林" => 1610, "萬榮" => 1611, + "光復" => 1612, "大富" => 1613, "富源" => 1614, "瑞北" => 1615, + "瑞穗" => 1616, "三民" => 1617, "玉里" => 1619, "安通" => 1620, + "東里" => 1621, "東竹" => 1622, "富里" => 1623, "池上" => 1624, + "海瑞" => 1625, "關山" => 1626, "月美" => 1627, "瑞和" => 1628, + "瑞源" => 1629, "鹿野" => 1630, "山里" => 1631, "台東" => 1632, + "永樂" => 1703, "東澳" => 1704, "南澳" => 1705, "武塔" => 1706, + "漢本" => 1708, "和平" => 1709, "和仁" => 1710, "崇德" => 1711, + "新城" => 1712, "景美" => 1713, "北埔" => 1714, "花蓮" => 1715, + "暖暖" => 1802, "四腳亭" => 1803, "瑞芳" => 1804, "侯硐" => 1805, + "三貂嶺" => 1806, "牡丹" => 1807, "雙溪" => 1808, "貢寮" => 1809, + "福隆" => 1810, "石城" => 1811, "大里" => 1812, "大溪" => 1813, + "龜山" => 1814, "外澳" => 1815, "頭城" => 1816, "頂埔" => 1817, + "礁溪" => 1818, "四城" => 1819, "宜蘭" => 1820, "二結" => 1821, + "中里" => 1822, "羅東" => 1823, "冬山" => 1824, "新馬" => 1825, + "蘇澳新站" => 1826, "蘇澳" => 1827, "大華" => 1903, "十分" => 1904, + "望古" => 1905, "嶺腳" => 1906, "平溪" => 1907, "菁桐 " => 1908, + "竹中" => 2203, "上員" => 2204, "竹東" => 2205, "橫山" => 2206, + "九讚頭" => 2207, "合興" => 2208, "南河" => 2209, "內灣" => 2210, + "榮華" => 2211, "源泉" => 2702, "濁水" => 2703, "龍泉" => 2704, + "集集" => 2705, "水里" => 2706, "車埕" => 2707, + ); +} |