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