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

1.1       harris41    1: #!/usr/bin/perl
1.2       albertel    2: 
1.28    ! harris41    3: # The LearningOnline Network with CAPA
        !             4: # lpml_parse.pl - Linux Packaging Markup Language parser
        !             5: #
        !             6: # $Id: lpml_parse.pl,v 1.27 2001/12/06 00:22:53 harris41 Exp $
        !             7: #
        !             8: # Written by Scott Harrison, harris41@msu.edu
        !             9: #
        !            10: # Copyright Michigan State University Board of Trustees
        !            11: #
        !            12: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
        !            13: #
        !            14: # LON-CAPA is free software; you can redistribute it and/or modify
        !            15: # it under the terms of the GNU General Public License as published by
        !            16: # the Free Software Foundation; either version 2 of the License, or
        !            17: # (at your option) any later version.
        !            18: #
        !            19: # LON-CAPA is distributed in the hope that it will be useful,
        !            20: # but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            21: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            22: # GNU General Public License for more details.
        !            23: #
        !            24: # You should have received a copy of the GNU General Public License
        !            25: # along with LON-CAPA; if not, write to the Free Software
        !            26: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        !            27: #
        !            28: # /home/httpd/html/adm/gpl.txt
        !            29: #
        !            30: # http://www.lon-capa.org/
        !            31: #
1.4       harris41   32: # YEAR=2001
1.2       albertel   33: # May 2001
1.3       harris41   34: # 06/19/2001,06/20,06/24 - Scott Harrison
1.5       harris41   35: # 9/5/2001,9/6,9/7,9/8 - Scott Harrison
1.14      harris41   36: # 9/17,9/18 - Scott Harrison
1.21      harris41   37: # 11/4,11/5,11/6,11/7,11/16,11/17 - Scott Harrison
1.28    ! harris41   38: # 12/2,12/3,12/4,12/5,12/6 - Scott Harrison
        !            39: #
1.18      harris41   40: ###
1.3       harris41   41: 
1.4       harris41   42: ###############################################################################
                     43: ##                                                                           ##
                     44: ## ORGANIZATION OF THIS PERL SCRIPT                                          ##
                     45: ## 1. Notes                                                                  ##
                     46: ## 2. Get command line arguments                                             ##
                     47: ## 3. First pass through (grab distribution-specific information)            ##
                     48: ## 4. Second pass through (parse out what is not necessary)                  ##
                     49: ## 5. Third pass through (translate markup according to specified mode)      ##
1.14      harris41   50: ## 6. Functions (most all just format contents of different markup tags)     ##
                     51: ## 7. POD (plain old documentation, CPAN style)                              ##
1.4       harris41   52: ##                                                                           ##
                     53: ###############################################################################
                     54: 
                     55: # ----------------------------------------------------------------------- Notes
                     56: #
1.3       harris41   57: # I am using a multiple pass-through approach to parsing
                     58: # the lpml file.  This saves memory and makes sure the server
                     59: # will never be overloaded.
1.4       harris41   60: #
                     61: # This is meant to parse files meeting the lpml document type.
                     62: # See lpml.dtd.  LPML=Linux Packaging Markup Language.
1.2       albertel   63: 
1.1       harris41   64: use HTML::TokeParser;
1.2       albertel   65: 
1.3       harris41   66: my $usage=<<END;
                     67: **** ERROR ERROR ERROR ERROR ****
                     68: Usage is for lpml file to come in through standard input.
                     69: 1st argument is the mode of parsing.
1.4       harris41   70: 2nd argument is the category permissions to use (runtime or development)
                     71: 3rd argument is the distribution (default,redhat6.2,debian2.2,redhat7.1,etc).
                     72: 4th argument is to manually specify a sourceroot.
                     73: 5th argument is to manually specify a targetroot.
1.3       harris41   74: 
                     75: Only the 1st argument is mandatory for the program to run.
                     76: 
                     77: Example:
                     78: 
                     79: cat ../../doc/loncapafiles.lpml |\\
1.25      harris41   80: perl lpml_parse.pl html development default /home/sherbert/loncapa /tmp/install
1.3       harris41   81: END
                     82: 
                     83: # ------------------------------------------------- Grab command line arguments
                     84: 
                     85: my $mode;
1.4       harris41   86: if (@ARGV==5) {
1.3       harris41   87:     $mode = shift @ARGV;
                     88: }
                     89: else {
1.4       harris41   90:     @ARGV=();shift @ARGV;
1.3       harris41   91:     while(<>){} # throw away the input to avoid broken pipes
                     92:     print $usage;
                     93:     exit -1; # exit with error status
                     94: }
                     95: 
1.4       harris41   96: my $categorytype;
                     97: if (@ARGV) {
                     98:     $categorytype = shift @ARGV;
                     99: }
                    100: 
1.3       harris41  101: my $dist;
                    102: if (@ARGV) {
                    103:     $dist = shift @ARGV;
                    104: }
1.2       albertel  105: 
1.3       harris41  106: my $targetroot;
                    107: my $sourceroot;
1.27      harris41  108: my $targetrootarg;
                    109: my $sourcerootarg;
1.3       harris41  110: if (@ARGV) {
1.4       harris41  111:     $sourceroot = shift @ARGV;
1.3       harris41  112: }
                    113: if (@ARGV) {
1.4       harris41  114:     $targetroot = shift @ARGV;
1.3       harris41  115: }
1.4       harris41  116: $sourceroot=~s/\/$//;
                    117: $targetroot=~s/\/$//;
1.27      harris41  118: $sourcerootarg=$sourceroot;
                    119: $targetrootarg=$targetroot;
1.3       harris41  120: 
1.19      harris41  121: my $logcmd='| tee -a WARNINGS';
                    122: 
1.5       harris41  123: my $invocation;
                    124: # --------------------------------------------------- Record program invocation
1.17      harris41  125: if ($mode eq 'install' or $mode eq 'configinstall' or $mode eq 'build') {
1.5       harris41  126:     $invocation=(<<END);
                    127: # Invocation: STDINPUT | lpml_parse.pl
                    128: #             1st argument (mode) is: $mode
                    129: #             2nd argument (category type) is: $categorytype
                    130: #             3rd argument (distribution) is: $dist
                    131: #             4th argument (targetroot) is: described below
                    132: #             5th argument (sourceroot) is: described below
                    133: END
                    134: }
                    135: 
1.3       harris41  136: # ---------------------------------------------------- Start first pass through
1.2       albertel  137: my @parsecontents = <>;
                    138: my $parsestring = join('',@parsecontents);
                    139: my $outstring;
                    140: 
1.3       harris41  141: # Need to make a pass through and figure out what defaults are
                    142: # overrided.  Top-down overriding strategy (leaves don't know
                    143: # about distant leaves).
                    144: 
                    145: my @hierarchy;
                    146: $hierarchy[0]=0;
                    147: my $hloc=0;
                    148: my $token;
                    149: $parser = HTML::TokeParser->new(\$parsestring) or
                    150:     die('can\'t create TokeParser object');
                    151: $parser->xml_mode('1');
                    152: my %hash;
                    153: my $key;
                    154: while ($token = $parser->get_token()) {
                    155:     if ($token->[0] eq 'S') {
                    156: 	$hloc++;
                    157: 	$hierarchy[$hloc]++;
                    158: 	$key=$token->[1].join(',',@hierarchy[0..($hloc-1)]);
                    159: 	my $thisdist=' '.$token->[2]{'dist'}.' ';
                    160: 	if ($thisdist eq ' default ') {
                    161: 	    $hash{$key}=1; # there is a default setting for this key
                    162: 	}
                    163: 	elsif ($dist && $hash{$key}==1 && $thisdist=~/\s$dist\s/) {
                    164: 	    $hash{$key}=2; # disregard default setting for this key if
                    165: 	                   # there is a directly requested distribution match
                    166: 	}
                    167:     }
                    168:     if ($token->[0] eq 'E') {
                    169: 	$hloc--;
                    170:     }
                    171: }
                    172: 
                    173: # --------------------------------------------------- Start second pass through
                    174: undef $hloc;
                    175: undef @hierarchy;
                    176: undef $parser;
                    177: $hierarchy[0]=0;
                    178: $parser = HTML::TokeParser->new(\$parsestring) or
                    179:     die('can\'t create TokeParser object');
                    180: $parser->xml_mode('1');
                    181: my $cleanstring;
                    182: while ($token = $parser->get_token()) {
                    183:     if ($token->[0] eq 'S') {
                    184: 	$hloc++;
                    185: 	$hierarchy[$hloc]++;
                    186: 	$key=$token->[1].join(',',@hierarchy[0..($hloc-1)]);
                    187: 	my $thisdist=' '.$token->[2]{'dist'}.' ';
1.4       harris41  188: 	# This conditional clause is set up to ignore two sets
                    189: 	# of invalid conditions before accepting entry into
                    190: 	# the cleanstring.
1.3       harris41  191: 	if ($hash{$key}==2 and
                    192: 	    !($thisdist eq '  ' or $thisdist =~/\s$dist\s/)) {
                    193: 	    if ($token->[4]!~/\/>$/) {
                    194: 		$parser->get_tag('/'.$token->[1]);
                    195: 		$hloc--;
                    196: 	    }
                    197: 	}
                    198: 	elsif ($thisdist ne '  ' and $thisdist!~/\s$dist\s/ and
                    199: 	       !($thisdist eq ' default ' and $hash{$key}!=2)) {
                    200: 	    if ($token->[4]!~/\/>$/) {
                    201: 		$parser->get_tag('/'.$token->[1]);
                    202: 		$hloc--;
                    203: 	    }
                    204: 	}
                    205: 	else {
                    206: 	    $cleanstring.=$token->[4];
                    207: 	}
                    208: 	if ($token->[4]=~/\/>$/) {
                    209: 	    $hloc--;
                    210: 	}
                    211:     }
                    212:     if ($token->[0] eq 'E') {
                    213: 	$cleanstring.=$token->[2];
                    214: 	$hloc--;
                    215:     }
                    216:     if ($token->[0] eq 'T') {
                    217: 	$cleanstring.=$token->[1];
                    218:     }
                    219: }
                    220: $cleanstring=&trim($cleanstring);
