#!/usr/bin/ruby -w # Generate the ruby strings that will be embedded into the comments of # each file. This involves splitting one code string to 5 pieces of # varying lengths that will fit within the individual files. $template_sizes = [ # ruby ange09.c "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".size, # ruby charlotte5.c "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".size, # ruby dorothy7.c "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".size, # ruby beatrice7.c "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".size, # ruby chise7.c "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".size, ] # ruby encode.rb template/small_gears.png # # An extra ';' is inserted to make sure ";print" is sorted first. $code = ';print"iVBORw0KGgoAAAANSUhEUgAAAoAAAAFoAQMAAAD9/NgSAAAABlBMVEX////ex5XWC+0GAAAB2UlEQVR42u3XPY7UMByG8X8IUjpcb+WCghZRTbEacxQqToEmkSi4Atwmoy32GhktB/CIJoXlh2IA0a70IlG8vwM8kh1/xBFmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmbPdXqv7U1s6uCuDRb6fxx88TFiziyy4Jv+YWj3eREO9/uwH5IsOBT6UA/TqgqO0MftMG7CII/bYZAFM/Cw3uuCCfi8HocqC/YC66wLzq1klnnRBfsxszytmzhYq26jHAsre53eajZKz33mQqtcRcEE0MqG6MA5JYA1owoysUMkoKq2cp1bJGqRBbdPNRJL1qwcYKVF7pElN98AQI/SonTVkOllYU/tJAm2BD1DLe0omcOWgQx1blkyh60AI9eNLrlKR+C8j7y+0CVX6QCcW7ybzpBEJzaXHjE9wKRZ2DvXHjE+wBfJZc/1B/U2l5pgvlzZIyZZsFzqn6DkQCxPlVUapLJFjE+QJEOegO32lTXBBETEqNop8fJXcKO/0tz0t+CgOm0iuD16amlF9cdZI2LYU581wbtvS0QMLZLoeTZ8vf1ByIK/F/iSmjZYRRf9X6+BVRoc/0FwCe0kar9JxN0aZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmz/ATDls1VaHR738AAAAASUVORK5CYII=".unpack("m")[0]'; $margin = $template_sizes.sum - $code.size if $margin < 0 print "Code is too big (#{$code.size} > #{$template_sizes.sum})\n" exit 1 end def final_split(prefix_length, parts) end def recursive_split(index, sizes, prefix_length, remaining_margin, parts) # Verify that part satisfies sort requirement. current_part = $code[prefix_length, $code.size - prefix_length] if index > 0 and current_part <= parts[index - 1] return end # There are actually quite a few splits to choose from, so for # aesthetics, we also require that parts begin with lowercase. if not (/^[;a-z]/.match(current_part)) return end if index == 4 # Add the final part and output results. We don't need to test # different lengths for the final part, since it gets whatever is left. parts.append(current_part) print "\nSizes = ", parts.map{|x| x.size} * ", ", "\n", "Margin = ", (0..(sizes.size - 1)).map{|i| sizes[i] - parts[i].size} * ", ", "\n" parts.size.times{|i| print "[#{i}] = '#{parts[i]}'\n" } return end # Try different lengths for all parts before the final part. # # Maximum length we can use is the length of the template for the # current part (from sizes array), and minimum length is that # number minus the remaining margin. We can't go smaller than the # remaining margin, because out would mean that the remaining # templates won't be big enough to hold the remaining pieces. (0..remaining_margin).each{|i| # Due to tight layout of dorothy7.c, we are not taking on # any margins for that file. if sizes[index] == 73 and i > 0 return end part_length = sizes[index] - i part = $code[prefix_length, part_length] recursive_split(index + 1, sizes, prefix_length + part_length, remaining_margin - i, parts + [part]) } end $template_sizes.permutation.each{|sizes| recursive_split(0, sizes, 0, $margin, []) }