<commit_before>#!/usr/bin/env ruby
#
# Copied from the TextMate HTML Bundle
#

require "zlib"

# Test for broken pack/unpack
if [1].pack('n') == "\001\000"
  class String
    alias_method :broken_unpack, :unpack
    def unpack(spec)
      broken_unpack(spec.tr("nNvV","vVnN"))
    end
  end
  class Array
    alias_method :broken_pack, :pack
    def pack(spec)
      broken_pack(spec.tr("nNvV","vVnN"))
    end
  end
end

class Swf
  
  @bits
  @width
  @height
  @version
  @bgcolor
  @buffer
  @zip
  @trace
  
  attr_reader :width
  attr_reader :height
  attr_reader :version
  attr_reader :bgcolor
  attr_reader :zip
  attr_reader :trace
  
  def initialize(f)
    @bits = ""
    
    @buffer = File.new(f,"r").read
    @zip = ("" << @buffer.slice(0)) == "C"
    @version = @buffer.slice(3).to_i
    
    #@trace = @buffer.slice(7)
    
    #Need to find out what we are cutting here.
    @buffer.slice!(0..7)
    
    if @zip
      @buffer = Zlib::Inflate.inflate(@buffer)
    end
    
    nbits = getBits(5)
    xmin = getBits(nbits)
    xmax = getBits(nbits)
    ymin = getBits(nbits)
    ymax = getBits(nbits)
    
    #mFrameRate = (float)swf.ReadByte() / 256;
    #mFrameRate += swf.ReadByte();
    
    @width = (xmax - xmin) / 20
    @height = (ymax - ymin) / 20
    
    @buffer.slice!(0..3)
    
    @bits = ""
    
    while(true)
      tag = getNextTag()
      if(tag[:id] == 9)
        @bgcolor = sprintf("#%02X%02X%02X", tag[:data][0], tag[:data][1], tag[:data][2])
        break
      end
    end
    <commit_msg>Extending comments to include links to swf file format documentation. Adding further definitions for swf format.<commit_after>#!/usr/bin/env ruby
#
# Copied from the TextMate HTML Bundle
#

require "zlib"

# Test for broken pack/unpack
if [1].pack('n') == "\001\000"
  class String
    alias_method :broken_unpack, :unpack
    def unpack(spec)
      broken_unpack(spec.tr("nNvV","vVnN"))
    end
  end
  class Array
    alias_method :broken_pack, :pack
    def pack(spec)
      broken_pack(spec.tr("nNvV","vVnN"))
    end
  end
end

class Swf
  
  @bits
  @width
  @height
  @version
  @bgcolor
  @buffer
  @zip
  @trace
  
  attr_reader :width
  attr_reader :height
  attr_reader :version
  attr_reader :bgcolor
  attr_reader :zip
  attr_reader :trace
  
  def initialize(f)
    @bits = ""
    
    @buffer = File.new(f,"r").read
    @zip = ("" << @buffer.slice(0)) == "C"
    @version = @buffer.slice(3).to_i
    
    #@trace = @buffer.slice(7)
    
    #Need to find out what we are cutting here.
    @buffer.slice!(0..7)
    
    if @zip
      @buffer = Zlib::Inflate.inflate(@buffer)
    end
    
    nbits = getBits(5)
    xmin = getBits(nbits)
    xmax = getBits(nbits)
    ymin = getBits(nbits)
    ymax = getBits(nbits)
    
    #mFrameRate = (float)swf.ReadByte() / 256;
    #mFrameRate += swf.ReadByte();
    
    @width = (xmax - xmin) / 20
    @height = (ymax - ymin) / 20
    
    @buffer.slice!(0..3)
    
    @bits = ""
    
    while(true)
		tag = getNextTag()

		# For an AS3 implementation:
		# http://flashpanoramas.com/blog/2007/07/02/swf-parser-air-application/		
		# There's also a C# version somewhere.
		
		# See http://the-labs.com/MacromediaFlash/SWF-Spec/SWFfilereference.html
		# For details of file format, id "Tag ID = 9" is Background Colour.
      
		if(tag[:id] == 9)
			@bgcolor = sprintf("#%02X%02X%02X", tag[:data][0], tag[:data][1], tag[:data][2])
			break
		elsif(tag[:id] == 39)
			# DefineSprite.
			break			
		elsif(tag[:id] == 43)
			# Frame Label, SWF 3 Only.
			break
		elsif(tag[:id] == 76)
			# SymbolClass.
			break						
		elsif(tag[:id] == 77)
			# Metadata.
			break
		end
    end
    
{'fraction_non_alphanumeric': 0.14558342420937842, 'fraction_numerical': 0.02262813522355507, 'mean_word_length': 2.461320754716981, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3680457', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1412, 'n_words': 310}