1.10      harris41  221: $cleanstring=~s/\>\s*\n\s*\</\>\</g;
                    222: 
1.3       harris41  223: # ---------------------------------------------------- Start final pass through
                    224: 
                    225: # storage variables
                    226: my $lpml;
                    227: my $categories;
                    228: my $category;
                    229: my $category_att_name;
                    230: my $category_att_type;
                    231: my $chown;
                    232: my $chmod;
1.25      harris41  233: my $abbreviation; # space-free abbreviation; esp. for image names
1.3       harris41  234: my $rpm;
                    235: my $rpmSummary;
                    236: my $rpmName;
                    237: my $rpmVersion;
                    238: my $rpmRelease;
                    239: my $rpmVendor;
                    240: my $rpmBuildRoot;
                    241: my $rpmCopyright;
                    242: my $rpmGroup;
                    243: my $rpmSource;
                    244: my $rpmAutoReqProv;
                    245: my $rpmdescription;
                    246: my $rpmpre;
                    247: my $directories;
                    248: my $directory;
                    249: my $targetdirs;
                    250: my $targetdir;
                    251: my $categoryname;
                    252: my $description;
                    253: my $files;
                    254: my $fileglobs;
                    255: my $links;
                    256: my $file;
                    257: my $link;
                    258: my $fileglob;
                    259: my $sourcedir;
                    260: my $targets;
                    261: my $target;
                    262: my $source;
                    263: my $note;
                    264: my $build;
1.14      harris41  265: my $buildlink;
1.3       harris41  266: my $commands;
                    267: my $command;
                    268: my $status;
                    269: my $dependencies;
                    270: my $dependency;
1.4       harris41  271: my @links;
                    272: my %categoryhash;
1.26      harris41  273: my $dpathlength;
                    274: my %fab; # file category abbreviation
1.3       harris41  275: 
1.11      harris41  276: my @buildall;
1.12      harris41  277: my @buildinfo;
                    278: 
                    279: my @configall;
1.11      harris41  280: 
1.3       harris41  281: # Make new parser with distribution specific input
                    282: undef $parser;
                    283: $parser = HTML::TokeParser->new(\$cleanstring) or
                    284:     die('can\'t create TokeParser object');
                    285: $parser->xml_mode('1');
                    286: 
                    287: # Define handling methods for mode-dependent text rendering
1.26      harris41  288: 
1.3       harris41  289: $parser->{textify}={
                    290:     targetroot => \&format_targetroot,
                    291:     sourceroot => \&format_sourceroot,
                    292:     categories => \&format_categories,
                    293:     category => \&format_category,
1.25      harris41  294:     abbreviation => \&format_abbreviation,
1.3       harris41  295:     targetdir => \&format_targetdir,
                    296:     chown => \&format_chown,
                    297:     chmod => \&format_chmod,
                    298:     rpm => \&format_rpm,
                    299:     rpmSummary => \&format_rpmSummary,
                    300:     rpmName => \&format_rpmName,
                    301:     rpmVersion => \&format_rpmVersion,
                    302:     rpmRelease => \&format_rpmRelease,
                    303:     rpmVendor => \&format_rpmVendor,
                    304:     rpmBuildRoot => \&format_rpmBuildRoot,
                    305:     rpmCopyright => \&format_rpmCopyright,
                    306:     rpmGroup => \&format_rpmGroup,
                    307:     rpmSource => \&format_rpmSource,
                    308:     rpmAutoReqProv => \&format_rpmAutoReqProv,
                    309:     rpmdescription => \&format_rpmdescription,
                    310:     rpmpre => \&format_rpmpre,
                    311:     directories => \&format_directories,
                    312:     directory => \&format_directory,
                    313:     categoryname => \&format_categoryname,
                    314:     description => \&format_description,
                    315:     files => \&format_files,
                    316:     file => \&format_file,
                    317:     fileglob => \&format_fileglob,
1.4       harris41  318:     links => \&format_links,
1.3       harris41  319:     link => \&format_link,
                    320:     linkto => \&format_linkto,
                    321:     source => \&format_source,
                    322:     target => \&format_target,
                    323:     note => \&format_note,
                    324:     build => \&format_build,
                    325:     status => \&format_status,
                    326:     dependencies => \&format_dependencies,
1.14      harris41  327:     buildlink => \&format_buildlink,
1.3       harris41  328:     glob => \&format_glob,
                    329:     sourcedir => \&format_sourcedir,
                    330:     filenames => \&format_filenames,
                    331:     };
                    332: 
                    333: my $text;
                    334: my $token;
                    335: undef $hloc;
                    336: undef @hierarchy;
                    337: my $hloc;
                    338: my @hierarchy2;
                    339: while ($token = $parser->get_tag('lpml')) {
                    340:     &format_lpml(@{$token});
                    341:     $text = &trim($parser->get_text('/lpml'));
                    342:     $token = $parser->get_tag('/lpml');
                    343:     print $lpml; 
                    344:     print "\n";
1.4       harris41  345: #    $text=~s/\s*\n\s*\n\s*/\n/g;
1.3       harris41  346:     print $text;
                    347:     print "\n";
                    348:     print &end();
                    349: }
                    350: exit;
                    351: 
1.14      harris41  352: # ---------- Functions (most all just format contents of different markup tags)
                    353: 
                    354: # ------------------------ Final output at end of markup parsing and formatting
