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