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