1.3       harris41  355: sub end {
                    356:     if ($mode eq 'html') {
1.24      harris41  357: 	return "</body></html>\n";
1.3       harris41  358:     }
1.4       harris41  359:     if ($mode eq 'install') {
                    360: 	return '';
                    361:     }
1.3       harris41  362: }
                    363: 
                    364: # ----------------------- Take in string to parse and the separation expression
                    365: sub extract_array {
                    366:     my ($stringtoparse,$sepexp) = @_;
                    367:     my @a=split(/$sepexp/,$stringtoparse);
                    368:     return \@a;
                    369: }
                    370: 
                    371: # --------------------------------------------------------- Format lpml section
                    372: sub format_lpml {
                    373:     my (@tokeninfo)=@_;
                    374:     my $date=`date`; chop $date;
                    375:     if ($mode eq 'html') {
1.24      harris41  376: 	$lpml=<<END;
                    377: <html>
                    378: <head>
1.25      harris41  379: <title>LPML Description Page
                    380: (dist=$dist, categorytype=$categorytype, $date)</title>
1.24      harris41  381: </head>
                    382: <body>
                    383: END
                    384: 	$lpml .= "<br /><font size='+2'>LPML Description Page (dist=$dist, ".
1.25      harris41  385: 	    "categorytype=$categorytype, $date)".
1.23      harris41  386: 	    "</font>";
                    387: 	$lpml .=<<END;
                    388: <ul>
1.24      harris41  389: <li><a href='#about'>About this file</a></li>
                    390: <li><a href='#ownperms'>File Type Ownership and Permissions
                    391: Descriptions</a></li>
                    392: <li><a href='#package'>Software Package Description</a></li>
                    393: <li><a href='#directories'>Directory Structure</a></li>
1.26      harris41  394: <li><a href='#files'>Files</a></li>
1.23      harris41  395: </ul>
                    396: END
                    397:         $lpml .=<<END;
1.24      harris41  398: <br />&nbsp;<br /><a name='about' />
1.23      harris41  399: <font size='+2'>About this file</font>
                    400: <p>
                    401: This file is generated dynamically by <tt>lpml_parse.pl</tt> as
1.28    ! harris41  402: part of a development compilation process.</p>
        !           403: <p>LPML written by Scott Harrison (harris41\@msu.edu).
1.23      harris41  404: </p>
                    405: END
                    406:     }
                    407:     elsif ($mode eq 'text') {
                    408: 	$lpml = "LPML Description Page (dist=$dist, $date)";
                    409: 	$lpml .=<<END;
                    410: 
                    411: * About this file
                    412: * Software Package Description
                    413: * Directory Structure
                    414: * File Type Ownership and Permissions
1.26      harris41  415: * Files
1.23      harris41  416: END
                    417:         $lpml .=<<END;
                    418: 
                    419: About this file
                    420: 
                    421: This file is generated dynamically by lpml_parse.pl as
                    422: part of a development compilation process.  Author: Scott
                    423: Harrison (harris41\@msu.edu).
                    424: 
                    425: END
1.3       harris41  426:     }
1.4       harris41  427:     elsif ($mode eq 'install') {
                    428: 	print '# LPML install targets. Linux Packaging Markup Language,';
                    429: 	print ' by Scott Harrison 2001'."\n";
                    430: 	print '# This file was automatically generated on '.`date`;
1.5       harris41  431: 	print "\n".$invocation;
1.14      harris41  432: 	$lpml .= "SHELL=\"/bin/bash\"\n\n";
1.4       harris41  433:     }
1.16      harris41  434:     elsif ($mode eq 'configinstall') {
1.17      harris41  435: 	print '# LPML configuration file targets (configinstall).'."\n";
                    436: 	print '# Linux Packaging Markup Language,';
1.16      harris41  437: 	print ' by Scott Harrison 2001'."\n";
                    438: 	print '# This file was automatically generated on '.`date`;
                    439: 	print "\n".$invocation;
                    440: 	$lpml .= "SHELL=\"/bin/bash\"\n\n";
                    441:     }
1.11      harris41  442:     elsif ($mode eq 'build') {
1.14      harris41  443: 	$lpml = "# LPML build targets. Linux Packaging Markup Language,";
                    444: 	$lpml .= ' by Scott Harrison 2001'."\n";
1.11      harris41  445: 	$lpml .= '# This file was automatically generated on '.`date`;
1.17      harris41  446: 	$lpml .= "\n".$invocation;
1.11      harris41  447: 	$lpml .= "SHELL=\"/bin/sh\"\n\n";
                    448:     }
1.4       harris41  449:     else {
                    450: 	return '';
                    451:     }
1.3       harris41  452: }
                    453: # --------------------------------------------------- Format targetroot section
                    454: sub format_targetroot {
                    455:     my $text=&trim($parser->get_text('/targetroot'));
                    456:     $text=$targetroot if $targetroot;
                    457:     $parser->get_tag('/targetroot');
                    458:     if ($mode eq 'html') {
1.10      harris41  459: 	return $targetroot="\n<br />TARGETROOT: $text";
1.3       harris41  460:     }
1.17      harris41  461:     elsif ($mode eq 'install' or $mode eq 'build' or
                    462: 	   $mode eq 'configinstall') {
1.11      harris41  463: 	return '# TARGET INSTALL LOCATION is "'.$targetroot."\"\n";
                    464:     }
1.3       harris41  465:     else {
                    466: 	return '';
                    467:     }
                    468: }
                    469: # --------------------------------------------------- Format sourceroot section
                    470: sub format_sourceroot {
                    471:     my $text=&trim($parser->get_text('/sourceroot'));
                    472:     $text=$sourceroot if $sourceroot;
                    473:     $parser->get_tag('/sourceroot');
                    474:     if ($mode eq 'html') {
1.10      harris41  475: 	return $sourceroot="\n<br />SOURCEROOT: $text";
1.3       harris41  476:     }
1.17      harris41  477:     elsif ($mode eq 'install' or $mode eq 'build' or
                    478: 	   $mode eq 'configinstall') {
1.11      harris41  479: 	return '# SOURCE CODE LOCATION IS "'.$sourceroot."\"\n";;
                    480:     }
1.3       harris41  481:     else {
                    482: 	return '';
                    483:     }
                    484: }
                    485: # --------------------------------------------------- Format categories section
                    486: sub format_categories {
                    487:     my $text=&trim($parser->get_text('/categories'));
                    488:     $parser->get_tag('/categories');
                    489:     if ($mode eq 'html') {
1.24      harris41  490: 	return $categories="\n<br />&nbsp;<br />".
                    491: 	    "\n<a name='ownperms'>".
                    492: 	    "\n<font size='+2'>File Type Ownership and Permissions".
                    493: 	    " Descriptions</font>".
1.25      harris41  494: 	    "\n<p>This table shows what permissions and ownership settings ".
                    495: 	    "correspond to each category.</p>".
                    496: 	    "\n<table border='1' cellpadding='5' width='60%'>\n".
                    497: 	    "<tr>".
                    498: 	    "<th align='left' bgcolor='#ffffff'>Icon</th>".
                    499: 	    "<th align='left' bgcolor='#ffffff'>Category Name</th>".
                    500: 	    "<th align='left' bgcolor='#ffffff'>Permissions ".
                    501: 	    "($categorytype)</th>".
                    502: 	    "</tr>".
                    503: 	    "\n$text\n".
1.24      harris41  504: 	    "</table>\n";
                    505:     }
                    506:     elsif ($mode eq 'text') {
                    507: 	return $categories="\n".
                    508: 	    "\nFile Type Ownership and Permissions".
                    509: 	    " Descriptions".
1.25      harris41  510: 	    "\n$text".
1.24      harris41  511: 	    "\n";
1.3       harris41  512:     }
                    513:     else {
                    514: 	return '';
                    515:     }
                    516: }
                    517: # --------------------------------------------------- Format categories section
                    518: sub format_category {
                    519:     my (@tokeninfo)=@_;
                    520:     $category_att_name=$tokeninfo[2]->{'name'};
                    521:     $category_att_type=$tokeninfo[2]->{'type'};
1.25      harris41  522:     $abbreviation=''; $chmod='';$chown='';
1.3       harris41  523:     $parser->get_text('/category');
                    524:     $parser->get_tag('/category');
1.26      harris41  525:     $fab{$category_att_name}=$abbreviation;
1.3       harris41  526:     if ($mode eq 'html') {
1.25      harris41  527: 	if ($category_att_type eq $categorytype) {
1.27      harris41  528: 	    $categoryhash{$category_att_name}="$chmod $chown";
1.25      harris41  529: 	    return $category="<tr>".
                    530: 		"<td><img src='$abbreviation.gif' ".
                    531:    	        "alt='${category_att_name}' /></td>\n".
                    532: 		"<td>${category_att_name}</td>\n".
                    533: 		"<td>$chmod $chown</td>\n".
                    534: 		"</tr>".
                    535: 		"\n";
                    536: #	return $category="\n<br />CATEGORY $category_att_name ".
                    537: #	    "$category_att_type $chmod $chown";
                    538: 	}
1.3       harris41  539:     }
                    540:     else {
1.4       harris41  541: 	if ($category_att_type eq $categorytype) {
                    542: 	    my ($user,$group)=split(/\:/,$chown);
                    543: 	    $categoryhash{$category_att_name}='-o '.$user.' -g '.$group.
                    544: 		' -m '.$chmod;
                    545: 	}
1.3       harris41  546: 	return '';
                    547:     }
                    548: }
1.25      harris41  549: # --------------------------------------------------- Format categories section
                    550: sub format_abbreviation {
                    551:     my @tokeninfo=@_;
                    552:     $abbreviation='';
                    553:     my $text=&trim($parser->get_text('/abbreviation'));
                    554:     if ($text) {
                    555: 	$parser->get_tag('/abbreviation');
                    556: 	$abbreviation=$text;
                    557:     }
                    558:     return '';
                    559: }
