bm2menu.pl (1027B)
1 #!/usr/bin/perl 2 3 $PRE_MENU = ""; 4 $POST_MENU = <<EOF; 5 nop "----------------------" 6 func "ブックマークに追加 (a)" ADD_BOOKMARK "aA" 7 EOF 8 # $POST_MENU = <<EOF; 9 # nop "----------------------" 10 # func "Add Bookmark (a)" ADD_BOOKMARK "aA" 11 # EOF 12 13 @section = (); 14 %title = (); 15 %url = (); 16 while(<>) { 17 if (/<h2>(.*)<\/h2>/) { 18 $s = &unquote($1); 19 push(@section, $s); 20 } elsif (/<li><a href=\"(.*)\">(.*)<\/a>/) { 21 $u = &unquote($1); 22 $t = &unquote($2); 23 $url{$s} .= "$u\n"; 24 $title{$s} .= "$t\n"; 25 } 26 } 27 28 print "menu Bookmarks\n"; 29 print $PRE_MENU; 30 foreach(@section) { 31 print " popup\t\"$_\"\t\"$_\"\n"; 32 } 33 print $POST_MENU; 34 print "end\n"; 35 36 foreach(@section) { 37 print "\n"; 38 print "menu \"$_\"\n"; 39 @ts = split("\n", $title{$_}); 40 @us = split("\n", $url{$_}); 41 while(@ts) { 42 $t = shift @ts; 43 $u = shift @us; 44 print " func\t\"$t\"\tGOTO\t\"\"\t\"$u\"\n"; 45 } 46 print "end\n"; 47 } 48 49 sub unquote { 50 local($_) = @_; 51 52 s/\</\</g; 53 s/\>/\>/g; 54 s/\ / /g; 55 s/\&/\&/g; 56 57 return $_; 58 }