File:  [LON-CAPA] / loncom / build / lpml_parse.pl
Revision 1.53: download - view: text, annotated - select for diffs
Fri Dec 9 20:41:35 2005 UTC (18 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: version_2_3_1, version_2_3_0, version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_X, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_0_99_1, HEAD
- updating lpml_parse so there can be an install time script run
- switch the jsMath-font installtion to take place during install bnot build
- update the plugins dir creation
- gradesubmission/.pl was trying to install itself in a not existant location

    1: #!/usr/bin/perl
    2: 
    3: # -------------------------------------------------------- Documentation notice
    4: # Run "perldoc ./lpml_parse.pl" in order to best view the software
    5: # documentation internalized in this program.
    6: 
    7: # --------------------------------------------------------- Distribution notice
    8: # This script is distributed with the LPML software project available at
    9: # http://lpml.sourceforge.net
   10: 
   11: # --------------------------------------------------------- License Information
   12: # The LearningOnline Network with CAPA
   13: # lpml_parse.pl - Linux Packaging Markup Language parser
   14: #
   15: # $Id: lpml_parse.pl,v 1.53 2005/12/09 20:41:35 albertel Exp $
   16: #
   17: # Written by Scott Harrison, codeharrison@yahoo.com
   18: #
   19: # Copyright Michigan State University Board of Trustees
   20: #
   21: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   22: #
   23: # LON-CAPA is free software; you can redistribute it and/or modify
   24: # it under the terms of the GNU General Public License as published by
   25: # the Free Software Foundation; either version 2 of the License, or
   26: # (at your option) any later version.
   27: #
   28: # LON-CAPA is distributed in the hope that it will be useful,
   29: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   30: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   31: # GNU General Public License for more details.
   32: #
   33: # You should have received a copy of the GNU General Public License
   34: # along with LON-CAPA; if not, write to the Free Software
   35: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   36: #
   37: # /home/httpd/html/adm/gpl.txt
   38: #
   39: # http://www.lon-capa.org/
   40: #
   41: # YEAR=2001
   42: # May 2001
   43: # 06/19/2001,06/20,06/24 - Scott Harrison
   44: # 9/5/2001,9/6,9/7,9/8 - Scott Harrison
   45: # 9/17,9/18 - Scott Harrison
   46: # 11/4,11/5,11/6,11/7,11/16,11/17 - Scott Harrison
   47: # 12/2,12/3,12/4,12/5,12/6,12/13,12/19,12/29 - Scott Harrison
   48: # YEAR=2002
   49: # 1/8,1/9,1/29,1/31,2/5,3/21,4/8,4/12 - Scott Harrison
   50: # 4/21,4/26,5/19,5/23,10/13 - Scott Harrison
   51: #
   52: ###
   53: 
   54: ###############################################################################
   55: ##                                                                           ##
   56: ## ORGANIZATION OF THIS PERL SCRIPT                                          ##
   57: ## 1. Notes                                                                  ##
   58: ## 2. Get command line arguments                                             ##
   59: ## 3. First pass through (grab distribution-specific information)            ##
   60: ## 4. Second pass through (parse out what is not necessary)                  ##
   61: ## 5. Third pass through (translate markup according to specified mode)      ##
   62: ## 6. Functions (most all just format contents of different markup tags)     ##
   63: ## 7. POD (plain old documentation, CPAN style)                              ##
   64: ##                                                                           ##
   65: ###############################################################################
   66: 
   67: # ----------------------------------------------------------------------- Notes
   68: #
   69: # I am using a multiple pass-through approach to parsing
   70: # the lpml file.  This saves memory and makes sure the server
   71: # will never be overloaded.
   72: #
   73: # This is meant to parse files meeting the lpml document type.
   74: # See lpml.dtd.  LPML=Linux Packaging Markup Language.
   75: 
   76: use HTML::TokeParser;
   77: 
   78: my $usage=<<END;
   79: **** ERROR ERROR ERROR ERROR ****
   80: Usage is for lpml file to come in through standard input.
   81: 1st argument is the mode of parsing:
   82:     install,configinstall,build,rpm,dpkg,htmldoc,textdoc,status
   83: 2nd argument is the category permissions to use:
   84:     typical choices: runtime,development
   85: 3rd argument is the distribution:
   86:     typical choices: default,redhat6.2,debian2.2,redhat7
   87: 4th argument is to manually specify a sourceroot.
   88: 5th argument is to manually specify a targetroot.
   89: 
   90: Only the 1st argument is mandatory for the program to run.
   91: 
   92: Example:
   93: 
   94: cat ../../doc/loncapafiles.lpml |\\
   95: perl lpml_parse.pl html development default /home/sherbert/loncapa /tmp/install
   96: 
   97: For more information, type "perldoc lpml_parse.pl".
   98: END
   99: 
  100: # ------------------------------------------------- Grab command line arguments
  101: 
  102: my $mode='';
  103: if (@ARGV==5) {
  104:     $mode = shift @ARGV;
  105: }
  106: else {
  107:     @ARGV=();shift @ARGV;
  108:     while(<>){} # throw away the input to avoid broken pipes
  109:     print $usage;
  110:     exit -1; # exit with error status
  111: }
  112: 
  113: my $categorytype='';
  114: if (@ARGV) {
  115:     $categorytype = shift @ARGV;
  116: }
  117: 
  118: my $dist='';
  119: if (@ARGV) {
  120:     $dist = shift @ARGV;
  121: }
  122: 
  123: my $targetroot='';
  124: my $sourceroot='';
  125: my $targetrootarg='';
  126: my $sourcerootarg='';
  127: if (@ARGV) {
  128:     $sourceroot = shift @ARGV;
  129: }
  130: if (@ARGV) {
  131:     $targetroot = shift @ARGV;
  132: }
  133: $sourceroot=~s/\/$//; # remove trailing directory slash
  134: $targetroot=~s/\/$//; # remove trailing directory slash
  135: $sourcerootarg=$sourceroot;
  136: $targetrootarg=$targetroot;
  137: 
  138: my $logcmd='| tee -a WARNINGS';
  139: 
  140: my $invocation; # Record how the program was invoked
  141: # --------------------------------------------------- Record program invocation
  142: if ($mode eq 'install' or $mode eq 'configinstall' or $mode eq 'build') {
  143:     $invocation=(<<END);
  144: # Invocation: STDINPUT | lpml_parse.pl
  145: #             1st argument (mode) is: $mode
  146: #             2nd argument (category type) is: $categorytype
  147: #             3rd argument (distribution) is: $dist
  148: #             4th argument (sourceroot) is: described below
  149: #             5th argument (targetroot) is: described below
  150: END
  151: }
  152: 
  153: # -------------------------- Start first pass through (just gather information)
  154: my @parsecontents=<>;
  155: my $parsestring=join('',@parsecontents);
  156: 
  157: # Need to make a pass through and figure out what defaults are
  158: # overrided.  Top-down overriding strategy (tree leaves don't know
  159: # about distant tree leaves).
  160: 
  161: my @hierarchy;
  162: $hierarchy[0]=0;
  163: my $hloc=0;
  164: my $token;
  165: $parser = HTML::TokeParser->new(\$parsestring) or
  166:     die('can\'t create TokeParser object');
  167: $parser->xml_mode('1');
  168: my %setting;
  169: 
  170: # Values for the %setting hash
  171: my $defaultset=1; # a default setting exists for a key
  172: my $distset=2; # a distribution setting exists for a key
  173:                # (overrides default setting)
  174: 
  175: my $key=''; # this is a unique key identifier (the token name with its
  176:             # coordinates inside the hierarchy)
  177: while ($token = $parser->get_token()) { # navigate through $parsestring
  178:     if ($token->[0] eq 'S') {
  179: 	$hloc++;
  180: 	$hierarchy[$hloc]++;
  181: 	$key=$token->[1].join(',',@hierarchy[0..($hloc-1)]);
  182: 	my $thisdist=' '.$token->[2]{'dist'}.' ';
  183: 	if ($thisdist eq ' default ') {
  184: 	    $setting{$key}=$defaultset;
  185: 	}
  186: 	elsif (length($dist)>0 &&
  187: 	       $setting{$key}==$defaultset &&
  188: 	       $thisdist=~/\s$dist\s/) {
  189: 	    $setting{$key}=$distset;
  190:                    # disregard default setting for this key if
  191:                    # there is a directly requested distribution match
  192:                    # (in other words, there must first be a default
  193: 	           # setting for a key in order for it to be overridden)
  194: 	}
  195:     }
  196:     if ($token->[0] eq 'E') {
  197: 	$hloc--;
  198:     }
  199: }
  200: 
  201: # - Start second pass through (clean up the string to allow for easy rendering)
  202: 
  203: # The string is cleaned up so that there is no white-space surrounding any
  204: # XML tag.  White-space inside text 'T' elements is preserved.
  205: 
  206: # Clear up memory
  207: undef($hloc);
  208: undef(@hierarchy);
  209: undef($parser);
  210: $hierarchy[0]=0; # initialize hierarchy
  211: $parser = HTML::TokeParser->new(\$parsestring) or
  212:     die('can\'t create TokeParser object');
  213: $parser->xml_mode('1');
  214: my $cleanstring; # contains the output of the second step
  215: while ($token = $parser->get_token()) { # navigate through $parsestring
  216:     if ($token->[0] eq 'S') { # a start tag
  217: 	$hloc++;
  218: 	$hierarchy[$hloc]++;
  219: 	$key=$token->[1].join(',',@hierarchy[0..($hloc-1)]);
  220: 
  221: 	# Surround tagdist (the dist attribute of an XML tag)
  222: 	# with white-space to allow for uniform searching a few
  223: 	# lines below here.
  224: 	my $tagdist=' '.$token->[2]{'dist'}.' ';
  225: 
  226: 	# This conditional clause is set up to ignore two sets
  227: 	# of invalid conditions before accepting entry into
  228: 	# $cleanstring.
  229: 
  230: 	# Condition #1: Ignore this part of the string if the tag 
  231: 	# has a superior distribution-specific setting and the tag
  232: 	# being evaluated has a dist setting something other than
  233: 	# blank or $dist.
  234: 	if ($setting{$key}==$distset and
  235: 	    !($tagdist eq '  ' or $tagdist =~/\s$dist\s/)) {
  236: 	    if ($token->[4]!~/\/>$/) {
  237: 		$parser->get_tag('/'.$token->[1]);
  238: 		$hloc--;
  239: 	    }
  240: 	}
  241: 	# Condition #2: Ignore this part of the string if the tag has
  242: 	# is not blank and does not equal dist and
  243: 	# either does not equal default or it has a prior $dist-specific
  244: 	# setting.
  245: 	elsif ($tagdist ne '  ' and $tagdist!~/\s$dist\s/ and
  246: 	       !($tagdist eq ' default ' and $setting{$key}!=$distset)) {
  247: 	    if ($token->[4]!~/\/>$/) {
  248: 		$parser->get_tag('/'.$token->[1]);
  249: 		$hloc--;
  250: 	    }
  251: 	}
  252: 	# In other words, output to $cleanstring if the tag is dist=default
  253: 	# or if the tag is set to dist=$dist for the first time.  And, always
  254: 	# output when dist='' is not present.
  255: 	else {
  256: 	    $cleanstring.=$token->[4];
  257: 	}
  258:     }
  259:     # Note: this loop DOES work with <tag /> style markup as well as
  260:     # <tag></tag> style markup since I always check for $token->[4] ending
  261:     # with "/>".
  262:     if ($token->[0] eq 'E') { # an end tag
  263: 	$cleanstring.=$token->[2];
  264: 	$hloc--;
  265:     }
  266:     if ($token->[0] eq 'T') { # text contents inside tags
  267: 	$cleanstring.=$token->[1];
  268:     }
  269: }
  270: $cleanstring=&trim($cleanstring);
  271: $cleanstring=~s/\>\s*\n\s*\</\>\</g;
  272: 
  273: # -------------------------------------------- Start final (third) pass through
  274: 
  275: # storage variables
  276: my $lpml;
  277: my $categories;
  278: my @categorynamelist;
  279: my $category;
  280: my $category_att_name;
  281: my $category_att_type;
  282: my $chown;
  283: my $chmod;
  284: my $abbreviation; # space-free abbreviation; esp. for image names
  285: my $rpm;
  286: my $rpmSummary;
  287: my $rpmName;
  288: my $rpmVersion;
  289: my $rpmRelease;
  290: my $rpmVendor;
  291: my $rpmBuildRoot;
  292: my $rpmCopyright;
  293: my $rpmGroup;
  294: my $rpmSource;
  295: my $rpmAutoReqProv;
  296: my $rpmdescription;
  297: my $rpmpre;
  298: my $directories;
  299: my $directory;
  300: my $targetdirs;
  301: my $targetdir;
  302: my $protectionlevel;
  303: my $categoryname;
  304: my $description;
  305: my $files;
  306: my $fileglobs;
  307: my $links;
  308: my $file;
  309: my $link;
  310: my $fileglob;
  311: my $sourcedir;
  312: my $targets;
  313: my $target;
  314: my $source;
  315: my $note;
  316: my $installscript;
  317: my $build;
  318: my $buildlink;
  319: my $commands;
  320: my $command;
  321: my $status;
  322: my $dependencies;
  323: my $dependency;
  324: my @links;
  325: my %categoryhash;
  326: my $dpathlength;
  327: my %fab; # file category abbreviation
  328: my $directory_count;
  329: my $file_count;
  330: my $link_count;
  331: my $fileglob_count;
  332: my $fileglobnames_count;
  333: my %categorycount;
  334: 
  335: my @buildall;
  336: my @buildinfo;
  337: 
  338: my @configall;
  339: 
  340: # Make new parser with distribution specific input
  341: undef $parser;
  342: $parser = HTML::TokeParser->new(\$cleanstring) or
  343:     die('can\'t create TokeParser object');
  344: $parser->xml_mode('1');
  345: 
  346: # Define handling methods for mode-dependent text rendering
  347: 
  348: $parser->{textify}={
  349:     specialnotices => \&format_specialnotices,
  350:     specialnotice => \&format_specialnotice,
  351:     targetroot => \&format_targetroot,
  352:     sourceroot => \&format_sourceroot,
  353:     categories => \&format_categories,
  354:     category => \&format_category,
  355:     abbreviation => \&format_abbreviation,
  356:     targetdir => \&format_targetdir,
  357:     protectionlevel => \&format_protectionlevel,
  358:     chown => \&format_chown,
  359:     chmod => \&format_chmod,
  360:     rpm => \&format_rpm,
  361:     rpmSummary => \&format_rpmSummary,
  362:     rpmName => \&format_rpmName,
  363:     rpmVersion => \&format_rpmVersion,
  364:     rpmRelease => \&format_rpmRelease,
  365:     rpmVendor => \&format_rpmVendor,
  366:     rpmBuildRoot => \&format_rpmBuildRoot,
  367:     rpmCopyright => \&format_rpmCopyright,
  368:     rpmGroup => \&format_rpmGroup,
  369:     rpmSource => \&format_rpmSource,
  370:     rpmAutoReqProv => \&format_rpmAutoReqProv,
  371:     rpmdescription => \&format_rpmdescription,
  372:     rpmpre => \&format_rpmpre,
  373:     rpmRequires => \&format_rpmRequires,
  374:     directories => \&format_directories,
  375:     directory => \&format_directory,
  376:     categoryname => \&format_categoryname,
  377:     description => \&format_description,
  378:     files => \&format_files,
  379:     file => \&format_file,
  380:     fileglob => \&format_fileglob,
  381:     links => \&format_links,
  382:     link => \&format_link,
  383:     linkto => \&format_linkto,
  384:     source => \&format_source,
  385:     target => \&format_target,
  386:     note => \&format_note,
  387:     build => \&format_build,
  388:     installscript => \&format_installscript,
  389:     status => \&format_status,
  390:     dependencies => \&format_dependencies,
  391:     privatedependencies => \&format_privatedependencies,
  392:     buildlink => \&format_buildlink,
  393:     glob => \&format_glob,
  394:     sourcedir => \&format_sourcedir,
  395:     filenames => \&format_filenames,
  396:     };
  397: 
  398: my $text;
  399: my $token;
  400: undef $hloc;
  401: undef @hierarchy;
  402: my $hloc;
  403: my @hierarchy2;
  404: while ($token = $parser->get_tag('lpml')) {
  405:     &format_lpml(@{$token});
  406:     $text = &trim($parser->get_text('/lpml'));
  407:     $token = $parser->get_tag('/lpml');
  408:     print $lpml; 
  409:     print "\n";
  410: #    $text=~s/\s*\n\s*\n\s*/\n/g;
  411:     print $text;
  412:     print "\n";
  413:     print &end();
  414: }
  415: exit;
  416: 
  417: # ---------- Functions (most all just format contents of different markup tags)
  418: 
  419: # ------------------------ Final output at end of markup parsing and formatting
  420: sub end {
  421:     if ($mode eq 'html') {
  422: 	return "<br />&nbsp;<br />".
  423: 	    "<a name='summary' /><font size='+2'>Summary of Source Repository".
  424: 	    "</font>".
  425: 	    "<br />&nbsp;<br />".
  426: 	    "<table border='1' cellpadding='5'>".
  427: 	    "<caption>Files, Directories, and Symbolic Links</caption>".
  428: 	    "<tr><td>Files (not referenced by globs)</td><td>$file_count</td>".
  429: 	    "</tr>".
  430: 	    "<tr><td>Files (referenced by globs)</td>".
  431: 	    "<td>$fileglobnames_count</td>".
  432: 	    "</tr>".
  433: 	    "<tr><td>Total Files</td>".
  434: 	    "<td>".($fileglobnames_count+$file_count)."</td>".
  435: 	    "</tr>".
  436: 	    "<tr><td>File globs</td>".
  437: 	    "<td>".$fileglob_count."</td>".
  438: 	    "</tr>".
  439: 	    "<tr><td>Directories</td>".
  440: 	    "<td>".$directory_count."</td>".
  441: 	    "</tr>".
  442: 	    "<tr><td>Symbolic links</td>".
  443: 	    "<td>".$link_count."</td>".
  444: 	    "</tr>".
  445: 	    "</table>".
  446: 	    "<table border='1' cellpadding='5'>".
  447: 	    "<caption>File Category Count</caption>".
  448: 	    "<tr><th>Icon</th><th>Name</th><th>Number of Occurrences</th>".
  449: 	    "<th>Number of Incorrect Counts</th>".
  450: 	    "</tr>".
  451: 	    join("\n",(map {"<tr><td><img src='$fab{$_}.gif' ".
  452: 		 "alt='$_ icon' /></td>".
  453:  	         "<td>$_</td><td>$categorycount{$_}</td>".
  454: 		 "<td><!-- POSTEVALINLINE $_ --></td></tr>"}
  455: 		@categorynamelist)).
  456: 	    "</table>".
  457: 	    "</body></html>\n";
  458: 
  459:     }
  460:     if ($mode eq 'install') {
  461: 	return '';
  462:     }
  463: }
  464: 
  465: # ----------------------- Take in string to parse and the separation expression
  466: sub extract_array {
  467:     my ($stringtoparse,$sepexp) = @_;
  468:     my @a=split(/$sepexp/,$stringtoparse);
  469:     return \@a;
  470: }
  471: 
  472: # --------------------------------------------------------- Format lpml section
  473: sub format_lpml {
  474:     my (@tokeninfo)=@_;
  475:     my $date=`date`; chop $date;
  476:     if ($mode eq 'html') {
  477: 	$lpml=<<END;
  478: <html>
  479: <head>
  480: <title>LPML Description Page
  481: (dist=$dist, categorytype=$categorytype, $date)</title>
  482: </head>
  483: <body>
  484: END
  485: 	$lpml .= "<br /><font size='+2'>LPML Description Page (dist=$dist, ".
  486: 	    "categorytype=$categorytype, $date)".
  487: 	    "</font>";
  488: 	$lpml .=<<END;
  489: <ul>
  490: <li><a href='#about'>About this file</a></li>
  491: <li><a href='#ownperms'>File Type Ownership and Permissions
  492: Descriptions</a></li>
  493: <li><a href='#package'>Software Package Description</a></li>
  494: <li><a href='#directories'>Directory Structure</a></li>
  495: <li><a href='#files'>Files</a></li>
  496: <li><a href='#summary'>Summary of Source Repository</a></li>
  497: </ul>
  498: END
  499:         $lpml .=<<END;
  500: <br />&nbsp;<br /><a name='about' />
  501: <font size='+2'>About this file</font>
  502: <p>
  503: This file is generated dynamically by <tt>lpml_parse.pl</tt> as
  504: part of a development compilation process.</p>
  505: <p>LPML written by Scott Harrison (harris41\@msu.edu).
  506: </p>
  507: END
  508:     }
  509:     elsif ($mode eq 'text') {
  510: 	$lpml = "LPML Description Page (dist=$dist, $date)";
  511: 	$lpml .=<<END;
  512: 
  513: * About this file
  514: * Software Package Description
  515: * Directory Structure
  516: * File Type Ownership and Permissions
  517: * Files
  518: END
  519:         $lpml .=<<END;
  520: 
  521: About this file
  522: 
  523: This file is generated dynamically by lpml_parse.pl as
  524: part of a development compilation process.  Author: Scott
  525: Harrison (harris41\@msu.edu).
  526: 
  527: END
  528:     }
  529:     elsif ($mode eq 'install') {
  530: 	print '# LPML install targets. Linux Packaging Markup Language,';
  531: 	print ' by Scott Harrison 2001'."\n";
  532: 	print '# This file was automatically generated on '.`date`;
  533: 	print "\n".$invocation;
  534: 	$lpml .= "SHELL=\"/bin/bash\"\n\n";
  535:     }
  536:     elsif ($mode eq 'configinstall') {
  537: 	print '# LPML configuration file targets (configinstall).'."\n";
  538: 	print '# Linux Packaging Markup Language,';
  539: 	print ' by Scott Harrison 2001'."\n";
  540: 	print '# This file was automatically generated on '.`date`;
  541: 	print "\n".$invocation;
  542: 	$lpml .= "SHELL=\"/bin/bash\"\n\n";
  543:     }
  544:     elsif ($mode eq 'build') {
  545: 	$lpml = "# LPML build targets. Linux Packaging Markup Language,";
  546: 	$lpml .= ' by Scott Harrison 2001'."\n";
  547: 	$lpml .= '# This file was automatically generated on '.`date`;
  548: 	$lpml .= "\n".$invocation;
  549: 	$lpml .= "SHELL=\"/bin/sh\"\n\n";
  550:     }
  551:     else {
  552: 	return '';
  553:     }
  554: }
  555: # --------------------------------------------------- Format targetroot section
  556: sub format_targetroot {
  557:     my $text=&trim($parser->get_text('/targetroot'));
  558:     $text=$targetroot if $targetroot;
  559:     $parser->get_tag('/targetroot');
  560:     if ($mode eq 'html') {
  561: 	return $targetroot="\n<br />TARGETROOT: $text";
  562:     }
  563:     elsif ($mode eq 'install' or $mode eq 'build' or
  564: 	   $mode eq 'configinstall') {
  565: 	return '# TARGET INSTALL LOCATION is "'.$targetroot."\"\n";
  566:     }
  567:     else {
  568: 	return '';
  569:     }
  570: }
  571: # --------------------------------------------------- Format sourceroot section
  572: sub format_sourceroot {
  573:     my $text=&trim($parser->get_text('/sourceroot'));
  574:     $text=$sourceroot if $sourceroot;
  575:     $parser->get_tag('/sourceroot');
  576:     if ($mode eq 'html') {
  577: 	return $sourceroot="\n<br />SOURCEROOT: $text";
  578:     }
  579:     elsif ($mode eq 'install' or $mode eq 'build' or
  580: 	   $mode eq 'configinstall') {
  581: 	return '# SOURCE CODE LOCATION IS "'.$sourceroot."\"\n";;
  582:     }
  583:     else {
  584: 	return '';
  585:     }
  586: }
  587: # --------------------------------------------------- Format categories section
  588: sub format_categories {
  589:     my $text=&trim($parser->get_text('/categories'));
  590:     $parser->get_tag('/categories');
  591:     if ($mode eq 'html') {
  592: 	return $categories="\n<br />&nbsp;<br />".
  593: 	    "\n<a name='ownperms'>".
  594: 	    "\n<font size='+2'>File Type Ownership and Permissions".
  595: 	    " Descriptions</font>".
  596: 	    "\n<p>This table shows what permissions and ownership settings ".
  597: 	    "correspond to each category.</p>".
  598: 	    "\n<table border='1' cellpadding='5' width='60%'>\n".
  599: 	    "<tr>".
  600: 	    "<th align='left' bgcolor='#ffffff'>Icon</th>".
  601: 	    "<th align='left' bgcolor='#ffffff'>Category Name</th>".
  602: 	    "<th align='left' bgcolor='#ffffff'>Permissions ".
  603: 	    "($categorytype)</th>".
  604: 	    "</tr>".
  605: 	    "\n$text\n".
  606: 	    "</table>\n";
  607:     }
  608:     elsif ($mode eq 'text') {
  609: 	return $categories="\n".
  610: 	    "\nFile Type Ownership and Permissions".
  611: 	    " Descriptions".
  612: 	    "\n$text".
  613: 	    "\n";
  614:     }
  615:     else {
  616: 	return '';
  617:     }
  618: }
  619: # --------------------------------------------------- Format categories section
  620: sub format_category {
  621:     my (@tokeninfo)=@_;
  622:     $category_att_name=$tokeninfo[2]->{'name'};
  623:     $category_att_type=$tokeninfo[2]->{'type'};
  624:     $abbreviation=''; $chmod='';$chown='';
  625:     $parser->get_text('/category');
  626:     $parser->get_tag('/category');
  627:     $fab{$category_att_name}=$abbreviation;
  628:     if ($mode eq 'html') {
  629: 	if ($category_att_type eq $categorytype) {
  630: 	    push @categorynamelist,$category_att_name;
  631: 	    $categoryhash{$category_att_name}="$chmod $chown";
  632: 	    return $category="<tr>".
  633: 		"<td><img src='$abbreviation.gif' ".
  634:    	        "alt='${category_att_name}' /></td>\n".
  635: 		"<td>${category_att_name}</td>\n".
  636: 		"<td>$chmod $chown</td>\n".
  637: 		"</tr>".
  638: 		"\n";
  639: #	return $category="\n<br />CATEGORY $category_att_name ".
  640: #	    "$category_att_type $chmod $chown";
  641: 	}
  642:     }
  643:     else {
  644: 	if ($category_att_type eq $categorytype) {
  645: 	    my ($user,$group)=split(/\:/,$chown);
  646: 	    $categoryhash{$category_att_name}='-o '.$user.' -g '.$group.
  647: 		' -m '.$chmod;
  648: 	    $categoryhash{"chmod.".$category_att_name}=$chmod;
  649: 	    $categoryhash{"chown.".$category_att_name}=$chown;
  650: 	}
  651: 	return '';
  652:     }
  653: }
  654: # --------------------------------------------------- Format categories section
  655: sub format_abbreviation {
  656:     my @tokeninfo=@_;
  657:     $abbreviation='';
  658:     my $text=&trim($parser->get_text('/abbreviation'));
  659:     if ($text) {
  660: 	$parser->get_tag('/abbreviation');
  661: 	$abbreviation=$text;
  662:     }
  663:     return '';
  664: }
  665: # -------------------------------------------------------- Format chown section
  666: sub format_chown {
  667:     my @tokeninfo=@_;
  668:     $chown='';
  669:     my $text=&trim($parser->get_text('/chown'));
  670:     if ($text) {
  671: 	$parser->get_tag('/chown');
  672: 	$chown=$text;
  673:     }
  674:     return '';
  675: }
  676: # -------------------------------------------------------- Format chmod section
  677: sub format_chmod {
  678:     my @tokeninfo=@_;
  679:     $chmod='';
  680:     my $text=&trim($parser->get_text('/chmod'));
  681:     if ($text) {
  682: 	$parser->get_tag('/chmod');
  683: 	$chmod=$text;
  684:     }
  685:     return '';
  686: }
  687: # ---------------------------------------------------------- Format rpm section
  688: sub format_rpm {
  689:     my $text=&trim($parser->get_text('/rpm'));
  690:     $parser->get_tag('/rpm');
  691:     if ($mode eq 'html') {
  692: 	return $rpm=<<END;
  693: <br />&nbsp;<br />
  694: <a name='package' />
  695: <font size='+2'>Software Package Description</font>
  696: <p>
  697: <table bgcolor='#ffffff' border='0' cellpadding='10' cellspacing='0'>
  698: <tr><td><pre>
  699: $text
  700: </pre></td></tr>
  701: </table>
  702: END
  703:     }
  704:     elsif ($mode eq 'make_rpm') {
  705: 	return $text;
  706:     }
  707:     elsif ($mode eq 'text') {
  708: 	return $rpm=<<END;
  709: Software Package Description
  710: 
  711: $text
  712: END
  713:     }
  714:     else {
  715: 	return '';
  716:     }
  717: }
  718: # --------------------------------------------------- Format rpmSummary section
  719: sub format_rpmSummary {
  720:     my $text=&trim($parser->get_text('/rpmSummary'));
  721:     $parser->get_tag('/rpmSummary');
  722:     if ($mode eq 'html') {
  723: 	return $rpmSummary="\nSummary     : $text";
  724:     }
  725:     elsif ($mode eq 'text') {
  726: 	return $rpmSummary="\nSummary     : $text";
  727:     }
  728:     elsif ($mode eq 'make_rpm') {
  729: 	return <<END;
  730: <summary>$text</summary>
  731: END
  732:     }
  733:     else {
  734: 	return '';
  735:     }
  736: }
  737: # ------------------------------------------------------ Format rpmName section
  738: sub format_rpmName {
  739:     my $text=&trim($parser->get_text('/rpmName'));
  740:     $parser->get_tag('/rpmName');
  741:     if ($mode eq 'html') {
  742: 	return $rpmName="\nName        : $text";
  743:     }
  744:     elsif ($mode eq 'text') {
  745: 	return $rpmName="\nName        : $text";
  746:     }
  747:     elsif ($mode eq 'make_rpm') {
  748: 	return <<END;
  749: <name>$text</name>
  750: END
  751:     }
  752:     else {
  753: 	return '';
  754:     }
  755: }
  756: # --------------------------------------------------- Format rpmVersion section
  757: sub format_rpmVersion {
  758:     my $text=$parser->get_text('/rpmVersion');
  759:     $parser->get_tag('/rpmVersion');
  760:     if ($mode eq 'html') {
  761: 	return $rpmVersion="\nVersion     : $text";
  762:     }
  763:     elsif ($mode eq 'text') {
  764: 	return $rpmVersion="\nVersion     : $text";
  765:     }
  766:     else {
  767: 	return '';
  768:     }
  769: }
  770: # --------------------------------------------------- Format rpmRelease section
  771: sub format_rpmRelease {
  772:     my $text=$parser->get_text('/rpmRelease');
  773:     $parser->get_tag('/rpmRelease');
  774:     if ($mode eq 'html') {
  775: 	return $rpmRelease="\nRelease     : $text";
  776:     }
  777:     elsif ($mode eq 'text') {
  778: 	return $rpmRelease="\nRelease     : $text";
  779:     }
  780:     else {
  781: 	return '';
  782:     }
  783: }
  784: # ---------------------------------------------------- Format rpmVendor section
  785: sub format_rpmVendor {
  786:     my $text=$parser->get_text('/rpmVendor');
  787:     $parser->get_tag('/rpmVendor');
  788:     if ($mode eq 'html') {
  789: 	return $rpmVendor="\nVendor      : $text";
  790:     }
  791:     elsif ($mode eq 'text') {
  792: 	return $rpmVendor="\nVendor      : $text";
  793:     }
  794:     elsif ($mode eq 'make_rpm') {
  795: 	return <<END;
  796: <vendor>$text</vendor>
  797: END
  798:     }
  799:     else {
  800: 	return '';
  801:     }
  802: }
  803: # ------------------------------------------------- Format rpmBuildRoot section
  804: sub format_rpmBuildRoot {
  805:     my $text=$parser->get_text('/rpmBuildRoot');
  806:     $parser->get_tag('/rpmBuildRoot');
  807:     if ($mode eq 'html') {
  808: 	return $rpmBuildRoot="\nBuild Root  : $text";
  809:     }
  810:     elsif ($mode eq 'text') {
  811: 	return $rpmBuildRoot="\nBuild Root  : $text";
  812:     }
  813:     else {
  814: 	return '';
  815:     }
  816: }
  817: # ------------------------------------------------- Format rpmCopyright section
  818: sub format_rpmCopyright {
  819:     my $text=$parser->get_text('/rpmCopyright');
  820:     $parser->get_tag('/rpmCopyright');
  821:     if ($mode eq 'html') {
  822: 	return $rpmCopyright="\nLicense     : $text";
  823:     }
  824:     elsif ($mode eq 'text') {
  825: 	return $rpmCopyright="\nLicense     : $text";
  826:     }
  827:     elsif ($mode eq 'make_rpm') {
  828: 	return <<END;
  829: <copyright>$text</copyright>
  830: END
  831:     }
  832:     else {
  833: 	return '';
  834:     }
  835: }
  836: # ----------------------------------------------------- Format rpmGroup section
  837: sub format_rpmGroup {
  838:     my $text=$parser->get_text('/rpmGroup');
  839:     $parser->get_tag('/rpmGroup');
  840:     if ($mode eq 'html') {
  841: 	return $rpmGroup="\nGroup       : $text";
  842:     }
  843:     elsif ($mode eq 'text') {
  844: 	return $rpmGroup="\nGroup       : $text";
  845:     }
  846:     elsif ($mode eq 'make_rpm') {
  847: 	return <<END;
  848: <group>Utilities/System</group>
  849: END
  850:     }
  851:     else {
  852: 	return '';
  853:     }
  854: }
  855: # ---------------------------------------------------- Format rpmSource section
  856: sub format_rpmSource {
  857:     my $text=$parser->get_text('/rpmSource');
  858:     $parser->get_tag('/rpmSource');
  859:     if ($mode eq 'html') {
  860: 	return $rpmSource="\nSource      : $text";
  861:     }
  862:     elsif ($mode eq 'text') {
  863: 	return $rpmSource="\nSource      : $text";
  864:     }
  865:     else {
  866: 	return '';
  867:     }
  868: }
  869: # ----------------------------------------------- Format rpmAutoReqProv section
  870: sub format_rpmAutoReqProv {
  871:     my $text=$parser->get_text('/rpmAutoReqProv');
  872:     $parser->get_tag('/rpmAutoReqProv');
  873:     if ($mode eq 'html') {
  874: 	return $rpmAutoReqProv="\nAutoReqProv : $text";
  875:     }
  876:     elsif ($mode eq 'text') {
  877: 	return $rpmAutoReqProv="\nAutoReqProv : $text";
  878:     }
  879:     elsif ($mode eq 'make_rpm') {
  880: 	return <<END;
  881: <AutoReqProv>$text</AutoReqProv>
  882: END
  883:     }
  884:     else {
  885: 	return '';
  886:     }
  887: }
  888: # ----------------------------------------------- Format rpmdescription section
  889: sub format_rpmdescription {
  890:     my $text=$parser->get_text('/rpmdescription');
  891:     $parser->get_tag('/rpmdescription');
  892:     if ($mode eq 'html') {
  893: 	$text=~s/\n//g;
  894: 	$text=~s/\\n/\n/g;
  895: 	return $rpmdescription="\nDescription : $text";
  896:     }
  897:     elsif ($mode eq 'text') {
  898: 	$text=~s/\n//g;
  899: 	$text=~s/\\n/\n/g;
  900: 	return $rpmdescription="\nDescription : $text";
  901:     }
  902:     elsif ($mode eq 'make_rpm') {
  903: 	$text=~s/\n//g;
  904: 	$text=~s/\\n/\n/g;
  905: 	return <<END;
  906: <description>$text</description>
  907: END
  908:     }
  909:     else {
  910: 	return '';
  911:     }
  912: }
  913: # ------------------------------------------------------- Format rpmpre section
  914: sub format_rpmpre {
  915:     my $text=$parser->get_text('/rpmpre');
  916:     $parser->get_tag('/rpmpre');
  917:     if ($mode eq 'html') {
  918: #	return $rpmpre="\n<br />RPMPRE $text";
  919: 	return '';
  920:     }
  921:     elsif ($mode eq 'make_rpm') {
  922: 	return <<END;
  923: <pre>$text</pre>
  924: END
  925:     }
  926:     else {
  927: 	return '';
  928:     }
  929: }
  930: # -------------------------------------------------- Format requires section
  931: sub format_rpmRequires {
  932:     my @tokeninfo=@_;
  933:     my $aref;
  934:     my $text;
  935:     if ($mode eq 'make_rpm') {
  936: 	while ($aref=$parser->get_token()) {
  937: 	    if ($aref->[0] eq 'E' && $aref->[1] eq 'rpmRequires') {
  938: 		last;
  939: 	    }
  940: 	    elsif ($aref->[0] eq 'S') {
  941: 		$text.=$aref->[4];
  942: 	    }
  943: 	    elsif ($aref->[0] eq 'E') {
  944: 		$text.=$aref->[2];
  945: 	    }
  946: 	    else {
  947: 		$text.=$aref->[1];
  948: 	    }
  949: 	}
  950:     }
  951:     else {
  952: 	$parser->get_tag('/rpmRequires');
  953: 	return '';
  954:     }
  955:     return '<rpmRequires>'.$text.'</rpmRequires>';
  956: }
  957: # -------------------------------------------------- Format directories section
  958: sub format_directories {
  959:     my $text=$parser->get_text('/directories');
  960:     $parser->get_tag('/directories');
  961:     if ($mode eq 'html') {
  962: 	$text=~s/\[\{\{\{\{\{DPATHLENGTH\}\}\}\}\}\]/$dpathlength/g;
  963: 	return $directories="\n<br />&nbsp;<br />".
  964: 	    "<a name='directories' />".
  965: 	    "<font size='+2'>Directory Structure</font>".
  966: 	    "\n<br />&nbsp;<br />".
  967: 	    "<table border='1' cellpadding='3' cellspacing='0'>\n".
  968: 	    "<tr><th bgcolor='#ffffff'>Category</th>".
  969: 	    "<th bgcolor='#ffffff'>Status</th>\n".
  970: 	    "<th bgcolor='#ffffff'>Expected Permissions & Ownership</th>\n".
  971: 	    "<th bgcolor='#ffffff' colspan='$dpathlength'>Target Directory ".
  972: 	    "Path</th></tr>\n".
  973:  	    "\n$text\n</table><br />"."\n";
  974:     }
  975:     elsif ($mode eq 'text') {
  976: 	return $directories="\nDirectory Structure\n$text\n".
  977: 	    "\n";
  978:     }
  979:     elsif ($mode eq 'install') {
  980: 	return "\n".'directories:'."\n".$text;
  981:     }
  982:     elsif ($mode eq 'rpm_file_list') {
  983: 	return $text;
  984:     }
  985:     elsif ($mode eq 'uninstall_shell_commands') {
  986: 	return $text;
  987:     }
  988:     else {
  989: 	return '';
  990:     }
  991: }
  992: # ---------------------------------------------------- Format directory section
  993: sub format_directory {
  994:     my (@tokeninfo)=@_;
  995:     $targetdir='';$categoryname='';$description='';$protectionlevel='';
  996:     $parser->get_text('/directory');
  997:     $parser->get_tag('/directory');
  998:     $directory_count++;
  999:     $categorycount{$categoryname}++;
 1000:     if ($mode eq 'html') {
 1001: 	my @a;
 1002: 	@a=($targetdir=~/\//g);
 1003: 	my $d=scalar(@a)+1;
 1004: 	$dpathlength=$d if $d>$dpathlength;
 1005: 	my $thtml=$targetdir;
 1006: 	$thtml=~s/\//\<\/td\>\<td bgcolor='#ffffff'\>/g;
 1007: 	my ($chmod,$chown)=split(/\s/,$categoryhash{$categoryname});
 1008: 	return $directory="\n<tr><td rowspan='2' bgcolor='#ffffff'>".
 1009: 	    "$categoryname</td>".
 1010: 	    "<td rowspan='2' bgcolor='#ffffff'><!-- POSTEVAL [$categoryname] ".
 1011: 	    "verify.pl directory /$targetdir $categoryhash{$categoryname} -->".
 1012: 	    "&nbsp;</td>".
 1013: 	    "<td rowspan='2' bgcolor='#ffffff'>$chmod<br />$chown</td>".
 1014: 	    "<td bgcolor='#ffffff'>$thtml</td></tr>".
 1015: 	    "<tr><td bgcolor='#ffffff' colspan='[{{{{{DPATHLENGTH}}}}}]'>".
 1016: 	    "$description</td></tr>";
 1017:     }
 1018:     if ($mode eq 'text') {
 1019: 	return $directory="\nDIRECTORY $targetdir $categoryname ".
 1020: 	    "$description";
 1021:     }
 1022:     elsif ($mode eq 'install') {
 1023: 	return "\t".'install '.$categoryhash{$categoryname}.' -d '.
 1024: 	    $targetroot.'/'.$targetdir."\n";
 1025:     }
 1026:     elsif ($mode eq 'rpm_file_list') {
 1027: 	return $targetroot.'/'.$targetdir."\n";
 1028:     }
 1029:     elsif ($mode eq 'uninstall_shell_commands') {
 1030: 	if ($protectionlevel eq 'never_delete') {
 1031: 	    return 'echo "LEAVING BEHIND '.$targetroot.'/'.$targetdir.
 1032: 		' which may have important data worth saving"'."\n";
 1033: 	}
 1034: 	elsif ($protectionlevel eq 'weak_delete') {
 1035: 	    if ($targetdir!~/\w/) {
 1036: 		die("targetdir=\"$targetdir\"! NEVER EVER DELETE THE WHOLE ".
 1037: 		    "FILESYSTEM"."\n");
 1038: 	    }
 1039: 	    return 'rm -Rvf -i '.$targetroot.'/'.$targetdir."\n";
 1040: 	}
 1041: 	elsif ($protectionlevel =~ /never/) {
 1042: 	    die("CONFUSING PROTECTION LEVEL \"$protectionlevel\" FOUND ".
 1043: 		"FOR directory $targetdir"."\n");
 1044: 	}
 1045: 	elsif ($protectionlevel !~
 1046:     /^never_delete|weak_delete|modest_delete|strong_delete|absolute_delete$/) {
 1047: 	    die("CONFUSING OR MISSING PROTECTION LEVEL \"$protectionlevel\" ".
 1048: 		"FOUND FOR directory $targetdir\n");
 1049: 	}
 1050: 	else {
 1051: 	    if ($targetdir!~/\w/) {
 1052: 		die("targetdir=\"$targetdir\"! NEVER EVER DELETE THE WHOLE ".
 1053: 		    "FILESYSTEM"."\n");
 1054: 	    }
 1055: 	    return 'rm -Rvf '.$targetroot.'/'.$targetdir.
 1056: 		"| grep 'removed directory'"."\n";
 1057: 	}
 1058:     }
 1059:     else {
 1060: 	return '';
 1061:     }
 1062: }
 1063: # ---------------------------------------------------- Format targetdir section
 1064: sub format_targetdir {
 1065:     my @tokeninfo=@_;
 1066:     $targetdir='';
 1067:     my $text=&trim($parser->get_text('/targetdir'));
 1068:     if ($text) {
 1069: 	$parser->get_tag('/targetdir');
 1070: 	$targetdir=$text;
 1071:     }
 1072:     return '';
 1073: }
 1074: # ---------------------------------------------- Format protectionlevel section
 1075: sub format_protectionlevel {
 1076:     my @tokeninfo=@_;
 1077:     $protectionlevel='';
 1078:     my $text=&trim($parser->get_text('/protectionlevel'));
 1079:     if ($text) {
 1080: 	$parser->get_tag('/protectionlevel');
 1081: 	$protectionlevel=$text;
 1082:     }
 1083:     return '';
 1084: }
 1085: # ------------------------------------------------- Format categoryname section
 1086: sub format_categoryname {
 1087:     my @tokeninfo=@_;
 1088:     $categoryname='';
 1089:     my $text=&trim($parser->get_text('/categoryname'));
 1090:     if ($text) {
 1091: 	$parser->get_tag('/categoryname');
 1092: 	$categoryname=$text;
 1093:     }
 1094:     return '';
 1095: }
 1096: # -------------------------------------------------- Format description section
 1097: sub format_description {
 1098:     my @tokeninfo=@_;
 1099:     $description='';
 1100:     my $text=&htmlsafe(&trim($parser->get_text('/description')));
 1101:     if ($text) {
 1102: 	$parser->get_tag('/description');
 1103: 	$description=$text;
 1104:     }
 1105:     return '';
 1106: }
 1107: # -------------------------------------------------------- Format files section
 1108: sub format_files {
 1109:     my $text=$parser->get_text('/files');
 1110:     $parser->get_tag('/files');
 1111:     if ($mode eq 'MANIFEST') {
 1112: 	return $text;
 1113:     }
 1114:     elsif ($mode eq 'html') {
 1115: 	return $directories="\n<br />&nbsp;<br />".
 1116: 	    "<a name='files' />".
 1117: 	    "<font size='+2'>Files</font><br />&nbsp;<br />".
 1118: 	    "<p>All source and target locations are relative to the ".
 1119: 	    "sourceroot and targetroot values at the beginning of this ".
 1120: 	    "document.</p>".
 1121: 	    "\n<table border='1' cellpadding='5'>".
 1122: 	    "<tr><th>Status</th><th colspan='2'>Category</th>".
 1123: 	    "<th>Name/Location</th>".
 1124: 	    "<th>Description</th><th>Notes</th></tr>".
 1125: 	    "$text</table>\n".
 1126: 	    "\n";
 1127:     }
 1128:     elsif ($mode eq 'text') {
 1129: 	return $directories="\n".
 1130: 	    "File and Directory Structure".
 1131: 	    "\n$text\n".
 1132: 	    "\n";
 1133:     }
 1134:     elsif ($mode eq 'install') {
 1135: 	return "\n".'files:'."\n".$text.
 1136: 	    "\n".'links:'."\n".join('',@links);
 1137:     }
 1138:     elsif ($mode eq 'configinstall') {
 1139: 	return "\n".'configfiles: '.
 1140: 	join(' ',@configall).
 1141: 	"\n\n".$text.
 1142: 	"\n\nalwaysrun:\n\n";
 1143:     }
 1144:     elsif ($mode eq 'build') {
 1145: 	my $binfo;
 1146: 	my $tword;
 1147: 	my $command2;
 1148: 	my @deps;
 1149: 	foreach my $bi (@buildinfo) {
 1150: 	    my ($target,$source,$command,$trigger,@deps)=split(/\;/,$bi);
 1151: 	    $tword=''; $tword=' alwaysrun' if $trigger eq 'always run'; 
 1152: 	    if ($command!~/\s/) {
 1153: 		$command=~s/\/([^\/]*)$//;
 1154: 		$command2="cd $command; sh ./$1;\\";
 1155: 	    }
 1156: 	    else {
 1157: 		$command=~s/(.*?\/)([^\/]+\s+.*)$/$1/;
 1158: 		$command2="cd $command; sh ./$2;\\";
 1159: 	    }
 1160: 	    my $depstring;
 1161: 	    my $depstring2="\t\t\@echo '';\\\n";
 1162: 	    my $olddep;
 1163: 	    foreach my $dep (@deps) {
 1164: 		unless ($olddep) {
 1165: 		    $olddep=$deps[$#deps];
 1166: 		}
 1167: 		$depstring.="\telif !(test -r $command/$dep);\\\n";
 1168: 		$depstring.="\t\tthen echo ".
 1169: 		"\"**** WARNING **** missing the file: ".
 1170:  	        "$command/$dep\"$logcmd;\\\n";
 1171: 		$depstring.="\t\ttest -e $source || test -e $target || echo ".
 1172: 		    "'**** ERROR **** neither source=$source nor target=".
 1173: 		    "$target exist and they cannot be built'$logcmd;\\\n";
 1174: 		$depstring.="\t\tmake -f Makefile.build ${source}___DEPS;\\\n";
 1175: 		if ($olddep) {
 1176: 		    $depstring2.="\t\tECODE=0;\\\n";
 1177: 		    $depstring2.="\t\t! test -e $source && test -r $command/$olddep &&".
 1178: 			" { perl filecompare.pl -b2 $command/$olddep $target ||  ECODE=\$\$?; } && { [ \$\$ECODE != \"2\" ] || echo \"**** WARNING **** dependency $command/$olddep is newer than target file $target; SOMETHING MAY BE WRONG\"$logcmd; };\\\n";
 1179: 		}
 1180: 		$olddep=$dep;
 1181: 	    }
 1182: 	    $binfo.="$source: $tword\n".
 1183: 		"\t\@if !(echo \"\");\\\n\t\tthen echo ".
 1184: 		"\"**** WARNING **** Strange shell. ".
 1185:  	        "Check your path settings.\"$logcmd;\\\n".
 1186: 		$depstring.
 1187: 		"\telse \\\n\t\t$command2\n\tfi\n\n";
 1188: 	    $binfo.="${source}___DEPS:\n".$depstring2."\t\tECODE=0;\n\n";
 1189: 	}
 1190: 	return 'all: '.join(' ',@buildall)."\n\n".
 1191:   	        $text.
 1192: 		$binfo."\n".
 1193: 		"alwaysrun:\n\n";
 1194:     }
 1195:     elsif ($mode eq 'rpm_file_list') {
 1196: 	return $text;
 1197:     }
 1198:     else {
 1199: 	return '';
 1200:     }
 1201: }
 1202: # ---------------------------------------------------- Format fileglobs section
 1203: sub format_fileglobs {
 1204: 
 1205: }
 1206: # -------------------------------------------------------- Format links section
 1207: # deprecated.. currently <link></link>'s are included in <files></files>
 1208: sub format_links {
 1209:     my $text=$parser->get_text('/links');
 1210:     $parser->get_tag('/links');
 1211:     if ($mode eq 'html') {
 1212: 	return $links="\n<br />BEGIN LINKS\n$text\n<br />END LINKS\n";
 1213:     }
 1214:     elsif ($mode eq 'install') {
 1215: 	return "\n".'links:'."\n\t".$text;
 1216:     }
 1217:     else {
 1218: 	return '';
 1219:     }
 1220: }
 1221: # --------------------------------------------------------- Format file section
 1222: sub format_file {
 1223:     my @tokeninfo=@_;
 1224:     $file=''; $source=''; $target=''; $categoryname=''; $description='';
 1225:     $note=''; $build=''; $status=''; $dependencies=''; $installscript='';
 1226:     my $text=&trim($parser->get_text('/file'));
 1227:     my $buildtest;
 1228:     $file_count++;
 1229:     $categorycount{$categoryname}++;
 1230:     if ($source) {
 1231: 	$parser->get_tag('/file');
 1232: 	if ($mode eq 'MANIFEST') {
 1233: 	    my $command=$build;
 1234: 	    if ($command!~/\s/) {
 1235: 		$command=~s/\/([^\/]*)$//;
 1236: 	    }
 1237: 	    else {
 1238: 		$command=~s/(.*?\/)([^\/]+\s+.*)$/$1/;
 1239: 	    }
 1240: 	    $command=~s/^$sourceroot\///;
 1241: 	    my (@deps)=split(/\;/,$dependencies);
 1242: 	    my $retval=join("\n",($source,
 1243: 		       (map {"$command$_"} @deps)));
 1244: 	    if ($tokeninfo[2]{type} eq 'private') {
 1245: 		return "\n";
 1246: 	    }
 1247: 	    return $retval."\n";
 1248: 	}
 1249: 	elsif ($mode eq 'html') {
 1250: 	    return ($file="\n<!-- FILESORT:$target -->".
 1251: 		    "<tr>".
 1252:           "<td><!-- POSTEVAL [$categoryname] verify.pl file '$sourcerootarg' ".
 1253: 		    "'$targetrootarg' ".
 1254: 		    "'$source' '$target' ".
 1255: 		    "$categoryhash{$categoryname} -->&nbsp;</td><td>".
 1256: 		    "<img src='$fab{$categoryname}.gif' ".
 1257: 		    "alt='$categoryname icon' /></td>".
 1258: 		    "<td>$categoryname<br /><font size='-1'>".
 1259: 		    $categoryhash{$categoryname}."</font></td>".
 1260: 		    "<td>SOURCE: $source<br />TARGET: $target</td>".
 1261: 		    "<td>$description</td>".
 1262: 		    "<td>$note</td>".
 1263: 		    "</tr>");
 1264: #	    return ($file="\n<br />BEGIN FILE\n".
 1265: #		"$source $target $categoryname $description $note " .
 1266: #		"$build $status $dependencies" .
 1267: #		"\nEND FILE");
 1268: 	}
 1269: 	elsif ($mode eq 'install' && $categoryname ne 'conf') {
 1270: 	    if ($build) {
 1271: 		my $bi=$sourceroot.'/'.$source.';'.$build.';'.
 1272: 		    $dependencies;
 1273: 		my ($source2,$command,$trigger,@deps)=split(/\;/,$bi);
 1274: 		$tword=''; $tword=' alwaysrun' if $trigger eq 'always run'; 
 1275: 		$command=~s/\/([^\/]*)$//;
 1276: 		$command2="cd $command; sh ./$1;\\";
 1277: 		my $depstring;
 1278: 		foreach my $dep (@deps) {
 1279: 		    $depstring.=<<END;
 1280: 		ECODE=0; DEP=''; \\
 1281: 		test -e $dep || (echo '**** WARNING **** cannot evaluate status of dependency $dep (for building ${sourceroot}/${source} with)'$logcmd); DEP="1"; \\
 1282: 		[ -n DEP ] && { perl filecompare.pl -b2 $dep ${targetroot}/${target} || ECODE=\$\$?; } || DEP="1"; \\
 1283: 		case "\$\$ECODE" in \\
 1284: 			2) echo "**** WARNING **** dependency $dep is newer than target file ${targetroot}/${target}; you may want to run make build"$logcmd;; \\
 1285: 		esac; \\
 1286: END
 1287: 		}
 1288:                 chomp $depstring;
 1289: 		$buildtest=<<END;
 1290: 	\@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
 1291: 		echo "**** ERROR **** ${sourceroot}/${source} is missing and is also not present at target location ${targetroot}/${target}; you must run make build"$logcmd; exit; \\
 1292: END
 1293:                 $buildtest.=<<END if $depstring;
 1294: 	elif !(test -e "${sourceroot}/${source}"); then \\
 1295: $depstring
 1296: END
 1297:                 $buildtest.=<<END;
 1298: 	fi
 1299: END
 1300: 	    }
 1301: 	    if ($installscript) {
 1302: 		my $dir = $sourceroot.'/'.$source;
 1303: 		$dir =~ s|/([^/]*)$||;
 1304: 		return <<"END";
 1305: $buildtest	cd $dir ; sh $installscript\\
 1306: 		chmod -R $categoryhash{chmod.$categoryname} ${targetroot}/${target} \\
 1307: 		chown -R $categoryhash{chown.$categoryname} ${targetroot}/${target} \\
 1308: END
 1309: 	    }
 1310:             my $bflag='-b1';
 1311:             $bflag='-b3' if $dependencies or $buildlink;
 1312: 	    return <<END;
 1313: $buildtest	\@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
 1314: 		echo "**** ERROR **** CVS source file does not exist: ${sourceroot}/${source} and neither does target: ${targetroot}/${target}"$logcmd; \\
 1315: 	elif !(test -e "${sourceroot}/${source}"); then \\
 1316: 		echo "**** WARNING **** CVS source file does not exist: ${sourceroot}/${source}"$logcmd; \\
 1317: 		perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\
 1318: 	else \\
 1319: 		ECODE=0; \\
 1320: 		perl filecompare.pl $bflag ${sourceroot}/${source} ${targetroot}/${target} || ECODE=\$\$?; \\
 1321: 		case "\$\$ECODE" in \\
 1322: 			1) echo "${targetroot}/${target} is unchanged";; \\
 1323: 			2) echo "**** WARNING **** target file ${targetroot}/${target} is newer than CVS source; saving current (old) target file to ${targetroot}/${target}.lpmlsave and then overwriting"$logcmd && install -o www -g www -m 0600 ${targetroot}/${target} ${targetroot}/${target}.lpmlsave && install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target};; \\
 1324: 			0) echo "install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target}" && install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target};; \\
 1325: 		esac; \\
 1326: 		perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\
 1327: 	fi
 1328: END
 1329: 	}
 1330: 	elsif ($mode eq 'configinstall' && $categoryname eq 'conf') {
 1331: 	    push @configall,$targetroot.'/'.$target;
 1332: 	    return $targetroot.'/'.$target.': alwaysrun'."\n".
 1333: 		"\t".'@# Compare source with target and intelligently respond'.
 1334: 		"\n\t\n\t\n".
 1335: 
 1336: 
 1337: 		"\t".'@echo -n ""; ECODE=0 && { perl filecompare.pl -b4 \\'.
 1338: 		"\n\t".$sourceroot.'/'.$source." \\\n\t".
 1339: 		$targetroot.'/'.$target." \\\n\t".
 1340: 		' || ECODE=$$?; } && '."\\\n\t"."\\\n\t"."\\\n\t".
 1341: 
 1342: 
 1343: 		'{ [ $$ECODE != "2" ] || '." \\\n\t".'(install '.
 1344:                 $categoryhash{$categoryname}." \\\n\t\t".
 1345: 		$sourceroot.'/'.$source." \\\n\t\t".
 1346: 		$targetroot.'/'.$target.'.lpmlnew'." \\\n\t\t".
 1347: 		' && echo "**** NOTE: CONFIGURATION FILE CHANGE ****"'.
 1348: 		" \\\n\t\t".$logcmd.' && '." \\\n\t\t"."echo -n \"".
 1349: 		'You likely need to compare contents of "'."\\\n\t\t\t".
 1350: 		'&& echo -n "'.$targetroot.'/'.$target.'"'."\\\n\t\t".
 1351: 		'&& echo -n " with the new "'."\\\n\t\t\t".
 1352:                 '&& echo "'.$targetroot.'/'.$target.'.lpmlnew"'."\\\n\t\t".
 1353: 		"$logcmd); } && "." \\\n\t"."\\\n\t"."\\\n\t".
 1354: 
 1355: 
 1356: 		'{ [ $$ECODE != "3" ] || '."\\\n\t".
 1357: 		'(install '.
 1358:                 $categoryhash{$categoryname}."\\\n\t\t".
 1359: 		$sourceroot.'/'.$source."\\\n\t\t".
 1360: 		$targetroot.'/'.$target."\\\n\t\t".
 1361: 		' && echo "**** WARNING: NEW CONFIGURATION FILE ADDED ****"'.
 1362: 		"\\\n\t\t".$logcmd.' && '."\\\n\t\t".
 1363: 		'echo -n "'.
 1364: 		'You likely need to review the contents of "'."\\\n\t\t\t".
 1365: 		'&& echo -n "'.
 1366: 		$targetroot.'/'.$target.'"'."\\\n\t\t\t".
 1367: 		'&& echo -n "'.
 1368: 		' to make sure its "'."\\\n\t\t".
 1369: 		'&& echo "'.
 1370:                 'settings are compatible with your overall system"'."\\\n\t\t".
 1371: 		"$logcmd); } && "."\\\n\t"."\\\n\t"."\\\n\t".
 1372: 
 1373: 
 1374: 		'{ [ $$ECODE != "1" ] || ('."\\\n\t\t".
 1375: 		'echo "**** ERROR ****"'.$logcmd.' && '."\\\n\t\t".'echo -n "'.
 1376: 		'Configuration source file does not exist "'."\\\n\t\t".
 1377: 		'&& echo -n "'.$sourceroot.'/'.$source.'"'."\\\n\t\t".
 1378: 		"$logcmd); } && "."\\\n\t\t".
 1379: 		"perl verifymodown.pl ${targetroot}/${target} "."\\\n\t\t\t".
 1380: 		"\"$categoryhash{$categoryname}\""."\\\n\t\t\t".
 1381: 		"$logcmd;\n\n";
 1382: 	}
 1383: 	elsif ($mode eq 'build' && $build) {
 1384: 	    push @buildall,$sourceroot.'/'.$source;
 1385: 	    push @buildinfo,$targetroot.'/'.$target.';'.$sourceroot.'/'.
 1386: 		$source.';'.$build.';'.
 1387: 		$dependencies;
 1388: #	    return '# need to build '.$source.";
 1389: 	}
 1390:         elsif ($mode eq 'rpm_file_list') {
 1391: 	    if ($categoryname eq 'doc') {
 1392: 		return $targetroot.'/'.$target.' # doc'."\n";
 1393: 	    }
 1394: 	    elsif ($categoryname eq 'conf') {
 1395: 		return $targetroot.'/'.$target.' # config'."\n";
 1396: 	    }
 1397: 	    else {
 1398: 		return $targetroot.'/'.$target."\n";
 1399: 	    }
 1400: 	}
 1401: 	else {
 1402: 	    return '';
 1403: 	}
 1404:     }
 1405:     return '';
 1406: }
 1407: # --------------------------------------------------------- Format link section
 1408: sub format_link {
 1409:     my @tokeninfo=@_;
 1410:     $link=''; $linkto=''; $source=''; $target=''; $categoryname=''; 
 1411:     $description=''; $note=''; $build=''; $status=''; $dependencies='';
 1412:     my $text=&trim($parser->get_text('/link'));
 1413:     if ($linkto) {
 1414: 	$parser->get_tag('/link');
 1415: 	if ($mode eq 'html') {
 1416: 	    my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
 1417: 	    $link_count+=scalar(@targets);
 1418: 	    foreach my $tgt (@targets) {
 1419: 		$categorycount{$categoryname}++;
 1420: 		push @links,("\n<!-- FILESORT:$tgt -->".
 1421: 		    "<tr>".
 1422: 		    "<td><!-- POSTEVAL [$categoryname] verify.pl link ".
 1423: 		    "'/$targetrootarg$linkto' '/$targetrootarg$tgt' ".
 1424: 		    "$categoryhash{$categoryname} -->&nbsp;</td><td>".
 1425: 		    "<img src='$fab{$categoryname}.gif' ".
 1426: 		    "alt='$categoryname icon' /></td>".
 1427: 		    "<td><font size='-1'>$categoryname</font></td>".
 1428: 		    "<td>LINKTO: $linkto<br />TARGET: $tgt</td>".
 1429: 		    "<td>$description</td>".
 1430: 		    "<td>$note</td>".
 1431: 		    "</tr>");
 1432: #		push @links,"\t".'ln -fs /'.$linkto.' /'.$targetroot.$tgt.
 1433: #		    "\n";
 1434: 	    }
 1435: 	    return join('',@links);
 1436: #	    return ($link="\n<!-- FILESORT:$target -->".
 1437: #		    "<tr>".
 1438: #		    "<td>&nbsp;</td><td><img src='$fab{$categoryname}.gif' ".
 1439: #		    "alt='$categoryname icon' /></td>".
 1440: #		    "<td>$categoryname</td>".
 1441: #		    "<td>LINKTO: $linkto<br />TARGET: $target</td>".
 1442: #		    "<td>$description</td>".
 1443: #		    "<td>$note</td>".
 1444: #		    "</tr>");
 1445: #	    return $link="\n<tr><td colspan='6'>BEGIN LINK\n".
 1446: #		"$linkto $target $categoryname $description $note " .
 1447: #		"$build $status $dependencies" .
 1448: #		    "\nEND LINK</td></tr>";
 1449: 	}
 1450: 	elsif ($mode eq 'install') {
 1451: 	    my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
 1452: 	    foreach my $tgt (@targets) {
 1453: 		push @links,"\t".'ln -fs /'.$linkto.' '.$targetroot.'/'.$tgt.
 1454: 		    "\n";
 1455: 	    }
 1456: #	    return join('',@links);
 1457: 	    return '';
 1458: 	}
 1459: 	elsif ($mode eq 'rpm_file_list') {
 1460: 	    my @linklocs;
 1461: 	    my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
 1462: 	    foreach my $tgt (@targets) {
 1463: 		push @linklocs,''.$targetroot.'/'.$tgt."\n";
 1464: 	    }
 1465: 	    return join('',@linklocs);
 1466: 	}
 1467: 	else {
 1468: 	    return '';
 1469: 	}
 1470:     }
 1471:     return '';
 1472: }
 1473: # ----------------------------------------------------- Format fileglob section
 1474: sub format_fileglob {
 1475:     my @tokeninfo=@_;
 1476:     $fileglob=''; $glob=''; $sourcedir='';
 1477:     $targetdir=''; $categoryname=''; $description='';
 1478:     $note=''; $build=''; $status=''; $dependencies='';
 1479:     $filenames='';
 1480:     my $text=&trim($parser->get_text('/fileglob'));
 1481:     my $filenames2=$filenames;$filenames2=~s/\s//g;
 1482:     $fileglob_count++;
 1483:     my @semi=($filenames2=~/(\;)/g);
 1484:     $fileglobnames_count+=scalar(@semi)+1;
 1485:     $categorycount{$categoryname}+=scalar(@semi)+1;
 1486:     if ($sourcedir) {
 1487: 	$parser->get_tag('/fileglob');
 1488: 	if ($mode eq 'MANIFEST') {
 1489:          return join("\n",(map {"$sourcedir$_"} split(/\;/,$filenames2)))."\n";
 1490: 	}
 1491: 	elsif ($mode eq 'html') {
 1492: 	    return $fileglob="\n<tr>".
 1493:       "<td><!-- POSTEVAL [$categoryname] verify.pl fileglob '$sourcerootarg' ".
 1494: 		"'$targetrootarg' ".
 1495: 		"'$glob' '$sourcedir' '$filenames2' '$targetdir' ".
 1496: 		"$categoryhash{$categoryname} -->&nbsp;</td>".
 1497: 		"<td>"."<img src='$fab{$categoryname}.gif' ".
 1498: 	        "alt='$categoryname icon' /></td>".
 1499: 		"<td>$categoryname<br />".
 1500: 		"<font size='-1'>".$categoryhash{$categoryname}."</font></td>".
 1501: 		"<td>SOURCEDIR: $sourcedir<br />".
 1502: 		"TARGETDIR: $targetdir<br />".
 1503:                 "GLOB: $glob<br />".
 1504:                 "FILENAMES: $filenames".
 1505: 		"</td>".
 1506: 		"<td>$description</td>".
 1507: 		"<td>$note</td>".
 1508: 		"</tr>";
 1509: #	    return $fileglob="\n<tr><td colspan='6'>BEGIN FILEGLOB\n".
 1510: #		"$glob sourcedir $targetdir $categoryname $description $note ".
 1511: #		"$build $status $dependencies $filenames" .
 1512: #		"\nEND FILEGLOB</td></tr>";
 1513: 	}
 1514: 	elsif ($mode eq 'install') {
 1515: 	    my $eglob=$glob;
 1516: 	    if ($glob eq '*') {
 1517: 		$eglob='[^C][^V][^S]'.$glob;
 1518: 	    }
 1519: 	    return "\t".'install '.
 1520: 		$categoryhash{$categoryname}.' '.
 1521: 		$sourceroot.'/'.$sourcedir.$eglob.' '.
 1522: 		$targetroot.'/'.$targetdir.'.'."\n";
 1523: 	}
 1524: 	elsif ($mode eq 'rpm_file_list') {
 1525: 	    my $eglob=$glob;
 1526: 	    if ($glob eq '*') {
 1527: 		$eglob='[^C][^V][^S]'.$glob;
 1528: 	    }
 1529: 	    my $targetdir2=$targetdir;$targetdir2=~s/\/$//;
 1530: 	    my @gfiles=map {s/^.*\///;"$targetroot/$targetdir2/$_\n"}
 1531: 	               glob("$sourceroot/$sourcedir/$eglob");
 1532: 	    return join('',@gfiles);
 1533: 	}
 1534: 	else {
 1535: 	    return '';
 1536: 	}
 1537:     }
 1538:     return '';
 1539: }
 1540: # ---------------------------------------------------- Format sourcedir section
 1541: sub format_sourcedir {
 1542:     my @tokeninfo=@_;
 1543:     $sourcedir='';
 1544:     my $text=&trim($parser->get_text('/sourcedir'));
 1545:     if ($text) {
 1546: 	$parser->get_tag('/sourcedir');
 1547: 	$sourcedir=$text;
 1548:     }
 1549:     return '';
 1550: }
 1551: # ------------------------------------------------------- Format target section
 1552: sub format_target {
 1553:     my @tokeninfo=@_;
 1554:     $target='';
 1555:     my $text=&trim($parser->get_text('/target'));
 1556:     if ($text) {
 1557: 	$parser->get_tag('/target');
 1558: 	$target=$text;
 1559:     }
 1560:     return '';
 1561: }
 1562: # ------------------------------------------------------- Format source section
 1563: sub format_source {
 1564:     my @tokeninfo=@_;
 1565:     $source='';
 1566:     my $text=&trim($parser->get_text('/source'));
 1567:     if ($text) {
 1568: 	$parser->get_tag('/source');
 1569: 	$source=$text;
 1570:     }
 1571:     return '';
 1572: }
 1573: # --------------------------------------------------------- Format note section
 1574: sub format_note {
 1575:     my @tokeninfo=@_;
 1576:     $note='';
 1577: #    my $text=&trim($parser->get_text('/note'));
 1578:     my $aref;
 1579:     my $text;
 1580:     while ($aref=$parser->get_token()) {
 1581: 	if ($aref->[0] eq 'E' && $aref->[1] eq 'note') {
 1582: 	    last;
 1583: 	}
 1584: 	elsif ($aref->[0] eq 'S') {
 1585: 	    $text.=$aref->[4];
 1586: 	}
 1587: 	elsif ($aref->[0] eq 'E') {
 1588: 	    $text.=$aref->[2];
 1589: 	}
 1590: 	else {
 1591: 	    $text.=$aref->[1];
 1592: 	}
 1593:     }
 1594:     if ($text) {
 1595: #	$parser->get_tag('/note');
 1596: 	$note=$text;
 1597:     }
 1598:     return '';
 1599: 
 1600: }
 1601: # -------------------------------------------------------- Format build section
 1602: sub format_build {
 1603:     my @tokeninfo=@_;
 1604:     $build='';
 1605:     my $text=&trim($parser->get_text('/build'));
 1606:     if ($text) {
 1607: 	$parser->get_tag('/build');
 1608: 	$build=$sourceroot.'/'.$text.';'.$tokeninfo[2]{'trigger'};
 1609: 	$build=~s/([^\\])\\\s+/$1/g; # allow for lines split onto new lines
 1610:     }
 1611:     return '';
 1612: }
 1613: # ------------------------------------------------ Format installscript section
 1614: sub format_installscript {
 1615:     my @tokeninfo=@_;
 1616:     $installscript= &trim($parser->get_text('/installscript'));
 1617:     if ($installscript) {
 1618: 	$parser->get_tag('/installscript');
 1619: 	$installscript=~s/([^\\])\\\s+/$1/g; # allow for lines split onto new lines
 1620:     }
 1621:     return '';
 1622: }
 1623: # -------------------------------------------------------- Format build section
 1624: sub format_buildlink {
 1625:     my @tokeninfo=@_;
 1626:     $buildlink='';
 1627:     my $text=&trim($parser->get_text('/buildlink'));
 1628:     if ($text) {
 1629: 	$parser->get_tag('/buildlink');
 1630: 	$buildlink=$sourceroot.'/'.$text;
 1631:     }
 1632:     return '';
 1633: }
 1634: # ------------------------------------------------------- Format status section
 1635: sub format_status {
 1636:     my @tokeninfo=@_;
 1637:     $status='';
 1638:     my $text=&trim($parser->get_text('/status'));
 1639:     if ($text) {
 1640: 	$parser->get_tag('/status');
 1641: 	$status=$text;
 1642:     }
 1643:     return '';
 1644: }
 1645: # ------------------------------------------------- Format dependencies section
 1646: sub format_dependencies {
 1647:     my @tokeninfo=@_;
 1648:     #$dependencies='';
 1649:     my $text=&trim($parser->get_text('/dependencies'));
 1650:     if ($text) {
 1651: 	$parser->get_tag('/dependencies');
 1652: 	$dependencies=join(';',((map {s/^\s*//;s/\s$//;$_} split(/\;/,$text)),$dependencies));
 1653: 	$dependencies=~s/;$//;
 1654:     }
 1655:     return '';
 1656: }
 1657: sub format_privatedependencies {
 1658:     my @tokeninfo=@_;
 1659:     #$dependencies='';
 1660:     my $text=&trim($parser->get_text('/privatedependencies'));
 1661:     if ($text) {
 1662: 	$parser->get_tag('/privatedependencies');
 1663: 	if ($mode eq 'MANIFEST') { return '';	}
 1664: 	$dependencies=join(';',((map {s/^\s*//;s/\s$//;$_} split(/\;/,$text)),$dependencies));
 1665: 	$dependencies=~s/;$//;
 1666:     }
 1667:     return '';
 1668: }
 1669: # --------------------------------------------------------- Format glob section
 1670: sub format_glob {
 1671:     my @tokeninfo=@_;
 1672:     $glob='';
 1673:     my $text=&trim($parser->get_text('/glob'));
 1674:     if ($text) {
 1675: 	$parser->get_tag('/glob');
 1676: 	$glob=$text;
 1677:     }
 1678:     return '';
 1679: }
 1680: # ---------------------------------------------------- Format filenames section
 1681: sub format_filenames {
 1682:     my @tokeninfo=@_;
 1683:     my $text=&trim($parser->get_text('/filenames'));
 1684:     if ($text) {
 1685: 	$parser->get_tag('/filenames');
 1686: 	$filenames=$text;
 1687:     }
 1688:     return '';
 1689: }
 1690: # ----------------------------------------------- Format specialnotices section
 1691: sub format_specialnotices {
 1692:     $parser->get_tag('/specialnotices');
 1693:     return '';
 1694: }
 1695: # ------------------------------------------------ Format specialnotice section
 1696: sub format_specialnotice {
 1697:     $parser->get_tag('/specialnotice');
 1698:     return '';
 1699: }
 1700: # ------------------------------------------------------- Format linkto section
 1701: sub format_linkto {
 1702:     my @tokeninfo=@_;
 1703:     my $text=&trim($parser->get_text('/linkto'));
 1704:     if ($text) {
 1705: 	$parser->get_tag('/linkto');
 1706: 	$linkto=$text;
 1707:     }
 1708:     return '';
 1709: }
 1710: # ------------------------------------- Render less-than and greater-than signs
 1711: sub htmlsafe {
 1712:     my $text=@_[0];
 1713:     $text =~ s/</&lt;/g;
 1714:     $text =~ s/>/&gt;/g;
 1715:     return $text;
 1716: }
 1717: # --------------------------------------- remove starting and ending whitespace
 1718: sub trim {
 1719:     my ($s)=@_; $s=~s/^\s*//; $s=~s/\s*$//; return $s;
 1720: } 
 1721: 
 1722: # ----------------------------------- POD (plain old documentation, CPAN style)
 1723: 
 1724: =pod
 1725: 
 1726: =head1 NAME
 1727: 
 1728: lpml_parse.pl - This is meant to parse files meeting the lpml document type.
 1729: 
 1730: =head1 SYNOPSIS
 1731: 
 1732: <STDIN> | perl lpml_parse.pl <MODE> <CATEGORY> <DIST> <SOURCE> <TARGET>
 1733: 
 1734: Usage is for the lpml file to come in through standard input.
 1735: 
 1736: =over 4
 1737: 
 1738: =item *
 1739: 
 1740: 1st argument is the mode of parsing.
 1741: 
 1742: =item * 
 1743: 
 1744: 2nd argument is the category permissions to use (runtime or development)
 1745: 
 1746: =item *
 1747: 
 1748: 3rd argument is the distribution
 1749: (default,redhat6.2,debian2.2,redhat7.1,etc).
 1750: 
 1751: =item *
 1752: 
 1753: 4th argument is to manually specify a sourceroot.
 1754: 
 1755: =item *
 1756: 
 1757: 5th argument is to manually specify a targetroot.
 1758: 
 1759: =back
 1760: 
 1761: Only the 1st argument is mandatory for the program to run.
 1762: 
 1763: Example:
 1764: 
 1765: cat ../../doc/loncapafiles.lpml |\\
 1766: perl lpml_parse.pl html runtime default /home/sherbert/loncapa /tmp/install
 1767: 
 1768: =head1 DESCRIPTION
 1769: 
 1770: The general flow of the script is to get command line arguments, run through
 1771: the XML document three times, and output according to any desired mode:
 1772: install, configinstall, build, rpm, dpkg, htmldoc, textdoc, and status.
 1773: 
 1774: A number of coding decisions are made according to the following principle:
 1775: installation software must be stand-alone.  Therefore, for instance, I try
 1776: not to use the GetOpt::Long module or any other perl modules.  (I do however
 1777: use HTML::TokeParser.)  I also have tried to keep all the MODES of
 1778: parsing inside this file.  Therefore, format_TAG subroutines are fairly
 1779: lengthy with their conditional logic.  A more "elegant" solution might
 1780: be to dynamically register the parsing mode and subroutines, or maybe even work
 1781: with stylesheets.  However, in order to make this the installation back-bone
 1782: of choice, there are advantages for HAVING EVERYTHING IN ONE FILE.
 1783: This way, the LPML installation software does not have to rely on OTHER
 1784: installation software (a chicken versus the egg problem).  Besides, I would
 1785: suggest the modes of parsing are fairly constant: install, configinstall,
 1786: build, rpm, dpkg, htmldoc, textdoc, and status.
 1787: 
 1788: Another coding decision is about using a multiple pass-through approach to
 1789: parsing the lpml file.  This saves memory and makes sure the server will never
 1790: be overloaded.  During the first pass-through, the script gathers information
 1791: specific as to resolving what tags with what 'dist=' attributes are to be used.
 1792: During the second pass-through, the script cleans up white-space surrounding
 1793: the XML tags, and filters through the tags based on information regarding the
 1794: 'dist=' attributes (information gathered in the first pass-through).
 1795: The third and final pass-through involves formatting and rendering the XML
 1796: into whatever XML mode is chosen: install, configinstall, build, rpm, dpkg,
 1797: htmldoc, textdoc, and status.
 1798: 
 1799: The hierarchy mandated by the DTD does not always correspond to the hierarchy
 1800: that is sensible for a Makefile.  For instance, in a Makefile it is sensible
 1801: that soft-links are installed after files.  However, in an LPML document, it
 1802: is sensible that files and links be considered together and the writer of the
 1803: LPML document should be free to place things in whatever order makes best
 1804: sense in terms of LOOKING at the information.  The complication that arises
 1805: is that the parser needs to have a memory for passing values from
 1806: leaves on the XML tree to higher-up branches.  Currently, this memory is
 1807: hard-coded (like with the @links array), but it may benefit from a more
 1808: formal approach in the future.
 1809: 
 1810: =head1 README
 1811: 
 1812: This parses an LPML file to generate information useful for
 1813: source to target installation, compilation, filesystem status
 1814: checking, RPM and Debian software packaging, and documentation.
 1815: 
 1816: More information on LPML is available at http://lpml.sourceforge.net.
 1817: 
 1818: =head1 PREREQUISITES
 1819: 
 1820: HTML::TokeParser
 1821: 
 1822: =head1 COREQUISITES
 1823: 
 1824: =head1 OSNAMES
 1825: 
 1826: linux
 1827: 
 1828: =head1 SCRIPT CATEGORIES
 1829: 
 1830: UNIX/System_administration
 1831: 
 1832: =head1 AUTHOR
 1833: 
 1834:  Scott Harrison
 1835:  codeharrison@yahoo.com
 1836: 
 1837: Please let me know how/if you are finding this script useful and
 1838: any/all suggestions.  -Scott
 1839: 
 1840: =cut

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