#!/usr/bin/perl # 17 may 00 # used at dharma.school.net.th/cgi-bin/ use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); $start_book = sprintf ("%02d", param ('start_book') || 1); $num_line = param ('num_line') || 80; $start_byte = param ('start_byte'); # context before this page (override by start_topic) $start_topic = param ('start_topic'); # #body {font-family: Cordia New} $HTML_HEAD = <<__HTML_HEAD__; อ่านพระไตรปิฎก: ลานธรรมเสวนา

ลานธรรมเสวนา

__HTML_HEAD__ $HTML_TAIL = <<__HTML_TAIL__;
Click Here!
__HTML_TAIL__ open (FILE, "../tipitaka/sutra/tipitaka$start_book.txt") or die "Can't open tipitaka$start_book.txt: $!"; #---------------------------------------- คำนวน start_byte จาก start_topic if($start_topic){ $start_topic =~ tr/0123456789/๐๑๒๓๔๕๖๗๘๙/; while(){ next unless /\[$start_topic\]/o; $start_byte = tell(FILE) - length($_) -1; last; } if (eof(FILE)) { print header(); print "

ไม่พบหัวข้อธรรมหมายเลข ", param('start_topic'), "

\n"; } } #-------------------------------------- คำนวน start_byte สำหรับหน้าก่อน $new_pos = $start_byte-($num_line*100); $new_pos = 0 if ($new_pos < 0); seek (FILE, $new_pos, 0); @starts = (tell FILE); while (){ last if (tell(FILE) >= $start_byte); push @starts, tell(FILE); } $prev_start = $starts[-$num_line] || 0; #---------------------------------------------อ่าน/แปลง ตัวเนื้อหาจริงๆ # เก็บ หนึ่งบรรทัดก่อนหน้า $new_pos = $start_byte-200; $new_pos = 0 if ($new_pos < 0); seek (FILE, $new_pos, 0); $text = while (tell(FILE) < $start_byte); chomp $text; $text = "$text\n"; # แสดงหนึ่งบรรทัดก่อนหน้า ด้วยสีเทา foreach (1..$num_line) { $text .= ; } $text =~ s/\n/
\n/g; $text =~ s/^( {13,}.*)/$1<\/b>/gm; $text =~ s/ ( +)/("\240" x length($1)) .' '/ge; #---------------------------------------------แสดงผล print "Content-type: text/html\n\n", $HTML_HEAD; print start_form(); print hidden('start_book'),""; print submit('direction', 'หน้าก่อน'); print end_form(); print "\nพระไตรปิฎก เล่มที่ $start_book
\n"; print $text; print "\n
\n"; print start_form(); print hidden('start_book'),""; #print submit('direction','prev page'); print submit('direction', 'หน้าถัดไป')," บรรทัด"; print end_form(); print start_form(); print submit('กระโดดไป'), " เล่มที่ "; print "หัวข้อที่", textfield('start_topic','',4); print end_form(); print $HTML_TAIL;