1.3       harris41  560: # -------------------------------------------------------- Format chown section
                    561: sub format_chown {
                    562:     my @tokeninfo=@_;
                    563:     $chown='';
                    564:     my $text=&trim($parser->get_text('/chown'));
                    565:     if ($text) {
                    566: 	$parser->get_tag('/chown');
                    567: 	$chown=$text;
                    568:     }
                    569:     return '';
                    570: }
                    571: # -------------------------------------------------------- Format chmod section
                    572: sub format_chmod {
                    573:     my @tokeninfo=@_;
                    574:     $chmod='';
                    575:     my $text=&trim($parser->get_text('/chmod'));
                    576:     if ($text) {
                    577: 	$parser->get_tag('/chmod');
                    578: 	$chmod=$text;
                    579:     }
                    580:     return '';
                    581: }
                    582: # ---------------------------------------------------------- Format rpm section
                    583: sub format_rpm {
                    584:     my $text=&trim($parser->get_text('/rpm'));
                    585:     $parser->get_tag('/rpm');
                    586:     if ($mode eq 'html') {
1.23      harris41  587: 	return $rpm=<<END;
1.24      harris41  588: <br />&nbsp;<br />
                    589: <a name='package' />
1.23      harris41  590: <font size='+2'>Software Package Description</font>
                    591: <p>
                    592: <table bgcolor='#ffffff' border='0' cellpadding='10' cellspacing='0'>
                    593: <tr><td><pre>
                    594: $text
                    595: </pre></td></tr>
                    596: </table>
                    597: END
                    598:     }
                    599:     elsif ($mode eq 'text') {
                    600: 	return $rpm=<<END;
                    601: Software Package Description
                    602: 
                    603: $text
                    604: END
1.3       harris41  605:     }
                    606:     else {
                    607: 	return '';
                    608:     }
                    609: }
                    610: # --------------------------------------------------- Format rpmSummary section
                    611: sub format_rpmSummary {
                    612:     my $text=&trim($parser->get_text('/rpmSummary'));
                    613:     $parser->get_tag('/rpmSummary');
                    614:     if ($mode eq 'html') {
1.23      harris41  615: 	return $rpmSummary="\nSummary     : $text";
                    616:     }
                    617:     elsif ($mode eq 'text') {
                    618: 	return $rpmSummary="\nSummary     : $text";
1.3       harris41  619:     }
                    620:     else {
                    621: 	return '';
                    622:     }
                    623: }
                    624: # ------------------------------------------------------ Format rpmName section
                    625: sub format_rpmName {
                    626:     my $text=&trim($parser->get_text('/rpmName'));
                    627:     $parser->get_tag('/rpmName');
                    628:     if ($mode eq 'html') {
1.24      harris41  629: 	return $rpmName="\nName        : $text";
                    630:     }
                    631:     elsif ($mode eq 'text') {
                    632: 	return $rpmName="\nName        : $text";
1.3       harris41  633:     }
                    634:     else {
                    635: 	return '';
                    636:     }
                    637: }
                    638: # --------------------------------------------------- Format rpmVersion section
                    639: sub format_rpmVersion {
                    640:     my $text=$parser->get_text('/rpmVersion');
                    641:     $parser->get_tag('/rpmVersion');
                    642:     if ($mode eq 'html') {
1.24      harris41  643: 	return $rpmVersion="\nVersion     : $text";
                    644:     }
                    645:     elsif ($mode eq 'text') {
                    646: 	return $rpmVersion="\nVersion     : $text";
1.3       harris41  647:     }
                    648:     else {
                    649: 	return '';
                    650:     }
                    651: }
                    652: # --------------------------------------------------- Format rpmRelease section
                    653: sub format_rpmRelease {
                    654:     my $text=$parser->get_text('/rpmRelease');
                    655:     $parser->get_tag('/rpmRelease');
                    656:     if ($mode eq 'html') {
1.24      harris41  657: 	return $rpmRelease="\nRelease     : $text";
                    658:     }
                    659:     elsif ($mode eq 'text') {
                    660: 	return $rpmRelease="\nRelease     : $text";
1.3       harris41  661:     }
                    662:     else {
                    663: 	return '';
                    664:     }
                    665: }
                    666: # ---------------------------------------------------- Format rpmVendor section
                    667: sub format_rpmVendor {
                    668:     my $text=$parser->get_text('/rpmVendor');
                    669:     $parser->get_tag('/rpmVendor');
                    670:     if ($mode eq 'html') {
1.24      harris41  671: 	return $rpmVendor="\nVendor      : $text";
                    672:     }
                    673:     elsif ($mode eq 'text') {
                    674: 	return $rpmVendor="\nVendor      : $text";
1.3       harris41  675:     }
                    676:     else {
                    677: 	return '';
                    678:     }
                    679: }
                    680: # ------------------------------------------------- Format rpmBuildRoot section
                    681: sub format_rpmBuildRoot {
                    682:     my $text=$parser->get_text('/rpmBuildRoot');
                    683:     $parser->get_tag('/rpmBuildRoot');
                    684:     if ($mode eq 'html') {
1.24      harris41  685: 	return $rpmBuildRoot="\nBuild Root  : $text";
                    686:     }
                    687:     elsif ($mode eq 'text') {
                    688: 	return $rpmBuildRoot="\nBuild Root  : $text";
1.3       harris41  689:     }
                    690:     else {
                    691: 	return '';
                    692:     }
                    693: }
                    694: # ------------------------------------------------- Format rpmCopyright section
                    695: sub format_rpmCopyright {
                    696:     my $text=$parser->get_text('/rpmCopyright');
                    697:     $parser->get_tag('/rpmCopyright');
                    698:     if ($mode eq 'html') {
1.24      harris41  699: 	return $rpmCopyright="\nLicense     : $text";
                    700:     }
                    701:     elsif ($mode eq 'text') {
                    702: 	return $rpmCopyright="\nLicense     : $text";
1.3       harris41  703:     }
                    704:     else {
                    705: 	return '';
                    706:     }
                    707: }
                    708: # ----------------------------------------------------- Format rpmGroup section
                    709: sub format_rpmGroup {
                    710:     my $text=$parser->get_text('/rpmGroup');
                    711:     $parser->get_tag('/rpmGroup');
                    712:     if ($mode eq 'html') {
1.24      harris41  713: 	return $rpmGroup="\nGroup       : $text";
                    714:     }
                    715:     elsif ($mode eq 'text') {
                    716: 	return $rpmGroup="\nGroup       : $text";
1.3       harris41  717:     }
                    718:     else {
                    719: 	return '';
                    720:     }
                    721: }
                    722: # ---------------------------------------------------- Format rpmSource section
                    723: sub format_rpmSource {
                    724:     my $text=$parser->get_text('/rpmSource');
                    725:     $parser->get_tag('/rpmSource');
                    726:     if ($mode eq 'html') {
1.24      harris41  727: 	return $rpmSource="\nSource      : $text";
                    728:     }
                    729:     elsif ($mode eq 'text') {
                    730: 	return $rpmSource="\nSource      : $text";
1.3       harris41  731:     }
                    732:     else {
                    733: 	return '';
                    734:     }
                    735: }
                    736: # ----------------------------------------------- Format rpmAutoReqProv section
                    737: sub format_rpmAutoReqProv {
                    738:     my $text=$parser->get_text('/rpmAutoReqProv');
                    739:     $parser->get_tag('/rpmAutoReqProv');
                    740:     if ($mode eq 'html') {
1.24      harris41  741: 	return $rpmAutoReqProv="\nAutoReqProv : $text";
                    742:     }
                    743:     if ($mode eq 'text') {
                    744: 	return $rpmAutoReqProv="\nAutoReqProv : $text";
1.3       harris41  745:     }
                    746:     else {
                    747: 	return '';
                    748:     }
                    749: }
                    750: # ----------------------------------------------- Format rpmdescription section
                    751: sub format_rpmdescription {
                    752:     my $text=$parser->get_text('/rpmdescription');
                    753:     $parser->get_tag('/rpmdescription');
                    754:     if ($mode eq 'html') {
1.25      harris41  755: 	$text=~s/\n//g;
                    756: 	$text=~s/\\n/\n/g;
1.24      harris41  757: 	return $rpmdescription="\nDescription : $text";
                    758:     }
                    759:     elsif ($mode eq 'text') {
1.25      harris41  760: 	$text=~s/\n//g;
                    761: 	$text=~s/\\n/\n/g;
1.24      harris41  762: 	return $rpmdescription="\nDescription : $text";
1.3       harris41  763:     }
                    764:     else {
                    765: 	return '';
                    766:     }
                    767: }
                    768: # ------------------------------------------------------- Format rpmpre section
                    769: sub format_rpmpre {
                    770:     my $text=$parser->get_text('/rpmpre');
                    771:     $parser->get_tag('/rpmpre');
                    772:     if ($mode eq 'html') {
1.24      harris41  773: #	return $rpmpre="\n<br />RPMPRE $text";
                    774: 	return '';
1.3       harris41  775:     }
                    776:     else {
                    777: 	return '';
                    778:     }
                    779: }
                    780: # -------------------------------------------------- Format directories section
                    781: sub format_directories {
1.4       harris41  782:     my $text=$parser->get_text('/directories');
1.3       harris41  783:     $parser->get_tag('/directories');
                    784:     if ($mode eq 'html') {
1.26      harris41  785: 	$text=~s/\[\{\{\{\{\{DPATHLENGTH\}\}\}\}\}\]/$dpathlength/g;
1.24      harris41  786: 	return $directories="\n<br />&nbsp;<br />".
                    787: 	    "<a name='directories' />".
                    788: 	    "<font size='+2'>Directory Structure</font>".
1.26      harris41  789: 	    "\n<br />&nbsp;<br />".
                    790: 	    "<table border='1' cellpadding='3' cellspacing='0'>\n".
                    791: 	    "<tr><th bgcolor='#ffffff'>Category</th>".
                    792: 	    "<th bgcolor='#ffffff'>Status</th>\n".
                    793: 	    "<th bgcolor='#ffffff'>Expected Permissions & Ownership</th>\n".
                    794: 	    "<th bgcolor='#ffffff' colspan='$dpathlength'>Target Directory ".
                    795: 	    "Path</th></tr>\n".
                    796:  	    "\n$text\n</table><br />"."\n";
1.24      harris41  797:     }
                    798:     elsif ($mode eq 'text') {
                    799: 	return $directories="\nDirectory Structure\n$text\n".
                    800: 	    "\n";
1.3       harris41  801:     }
1.4       harris41  802:     elsif ($mode eq 'install') {
                    803: 	return "\n".'directories:'."\n".$text;
                    804:    }
1.3       harris41  805:     else {
                    806: 	return '';
                    807:     }
                    808: }
                    809: # ---------------------------------------------------- Format directory section
                    810: sub format_directory {
                    811:     my (@tokeninfo)=@_;
                    812:     $targetdir='';$categoryname='';$description='';
                    813:     $parser->get_text('/directory');
                    814:     $parser->get_tag('/directory');
                    815:     if ($mode eq 'html') {
1.26      harris41  816: 	my @a;
                    817: 	@a=($targetdir=~/\//g);
                    818: 	my $d=scalar(@a)+1;
                    819: 	$dpathlength=$d if $d>$dpathlength;
                    820: 	my $thtml=$targetdir;
                    821: 	$thtml=~s/\//\<\/td\>\<td bgcolor='#ffffff'\>/g;
1.28    ! harris41  822: 	my ($chmod,$chown)=split(/\s/,$categoryhash{$categoryname});
1.26      harris41  823: 	return $directory="\n<tr><td rowspan='2' bgcolor='#ffffff'>".
                    824: 	    "$categoryname</td>".
1.28    ! harris41  825: 	    "<td rowspan='2' bgcolor='#ffffff'><!-- POSTEVAL2 verify.pl directory /$targetdir $categoryhash{$categoryname} -->&nbsp;</td>".
1.26      harris41  826: 	    "<td rowspan='2' bgcolor='#ffffff'>$chmod<br />$chown</td>".
                    827: 	    "<td bgcolor='#ffffff'>$thtml</td></tr>".
                    828: 	    "<tr><td bgcolor='#ffffff' colspan='[{{{{{DPATHLENGTH}}}}}]'>".
                    829: 	    "$description</td></tr>";
                    830:     }
                    831:     if ($mode eq 'text') {
                    832: 	return $directory="\nDIRECTORY $targetdir $categoryname ".
1.10      harris41  833: 	    "$description";
1.3       harris41  834:     }
1.4       harris41  835:     elsif ($mode eq 'install') {
1.8       harris41  836: 	return "\t".'install '.$categoryhash{$categoryname}.' -d '.
                    837: 	    $targetroot.'/'.$targetdir."\n";
1.4       harris41  838:     }
1.3       harris41  839:     else {
                    840: 	return '';
                    841:     }
                    842: }
                    843: # ---------------------------------------------------- Format targetdir section
                    844: sub format_targetdir {
                    845:     my @tokeninfo=@_;
                    846:     $targetdir='';
                    847:     my $text=&trim($parser->get_text('/targetdir'));
                    848:     if ($text) {
                    849: 	$parser->get_tag('/targetdir');
                    850: 	$targetdir=$text;
                    851:     }
                    852:     return '';
                    853: }
                    854: # ------------------------------------------------- Format categoryname section
                    855: sub format_categoryname {
                    856:     my @tokeninfo=@_;
                    857:     $categoryname='';
                    858:     my $text=&trim($parser->get_text('/categoryname'));
                    859:     if ($text) {
                    860: 	$parser->get_tag('/categoryname');
                    861: 	$categoryname=$text;
                    862:     }
                    863:     return '';
                    864: }
                    865: # -------------------------------------------------- Format description section
                    866: sub format_description {
                    867:     my @tokeninfo=@_;
                    868:     $description='';
1.10      harris41  869:     my $text=&htmlsafe(&trim($parser->get_text('/description')));
1.3       harris41  870:     if ($text) {
                    871: 	$parser->get_tag('/description');
                    872: 	$description=$text;
                    873:     }
                    874:     return '';
                    875: }
                    876: # -------------------------------------------------------- Format files section
                    877: sub format_files {
1.4       harris41  878:     my $text=$parser->get_text('/files');
1.3       harris41  879:     $parser->get_tag('/files');
                    880:     if ($mode eq 'html') {
1.24      harris41  881: 	return $directories="\n<br />&nbsp;<br />".
                    882: 	    "<a name='files' />".
1.26      harris41  883: 	    "<font size='+2'>Files</font><br />&nbsp;<br />".
                    884: 	    "<p>All source and target locations are relative to the ".
                    885: 	    "sourceroot and targetroot values at the beginning of this ".
                    886: 	    "document.</p>".
                    887: 	    "\n<table border='1' cellpadding='5'>".
                    888: 	    "<tr><th>Status</th><th colspan='2'>Category</th>".
                    889: 	    "<th>Name/Location</th>".
                    890: 	    "<th>Description</th><th>Notes</th></tr>".
                    891: 	    "$text</table>\n".
1.24      harris41  892: 	    "\n";
                    893:     }
                    894:     elsif ($mode eq 'text') {
                    895: 	return $directories="\n".
                    896: 	    "File and Directory Structure".
                    897: 	    "\n$text\n".
                    898: 	    "\n";
1.3       harris41  899:     }
1.4       harris41  900:     elsif ($mode eq 'install') {
                    901: 	return "\n".'files:'."\n".$text.
                    902: 	    "\n".'links:'."\n".join('',@links);
                    903:     }
1.12      harris41  904:     elsif ($mode eq 'configinstall') {
                    905: 	return "\n".'configfiles: '.
                    906: 	join(' ',@configall).
1.14      harris41  907: 	"\n\n".$text.
                    908: 	"\n\nalwaysrun:\n\n";
1.12      harris41  909:     }
1.11      harris41  910:     elsif ($mode eq 'build') {
                    911: 	my $binfo;
                    912: 	my $tword;
                    913: 	my $command2;
                    914: 	my @deps;
                    915: 	foreach my $bi (@buildinfo) {
1.14      harris41  916: 	    my ($target,$source,$command,$trigger,@deps)=split(/\;/,$bi);
1.11      harris41  917: 	    $tword=''; $tword=' alwaysrun' if $trigger eq 'always run'; 
                    918: 	    $command=~s/\/([^\/]*)$//;
                    919: 	    $command2="cd $command; sh ./$1;\\";
                    920: 	    my $depstring;
1.14      harris41  921: 	    my $depstring2="\t\t\@echo '';\\\n";
                    922: 	    my $olddep;
1.11      harris41  923: 	    foreach my $dep (@deps) {
1.14      harris41  924: 		unless ($olddep) {
                    925: 		    $olddep=$deps[$#deps];
                    926: 		}
1.11      harris41  927: 		$depstring.="\telif !(test -r $command/$dep);\\\n";
                    928: 		$depstring.="\t\tthen echo ".
1.14      harris41  929: 		"\"**** WARNING **** missing the file: ".
1.19      harris41  930:  	        "$command/$dep\"$logcmd;\\\n";
1.14      harris41  931: 		$depstring.="\t\ttest -e $source || test -e $target || echo ".
                    932: 		    "'**** ERROR **** neither source=$source nor target=".
1.19      harris41  933: 		    "$target exist and they cannot be built'$logcmd;\\\n";
1.14      harris41  934: 		$depstring.="\t\tmake -f Makefile.build ${source}___DEPS;\\\n";
                    935: 		if ($olddep) {
                    936: 		    $depstring2.="\t\tECODE=0;\\\n";
                    937: 		    $depstring2.="\t\t! test -e $source && test -r $command/$olddep &&".
1.19      harris41  938: 			" { 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  939: 		}
                    940: 		$olddep=$dep;
1.11      harris41  941: 	    }
                    942: 	    $binfo.="$source: $tword\n".
                    943: 		"\t\@if !(echo \"\");\\\n\t\tthen echo ".
1.14      harris41  944: 		"\"**** WARNING **** Strange shell. ".
1.19      harris41  945:  	        "Check your path settings.\"$logcmd;\\\n".
1.11      harris41  946: 		$depstring.
                    947: 		"\telse \\\n\t\t$command2\n\tfi\n\n";
1.14      harris41  948: 	    $binfo.="${source}___DEPS:\n".$depstring2."\t\tECODE=0;\n\n";
1.11      harris41  949: 	}
                    950: 	return 'all: '.join(' ',@buildall)."\n\n".
                    951:   	        $text.
                    952: 		$binfo."\n".
                    953: 		"alwaysrun:\n\n";
                    954:     }
1.3       harris41  955:     else {
                    956: 	return '';
                    957:     }
                    958: }
                    959: # ---------------------------------------------------- Format fileglobs section
                    960: sub format_fileglobs {
                    961: 
                    962: }
                    963: # -------------------------------------------------------- Format links section
1.4       harris41  964: # deprecated.. currently <link></link>'s are included in <files></files>
1.3       harris41  965: sub format_links {
1.4       harris41  966:     my $text=$parser->get_text('/links');
                    967:     $parser->get_tag('/links');
                    968:     if ($mode eq 'html') {
1.10      harris41  969: 	return $links="\n<br />BEGIN LINKS\n$text\n<br />END LINKS\n";
1.4       harris41  970:     }
                    971:     elsif ($mode eq 'install') {
                    972: 	return "\n".'links:'."\n\t".$text;
                    973:     }
                    974:     else {
                    975: 	return '';
                    976:     }
1.1       harris41  977: }
1.3       harris41  978: # --------------------------------------------------------- Format file section
                    979: sub format_file {
                    980:     my @tokeninfo=@_;
                    981:     $file=''; $source=''; $target=''; $categoryname=''; $description='';
                    982:     $note=''; $build=''; $status=''; $dependencies='';
                    983:     my $text=&trim($parser->get_text('/file'));
1.14      harris41  984:     my $buildtest;
1.3       harris41  985:     if ($source) {
                    986: 	$parser->get_tag('/file');
                    987: 	if ($mode eq 'html') {
1.26      harris41  988: 	    return ($file="\n<!-- FILESORT:$target -->".
                    989: 		    "<tr>".
1.28    ! harris41  990: 		    "<td><!-- POSTEVAL2 verify.pl file '$sourcerootarg' ".
        !           991: 		    "'$targetrootarg' ".
        !           992: 		    "'$source' '$target' ".
        !           993: 		    "$categoryhash{$categoryname} -->&nbsp;</td><td>".
1.27      harris41  994: 		    "<img src='$fab{$categoryname}.gif' ".
1.26      harris41  995: 		    "alt='$categoryname icon' /></td>".
1.27      harris41  996: 		    "<td>$categoryname<br /><font size='-1'>".
                    997: 		    $categoryhash{$categoryname}."</font></td>".
1.26      harris41  998: 		    "<td>SOURCE: $source<br />TARGET: $target</td>".
                    999: 		    "<td>$description</td>".
                   1000: 		    "<td>$note</td>".
                   1001: 		    "</tr>");
                   1002: #	    return ($file="\n<br />BEGIN FILE\n".
                   1003: #		"$source $target $categoryname $description $note " .
                   1004: #		"$build $status $dependencies" .
                   1005: #		"\nEND FILE");
1.3       harris41 1006: 	}
1.5       harris41 1007: 	elsif ($mode eq 'install' && $categoryname ne 'conf') {
1.14      harris41 1008: 	    if ($build) {
                   1009: 		my $bi=$sourceroot.'/'.$source.';'.$build.';'.
                   1010: 		    $dependencies;
                   1011: 		my ($source2,$command,$trigger,@deps)=split(/\;/,$bi);
                   1012: 		$tword=''; $tword=' alwaysrun' if $trigger eq 'always run'; 
                   1013: 		$command=~s/\/([^\/]*)$//;
                   1014: 		$command2="cd $command; sh ./$1;\\";
                   1015: 		my $depstring;
                   1016: 		foreach my $dep (@deps) {
                   1017: 		    $depstring.=<<END;
                   1018: 		ECODE=0; DEP=''; \\
1.19      harris41 1019: 		test -e $command/$dep || (echo '**** WARNING **** cannot evaluate status of dependency $command/$dep (for building ${sourceroot}/${source} with)'$logcmd); DEP="1"; \\
1.18      harris41 1020: 		[ -n DEP ] && { perl filecompare.pl -b2 $command/$dep ${targetroot}/${target} || ECODE=\$\$?; } || DEP="1"; \\
1.14      harris41 1021: 		case "\$\$ECODE" in \\
1.19      harris41 1022: 			2) echo "**** WARNING **** dependency $command/$dep is newer than target file ${targetroot}/${target}; you may want to run make build"$logcmd;; \\
1.14      harris41 1023: 		esac; \\
                   1024: END
                   1025: 		}
                   1026:                 chomp $depstring;
                   1027: 		$buildtest=<<END;
                   1028: 	\@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
1.19      harris41 1029: 		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 1030: END
                   1031:                 $buildtest.=<<END if $depstring;
                   1032: 	elif !(test -e "${sourceroot}/${source}"); then \\
                   1033: $depstring
                   1034: END
                   1035:                 $buildtest.=<<END;
                   1036: 	fi
                   1037: END
                   1038: 	    }
1.18      harris41 1039:             my $bflag='-b1';
                   1040:             $bflag='-b3' if $dependencies or $buildlink;
1.14      harris41 1041: 	    return <<END;
1.19      harris41 1042: $buildtest	\@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
                   1043: 		echo "**** ERROR **** CVS source file does not exist: ${sourceroot}/${source} and neither does target: ${targetroot}/${target}"$logcmd; \\
                   1044: 	elif !(test -e "${sourceroot}/${source}"); then \\
                   1045: 		echo "**** WARNING **** CVS source file does not exist: ${sourceroot}/${source}"$logcmd; \\
1.21      harris41 1046: 		perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\
1.14      harris41 1047: 	else \\
                   1048: 		ECODE=0; \\
                   1049: 		perl filecompare.pl $bflag ${sourceroot}/${source} ${targetroot}/${target} || ECODE=\$\$?; \\
                   1050: 		case "\$\$ECODE" in \\
                   1051: 			1) echo "${targetroot}/${target} is unchanged";; \\
1.21      harris41 1052: 			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 1053: 			0) echo "install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target}" && install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target};; \\
1.14      harris41 1054: 		esac; \\
1.21      harris41 1055: 		perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\
1.14      harris41 1056: 	fi
                   1057: END
1.12      harris41 1058: 	}
                   1059: 	elsif ($mode eq 'configinstall' && $categoryname eq 'conf') {
                   1060: 	    push @configall,$targetroot.'/'.$target;
1.14      harris41 1061: 	    return $targetroot.'/'.$target.': alwaysrun'."\n".
1.20      harris41 1062: 		"\t".'@echo -n ""; ECODE=0 && { perl filecompare.pl -b4 '.
                   1063: 		$sourceroot.'/'.$source.' '.$targetroot.'/'.$target.
                   1064: 		' || ECODE=$$?; } && '.
                   1065: 		'{ [ $$ECODE != "2" ] || (install '.
                   1066:                 $categoryhash{$categoryname}.' '.
1.12      harris41 1067: 		$sourceroot.'/'.$source.' '.
1.21      harris41 1068: 		$targetroot.'/'.$target.'.lpmlnew'.
1.19      harris41 1069: 		' && echo "**** NOTE: CONFIGURATION FILE CHANGE ****"'.
                   1070: 		$logcmd.' && echo "'.
1.14      harris41 1071: 		'You likely need to compare contents of '.
                   1072: 		''.$targetroot.'/'.$target.' with the new '.
1.21      harris41 1073:                 ''.$targetroot.'/'.$target.'.lpmlnew"'.
1.20      harris41 1074: 		"$logcmd); } && ".
                   1075: 		'{ [ $$ECODE != "3" ] || (install '.
                   1076:                 $categoryhash{$categoryname}.' '.
                   1077: 		$sourceroot.'/'.$source.' '.
                   1078: 		$targetroot.'/'.$target.''.
                   1079: 		' && echo "**** WARNING: NEW CONFIGURATION FILE ADDED ****"'.
                   1080: 		$logcmd.' && echo "'.
                   1081: 		'You likely need to review the contents of '.
                   1082: 		''.$targetroot.'/'.$target.' to make sure its '.
                   1083:                 'settings are compatible with your overall system"'.
                   1084: 		"$logcmd); } && ".
                   1085: 		'{ [ $$ECODE != "1" ] || ('.
                   1086: 		'echo "**** ERROR ****"'.
                   1087: 		$logcmd.' && echo "'.
                   1088: 		'Configuration source file does not exist '.
                   1089: 		''.$sourceroot.'/'.$source.'"'.
1.22      harris41 1090: 		"$logcmd); } && perl verifymodown.pl ${targetroot}/${target} \"$categoryhash{$categoryname}\"$logcmd;\n\n";
1.4       harris41 1091: 	}
1.11      harris41 1092: 	elsif ($mode eq 'build' && $build) {
                   1093: 	    push @buildall,$sourceroot.'/'.$source;
1.14      harris41 1094: 	    push @buildinfo,$targetroot.'/'.$target.';'.$sourceroot.'/'.
                   1095: 		$source.';'.$build.';'.
1.11      harris41 1096: 		$dependencies;
                   1097: #	    return '# need to build '.$source.";
                   1098: 	}
1.3       harris41 1099: 	else {
                   1100: 	    return '';
                   1101: 	}
                   1102:     }
                   1103:     return '';
                   1104: }
                   1105: # --------------------------------------------------------- Format link section
                   1106: sub format_link {
                   1107:     my @tokeninfo=@_;
1.27      harris41 1108:     $link=''; $linkto=''; $source=''; $target=''; $categoryname=''; 
                   1109:     $description=''; $note=''; $build=''; $status=''; $dependencies='';
1.3       harris41 1110:     my $text=&trim($parser->get_text('/link'));
                   1111:     if ($linkto) {
                   1112: 	$parser->get_tag('/link');
                   1113: 	if ($mode eq 'html') {
1.27      harris41 1114: 	    my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
                   1115: 	    foreach my $tgt (@targets) {
                   1116: 		push @links,("\n<!-- FILESORT:$tgt -->".
                   1117: 		    "<tr>".
1.28    ! harris41 1118: 		    "<td><!-- POSTEVAL2 verify.pl link ".
        !          1119: 		    "'/$targetrootarg$linkto' '/$targetrootarg$tgt' ".
        !          1120: 		    "$categoryhash{$categoryname} -->&nbsp;</td><td>".
1.27      harris41 1121: 		    "<img src='$fab{$categoryname}.gif' ".
                   1122: 		    "alt='$categoryname icon' /></td>".
                   1123: 		    "<td><font size='-1'>$categoryname</font></td>".
                   1124: 		    "<td>LINKTO: $linkto<br />TARGET: $tgt</td>".
                   1125: 		    "<td>$description</td>".
                   1126: 		    "<td>$note</td>".
                   1127: 		    "</tr>");
                   1128: #		push @links,"\t".'ln -fs /'.$linkto.' /'.$targetroot.$tgt.
                   1129: #		    "\n";
                   1130: 	    }
                   1131: 	    return join('',@links);
                   1132: #	    return ($link="\n<!-- FILESORT:$target -->".
                   1133: #		    "<tr>".
                   1134: #		    "<td>&nbsp;</td><td><img src='$fab{$categoryname}.gif' ".
                   1135: #		    "alt='$categoryname icon' /></td>".
                   1136: #		    "<td>$categoryname</td>".
                   1137: #		    "<td>LINKTO: $linkto<br />TARGET: $target</td>".
                   1138: #		    "<td>$description</td>".
                   1139: #		    "<td>$note</td>".
                   1140: #		    "</tr>");
                   1141: #	    return $link="\n<tr><td colspan='6'>BEGIN LINK\n".
                   1142: #		"$linkto $target $categoryname $description $note " .
                   1143: #		"$build $status $dependencies" .
                   1144: #		    "\nEND LINK</td></tr>";
1.4       harris41 1145: 	}
                   1146: 	elsif ($mode eq 'install') {
1.10      harris41 1147: 	    my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
1.5       harris41 1148: 	    foreach my $tgt (@targets) {
                   1149: 		push @links,"\t".'ln -fs /'.$linkto.' /'.$targetroot.$tgt.
                   1150: 		    "\n";
                   1151: 	    }
1.4       harris41 1152: 	    return '';
1.3       harris41 1153: 	}
                   1154: 	else {
                   1155: 	    return '';
                   1156: 	}
                   1157:     }
                   1158:     return '';
                   1159: }
                   1160: # ----------------------------------------------------- Format fileglob section
                   1161: sub format_fileglob {
                   1162:     my @tokeninfo=@_;
                   1163:     $fileglob=''; $glob=''; $sourcedir='';
                   1164:     $targetdir=''; $categoryname=''; $description='';
                   1165:     $note=''; $build=''; $status=''; $dependencies='';
                   1166:     $filenames='';
                   1167:     my $text=&trim($parser->get_text('/fileglob'));
1.27      harris41 1168:     my $filenames2=$filenames;$filenames2=~s/\s//g;
1.3       harris41 1169:     if ($sourcedir) {
                   1170: 	$parser->get_tag('/fileglob');
                   1171: 	if ($mode eq 'html') {
1.27      harris41 1172: 	    return $fileglob="\n<tr>".
                   1173: 		"<td><!-- POSTEVAL2 verify.pl fileglob '$sourcerootarg' ".
                   1174: 		"'$targetrootarg' ".
                   1175: 		"'$glob' '$sourcedir' '$filenames2' '$targetdir' ".
                   1176: 		"$categoryhash{$categoryname} -->&nbsp;</td>".
                   1177: 		"<td>"."<img src='$fab{$categoryname}.gif' ".
                   1178: 	        "alt='$categoryname icon' /></td>".
                   1179: 		"<td>$categoryname<br />".
                   1180: 		"<font size='-1'>".$categoryhash{$categoryname}."</font></td>".
                   1181: 		"<td>SOURCEDIR: $sourcedir<br />".
                   1182: 		"TARGETDIR: $targetdir<br />".
                   1183:                 "GLOB: $glob<br />".
                   1184:                 "FILENAMES: $filenames".
                   1185: 		"</td>".
                   1186: 		"<td>$description</td>".
                   1187: 		"<td>$note</td>".
                   1188: 		"</tr>";
                   1189: #	    return $fileglob="\n<tr><td colspan='6'>BEGIN FILEGLOB\n".
                   1190: #		"$glob sourcedir $targetdir $categoryname $description $note ".
                   1191: #		"$build $status $dependencies $filenames" .
                   1192: #		"\nEND FILEGLOB</td></tr>";
1.3       harris41 1193: 	}
1.5       harris41 1194: 	elsif ($mode eq 'install') {
                   1195: 	    return "\t".'install '.
                   1196: 		$categoryhash{$categoryname}.' '.
1.13      albertel 1197: 		$sourceroot.'/'.$sourcedir.'[^C][^V][^S]'.$glob.' '.
1.5       harris41 1198: 		$targetroot.'/'.$targetdir.'.'."\n";
                   1199: 	}
1.3       harris41 1200: 	else {
                   1201: 	    return '';
                   1202: 	}
                   1203:     }
                   1204:     return '';
                   1205: }
                   1206: # ---------------------------------------------------- Format sourcedir section
                   1207: sub format_sourcedir {
                   1208:     my @tokeninfo=@_;
                   1209:     $sourcedir='';
                   1210:     my $text=&trim($parser->get_text('/sourcedir'));
                   1211:     if ($text) {
                   1212: 	$parser->get_tag('/sourcedir');
                   1213: 	$sourcedir=$text;
                   1214:     }
                   1215:     return '';
                   1216: }
                   1217: # ------------------------------------------------------- Format target section
                   1218: sub format_target {
                   1219:     my @tokeninfo=@_;
                   1220:     $target='';
                   1221:     my $text=&trim($parser->get_text('/target'));
                   1222:     if ($text) {
                   1223: 	$parser->get_tag('/target');
                   1224: 	$target=$text;
                   1225:     }
                   1226:     return '';
                   1227: }
                   1228: # ------------------------------------------------------- Format source section
                   1229: sub format_source {
                   1230:     my @tokeninfo=@_;
                   1231:     $source='';
                   1232:     my $text=&trim($parser->get_text('/source'));
                   1233:     if ($text) {
                   1234: 	$parser->get_tag('/source');
                   1235: 	$source=$text;
                   1236:     }
                   1237:     return '';
                   1238: }
                   1239: # --------------------------------------------------------- Format note section
                   1240: sub format_note {
                   1241:     my @tokeninfo=@_;
                   1242:     $note='';
1.26      harris41 1243: #    my $text=&trim($parser->get_text('/note'));
                   1244:     my $aref;
                   1245:     my $text;
                   1246:     while ($aref=$parser->get_token()) {
                   1247: 	if ($aref->[0] eq 'E' && $aref->[1] eq 'note') {
                   1248: 	    last;
                   1249: 	}
                   1250: 	elsif ($aref->[0] eq 'S') {
                   1251: 	    $text.=$aref->[4];
                   1252: 	}
                   1253: 	elsif ($aref->[0] eq 'E') {
                   1254: 	    $text.=$aref->[2];
                   1255: 	}
                   1256: 	else {
                   1257: 	    $text.=$aref->[1];
                   1258: 	}
                   1259:     }
1.3       harris41 1260:     if ($text) {
1.26      harris41 1261: #	$parser->get_tag('/note');
1.3       harris41 1262: 	$note=$text;
                   1263:     }
                   1264:     return '';
                   1265: 
                   1266: }
                   1267: # -------------------------------------------------------- Format build section
                   1268: sub format_build {
                   1269:     my @tokeninfo=@_;
                   1270:     $build='';
                   1271:     my $text=&trim($parser->get_text('/build'));
                   1272:     if ($text) {
                   1273: 	$parser->get_tag('/build');
1.11      harris41 1274: 	$build=$sourceroot.'/'.$text.';'.$tokeninfo[2]{'trigger'};
1.3       harris41 1275:     }
                   1276:     return '';
                   1277: }
