(back to the source index) midday

commented source





#!/usr/bin/perl # This script is part of the NoonQuilt project: # # <insert URL> # # © Ali Graham, 1998 <mailto:agraham@hal9000.net.au> # # (See makeQuilt.pl for the version history.) # # # Start of editAll.pl (List all patches to be edited) # ################################################################ # make sure this is syntactically clear... use strict; use English; # ...and running under Perl5... require 5.001; # uses a module available from # CPAN ( http://www.perl.com/CPAN/ ), # CGI_Lite # set the include path to recognise it use lib 'perllib'; # include the external files... my $path = ""; if ( $OSNAME =~ /^mswin/i ) { $path = "d:\\Inetpub\\wwwroot\\quilt\\scripts\\"; chdir($path); }

(I needed to add the above lines to the start of every script, otherwise the Perl interpreter on Windows NT would not change to the directory the scripts were running in -- this is inconsistent with the behaviour on Unix, Amiga & Macintosh Perl, which did.)



(require $path."nq_config.pl") or (die "Can't open \"nq_config.pl\": $!\n"); (require $path."nq_dirstuff.pl") or (die "Can't open \"nq_dirstuff.pl\": $!\n"); # ################################################################ # Start of main() # get the dirs based on CGI data use CGI_Lite; my $cgi = new CGI_Lite (); my %cgi_data = $cgi->parse_form_data(); my $params; my $patch_file; my $defaults = &nqco_getScriptDefaults;

The code below checks the location of the directory to list be edited: this is passed in by the HTML page that calls this script, control.htm, based on the selection on the form on the left-hand side of the control bar.



my $source_dir; my $page_title; if ( $cgi_data{'subm_type'} eq "pending" ) { $source_dir = $defaults->{'S_PatchInDir'}; $page_title = "list of submitted patches"; } elsif ( $cgi_data{'subm_type'} eq "accepted" ) { $source_dir = $defaults->{'S_PatchDir'}; $page_title = "list of accepted patches"; } else { $source_dir = $defaults->{'S_PatchRejectDir'}; $page_title = "list of rejected patches"; } my @patch_files = sort( &nqds_getDirList($source_dir) ); if ( $#patch_files > -1 ) {

This is an oft-repeated tactic used in this source code -- in-line HTML code with the occasional interspersion of Perl variables. It may be a little confusing to mix metaphors like this, but the advantages that come from the resultant terseness make it much easier than using a succession of print "" statements.



print STDOUT <<End_StartPatchList; Content-type: text/html <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> <HTML> <HEAD> <TITLE>$page_title</TITLE> </HEAD> <BODY BGCOLOR="#FFFFCE" TEXT="#313131"> <DIV ALIGN=CENTER> <BR> <FONT SIZE="+1">$page_title</FONT> <BR> <BR> <TABLE CELLSPACING=0 CELLPADDING=8 BORDER=1 WIDTH="95%"> <TR> <TH WIDTH="10%" ALIGN=LEFT>( edit )</TH> <TH WIDTH="20%" ALIGN=LEFT>( file name )</TH> <TH WIDTH="20%" ALIGN=LEFT>( author )</TH> <TH WIDTH="50%" ALIGN=LEFT>( start of submission )</TH> </TR> End_StartPatchList

The code below writes a row in the table for each file it finds in the directory it has been told to list. Each row has a button to edit it, the name of the file, the name of the person who submitted it, and the first few words of the submission so it can be easily identified.



for $patch_file (@patch_files) { my $submission; $params = &nqco_readParameters("$source_dir$patch_file"); $submission = $params->{'F_UserSubmission'}{'Value'}; # strip out all parts in angled brackets... $submission =~ s/<.*?>//gs; $submission = substr($submission, 0, 40); print STDOUT <<End_PatchRow; <TR> <TD> <FORM ACTION="editPatch.pl" METHOD="POST"> <INPUT TYPE="hidden" NAME="subm_type" VALUE="$cgi_data{'subm_type'}"> <INPUT TYPE="hidden" NAME="subm_file" VALUE="$patch_file"> <INPUT TYPE="submit" VALUE="Edit..."> </FORM> </TD> <TD> $patch_file </TD> <TD> $params->{'F_UserName'}{'Value'} </TD> <TD> <I>$submission</I> </TD> </TR> End_PatchRow } print STDOUT <<End_EndPatchList; </TABLE> </DIV> </BODY> </HTML> End_EndPatchList } else {

This prints out an error message, if there are no files in the selected directory.



print STDOUT <<End_NoPatches; Content-type: text/html <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> <HTML> <HEAD> <TITLE>choose a patch to edit</TITLE> </HEAD> <BODY BGCOLOR="#FFFFCE" TEXT="#313131"> <BR> <BR> <DIV ALIGN=CENTER> <BR> <BR> There are no files in the directory ( $source_dir ). </DIV> </BODY> </HTML> End_NoPatches } # End of main() # End of editList.pl