From 0641bdb4a55e89acb3dcfb7785df57304d82f155 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Sat, 16 Jun 2018 19:03:23 +0200 Subject: add etrax-tools --- package/etrax-tools/src/e100boot/sbl/cconv | 158 +++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100755 package/etrax-tools/src/e100boot/sbl/cconv (limited to 'package/etrax-tools/src/e100boot/sbl/cconv') diff --git a/package/etrax-tools/src/e100boot/sbl/cconv b/package/etrax-tools/src/e100boot/sbl/cconv new file mode 100755 index 000000000..ce5ab3d70 --- /dev/null +++ b/package/etrax-tools/src/e100boot/sbl/cconv @@ -0,0 +1,158 @@ +#!/usr/bin/perl +#! +#! FILE NAME : cconv +#! +#! PARAMETERS : Name of C program array variable. +#! +#! DESCRIPTION: Converts bytes of a binary file to C source code containing +#! char array initialized with the binary file data. +#! +#! SUBROUTINES: +#! +#!--------------------------------------------------------------------------- +#! HISTORY +#! +#! DATE NAME CHANGES +#! ---- ---- ------- +#! Dec 15 1997 Sven Ekstrom Initial version. Rewritten to Perl from C. +#! Dec 16 1997 Sven Ekstrom Fixed bug that generated truncated result. +#! +#!--------------------------------------------------------------------------- +#! +#! (C) Copyright 1997, Axis Communications AB, LUND, SWEDEN +#! +#!*************************************************************************** +# @(#) cconv 1.2 12/16/97 + +#********************** CONSTANT SECTION ************************************ + +$MyName = 'cconv'; + +# +# Number of bytes per line in the result. +# +$LineLength = 8; + +#********************** MAIN PROGRAM SECTION ******************************** + +# +# Make sure the command line contains the name of a C array. +# +if (scalar @ARGV != 1 || $ARGV[0] =~ /^-/) +{ + die "$MyName: Usage:\n", + "\n", + " Syntax\n", + " $MyName \n", + "\n", + " : This is the name of the char array where\n", + " the result is placed.\n", + "\n", + " Description\n", + "\n", + " Reads input from STDIN as binary data. Each byte of input data is\n", + " converted to C char data in hexadecimal form. The whole file read\n", + " from STDIN is converted and the result, C source code definition of\n", + " a char array, is printed on STDOUT.\n", + "\n"; +} + +# +# Start with the name and version of this program and the name of the array. +# +print "\n", + "/* $MyName 1.2 12/16/97, Copyright (C) 1997, Axis Communications AB */\n", + "\n", + "const char $ARGV[0]\[\] =\n", + "{"; + +# +# Read all bytes from STDIN, convert them to char data and print them on +# STDOUT. +# +$CurrentOffset = 0; +while (!eof(STDIN)) +{ + $Byte = ord(getc); + + if ($CurrentOffset % $LineLength == 0) + { + # + # Start of a new line. + # + if ($CurrentOffset != 0) + { + # + # This is not the first byte. + # + print ","; + } + # + # The new line is indented by 2 spaces. + # + print "\n", + " "; + } + else + { + # + # Continuing an old line. + # + print ", "; + } + + # + # Print the value of the byte as hex char data. + # + printf("'\\x%02x'", $Byte); + + $CurrentOffset++; +} + +if ($CurrentOffset == 0) +{ + # + # Initialize the array with a single byte of zero. + # + print "\n '\\x00'"; +} + +# +# End with the closing bracket and semicolon. +# +print "\n", + "};\n"; + +exit 0; + + +#********************** SUBROUTINE DEFINITION SECTION *********************** + +#**************************************************************************** +#* +#* SUBROUTINE : +#* +#* PARAMETERS : +#* +#* RETURNS : +#* +#* SIDE EFFECTS: +#* +#* DESCRIPTION : +#* +#*--------------------------------------------------------------------------- +#* HISTORY +#* +#* DATE NAME CHANGES +#* ---- ---- ------- +#* May 05, 1995 Sven Ekstrom Initial version +#* +#**************************************************************************** + +#sub NN +#{ +# local() = @_; +# +#} + +#************************ END OF FILE cconv ********************************* -- cgit v1.2.3