ce5ab3d705689aaa284538a621f623666b651c04
5 #! PARAMETERS : Name of C program array variable.
7 #! DESCRIPTION: Converts bytes of a binary file to C source code containing
8 #! char array initialized with the binary file data.
12 #!---------------------------------------------------------------------------
17 #! Dec 15 1997 Sven Ekstrom Initial version. Rewritten to Perl from C.
18 #! Dec 16 1997 Sven Ekstrom Fixed bug that generated truncated result.
20 #!---------------------------------------------------------------------------
22 #! (C) Copyright 1997, Axis Communications AB, LUND, SWEDEN
24 #!***************************************************************************
25 # @(#) cconv 1.2 12/16/97
27 #********************** CONSTANT SECTION ************************************
32 # Number of bytes per line in the result.
36 #********************** MAIN PROGRAM SECTION ********************************
39 # Make sure the command line contains the name of a C array.
41 if (scalar @ARGV != 1 || $ARGV[0] =~ /^-/)
43 die "$MyName: Usage:\n",
46 " $MyName <name of C char array>\n",
48 " <name of C char array> : This is the name of the char array where\n",
49 " the result is placed.\n",
53 " Reads input from STDIN as binary data. Each byte of input data is\n",
54 " converted to C char data in hexadecimal form. The whole file read\n",
55 " from STDIN is converted and the result, C source code definition of\n",
56 " a char array, is printed on STDOUT.\n",
61 # Start with the name and version of this program and the name of the array.
64 "/* $MyName 1.2 12/16/97, Copyright (C) 1997, Axis Communications AB */\n",
66 "const char $ARGV[0]\[\] =\n",
70 # Read all bytes from STDIN, convert them to char data and print them on
78 if ($CurrentOffset % $LineLength == 0)
81 # Start of a new line.
83 if ($CurrentOffset != 0)
86 # This is not the first byte.
91 # The new line is indented by 2 spaces.
99 # Continuing an old line.
105 # Print the value of the byte as hex char data.
107 printf("'\\x%02x'", $Byte);
112 if ($CurrentOffset == 0)
115 # Initialize the array with a single byte of zero.
121 # End with the closing bracket and semicolon.
129 #********************** SUBROUTINE DEFINITION SECTION ***********************
131 #****************************************************************************
143 #*---------------------------------------------------------------------------
148 #* May 05, 1995 Sven Ekstrom Initial version
150 #****************************************************************************
158 #************************ END OF FILE cconv *********************************
This page took 0.050359 seconds and 3 git commands to generate.