File:  [LON-CAPA] / loncom / build / lpml_parse.pl
Revision 1.26: download - view: text, annotated - select for diffs
Wed Dec 5 01:39:08 2001 UTC (22 years, 6 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
a significant step forward for implementing html mode

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

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