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

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.48    ! harris41   15: # $Id: lpml_parse.pl,v 1.5 2002/05/19 17:45:49 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') {
1.47      harris41 1181: 	    my $command=$build;
                   1182: 	    if ($command!~/\s/) {
                   1183: 		$command=~s/\/([^\/]*)$//;
                   1184: 	    }
                   1185: 	    else {
                   1186: 		$command=~s/(.*?\/)([^\/]+\s+.*)$/$1/;
                   1187: 	    }
                   1188: 	    $command=~s/^$sourceroot\///;
                   1189: 	    my (@deps)=split(/\;/,$dependencies);
                   1190: 	    my $retval=join("\n",($source,
                   1191: 		       (map {"$command$_"} @deps)));
                   1192: 	    return $retval."\n";
1.46      harris41 1193: 	}
                   1194: 	elsif ($mode eq 'html') {
1.26      harris41 1195: 	    return ($file="\n<!-- FILESORT:$target -->".
                   1196: 		    "<tr>".
1.41      harris41 1197:           "<td><!-- POSTEVAL [$categoryname] verify.pl file '$sourcerootarg' ".
1.28      harris41 1198: 		    "'$targetrootarg' ".
                   1199: 		    "'$source' '$target' ".
                   1200: 		    "$categoryhash{$categoryname} -->&nbsp;</td><td>".
1.27      harris41 1201: 		    "<img src='$fab{$categoryname}.gif' ".
1.26      harris41 1202: 		    "alt='$categoryname icon' /></td>".
1.27      harris41 1203: 		    "<td>$categoryname<br /><font size='-1'>".
                   1204: 		    $categoryhash{$categoryname}."</font></td>".
1.26      harris41 1205: 		    "<td>SOURCE: $source<br />TARGET: $target</td>".
                   1206: 		    "<td>$description</td>".
                   1207: 		    "<td>$note</td>".
                   1208: 		    "</tr>");
                   1209: #	    return ($file="\n<br />BEGIN FILE\n".
                   1210: #		"$source $target $categoryname $description $note " .
                   1211: #		"$build $status $dependencies" .
                   1212: #		"\nEND FILE");
1.3       harris41 1213: 	}
1.5       harris41 1214: 	elsif ($mode eq 'install' && $categoryname ne 'conf') {
1.14      harris41 1215: 	    if ($build) {
                   1216: 		my $bi=$sourceroot.'/'.$source.';'.$build.';'.
                   1217: 		    $dependencies;
                   1218: 		my ($source2,$command,$trigger,@deps)=split(/\;/,$bi);
                   1219: 		$tword=''; $tword=' alwaysrun' if $trigger eq 'always run'; 
                   1220: 		$command=~s/\/([^\/]*)$//;
                   1221: 		$command2="cd $command; sh ./$1;\\";
                   1222: 		my $depstring;
                   1223: 		foreach my $dep (@deps) {
                   1224: 		    $depstring.=<<END;
                   1225: 		ECODE=0; DEP=''; \\
1.34      harris41 1226: 		test -e $dep || (echo '**** WARNING **** cannot evaluate status of dependency $dep (for building ${sourceroot}/${source} with)'$logcmd); DEP="1"; \\
                   1227: 		[ -n DEP ] && { perl filecompare.pl -b2 $dep ${targetroot}/${target} || ECODE=\$\$?; } || DEP="1"; \\
1.14      harris41 1228: 		case "\$\$ECODE" in \\
1.34      harris41 1229: 			2) echo "**** WARNING **** dependency $dep is newer than target file ${targetroot}/${target}; you may want to run make build"$logcmd;; \\
1.14      harris41 1230: 		esac; \\
                   1231: END
                   1232: 		}
                   1233:                 chomp $depstring;
                   1234: 		$buildtest=<<END;
                   1235: 	\@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
1.19      harris41 1236: 		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 1237: END
                   1238:                 $buildtest.=<<END if $depstring;
                   1239: 	elif !(test -e "${sourceroot}/${source}"); then \\
                   1240: $depstring
                   1241: END
                   1242:                 $buildtest.=<<END;
                   1243: 	fi
                   1244: END
                   1245: 	    }
