Annotation of loncom/build/lpml_parse.pl, revision 1.51

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

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