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

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

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