mirror of https://github.com/fadden/nulib2.git
Reformatted files to use spaces instead of hard tabs. No substantitve changes.
This commit is contained in:
parent
768a224513
commit
d6a5154b60
|
@ -1,159 +1,163 @@
|
|||
2000/05/22 ***** v1.0.1 shipped *****
|
||||
2002/09/20 fadden
|
||||
- pulled the sources out and started fiddling with them again
|
||||
- changed hard tabs to spaces
|
||||
|
||||
2000/05/22 fadden
|
||||
- added workaround for buggy 140K DOS3.3 GSHK images
|
||||
2000/05/22 ***** v1.0.1 shipped *****
|
||||
|
||||
2000/05/18 ***** v1.0.0 shipped *****
|
||||
2000/05/22 fadden
|
||||
- added workaround for buggy 140K DOS3.3 GSHK images
|
||||
|
||||
2000/05/18 fadden
|
||||
- updated version information to indicate final release
|
||||
2000/05/18 ***** v1.0.0 shipped *****
|
||||
|
||||
2000/03/25 ***** v0.6.1 shipped *****
|
||||
2000/05/18 fadden
|
||||
- updated version information to indicate final release
|
||||
|
||||
2000/03/25 fadden
|
||||
- Sheppy says Mac OS X PPC v1.02 and v1.2 work with minor SysDefs tweak
|
||||
2000/03/25 ***** v0.6.1 shipped *****
|
||||
|
||||
2000/03/05 ***** v0.6.0 (beta) shipped *****
|
||||
2000/03/25 fadden
|
||||
- Sheppy says Mac OS X PPC v1.02 and v1.2 work with minor SysDefs tweak
|
||||
|
||||
2000/03/05 fadden
|
||||
- modified NuOpenRW to call mktemp or mkstemp if tmpPath looks like
|
||||
a template
|
||||
- removed DEBUG_MSGS from default CFLAGS
|
||||
- updated version information to indicate beta release
|
||||
2000/03/05 ***** v0.6.0 (beta) shipped *****
|
||||
|
||||
2000/02/24 ***** v0.5.1 shipped *****
|
||||
2000/03/05 fadden
|
||||
- modified NuOpenRW to call mktemp or mkstemp if tmpPath looks like
|
||||
a template
|
||||
- removed DEBUG_MSGS from default CFLAGS
|
||||
- updated version information to indicate beta release
|
||||
|
||||
2000/02/20 changes from Scott Blackman
|
||||
- portability fixes for DJGPP under Win95
|
||||
2000/02/24 ***** v0.5.1 shipped *****
|
||||
|
||||
2000/02/17 changes from Devin Reade
|
||||
- portability fixes for BSD, AIX, and others
|
||||
2000/02/20 changes from Scott Blackman
|
||||
- portability fixes for DJGPP under Win95
|
||||
|
||||
2000/02/09 ***** v0.5.0 (alpha) shipped *****
|
||||
2000/02/17 changes from Devin Reade
|
||||
- portability fixes for BSD, AIX, and others
|
||||
|
||||
2000/02/08 fadden
|
||||
- tweaked the BeOS/PPC config around a little
|
||||
- deleted some commas to make "gcc -pendantic" happy
|
||||
2000/02/09 ***** v0.5.0 (alpha) shipped *****
|
||||
|
||||
2000/02/06 fadden
|
||||
- include @CFLAGS@ in case somebody wants to override them
|
||||
2000/02/08 fadden
|
||||
- tweaked the BeOS/PPC config around a little
|
||||
- deleted some commas to make "gcc -pendantic" happy
|
||||
|
||||
2000/02/06 ***** v0.4.0b shipped *****
|
||||
2000/02/06 fadden
|
||||
- include @CFLAGS@ in case somebody wants to override them
|
||||
|
||||
2000/02/06 fadden
|
||||
- added "install-shared" make target
|
||||
- portability fixes for HP/UX
|
||||
- configure.in test for presence of snprintf/vsnprintf declarations
|
||||
2000/02/06 ***** v0.4.0b shipped *****
|
||||
|
||||
2000/02/06 ***** v0.4.0a shipped *****
|
||||
2000/02/06 fadden
|
||||
- added "install-shared" make target
|
||||
- portability fixes for HP/UX
|
||||
- configure.in test for presence of snprintf/vsnprintf declarations
|
||||
|
||||
2000/02/06 fadden
|
||||
- massaged configure.in for BeOS, and added some type casts for mwerks
|
||||
2000/02/06 ***** v0.4.0a shipped *****
|
||||
|
||||
2000/02/06 ***** v0.4.0 shipped *****
|
||||
2000/02/06 fadden
|
||||
- massaged configure.in for BeOS, and added some type casts for mwerks
|
||||
|
||||
2000/02/06 fadden
|
||||
- added value range checking to Nu_SetValue
|
||||
2000/02/06 ***** v0.4.0 shipped *****
|
||||
|
||||
2000/02/05 fadden
|
||||
- finished "test-basic"
|
||||
- added an "install" target to copy libnufx and NufxLib.h
|
||||
- added "mkinstalldirs"
|
||||
- fixed a memory leak in NuTest
|
||||
- made several implicit typecasts explicit for Visual C++'s benefit
|
||||
- renamed MiscStuff's replacement function to "Nu_function"
|
||||
- use "rb" or "wb" as fopen arg in sample code for Win32
|
||||
2000/02/06 fadden
|
||||
- added value range checking to Nu_SetValue
|
||||
|
||||
2000/02/04 fadden
|
||||
- wrote a fair piece of "test-basic"
|
||||
- added "stickyErr" to "toBuffer" data sink so we can catch overruns
|
||||
2000/02/05 fadden
|
||||
- finished "test-basic"
|
||||
- added an "install" target to copy libnufx and NufxLib.h
|
||||
- added "mkinstalldirs"
|
||||
- fixed a memory leak in NuTest
|
||||
- made several implicit typecasts explicit for Visual C++'s benefit
|
||||
- renamed MiscStuff's replacement function to "Nu_function"
|
||||
- use "rb" or "wb" as fopen arg in sample code for Win32
|
||||
|
||||
2000/02/02 fadden
|
||||
- minor changes to get it working under Win32 (Visual C++ 6.0)
|
||||
- added --enable-dmalloc to configuration
|
||||
- instead of constantly allocating 16K buffers, use pArchive->compBuf
|
||||
- ignore DataSink convertEOL value when doExpand is false
|
||||
2000/02/04 fadden
|
||||
- wrote a fair piece of "test-basic"
|
||||
- added "stickyErr" to "toBuffer" data sink so we can catch overruns
|
||||
|
||||
2000/02/01 fadden
|
||||
- added system-specific PATH_SEP define for samples (imgconv, exerciser)
|
||||
- set the pathname in ErrorStatus for CRC failures
|
||||
2000/02/02 fadden
|
||||
- minor changes to get it working under Win32 (Visual C++ 6.0)
|
||||
- added --enable-dmalloc to configuration
|
||||
- instead of constantly allocating 16K buffers, use pArchive->compBuf
|
||||
- ignore DataSink convertEOL value when doExpand is false
|
||||
|
||||
2000/01/31 fadden
|
||||
- fixed a typo causing zero-byte GSHK-damaged files to report CRC errors
|
||||
- added support for DOS-ordered 2MG images to "imgconv"
|
||||
2000/02/01 fadden
|
||||
- added system-specific PATH_SEP define for samples (imgconv, exerciser)
|
||||
- set the pathname in ErrorStatus for CRC failures
|
||||
|
||||
2000/01/29 ***** v0.3.0 shipped *****
|
||||
2000/01/31 fadden
|
||||
- fixed a typo causing zero-byte GSHK-damaged files to report CRC errors
|
||||
- added support for DOS-ordered 2MG images to "imgconv"
|
||||
|
||||
2000/01/29 fadden
|
||||
- renamed "tests" to "samples"
|
||||
- changed library version to x.y.z format (major, minor, bug-fix)
|
||||
- added DEBUG_VERBOSE define, took some stuff out of DEBUG_MSGS
|
||||
2000/01/29 ***** v0.3.0 shipped *****
|
||||
|
||||
2000/01/28 fadden
|
||||
- make the Skip result work when an input file can't be opened
|
||||
- don't allow leading fssep chars in AddRecord
|
||||
- don't treat a multi-file BNY that happens to have a ShrinkIt archive
|
||||
in the first slot as a BXY
|
||||
- added "-t" flag (write to temp) to "launder"
|
||||
- in OpenReadWrite, treat zero-length archive files as newly-created
|
||||
- added workaround for GSHK's zero-byte data fork bug
|
||||
2000/01/29 fadden
|
||||
- renamed "tests" to "samples"
|
||||
- changed library version to x.y.z format (major, minor, bug-fix)
|
||||
- added DEBUG_VERBOSE define, took some stuff out of DEBUG_MSGS
|
||||
|
||||
2000/01/26 fadden
|
||||
- added status result flags to NuFlush
|
||||
- dropped kNuAbortAll and added kNuIgnore
|
||||
- implemented kNuValueIgnoreCRC
|
||||
- update the storageType whenever we change the record
|
||||
2000/01/28 fadden
|
||||
- make the Skip result work when an input file can't be opened
|
||||
- don't allow leading fssep chars in AddRecord
|
||||
- don't treat a multi-file BNY that happens to have a ShrinkIt archive
|
||||
in the first slot as a BXY
|
||||
- added "-t" flag (write to temp) to "launder"
|
||||
- in OpenReadWrite, treat zero-length archive files as newly-created
|
||||
- added workaround for GSHK's zero-byte data fork bug
|
||||
|
||||
2000/01/25 fadden
|
||||
- don't remove the temp file if the rename fails
|
||||
- Nu_ReportError now optionally uses a callback instead of stderr
|
||||
- pass NuArchive* and all the trimmings into Nu_ReportError so we can
|
||||
do the callback thing; required adding arguments to lots of places
|
||||
- clearly labeled BailError output as debug-only, then replaced most
|
||||
of the BailErrorQuiet calls with BailError
|
||||
- added global error message for when pArchive doesn't exist (e.g. Open)
|
||||
2000/01/26 fadden
|
||||
- added status result flags to NuFlush
|
||||
- dropped kNuAbortAll and added kNuIgnore
|
||||
- implemented kNuValueIgnoreCRC
|
||||
- update the storageType whenever we change the record
|
||||
|
||||
2000/01/24 fadden
|
||||
- added args to "launder", and made it work right with 0-length threads
|
||||
- reject disk image threads that aren't a valid size
|
||||
- in NuFlush, recognize when a "copy" set hasn't had any changes made
|
||||
- AddThread no longer makes a copy of the DataSource
|
||||
2000/01/25 fadden
|
||||
- don't remove the temp file if the rename fails
|
||||
- Nu_ReportError now optionally uses a callback instead of stderr
|
||||
- pass NuArchive* and all the trimmings into Nu_ReportError so we can
|
||||
do the callback thing; required adding arguments to lots of places
|
||||
- clearly labeled BailError output as debug-only, then replaced most
|
||||
of the BailErrorQuiet calls with BailError
|
||||
- added global error message for when pArchive doesn't exist (e.g. Open)
|
||||
|
||||
2000/01/24 ***** v0.2 shipped *****
|
||||
2000/01/24 fadden
|
||||
- added args to "launder", and made it work right with 0-length threads
|
||||
- reject disk image threads that aren't a valid size
|
||||
- in NuFlush, recognize when a "copy" set hasn't had any changes made
|
||||
- AddThread no longer makes a copy of the DataSource
|
||||
|
||||
2000/01/23 fadden
|
||||
- added "sec" (Set ErrorHandler Callback) to exerciser
|
||||
- wrote "launder" test program
|
||||
- made "doExpand" option on data sinks work
|
||||
2000/01/24 ***** v0.2 shipped *****
|
||||
|
||||
2000/01/22 fadden
|
||||
- added OnlyUpdateOlder attribute and implemented for add and extract
|
||||
- made HandleExisting work for AddFile/AddRecord
|
||||
- AddThread's validation now blocks data and control threads in same
|
||||
record
|
||||
- AddFile and AddRecord now use same validation function as AddThread
|
||||
2000/01/23 fadden
|
||||
- added "sec" (Set ErrorHandler Callback) to exerciser
|
||||
- wrote "launder" test program
|
||||
- made "doExpand" option on data sinks work
|
||||
|
||||
2000/01/20 fadden
|
||||
- added Eric Shepherd's BeOS shared lib stuff to configure.in
|
||||
- restructed the progress updater, and made it work when adding files
|
||||
2000/01/22 fadden
|
||||
- added OnlyUpdateOlder attribute and implemented for add and extract
|
||||
- made HandleExisting work for AddFile/AddRecord
|
||||
- AddThread's validation now blocks data and control threads in same
|
||||
record
|
||||
- AddFile and AddRecord now use same validation function as AddThread
|
||||
|
||||
2000/01/19 fadden
|
||||
- normalized SysDefs.h, changing UNIX to UNIX_LIKE and defining for BeOS
|
||||
- added "shared" target to makefile
|
||||
- added BeOS stuff to autoconf setup
|
||||
2000/01/20 fadden
|
||||
- added Eric Shepherd's BeOS shared lib stuff to configure.in
|
||||
- restructed the progress updater, and made it work when adding files
|
||||
|
||||
2000/01/17 fadden
|
||||
- fixed Makefile issue preventing "tests" from working with old GNU make
|
||||
- fixed Lzw.c problem fouling up SunOS gcc v2.5.8
|
||||
- discovered "<" vs "<=" flapping in GSHK, which I can't Mimic
|
||||
- fixed option list dump in debug print
|
||||
- properly return from all Malloc errors; abort is now debug-only again
|
||||
- lots of BeOS/Metrowerks "it's not gcc" changes from Eric Shepherd
|
||||
2000/01/19 fadden
|
||||
- normalized SysDefs.h, changing UNIX to UNIX_LIKE and defining for BeOS
|
||||
- added "shared" target to makefile
|
||||
- added BeOS stuff to autoconf setup
|
||||
|
||||
2000/01/17 ***** v0.1 shipped *****
|
||||
2000/01/17 fadden
|
||||
- fixed Makefile issue preventing "tests" from working with old GNU make
|
||||
- fixed Lzw.c problem fouling up SunOS gcc v2.5.8
|
||||
- discovered "<" vs "<=" flapping in GSHK, which I can't Mimic
|
||||
- fixed option list dump in debug print
|
||||
- properly return from all Malloc errors; abort is now debug-only again
|
||||
- lots of BeOS/Metrowerks "it's not gcc" changes from Eric Shepherd
|
||||
|
||||
2000/01/17 ***** v0.1 shipped *****
|
||||
|
||||
(much time passes)
|
||||
|
||||
mid-1998 fadden
|
||||
- work begins
|
||||
mid-1998 fadden
|
||||
- work begins
|
||||
|
||||
|
|
|
@ -69,9 +69,9 @@ DJGPP, follow the UNIX instructions.
|
|||
|
||||
NufxLib has been tested with Microsoft Visual C++ 6.0. To build NufxLib,
|
||||
start up a DOS shell and run vcvars32.bat to set your environment. Run:
|
||||
nmake -f makefile.msc
|
||||
nmake -f makefile.msc
|
||||
to build with debugging info, or
|
||||
nmake -f makefile.msc nodebug=1
|
||||
nmake -f makefile.msc nodebug=1
|
||||
to build optimized.
|
||||
|
||||
Once the library has been built, "cd samples" and run the same command there.
|
||||
|
@ -81,7 +81,7 @@ When it finishes, run "test-basic.exe".
|
|||
Other Notes
|
||||
===========
|
||||
|
||||
All of the source code was formatted with four-space hard tabs.
|
||||
All of the source code is now formatted with spaces instead of tabs.
|
||||
|
||||
If you want to use the library in a multithreaded application, you should
|
||||
define "USE_REENTRANT_CALLS" to tell it to use reentrant versions of
|
||||
|
|
|
@ -9,33 +9,33 @@
|
|||
#ifndef __Common__
|
||||
#define __Common__
|
||||
|
||||
#include "SysDefs.h" /* might as well draft off the autoconf */
|
||||
#include "SysDefs.h" /* might as well draft off the autoconf */
|
||||
#include "NufxLib.h"
|
||||
|
||||
#ifdef USE_DMALLOC
|
||||
# include "dmalloc.h"
|
||||
#endif
|
||||
|
||||
#define nil NULL /* this is seriously habit-forming */
|
||||
#define nil NULL /* this is seriously habit-forming */
|
||||
|
||||
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
#ifndef __cplusplus
|
||||
#define false 0
|
||||
#define true (!false)
|
||||
#define false 0
|
||||
#define true (!false)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef FOPEN_WANTS_B
|
||||
# define kNuFileOpenReadOnly "rb"
|
||||
# define kNuFileOpenReadWrite "r+b"
|
||||
# define kNuFileOpenWriteTrunc "wb"
|
||||
# define kNuFileOpenReadWriteCreat "w+b"
|
||||
# define kNuFileOpenReadOnly "rb"
|
||||
# define kNuFileOpenReadWrite "r+b"
|
||||
# define kNuFileOpenWriteTrunc "wb"
|
||||
# define kNuFileOpenReadWriteCreat "w+b"
|
||||
#else
|
||||
# define kNuFileOpenReadOnly "r"
|
||||
# define kNuFileOpenReadWrite "r+"
|
||||
# define kNuFileOpenWriteTrunc "w"
|
||||
# define kNuFileOpenReadWriteCreat "w+"
|
||||
# define kNuFileOpenReadOnly "r"
|
||||
# define kNuFileOpenReadWrite "r+"
|
||||
# define kNuFileOpenWriteTrunc "w"
|
||||
# define kNuFileOpenReadWriteCreat "w+"
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -44,23 +44,23 @@
|
|||
*/
|
||||
|
||||
#ifdef MSDOS
|
||||
# define PATH_SEP '\\'
|
||||
# define PATH_SEP '\\'
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
# define PATH_SEP '\\'
|
||||
# define PATH_SEP '\\'
|
||||
#endif
|
||||
|
||||
#ifdef MACOS
|
||||
# define PATH_SEP ':'
|
||||
# define PATH_SEP ':'
|
||||
#endif
|
||||
|
||||
#if defined(APW) || defined(__ORCAC__)
|
||||
# define PATH_SEP ':'
|
||||
# define PATH_SEP ':'
|
||||
#endif
|
||||
|
||||
#ifndef PATH_SEP
|
||||
# define PATH_SEP '/'
|
||||
# define PATH_SEP '/'
|
||||
#endif
|
||||
|
||||
#endif /*__Common__*/
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -22,43 +22,43 @@ int Nu_strcasecmp(const char *s1, const char *s2);
|
|||
#endif
|
||||
|
||||
|
||||
#define kTempFile "imgconv.tmp"
|
||||
#define kLocalFssep PATH_SEP
|
||||
#define false 0
|
||||
#define true (!false)
|
||||
#define kTempFile "imgconv.tmp"
|
||||
#define kLocalFssep PATH_SEP
|
||||
#define false 0
|
||||
#define true (!false)
|
||||
|
||||
|
||||
/*
|
||||
* ===========================================================================
|
||||
* 2IMG stuff
|
||||
* 2IMG stuff
|
||||
* ===========================================================================
|
||||
*/
|
||||
|
||||
#define kImgMagic "2IMG"
|
||||
#define kMyCreator "NFXL"
|
||||
#define kImgMagic "2IMG"
|
||||
#define kMyCreator "NFXL"
|
||||
|
||||
#define kImageFormatDOS 0
|
||||
#define kImageFormatProDOS 1
|
||||
#define kImageFormatNibble 2
|
||||
#define kImageFormatDOS 0
|
||||
#define kImageFormatProDOS 1
|
||||
#define kImageFormatNibble 2
|
||||
|
||||
/*
|
||||
* 2IMG header definition (http://www.magnet.ch/emutech/Tech/).
|
||||
*/
|
||||
typedef struct ImgHeader {
|
||||
char magic[4];
|
||||
char creator[4];
|
||||
short headerLen;
|
||||
short version;
|
||||
long imageFormat;
|
||||
unsigned long flags;
|
||||
long numBlocks;
|
||||
long dataOffset;
|
||||
long dataLen;
|
||||
long cmntOffset;
|
||||
long cmntLen;
|
||||
long creatorOffset;
|
||||
long creatorLen;
|
||||
long spare[4];
|
||||
char magic[4];
|
||||
char creator[4];
|
||||
short headerLen;
|
||||
short version;
|
||||
long imageFormat;
|
||||
unsigned long flags;
|
||||
long numBlocks;
|
||||
long dataOffset;
|
||||
long dataLen;
|
||||
long cmntOffset;
|
||||
long cmntLen;
|
||||
long creatorOffset;
|
||||
long creatorLen;
|
||||
long spare[4];
|
||||
} ImgHeader;
|
||||
|
||||
/*
|
||||
|
@ -67,8 +67,8 @@ typedef struct ImgHeader {
|
|||
void
|
||||
ReadShortLE(FILE* fp, short* pBuf)
|
||||
{
|
||||
*pBuf = getc(fp);
|
||||
*pBuf += (short) getc(fp) << 8;
|
||||
*pBuf = getc(fp);
|
||||
*pBuf += (short) getc(fp) << 8;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -77,8 +77,8 @@ ReadShortLE(FILE* fp, short* pBuf)
|
|||
void
|
||||
WriteShortLE(FILE* fp, unsigned short val)
|
||||
{
|
||||
putc(val, fp);
|
||||
putc(val >> 8, fp);
|
||||
putc(val, fp);
|
||||
putc(val >> 8, fp);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -87,10 +87,10 @@ WriteShortLE(FILE* fp, unsigned short val)
|
|||
void
|
||||
ReadLongLE(FILE* fp, long* pBuf)
|
||||
{
|
||||
*pBuf = getc(fp);
|
||||
*pBuf += (long) getc(fp) << 8;
|
||||
*pBuf += (long) getc(fp) << 16;
|
||||
*pBuf += (long) getc(fp) << 24;
|
||||
*pBuf = getc(fp);
|
||||
*pBuf += (long) getc(fp) << 8;
|
||||
*pBuf += (long) getc(fp) << 16;
|
||||
*pBuf += (long) getc(fp) << 24;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -99,10 +99,10 @@ ReadLongLE(FILE* fp, long* pBuf)
|
|||
void
|
||||
WriteLongLE(FILE* fp, unsigned long val)
|
||||
{
|
||||
putc(val, fp);
|
||||
putc(val >> 8, fp);
|
||||
putc(val >> 16, fp);
|
||||
putc(val >> 24, fp);
|
||||
putc(val, fp);
|
||||
putc(val >> 8, fp);
|
||||
putc(val >> 16, fp);
|
||||
putc(val >> 24, fp);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -111,38 +111,38 @@ WriteLongLE(FILE* fp, unsigned long val)
|
|||
int
|
||||
ReadImgHeader(FILE* fp, ImgHeader* pHeader)
|
||||
{
|
||||
fread(pHeader->magic, 4, 1, fp);
|
||||
fread(pHeader->creator, 4, 1, fp);
|
||||
ReadShortLE(fp, &pHeader->headerLen);
|
||||
ReadShortLE(fp, &pHeader->version);
|
||||
ReadLongLE(fp, &pHeader->imageFormat);
|
||||
ReadLongLE(fp, (long*)&pHeader->flags);
|
||||
ReadLongLE(fp, &pHeader->numBlocks);
|
||||
ReadLongLE(fp, &pHeader->dataOffset);
|
||||
ReadLongLE(fp, &pHeader->dataLen);
|
||||
ReadLongLE(fp, &pHeader->cmntOffset);
|
||||
ReadLongLE(fp, &pHeader->cmntLen);
|
||||
ReadLongLE(fp, &pHeader->creatorOffset);
|
||||
ReadLongLE(fp, &pHeader->creatorLen);
|
||||
ReadLongLE(fp, &pHeader->spare[0]);
|
||||
ReadLongLE(fp, &pHeader->spare[1]);
|
||||
ReadLongLE(fp, &pHeader->spare[2]);
|
||||
ReadLongLE(fp, &pHeader->spare[3]);
|
||||
fread(pHeader->magic, 4, 1, fp);
|
||||
fread(pHeader->creator, 4, 1, fp);
|
||||
ReadShortLE(fp, &pHeader->headerLen);
|
||||
ReadShortLE(fp, &pHeader->version);
|
||||
ReadLongLE(fp, &pHeader->imageFormat);
|
||||
ReadLongLE(fp, (long*)&pHeader->flags);
|
||||
ReadLongLE(fp, &pHeader->numBlocks);
|
||||
ReadLongLE(fp, &pHeader->dataOffset);
|
||||
ReadLongLE(fp, &pHeader->dataLen);
|
||||
ReadLongLE(fp, &pHeader->cmntOffset);
|
||||
ReadLongLE(fp, &pHeader->cmntLen);
|
||||
ReadLongLE(fp, &pHeader->creatorOffset);
|
||||
ReadLongLE(fp, &pHeader->creatorLen);
|
||||
ReadLongLE(fp, &pHeader->spare[0]);
|
||||
ReadLongLE(fp, &pHeader->spare[1]);
|
||||
ReadLongLE(fp, &pHeader->spare[2]);
|
||||
ReadLongLE(fp, &pHeader->spare[3]);
|
||||
|
||||
if (feof(fp) || ferror(fp))
|
||||
return -1;
|
||||
if (feof(fp) || ferror(fp))
|
||||
return -1;
|
||||
|
||||
if (strncmp(pHeader->magic, kImgMagic, 4) != 0) {
|
||||
fprintf(stderr, "ERROR: bad magic number on 2IMG file\n");
|
||||
return -1;
|
||||
}
|
||||
if (strncmp(pHeader->magic, kImgMagic, 4) != 0) {
|
||||
fprintf(stderr, "ERROR: bad magic number on 2IMG file\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pHeader->version > 1) {
|
||||
fprintf(stderr, "WARNING: might not be able to handle version=%d\n",
|
||||
pHeader->version);
|
||||
}
|
||||
if (pHeader->version > 1) {
|
||||
fprintf(stderr, "WARNING: might not be able to handle version=%d\n",
|
||||
pHeader->version);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -151,28 +151,28 @@ ReadImgHeader(FILE* fp, ImgHeader* pHeader)
|
|||
int
|
||||
WriteImgHeader(FILE* fp, ImgHeader* pHeader)
|
||||
{
|
||||
fwrite(pHeader->magic, 4, 1, fp);
|
||||
fwrite(pHeader->creator, 4, 1, fp);
|
||||
WriteShortLE(fp, pHeader->headerLen);
|
||||
WriteShortLE(fp, pHeader->version);
|
||||
WriteLongLE(fp, pHeader->imageFormat);
|
||||
WriteLongLE(fp, pHeader->flags);
|
||||
WriteLongLE(fp, pHeader->numBlocks);
|
||||
WriteLongLE(fp, pHeader->dataOffset);
|
||||
WriteLongLE(fp, pHeader->dataLen);
|
||||
WriteLongLE(fp, pHeader->cmntOffset);
|
||||
WriteLongLE(fp, pHeader->cmntLen);
|
||||
WriteLongLE(fp, pHeader->creatorOffset);
|
||||
WriteLongLE(fp, pHeader->creatorLen);
|
||||
WriteLongLE(fp, pHeader->spare[0]);
|
||||
WriteLongLE(fp, pHeader->spare[1]);
|
||||
WriteLongLE(fp, pHeader->spare[2]);
|
||||
WriteLongLE(fp, pHeader->spare[3]);
|
||||
fwrite(pHeader->magic, 4, 1, fp);
|
||||
fwrite(pHeader->creator, 4, 1, fp);
|
||||
WriteShortLE(fp, pHeader->headerLen);
|
||||
WriteShortLE(fp, pHeader->version);
|
||||
WriteLongLE(fp, pHeader->imageFormat);
|
||||
WriteLongLE(fp, pHeader->flags);
|
||||
WriteLongLE(fp, pHeader->numBlocks);
|
||||
WriteLongLE(fp, pHeader->dataOffset);
|
||||
WriteLongLE(fp, pHeader->dataLen);
|
||||
WriteLongLE(fp, pHeader->cmntOffset);
|
||||
WriteLongLE(fp, pHeader->cmntLen);
|
||||
WriteLongLE(fp, pHeader->creatorOffset);
|
||||
WriteLongLE(fp, pHeader->creatorLen);
|
||||
WriteLongLE(fp, pHeader->spare[0]);
|
||||
WriteLongLE(fp, pHeader->spare[1]);
|
||||
WriteLongLE(fp, pHeader->spare[2]);
|
||||
WriteLongLE(fp, pHeader->spare[3]);
|
||||
|
||||
if (ferror(fp))
|
||||
return -1;
|
||||
if (ferror(fp))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -182,27 +182,27 @@ WriteImgHeader(FILE* fp, ImgHeader* pHeader)
|
|||
void
|
||||
DumpImgHeader(ImgHeader* pHeader)
|
||||
{
|
||||
printf("--- header contents:\n");
|
||||
printf("\tmagic = '%.4s'\n", pHeader->magic);
|
||||
printf("\tcreator = '%.4s'\n", pHeader->creator);
|
||||
printf("\theaderLen = %d\n", pHeader->headerLen);
|
||||
printf("\tversion = %d\n", pHeader->version);
|
||||
printf("\timageFormat = %ld\n", pHeader->imageFormat);
|
||||
printf("\tflags = 0x%08lx\n", pHeader->flags);
|
||||
printf("\tnumBlocks = %ld\n", pHeader->numBlocks);
|
||||
printf("\tdataOffset = %ld\n", pHeader->dataOffset);
|
||||
printf("\tdataLen = %ld\n", pHeader->dataLen);
|
||||
printf("\tcmntOffset = %ld\n", pHeader->cmntOffset);
|
||||
printf("\tcmntLen = %ld\n", pHeader->cmntLen);
|
||||
printf("\tcreatorOffset = %ld\n", pHeader->creatorOffset);
|
||||
printf("\tcreatorLen = %ld\n", pHeader->creatorLen);
|
||||
printf("\n");
|
||||
printf("--- header contents:\n");
|
||||
printf("\tmagic = '%.4s'\n", pHeader->magic);
|
||||
printf("\tcreator = '%.4s'\n", pHeader->creator);
|
||||
printf("\theaderLen = %d\n", pHeader->headerLen);
|
||||
printf("\tversion = %d\n", pHeader->version);
|
||||
printf("\timageFormat = %ld\n", pHeader->imageFormat);
|
||||
printf("\tflags = 0x%08lx\n", pHeader->flags);
|
||||
printf("\tnumBlocks = %ld\n", pHeader->numBlocks);
|
||||
printf("\tdataOffset = %ld\n", pHeader->dataOffset);
|
||||
printf("\tdataLen = %ld\n", pHeader->dataLen);
|
||||
printf("\tcmntOffset = %ld\n", pHeader->cmntOffset);
|
||||
printf("\tcmntLen = %ld\n", pHeader->cmntLen);
|
||||
printf("\tcreatorOffset = %ld\n", pHeader->creatorOffset);
|
||||
printf("\tcreatorLen = %ld\n", pHeader->creatorLen);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ===========================================================================
|
||||
* Main functions
|
||||
* Main functions
|
||||
* ===========================================================================
|
||||
*/
|
||||
|
||||
|
@ -214,10 +214,10 @@ typedef enum ArchiveKind { kKindUnknown, kKindShk, kKindImg } ArchiveKind;
|
|||
*/
|
||||
NuError
|
||||
CreateProdosSource(const ImgHeader* pHeader, FILE* fp,
|
||||
NuDataSource** ppDataSource)
|
||||
NuDataSource** ppDataSource)
|
||||
{
|
||||
return NuCreateDataSourceForFP(kNuThreadFormatUncompressed, false, 0, fp,
|
||||
pHeader->dataOffset, pHeader->dataLen, ppDataSource);
|
||||
return NuCreateDataSourceForFP(kNuThreadFormatUncompressed, false, 0, fp,
|
||||
pHeader->dataOffset, pHeader->dataLen, ppDataSource);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -226,76 +226,76 @@ CreateProdosSource(const ImgHeader* pHeader, FILE* fp,
|
|||
*/
|
||||
NuError
|
||||
CreateDosSource(const ImgHeader* pHeader, FILE* fp,
|
||||
NuDataSource** ppDataSource)
|
||||
NuDataSource** ppDataSource)
|
||||
{
|
||||
NuError err;
|
||||
char* diskBuffer = nil;
|
||||
long offset;
|
||||
NuError err;
|
||||
char* diskBuffer = nil;
|
||||
long offset;
|
||||
|
||||
if (pHeader->dataLen % 4096) {
|
||||
fprintf(stderr,
|
||||
"ERROR: image size must be multiple of 4096 (%ld isn't)\n",
|
||||
pHeader->dataLen);
|
||||
err = kNuErrGeneric;
|
||||
goto bail;
|
||||
}
|
||||
if (pHeader->dataLen % 4096) {
|
||||
fprintf(stderr,
|
||||
"ERROR: image size must be multiple of 4096 (%ld isn't)\n",
|
||||
pHeader->dataLen);
|
||||
err = kNuErrGeneric;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (fseek(fp, pHeader->dataOffset, SEEK_SET) < 0) {
|
||||
err = errno;
|
||||
perror("fseek failed");
|
||||
goto bail;
|
||||
}
|
||||
if (fseek(fp, pHeader->dataOffset, SEEK_SET) < 0) {
|
||||
err = errno;
|
||||
perror("fseek failed");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
diskBuffer = malloc(pHeader->dataLen);
|
||||
if (diskBuffer == nil) {
|
||||
fprintf(stderr, "ERROR: malloc(%ld) failed\n", pHeader->dataLen);
|
||||
err = kNuErrMalloc;
|
||||
goto bail;
|
||||
}
|
||||
diskBuffer = malloc(pHeader->dataLen);
|
||||
if (diskBuffer == nil) {
|
||||
fprintf(stderr, "ERROR: malloc(%ld) failed\n", pHeader->dataLen);
|
||||
err = kNuErrMalloc;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Run through the image, reordering each track. This is a
|
||||
* reversible transformation, i.e. if you do this twice you're back
|
||||
* to ProDOS ordering.
|
||||
*/
|
||||
for (offset = 0; offset < pHeader->dataLen; offset += 4096) {
|
||||
fread(diskBuffer + offset + 0x0000, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0e00, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0d00, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0c00, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0b00, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0a00, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0900, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0800, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0700, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0600, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0500, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0400, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0300, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0200, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0100, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0f00, 256, 1, fp);
|
||||
}
|
||||
if (feof(fp) || ferror(fp)) {
|
||||
err = errno ? errno : -1;
|
||||
fprintf(stderr, "ERROR: failed while reading source file\n");
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* Run through the image, reordering each track. This is a
|
||||
* reversible transformation, i.e. if you do this twice you're back
|
||||
* to ProDOS ordering.
|
||||
*/
|
||||
for (offset = 0; offset < pHeader->dataLen; offset += 4096) {
|
||||
fread(diskBuffer + offset + 0x0000, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0e00, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0d00, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0c00, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0b00, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0a00, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0900, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0800, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0700, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0600, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0500, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0400, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0300, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0200, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0100, 256, 1, fp);
|
||||
fread(diskBuffer + offset + 0x0f00, 256, 1, fp);
|
||||
}
|
||||
if (feof(fp) || ferror(fp)) {
|
||||
err = errno ? errno : -1;
|
||||
fprintf(stderr, "ERROR: failed while reading source file\n");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a data source for the buffer. We set the "doClose" flag to
|
||||
* "true", so NufxLib will free the buffer for us.
|
||||
*/
|
||||
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true, 0,
|
||||
(const unsigned char*) diskBuffer, 0, pHeader->dataLen,
|
||||
ppDataSource);
|
||||
if (err == kNuErrNone)
|
||||
diskBuffer = nil;
|
||||
/*
|
||||
* Create a data source for the buffer. We set the "doClose" flag to
|
||||
* "true", so NufxLib will free the buffer for us.
|
||||
*/
|
||||
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true, 0,
|
||||
(const unsigned char*) diskBuffer, 0, pHeader->dataLen,
|
||||
ppDataSource);
|
||||
if (err == kNuErrNone)
|
||||
diskBuffer = nil;
|
||||
|
||||
bail:
|
||||
if (diskBuffer != nil)
|
||||
free(diskBuffer);
|
||||
return err;
|
||||
if (diskBuffer != nil)
|
||||
free(diskBuffer);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -309,146 +309,146 @@ bail:
|
|||
int
|
||||
ConvertFromImgToShk(const char* srcName, const char* dstName)
|
||||
{
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
NuDataSource* pDataSource = nil;
|
||||
NuRecordIdx recordIdx;
|
||||
NuFileDetails fileDetails;
|
||||
ImgHeader header;
|
||||
FILE* fp = nil;
|
||||
long flushStatus;
|
||||
char* storageName = nil;
|
||||
char* cp;
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
NuDataSource* pDataSource = nil;
|
||||
NuRecordIdx recordIdx;
|
||||
NuFileDetails fileDetails;
|
||||
ImgHeader header;
|
||||
FILE* fp = nil;
|
||||
long flushStatus;
|
||||
char* storageName = nil;
|
||||
char* cp;
|
||||
|
||||
printf("Converting 2IMG file '%s' to ShrinkIt archive '%s'\n\n",
|
||||
srcName, dstName);
|
||||
printf("Converting 2IMG file '%s' to ShrinkIt archive '%s'\n\n",
|
||||
srcName, dstName);
|
||||
|
||||
err = kNuErrGeneric;
|
||||
err = kNuErrGeneric;
|
||||
|
||||
fp = fopen(srcName, kNuFileOpenReadOnly);
|
||||
if (fp == NULL) {
|
||||
perror("fopen failed");
|
||||
goto bail;
|
||||
}
|
||||
fp = fopen(srcName, kNuFileOpenReadOnly);
|
||||
if (fp == NULL) {
|
||||
perror("fopen failed");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (ReadImgHeader(fp, &header) < 0) {
|
||||
fprintf(stderr, "ERROR: header read failed\n");
|
||||
goto bail;
|
||||
}
|
||||
if (ReadImgHeader(fp, &header) < 0) {
|
||||
fprintf(stderr, "ERROR: header read failed\n");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
DumpImgHeader(&header);
|
||||
DumpImgHeader(&header);
|
||||
|
||||
if (header.imageFormat != kImageFormatDOS &&
|
||||
header.imageFormat != kImageFormatProDOS)
|
||||
{
|
||||
fprintf(stderr, "ERROR: can only handle DOS and ProDOS images\n");
|
||||
goto bail;
|
||||
}
|
||||
if (header.imageFormat != kImageFormatDOS &&
|
||||
header.imageFormat != kImageFormatProDOS)
|
||||
{
|
||||
fprintf(stderr, "ERROR: can only handle DOS and ProDOS images\n");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (header.numBlocks > 1600)
|
||||
printf("WARNING: that's a big honking image!\n");
|
||||
if (header.numBlocks > 1600)
|
||||
printf("WARNING: that's a big honking image!\n");
|
||||
|
||||
/*
|
||||
* Open a new archive read-write. This refuses to overwrite an
|
||||
* existing file.
|
||||
*/
|
||||
(void) unlink(kTempFile);
|
||||
err = NuOpenRW(dstName, kTempFile, kNuOpenCreat|kNuOpenExcl, &pArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create archive (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* Open a new archive read-write. This refuses to overwrite an
|
||||
* existing file.
|
||||
*/
|
||||
(void) unlink(kTempFile);
|
||||
err = NuOpenRW(dstName, kTempFile, kNuOpenCreat|kNuOpenExcl, &pArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create archive (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* create the name that will be stored in the archive */
|
||||
storageName = strdup(dstName);
|
||||
cp = strrchr(storageName, '.');
|
||||
if (cp != nil)
|
||||
*cp = '\0';
|
||||
cp = strrchr(storageName, kLocalFssep);
|
||||
if (cp != nil && *(cp+1) != '\0')
|
||||
cp++;
|
||||
else
|
||||
cp = storageName;
|
||||
/* create the name that will be stored in the archive */
|
||||
storageName = strdup(dstName);
|
||||
cp = strrchr(storageName, '.');
|
||||
if (cp != nil)
|
||||
*cp = '\0';
|
||||
cp = strrchr(storageName, kLocalFssep);
|
||||
if (cp != nil && *(cp+1) != '\0')
|
||||
cp++;
|
||||
else
|
||||
cp = storageName;
|
||||
|
||||
/*
|
||||
* We can't say "add file", because NufxLib doesn't know what a 2MG
|
||||
* archive is. However, we can point a DataSource at the data in
|
||||
* the file, and construct the record manually.
|
||||
*/
|
||||
/*
|
||||
* We can't say "add file", because NufxLib doesn't know what a 2MG
|
||||
* archive is. However, we can point a DataSource at the data in
|
||||
* the file, and construct the record manually.
|
||||
*/
|
||||
|
||||
/* set up the contents of the NuFX Record */
|
||||
memset(&fileDetails, 0, sizeof(fileDetails));
|
||||
fileDetails.storageName = cp;
|
||||
fileDetails.fileSysID = kNuFileSysUnknown; /* DOS? ProDOS? */
|
||||
fileDetails.fileSysInfo = kLocalFssep;
|
||||
fileDetails.access = kNuAccessUnlocked;
|
||||
fileDetails.extraType = header.numBlocks;
|
||||
fileDetails.storageType = 512;
|
||||
/* FIX - ought to set the file dates */
|
||||
/* set up the contents of the NuFX Record */
|
||||
memset(&fileDetails, 0, sizeof(fileDetails));
|
||||
fileDetails.storageName = cp;
|
||||
fileDetails.fileSysID = kNuFileSysUnknown; /* DOS? ProDOS? */
|
||||
fileDetails.fileSysInfo = kLocalFssep;
|
||||
fileDetails.access = kNuAccessUnlocked;
|
||||
fileDetails.extraType = header.numBlocks;
|
||||
fileDetails.storageType = 512;
|
||||
/* FIX - ought to set the file dates */
|
||||
|
||||
/* add a new record */
|
||||
err = NuAddRecord(pArchive, &fileDetails, &recordIdx);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create record (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
/* add a new record */
|
||||
err = NuAddRecord(pArchive, &fileDetails, &recordIdx);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create record (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a data source for the 2IMG file. We do this differently
|
||||
* for DOS and ProDOS, because we have to rearrange the sector
|
||||
* ordering for DOS-ordered images (ShrinkIt always uses ProDOS order).
|
||||
*/
|
||||
switch (header.imageFormat) {
|
||||
case kImageFormatDOS:
|
||||
err = CreateDosSource(&header, fp, &pDataSource);
|
||||
break;
|
||||
case kImageFormatProDOS:
|
||||
err = CreateProdosSource(&header, fp, &pDataSource);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "How the heck did I get here?");
|
||||
err = kNuErrInternal;
|
||||
goto bail;
|
||||
}
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create data source (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* Create a data source for the 2IMG file. We do this differently
|
||||
* for DOS and ProDOS, because we have to rearrange the sector
|
||||
* ordering for DOS-ordered images (ShrinkIt always uses ProDOS order).
|
||||
*/
|
||||
switch (header.imageFormat) {
|
||||
case kImageFormatDOS:
|
||||
err = CreateDosSource(&header, fp, &pDataSource);
|
||||
break;
|
||||
case kImageFormatProDOS:
|
||||
err = CreateProdosSource(&header, fp, &pDataSource);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "How the heck did I get here?");
|
||||
err = kNuErrInternal;
|
||||
goto bail;
|
||||
}
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create data source (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* add a disk image thread */
|
||||
err = NuAddThread(pArchive, recordIdx, kNuThreadIDDiskImage, pDataSource,
|
||||
nil);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create thread (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
pDataSource = nil; /* library owns it now */
|
||||
/* add a disk image thread */
|
||||
err = NuAddThread(pArchive, recordIdx, kNuThreadIDDiskImage, pDataSource,
|
||||
nil);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create thread (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
pDataSource = nil; /* library owns it now */
|
||||
|
||||
/* nothing happens until we Flush */
|
||||
err = NuFlush(pArchive, &flushStatus);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: flush failed (err=%d, status=0x%04lx)\n",
|
||||
err, flushStatus);
|
||||
goto bail;
|
||||
}
|
||||
err = NuClose(pArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: close failed (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
pArchive = nil;
|
||||
/* nothing happens until we Flush */
|
||||
err = NuFlush(pArchive, &flushStatus);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: flush failed (err=%d, status=0x%04lx)\n",
|
||||
err, flushStatus);
|
||||
goto bail;
|
||||
}
|
||||
err = NuClose(pArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: close failed (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
pArchive = nil;
|
||||
|
||||
bail:
|
||||
if (pArchive != nil) {
|
||||
(void)NuAbort(pArchive);
|
||||
(void)NuClose(pArchive);
|
||||
}
|
||||
NuFreeDataSource(pDataSource);
|
||||
if (storageName != nil)
|
||||
free(storageName);
|
||||
if (fp != nil)
|
||||
fclose(fp);
|
||||
return (err == kNuErrNone) ? 0 : -1;
|
||||
if (pArchive != nil) {
|
||||
(void)NuAbort(pArchive);
|
||||
(void)NuClose(pArchive);
|
||||
}
|
||||
NuFreeDataSource(pDataSource);
|
||||
if (storageName != nil)
|
||||
free(storageName);
|
||||
if (fp != nil)
|
||||
fclose(fp);
|
||||
return (err == kNuErrNone) ? 0 : -1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -461,109 +461,109 @@ bail:
|
|||
int
|
||||
ConvertFromShkToImg(const char* srcName, const char* dstName)
|
||||
{
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
NuDataSink* pDataSink = nil;
|
||||
NuRecordIdx recordIdx;
|
||||
const NuRecord* pRecord;
|
||||
const NuThread* pThread = nil;
|
||||
ImgHeader header;
|
||||
FILE* fp = nil;
|
||||
int idx;
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
NuDataSink* pDataSink = nil;
|
||||
NuRecordIdx recordIdx;
|
||||
const NuRecord* pRecord;
|
||||
const NuThread* pThread = nil;
|
||||
ImgHeader header;
|
||||
FILE* fp = nil;
|
||||
int idx;
|
||||
|
||||
printf("Converting ShrinkIt archive '%s' to 2IMG file '%s'\n\n",
|
||||
srcName, dstName);
|
||||
printf("Converting ShrinkIt archive '%s' to 2IMG file '%s'\n\n",
|
||||
srcName, dstName);
|
||||
|
||||
/*
|
||||
* Open the archive.
|
||||
*/
|
||||
err = NuOpenRO(srcName, &pArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to open archive (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* Open the archive.
|
||||
*/
|
||||
err = NuOpenRO(srcName, &pArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to open archive (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* get the first record */
|
||||
err = NuGetRecordIdxByPosition(pArchive, 0, &recordIdx);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to get first recordIdx (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
err = NuGetRecord(pArchive, recordIdx, &pRecord);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to get first record (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
/* get the first record */
|
||||
err = NuGetRecordIdxByPosition(pArchive, 0, &recordIdx);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to get first recordIdx (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
err = NuGetRecord(pArchive, recordIdx, &pRecord);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to get first record (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* find a disk image thread */
|
||||
for (idx = 0; idx < (int)NuRecordGetNumThreads(pRecord); idx++) {
|
||||
pThread = NuGetThread(pRecord, idx);
|
||||
/* find a disk image thread */
|
||||
for (idx = 0; idx < (int)NuRecordGetNumThreads(pRecord); idx++) {
|
||||
pThread = NuGetThread(pRecord, idx);
|
||||
|
||||
if (NuGetThreadID(pThread) == kNuThreadIDDiskImage)
|
||||
break;
|
||||
}
|
||||
if (idx == (int)NuRecordGetNumThreads(pRecord)) {
|
||||
fprintf(stderr, "ERROR: no disk image found in first record\n");
|
||||
err = -1;
|
||||
goto bail;
|
||||
}
|
||||
if (NuGetThreadID(pThread) == kNuThreadIDDiskImage)
|
||||
break;
|
||||
}
|
||||
if (idx == (int)NuRecordGetNumThreads(pRecord)) {
|
||||
fprintf(stderr, "ERROR: no disk image found in first record\n");
|
||||
err = -1;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Looks good. Open the 2IMG file, and create the header.
|
||||
*/
|
||||
if (access(dstName, F_OK) == 0) {
|
||||
fprintf(stderr, "ERROR: output file already exists\n");
|
||||
err = -1;
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* Looks good. Open the 2IMG file, and create the header.
|
||||
*/
|
||||
if (access(dstName, F_OK) == 0) {
|
||||
fprintf(stderr, "ERROR: output file already exists\n");
|
||||
err = -1;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
fp = fopen(dstName, kNuFileOpenWriteTrunc);
|
||||
if (fp == NULL) {
|
||||
perror("fopen failed");
|
||||
goto bail;
|
||||
}
|
||||
fp = fopen(dstName, kNuFileOpenWriteTrunc);
|
||||
if (fp == NULL) {
|
||||
perror("fopen failed");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* set up the 2MG header, based on the NuFX Record */
|
||||
memset(&header, 0, sizeof(header));
|
||||
memcpy(header.magic, kImgMagic, sizeof(header.magic));
|
||||
memcpy(header.creator, kMyCreator, sizeof(header.creator));
|
||||
header.headerLen = 64;
|
||||
header.version = 1;
|
||||
header.imageFormat = kImageFormatProDOS; /* always ProDOS-order */
|
||||
header.numBlocks = pRecord->recExtraType;
|
||||
header.dataOffset = 64;
|
||||
/* old versions of ShrinkIt blew the threadEOF, so use NufxLib's "actual" */
|
||||
header.dataLen = pThread->actualThreadEOF;
|
||||
DumpImgHeader(&header);
|
||||
if (WriteImgHeader(fp, &header) < 0) {
|
||||
fprintf(stderr, "ERROR: header write failed\n");
|
||||
err = -1;
|
||||
goto bail;
|
||||
}
|
||||
/* set up the 2MG header, based on the NuFX Record */
|
||||
memset(&header, 0, sizeof(header));
|
||||
memcpy(header.magic, kImgMagic, sizeof(header.magic));
|
||||
memcpy(header.creator, kMyCreator, sizeof(header.creator));
|
||||
header.headerLen = 64;
|
||||
header.version = 1;
|
||||
header.imageFormat = kImageFormatProDOS; /* always ProDOS-order */
|
||||
header.numBlocks = pRecord->recExtraType;
|
||||
header.dataOffset = 64;
|
||||
/* old versions of ShrinkIt blew the threadEOF, so use NufxLib's "actual" */
|
||||
header.dataLen = pThread->actualThreadEOF;
|
||||
DumpImgHeader(&header);
|
||||
if (WriteImgHeader(fp, &header) < 0) {
|
||||
fprintf(stderr, "ERROR: header write failed\n");
|
||||
err = -1;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* We want to expand the disk image thread into "fp" at the current
|
||||
* offset.
|
||||
*/
|
||||
err = NuCreateDataSinkForFP(true, kNuConvertOff, fp, &pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create data sink (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* We want to expand the disk image thread into "fp" at the current
|
||||
* offset.
|
||||
*/
|
||||
err = NuCreateDataSinkForFP(true, kNuConvertOff, fp, &pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create data sink (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to extract thread (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to extract thread (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
bail:
|
||||
if (pArchive != nil)
|
||||
NuClose(pArchive);
|
||||
NuFreeDataSink(pDataSink);
|
||||
if (fp != nil)
|
||||
fclose(fp);
|
||||
return (err == kNuErrNone) ? 0 : -1;
|
||||
if (pArchive != nil)
|
||||
NuClose(pArchive);
|
||||
NuFreeDataSink(pDataSink);
|
||||
if (fp != nil)
|
||||
fclose(fp);
|
||||
return (err == kNuErrNone) ? 0 : -1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -573,18 +573,18 @@ bail:
|
|||
ArchiveKind
|
||||
DetermineKind(const char* filename)
|
||||
{
|
||||
const char* dot;
|
||||
const char* dot;
|
||||
|
||||
dot = strrchr(filename, '.');
|
||||
if (dot == nil)
|
||||
return kKindUnknown;
|
||||
dot = strrchr(filename, '.');
|
||||
if (dot == nil)
|
||||
return kKindUnknown;
|
||||
|
||||
if (strcasecmp(dot, ".shk") == 0 || strcasecmp(dot, ".sdk") == 0)
|
||||
return kKindShk;
|
||||
else if (strcasecmp(dot, ".2mg") == 0)
|
||||
return kKindImg;
|
||||
if (strcasecmp(dot, ".shk") == 0 || strcasecmp(dot, ".sdk") == 0)
|
||||
return kKindShk;
|
||||
else if (strcasecmp(dot, ".2mg") == 0)
|
||||
return kKindImg;
|
||||
|
||||
return kKindUnknown;
|
||||
return kKindUnknown;
|
||||
}
|
||||
|
||||
|
||||
|
@ -595,30 +595,30 @@ DetermineKind(const char* filename)
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
ArchiveKind kind;
|
||||
int cc;
|
||||
ArchiveKind kind;
|
||||
int cc;
|
||||
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: %s (input.2mg|input.shk) output\n", argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: %s (input.2mg|input.shk) output\n", argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
kind = DetermineKind(argv[1]);
|
||||
if (kind == kKindUnknown) {
|
||||
fprintf(stderr, "ERROR: input name must end in '.shk' or '.2mg'\n");
|
||||
exit(2);
|
||||
}
|
||||
kind = DetermineKind(argv[1]);
|
||||
if (kind == kKindUnknown) {
|
||||
fprintf(stderr, "ERROR: input name must end in '.shk' or '.2mg'\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if (kind == kKindShk)
|
||||
cc = ConvertFromShkToImg(argv[1], argv[2]);
|
||||
else
|
||||
cc = ConvertFromImgToShk(argv[1], argv[2]);
|
||||
if (kind == kKindShk)
|
||||
cc = ConvertFromShkToImg(argv[1], argv[2]);
|
||||
else
|
||||
cc = ConvertFromImgToShk(argv[1], argv[2]);
|
||||
|
||||
if (cc)
|
||||
fprintf(stderr, "Failed\n");
|
||||
else
|
||||
printf("Done!\n");
|
||||
if (cc)
|
||||
fprintf(stderr, "Failed\n");
|
||||
else
|
||||
printf("Done!\n");
|
||||
|
||||
exit(cc != 0);
|
||||
exit(cc != 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,13 +29,13 @@
|
|||
#include "Common.h"
|
||||
|
||||
|
||||
#define kTempFile "tmp-laundry"
|
||||
#define kTempFile "tmp-laundry"
|
||||
|
||||
#define kFlagCopyOnly (1)
|
||||
#define kFlagReverseThreads (1 << 1)
|
||||
#define kFlagFrequentFlush (1 << 2)
|
||||
#define kFlagFrequentAbort (1 << 3) /* implies FrequentFlush */
|
||||
#define kFlagUseTmp (1 << 4)
|
||||
#define kFlagCopyOnly (1)
|
||||
#define kFlagReverseThreads (1 << 1)
|
||||
#define kFlagFrequentFlush (1 << 2)
|
||||
#define kFlagFrequentAbort (1 << 3) /* implies FrequentFlush */
|
||||
#define kFlagUseTmp (1 << 4)
|
||||
|
||||
|
||||
/*
|
||||
|
@ -53,99 +53,99 @@ char gSentRecordWarning = false;
|
|||
*/
|
||||
NuError
|
||||
CopyThreadRecompressed(NuArchive* pInArchive, NuArchive* pOutArchive,
|
||||
long flags, const NuThread* pThread, long newRecordIdx)
|
||||
long flags, const NuThread* pThread, long newRecordIdx)
|
||||
{
|
||||
NuError err = kNuErrNone;
|
||||
NuDataSource* pDataSource = nil;
|
||||
NuDataSink* pDataSink = nil;
|
||||
uchar* buffer = nil;
|
||||
NuError err = kNuErrNone;
|
||||
NuDataSource* pDataSource = nil;
|
||||
NuDataSink* pDataSink = nil;
|
||||
uchar* buffer = nil;
|
||||
|
||||
/*
|
||||
* Allocate a buffer large enough to hold all the uncompressed data, and
|
||||
* wrap a data sink around it.
|
||||
*
|
||||
* If the thread is zero bytes long, we can skip this part.
|
||||
*/
|
||||
if (pThread->actualThreadEOF) {
|
||||
buffer = malloc(pThread->actualThreadEOF);
|
||||
if (buffer == nil) {
|
||||
err = kNuErrMalloc;
|
||||
goto bail;
|
||||
}
|
||||
err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buffer,
|
||||
pThread->actualThreadEOF, &pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create data sink (err=%d)\n",
|
||||
err);
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* Allocate a buffer large enough to hold all the uncompressed data, and
|
||||
* wrap a data sink around it.
|
||||
*
|
||||
* If the thread is zero bytes long, we can skip this part.
|
||||
*/
|
||||
if (pThread->actualThreadEOF) {
|
||||
buffer = malloc(pThread->actualThreadEOF);
|
||||
if (buffer == nil) {
|
||||
err = kNuErrMalloc;
|
||||
goto bail;
|
||||
}
|
||||
err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buffer,
|
||||
pThread->actualThreadEOF, &pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create data sink (err=%d)\n",
|
||||
err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Expand the data. For a pre-sized thread, this grabs only the
|
||||
* interesting part of the buffer.
|
||||
*/
|
||||
err = NuExtractThread(pInArchive, pThread->threadIdx, pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to extract thread %ld (err=%d)\n",
|
||||
pThread->threadIdx, err);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Expand the data. For a pre-sized thread, this grabs only the
|
||||
* interesting part of the buffer.
|
||||
*/
|
||||
err = NuExtractThread(pInArchive, pThread->threadIdx, pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to extract thread %ld (err=%d)\n",
|
||||
pThread->threadIdx, err);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The expanded data is in the buffer, now create a data source that
|
||||
* describes it.
|
||||
*
|
||||
* This is complicated by the existence of pre-sized threads, which
|
||||
* require us to set "otherLen".
|
||||
*
|
||||
* We always use "actualThreadEOF" because "thThreadEOF" is broken
|
||||
* for disk archives created by certain versions of ShrinkIt.
|
||||
*
|
||||
* It's okay to pass in a nil value for "buffer", so long as the
|
||||
* amount of data in the buffer is also zero. The library will do
|
||||
* the right thing.
|
||||
*/
|
||||
if (NuIsPresizedThreadID(NuGetThreadID(pThread))) {
|
||||
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true,
|
||||
pThread->thCompThreadEOF, buffer, 0,
|
||||
pThread->actualThreadEOF, &pDataSource);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr,
|
||||
"ERROR: unable to create pre-sized data source (err=%d)\n",err);
|
||||
goto bail;
|
||||
}
|
||||
} else {
|
||||
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true,
|
||||
0, buffer, 0,
|
||||
pThread->actualThreadEOF, &pDataSource);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr,
|
||||
"ERROR: unable to create data source (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
buffer = nil; /* doClose was set, so it's owned by the data source */
|
||||
/*
|
||||
* The expanded data is in the buffer, now create a data source that
|
||||
* describes it.
|
||||
*
|
||||
* This is complicated by the existence of pre-sized threads, which
|
||||
* require us to set "otherLen".
|
||||
*
|
||||
* We always use "actualThreadEOF" because "thThreadEOF" is broken
|
||||
* for disk archives created by certain versions of ShrinkIt.
|
||||
*
|
||||
* It's okay to pass in a nil value for "buffer", so long as the
|
||||
* amount of data in the buffer is also zero. The library will do
|
||||
* the right thing.
|
||||
*/
|
||||
if (NuIsPresizedThreadID(NuGetThreadID(pThread))) {
|
||||
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true,
|
||||
pThread->thCompThreadEOF, buffer, 0,
|
||||
pThread->actualThreadEOF, &pDataSource);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr,
|
||||
"ERROR: unable to create pre-sized data source (err=%d)\n",err);
|
||||
goto bail;
|
||||
}
|
||||
} else {
|
||||
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true,
|
||||
0, buffer, 0,
|
||||
pThread->actualThreadEOF, &pDataSource);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr,
|
||||
"ERROR: unable to create data source (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
buffer = nil; /* doClose was set, so it's owned by the data source */
|
||||
|
||||
/*
|
||||
* Schedule the data for addition to the record.
|
||||
*/
|
||||
err = NuAddThread(pOutArchive, newRecordIdx, NuGetThreadID(pThread),
|
||||
pDataSource, nil);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to add thread (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
pDataSource = nil; /* library owns it now */
|
||||
/*
|
||||
* Schedule the data for addition to the record.
|
||||
*/
|
||||
err = NuAddThread(pOutArchive, newRecordIdx, NuGetThreadID(pThread),
|
||||
pDataSource, nil);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to add thread (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
pDataSource = nil; /* library owns it now */
|
||||
|
||||
bail:
|
||||
if (pDataSource != nil)
|
||||
NuFreeDataSource(pDataSource);
|
||||
if (pDataSink != nil)
|
||||
NuFreeDataSink(pDataSink);
|
||||
if (buffer != nil)
|
||||
free(buffer);
|
||||
return err;
|
||||
if (pDataSource != nil)
|
||||
NuFreeDataSource(pDataSource);
|
||||
if (pDataSink != nil)
|
||||
NuFreeDataSink(pDataSink);
|
||||
if (buffer != nil)
|
||||
free(buffer);
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -167,122 +167,122 @@ bail:
|
|||
*/
|
||||
NuError
|
||||
CopyThreadUncompressed(NuArchive* pInArchive, NuArchive* pOutArchive,
|
||||
long flags, const NuThread* pThread, long newRecordIdx)
|
||||
long flags, const NuThread* pThread, long newRecordIdx)
|
||||
{
|
||||
NuError err = kNuErrNone;
|
||||
NuDataSource* pDataSource = nil;
|
||||
NuDataSink* pDataSink = nil;
|
||||
uchar* buffer = nil;
|
||||
NuError err = kNuErrNone;
|
||||
NuDataSource* pDataSource = nil;
|
||||
NuDataSink* pDataSink = nil;
|
||||
uchar* buffer = nil;
|
||||
|
||||
/*
|
||||
* If we have some data files that were left uncompressed, perhaps
|
||||
* because of GSHK's "don't compress anything smaller than 512 bytes"
|
||||
* rule, NufxLib will try to compress them. We disable this
|
||||
* behavior by disabling compression. That way, stuff that is
|
||||
* already compressed will remain that way, and stuff that isn't
|
||||
* compressed won't be. (We really only need to do this once, at
|
||||
* the start of the program, but it's illustrative to do it here.)
|
||||
*/
|
||||
err = NuSetValue(pOutArchive, kNuValueDataCompression, kNuCompressNone);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to set compression (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* If we have some data files that were left uncompressed, perhaps
|
||||
* because of GSHK's "don't compress anything smaller than 512 bytes"
|
||||
* rule, NufxLib will try to compress them. We disable this
|
||||
* behavior by disabling compression. That way, stuff that is
|
||||
* already compressed will remain that way, and stuff that isn't
|
||||
* compressed won't be. (We really only need to do this once, at
|
||||
* the start of the program, but it's illustrative to do it here.)
|
||||
*/
|
||||
err = NuSetValue(pOutArchive, kNuValueDataCompression, kNuCompressNone);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to set compression (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a buffer large enough to hold all the compressed data, and
|
||||
* wrap a data sink around it.
|
||||
*/
|
||||
buffer = malloc(pThread->thCompThreadEOF);
|
||||
if (buffer == nil) {
|
||||
err = kNuErrMalloc;
|
||||
goto bail;
|
||||
}
|
||||
err = NuCreateDataSinkForBuffer(false, kNuConvertOff, buffer,
|
||||
pThread->thCompThreadEOF, &pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create data sink (err=%d)\n",
|
||||
err);
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* Allocate a buffer large enough to hold all the compressed data, and
|
||||
* wrap a data sink around it.
|
||||
*/
|
||||
buffer = malloc(pThread->thCompThreadEOF);
|
||||
if (buffer == nil) {
|
||||
err = kNuErrMalloc;
|
||||
goto bail;
|
||||
}
|
||||
err = NuCreateDataSinkForBuffer(false, kNuConvertOff, buffer,
|
||||
pThread->thCompThreadEOF, &pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to create data sink (err=%d)\n",
|
||||
err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the compressed data. For a pre-sized thread, this grabs the
|
||||
* entire contents of the buffer, including the padding.
|
||||
*/
|
||||
err = NuExtractThread(pInArchive, pThread->threadIdx, pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to extract thread %ld (err=%d)\n",
|
||||
pThread->threadIdx, err);
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* Get the compressed data. For a pre-sized thread, this grabs the
|
||||
* entire contents of the buffer, including the padding.
|
||||
*/
|
||||
err = NuExtractThread(pInArchive, pThread->threadIdx, pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to extract thread %ld (err=%d)\n",
|
||||
pThread->threadIdx, err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* The (perhaps compressed) data is in the buffer, now create a data
|
||||
* source that describes it.
|
||||
*
|
||||
* This is complicated by the existence of pre-sized threads. There
|
||||
* are two possibilities:
|
||||
* 1. We have a certain amount of non-pre-sized data (thCompThreadEOF)
|
||||
* that will expand out to a certain length (actualThreadEOF).
|
||||
* 2. We have a certain amount of pre-sized data (actualThreadEOF)
|
||||
* that will fit within a buffer (thCompThreadEOF).
|
||||
* As you can see, the arguments need to be reversed for pre-sized
|
||||
* threads.
|
||||
*
|
||||
* We always use "actualThreadEOF" because "thThreadEOF" is broken
|
||||
* for disk archives created by certain versions of ShrinkIt.
|
||||
*/
|
||||
if (NuIsPresizedThreadID(NuGetThreadID(pThread))) {
|
||||
err = NuCreateDataSourceForBuffer(pThread->thThreadFormat, true,
|
||||
pThread->thCompThreadEOF, buffer, 0,
|
||||
pThread->actualThreadEOF, &pDataSource);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr,
|
||||
"ERROR: unable to create pre-sized data source (err=%d)\n",err);
|
||||
goto bail;
|
||||
}
|
||||
} else {
|
||||
err = NuCreateDataSourceForBuffer(pThread->thThreadFormat, true,
|
||||
pThread->actualThreadEOF, buffer, 0,
|
||||
pThread->thCompThreadEOF, &pDataSource);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr,
|
||||
"ERROR: unable to create data source (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
buffer = nil; /* doClose was set, so it's owned by the data source */
|
||||
/*
|
||||
* The (perhaps compressed) data is in the buffer, now create a data
|
||||
* source that describes it.
|
||||
*
|
||||
* This is complicated by the existence of pre-sized threads. There
|
||||
* are two possibilities:
|
||||
* 1. We have a certain amount of non-pre-sized data (thCompThreadEOF)
|
||||
* that will expand out to a certain length (actualThreadEOF).
|
||||
* 2. We have a certain amount of pre-sized data (actualThreadEOF)
|
||||
* that will fit within a buffer (thCompThreadEOF).
|
||||
* As you can see, the arguments need to be reversed for pre-sized
|
||||
* threads.
|
||||
*
|
||||
* We always use "actualThreadEOF" because "thThreadEOF" is broken
|
||||
* for disk archives created by certain versions of ShrinkIt.
|
||||
*/
|
||||
if (NuIsPresizedThreadID(NuGetThreadID(pThread))) {
|
||||
err = NuCreateDataSourceForBuffer(pThread->thThreadFormat, true,
|
||||
pThread->thCompThreadEOF, buffer, 0,
|
||||
pThread->actualThreadEOF, &pDataSource);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr,
|
||||
"ERROR: unable to create pre-sized data source (err=%d)\n",err);
|
||||
goto bail;
|
||||
}
|
||||
} else {
|
||||
err = NuCreateDataSourceForBuffer(pThread->thThreadFormat, true,
|
||||
pThread->actualThreadEOF, buffer, 0,
|
||||
pThread->thCompThreadEOF, &pDataSource);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr,
|
||||
"ERROR: unable to create data source (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
buffer = nil; /* doClose was set, so it's owned by the data source */
|
||||
|
||||
/* yes, this is a kluge... sigh */
|
||||
err = NuDataSourceSetRawCrc(pDataSource, pThread->thThreadCRC);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: can't set source CRC (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
/* yes, this is a kluge... sigh */
|
||||
err = NuDataSourceSetRawCrc(pDataSource, pThread->thThreadCRC);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: can't set source CRC (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Schedule the data for addition to the record.
|
||||
*
|
||||
* Note that NuAddThread makes a copy of the data source, and clears
|
||||
* "doClose" on our copy, so we are free to dispose of pDataSource.
|
||||
*/
|
||||
err = NuAddThread(pOutArchive, newRecordIdx, NuGetThreadID(pThread),
|
||||
pDataSource, nil);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to add thread (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
pDataSource = nil; /* library owns it now */
|
||||
/*
|
||||
* Schedule the data for addition to the record.
|
||||
*
|
||||
* Note that NuAddThread makes a copy of the data source, and clears
|
||||
* "doClose" on our copy, so we are free to dispose of pDataSource.
|
||||
*/
|
||||
err = NuAddThread(pOutArchive, newRecordIdx, NuGetThreadID(pThread),
|
||||
pDataSource, nil);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to add thread (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
pDataSource = nil; /* library owns it now */
|
||||
|
||||
bail:
|
||||
if (pDataSource != nil)
|
||||
NuFreeDataSource(pDataSource);
|
||||
if (pDataSink != nil)
|
||||
NuFreeDataSink(pDataSink);
|
||||
if (buffer != nil)
|
||||
free(buffer);
|
||||
return err;
|
||||
if (pDataSource != nil)
|
||||
NuFreeDataSource(pDataSource);
|
||||
if (pDataSink != nil)
|
||||
NuFreeDataSink(pDataSink);
|
||||
if (buffer != nil)
|
||||
free(buffer);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -294,15 +294,15 @@ bail:
|
|||
*/
|
||||
NuError
|
||||
CopyThread(NuArchive* pInArchive, NuArchive* pOutArchive, long flags,
|
||||
const NuThread* pThread, long newRecordIdx)
|
||||
const NuThread* pThread, long newRecordIdx)
|
||||
{
|
||||
if (flags & kFlagCopyOnly) {
|
||||
return CopyThreadUncompressed(pInArchive, pOutArchive, flags, pThread,
|
||||
newRecordIdx);
|
||||
} else {
|
||||
return CopyThreadRecompressed(pInArchive, pOutArchive, flags, pThread,
|
||||
newRecordIdx);
|
||||
}
|
||||
if (flags & kFlagCopyOnly) {
|
||||
return CopyThreadUncompressed(pInArchive, pOutArchive, flags, pThread,
|
||||
newRecordIdx);
|
||||
} else {
|
||||
return CopyThreadRecompressed(pInArchive, pOutArchive, flags, pThread,
|
||||
newRecordIdx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -316,91 +316,91 @@ CopyThread(NuArchive* pInArchive, NuArchive* pOutArchive, long flags,
|
|||
*/
|
||||
NuError
|
||||
CopyRecord(NuArchive* pInArchive, NuArchive* pOutArchive, long flags,
|
||||
NuRecordIdx recordIdx)
|
||||
NuRecordIdx recordIdx)
|
||||
{
|
||||
NuError err = kNuErrNone;
|
||||
const NuRecord* pRecord;
|
||||
const NuThread* pThread;
|
||||
NuFileDetails fileDetails;
|
||||
NuRecordIdx newRecordIdx;
|
||||
long numThreads;
|
||||
int idx;
|
||||
NuError err = kNuErrNone;
|
||||
const NuRecord* pRecord;
|
||||
const NuThread* pThread;
|
||||
NuFileDetails fileDetails;
|
||||
NuRecordIdx newRecordIdx;
|
||||
long numThreads;
|
||||
int idx;
|
||||
|
||||
/*
|
||||
* Grab the original record and see how many threads it has.
|
||||
*/
|
||||
err = NuGetRecord(pInArchive, recordIdx, &pRecord);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to get recordIdx %ld\n", recordIdx);
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* Grab the original record and see how many threads it has.
|
||||
*/
|
||||
err = NuGetRecord(pInArchive, recordIdx, &pRecord);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to get recordIdx %ld\n", recordIdx);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Pre-v3 records didn't put CRCs in the thread headers. If we just
|
||||
* copy the thread over without reprocessing the data, we won't compute
|
||||
* a CRC for the thread, and we will get CRC failures.
|
||||
*/
|
||||
if (!gSentRecordWarning && (flags & kFlagCopyOnly) &&
|
||||
pRecord->recVersionNumber < 3)
|
||||
{
|
||||
printf("WARNING: pre-v3 records that aren't recompressed may exhibit CRC failures\n");
|
||||
gSentRecordWarning = true;
|
||||
}
|
||||
/*
|
||||
* Pre-v3 records didn't put CRCs in the thread headers. If we just
|
||||
* copy the thread over without reprocessing the data, we won't compute
|
||||
* a CRC for the thread, and we will get CRC failures.
|
||||
*/
|
||||
if (!gSentRecordWarning && (flags & kFlagCopyOnly) &&
|
||||
pRecord->recVersionNumber < 3)
|
||||
{
|
||||
printf("WARNING: pre-v3 records that aren't recompressed may exhibit CRC failures\n");
|
||||
gSentRecordWarning = true;
|
||||
}
|
||||
|
||||
numThreads = NuRecordGetNumThreads(pRecord);
|
||||
if (!numThreads) {
|
||||
fprintf(stderr, "WARNING: recordIdx=%ld was empty\n", recordIdx);
|
||||
goto bail;
|
||||
}
|
||||
numThreads = NuRecordGetNumThreads(pRecord);
|
||||
if (!numThreads) {
|
||||
fprintf(stderr, "WARNING: recordIdx=%ld was empty\n", recordIdx);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new record that looks just like the original.
|
||||
*/
|
||||
memset(&fileDetails, 0, sizeof(fileDetails));
|
||||
fileDetails.storageName = pRecord->filename;
|
||||
fileDetails.fileSysID = pRecord->recFileSysID;
|
||||
fileDetails.fileSysInfo = pRecord->recFileSysInfo;
|
||||
fileDetails.access = pRecord->recAccess;
|
||||
fileDetails.fileType = pRecord->recFileType;
|
||||
fileDetails.extraType = pRecord->recExtraType;
|
||||
fileDetails.storageType = pRecord->recStorageType;
|
||||
fileDetails.createWhen = pRecord->recCreateWhen;
|
||||
fileDetails.modWhen = pRecord->recModWhen;
|
||||
fileDetails.archiveWhen = pRecord->recArchiveWhen;
|
||||
/*
|
||||
* Create a new record that looks just like the original.
|
||||
*/
|
||||
memset(&fileDetails, 0, sizeof(fileDetails));
|
||||
fileDetails.storageName = pRecord->filename;
|
||||
fileDetails.fileSysID = pRecord->recFileSysID;
|
||||
fileDetails.fileSysInfo = pRecord->recFileSysInfo;
|
||||
fileDetails.access = pRecord->recAccess;
|
||||
fileDetails.fileType = pRecord->recFileType;
|
||||
fileDetails.extraType = pRecord->recExtraType;
|
||||
fileDetails.storageType = pRecord->recStorageType;
|
||||
fileDetails.createWhen = pRecord->recCreateWhen;
|
||||
fileDetails.modWhen = pRecord->recModWhen;
|
||||
fileDetails.archiveWhen = pRecord->recArchiveWhen;
|
||||
|
||||
err = NuAddRecord(pOutArchive, &fileDetails, &newRecordIdx);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: NuAddRecord failed (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
err = NuAddRecord(pOutArchive, &fileDetails, &newRecordIdx);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: NuAddRecord failed (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy the threads.
|
||||
*/
|
||||
if (flags & kFlagReverseThreads) {
|
||||
for (idx = numThreads-1; idx >= 0; idx--) {
|
||||
pThread = NuGetThread(pRecord, idx);
|
||||
assert(pThread != nil);
|
||||
/*
|
||||
* Copy the threads.
|
||||
*/
|
||||
if (flags & kFlagReverseThreads) {
|
||||
for (idx = numThreads-1; idx >= 0; idx--) {
|
||||
pThread = NuGetThread(pRecord, idx);
|
||||
assert(pThread != nil);
|
||||
|
||||
err = CopyThread(pInArchive, pOutArchive, flags, pThread,
|
||||
newRecordIdx);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
}
|
||||
} else {
|
||||
for (idx = 0; idx < numThreads; idx++) {
|
||||
pThread = NuGetThread(pRecord, idx);
|
||||
assert(pThread != nil);
|
||||
err = CopyThread(pInArchive, pOutArchive, flags, pThread,
|
||||
newRecordIdx);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
}
|
||||
} else {
|
||||
for (idx = 0; idx < numThreads; idx++) {
|
||||
pThread = NuGetThread(pRecord, idx);
|
||||
assert(pThread != nil);
|
||||
|
||||
err = CopyThread(pInArchive, pOutArchive, flags, pThread,
|
||||
newRecordIdx);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
err = CopyThread(pInArchive, pOutArchive, flags, pThread,
|
||||
newRecordIdx);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
|
||||
bail:
|
||||
return err;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -412,113 +412,113 @@ bail:
|
|||
int
|
||||
LaunderArchive(const char* inFile, const char* outFile, long flags)
|
||||
{
|
||||
NuError err = kNuErrNone;
|
||||
NuArchive* pInArchive = nil;
|
||||
NuArchive* pOutArchive = nil;
|
||||
const NuMasterHeader* pMasterHeader;
|
||||
NuRecordIdx recordIdx;
|
||||
long idx, flushStatus;
|
||||
NuError err = kNuErrNone;
|
||||
NuArchive* pInArchive = nil;
|
||||
NuArchive* pOutArchive = nil;
|
||||
const NuMasterHeader* pMasterHeader;
|
||||
NuRecordIdx recordIdx;
|
||||
long idx, flushStatus;
|
||||
|
||||
err = NuOpenRO(inFile, &pInArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: couldn't open input archive '%s' (err=%d)\n",
|
||||
inFile, err);
|
||||
goto bail;
|
||||
}
|
||||
err = NuOpenRW(outFile, kTempFile, kNuOpenCreat|kNuOpenExcl, &pOutArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: couldn't open output archive '%s' (err=%d)\n",
|
||||
outFile, err);
|
||||
goto bail;
|
||||
}
|
||||
err = NuOpenRO(inFile, &pInArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: couldn't open input archive '%s' (err=%d)\n",
|
||||
inFile, err);
|
||||
goto bail;
|
||||
}
|
||||
err = NuOpenRW(outFile, kTempFile, kNuOpenCreat|kNuOpenExcl, &pOutArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: couldn't open output archive '%s' (err=%d)\n",
|
||||
outFile, err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* allow duplicates, in case the original archive has them */
|
||||
err = NuSetValue(pOutArchive, kNuValueAllowDuplicates, true);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: couldn't allow duplicates (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
/* allow duplicates, in case the original archive has them */
|
||||
err = NuSetValue(pOutArchive, kNuValueAllowDuplicates, true);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: couldn't allow duplicates (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (flags & kFlagUseTmp) {
|
||||
err = NuSetValue(pOutArchive, kNuValueModifyOrig, false);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr,
|
||||
"ERROR: couldn't disable modify orig (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
if (flags & kFlagUseTmp) {
|
||||
err = NuSetValue(pOutArchive, kNuValueModifyOrig, false);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr,
|
||||
"ERROR: couldn't disable modify orig (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
|
||||
err = NuGetMasterHeader(pInArchive, &pMasterHeader);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: couldn't get master header (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
err = NuGetMasterHeader(pInArchive, &pMasterHeader);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: couldn't get master header (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterate through the set of records.
|
||||
*/
|
||||
for (idx = 0; idx < (int)pMasterHeader->mhTotalRecords; idx++) {
|
||||
err = NuGetRecordIdxByPosition(pInArchive, idx, &recordIdx);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: couldn't get record #%ld (err=%d)\n",
|
||||
idx, err);
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* Iterate through the set of records.
|
||||
*/
|
||||
for (idx = 0; idx < (int)pMasterHeader->mhTotalRecords; idx++) {
|
||||
err = NuGetRecordIdxByPosition(pInArchive, idx, &recordIdx);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: couldn't get record #%ld (err=%d)\n",
|
||||
idx, err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
err = CopyRecord(pInArchive, pOutArchive, flags, recordIdx);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = CopyRecord(pInArchive, pOutArchive, flags, recordIdx);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
/*
|
||||
* If "frequent abort" is set, abort what we just did and redo it.
|
||||
*/
|
||||
if (flags & kFlagFrequentAbort) {
|
||||
printf("(abort)\n");
|
||||
err = NuAbort(pOutArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: abort failed (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* If "frequent abort" is set, abort what we just did and redo it.
|
||||
*/
|
||||
if (flags & kFlagFrequentAbort) {
|
||||
printf("(abort)\n");
|
||||
err = NuAbort(pOutArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: abort failed (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
err = CopyRecord(pInArchive, pOutArchive, flags, recordIdx);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = CopyRecord(pInArchive, pOutArchive, flags, recordIdx);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If "frequent abort" or "frequent flush" is set, flush after
|
||||
* each record is copied.
|
||||
*/
|
||||
if ((flags & kFlagFrequentAbort) || (flags & kFlagFrequentFlush)) {
|
||||
printf("(flush)\n");
|
||||
err = NuFlush(pOutArchive, &flushStatus);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr,
|
||||
"ERROR: flush failed (err=%d, status=0x%04lx)\n",
|
||||
err, flushStatus);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* If "frequent abort" or "frequent flush" is set, flush after
|
||||
* each record is copied.
|
||||
*/
|
||||
if ((flags & kFlagFrequentAbort) || (flags & kFlagFrequentFlush)) {
|
||||
printf("(flush)\n");
|
||||
err = NuFlush(pOutArchive, &flushStatus);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr,
|
||||
"ERROR: flush failed (err=%d, status=0x%04lx)\n",
|
||||
err, flushStatus);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* first and only flush if frequent-flushing wasn't enabled */
|
||||
err = NuFlush(pOutArchive, &flushStatus);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: flush failed (err=%d, status=0x%04lx)\n",
|
||||
err, flushStatus);
|
||||
goto bail;
|
||||
}
|
||||
/* first and only flush if frequent-flushing wasn't enabled */
|
||||
err = NuFlush(pOutArchive, &flushStatus);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: flush failed (err=%d, status=0x%04lx)\n",
|
||||
err, flushStatus);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
bail:
|
||||
if (pInArchive != nil)
|
||||
NuClose(pInArchive);
|
||||
if (pOutArchive != nil) {
|
||||
if (err != kNuErrNone)
|
||||
NuAbort(pOutArchive);
|
||||
NuClose(pOutArchive); /* flush pending changes and close */
|
||||
}
|
||||
return (err != kNuErrNone);
|
||||
if (pInArchive != nil)
|
||||
NuClose(pInArchive);
|
||||
if (pOutArchive != nil) {
|
||||
if (err != kNuErrNone)
|
||||
NuAbort(pOutArchive);
|
||||
NuClose(pOutArchive); /* flush pending changes and close */
|
||||
}
|
||||
return (err != kNuErrNone);
|
||||
}
|
||||
|
||||
|
||||
|
@ -528,7 +528,7 @@ bail:
|
|||
void
|
||||
Usage(const char* argv0)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-crfat] infile.shk outfile.shk\n", argv0);
|
||||
fprintf(stderr, "Usage: %s [-crfat] infile.shk outfile.shk\n", argv0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -537,51 +537,51 @@ Usage(const char* argv0)
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
long major, minor, bug;
|
||||
const char* pBuildDate;
|
||||
long flags = 0;
|
||||
char* cp = nil;
|
||||
int cc;
|
||||
long major, minor, bug;
|
||||
const char* pBuildDate;
|
||||
long flags = 0;
|
||||
char* cp = nil;
|
||||
int cc;
|
||||
|
||||
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil);
|
||||
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n",
|
||||
major, minor, bug, pBuildDate);
|
||||
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil);
|
||||
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n",
|
||||
major, minor, bug, pBuildDate);
|
||||
|
||||
if (argc < 3 || argc > 4) {
|
||||
Usage(argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
if (argc < 3 || argc > 4) {
|
||||
Usage(argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if (argc == 4) {
|
||||
cp = argv[1];
|
||||
if (*cp++ != '-') {
|
||||
Usage(argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
if (argc == 4) {
|
||||
cp = argv[1];
|
||||
if (*cp++ != '-') {
|
||||
Usage(argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
while (*cp != '\0') {
|
||||
switch (*cp) {
|
||||
case 'c': flags |= kFlagCopyOnly; break;
|
||||
case 'r': flags |= kFlagReverseThreads; break;
|
||||
case 'f': flags |= kFlagFrequentFlush; break;
|
||||
case 'a': flags |= kFlagFrequentAbort; break;
|
||||
case 't': flags |= kFlagUseTmp; break;
|
||||
default:
|
||||
Usage(argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
while (*cp != '\0') {
|
||||
switch (*cp) {
|
||||
case 'c': flags |= kFlagCopyOnly; break;
|
||||
case 'r': flags |= kFlagReverseThreads; break;
|
||||
case 'f': flags |= kFlagFrequentFlush; break;
|
||||
case 'a': flags |= kFlagFrequentAbort; break;
|
||||
case 't': flags |= kFlagUseTmp; break;
|
||||
default:
|
||||
Usage(argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
argv++;
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
|
||||
cc = LaunderArchive(argv[1], argv[2], flags);
|
||||
cc = LaunderArchive(argv[1], argv[2], flags);
|
||||
|
||||
if (cc == 0)
|
||||
printf("Success!\n");
|
||||
else
|
||||
printf("Failed.\n");
|
||||
exit(cc != 0);
|
||||
if (cc == 0)
|
||||
printf("Success!\n");
|
||||
else
|
||||
printf("Failed.\n");
|
||||
exit(cc != 0);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -21,15 +21,15 @@
|
|||
#include "Common.h"
|
||||
|
||||
|
||||
#define false 0
|
||||
#define true (!false)
|
||||
#define false 0
|
||||
#define true (!false)
|
||||
|
||||
#define kHappySize 2408
|
||||
#define kHappySize 2408
|
||||
|
||||
|
||||
/*
|
||||
* ===========================================================================
|
||||
* ArchiveRecord
|
||||
* ArchiveRecord
|
||||
* ===========================================================================
|
||||
*/
|
||||
|
||||
|
@ -37,13 +37,13 @@
|
|||
* Track an archive record.
|
||||
*/
|
||||
typedef struct ArchiveRecord {
|
||||
char* filename;
|
||||
NuRecordIdx recordIdx;
|
||||
char* filename;
|
||||
NuRecordIdx recordIdx;
|
||||
|
||||
long numThreads;
|
||||
NuThread* pThreads;
|
||||
long numThreads;
|
||||
NuThread* pThreads;
|
||||
|
||||
struct ArchiveRecord* pNext;
|
||||
struct ArchiveRecord* pNext;
|
||||
} ArchiveRecord;
|
||||
|
||||
|
||||
|
@ -53,24 +53,24 @@ typedef struct ArchiveRecord {
|
|||
ArchiveRecord*
|
||||
ArchiveRecord_New(const NuRecord* pRecord)
|
||||
{
|
||||
ArchiveRecord* pArcRec = nil;
|
||||
ArchiveRecord* pArcRec = nil;
|
||||
|
||||
pArcRec = malloc(sizeof(*pArcRec));
|
||||
if (pArcRec == nil)
|
||||
return nil;
|
||||
pArcRec = malloc(sizeof(*pArcRec));
|
||||
if (pArcRec == nil)
|
||||
return nil;
|
||||
|
||||
if (pRecord->filename == nil)
|
||||
pArcRec->filename = strdup("<unknown>");
|
||||
else
|
||||
pArcRec->filename = strdup((char*)pRecord->filename);
|
||||
if (pRecord->filename == nil)
|
||||
pArcRec->filename = strdup("<unknown>");
|
||||
else
|
||||
pArcRec->filename = strdup((char*)pRecord->filename);
|
||||
|
||||
pArcRec->recordIdx = pRecord->recordIdx;
|
||||
pArcRec->numThreads = NuRecordGetNumThreads(pRecord);
|
||||
(void) NuRecordCopyThreads(pRecord, &pArcRec->pThreads);
|
||||
pArcRec->recordIdx = pRecord->recordIdx;
|
||||
pArcRec->numThreads = NuRecordGetNumThreads(pRecord);
|
||||
(void) NuRecordCopyThreads(pRecord, &pArcRec->pThreads);
|
||||
|
||||
pArcRec->pNext = nil;
|
||||
pArcRec->pNext = nil;
|
||||
|
||||
return pArcRec;
|
||||
return pArcRec;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -79,14 +79,14 @@ ArchiveRecord_New(const NuRecord* pRecord)
|
|||
void
|
||||
ArchiveRecord_Free(ArchiveRecord* pArcRec)
|
||||
{
|
||||
if (pArcRec == nil)
|
||||
return;
|
||||
if (pArcRec == nil)
|
||||
return;
|
||||
|
||||
if (pArcRec->filename != nil)
|
||||
free(pArcRec->filename);
|
||||
if (pArcRec->pThreads != nil)
|
||||
free(pArcRec->pThreads);
|
||||
free(pArcRec);
|
||||
if (pArcRec->filename != nil)
|
||||
free(pArcRec->filename);
|
||||
if (pArcRec->pThreads != nil)
|
||||
free(pArcRec->pThreads);
|
||||
free(pArcRec);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -95,61 +95,61 @@ ArchiveRecord_Free(ArchiveRecord* pArcRec)
|
|||
const NuThread*
|
||||
ArchiveRecord_FindThreadByID(const ArchiveRecord* pArcRec, NuThreadID threadID)
|
||||
{
|
||||
const NuThread* pThread;
|
||||
int i;
|
||||
const NuThread* pThread;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < pArcRec->numThreads; i++) {
|
||||
pThread = NuThreadGetByIdx(pArcRec->pThreads, i);
|
||||
if (NuGetThreadID(pThread) == threadID)
|
||||
return pThread;
|
||||
}
|
||||
for (i = 0; i < pArcRec->numThreads; i++) {
|
||||
pThread = NuThreadGetByIdx(pArcRec->pThreads, i);
|
||||
if (NuGetThreadID(pThread) == threadID)
|
||||
return pThread;
|
||||
}
|
||||
|
||||
return nil;
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
ArchiveRecord_GetFilename(const ArchiveRecord* pArcRec)
|
||||
{
|
||||
return pArcRec->filename;
|
||||
return pArcRec->filename;
|
||||
}
|
||||
|
||||
NuRecordIdx
|
||||
ArchiveRecord_GetRecordIdx(const ArchiveRecord* pArcRec)
|
||||
{
|
||||
return pArcRec->recordIdx;
|
||||
return pArcRec->recordIdx;
|
||||
}
|
||||
|
||||
long
|
||||
ArchiveRecord_GetNumThreads(const ArchiveRecord* pArcRec)
|
||||
{
|
||||
return pArcRec->numThreads;
|
||||
return pArcRec->numThreads;
|
||||
}
|
||||
|
||||
const NuThread*
|
||||
ArchiveRecord_GetThread(const ArchiveRecord* pArcRec, int idx)
|
||||
{
|
||||
if (idx < 0 || idx >= pArcRec->numThreads)
|
||||
return nil;
|
||||
return NuThreadGetByIdx(pArcRec->pThreads, idx);
|
||||
if (idx < 0 || idx >= pArcRec->numThreads)
|
||||
return nil;
|
||||
return NuThreadGetByIdx(pArcRec->pThreads, idx);
|
||||
}
|
||||
|
||||
void
|
||||
ArchiveRecord_SetNext(ArchiveRecord* pArcRec, ArchiveRecord* pNextRec)
|
||||
{
|
||||
pArcRec->pNext = pNextRec;
|
||||
pArcRec->pNext = pNextRec;
|
||||
}
|
||||
|
||||
ArchiveRecord*
|
||||
ArchiveRecord_GetNext(const ArchiveRecord* pArcRec)
|
||||
{
|
||||
return pArcRec->pNext;
|
||||
return pArcRec->pNext;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ===========================================================================
|
||||
* ArchiveData
|
||||
* ArchiveData
|
||||
* ===========================================================================
|
||||
*/
|
||||
|
||||
|
@ -157,50 +157,50 @@ ArchiveRecord_GetNext(const ArchiveRecord* pArcRec)
|
|||
* A collection of records.
|
||||
*/
|
||||
typedef struct ArchiveData {
|
||||
long numRecords;
|
||||
ArchiveRecord* pRecordHead;
|
||||
ArchiveRecord* pRecordTail;
|
||||
long numRecords;
|
||||
ArchiveRecord* pRecordHead;
|
||||
ArchiveRecord* pRecordTail;
|
||||
} ArchiveData;
|
||||
|
||||
|
||||
ArchiveData*
|
||||
ArchiveData_New(void)
|
||||
{
|
||||
ArchiveData* pArcData;
|
||||
ArchiveData* pArcData;
|
||||
|
||||
pArcData = malloc(sizeof(*pArcData));
|
||||
if (pArcData == nil)
|
||||
return nil;
|
||||
pArcData = malloc(sizeof(*pArcData));
|
||||
if (pArcData == nil)
|
||||
return nil;
|
||||
|
||||
pArcData->numRecords = 0;
|
||||
pArcData->pRecordHead = pArcData->pRecordTail = nil;
|
||||
pArcData->numRecords = 0;
|
||||
pArcData->pRecordHead = pArcData->pRecordTail = nil;
|
||||
|
||||
return pArcData;
|
||||
return pArcData;
|
||||
}
|
||||
|
||||
void
|
||||
ArchiveData_Free(ArchiveData* pArcData)
|
||||
{
|
||||
ArchiveRecord* pNext;
|
||||
ArchiveRecord* pNext;
|
||||
|
||||
if (pArcData == nil)
|
||||
return;
|
||||
if (pArcData == nil)
|
||||
return;
|
||||
|
||||
printf("*** Deleting %ld records!\n", pArcData->numRecords);
|
||||
while (pArcData->pRecordHead != nil) {
|
||||
pNext = ArchiveRecord_GetNext(pArcData->pRecordHead);
|
||||
ArchiveRecord_Free(pArcData->pRecordHead);
|
||||
pArcData->pRecordHead = pNext;
|
||||
}
|
||||
printf("*** Deleting %ld records!\n", pArcData->numRecords);
|
||||
while (pArcData->pRecordHead != nil) {
|
||||
pNext = ArchiveRecord_GetNext(pArcData->pRecordHead);
|
||||
ArchiveRecord_Free(pArcData->pRecordHead);
|
||||
pArcData->pRecordHead = pNext;
|
||||
}
|
||||
|
||||
free(pArcData);
|
||||
free(pArcData);
|
||||
}
|
||||
|
||||
|
||||
ArchiveRecord*
|
||||
ArchiveData_GetRecordHead(const ArchiveData* pArcData)
|
||||
{
|
||||
return pArcData->pRecordHead;
|
||||
return pArcData->pRecordHead;
|
||||
}
|
||||
|
||||
|
||||
|
@ -208,52 +208,52 @@ ArchiveData_GetRecordHead(const ArchiveData* pArcData)
|
|||
void
|
||||
ArchiveData_AddRecord(ArchiveData* pArcData, ArchiveRecord* pRecord)
|
||||
{
|
||||
assert(pRecord != nil);
|
||||
assert((pArcData->pRecordHead == nil && pArcData->pRecordTail == nil) ||
|
||||
(pArcData->pRecordHead != nil && pArcData->pRecordTail != nil));
|
||||
assert(pRecord != nil);
|
||||
assert((pArcData->pRecordHead == nil && pArcData->pRecordTail == nil) ||
|
||||
(pArcData->pRecordHead != nil && pArcData->pRecordTail != nil));
|
||||
|
||||
if (pArcData->pRecordHead == nil) {
|
||||
/* first */
|
||||
pArcData->pRecordHead = pArcData->pRecordTail = pRecord;
|
||||
} else {
|
||||
/* not first, add to end */
|
||||
ArchiveRecord_SetNext(pArcData->pRecordTail, pRecord);
|
||||
pArcData->pRecordTail = pRecord;
|
||||
}
|
||||
if (pArcData->pRecordHead == nil) {
|
||||
/* first */
|
||||
pArcData->pRecordHead = pArcData->pRecordTail = pRecord;
|
||||
} else {
|
||||
/* not first, add to end */
|
||||
ArchiveRecord_SetNext(pArcData->pRecordTail, pRecord);
|
||||
pArcData->pRecordTail = pRecord;
|
||||
}
|
||||
|
||||
pArcData->numRecords++;
|
||||
pArcData->numRecords++;
|
||||
}
|
||||
|
||||
/* dump the contents of the ArchiveData to stdout */
|
||||
void
|
||||
ArchiveData_DumpContents(const ArchiveData* pArcData)
|
||||
{
|
||||
ArchiveRecord* pArcRec;
|
||||
ArchiveRecord* pArcRec;
|
||||
|
||||
pArcRec = pArcData->pRecordHead;
|
||||
while (pArcRec != nil) {
|
||||
const NuThread* pThread;
|
||||
int i, count;
|
||||
pArcRec = pArcData->pRecordHead;
|
||||
while (pArcRec != nil) {
|
||||
const NuThread* pThread;
|
||||
int i, count;
|
||||
|
||||
printf("%5ld '%s'\n",
|
||||
ArchiveRecord_GetRecordIdx(pArcRec),
|
||||
ArchiveRecord_GetFilename(pArcRec));
|
||||
printf("%5ld '%s'\n",
|
||||
ArchiveRecord_GetRecordIdx(pArcRec),
|
||||
ArchiveRecord_GetFilename(pArcRec));
|
||||
|
||||
count = ArchiveRecord_GetNumThreads(pArcRec);
|
||||
for (i = 0; i < count; i++) {
|
||||
pThread = ArchiveRecord_GetThread(pArcRec, i);
|
||||
printf(" %5ld 0x%04x 0x%04x\n", pThread->threadIdx,
|
||||
pThread->thThreadClass, pThread->thThreadKind);
|
||||
}
|
||||
count = ArchiveRecord_GetNumThreads(pArcRec);
|
||||
for (i = 0; i < count; i++) {
|
||||
pThread = ArchiveRecord_GetThread(pArcRec, i);
|
||||
printf(" %5ld 0x%04x 0x%04x\n", pThread->threadIdx,
|
||||
pThread->thThreadClass, pThread->thThreadKind);
|
||||
}
|
||||
|
||||
pArcRec = ArchiveRecord_GetNext(pArcRec);
|
||||
}
|
||||
pArcRec = ArchiveRecord_GetNext(pArcRec);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ===========================================================================
|
||||
* Main stuff
|
||||
* Main stuff
|
||||
* ===========================================================================
|
||||
*/
|
||||
|
||||
|
@ -263,19 +263,19 @@ ArchiveData_DumpContents(const ArchiveData* pArcData)
|
|||
NuResult
|
||||
GatherContents(NuArchive* pArchive, void* vpRecord)
|
||||
{
|
||||
NuRecord* pRecord = (NuRecord*) vpRecord;
|
||||
ArchiveData* pArchiveData = nil;
|
||||
ArchiveRecord* pArchiveRecord = ArchiveRecord_New(pRecord);
|
||||
NuRecord* pRecord = (NuRecord*) vpRecord;
|
||||
ArchiveData* pArchiveData = nil;
|
||||
ArchiveRecord* pArchiveRecord = ArchiveRecord_New(pRecord);
|
||||
|
||||
NuGetExtraData(pArchive, (void**)&pArchiveData);
|
||||
assert(pArchiveData != nil);
|
||||
NuGetExtraData(pArchive, (void**)&pArchiveData);
|
||||
assert(pArchiveData != nil);
|
||||
|
||||
printf("*** Filename = '%s'\n",
|
||||
pRecord->filename == nil ? "<unknown>":(const char*)pRecord->filename);
|
||||
printf("*** Filename = '%s'\n",
|
||||
pRecord->filename == nil ? "<unknown>":(const char*)pRecord->filename);
|
||||
|
||||
ArchiveData_AddRecord(pArchiveData, pArchiveRecord);
|
||||
ArchiveData_AddRecord(pArchiveData, pArchiveRecord);
|
||||
|
||||
return kNuOK;
|
||||
return kNuOK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -284,28 +284,28 @@ GatherContents(NuArchive* pArchive, void* vpRecord)
|
|||
*/
|
||||
NuError
|
||||
ReadAllFilenameThreads(NuArchive* pArchive, ArchiveData* pArchiveData,
|
||||
NuDataSink* pDataSink)
|
||||
NuDataSink* pDataSink)
|
||||
{
|
||||
NuError err = kNuErrNone;
|
||||
ArchiveRecord* pArchiveRecord;
|
||||
const NuThread* pThread;
|
||||
NuError err = kNuErrNone;
|
||||
ArchiveRecord* pArchiveRecord;
|
||||
const NuThread* pThread;
|
||||
|
||||
pArchiveRecord = ArchiveData_GetRecordHead(pArchiveData);
|
||||
while (pArchiveRecord != nil) {
|
||||
pThread = ArchiveRecord_FindThreadByID(pArchiveRecord,
|
||||
kNuThreadIDFilename);
|
||||
if (pThread != nil) {
|
||||
err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "*** Extract failed (%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
pArchiveRecord = ArchiveRecord_GetNext(pArchiveRecord);
|
||||
}
|
||||
pArchiveRecord = ArchiveData_GetRecordHead(pArchiveData);
|
||||
while (pArchiveRecord != nil) {
|
||||
pThread = ArchiveRecord_FindThreadByID(pArchiveRecord,
|
||||
kNuThreadIDFilename);
|
||||
if (pThread != nil) {
|
||||
err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "*** Extract failed (%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
pArchiveRecord = ArchiveRecord_GetNext(pArchiveRecord);
|
||||
}
|
||||
|
||||
bail:
|
||||
return err;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -313,96 +313,96 @@ bail:
|
|||
NuError
|
||||
ExtractToFile(NuArchive* pArchive, ArchiveData* pArchiveData)
|
||||
{
|
||||
NuError err;
|
||||
NuDataSink* pDataSink = nil;
|
||||
NuError err;
|
||||
NuDataSink* pDataSink = nil;
|
||||
|
||||
err = NuCreateDataSinkForFile(true, kNuConvertOff, "out.file", PATH_SEP,
|
||||
&pDataSink);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = NuCreateDataSinkForFile(true, kNuConvertOff, "out.file", PATH_SEP,
|
||||
&pDataSink);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
err = NuSetValue(pArchive, kNuValueHandleExisting, kNuAlwaysOverwrite);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = NuSetValue(pArchive, kNuValueHandleExisting, kNuAlwaysOverwrite);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
err = ReadAllFilenameThreads(pArchive, pArchiveData, pDataSink);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = ReadAllFilenameThreads(pArchive, pArchiveData, pDataSink);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
bail:
|
||||
(void) NuFreeDataSink(pDataSink);
|
||||
if (err == kNuErrNone)
|
||||
printf("*** File write complete\n");
|
||||
return err;
|
||||
(void) NuFreeDataSink(pDataSink);
|
||||
if (err == kNuErrNone)
|
||||
printf("*** File write complete\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
/* extract every filename thread into a FILE*, appending */
|
||||
NuError
|
||||
ExtractToFP(NuArchive* pArchive, ArchiveData* pArchiveData)
|
||||
{
|
||||
NuError err;
|
||||
FILE* fp = nil;
|
||||
NuDataSink* pDataSink = nil;
|
||||
NuError err;
|
||||
FILE* fp = nil;
|
||||
NuDataSink* pDataSink = nil;
|
||||
|
||||
if ((fp = fopen("out.fp", kNuFileOpenWriteTrunc)) == nil)
|
||||
return kNuErrFileOpen;
|
||||
if ((fp = fopen("out.fp", kNuFileOpenWriteTrunc)) == nil)
|
||||
return kNuErrFileOpen;
|
||||
|
||||
err = NuCreateDataSinkForFP(true, kNuConvertOff, fp, &pDataSink);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = NuCreateDataSinkForFP(true, kNuConvertOff, fp, &pDataSink);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
err = ReadAllFilenameThreads(pArchive, pArchiveData, pDataSink);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = ReadAllFilenameThreads(pArchive, pArchiveData, pDataSink);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
bail:
|
||||
(void) NuFreeDataSink(pDataSink);
|
||||
if (fp != nil)
|
||||
fclose(fp);
|
||||
if (err == kNuErrNone)
|
||||
printf("*** FP write complete\n");
|
||||
return err;
|
||||
(void) NuFreeDataSink(pDataSink);
|
||||
if (fp != nil)
|
||||
fclose(fp);
|
||||
if (err == kNuErrNone)
|
||||
printf("*** FP write complete\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
/* extract every filename thread into a buffer, advancing as we go */
|
||||
NuError
|
||||
ExtractToBuffer(NuArchive* pArchive, ArchiveData* pArchiveData)
|
||||
{
|
||||
NuError err;
|
||||
unsigned char buffer[kHappySize];
|
||||
NuDataSink* pDataSink = nil;
|
||||
unsigned long count;
|
||||
NuError err;
|
||||
unsigned char buffer[kHappySize];
|
||||
NuDataSink* pDataSink = nil;
|
||||
unsigned long count;
|
||||
|
||||
err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buffer, kHappySize,
|
||||
&pDataSink);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buffer, kHappySize,
|
||||
&pDataSink);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
err = ReadAllFilenameThreads(pArchive, pArchiveData, pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
if (err == kNuErrBufferOverrun)
|
||||
fprintf(stderr, "*** Hey, buffer wasn't big enough!\n");
|
||||
goto bail;
|
||||
}
|
||||
err = ReadAllFilenameThreads(pArchive, pArchiveData, pDataSink);
|
||||
if (err != kNuErrNone) {
|
||||
if (err == kNuErrBufferOverrun)
|
||||
fprintf(stderr, "*** Hey, buffer wasn't big enough!\n");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* write the buffer to a file */
|
||||
(void) NuDataSinkGetOutCount(pDataSink, &count);
|
||||
if (count > 0) {
|
||||
FILE* fp;
|
||||
if ((fp = fopen("out.buf", kNuFileOpenWriteTrunc)) != nil) {
|
||||
/* write the buffer to a file */
|
||||
(void) NuDataSinkGetOutCount(pDataSink, &count);
|
||||
if (count > 0) {
|
||||
FILE* fp;
|
||||
if ((fp = fopen("out.buf", kNuFileOpenWriteTrunc)) != nil) {
|
||||
|
||||
printf("*** Writing %ld bytes\n", count);
|
||||
if (fwrite(buffer, count, 1, fp) != 1)
|
||||
err = kNuErrFileWrite;
|
||||
fclose(fp);
|
||||
}
|
||||
} else {
|
||||
printf("*** No data found!\n");
|
||||
}
|
||||
printf("*** Writing %ld bytes\n", count);
|
||||
if (fwrite(buffer, count, 1, fp) != 1)
|
||||
err = kNuErrFileWrite;
|
||||
fclose(fp);
|
||||
}
|
||||
} else {
|
||||
printf("*** No data found!\n");
|
||||
}
|
||||
|
||||
bail:
|
||||
(void) NuFreeDataSink(pDataSink);
|
||||
return err;
|
||||
(void) NuFreeDataSink(pDataSink);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -412,52 +412,52 @@ bail:
|
|||
int
|
||||
DoFileStuff(const char* filename)
|
||||
{
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
NuMasterHeader* pMasterHeader = nil;
|
||||
ArchiveData* pArchiveData = ArchiveData_New();
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
NuMasterHeader* pMasterHeader = nil;
|
||||
ArchiveData* pArchiveData = ArchiveData_New();
|
||||
|
||||
err = NuOpenRO(filename, &pArchive);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = NuOpenRO(filename, &pArchive);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
NuSetExtraData(pArchive, pArchiveData);
|
||||
NuSetExtraData(pArchive, pArchiveData);
|
||||
|
||||
printf("*** Gathering contents!\n");
|
||||
err = NuContents(pArchive, GatherContents);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
printf("*** Gathering contents!\n");
|
||||
err = NuContents(pArchive, GatherContents);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
printf("*** Dumping contents!\n");
|
||||
ArchiveData_DumpContents(pArchiveData);
|
||||
printf("*** Dumping contents!\n");
|
||||
ArchiveData_DumpContents(pArchiveData);
|
||||
|
||||
err = ExtractToFile(pArchive, pArchiveData);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = ExtractToFP(pArchive, pArchiveData);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = ExtractToBuffer(pArchive, pArchiveData);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = ExtractToFile(pArchive, pArchiveData);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = ExtractToFP(pArchive, pArchiveData);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = ExtractToBuffer(pArchive, pArchiveData);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
bail:
|
||||
if (err != kNuErrNone)
|
||||
fprintf(stderr, "*** ERROR: got error %d\n", err);
|
||||
if (err != kNuErrNone)
|
||||
fprintf(stderr, "*** ERROR: got error %d\n", err);
|
||||
|
||||
if (pArchive != nil) {
|
||||
NuError err2 = NuClose(pArchive);
|
||||
if (err == kNuErrNone && err2 != kNuErrNone)
|
||||
err = err2;
|
||||
}
|
||||
if (pArchive != nil) {
|
||||
NuError err2 = NuClose(pArchive);
|
||||
if (err == kNuErrNone && err2 != kNuErrNone)
|
||||
err = err2;
|
||||
}
|
||||
|
||||
if (pMasterHeader != nil)
|
||||
free(pMasterHeader);
|
||||
if (pMasterHeader != nil)
|
||||
free(pMasterHeader);
|
||||
|
||||
if (pArchiveData != nil)
|
||||
free(pArchiveData);
|
||||
if (pArchiveData != nil)
|
||||
free(pArchiveData);
|
||||
|
||||
return err;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -467,28 +467,28 @@ bail:
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
long major, minor, bug;
|
||||
const char* pBuildDate;
|
||||
FILE* infp;
|
||||
int cc;
|
||||
long major, minor, bug;
|
||||
const char* pBuildDate;
|
||||
FILE* infp;
|
||||
int cc;
|
||||
|
||||
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil);
|
||||
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n",
|
||||
major, minor, bug, pBuildDate);
|
||||
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil);
|
||||
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n",
|
||||
major, minor, bug, pBuildDate);
|
||||
|
||||
if (argc == 2) {
|
||||
infp = fopen(argv[1], kNuFileOpenReadOnly);
|
||||
if (infp == nil) {
|
||||
perror("fopen failed");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "ERROR: you have to specify a filename\n");
|
||||
exit(2);
|
||||
}
|
||||
if (argc == 2) {
|
||||
infp = fopen(argv[1], kNuFileOpenReadOnly);
|
||||
if (infp == nil) {
|
||||
perror("fopen failed");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "ERROR: you have to specify a filename\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
cc = DoFileStuff(argv[1]);
|
||||
cc = DoFileStuff(argv[1]);
|
||||
|
||||
exit(cc != 0);
|
||||
exit(cc != 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,11 +24,11 @@
|
|||
NuResult
|
||||
ShowContents(NuArchive* pArchive, void* vpRecord)
|
||||
{
|
||||
const NuRecord* pRecord = (NuRecord*) vpRecord;
|
||||
const NuRecord* pRecord = (NuRecord*) vpRecord;
|
||||
|
||||
printf("*** Filename = '%s'\n", pRecord->filename);
|
||||
printf("*** Filename = '%s'\n", pRecord->filename);
|
||||
|
||||
return kNuOK;
|
||||
return kNuOK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,31 +41,31 @@ ShowContents(NuArchive* pArchive, void* vpRecord)
|
|||
int
|
||||
DoStreamStuff(FILE* fp)
|
||||
{
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
|
||||
err = NuStreamOpenRO(fp, &pArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to open stream archive (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
err = NuStreamOpenRO(fp, &pArchive);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to open stream archive (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
printf("*** Streaming contents!\n");
|
||||
printf("*** Streaming contents!\n");
|
||||
|
||||
err = NuContents(pArchive, ShowContents);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: NuContents failed (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
err = NuContents(pArchive, ShowContents);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: NuContents failed (err=%d)\n", err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
bail:
|
||||
if (pArchive != nil) {
|
||||
NuError err2 = NuClose(pArchive);
|
||||
if (err == kNuErrNone)
|
||||
err = err2;
|
||||
}
|
||||
if (pArchive != nil) {
|
||||
NuError err2 = NuClose(pArchive);
|
||||
if (err == kNuErrNone)
|
||||
err = err2;
|
||||
}
|
||||
|
||||
return err;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -75,31 +75,31 @@ bail:
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
long major, minor, bug;
|
||||
const char* pBuildDate;
|
||||
FILE* infp = nil;
|
||||
int cc;
|
||||
long major, minor, bug;
|
||||
const char* pBuildDate;
|
||||
FILE* infp = nil;
|
||||
int cc;
|
||||
|
||||
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil);
|
||||
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n",
|
||||
major, minor, bug, pBuildDate);
|
||||
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil);
|
||||
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n",
|
||||
major, minor, bug, pBuildDate);
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s (archive-name|-)\n", argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s (archive-name|-)\n", argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "-") == 0)
|
||||
infp = stdin;
|
||||
else {
|
||||
infp = fopen(argv[1], kNuFileOpenReadOnly);
|
||||
if (infp == nil) {
|
||||
fprintf(stderr, "ERROR: unable to open '%s'\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (strcmp(argv[1], "-") == 0)
|
||||
infp = stdin;
|
||||
else {
|
||||
infp = fopen(argv[1], kNuFileOpenReadOnly);
|
||||
if (infp == nil) {
|
||||
fprintf(stderr, "ERROR: unable to open '%s'\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
cc = DoStreamStuff(infp);
|
||||
exit(cc != 0);
|
||||
cc = DoStreamStuff(infp);
|
||||
exit(cc != 0);
|
||||
}
|
||||
|
||||
|
|
116
nulib2/Add.c
116
nulib2/Add.c
|
@ -17,58 +17,58 @@ static NuError AddToArchive(NulibState* pState, NuArchive* pArchive);
|
|||
NuError
|
||||
DoAdd(NulibState* pState)
|
||||
{
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
long flushStatus;
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
long flushStatus;
|
||||
|
||||
assert(pState != nil);
|
||||
assert(pState != nil);
|
||||
|
||||
err = OpenArchiveReadWrite(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = OpenArchiveReadWrite(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
|
||||
NState_SetMatchCount(pState, 0);
|
||||
NState_SetMatchCount(pState, 0);
|
||||
|
||||
/* tell them about the list of files */
|
||||
err = AddToArchive(pState, pArchive);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
/* tell them about the list of files */
|
||||
err = AddToArchive(pState, pArchive);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
/*(void)NuDebugDumpArchive(pArchive);*/
|
||||
/*(void)NuDebugDumpArchive(pArchive);*/
|
||||
|
||||
if (!NState_GetMatchCount(pState))
|
||||
printf("%s: no records matched\n", gProgName);
|
||||
if (!NState_GetMatchCount(pState))
|
||||
printf("%s: no records matched\n", gProgName);
|
||||
|
||||
bail:
|
||||
if (pArchive != nil) {
|
||||
NuError err2;
|
||||
if (pArchive != nil) {
|
||||
NuError err2;
|
||||
|
||||
#if 0
|
||||
if (err != kNuErrNone) {
|
||||
printf("Attempting to flush changes in spite of errors...\n");
|
||||
err = kNuErrNone;
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
if (err != kNuErrNone) {
|
||||
printf("Attempting to flush changes in spite of errors...\n");
|
||||
err = kNuErrNone;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == kNuErrNone) {
|
||||
err = NuFlush(pArchive, &flushStatus);
|
||||
if (err != kNuErrNone && err == kNuErrNone) {
|
||||
ReportError(err,
|
||||
"Unable to flush archive changes (status=0x%04lx)",
|
||||
flushStatus);
|
||||
NuAbort(pArchive);
|
||||
}
|
||||
} else {
|
||||
NuAbort(pArchive);
|
||||
}
|
||||
if (err == kNuErrNone) {
|
||||
err = NuFlush(pArchive, &flushStatus);
|
||||
if (err != kNuErrNone && err == kNuErrNone) {
|
||||
ReportError(err,
|
||||
"Unable to flush archive changes (status=0x%04lx)",
|
||||
flushStatus);
|
||||
NuAbort(pArchive);
|
||||
}
|
||||
} else {
|
||||
NuAbort(pArchive);
|
||||
}
|
||||
|
||||
err2 = NuClose(pArchive);
|
||||
assert(err2 == kNuErrNone);
|
||||
}
|
||||
return err;
|
||||
err2 = NuClose(pArchive);
|
||||
assert(err2 == kNuErrNone);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -81,29 +81,29 @@ bail:
|
|||
static NuError
|
||||
AddToArchive(NulibState* pState, NuArchive* pArchive)
|
||||
{
|
||||
NuError err = kNuErrNone;
|
||||
char* const* pSpec;
|
||||
ulong fileCount;
|
||||
int i;
|
||||
NuError err = kNuErrNone;
|
||||
char* const* pSpec;
|
||||
ulong fileCount;
|
||||
int i;
|
||||
|
||||
assert(pState != nil);
|
||||
assert(pArchive != nil);
|
||||
assert(pState != nil);
|
||||
assert(pArchive != nil);
|
||||
|
||||
if (!NState_GetFilespecCount(pState)) {
|
||||
err = kNuErrSyntax;
|
||||
ReportError(err, "no files were specified");
|
||||
}
|
||||
if (!NState_GetFilespecCount(pState)) {
|
||||
err = kNuErrSyntax;
|
||||
ReportError(err, "no files were specified");
|
||||
}
|
||||
|
||||
fileCount = 0;
|
||||
fileCount = 0;
|
||||
|
||||
pSpec = NState_GetFilespecPointer(pState);
|
||||
for (i = NState_GetFilespecCount(pState); i > 0; i--, pSpec++) {
|
||||
err = AddFile(pState, pArchive, *pSpec);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
}
|
||||
pSpec = NState_GetFilespecPointer(pState);
|
||||
for (i = NState_GetFilespecCount(pState); i > 0; i--, pSpec++) {
|
||||
err = AddFile(pState, pArchive, *pSpec);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
}
|
||||
|
||||
bail:
|
||||
return err;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
1214
nulib2/ArcUtils.c
1214
nulib2/ArcUtils.c
File diff suppressed because it is too large
Load Diff
|
@ -1,125 +1,129 @@
|
|||
2000/05/22 ***** v1.0.1 shipped (no changes - version follows nufxlib) *****
|
||||
2002/09/20 fadden
|
||||
- pulled the sources out and started fiddling with them again
|
||||
- changed hard tabs to spaces
|
||||
|
||||
2000/05/18 ***** v1.0.0 shipped *****
|
||||
2000/05/22 ***** v1.0.1 shipped (no changes - version follows nufxlib) *****
|
||||
|
||||
2000/05/18 fadden
|
||||
- added nulib2 to set of things stripped by "distbin"
|
||||
- updated version information to indicate final release
|
||||
2000/05/18 ***** v1.0.0 shipped *****
|
||||
|
||||
2000/03/25 ***** v0.6.1 shipped *****
|
||||
2000/05/18 fadden
|
||||
- added nulib2 to set of things stripped by "distbin"
|
||||
- updated version information to indicate final release
|
||||
|
||||
2000/03/25 ***** v0.6.1 shipped *****
|
||||
|
||||
2000/03/25 fadden
|
||||
- Sheppy says Mac OS X PPC v1.02 and v1.2 work with minor SysDefs tweak
|
||||
- Sheppy says Mac OS X PPC v1.02 and v1.2 work with minor SysDefs tweak
|
||||
|
||||
2000/03/05 ***** v0.6.0 (beta) shipped *****
|
||||
2000/03/05 ***** v0.6.0 (beta) shipped *****
|
||||
|
||||
2000/03/05 fadden
|
||||
- don't call mktemp(), just pass template into NuOpenRW
|
||||
- removed DEBUG_MSGS from default CFLAGS
|
||||
- updated version information to indicate beta release
|
||||
2000/03/05 fadden
|
||||
- don't call mktemp(), just pass template into NuOpenRW
|
||||
- removed DEBUG_MSGS from default CFLAGS
|
||||
- updated version information to indicate beta release
|
||||
|
||||
2000/02/24 ***** v0.5.1 shipped *****
|
||||
2000/02/24 ***** v0.5.1 shipped *****
|
||||
|
||||
2000/02/20 changes from Scott Blackman
|
||||
- portability fixes for DJGPP under Win95
|
||||
2000/02/20 changes from Scott Blackman
|
||||
- portability fixes for DJGPP under Win95
|
||||
|
||||
2000/02/17 changes from Devin Reade
|
||||
- portability fixes for BSD, AIX, and others
|
||||
- added "distbin" target
|
||||
2000/02/17 changes from Devin Reade
|
||||
- portability fixes for BSD, AIX, and others
|
||||
- added "distbin" target
|
||||
|
||||
2000/02/09 ***** v0.5.0 (alpha) shipped *****
|
||||
2000/02/09 ***** v0.5.0 (alpha) shipped *****
|
||||
|
||||
2000/02/09 fadden
|
||||
- changed the comparison used when extracting/deleting a list of files
|
||||
from strcasecmp to strcmp, since NufxLib does case-sensitive compares.
|
||||
- fixed the percentage for files and archives larger than 21MB
|
||||
2000/02/09 fadden
|
||||
- changed the comparison used when extracting/deleting a list of files
|
||||
from strcasecmp to strcmp, since NufxLib does case-sensitive compares.
|
||||
- fixed the percentage for files and archives larger than 21MB
|
||||
|
||||
2000/02/08 fadden
|
||||
- tweaked the BeOS/PPC config around a little
|
||||
- deleted some commas to make "gcc -pedantic" happy
|
||||
- changed version to x.y.z format here too
|
||||
- generalized the "aux" handling to include all MS-DOS device names
|
||||
2000/02/08 fadden
|
||||
- tweaked the BeOS/PPC config around a little
|
||||
- deleted some commas to make "gcc -pedantic" happy
|
||||
- changed version to x.y.z format here too
|
||||
- generalized the "aux" handling to include all MS-DOS device names
|
||||
|
||||
2000/02/06 fadden
|
||||
- include @CFLAGS@ in case somebody wants to override them
|
||||
2000/02/06 fadden
|
||||
- include @CFLAGS@ in case somebody wants to override them
|
||||
|
||||
2000/02/06 ***** v0.4b shipped *****
|
||||
2000/02/06 ***** v0.4b shipped *****
|
||||
|
||||
2000/02/06 fadden
|
||||
- added "install-shared" make target
|
||||
- portability fixes for HP/UX
|
||||
2000/02/06 fadden
|
||||
- added "install-shared" make target
|
||||
- portability fixes for HP/UX
|
||||
|
||||
2000/02/06 ***** v0.4a shipped *****
|
||||
2000/02/06 ***** v0.4a shipped *****
|
||||
|
||||
2000/02/06 fadden
|
||||
- massaged configure.in for BeOS, and added some type casts for mwerks
|
||||
2000/02/06 fadden
|
||||
- massaged configure.in for BeOS, and added some type casts for mwerks
|
||||
|
||||
2000/02/06 ***** v0.4 shipped *****
|
||||
2000/02/06 ***** v0.4 shipped *****
|
||||
|
||||
2000/02/05 fadden
|
||||
- added "mkinstalldirs" to install target
|
||||
- added Win32 makefile
|
||||
- made a few implicit typecasts explicit for Visual C++'s benefit
|
||||
- change "aux" to "_aux", because FAT filesystems choke on it
|
||||
2000/02/05 fadden
|
||||
- added "mkinstalldirs" to install target
|
||||
- added Win32 makefile
|
||||
- made a few implicit typecasts explicit for Visual C++'s benefit
|
||||
- change "aux" to "_aux", because FAT filesystems choke on it
|
||||
|
||||
2000/02/04 fadden
|
||||
- added Win32 recursive directory descent
|
||||
2000/02/04 fadden
|
||||
- added Win32 recursive directory descent
|
||||
|
||||
2000/02/02 fadden
|
||||
- minor changes to get it working under Win32 (Visual C++ 6.0)
|
||||
- added --enable-dmalloc to configuration
|
||||
2000/02/02 fadden
|
||||
- minor changes to get it working under Win32 (Visual C++ 6.0)
|
||||
- added --enable-dmalloc to configuration
|
||||
|
||||
2000/02/01 fadden
|
||||
- screen out leading "./", and junk the path if ".." shows up in path
|
||||
- don't try to add comments to records we're skipping
|
||||
- set kNuValueEOL appropriately for the current system
|
||||
2000/02/01 fadden
|
||||
- screen out leading "./", and junk the path if ".." shows up in path
|
||||
- don't try to add comments to records we're skipping
|
||||
- set kNuValueEOL appropriately for the current system
|
||||
|
||||
2000/01/29 ***** v0.3 shipped *****
|
||||
2000/01/29 ***** v0.3 shipped *****
|
||||
|
||||
2000/01/29 fadden
|
||||
- added "make install" target, with the standard autoconf defines
|
||||
- added some examples to the man page
|
||||
2000/01/29 fadden
|
||||
- added "make install" target, with the standard autoconf defines
|
||||
- added some examples to the man page
|
||||
|
||||
2000/01/28 fadden
|
||||
- merged "Kind" and "Type" columns in "v" output
|
||||
- display a '+' when doing EOL conversions on an extracted file
|
||||
2000/01/28 fadden
|
||||
- merged "Kind" and "Type" columns in "v" output
|
||||
- display a '+' when doing EOL conversions on an extracted file
|
||||
|
||||
2000/01/26 fadden
|
||||
- added UI for allowing the user to ignore bad CRCs
|
||||
- implemented "-j" (junk paths) for add and extract
|
||||
- implemented "-c" (comments) for add and extract
|
||||
- added totals to bottom of "v" output
|
||||
2000/01/26 fadden
|
||||
- added UI for allowing the user to ignore bad CRCs
|
||||
- implemented "-j" (junk paths) for add and extract
|
||||
- implemented "-c" (comments) for add and extract
|
||||
- added totals to bottom of "v" output
|
||||
|
||||
2000/01/25 fadden
|
||||
- when extracting without type preservation, append "_rsrc_" to
|
||||
resource forks
|
||||
2000/01/25 fadden
|
||||
- when extracting without type preservation, append "_rsrc_" to
|
||||
resource forks
|
||||
|
||||
2000/01/24 fadden
|
||||
- added support for "-k" (add as disk image) flag
|
||||
2000/01/24 fadden
|
||||
- added support for "-k" (add as disk image) flag
|
||||
|
||||
2000/01/24 ***** v0.2 shipped *****
|
||||
2000/01/24 ***** v0.2 shipped *****
|
||||
|
||||
2000/01/22 fadden
|
||||
- added support for "-u" (update) and "-f" (freshen) flags
|
||||
- set file dates in AddFile call
|
||||
2000/01/22 fadden
|
||||
- added support for "-u" (update) and "-f" (freshen) flags
|
||||
- set file dates in AddFile call
|
||||
|
||||
2000/01/20 fadden
|
||||
- restructed the progress updater
|
||||
2000/01/20 fadden
|
||||
- restructed the progress updater
|
||||
|
||||
2000/01/19 fadden
|
||||
- normalized SysDefs.h, changing UNIX to UNIX_LIKE and defining for BeOS
|
||||
- added "shared" target to makefile
|
||||
- added BeOS stuff to autoconf setup
|
||||
2000/01/19 fadden
|
||||
- normalized SysDefs.h, changing UNIX to UNIX_LIKE and defining for BeOS
|
||||
- added "shared" target to makefile
|
||||
- added BeOS stuff to autoconf setup
|
||||
|
||||
2000/01/17 fadden
|
||||
- started recording locked/unlocked status
|
||||
- some BeOS/Metrowerks "it's not gcc" changes from Eric Shepherd
|
||||
- implemented "-s" (stomp existing) and "-0" (no compression) modifiers
|
||||
2000/01/17 fadden
|
||||
- started recording locked/unlocked status
|
||||
- some BeOS/Metrowerks "it's not gcc" changes from Eric Shepherd
|
||||
- implemented "-s" (stomp existing) and "-0" (no compression) modifiers
|
||||
|
||||
2000/01/17 ***** v0.1 shipped *****
|
||||
2000/01/17 ***** v0.1 shipped *****
|
||||
|
||||
(much time passes)
|
||||
|
||||
mid-1998 fadden
|
||||
- work begins
|
||||
mid-1998 fadden
|
||||
- work begins
|
||||
|
||||
|
|
|
@ -18,29 +18,29 @@
|
|||
NuError
|
||||
DoDelete(NulibState* pState)
|
||||
{
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
|
||||
assert(pState != nil);
|
||||
assert(pState != nil);
|
||||
|
||||
err = OpenArchiveReadWrite(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
err = OpenArchiveReadWrite(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
|
||||
NState_SetMatchCount(pState, 0);
|
||||
NState_SetMatchCount(pState, 0);
|
||||
|
||||
err = NuDelete(pArchive);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = NuDelete(pArchive);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
if (!NState_GetMatchCount(pState))
|
||||
printf("%s: no records matched\n", gProgName);
|
||||
if (!NState_GetMatchCount(pState))
|
||||
printf("%s: no records matched\n", gProgName);
|
||||
|
||||
bail:
|
||||
if (pArchive != nil)
|
||||
(void) NuClose(pArchive);
|
||||
return err;
|
||||
if (pArchive != nil)
|
||||
(void) NuClose(pArchive);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
196
nulib2/Extract.c
196
nulib2/Extract.c
|
@ -20,67 +20,67 @@
|
|||
static NuError
|
||||
ExtractAllRecords(NulibState* pState, NuArchive* pArchive)
|
||||
{
|
||||
NuError err;
|
||||
const NuRecord* pRecord;
|
||||
const NuThread* pThread;
|
||||
NuRecordIdx recordIdx;
|
||||
NuAttr numRecords;
|
||||
int idx, threadIdx;
|
||||
NuError err;
|
||||
const NuRecord* pRecord;
|
||||
const NuThread* pThread;
|
||||
NuRecordIdx recordIdx;
|
||||
NuAttr numRecords;
|
||||
int idx, threadIdx;
|
||||
|
||||
DBUG(("--- doing manual extract\n"));
|
||||
assert(NState_GetCommand(pState) == kCommandExtract); /* no "-p" here */
|
||||
DBUG(("--- doing manual extract\n"));
|
||||
assert(NState_GetCommand(pState) == kCommandExtract); /* no "-p" here */
|
||||
|
||||
err = NuGetAttr(pArchive, kNuAttrNumRecords, &numRecords);
|
||||
for (idx = 0; idx < (int) numRecords; idx++) {
|
||||
err = NuGetRecordIdxByPosition(pArchive, idx, &recordIdx);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: couldn't get record #%d (err=%d)\n",
|
||||
idx, err);
|
||||
goto bail;
|
||||
}
|
||||
err = NuGetAttr(pArchive, kNuAttrNumRecords, &numRecords);
|
||||
for (idx = 0; idx < (int) numRecords; idx++) {
|
||||
err = NuGetRecordIdxByPosition(pArchive, idx, &recordIdx);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: couldn't get record #%d (err=%d)\n",
|
||||
idx, err);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
err = NuGetRecord(pArchive, recordIdx, &pRecord);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to get recordIdx %ld\n", recordIdx);
|
||||
goto bail;
|
||||
}
|
||||
err = NuGetRecord(pArchive, recordIdx, &pRecord);
|
||||
if (err != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to get recordIdx %ld\n", recordIdx);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* do we want to extract this record? */
|
||||
if (!IsSpecified(pState, pRecord))
|
||||
continue;
|
||||
NState_IncMatchCount(pState);
|
||||
/* do we want to extract this record? */
|
||||
if (!IsSpecified(pState, pRecord))
|
||||
continue;
|
||||
NState_IncMatchCount(pState);
|
||||
|
||||
/*
|
||||
* Look for a comment thread.
|
||||
*/
|
||||
for (threadIdx = 0; (ulong)threadIdx < pRecord->recTotalThreads;
|
||||
threadIdx++)
|
||||
{
|
||||
pThread = NuGetThread(pRecord, threadIdx);
|
||||
assert(pThread != nil);
|
||||
/*
|
||||
* Look for a comment thread.
|
||||
*/
|
||||
for (threadIdx = 0; (ulong)threadIdx < pRecord->recTotalThreads;
|
||||
threadIdx++)
|
||||
{
|
||||
pThread = NuGetThread(pRecord, threadIdx);
|
||||
assert(pThread != nil);
|
||||
|
||||
if (NuGetThreadID(pThread) == kNuThreadIDComment &&
|
||||
pThread->actualThreadEOF > 0)
|
||||
{
|
||||
printf("----- '%s':\n", pRecord->filename);
|
||||
err = NuExtractThread(pArchive, pThread->threadIdx,
|
||||
NState_GetCommentSink(pState));
|
||||
if (err != kNuErrNone) {
|
||||
printf("[comment extraction failed, continuing\n");
|
||||
} else {
|
||||
printf("\n-----\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (NuGetThreadID(pThread) == kNuThreadIDComment &&
|
||||
pThread->actualThreadEOF > 0)
|
||||
{
|
||||
printf("----- '%s':\n", pRecord->filename);
|
||||
err = NuExtractThread(pArchive, pThread->threadIdx,
|
||||
NState_GetCommentSink(pState));
|
||||
if (err != kNuErrNone) {
|
||||
printf("[comment extraction failed, continuing\n");
|
||||
} else {
|
||||
printf("\n-----\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* extract the record, using the usual mechanisms */
|
||||
err = NuExtractRecord(pArchive, recordIdx);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
}
|
||||
/* extract the record, using the usual mechanisms */
|
||||
err = NuExtractRecord(pArchive, recordIdx);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
}
|
||||
|
||||
bail:
|
||||
return err;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -90,40 +90,40 @@ bail:
|
|||
NuError
|
||||
DoExtract(NulibState* pState)
|
||||
{
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
|
||||
assert(pState != nil);
|
||||
assert(pState != nil);
|
||||
|
||||
err = OpenArchiveReadOnly(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
err = OpenArchiveReadOnly(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
|
||||
NState_SetMatchCount(pState, 0);
|
||||
NState_SetMatchCount(pState, 0);
|
||||
|
||||
/*
|
||||
* If we're not interested in comments, just use the "bulk" extract
|
||||
* call. If we want comments, we need to do this one at a time.
|
||||
*/
|
||||
if (!NState_GetModComments(pState)) {
|
||||
err = NuExtract(pArchive);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
} else {
|
||||
err = ExtractAllRecords(pState, pArchive);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
}
|
||||
/*
|
||||
* If we're not interested in comments, just use the "bulk" extract
|
||||
* call. If we want comments, we need to do this one at a time.
|
||||
*/
|
||||
if (!NState_GetModComments(pState)) {
|
||||
err = NuExtract(pArchive);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
} else {
|
||||
err = ExtractAllRecords(pState, pArchive);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (!NState_GetMatchCount(pState))
|
||||
printf("%s: no records match\n", gProgName);
|
||||
if (!NState_GetMatchCount(pState))
|
||||
printf("%s: no records match\n", gProgName);
|
||||
|
||||
bail:
|
||||
if (pArchive != nil)
|
||||
(void) NuClose(pArchive);
|
||||
return err;
|
||||
if (pArchive != nil)
|
||||
(void) NuClose(pArchive);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -133,8 +133,8 @@ bail:
|
|||
NuError
|
||||
DoExtractToPipe(NulibState* pState)
|
||||
{
|
||||
/* we handle the "to pipe" part farther down */
|
||||
return DoExtract(pState);
|
||||
/* we handle the "to pipe" part farther down */
|
||||
return DoExtract(pState);
|
||||
}
|
||||
|
||||
|
||||
|
@ -144,29 +144,29 @@ DoExtractToPipe(NulibState* pState)
|
|||
NuError
|
||||
DoTest(NulibState* pState)
|
||||
{
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
|
||||
assert(pState != nil);
|
||||
assert(pState != nil);
|
||||
|
||||
err = OpenArchiveReadOnly(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
err = OpenArchiveReadOnly(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
|
||||
NState_SetMatchCount(pState, 0);
|
||||
NState_SetMatchCount(pState, 0);
|
||||
|
||||
err = NuTest(pArchive);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = NuTest(pArchive);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
if (!NState_GetMatchCount(pState))
|
||||
printf("%s: no records match\n", gProgName);
|
||||
if (!NState_GetMatchCount(pState))
|
||||
printf("%s: no records match\n", gProgName);
|
||||
|
||||
bail:
|
||||
if (pArchive != nil)
|
||||
(void) NuClose(pArchive);
|
||||
return err;
|
||||
if (pArchive != nil)
|
||||
(void) NuClose(pArchive);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
480
nulib2/List.c
480
nulib2/List.c
|
@ -11,31 +11,31 @@
|
|||
|
||||
/* kinds of records */
|
||||
enum RecordKind {
|
||||
kRecordKindUnknown = 0,
|
||||
kRecordKindDisk,
|
||||
kRecordKindFile,
|
||||
kRecordKindForkedFile
|
||||
kRecordKindUnknown = 0,
|
||||
kRecordKindDisk,
|
||||
kRecordKindFile,
|
||||
kRecordKindForkedFile
|
||||
};
|
||||
|
||||
static const char* gShortFormatNames[] = {
|
||||
"unc", "squ", "lz1", "lz2", "u12", "u16"
|
||||
"unc", "squ", "lz1", "lz2", "u12", "u16"
|
||||
};
|
||||
|
||||
|
||||
#if 0
|
||||
/* days of the week */
|
||||
static const char* gDayNames[] = {
|
||||
"[ null ]",
|
||||
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
|
||||
"[ null ]",
|
||||
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
|
||||
};
|
||||
#endif
|
||||
/* months of the year */
|
||||
static const char* gMonths[] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
|
||||
#define kNuDateOutputLen 64
|
||||
#define kNuDateOutputLen 64
|
||||
|
||||
|
||||
/*
|
||||
|
@ -44,21 +44,21 @@ static const char* gMonths[] = {
|
|||
int
|
||||
ComputePercent(ulong totalSize, ulong size)
|
||||
{
|
||||
int perc;
|
||||
int perc;
|
||||
|
||||
if (!totalSize && !size)
|
||||
return 100; /* file is zero bytes long */
|
||||
if (!totalSize && !size)
|
||||
return 100; /* file is zero bytes long */
|
||||
|
||||
if (totalSize < 21474836)
|
||||
perc = (totalSize * 100) / size;
|
||||
else
|
||||
perc = totalSize / (size/100);
|
||||
if (totalSize < 21474836)
|
||||
perc = (totalSize * 100) / size;
|
||||
else
|
||||
perc = totalSize / (size/100);
|
||||
|
||||
/* don't say "0%" if it's not actually zero... it looks dumb */
|
||||
if (!perc && size)
|
||||
perc = 1;
|
||||
/* don't say "0%" if it's not actually zero... it looks dumb */
|
||||
if (!perc && size)
|
||||
perc = 1;
|
||||
|
||||
return perc;
|
||||
return perc;
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,29 +73,29 @@ ComputePercent(ulong totalSize, ulong size)
|
|||
static char*
|
||||
FormatDateShort(const NuDateTime* pDateTime, char* buffer)
|
||||
{
|
||||
/* is it valid? */
|
||||
if (pDateTime->day > 30 || pDateTime->month > 11 || pDateTime->hour > 24 ||
|
||||
pDateTime->minute > 59)
|
||||
{
|
||||
strcpy(buffer, " <invalid> ");
|
||||
goto bail;
|
||||
}
|
||||
/* is it valid? */
|
||||
if (pDateTime->day > 30 || pDateTime->month > 11 || pDateTime->hour > 24 ||
|
||||
pDateTime->minute > 59)
|
||||
{
|
||||
strcpy(buffer, " <invalid> ");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* is it empty? */
|
||||
if ((pDateTime->second | pDateTime->minute | pDateTime->hour |
|
||||
pDateTime->year | pDateTime->day | pDateTime->month |
|
||||
pDateTime->extra | pDateTime->weekDay) == 0)
|
||||
{
|
||||
strcpy(buffer, " [No Date] ");
|
||||
goto bail;
|
||||
}
|
||||
/* is it empty? */
|
||||
if ((pDateTime->second | pDateTime->minute | pDateTime->hour |
|
||||
pDateTime->year | pDateTime->day | pDateTime->month |
|
||||
pDateTime->extra | pDateTime->weekDay) == 0)
|
||||
{
|
||||
strcpy(buffer, " [No Date] ");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
sprintf(buffer, "%02d-%s-%02d %02d:%02d",
|
||||
pDateTime->day+1, gMonths[pDateTime->month], pDateTime->year % 100,
|
||||
pDateTime->hour, pDateTime->minute);
|
||||
sprintf(buffer, "%02d-%s-%02d %02d:%02d",
|
||||
pDateTime->day+1, gMonths[pDateTime->month], pDateTime->year % 100,
|
||||
pDateTime->hour, pDateTime->minute);
|
||||
|
||||
bail:
|
||||
return buffer;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,21 +105,21 @@ bail:
|
|||
static NuResult
|
||||
ShowContentsShort(NuArchive* pArchive, void* vpRecord)
|
||||
{
|
||||
const NuRecord* pRecord = (NuRecord*) vpRecord;
|
||||
NulibState* pState;
|
||||
const NuRecord* pRecord = (NuRecord*) vpRecord;
|
||||
NulibState* pState;
|
||||
|
||||
assert(pArchive != nil);
|
||||
(void) NuGetExtraData(pArchive, (void**) &pState);
|
||||
assert(pState != nil);
|
||||
assert(pArchive != nil);
|
||||
(void) NuGetExtraData(pArchive, (void**) &pState);
|
||||
assert(pState != nil);
|
||||
|
||||
if (!IsSpecified(pState, pRecord))
|
||||
goto bail;
|
||||
if (!IsSpecified(pState, pRecord))
|
||||
goto bail;
|
||||
|
||||
printf("%s\n",
|
||||
pRecord->filename == nil ? "<unknown>":(const char*)pRecord->filename);
|
||||
printf("%s\n",
|
||||
pRecord->filename == nil ? "<unknown>":(const char*)pRecord->filename);
|
||||
|
||||
bail:
|
||||
return kNuOK;
|
||||
return kNuOK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,42 +140,42 @@ bail:
|
|||
*/
|
||||
static NuError
|
||||
AnalyzeRecord(const NuRecord* pRecord, enum RecordKind* pRecordKind,
|
||||
ushort* pFormat, ulong* pTotalLen, ulong* pTotalCompLen)
|
||||
ushort* pFormat, ulong* pTotalLen, ulong* pTotalCompLen)
|
||||
{
|
||||
const NuThread* pThread;
|
||||
NuThreadID threadID;
|
||||
ulong idx;
|
||||
const NuThread* pThread;
|
||||
NuThreadID threadID;
|
||||
ulong idx;
|
||||
|
||||
*pRecordKind = kRecordKindUnknown;
|
||||
*pTotalLen = *pTotalCompLen = 0;
|
||||
*pFormat = kNuThreadFormatUncompressed;
|
||||
*pRecordKind = kRecordKindUnknown;
|
||||
*pTotalLen = *pTotalCompLen = 0;
|
||||
*pFormat = kNuThreadFormatUncompressed;
|
||||
|
||||
for (idx = 0; idx < pRecord->recTotalThreads; idx++) {
|
||||
pThread = NuGetThread(pRecord, idx);
|
||||
assert(pThread != nil);
|
||||
for (idx = 0; idx < pRecord->recTotalThreads; idx++) {
|
||||
pThread = NuGetThread(pRecord, idx);
|
||||
assert(pThread != nil);
|
||||
|
||||
if (pThread->thThreadClass == kNuThreadClassData) {
|
||||
/* replace what's there if this might be more interesting */
|
||||
if (*pFormat == kNuThreadFormatUncompressed)
|
||||
*pFormat = pThread->thThreadFormat;
|
||||
if (pThread->thThreadClass == kNuThreadClassData) {
|
||||
/* replace what's there if this might be more interesting */
|
||||
if (*pFormat == kNuThreadFormatUncompressed)
|
||||
*pFormat = pThread->thThreadFormat;
|
||||
|
||||
threadID = NuMakeThreadID(pThread->thThreadClass,
|
||||
pThread->thThreadKind);
|
||||
if (threadID == kNuThreadIDRsrcFork)
|
||||
*pRecordKind = kRecordKindForkedFile;
|
||||
else if (threadID == kNuThreadIDDiskImage)
|
||||
*pRecordKind = kRecordKindDisk;
|
||||
else if (threadID == kNuThreadIDDataFork &&
|
||||
*pRecordKind == kRecordKindUnknown)
|
||||
*pRecordKind = kRecordKindFile;
|
||||
threadID = NuMakeThreadID(pThread->thThreadClass,
|
||||
pThread->thThreadKind);
|
||||
if (threadID == kNuThreadIDRsrcFork)
|
||||
*pRecordKind = kRecordKindForkedFile;
|
||||
else if (threadID == kNuThreadIDDiskImage)
|
||||
*pRecordKind = kRecordKindDisk;
|
||||
else if (threadID == kNuThreadIDDataFork &&
|
||||
*pRecordKind == kRecordKindUnknown)
|
||||
*pRecordKind = kRecordKindFile;
|
||||
|
||||
/* sum up, so we get both forks of forked files */
|
||||
*pTotalLen += pThread->actualThreadEOF;
|
||||
*pTotalCompLen += pThread->thCompThreadEOF;
|
||||
}
|
||||
}
|
||||
/* sum up, so we get both forks of forked files */
|
||||
*pTotalLen += pThread->actualThreadEOF;
|
||||
*pTotalCompLen += pThread->thCompThreadEOF;
|
||||
}
|
||||
}
|
||||
|
||||
return kNuErrNone;
|
||||
return kNuErrNone;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -187,89 +187,89 @@ AnalyzeRecord(const NuRecord* pRecord, enum RecordKind* pRecordKind,
|
|||
static NuResult
|
||||
ShowContentsVerbose(NuArchive* pArchive, void* vpRecord)
|
||||
{
|
||||
NuError err = kNuErrNone;
|
||||
const NuRecord* pRecord = (NuRecord*) vpRecord;
|
||||
enum RecordKind recordKind;
|
||||
ulong totalLen, totalCompLen;
|
||||
ushort format;
|
||||
NulibState* pState;
|
||||
char date1[kNuDateOutputLen];
|
||||
char tmpbuf[16];
|
||||
int len;
|
||||
NuError err = kNuErrNone;
|
||||
const NuRecord* pRecord = (NuRecord*) vpRecord;
|
||||
enum RecordKind recordKind;
|
||||
ulong totalLen, totalCompLen;
|
||||
ushort format;
|
||||
NulibState* pState;
|
||||
char date1[kNuDateOutputLen];
|
||||
char tmpbuf[16];
|
||||
int len;
|
||||
|
||||
assert(pArchive != nil);
|
||||
(void) NuGetExtraData(pArchive, (void**) &pState);
|
||||
assert(pState != nil);
|
||||
assert(pArchive != nil);
|
||||
(void) NuGetExtraData(pArchive, (void**) &pState);
|
||||
assert(pState != nil);
|
||||
|
||||
if (!IsSpecified(pState, pRecord))
|
||||
goto bail;
|
||||
if (!IsSpecified(pState, pRecord))
|
||||
goto bail;
|
||||
|
||||
err = AnalyzeRecord(pRecord, &recordKind, &format, &totalLen,
|
||||
&totalCompLen);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = AnalyzeRecord(pRecord, &recordKind, &format, &totalLen,
|
||||
&totalCompLen);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
len = strlen(pRecord->filename);
|
||||
if (len <= 27) {
|
||||
printf("%c%-27.27s ", IsRecordReadOnly(pRecord) ? '+' : ' ',
|
||||
pRecord->filename);
|
||||
} else {
|
||||
printf("%c..%-25.25s ", IsRecordReadOnly(pRecord) ? '+' : ' ',
|
||||
pRecord->filename + len - 25);
|
||||
}
|
||||
switch (recordKind) {
|
||||
case kRecordKindUnknown:
|
||||
printf("??? $%04lX ",
|
||||
/*GetFileTypeString(pRecord->recFileType),*/
|
||||
pRecord->recExtraType);
|
||||
break;
|
||||
case kRecordKindDisk:
|
||||
sprintf(tmpbuf, "%ldk", totalLen / 1024);
|
||||
printf("Disk %-6s ", tmpbuf);
|
||||
break;
|
||||
case kRecordKindFile:
|
||||
case kRecordKindForkedFile:
|
||||
printf("%s%c $%04lX ",
|
||||
GetFileTypeString(pRecord->recFileType),
|
||||
recordKind == kRecordKindForkedFile ? '+' : ' ',
|
||||
pRecord->recExtraType);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
printf("ERROR ");
|
||||
}
|
||||
len = strlen(pRecord->filename);
|
||||
if (len <= 27) {
|
||||
printf("%c%-27.27s ", IsRecordReadOnly(pRecord) ? '+' : ' ',
|
||||
pRecord->filename);
|
||||
} else {
|
||||
printf("%c..%-25.25s ", IsRecordReadOnly(pRecord) ? '+' : ' ',
|
||||
pRecord->filename + len - 25);
|
||||
}
|
||||
switch (recordKind) {
|
||||
case kRecordKindUnknown:
|
||||
printf("??? $%04lX ",
|
||||
/*GetFileTypeString(pRecord->recFileType),*/
|
||||
pRecord->recExtraType);
|
||||
break;
|
||||
case kRecordKindDisk:
|
||||
sprintf(tmpbuf, "%ldk", totalLen / 1024);
|
||||
printf("Disk %-6s ", tmpbuf);
|
||||
break;
|
||||
case kRecordKindFile:
|
||||
case kRecordKindForkedFile:
|
||||
printf("%s%c $%04lX ",
|
||||
GetFileTypeString(pRecord->recFileType),
|
||||
recordKind == kRecordKindForkedFile ? '+' : ' ',
|
||||
pRecord->recExtraType);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
printf("ERROR ");
|
||||
}
|
||||
|
||||
printf("%s ", FormatDateShort(&pRecord->recArchiveWhen, date1));
|
||||
if (format >= NELEM(gShortFormatNames))
|
||||
printf("??? ");
|
||||
else
|
||||
printf("%s ", gShortFormatNames[format]);
|
||||
printf("%s ", FormatDateShort(&pRecord->recArchiveWhen, date1));
|
||||
if (format >= NELEM(gShortFormatNames))
|
||||
printf("??? ");
|
||||
else
|
||||
printf("%s ", gShortFormatNames[format]);
|
||||
|
||||
/* compute the percent size */
|
||||
if ((!totalLen && totalCompLen) || (totalLen && !totalCompLen))
|
||||
printf("--- "); /* weird */
|
||||
else if (totalLen < totalCompLen)
|
||||
printf(">100%% "); /* compression failed? */
|
||||
else {
|
||||
sprintf(tmpbuf, "%02d%%", ComputePercent(totalCompLen, totalLen));
|
||||
printf("%4s ", tmpbuf);
|
||||
}
|
||||
/* compute the percent size */
|
||||
if ((!totalLen && totalCompLen) || (totalLen && !totalCompLen))
|
||||
printf("--- "); /* weird */
|
||||
else if (totalLen < totalCompLen)
|
||||
printf(">100%% "); /* compression failed? */
|
||||
else {
|
||||
sprintf(tmpbuf, "%02d%%", ComputePercent(totalCompLen, totalLen));
|
||||
printf("%4s ", tmpbuf);
|
||||
}
|
||||
|
||||
if (!totalLen && totalCompLen)
|
||||
printf(" ????"); /* weird */
|
||||
else
|
||||
printf("%8ld", totalLen);
|
||||
if (!totalLen && totalCompLen)
|
||||
printf(" ????"); /* weird */
|
||||
else
|
||||
printf("%8ld", totalLen);
|
||||
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
|
||||
NState_AddToTotals(pState, totalLen, totalCompLen);
|
||||
NState_AddToTotals(pState, totalLen, totalCompLen);
|
||||
|
||||
bail:
|
||||
if (err != kNuErrNone) {
|
||||
printf("(ERROR on '%s')\n", pRecord->filename == nil ?
|
||||
"<unknown>" : (const char*)pRecord->filename);
|
||||
}
|
||||
return kNuOK;
|
||||
if (err != kNuErrNone) {
|
||||
printf("(ERROR on '%s')\n", pRecord->filename == nil ?
|
||||
"<unknown>" : (const char*)pRecord->filename);
|
||||
}
|
||||
return kNuOK;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -278,24 +278,24 @@ bail:
|
|||
NuError
|
||||
DoListShort(NulibState* pState)
|
||||
{
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
|
||||
assert(pState != nil);
|
||||
assert(pState != nil);
|
||||
|
||||
err = OpenArchiveReadOnly(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
err = OpenArchiveReadOnly(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
|
||||
err = NuContents(pArchive, ShowContentsShort);
|
||||
/* fall through with err */
|
||||
err = NuContents(pArchive, ShowContentsShort);
|
||||
/* fall through with err */
|
||||
|
||||
bail:
|
||||
if (pArchive != nil)
|
||||
(void) NuClose(pArchive);
|
||||
return err;
|
||||
if (pArchive != nil)
|
||||
(void) NuClose(pArchive);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -305,72 +305,72 @@ bail:
|
|||
NuError
|
||||
DoListVerbose(NulibState* pState)
|
||||
{
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
const NuMasterHeader* pHeader;
|
||||
char date1[kNuDateOutputLen];
|
||||
char date2[kNuDateOutputLen];
|
||||
long totalLen, totalCompLen;
|
||||
const char* cp;
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
const NuMasterHeader* pHeader;
|
||||
char date1[kNuDateOutputLen];
|
||||
char date2[kNuDateOutputLen];
|
||||
long totalLen, totalCompLen;
|
||||
const char* cp;
|
||||
|
||||
assert(pState != nil);
|
||||
assert(pState != nil);
|
||||
|
||||
err = OpenArchiveReadOnly(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
err = OpenArchiveReadOnly(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
|
||||
/*
|
||||
* Try to get just the filename.
|
||||
*/
|
||||
if (IsFilenameStdin(NState_GetArchiveFilename(pState)))
|
||||
cp = "<stdin>";
|
||||
else
|
||||
cp = FilenameOnly(pState, NState_GetArchiveFilename(pState));
|
||||
/*
|
||||
* Try to get just the filename.
|
||||
*/
|
||||
if (IsFilenameStdin(NState_GetArchiveFilename(pState)))
|
||||
cp = "<stdin>";
|
||||
else
|
||||
cp = FilenameOnly(pState, NState_GetArchiveFilename(pState));
|
||||
|
||||
/* grab the master header block */
|
||||
err = NuGetMasterHeader(pArchive, &pHeader);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
/* grab the master header block */
|
||||
err = NuGetMasterHeader(pArchive, &pHeader);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
printf(" %-15.15s Created:%s Mod:%s Recs:%5lu\n\n",
|
||||
cp,
|
||||
FormatDateShort(&pHeader->mhArchiveCreateWhen, date1),
|
||||
FormatDateShort(&pHeader->mhArchiveModWhen, date2),
|
||||
pHeader->mhTotalRecords);
|
||||
printf(" Name Type Auxtyp Archived"
|
||||
" Fmat Size Un-Length\n");
|
||||
printf("-------------------------------------------------"
|
||||
"----------------------------\n");
|
||||
printf(" %-15.15s Created:%s Mod:%s Recs:%5lu\n\n",
|
||||
cp,
|
||||
FormatDateShort(&pHeader->mhArchiveCreateWhen, date1),
|
||||
FormatDateShort(&pHeader->mhArchiveModWhen, date2),
|
||||
pHeader->mhTotalRecords);
|
||||
printf(" Name Type Auxtyp Archived"
|
||||
" Fmat Size Un-Length\n");
|
||||
printf("-------------------------------------------------"
|
||||
"----------------------------\n");
|
||||
|
||||
err = NuContents(pArchive, ShowContentsVerbose);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
err = NuContents(pArchive, ShowContentsVerbose);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
/*
|
||||
* Show the totals. NuFX overhead can be as much as 25% for archives
|
||||
* with lots of small files.
|
||||
*/
|
||||
NState_GetTotals(pState, &totalLen, &totalCompLen);
|
||||
printf("-------------------------------------------------"
|
||||
"----------------------------\n");
|
||||
printf(" Uncomp: %ld Comp: %ld %%of orig: %d%%\n",
|
||||
totalLen, totalCompLen,
|
||||
totalLen == 0 ? 0 : ComputePercent(totalCompLen, totalLen));
|
||||
#ifdef DEBUG_VERBOSE
|
||||
printf(" Overhead: %ld (%d%%)\n",
|
||||
pHeader->mhMasterEOF - totalCompLen,
|
||||
ComputePercent(pHeader->mhMasterEOF - totalCompLen,
|
||||
pHeader->mhMasterEOF));
|
||||
#endif
|
||||
/*
|
||||
* Show the totals. NuFX overhead can be as much as 25% for archives
|
||||
* with lots of small files.
|
||||
*/
|
||||
NState_GetTotals(pState, &totalLen, &totalCompLen);
|
||||
printf("-------------------------------------------------"
|
||||
"----------------------------\n");
|
||||
printf(" Uncomp: %ld Comp: %ld %%of orig: %d%%\n",
|
||||
totalLen, totalCompLen,
|
||||
totalLen == 0 ? 0 : ComputePercent(totalCompLen, totalLen));
|
||||
#ifdef DEBUG_VERBOSE
|
||||
printf(" Overhead: %ld (%d%%)\n",
|
||||
pHeader->mhMasterEOF - totalCompLen,
|
||||
ComputePercent(pHeader->mhMasterEOF - totalCompLen,
|
||||
pHeader->mhMasterEOF));
|
||||
#endif
|
||||
|
||||
/*(void) NuDebugDumpArchive(pArchive);*/
|
||||
/*(void) NuDebugDumpArchive(pArchive);*/
|
||||
|
||||
bail:
|
||||
if (pArchive != nil)
|
||||
(void) NuClose(pArchive);
|
||||
return err;
|
||||
if (pArchive != nil)
|
||||
(void) NuClose(pArchive);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -381,7 +381,7 @@ bail:
|
|||
static NuResult
|
||||
NullCallback(NuArchive* pArchive, void* vpRecord)
|
||||
{
|
||||
return kNuOK;
|
||||
return kNuOK;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -391,30 +391,30 @@ NullCallback(NuArchive* pArchive, void* vpRecord)
|
|||
NuError
|
||||
DoListDebug(NulibState* pState)
|
||||
{
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
NuError err;
|
||||
NuArchive* pArchive = nil;
|
||||
|
||||
assert(pState != nil);
|
||||
assert(pState != nil);
|
||||
|
||||
err = OpenArchiveReadOnly(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
err = OpenArchiveReadOnly(pState);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
pArchive = NState_GetNuArchive(pState);
|
||||
assert(pArchive != nil);
|
||||
|
||||
/* have to do something to force the library to scan the archive */
|
||||
err = NuContents(pArchive, NullCallback);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
/* have to do something to force the library to scan the archive */
|
||||
err = NuContents(pArchive, NullCallback);
|
||||
if (err != kNuErrNone)
|
||||
goto bail;
|
||||
|
||||
err = NuDebugDumpArchive(pArchive);
|
||||
if (err != kNuErrNone)
|
||||
fprintf(stderr, "ERROR: debugging not enabled in nufxlib\n");
|
||||
/* fall through with err */
|
||||
err = NuDebugDumpArchive(pArchive);
|
||||
if (err != kNuErrNone)
|
||||
fprintf(stderr, "ERROR: debugging not enabled in nufxlib\n");
|
||||
/* fall through with err */
|
||||
|
||||
bail:
|
||||
if (pArchive != nil)
|
||||
(void) NuClose(pArchive);
|
||||
return err;
|
||||
if (pArchive != nil)
|
||||
(void) NuClose(pArchive);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
524
nulib2/Main.c
524
nulib2/Main.c
|
@ -20,21 +20,21 @@ const char* gProgName = "Nulib2";
|
|||
* Which modifiers are valid with which commands?
|
||||
*/
|
||||
typedef struct ValidCombo {
|
||||
Command cmd;
|
||||
Boolean okayForPipe;
|
||||
Boolean filespecRequired;
|
||||
const char* modifiers;
|
||||
Command cmd;
|
||||
Boolean okayForPipe;
|
||||
Boolean filespecRequired;
|
||||
const char* modifiers;
|
||||
} ValidCombo;
|
||||
|
||||
static const ValidCombo gValidCombos[] = {
|
||||
{ kCommandAdd, false, true, "ufrj0cke" },
|
||||
{ kCommandDelete, false, true, "r" },
|
||||
{ kCommandExtract, true, false, "ufrjclse" },
|
||||
{ kCommandExtractToPipe, true, false, "rl" },
|
||||
{ kCommandListShort, true, false, "" },
|
||||
{ kCommandListVerbose, true, false, "" },
|
||||
{ kCommandListDebug, true, false, "" },
|
||||
{ kCommandTest, true, false, "r" },
|
||||
{ kCommandAdd, false, true, "ufrj0cke" },
|
||||
{ kCommandDelete, false, true, "r" },
|
||||
{ kCommandExtract, true, false, "ufrjclse" },
|
||||
{ kCommandExtractToPipe, true, false, "rl" },
|
||||
{ kCommandListShort, true, false, "" },
|
||||
{ kCommandListVerbose, true, false, "" },
|
||||
{ kCommandListDebug, true, false, "" },
|
||||
{ kCommandTest, true, false, "r" },
|
||||
};
|
||||
|
||||
|
||||
|
@ -46,14 +46,14 @@ static const ValidCombo gValidCombos[] = {
|
|||
static const ValidCombo*
|
||||
FindValidComboEntry(Command cmd)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NELEM(gValidCombos); i++) {
|
||||
if (gValidCombos[i].cmd == cmd)
|
||||
return &gValidCombos[i];
|
||||
}
|
||||
for (i = 0; i < NELEM(gValidCombos); i++) {
|
||||
if (gValidCombos[i].cmd == cmd)
|
||||
return &gValidCombos[i];
|
||||
}
|
||||
|
||||
return nil;
|
||||
return nil;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -63,16 +63,16 @@ FindValidComboEntry(Command cmd)
|
|||
static Boolean
|
||||
IsValidModifier(Command cmd, char modifier)
|
||||
{
|
||||
const ValidCombo* pvc;
|
||||
const ValidCombo* pvc;
|
||||
|
||||
pvc = FindValidComboEntry(cmd);
|
||||
if (pvc != nil) {
|
||||
if (strchr(pvc->modifiers, modifier) == nil)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
pvc = FindValidComboEntry(cmd);
|
||||
if (pvc != nil) {
|
||||
if (strchr(pvc->modifiers, modifier) == nil)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -81,13 +81,13 @@ IsValidModifier(Command cmd, char modifier)
|
|||
static Boolean
|
||||
IsValidOnPipe(Command cmd)
|
||||
{
|
||||
const ValidCombo* pvc;
|
||||
const ValidCombo* pvc;
|
||||
|
||||
pvc = FindValidComboEntry(cmd);
|
||||
if (pvc != nil) {
|
||||
return pvc->okayForPipe;
|
||||
} else
|
||||
return false;
|
||||
pvc = FindValidComboEntry(cmd);
|
||||
if (pvc != nil) {
|
||||
return pvc->okayForPipe;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -96,17 +96,17 @@ IsValidOnPipe(Command cmd)
|
|||
static Boolean
|
||||
IsFilespecRequired(Command cmd)
|
||||
{
|
||||
const ValidCombo* pvc;
|
||||
const ValidCombo* pvc;
|
||||
|
||||
pvc = FindValidComboEntry(cmd);
|
||||
if (pvc != nil) {
|
||||
return pvc->filespecRequired;
|
||||
} else {
|
||||
/* command not found? warn about it here... */
|
||||
fprintf(stderr, "%s: Command %d not found in gValidCombos table\n",
|
||||
gProgName, cmd);
|
||||
return false;
|
||||
}
|
||||
pvc = FindValidComboEntry(cmd);
|
||||
if (pvc != nil) {
|
||||
return pvc->filespecRequired;
|
||||
} else {
|
||||
/* command not found? warn about it here... */
|
||||
fprintf(stderr, "%s: Command %d not found in gValidCombos table\n",
|
||||
gProgName, cmd);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -116,19 +116,19 @@ IsFilespecRequired(Command cmd)
|
|||
static const char*
|
||||
GetProgName(const NulibState* pState, const char* argv0)
|
||||
{
|
||||
const char* result;
|
||||
char sep;
|
||||
const char* result;
|
||||
char sep;
|
||||
|
||||
/* use the appropriate system pathname separator */
|
||||
sep = NState_GetSystemPathSeparator(pState);
|
||||
/* use the appropriate system pathname separator */
|
||||
sep = NState_GetSystemPathSeparator(pState);
|
||||
|
||||
result = strrchr(argv0, sep);
|
||||
if (result == nil)
|
||||
result = argv0;
|
||||
else
|
||||
result++; /* advance past the separator */
|
||||
|
||||
return result;
|
||||
result = strrchr(argv0, sep);
|
||||
if (result == nil)
|
||||
result = argv0;
|
||||
else
|
||||
result++; /* advance past the separator */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -138,34 +138,34 @@ GetProgName(const NulibState* pState, const char* argv0)
|
|||
static void
|
||||
Usage(const NulibState* pState)
|
||||
{
|
||||
long majorVersion, minorVersion, bugVersion;
|
||||
const char* nufxLibDate;
|
||||
const char* nufxLibFlags;
|
||||
long majorVersion, minorVersion, bugVersion;
|
||||
const char* nufxLibDate;
|
||||
const char* nufxLibFlags;
|
||||
|
||||
(void) NuGetVersion(&majorVersion, &minorVersion, &bugVersion,
|
||||
&nufxLibDate, &nufxLibFlags);
|
||||
(void) NuGetVersion(&majorVersion, &minorVersion, &bugVersion,
|
||||
&nufxLibDate, &nufxLibFlags);
|
||||
|
||||
printf("\nNulib2 v%s, linked with NufxLib v%ld.%ld.%ld [%s]\n",
|
||||
NState_GetProgramVersion(pState),
|
||||
majorVersion, minorVersion, bugVersion, nufxLibFlags);
|
||||
printf("This software is distributed under terms of the GNU General Public License.\n");
|
||||
printf("Written by Andy McFadden, http://www.nulib.com/.\n\n");
|
||||
printf("Usage: %s -command[modifiers] archive [filename-list]\n\n",
|
||||
gProgName);
|
||||
printf(
|
||||
" -a add files, create arc if needed -x extract files\n"
|
||||
" -t list files (short) -v list files (verbose)\n"
|
||||
" -p extract files to pipe, no msgs -i test archive integrity\n"
|
||||
" -d delete files from archive\n"
|
||||
"\n"
|
||||
" modifiers:\n"
|
||||
" -u update files (add + keep newest) -f freshen (update, no add)\n"
|
||||
" -r recurse into subdirs -j junk (don't record) directory names\n"
|
||||
" -0 don't use compression -c add one-line comments\n"
|
||||
" -l auto-convert text files -ll auto-convert ALL files\n"
|
||||
" -s stomp existing files w/o asking -k store files as disk images\n"
|
||||
" -e preserve ProDOS file types -ee extend preserved names\n"
|
||||
);
|
||||
printf("\nNulib2 v%s, linked with NufxLib v%ld.%ld.%ld [%s]\n",
|
||||
NState_GetProgramVersion(pState),
|
||||
majorVersion, minorVersion, bugVersion, nufxLibFlags);
|
||||
printf("This software is distributed under terms of the GNU General Public License.\n");
|
||||
printf("Written by Andy McFadden, http://www.nulib.com/.\n\n");
|
||||
printf("Usage: %s -command[modifiers] archive [filename-list]\n\n",
|
||||
gProgName);
|
||||
printf(
|
||||
" -a add files, create arc if needed -x extract files\n"
|
||||
" -t list files (short) -v list files (verbose)\n"
|
||||
" -p extract files to pipe, no msgs -i test archive integrity\n"
|
||||
" -d delete files from archive\n"
|
||||
"\n"
|
||||
" modifiers:\n"
|
||||
" -u update files (add + keep newest) -f freshen (update, no add)\n"
|
||||
" -r recurse into subdirs -j junk (don't record) directory names\n"
|
||||
" -0 don't use compression -c add one-line comments\n"
|
||||
" -l auto-convert text files -ll auto-convert ALL files\n"
|
||||
" -s stomp existing files w/o asking -k store files as disk images\n"
|
||||
" -e preserve ProDOS file types -ee extend preserved names\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
@ -175,147 +175,147 @@ Usage(const NulibState* pState)
|
|||
static int
|
||||
ProcessOptions(NulibState* pState, int argc, char* const* argv)
|
||||
{
|
||||
const char* cp;
|
||||
int idx;
|
||||
const char* cp;
|
||||
int idx;
|
||||
|
||||
/*
|
||||
* Must have at least a command letter and an archive filename.
|
||||
*/
|
||||
if (argc < 3) {
|
||||
Usage(pState);
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
* Must have at least a command letter and an archive filename.
|
||||
*/
|
||||
if (argc < 3) {
|
||||
Usage(pState);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Argv[1] and any subsequent entries that have a leading hyphen
|
||||
* are options. Anything after that is a filename. Parse until we
|
||||
* think we've hit the filename.
|
||||
*
|
||||
* By UNIX convention, however, stdin is specified as a file called "-".
|
||||
*/
|
||||
for (idx = 1; idx < argc; idx++) {
|
||||
cp = argv[idx];
|
||||
/*
|
||||
* Argv[1] and any subsequent entries that have a leading hyphen
|
||||
* are options. Anything after that is a filename. Parse until we
|
||||
* think we've hit the filename.
|
||||
*
|
||||
* By UNIX convention, however, stdin is specified as a file called "-".
|
||||
*/
|
||||
for (idx = 1; idx < argc; idx++) {
|
||||
cp = argv[idx];
|
||||
|
||||
if (idx > 1 && *cp != '-')
|
||||
break;
|
||||
if (idx > 1 && *cp != '-')
|
||||
break;
|
||||
|
||||
if (*cp == '-')
|
||||
cp++;
|
||||
if (*cp == '\0') {
|
||||
if (idx == 1) {
|
||||
fprintf(stderr,
|
||||
"%s: You must specify a command after the '-'\n",
|
||||
gProgName);
|
||||
goto fail;
|
||||
} else {
|
||||
/* they're using '-' for the filename */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (*cp == '-')
|
||||
cp++;
|
||||
if (*cp == '\0') {
|
||||
if (idx == 1) {
|
||||
fprintf(stderr,
|
||||
"%s: You must specify a command after the '-'\n",
|
||||
gProgName);
|
||||
goto fail;
|
||||
} else {
|
||||
/* they're using '-' for the filename */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (idx == 1) {
|
||||
switch (tolower(*cp)) {
|
||||
case 'a': NState_SetCommand(pState, kCommandAdd); break;
|
||||
case 'x': NState_SetCommand(pState, kCommandExtract); break;
|
||||
case 'p': NState_SetCommand(pState, kCommandExtractToPipe); break;
|
||||
case 't': NState_SetCommand(pState, kCommandListShort); break;
|
||||
case 'v': NState_SetCommand(pState, kCommandListVerbose); break;
|
||||
case 'z': NState_SetCommand(pState, kCommandListDebug); break;
|
||||
case 'i': NState_SetCommand(pState, kCommandTest); break;
|
||||
case 'd': NState_SetCommand(pState, kCommandDelete); break;
|
||||
default:
|
||||
fprintf(stderr, "%s: Unknown command '%c'\n", gProgName, *cp);
|
||||
goto fail;
|
||||
}
|
||||
if (idx == 1) {
|
||||
switch (tolower(*cp)) {
|
||||
case 'a': NState_SetCommand(pState, kCommandAdd); break;
|
||||
case 'x': NState_SetCommand(pState, kCommandExtract); break;
|
||||
case 'p': NState_SetCommand(pState, kCommandExtractToPipe); break;
|
||||
case 't': NState_SetCommand(pState, kCommandListShort); break;
|
||||
case 'v': NState_SetCommand(pState, kCommandListVerbose); break;
|
||||
case 'z': NState_SetCommand(pState, kCommandListDebug); break;
|
||||
case 'i': NState_SetCommand(pState, kCommandTest); break;
|
||||
case 'd': NState_SetCommand(pState, kCommandDelete); break;
|
||||
default:
|
||||
fprintf(stderr, "%s: Unknown command '%c'\n", gProgName, *cp);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
cp++;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
while (*cp != '\0') {
|
||||
switch (tolower(*cp)) {
|
||||
case 'u': NState_SetModUpdate(pState, true); break;
|
||||
case 'f': NState_SetModFreshen(pState, true); break;
|
||||
case 'r': NState_SetModRecurse(pState, true); break;
|
||||
case 'j': NState_SetModJunkPaths(pState, true); break;
|
||||
case '0': NState_SetModNoCompression(pState, true); break;
|
||||
case 'c': NState_SetModComments(pState, true); break;
|
||||
case 's': NState_SetModOverwriteExisting(pState, true); break;
|
||||
case 'k': NState_SetModAddAsDisk(pState, true); break;
|
||||
case 'e':
|
||||
if (*(cp-1) == 'e') /* should never point at invalid */
|
||||
NState_SetModPreserveTypeExtended(pState, true);
|
||||
else
|
||||
NState_SetModPreserveType(pState, true);
|
||||
break;
|
||||
case 'l':
|
||||
if (*(cp-1) == 'l') /* should never point at invalid */
|
||||
NState_SetModConvertAll(pState, true);
|
||||
else
|
||||
NState_SetModConvertText(pState, true);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: Unknown modifier '%c'\n", gProgName, *cp);
|
||||
goto fail;
|
||||
}
|
||||
while (*cp != '\0') {
|
||||
switch (tolower(*cp)) {
|
||||
case 'u': NState_SetModUpdate(pState, true); break;
|
||||
case 'f': NState_SetModFreshen(pState, true); break;
|
||||
case 'r': NState_SetModRecurse(pState, true); break;
|
||||
case 'j': NState_SetModJunkPaths(pState, true); break;
|
||||
case '0': NState_SetModNoCompression(pState, true); break;
|
||||
case 'c': NState_SetModComments(pState, true); break;
|
||||
case 's': NState_SetModOverwriteExisting(pState, true); break;
|
||||
case 'k': NState_SetModAddAsDisk(pState, true); break;
|
||||
case 'e':
|
||||
if (*(cp-1) == 'e') /* should never point at invalid */
|
||||
NState_SetModPreserveTypeExtended(pState, true);
|
||||
else
|
||||
NState_SetModPreserveType(pState, true);
|
||||
break;
|
||||
case 'l':
|
||||
if (*(cp-1) == 'l') /* should never point at invalid */
|
||||
NState_SetModConvertAll(pState, true);
|
||||
else
|
||||
NState_SetModConvertText(pState, true);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: Unknown modifier '%c'\n", gProgName, *cp);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!IsValidModifier(NState_GetCommand(pState), (char)tolower(*cp)))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: The '%c' modifier doesn't make sense here\n",
|
||||
gProgName, tolower(*cp));
|
||||
goto fail;
|
||||
}
|
||||
if (!IsValidModifier(NState_GetCommand(pState), (char)tolower(*cp)))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: The '%c' modifier doesn't make sense here\n",
|
||||
gProgName, tolower(*cp));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* See if we have an archive name. If it's "-", see if we allow that.
|
||||
*/
|
||||
assert(idx < argc);
|
||||
NState_SetArchiveFilename(pState, argv[idx]);
|
||||
if (IsFilenameStdin(argv[idx])) {
|
||||
if (!IsValidOnPipe(NState_GetCommand(pState))) {
|
||||
fprintf(stderr, "%s: You can't do that with a pipe\n",
|
||||
gProgName);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
idx++;
|
||||
/*
|
||||
* See if we have an archive name. If it's "-", see if we allow that.
|
||||
*/
|
||||
assert(idx < argc);
|
||||
NState_SetArchiveFilename(pState, argv[idx]);
|
||||
if (IsFilenameStdin(argv[idx])) {
|
||||
if (!IsValidOnPipe(NState_GetCommand(pState))) {
|
||||
fprintf(stderr, "%s: You can't do that with a pipe\n",
|
||||
gProgName);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
idx++;
|
||||
|
||||
/*
|
||||
* See if we have a file specification. Some of the commands require
|
||||
* a filespec; others just perform the requested operation on all of
|
||||
* the records in the archive if none is provided.
|
||||
*/
|
||||
if (idx < argc) {
|
||||
/* got one or more */
|
||||
NState_SetFilespecPointer(pState, &argv[idx]);
|
||||
NState_SetFilespecCount(pState, argc - idx);
|
||||
} else {
|
||||
assert(idx == argc);
|
||||
if (IsFilespecRequired(NState_GetCommand(pState))) {
|
||||
fprintf(stderr, "%s: This command requires a list of files\n",
|
||||
gProgName);
|
||||
goto fail;
|
||||
}
|
||||
NState_SetFilespecPointer(pState, nil);
|
||||
NState_SetFilespecCount(pState, 0);
|
||||
}
|
||||
/*
|
||||
* See if we have a file specification. Some of the commands require
|
||||
* a filespec; others just perform the requested operation on all of
|
||||
* the records in the archive if none is provided.
|
||||
*/
|
||||
if (idx < argc) {
|
||||
/* got one or more */
|
||||
NState_SetFilespecPointer(pState, &argv[idx]);
|
||||
NState_SetFilespecCount(pState, argc - idx);
|
||||
} else {
|
||||
assert(idx == argc);
|
||||
if (IsFilespecRequired(NState_GetCommand(pState))) {
|
||||
fprintf(stderr, "%s: This command requires a list of files\n",
|
||||
gProgName);
|
||||
goto fail;
|
||||
}
|
||||
NState_SetFilespecPointer(pState, nil);
|
||||
NState_SetFilespecCount(pState, 0);
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG_VERBOSE
|
||||
NState_DebugDump(pState);
|
||||
NState_DebugDump(pState);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
fprintf(stderr,
|
||||
"%s: (invoke without arguments to see usage information)\n",
|
||||
gProgName);
|
||||
return -1;
|
||||
fprintf(stderr,
|
||||
"%s: (invoke without arguments to see usage information)\n",
|
||||
gProgName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -328,42 +328,42 @@ fail:
|
|||
int
|
||||
DoWork(NulibState* pState)
|
||||
{
|
||||
NuError err;
|
||||
NuError err;
|
||||
|
||||
switch (NState_GetCommand(pState)) {
|
||||
case kCommandAdd:
|
||||
err = DoAdd(pState);
|
||||
break;
|
||||
case kCommandExtract:
|
||||
err = DoExtract(pState);
|
||||
break;
|
||||
case kCommandExtractToPipe:
|
||||
err = DoExtractToPipe(pState);
|
||||
break;
|
||||
case kCommandTest:
|
||||
err = DoTest(pState);
|
||||
break;
|
||||
case kCommandListShort:
|
||||
err = DoListShort(pState);
|
||||
break;
|
||||
case kCommandListVerbose:
|
||||
err = DoListVerbose(pState);
|
||||
break;
|
||||
case kCommandListDebug:
|
||||
err = DoListDebug(pState);
|
||||
break;
|
||||
case kCommandDelete:
|
||||
err = DoDelete(pState);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "ERROR: unexpected command %d\n",
|
||||
NState_GetCommand(pState));
|
||||
err = kNuErrInternal;
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
switch (NState_GetCommand(pState)) {
|
||||
case kCommandAdd:
|
||||
err = DoAdd(pState);
|
||||
break;
|
||||
case kCommandExtract:
|
||||
err = DoExtract(pState);
|
||||
break;
|
||||
case kCommandExtractToPipe:
|
||||
err = DoExtractToPipe(pState);
|
||||
break;
|
||||
case kCommandTest:
|
||||
err = DoTest(pState);
|
||||
break;
|
||||
case kCommandListShort:
|
||||
err = DoListShort(pState);
|
||||
break;
|
||||
case kCommandListVerbose:
|
||||
err = DoListVerbose(pState);
|
||||
break;
|
||||
case kCommandListDebug:
|
||||
err = DoListDebug(pState);
|
||||
break;
|
||||
case kCommandDelete:
|
||||
err = DoDelete(pState);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "ERROR: unexpected command %d\n",
|
||||
NState_GetCommand(pState));
|
||||
err = kNuErrInternal;
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
|
||||
return (err != kNuErrNone);
|
||||
return (err != kNuErrNone);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -372,38 +372,38 @@ DoWork(NulibState* pState)
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
NulibState* pState = nil;
|
||||
int result = 0;
|
||||
NulibState* pState = nil;
|
||||
int result = 0;
|
||||
|
||||
#if 0
|
||||
extern NuResult ErrorMessageHandler(NuArchive* pArchive,
|
||||
void* vErrorMessage);
|
||||
NuSetGlobalErrorMessageHandler(ErrorMessageHandler);
|
||||
#endif
|
||||
#if 0
|
||||
extern NuResult ErrorMessageHandler(NuArchive* pArchive,
|
||||
void* vErrorMessage);
|
||||
NuSetGlobalErrorMessageHandler(ErrorMessageHandler);
|
||||
#endif
|
||||
|
||||
if (NState_Init(&pState) != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to initialize globals\n");
|
||||
exit(1);
|
||||
}
|
||||
if (NState_Init(&pState) != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: unable to initialize globals\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gProgName = GetProgName(pState, argv[0]);
|
||||
gProgName = GetProgName(pState, argv[0]);
|
||||
|
||||
if (ProcessOptions(pState, argc, argv) < 0) {
|
||||
result = 2;
|
||||
goto bail;
|
||||
}
|
||||
if (ProcessOptions(pState, argc, argv) < 0) {
|
||||
result = 2;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (NState_ExtraInit(pState) != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: additional initialization failed\n");
|
||||
exit(1);
|
||||
}
|
||||
if (NState_ExtraInit(pState) != kNuErrNone) {
|
||||
fprintf(stderr, "ERROR: additional initialization failed\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
result = DoWork(pState);
|
||||
if (result)
|
||||
printf("Failed.\n");
|
||||
result = DoWork(pState);
|
||||
if (result)
|
||||
printf("Failed.\n");
|
||||
|
||||
bail:
|
||||
NState_Free(pState);
|
||||
exit(result);
|
||||
NState_Free(pState);
|
||||
exit(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
const char*
|
||||
Nu_strerror(int errnum)
|
||||
{
|
||||
extern int sys_nerr;
|
||||
extern char *sys_errlist[];
|
||||
extern int sys_nerr;
|
||||
extern char *sys_errlist[];
|
||||
|
||||
if (errnum < 0 || errnum > sys_nerr)
|
||||
return NULL;
|
||||
if (errnum < 0 || errnum > sys_nerr)
|
||||
return NULL;
|
||||
|
||||
return sys_errlist[errnum];
|
||||
return sys_errlist[errnum];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -41,13 +41,13 @@ Nu_strerror(int errnum)
|
|||
void*
|
||||
Nu_memmove(void* dst, const void* src, size_t n)
|
||||
{
|
||||
void* retval = dst;
|
||||
char* srcp = (char*)src;
|
||||
char* dstp = (char*)dst;
|
||||
void* retval = dst;
|
||||
char* srcp = (char*)src;
|
||||
char* dstp = (char*)dst;
|
||||
|
||||
/* you can normally get away with this if n==0 */
|
||||
assert(dst != NULL);
|
||||
assert(src != NULL);
|
||||
/* you can normally get away with this if n==0 */
|
||||
assert(dst != NULL);
|
||||
assert(src != NULL);
|
||||
|
||||
if (dstp == srcp || !n) {
|
||||
/* nothing to do */
|
||||
|
@ -63,7 +63,7 @@ Nu_memmove(void* dst, const void* src, size_t n)
|
|||
*dstp++ = *srcp++;
|
||||
}
|
||||
|
||||
return retval;
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -83,7 +83,7 @@ Nu_memmove(void* dst, const void* src, size_t n)
|
|||
unsigned long
|
||||
Nu_strtoul(const char *nptr, char **endptr, int base)
|
||||
{
|
||||
return strtol(nptr, endptr, base);
|
||||
return strtol(nptr, endptr, base);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -94,9 +94,9 @@ Nu_strtoul(const char *nptr, char **endptr, int base)
|
|||
int
|
||||
Nu_strcasecmp(const char *str1, const char *str2)
|
||||
{
|
||||
while (*str1 && *str2 && toupper(*str1) == toupper(*str2))
|
||||
str1++, str2++;
|
||||
return (toupper(*str1) - toupper(*str2));
|
||||
while (*str1 && *str2 && toupper(*str1) == toupper(*str2))
|
||||
str1++, str2++;
|
||||
return (toupper(*str1) - toupper(*str2));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -108,13 +108,13 @@ Nu_strcasecmp(const char *str1, const char *str2)
|
|||
int
|
||||
Nu_strncasecmp(const char *str1, const char *str2, size_t n)
|
||||
{
|
||||
while (n && *str1 && *str2 && toupper(*str1) == toupper(*str2))
|
||||
str1++, str2++, n--;
|
||||
while (n && *str1 && *str2 && toupper(*str1) == toupper(*str2))
|
||||
str1++, str2++, n--;
|
||||
|
||||
if (n)
|
||||
return (toupper(*str1) - toupper(*str2));
|
||||
else
|
||||
return 0; /* no mismatch in first n chars */
|
||||
if (n)
|
||||
return (toupper(*str1) - toupper(*str2));
|
||||
else
|
||||
return 0; /* no mismatch in first n chars */
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -42,11 +42,11 @@ int Nu_strncasecmp(const char *s1, const char *s2, size_t n);
|
|||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define nil NULL /* I can't seem to stop typing 'nil' now */
|
||||
#define nil NULL /* I can't seem to stop typing 'nil' now */
|
||||
|
||||
typedef uchar Boolean;
|
||||
#define false (0)
|
||||
#define true (!false)
|
||||
typedef uchar Boolean;
|
||||
#define false (0)
|
||||
#define true (!false)
|
||||
|
||||
|
||||
/*
|
||||
|
@ -54,15 +54,15 @@ typedef uchar Boolean;
|
|||
*/
|
||||
|
||||
/* compute #of elements in a static array */
|
||||
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
|
||||
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
/* convert single hex digit char to number */
|
||||
#define HexDigit(x) ( !isxdigit((int)(x)) ? -1 : \
|
||||
(x) <= '9' ? (x) - '0' : toupper(x) +10 - 'A' )
|
||||
(x) <= '9' ? (x) - '0' : toupper(x) +10 - 'A' )
|
||||
|
||||
/* convert number from 0-15 to hex digit */
|
||||
#define HexConv(x) ( ((uint)(x)) <= 15 ? \
|
||||
( (x) <= 9 ? (x) + '0' : (x) -10 + 'A') : -1 )
|
||||
#define HexConv(x) ( ((uint)(x)) <= 15 ? \
|
||||
( (x) <= 9 ? (x) + '0' : (x) -10 + 'A') : -1 )
|
||||
|
||||
|
||||
/*
|
||||
|
@ -80,29 +80,29 @@ typedef uchar Boolean;
|
|||
|
||||
#if defined(DEBUG_VERBOSE)
|
||||
/* quick debug printf macro */
|
||||
#define DBUG(args) printf args
|
||||
#define DBUG(args) printf args
|
||||
#else
|
||||
#define DBUG(args) ((void)0)
|
||||
#define DBUG(args) ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(NDEBUG)
|
||||
#define DebugFill(addr, len) ((void)0)
|
||||
#define DebugFill(addr, len) ((void)0)
|
||||
|
||||
#define DebugAbort() ((void)0)
|
||||
#define DebugAbort() ((void)0)
|
||||
|
||||
#else
|
||||
/* when debugging, fill Malloc blocks with junk, unless we're using Purify */
|
||||
#if !defined(PURIFY)
|
||||
#define DebugFill(addr, len) memset(addr, 0xa3, len)
|
||||
#define DebugFill(addr, len) memset(addr, 0xa3, len)
|
||||
#else
|
||||
#define DebugFill(addr, len) ((void)0)
|
||||
#define DebugFill(addr, len) ((void)0)
|
||||
#endif
|
||||
|
||||
#define DebugAbort() abort()
|
||||
#define DebugAbort() abort()
|
||||
#endif
|
||||
|
||||
#define kInvalidFill (0xa3)
|
||||
#define kInvalidPtr ((void*)0xa3a3a3a3)
|
||||
#define kInvalidFill (0xa3)
|
||||
#define kInvalidPtr ((void*)0xa3a3a3a3)
|
||||
|
||||
#endif /*__MiscStuff__*/
|
||||
|
|
|
@ -19,39 +19,39 @@
|
|||
void
|
||||
ReportError(NuError err, const char* format, ...)
|
||||
{
|
||||
const char* msg;
|
||||
va_list args;
|
||||
const char* msg;
|
||||
va_list args;
|
||||
|
||||
assert(format != nil);
|
||||
assert(format != nil);
|
||||
|
||||
va_start(args, format);
|
||||
va_start(args, format);
|
||||
|
||||
/* print the message, if any */
|
||||
if (format != nil) {
|
||||
fprintf(stderr, "%s: ERROR: ", gProgName);
|
||||
vfprintf(stderr, format, args);
|
||||
}
|
||||
/* print the message, if any */
|
||||
if (format != nil) {
|
||||
fprintf(stderr, "%s: ERROR: ", gProgName);
|
||||
vfprintf(stderr, format, args);
|
||||
}
|
||||
|
||||
/* print the error code data, if any */
|
||||
if (err == kNuErrNone)
|
||||
fprintf(stderr, "\n");
|
||||
else {
|
||||
if (format != nil)
|
||||
fprintf(stderr, ": ");
|
||||
/* print the error code data, if any */
|
||||
if (err == kNuErrNone)
|
||||
fprintf(stderr, "\n");
|
||||
else {
|
||||
if (format != nil)
|
||||
fprintf(stderr, ": ");
|
||||
|
||||
msg = nil;
|
||||
if (err >= 0)
|
||||
msg = strerror(err);
|
||||
if (msg == nil)
|
||||
msg = NuStrError(err);
|
||||
msg = nil;
|
||||
if (err >= 0)
|
||||
msg = strerror(err);
|
||||
if (msg == nil)
|
||||
msg = NuStrError(err);
|
||||
|
||||
if (msg == nil)
|
||||
fprintf(stderr, "(unknown err=%d)\n", err);
|
||||
else
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
}
|
||||
if (msg == nil)
|
||||
fprintf(stderr, "(unknown err=%d)\n", err);
|
||||
else
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
|
@ -65,46 +65,46 @@ ReportError(NuError err, const char* format, ...)
|
|||
void*
|
||||
Malloc(size_t size)
|
||||
{
|
||||
void* _result;
|
||||
void* _result;
|
||||
|
||||
Assert(size > 0);
|
||||
_result = malloc(size);
|
||||
if (_result == nil) {
|
||||
ReportError(kNuErrMalloc, "malloc(%u) failed", (uint) size);
|
||||
DebugAbort(); /* leave a core dump if we're built for it */
|
||||
}
|
||||
DebugFill(_result, size);
|
||||
return _result;
|
||||
Assert(size > 0);
|
||||
_result = malloc(size);
|
||||
if (_result == nil) {
|
||||
ReportError(kNuErrMalloc, "malloc(%u) failed", (uint) size);
|
||||
DebugAbort(); /* leave a core dump if we're built for it */
|
||||
}
|
||||
DebugFill(_result, size);
|
||||
return _result;
|
||||
}
|
||||
|
||||
void*
|
||||
Calloc(size_t size)
|
||||
{
|
||||
void* _cresult = Malloc(size);
|
||||
memset(_cresult, 0, size);
|
||||
return _cresult;
|
||||
void* _cresult = Malloc(size);
|
||||
memset(_cresult, 0, size);
|
||||
return _cresult;
|
||||
}
|
||||
|
||||
void*
|
||||
Realloc(void* ptr, size_t size)
|
||||
{
|
||||
void* _result;
|
||||
void* _result;
|
||||
|
||||
Assert(ptr != nil); /* disallow this usage */
|
||||
Assert(size > 0); /* disallow this usage */
|
||||
_result = realloc(ptr, size);
|
||||
if (_result == nil) {
|
||||
ReportError(kNuErrMalloc, "realloc(%u) failed", (uint) size);
|
||||
DebugAbort(); /* leave a core dump if we're built for it */
|
||||
}
|
||||
return _result;
|
||||
Assert(ptr != nil); /* disallow this usage */
|
||||
Assert(size > 0); /* disallow this usage */
|
||||
_result = realloc(ptr, size);
|
||||
if (_result == nil) {
|
||||
ReportError(kNuErrMalloc, "realloc(%u) failed", (uint) size);
|
||||
DebugAbort(); /* leave a core dump if we're built for it */
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
void
|
||||
Free(void* ptr)
|
||||
{
|
||||
if (ptr != nil)
|
||||
free(ptr);
|
||||
if (ptr != nil)
|
||||
free(ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#ifndef __Nulib2__
|
||||
#define __Nulib2__
|
||||
|
||||
#include "SysDefs.h" /* system-dependent defs; must come first */
|
||||
#include "SysDefs.h" /* system-dependent defs; must come first */
|
||||
#include <NufxLib.h>
|
||||
#include "State.h"
|
||||
#include "MiscStuff.h"
|
||||
|
@ -18,10 +18,10 @@
|
|||
#endif
|
||||
|
||||
/* replace unsupported chars with '%xx' */
|
||||
#define kForeignIndic '%'
|
||||
#define kForeignIndic '%'
|
||||
|
||||
/* make our one-line comments this big */
|
||||
#define kDefaultCommentLen 200
|
||||
#define kDefaultCommentLen 200
|
||||
|
||||
|
||||
/*
|
||||
|
@ -52,9 +52,9 @@ NuError DoTest(NulibState* pState);
|
|||
const char* GetFileTypeString(ulong fileType);
|
||||
const char* NormalizePath(NulibState* pState, NuPathnameProposal* pathProposal);
|
||||
void InterpretExtension(NulibState* pState, const char* pathName,
|
||||
ulong* pFileType, ulong* pAuxType);
|
||||
ulong* pFileType, ulong* pAuxType);
|
||||
Boolean ExtractPreservationString(NulibState* pState, char* pathname,
|
||||
ulong* pFileType, ulong* pAuxType, NuThreadID* pThreadID);
|
||||
ulong* pFileType, ulong* pAuxType, NuThreadID* pThreadID);
|
||||
void DenormalizePath(NulibState* pState, char* pathBuf);
|
||||
const char* FilenameOnly(NulibState* pState, const char* pathname);
|
||||
const char* FindExtension(NulibState* pState, const char* pathname);
|
||||
|
@ -73,7 +73,7 @@ void ReportError(NuError err, const char* format, ...)
|
|||
__attribute__ ((format(printf, 2, 3)))
|
||||
#endif
|
||||
;
|
||||
#ifdef USE_DMALLOC /* want file and line numbers for calls */
|
||||
#ifdef USE_DMALLOC /* want file and line numbers for calls */
|
||||
# define Malloc(size) malloc(size)
|
||||
# define Calloc(size) calloc(1, size)
|
||||
# define Realloc(ptr, size) realloc(ptr, size)
|
||||
|
@ -87,11 +87,11 @@ void Free(void* ptr);
|
|||
|
||||
/* SysUtils.c */
|
||||
NuError NormalizeFileName(NulibState* pState, const char* srcp, long srcLen,
|
||||
char fssep, char** pDstp, long dstLen);
|
||||
char fssep, char** pDstp, long dstLen);
|
||||
NuError NormalizeDirectoryName(NulibState* pState, const char* srcp,
|
||||
long srcLen, char fssep, char** pDstp, long dstLen);
|
||||
long srcLen, char fssep, char** pDstp, long dstLen);
|
||||
char* MakeTempArchiveName(NulibState* pState);
|
||||
NuError AddFile(NulibState* pState, NuArchive* pArchive,
|
||||
const char* pathname);
|
||||
const char* pathname);
|
||||
|
||||
#endif /*__Nulib2__*/
|
||||
|
|
|
@ -59,16 +59,16 @@ DJGPP, follow the UNIX instructions.
|
|||
|
||||
NuLib2 has been tested with Microsoft Visual C++ 6.0. To build NuLib2,
|
||||
start up a DOS shell and run vcvars32.bat to set your environment. Run:
|
||||
nmake -f makefile.msc
|
||||
nmake -f makefile.msc
|
||||
to build with debugging info, or
|
||||
nmake -f makefile.msc nodebug=1
|
||||
nmake -f makefile.msc nodebug=1
|
||||
to build optimized.
|
||||
|
||||
|
||||
Other Notes
|
||||
===========
|
||||
|
||||
All of the source code was formatted with four-space hard tabs.
|
||||
All of the source code is now formatted with spaces instead of tabs.
|
||||
|
||||
|
||||
Fun benchmark of the day:
|
||||
|
|
318
nulib2/State.c
318
nulib2/State.c
|
@ -18,19 +18,19 @@ static const char* gProgramVersion = "1.0.1";
|
|||
NuError
|
||||
NState_Init(NulibState** ppState)
|
||||
{
|
||||
assert(ppState != nil);
|
||||
assert(ppState != nil);
|
||||
|
||||
*ppState = Calloc(sizeof(**ppState));
|
||||
if (*ppState == nil)
|
||||
return kNuErrMalloc;
|
||||
*ppState = Calloc(sizeof(**ppState));
|
||||
if (*ppState == nil)
|
||||
return kNuErrMalloc;
|
||||
|
||||
/*
|
||||
* Initialize the contents to default values.
|
||||
*/
|
||||
(*ppState)->systemPathSeparator = PATH_SEP;
|
||||
(*ppState)->programVersion = gProgramVersion;
|
||||
/*
|
||||
* Initialize the contents to default values.
|
||||
*/
|
||||
(*ppState)->systemPathSeparator = PATH_SEP;
|
||||
(*ppState)->programVersion = gProgramVersion;
|
||||
|
||||
return kNuErrNone;
|
||||
return kNuErrNone;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -39,30 +39,30 @@ NState_Init(NulibState** ppState)
|
|||
NuError
|
||||
NState_ExtraInit(NulibState* pState)
|
||||
{
|
||||
NuError err;
|
||||
NuValue convertEOL;
|
||||
NuError err;
|
||||
NuValue convertEOL;
|
||||
|
||||
/*
|
||||
* Create a data sink for "stdout", in case we use the "-p" command.
|
||||
* Set the EOL conversion according to the "-l" modifier.
|
||||
*/
|
||||
convertEOL = kNuConvertOff;
|
||||
if (pState->modConvertText)
|
||||
convertEOL = kNuConvertAuto;
|
||||
if (pState->modConvertAll)
|
||||
convertEOL = kNuConvertOn;
|
||||
/*
|
||||
* Create a data sink for "stdout", in case we use the "-p" command.
|
||||
* Set the EOL conversion according to the "-l" modifier.
|
||||
*/
|
||||
convertEOL = kNuConvertOff;
|
||||
if (pState->modConvertText)
|
||||
convertEOL = kNuConvertAuto;
|
||||
if (pState->modConvertAll)
|
||||
convertEOL = kNuConvertOn;
|
||||
|
||||
err = NuCreateDataSinkForFP(true, convertEOL, stdout, &pState->pPipeSink);
|
||||
if (err != kNuErrNone)
|
||||
return err;
|
||||
err = NuCreateDataSinkForFP(true, convertEOL, stdout, &pState->pPipeSink);
|
||||
if (err != kNuErrNone)
|
||||
return err;
|
||||
|
||||
/*
|
||||
* Create a data sink for "stdout", in case we use the "-c" modifier.
|
||||
* The EOL conversion is always on.
|
||||
*/
|
||||
err = NuCreateDataSinkForFP(true, kNuConvertOn, stdout,
|
||||
&pState->pCommentSink);
|
||||
return err;
|
||||
/*
|
||||
* Create a data sink for "stdout", in case we use the "-c" modifier.
|
||||
* The EOL conversion is always on.
|
||||
*/
|
||||
err = NuCreateDataSinkForFP(true, kNuConvertOn, stdout,
|
||||
&pState->pCommentSink);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,16 +72,16 @@ NState_ExtraInit(NulibState* pState)
|
|||
void
|
||||
NState_Free(NulibState* pState)
|
||||
{
|
||||
if (pState == nil)
|
||||
return;
|
||||
if (pState == nil)
|
||||
return;
|
||||
|
||||
Free(pState->renameToStr); /* ?? */
|
||||
Free(pState->tempPathnameBuf);
|
||||
if (pState->pPipeSink != nil)
|
||||
NuFreeDataSink(pState->pPipeSink);
|
||||
if (pState->pCommentSink != nil)
|
||||
NuFreeDataSink(pState->pCommentSink);
|
||||
Free(pState);
|
||||
Free(pState->renameToStr); /* ?? */
|
||||
Free(pState->tempPathnameBuf);
|
||||
if (pState->pPipeSink != nil)
|
||||
NuFreeDataSink(pState->pPipeSink);
|
||||
if (pState->pCommentSink != nil)
|
||||
NuFreeDataSink(pState->pCommentSink);
|
||||
Free(pState);
|
||||
}
|
||||
|
||||
|
||||
|
@ -89,411 +89,411 @@ NState_Free(NulibState* pState)
|
|||
void
|
||||
NState_DebugDump(const NulibState* pState)
|
||||
{
|
||||
/* this will break when the code changes, but it's just for debugging */
|
||||
static const char* kCommandNames[] = {
|
||||
"<unknown>",
|
||||
"add",
|
||||
"delete",
|
||||
"extract",
|
||||
"extractToPipe",
|
||||
"listShort",
|
||||
"listVerbose",
|
||||
"listDebug",
|
||||
"test",
|
||||
};
|
||||
/* this will break when the code changes, but it's just for debugging */
|
||||
static const char* kCommandNames[] = {
|
||||
"<unknown>",
|
||||
"add",
|
||||
"delete",
|
||||
"extract",
|
||||
"extractToPipe",
|
||||
"listShort",
|
||||
"listVerbose",
|
||||
"listDebug",
|
||||
"test",
|
||||
};
|
||||
|
||||
assert(pState != nil);
|
||||
assert(pState != nil);
|
||||
|
||||
printf("NState:\n");
|
||||
printf(" programVersion: '%s'\n", pState->programVersion);
|
||||
printf(" systemPathSeparator: '%c'\n", pState->systemPathSeparator);
|
||||
printf(" archiveFilename: '%s'\n", pState->archiveFilename);
|
||||
printf(" filespec: %ld (%s ...)\n", pState->filespecCount,
|
||||
!pState->filespecCount ? "<none>" : *pState->filespecPointer);
|
||||
printf("NState:\n");
|
||||
printf(" programVersion: '%s'\n", pState->programVersion);
|
||||
printf(" systemPathSeparator: '%c'\n", pState->systemPathSeparator);
|
||||
printf(" archiveFilename: '%s'\n", pState->archiveFilename);
|
||||
printf(" filespec: %ld (%s ...)\n", pState->filespecCount,
|
||||
!pState->filespecCount ? "<none>" : *pState->filespecPointer);
|
||||
|
||||
printf(" command: %d (%s); modifiers:\n", pState->command,
|
||||
kCommandNames[pState->command]);
|
||||
if (pState->modUpdate)
|
||||
printf(" update\n");
|
||||
if (pState->modFreshen)
|
||||
printf(" freshen\n");
|
||||
if (pState->modRecurse)
|
||||
printf(" recurse\n");
|
||||
if (pState->modJunkPaths)
|
||||
printf(" junkPaths\n");
|
||||
if (pState->modNoCompression)
|
||||
printf(" noCompression\n");
|
||||
if (pState->modComments)
|
||||
printf(" comments\n");
|
||||
if (pState->modConvertText)
|
||||
printf(" convertText\n");
|
||||
if (pState->modConvertAll)
|
||||
printf(" convertAll\n");
|
||||
if (pState->modOverwriteExisting)
|
||||
printf(" overwriteExisting\n");
|
||||
if (pState->modPreserveType)
|
||||
printf(" preserveType\n");
|
||||
if (pState->modPreserveTypeExtended)
|
||||
printf(" preserveTypeExtended\n");
|
||||
printf(" command: %d (%s); modifiers:\n", pState->command,
|
||||
kCommandNames[pState->command]);
|
||||
if (pState->modUpdate)
|
||||
printf(" update\n");
|
||||
if (pState->modFreshen)
|
||||
printf(" freshen\n");
|
||||
if (pState->modRecurse)
|
||||
printf(" recurse\n");
|
||||
if (pState->modJunkPaths)
|
||||
printf(" junkPaths\n");
|
||||
if (pState->modNoCompression)
|
||||
printf(" noCompression\n");
|
||||
if (pState->modComments)
|
||||
printf(" comments\n");
|
||||
if (pState->modConvertText)
|
||||
printf(" convertText\n");
|
||||
if (pState->modConvertAll)
|
||||
printf(" convertAll\n");
|
||||
if (pState->modOverwriteExisting)
|
||||
printf(" overwriteExisting\n");
|
||||
if (pState->modPreserveType)
|
||||
printf(" preserveType\n");
|
||||
if (pState->modPreserveTypeExtended)
|
||||
printf(" preserveTypeExtended\n");
|
||||
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* ===========================================================================
|
||||
* Simple set/get functions
|
||||
* Simple set/get functions
|
||||
* ===========================================================================
|
||||
*/
|
||||
|
||||
char
|
||||
NState_GetSystemPathSeparator(const NulibState* pState)
|
||||
{
|
||||
return pState->systemPathSeparator;
|
||||
return pState->systemPathSeparator;
|
||||
}
|
||||
|
||||
const char*
|
||||
NState_GetProgramVersion(const NulibState* pState)
|
||||
{
|
||||
return pState->programVersion;
|
||||
return pState->programVersion;
|
||||
}
|
||||
|
||||
NuArchive*
|
||||
NState_GetNuArchive(const NulibState* pState)
|
||||
{
|
||||
return pState->pArchive;
|
||||
return pState->pArchive;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetNuArchive(NulibState* pState, NuArchive* pArchive)
|
||||
{
|
||||
pState->pArchive = pArchive;
|
||||
pState->pArchive = pArchive;
|
||||
}
|
||||
|
||||
|
||||
Boolean
|
||||
NState_GetSuppressOutput(const NulibState* pState)
|
||||
{
|
||||
return pState->suppressOutput;
|
||||
return pState->suppressOutput;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetSuppressOutput(NulibState* pState, Boolean doSuppress)
|
||||
{
|
||||
pState->suppressOutput = doSuppress;
|
||||
pState->suppressOutput = doSuppress;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetInputUnavailable(const NulibState* pState)
|
||||
{
|
||||
return pState->inputUnavailable;
|
||||
return pState->inputUnavailable;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetInputUnavailable(NulibState* pState, Boolean isUnavailable)
|
||||
{
|
||||
pState->inputUnavailable = isUnavailable;
|
||||
pState->inputUnavailable = isUnavailable;
|
||||
}
|
||||
|
||||
NuRecordIdx
|
||||
NState_GetRenameFromIdx(const NulibState* pState)
|
||||
{
|
||||
return pState->renameFromIdx;
|
||||
return pState->renameFromIdx;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetRenameFromIdx(NulibState* pState, NuRecordIdx recordIdx)
|
||||
{
|
||||
pState->renameFromIdx = recordIdx;
|
||||
pState->renameFromIdx = recordIdx;
|
||||
}
|
||||
|
||||
char*
|
||||
NState_GetRenameToStr(const NulibState* pState)
|
||||
{
|
||||
return pState->renameToStr;
|
||||
return pState->renameToStr;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetRenameToStr(NulibState* pState, char* str)
|
||||
{
|
||||
Free(pState->renameToStr);
|
||||
pState->renameToStr = str;
|
||||
Free(pState->renameToStr);
|
||||
pState->renameToStr = str;
|
||||
}
|
||||
|
||||
|
||||
NuDataSink*
|
||||
NState_GetPipeSink(const NulibState* pState)
|
||||
{
|
||||
return pState->pPipeSink;
|
||||
return pState->pPipeSink;
|
||||
}
|
||||
|
||||
NuDataSink*
|
||||
NState_GetCommentSink(const NulibState* pState)
|
||||
{
|
||||
return pState->pCommentSink;
|
||||
return pState->pCommentSink;
|
||||
}
|
||||
|
||||
long
|
||||
NState_GetMatchCount(const NulibState* pState)
|
||||
{
|
||||
return pState->matchCount;
|
||||
return pState->matchCount;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetMatchCount(NulibState* pState, long count)
|
||||
{
|
||||
pState->matchCount = count;
|
||||
pState->matchCount = count;
|
||||
}
|
||||
|
||||
void
|
||||
NState_IncMatchCount(NulibState* pState)
|
||||
{
|
||||
pState->matchCount++;
|
||||
pState->matchCount++;
|
||||
}
|
||||
|
||||
void
|
||||
NState_AddToTotals(NulibState* pState, long len, long compLen)
|
||||
{
|
||||
pState->totalLen += len;
|
||||
pState->totalCompLen += compLen;
|
||||
pState->totalLen += len;
|
||||
pState->totalCompLen += compLen;
|
||||
}
|
||||
|
||||
void
|
||||
NState_GetTotals(NulibState* pState, long* pTotalLen, long* pTotalCompLen)
|
||||
{
|
||||
*pTotalLen = pState->totalLen;
|
||||
*pTotalCompLen = pState->totalCompLen;
|
||||
*pTotalLen = pState->totalLen;
|
||||
*pTotalCompLen = pState->totalCompLen;
|
||||
}
|
||||
|
||||
long
|
||||
NState_GetTempPathnameLen(NulibState* pState)
|
||||
{
|
||||
return pState->tempPathnameAlloc;
|
||||
return pState->tempPathnameAlloc;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetTempPathnameLen(NulibState* pState, long len)
|
||||
{
|
||||
char* newBuf;
|
||||
char* newBuf;
|
||||
|
||||
len++; /* add one for the '\0' */
|
||||
len++; /* add one for the '\0' */
|
||||
|
||||
if (pState->tempPathnameAlloc < len) {
|
||||
if (pState->tempPathnameBuf == nil)
|
||||
newBuf = Malloc(len);
|
||||
else
|
||||
newBuf = Realloc(pState->tempPathnameBuf, len);
|
||||
assert(newBuf != nil);
|
||||
if (newBuf == nil) {
|
||||
Free(pState->tempPathnameBuf);
|
||||
pState->tempPathnameBuf = nil;
|
||||
pState->tempPathnameAlloc = 0;
|
||||
ReportError(kNuErrMalloc, "buf realloc failed (%ld)", len);
|
||||
return;
|
||||
}
|
||||
if (pState->tempPathnameAlloc < len) {
|
||||
if (pState->tempPathnameBuf == nil)
|
||||
newBuf = Malloc(len);
|
||||
else
|
||||
newBuf = Realloc(pState->tempPathnameBuf, len);
|
||||
assert(newBuf != nil);
|
||||
if (newBuf == nil) {
|
||||
Free(pState->tempPathnameBuf);
|
||||
pState->tempPathnameBuf = nil;
|
||||
pState->tempPathnameAlloc = 0;
|
||||
ReportError(kNuErrMalloc, "buf realloc failed (%ld)", len);
|
||||
return;
|
||||
}
|
||||
|
||||
pState->tempPathnameBuf = newBuf;
|
||||
pState->tempPathnameAlloc = len;
|
||||
}
|
||||
pState->tempPathnameBuf = newBuf;
|
||||
pState->tempPathnameAlloc = len;
|
||||
}
|
||||
}
|
||||
|
||||
char*
|
||||
NState_GetTempPathnameBuf(NulibState* pState)
|
||||
{
|
||||
return pState->tempPathnameBuf;
|
||||
return pState->tempPathnameBuf;
|
||||
}
|
||||
|
||||
|
||||
Command
|
||||
NState_GetCommand(const NulibState* pState)
|
||||
{
|
||||
return pState->command;
|
||||
return pState->command;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetCommand(NulibState* pState, Command cmd)
|
||||
{
|
||||
pState->command = cmd;
|
||||
pState->command = cmd;
|
||||
}
|
||||
|
||||
const char*
|
||||
NState_GetArchiveFilename(const NulibState* pState)
|
||||
{
|
||||
return pState->archiveFilename;
|
||||
return pState->archiveFilename;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetArchiveFilename(NulibState* pState, const char* archiveFilename)
|
||||
{
|
||||
pState->archiveFilename = archiveFilename;
|
||||
pState->archiveFilename = archiveFilename;
|
||||
}
|
||||
|
||||
char* const*
|
||||
NState_GetFilespecPointer(const NulibState* pState)
|
||||
{
|
||||
return pState->filespecPointer;
|
||||
return pState->filespecPointer;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetFilespecPointer(NulibState* pState, char* const* filespecPointer)
|
||||
{
|
||||
pState->filespecPointer = filespecPointer;
|
||||
pState->filespecPointer = filespecPointer;
|
||||
}
|
||||
|
||||
long
|
||||
NState_GetFilespecCount(const NulibState* pState)
|
||||
{
|
||||
return pState->filespecCount;
|
||||
return pState->filespecCount;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetFilespecCount(NulibState* pState, long filespecCount)
|
||||
{
|
||||
pState->filespecCount = filespecCount;
|
||||
pState->filespecCount = filespecCount;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetModUpdate(const NulibState* pState)
|
||||
{
|
||||
return pState->modUpdate;
|
||||
return pState->modUpdate;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetModUpdate(NulibState* pState, Boolean val)
|
||||
{
|
||||
pState->modUpdate = val;
|
||||
pState->modUpdate = val;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetModFreshen(const NulibState* pState)
|
||||
{
|
||||
return pState->modFreshen;
|
||||
return pState->modFreshen;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetModFreshen(NulibState* pState, Boolean val)
|
||||
{
|
||||
pState->modFreshen = val;
|
||||
pState->modFreshen = val;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetModRecurse(const NulibState* pState)
|
||||
{
|
||||
return pState->modRecurse;
|
||||
return pState->modRecurse;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetModRecurse(NulibState* pState, Boolean val)
|
||||
{
|
||||
pState->modRecurse = val;
|
||||
pState->modRecurse = val;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetModJunkPaths(const NulibState* pState)
|
||||
{
|
||||
return pState->modJunkPaths;
|
||||
return pState->modJunkPaths;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetModJunkPaths(NulibState* pState, Boolean val)
|
||||
{
|
||||
pState->modJunkPaths = val;
|
||||
pState->modJunkPaths = val;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetModNoCompression(const NulibState* pState)
|
||||
{
|
||||
return pState->modNoCompression;
|
||||
return pState->modNoCompression;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetModNoCompression(NulibState* pState, Boolean val)
|
||||
{
|
||||
pState->modNoCompression = val;
|
||||
pState->modNoCompression = val;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetModComments(const NulibState* pState)
|
||||
{
|
||||
return pState->modComments;
|
||||
return pState->modComments;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetModComments(NulibState* pState, Boolean val)
|
||||
{
|
||||
pState->modComments = val;
|
||||
pState->modComments = val;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetModConvertText(const NulibState* pState)
|
||||
{
|
||||
return pState->modConvertText;
|
||||
return pState->modConvertText;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetModConvertText(NulibState* pState, Boolean val)
|
||||
{
|
||||
pState->modConvertText = val;
|
||||
pState->modConvertText = val;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetModConvertAll(const NulibState* pState)
|
||||
{
|
||||
return pState->modConvertAll;
|
||||
return pState->modConvertAll;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetModConvertAll(NulibState* pState, Boolean val)
|
||||
{
|
||||
pState->modConvertAll = val;
|
||||
pState->modConvertAll = val;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetModOverwriteExisting(const NulibState* pState)
|
||||
{
|
||||
return pState->modOverwriteExisting;
|
||||
return pState->modOverwriteExisting;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetModOverwriteExisting(NulibState* pState, Boolean val)
|
||||
{
|
||||
pState->modOverwriteExisting = val;
|
||||
pState->modOverwriteExisting = val;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetModAddAsDisk(const NulibState* pState)
|
||||
{
|
||||
return pState->modAddAsDisk;
|
||||
return pState->modAddAsDisk;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetModAddAsDisk(NulibState* pState, Boolean val)
|
||||
{
|
||||
pState->modAddAsDisk = val;
|
||||
pState->modAddAsDisk = val;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetModPreserveType(const NulibState* pState)
|
||||
{
|
||||
return pState->modPreserveType;
|
||||
return pState->modPreserveType;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetModPreserveType(NulibState* pState, Boolean val)
|
||||
{
|
||||
pState->modPreserveType = val;
|
||||
pState->modPreserveType = val;
|
||||
}
|
||||
|
||||
Boolean
|
||||
NState_GetModPreserveTypeExtended(const NulibState* pState)
|
||||
{
|
||||
return pState->modPreserveTypeExtended;
|
||||
return pState->modPreserveTypeExtended;
|
||||
}
|
||||
|
||||
void
|
||||
NState_SetModPreserveTypeExtended(NulibState* pState, Boolean val)
|
||||
{
|
||||
pState->modPreserveTypeExtended = val;
|
||||
pState->modPreserveTypeExtended = val;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,15 +16,15 @@
|
|||
* (Some debug code in NState_DebugDump() is sensitive to the order here.)
|
||||
*/
|
||||
typedef enum Command {
|
||||
kCommandUnknown = 0,
|
||||
kCommandAdd,
|
||||
kCommandDelete,
|
||||
kCommandExtract,
|
||||
kCommandExtractToPipe,
|
||||
kCommandListShort,
|
||||
kCommandListVerbose,
|
||||
kCommandListDebug,
|
||||
kCommandTest
|
||||
kCommandUnknown = 0,
|
||||
kCommandAdd,
|
||||
kCommandDelete,
|
||||
kCommandExtract,
|
||||
kCommandExtractToPipe,
|
||||
kCommandListShort,
|
||||
kCommandListVerbose,
|
||||
kCommandListDebug,
|
||||
kCommandTest
|
||||
} Command;
|
||||
|
||||
|
||||
|
@ -32,48 +32,48 @@ typedef enum Command {
|
|||
* Program-wide state.
|
||||
*/
|
||||
typedef struct NulibState {
|
||||
/* global goodness */
|
||||
const char* programVersion;
|
||||
/* global goodness */
|
||||
const char* programVersion;
|
||||
|
||||
/* system-specific values */
|
||||
char systemPathSeparator;
|
||||
/* system-specific values */
|
||||
char systemPathSeparator;
|
||||
|
||||
/* pointer to archive we're working with */
|
||||
NuArchive* pArchive;
|
||||
/* pointer to archive we're working with */
|
||||
NuArchive* pArchive;
|
||||
|
||||
/* misc state */
|
||||
Boolean suppressOutput;
|
||||
Boolean inputUnavailable;
|
||||
NuRecordIdx renameFromIdx;
|
||||
char* renameToStr;
|
||||
NuDataSink* pPipeSink;
|
||||
NuDataSink* pCommentSink;
|
||||
long matchCount;
|
||||
long totalLen;
|
||||
long totalCompLen;
|
||||
/* misc state */
|
||||
Boolean suppressOutput;
|
||||
Boolean inputUnavailable;
|
||||
NuRecordIdx renameFromIdx;
|
||||
char* renameToStr;
|
||||
NuDataSink* pPipeSink;
|
||||
NuDataSink* pCommentSink;
|
||||
long matchCount;
|
||||
long totalLen;
|
||||
long totalCompLen;
|
||||
|
||||
/* temp storage */
|
||||
long tempPathnameAlloc;
|
||||
char* tempPathnameBuf;
|
||||
/* temp storage */
|
||||
long tempPathnameAlloc;
|
||||
char* tempPathnameBuf;
|
||||
|
||||
/* command-line options */
|
||||
Command command;
|
||||
Boolean modUpdate;
|
||||
Boolean modFreshen;
|
||||
Boolean modRecurse;
|
||||
Boolean modJunkPaths;
|
||||
Boolean modNoCompression;
|
||||
Boolean modComments;
|
||||
Boolean modConvertText;
|
||||
Boolean modConvertAll;
|
||||
Boolean modOverwriteExisting;
|
||||
Boolean modAddAsDisk;
|
||||
Boolean modPreserveType;
|
||||
Boolean modPreserveTypeExtended;
|
||||
/* command-line options */
|
||||
Command command;
|
||||
Boolean modUpdate;
|
||||
Boolean modFreshen;
|
||||
Boolean modRecurse;
|
||||
Boolean modJunkPaths;
|
||||
Boolean modNoCompression;
|
||||
Boolean modComments;
|
||||
Boolean modConvertText;
|
||||
Boolean modConvertAll;
|
||||
Boolean modOverwriteExisting;
|
||||
Boolean modAddAsDisk;
|
||||
Boolean modPreserveType;
|
||||
Boolean modPreserveTypeExtended;
|
||||
|
||||
const char* archiveFilename;
|
||||
char* const* filespecPointer;
|
||||
long filespecCount;
|
||||
const char* archiveFilename;
|
||||
char* const* filespecPointer;
|
||||
long filespecCount;
|
||||
} NulibState;
|
||||
|
||||
NuError NState_Init(NulibState** ppState);
|
||||
|
|
|
@ -13,35 +13,35 @@
|
|||
#define __SunOS4__
|
||||
|
||||
#ifdef __GNUC__
|
||||
extern int _flsbuf(int, FILE*);
|
||||
extern int _filbuf(FILE*);
|
||||
extern int _flsbuf(int, FILE*);
|
||||
extern int _filbuf(FILE*);
|
||||
#endif
|
||||
|
||||
extern void bcopy(char*, char*, int);
|
||||
extern int fclose(FILE*);
|
||||
extern int fflush(FILE*);
|
||||
extern int fprintf(FILE*, const char*, ...);
|
||||
extern int fread(char*, int, int, FILE *);
|
||||
extern int fseek(FILE*, long, int);
|
||||
extern int ftruncate(int, off_t);
|
||||
extern int fwrite(const char*, int, int, FILE*);
|
||||
extern char* mktemp(char *template);
|
||||
extern time_t mktime(struct tm*);
|
||||
extern int perror(const char*);
|
||||
extern int printf(const char*, ...);
|
||||
extern int remove(const char*);
|
||||
extern int rename(const char*, const char*);
|
||||
extern int tolower(int);
|
||||
extern int setvbuf(FILE*, char*, int, int);
|
||||
extern int sscanf(char*, const char*, ...);
|
||||
extern int strcasecmp(const char*, const char*);
|
||||
extern int strncasecmp(const char*, const char*, size_t);
|
||||
extern long strtol(const char *, char **, int);
|
||||
extern int system(const char*);
|
||||
extern time_t timelocal(struct tm*);
|
||||
extern time_t time(time_t*);
|
||||
extern int toupper(int);
|
||||
extern int vfprintf(FILE*, const char *, va_list);
|
||||
extern char* vsprintf(char *str, const char *format, va_list ap);
|
||||
extern void bcopy(char*, char*, int);
|
||||
extern int fclose(FILE*);
|
||||
extern int fflush(FILE*);
|
||||
extern int fprintf(FILE*, const char*, ...);
|
||||
extern int fread(char*, int, int, FILE *);
|
||||
extern int fseek(FILE*, long, int);
|
||||
extern int ftruncate(int, off_t);
|
||||
extern int fwrite(const char*, int, int, FILE*);
|
||||
extern char* mktemp(char *template);
|
||||
extern time_t mktime(struct tm*);
|
||||
extern int perror(const char*);
|
||||
extern int printf(const char*, ...);
|
||||
extern int remove(const char*);
|
||||
extern int rename(const char*, const char*);
|
||||
extern int tolower(int);
|
||||
extern int setvbuf(FILE*, char*, int, int);
|
||||
extern int sscanf(char*, const char*, ...);
|
||||
extern int strcasecmp(const char*, const char*);
|
||||
extern int strncasecmp(const char*, const char*, size_t);
|
||||
extern long strtol(const char *, char **, int);
|
||||
extern int system(const char*);
|
||||
extern time_t timelocal(struct tm*);
|
||||
extern time_t time(time_t*);
|
||||
extern int toupper(int);
|
||||
extern int vfprintf(FILE*, const char *, va_list);
|
||||
extern char* vsprintf(char *str, const char *format, va_list ap);
|
||||
|
||||
#endif /*__SunOS4__*/
|
||||
|
|
|
@ -93,16 +93,16 @@
|
|||
|
||||
#if defined(WINDOWS_LIKE)
|
||||
# ifndef F_OK
|
||||
# define F_OK 02
|
||||
# define F_OK 02
|
||||
# endif
|
||||
# ifndef R_OK
|
||||
# define R_OK 04
|
||||
# define R_OK 04
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__unix__) || defined(__unix) || defined(__BEOS__) || \
|
||||
defined(__hpux) || defined(_AIX) || defined(__APPLE__)
|
||||
defined(__hpux) || defined(_AIX) || defined(__APPLE__)
|
||||
# define UNIX_LIKE
|
||||
#endif
|
||||
|
||||
|
@ -190,7 +190,7 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__ /* this was missing from BeOS __MWERKS__, and probably others */
|
||||
#ifdef __GNUC__ /* this was missing from BeOS __MWERKS__, and probably others */
|
||||
# define HAS__FUNCTION__
|
||||
#endif
|
||||
|
||||
|
@ -207,7 +207,7 @@
|
|||
# define SYSTEM_DEFAULT_EOL "\n"
|
||||
#endif
|
||||
#ifndef MAX_PATH_LEN
|
||||
# define MAX_PATH_LEN 1024
|
||||
# define MAX_PATH_LEN 1024
|
||||
#endif
|
||||
|
||||
#endif /*__SysDefs__*/
|
||||
|
|
1188
nulib2/SysUtils.c
1188
nulib2/SysUtils.c
File diff suppressed because it is too large
Load Diff
|
@ -15,7 +15,7 @@ dnl Checks for header files.
|
|||
AC_HEADER_DIRENT
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(fcntl.h limits.h malloc.h stdlib.h strings.h sys/stat.h \
|
||||
sys/time.h sys/types.h unistd.h)
|
||||
sys/time.h sys/types.h unistd.h)
|
||||
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
|
@ -37,50 +37,50 @@ dnl BeOS doesn't like /usr/local/include, and gets feisty about it. If libdir
|
|||
dnl and includedir are set to defaults, replace them with BeOS values. This
|
||||
dnl might be going a little too far...
|
||||
if test "$host_os" = "beos"; then
|
||||
if test "$prefix" = "NONE" -a \
|
||||
"$includedir" = '${prefix}/include' -a \
|
||||
"$libdir" = '${exec_prefix}/lib' -a \
|
||||
"$bindir" = '${exec_prefix}/bin' -a \
|
||||
"$mandir" = '${prefix}/man'
|
||||
then
|
||||
echo replacing install locations with BeOS values
|
||||
prefix=/boot
|
||||
includedir='${prefix}/develop/headers'
|
||||
libdir='${exec_prefix}/home/config/lib'
|
||||
bindir='${exec_prefix}/home/config/bin'
|
||||
mandir='/tmp'
|
||||
AC_SUBST(prefix)
|
||||
AC_SUBST(includedir)
|
||||
AC_SUBST(libdir)
|
||||
AC_SUBST(bindir)
|
||||
AC_SUBST(mandir)
|
||||
fi
|
||||
if test "$prefix" = "NONE" -a \
|
||||
"$includedir" = '${prefix}/include' -a \
|
||||
"$libdir" = '${exec_prefix}/lib' -a \
|
||||
"$bindir" = '${exec_prefix}/bin' -a \
|
||||
"$mandir" = '${prefix}/man'
|
||||
then
|
||||
echo replacing install locations with BeOS values
|
||||
prefix=/boot
|
||||
includedir='${prefix}/develop/headers'
|
||||
libdir='${exec_prefix}/home/config/lib'
|
||||
bindir='${exec_prefix}/home/config/bin'
|
||||
mandir='/tmp'
|
||||
AC_SUBST(prefix)
|
||||
AC_SUBST(includedir)
|
||||
AC_SUBST(libdir)
|
||||
AC_SUBST(bindir)
|
||||
AC_SUBST(mandir)
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
dnl Figure out what the build and link flags should be
|
||||
if test "$host_cpu" = "powerpc" -a "$host_os" = "beos"; then
|
||||
dnl BeOS/PPC with Metrowerks compiler
|
||||
CC=cc
|
||||
GCC=
|
||||
CFLAGS='-proc 603 -opt full'
|
||||
echo "forcing CC to \"$CC\" and CFLAGS to \"$CFLAGS\""
|
||||
dnl BeOS/PPC with Metrowerks compiler
|
||||
CC=cc
|
||||
GCC=
|
||||
CFLAGS='-proc 603 -opt full'
|
||||
echo "forcing CC to \"$CC\" and CFLAGS to \"$CFLAGS\""
|
||||
fi
|
||||
|
||||
dnl if we're using gcc, include gcc-specific warning flags
|
||||
dnl (
|
||||
if test -z "$GCC"; then
|
||||
BUILD_FLAGS='$(OPT)'
|
||||
BUILD_FLAGS='$(OPT)'
|
||||
else
|
||||
BUILD_FLAGS='$(OPT) $(GCC_FLAGS)'
|
||||
BUILD_FLAGS='$(OPT) $(GCC_FLAGS)'
|
||||
fi
|
||||
|
||||
AC_SUBST(BUILD_FLAGS)
|
||||
|
||||
DMALLOC=
|
||||
AC_ARG_ENABLE(dmalloc, [ --enable-dmalloc: do dmalloc stuff], \
|
||||
[ echo "--- enabling dmalloc";
|
||||
DMALLOC="-L/usr/local/lib -ldmalloc"; AC_DEFINE(USE_DMALLOC) ])
|
||||
[ echo "--- enabling dmalloc";
|
||||
DMALLOC="-L/usr/local/lib -ldmalloc"; AC_DEFINE(USE_DMALLOC) ])
|
||||
AC_SUBST(DMALLOC)
|
||||
|
||||
AC_OUTPUT(Makefile)
|
||||
|
|
Loading…
Reference in New Issue