Может кому-нибудь пригодится: #!/bin/sh export LC_ALL=C if [ $# -ne 2 ]; then echo "Invalid number of arguments!" >&2 echo "Usage:" echo " ${0} <input file> <C variable name>" echo " If <input file> is -, read standard input." echo "Example:" echo " ${0} ${0} bin2c" echo " This command will create files bin2c.h and bin2c.c with" echo " variables 'const unsigned char *const bin2c;' and" echo " 'const size_t bin2c_size;'." exit 1 fi od --width=8 -A n -v -t x1 "${1}" | ( echo "/* ${0} \"${1}\" \"${2}\" */" echo echo "#include \"${2}.h\"" echo echo -n "const unsigned char *const ${2} = (unsigned char []) {" bytes=0 l_end="" while read line; do echo "${l_end}" l_begin=" " for code in $line; do echo -n "${l_begin}0x${code}" l_begin=", " bytes=$(( $bytes + 1 )) done l_end="," done echo "};" echo echo "const size_t ${2}_size = ${bytes};" echo ) > "${2}.c" ( echo "/* ${0} \"${1}\" \"${2}\" */" echo echo "#include <stddef.h>" echo echo "extern const unsigned char *const ${2};" echo "extern const size_t ${2}_size;" echo ) > "${2}.h"
Ответ на:
комментарий
от anonymous
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.
Похожие темы
- Форум Проблемы с gcc в Mandrake 10.1 (2005)
- Форум Кодирование и декодирование base64 на Си (2024)
- Форум Почему не видно устройства, и как исправить это? (2017)
- Форум boost.asio, boost.serialization (2010)
- Форум Не работает линкер. (2007)
- Форум ChatGPT (2023)
- Форум Не собираются пакеты в Cygwin | ошибка: несовместимые типы (2017)
- Форум php-q (2013)
- Форум GCC 11 дает предупреждение только при определенном порядке аргументов, баг? (2021)
- Форум [php5][expat] где мои entity? (2008)