filesplitter.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
/** @file
* File splitter: splits a text file according to ###### markers in it.
*/
/*
* Copyright (C) 2006-2009 Oracle Corporation
*
* 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 (GPL) 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.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
{
unsigned long cLine = 0;
{
if (!pStr)
break;
++cLine;
++pStr;
}
return cLine;
}
{
int rc = 0;
const char *pcszBeginMarker = "\n// ##### BEGINFILE \"";
const char *pcszEndMarker = "\n// ##### ENDFILE";
do {
if (argc != 3)
{
"1) the input file and 2) the directory where to put the output files\n");
rc = 2;
break;
}
{
rc = 2;
break;
}
{
rc = 2;
break;
}
{
rc = 2;
break;
}
{
rc = 2;
break;
}
unsigned long cFiles = 0;
do
{
/* find begin marker */
if (!pBegin)
break;
/* find line after begin marker */
if (!pLineAfterBegin)
{
rc = 2;
break;
}
/* find second quote in begin marker line */
if ( !pSecondQuote
|| pSecondQuote >= pLineAfterBegin)
{
fprintf(stderr, "filesplitter: Can't parse filename after begin-file marker (line %lu).\n", lineNumber(pBuffer, pcszBeginMarker));
rc = 2;
break;
}
/* find end marker */
if (!pEnd)
{
fprintf(stderr, "filesplitter: No matching end-line marker for begin-file marker found (line %lu).\n", lineNumber(pBuffer, pcszBeginMarker));
rc = 2;
break;
}
/* construct output filename */
char *pszFilename;
{
rc = 2;
break;
}
/* create output file and write file contents */
{
rc = 2;
}
else
{
{
fprintf(stderr, "filesplitter: Failed to write %ld bytes to file \"%s\"\n", (long)cbFile, pszFilename);
rc = 2;
}
if (!rc)
{
++cFiles;
}
}
if (rc)
break;
} while (pSearch);
} while (0);
if (pBuffer)
if (pFileIn)
return rc;
}