1.18      harris41 1246:             my $bflag='-b1';
                   1247:             $bflag='-b3' if $dependencies or $buildlink;
1.14      harris41 1248: 	    return <<END;
1.19      harris41 1249: $buildtest	\@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
                   1250: 		echo "**** ERROR **** CVS source file does not exist: ${sourceroot}/${source} and neither does target: ${targetroot}/${target}"$logcmd; \\
                   1251: 	elif !(test -e "${sourceroot}/${source}"); then \\
                   1252: 		echo "**** WARNING **** CVS source file does not exist: ${sourceroot}/${source}"$logcmd; \\
1.21      harris41 1253: 		perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\
1.14      harris41 1254: 	else \\
                   1255: 		ECODE=0; \\
                   1256: 		perl filecompare.pl $bflag ${sourceroot}/${source} ${targetroot}/${target} || ECODE=\$\$?; \\
                   1257: 		case "\$\$ECODE" in \\
                   1258: 			1) echo "${targetroot}/${target} is unchanged";; \\
1.21      harris41 1259: 			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 1260: 			0) echo "install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target}" && install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target};; \\
1.14      harris41 1261: 		esac; \\
1.21      harris41 1262: 		perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\
1.14      harris41 1263: 	fi
                   1264: END
1.12      harris41 1265: 	}
                   1266: 	elsif ($mode eq 'configinstall' && $categoryname eq 'conf') {
                   1267: 	    push @configall,$targetroot.'/'.$target;
1.14      harris41 1268: 	    return $targetroot.'/'.$target.': alwaysrun'."\n".
1.48    ! harris41 1269: 		"\t".'@# Compare source with target and intelligently respond'.
        !          1270: 		"\n\t\n\t\n".
        !          1271: 
        !          1272: 
        !          1273: 		"\t".'@echo -n ""; ECODE=0 && { perl filecompare.pl -b4 \\'.
        !          1274: 		"\n\t".$sourceroot.'/'.$source." \\\n\t".
        !          1275: 		$targetroot.'/'.$target." \\\n\t".
        !          1276: 		' || ECODE=$$?; } && '."\\\n\t"."\\\n\t"."\\\n\t".
        !          1277: 
        !          1278: 
        !          1279: 		'{ [ $$ECODE != "2" ] || '." \\\n\t".'(install '.
        !          1280:                 $categoryhash{$categoryname}." \\\n\t\t".
        !          1281: 		$sourceroot.'/'.$source." \\\n\t\t".
        !          1282: 		$targetroot.'/'.$target.'.lpmlnew'." \\\n\t\t".
1.19      harris41 1283: 		' && echo "**** NOTE: CONFIGURATION FILE CHANGE ****"'.
1.48    ! harris41 1284: 		" \\\n\t\t".$logcmd.' && '." \\\n\t\t"."echo -n \"".
        !          1285: 		'You likely need to compare contents of "'."\\\n\t\t\t".
        !          1286: 		'echo -n "'.$targetroot.'/'.$target.'"'."\\\n\t\t".
        !          1287: 		'echo -n "with the new "'."\\\n\t\t\t".
        !          1288:                 'echo "'.$targetroot.'/'.$target.'.lpmlnew"'."\\\n\t\t".
        !          1289: 		"$logcmd); } && "." \\\n\t"."\\\n\t"."\\\n\t".
        !          1290: 
        !          1291: 
        !          1292: 		'{ [ $$ECODE != "3" ] || '."\\\n\t".
        !          1293: 		'(install '.
        !          1294:                 $categoryhash{$categoryname}."\\\n\t\t".
        !          1295: 		$sourceroot.'/'.$source."\\\n\t\t".
        !          1296: 		$targetroot.'/'.$target."\\\n\t\t".
1.20      harris41 1297: 		' && echo "**** WARNING: NEW CONFIGURATION FILE ADDED ****"'.
1.48    ! harris41 1298: 		"\\\n\t\t".$logcmd.' && '."\\\n\t\t".
        !          1299: 		'echo -n "'.
        !          1300: 		'You likely need to review the contents of "'."\\\n\t\t\t".
        !          1301: 		'echo -n "'.
        !          1302: 		$targetroot.'/'.$target.'"'."\\\n\t\t\t".
        !          1303: 		'echo -n "'.
        !          1304: 		'to make sure its "'."\\\n\t\t".
        !          1305: 		'echo "'.
        !          1306:                 'settings are compatible with your overall system"'."\\\n\t\t".
        !          1307: 		"$logcmd); } && "."\\\n\t"."\\\n\t"."\\\n\t".
        !          1308: 
        !          1309: 
        !          1310: 		'{ [ $$ECODE != "1" ] || ('."\\\n\t\t".
        !          1311: 		'echo "**** ERROR ****"'.$logcmd.' && '."\\\n\t\t".'echo -n "'.
        !          1312: 		'Configuration source file does not exist "'."\\\n\t\t".
        !          1313: 		'echo -n "'.$sourceroot.'/'.$source.'"'."\\\n\t\t".
        !          1314: 		"$logcmd); } && "."\\\n\t\t".
        !          1315: 		"perl verifymodown.pl ${targetroot}/${target} "."\\\n\t\t\t".
        !          1316: 		"\"$categoryhash{$categoryname}\""."\\\n\t\t\t".
        !          1317: 		"$logcmd;\n\n";
1.4       harris41 1318: 	}
1.11      harris41 1319: 	elsif ($mode eq 'build' && $build) {
                   1320: 	    push @buildall,$sourceroot.'/'.$source;
1.14      harris41 1321: 	    push @buildinfo,$targetroot.'/'.$target.';'.$sourceroot.'/'.
                   1322: 		$source.';'.$build.';'.
1.11      harris41 1323: 		$dependencies;
                   1324: #	    return '# need to build '.$source.";
                   1325: 	}
