12bde8e466a4451c7319e3a072d118917957d6554Steve Block#! /usr/bin/perl 22bde8e466a4451c7319e3a072d118917957d6554Steve Block 32bde8e466a4451c7319e3a072d118917957d6554Steve Block# Copyright (C) 2010-2011 Google Inc. All rights reserved. 42bde8e466a4451c7319e3a072d118917957d6554Steve Block# 52bde8e466a4451c7319e3a072d118917957d6554Steve Block# Redistribution and use in source and binary forms, with or without 62bde8e466a4451c7319e3a072d118917957d6554Steve Block# modification, are permitted provided that the following conditions are 72bde8e466a4451c7319e3a072d118917957d6554Steve Block# met: 82bde8e466a4451c7319e3a072d118917957d6554Steve Block# 92bde8e466a4451c7319e3a072d118917957d6554Steve Block# # Redistributions of source code must retain the above copyright 102bde8e466a4451c7319e3a072d118917957d6554Steve Block# notice, this list of conditions and the following disclaimer. 112bde8e466a4451c7319e3a072d118917957d6554Steve Block# # Redistributions in binary form must reproduce the above 122bde8e466a4451c7319e3a072d118917957d6554Steve Block# copyright notice, this list of conditions and the following disclaimer 132bde8e466a4451c7319e3a072d118917957d6554Steve Block# in the documentation and/or other materials provided with the 142bde8e466a4451c7319e3a072d118917957d6554Steve Block# distribution. 152bde8e466a4451c7319e3a072d118917957d6554Steve Block# # Neither the name of Google Inc. nor the names of its 162bde8e466a4451c7319e3a072d118917957d6554Steve Block# contributors may be used to endorse or promote products derived from 172bde8e466a4451c7319e3a072d118917957d6554Steve Block# this software without specific prior written permission. 182bde8e466a4451c7319e3a072d118917957d6554Steve Block# 192bde8e466a4451c7319e3a072d118917957d6554Steve Block# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 202bde8e466a4451c7319e3a072d118917957d6554Steve Block# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 212bde8e466a4451c7319e3a072d118917957d6554Steve Block# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 222bde8e466a4451c7319e3a072d118917957d6554Steve Block# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 232bde8e466a4451c7319e3a072d118917957d6554Steve Block# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 242bde8e466a4451c7319e3a072d118917957d6554Steve Block# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 252bde8e466a4451c7319e3a072d118917957d6554Steve Block# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 262bde8e466a4451c7319e3a072d118917957d6554Steve Block# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 272bde8e466a4451c7319e3a072d118917957d6554Steve Block# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 282bde8e466a4451c7319e3a072d118917957d6554Steve Block# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 292bde8e466a4451c7319e3a072d118917957d6554Steve Block# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 302bde8e466a4451c7319e3a072d118917957d6554Steve Block# 312bde8e466a4451c7319e3a072d118917957d6554Steve Block 322bde8e466a4451c7319e3a072d118917957d6554Steve Block$varname = shift; 332bde8e466a4451c7319e3a072d118917957d6554Steve Block$fname = shift; 342bde8e466a4451c7319e3a072d118917957d6554Steve Block$output = shift; 352bde8e466a4451c7319e3a072d118917957d6554Steve Block 362bde8e466a4451c7319e3a072d118917957d6554Steve Blockopen($input, '<', $fname) or die "Can't open file for read: $fname $!"; 372bde8e466a4451c7319e3a072d118917957d6554Steve Block$/ = undef; 382bde8e466a4451c7319e3a072d118917957d6554Steve Block$text = <$input>; 392bde8e466a4451c7319e3a072d118917957d6554Steve Blockclose($input); 402bde8e466a4451c7319e3a072d118917957d6554Steve Block 412bde8e466a4451c7319e3a072d118917957d6554Steve Block$text = join(', ', map('0x' . unpack("H*", $_), split(undef, $text))); 422bde8e466a4451c7319e3a072d118917957d6554Steve Block 432bde8e466a4451c7319e3a072d118917957d6554Steve Blockopen($output, '>', $output) or die "Can't open file for write: $output $!"; 442bde8e466a4451c7319e3a072d118917957d6554Steve Blockprint $output "const unsigned char $varname\[\] = {\n$text\n};\n"; 452bde8e466a4451c7319e3a072d118917957d6554Steve Blockclose($output); 46