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

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

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