1.35      harris41 1326:         elsif ($mode eq 'rpm_file_list') {
                   1327: 	    if ($categoryname eq 'doc') {
                   1328: 		return $targetroot.'/'.$target.' # doc'."\n";
                   1329: 	    }
                   1330: 	    elsif ($categoryname eq 'conf') {
                   1331: 		return $targetroot.'/'.$target.' # config'."\n";
                   1332: 	    }
                   1333: 	    else {
                   1334: 		return $targetroot.'/'.$target."\n";
                   1335: 	    }
                   1336: 	}
1.3       harris41 1337: 	else {
                   1338: 	    return '';
                   1339: 	}
                   1340:     }
                   1341:     return '';
                   1342: }
                   1343: # --------------------------------------------------------- Format link section
                   1344: sub format_link {
                   1345:     my @tokeninfo=@_;
1.27      harris41 1346:     $link=''; $linkto=''; $source=''; $target=''; $categoryname=''; 
                   1347:     $description=''; $note=''; $build=''; $status=''; $dependencies='';
1.3       harris41 1348:     my $text=&trim($parser->get_text('/link'));
                   1349:     if ($linkto) {
                   1350: 	$parser->get_tag('/link');
                   1351: 	if ($mode eq 'html') {
1.27      harris41 1352: 	    my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
1.29      harris41 1353: 	    $link_count+=scalar(@targets);
1.27      harris41 1354: 	    foreach my $tgt (@targets) {
1.29      harris41 1355: 		$categorycount{$categoryname}++;
1.27      harris41 1356: 		push @links,("\n<!-- FILESORT:$tgt -->".
                   1357: 		    "<tr>".
1.32      harris41 1358: 		    "<td><!-- POSTEVAL [$categoryname] verify.pl link ".
1.28      harris41 1359: 		    "'/$targetrootarg$linkto' '/$targetrootarg$tgt' ".
                   1360: 		    "$categoryhash{$categoryname} -->&nbsp;</td><td>".
1.27      harris41 1361: 		    "<img src='$fab{$categoryname}.gif' ".
                   1362: 		    "alt='$categoryname icon' /></td>".
                   1363: 		    "<td><font size='-1'>$categoryname</font></td>".
                   1364: 		    "<td>LINKTO: $linkto<br />TARGET: $tgt</td>".
                   1365: 		    "<td>$description</td>".
                   1366: 		    "<td>$note</td>".
                   1367: 		    "</tr>");
                   1368: #		push @links,"\t".'ln -fs /'.$linkto.' /'.$targetroot.$tgt.
                   1369: #		    "\n";
                   1370: 	    }
                   1371: 	    return join('',@links);
                   1372: #	    return ($link="\n<!-- FILESORT:$target -->".
                   1373: #		    "<tr>".
                   1374: #		    "<td>&nbsp;</td><td><img src='$fab{$categoryname}.gif' ".
                   1375: #		    "alt='$categoryname icon' /></td>".
                   1376: #		    "<td>$categoryname</td>".
                   1377: #		    "<td>LINKTO: $linkto<br />TARGET: $target</td>".
                   1378: #		    "<td>$description</td>".
                   1379: #		    "<td>$note</td>".
                   1380: #		    "</tr>");
                   1381: #	    return $link="\n<tr><td colspan='6'>BEGIN LINK\n".
                   1382: #		"$linkto $target $categoryname $description $note " .
                   1383: #		"$build $status $dependencies" .
                   1384: #		    "\nEND LINK</td></tr>";
1.4       harris41 1385: 	}
                   1386: 	elsif ($mode eq 'install') {
1.10      harris41 1387: 	    my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
1.5       harris41 1388: 	    foreach my $tgt (@targets) {
1.35      harris41 1389: 		push @links,"\t".'ln -fs /'.$linkto.' '.$targetroot.'/'.$tgt.
1.5       harris41 1390: 		    "\n";
                   1391: 	    }
1.35      harris41 1392: #	    return join('',@links);
1.4       harris41 1393: 	    return '';
1.3       harris41 1394: 	}
1.35      harris41 1395: 	elsif ($mode eq 'rpm_file_list') {
                   1396: 	    my @linklocs;
                   1397: 	    my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
                   1398: 	    foreach my $tgt (@targets) {
                   1399: 		push @linklocs,''.$targetroot.'/'.$tgt."\n";
                   1400: 	    }
                   1401: 	    return join('',@linklocs);
                   1402: 	}
1.3       harris41 1403: 	else {
                   1404: 	    return '';
                   1405: 	}
                   1406:     }
                   1407:     return '';
                   1408: }
                   1409: # ----------------------------------------------------- Format fileglob section
                   1410: sub format_fileglob {
                   1411:     my @tokeninfo=@_;
                   1412:     $fileglob=''; $glob=''; $sourcedir='';
                   1413:     $targetdir=''; $categoryname=''; $description='';
                   1414:     $note=''; $build=''; $status=''; $dependencies='';
                   1415:     $filenames='';
                   1416:     my $text=&trim($parser->get_text('/fileglob'));
1.27      harris41 1417:     my $filenames2=$filenames;$filenames2=~s/\s//g;
1.29      harris41 1418:     $fileglob_count++;
                   1419:     my @semi=($filenames2=~/(\;)/g);
                   1420:     $fileglobnames_count+=scalar(@semi)+1;
                   1421:     $categorycount{$categoryname}+=scalar(@semi)+1;
1.3       harris41 1422:     if ($sourcedir) {
                   1423: 	$parser->get_tag('/fileglob');
1.46      harris41 1424: 	if ($mode eq 'MANIFEST') {
                   1425:          return join("\n",(map {"$sourcedir$_"} split(/\;/,$filenames2)))."\n";
                   1426: 	}
                   1427: 	elsif ($mode eq 'html') {
1.27      harris41 1428: 	    return $fileglob="\n<tr>".
1.41      harris41 1429:       "<td><!-- POSTEVAL [$categoryname] verify.pl fileglob '$sourcerootarg' ".
1.27      harris41 1430: 		"'$targetrootarg' ".
                   1431: 		"'$glob' '$sourcedir' '$filenames2' '$targetdir' ".
                   1432: 		"$categoryhash{$categoryname} -->&nbsp;</td>".
                   1433: 		"<td>"."<img src='$fab{$categoryname}.gif' ".
                   1434: 	        "alt='$categoryname icon' /></td>".
                   1435: 		"<td>$categoryname<br />".
                   1436: 		"<font size='-1'>".$categoryhash{$categoryname}."</font></td>".
                   1437: 		"<td>SOURCEDIR: $sourcedir<br />".
                   1438: 		"TARGETDIR: $targetdir<br />".
                   1439:                 "GLOB: $glob<br />".
                   1440:                 "FILENAMES: $filenames".
                   1441: 		"</td>".
                   1442: 		"<td>$description</td>".
                   1443: 		"<td>$note</td>".
                   1444: 		"</tr>";
                   1445: #	    return $fileglob="\n<tr><td colspan='6'>BEGIN FILEGLOB\n".
                   1446: #		"$glob sourcedir $targetdir $categoryname $description $note ".
                   1447: #		"$build $status $dependencies $filenames" .
                   1448: #		"\nEND FILEGLOB</td></tr>";
1.3       harris41 1449: 	}
1.5       harris41 1450: 	elsif ($mode eq 'install') {
1.30      harris41 1451: 	    my $eglob=$glob;
                   1452: 	    if ($glob eq '*') {
                   1453: 		$eglob='[^C][^V][^S]'.$glob;
                   1454: 	    }
1.5       harris41 1455: 	    return "\t".'install '.
                   1456: 		$categoryhash{$categoryname}.' '.
1.30      harris41 1457: 		$sourceroot.'/'.$sourcedir.$eglob.' '.
1.5       harris41 1458: 		$targetroot.'/'.$targetdir.'.'."\n";
1.35      harris41 1459: 	}
                   1460: 	elsif ($mode eq 'rpm_file_list') {
                   1461: 	    my $eglob=$glob;
                   1462: 	    if ($glob eq '*') {
                   1463: 		$eglob='[^C][^V][^S]'.$glob;
                   1464: 	    }
                   1465: 	    my $targetdir2=$targetdir;$targetdir2=~s/\/$//;
                   1466: 	    my @gfiles=map {s/^.*\///;"$targetroot/$targetdir2/$_\n"}
                   1467: 	               glob("$sourceroot/$sourcedir/$eglob");
                   1468: 	    return join('',@gfiles);
1.5       harris41 1469: 	}
1.3       harris41 1470: 	else {
                   1471: 	    return '';
                   1472: 	}
                   1473:     }
                   1474:     return '';
                   1475: }
                   1476: # ---------------------------------------------------- Format sourcedir section
                   1477: sub format_sourcedir {
                   1478:     my @tokeninfo=@_;
                   1479:     $sourcedir='';
                   1480:     my $text=&trim($parser->get_text('/sourcedir'));
                   1481:     if ($text) {
                   1482: 	$parser->get_tag('/sourcedir');
                   1483: 	$sourcedir=$text;
                   1484:     }
                   1485:     return '';
                   1486: }
                   1487: # ------------------------------------------------------- Format target section
                   1488: sub format_target {
                   1489:     my @tokeninfo=@_;
                   1490:     $target='';
                   1491:     my $text=&trim($parser->get_text('/target'));
                   1492:     if ($text) {
                   1493: 	$parser->get_tag('/target');
                   1494: 	$target=$text;
                   1495:     }
                   1496:     return '';
                   1497: }
                   1498: # ------------------------------------------------------- Format source section
                   1499: sub format_source {
                   1500:     my @tokeninfo=@_;
                   1501:     $source='';
                   1502:     my $text=&trim($parser->get_text('/source'));
                   1503:     if ($text) {
                   1504: 	$parser->get_tag('/source');
                   1505: 	$source=$text;
                   1506:     }
                   1507:     return '';
                   1508: }
                   1509: # --------------------------------------------------------- Format note section
                   1510: sub format_note {
                   1511:     my @tokeninfo=@_;
                   1512:     $note='';
1.26      harris41 1513: #    my $text=&trim($parser->get_text('/note'));
                   1514:     my $aref;
                   1515:     my $text;
                   1516:     while ($aref=$parser->get_token()) {
                   1517: 	if ($aref->[0] eq 'E' && $aref->[1] eq 'note') {
                   1518: 	    last;
                   1519: 	}
                   1520: 	elsif ($aref->[0] eq 'S') {
                   1521: 	    $text.=$aref->[4];
                   1522: 	}
                   1523: 	elsif ($aref->[0] eq 'E') {
                   1524: 	    $text.=$aref->[2];
                   1525: 	}
                   1526: 	else {
                   1527: 	    $text.=$aref->[1];
                   1528: 	}
                   1529:     }
1.3       harris41 1530:     if ($text) {
1.26      harris41 1531: #	$parser->get_tag('/note');
1.3       harris41 1532: 	$note=$text;
                   1533:     }
                   1534:     return '';
                   1535: 
                   1536: }
                   1537: # -------------------------------------------------------- Format build section
                   1538: sub format_build {
                   1539:     my @tokeninfo=@_;
                   1540:     $build='';
                   1541:     my $text=&trim($parser->get_text('/build'));
                   1542:     if ($text) {
                   1543: 	$parser->get_tag('/build');
1.11      harris41 1544: 	$build=$sourceroot.'/'.$text.';'.$tokeninfo[2]{'trigger'};
1.42      harris41 1545: 	$build=~s/([^\\])\\\s+/$1/g; # allow for lines split onto new lines
1.3       harris41 1546:     }
                   1547:     return '';
                   1548: }
1.14      harris41 1549: # -------------------------------------------------------- Format build section
                   1550: sub format_buildlink {
                   1551:     my @tokeninfo=@_;
                   1552:     $buildlink='';
                   1553:     my $text=&trim($parser->get_text('/buildlink'));
                   1554:     if ($text) {
                   1555: 	$parser->get_tag('/buildlink');
                   1556: 	$buildlink=$sourceroot.'/'.$text;
                   1557:     }
                   1558:     return '';
                   1559: }
1.3       harris41 1560: # ------------------------------------------------------- Format status section
                   1561: sub format_status {
                   1562:     my @tokeninfo=@_;
                   1563:     $status='';
                   1564:     my $text=&trim($parser->get_text('/status'));
                   1565:     if ($text) {
                   1566: 	$parser->get_tag('/status');
                   1567: 	$status=$text;
                   1568:     }
                   1569:     return '';
                   1570: }
                   1571: # ------------------------------------------------- Format dependencies section
                   1572: sub format_dependencies {
                   1573:     my @tokeninfo=@_;
                   1574:     $dependencies='';
                   1575:     my $text=&trim($parser->get_text('/dependencies'));
                   1576:     if ($text) {
                   1577: 	$parser->get_tag('/dependencies');
1.11      harris41 1578: 	$dependencies=join(';',
                   1579: 			      (map {s/^\s*//;s/\s$//;$_} split(/\;/,$text)));
1.3       harris41 1580:     }
                   1581:     return '';
                   1582: }
                   1583: # --------------------------------------------------------- Format glob section
                   1584: sub format_glob {
                   1585:     my @tokeninfo=@_;
                   1586:     $glob='';
                   1587:     my $text=&trim($parser->get_text('/glob'));
                   1588:     if ($text) {
                   1589: 	$parser->get_tag('/glob');
                   1590: 	$glob=$text;
                   1591:     }
                   1592:     return '';
                   1593: }
                   1594: # ---------------------------------------------------- Format filenames section
                   1595: sub format_filenames {
                   1596:     my @tokeninfo=@_;
                   1597:     my $text=&trim($parser->get_text('/filenames'));
                   1598:     if ($text) {
                   1599: 	$parser->get_tag('/filenames');
                   1600: 	$filenames=$text;
                   1601:     }
1.31      harris41 1602:     return '';
                   1603: }
1.38      harris41 1604: # ----------------------------------------------- Format specialnotices section
1.31      harris41 1605: sub format_specialnotices {
                   1606:     $parser->get_tag('/specialnotices');
                   1607:     return '';
                   1608: }
                   1609: # ------------------------------------------------ Format specialnotice section
                   1610: sub format_specialnotice {
                   1611:     $parser->get_tag('/specialnotice');
1.3       harris41 1612:     return '';
                   1613: }
                   1614: # ------------------------------------------------------- Format linkto section
                   1615: sub format_linkto {
                   1616:     my @tokeninfo=@_;
                   1617:     my $text=&trim($parser->get_text('/linkto'));
                   1618:     if ($text) {
                   1619: 	$parser->get_tag('/linkto');
                   1620: 	$linkto=$text;
                   1621:     }
                   1622:     return '';
1.10      harris41 1623: }
                   1624: # ------------------------------------- Render less-than and greater-than signs
                   1625: sub htmlsafe {
                   1626:     my $text=@_[0];
                   1627:     $text =~ s/</&lt;/g;
                   1628:     $text =~ s/>/&gt;/g;
                   1629:     return $text;
1.3       harris41 1630: }
                   1631: # --------------------------------------- remove starting and ending whitespace
                   1632: sub trim {
                   1633:     my ($s)=@_; $s=~s/^\s*//; $s=~s/\s*$//; return $s;
                   1634: } 
1.14      harris41 1635: 
                   1636: # ----------------------------------- POD (plain old documentation, CPAN style)
1.18      harris41 1637: 
1.43      harris41 1638: =pod
                   1639: 
1.18      harris41 1640: =head1 NAME
                   1641: 
1.45      harris41 1642: lpml_parse.pl - This is meant to parse files meeting the lpml document type.
1.18      harris41 1643: 
                   1644: =head1 SYNOPSIS
                   1645: 
1.45      harris41 1646: <STDIN> | perl lpml_parse.pl <MODE> <CATEGORY> <DIST> <SOURCE> <TARGET>
                   1647: 
                   1648: Usage is for the lpml file to come in through standard input.
1.18      harris41 1649: 
                   1650: =over 4
                   1651: 
                   1652: =item *
                   1653: 
                   1654: 1st argument is the mode of parsing.
                   1655: 
                   1656: =item * 
                   1657: 
                   1658: 2nd argument is the category permissions to use (runtime or development)
                   1659: 
                   1660: =item *
                   1661: 
                   1662: 3rd argument is the distribution
                   1663: (default,redhat6.2,debian2.2,redhat7.1,etc).
                   1664: 
                   1665: =item *
                   1666: 
                   1667: 4th argument is to manually specify a sourceroot.
                   1668: 
                   1669: =item *
                   1670: 
                   1671: 5th argument is to manually specify a targetroot.
                   1672: 
                   1673: =back
                   1674: 
                   1675: Only the 1st argument is mandatory for the program to run.
                   1676: 
                   1677: Example:
                   1678: 
                   1679: cat ../../doc/loncapafiles.lpml |\\
1.45      harris41 1680: perl lpml_parse.pl html runtime default /home/sherbert/loncapa /tmp/install
1.18      harris41 1681: 
                   1682: =head1 DESCRIPTION
                   1683: 
1.45      harris41 1684: The general flow of the script is to get command line arguments, run through
                   1685: the XML document three times, and output according to any desired mode:
                   1686: install, configinstall, build, rpm, dpkg, htmldoc, textdoc, and status.
                   1687: 
                   1688: A number of coding decisions are made according to the following principle:
                   1689: installation software must be stand-alone.  Therefore, for instance, I try
                   1690: not to use the GetOpt::Long module or any other perl modules.  (I do however
                   1691: use HTML::TokeParser.)  I also have tried to keep all the MODES of
                   1692: parsing inside this file.  Therefore, format_TAG subroutines are fairly
                   1693: lengthy with their conditional logic.  A more "elegant" solution might
                   1694: be to dynamically register the parsing mode and subroutines, or maybe even work
                   1695: with stylesheets.  However, in order to make this the installation back-bone
                   1696: of choice, there are advantages for HAVING EVERYTHING IN ONE FILE.
                   1697: This way, the LPML installation software does not have to rely on OTHER
                   1698: installation software (a chicken versus the egg problem).  Besides, I would
                   1699: suggest the modes of parsing are fairly constant: install, configinstall,
                   1700: build, rpm, dpkg, htmldoc, textdoc, and status.
                   1701: 
                   1702: Another coding decision is about using a multiple pass-through approach to
                   1703: parsing the lpml file.  This saves memory and makes sure the server will never
                   1704: be overloaded.  During the first pass-through, the script gathers information
                   1705: specific as to resolving what tags with what 'dist=' attributes are to be used.
                   1706: During the second pass-through, the script cleans up white-space surrounding
                   1707: the XML tags, and filters through the tags based on information regarding the
                   1708: 'dist=' attributes (information gathered in the first pass-through).
                   1709: The third and final pass-through involves formatting and rendering the XML
                   1710: into whatever XML mode is chosen: install, configinstall, build, rpm, dpkg,
                   1711: htmldoc, textdoc, and status.
                   1712: 
                   1713: The hierarchy mandated by the DTD does not always correspond to the hierarchy
                   1714: that is sensible for a Makefile.  For instance, in a Makefile it is sensible
                   1715: that soft-links are installed after files.  However, in an LPML document, it
                   1716: is sensible that files and links be considered together and the writer of the
                   1717: LPML document should be free to place things in whatever order makes best
                   1718: sense in terms of LOOKING at the information.  The complication that arises
                   1719: is that the parser needs to have a memory for passing values from
                   1720: leaves on the XML tree to higher-up branches.  Currently, this memory is
                   1721: hard-coded (like with the @links array), but it may benefit from a more
                   1722: formal approach in the future.
1.18      harris41 1723: 
                   1724: =head1 README
                   1725: 
1.45      harris41 1726: This parses an LPML file to generate information useful for
                   1727: source to target installation, compilation, filesystem status
                   1728: checking, RPM and Debian software packaging, and documentation.
                   1729: 
                   1730: More information on LPML is available at http://lpml.sourceforge.net.
1.18      harris41 1731: 
                   1732: =head1 PREREQUISITES
                   1733: 
                   1734: HTML::TokeParser
                   1735: 
                   1736: =head1 COREQUISITES
                   1737: 
                   1738: =head1 OSNAMES
                   1739: 
                   1740: linux
                   1741: 
                   1742: =head1 SCRIPT CATEGORIES
                   1743: 
1.45      harris41 1744: UNIX/System_administration
1.43      harris41 1745: 
                   1746: =head1 AUTHOR
                   1747: 
                   1748:  Scott Harrison
                   1749:  codeharrison@yahoo.com
                   1750: 
                   1751: Please let me know how/if you are finding this script useful and
                   1752: any/all suggestions.  -Scott
1.18      harris41 1753: 
                   1754: =cut

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