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