bin2c.c revision c97989161fbe75bc14cea477a5443bbf474dd3ad
/* $Id$ */
/** @file
* PC-BIOS - Binary 2 C Structure Converter.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/**
* File size.
*
* @returns file size in bytes.
* @returns 0 on failure.
* @param pFile File to size.
*/
{
long cbFile;
if ( Pos >= 0
{
if ( cbFile >= 0
return cbFile;
}
return 0;
}
{
int i;
int fAscii = 0;
int fExport = 0;
unsigned char abLine[16];
if (argc < 2)
goto syntax_error;
for (i=1; i<argc; i++)
{
{
if (++i>=argc)
goto syntax_error;
continue;
}
{
if (++i>=argc)
goto syntax_error;
continue;
}
{
if (++i>=argc)
goto syntax_error;
continue;
}
{
fAscii = 1;
continue;
}
{
fExport = 1;
continue;
}
else if (i==argc-3)
break;
"Syntax: %s [options] <arrayname> <binaryfile> <outname>\n"
" -min <n> check if <binaryfile> is not smaller than <n>KB\n"
" -max <n> check if <binaryfile> is not bigger than <n>KB\n"
" -mask <n> check if size of binaryfile is <n>-aligned\n"
" -ascii show ASCII representation of binary as comment\n",
argv[0]);
return 1;
}
if (!pFileIn)
{
return 1;
}
if (!pFileOut)
{
return 1;
}
"/*\n"
" * This file was automatically generated\n"
" * from %s by\n"
" * by %s.\n"
" */\n"
"\n"
"\n"
"%sconst unsigned char%s g_ab%s[] =\n"
"{\n",
/* check size restrictions */
{
return 1;
}
{
return 1;
}
/* the binary data */
off = 0;
{
size_t i;
for (i = 0; i < cbRead; i++)
for (; i < sizeof(abLine); i++)
if (fAscii)
{
for (i = 0; i < cbRead; i++)
for (; i < sizeof(abLine); i++)
}
}
/* check for errors */
{
goto error;
}
{
goto error;
}
/* finish the structure. */
"};\n"
"\n"
"%sconst unsigned%s g_cb%s = sizeof(g_ab%s);\n"
"/* end of file */\n",
/* flush output and check for error. */
{
goto error;
}
return 0;
return 1;
}