From f1b04a20dcf6baedbd0f06a38d8748586d48dbb7 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Sun, 11 May 2014 22:15:55 +0400 Subject: Provide od+sed replacement for the bin2char helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using custom build-time tools is always more problematic, especially for cross-compiling. This alternative implementation assumes "od" (IEEE Std 1003.1-2001) and sed are available which should be the case for any reasonably modern system. Change-Id: I0208f475648c78e7dca127ff4bab60d314b2bf53 Signed-off-by: Paul Fertser Reviewed-on: http://openocd.zylin.com/2139 Tested-by: jenkins Reviewed-by: Fatih Aşıcı Reviewed-by: Andreas Fritiofson --- src/helper/Makefile.am | 11 +--------- src/helper/bin2char.c | 58 -------------------------------------------------- src/helper/bin2char.sh | 14 ++++++++++++ 3 files changed, 15 insertions(+), 68 deletions(-) delete mode 100644 src/helper/bin2char.c create mode 100755 src/helper/bin2char.sh (limited to 'src/helper') diff --git a/src/helper/Makefile.am b/src/helper/Makefile.am index 215bbaed..9477267f 100644 --- a/src/helper/Makefile.am +++ b/src/helper/Makefile.am @@ -44,18 +44,9 @@ noinst_HEADERS = \ replacements.h \ fileio.h \ system.h \ - bin2char.c \ + bin2char.sh \ jim-nvp.h EXTRA_DIST = startup.tcl -BIN2C = bin2char$(EXEEXT_FOR_BUILD) - -BUILT_SOURCES = $(BIN2C) - -$(BIN2C): bin2char.c - ${CC_FOR_BUILD} ${CFLAGS_FOR_BUILD} $(srcdir)/bin2char.c -o $@ - -CLEANFILES = bin2char$(EXEEXT_FOR_BUILD) - MAINTAINERCLEANFILES = $(srcdir)/Makefile.in diff --git a/src/helper/bin2char.c b/src/helper/bin2char.c deleted file mode 100644 index d5fe7f30..00000000 --- a/src/helper/bin2char.c +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005 by Dominic Rath * - * Dominic.Rath@gmx.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - ***************************************************************************/ - -#include -#include - -#ifdef _WIN32 - #include -#endif - -int main(int argc, char **argv) -{ - int c; - unsigned int n; - const char *name; - - if (argc == 1) { - fprintf(stderr, "bin2char \n"); - fprintf(stderr, "read from standard input and write a char" - " array out to standard output\n"); - exit(1); - } - -#ifdef _WIN32 - /* for win32 set stdin/stdout to binary mode */ - _setmode(_fileno(stdin), _O_BINARY); - _setmode(_fileno(stdout), _O_BINARY); -#endif - - n = 0; - name = argv[1]; - fprintf(stdout, "/* autogenerated from %s */\n", argv[0]); - fprintf(stdout, "unsigned const char %s[] = {\n", name); - while ((c = getc(stdin)) != EOF) { - fprintf(stdout, "0x%02x,", c & 0xff); - if ((++n % 16) == 0) - fprintf(stdout, "\n"); - } - fprintf(stdout, "0 /* terminate with a null */};\n"); - return 0; -} diff --git a/src/helper/bin2char.sh b/src/helper/bin2char.sh new file mode 100755 index 00000000..f9da3094 --- /dev/null +++ b/src/helper/bin2char.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +[ $# = 0 ] && { + echo "Usage: $0 " + echo + echo "Read binary data from standard input and write it as a C character" + echo "array to standard output. Add a final NULL for terminating." + exit 1 +} + +echo "/* Autogenerated with $0 */" +echo "unsigned const char $1[] = {" +od -v -A n -t x1 | sed 's/ *\(..\) */0x\1,/g' +echo "0 /* NULL-terminated */ };" -- cgit v1.2.3-18-g5258