File:  [LON-CAPA] / loncom / build / Attic / parse.pl
Revision 1.17: download - view: text, annotated - select for diffs
Thu Dec 14 18:38:37 2000 UTC (23 years, 6 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
debugging configinstall target; enforcing file ownerships and
permissions to compensate for activity of loncaparestoreconfiguration
script -Scott

: ----------------------------------------------------------------------

    1: #!/usr/bin/perl
    2: 
    3: # Scott Harrison
    4: # November 2000
    5: 
    6: # Read in loncapa tags and metagroup tags
    7: 
    8: # ---------------------------------------------- Read in command line arguments
    9: my ($file,$mode)=@ARGV;
   10: 
   11: # ---------------------------------------------------- Read in master data file
   12: open IN,"<$file";
   13: my @lines=<IN>;
   14: close IN;
   15: my $info1=join('',@lines);
   16: my $info2=$info1; # value to allow for meta data group retrieval
   17: 
   18: # ------------------------------------------------------- Make default settings
   19: my $distribution="redhat6.2";
   20: my $date=`date +'%B %e, %Y'`; chop $date;
   21: my $buildhost=`hostname`; chop $buildhost;
   22: # file category mappings
   23: my %fcm=(
   24: 	 'conf' => 'configurable',
   25: 	 'graphic file' => 'graphicfile',
   26: 	 'handler' => 'handler',
   27: 	 'interface file' => 'interfacefile',
   28: 	 'symbolic link' => 'link',
   29: 	 'root script' => 'rootscript',
   30: 	 'script' => 'script',
   31: 	 'setuid script' => 'setuid',
   32: 	 'static conf' => 'static',
   33: 	 'system file' => 'systemfile',
   34: 	 );
   35: 
   36: # ---------------------------------------------------- Parse the marked up data
   37: my %info; # big data storage object
   38: while ($info1=~/\<loncapa\s+(.*?)\>/isg) {
   39:     my $keystring=$1;
   40:     # In the parsing of LON-CAPA tags, remove boundary white-space,
   41:     # and handle quotation commands.
   42:     my %hash=map {my ($key,$value)=split(/\=(?!")|\=(?=\s*"[^"]*"[^"]*$)/);
   43:                                    $value=~s/^"//;
   44:  				   $value=~s/"$//;
   45:                                    (uc($key),$value);}
   46:              split(/\s+(?=\w+\s*\=)/,$keystring);
   47:     # Handle the different types of commands
   48:     if (uc($hash{'TYPE'}) eq "OWNERSHIP") {
   49:         $info{$hash{'TYPE'}}{$hash{'CATEGORY'}}{'CHMOD'}=$hash{'CHMOD'};
   50:         $info{$hash{'TYPE'}}{$hash{'CATEGORY'}}{'CHOWN'}=$hash{'CHOWN'};
   51:     }
   52:     elsif (uc($hash{'TYPE'}) eq "DEVOWNERSHIP") {
   53:         $info{$hash{'TYPE'}}{$hash{'CATEGORY'}}{'CHMOD'}=$hash{'CHMOD'};
   54:         $info{$hash{'TYPE'}}{$hash{'CATEGORY'}}{'CHOWN'}=$hash{'CHOWN'};
   55:     }
   56:     elsif (uc($hash{'TYPE'}) eq "RPM") {
   57:         $hash{'VALUE'}=~s/\\n/\n/g;
   58:         $info{$hash{'TYPE'}}{$hash{'NAME'}}=$hash{'VALUE'};
   59:     }
   60:     elsif (uc($hash{'TYPE'}) eq "DIRECTORY") {
   61:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'CATEGORY'}=
   62:                                                        $hash{'CATEGORY'};
   63:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'DESCRIPTION'}=
   64:                                $hash{'DESCRIPTION'} if $hash{'DESCRIPTION'};
   65:     }
   66:     elsif (uc($hash{'TYPE'}) eq "LOCATION") {
   67:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'CATEGORY'}=                               $hash{'CATEGORY'};
   68:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'LINKTO'}=                               $hash{'LINKTO'};
   69:         $info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{'SOURCE'}=                                               $hash{'SOURCE'};
   70:         # get surrounding metagroup information
   71:         my $ckeystring=$keystring; $ckeystring=~s/(SOURCE\=\"[^"]*)\*/$1\\\*/g;
   72:         $ckeystring=~s/(TARGET\=\"[^"]*)\*/$1\\\*/g;
   73:         $info2=~/.*\<(?:metagroup|metasupergroup)\>(.*?)\<loncapa\s+$ckeystring\>(.*?)\<\/(?:metagroup|metasupergroup)\>/is;
   74: 	my $data=$1.$2;
   75:         my @meta=('description','build','dependencies','files','note');
   76:         foreach my $m (@meta) {
   77: 	    if ($data=~/\<($m)\>(.*?)\<\/$m\>/sgi) {
   78: 		my ($key,$value)=($1,$2);
   79: 		$info{$hash{'TYPE'}}{$hash{'DIST'}}{$hash{'TARGET'}}{uc($key)}=
   80: 		                                                    $value;
   81: 	    }
   82:         }
   83:     }
   84:     else {
   85:         warn("WARNING: this tag text will be ignored since it cannot be understood\n---> $keystring\n");
   86:     }
   87: }
   88: 
   89: my $a;
   90: my @directories;
   91: if ($mode eq "HTML") {
   92:     $a=&begin_description_page;
   93:     print $a;
   94:     $a=&make_rpm_description_block;
   95:     print $a;
   96:     @directories=&determine_directory_structure;
   97:     $a=&make_directory_structure_description_block(\@directories);
   98:     print $a;
   99:     $a=&make_file_type_ownership_and_permissions_description_block;
  100:     print $a;
  101:     $a=&make_directory_and_file_structure_description_block(\@directories);
  102:     print $a;
  103:     $a=&end_description_page;
  104:     print $a;
  105: }
  106: elsif ($mode eq "SPEC") {
  107:     my $out=$info{'RPM'}{'Name'} . '-' . $info{'RPM'}{'Version'} . '.spec';
  108:     open OUT,">$out";
  109:     $a=&make_rpm_spec_block;
  110:     print OUT $a;
  111:     $a=&make_rpm_build_block;
  112:     print OUT $a;
  113:     @directories=&determine_directory_structure;
  114:     $a=&make_directory_structure_spec_block(\@directories);
  115:     print OUT $a;
  116:     $a=&make_directory_and_file_structure_spec_block(\@directories);
  117:     print OUT $a;
  118:     $a=&end_spec_page;
  119:     print OUT $a;
  120:     close OUT;
  121: }
  122: elsif ($mode eq "LCMakefile") {
  123:     @directories=&determine_directory_structure;
  124:     $a=&make_directory_LCMakefile_segment(\@directories);
  125:     print $a;
  126:     $a=&make_files_LCMakefile_segment(\@directories);
  127:     print $a;
  128:     $a=&make_links_LCMakefile_segment(\@directories);
  129:     print $a;
  130: }
  131: elsif ($mode eq "BinaryRoot") {
  132:     mkdir "BinaryRoot",0755;
  133:     open OUT,">Makefile.BinaryRoot";
  134:     @directories=&determine_directory_structure;
  135:     $a=&make_directory_binaryroot_segment(\@directories);
  136:     print OUT $a;
  137:     $a=&make_files_binaryroot_segment(\@directories);
  138:     print OUT $a;
  139:     $a=&make_links_binaryroot_segment(\@directories);
  140:     print OUT $a;
  141:     close OUT;
  142:     print `make -f Makefile.BinaryRoot TARGET='BinaryRoot' SOURCE='../..' directories`;
  143:     print `make -f Makefile.BinaryRoot TARGET='BinaryRoot' SOURCE='../..' files`;
  144:     print `make -f Makefile.BinaryRoot TARGET='BinaryRoot' SOURCE='../..' links`;
  145:     open OUT,">base_file_list.txt";
  146:     $a=&make_file_list(\@directories);
  147:     print OUT $a;
  148:     close OUT;
  149:     
  150: }
  151: elsif ($mode eq "status") {
  152: }
  153: elsif ($mode eq "update") {
  154: }
  155: elsif ($mode eq "configinstall") {
  156:     @directories=&determine_directory_structure;
  157:     $a=&make_files_configinstall_segment(\@directories);
  158:     print $a;
  159:     $a=&make_files_configpermissions_segment(\@directories);
  160:     print $a;
  161: }
  162: elsif ($mode eq "install") {
  163:     @directories=&determine_directory_structure;
  164:     $a=&make_directory_install_segment(\@directories);
  165:     print $a;
  166:     $a=&make_files_install_segment(\@directories);
  167:     print $a;
  168:     $a=&make_links_install_segment(\@directories);
  169:     print $a;
  170: }
  171: elsif ($mode eq "build") {
  172:     @directories=&determine_directory_structure;
  173:     $a=&make_files_build_segment(\@directories);
  174:     print $a;
  175: }
  176: 
  177: # ------------------------------------------------------ a list of file targets
  178: sub make_file_list {
  179:     my ($dirs)=@_;
  180:     my $description;
  181:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  182:     foreach my $d (@$dirs) {
  183: 	# set other values
  184: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  185: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  186: 	# find files that are contained in this directory
  187: 	my @files;
  188: 	my @filesfull;
  189: 	foreach my $f (@allfiles) {
  190: 	    if ($f=~/^$d\/([^\/]+)$/) {
  191: 		push @files,$1;
  192: 		push @filesfull,$f;
  193: 	    }
  194: 	}
  195: 	# render starting HTML formatting elements
  196: 	if (@files) {
  197:         }
  198: 	my $pwd=`pwd`; chop $pwd;
  199: 	if (@files) {
  200:             foreach my $i (0..$#files) {
  201: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  202: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  203: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  204: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  205: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  206: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  207: 		my $rot="/".$filesfull[$i];
  208: 		if ($rot=~/\*/) {
  209: 		    $rot=~s/[^\/]+$// if $rot=~/\*/;
  210: 		    my $listing=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'FILES'};
  211: 		    chop $listing;
  212: 		    my @list=split(/\s+/,$listing);
  213: 		    my $rot2;
  214: 		    foreach my $l (@list) {
  215: 			$l=~s/^\s*//; $l=~s/\s*$//;
  216: 			$rot2.="BinaryRoot$rot$l\n" if length($l);
  217: 		    }
  218: 		    chop $rot2;
  219: 		    $rot=$rot2;
  220: 		}
  221: 		else {
  222: 		    $rot="BinaryRoot$rot";
  223: 		}
  224: 		if ($category eq "conf") {
  225: 		    $rot.=" # config";
  226: 		}
  227: 		$description.=<<END;
  228: $rot
  229: END
  230: 	    }
  231: 	}
  232:     }
  233:     $description.=<<END;
  234: 
  235: END
  236:     return $description;
  237: }
  238: 
  239: # --------------------------------- Commands to make BinaryRoot directories
  240: sub make_directory_binaryroot_segment {
  241:     my ($dirs)=@_;
  242:     my $description=<<END;
  243: directories:
  244: END
  245:     foreach my $d (@$dirs) {
  246: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  247: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  248: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  249: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  250: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  251: 	my $own=$devchown; $own=~s/\:/\,/;
  252: 	$description.=<<END;
  253: \tinstall -m $devchmod -d \$(TARGET)/$d
  254: END
  255:     }
  256:     $description.=<<END;
  257: 
  258: END
  259:     return $description;
  260: }
  261: 
  262: # --------------------------------------- Commands to make BinaryRoot files
  263: sub make_files_binaryroot_segment {
  264:     my ($dirs)=@_;
  265:     my $description=<<END;
  266: files:
  267: END
  268:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  269:     foreach my $d (@$dirs) {
  270: 	# set other values
  271: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  272: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  273: 	# find files that are contained in this directory
  274: 	my @files;
  275: 	my @filesfull;
  276: 	foreach my $f (@allfiles) {
  277: 	    if ($f=~/^$d\/([^\/]+)$/) {
  278: 		push @files,$1;
  279: 		push @filesfull,$f;
  280: 	    }
  281: 	}
  282: 	# render starting HTML formatting elements
  283: 	if (@files) {
  284: 	    $description.=<<END;
  285: \t# $d $dirdescription
  286: END
  287:         }
  288: 	if (@files) {
  289:             foreach my $i (0..$#files) {
  290: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  291: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  292: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  293: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  294: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  295: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  296: 		my $rot=$filesfull[$i];
  297: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  298: 		$description.=<<END if $category ne 'symbolic link';
  299: \tinstall -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
  300: END
  301: 	    }
  302: 	}
  303:     }
  304:     $description.=<<END;
  305: 
  306: END
  307:     return $description;
  308: }
  309: 
  310: # ------------------------------ Commands to make BinaryRoot symbolic links
  311: sub make_links_binaryroot_segment {
  312:     my ($dirs)=@_;
  313:     my $description=<<END;
  314: links:
  315: END
  316:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  317:     foreach my $d (@$dirs) {
  318: 	# find files that are contained in this directory
  319: 	my @files;
  320: 	my @filesfull;
  321: 	foreach my $f (@allfiles) {
  322: 	    if ($f=~/^$d\/([^\/]+)$/) {
  323: 		push @files,$1;
  324: 		push @filesfull,$f;
  325: 	    }
  326: 	}
  327: 	# render starting HTML formatting elements
  328: 	if (@files) {
  329:             foreach my $i (0..$#files) {
  330: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  331: 		my $linkto=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'LINKTO'};
  332: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  333: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  334: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  335: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  336: 		$description.=<<END if $category eq 'symbolic link';
  337: \tln -s /$linkto \$(TARGET)/$filesfull[$i]
  338: END
  339: 	    }
  340: 	}
  341:     }
  342:     $description.=<<END;
  343: 
  344: END
  345:     return $description;
  346: }
  347: 
  348: # ------ Installation commands for a Makefile used only by a rpm -ba invocation
  349: sub make_directory_LCMakefile_segment {
  350:     my ($dirs)=@_;
  351:     my $description=<<END;
  352: directories:
  353: END
  354:     foreach my $d (@$dirs) {
  355: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  356: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  357: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  358: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  359: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  360: 	my $own=$devchown; $own=~s/\:/\,/;
  361: 	$description.=<<END;
  362: \tinstall -m $devchmod -d \$(SOURCE)/$d \$(ROOT)/$d
  363: END
  364:     }
  365:     $description.=<<END;
  366: 
  367: END
  368:     return $description;
  369: }
  370: 
  371: # ------ Installation commands for a Makefile used only by a rpm -ba invocation
  372: sub make_files_LCMakefile_segment {
  373:     my ($dirs)=@_;
  374:     my $description=<<END;
  375: files:
  376: END
  377:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  378:     foreach my $d (@$dirs) {
  379: 	# set other values
  380: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  381: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  382: 	# find files that are contained in this directory
  383: 	my @files;
  384: 	my @filesfull;
  385: 	foreach my $f (@allfiles) {
  386: 	    if ($f=~/^$d\/([^\/]+)$/) {
  387: 		push @files,$1;
  388: 		push @filesfull,$f;
  389: 	    }
  390: 	}
  391: 	# render starting HTML formatting elements
  392: 	if (@files) {
  393: 	    $description.=<<END;
  394: \t# $d $dirdescription
  395: END
  396:         }
  397: 	if (@files) {
  398:             foreach my $i (0..$#files) {
  399: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  400: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  401: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  402: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  403: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  404: 		my $rot=$filesfull[$i];
  405: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  406: 		$description.=<<END if $category ne 'symbolic link';
  407: \tinstall -m $devchmod \$(SOURCE)/$filesfull[$i] \$(ROOT)/$rot
  408: END
  409: 	    }
  410: 	}
  411:     }
  412:     $description.=<<END;
  413: 
  414: END
  415:     return $description;
  416: }
  417: 
  418: # ------ Installation commands for a Makefile used only by a rpm -ba invocation
  419: sub make_links_LCMakefile_segment {
  420:     my ($dirs)=@_;
  421:     my $description=<<END;
  422: links:
  423: END
  424:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  425:     foreach my $d (@$dirs) {
  426: 	# find files that are contained in this directory
  427: 	my @files;
  428: 	my @filesfull;
  429: 	foreach my $f (@allfiles) {
  430: 	    if ($f=~/^$d\/([^\/]+)$/) {
  431: 		push @files,$1;
  432: 		push @filesfull,$f;
  433: 	    }
  434: 	}
  435: 	# render starting HTML formatting elements
  436: 	if (@files) {
  437:             foreach my $i (0..$#files) {
  438: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  439: 		my $linkto=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'LINKTO'};
  440: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  441: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  442: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  443: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  444: 		$description.=<<END if $category eq 'symbolic link';
  445: \tln -s /$linkto \$(ROOT)/$filesfull[$i]
  446: END
  447: 	    }
  448: 	}
  449:     }
  450:     $description.=<<END;
  451: 
  452: END
  453:     return $description;
  454: }
  455: 
  456: # --------------------------------- Installation commands to install directories
  457: sub make_directory_install_segment {
  458:     my ($dirs)=@_;
  459:     my $description=<<END;
  460: directories:
  461: END
  462:     foreach my $d (@$dirs) {
  463: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  464: 	my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  465: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  466: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  467: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  468: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  469: 	my ($owner,$group)=split(/\:/,$devchown);
  470: 	my $own=$devchown; $own=~s/\:/\,/;
  471: 	$description.=<<END;
  472: \tinstall -o $owner -g $group -m $devchmod -d \$(TARGET)/$d
  473: END
  474:     }
  475:     $description.=<<END;
  476: 
  477: END
  478:     return $description;
  479: }
  480: 
  481: # ------------------------------------------------------ Commands to build files
  482: sub make_files_build_segment {
  483:     my ($dirs)=@_;
  484:     my $description;
  485:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  486:     my $tab="\t";
  487:     my $sources="all: ";
  488:     foreach my $d (@$dirs) {
  489: 	# set other values
  490: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  491: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  492: 	# find files that are contained in this directory
  493: 	my @files;
  494: 	my @filesfull;
  495: 	foreach my $f (@allfiles) {
  496: 	    if ($f=~/^$d\/([^\/]+)$/) {
  497: 		push @files,$1;
  498: 		push @filesfull,$f;
  499: 	    }
  500: 	}
  501: 	if (@files) {
  502:             foreach my $i (0..$#files) {
  503: 		# if has build information, output appropriate something
  504: 		my $build=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'BUILD'};
  505: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  506: 		$build=~s/^\s+//; $build=~s/\s+$//;
  507: 		if ($build) {
  508: 		    my $dependencies=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'DEPENDENCIES'};
  509: 		    my $source2=$source;
  510: 		    $source2=~s/^[^\/]+\///;
  511:  		    $source2="../" . $source2;
  512: 		    $sources.="$source2 ";
  513: 		    my $directory=$build;
  514: 		    $directory=~s/^[^\/]+\///;
  515: 		    $directory=~s/([^\/]+)$//;
  516:  		    $directory="../" . $directory;
  517: 		    my $buildfile=$1;
  518: 		    my $sdir=$source;
  519: 		    $sdir=~s/^[^\/]+\///;
  520: 		    $sdir=~s/([^\/]+)$//;
  521:  		    $sdir="../" . $sdir;
  522: 		    $dependencies=~s/\s+$//;
  523: 		    my $depstat="";
  524: 		    if ($dependencies=~s/\s+\[ALWAYS_RUN_BUILD_COMMAND\]//) {
  525: 			$depstat=" alwaysrun";
  526: 		    }
  527: 		    $dependencies=~s/\s+/ $sdir/gs;
  528: 		    $description.=<<END;
  529: $source2: $dependencies$depstat
  530: ${tab}cd $directory; sh ./$buildfile
  531: 
  532: END
  533: 		}
  534: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  535: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  536: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  537: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  538: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  539: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  540: 		my $rot=$filesfull[$i];
  541: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  542: #		$description.=<<END if $category ne 'symbolic link';
  543: #\tinstall -o $owner -g $group -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
  544: #END
  545: 	    }
  546: 	}
  547:     }
  548:     $description.=<<END;
  549: alwaysrun:
  550: 
  551: END
  552:     $sources.="\n\n";
  553:     return ($sources . $description);
  554: }
  555: 
  556: # --------------------------------------- Installation commands to install files
  557: sub make_files_install_segment {
  558:     my ($dirs)=@_;
  559:     my $description=<<END;
  560: files:
  561: END
  562:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  563:     foreach my $d (@$dirs) {
  564: 	# set other values
  565: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  566: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  567: 	# find files that are contained in this directory
  568: 	my @files;
  569: 	my @filesfull;
  570: 	foreach my $f (@allfiles) {
  571: 	    if ($f=~/^$d\/([^\/]+)$/) {
  572: 		push @files,$1;
  573: 		push @filesfull,$f;
  574: 	    }
  575: 	}
  576: 	# render starting HTML formatting elements
  577: 	if (@files) {
  578: 	    $description.=<<END;
  579: \t# $d $dirdescription
  580: END
  581:         }
  582: 	if (@files) {
  583:             foreach my $i (0..$#files) {
  584: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  585: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  586: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  587: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  588: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  589: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  590: 		my $rot=$filesfull[$i];
  591: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  592: 		my ($owner,$group)=split(/\:/,$devchown);
  593: 		if ($category ne 'conf') {
  594: 		    $description.=<<END if $category ne 'symbolic link';
  595: \tinstall -o $owner -g $group -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
  596: END
  597:                 }
  598: 	    }
  599: 	}
  600:     }
  601:     $description.=<<END;
  602: 
  603: END
  604:     return $description;
  605: }
  606: 
  607: # ------ Installation commands to install configuration files (and make backups)
  608: sub make_files_configinstall_segment {
  609:     my ($dirs)=@_;
  610:     my $description=<<END;
  611: configfiles:
  612: END
  613:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  614:     foreach my $d (@$dirs) {
  615: 	# set other values
  616: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  617: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  618: 	# find files that are contained in this directory
  619: 	my @files;
  620: 	my @filesfull;
  621: 	foreach my $f (@allfiles) {
  622: 	    if ($f=~/^$d\/([^\/]+)$/) {
  623: 		push @files,$1;
  624: 		push @filesfull,$f;
  625: 	    }
  626: 	}
  627: 	# render starting HTML formatting elements
  628: 	if (@files) {
  629: 	    $description.=<<END;
  630: \t# $d $dirdescription
  631: END
  632:         }
  633: 	if (@files) {
  634:             foreach my $i (0..$#files) {
  635: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  636: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  637: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  638: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  639: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  640: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  641: 		my $rot=$filesfull[$i];
  642: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  643: 		my ($owner,$group)=split(/\:/,$devchown);
  644: 		if ($category eq 'conf') {
  645: 		    $description.=<<END;
  646: \tinstall -b -S `date +'.\%Y\%m\%d\%H\%M\%S'` -o $owner -g $group -m $devchmod \$(SOURCE)/$source \$(TARGET)/$rot
  647: END
  648:                 }
  649: 	    }
  650: 	}
  651:     }
  652:     $description.=<<END;
  653: 
  654: END
  655:     return $description;
  656: }
  657: 
  658: # ------ Commands to enforce configuration file permissions
  659: sub make_files_configpermissions_segment {
  660:     my ($dirs)=@_;
  661:     my $description=<<END;
  662: configpermissions:
  663: END
  664:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  665:     foreach my $d (@$dirs) {
  666: 	# set other values
  667: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  668: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  669: 	# find files that are contained in this directory
  670: 	my @files;
  671: 	my @filesfull;
  672: 	foreach my $f (@allfiles) {
  673: 	    if ($f=~/^$d\/([^\/]+)$/) {
  674: 		push @files,$1;
  675: 		push @filesfull,$f;
  676: 	    }
  677: 	}
  678: 	# render starting HTML formatting elements
  679: 	if (@files) {
  680: 	    $description.=<<END;
  681: \t# $d $dirdescription
  682: END
  683:         }
  684: 	if (@files) {
  685:             foreach my $i (0..$#files) {
  686: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  687: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
  688: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  689: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  690: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  691: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  692: 		my $rot=$filesfull[$i];
  693: 		$rot=~s/[^\/]+$/\./ if $rot=~/\*/;
  694: 		my ($owner,$group)=split(/\:/,$devchown);
  695: 		if ($category eq 'conf') {
  696: 		    $description.=<<END;
  697: \tchmod $devchmod \$(TARGET)/$rot
  698: \tchown $devchown \$(TARGET)/$rot
  699: END
  700:                 }
  701: 	    }
  702: 	}
  703:     }
  704:     $description.=<<END;
  705: 
  706: END
  707:     return $description;
  708: }
  709: 
  710: # ------------------------------ Installation commands to install symbolic links
  711: sub make_links_install_segment {
  712:     my ($dirs)=@_;
  713:     my $description=<<END;
  714: links:
  715: END
  716:     chop $description;
  717:     my $description2;
  718:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  719:     foreach my $d (@$dirs) {
  720: 	# find files that are contained in this directory
  721: 	my @files;
  722: 	my @filesfull;
  723: 	foreach my $f (@allfiles) {
  724: 	    if ($f=~/^$d\/([^\/]+)$/) {
  725: 		push @files,$1;
  726: 		push @filesfull,$f;
  727: 	    }
  728: 	}
  729: 	# render starting HTML formatting elements
  730: 	if (@files) {
  731:             foreach my $i (0..$#files) {
  732: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  733: 		my $linkto=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'LINKTO'};
  734: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  735: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  736: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  737: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  738: 		if ($category eq 'symbolic link') {
  739: 		    $description.=" \$(TARGET)/$filesfull[$i]";
  740: 		    $description2.=<<END;
  741: \$(TARGET)/$filesfull[$i]:
  742: \tln -s /$linkto \$(TARGET)/$filesfull[$i]
  743: 
  744: END
  745:                 }
  746: 	    }
  747: 	}
  748:     }
  749:     $description.=<<END;
  750: 
  751: END
  752:     $description.=$description2;
  753:     return $description;
  754: }
  755: 
  756: # --------------------------------------------------------- Make RPM .spec block
  757: sub make_rpm_spec_block {
  758:     my $pwd=`pwd`; chop $pwd;
  759:     my $buildroot="$pwd/LON-CAPA-BuildRoot";
  760:     my $source=$info{'RPM'}{'Name'} . "-" . $info{'RPM'}{'Version'} . '.tar.gz';
  761:     my $description=<<END;
  762: Summary: $info{'RPM'}{'Summary'}
  763: Name: $info{'RPM'}{'Name'}
  764: Version: $info{'RPM'}{'Version'}
  765: Release: $info{'RPM'}{'Release'}
  766: Vendor: $info{'RPM'}{'Vendor'} 
  767: BuildRoot: $buildroot
  768: Copyright: $info{'RPM'}{'Copyright'}
  769: Group: $info{'RPM'}{'Group'}
  770: Source: $source
  771: AutoReqProv: $info{'RPM'}{'AutoReqProv'}
  772: \%description
  773: $info{'RPM'}{'description'}
  774: 
  775: END
  776:     return $description;
  777: }
  778: 
  779: # --------------------------------------------------- Make RPM build .spec block
  780: sub make_rpm_build_block {
  781:     my $pwd=`pwd`; chop $pwd;
  782:     my $buildroot="$pwd/LON-CAPA-BuildRoot";
  783:     my $sourceroot="$pwd/LON-CAPA-SourceRoot";
  784:     my $description=<<END;
  785: 
  786: \%prep
  787: \%setup
  788: 
  789: \%build
  790: rm -Rf "$buildroot"
  791: 
  792: \%install
  793: make -f LCMakefile ROOT="\$RPM_BUILD_ROOT" SOURCE="$sourceroot" directories
  794: make -f LCMakefile ROOT="\$RPM_BUILD_ROOT" SOURCE="$sourceroot" files
  795: make -f LCMakefile ROOT="\$RPM_BUILD_ROOT" SOURCE="$sourceroot" links
  796: 
  797: \%pre
  798: $info{'RPM'}{'pre'}
  799: 
  800: \%post
  801: \%postun
  802: 
  803: \%files
  804: # \%doc README COPYING ChangeLog LICENSE
  805: END
  806:     return $description;
  807: }
  808: 
  809: # ------------------------------------- Make directory structure RPM .spec block
  810: sub make_directory_structure_spec_block {
  811:     my ($dirs)=@_;
  812:     foreach my $d (@$dirs) {
  813: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  814: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  815: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  816: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  817: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  818: 	my $own=$devchown; $own=~s/\:/\,/;
  819: 	$description.=<<END;
  820: \%dir \%attr($devchmod,$own) /$d
  821: END
  822:     }
  823:     return $description;
  824: }
  825: 
  826: # ---------------------------- Make directory and file structure RPM .spec block
  827: sub make_directory_and_file_structure_spec_block {
  828:     my ($dirs)=@_;
  829:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  830:     foreach my $d (@$dirs) {
  831: 	# set other values
  832: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
  833: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
  834: 	# find files that are contained in this directory
  835: 	my @files;
  836: 	my @filesfull;
  837: 	foreach my $f (@allfiles) {
  838: 	    if ($f=~/^$d\/([^\/]+)$/) {
  839: 		push @files,$1;
  840: 		push @filesfull,$f;
  841: 	    }
  842: 	}
  843: 	# render starting HTML formatting elements
  844: 	if (@files) {
  845: 	    $description.=<<END;
  846: # $d $dirdescription
  847: END
  848:         }
  849: 	if (@files) {
  850:             foreach my $i (0..$#files) {
  851: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
  852: 		my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  853: 		my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  854: 		my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  855: 		my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  856: 		my $own=$devchown; $own=~s/\:/\,/;
  857: 		my $config="";
  858: 		$config="\%config " if $category eq 'conf';
  859: 		$devchmod='-' if $category eq 'symbolic link';
  860: 		$description.=<<END;
  861: $config\%attr($devchmod,$own) /$filesfull[$i]
  862: END
  863: 	    }
  864: 	}
  865:     }
  866:     return $description;
  867: }
  868: 
  869: # ----------------------------------------------------------- End RPM .spec page
  870: sub end_spec_page {
  871: }
  872: 
  873: # ------------------------------------------------------- Begin description page
  874: sub begin_description_page {
  875:     my $description=<<END;
  876: <HTML>
  877: <HEAD>
  878: <TITLE>LON-CAPA Software Description Page ($distribution, $date)</TITLE>
  879: </HEAD>
  880: <BODY>
  881: <FONT SIZE=+2>LON-CAPA Software Description Page ($distribution, $date)</FONT>
  882: <BR>Michigan State University
  883: <BR>Learning Online with CAPA
  884: <BR>Contact korte\@lon-capa.org
  885: <UL>
  886: <LI>About this file
  887: <LI>Software Package Description
  888: <LI>Directory Structure
  889: <LI>File Type Ownership and Permissions
  890: <LI>File and Directory Structure
  891: </UL>
  892: <FONT SIZE=+2>About this file</FONT>
  893: <P>
  894: This file is generated dynamically by <TT>parse.pl</TT> as
  895: part of a development compilation process.  See 
  896: http://install.lon-capa.org/compile/index.html for more
  897: information.
  898: </P>
  899: END
  900:     return $description;
  901: }
  902: 
  903: # ------------------------------------------------- End description page
  904: sub end_description_page {
  905:     my $description=<<END;
  906: <HR>
  907: <FONT SIZE=-1>LON-CAPA Software Development Team</FONT>
  908: </BODY>
  909: </HTML>
  910: END
  911:     return $description;
  912: }
  913: 
  914: # ------------------------------------------------- Make RPM description block
  915: sub make_rpm_description_block {
  916:     my $description=<<END;
  917: <FONT SIZE=+2>Rolled in a RedHat 6.2 RPM, $date</FONT>
  918: <P>
  919: <TABLE BGCOLOR=#FFFFFF BORDER=0 CELLPADDING=10 CELLSPACING=0>
  920: <TR><TD>
  921: <PRE>
  922: Name        : $info{'RPM'}{'Name'}
  923: Version     : $info{'RPM'}{'Version'}
  924: Vendor      : $info{'RPM'}{'Vendor'} 
  925: Release     : $info{'RPM'}{'Release'}                             
  926: Build Host  : $buildhost
  927: Group       : $info{'RPM'}{'Group'}
  928: License     : $info{'RPM'}{'Copyright'}
  929: Summary     : $info{'RPM'}{'Summary'}
  930: Description : 
  931: $info{'RPM'}{'description'}
  932: </PRE>
  933: </TD></TR>
  934: </TABLE>
  935: </P>
  936: END
  937:     return $description;
  938: }
  939: 
  940: # ----------------------------------------------- Determine directory structure
  941: sub determine_directory_structure {
  942:     my @directories=keys %{$info{'DIRECTORY'}{$distribution}};
  943:     return (sort @directories);
  944: }
  945: 
  946: 
  947: # ---------------------------------- Make directory structure description block
  948: sub make_directory_structure_description_block {
  949:     my ($dirs)=@_;
  950:     my $description=<<END;
  951: <FONT SIZE=+2>Directory Structure Description, $date</FONT>
  952: <P>
  953: The directory structure description below shows only those
  954: directories which either contain LON-CAPA specific files
  955: or normally do not exist on a RedHat Linux system (and
  956: must be generated to allow proper placement of files
  957: during LON-CAPA run-time operation).
  958: </P>
  959: <P>
  960: <TABLE BORDER=1 CELLPADDING=3 CELLSPACING=0>
  961: END
  962:     my $maxcount=0;
  963:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
  964:     my %diraccount; # hash to track which directories are accounted for
  965:     foreach my $file (@allfiles) {
  966: 	$file=~/^(.*)\/([^\/]+)$/;
  967: 	$diraccount{$1}=1;
  968:     }
  969:     foreach my $d (@$dirs) {
  970:         my (@matches)=($d=~/\//g);
  971: 	my $count=scalar(@matches);
  972: 	$maxcount=$count if $count>$maxcount;
  973: 	delete $diraccount{$d};
  974:     }
  975:     $description.=<<END;
  976: <TR>
  977: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Category</TH>
  978: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Permissions</TH>
  979: <TH ALIGN=LEFT BGCOLOR=#FFFFFF><FONT COLOR=#FF0000>Development<BR>Permissions</FONT></TH>
  980: END
  981:     $description.="<TH ALIGN=LEFT BGCOLOR=#FFFFFF COLSPAN=".($maxcount+1).">Directory Path</TH>\n";
  982:     if (keys %diraccount) {
  983: 	$description.= "<TR><TD ALIGN=LEFT BGCOLOR=#FFFFFF COLSPAN=".($maxcount+4)."><I><PRE>Directories that are unaccounted for: \n";
  984: 	foreach my $d (keys %diraccount) {
  985: 	    $description.="$d\n";
  986: 	}
  987: 	$description.="</PRE></I></TH></TR>\n";
  988:     }
  989:     foreach my $d (@$dirs) {
  990: 	my $dtable=$d;
  991: 	$dtable=~s/\//\<\/TD\>\<TD\>/g;
  992: 	my $category=$info{'DIRECTORY'}{$distribution}{$d}{'CATEGORY'};
  993: 	my $chown=$info{'OWNERSHIP'}{$category}{'CHOWN'};
  994: 	my $chmod=$info{'OWNERSHIP'}{$category}{'CHMOD'};
  995: 	my $devchown=$info{'DEVOWNERSHIP'}{$category}{'CHOWN'};
  996: 	my $devchmod=$info{'DEVOWNERSHIP'}{$category}{'CHMOD'};
  997: 	$description.=<<END;
  998: <TR>
  999: <TD BGCOLOR=#FFFFFF>$category</TD>
 1000: <TD BGCOLOR=#FFFFFF><TT>$chmod $chown</TT></TD>
 1001: <TD BGCOLOR=#FFFFFF><FONT COLOR=#FF0000><TT>$devchmod $devchown</TT></FONT></TD>
 1002: <TD>
 1003: $dtable
 1004: </TD>
 1005: </TR>
 1006: END
 1007:     }
 1008:     $description.=<<END;
 1009: </TABLE>
 1010: </P>
 1011: END
 1012:     return $description;
 1013: }
 1014: 
 1015: # ------------------- Make file type ownership and permissions description block
 1016: sub make_file_type_ownership_and_permissions_description_block {
 1017:     my $description=<<END;
 1018: <FONT SIZE=+2>File Type Ownership and Permissions Descriptions, $date</FONT>
 1019: <P>
 1020: This table shows what permissions and ownership settings correspond
 1021: to each kind of file type.
 1022: </P>
 1023: <P>
 1024: <TABLE BORDER=1 CELLPADDING=5 WIDTH=60%>
 1025: <TR>
 1026: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Icon</TH>
 1027: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Type</TH>
 1028: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Permissions</TH>
 1029: <TH ALIGN=LEFT BGCOLOR=#FFFFFF>Development Permissions</TH>
 1030: </TR>
 1031: END
 1032:     foreach my $type (keys %{$info{'OWNERSHIP'}}) {
 1033: 	if (defined($fcm{$type})) {
 1034: 	    my $chmod=$info{'OWNERSHIP'}{$type}{'CHMOD'};
 1035: 	    my $chown=$info{'OWNERSHIP'}{$type}{'CHOWN'};
 1036: 	    my $devchmod=$info{'DEVOWNERSHIP'}{$type}{'CHMOD'};
 1037: 	    my $devchown=$info{'DEVOWNERSHIP'}{$type}{'CHOWN'};
 1038: 	    $description.=<<END;
 1039: <TR>
 1040: <TD><IMG SRC="$fcm{$type}.gif" ALT="$type"></TD>
 1041: <TD>$type</TD>
 1042: <TD><TT>$chmod $chown</TT></TD>
 1043: <TD><TT>$devchmod $devchown</TT></TD>
 1044: </TR>
 1045: END
 1046:         }
 1047:     }
 1048:     $description.=<<END;
 1049: </TABLE>
 1050: </P>
 1051: END
 1052: }
 1053: 
 1054: # ------------------------- Make directory and file structure description block
 1055: sub make_directory_and_file_structure_description_block {
 1056:     my ($dirs)=@_;
 1057:     my $description=<<END;
 1058: <FONT SIZE=+2>Directory and File Structure Description, $date</FONT>
 1059: <P>
 1060: The icons on the left column correspond to the file type
 1061: specified in the second column.  The last column "Notes" shows compilation,
 1062: dependency, and configuration information.  The CVS location
 1063: shows the location of the binary source file (if applicable) needed to
 1064: be copied to the target.  If the binary source file is not at
 1065: the specified location, then the text is shown in 
 1066: <FONT COLOR=#FF0000>red</FONT>.
 1067: </P>
 1068: <P>
 1069: <TABLE BORDER=1 CELLPADDING=5 WIDTH=500>
 1070: END
 1071:     my $counter=0;
 1072:     my @colorindex=("#80FF80","#80FFFF","#FFFF80");
 1073:     my @allfiles=keys %{$info{'LOCATION'}{$distribution}};
 1074:     foreach my $d (@$dirs) {
 1075: 	# set color
 1076: 	my $color=$colorindex[$counter%3];
 1077: 	# set other values
 1078: 	my $dirdescription=$info{'DIRECTORY'}{$distribution}{$d}{'DESCRIPTION'};
 1079: 	$dirdescription="(" . $dirdescription . ")" if $dirdescription;
 1080: 	# find subdirectories that are contained in this directory
 1081: 	my @subdirs;
 1082: 	foreach my $d2 (@$dirs) {
 1083: 	    if ($d2=~/^$d\/([^\/]+)$/) {
 1084: 		push @subdirs,$1;
 1085: 	    }
 1086: 	}
 1087: 	# find files that are contained in this directory
 1088: 	my @files;
 1089: 	my @filesfull;
 1090: 	foreach my $f (@allfiles) {
 1091: 	    if ($f=~/^$d\/([^\/]+)$/) {
 1092: 		push @files,$1;
 1093: 		push @filesfull,$f;
 1094: 	    }
 1095: 	}
 1096: 	# render starting HTML formatting elements
 1097: 	if (@subdirs || @files) {
 1098: 	    my $subdirstring="<BR>* Relevant subdirectories: " . join(", ",@subdirs) if @subdirs;
 1099: 	    $description.=<<END;
 1100: <TR><TD BGCOLOR=#000000 COLSPAN=6><FONT COLOR=$color><IMG SRC="directory.gif" ALT="directory">DIRECTORY -- $d $dirdescription
 1101: $subdirstring</FONT></TD></TR>
 1102: END
 1103:         }
 1104: 	else {
 1105: 	    $description.=<<END;
 1106: <TR><TD BGCOLOR=#000000 COLSPAN=6><FONT COLOR=$color><IMG SRC="emptydirectory.gif" ALT="empty directory">EMPTY DIRECTORY - $d $dirdescription</FONT></TD></TR>
 1107: END
 1108:         }
 1109: 	if (@files) {
 1110: 	    $description.=<<END;
 1111: <TR>
 1112: <TH BGCOLOR=$color ALIGN=LEFT COLSPAN=2>Type</TH>
 1113: <TH BGCOLOR=$color ALIGN=LEFT>File Name</TH>
 1114: <TH BGCOLOR=$color ALIGN=LEFT>Function</TH>
 1115: <TH BGCOLOR=$color ALIGN=LEFT>CVS Location</TH>
 1116: <TH BGCOLOR=$color ALIGN=LEFT>Notes</TH>
 1117: </TR>
 1118: END
 1119:             foreach my $i (0..$#files) {
 1120: 		my $category=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'CATEGORY'};
 1121: 		my $fdescription=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'DESCRIPTION'};
 1122: 		my $source=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'SOURCE'};
 1123: 		my $note=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'NOTE'};
 1124: 		$note.="<BR>" if $note;
 1125: 		my $listing=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'FILES'};
 1126: 		my @E=split(/\s+/,$listing);
 1127: 		$source=~/(.*)\/[^\/]+$/;
 1128: 		my $sd=$1;
 1129: 		my $eflag=0;
 1130: 		foreach my $e (@E) {
 1131: 		    unless (-e "../../$sd/$e") {
 1132: 			$e="<FONT COLOR=#FF0000>$e</FONT>";
 1133: 			$eflag=1;
 1134: 		    }
 1135: 		}
 1136: 		$listing=join("\n",@E);
 1137: 		$listing="<B>listing</B><BR><FONT SIZE=-2>$listing</FONT>" if $listing;
 1138: 		$listing.="<BR>" if $listing;
 1139: 		my $build=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'BUILD'};
 1140: 		$build="<B>build</B><BR>$build" if $build;
 1141: 		$build.="<BR>" if $build;
 1142: 		my $dependencies=$info{'LOCATION'}{$distribution}{$filesfull[$i]}{'DEPENDENCIES'};
 1143: 		$dependencies="<B>dependencies</B><BR>$dependencies" if $dependencies;
 1144: 		$dependencies.="<BR>" if $dependencies;
 1145: 		unless (-e "../../$source") {
 1146: 		    $source=~/([^\/]+)$/;
 1147: 		    my $s=$1;
 1148: 		    if ($source!~/\*/) {
 1149: 			$source="<FONT COLOR=#FF0000>$source</FONT>";
 1150: 		    }
 1151: 		    elsif ($eflag) {
 1152: 			$source="<FONT COLOR=#FF0000>$source</FONT>";
 1153: 		    }
 1154: 		}
 1155: 		$description.=<<END;
 1156: <TR>
 1157: <TD BGCOLOR=#A0A0A0><IMG SRC="$fcm{$category}.gif" ALT="$category"></TD>
 1158: <TD BGCOLOR=$color>$category</TD>
 1159: <TD BGCOLOR=$color>$files[$i]</TD>
 1160: <TD BGCOLOR=$color>$fdescription&nbsp;</TD>
 1161: <TD BGCOLOR=$color>$source</TD>
 1162: <TD BGCOLOR=$color>$note$listing$build$dependencies&nbsp;</TD>
 1163: </TR>
 1164: END
 1165: 	    }
 1166: 	}
 1167: 	$counter++;
 1168:     }
 1169:     $description.=<<END;
 1170: </TABLE>
 1171: </P>
 1172: END
 1173:     return $description;
 1174: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>