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