mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
4.8 KiB

  1. #!/usr/bin/perl
  2. #
  3. # re-run this scrip if hosted_freedict.txt has changed
  4. # generates hosted_freedict.{desc,sel,cfg}
  5. #
  6. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  7. #
  8. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  9. # Please add additional copyright information _after_ the line containing
  10. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  11. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  12. #
  13. # ROCK Linux: rock-src/package/import/freedict/hosted_freedict.pl
  14. # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  15. #
  16. # This program is free software; you can redistribute it and/or modify
  17. # it under the terms of the GNU General Public License as published by
  18. # the Free Software Foundation; either version 2 of the License, or
  19. # (at your option) any later version. A copy of the GNU General Public
  20. # License can be found at Documentation/COPYING.
  21. #
  22. # Many people helped and are helping developing ROCK Linux. Please
  23. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  24. # file for details.
  25. #
  26. # --- ROCK-COPYRIGHT-NOTE-END ---
  27. use warnings;
  28. use strict;
  29. use XML::Parser;
  30. our $baseurl="http://jaist.dl.sourceforge.net/sourceforge/freedict/";
  31. our (%hosted,%lang,$current);
  32. my $p= new XML::Parser( Handlers => { Start => start_handler() } );
  33. %lang=(
  34. afr => 'Afrikaans',
  35. cro => 'Croatian',
  36. cze => 'Czech',
  37. dan => 'Danish',
  38. nld => 'Dutch',
  39. eng => 'English',
  40. deu => 'German',
  41. fra => 'French',
  42. ara => 'Arabic',
  43. hin => 'Hindi',
  44. hun => 'Hungarian',
  45. iri => 'Irish',
  46. ita => 'Italian',
  47. lat => 'Latin',
  48. por => 'Portuguese',
  49. rom => 'Romanian',
  50. rus => 'Russian',
  51. san => 'Sanskrit',
  52. sco => 'Scottish',
  53. slo => 'Slovak',
  54. spa => 'Spanish',
  55. swa => 'Swahili',
  56. swe => 'Swedish',
  57. wel => 'Welsh',
  58. jpn => 'Japanese',
  59. kha => 'Khasi',
  60. scr => 'Serbo-Croat',
  61. tur => 'Turkish' );
  62. my $database='download/mirror/f/freedict-database-20050726.xml';
  63. die 'Please download freedict dictionary list with "./scripts/Download freedict" and try again.'
  64. unless -f $database;
  65. $p->parsefile($database); # No need, to say die.
  66. my %cksum_cache;
  67. open(D, "package/import/freedict/hosted_freedict.desc");
  68. while (<D>) {
  69. $cksum_cache{$2} = $1 if /^\[D\] (\d+) (\S+)/;
  70. }
  71. close D;
  72. open(D, ">package/import/freedict/hosted_freedict.desc") || die $!;
  73. open(S, ">package/import/freedict/hosted_freedict.sel") || die $!;
  74. open(C, ">package/import/freedict/hosted_freedict.cfg") || die $!;
  75. print D "# Auto-generated by hosted_freedict.pl from $database\n";
  76. print S "# Auto-generated by hosted_freedict.pl from $database\n";
  77. print C "# Auto-generated by hosted_freedict.pl from $database\n";
  78. print S "\ncase \"\$xpkg\" in\n";
  79. print D "\n";
  80. print C "\n";
  81. foreach my $name ( sort keys %hosted ){
  82. my $dict=$hosted{$name};
  83. next unless $dict->{'file'};
  84. if( $ARGV[0] ){
  85. print "# $name: $dict->{'fullname'} $dict->{'version'} $dict->{'file'}\n";
  86. print "./scripts/Build-Pkg freedict-$name\n";
  87. }
  88. my $f =$dict->{'file'};
  89. my $fn=$dict->{'fullname'};
  90. my $v =$dict->{'version'};
  91. my $ydict=uc $name;
  92. $ydict=~ s/\-/_/g;
  93. my $c = 0;
  94. $c = $cksum_cache{"freedict-$name-$v.tar.gz"}
  95. if defined $cksum_cache{"freedict-$name-$v.tar.gz"};
  96. print D "#if xpkg == freedict-$name\n";
  97. print D "[I] $fn dictionary\n";
  98. print D '[T] headwords: '.$dict->{'headwords'}."\n";
  99. print D '[U] '.$dict->{'url'}."\n" if $dict->{'url'};
  100. print D "[V] $v\n";
  101. print D "[D] $c freedict-$name-$v.tar.gz !$baseurl$f\n";
  102. print D "#endif\n\n";
  103. print S "\tfreedict-$name)\n";
  104. print S "\t\tfreedict=\"$name\"\n";
  105. print S "\t\tfreedictver=\"$v\"\n";
  106. print S "\t\tsrctar=\"freedict-$name-$v.tar.bz2\"\n";
  107. print S "\t\t;;\n";
  108. print C "bool 'Building package freedict-$name ($fn)' ROCKCFG_PKG_FREEDICT_$ydict 1\n";
  109. print C "if [ \$ROCKCFG_PKG_FREEDICT_$ydict = 1 ]; then pkgfork freedict freedict-$name priority 700.000; fi\n\n"
  110. }
  111. print S "esac\n\n";
  112. close D; close S;
  113. close C;
  114. #########################
  115. sub start_handler{ sub{
  116. #########################
  117. my $expat=shift;
  118. my $tag =shift;
  119. my %attr =@_;
  120. if( $tag eq 'dictionary' ){
  121. my %dict=();
  122. $current=$attr{'name'};
  123. my ($source,$target)=split /-/,$current;
  124. warn "Unknown source language $source" unless $lang{$source};
  125. warn "Unknown target language $target" unless $lang{$target};
  126. $dict{'fullname'}="$lang{$source}-$lang{$target}";
  127. $dict{'headwords'}=$attr{'headwords'};
  128. $dict{'url'}= $attr{'sourceURL'} =~ /freedict/ ? undef : $attr{'sourceURL'};
  129. $dict{'version'}=$attr{'edition'};
  130. $hosted{$current}=\%dict;
  131. }
  132. if( $tag eq 'release' ){
  133. if( $attr{'platform'} eq "dict-tgz" ){
  134. my $file= $attr{'URL'} =~ m'freedict/([^\?]+)\?download' && $1;
  135. $hosted{$current}->{'file'}=$file;
  136. }
  137. }
  138. }}