generate-rdf.pl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. use File::Spec;
  2. my(@chunks, @list, $entry, $main_cats, $spacing);
  3. @list = ('conf', 'perf');
  4. foreach $entry (@list) {
  5. $main_cats .= " <rdf:li><rdf:Description about=\"urn:x-buster:$entry\" nc:dir=\"$entry\" /></rdf:li>\n";
  6. go_in($entry, '', $entry);
  7. }
  8. if ($ARGV[0]) {
  9. open OUTPUT, ">$ARGV[0]";
  10. }
  11. else {
  12. open OUTPUT, ">xalan.rdf";
  13. };
  14. select(OUTPUT);
  15. print '<?xml version="1.0"?>
  16. <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  17. xmlns:nc="http://home.netscape.com/NC-rdf#">
  18. <rdf:Seq about="urn:root">
  19. ' . $main_cats . ' </rdf:Seq>
  20. ';
  21. print join('',@chunks);
  22. print '</rdf:RDF>
  23. ';
  24. exit 0;
  25. sub go_in {
  26. my($current, $about, $cat) = @_;
  27. my (@list, $entry, @subdirs, @files, @purps, $rdf);
  28. chdir $current;
  29. @list = <*>;
  30. LOOP: foreach $entry (@list) {
  31. next LOOP if $entry=~/^CVS$/;
  32. if (! -d $entry) {
  33. if ($entry=~/^($current.*)\.xsl$/) {
  34. local $source = $entry;
  35. $source=~s/xsl$/xml/;
  36. next LOOP if ! -f $source;
  37. $entry=~/^($current.*)\.xsl$/;
  38. push(@files, $1);
  39. local ($purp, $purp_open);
  40. open STYLE, $entry;
  41. $purp_open = 0;
  42. while (<STYLE>) {
  43. if (/<!--\s+purpose: (.+)\s*-->/i) {
  44. $purp .= $1;
  45. }
  46. elsif (/<!--\s+purpose: (.+)\s*$/i) {
  47. $purp_open = 1;
  48. $purp .= $1;
  49. }
  50. elsif ($purp_open) {
  51. if (/\s*(\s.+)\s*-->/) {
  52. $purp_open = 0;
  53. $purp .= $1;
  54. }
  55. elsif (/\s*(\s.+)\s*$/) {
  56. $purp .= $1;
  57. }
  58. }
  59. }
  60. $purp=~s/"/'/g; $purp=~s/&/&amp;/g; $purp=~s/</&lt;/g;
  61. $purp=~s/\r/ /g; $purp=~s/\s\s/ /g; $purp=~s/\s$//g;
  62. push(@purps, $purp);
  63. }
  64. }
  65. else {
  66. push(@subdirs, $entry);
  67. }
  68. }
  69. if (@subdirs > 0 || @files > 0) {
  70. my $topic = $about.$current; $topic=~s/\///g;
  71. $rdf = ' <rdf:Seq about="urn:x-buster:'.$topic."\">\n";
  72. foreach $entry (@subdirs) {
  73. if (go_in($entry, $about.$current.'/', $cat)) {
  74. my $id = 'urn:x-buster:'.$about.$current.$entry; $id=~s/\///g;
  75. $rdf .= " <rdf:li><rdf:Description about=\"$id\" nc:dir=\"$entry\" /></rdf:li>\n";
  76. }
  77. }
  78. for (my $i=0; $i < @files; $i++) {
  79. my $uri = $about.$current.'/'.$files[$i];
  80. $uri=~s/[^\/]+\///;
  81. my $id = $uri; $id=~s/\///g;
  82. $rdf .= " <rdf:li><rdf:Description about=\"urn:x-buster:$files[$i]\" nc:name=\"$files[$i]\" nc:purp=\"$purps[$i]\" nc:path=\"$uri\" nc:category=\"$cat\" /></rdf:li>\n";
  83. }
  84. $rdf .= " </rdf:Seq>\n";
  85. push(@chunks, $rdf);
  86. }
  87. chdir File::Spec->updir;
  88. return (@subdirs > 0 || @files > 0);
  89. }