1.14      harris41 1278: # -------------------------------------------------------- Format build section
                   1279: sub format_buildlink {
                   1280:     my @tokeninfo=@_;
                   1281:     $buildlink='';
                   1282:     my $text=&trim($parser->get_text('/buildlink'));
                   1283:     if ($text) {
                   1284: 	$parser->get_tag('/buildlink');
                   1285: 	$buildlink=$sourceroot.'/'.$text;
                   1286:     }
                   1287:     return '';
                   1288: }
1.3       harris41 1289: # ------------------------------------------------------- Format status section
                   1290: sub format_status {
                   1291:     my @tokeninfo=@_;
                   1292:     $status='';
                   1293:     my $text=&trim($parser->get_text('/status'));
                   1294:     if ($text) {
                   1295: 	$parser->get_tag('/status');
                   1296: 	$status=$text;
                   1297:     }
                   1298:     return '';
                   1299: }
                   1300: # ------------------------------------------------- Format dependencies section
                   1301: sub format_dependencies {
                   1302:     my @tokeninfo=@_;
                   1303:     $dependencies='';
                   1304:     my $text=&trim($parser->get_text('/dependencies'));
                   1305:     if ($text) {
                   1306: 	$parser->get_tag('/dependencies');
1.11      harris41 1307: 	$dependencies=join(';',
                   1308: 			      (map {s/^\s*//;s/\s$//;$_} split(/\;/,$text)));
1.3       harris41 1309:     }
                   1310:     return '';
                   1311: }
                   1312: # --------------------------------------------------------- Format glob section
                   1313: sub format_glob {
                   1314:     my @tokeninfo=@_;
                   1315:     $glob='';
                   1316:     my $text=&trim($parser->get_text('/glob'));
                   1317:     if ($text) {
                   1318: 	$parser->get_tag('/glob');
                   1319: 	$glob=$text;
                   1320:     }
                   1321:     return '';
                   1322: }
                   1323: # ---------------------------------------------------- Format filenames section
                   1324: sub format_filenames {
                   1325:     my @tokeninfo=@_;
                   1326:     my $text=&trim($parser->get_text('/filenames'));
                   1327:     if ($text) {
                   1328: 	$parser->get_tag('/filenames');
                   1329: 	$filenames=$text;
                   1330:     }
                   1331:     return '';
                   1332: }
                   1333: # ------------------------------------------------------- Format linkto section
                   1334: sub format_linkto {
                   1335:     my @tokeninfo=@_;
                   1336:     my $text=&trim($parser->get_text('/linkto'));
                   1337:     if ($text) {
                   1338: 	$parser->get_tag('/linkto');
                   1339: 	$linkto=$text;
                   1340:     }
                   1341:     return '';
1.10      harris41 1342: }
                   1343: # ------------------------------------- Render less-than and greater-than signs
                   1344: sub htmlsafe {
                   1345:     my $text=@_[0];
                   1346:     $text =~ s/</&lt;/g;
                   1347:     $text =~ s/>/&gt;/g;
                   1348:     return $text;
1.3       harris41 1349: }
                   1350: # --------------------------------------- remove starting and ending whitespace
                   1351: sub trim {
                   1352:     my ($s)=@_; $s=~s/^\s*//; $s=~s/\s*$//; return $s;
                   1353: } 
1.14      harris41 1354: 
                   1355: # ----------------------------------- POD (plain old documentation, CPAN style)
1.18      harris41 1356: 
                   1357: =head1 NAME
                   1358: 
                   1359: lpml_parse.pl - This is meant to parse files meeting the lpml document type.
                   1360: See lpml.dtd.  LPML=Linux Packaging Markup Language.
                   1361: 
                   1362: =head1 SYNOPSIS
                   1363: 
                   1364: Usage is for lpml file to come in through standard input.
                   1365: 
                   1366: =over 4
                   1367: 
                   1368: =item *
                   1369: 
                   1370: 1st argument is the mode of parsing.
                   1371: 
                   1372: =item * 
                   1373: 
                   1374: 2nd argument is the category permissions to use (runtime or development)
                   1375: 
                   1376: =item *
                   1377: 
                   1378: 3rd argument is the distribution
                   1379: (default,redhat6.2,debian2.2,redhat7.1,etc).
                   1380: 
                   1381: =item *
                   1382: 
                   1383: 4th argument is to manually specify a sourceroot.
                   1384: 
                   1385: =item *
                   1386: 
                   1387: 5th argument is to manually specify a targetroot.
                   1388: 
                   1389: =back
                   1390: 
                   1391: Only the 1st argument is mandatory for the program to run.
                   1392: 
                   1393: Example:
                   1394: 
                   1395: cat ../../doc/loncapafiles.lpml |\\
                   1396: perl lpml_parse.pl html default /home/sherbert/loncapa /tmp/install
                   1397: 
                   1398: =head1 DESCRIPTION
                   1399: 
                   1400: I am using a multiple pass-through approach to parsing
                   1401: the lpml file.  This saves memory and makes sure the server
                   1402: will never be overloaded.
                   1403: 
                   1404: =head1 README
                   1405: 
                   1406: I am using a multiple pass-through approach to parsing
                   1407: the lpml file.  This saves memory and makes sure the server
                   1408: will never be overloaded.
                   1409: 
                   1410: =head1 PREREQUISITES
                   1411: 
                   1412: HTML::TokeParser
                   1413: 
                   1414: =head1 COREQUISITES
                   1415: 
                   1416: =head1 OSNAMES
                   1417: 
                   1418: linux
                   1419: 
                   1420: =head1 SCRIPT CATEGORIES
                   1421: 
                   1422: Packaging/Administrative
                   1423: 
                   1424: =cut

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