Annotation of loncom/build/lpml_parse.pl, revision 1.30
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.30 ! harris41 6: # $Id: lpml_parse.pl,v 1.29 2001/12/07 04:45:16 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.28 harris41 38: # 12/2,12/3,12/4,12/5,12/6 - Scott Harrison
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}={
301: targetroot => \&format_targetroot,
302: sourceroot => \&format_sourceroot,
303: categories => \&format_categories,
304: category => \&format_category,
1.25 harris41 305: abbreviation => \&format_abbreviation,
1.3 harris41 306: targetdir => \&format_targetdir,
307: chown => \&format_chown,
308: chmod => \&format_chmod,
309: rpm => \&format_rpm,
310: rpmSummary => \&format_rpmSummary,
311: rpmName => \&format_rpmName,
312: rpmVersion => \&format_rpmVersion,
313: rpmRelease => \&format_rpmRelease,
314: rpmVendor => \&format_rpmVendor,
315: rpmBuildRoot => \&format_rpmBuildRoot,
316: rpmCopyright => \&format_rpmCopyright,
317: rpmGroup => \&format_rpmGroup,
318: rpmSource => \&format_rpmSource,
319: rpmAutoReqProv => \&format_rpmAutoReqProv,
320: rpmdescription => \&format_rpmdescription,
321: rpmpre => \&format_rpmpre,
322: directories => \&format_directories,
323: directory => \&format_directory,
324: categoryname => \&format_categoryname,
325: description => \&format_description,
326: files => \&format_files,
327: file => \&format_file,
328: fileglob => \&format_fileglob,
1.4 harris41 329: links => \&format_links,
1.3 harris41 330: link => \&format_link,
331: linkto => \&format_linkto,
332: source => \&format_source,
333: target => \&format_target,
334: note => \&format_note,
335: build => \&format_build,
336: status => \&format_status,
337: dependencies => \&format_dependencies,
1.14 harris41 338: buildlink => \&format_buildlink,
1.3 harris41 339: glob => \&format_glob,
340: sourcedir => \&format_sourcedir,
341: filenames => \&format_filenames,
342: };
343:
344: my $text;
345: my $token;
346: undef $hloc;
347: undef @hierarchy;
348: my $hloc;
349: my @hierarchy2;
350: while ($token = $parser->get_tag('lpml')) {
351: &format_lpml(@{$token});
352: $text = &trim($parser->get_text('/lpml'));
353: $token = $parser->get_tag('/lpml');
354: print $lpml;
355: print "\n";
1.4 harris41 356: # $text=~s/\s*\n\s*\n\s*/\n/g;
1.3 harris41 357: print $text;
358: print "\n";
359: print &end();
360: }
361: exit;
362:
1.14 harris41 363: # ---------- Functions (most all just format contents of different markup tags)
364:
365: # ------------------------ Final output at end of markup parsing and formatting
1.3 harris41 366: sub end {
367: if ($mode eq 'html') {
1.29 harris41 368: # START TEMP WAY
369: # my $totallinecount;
370: # my $totalbytecount;
371: # map {$totallinecount+=$linecount{$_};
372: # $totalbytecount+=$bytecount{$_}}
373: # @categorynamelist;
374: # END TEMP WAY
375: return "<br /> <br />".
376: "<a name='summary' /><font size='+2'>Summary of Source Repository".
377: "</font>".
378: "<br /> <br />".
379: "<table border='1' cellpadding='5'>".
380: "<caption>Files, Directories, and Symbolic Links</caption>".
381: "<tr><td>Files (not referenced by globs)</td><td>$file_count</td>".
382: "</tr>".
383: "<tr><td>Files (referenced by globs)</td>".
384: "<td>$fileglobnames_count</td>".
385: "</tr>".
386: "<tr><td>Total Files</td>".
387: "<td>".($fileglobnames_count+$file_count)."</td>".
388: "</tr>".
389: "<tr><td>File globs</td>".
390: "<td>".$fileglob_count."</td>".
391: "</tr>".
392: "<tr><td>Directories</td>".
393: "<td>".$directory_count."</td>".
394: "</tr>".
395: "<tr><td>Symbolic links</td>".
396: "<td>".$link_count."</td>".
397: "</tr>".
398: "</table>".
399: "<table border='1' cellpadding='5'>".
400: "<caption>File Category Count</caption>".
401: "<tr><th>Icon</th><th>Name</th><th>Number of Occurrences</th>".
402: join("\n",(map {"<tr><td><img src='$fab{$_}.gif' ".
403: "alt='$_ icon' /></td>".
404: "<td>$_</td><td>$categorycount{$_}</td></tr>"}
405: @categorynamelist)).
406: "</table>".
407: "</body></html>\n";
408:
409: # START TEMP WAY
410: # join("\n",(map {"<tr><td><img src='$fab{$_}.gif' ".
411: # "alt='$_ icon' /></td>".
412: # "<td>$_</td><td>$categorycount{$_}</td><td>$linecount{$_}</td><td>$bytecount{$_}</td></tr>"}
413: # @categorynamelist)).
414: # "<br /> <br />".
415: # "Total Lines of Code: $totallinecount".
416: # "<br /> <br />".
417: # "Total Bytes: $totalbytecount".
418: # END TEMP WAY
1.3 harris41 419: }
1.4 harris41 420: if ($mode eq 'install') {
421: return '';
422: }
1.3 harris41 423: }
424:
425: # ----------------------- Take in string to parse and the separation expression
426: sub extract_array {
427: my ($stringtoparse,$sepexp) = @_;
428: my @a=split(/$sepexp/,$stringtoparse);
429: return \@a;
430: }
431:
432: # --------------------------------------------------------- Format lpml section
433: sub format_lpml {
434: my (@tokeninfo)=@_;
435: my $date=`date`; chop $date;
436: if ($mode eq 'html') {
1.24 harris41 437: $lpml=<<END;
438: <html>
439: <head>
1.25 harris41 440: <title>LPML Description Page
441: (dist=$dist, categorytype=$categorytype, $date)</title>
1.24 harris41 442: </head>
443: <body>
444: END
445: $lpml .= "<br /><font size='+2'>LPML Description Page (dist=$dist, ".
1.25 harris41 446: "categorytype=$categorytype, $date)".
1.23 harris41 447: "</font>";
448: $lpml .=<<END;
449: <ul>
1.24 harris41 450: <li><a href='#about'>About this file</a></li>
451: <li><a href='#ownperms'>File Type Ownership and Permissions
452: Descriptions</a></li>
453: <li><a href='#package'>Software Package Description</a></li>
454: <li><a href='#directories'>Directory Structure</a></li>
1.26 harris41 455: <li><a href='#files'>Files</a></li>
1.29 harris41 456: <li><a href='#summary'>Summary of Source Repository</a></li>
1.23 harris41 457: </ul>
458: END
459: $lpml .=<<END;
1.24 harris41 460: <br /> <br /><a name='about' />
1.23 harris41 461: <font size='+2'>About this file</font>
462: <p>
463: This file is generated dynamically by <tt>lpml_parse.pl</tt> as
1.28 harris41 464: part of a development compilation process.</p>
465: <p>LPML written by Scott Harrison (harris41\@msu.edu).
1.23 harris41 466: </p>
467: END
468: }
469: elsif ($mode eq 'text') {
470: $lpml = "LPML Description Page (dist=$dist, $date)";
471: $lpml .=<<END;
472:
473: * About this file
474: * Software Package Description
475: * Directory Structure
476: * File Type Ownership and Permissions
1.26 harris41 477: * Files
1.23 harris41 478: END
479: $lpml .=<<END;
480:
481: About this file
482:
483: This file is generated dynamically by lpml_parse.pl as
484: part of a development compilation process. Author: Scott
485: Harrison (harris41\@msu.edu).
486:
487: END
1.3 harris41 488: }
1.4 harris41 489: elsif ($mode eq 'install') {
490: print '# LPML install targets. Linux Packaging Markup Language,';
491: print ' by Scott Harrison 2001'."\n";
492: print '# This file was automatically generated on '.`date`;
1.5 harris41 493: print "\n".$invocation;
1.14 harris41 494: $lpml .= "SHELL=\"/bin/bash\"\n\n";
1.4 harris41 495: }
1.16 harris41 496: elsif ($mode eq 'configinstall') {
1.17 harris41 497: print '# LPML configuration file targets (configinstall).'."\n";
498: print '# Linux Packaging Markup Language,';
1.16 harris41 499: print ' by Scott Harrison 2001'."\n";
500: print '# This file was automatically generated on '.`date`;
501: print "\n".$invocation;
502: $lpml .= "SHELL=\"/bin/bash\"\n\n";
503: }
1.11 harris41 504: elsif ($mode eq 'build') {
1.14 harris41 505: $lpml = "# LPML build targets. Linux Packaging Markup Language,";
506: $lpml .= ' by Scott Harrison 2001'."\n";
1.11 harris41 507: $lpml .= '# This file was automatically generated on '.`date`;
1.17 harris41 508: $lpml .= "\n".$invocation;
1.11 harris41 509: $lpml .= "SHELL=\"/bin/sh\"\n\n";
510: }
1.4 harris41 511: else {
512: return '';
513: }
1.3 harris41 514: }
515: # --------------------------------------------------- Format targetroot section
516: sub format_targetroot {
517: my $text=&trim($parser->get_text('/targetroot'));
518: $text=$targetroot if $targetroot;
519: $parser->get_tag('/targetroot');
520: if ($mode eq 'html') {
1.10 harris41 521: return $targetroot="\n<br />TARGETROOT: $text";
1.3 harris41 522: }
1.17 harris41 523: elsif ($mode eq 'install' or $mode eq 'build' or
524: $mode eq 'configinstall') {
1.11 harris41 525: return '# TARGET INSTALL LOCATION is "'.$targetroot."\"\n";
526: }
1.3 harris41 527: else {
528: return '';
529: }
530: }
531: # --------------------------------------------------- Format sourceroot section
532: sub format_sourceroot {
533: my $text=&trim($parser->get_text('/sourceroot'));
534: $text=$sourceroot if $sourceroot;
535: $parser->get_tag('/sourceroot');
536: if ($mode eq 'html') {
1.10 harris41 537: return $sourceroot="\n<br />SOURCEROOT: $text";
1.3 harris41 538: }
1.17 harris41 539: elsif ($mode eq 'install' or $mode eq 'build' or
540: $mode eq 'configinstall') {
1.11 harris41 541: return '# SOURCE CODE LOCATION IS "'.$sourceroot."\"\n";;
542: }
1.3 harris41 543: else {
544: return '';
545: }
546: }
547: # --------------------------------------------------- Format categories section
548: sub format_categories {
549: my $text=&trim($parser->get_text('/categories'));
550: $parser->get_tag('/categories');
551: if ($mode eq 'html') {
1.24 harris41 552: return $categories="\n<br /> <br />".
553: "\n<a name='ownperms'>".
554: "\n<font size='+2'>File Type Ownership and Permissions".
555: " Descriptions</font>".
1.25 harris41 556: "\n<p>This table shows what permissions and ownership settings ".
557: "correspond to each category.</p>".
558: "\n<table border='1' cellpadding='5' width='60%'>\n".
559: "<tr>".
560: "<th align='left' bgcolor='#ffffff'>Icon</th>".
561: "<th align='left' bgcolor='#ffffff'>Category Name</th>".
562: "<th align='left' bgcolor='#ffffff'>Permissions ".
563: "($categorytype)</th>".
564: "</tr>".
565: "\n$text\n".
1.24 harris41 566: "</table>\n";
567: }
568: elsif ($mode eq 'text') {
569: return $categories="\n".
570: "\nFile Type Ownership and Permissions".
571: " Descriptions".
1.25 harris41 572: "\n$text".
1.24 harris41 573: "\n";
1.3 harris41 574: }
575: else {
576: return '';
577: }
578: }
579: # --------------------------------------------------- Format categories section
580: sub format_category {
581: my (@tokeninfo)=@_;
582: $category_att_name=$tokeninfo[2]->{'name'};
583: $category_att_type=$tokeninfo[2]->{'type'};
1.25 harris41 584: $abbreviation=''; $chmod='';$chown='';
1.3 harris41 585: $parser->get_text('/category');
586: $parser->get_tag('/category');
1.26 harris41 587: $fab{$category_att_name}=$abbreviation;
1.3 harris41 588: if ($mode eq 'html') {
1.25 harris41 589: if ($category_att_type eq $categorytype) {
1.29 harris41 590: push @categorynamelist,$category_att_name;
1.27 harris41 591: $categoryhash{$category_att_name}="$chmod $chown";
1.25 harris41 592: return $category="<tr>".
593: "<td><img src='$abbreviation.gif' ".
594: "alt='${category_att_name}' /></td>\n".
595: "<td>${category_att_name}</td>\n".
596: "<td>$chmod $chown</td>\n".
597: "</tr>".
598: "\n";
599: # return $category="\n<br />CATEGORY $category_att_name ".
600: # "$category_att_type $chmod $chown";
601: }
1.3 harris41 602: }
603: else {
1.4 harris41 604: if ($category_att_type eq $categorytype) {
605: my ($user,$group)=split(/\:/,$chown);
606: $categoryhash{$category_att_name}='-o '.$user.' -g '.$group.
607: ' -m '.$chmod;
608: }
1.3 harris41 609: return '';
610: }
611: }
1.25 harris41 612: # --------------------------------------------------- Format categories section
613: sub format_abbreviation {
614: my @tokeninfo=@_;
615: $abbreviation='';
616: my $text=&trim($parser->get_text('/abbreviation'));
617: if ($text) {
618: $parser->get_tag('/abbreviation');
619: $abbreviation=$text;
620: }
621: return '';
622: }
1.3 harris41 623: # -------------------------------------------------------- Format chown section
624: sub format_chown {
625: my @tokeninfo=@_;
626: $chown='';
627: my $text=&trim($parser->get_text('/chown'));
628: if ($text) {
629: $parser->get_tag('/chown');
630: $chown=$text;
631: }
632: return '';
633: }
634: # -------------------------------------------------------- Format chmod section
635: sub format_chmod {
636: my @tokeninfo=@_;
637: $chmod='';
638: my $text=&trim($parser->get_text('/chmod'));
639: if ($text) {
640: $parser->get_tag('/chmod');
641: $chmod=$text;
642: }
643: return '';
644: }
645: # ---------------------------------------------------------- Format rpm section
646: sub format_rpm {
647: my $text=&trim($parser->get_text('/rpm'));
648: $parser->get_tag('/rpm');
649: if ($mode eq 'html') {
1.23 harris41 650: return $rpm=<<END;
1.24 harris41 651: <br /> <br />
652: <a name='package' />
1.23 harris41 653: <font size='+2'>Software Package Description</font>
654: <p>
655: <table bgcolor='#ffffff' border='0' cellpadding='10' cellspacing='0'>
656: <tr><td><pre>
657: $text
658: </pre></td></tr>
659: </table>
660: END
661: }
662: elsif ($mode eq 'text') {
663: return $rpm=<<END;
664: Software Package Description
665:
666: $text
667: END
1.3 harris41 668: }
669: else {
670: return '';
671: }
672: }
673: # --------------------------------------------------- Format rpmSummary section
674: sub format_rpmSummary {
675: my $text=&trim($parser->get_text('/rpmSummary'));
676: $parser->get_tag('/rpmSummary');
677: if ($mode eq 'html') {
1.23 harris41 678: return $rpmSummary="\nSummary : $text";
679: }
680: elsif ($mode eq 'text') {
681: return $rpmSummary="\nSummary : $text";
1.3 harris41 682: }
683: else {
684: return '';
685: }
686: }
687: # ------------------------------------------------------ Format rpmName section
688: sub format_rpmName {
689: my $text=&trim($parser->get_text('/rpmName'));
690: $parser->get_tag('/rpmName');
691: if ($mode eq 'html') {
1.24 harris41 692: return $rpmName="\nName : $text";
693: }
694: elsif ($mode eq 'text') {
695: return $rpmName="\nName : $text";
1.3 harris41 696: }
697: else {
698: return '';
699: }
700: }
701: # --------------------------------------------------- Format rpmVersion section
702: sub format_rpmVersion {
703: my $text=$parser->get_text('/rpmVersion');
704: $parser->get_tag('/rpmVersion');
705: if ($mode eq 'html') {
1.24 harris41 706: return $rpmVersion="\nVersion : $text";
707: }
708: elsif ($mode eq 'text') {
709: return $rpmVersion="\nVersion : $text";
1.3 harris41 710: }
711: else {
712: return '';
713: }
714: }
715: # --------------------------------------------------- Format rpmRelease section
716: sub format_rpmRelease {
717: my $text=$parser->get_text('/rpmRelease');
718: $parser->get_tag('/rpmRelease');
719: if ($mode eq 'html') {
1.24 harris41 720: return $rpmRelease="\nRelease : $text";
721: }
722: elsif ($mode eq 'text') {
723: return $rpmRelease="\nRelease : $text";
1.3 harris41 724: }
725: else {
726: return '';
727: }
728: }
729: # ---------------------------------------------------- Format rpmVendor section
730: sub format_rpmVendor {
731: my $text=$parser->get_text('/rpmVendor');
732: $parser->get_tag('/rpmVendor');
733: if ($mode eq 'html') {
1.24 harris41 734: return $rpmVendor="\nVendor : $text";
735: }
736: elsif ($mode eq 'text') {
737: return $rpmVendor="\nVendor : $text";
1.3 harris41 738: }
739: else {
740: return '';
741: }
742: }
743: # ------------------------------------------------- Format rpmBuildRoot section
744: sub format_rpmBuildRoot {
745: my $text=$parser->get_text('/rpmBuildRoot');
746: $parser->get_tag('/rpmBuildRoot');
747: if ($mode eq 'html') {
1.24 harris41 748: return $rpmBuildRoot="\nBuild Root : $text";
749: }
750: elsif ($mode eq 'text') {
751: return $rpmBuildRoot="\nBuild Root : $text";
1.3 harris41 752: }
753: else {
754: return '';
755: }
756: }
757: # ------------------------------------------------- Format rpmCopyright section
758: sub format_rpmCopyright {
759: my $text=$parser->get_text('/rpmCopyright');
760: $parser->get_tag('/rpmCopyright');
761: if ($mode eq 'html') {
1.24 harris41 762: return $rpmCopyright="\nLicense : $text";
763: }
764: elsif ($mode eq 'text') {
765: return $rpmCopyright="\nLicense : $text";
1.3 harris41 766: }
767: else {
768: return '';
769: }
770: }
771: # ----------------------------------------------------- Format rpmGroup section
772: sub format_rpmGroup {
773: my $text=$parser->get_text('/rpmGroup');
774: $parser->get_tag('/rpmGroup');
775: if ($mode eq 'html') {
1.24 harris41 776: return $rpmGroup="\nGroup : $text";
777: }
778: elsif ($mode eq 'text') {
779: return $rpmGroup="\nGroup : $text";
1.3 harris41 780: }
781: else {
782: return '';
783: }
784: }
785: # ---------------------------------------------------- Format rpmSource section
786: sub format_rpmSource {
787: my $text=$parser->get_text('/rpmSource');
788: $parser->get_tag('/rpmSource');
789: if ($mode eq 'html') {
1.24 harris41 790: return $rpmSource="\nSource : $text";
791: }
792: elsif ($mode eq 'text') {
793: return $rpmSource="\nSource : $text";
1.3 harris41 794: }
795: else {
796: return '';
797: }
798: }
799: # ----------------------------------------------- Format rpmAutoReqProv section
800: sub format_rpmAutoReqProv {
801: my $text=$parser->get_text('/rpmAutoReqProv');
802: $parser->get_tag('/rpmAutoReqProv');
803: if ($mode eq 'html') {
1.24 harris41 804: return $rpmAutoReqProv="\nAutoReqProv : $text";
805: }
806: if ($mode eq 'text') {
807: return $rpmAutoReqProv="\nAutoReqProv : $text";
1.3 harris41 808: }
809: else {
810: return '';
811: }
812: }
813: # ----------------------------------------------- Format rpmdescription section
814: sub format_rpmdescription {
815: my $text=$parser->get_text('/rpmdescription');
816: $parser->get_tag('/rpmdescription');
817: if ($mode eq 'html') {
1.25 harris41 818: $text=~s/\n//g;
819: $text=~s/\\n/\n/g;
1.24 harris41 820: return $rpmdescription="\nDescription : $text";
821: }
822: elsif ($mode eq 'text') {
1.25 harris41 823: $text=~s/\n//g;
824: $text=~s/\\n/\n/g;
1.24 harris41 825: return $rpmdescription="\nDescription : $text";
1.3 harris41 826: }
827: else {
828: return '';
829: }
830: }
831: # ------------------------------------------------------- Format rpmpre section
832: sub format_rpmpre {
833: my $text=$parser->get_text('/rpmpre');
834: $parser->get_tag('/rpmpre');
835: if ($mode eq 'html') {
1.24 harris41 836: # return $rpmpre="\n<br />RPMPRE $text";
837: return '';
1.3 harris41 838: }
839: else {
840: return '';
841: }
842: }
843: # -------------------------------------------------- Format directories section
844: sub format_directories {
1.4 harris41 845: my $text=$parser->get_text('/directories');
1.3 harris41 846: $parser->get_tag('/directories');
847: if ($mode eq 'html') {
1.26 harris41 848: $text=~s/\[\{\{\{\{\{DPATHLENGTH\}\}\}\}\}\]/$dpathlength/g;
1.24 harris41 849: return $directories="\n<br /> <br />".
850: "<a name='directories' />".
851: "<font size='+2'>Directory Structure</font>".
1.26 harris41 852: "\n<br /> <br />".
853: "<table border='1' cellpadding='3' cellspacing='0'>\n".
854: "<tr><th bgcolor='#ffffff'>Category</th>".
855: "<th bgcolor='#ffffff'>Status</th>\n".
856: "<th bgcolor='#ffffff'>Expected Permissions & Ownership</th>\n".
857: "<th bgcolor='#ffffff' colspan='$dpathlength'>Target Directory ".
858: "Path</th></tr>\n".
859: "\n$text\n</table><br />"."\n";
1.24 harris41 860: }
861: elsif ($mode eq 'text') {
862: return $directories="\nDirectory Structure\n$text\n".
863: "\n";
1.3 harris41 864: }
1.4 harris41 865: elsif ($mode eq 'install') {
866: return "\n".'directories:'."\n".$text;
867: }
1.3 harris41 868: else {
869: return '';
870: }
871: }
872: # ---------------------------------------------------- Format directory section
873: sub format_directory {
874: my (@tokeninfo)=@_;
875: $targetdir='';$categoryname='';$description='';
876: $parser->get_text('/directory');
877: $parser->get_tag('/directory');
1.29 harris41 878: $directory_count++;
879: $categorycount{$categoryname}++;
1.3 harris41 880: if ($mode eq 'html') {
1.26 harris41 881: my @a;
882: @a=($targetdir=~/\//g);
883: my $d=scalar(@a)+1;
884: $dpathlength=$d if $d>$dpathlength;
885: my $thtml=$targetdir;
886: $thtml=~s/\//\<\/td\>\<td bgcolor='#ffffff'\>/g;
1.28 harris41 887: my ($chmod,$chown)=split(/\s/,$categoryhash{$categoryname});
1.26 harris41 888: return $directory="\n<tr><td rowspan='2' bgcolor='#ffffff'>".
889: "$categoryname</td>".
1.29 harris41 890: "<td rowspan='2' bgcolor='#ffffff'><!-- POSTEVAL verify.pl directory /$targetdir $categoryhash{$categoryname} --> </td>".
1.26 harris41 891: "<td rowspan='2' bgcolor='#ffffff'>$chmod<br />$chown</td>".
892: "<td bgcolor='#ffffff'>$thtml</td></tr>".
893: "<tr><td bgcolor='#ffffff' colspan='[{{{{{DPATHLENGTH}}}}}]'>".
894: "$description</td></tr>";
895: }
896: if ($mode eq 'text') {
897: return $directory="\nDIRECTORY $targetdir $categoryname ".
1.10 harris41 898: "$description";
1.3 harris41 899: }
1.4 harris41 900: elsif ($mode eq 'install') {
1.8 harris41 901: return "\t".'install '.$categoryhash{$categoryname}.' -d '.
902: $targetroot.'/'.$targetdir."\n";
1.4 harris41 903: }
1.3 harris41 904: else {
905: return '';
906: }
907: }
908: # ---------------------------------------------------- Format targetdir section
909: sub format_targetdir {
910: my @tokeninfo=@_;
911: $targetdir='';
912: my $text=&trim($parser->get_text('/targetdir'));
913: if ($text) {
914: $parser->get_tag('/targetdir');
915: $targetdir=$text;
916: }
917: return '';
918: }
919: # ------------------------------------------------- Format categoryname section
920: sub format_categoryname {
921: my @tokeninfo=@_;
922: $categoryname='';
923: my $text=&trim($parser->get_text('/categoryname'));
924: if ($text) {
925: $parser->get_tag('/categoryname');
926: $categoryname=$text;
927: }
928: return '';
929: }
930: # -------------------------------------------------- Format description section
931: sub format_description {
932: my @tokeninfo=@_;
933: $description='';
1.10 harris41 934: my $text=&htmlsafe(&trim($parser->get_text('/description')));
1.3 harris41 935: if ($text) {
936: $parser->get_tag('/description');
937: $description=$text;
938: }
939: return '';
940: }
941: # -------------------------------------------------------- Format files section
942: sub format_files {
1.4 harris41 943: my $text=$parser->get_text('/files');
1.3 harris41 944: $parser->get_tag('/files');
945: if ($mode eq 'html') {
1.24 harris41 946: return $directories="\n<br /> <br />".
947: "<a name='files' />".
1.26 harris41 948: "<font size='+2'>Files</font><br /> <br />".
949: "<p>All source and target locations are relative to the ".
950: "sourceroot and targetroot values at the beginning of this ".
951: "document.</p>".
952: "\n<table border='1' cellpadding='5'>".
953: "<tr><th>Status</th><th colspan='2'>Category</th>".
954: "<th>Name/Location</th>".
955: "<th>Description</th><th>Notes</th></tr>".
956: "$text</table>\n".
1.24 harris41 957: "\n";
958: }
959: elsif ($mode eq 'text') {
960: return $directories="\n".
961: "File and Directory Structure".
962: "\n$text\n".
963: "\n";
1.3 harris41 964: }
1.4 harris41 965: elsif ($mode eq 'install') {
966: return "\n".'files:'."\n".$text.
967: "\n".'links:'."\n".join('',@links);
968: }
1.12 harris41 969: elsif ($mode eq 'configinstall') {
970: return "\n".'configfiles: '.
971: join(' ',@configall).
1.14 harris41 972: "\n\n".$text.
973: "\n\nalwaysrun:\n\n";
1.12 harris41 974: }
1.11 harris41 975: elsif ($mode eq 'build') {
976: my $binfo;
977: my $tword;
978: my $command2;
979: my @deps;
980: foreach my $bi (@buildinfo) {
1.14 harris41 981: my ($target,$source,$command,$trigger,@deps)=split(/\;/,$bi);
1.11 harris41 982: $tword=''; $tword=' alwaysrun' if $trigger eq 'always run';
983: $command=~s/\/([^\/]*)$//;
984: $command2="cd $command; sh ./$1;\\";
985: my $depstring;
1.14 harris41 986: my $depstring2="\t\t\@echo '';\\\n";
987: my $olddep;
1.11 harris41 988: foreach my $dep (@deps) {
1.14 harris41 989: unless ($olddep) {
990: $olddep=$deps[$#deps];
991: }
1.11 harris41 992: $depstring.="\telif !(test -r $command/$dep);\\\n";
993: $depstring.="\t\tthen echo ".
1.14 harris41 994: "\"**** WARNING **** missing the file: ".
1.19 harris41 995: "$command/$dep\"$logcmd;\\\n";
1.14 harris41 996: $depstring.="\t\ttest -e $source || test -e $target || echo ".
997: "'**** ERROR **** neither source=$source nor target=".
1.19 harris41 998: "$target exist and they cannot be built'$logcmd;\\\n";
1.14 harris41 999: $depstring.="\t\tmake -f Makefile.build ${source}___DEPS;\\\n";
1000: if ($olddep) {
1001: $depstring2.="\t\tECODE=0;\\\n";
1002: $depstring2.="\t\t! test -e $source && test -r $command/$olddep &&".
1.19 harris41 1003: " { 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 1004: }
1005: $olddep=$dep;
1.11 harris41 1006: }
1007: $binfo.="$source: $tword\n".
1008: "\t\@if !(echo \"\");\\\n\t\tthen echo ".
1.14 harris41 1009: "\"**** WARNING **** Strange shell. ".
1.19 harris41 1010: "Check your path settings.\"$logcmd;\\\n".
1.11 harris41 1011: $depstring.
1012: "\telse \\\n\t\t$command2\n\tfi\n\n";
1.14 harris41 1013: $binfo.="${source}___DEPS:\n".$depstring2."\t\tECODE=0;\n\n";
1.11 harris41 1014: }
1015: return 'all: '.join(' ',@buildall)."\n\n".
1016: $text.
1017: $binfo."\n".
1018: "alwaysrun:\n\n";
1019: }
1.3 harris41 1020: else {
1021: return '';
1022: }
1023: }
1024: # ---------------------------------------------------- Format fileglobs section
1025: sub format_fileglobs {
1026:
1027: }
1028: # -------------------------------------------------------- Format links section
1.4 harris41 1029: # deprecated.. currently <link></link>'s are included in <files></files>
1.3 harris41 1030: sub format_links {
1.4 harris41 1031: my $text=$parser->get_text('/links');
1032: $parser->get_tag('/links');
1033: if ($mode eq 'html') {
1.10 harris41 1034: return $links="\n<br />BEGIN LINKS\n$text\n<br />END LINKS\n";
1.4 harris41 1035: }
1036: elsif ($mode eq 'install') {
1037: return "\n".'links:'."\n\t".$text;
1038: }
1039: else {
1040: return '';
1041: }
1.1 harris41 1042: }
1.3 harris41 1043: # --------------------------------------------------------- Format file section
1044: sub format_file {
1045: my @tokeninfo=@_;
1046: $file=''; $source=''; $target=''; $categoryname=''; $description='';
1047: $note=''; $build=''; $status=''; $dependencies='';
1048: my $text=&trim($parser->get_text('/file'));
1.14 harris41 1049: my $buildtest;
1.29 harris41 1050: $file_count++;
1051: $categorycount{$categoryname}++;
1052: # START TEMP WAY
1053: # if (-T "$sourcerootarg/$source") {
1054: # $linecount{$categoryname}+=`wc -l $sourcerootarg/$source`;
1055: # }
1056: # my $bytesize=(-s "$sourcerootarg/$source");
1057: # $bytecount{$categoryname}+=$bytesize;
1058: # END TEMP WAY
1.3 harris41 1059: if ($source) {
1060: $parser->get_tag('/file');
1061: if ($mode eq 'html') {
1.26 harris41 1062: return ($file="\n<!-- FILESORT:$target -->".
1063: "<tr>".
1.29 harris41 1064: "<td><!-- POSTEVAL verify.pl file '$sourcerootarg' ".
1.28 harris41 1065: "'$targetrootarg' ".
1066: "'$source' '$target' ".
1067: "$categoryhash{$categoryname} --> </td><td>".
1.27 harris41 1068: "<img src='$fab{$categoryname}.gif' ".
1.26 harris41 1069: "alt='$categoryname icon' /></td>".
1.27 harris41 1070: "<td>$categoryname<br /><font size='-1'>".
1071: $categoryhash{$categoryname}."</font></td>".
1.26 harris41 1072: "<td>SOURCE: $source<br />TARGET: $target</td>".
1073: "<td>$description</td>".
1074: "<td>$note</td>".
1075: "</tr>");
1076: # return ($file="\n<br />BEGIN FILE\n".
1077: # "$source $target $categoryname $description $note " .
1078: # "$build $status $dependencies" .
1079: # "\nEND FILE");
1.3 harris41 1080: }
1.5 harris41 1081: elsif ($mode eq 'install' && $categoryname ne 'conf') {
1.14 harris41 1082: if ($build) {
1083: my $bi=$sourceroot.'/'.$source.';'.$build.';'.
1084: $dependencies;
1085: my ($source2,$command,$trigger,@deps)=split(/\;/,$bi);
1086: $tword=''; $tword=' alwaysrun' if $trigger eq 'always run';
1087: $command=~s/\/([^\/]*)$//;
1088: $command2="cd $command; sh ./$1;\\";
1089: my $depstring;
1090: foreach my $dep (@deps) {
1091: $depstring.=<<END;
1092: ECODE=0; DEP=''; \\
1.19 harris41 1093: test -e $command/$dep || (echo '**** WARNING **** cannot evaluate status of dependency $command/$dep (for building ${sourceroot}/${source} with)'$logcmd); DEP="1"; \\
1.18 harris41 1094: [ -n DEP ] && { perl filecompare.pl -b2 $command/$dep ${targetroot}/${target} || ECODE=\$\$?; } || DEP="1"; \\
1.14 harris41 1095: case "\$\$ECODE" in \\
1.19 harris41 1096: 2) echo "**** WARNING **** dependency $command/$dep is newer than target file ${targetroot}/${target}; you may want to run make build"$logcmd;; \\
1.14 harris41 1097: esac; \\
1098: END
1099: }
1100: chomp $depstring;
1101: $buildtest=<<END;
1102: \@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
1.19 harris41 1103: 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 1104: END
1105: $buildtest.=<<END if $depstring;
1106: elif !(test -e "${sourceroot}/${source}"); then \\
1107: $depstring
1108: END
1109: $buildtest.=<<END;
1110: fi
1111: END
1112: }
1.18 harris41 1113: my $bflag='-b1';
1114: $bflag='-b3' if $dependencies or $buildlink;
1.14 harris41 1115: return <<END;
1.19 harris41 1116: $buildtest \@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
1117: echo "**** ERROR **** CVS source file does not exist: ${sourceroot}/${source} and neither does target: ${targetroot}/${target}"$logcmd; \\
1118: elif !(test -e "${sourceroot}/${source}"); then \\
1119: echo "**** WARNING **** CVS source file does not exist: ${sourceroot}/${source}"$logcmd; \\
1.21 harris41 1120: perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\
1.14 harris41 1121: else \\
1122: ECODE=0; \\
1123: perl filecompare.pl $bflag ${sourceroot}/${source} ${targetroot}/${target} || ECODE=\$\$?; \\
1124: case "\$\$ECODE" in \\
1125: 1) echo "${targetroot}/${target} is unchanged";; \\
1.21 harris41 1126: 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 1127: 0) echo "install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target}" && install $categoryhash{$categoryname} ${sourceroot}/${source} ${targetroot}/${target};; \\
1.14 harris41 1128: esac; \\
1.21 harris41 1129: perl verifymodown.pl ${targetroot}/${target} "$categoryhash{$categoryname}"$logcmd; \\
1.14 harris41 1130: fi
1131: END
1.12 harris41 1132: }
1133: elsif ($mode eq 'configinstall' && $categoryname eq 'conf') {
1134: push @configall,$targetroot.'/'.$target;
1.14 harris41 1135: return $targetroot.'/'.$target.': alwaysrun'."\n".
1.20 harris41 1136: "\t".'@echo -n ""; ECODE=0 && { perl filecompare.pl -b4 '.
1137: $sourceroot.'/'.$source.' '.$targetroot.'/'.$target.
1138: ' || ECODE=$$?; } && '.
1139: '{ [ $$ECODE != "2" ] || (install '.
1140: $categoryhash{$categoryname}.' '.
1.12 harris41 1141: $sourceroot.'/'.$source.' '.
1.21 harris41 1142: $targetroot.'/'.$target.'.lpmlnew'.
1.19 harris41 1143: ' && echo "**** NOTE: CONFIGURATION FILE CHANGE ****"'.
1144: $logcmd.' && echo "'.
1.14 harris41 1145: 'You likely need to compare contents of '.
1146: ''.$targetroot.'/'.$target.' with the new '.
1.21 harris41 1147: ''.$targetroot.'/'.$target.'.lpmlnew"'.
1.20 harris41 1148: "$logcmd); } && ".
1149: '{ [ $$ECODE != "3" ] || (install '.
1150: $categoryhash{$categoryname}.' '.
1151: $sourceroot.'/'.$source.' '.
1152: $targetroot.'/'.$target.''.
1153: ' && echo "**** WARNING: NEW CONFIGURATION FILE ADDED ****"'.
1154: $logcmd.' && echo "'.
1155: 'You likely need to review the contents of '.
1156: ''.$targetroot.'/'.$target.' to make sure its '.
1157: 'settings are compatible with your overall system"'.
1158: "$logcmd); } && ".
1159: '{ [ $$ECODE != "1" ] || ('.
1160: 'echo "**** ERROR ****"'.
1161: $logcmd.' && echo "'.
1162: 'Configuration source file does not exist '.
1163: ''.$sourceroot.'/'.$source.'"'.
1.22 harris41 1164: "$logcmd); } && perl verifymodown.pl ${targetroot}/${target} \"$categoryhash{$categoryname}\"$logcmd;\n\n";
1.4 harris41 1165: }
1.11 harris41 1166: elsif ($mode eq 'build' && $build) {
1167: push @buildall,$sourceroot.'/'.$source;
1.14 harris41 1168: push @buildinfo,$targetroot.'/'.$target.';'.$sourceroot.'/'.
1169: $source.';'.$build.';'.
1.11 harris41 1170: $dependencies;
1171: # return '# need to build '.$source.";
1172: }
1.3 harris41 1173: else {
1174: return '';
1175: }
1176: }
1177: return '';
1178: }
1179: # --------------------------------------------------------- Format link section
1180: sub format_link {
1181: my @tokeninfo=@_;
1.27 harris41 1182: $link=''; $linkto=''; $source=''; $target=''; $categoryname='';
1183: $description=''; $note=''; $build=''; $status=''; $dependencies='';
1.3 harris41 1184: my $text=&trim($parser->get_text('/link'));
1.29 harris41 1185: my @links;
1.3 harris41 1186: if ($linkto) {
1187: $parser->get_tag('/link');
1188: if ($mode eq 'html') {
1.27 harris41 1189: my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
1.29 harris41 1190: $link_count+=scalar(@targets);
1.27 harris41 1191: foreach my $tgt (@targets) {
1.29 harris41 1192: $categorycount{$categoryname}++;
1.27 harris41 1193: push @links,("\n<!-- FILESORT:$tgt -->".
1194: "<tr>".
1.29 harris41 1195: "<td><!-- POSTEVAL verify.pl link ".
1.28 harris41 1196: "'/$targetrootarg$linkto' '/$targetrootarg$tgt' ".
1197: "$categoryhash{$categoryname} --> </td><td>".
1.27 harris41 1198: "<img src='$fab{$categoryname}.gif' ".
1199: "alt='$categoryname icon' /></td>".
1200: "<td><font size='-1'>$categoryname</font></td>".
1201: "<td>LINKTO: $linkto<br />TARGET: $tgt</td>".
1202: "<td>$description</td>".
1203: "<td>$note</td>".
1204: "</tr>");
1205: # push @links,"\t".'ln -fs /'.$linkto.' /'.$targetroot.$tgt.
1206: # "\n";
1207: }
1208: return join('',@links);
1209: # return ($link="\n<!-- FILESORT:$target -->".
1210: # "<tr>".
1211: # "<td> </td><td><img src='$fab{$categoryname}.gif' ".
1212: # "alt='$categoryname icon' /></td>".
1213: # "<td>$categoryname</td>".
1214: # "<td>LINKTO: $linkto<br />TARGET: $target</td>".
1215: # "<td>$description</td>".
1216: # "<td>$note</td>".
1217: # "</tr>");
1218: # return $link="\n<tr><td colspan='6'>BEGIN LINK\n".
1219: # "$linkto $target $categoryname $description $note " .
1220: # "$build $status $dependencies" .
1221: # "\nEND LINK</td></tr>";
1.4 harris41 1222: }
1223: elsif ($mode eq 'install') {
1.10 harris41 1224: my @targets=map {s/^\s*//;s/\s$//;$_} split(/\;/,$target);
1.5 harris41 1225: foreach my $tgt (@targets) {
1226: push @links,"\t".'ln -fs /'.$linkto.' /'.$targetroot.$tgt.
1227: "\n";
1228: }
1.4 harris41 1229: return '';
1.3 harris41 1230: }
1231: else {
1232: return '';
1233: }
1234: }
1235: return '';
1236: }
1237: # ----------------------------------------------------- Format fileglob section
1238: sub format_fileglob {
1239: my @tokeninfo=@_;
1240: $fileglob=''; $glob=''; $sourcedir='';
1241: $targetdir=''; $categoryname=''; $description='';
1242: $note=''; $build=''; $status=''; $dependencies='';
1243: $filenames='';
1244: my $text=&trim($parser->get_text('/fileglob'));
1.27 harris41 1245: my $filenames2=$filenames;$filenames2=~s/\s//g;
1.29 harris41 1246: $fileglob_count++;
1247: my @semi=($filenames2=~/(\;)/g);
1248: $fileglobnames_count+=scalar(@semi)+1;
1249: $categorycount{$categoryname}+=scalar(@semi)+1;
1250: # START TEMP WAY
1251: # for my $f (split(/\;/,$filenames2)) {
1252: # if (-T "$sourcerootarg/$sourcedir/$f") {
1253: # $linecount{$categoryname}+=`wc -l $sourcerootarg/$sourcedir/$f`;
1254: # open OUT,">>/tmp/junk123";
1255: # print OUT "$linecount{$categoryname} $categoryname $sourcerootarg/$sourcedir/$f\n";
1256: # close OUT;
1257: # }
1258: # my $bytesize=(-s "$sourcerootarg/$sourcedir/$f");
1259: # $bytecount{$categoryname}+=$bytesize;
1260: # }
1261: # END TEMP WAY
1.3 harris41 1262: if ($sourcedir) {
1263: $parser->get_tag('/fileglob');
1264: if ($mode eq 'html') {
1.27 harris41 1265: return $fileglob="\n<tr>".
1.29 harris41 1266: "<td><!-- POSTEVAL verify.pl fileglob '$sourcerootarg' ".
1.27 harris41 1267: "'$targetrootarg' ".
1268: "'$glob' '$sourcedir' '$filenames2' '$targetdir' ".
1269: "$categoryhash{$categoryname} --> </td>".
1270: "<td>"."<img src='$fab{$categoryname}.gif' ".
1271: "alt='$categoryname icon' /></td>".
1272: "<td>$categoryname<br />".
1273: "<font size='-1'>".$categoryhash{$categoryname}."</font></td>".
1274: "<td>SOURCEDIR: $sourcedir<br />".
1275: "TARGETDIR: $targetdir<br />".
1276: "GLOB: $glob<br />".
1277: "FILENAMES: $filenames".
1278: "</td>".
1279: "<td>$description</td>".
1280: "<td>$note</td>".
1281: "</tr>";
1282: # return $fileglob="\n<tr><td colspan='6'>BEGIN FILEGLOB\n".
1283: # "$glob sourcedir $targetdir $categoryname $description $note ".
1284: # "$build $status $dependencies $filenames" .
1285: # "\nEND FILEGLOB</td></tr>";
1.3 harris41 1286: }
1.5 harris41 1287: elsif ($mode eq 'install') {
1.30 ! harris41 1288: my $eglob=$glob;
! 1289: if ($glob eq '*') {
! 1290: $eglob='[^C][^V][^S]'.$glob;
! 1291: }
1.5 harris41 1292: return "\t".'install '.
1293: $categoryhash{$categoryname}.' '.
1.30 ! harris41 1294: $sourceroot.'/'.$sourcedir.$eglob.' '.
1.5 harris41 1295: $targetroot.'/'.$targetdir.'.'."\n";
1296: }
1.3 harris41 1297: else {
1298: return '';
1299: }
1300: }
1301: return '';
1302: }
1303: # ---------------------------------------------------- Format sourcedir section
1304: sub format_sourcedir {
1305: my @tokeninfo=@_;
1306: $sourcedir='';
1307: my $text=&trim($parser->get_text('/sourcedir'));
1308: if ($text) {
1309: $parser->get_tag('/sourcedir');
1310: $sourcedir=$text;
1311: }
1312: return '';
1313: }
1314: # ------------------------------------------------------- Format target section
1315: sub format_target {
1316: my @tokeninfo=@_;
1317: $target='';
1318: my $text=&trim($parser->get_text('/target'));
1319: if ($text) {
1320: $parser->get_tag('/target');
1321: $target=$text;
1322: }
1323: return '';
1324: }
1325: # ------------------------------------------------------- Format source section
1326: sub format_source {
1327: my @tokeninfo=@_;
1328: $source='';
1329: my $text=&trim($parser->get_text('/source'));
1330: if ($text) {
1331: $parser->get_tag('/source');
1332: $source=$text;
1333: }
1334: return '';
1335: }
1336: # --------------------------------------------------------- Format note section
1337: sub format_note {
1338: my @tokeninfo=@_;
1339: $note='';
1.26 harris41 1340: # my $text=&trim($parser->get_text('/note'));
1341: my $aref;
1342: my $text;
1343: while ($aref=$parser->get_token()) {
1344: if ($aref->[0] eq 'E' && $aref->[1] eq 'note') {
1345: last;
1346: }
1347: elsif ($aref->[0] eq 'S') {
1348: $text.=$aref->[4];
1349: }
1350: elsif ($aref->[0] eq 'E') {
1351: $text.=$aref->[2];
1352: }
1353: else {
1354: $text.=$aref->[1];
1355: }
1356: }
1.3 harris41 1357: if ($text) {
1.26 harris41 1358: # $parser->get_tag('/note');
1.3 harris41 1359: $note=$text;
1360: }
1361: return '';
1362:
1363: }
1364: # -------------------------------------------------------- Format build section
1365: sub format_build {
1366: my @tokeninfo=@_;
1367: $build='';
1368: my $text=&trim($parser->get_text('/build'));
1369: if ($text) {
1370: $parser->get_tag('/build');
1.11 harris41 1371: $build=$sourceroot.'/'.$text.';'.$tokeninfo[2]{'trigger'};
1.3 harris41 1372: }
1373: return '';
1374: }
1.14 harris41 1375: # -------------------------------------------------------- Format build section
1376: sub format_buildlink {
1377: my @tokeninfo=@_;
1378: $buildlink='';
1379: my $text=&trim($parser->get_text('/buildlink'));
1380: if ($text) {
1381: $parser->get_tag('/buildlink');
1382: $buildlink=$sourceroot.'/'.$text;
1383: }
1384: return '';
1385: }
1.3 harris41 1386: # ------------------------------------------------------- Format status section
1387: sub format_status {
1388: my @tokeninfo=@_;
1389: $status='';
1390: my $text=&trim($parser->get_text('/status'));
1391: if ($text) {
1392: $parser->get_tag('/status');
1393: $status=$text;
1394: }
1395: return '';
1396: }
1397: # ------------------------------------------------- Format dependencies section
1398: sub format_dependencies {
1399: my @tokeninfo=@_;
1400: $dependencies='';
1401: my $text=&trim($parser->get_text('/dependencies'));
1402: if ($text) {
1403: $parser->get_tag('/dependencies');
1.11 harris41 1404: $dependencies=join(';',
1405: (map {s/^\s*//;s/\s$//;$_} split(/\;/,$text)));
1.3 harris41 1406: }
1407: return '';
1408: }
1409: # --------------------------------------------------------- Format glob section
1410: sub format_glob {
1411: my @tokeninfo=@_;
1412: $glob='';
1413: my $text=&trim($parser->get_text('/glob'));
1414: if ($text) {
1415: $parser->get_tag('/glob');
1416: $glob=$text;
1417: }
1418: return '';
1419: }
1420: # ---------------------------------------------------- Format filenames section
1421: sub format_filenames {
1422: my @tokeninfo=@_;
1423: my $text=&trim($parser->get_text('/filenames'));
1424: if ($text) {
1425: $parser->get_tag('/filenames');
1426: $filenames=$text;
1427: }
1428: return '';
1429: }
1430: # ------------------------------------------------------- Format linkto section
1431: sub format_linkto {
1432: my @tokeninfo=@_;
1433: my $text=&trim($parser->get_text('/linkto'));
1434: if ($text) {
1435: $parser->get_tag('/linkto');
1436: $linkto=$text;
1437: }
1438: return '';
1.10 harris41 1439: }
1440: # ------------------------------------- Render less-than and greater-than signs
1441: sub htmlsafe {
1442: my $text=@_[0];
1443: $text =~ s/</</g;
1444: $text =~ s/>/>/g;
1445: return $text;
1.3 harris41 1446: }
1447: # --------------------------------------- remove starting and ending whitespace
1448: sub trim {
1449: my ($s)=@_; $s=~s/^\s*//; $s=~s/\s*$//; return $s;
1450: }
1.14 harris41 1451:
1452: # ----------------------------------- POD (plain old documentation, CPAN style)
1.18 harris41 1453:
1454: =head1 NAME
1455:
1456: lpml_parse.pl - This is meant to parse files meeting the lpml document type.
1457: See lpml.dtd. LPML=Linux Packaging Markup Language.
1458:
1459: =head1 SYNOPSIS
1460:
1461: Usage is for lpml file to come in through standard input.
1462:
1463: =over 4
1464:
1465: =item *
1466:
1467: 1st argument is the mode of parsing.
1468:
1469: =item *
1470:
1471: 2nd argument is the category permissions to use (runtime or development)
1472:
1473: =item *
1474:
1475: 3rd argument is the distribution
1476: (default,redhat6.2,debian2.2,redhat7.1,etc).
1477:
1478: =item *
1479:
1480: 4th argument is to manually specify a sourceroot.
1481:
1482: =item *
1483:
1484: 5th argument is to manually specify a targetroot.
1485:
1486: =back
1487:
1488: Only the 1st argument is mandatory for the program to run.
1489:
1490: Example:
1491:
1492: cat ../../doc/loncapafiles.lpml |\\
1493: perl lpml_parse.pl html default /home/sherbert/loncapa /tmp/install
1494:
1495: =head1 DESCRIPTION
1496:
1497: I am using a multiple pass-through approach to parsing
1498: the lpml file. This saves memory and makes sure the server
1499: will never be overloaded.
1500:
1501: =head1 README
1502:
1503: I am using a multiple pass-through approach to parsing
1504: the lpml file. This saves memory and makes sure the server
1505: will never be overloaded.
1506:
1507: =head1 PREREQUISITES
1508:
1509: HTML::TokeParser
1510:
1511: =head1 COREQUISITES
1512:
1513: =head1 OSNAMES
1514:
1515: linux
1516:
1517: =head1 SCRIPT CATEGORIES
1518:
1519: Packaging/Administrative
1520:
1521: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>