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

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

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