Changeset 688

Show
Ignore:
Timestamp:
10/24/07 22:59:25 (6 years ago)
Author:
cho45
Message:

lang/ruby/chm/lib/chm.rb:

Gauche のやつがよめないのでデバッグしまくり。
Chmox のコードを移植しなおし (PyCHM は不完全だった)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/chm/lib/chm.rb

    r683 r688  
    5858 
    5959                index = {} 
    60                 text.scan(/<OBJECT type="text\/sitemap">(.+?)<\/OBJECT>/m) do |m| 
    61                         local = m[0][/<param name="Local" value="([^"]+)">/, 1] 
    62                         m[0].scan(/<param name="Name" value="([^"]+)">/) do |n| 
     60                text.scan(/<OBJECT\s+type="text\/sitemap">(.+?)<\/OBJECT>/m) do |m| 
     61                        local = m[0][/<param\s+name="Local"\s+value="([^"]+)">/, 1] 
     62                        m[0].scan(/<param\s+name="Name"\s+value="([^"]+)">/) do |n| 
    6363                                n = n[0] 
    6464                                next unless n 
     
    8787                        case s[1] 
    8888                        when "LI" 
    89                                 s.skip(%r{<OBJECT type="text/sitemap">\s*}) 
    90                                 s.scan(%r{<param name="Name" value="([^"]+)">\s*(<param name="Local" value="([^"]+)">)?\s*}) 
     89                                s.skip(%r{<OBJECT\s+type="text/sitemap">\s*}) 
     90                                s.scan(%r{<param\s+name="Name"\s+value="([^"]+)">\s*(<param\s+name="Local"\s+value="([^"]+)">)?\s*}) 
    9191                                current << { 
    9292                                        :name   => unescape!(s[1]), 
     
    185185 
    186186        def get_windows_info 
    187                 text = retrieve_object("/#WINDOWS") 
    188                 num_entries, entry_size = text.unpack("VV") 
    189  
    190                 return if num_entries < 1 
    191  
    192                 text = retrieve_object("/#WINDOWS", 8, entry_size) 
    193                 return if text.length <  entry_size 
    194  
    195                 toc_index, idx_index, dft_index = text.unpack("V3") 
    196  
    197                 text = retrieve_object("/#STRINGS") 
    198  
    199                 unless @topics 
    200                         @topics = text[toc_index..-1].unpack("Z*") 
    201                         @topics = "/#{@topics}" unless @topics[0] == ?/ 
    202                 end 
    203  
    204                 unless @index 
    205                         @index = text[tdx_index..-1].unpack("Z*") 
    206                         @index = "/#{@index}" unless @index[0] == ?/ 
    207                 end 
    208  
    209                 unless dft_index == 0 
    210                         @home = text[dft_index..-1].unpack("Z*") 
    211                         @home = "/#{@home}" unless @home[0] == ?/ 
    212                 end 
     187                # logic from Chmox 
     188                windowsData = retrieve_object("/#WINDOWS") 
     189                stringsData = retrieve_object("/#STRINGS") 
     190 
     191                if !windowsData.empty? && !stringsData.empty? 
     192                        entryCount, entrySize = windowsData.unpack("VV") 
     193                        #p "Entries: %d x %d bytes" % [entryCount, entrySize] 
     194 
     195                        entryIndex = 0 
     196                        while entryIndex < entryCount 
     197                                entryOffset = 8 + ( entryIndex * entrySize ); 
     198 
     199                                #_title = readTrimmedString( stringsData, readLong( windowsData, entryOffset + 0x14 ) ); 
     200                                toc_index, idx_index, dft_index = windowsData[entryOffset+0x60,12].unpack("V3") 
     201                                @topics = stringsData[toc_index..-1].unpack("Z*")[0] if @topics.nil? || @topics.empty? 
     202                                @index  = stringsData[idx_index..-1].unpack("Z*")[0] if @index.nil?  || @index.empty? 
     203                                @home   = stringsData[dft_index..-1].unpack("Z*")[0] if @home.nil?   || @home.empty? 
     204                                entryIndex += 1 
     205                        end 
     206                end 
     207                @topics = "/#{@topics}" unless @topics[0] == ?/ 
     208                @index  = "/#{@index}"  unless @index[0]  == ?/ 
     209                @home   = "/#{@home}"   unless @home[0]   == ?/ 
    213210        rescue ResolvError 
    214211        end 
     
    242239        pp chm.home 
    243240        #pp chm.topics 
     241        chm = Chmlib::Chm.new("/Users/cho45/htmlhelp/gauche-refj-0.8.7.chm") 
     242        pp chm.home 
     243        pp chm.instance_eval { @index } 
     244        pp chm.index 
     245        #pp chm.topics 
    244246end