Annotation of loncom/build/lpml_parse.pl, revision 1.54
1.1 harris41 1: #!/usr/bin/perl
1.2 albertel 2:
1.43 harris41 3: # -------------------------------------------------------- Documentation notice
4: # Run "perldoc ./lpml_parse.pl" in order to best view the software
5: # documentation internalized in this program.
6:
1.45 harris41 7: # --------------------------------------------------------- Distribution notice
8: # This script is distributed with the LPML software project available at
9: # http://lpml.sourceforge.net
10:
1.43 harris41 11: # --------------------------------------------------------- License Information
1.28 harris41 12: # The LearningOnline Network with CAPA
13: # lpml_parse.pl - Linux Packaging Markup Language parser
14: #
1.54 ! raeburn 15: # $Id: lpml_parse.pl,v 1.53 2005/12/09 20:41:35 albertel Exp $
1.28 harris41 16: #
1.43 harris41 17: # Written by Scott Harrison, codeharrison@yahoo.com
1.28 harris41 18: #
19: # Copyright Michigan State University Board of Trustees
20: #
21: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
22: #
23: # LON-CAPA is free software; you can redistribute it and/or modify
24: # it under the terms of the GNU General Public License as published by
25: # the Free Software Foundation; either version 2 of the License, or
26: # (at your option) any later version.
27: #
28: # LON-CAPA is distributed in the hope that it will be useful,
29: # but WITHOUT ANY WARRANTY; without even the implied warranty of
30: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31: # GNU General Public License for more details.
32: #
33: # You should have received a copy of the GNU General Public License
34: # along with LON-CAPA; if not, write to the Free Software
35: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36: #
37: # /home/httpd/html/adm/gpl.txt
38: #
39: # http://www.lon-capa.org/
40: #
1.4 harris41 41: # YEAR=2001
1.2 albertel 42: # May 2001
1.3 harris41 43: # 06/19/2001,06/20,06/24 - Scott Harrison
1.5 harris41 44: # 9/5/2001,9/6,9/7,9/8 - Scott Harrison
1.14 harris41 45: # 9/17,9/18 - Scott Harrison
1.21 harris41 46: # 11/4,11/5,11/6,11/7,11/16,11/17 - Scott Harrison
1.35 harris41 47: # 12/2,12/3,12/4,12/5,12/6,12/13,12/19,12/29 - Scott Harrison
48: # YEAR=2002
1.45 harris41 49: # 1/8,1/9,1/29,1/31,2/5,3/21,4/8,4/12 - Scott Harrison
1.51 harris41 50: # 4/21,4/26,5/19,5/23,10/13 - Scott Harrison
1.43 harris41 51: #
1.18 harris41 52: ###
1.3 harris41 53:
1.4 harris41 54: ###############################################################################
55: ## ##
56: ## ORGANIZATION OF THIS PERL SCRIPT ##
57: ## 1. Notes ##
58: ## 2. Get command line arguments ##
59: ## 3. First pass through (grab distribution-specific information) ##
60: ## 4. Second pass through (parse out what is not necessary) ##
61: ## 5. Third pass through (translate markup according to specified mode) ##
1.14 harris41 62: ## 6. Functions (most all just format contents of different markup tags) ##
63: ## 7. POD (plain old documentation, CPAN style) ##
1.4 harris41 64: ## ##
65: ###############################################################################
66:
67: # ----------------------------------------------------------------------- Notes
68: #
1.3 harris41 69: # I am using a multiple pass-through approach to parsing
70: # the lpml file. This saves memory and makes sure the server
1.45 harris41 71: # will never be overloaded.
1.4 harris41 72: #
73: # This is meant to parse files meeting the lpml document type.
74: # See lpml.dtd. LPML=Linux Packaging Markup Language.
1.2 albertel 75:
1.1 harris41 76: use HTML::TokeParser;
1.2 albertel 77:
1.3 harris41 78: my $usage=<<END;
79: **** ERROR ERROR ERROR ERROR ****
80: Usage is for lpml file to come in through standard input.
1.45 harris41 81: 1st argument is the mode of parsing:
82: install,configinstall,build,rpm,dpkg,htmldoc,textdoc,status
83: 2nd argument is the category permissions to use:
84: typical choices: runtime,development
85: 3rd argument is the distribution:
86: typical choices: default,redhat6.2,debian2.2,redhat7
1.4 harris41 87: 4th argument is to manually specify a sourceroot.
88: 5th argument is to manually specify a targetroot.
1.3 harris41 89:
90: Only the 1st argument is mandatory for the program to run.
91:
92: Example:
93:
94: cat ../../doc/loncapafiles.lpml |\\
1.25 harris41 95: perl lpml_parse.pl html development default /home/sherbert/loncapa /tmp/install
1.45 harris41 96:
97: For more information, type "perldoc lpml_parse.pl".
1.3 harris41 98: END
99:
100: # ------------------------------------------------- Grab command line arguments
101:
1.43 harris41 102: my $mode='';
1.4 harris41 103: if (@ARGV==5) {
1.3 harris41 104: $mode = shift @ARGV;
105: }
106: else {
1.4 harris41 107: @ARGV=();shift @ARGV;
1.3 harris41 108: while(<>){} # throw away the input to avoid broken pipes
109: print $usage;
110: exit -1; # exit with error status
111: }
112:
1.43 harris41 113: my $categorytype='';
1.4 harris41 114: if (@ARGV) {
115: $categorytype = shift @ARGV;
116: }
117:
1.43 harris41 118: my $dist='';
1.3 harris41 119: if (@ARGV) {
120: $dist = shift @ARGV;
121: }
1.2 albertel 122:
1.43 harris41 123: my $targetroot='';
124: my $sourceroot='';
125: my $targetrootarg='';
126: my $sourcerootarg='';
1.3 harris41 127: if (@ARGV) {
1.4 harris41 128: $sourceroot = shift @ARGV;
1.3 harris41 129: }
130: if (@ARGV) {
1.4 harris41 131: $targetroot = shift @ARGV;
1.3 harris41 132: }
1.45 harris41 133: $sourceroot=~s/\/$//; # remove trailing directory slash
134: $targetroot=~s/\/$//; # remove trailing directory slash
1.27 harris41 135: $sourcerootarg=$sourceroot;
136: $targetrootarg=$targetroot;
1.3 harris41 137:
1.19 harris41 138: my $logcmd='| tee -a WARNINGS';
139:
1.45 harris41 140: my $invocation; # Record how the program was invoked
1.5 harris41 141: # --------------------------------------------------- Record program invocation
1.17 harris41 142: if ($mode eq 'install' or $mode eq 'configinstall' or $mode eq 'build') {
1.5 harris41 143: $invocation=(<<END);
144: # Invocation: STDINPUT | lpml_parse.pl
145: # 1st argument (mode) is: $mode
146: # 2nd argument (category type) is: $categorytype
147: # 3rd argument (distribution) is: $dist
1.36 harris41 148: # 4th argument (sourceroot) is: described below
149: # 5th argument (targetroot) is: described below
1.5 harris41 150: END
151: }
152:
1.45 harris41 153: # -------------------------- Start first pass through (just gather information)
154: my @parsecontents=<>;
155: my $parsestring=join('',@parsecontents);
1.2 albertel 156:
1.3 harris41 157: # Need to make a pass through and figure out what defaults are
1.45 harris41 158: # overrided. Top-down overriding strategy (tree leaves don't know
159: # about distant tree leaves).
1.3 harris41 160:
161: my @hierarchy;
162: $hierarchy[0]=0;
163: my $hloc=0;
164: my $token;
165: $parser = HTML::TokeParser->new(\$parsestring) or
166: die('can\'t create TokeParser object');
167: $parser->xml_mode('1');
1.45 harris41 168: my %setting;
169:
170: # Values for the %setting hash
171: my $defaultset=1; # a default setting exists for a key
172: my $distset=2; # a distribution setting exists for a key
173: # (overrides default setting)
174:
175: my $key=''; # this is a unique key identifier (the token name with its
176: # coordinates inside the hierarchy)
177: while ($token = $parser->get_token()) { # navigate through $parsestring
1.3 harris41 178: if ($token->[0] eq 'S') {
179: $hloc++;
180: $hierarchy[$hloc]++;
181: $key=$token->[1].join(',',@hierarchy[0..($hloc-1)]);
182: my $thisdist=' '.$token->[2]{'dist'}.' ';
183: if ($thisdist eq ' default ') {
1.45 harris41 184: $setting{$key}=$defaultset;
1.3 harris41 185: }
1.45 harris41 186: elsif (length($dist)>0 &&
187: $setting{$key}==$defaultset &&
188: $thisdist=~/\s$dist\s/) {
189: $setting{$key}=$distset;
190: # disregard default setting for this key if
191: # there is a directly requested distribution match
192: # (in other words, there must first be a default
193: # setting for a key in order for it to be overridden)
1.3 harris41 194: }
195: }
196: if ($token->[0] eq 'E') {
197: $hloc--;
198: }
199: }
200:
1.45 harris41 201: # - Start second pass through (clean up the string to allow for easy rendering)
202:
203: # The string is cleaned up so that there is no white-space surrounding any
204: # XML tag. White-space inside text 'T' elements is preserved.
205:
206: # Clear up memory
1.43 harris41 207: undef($hloc);
208: undef(@hierarchy);
209: undef($parser);
1.45 harris41 210: $hierarchy[0]=0; # initialize hierarchy
1.3 harris41 211: $parser = HTML::TokeParser->new(\$parsestring) or
212: die('can\'t create TokeParser object');
213: $parser->xml_mode('1');
1.45 harris41 214: my $cleanstring; # contains the output of the second step
215: while ($token = $parser->get_token()) { # navigate through $parsestring
216: if ($token->[0] eq 'S') { # a start tag
1.3 harris41 217: $hloc++;
218: $hierarchy[$hloc]++;
219: $key=$token->[1].join(',',@hierarchy[0..($hloc-1)]);
1.45 harris41 220:
221: # Surround tagdist (the dist attribute of an XML tag)
222: # with white-space to allow for uniform searching a few
223: # lines below here.
224: my $tagdist=' '.$token->[2]{'dist'}.' ';
225:
1.4 harris41 226: # This conditional clause is set up to ignore two sets
227: # of invalid conditions before accepting entry into
1.45 harris41 228: # $cleanstring.
229:
230: # Condition #1: Ignore this part of the string if the tag
231: # has a superior distribution-specific setting and the tag
232: # being evaluated has a dist setting something other than
233: # blank or $dist.
234: if ($setting{$key}==$distset and
235: !($tagdist eq ' ' or $tagdist =~/\s$dist\s/)) {
1.3 harris41 236: if ($token->[4]!~/\/>$/) {
237: $parser->get_tag('/'.$token->[1]);
238: $hloc--;
239: }
240: }
1.45 harris41 241: # Condition #2: Ignore this part of the string if the tag has
242: # is not blank and does not equal dist and
243: # either does not equal default or it has a prior $dist-specific
244: # setting.
245: elsif ($tagdist ne ' ' and $tagdist!~/\s$dist\s/ and
246: !($tagdist eq ' default ' and $setting{$key}!=$distset)) {
1.3 harris41 247: if ($token->[4]!~/\/>$/) {
248: $parser->get_tag('/'.$token->[1]);
249: $hloc--;
250: }
251: }
1.45 harris41 252: # In other words, output to $cleanstring if the tag is dist=default
253: # or if the tag is set to dist=$dist for the first time. And, always
254: # output when dist='' is not present.
1.3 harris41 255: else {
256: $cleanstring.=$token->[4];
257: }
258: }
1.45 harris41 259: # Note: this loop DOES work with <tag /> style markup as well as
260: # <tag></tag> style markup since I always check for $token->[4] ending
261: # with "/>".
262: if ($token->[0] eq 'E') { # an end tag
1.3 harris41 263: $cleanstring.=$token->[2];
264: $hloc--;
265: }
1.45 harris41 266: if ($token->[0] eq 'T') { # text contents inside tags
1.3 harris41 267: $cleanstring.=$token->[1];
268: }
269: }
270: $cleanstring=&trim($cleanstring);
1.10 harris41 271: $cleanstring=~s/\>\s*\n\s*\</\>\</g;
272:
1.45 harris41 273: # -------------------------------------------- Start final (third) pass through
1.3 harris41 274:
275: # storage variables
276: my $lpml;
277: my $categories;
1.29 harris41 278: my @categorynamelist;
1.3 harris41 279: my $category;
280: my $category_att_name;
281: my $category_att_type;
282: my $chown;
283: my $chmod;
1.25 harris41 284: my $abbreviation; # space-free abbreviation; esp. for image names
1.3 harris41 285: my $rpm;
286: my $rpmSummary;
287: my $rpmName;
288: my $rpmVersion;
289: my $rpmRelease;
290: my $rpmVendor;
291: my $rpmBuildRoot;
292: my $rpmCopyright;
293: my $rpmGroup;
294: my $rpmSource;
295: my $rpmAutoReqProv;
296: my $rpmdescription;
297: my $rpmpre;
298: my $directories;
299: my $directory;
300: my $targetdirs;
301: my $targetdir;
1.51 harris41 302: my $protectionlevel;
1.3 harris41 303: my $categoryname;
304: my $description;
305: my $files;
306: my $fileglobs;
307: my $links;
308: my $file;
309: my $link;
310: my $fileglob;
311: my $sourcedir;
312: my $targets;
313: my $target;
314: my $source;
315: my $note;
1.53 albertel 316: my $installscript;
1.3 harris41 317: my $build;
1.14 harris41 318: my $buildlink;
1.3 harris41 319: my $commands;
320: my $command;
321: my $status;
322: my $dependencies;
323: my $dependency;
1.4 harris41 324: my @links;
325: my %categoryhash;
1.26 harris41 326: my $dpathlength;
327: my %fab; # file category abbreviation
1.29 harris41 328: my $directory_count;
329: my $file_count;
330: my $link_count;
331: my $fileglob_count;
332: my $fileglobnames_count;
333: my %categorycount;
1.3 harris41 334:
1.11 harris41 335: my @buildall;
1.12 harris41 336: my @buildinfo;
337:
338: my @configall;
1.11 harris41 339:
1.3 harris41 340: # Make new parser with distribution specific input
341: undef $parser;
342: $parser = HTML::TokeParser->new(\$cleanstring) or
343: die('can\'t create TokeParser object');
344: $parser->xml_mode('1');
345:
346: # Define handling methods for mode-dependent text rendering
1.26 harris41 347:
1.3 harris41 348: $parser->{textify}={
1.31 harris41 349: specialnotices => \&format_specialnotices,
350: specialnotice => \&format_specialnotice,
1.3 harris41 351: targetroot => \&format_targetroot,
352: sourceroot => \&format_sourceroot,
353: categories => \&format_categories,
354: category => \&format_category,
1.25 harris41 355: abbreviation => \&format_abbreviation,
1.3 harris41 356: targetdir => \&format_targetdir,
1.51 harris41 357: protectionlevel => \&format_protectionlevel,
1.3 harris41 358: chown => \&format_chown,
359: chmod => \&format_chmod,
360: rpm => \&format_rpm,
361: rpmSummary => \&format_rpmSummary,
362: rpmName => \&format_rpmName,
363: rpmVersion => \&format_rpmVersion,
364: rpmRelease => \&format_rpmRelease,
365: rpmVendor => \&format_rpmVendor,
366: rpmBuildRoot => \&format_rpmBuildRoot,
367: rpmCopyright => \&format_rpmCopyright,
368: rpmGroup => \&format_rpmGroup,
369: rpmSource => \&format_rpmSource,
370: rpmAutoReqProv => \&format_rpmAutoReqProv,
371: rpmdescription => \&format_rpmdescription,
372: rpmpre => \&format_rpmpre,
1.35 harris41 373: rpmRequires => \&format_rpmRequires,
1.3 harris41 374: directories => \&format_directories,
375: directory => \&format_directory,
376: categoryname => \&format_categoryname,
377: description => \&format_description,
378: files => \&format_files,
379: file => \&format_file,
380: fileglob => \&format_fileglob,
1.4 harris41 381: links => \&format_links,
1.3 harris41 382: link => \&format_link,
383: linkto => \&format_linkto,
384: source => \&format_source,
385: target => \&format_target,
386: note => \&format_note,
387: build => \&format_build,
1.53 albertel 388: installscript => \&format_installscript,
1.3 harris41 389: status => \&format_status,
390: dependencies => \&format_dependencies,
1.52 albertel 391: privatedependencies => \&format_privatedependencies,
1.14 harris41 392: buildlink => \&format_buildlink,
1.3 harris41 393: glob => \&format_glob,
394: sourcedir => \&format_sourcedir,
395: filenames => \&format_filenames,
396: };
397:
398: my $text;
399: my $token;
400: undef $hloc;
401: undef @hierarchy;
402: my $hloc;
403: my @hierarchy2;
404: while ($token = $parser->get_tag('lpml')) {
405: &format_lpml(@{$token});
406: $text = &trim($parser->get_text('/lpml'));
407: $token = $parser->get_tag('/lpml');
408: print $lpml;
409: print "\n";
1.4 harris41 410: # $text=~s/\s*\n\s*\n\s*/\n/g;
1.3 harris41 411: print $text;
412: print "\n";
413: print &end();
414: }
415: exit;
416:
1.14 harris41 417: # ---------- Functions (most all just format contents of different markup tags)
418:
419: # ------------------------ Final output at end of markup parsing and formatting
1.3 harris41 420: sub end {
421: if ($mode eq 'html') {
1.29 harris41 422: return "<br /> <br />".
423: "<a name='summary' /><font size='+2'>Summary of Source Repository".
424: "</font>".
425: "<br /> <br />".
426: "<table border='1' cellpadding='5'>".
427: "<caption>Files, Directories, and Symbolic Links</caption>".
428: "<tr><td>Files (not referenced by globs)</td><td>$file_count</td>".
429: "</tr>".
430: "<tr><td>Files (referenced by globs)</td>".
431: "<td>$fileglobnames_count</td>".
432: "</tr>".
433: "<tr><td>Total Files</td>".
434: "<td>".($fileglobnames_count+$file_count)."</td>".
435: "</tr>".
436: "<tr><td>File globs</td>".
437: "<td>".$fileglob_count."</td>".
438: "</tr>".
439: "<tr><td>Directories</td>".
440: "<td>".$directory_count."</td>".
441: "</tr>".
442: "<tr><td>Symbolic links</td>".
443: "<td>".$link_count."</td>".
444: "</tr>".
445: "</table>".
446: "<table border='1' cellpadding='5'>".
447: "<caption>File Category Count</caption>".
448: "<tr><th>Icon</th><th>Name</th><th>Number of Occurrences</th>".
1.32 harris41 449: "<th>Number of Incorrect Counts</th>".
450: "</tr>".
1.29 harris41 451: join("\n",(map {"<tr><td><img src='$fab{$_}.gif' ".
452: "alt='$_ icon' /></td>".
1.32 harris41 453: "<td>$_</td><td>$categorycount{$_}</td>".
454: "<td><!-- POSTEVALINLINE $_ --></td></tr>"}
1.29 harris41 455: @categorynamelist)).
456: "</table>".
457: "</body></html>\n";
458:
1.3 harris41 459: }
1.4 harris41 460: if ($mode eq 'install') {
461: return '';
462: }
1.3 harris41 463: }
464:
465: # ----------------------- Take in string to parse and the separation expression
466: sub extract_array {
467: my ($stringtoparse,$sepexp) = @_;
468: my @a=split(/$sepexp/,$stringtoparse);
469: return \@a;
470: }
471:
472: # --------------------------------------------------------- Format lpml section
473: sub format_lpml {
474: my (@tokeninfo)=@_;
475: my $date=`date`; chop $date;
476: if ($mode eq 'html') {
1.24 harris41 477: $lpml=<<END;
478: <html>
479: <head>
1.25 harris41 480: <title>LPML Description Page
481: (dist=$dist, categorytype=$categorytype, $date)</title>
1.24 harris41 482: </head>
483: <body>
484: END
485: $lpml .= "<br /><font size='+2'>LPML Description Page (dist=$dist, ".
1.25 harris41 486: "categorytype=$categorytype, $date)".
1.23 harris41 487: "</font>";
488: $lpml .=<<END;
489: <ul>
1.24 harris41 490: <li><a href='#about'>About this file</a></li>
491: <li><a href='#ownperms'>File Type Ownership and Permissions
492: Descriptions</a></li>
493: <li><a href='#package'>Software Package Description</a></li>
494: <li><a href='#directories'>Directory Structure</a></li>
1.26 harris41 495: <li><a href='#files'>Files</a></li>
1.29 harris41 496: <li><a href='#summary'>Summary of Source Repository</a></li>
1.23 harris41 497: </ul>
498: END
499: $lpml .=<<END;
1.24 harris41 500: <br /> <br /><a name='about' />
1.23 harris41 501: <font size='+2'>About this file</font>
502: <p>
503: This file is generated dynamically by <tt>lpml_parse.pl</tt> as
1.28 harris41 504: part of a development compilation process.</p>
505: <p>LPML written by Scott Harrison (harris41\@msu.edu).
1.23 harris41 506: </p>
507: END
508: }
509: elsif ($mode eq 'text') {
510: $lpml = "LPML Description Page (dist=$dist, $date)";
511: $lpml .=<<END;
512:
513: * About this file
514: * Software Package Description
515: * Directory Structure
516: * File Type Ownership and Permissions
1.26 harris41 517: * Files
1.23 harris41 518: END
519: $lpml .=<<END;
520:
521: About this file
522:
523: This file is generated dynamically by lpml_parse.pl as
524: part of a development compilation process. Author: Scott
525: Harrison (harris41\@msu.edu).
526:
527: END
1.3 harris41 528: }
1.4 harris41 529: elsif ($mode eq 'install') {
530: print '# LPML install targets. Linux Packaging Markup Language,';
531: print ' by Scott Harrison 2001'."\n";
532: print '# This file was automatically generated on '.`date`;
1.5 harris41 533: print "\n".$invocation;
1.54 ! raeburn 534: $lpml .= "\n";
1.4 harris41 535: }
1.16 harris41 536: elsif ($mode eq 'configinstall') {
1.17 harris41 537: print '# LPML configuration file targets (configinstall).'."\n";
538: print '# Linux Packaging Markup Language,';
1.16 harris41 539: print ' by Scott Harrison 2001'."\n";
540: print '# This file was automatically generated on '.`date`;
541: print "\n".$invocation;
1.54 ! raeburn 542: $lpml .= "\n";
1.16 harris41 543: }
1.11 harris41 544: elsif ($mode eq 'build') {
1.14 harris41 545: $lpml = "# LPML build targets. Linux Packaging Markup Language,";
546: $lpml .= ' by Scott Harrison 2001'."\n";
1.11 harris41 547: $lpml .= '# This file was automatically generated on '.`date`;
1.17 harris41 548: $lpml .= "\n".$invocation;
1.54 ! raeburn 549: $lpml .= "\n";
1.11 harris41 550: }
1.4 harris41 551: else {
552: return '';
553: }
1.3 harris41 554: }
555: # --------------------------------------------------- Format targetroot section
556: sub format_targetroot {
557: my $text=&trim($parser->get_text('/targetroot'));
558: $text=$targetroot if $targetroot;
559: $parser->get_tag('/targetroot');
560: if ($mode eq 'html') {
1.10 harris41 561: return $targetroot="\n<br />TARGETROOT: $text";
1.3 harris41 562: }
1.17 harris41 563: elsif ($mode eq 'install' or $mode eq 'build' or
564: $mode eq 'configinstall') {
1.11 harris41 565: return '# TARGET INSTALL LOCATION is "'.$targetroot."\"\n";
566: }
1.3 harris41 567: else {
568: return '';
569: }
570: }
571: # --------------------------------------------------- Format sourceroot section
572: sub format_sourceroot {
573: my $text=&trim($parser->get_text('/sourceroot'));
574: $text=$sourceroot if $sourceroot;
575: $parser->get_tag('/sourceroot');
576: if ($mode eq 'html') {
1.10 harris41 577: return $sourceroot="\n<br />SOURCEROOT: $text";
1.3 harris41 578: }
1.17 harris41 579: elsif ($mode eq 'install' or $mode eq 'build' or
580: $mode eq 'configinstall') {
1.11 harris41 581: return '# SOURCE CODE LOCATION IS "'.$sourceroot."\"\n";;
582: }
1.3 harris41 583: else {
584: return '';
585: }
586: }
587: # --------------------------------------------------- Format categories section
588: sub format_categories {
589: my $text=&trim($parser->get_text('/categories'));
590: $parser->get_tag('/categories');
591: if ($mode eq 'html') {
1.24 harris41 592: return $categories="\n<br /> <br />".
593: "\n<a name='ownperms'>".
594: "\n<font size='+2'>File Type Ownership and Permissions".
595: " Descriptions</font>".
1.25 harris41 596: "\n<p>This table shows what permissions and ownership settings ".
597: "correspond to each category.</p>".
598: "\n<table border='1' cellpadding='5' width='60%'>\n".
599: "<tr>".
600: "<th align='left' bgcolor='#ffffff'>Icon</th>".
601: "<th align='left' bgcolor='#ffffff'>Category Name</th>".
602: "<th align='left' bgcolor='#ffffff'>Permissions ".
603: "($categorytype)</th>".
604: "</tr>".
605: "\n$text\n".
1.24 harris41 606: "</table>\n";
607: }
608: elsif ($mode eq 'text') {
609: return $categories="\n".
610: "\nFile Type Ownership and Permissions".
611: " Descriptions".
1.25 harris41 612: "\n$text".
1.24 harris41 613: "\n";
1.3 harris41 614: }
615: else {
616: return '';
617: }
618: }
619: # --------------------------------------------------- Format categories section
620: sub format_category {
621: my (@tokeninfo)=@_;
622: $category_att_name=$tokeninfo[2]->{'name'};
623: $category_att_type=$tokeninfo[2]->{'type'};
1.25 harris41 624: $abbreviation=''; $chmod='';$chown='';
1.3 harris41 625: $parser->get_text('/category');
626: $parser->get_tag('/category');
1.26 harris41 627: $fab{$category_att_name}=$abbreviation;
1.3 harris41 628: if ($mode eq 'html') {
1.25 harris41 629: if ($category_att_type eq $categorytype) {
1.29 harris41 630: push @categorynamelist,$category_att_name;
1.27 harris41 631: $categoryhash{$category_att_name}="$chmod $chown";
1.25 harris41 632: return $category="<tr>".
633: "<td><img src='$abbreviation.gif' ".
634: "alt='${category_att_name}' /></td>\n".
635: "<td>${category_att_name}</td>\n".
636: "<td>$chmod $chown</td>\n".
637: "</tr>".
638: "\n";
639: # return $category="\n<br />CATEGORY $category_att_name ".
640: # "$category_att_type $chmod $chown";
641: }
1.3 harris41 642: }
643: else {
1.4 harris41 644: if ($category_att_type eq $categorytype) {
645: my ($user,$group)=split(/\:/,$chown);
646: $categoryhash{$category_att_name}='-o '.$user.' -g '.$group.
647: ' -m '.$chmod;
1.53 albertel 648: $categoryhash{"chmod.".$category_att_name}=$chmod;
649: $categoryhash{"chown.".$category_att_name}=$chown;
1.4 harris41 650: }
1.3 harris41 651: return '';
652: }
653: }
1.25 harris41 654: # --------------------------------------------------- Format categories section
655: sub format_abbreviation {
656: my @tokeninfo=@_;
657: $abbreviation='';
658: my $text=&trim($parser->get_text('/abbreviation'));
659: if ($text) {
660: $parser->get_tag('/abbreviation');
661: $abbreviation=$text;
662: }
663: return '';
664: }
1.3 harris41 665: # -------------------------------------------------------- Format chown section
666: sub format_chown {
667: my @tokeninfo=@_;
668: $chown='';
669: my $text=&trim($parser->get_text('/chown'));
670: if ($text) {
671: $parser->get_tag('/chown');
672: $chown=$text;
673: }
674: return '';
675: }
676: # -------------------------------------------------------- Format chmod section
677: sub format_chmod {
678: my @tokeninfo=@_;
679: $chmod='';
680: my $text=&trim($parser->get_text('/chmod'));
681: if ($text) {
682: $parser->get_tag('/chmod');
683: $chmod=$text;
684: }
685: return '';
686: }
687: # ---------------------------------------------------------- Format rpm section
688: sub format_rpm {
689: my $text=&trim($parser->get_text('/rpm'));
690: $parser->get_tag('/rpm');
691: if ($mode eq 'html') {
1.23 harris41 692: return $rpm=<<END;
1.24 harris41 693: <br /> <br />
694: <a name='package' />
1.23 harris41 695: <font size='+2'>Software Package Description</font>
696: <p>
697: <table bgcolor='#ffffff' border='0' cellpadding='10' cellspacing='0'>
698: <tr><td><pre>
699: $text
700: </pre></td></tr>
701: </table>
702: END
703: }
1.35 harris41 704: elsif ($mode eq 'make_rpm') {
705: return $text;
706: }
1.23 harris41 707: elsif ($mode eq 'text') {
708: return $rpm=<<END;
709: Software Package Description
710:
711: $text
712: END
1.3 harris41 713: }
714: else {
715: return '';
716: }
717: }
718: # --------------------------------------------------- Format rpmSummary section
719: sub format_rpmSummary {
720: my $text=&trim($parser->get_text('/rpmSummary'));
721: $parser->get_tag('/rpmSummary');
722: if ($mode eq 'html') {
1.23 harris41 723: return $rpmSummary="\nSummary : $text";
724: }
725: elsif ($mode eq 'text') {
726: return $rpmSummary="\nSummary : $text";
1.3 harris41 727: }
1.35 harris41 728: elsif ($mode eq 'make_rpm') {
729: return <<END;
730: <summary>$text</summary>
731: END
732: }
1.3 harris41 733: else {
734: return '';
735: }
736: }
737: # ------------------------------------------------------ Format rpmName section
738: sub format_rpmName {
739: my $text=&trim($parser->get_text('/rpmName'));
740: $parser->get_tag('/rpmName');
741: if ($mode eq 'html') {
1.24 harris41 742: return $rpmName="\nName : $text";
743: }
744: elsif ($mode eq 'text') {
745: return $rpmName="\nName : $text";
1.3 harris41 746: }
1.35 harris41 747: elsif ($mode eq 'make_rpm') {
748: return <<END;
749: <name>$text</name>
750: END
751: }
1.3 harris41 752: else {
753: return '';
754: }
755: }
756: # --------------------------------------------------- Format rpmVersion section
757: sub format_rpmVersion {
758: my $text=$parser->get_text('/rpmVersion');
759: $parser->get_tag('/rpmVersion');
760: if ($mode eq 'html') {
1.24 harris41 761: return $rpmVersion="\nVersion : $text";
762: }
763: elsif ($mode eq 'text') {
764: return $rpmVersion="\nVersion : $text";
1.3 harris41 765: }
766: else {
767: return '';
768: }
769: }
770: # --------------------------------------------------- Format rpmRelease section
771: sub format_rpmRelease {
772: my $text=$parser->get_text('/rpmRelease');
773: $parser->get_tag('/rpmRelease');
774: if ($mode eq 'html') {
1.24 harris41 775: return $rpmRelease="\nRelease : $text";
776: }
777: elsif ($mode eq 'text') {
778: return $rpmRelease="\nRelease : $text";
1.3 harris41 779: }
780: else {
781: return '';
782: }
783: }
784: # ---------------------------------------------------- Format rpmVendor section
785: sub format_rpmVendor {
786: my $text=$parser->get_text('/rpmVendor');
787: $parser->get_tag('/rpmVendor');
788: if ($mode eq 'html') {
1.24 harris41 789: return $rpmVendor="\nVendor : $text";
790: }
791: elsif ($mode eq 'text') {
792: return $rpmVendor="\nVendor : $text";
1.3 harris41 793: }
1.35 harris41 794: elsif ($mode eq 'make_rpm') {
795: return <<END;
796: <vendor>$text</vendor>
797: END
798: }
1.3 harris41 799: else {
800: return '';
801: }
802: }
803: # ------------------------------------------------- Format rpmBuildRoot section
804: sub format_rpmBuildRoot {
805: my $text=$parser->get_text('/rpmBuildRoot');
806: $parser->get_tag('/rpmBuildRoot');
807: if ($mode eq 'html') {
1.24 harris41 808: return $rpmBuildRoot="\nBuild Root : $text";
809: }
810: elsif ($mode eq 'text') {
811: return $rpmBuildRoot="\nBuild Root : $text";
1.3 harris41 812: }
813: else {
814: return '';
815: }
816: }
817: # ------------------------------------------------- Format rpmCopyright section
818: sub format_rpmCopyright {
819: my $text=$parser->get_text('/rpmCopyright');
820: $parser->get_tag('/rpmCopyright');
821: if ($mode eq 'html') {
1.24 harris41 822: return $rpmCopyright="\nLicense : $text";
823: }
824: elsif ($mode eq 'text') {
825: return $rpmCopyright="\nLicense : $text";
1.3 harris41 826: }
1.35 harris41 827: elsif ($mode eq 'make_rpm') {
828: return <<END;
829: <copyright>$text</copyright>
830: END
831: }
1.3 harris41 832: else {
833: return '';
834: }
835: }
836: # ----------------------------------------------------- Format rpmGroup section
837: sub format_rpmGroup {
838: my $text=$parser->get_text('/rpmGroup');
839: $parser->get_tag('/rpmGroup');
840: if ($mode eq 'html') {
1.24 harris41 841: return $rpmGroup="\nGroup : $text";
842: }
843: elsif ($mode eq 'text') {
844: return $rpmGroup="\nGroup : $text";
1.3 harris41 845: }
1.35 harris41 846: elsif ($mode eq 'make_rpm') {
847: return <<END;
848: <group>Utilities/System</group>
849: END
850: }
1.3 harris41 851: else {
852: return '';
853: }
854: }
855: # ---------------------------------------------------- Format rpmSource section
856: sub format_rpmSource {
857: my $text=$parser->get_text('/rpmSource');
858: $parser->get_tag('/rpmSource');
859: if ($mode eq 'html') {
1.24 harris41 860: return $rpmSource="\nSource : $text";
861: }
862: elsif ($mode eq 'text') {
863: return $rpmSource="\nSource : $text";
1.3 harris41 864: }
865: else {
866: return '';
867: }
868: }
869: # ----------------------------------------------- Format rpmAutoReqProv section
870: sub format_rpmAutoReqProv {
871: my $text=$parser->get_text('/rpmAutoReqProv');
872: $parser->get_tag('/rpmAutoReqProv');
873: if ($mode eq 'html') {
1.24 harris41 874: return $rpmAutoReqProv="\nAutoReqProv : $text";
875: }
1.35 harris41 876: elsif ($mode eq 'text') {
1.24 harris41 877: return $rpmAutoReqProv="\nAutoReqProv : $text";
1.3 harris41 878: }
1.35 harris41 879: elsif ($mode eq 'make_rpm') {
880: return <<END;
881: <AutoReqProv>$text</AutoReqProv>
882: END
883: }
1.3 harris41 884: else {
885: return '';
886: }
887: }
888: # ----------------------------------------------- Format rpmdescription section
889: sub format_rpmdescription {
890: my $text=$parser->get_text('/rpmdescription');
891: $parser->get_tag('/rpmdescription');
892: if ($mode eq 'html') {
1.25 harris41 893: $text=~s/\n//g;
894: $text=~s/\\n/\n/g;
1.24 harris41 895: return $rpmdescription="\nDescription : $text";
896: }
897: elsif ($mode eq 'text') {
1.25 harris41 898: $text=~s/\n//g;
899: $text=~s/\\n/\n/g;
1.24 harris41 900: return $rpmdescription="\nDescription : $text";
1.3 harris41 901: }
1.35 harris41 902: elsif ($mode eq 'make_rpm') {
903: $text=~s/\n//g;
904: $text=~s/\\n/\n/g;
905: return <<END;
906: <description>$text</description>
907: END
908: }
1.3 harris41 909: else {
910: return '';
911: }
912: }
913: # ------------------------------------------------------- Format rpmpre section
914: sub format_rpmpre {
915: my $text=$parser->get_text('/rpmpre');
916: $parser->get_tag('/rpmpre');
917: if ($mode eq 'html') {
1.24 harris41 918: # return $rpmpre="\n<br />RPMPRE $text";
919: return '';
1.3 harris41 920: }
1.35 harris41 921: elsif ($mode eq 'make_rpm') {
922: return <<END;
923: <pre>$text</pre>
924: END
925: }
1.3 harris41 926: else {
927: return '';
928: }
929: }
1.35 harris41 930: # -------------------------------------------------- Format requires section
931: sub format_rpmRequires {
932: my @tokeninfo=@_;
933: my $aref;
934: my $text;
935: if ($mode eq 'make_rpm') {
936: while ($aref=$parser->get_token()) {
937: if ($aref->[0] eq 'E' && $aref->[1] eq 'rpmRequires') {
938: last;
939: }
940: elsif ($aref->[0] eq 'S') {
941: $text.=$aref->[4];
942: }
943: elsif ($aref->[0] eq 'E') {
944: $text.=$aref->[2];
945: }
946: else {
947: $text.=$aref->[1];
948: }
949: }
950: }
951: else {
952: $parser->get_tag('/rpmRequires');
953: return '';
954: }
955: return '<rpmRequires>'.$text.'</rpmRequires>';
956: }
1.3 harris41 957: # -------------------------------------------------- Format directories section
958: sub format_directories {
1.4 harris41 959: my $text=$parser->get_text('/directories');
1.3 harris41 960: $parser->get_tag('/directories');
961: if ($mode eq 'html') {
1.26 harris41 962: $text=~s/\[\{\{\{\{\{DPATHLENGTH\}\}\}\}\}\]/$dpathlength/g;
1.24 harris41 963: return $directories="\n<br /> <br />".
964: "<a name='directories' />".
965: "<font size='+2'>Directory Structure</font>".
1.26 harris41 966: "\n<br /> <br />".
967: "<table border='1' cellpadding='3' cellspacing='0'>\n".
968: "<tr><th bgcolor='#ffffff'>Category</th>".
969: "<th bgcolor='#ffffff'>Status</th>\n".
970: "<th bgcolor='#ffffff'>Expected Permissions & Ownership</th>\n".
971: "<th bgcolor='#ffffff' colspan='$dpathlength'>Target Directory ".
972: "Path</th></tr>\n".
973: "\n$text\n</table><br />"."\n";
1.24 harris41 974: }
975: elsif ($mode eq 'text') {
976: return $directories="\nDirectory Structure\n$text\n".
977: "\n";
1.3 harris41 978: }
1.4 harris41 979: elsif ($mode eq 'install') {
980: return "\n".'directories:'."\n".$text;
1.35 harris41 981: }
982: elsif ($mode eq 'rpm_file_list') {
983: return $text;
984: }
1.51 harris41 985: elsif ($mode eq 'uninstall_shell_commands') {
986: return $text;
987: }
1.3 harris41 988: else {
989: return '';
990: }
991: }
992: # ---------------------------------------------------- Format directory section
993: sub format_directory {
994: my (@tokeninfo)=@_;
1.51 harris41 995: $targetdir='';$categoryname='';$description='';$protectionlevel='';
1.3 harris41 996: $parser->get_text('/directory');
997: $parser->get_tag('/directory');
1.29 harris41 998: $directory_count++;
999: $categorycount{$categoryname}++;
1.3 harris41 1000: if ($mode eq 'html') {
1.26 harris41 1001: my @a;
1002: @a=($targetdir=~/\//g);
1003: my $d=scalar(@a)+1;
1004: $dpathlength=$d if $d>$dpathlength;
1005: my $thtml=$targetdir;
1006: $thtml=~s/\//\<\/td\>\<td bgcolor='#ffffff'\>/g;
1.28 harris41 1007: my ($chmod,$chown)=split(/\s/,$categoryhash{$categoryname});
1.26 harris41 1008: return $directory="\n<tr><td rowspan='2' bgcolor='#ffffff'>".
1009: "$categoryname</td>".
1.41 harris41 1010: "<td rowspan='2' bgcolor='#ffffff'><!-- POSTEVAL [$categoryname] ".
1011: "verify.pl directory /$targetdir $categoryhash{$categoryname} -->".
1012: " </td>".
1.26 harris41 1013: "<td rowspan='2' bgcolor='#ffffff'>$chmod<br />$chown</td>".
1014: "<td bgcolor='#ffffff'>$thtml</td></tr>".
1015: "<tr><td bgcolor='#ffffff' colspan='[{{{{{DPATHLENGTH}}}}}]'>".
1016: "$description</td></tr>";
1017: }
1018: if ($mode eq 'text') {
1019: return $directory="\nDIRECTORY $targetdir $categoryname ".
1.10 harris41 1020: "$description";
1.3 harris41 1021: }
1.4 harris41 1022: elsif ($mode eq 'install') {
1.8 harris41 1023: return "\t".'install '.$categoryhash{$categoryname}.' -d '.
1024: $targetroot.'/'.$targetdir."\n";
1.4 harris41 1025: }
1.35 harris41 1026: elsif ($mode eq 'rpm_file_list') {
1027: return $targetroot.'/'.$targetdir."\n";
1028: }
1.51 harris41 1029: elsif ($mode eq 'uninstall_shell_commands') {
1030: if ($protectionlevel eq 'never_delete') {
1031: return 'echo "LEAVING BEHIND '.$targetroot.'/'.$targetdir.
1032: ' which may have important data worth saving"'."\n";
1033: }
1034: elsif ($protectionlevel eq 'weak_delete') {
1035: if ($targetdir!~/\w/) {
1036: die("targetdir=\"$targetdir\"! NEVER EVER DELETE THE WHOLE ".
1037: "FILESYSTEM"."\n");
1038: }
1039: return 'rm -Rvf -i '.$targetroot.'/'.$targetdir."\n";
1040: }
1041: elsif ($protectionlevel =~ /never/) {
1042: die("CONFUSING PROTECTION LEVEL \"$protectionlevel\" FOUND ".
1043: "FOR directory $targetdir"."\n");
1044: }
1045: elsif ($protectionlevel !~
1046: /^never_delete|weak_delete|modest_delete|strong_delete|absolute_delete$/) {
1047: die("CONFUSING OR MISSING PROTECTION LEVEL \"$protectionlevel\" ".
1048: "FOUND FOR directory $targetdir\n");
1049: }
1050: else {
1051: if ($targetdir!~/\w/) {
1052: die("targetdir=\"$targetdir\"! NEVER EVER DELETE THE WHOLE ".
1053: "FILESYSTEM"."\n");
1054: }
1055: return 'rm -Rvf '.$targetroot.'/'.$targetdir.
1056: "| grep 'removed directory'"."\n";
1057: }
1058: }
1.3 harris41 1059: else {
1060: return '';
1061: }
1062: }
1063: # ---------------------------------------------------- Format targetdir section
1064: sub format_targetdir {
1065: my @tokeninfo=@_;
1066: $targetdir='';
1067: my $text=&trim($parser->get_text('/targetdir'));
1068: if ($text) {
1069: $parser->get_tag('/targetdir');
1070: $targetdir=$text;
1.51 harris41 1071: }
1072: return '';
1073: }
1074: # ---------------------------------------------- Format protectionlevel section
1075: sub format_protectionlevel {
1076: my @tokeninfo=@_;
1077: $protectionlevel='';
1078: my $text=&trim($parser->get_text('/protectionlevel'));
1079: if ($text) {
1080: $parser->get_tag('/protectionlevel');
1081: $protectionlevel=$text;
1.3 harris41 1082: }
1083: return '';
1084: }
1085: # ------------------------------------------------- Format categoryname section
1086: sub format_categoryname {
1087: my @tokeninfo=@_;
1088: $categoryname='';
1089: my $text=&trim($parser->get_text('/categoryname'));
1090: if ($text) {
1091: $parser->get_tag('/categoryname');
1092: $categoryname=$text;
1093: }
1094: return '';
1095: }
1096: # -------------------------------------------------- Format description section
1097: sub format_description {
1098: my @tokeninfo=@_;
1099: $description='';
1.10 harris41 1100: my $text=&htmlsafe(&trim($parser->get_text('/description')));
1.3 harris41 1101: if ($text) {
1102: $parser->get_tag('/description');
1103: $description=$text;
1104: }
1105: return '';
1106: }
1107: # -------------------------------------------------------- Format files section
1108: sub format_files {
1.4 harris41 1109: my $text=$parser->get_text('/files');
1.3 harris41 1110: $parser->get_tag('/files');
1.46 harris41 1111: if ($mode eq 'MANIFEST') {
1112: return $text;
1113: }
1114: elsif ($mode eq 'html') {
1.24 harris41 1115: return $directories="\n<br /> <br />".
1116: "<a name='files' />".
1.26 harris41 1117: "<font size='+2'>Files</font><br /> <br />".
1118: "<p>All source and target locations are relative to the ".
1119: "sourceroot and targetroot values at the beginning of this ".
1120: "document.</p>".
1121: "\n<table border='1' cellpadding='5'>".
1122: "<tr><th>Status</th><th colspan='2'>Category</th>".
1123: "<th>Name/Location</th>".
1124: "<th>Description</th><th>Notes</th></tr>".
1125: "$text</table>\n".
1.24 harris41 1126: "\n";
1127: }
1128: elsif ($mode eq 'text') {
1129: return $directories="\n".
1130: "File and Directory Structure".
1131: "\n$text\n".
1132: "\n";
1.3 harris41 1133: }
1.4 harris41 1134: elsif ($mode eq 'install') {
1135: return "\n".'files:'."\n".$text.
1136: "\n".'links:'."\n".join('',@links);
1137: }
1.12 harris41 1138: elsif ($mode eq 'configinstall') {
1139: return "\n".'configfiles: '.
1140: join(' ',@configall).
1.14 harris41 1141: "\n\n".$text.
1142: "\n\nalwaysrun:\n\n";
1.12 harris41 1143: }
1.11 harris41 1144: elsif ($mode eq 'build') {
1145: my $binfo;
1146: my $tword;
1147: my $command2;
1148: my @deps;
1149: foreach my $bi (@buildinfo) {
1.14 harris41 1150: my ($target,$source,$command,$trigger,@deps)=split(/\;/,$bi);
1.11 harris41 1151: $tword=''; $tword=' alwaysrun' if $trigger eq 'always run';
1.33 harris41 1152: if ($command!~/\s/) {
1153: $command=~s/\/([^\/]*)$//;
1154: $command2="cd $command; sh ./$1;\\";
1155: }
1156: else {
1157: $command=~s/(.*?\/)([^\/]+\s+.*)$/$1/;
1158: $command2="cd $command; sh ./$2;\\";
1159: }
1.11 harris41 1160: my $depstring;
1.14 harris41 1161: my $depstring2="\t\t\@echo '';\\\n";
1162: my $olddep;
1.11 harris41 1163: foreach my $dep (@deps) {
1.14 harris41 1164: unless ($olddep) {
1165: $olddep=$deps[$#deps];
1166: }
1.11 harris41 1167: $depstring.="\telif !(test -r $command/$dep);\\\n";
1168: $depstring.="\t\tthen echo ".
1.14 harris41 1169: "\"**** WARNING **** missing the file: ".
1.19 harris41 1170: "$command/$dep\"$logcmd;\\\n";
1.14 harris41 1171: $depstring.="\t\ttest -e $source || test -e $target || echo ".
1172: "'**** ERROR **** neither source=$source nor target=".
1.19 harris41 1173: "$target exist and they cannot be built'$logcmd;\\\n";
1.14 harris41 1174: $depstring.="\t\tmake -f Makefile.build ${source}___DEPS;\\\n";
1175: if ($olddep) {
1176: $depstring2.="\t\tECODE=0;\\\n";
1177: $depstring2.="\t\t! test -e $source && test -r $command/$olddep &&".
1.19 harris41 1178: " { perl filecompare.pl -b2 $command/$olddep $target || ECODE=\$\$?; } && { [ \$\$ECODE != \"2\" ] || echo \"**** WARNING **** dependency $command/$olddep is newer than target file $target; SOMETHING MAY BE WRONG\"$logcmd; };\\\n";
1.14 harris41 1179: }
1180: $olddep=$dep;
1.11 harris41 1181: }
1182: $binfo.="$source: $tword\n".
1183: "\t\@if !(echo \"\");\\\n\t\tthen echo ".
1.14 harris41 1184: "\"**** WARNING **** Strange shell. ".
1.19 harris41 1185: "Check your path settings.\"$logcmd;\\\n".
1.11 harris41 1186: $depstring.
1187: "\telse \\\n\t\t$command2\n\tfi\n\n";
1.14 harris41 1188: $binfo.="${source}___DEPS:\n".$depstring2."\t\tECODE=0;\n\n";
1.11 harris41 1189: }
1190: return 'all: '.join(' ',@buildall)."\n\n".
1191: $text.
1192: $binfo."\n".
1193: "alwaysrun:\n\n";
1194: }
1.35 harris41 1195: elsif ($mode eq 'rpm_file_list') {
1196: return $text;
1197: }
1.3 harris41 1198: else {
1199: return '';
1200: }
1201: }
1202: # ---------------------------------------------------- Format fileglobs section
1203: sub format_fileglobs {
1204:
1205: }
1206: # -------------------------------------------------------- Format links section
1.4 harris41 1207: # deprecated.. currently <link></link>'s are included in <files></files>
1.3 harris41 1208: sub format_links {
1.4 harris41 1209: my $text=$parser->get_text('/links');
1210: $parser->get_tag('/links');
1211: if ($mode eq 'html') {
1.10 harris41 1212: return $links="\n<br />BEGIN LINKS\n$text\n<br />END LINKS\n";
1.4 harris41 1213: }
1214: elsif ($mode eq 'install') {
1215: return "\n".'links:'."\n\t".$text;
1216: }
1217: else {
1218: return '';
1219: }
1.1 harris41 1220: }
1.3 harris41 1221: # --------------------------------------------------------- Format file section
1222: sub format_file {
1223: my @tokeninfo=@_;
1224: $file=''; $source=''; $target=''; $categoryname=''; $description='';
1.53 albertel 1225: $note=''; $build=''; $status=''; $dependencies=''; $installscript='';
1.3 harris41 1226: my $text=&trim($parser->get_text('/file'));
1.14 harris41 1227: my $buildtest;
1.29 harris41 1228: $file_count++;
1229: $categorycount{$categoryname}++;
1.3 harris41 1230: if ($source) {
1231: $parser->get_tag('/file');
1.46 harris41 1232: if ($mode eq 'MANIFEST') {
1.47 harris41 1233: my $command=$build;
1234: if ($command!~/\s/) {
1235: $command=~s/\/([^\/]*)$//;
1236: }
1237: else {
1238: $command=~s/(.*?\/)([^\/]+\s+.*)$/$1/;
1239: }
1240: $command=~s/^$sourceroot\///;
1241: my (@deps)=split(/\;/,$dependencies);
1242: my $retval=join("\n",($source,
1243: (map {"$command$_"} @deps)));
1.52 albertel 1244: if ($tokeninfo[2]{type} eq 'private') {
1245: return "\n";
1246: }
1.47 harris41 1247: return $retval."\n";
1.46 harris41 1248: }
1249: elsif ($mode eq 'html') {
1.26 harris41 1250: return ($file="\n<!-- FILESORT:$target -->".
1251: "<tr>".
1.41 harris41 1252: "<td><!-- POSTEVAL [$categoryname] verify.pl file '$sourcerootarg' ".
1.28 harris41 1253: "'$targetrootarg' ".
1254: "'$source' '$target' ".
1255: "$categoryhash{$categoryname} --> </td><td>".
1.27 harris41 1256: "<img src='$fab{$categoryname}.gif' ".
1.26 harris41 1257: "alt='$categoryname icon' /></td>".
1.27 harris41 1258: "<td>$categoryname<br /><font size='-1'>".
1259: $categoryhash{$categoryname}."</font></td>".
1.26 harris41 1260: "<td>SOURCE: $source<br />TARGET: $target</td>".
1261: "<td>$description</td>".
1262: "<td>$note</td>".
1263: "</tr>");
1264: # return ($file="\n<br />BEGIN FILE\n".
1265: # "$source $target $categoryname $description $note " .
1266: # "$build $status $dependencies" .
1267: # "\nEND FILE");
1.3 harris41 1268: }
1.5 harris41 1269: elsif ($mode eq 'install' && $categoryname ne 'conf') {
1.14 harris41 1270: if ($build) {
1271: my $bi=$sourceroot.'/'.$source.';'.$build.';'.
1272: $dependencies;
1273: my ($source2,$command,$trigger,@deps)=split(/\;/,$bi);
1274: $tword=''; $tword=' alwaysrun' if $trigger eq 'always run';
1275: $command=~s/\/([^\/]*)$//;
1276: $command2="cd $command; sh ./$1;\\";
1277: my $depstring;
1278: foreach my $dep (@deps) {
1279: $depstring.=<<END;
1280: ECODE=0; DEP=''; \\
1.34 harris41 1281: test -e $dep || (echo '**** WARNING **** cannot evaluate status of dependency $dep (for building ${sourceroot}/${source} with)'$logcmd); DEP="1"; \\
1282: [ -n DEP ] && { perl filecompare.pl -b2 $dep ${targetroot}/${target} || ECODE=\$\$?; } || DEP="1"; \\
1.14 harris41 1283: case "\$\$ECODE" in \\
1.34 harris41 1284: 2) echo "**** WARNING **** dependency $dep is newer than target file ${targetroot}/${target}; you may want to run make build"$logcmd;; \\
1.14 harris41 1285: esac; \\
1286: END
1287: }
1288: chomp $depstring;
1289: $buildtest=<<END;
1290: \@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
1.19 harris41 1291: echo "**** ERROR **** ${sourceroot}/${source} is missing and is also not present at target location ${targetroot}/${target}; you must run make build"$logcmd; exit; \\
1.14 harris41 1292: END
1293: $buildtest.=<<END if $depstring;
1294: elif !(test -e "${sourceroot}/${source}"); then \\
1295: $depstring
1296: END
1297: $buildtest.=<<END;
1298: fi
1299: END
1300: }
1.53 albertel 1301: if ($installscript) {
1302: my $dir = $sourceroot.'/'.$source;
1303: $dir =~ s|/([^/]*)$||;
1304: return <<"END";
1305: $buildtest cd $dir ; sh $installscript\\
1306: chmod -R $categoryhash{chmod.$categoryname} ${targetroot}/${target} \\
1307: chown -R $categoryhash{chown.$categoryname} ${targetroot}/${target} \\
1308: END
1309: }
1.18 harris41 1310: my $bflag='-b1';
1311: $bflag='-b3' if $dependencies or $buildlink;
1.14 harris41 1312: return <<END;
1.19 harris41 1313: $buildtest \@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
1314: echo "**** ERROR **** CVS source file does not exist: ${sourceroot}/${source} and neither does target: ${targetroot}/${target}"$logcmd; \\
1315: elif !(test -e "${sourceroot}/${source}"); then \\
1316: echo "**** WARNING **** CVS source file does not exist: ${sourceroot}/${source}"$logcmd; \\
1.21 harris41 1317: perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\
1.14 harris41 1318: else \\
1319: ECODE=0; \\
1320: perl filecompare.pl $bflag ${sourceroot}/${source} ${targetroot}/${target} || ECODE=\$\$?; \\
1321: case "\$\$ECODE" in \\
1322: 1) echo "${targetroot}/${target} is unchanged";; \\
1.21 harris41 1323: 2) echo "**** WARNING **** target file ${targetroot}/${target} is newer than CVS source; saving current (old) target file to ${targetroot}/${target}.lpmlsave and then overwriting"$logcmd && install -o www -g www -m 0600 ${targetroot}/${target} ${targetroot}/${target}.lpmlsave && install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target};; \\
1.27 harris41 1324: 0) echo "install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target}" && install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target};; \\
1.14 harris41 1325: esac; \\
1.21 harris41 1326: perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\
1.14 harris41 1327: fi
1328: END
1.12 harris41 1329: }
1330: elsif ($mode eq 'configinstall' && $categoryname eq 'conf') {
1331: push @configall,$targetroot.'/'.$target;
1.14 harris41 1332: return $targetroot.'/'.$target.': alwaysrun'."\n".
1.48 harris41 1333: "\t".'@# Compare source with target and intelligently respond'.
1334: "\n\t\n\t\n".
1335:
1336:
1337: "\t".'@echo -n ""; ECODE=0 && { perl filecompare.pl -b4 \\'.
1338: "\n\t".$sourceroot.'/'.$source." \\\n\t".
1339: $targetroot.'/'.$target." \\\n\t".
1340: ' || ECODE=$$?; } && '."\\\n\t"."\\\n\t"."\\\n\t".
1341:
1342:
1343: '{ [ $$ECODE != "2" ] || '." \\\n\t".'(install '.
1344: $categoryhash{$categoryname}." \\\n\t\t".
1345: $sourceroot.'/'.$source." \\\n\t\t".
1346: $targetroot.'/'.$target.'.lpmlnew'." \\\n\t\t".
1.19 harris41 1347: ' && echo "**** NOTE: CONFIGURATION FILE CHANGE ****"'.
1.48 harris41 1348: " \\\n\t\t".$logcmd.' && '." \\\n\t\t"."echo -n \"".
1349: 'You likely need to compare contents of "'."\\\n\t\t\t".
1.49 harris41 1350: '&& echo -n "'.$targetroot.'/'.$target.'"'."\\\n\t\t".
1351: '&& echo -n " with the new "'."\\\n\t\t\t".
1352: '&& echo "'.$targetroot.'/'.$target.'.lpmlnew"'."\\\n\t\t".
1.48 harris41 1353: "$logcmd); } && "." \\\n\t"."\\\n\t"."\\\n\t".
1354:
1355:
1356: '{ [ $$ECODE != "3" ] || '."\\\n\t".
1357: '(install '.
1358: $categoryhash{$categoryname}."\\\n\t\t".
1359: $sourceroot.'/'.$source."\\\n\t\t".
1360: $targetroot.'/'.$target."\\\n\t\t".
1.20 harris41 1361: ' && echo "**** WARNING: NEW CONFIGURATION FILE ADDED ****"'.
1.48 harris41 1362: "\\\n\t\t".$logcmd.' && '."\\\n\t\t".
1.50 harris41 1363: 'echo -n "'.
1.48 harris41 1364: 'You likely need to review the contents of "'."\\\n\t\t\t".
1.49 harris41 1365: '&& echo -n "'.
1.48 harris41 1366: $targetroot.'/'.$target.'"'."\\\n\t\t\t".
1.49 harris41 1367: '&& echo -n "'.
1368: ' to make sure its "'."\\\n\t\t".
1369: '&& echo "'.
1.48 harris41 1370: 'settings are compatible with your overall system"'."\\\n\t\t".
1371: "$logcmd); } && "."\\\n\t"."\\\n\t"."\\\n\t".
1372:
1373:
1374: '{ [ $$ECODE != "1" ] || ('."\\\n\t\t".
1375: 'echo "**** ERROR ****"'.$logcmd.' && '."\\\n\t\t".'echo -n "'.
1376: 'Configuration source file does not exist "'."\\\n\t\t".
1.50 harris41 1377: '&& echo -n "'.$sourceroot.'/'.$source.'"'."\\\n\t\t".
1.48 harris41 1378: "$logcmd); } && "."\\\n\t\t".
1379: "perl verifymodown.pl ${targetroot}/${target} "."\\\n\t\t\t".
1380: "\"$categoryhash{$categoryname}\""."\\\n\t\t\t".
1381: "$logcmd;\n\n";
1.4 harris41 1382: }
1.11 harris41 1383: elsif ($mode eq 'build' && $build) {
1384: push @buildall,$sourceroot.'/'.$source;
1.14 harris41 1385: push @buildinfo,$targetroot.'/'.$target.';'.$sourceroot.'/'.
1386: $source.';'.$build.';'.
1.11 harris41 1387: $dependencies;
1388: # return '# need to build '.$source.";
1389: }
1.35 harris41 1390: elsif ($mode eq 'rpm_file_list') {
1391: if ($categoryname eq 'doc') {
1392: return $targetroot.'/'.$target.' # doc'."\n";
1393: }
1394: elsif ($categoryname eq 'conf') {
1395: return $targetroot.'/'.$target.' # config'."\n";
1396: }
1397: else {
1398: return $targetroot.'/'.$target."\n";
1399: }
1400: }
1.3 harris41 1401: else {
1402: return '';
1403: }
1404: }
1405: return '';
1406: }
1407: # --------------------------------------------------------- Format link section
1408: sub format_link {
1409: my @tokeninfo=@_;
1.27 harris41 1410: $link=''; $linkto=''; $source=''; $target=''; $categoryname='';
1411: $description=''; $note=''; $build=''; $status=''; $dependencies='';
1.3 harris41 1412: my $text=&trim($parser->get_text('/link'));
1413: if ($linkto) {
1414: $parser->get_tag('/link');
1415: if ($mode eq 'html') {
1.27 harris41 1416: my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
1.29 harris41 1417: $link_count+=scalar(@targets);
1.27 harris41 1418: foreach my $tgt (@targets) {
1.29 harris41 1419: $categorycount{$categoryname}++;
1.27 harris41 1420: push @links,("\n<!-- FILESORT:$tgt -->".
1421: "<tr>".
1.32 harris41 1422: "<td><!-- POSTEVAL [$categoryname] verify.pl link ".
1.28 harris41 1423: "'/$targetrootarg$linkto' '/$targetrootarg$tgt' ".
1424: "$categoryhash{$categoryname} --> </td><td>".
1.27 harris41 1425: "<img src='$fab{$categoryname}.gif' ".
1426: "alt='$categoryname icon' /></td>".
1427: "<td><font size='-1'>$categoryname</font></td>".
1428: "<td>LINKTO: $linkto<br />TARGET: $tgt</td>".
1429: "<td>$description</td>".
1430: "<td>$note</td>".
1431: "</tr>");
1432: # push @links,"\t".'ln -fs /'.$linkto.' /'.$targetroot.$tgt.
1433: # "\n";
1434: }
1435: return join('',@links);
1436: # return ($link="\n<!-- FILESORT:$target -->".
1437: # "<tr>".
1438: # "<td> </td><td><img src='$fab{$categoryname}.gif' ".
1439: # "alt='$categoryname icon' /></td>".
1440: # "<td>$categoryname</td>".
1441: # "<td>LINKTO: $linkto<br />TARGET: $target</td>".
1442: # "<td>$description</td>".
1443: # "<td>$note</td>".
1444: # "</tr>");
1445: # return $link="\n<tr><td colspan='6'>BEGIN LINK\n".
1446: # "$linkto $target $categoryname $description $note " .
1447: # "$build $status $dependencies" .
1448: # "\nEND LINK</td></tr>";
1.4 harris41 1449: }
1450: elsif ($mode eq 'install') {
1.10 harris41 1451: my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
1.5 harris41 1452: foreach my $tgt (@targets) {
1.35 harris41 1453: push @links,"\t".'ln -fs /'.$linkto.' '.$targetroot.'/'.$tgt.
1.5 harris41 1454: "\n";
1455: }
1.35 harris41 1456: # return join('',@links);
1.4 harris41 1457: return '';
1.3 harris41 1458: }
1.35 harris41 1459: elsif ($mode eq 'rpm_file_list') {
1460: my @linklocs;
1461: my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
1462: foreach my $tgt (@targets) {
1463: push @linklocs,''.$targetroot.'/'.$tgt."\n";
1464: }
1465: return join('',@linklocs);
1466: }
1.3 harris41 1467: else {
1468: return '';
1469: }
1470: }
1471: return '';
1472: }
1473: # ----------------------------------------------------- Format fileglob section
1474: sub format_fileglob {
1475: my @tokeninfo=@_;
1476: $fileglob=''; $glob=''; $sourcedir='';
1477: $targetdir=''; $categoryname=''; $description='';
1478: $note=''; $build=''; $status=''; $dependencies='';
1479: $filenames='';
1480: my $text=&trim($parser->get_text('/fileglob'));
1.27 harris41 1481: my $filenames2=$filenames;$filenames2=~s/\s//g;
1.29 harris41 1482: $fileglob_count++;
1483: my @semi=($filenames2=~/(\;)/g);
1484: $fileglobnames_count+=scalar(@semi)+1;
1485: $categorycount{$categoryname}+=scalar(@semi)+1;
1.3 harris41 1486: if ($sourcedir) {
1487: $parser->get_tag('/fileglob');
1.46 harris41 1488: if ($mode eq 'MANIFEST') {
1489: return join("\n",(map {"$sourcedir$_"} split(/\;/,$filenames2)))."\n";
1490: }
1491: elsif ($mode eq 'html') {
1.27 harris41 1492: return $fileglob="\n<tr>".
1.41 harris41 1493: "<td><!-- POSTEVAL [$categoryname] verify.pl fileglob '$sourcerootarg' ".
1.27 harris41 1494: "'$targetrootarg' ".
1495: "'$glob' '$sourcedir' '$filenames2' '$targetdir' ".
1496: "$categoryhash{$categoryname} --> </td>".
1497: "<td>"."<img src='$fab{$categoryname}.gif' ".
1498: "alt='$categoryname icon' /></td>".
1499: "<td>$categoryname<br />".
1500: "<font size='-1'>".$categoryhash{$categoryname}."</font></td>".
1501: "<td>SOURCEDIR: $sourcedir<br />".
1502: "TARGETDIR: $targetdir<br />".
1503: "GLOB: $glob<br />".
1504: "FILENAMES: $filenames".
1505: "</td>".
1506: "<td>$description</td>".
1507: "<td>$note</td>".
1508: "</tr>";
1509: # return $fileglob="\n<tr><td colspan='6'>BEGIN FILEGLOB\n".
1510: # "$glob sourcedir $targetdir $categoryname $description $note ".
1511: # "$build $status $dependencies $filenames" .
1512: # "\nEND FILEGLOB</td></tr>";
1.3 harris41 1513: }
1.5 harris41 1514: elsif ($mode eq 'install') {
1.30 harris41 1515: my $eglob=$glob;
1516: if ($glob eq '*') {
1517: $eglob='[^C][^V][^S]'.$glob;
1518: }
1.5 harris41 1519: return "\t".'install '.
1520: $categoryhash{$categoryname}.' '.
1.30 harris41 1521: $sourceroot.'/'.$sourcedir.$eglob.' '.
1.5 harris41 1522: $targetroot.'/'.$targetdir.'.'."\n";
1.35 harris41 1523: }
1524: elsif ($mode eq 'rpm_file_list') {
1525: my $eglob=$glob;
1526: if ($glob eq '*') {
1527: $eglob='[^C][^V][^S]'.$glob;
1528: }
1529: my $targetdir2=$targetdir;$targetdir2=~s/\/$//;
1530: my @gfiles=map {s/^.*\///;"$targetroot/$targetdir2/$_\n"}
1531: glob("$sourceroot/$sourcedir/$eglob");
1532: return join('',@gfiles);
1.5 harris41 1533: }
1.3 harris41 1534: else {
1535: return '';
1536: }
1537: }
1538: return '';
1539: }
1540: # ---------------------------------------------------- Format sourcedir section
1541: sub format_sourcedir {
1542: my @tokeninfo=@_;
1543: $sourcedir='';
1544: my $text=&trim($parser->get_text('/sourcedir'));
1545: if ($text) {
1546: $parser->get_tag('/sourcedir');
1547: $sourcedir=$text;
1548: }
1549: return '';
1550: }
1551: # ------------------------------------------------------- Format target section
1552: sub format_target {
1553: my @tokeninfo=@_;
1554: $target='';
1555: my $text=&trim($parser->get_text('/target'));
1556: if ($text) {
1557: $parser->get_tag('/target');
1558: $target=$text;
1559: }
1560: return '';
1561: }
1562: # ------------------------------------------------------- Format source section
1563: sub format_source {
1564: my @tokeninfo=@_;
1565: $source='';
1566: my $text=&trim($parser->get_text('/source'));
1567: if ($text) {
1568: $parser->get_tag('/source');
1569: $source=$text;
1570: }
1571: return '';
1572: }
1573: # --------------------------------------------------------- Format note section
1574: sub format_note {
1575: my @tokeninfo=@_;
1576: $note='';
1.26 harris41 1577: # my $text=&trim($parser->get_text('/note'));
1578: my $aref;
1579: my $text;
1580: while ($aref=$parser->get_token()) {
1581: if ($aref->[0] eq 'E' && $aref->[1] eq 'note') {
1582: last;
1583: }
1584: elsif ($aref->[0] eq 'S') {
1585: $text.=$aref->[4];
1586: }
1587: elsif ($aref->[0] eq 'E') {
1588: $text.=$aref->[2];
1589: }
1590: else {
1591: $text.=$aref->[1];
1592: }
1593: }
1.3 harris41 1594: if ($text) {
1.26 harris41 1595: # $parser->get_tag('/note');
1.3 harris41 1596: $note=$text;
1597: }
1598: return '';
1599:
1600: }
1601: # -------------------------------------------------------- Format build section
1602: sub format_build {
1603: my @tokeninfo=@_;
1604: $build='';
1605: my $text=&trim($parser->get_text('/build'));
1606: if ($text) {
1607: $parser->get_tag('/build');
1.11 harris41 1608: $build=$sourceroot.'/'.$text.';'.$tokeninfo[2]{'trigger'};
1.42 harris41 1609: $build=~s/([^\\])\\\s+/$1/g; # allow for lines split onto new lines
1.3 harris41 1610: }
1611: return '';
1612: }
1.53 albertel 1613: # ------------------------------------------------ Format installscript section
1614: sub format_installscript {
1615: my @tokeninfo=@_;
1616: $installscript= &trim($parser->get_text('/installscript'));
1617: if ($installscript) {
1618: $parser->get_tag('/installscript');
1619: $installscript=~s/([^\\])\\\s+/$1/g; # allow for lines split onto new lines
1620: }
1621: return '';
1622: }
1.14 harris41 1623: # -------------------------------------------------------- Format build section
1624: sub format_buildlink {
1625: my @tokeninfo=@_;
1626: $buildlink='';
1627: my $text=&trim($parser->get_text('/buildlink'));
1628: if ($text) {
1629: $parser->get_tag('/buildlink');
1630: $buildlink=$sourceroot.'/'.$text;
1631: }
1632: return '';
1633: }
1.3 harris41 1634: # ------------------------------------------------------- Format status section
1635: sub format_status {
1636: my @tokeninfo=@_;
1637: $status='';
1638: my $text=&trim($parser->get_text('/status'));
1639: if ($text) {
1640: $parser->get_tag('/status');
1641: $status=$text;
1642: }
1643: return '';
1644: }
1645: # ------------------------------------------------- Format dependencies section
1646: sub format_dependencies {
1647: my @tokeninfo=@_;
1.52 albertel 1648: #$dependencies='';
1.3 harris41 1649: my $text=&trim($parser->get_text('/dependencies'));
1650: if ($text) {
1651: $parser->get_tag('/dependencies');
1.52 albertel 1652: $dependencies=join(';',((map {s/^\s*//;s/\s$//;$_} split(/\;/,$text)),$dependencies));
1653: $dependencies=~s/;$//;
1654: }
1655: return '';
1656: }
1657: sub format_privatedependencies {
1658: my @tokeninfo=@_;
1659: #$dependencies='';
1660: my $text=&trim($parser->get_text('/privatedependencies'));
1661: if ($text) {
1662: $parser->get_tag('/privatedependencies');
1663: if ($mode eq 'MANIFEST') { return ''; }
1664: $dependencies=join(';',((map {s/^\s*//;s/\s$//;$_} split(/\;/,$text)),$dependencies));
1665: $dependencies=~s/;$//;
1.3 harris41 1666: }
1667: return '';
1668: }
1669: # --------------------------------------------------------- Format glob section
1670: sub format_glob {
1671: my @tokeninfo=@_;
1672: $glob='';
1673: my $text=&trim($parser->get_text('/glob'));
1674: if ($text) {
1675: $parser->get_tag('/glob');
1676: $glob=$text;
1677: }
1678: return '';
1679: }
1680: # ---------------------------------------------------- Format filenames section
1681: sub format_filenames {
1682: my @tokeninfo=@_;
1683: my $text=&trim($parser->get_text('/filenames'));
1684: if ($text) {
1685: $parser->get_tag('/filenames');
1686: $filenames=$text;
1687: }
1.31 harris41 1688: return '';
1689: }
1.38 harris41 1690: # ----------------------------------------------- Format specialnotices section
1.31 harris41 1691: sub format_specialnotices {
1692: $parser->get_tag('/specialnotices');
1693: return '';
1694: }
1695: # ------------------------------------------------ Format specialnotice section
1696: sub format_specialnotice {
1697: $parser->get_tag('/specialnotice');
1.3 harris41 1698: return '';
1699: }
1700: # ------------------------------------------------------- Format linkto section
1701: sub format_linkto {
1702: my @tokeninfo=@_;
1703: my $text=&trim($parser->get_text('/linkto'));
1704: if ($text) {
1705: $parser->get_tag('/linkto');
1706: $linkto=$text;
1707: }
1708: return '';
1.10 harris41 1709: }
1710: # ------------------------------------- Render less-than and greater-than signs
1711: sub htmlsafe {
1712: my $text=@_[0];
1713: $text =~ s/</</g;
1714: $text =~ s/>/>/g;
1715: return $text;
1.3 harris41 1716: }
1717: # --------------------------------------- remove starting and ending whitespace
1718: sub trim {
1719: my ($s)=@_; $s=~s/^\s*//; $s=~s/\s*$//; return $s;
1720: }
1.14 harris41 1721:
1722: # ----------------------------------- POD (plain old documentation, CPAN style)
1.18 harris41 1723:
1.43 harris41 1724: =pod
1725:
1.18 harris41 1726: =head1 NAME
1727:
1.45 harris41 1728: lpml_parse.pl - This is meant to parse files meeting the lpml document type.
1.18 harris41 1729:
1730: =head1 SYNOPSIS
1731:
1.45 harris41 1732: <STDIN> | perl lpml_parse.pl <MODE> <CATEGORY> <DIST> <SOURCE> <TARGET>
1733:
1734: Usage is for the lpml file to come in through standard input.
1.18 harris41 1735:
1736: =over 4
1737:
1738: =item *
1739:
1740: 1st argument is the mode of parsing.
1741:
1742: =item *
1743:
1744: 2nd argument is the category permissions to use (runtime or development)
1745:
1746: =item *
1747:
1748: 3rd argument is the distribution
1749: (default,redhat6.2,debian2.2,redhat7.1,etc).
1750:
1751: =item *
1752:
1753: 4th argument is to manually specify a sourceroot.
1754:
1755: =item *
1756:
1757: 5th argument is to manually specify a targetroot.
1758:
1759: =back
1760:
1761: Only the 1st argument is mandatory for the program to run.
1762:
1763: Example:
1764:
1765: cat ../../doc/loncapafiles.lpml |\\
1.45 harris41 1766: perl lpml_parse.pl html runtime default /home/sherbert/loncapa /tmp/install
1.18 harris41 1767:
1768: =head1 DESCRIPTION
1769:
1.45 harris41 1770: The general flow of the script is to get command line arguments, run through
1771: the XML document three times, and output according to any desired mode:
1772: install, configinstall, build, rpm, dpkg, htmldoc, textdoc, and status.
1773:
1774: A number of coding decisions are made according to the following principle:
1775: installation software must be stand-alone. Therefore, for instance, I try
1776: not to use the GetOpt::Long module or any other perl modules. (I do however
1777: use HTML::TokeParser.) I also have tried to keep all the MODES of
1778: parsing inside this file. Therefore, format_TAG subroutines are fairly
1779: lengthy with their conditional logic. A more "elegant" solution might
1780: be to dynamically register the parsing mode and subroutines, or maybe even work
1781: with stylesheets. However, in order to make this the installation back-bone
1782: of choice, there are advantages for HAVING EVERYTHING IN ONE FILE.
1783: This way, the LPML installation software does not have to rely on OTHER
1784: installation software (a chicken versus the egg problem). Besides, I would
1785: suggest the modes of parsing are fairly constant: install, configinstall,
1786: build, rpm, dpkg, htmldoc, textdoc, and status.
1787:
1788: Another coding decision is about using a multiple pass-through approach to
1789: parsing the lpml file. This saves memory and makes sure the server will never
1790: be overloaded. During the first pass-through, the script gathers information
1791: specific as to resolving what tags with what 'dist=' attributes are to be used.
1792: During the second pass-through, the script cleans up white-space surrounding
1793: the XML tags, and filters through the tags based on information regarding the
1794: 'dist=' attributes (information gathered in the first pass-through).
1795: The third and final pass-through involves formatting and rendering the XML
1796: into whatever XML mode is chosen: install, configinstall, build, rpm, dpkg,
1797: htmldoc, textdoc, and status.
1798:
1799: The hierarchy mandated by the DTD does not always correspond to the hierarchy
1800: that is sensible for a Makefile. For instance, in a Makefile it is sensible
1801: that soft-links are installed after files. However, in an LPML document, it
1802: is sensible that files and links be considered together and the writer of the
1803: LPML document should be free to place things in whatever order makes best
1804: sense in terms of LOOKING at the information. The complication that arises
1805: is that the parser needs to have a memory for passing values from
1806: leaves on the XML tree to higher-up branches. Currently, this memory is
1807: hard-coded (like with the @links array), but it may benefit from a more
1808: formal approach in the future.
1.18 harris41 1809:
1810: =head1 README
1811:
1.45 harris41 1812: This parses an LPML file to generate information useful for
1813: source to target installation, compilation, filesystem status
1814: checking, RPM and Debian software packaging, and documentation.
1815:
1816: More information on LPML is available at http://lpml.sourceforge.net.
1.18 harris41 1817:
1818: =head1 PREREQUISITES
1819:
1820: HTML::TokeParser
1821:
1822: =head1 COREQUISITES
1823:
1824: =head1 OSNAMES
1825:
1826: linux
1827:
1828: =head1 SCRIPT CATEGORIES
1829:
1.45 harris41 1830: UNIX/System_administration
1.43 harris41 1831:
1832: =head1 AUTHOR
1833:
1834: Scott Harrison
1835: codeharrison@yahoo.com
1836:
1837: Please let me know how/if you are finding this script useful and
1838: any/all suggestions. -Scott
1.18 harris41 1839:
1840: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>