📄 ch18.htm
字号:
sub no_author_error {<BR>
<BR>
print "Content-type: text/html\n\n";
<BR>
print <<END;<BR>
<HTML><HEAD><TITLE>No Author Error!</TITLE></HEAD>
<BR>
<BODY><BR>
<FONT SIZE=+1><B><BR>
<P><BR>
No author name was entered into the posting form. One
is required.<BR><BR>
Press the BACK button on your browser to re-enter the form.</B></FONT>
<BR>
</BODY></HTML><BR>
END<BR>
exit 1;<BR>
}<BR>
<BR>
sub no_subject_error {<BR>
<BR>
print "Content-type: text/html\n\n";
<BR>
print <<END;<BR>
<HTML><HEAD><TITLE>No Subject Error!</TITLE></HEAD>
<BR>
<BODY><BR>
<FONT SIZE=+1><B><BR>
<P><BR>
No subject was entered into the posting form. One is
required.<BR><BR>
Press the BACK button on your browser to re-enter the form.</B></FONT>
<BR>
</BODY></HTML><BR>
END<BR>
exit 1;<BR>
}<BR>
<BR>
sub print_list {<BR>
<BR>
if ( $prefix ne '' ) {<BR>
print "<H3>Follow-up
Postings:</H3>\n";<BR>
shift(@posts);<BR>
}<BR>
<BR>
if ( $#posts == -1 ) {<BR>
print "<H4>None</H4>\n<HR>\n";
<BR>
return 0;<BR>
}<BR>
<BR>
#<BR>
# reconstructs header fields from posting and place into the list
<BR>
#<BR>
$ul_count = 0;<BR>
foreach $i ( 0 .. $#posts ) {<BR>
<BR>
#<BR>
# this if structure implements my "typographical trick"
which threads<BR>
# postings based solely on their file names. "bits"
of posting names,<BR>
# separated by '_', are compared, first to see how many left-most
bits<BR>
# the current posting has in common with its immediate predecessor,
<BR>
# and then the signed inequality of right-most not-in-common bits
is<BR>
# used to determine the extent of <UL> pushing/popping needed
to thread<BR>
#<BR>
if ( $i != 0 ) {<BR>
<BR>
$this =
$posts[$i];<BR>
$previous
= $posts[$i-1];<BR>
<BR>
@this_bits
= split(/-/,$this);<BR>
@previous_bits
= split(/-/,$previous);<BR>
<BR>
if ( $#this_bits
> $#previous_bits ) {<BR>
$lesser_bits
= $#previous_bits;<BR>
} else {
<BR>
$lesser_bits
= $#this_bits;<BR>
}<BR>
<BR>
$common
= 0;<BR>
for $j (
0 .. $lesser_bits ) {<BR>
last
if $this_bits[$j] ne $previous_bits[$j];<BR>
$common++;
<BR>
}<BR>
<BR>
splice(@this_bits,$[,$common);
<BR>
splice(@previous_bits,$[,$common);
<BR>
<BR>
if ( $common
== 0 ) {<BR>
while
( $ul_count ) {<BR>
print
"</UL>";<BR>
$ul_count-;
<BR>
}
<BR>
} else {
<BR>
if
( $#this_bits > $#previous_bits ) {<BR>
for
$k ( 1 .. ($#this_bits - $#previous_bits) ) {<BR>
print
"<UL>\n";<BR>
$ul_count++;
<BR>
}
<BR>
}
elsif ( $#this_bits < $#previous_bits ) {<BR>
for
$k ( 1 .. ($#previous_bits - $#this_bits) ) {<BR>
print
"</UL>\n";<BR>
$ul_count-;
<BR>
}
<BR>
}
<BR>
}<BR>
} else {<BR>
$this =
$posts[0];<BR>
print "<UL>\n";
<BR>
}<BR>
<BR>
open(POST,"$this.post");
<BR>
&read_header;<BR>
close(POST);<BR>
<BR>
print "<LI> <A
HREF=$prog_url?$this>$subject</A> ";<BR>
if ( $email ne '' ) {<BR>
print "<FONT
SIZE=-1><A HREF=mailto:$email><B>$author</B></A>
";<BR>
} else {<BR>
print "<FONT
SIZE=-1><B>$author</B> ";<BR>
}<BR>
if ( $to ne '' ) { print "<I>To:</I>
<B>$to</B> "; }<BR>
print "<I>$time</I></FONT>\n";
<BR>
}<BR>
<BR>
while ( $ul_count ) {<BR>
print "</UL>";
<BR>
$ul_count--;<BR>
}<BR>
print "</UL>\n<HR>\n";
<BR>
}<BR>
<BR>
sub get_posts {<BR>
<BR>
local($pre);<BR>
($pre) = @_;<BR>
<BR>
@posts = 'ls -r1 $pre*.post';<BR>
$post_len = length(".post\n");<BR>
foreach $post ( @posts ) {<BR>
substr($post,-$post_len) =
''; # remove unwanted tailing characters<BR>
}<BR>
}<BR>
<BR>
sub new_article {<BR>
<BR>
$temp = $input{'author'};<BR>
$temp =~ s/\s//;<BR>
if ( $temp eq '' ) {<BR>
&no_author_error;<BR>
}<BR>
$temp = $input{'subject'};<BR>
$temp =~ s/\s//;<BR>
if ( $temp eq '' ) {<BR>
&no_subject_error;<BR>
}<BR>
<BR>
&get_posts($input{'basepost'});<BR>
<BR>
if ( $#posts == -1 ) {<BR>
#<BR>
# case where there are absolutely no postings in the tree<BR>
#<BR>
$fname = '00000';<BR>
} else {<BR>
if ( $input{'basepost'} eq
'' ) {<BR>
#<BR>
# case where we are adding a new posting to the base level of
the tree<BR>
#<BR>
@parts =
split(/-/,$posts[0]);<BR>
$fname =
++($parts[0]);<BR>
} else {<BR>
$temp =
shift(@posts);<BR>
if ( $#posts
== -1 ) {<BR>
#<BR>
# case of a first reply<BR>
#<BR>
$fname
= $temp . '-' . '00000';<BR>
} else {
<BR>
#<BR>
# case of each subsequent reply<BR>
#<BR>
@parts
= split(/-/,$posts[0]);<BR>
++($parts[$#parts]);
<BR>
$fname
= join('-',@parts);<BR>
}<BR>
}<BR>
}<BR>
<BR>
#<BR>
# gets the current system time and removes some info for the sake
of<BR>
# horizontal space (some info = seconds & time zone)<BR>
#<BR>
chop($time = 'date');<BR>
@timefields = split(/[\s]+/,$time);<BR>
substr($timefields[3],-3,3) = '';<BR>
$time = join(' ',@timefields[0..3],$timefields[5]);
<BR>
<BR>
#<BR>
# remove DOS-style newline info from posting body<BR>
#<BR>
$input{'body'} =~ s/\cM//g;<BR>
<BR>
open(POST,"> $fname.post");<BR>
print POST "Author\t$input{'author'}\n";
<BR>
print POST "Email\t$input{'email'}\n";
<BR>
print POST "Subject\t$input{'subject'}\n";
<BR>
print POST "To\t$input{'to'}\n";<BR>
print POST "Time\t$time\n";<BR>
print POST $input{'body'};<BR>
close(POST);<BR>
<BR>
chmod 0660,"$fname.post";<BR>
}<BR>
<BR>
sub footer {<BR>
print "</BODY></HTML>\n\n";
<BR>
}<BR>
<BR>
sub print_form {<BR>
<BR>
if ( $prefix eq '' ) {<BR>
print <<END;<BR>
<H3>Submit a New Posting</H3><BR>
<FORM METHOD=POST ACTION=$prog_url><BR>
<INPUT TYPE=HIDDEN NAME="basepost" VALUE="$prefix">
<BR>
<PRE><BR>
Author : <INPUT TYPE=text NAME="author">
<BR>
Email : <INPUT TYPE=text NAME="email">
(optional)<BR>
Subject : <INPUT TYPE=text NAME="subject"><BR>
To : <INPUT TYPE=text NAME="to">
(optional) <BR><BR>
Body of Article:<BR>
<TEXTAREA NAME="body" ROWS=5 COLS=50></TEXTAREA></PRE>
<BR>
<INPUT TYPE=SUBMIT NAME="submit" VALUE="Submit
this Article"><BR>
<INPUT TYPE=RESET NAME=clear Value="Clear this form">
<BR>
</FORM><BR>
END<BR>
} else {<BR>
<BR>
&read_article($prefix);
<BR>
<BR>
print <<END;<BR>
<H3>Reply to this Posting</H3><BR>
<FORM METHOD=POST ACTION=$prog_url><BR>
<INPUT TYPE=HIDDEN NAME="basepost" VALUE="$prefix">
<BR>
<PRE><BR>
Author : <INPUT TYPE=text NAME="author">
<BR>
Email : <INPUT TYPE=text NAME="email">
(optional)<BR>
Subject : <INPUT TYPE=text NAME="subject" VALUE="Re:
$subject"><BR>
To : <INPUT TYPE=text NAME="to" VALUE=\"$author\">
(optional)<BR>
<BR> Body of Article:<BR>
END<BR>
print "<TEXTAREA NAME=\"body\"
ROWS=5 COLS=50>";<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -