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

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.55    ! albertel   15: # $Id: lpml_parse.pl,v 1.54 2007/01/25 22:54:25 raeburn Exp $
1.28      harris41   16: #
1.43      harris41   17: # Written by Scott Harrison, codeharrison@yahoo.com
1.28      harris41   18: #
                     19: # Copyright Michigan State University Board of Trustees
                     20: #
                     21: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     22: #
                     23: # LON-CAPA is free software; you can redistribute it and/or modify
                     24: # it under the terms of the GNU General Public License as published by
                     25: # the Free Software Foundation; either version 2 of the License, or
                     26: # (at your option) any later version.
                     27: #
                     28: # LON-CAPA is distributed in the hope that it will be useful,
                     29: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     30: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     31: # GNU General Public License for more details.
                     32: #
                     33: # You should have received a copy of the GNU General Public License
                     34: # along with LON-CAPA; if not, write to the Free Software
                     35: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     36: #
                     37: # /home/httpd/html/adm/gpl.txt
                     38: #
                     39: # http://www.lon-capa.org/
                     40: #
1.4       harris41   41: # YEAR=2001
1.2       albertel   42: # May 2001
1.3       harris41   43: # 06/19/2001,06/20,06/24 - Scott Harrison
1.5       harris41   44: # 9/5/2001,9/6,9/7,9/8 - Scott Harrison
1.14      harris41   45: # 9/17,9/18 - Scott Harrison
1.21      harris41   46: # 11/4,11/5,11/6,11/7,11/16,11/17 - Scott Harrison
1.35      harris41   47: # 12/2,12/3,12/4,12/5,12/6,12/13,12/19,12/29 - Scott Harrison
                     48: # YEAR=2002
1.45      harris41   49: # 1/8,1/9,1/29,1/31,2/5,3/21,4/8,4/12 - Scott Harrison
1.51      harris41   50: # 4/21,4/26,5/19,5/23,10/13 - Scott Harrison
1.43      harris41   51: #
1.18      harris41   52: ###
1.3       harris41   53: 
1.4       harris41   54: ###############################################################################
                     55: ##                                                                           ##
                     56: ## ORGANIZATION OF THIS PERL SCRIPT                                          ##
                     57: ## 1. Notes                                                                  ##
                     58: ## 2. Get command line arguments                                             ##
                     59: ## 3. First pass through (grab distribution-specific information)            ##
                     60: ## 4. Second pass through (parse out what is not necessary)                  ##
                     61: ## 5. Third pass through (translate markup according to specified mode)      ##
1.14      harris41   62: ## 6. Functions (most all just format contents of different markup tags)     ##
                     63: ## 7. POD (plain old documentation, CPAN style)                              ##
1.4       harris41   64: ##                                                                           ##
                     65: ###############################################################################
                     66: 
                     67: # ----------------------------------------------------------------------- Notes
                     68: #
1.3       harris41   69: # I am using a multiple pass-through approach to parsing
                     70: # the lpml file.  This saves memory and makes sure the server
1.45      harris41   71: # will never be overloaded.
1.4       harris41   72: #
                     73: # This is meant to parse files meeting the lpml document type.
                     74: # See lpml.dtd.  LPML=Linux Packaging Markup Language.
1.2       albertel   75: 
1.1       harris41   76: use HTML::TokeParser;
1.2       albertel   77: 
1.3       harris41   78: my $usage=<<END;
                     79: **** ERROR ERROR ERROR ERROR ****
                     80: Usage is for lpml file to come in through standard input.
1.45      harris41   81: 1st argument is the mode of parsing:
                     82:     install,configinstall,build,rpm,dpkg,htmldoc,textdoc,status
                     83: 2nd argument is the category permissions to use:
                     84:     typical choices: runtime,development
                     85: 3rd argument is the distribution:
                     86:     typical choices: default,redhat6.2,debian2.2,redhat7
1.4       harris41   87: 4th argument is to manually specify a sourceroot.
                     88: 5th argument is to manually specify a targetroot.
1.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.5       harris41 1269: 	elsif ($mode eq 'install' && $categoryname ne 'conf') {
1.14      harris41 1270: 	    if ($build) {
                   1271: 		my $bi=$sourceroot.'/'.$source.';'.$build.';'.
                   1272: 		    $dependencies;
                   1273: 		my ($source2,$command,$trigger,@deps)=split(/\;/,$bi);
                   1274: 		$tword=''; $tword=' alwaysrun' if $trigger eq 'always run'; 
                   1275: 		$command=~s/\/([^\/]*)$//;
                   1276: 		$command2="cd $command; sh ./$1;\\";
                   1277: 		my $depstring;
                   1278: 		foreach my $dep (@deps) {
                   1279: 		    $depstring.=<<END;
                   1280: 		ECODE=0; DEP=''; \\
1.34      harris41 1281: 		test -e $dep || (echo '**** WARNING **** cannot evaluate status of dependency $dep (for building ${sourceroot}/${source} with)'$logcmd); DEP="1"; \\
                   1282: 		[ -n DEP ] && { perl filecompare.pl -b2 $dep ${targetroot}/${target} || ECODE=\$\$?; } || DEP="1"; \\
1.14      harris41 1283: 		case "\$\$ECODE" in \\
1.34      harris41 1284: 			2) echo "**** WARNING **** dependency $dep is newer than target file ${targetroot}/${target}; you may want to run make build"$logcmd;; \\
1.14      harris41 1285: 		esac; \\
                   1286: END
                   1287: 		}
                   1288:                 chomp $depstring;
                   1289: 		$buildtest=<<END;
                   1290: 	\@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
1.19      harris41 1291: 		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 1292: END
                   1293:                 $buildtest.=<<END if $depstring;
                   1294: 	elif !(test -e "${sourceroot}/${source}"); then \\
                   1295: $depstring
                   1296: END
                   1297:                 $buildtest.=<<END;
                   1298: 	fi
                   1299: END
1.55    ! albertel 1300:             }
1.53      albertel 1301: 	    if ($installscript) {
                   1302: 		my $dir = $sourceroot.'/'.$source;
                   1303: 		$dir =~ s|/([^/]*)$||;
1.55    ! albertel 1304: 		my $result =" 
        !          1305: $buildtest	cd $dir ; sh $installscript";
        !          1306: 		if ($categoryname 
        !          1307: 		    && exists($categoryhash{"chmod.$categoryname"}) ) {
        !          1308: 		    $result .="\\\n";
        !          1309: 		    $result .=<<"END"
        !          1310: 		chmod -R $categoryhash{"chmod.$categoryname"} ${targetroot}/${target} \\
        !          1311: 		chown -R $categoryhash{"chown.$categoryname"} ${targetroot}/${target} 
1.53      albertel 1312: END
1.55    ! albertel 1313:                 } else {
        !          1314: 		    $result.="\n";
        !          1315: 		}
        !          1316: 		return $result;
1.53      albertel 1317: 	    }
1.18      harris41 1318:             my $bflag='-b1';
                   1319:             $bflag='-b3' if $dependencies or $buildlink;
1.14      harris41 1320: 	    return <<END;
1.19      harris41 1321: $buildtest	\@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
                   1322: 		echo "**** ERROR **** CVS source file does not exist: ${sourceroot}/${source} and neither does target: ${targetroot}/${target}"$logcmd; \\
                   1323: 	elif !(test -e "${sourceroot}/${source}"); then \\
                   1324: 		echo "**** WARNING **** CVS source file does not exist: ${sourceroot}/${source}"$logcmd; \\
1.21      harris41 1325: 		perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\
1.14      harris41 1326: 	else \\
                   1327: 		ECODE=0; \\
                   1328: 		perl filecompare.pl $bflag ${sourceroot}/${source} ${targetroot}/${target} || ECODE=\$\$?; \\
                   1329: 		case "\$\$ECODE" in \\
                   1330: 			1) echo "${targetroot}/${target} is unchanged";; \\
1.21      harris41 1331: 			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 1332: 			0) echo "install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target}" && install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target};; \\
1.14      harris41 1333: 		esac; \\
1.21      harris41 1334: 		perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\
1.14      harris41 1335: 	fi
                   1336: END
1.12      harris41 1337: 	}
                   1338: 	elsif ($mode eq 'configinstall' && $categoryname eq 'conf') {
                   1339: 	    push @configall,$targetroot.'/'.$target;
1.14      harris41 1340: 	    return $targetroot.'/'.$target.': alwaysrun'."\n".
1.48      harris41 1341: 		"\t".'@# Compare source with target and intelligently respond'.
                   1342: 		"\n\t\n\t\n".
                   1343: 
                   1344: 
                   1345: 		"\t".'@echo -n ""; ECODE=0 && { perl filecompare.pl -b4 \\'.
                   1346: 		"\n\t".$sourceroot.'/'.$source." \\\n\t".
                   1347: 		$targetroot.'/'.$target." \\\n\t".
                   1348: 		' || ECODE=$$?; } && '."\\\n\t"."\\\n\t"."\\\n\t".
                   1349: 
                   1350: 
                   1351: 		'{ [ $$ECODE != "2" ] || '." \\\n\t".'(install '.
                   1352:                 $categoryhash{$categoryname}." \\\n\t\t".
                   1353: 		$sourceroot.'/'.$source." \\\n\t\t".
                   1354: 		$targetroot.'/'.$target.'.lpmlnew'." \\\n\t\t".
1.19      harris41 1355: 		' && echo "**** NOTE: CONFIGURATION FILE CHANGE ****"'.
1.48      harris41 1356: 		" \\\n\t\t".$logcmd.' && '." \\\n\t\t"."echo -n \"".
                   1357: 		'You likely need to compare contents of "'."\\\n\t\t\t".
1.49      harris41 1358: 		'&& echo -n "'.$targetroot.'/'.$target.'"'."\\\n\t\t".
                   1359: 		'&& echo -n " with the new "'."\\\n\t\t\t".
                   1360:                 '&& echo "'.$targetroot.'/'.$target.'.lpmlnew"'."\\\n\t\t".
1.48      harris41 1361: 		"$logcmd); } && "." \\\n\t"."\\\n\t"."\\\n\t".
                   1362: 
                   1363: 
                   1364: 		'{ [ $$ECODE != "3" ] || '."\\\n\t".
                   1365: 		'(install '.
                   1366:                 $categoryhash{$categoryname}."\\\n\t\t".
                   1367: 		$sourceroot.'/'.$source."\\\n\t\t".
                   1368: 		$targetroot.'/'.$target."\\\n\t\t".
1.20      harris41 1369: 		' && echo "**** WARNING: NEW CONFIGURATION FILE ADDED ****"'.
1.48      harris41 1370: 		"\\\n\t\t".$logcmd.' && '."\\\n\t\t".
1.50      harris41 1371: 		'echo -n "'.
1.48      harris41 1372: 		'You likely need to review the contents of "'."\\\n\t\t\t".
1.49      harris41 1373: 		'&& echo -n "'.
1.48      harris41 1374: 		$targetroot.'/'.$target.'"'."\\\n\t\t\t".
1.49      harris41 1375: 		'&& echo -n "'.
                   1376: 		' to make sure its "'."\\\n\t\t".
                   1377: 		'&& echo "'.
1.48      harris41 1378:                 'settings are compatible with your overall system"'."\\\n\t\t".
                   1379: 		"$logcmd); } && "."\\\n\t"."\\\n\t"."\\\n\t".
                   1380: 
                   1381: 
                   1382: 		'{ [ $$ECODE != "1" ] || ('."\\\n\t\t".
                   1383: 		'echo "**** ERROR ****"'.$logcmd.' && '."\\\n\t\t".'echo -n "'.
                   1384: 		'Configuration source file does not exist "'."\\\n\t\t".
1.50      harris41 1385: 		'&& echo -n "'.$sourceroot.'/'.$source.'"'."\\\n\t\t".
1.48      harris41 1386: 		"$logcmd); } && "."\\\n\t\t".
                   1387: 		"perl verifymodown.pl ${targetroot}/${target} "."\\\n\t\t\t".
                   1388: 		"\"$categoryhash{$categoryname}\""."\\\n\t\t\t".
                   1389: 		"$logcmd;\n\n";
1.4       harris41 1390: 	}
1.11      harris41 1391: 	elsif ($mode eq 'build' && $build) {
                   1392: 	    push @buildall,$sourceroot.'/'.$source;
1.14      harris41 1393: 	    push @buildinfo,$targetroot.'/'.$target.';'.$sourceroot.'/'.
                   1394: 		$source.';'.$build.';'.
1.11      harris41 1395: 		$dependencies;
                   1396: #	    return '# need to build '.$source.";
                   1397: 	}
1.35      harris41 1398:         elsif ($mode eq 'rpm_file_list') {
                   1399: 	    if ($categoryname eq 'doc') {
                   1400: 		return $targetroot.'/'.$target.' # doc'."\n";
                   1401: 	    }
                   1402: 	    elsif ($categoryname eq 'conf') {
                   1403: 		return $targetroot.'/'.$target.' # config'."\n";
                   1404: 	    }
                   1405: 	    else {
                   1406: 		return $targetroot.'/'.$target."\n";
                   1407: 	    }
                   1408: 	}
1.3       harris41 1409: 	else {
                   1410: 	    return '';
                   1411: 	}
                   1412:     }
                   1413:     return '';
                   1414: }
                   1415: # --------------------------------------------------------- Format link section
                   1416: sub format_link {
                   1417:     my @tokeninfo=@_;
1.27      harris41 1418:     $link=''; $linkto=''; $source=''; $target=''; $categoryname=''; 
                   1419:     $description=''; $note=''; $build=''; $status=''; $dependencies='';
1.3       harris41 1420:     my $text=&trim($parser->get_text('/link'));
                   1421:     if ($linkto) {
                   1422: 	$parser->get_tag('/link');
                   1423: 	if ($mode eq 'html') {
1.27      harris41 1424: 	    my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
1.29      harris41 1425: 	    $link_count+=scalar(@targets);
1.27      harris41 1426: 	    foreach my $tgt (@targets) {
1.29      harris41 1427: 		$categorycount{$categoryname}++;
1.27      harris41 1428: 		push @links,("\n<!-- FILESORT:$tgt -->".
                   1429: 		    "<tr>".
1.32      harris41 1430: 		    "<td><!-- POSTEVAL [$categoryname] verify.pl link ".
1.28      harris41 1431: 		    "'/$targetrootarg$linkto' '/$targetrootarg$tgt' ".
                   1432: 		    "$categoryhash{$categoryname} -->&nbsp;</td><td>".
1.27      harris41 1433: 		    "<img src='$fab{$categoryname}.gif' ".
                   1434: 		    "alt='$categoryname icon' /></td>".
                   1435: 		    "<td><font size='-1'>$categoryname</font></td>".
                   1436: 		    "<td>LINKTO: $linkto<br />TARGET: $tgt</td>".
                   1437: 		    "<td>$description</td>".
                   1438: 		    "<td>$note</td>".
                   1439: 		    "</tr>");
                   1440: #		push @links,"\t".'ln -fs /'.$linkto.' /'.$targetroot.$tgt.
                   1441: #		    "\n";
                   1442: 	    }
                   1443: 	    return join('',@links);
                   1444: #	    return ($link="\n<!-- FILESORT:$target -->".
                   1445: #		    "<tr>".
                   1446: #		    "<td>&nbsp;</td><td><img src='$fab{$categoryname}.gif' ".
                   1447: #		    "alt='$categoryname icon' /></td>".
                   1448: #		    "<td>$categoryname</td>".
                   1449: #		    "<td>LINKTO: $linkto<br />TARGET: $target</td>".
                   1450: #		    "<td>$description</td>".
                   1451: #		    "<td>$note</td>".
                   1452: #		    "</tr>");
                   1453: #	    return $link="\n<tr><td colspan='6'>BEGIN LINK\n".
                   1454: #		"$linkto $target $categoryname $description $note " .
                   1455: #		"$build $status $dependencies" .
                   1456: #		    "\nEND LINK</td></tr>";
1.4       harris41 1457: 	}
                   1458: 	elsif ($mode eq 'install') {
1.10      harris41 1459: 	    my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
1.5       harris41 1460: 	    foreach my $tgt (@targets) {
1.35      harris41 1461: 		push @links,"\t".'ln -fs /'.$linkto.' '.$targetroot.'/'.$tgt.
1.5       harris41 1462: 		    "\n";
                   1463: 	    }
1.35      harris41 1464: #	    return join('',@links);
1.4       harris41 1465: 	    return '';
1.3       harris41 1466: 	}
1.35      harris41 1467: 	elsif ($mode eq 'rpm_file_list') {
                   1468: 	    my @linklocs;
                   1469: 	    my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
                   1470: 	    foreach my $tgt (@targets) {
                   1471: 		push @linklocs,''.$targetroot.'/'.$tgt."\n";
                   1472: 	    }
                   1473: 	    return join('',@linklocs);
                   1474: 	}
1.3       harris41 1475: 	else {
                   1476: 	    return '';
                   1477: 	}
                   1478:     }
                   1479:     return '';
                   1480: }
                   1481: # ----------------------------------------------------- Format fileglob section
                   1482: sub format_fileglob {
                   1483:     my @tokeninfo=@_;
                   1484:     $fileglob=''; $glob=''; $sourcedir='';
                   1485:     $targetdir=''; $categoryname=''; $description='';
                   1486:     $note=''; $build=''; $status=''; $dependencies='';
                   1487:     $filenames='';
                   1488:     my $text=&trim($parser->get_text('/fileglob'));
1.27      harris41 1489:     my $filenames2=$filenames;$filenames2=~s/\s//g;
1.29      harris41 1490:     $fileglob_count++;
                   1491:     my @semi=($filenames2=~/(\;)/g);
                   1492:     $fileglobnames_count+=scalar(@semi)+1;
                   1493:     $categorycount{$categoryname}+=scalar(@semi)+1;
1.3       harris41 1494:     if ($sourcedir) {
                   1495: 	$parser->get_tag('/fileglob');
1.46      harris41 1496: 	if ($mode eq 'MANIFEST') {
                   1497:          return join("\n",(map {"$sourcedir$_"} split(/\;/,$filenames2)))."\n";
                   1498: 	}
                   1499: 	elsif ($mode eq 'html') {
1.27      harris41 1500: 	    return $fileglob="\n<tr>".
1.41      harris41 1501:       "<td><!-- POSTEVAL [$categoryname] verify.pl fileglob '$sourcerootarg' ".
1.27      harris41 1502: 		"'$targetrootarg' ".
                   1503: 		"'$glob' '$sourcedir' '$filenames2' '$targetdir' ".
                   1504: 		"$categoryhash{$categoryname} -->&nbsp;</td>".
                   1505: 		"<td>"."<img src='$fab{$categoryname}.gif' ".
                   1506: 	        "alt='$categoryname icon' /></td>".
                   1507: 		"<td>$categoryname<br />".
                   1508: 		"<font size='-1'>".$categoryhash{$categoryname}."</font></td>".
                   1509: 		"<td>SOURCEDIR: $sourcedir<br />".
                   1510: 		"TARGETDIR: $targetdir<br />".
                   1511:                 "GLOB: $glob<br />".
                   1512:                 "FILENAMES: $filenames".
                   1513: 		"</td>".
                   1514: 		"<td>$description</td>".
                   1515: 		"<td>$note</td>".
                   1516: 		"</tr>";
                   1517: #	    return $fileglob="\n<tr><td colspan='6'>BEGIN FILEGLOB\n".
                   1518: #		"$glob sourcedir $targetdir $categoryname $description $note ".
                   1519: #		"$build $status $dependencies $filenames" .
                   1520: #		"\nEND FILEGLOB</td></tr>";
1.3       harris41 1521: 	}
1.5       harris41 1522: 	elsif ($mode eq 'install') {
1.30      harris41 1523: 	    my $eglob=$glob;
                   1524: 	    if ($glob eq '*') {
                   1525: 		$eglob='[^C][^V][^S]'.$glob;
                   1526: 	    }
1.5       harris41 1527: 	    return "\t".'install '.
                   1528: 		$categoryhash{$categoryname}.' '.
1.30      harris41 1529: 		$sourceroot.'/'.$sourcedir.$eglob.' '.
1.5       harris41 1530: 		$targetroot.'/'.$targetdir.'.'."\n";
1.35      harris41 1531: 	}
                   1532: 	elsif ($mode eq 'rpm_file_list') {
                   1533: 	    my $eglob=$glob;
                   1534: 	    if ($glob eq '*') {
                   1535: 		$eglob='[^C][^V][^S]'.$glob;
                   1536: 	    }
                   1537: 	    my $targetdir2=$targetdir;$targetdir2=~s/\/$//;
                   1538: 	    my @gfiles=map {s/^.*\///;"$targetroot/$targetdir2/$_\n"}
                   1539: 	               glob("$sourceroot/$sourcedir/$eglob");
                   1540: 	    return join('',@gfiles);
1.5       harris41 1541: 	}
1.3       harris41 1542: 	else {
                   1543: 	    return '';
                   1544: 	}
                   1545:     }
                   1546:     return '';
                   1547: }
                   1548: # ---------------------------------------------------- Format sourcedir section
                   1549: sub format_sourcedir {
                   1550:     my @tokeninfo=@_;
                   1551:     $sourcedir='';
                   1552:     my $text=&trim($parser->get_text('/sourcedir'));
                   1553:     if ($text) {
                   1554: 	$parser->get_tag('/sourcedir');
                   1555: 	$sourcedir=$text;
                   1556:     }
                   1557:     return '';
                   1558: }
                   1559: # ------------------------------------------------------- Format target section
                   1560: sub format_target {
                   1561:     my @tokeninfo=@_;
                   1562:     $target='';
                   1563:     my $text=&trim($parser->get_text('/target'));
                   1564:     if ($text) {
                   1565: 	$parser->get_tag('/target');
                   1566: 	$target=$text;
                   1567:     }
                   1568:     return '';
                   1569: }
                   1570: # ------------------------------------------------------- Format source section
                   1571: sub format_source {
                   1572:     my @tokeninfo=@_;
                   1573:     $source='';
                   1574:     my $text=&trim($parser->get_text('/source'));
                   1575:     if ($text) {
                   1576: 	$parser->get_tag('/source');
                   1577: 	$source=$text;
                   1578:     }
                   1579:     return '';
                   1580: }
                   1581: # --------------------------------------------------------- Format note section
                   1582: sub format_note {
                   1583:     my @tokeninfo=@_;
                   1584:     $note='';
1.26      harris41 1585: #    my $text=&trim($parser->get_text('/note'));
                   1586:     my $aref;
                   1587:     my $text;
                   1588:     while ($aref=$parser->get_token()) {
                   1589: 	if ($aref->[0] eq 'E' && $aref->[1] eq 'note') {
                   1590: 	    last;
                   1591: 	}
                   1592: 	elsif ($aref->[0] eq 'S') {
                   1593: 	    $text.=$aref->[4];
                   1594: 	}
                   1595: 	elsif ($aref->[0] eq 'E') {
                   1596: 	    $text.=$aref->[2];
                   1597: 	}
                   1598: 	else {
                   1599: 	    $text.=$aref->[1];
                   1600: 	}
                   1601:     }
1.3       harris41 1602:     if ($text) {
1.26      harris41 1603: #	$parser->get_tag('/note');
1.3       harris41 1604: 	$note=$text;
                   1605:     }
                   1606:     return '';
                   1607: 
                   1608: }
                   1609: # -------------------------------------------------------- Format build section
                   1610: sub format_build {
                   1611:     my @tokeninfo=@_;
                   1612:     $build='';
                   1613:     my $text=&trim($parser->get_text('/build'));
                   1614:     if ($text) {
                   1615: 	$parser->get_tag('/build');
1.11      harris41 1616: 	$build=$sourceroot.'/'.$text.';'.$tokeninfo[2]{'trigger'};
1.42      harris41 1617: 	$build=~s/([^\\])\\\s+/$1/g; # allow for lines split onto new lines
1.3       harris41 1618:     }
                   1619:     return '';
                   1620: }
1.53      albertel 1621: # ------------------------------------------------ Format installscript section
                   1622: sub format_installscript {
                   1623:     my @tokeninfo=@_;
                   1624:     $installscript= &trim($parser->get_text('/installscript'));
                   1625:     if ($installscript) {
                   1626: 	$parser->get_tag('/installscript');
                   1627: 	$installscript=~s/([^\\])\\\s+/$1/g; # allow for lines split onto new lines
                   1628:     }
                   1629:     return '';
                   1630: }
1.14      harris41 1631: # -------------------------------------------------------- Format build section
                   1632: sub format_buildlink {
                   1633:     my @tokeninfo=@_;
                   1634:     $buildlink='';
                   1635:     my $text=&trim($parser->get_text('/buildlink'));
                   1636:     if ($text) {
                   1637: 	$parser->get_tag('/buildlink');
                   1638: 	$buildlink=$sourceroot.'/'.$text;
                   1639:     }
                   1640:     return '';
                   1641: }
1.3       harris41 1642: # ------------------------------------------------------- Format status section
                   1643: sub format_status {
                   1644:     my @tokeninfo=@_;
                   1645:     $status='';
                   1646:     my $text=&trim($parser->get_text('/status'));
                   1647:     if ($text) {
                   1648: 	$parser->get_tag('/status');
                   1649: 	$status=$text;
                   1650:     }
                   1651:     return '';
                   1652: }
                   1653: # ------------------------------------------------- Format dependencies section
                   1654: sub format_dependencies {
                   1655:     my @tokeninfo=@_;
1.52      albertel 1656:     #$dependencies='';
1.3       harris41 1657:     my $text=&trim($parser->get_text('/dependencies'));
                   1658:     if ($text) {
                   1659: 	$parser->get_tag('/dependencies');
1.52      albertel 1660: 	$dependencies=join(';',((map {s/^\s*//;s/\s$//;$_} split(/\;/,$text)),$dependencies));
                   1661: 	$dependencies=~s/;$//;
                   1662:     }
                   1663:     return '';
                   1664: }
                   1665: sub format_privatedependencies {
                   1666:     my @tokeninfo=@_;
                   1667:     #$dependencies='';
                   1668:     my $text=&trim($parser->get_text('/privatedependencies'));
                   1669:     if ($text) {
                   1670: 	$parser->get_tag('/privatedependencies');
                   1671: 	if ($mode eq 'MANIFEST') { return '';	}
                   1672: 	$dependencies=join(';',((map {s/^\s*//;s/\s$//;$_} split(/\;/,$text)),$dependencies));
                   1673: 	$dependencies=~s/;$//;
1.3       harris41 1674:     }
                   1675:     return '';
                   1676: }
                   1677: # --------------------------------------------------------- Format glob section
                   1678: sub format_glob {
                   1679:     my @tokeninfo=@_;
                   1680:     $glob='';
                   1681:     my $text=&trim($parser->get_text('/glob'));
                   1682:     if ($text) {
                   1683: 	$parser->get_tag('/glob');
                   1684: 	$glob=$text;
                   1685:     }
                   1686:     return '';
                   1687: }
                   1688: # ---------------------------------------------------- Format filenames section
                   1689: sub format_filenames {
                   1690:     my @tokeninfo=@_;
                   1691:     my $text=&trim($parser->get_text('/filenames'));
                   1692:     if ($text) {
                   1693: 	$parser->get_tag('/filenames');
                   1694: 	$filenames=$text;
                   1695:     }
1.31      harris41 1696:     return '';
                   1697: }
1.38      harris41 1698: # ----------------------------------------------- Format specialnotices section
1.31      harris41 1699: sub format_specialnotices {
                   1700:     $parser->get_tag('/specialnotices');
                   1701:     return '';
                   1702: }
                   1703: # ------------------------------------------------ Format specialnotice section
                   1704: sub format_specialnotice {
                   1705:     $parser->get_tag('/specialnotice');
1.3       harris41 1706:     return '';
                   1707: }
                   1708: # ------------------------------------------------------- Format linkto section
                   1709: sub format_linkto {
                   1710:     my @tokeninfo=@_;
                   1711:     my $text=&trim($parser->get_text('/linkto'));
                   1712:     if ($text) {
                   1713: 	$parser->get_tag('/linkto');
                   1714: 	$linkto=$text;
                   1715:     }
                   1716:     return '';
1.10      harris41 1717: }
                   1718: # ------------------------------------- Render less-than and greater-than signs
                   1719: sub htmlsafe {
                   1720:     my $text=@_[0];
                   1721:     $text =~ s/</&lt;/g;
                   1722:     $text =~ s/>/&gt;/g;
                   1723:     return $text;
1.3       harris41 1724: }
                   1725: # --------------------------------------- remove starting and ending whitespace
                   1726: sub trim {
                   1727:     my ($s)=@_; $s=~s/^\s*//; $s=~s/\s*$//; return $s;
                   1728: } 
1.14      harris41 1729: 
                   1730: # ----------------------------------- POD (plain old documentation, CPAN style)
1.18      harris41 1731: 
1.43      harris41 1732: =pod
                   1733: 
1.18      harris41 1734: =head1 NAME
                   1735: 
1.45      harris41 1736: lpml_parse.pl - This is meant to parse files meeting the lpml document type.
1.18      harris41 1737: 
                   1738: =head1 SYNOPSIS
                   1739: 
1.45      harris41 1740: <STDIN> | perl lpml_parse.pl <MODE> <CATEGORY> <DIST> <SOURCE> <TARGET>
                   1741: 
                   1742: Usage is for the lpml file to come in through standard input.
1.18      harris41 1743: 
                   1744: =over 4
                   1745: 
                   1746: =item *
                   1747: 
                   1748: 1st argument is the mode of parsing.
                   1749: 
                   1750: =item * 
                   1751: 
                   1752: 2nd argument is the category permissions to use (runtime or development)
                   1753: 
                   1754: =item *
                   1755: 
                   1756: 3rd argument is the distribution
                   1757: (default,redhat6.2,debian2.2,redhat7.1,etc).
                   1758: 
                   1759: =item *
                   1760: 
                   1761: 4th argument is to manually specify a sourceroot.
                   1762: 
                   1763: =item *
                   1764: 
                   1765: 5th argument is to manually specify a targetroot.
                   1766: 
                   1767: =back
                   1768: 
                   1769: Only the 1st argument is mandatory for the program to run.
                   1770: 
                   1771: Example:
                   1772: 
                   1773: cat ../../doc/loncapafiles.lpml |\\
1.45      harris41 1774: perl lpml_parse.pl html runtime default /home/sherbert/loncapa /tmp/install
1.18      harris41 1775: 
                   1776: =head1 DESCRIPTION
                   1777: 
1.45      harris41 1778: The general flow of the script is to get command line arguments, run through
                   1779: the XML document three times, and output according to any desired mode:
                   1780: install, configinstall, build, rpm, dpkg, htmldoc, textdoc, and status.
                   1781: 
                   1782: A number of coding decisions are made according to the following principle:
                   1783: installation software must be stand-alone.  Therefore, for instance, I try
                   1784: not to use the GetOpt::Long module or any other perl modules.  (I do however
                   1785: use HTML::TokeParser.)  I also have tried to keep all the MODES of
                   1786: parsing inside this file.  Therefore, format_TAG subroutines are fairly
                   1787: lengthy with their conditional logic.  A more "elegant" solution might
                   1788: be to dynamically register the parsing mode and subroutines, or maybe even work
                   1789: with stylesheets.  However, in order to make this the installation back-bone
                   1790: of choice, there are advantages for HAVING EVERYTHING IN ONE FILE.
                   1791: This way, the LPML installation software does not have to rely on OTHER
                   1792: installation software (a chicken versus the egg problem).  Besides, I would
                   1793: suggest the modes of parsing are fairly constant: install, configinstall,
                   1794: build, rpm, dpkg, htmldoc, textdoc, and status.
                   1795: 
                   1796: Another coding decision is about using a multiple pass-through approach to
                   1797: parsing the lpml file.  This saves memory and makes sure the server will never
                   1798: be overloaded.  During the first pass-through, the script gathers information
                   1799: specific as to resolving what tags with what 'dist=' attributes are to be used.
                   1800: During the second pass-through, the script cleans up white-space surrounding
                   1801: the XML tags, and filters through the tags based on information regarding the
                   1802: 'dist=' attributes (information gathered in the first pass-through).
                   1803: The third and final pass-through involves formatting and rendering the XML
                   1804: into whatever XML mode is chosen: install, configinstall, build, rpm, dpkg,
                   1805: htmldoc, textdoc, and status.
                   1806: 
                   1807: The hierarchy mandated by the DTD does not always correspond to the hierarchy
                   1808: that is sensible for a Makefile.  For instance, in a Makefile it is sensible
                   1809: that soft-links are installed after files.  However, in an LPML document, it
                   1810: is sensible that files and links be considered together and the writer of the
                   1811: LPML document should be free to place things in whatever order makes best
                   1812: sense in terms of LOOKING at the information.  The complication that arises
                   1813: is that the parser needs to have a memory for passing values from
                   1814: leaves on the XML tree to higher-up branches.  Currently, this memory is
                   1815: hard-coded (like with the @links array), but it may benefit from a more
                   1816: formal approach in the future.
1.18      harris41 1817: 
                   1818: =head1 README
                   1819: 
1.45      harris41 1820: This parses an LPML file to generate information useful for
                   1821: source to target installation, compilation, filesystem status
                   1822: checking, RPM and Debian software packaging, and documentation.
                   1823: 
                   1824: More information on LPML is available at http://lpml.sourceforge.net.
1.18      harris41 1825: 
                   1826: =head1 PREREQUISITES
                   1827: 
                   1828: HTML::TokeParser
                   1829: 
                   1830: =head1 COREQUISITES
                   1831: 
                   1832: =head1 OSNAMES
                   1833: 
                   1834: linux
                   1835: 
                   1836: =head1 SCRIPT CATEGORIES
                   1837: 
1.45      harris41 1838: UNIX/System_administration
1.43      harris41 1839: 
                   1840: =head1 AUTHOR
                   1841: 
                   1842:  Scott Harrison
                   1843:  codeharrison@yahoo.com
                   1844: 
                   1845: Please let me know how/if you are finding this script useful and
                   1846: any/all suggestions.  -Scott
1.18      harris41 1847: 
                   1848: =cut

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