Permalink
Browse files

Removed CSVF RLE compression

  • Loading branch information...
1 parent 29465fe commit def02c341578dc63b2d3896001de642f6534f4f8 makestuff committed Mar 18, 2013
Showing with 33 additions and 392 deletions.
  1. +25 −20 csvfplay.c
  2. +2 −2 csvfplay.h
  3. +0 −139 csvfreader.c
  4. +0 −42 csvfreader.h
  5. +0 −49 fx2.c
  6. +1 −6 jtag.c
  7. +1 −20 private.h
  8. +0 −99 xsvf2csvf.c
  9. +4 −15 xsvf2csvf/main.c
View
45 csvfplay.c
@@ -27,7 +27,6 @@
#include "vendorCommands.h"
#include "xsvf.h"
#include "csvfplay.h"
-#include "csvfreader.h"
// -------------------------------------------------------------------------------------------------
// Declaration of private types & functions
@@ -41,9 +40,9 @@ static bool tdoMatchFailed(
// Public functions
// -------------------------------------------------------------------------------------------------
-// Play the uncompressed CSVF stream into the JTAG port.
+// Play the CSVF stream into the JTAG port.
//
-FLStatus csvfPlay(struct FLContext *handle, const uint8 *csvfData, bool isCompressed, const char **error) {
+FLStatus csvfPlay(struct FLContext *handle, const uint8 *csvfData, const char **error) {
FLStatus returnCode = FL_SUCCESS;
FLStatus fStatus;
uint8 thisByte, numBits;
@@ -62,18 +61,12 @@ FLStatus csvfPlay(struct FLContext *handle, const uint8 *csvfData, bool isCompre
char expected[CSVF_BUF_SIZE*2+1];
uint8 *tdiAll;
- struct Context cp;
+ const uint8 *ptr = csvfData;
fStatus = neroClockFSM(handle, 0x0000001F, 6, error); // Reset TAP, goto Run-Test/Idle
CHECK_STATUS(fStatus, "csvfPlay()", fStatus);
- if ( csvfInitReader(&cp, csvfData, isCompressed) ) {
- // Header byte may be used for something later. For now, ensure it's zero.
- errRender(error, "csvfPlay(): Bad CSVF header!");
- FAIL(FL_FILE_ERR);
- }
-
- thisByte = csvfGetByte(&cp);
+ thisByte = *ptr++;
while ( thisByte != XCOMPLETE ) {
switch ( thisByte ) {
case XTDOMASK:
@@ -83,7 +76,7 @@ FLStatus csvfPlay(struct FLContext *handle, const uint8 *csvfData, bool isCompre
numBytes = bitsToBytes(xsdrSize);
tdoPtr = tdoMask;
while ( numBytes-- ) {
- thisByte = csvfGetByte(&cp);
+ thisByte = *ptr++;
#ifdef DEBUG
printf("%02X", thisByte);
#endif
@@ -95,7 +88,13 @@ FLStatus csvfPlay(struct FLContext *handle, const uint8 *csvfData, bool isCompre
break;
case XRUNTEST:
- xruntest = csvfGetLong(&cp);
+ xruntest = *ptr++;
+ xruntest <<= 8;
+ xruntest |= *ptr++;
+ xruntest <<= 8;
+ xruntest |= *ptr++;
+ xruntest <<= 8;
+ xruntest |= *ptr++;
#ifdef DEBUG
printf("XRUNTEST(%08X)\n", xruntest);
#endif
@@ -104,14 +103,14 @@ FLStatus csvfPlay(struct FLContext *handle, const uint8 *csvfData, bool isCompre
case XSIR:
fStatus = neroClockFSM(handle, 0x00000003, 4, error); // -> Shift-IR
CHECK_STATUS(fStatus, "csvfPlay()", fStatus);
- numBits = csvfGetByte(&cp);
+ numBits = *ptr++;
#ifdef DEBUG
printf("XSIR(%02X, ", numBits);
#endif
numBytes = bitsToBytes(numBits);
tdiPtr = tdiData;
while ( numBytes-- ) {
- thisByte = csvfGetByte(&cp);
+ thisByte = *ptr++;
#ifdef DEBUG
printf("%02X", thisByte);
#endif
@@ -131,7 +130,13 @@ FLStatus csvfPlay(struct FLContext *handle, const uint8 *csvfData, bool isCompre
break;
case XSDRSIZE:
- xsdrSize = csvfGetLong(&cp);
+ xsdrSize = *ptr++;
+ xsdrSize <<= 8;
+ xsdrSize |= *ptr++;
+ xsdrSize <<= 8;
+ xsdrSize |= *ptr++;
+ xsdrSize <<= 8;
+ xsdrSize |= *ptr++;
#ifdef DEBUG
printf("XSDRSIZE(%08X)\n", xsdrSize);
#endif
@@ -142,8 +147,8 @@ FLStatus csvfPlay(struct FLContext *handle, const uint8 *csvfData, bool isCompre
tdiPtr = tdiData;
tdoPtr = tdoExpected;
while ( numBytes-- ) {
- *tdiPtr++ = csvfGetByte(&cp);
- *tdoPtr++ = csvfGetByte(&cp);
+ *tdiPtr++ = *ptr++;
+ *tdoPtr++ = *ptr++;
}
numBytes = bitsToBytes(xsdrSize);
i = 0;
@@ -190,7 +195,7 @@ FLStatus csvfPlay(struct FLContext *handle, const uint8 *csvfData, bool isCompre
tdiAll = malloc(numBytes);
tdiPtr = tdiAll;
while ( numBytes-- ) {
- *tdiPtr++ = csvfGetByte(&cp);
+ *tdiPtr++ = *ptr++;
}
fStatus = neroShift(handle, xsdrSize, tdiAll, NULL, true, error); // -> Exit1-DR
free(tdiAll);
@@ -207,7 +212,7 @@ FLStatus csvfPlay(struct FLContext *handle, const uint8 *csvfData, bool isCompre
errRender(error, "csvfPlay(): Unsupported command 0x%02X", thisByte);
FAIL(FL_PROG_SVF_UNKNOWN_CMD);
}
- thisByte = csvfGetByte(&cp);
+ thisByte = *ptr++;
}
cleanup:
return returnCode;
View
4 csvfplay.h
@@ -24,9 +24,9 @@
extern "C" {
#endif
- // Play the uncompressed CSVF stream into the JTAG port.
+ // Play the CSVF stream into the JTAG port.
FLStatus csvfPlay(
- struct FLContext *handle, const uint8 *csvfData, bool isCompressed, const char **error
+ struct FLContext *handle, const uint8 *csvfData, const char **error
) WARN_UNUSED_RESULT;
#ifdef __cplusplus
View
139 csvfreader.c
@@ -1,139 +0,0 @@
-/*
- * Copyright (C) 2009-2012 Chris McClelland
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#include <makestuff.h>
-#include "csvfreader.h"
-
-// -------------------------------------------------------------------------------------------------
-// Declaration of private types & functions
-// -------------------------------------------------------------------------------------------------
-
-static uint8 getRawByte(struct Context *cp);
-static uint32 readLength(struct Context *cp);
-
-// -------------------------------------------------------------------------------------------------
-// Public functions
-// -------------------------------------------------------------------------------------------------
-
-// Init the reader, return the header byte
-//
-uint8 csvfInitReader(struct Context *cp, const uint8 *csvfData, bool isCompressed) {
- uint8 thisByte;
- cp->data = csvfData;
- if ( isCompressed ) {
- cp->isCompressed = true;
- thisByte = getRawByte(cp);
- cp->count = readLength(cp);
- } else {
- cp->isCompressed = false;
- thisByte = 0x00;
- cp->count = 0;
- }
- cp->isReadingChunk = true;
- return thisByte;
-}
-
-// Get the next byte from the uncompressed stream. Uses m_count & m_isReadingChunk to keep state.
-//
-uint8 csvfGetByte(struct Context *cp) {
- if ( !cp->isCompressed ) {
- return getRawByte(cp);
- }
- if ( cp->isReadingChunk ) {
- // We're in the middle of reading a chunk.
- if ( cp->count ) {
- // There are still some bytes to copy verbatim into the uncompressed stream.
- cp->count--;
- return getRawByte(cp);
- } else {
- // We're at the end of this chunk; there will now be some zeros to insert into the
- // uncompressed stream.
- cp->count = readLength(cp);
- cp->isReadingChunk = false;
- return csvfGetByte(cp);
- }
- } else {
- // We're in the middle of a run of zeros.
- if ( cp->count ) {
- // There are still some zero bytes to write to the uncompressed stream.
- cp->count--;
- return 0x00;
- } else {
- // We're at the end of this run of zeros; there will now be a chunk of data to be copied
- // verbatim over to the uncompressed stream.
- cp->count = readLength(cp);
- cp->isReadingChunk = true;
- return csvfGetByte(cp);
- }
- }
-}
-
-// Get big-endian uint16 from the stream
-//
-uint16 csvfGetWord(struct Context *cp) {
- uint16 value;
- value = csvfGetByte(cp);
- value <<= 8;
- value |= csvfGetByte(cp);
- return value;
-}
-
-// Get big-endian uint32 from the stream
-//
-uint32 csvfGetLong(struct Context *cp) {
- uint32 value;
- value = csvfGetByte(cp);
- value <<= 8;
- value |= csvfGetByte(cp);
- value <<= 8;
- value |= csvfGetByte(cp);
- value <<= 8;
- value |= csvfGetByte(cp);
- return value;
-}
-
-// -------------------------------------------------------------------------------------------------
-// Implementation of private functions
-// -------------------------------------------------------------------------------------------------
-
-// Read the next raw byte from the input stream
-//
-static uint8 getRawByte(struct Context *cp) {
- return *cp->data++;
-}
-
-// Read the length (of the chunk or the zero run). A short block (<256 bytes) length is encoded in a
-// single byte. If that single byte is zero, we know it's a long block (256-65535 bytes), so read in
-// the next two bytes as a big-endian uint16.
-//
-static uint32 readLength(struct Context *cp) {
- uint32 len = getRawByte(cp);
- if ( !len ) {
- len = getRawByte(cp);
- len <<= 8;
- len |= getRawByte(cp);
- }
- if ( !len ) {
- len = getRawByte(cp);
- len <<= 8;
- len |= getRawByte(cp);
- len <<= 8;
- len |= getRawByte(cp);
- len <<= 8;
- len |= getRawByte(cp);
- }
- return len;
-}
View
42 csvfreader.h
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2009-2012 Chris McClelland
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef CSVF2XSVF_H
-#define CSVF2XSVF_H
-
-#include <makestuff.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
- struct Context {
- const uint8 *data;
- uint32 count;
- bool isReadingChunk;
- bool isCompressed;
- };
-
- uint8 csvfInitReader(struct Context *cp, const uint8 *data, bool isCompressed);
- uint8 csvfGetByte(struct Context *cp);
- uint16 csvfGetWord(struct Context *cp);
- uint32 csvfGetLong(struct Context *cp);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
View
49 fx2.c
@@ -25,10 +25,6 @@
#include "private.h"
#include "firmware.h"
-//static FLStatus convertJtagFileToCsvf(
-// struct Buffer *dest, const char *xsvfFile, const char **error
-//) WARN_UNUSED_RESULT;
-
// Load the standard FPGALink firmware into the FX2 at currentVid/currentPid.
DLLEXPORT(FLStatus) flLoadStandardFirmware(
const char *curVidPid, const char *newVidPid, const char **error)
@@ -226,48 +222,3 @@ FLStatus copyFirmwareAndRewriteIDs(
cleanup:
return returnCode;
}
-
-/*static FLStatus convertJtagFileToCsvf(struct Buffer *dest, const char *xsvfFile, const char **error) {
- FLStatus returnCode, fStatus;
- struct Buffer csvfBuf = {0,};
- BufferStatus bStatus;
- uint32 maxBufSize;
- const char *const ext = xsvfFile + strlen(xsvfFile) - 5;
- if ( strcmp(".svf", ext+1) == 0 ) {
- bStatus = bufInitialise(&csvfBuf, 0x20000, 0, error);
- CHECK_STATUS(bStatus, "convertJtagFileToCsvf()", FL_ALLOC_ERR);
- fStatus = flLoadSvfAndConvertToCsvf(xsvfFile, &csvfBuf, &maxBufSize, error);
- CHECK_STATUS(fStatus, "convertJtagFileToCsvf()", fStatus);
- if ( maxBufSize > CSVF_BUF_SIZE ) {
- errRender(error, "convertJtagFileToCsvf(): This SVF file requires CSVF_BUF_SIZE=%d", maxBufSize);
- FAIL(FL_JTAG_ERR);
- }
- fStatus = flCompressCsvf(&csvfBuf, error);
- CHECK_STATUS(fStatus, "convertJtagFileToCsvf()", fStatus);
- bStatus = bufAppendBlock(dest, csvfBuf.data, csvfBuf.length, error);
- CHECK_STATUS(bStatus, "convertJtagFileToCsvf()", FL_ALLOC_ERR);
- } else if ( strcmp(".xsvf", ext) == 0 ) {
- bStatus = bufInitialise(&csvfBuf, 0x20000, 0, error);
- CHECK_STATUS(bStatus, "convertJtagFileToCsvf()", FL_ALLOC_ERR);
- fStatus = flLoadXsvfAndConvertToCsvf(xsvfFile, &csvfBuf, &maxBufSize, error);
- CHECK_STATUS(fStatus, "convertJtagFileToCsvf()", fStatus);
- if ( maxBufSize > CSVF_BUF_SIZE ) {
- errRender(error, "convertJtagFileToCsvf(): This XSVF file requires CSVF_BUF_SIZE=%d", maxBufSize);
- FAIL(FL_JTAG_ERR);
- }
- fStatus = flCompressCsvf(&csvfBuf, error);
- CHECK_STATUS(fStatus, "convertJtagFileToCsvf()", fStatus);
- bStatus = bufAppendBlock(dest, csvfBuf.data, csvfBuf.length, error);
- CHECK_STATUS(bStatus, "convertJtagFileToCsvf()", FL_ALLOC_ERR);
- } else if ( strcmp(".csvf", ext) == 0 ) {
- bStatus = bufAppendFromBinaryFile(dest, xsvfFile, error);
- CHECK_STATUS(bStatus, "convertJtagFileToCsvf()", FL_FILE_ERR);
- } else {
- errRender(error, "convertJtagFileToCsvf(): Filename should have .svf, .xsvf or .csvf extension");
- FAIL(FL_FILE_ERR);
- }
- returnCode = FL_SUCCESS;
-cleanup:
- bufDestroy(&csvfBuf);
- return returnCode;
-}*/
View
7 jtag.c
@@ -650,8 +650,6 @@ static FLStatus playSVF(struct FLContext *handle, const char *svfFile, const cha
struct Buffer csvfBuf = {0,};
BufferStatus bStatus;
uint32 maxBufSize;
- bool isCompressed;
-
const char *const ext = svfFile + strlen(svfFile) - 5;
if ( !handle->isNeroCapable ) {
errRender(error, "playSVF(): This device does not support NeroJTAG");
@@ -662,20 +660,17 @@ static FLStatus playSVF(struct FLContext *handle, const char *svfFile, const cha
if ( strcmp(".svf", ext+1) == 0 ) {
fStatus = flLoadSvfAndConvertToCsvf(svfFile, &csvfBuf, &maxBufSize, error);
CHECK_STATUS(fStatus, "playSVF()", fStatus);
- isCompressed = false;
} else if ( strcmp(".xsvf", ext) == 0 ) {
fStatus = flLoadXsvfAndConvertToCsvf(svfFile, &csvfBuf, &maxBufSize, error);
CHECK_STATUS(fStatus, "playSVF()", fStatus);
- isCompressed = false;
} else if ( strcmp(".csvf", ext) == 0 ) {
bStatus = bufAppendFromBinaryFile(&csvfBuf, svfFile, error);
CHECK_STATUS(bStatus, "playSVF()", FL_FILE_ERR);
- isCompressed = true;
} else {
errRender(error, "playSVF(): Filename should have .svf, .xsvf or .csvf extension");
FAIL(FL_FILE_ERR);
}
- fStatus = csvfPlay(handle, csvfBuf.data, isCompressed, error);
+ fStatus = csvfPlay(handle, csvfBuf.data, error);
CHECK_STATUS(fStatus, "playSVF()", fStatus);
cleanup:
bufDestroy(&csvfBuf);
View
21 private.h
@@ -94,8 +94,7 @@ extern "C" {
*
* The CSVF format ("Compressed Serial Vector Format") swaps the byte order so bit sequences
* can be played by reading forwards, and it replaces each XSDRB, XSDRC*, XSDRE command sequence
- * with one big XSDR command. CSVF buffers should be compressed with /c flCompressCsvf() before
- * being written to persistent storage.
+ * with one big XSDR command.
*
* @param xsvfFile The XSVF filename.
* @param csvfBuf A pointer to a \c Buffer to be populated with the CSVF data.
@@ -120,24 +119,6 @@ extern "C" {
const char *xsvfFile, struct Buffer *csvfBuf, uint32 *maxBufSize, const char **error
) WARN_UNUSED_RESULT;
- /**
- * @brief Perform run-length encoding on a CSVF buffer.
- *
- * @param csvfBuf A pointer to a \c Buffer containing CSVF data to be RLE-compressed.
- * @param error A pointer to a <code>char*</code> which will be set on exit to an allocated
- * error message if something goes wrong. Responsibility for this allocated memory
- * passes to the caller and must be freed with \c flFreeError(). If \c error is
- * \c NULL, no allocation is done and no message is returned, but the return code
- * will still be valid.
- * @returns
- * - \c FL_SUCCESS if the command completed successfully.
- * - \c FL_BUF_INIT_ERR If the compress buffer could not be allocated.
- * - \c FL_BUF_APPEND_ERR If the compress buffer could not be grown.
- */
- DLLEXPORT(FLStatus) flCompressCsvf(
- struct Buffer *csvfBuf, const char **error
- ) WARN_UNUSED_RESULT;
-
DLLEXPORT(FLStatus) flLoadSvfAndConvertToCsvf(
const char *svfFile, struct Buffer *csvfBuf, uint32 *maxBufSize, const char **error
) WARN_UNUSED_RESULT;
View
99 xsvf2csvf.c
@@ -305,89 +305,6 @@ static FLStatus xsvfSwapBytes(XC *xc, struct Buffer *outBuf, uint32 *maxBufSize,
return returnCode;
}
-static FLStatus compress(const struct Buffer *inBuf, struct Buffer *outBuf, const char **error) {
- FLStatus returnCode = FL_SUCCESS;
- const uint8 *runStart, *runEnd, *bufEnd, *chunkStart, *chunkEnd;
- uint32 runLen, chunkLen;
- BufferStatus bStatus;
- bufEnd = inBuf->data + inBuf->length;
- runStart = chunkStart = inBuf->data;
- bStatus = bufAppendByte(outBuf, 0x00, error); // Hdr byte: defaults
- CHECK_STATUS(bStatus, "compress()", FL_BUF_APPEND_ERR);
- while ( runStart < bufEnd ) {
- // Find next zero
- while ( runStart < bufEnd && *runStart ) {
- runStart++;
- }
-
- // Remember the position of the zero
- runEnd = runStart;
-
- // Find the end of this run of zeros
- while ( runEnd < bufEnd && !*runEnd ) {
- runEnd++;
- }
-
- // Get the length of this run
- runLen = (uint32)(runEnd - runStart);
-
- // If this run is more than four zeros, break the chunk
- if ( runLen > 8 || runEnd == bufEnd ) {
- chunkEnd = runStart;
- chunkLen = (uint32)(chunkEnd - chunkStart);
-
- // There is now a chunk starting at chunkStart and ending at chunkEnd (length chunkLen),
- // Followed by a run of zeros starting at runStart and ending at runEnd (length runLen).
- //printf("Chunk: %d bytes followed by %d zeros\n", chunkLen, runLen);
- if ( chunkLen < 256 ) {
- // Short chunk: uint8
- bStatus = bufAppendByte(outBuf, (uint8)chunkLen, error);
- CHECK_STATUS(bStatus, "compress()", FL_BUF_APPEND_ERR);
- } else if ( chunkLen < 65536 ) {
- // Medium chunk: uint16 (big-endian)
- bStatus = bufAppendByte(outBuf, 0x00, error);
- CHECK_STATUS(bStatus, "compress()", FL_BUF_APPEND_ERR);
- bStatus = bufAppendWordBE(outBuf, (uint16)chunkLen, error);
- CHECK_STATUS(bStatus, "compress()", FL_BUF_APPEND_ERR);
- } else {
- // Long chunk: uint32 (big-endian)
- bStatus = bufAppendConst(outBuf, 0x00, 3, error);
- CHECK_STATUS(bStatus, "compress()", FL_BUF_APPEND_ERR);
- bStatus = bufAppendLongBE(outBuf, chunkLen, error);
- }
- while ( chunkStart < chunkEnd ) {
- bStatus = bufAppendByte(outBuf, *chunkStart++, error);
- CHECK_STATUS(bStatus, "compress()", FL_BUF_APPEND_ERR);
- }
- if ( runLen < 256 ) {
- // Short run: uint8
- bStatus = bufAppendByte(outBuf, (uint8)runLen, error);
- CHECK_STATUS(bStatus, "compress()", FL_BUF_APPEND_ERR);
- } else if ( runLen < 65536 ) {
- // Medium run: uint16 (big-endian)
- bStatus = bufAppendByte(outBuf, 0x00, error);
- CHECK_STATUS(bStatus, "compress()", FL_BUF_APPEND_ERR);
- bStatus = bufAppendWordBE(outBuf, (uint16)runLen, error);
- CHECK_STATUS(bStatus, "compress()", FL_BUF_APPEND_ERR);
- } else {
- // Long run: uint32 (big-endian)
- bStatus = bufAppendConst(outBuf, 0x00, 3, error);
- CHECK_STATUS(bStatus, "compress()", FL_BUF_APPEND_ERR);
- bStatus = bufAppendLongBE(outBuf, runLen, error);
- CHECK_STATUS(bStatus, "compress()", FL_BUF_APPEND_ERR);
- }
-
- chunkStart = runEnd;
- }
-
- // Start the next round from the end of this run
- runStart = runEnd;
- }
-
-cleanup:
- return returnCode;
-}
-
DLLEXPORT(FLStatus) flLoadXsvfAndConvertToCsvf(
const char *xsvfFile, struct Buffer *csvfBuf, uint32 *maxBufSize, const char **error)
{
@@ -405,19 +322,3 @@ DLLEXPORT(FLStatus) flLoadXsvfAndConvertToCsvf(
bufDestroy(&xc.xsvfBuf);
return returnCode;
}
-
-DLLEXPORT(FLStatus) flCompressCsvf(
- struct Buffer *csvfBuf, const char **error)
-{
- FLStatus fStatus, returnCode = FL_SUCCESS;
- struct Buffer swapBuf = {0,};
- BufferStatus bStatus;
- bStatus = bufInitialise(&swapBuf, 0x20000, 0, error);
- CHECK_STATUS(bStatus, "flCompressCsvf()", FL_BUF_INIT_ERR);
- fStatus = compress(csvfBuf, &swapBuf, error);
- CHECK_STATUS(fStatus, "flCompressCsvf()", fStatus);
- bufSwap(csvfBuf, &swapBuf);
-cleanup:
- bufDestroy(&swapBuf);
- return returnCode;
-}
View
19 xsvf2csvf/main.c
@@ -35,20 +35,13 @@ int main(int argc, const char *argv[]) {
const char *error = NULL;
uint32 csvfBufSize = 0;
const char *srcFile, *dstFile;
- bool doCompress;
const char *ext;
- if ( argc == 3 ) {
- srcFile = argv[1];
- dstFile = argv[2];
- doCompress = true;
- } else if ( argc == 4 && argv[1][0] == '-' && argv[1][1] == 'u' && argv[1][2] == '\0' ) {
- srcFile = argv[2];
- dstFile = argv[3];
- doCompress = false;
- } else {
+ if ( argc != 3 ) {
fprintf(stderr, "Synopsis: %s [-u] <src.xsvf|src.svf> <dst.csvf>\n", argv[0]);
FAIL(1);
}
+ srcFile = argv[1];
+ dstFile = argv[2];
ext = srcFile + strlen(srcFile) - 5;
bStatus = bufInitialise(&csvfBuf, 10240, 0x00, &error);
CHECK(bStatus, 2);
@@ -57,15 +50,11 @@ int main(int argc, const char *argv[]) {
} else if ( strcmp(".xsvf", ext) == 0 ) {
fStatus = flLoadXsvfAndConvertToCsvf(srcFile, &csvfBuf, &csvfBufSize, &error);
} else {
- fprintf(stderr, "Source file should have .svf or .xsvf extension\n");
+ fprintf(stderr, "Source filename should have an .svf or an .xsvf extension\n");
FAIL(3);
}
CHECK(fStatus, 4);
printf("CSVF_BUF_SIZE = %d\n", csvfBufSize);
- if ( doCompress ) {
- fStatus = flCompressCsvf(&csvfBuf, &error);
- CHECK(fStatus, 5);
- }
bStatus = bufWriteBinaryFile(&csvfBuf, dstFile, 0, csvfBuf.length, &error);
CHECK(bStatus, 6);

0 comments on commit def02c3

Please sign in to comment.