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

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

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