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