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

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

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