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

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

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