├── nulib2 ├── .gitignore ├── README-Win32.txt ├── mkinstalldirs ├── Delete.c ├── Makefile.msc ├── MiscStuff.h ├── config.h.in ├── Add.c ├── MiscStuff.c ├── MiscUtils.c ├── NuLib2.h ├── Makefile.in ├── SysDefs.h ├── configure.in ├── Extract.c ├── README.txt ├── install-sh ├── State.h ├── nulib2-man.txt ├── nulib2.1 ├── ChangeLog.txt └── INSTALL ├── .gitignore ├── nufxlib ├── nufxlib.pc.in ├── .gitignore ├── mkinstalldirs ├── Version.c ├── samples │ ├── Common.h │ ├── Makefile.in │ ├── TestSimple.c │ ├── Makefile.msc │ └── README-S.txt ├── nufxlib.def ├── MiscStuff.h ├── MiscStuff.c ├── SysDefs.h ├── config.h.in ├── README.txt ├── Makefile.in ├── Crc16.c ├── Makefile.msc ├── install-sh ├── Expand.c ├── configure.in ├── INSTALL ├── Deflate.c ├── Bzip2.c └── Value.c ├── README.md └── LICENSE /nulib2/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | config.h 3 | config.log 4 | config.status 5 | nulib2 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | autom4te.cache 2 | *.o 3 | *.obj 4 | *.a 5 | *.lib 6 | *.dll 7 | *.exe 8 | *.exp 9 | *.pdb 10 | *~ 11 | *.swp 12 | tags 13 | -------------------------------------------------------------------------------- /nufxlib/nufxlib.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: nufxlib 7 | Description: NuFX archive manipulation library. 8 | Version: @NUFX_VERSION@ 9 | Libs: -L${libdir} -lnufx @LIBS@ 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /nufxlib/.gitignore: -------------------------------------------------------------------------------- 1 | # config-generated sources 2 | Makefile 3 | config.h 4 | config.log 5 | config.status 6 | nufxlib.pc 7 | 8 | # generated binaries 9 | libnufx.a 10 | samples/exerciser 11 | samples/imgconv 12 | samples/launder 13 | samples/test-basic 14 | samples/test-extract 15 | samples/test-names 16 | samples/test-simple 17 | samples/test-twirl 18 | -------------------------------------------------------------------------------- /nulib2/README-Win32.txt: -------------------------------------------------------------------------------- 1 | This archive contains the NuLib2 exe for Win32, plus the sample 2 | applications from the NufxLib distribution. These were built with 3 | assertions and extended tests enabled, which adds a little bit to the 4 | file size and reduces the performance somewhat, but it catches errors 5 | earlier and makes the failure messages more useful. 6 | 7 | The latest versions will always be available from http://www.nulib.com/. 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NuLib2 2 | ====== 3 | 4 | NuLib2 is a command-line file archiver for Apple II archives. It can 5 | operate on ShrinkIt and Binary II files (.shk, .sdk, .bxy, .bse, .bny, .bqy). 6 | 7 | NufxLib is a library of code that supports ShrinkIt archives. It's 8 | used by NuLib2 and CiderPress. 9 | 10 | A pre-built NuLib2 binary is available for x86 Windows. For Linux and 11 | Mac OS X systems, you can download the source code and build it. 12 | 13 | More information, including full documentation for NuLib2 and NufxLib, 14 | can be found on https://nulib.com/ (or https://fadden.github.io/nulib2). 15 | -------------------------------------------------------------------------------- /nulib2/mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | # Author: Noah Friedman 4 | # Created: 1993-05-16 5 | # Last modified: 1995-03-05 6 | # Public domain 7 | 8 | errstatus=0 9 | 10 | for file in ${1+"$@"} ; do 11 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 12 | shift 13 | 14 | pathcomp= 15 | for d in ${1+"$@"} ; do 16 | pathcomp="$pathcomp$d" 17 | case "$pathcomp" in 18 | -* ) pathcomp=./$pathcomp ;; 19 | esac 20 | 21 | if test ! -d "$pathcomp"; then 22 | echo "mkdir $pathcomp" 1>&2 23 | mkdir "$pathcomp" > /dev/null 2>&1 || lasterr=$? 24 | fi 25 | 26 | if test ! -d "$pathcomp"; then 27 | errstatus=$lasterr 28 | fi 29 | 30 | pathcomp="$pathcomp/" 31 | done 32 | done 33 | 34 | exit $errstatus 35 | -------------------------------------------------------------------------------- /nufxlib/mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | # Author: Noah Friedman 4 | # Created: 1993-05-16 5 | # Last modified: 1995-03-05 6 | # Public domain 7 | 8 | errstatus=0 9 | 10 | for file in ${1+"$@"} ; do 11 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 12 | shift 13 | 14 | pathcomp= 15 | for d in ${1+"$@"} ; do 16 | pathcomp="$pathcomp$d" 17 | case "$pathcomp" in 18 | -* ) pathcomp=./$pathcomp ;; 19 | esac 20 | 21 | if test ! -d "$pathcomp"; then 22 | echo "mkdir $pathcomp" 1>&2 23 | mkdir "$pathcomp" > /dev/null 2>&1 || lasterr=$? 24 | fi 25 | 26 | if test ! -d "$pathcomp"; then 27 | errstatus=$lasterr 28 | fi 29 | 30 | pathcomp="$pathcomp/" 31 | done 32 | done 33 | 34 | exit $errstatus 35 | -------------------------------------------------------------------------------- /nulib2/Delete.c: -------------------------------------------------------------------------------- 1 | /* 2 | * NuLib2 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING. 6 | * 7 | * Delete files from the archive. 8 | */ 9 | #include "NuLib2.h" 10 | 11 | 12 | /* 13 | * Delete the specified files. 14 | * 15 | * This uses the "bulk" delete call, allowing the SelectionFilter callback 16 | * to do the matching against specified filenames. 17 | */ 18 | NuError DoDelete(NulibState* pState) 19 | { 20 | NuError err; 21 | NuArchive* pArchive = NULL; 22 | 23 | Assert(pState != NULL); 24 | 25 | err = OpenArchiveReadWrite(pState); 26 | if (err != kNuErrNone) 27 | goto bail; 28 | pArchive = NState_GetNuArchive(pState); 29 | Assert(pArchive != NULL); 30 | 31 | NState_SetMatchCount(pState, 0); 32 | 33 | err = NuDelete(pArchive); 34 | if (err != kNuErrNone) 35 | goto bail; 36 | 37 | if (!NState_GetMatchCount(pState)) 38 | printf("%s: no records matched\n", gProgName); 39 | 40 | bail: 41 | if (pArchive != NULL) 42 | (void) NuClose(pArchive); 43 | return err; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /nufxlib/Version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * NuFX archive manipulation library 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING-LIB. 6 | */ 7 | #include "NufxLibPriv.h" 8 | 9 | /* executable was build on or after this date */ 10 | #ifdef __DATE__ 11 | static const char gNuBuildDate[] = __DATE__; 12 | #else 13 | static const char gNuBuildDate[] = "??? ?? ????"; 14 | #endif 15 | 16 | #ifdef OPTFLAGSTR 17 | static const char gNuBuildFlags[] = OPTFLAGSTR; 18 | #else 19 | static const char gNuBuildFlags[] = "-"; 20 | #endif 21 | 22 | 23 | /* 24 | * Return the version number, date built, and build flags. 25 | */ 26 | NuError Nu_GetVersion(int32_t* pMajorVersion, int32_t* pMinorVersion, 27 | int32_t* pBugVersion, const char** ppBuildDate, const char** ppBuildFlags) 28 | { 29 | if (pMajorVersion != NULL) 30 | *pMajorVersion = kNuVersionMajor; 31 | if (pMinorVersion != NULL) 32 | *pMinorVersion = kNuVersionMinor; 33 | if (pBugVersion != NULL) 34 | *pBugVersion = kNuVersionBug; 35 | if (ppBuildDate != NULL) 36 | *ppBuildDate = gNuBuildDate; 37 | if (ppBuildFlags != NULL) 38 | *ppBuildFlags = gNuBuildFlags; 39 | return kNuErrNone; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2007, Andy McFadden. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the copyright holder nor the names of project 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 22 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 23 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | -------------------------------------------------------------------------------- /nufxlib/samples/Common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NuFX archive manipulation library 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING.LIB. 6 | * 7 | * Common functions for NuLib tests. 8 | */ 9 | #ifndef NUFXLIB_SAMPLES_COMMON_H 10 | #define NUFXLIB_SAMPLES_COMMON_H 11 | 12 | #include "SysDefs.h" /* might as well draft off the autoconf */ 13 | #include "NufxLib.h" 14 | 15 | #ifdef USE_DMALLOC 16 | # include "dmalloc.h" 17 | #endif 18 | 19 | #define NELEM(x) (sizeof(x) / sizeof((x)[0])) 20 | 21 | #ifndef __cplusplus 22 | #define false 0 23 | #define true (!false) 24 | #endif 25 | 26 | 27 | #ifdef FOPEN_WANTS_B 28 | # define kNuFileOpenReadOnly "rb" 29 | # define kNuFileOpenReadWrite "r+b" 30 | # define kNuFileOpenWriteTrunc "wb" 31 | # define kNuFileOpenReadWriteCreat "w+b" 32 | #else 33 | # define kNuFileOpenReadOnly "r" 34 | # define kNuFileOpenReadWrite "r+" 35 | # define kNuFileOpenWriteTrunc "w" 36 | # define kNuFileOpenReadWriteCreat "w+" 37 | #endif 38 | 39 | 40 | /* 41 | * Figure out what path separator to use. 42 | * 43 | * NOTE: recent versions of Win32 will also accept '/'. 44 | */ 45 | 46 | #ifdef MSDOS 47 | # define PATH_SEP '\\' 48 | #endif 49 | 50 | #ifdef WIN32 51 | # define PATH_SEP '\\' 52 | #endif 53 | 54 | #ifdef MACOS 55 | # define PATH_SEP ':' 56 | #endif 57 | 58 | #if defined(APW) || defined(__ORCAC__) 59 | # define PATH_SEP ':' 60 | #endif 61 | 62 | #ifndef PATH_SEP 63 | # define PATH_SEP '/' 64 | #endif 65 | 66 | #endif /*NUFXLIB_SAMPLES_COMMON_H*/ 67 | -------------------------------------------------------------------------------- /nufxlib/nufxlib.def: -------------------------------------------------------------------------------- 1 | ; NufxLib library exported symbols 2 | ; 3 | ; This is redundant with the __declspec(dllexport) declarations enabled 4 | ; with the NUFXLIB_EXPORTS symbol. If we're just building a DLL, there's 5 | ; no need for this file. However, the objects we're building are used for 6 | ; both the static library and the dynamic library, and we don't want to 7 | ; have exports in the static library. If we do, the linker will create 8 | ; .lib and .exp files for every executable we link against it. This is 9 | ; mostly harmless, but a tad messy. I don't expect the interface to change, 10 | ; so there's not much of a maintenance burden here. 11 | ; 12 | EXPORTS 13 | NuAbort 14 | NuAddFile 15 | NuAddRecord 16 | NuAddThread 17 | NuClose 18 | NuContents 19 | NuConvertMORToUNI 20 | NuConvertUNIToMOR 21 | NuCreateDataSinkForBuffer 22 | NuCreateDataSinkForFP 23 | NuCreateDataSinkForFile 24 | NuCreateDataSourceForBuffer 25 | NuCreateDataSourceForFP 26 | NuCreateDataSourceForFile 27 | NuDataSinkGetOutCount 28 | NuDataSourceSetRawCrc 29 | NuDebugDumpArchive 30 | NuDelete 31 | NuDeleteRecord 32 | NuDeleteThread 33 | NuExtract 34 | NuExtractRecord 35 | NuExtractThread 36 | NuFlush 37 | NuFreeDataSink 38 | NuFreeDataSource 39 | NuGetAttr 40 | NuGetExtraData 41 | NuGetMasterHeader 42 | NuGetRecord 43 | NuGetRecordIdxByName 44 | NuGetRecordIdxByPosition 45 | NuGetValue 46 | NuGetVersion 47 | NuIsPresizedThreadID 48 | NuOpenRO 49 | NuOpenRW 50 | NuRecordCopyAttr 51 | NuRecordCopyThreads 52 | NuRecordGetNumThreads 53 | NuRename 54 | NuSetErrorHandler 55 | NuSetErrorMessageHandler 56 | NuSetExtraData 57 | NuSetGlobalErrorMessageHandler 58 | NuSetOutputPathnameFilter 59 | NuSetProgressUpdater 60 | NuSetRecordAttr 61 | NuSetSelectionFilter 62 | NuSetValue 63 | NuStrError 64 | NuStreamOpenRO 65 | NuTest 66 | NuTestFeature 67 | NuTestRecord 68 | NuThreadGetByIdx 69 | NuUpdatePresizedThread 70 | -------------------------------------------------------------------------------- /nulib2/Makefile.msc: -------------------------------------------------------------------------------- 1 | # Makefile for NuLib2 using Microsoft Visual C++. 2 | # 3 | # Tested with VS 2013 Pro. From the "VS2013 x86 Native Tools Command 4 | # Prompt", run "nmake -f makefile.msc". 5 | # 6 | # If you're including zlib support, place a copy of the zlib 7 | # library in this directory. 8 | # 9 | 10 | TOP = . 11 | NUFXSRCDIR = ..\nufxlib 12 | NUFXLIB = $(NUFXSRCDIR)\nufxlib2.lib 13 | 14 | PRODUCT = nulib2.exe 15 | 16 | CC = cl 17 | LD = link 18 | 19 | # C compiler flags 20 | # -Ox: full optimization 21 | # -Oy-: disable frame pointer omission (for easier debugging) 22 | # -MD: create a multithreaded DLL using MSVCRT.lib; alternatively, 23 | # use -MDd to create a debug executable with MSVCRTD.lib 24 | # -nologo: suppress display of copyright banner 25 | # -W3: set warning level to 3 (all production-level warnings) 26 | # -Zi: generate a PDB file with full debugging info 27 | CFLAGS = -nologo -MD -W3 -Ox -Oy- -Zi "-I$(NUFXSRCDIR)" 28 | 29 | # Warning suppression flags 30 | WFLAGS = -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE 31 | 32 | # Linker flags 33 | # -debug: creates debugging info for EXE or DLL in PDB file 34 | # -nologo: suppress display of copyright banner 35 | # -opt:ref: eliminates unreferenced functions and data (default for non-debug 36 | # builds, but we've enabled debug info) 37 | LDFLAGS = -nologo -debug -opt:ref 38 | 39 | 40 | ZLIB=1 41 | !ifdef ZLIB 42 | # enable deflate support; requires zlib 43 | LDFLAGS = $(LDFLAGS) zlib.lib 44 | !endif 45 | 46 | 47 | # object files 48 | OBJS = Add.obj ArcUtils.obj Binary2.obj Delete.obj Extract.obj Filename.obj \ 49 | List.obj Main.obj MiscStuff.obj MiscUtils.obj State.obj SysUtils.obj 50 | 51 | 52 | # build targets 53 | all: $(PRODUCT) 54 | 55 | $(PRODUCT): $(OBJS) $(NUFXLIB) 56 | $(LD) $(LDFLAGS) -out:$@ $(OBJS) $(NUFXLIB) 57 | 58 | clean: 59 | -del *.obj *.pdb *.exp 60 | -del $(PRODUCT) 61 | 62 | # generic rules 63 | .c.obj: 64 | $(CC) -c $(WFLAGS) $(CFLAGS) $< 65 | 66 | # dependency info 67 | COMMON_HDRS = NuLib2.h $(NUFXSRCDIR)\NufxLib.h SysDefs.h State.h MiscStuff.h 68 | Add.obj: Add.c $(COMMON_HDRS) 69 | ArcUtils.obj: ArcUtils.c $(COMMON_HDRS) 70 | Binary2.obj: Binary2.c $(COMMON_HDRS) 71 | Delete.obj: Delete.c $(COMMON_HDRS) 72 | Extract.obj: Extract.c $(COMMON_HDRS) 73 | Filename.obj: Filename.c $(COMMON_HDRS) 74 | List.obj: List.c $(COMMON_HDRS) 75 | Main.obj: Main.c $(COMMON_HDRS) 76 | MiscStuff.obj: MiscStuff.c $(COMMON_HDRS) 77 | MiscUtils.obj: MiscUtils.c $(COMMON_HDRS) 78 | State.obj: State.c $(COMMON_HDRS) 79 | SysUtils.obj: SysUtils.c $(COMMON_HDRS) 80 | 81 | -------------------------------------------------------------------------------- /nufxlib/samples/Makefile.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 3 | # This is free software; you can redistribute it and/or modify it under the 4 | # terms of the BSD, see the file COPYING. 5 | # 6 | # Makefile for nufxlib tests (should work with non-GNU make). 7 | # 8 | # This is normally invoked from the nufxlib makefile. 9 | # 10 | # If you invoke this directly, LIB_PRODUCT won't be defined, and it 11 | # won't automatically detect changes to the library. However, any 12 | # changes to the library should cause a re-build in here anyway if 13 | # you're running "make" from the library directory. 14 | # 15 | SHELL = /bin/sh 16 | CC = @CC@ 17 | AR = ar rcv 18 | #OPT = @CFLAGS@ -DNDEBUG 19 | OPT = @CFLAGS@ 20 | #OPT = @CFLAGS@ -DDEBUG_MSGS 21 | #OPT = @CFLAGS@ -DDEBUG_VERBOSE 22 | GCC_FLAGS = -Wall -Wwrite-strings -Wstrict-prototypes -Wpointer-arith -Wshadow 23 | CFLAGS = @BUILD_FLAGS@ -I. -I.. @DEFS@ 24 | 25 | #ALL_SRCS = $(wildcard *.c *.cpp) 26 | ALL_SRCS = Exerciser.c ImgConv.c Launder.c TestBasic.c \ 27 | TestExtract.c TestSimple.c TestTwirl.c 28 | 29 | NUFXLIB = -L.. -lnufx 30 | 31 | PRODUCTS = exerciser imgconv launder test-basic test-extract test-names \ 32 | test-simple test-twirl 33 | 34 | all: $(PRODUCTS) 35 | @true 36 | 37 | exerciser: Exerciser.o $(LIB_PRODUCT) 38 | $(CC) -o $@ Exerciser.o $(NUFXLIB) @LIBS@ 39 | 40 | imgconv: ImgConv.o $(LIB_PRODUCT) 41 | $(CC) -o $@ ImgConv.o $(NUFXLIB) @LIBS@ 42 | 43 | launder: Launder.o $(LIB_PRODUCT) 44 | $(CC) -o $@ Launder.o $(NUFXLIB) @LIBS@ 45 | 46 | test-basic: TestBasic.o $(LIB_PRODUCT) 47 | $(CC) -o $@ TestBasic.o $(NUFXLIB) @LIBS@ 48 | 49 | test-extract: TestExtract.o $(LIB_PRODUCT) 50 | $(CC) -o $@ TestExtract.o $(NUFXLIB) @LIBS@ 51 | 52 | test-names: TestNames.o $(LIB_PRODUCT) 53 | $(CC) -o $@ TestNames.o $(NUFXLIB) @LIBS@ 54 | 55 | test-simple: TestSimple.o $(LIB_PRODUCT) 56 | $(CC) -o $@ TestSimple.o $(NUFXLIB) @LIBS@ 57 | 58 | test-twirl: TestTwirl.o $(LIB_PRODUCT) 59 | $(CC) -o $@ TestTwirl.o $(NUFXLIB) @LIBS@ 60 | 61 | tags:: 62 | ctags --totals -R ../* 63 | @#ctags *.cpp ../*.c *.h ../*.h 64 | 65 | clean: 66 | -rm -f *.o core 67 | -rm -f $(PRODUCTS) 68 | 69 | distclean: clean 70 | -rm -f tags 71 | -rm -f Makefile Makefile.bak 72 | 73 | COMMON_HDRS = ../NufxLibPriv.h ../NufxLib.h ../MiscStuff.h ../SysDefs.h 74 | Exerciser.o: Exerciser.c $(COMMON_HDRS) 75 | ImgConv.o: ImgConv.c $(COMMON_HDRS) 76 | Launder.o: Launder.c $(COMMON_HDRS) 77 | TestBasic.o: TestBasic.c $(COMMON_HDRS) 78 | TestExtract.o: TestExtract.c $(COMMON_HDRS) 79 | TestNames.o: TestNames.c $(COMMON_HDRS) 80 | TestSimple.o: TestSimple.c $(COMMON_HDRS) 81 | TestTwirl.o: TestTwirl.c $(COMMON_HDRS) 82 | -------------------------------------------------------------------------------- /nulib2/MiscStuff.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 3 | * This is free software; you can redistribute it and/or modify it under the 4 | * terms of the BSD License, see the file COPYING-LIB. 5 | * 6 | * Misc stuff (shared between nufxlib and nulib2). This is a collection 7 | * of miscellaneous types and macros that I find generally useful. 8 | */ 9 | #ifndef NULIB2_MISCSTUFF_H 10 | #define NULIB2_MISCSTUFF_H 11 | 12 | #define VALGRIND /* assume we're using it */ 13 | 14 | #include "SysDefs.h" 15 | 16 | /* 17 | * Use our versions of functions if they don't exist locally. 18 | */ 19 | #ifndef HAVE_STRERROR 20 | #define strerror Nu_strerror 21 | const char* Nu_strerror(int errnum); 22 | #endif 23 | #ifndef HAVE_MEMMOVE 24 | #define memmove Nu_memmove 25 | void* Nu_memmove(void *dest, const void *src, size_t n); 26 | #endif 27 | #ifndef HAVE_STRTOUL 28 | #define strtoul Nu_strtoul 29 | unsigned long Nu_strtoul(const char *nptr, char **endptr, int base); 30 | #endif 31 | #ifndef HAVE_STRCASECMP 32 | #define strcasecmp Nu_strcasecmp 33 | int Nu_strcasecmp(const char *s1, const char *s2); 34 | #endif 35 | #ifndef HAVE_STRNCASECMP 36 | #define strncasecmp Nu_strncasecmp 37 | int Nu_strncasecmp(const char *s1, const char *s2, size_t n); 38 | #endif 39 | 40 | 41 | /* 42 | * Misc types. 43 | */ 44 | 45 | typedef unsigned char Boolean; 46 | #define false (0) 47 | #define true (!false) 48 | 49 | 50 | /* 51 | * Handy macros. 52 | */ 53 | 54 | /* compute #of elements in a static array */ 55 | #define NELEM(x) (sizeof(x) / sizeof((x)[0])) 56 | 57 | /* convert single hex digit char to number */ 58 | #define HexDigit(x) ( !isxdigit((int)(x)) ? -1 : \ 59 | (x) <= '9' ? (x) - '0' : toupper(x) +10 - 'A' ) 60 | 61 | /* convert number from 0-15 to hex digit */ 62 | #define HexConv(x) ( ((unsigned int)(x)) <= 15 ? \ 63 | ( (x) <= 9 ? (x) + '0' : (x) -10 + 'A') : -1 ) 64 | 65 | 66 | /* 67 | * Debug stuff. 68 | */ 69 | 70 | /* 71 | * Redefine this if you want assertions to do something other than default. 72 | * Changing the definition of assert is tough, because assert.h redefines 73 | * it every time it's included. On a Solaris 2.7 system I was using, gcc 74 | * pulled assert.h in with some of the system headers, and their definition 75 | * resulted in corrupted core dumps. 76 | */ 77 | #define Assert assert 78 | 79 | #if defined(DEBUG_VERBOSE) 80 | /* quick debug printf macro */ 81 | #define DBUG(args) printf args 82 | #else 83 | #define DBUG(args) ((void)0) 84 | #endif 85 | 86 | 87 | #if defined(NDEBUG) 88 | #define DebugFill(addr, len) ((void)0) 89 | 90 | #define DebugAbort() ((void)0) 91 | 92 | #else 93 | /* when debugging, fill Malloc blocks with junk, unless we're using Purify */ 94 | #if !defined(PURIFY) && !defined(VALGRIND) 95 | #define DebugFill(addr, len) memset(addr, 0xa3, len) 96 | #else 97 | #define DebugFill(addr, len) ((void)0) 98 | #endif 99 | 100 | #define DebugAbort() abort() 101 | #endif 102 | 103 | #define kInvalidPtr ((void*)0xa3a3a3a3) 104 | 105 | #endif /*NULIB2_MISCSTUFF_H*/ 106 | -------------------------------------------------------------------------------- /nufxlib/MiscStuff.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 3 | * This is free software; you can redistribute it and/or modify it under the 4 | * terms of the BSD License, see the file COPYING-LIB. 5 | * 6 | * Misc stuff (shared between nufxlib and nulib2). This is a collection 7 | * of miscellaneous types and macros that I find generally useful. 8 | */ 9 | #ifndef NUFXLIB_MISCSTUFF_H 10 | #define NUFXLIB_MISCSTUFF_H 11 | 12 | #define VALGRIND /* assume we're using it */ 13 | 14 | #include "SysDefs.h" 15 | 16 | /* 17 | * Use our versions of functions if they don't exist locally. 18 | */ 19 | #ifndef HAVE_STRERROR 20 | #define strerror Nu_strerror 21 | const char* Nu_strerror(int errnum); 22 | #endif 23 | #ifndef HAVE_MEMMOVE 24 | #define memmove Nu_memmove 25 | void* Nu_memmove(void *dest, const void *src, size_t n); 26 | #endif 27 | #ifndef HAVE_STRTOUL 28 | #define strtoul Nu_strtoul 29 | unsigned long Nu_strtoul(const char *nptr, char **endptr, int base); 30 | #endif 31 | #ifndef HAVE_STRCASECMP 32 | #define strcasecmp Nu_strcasecmp 33 | int Nu_strcasecmp(const char *s1, const char *s2); 34 | #endif 35 | #ifndef HAVE_STRNCASECMP 36 | #define strncasecmp Nu_strncasecmp 37 | int Nu_strncasecmp(const char *s1, const char *s2, size_t n); 38 | #endif 39 | 40 | 41 | /* 42 | * Misc types. 43 | */ 44 | 45 | typedef unsigned char Boolean; 46 | #define false (0) 47 | #define true (!false) 48 | 49 | 50 | /* 51 | * Handy macros. 52 | */ 53 | 54 | /* compute #of elements in a static array */ 55 | #define NELEM(x) (sizeof(x) / sizeof((x)[0])) 56 | 57 | /* convert single hex digit char to number */ 58 | #define HexDigit(x) ( !isxdigit((int)(x)) ? -1 : \ 59 | (x) <= '9' ? (x) - '0' : toupper(x) +10 - 'A' ) 60 | 61 | /* convert number from 0-15 to hex digit */ 62 | #define HexConv(x) ( ((unsigned int)(x)) <= 15 ? \ 63 | ( (x) <= 9 ? (x) + '0' : (x) -10 + 'A') : -1 ) 64 | 65 | 66 | /* 67 | * Debug stuff. 68 | */ 69 | 70 | /* 71 | * Redefine this if you want assertions to do something other than default. 72 | * Changing the definition of assert is tough, because assert.h redefines 73 | * it every time it's included. On a Solaris 2.7 system I was using, gcc 74 | * pulled assert.h in with some of the system headers, and their definition 75 | * resulted in corrupted core dumps. 76 | */ 77 | #define Assert assert 78 | 79 | #if defined(DEBUG_VERBOSE) 80 | /* quick debug printf macro */ 81 | #define DBUG(args) printf args 82 | #else 83 | #define DBUG(args) ((void)0) 84 | #endif 85 | 86 | 87 | #if defined(NDEBUG) 88 | #define DebugFill(addr, len) ((void)0) 89 | 90 | #define DebugAbort() ((void)0) 91 | 92 | #else 93 | /* when debugging, fill Malloc blocks with junk, unless we're using Purify */ 94 | #if !defined(PURIFY) && !defined(VALGRIND) 95 | #define DebugFill(addr, len) memset(addr, 0xa3, len) 96 | #else 97 | #define DebugFill(addr, len) ((void)0) 98 | #endif 99 | 100 | #define DebugAbort() abort() 101 | #endif 102 | 103 | #define kInvalidPtr ((void*)0xa3a3a3a3) 104 | 105 | #endif /*NUFXLIB_MISCSTUFF_H*/ 106 | -------------------------------------------------------------------------------- /nulib2/config.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Nulib2 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING. 6 | * 7 | */ 8 | /* config.h.in. Generated automatically from configure.in by autoheader. */ 9 | 10 | /* Define to empty if the keyword does not work. */ 11 | #undef const 12 | 13 | /* Define if utime(file, NULL) sets file's timestamp to the present. */ 14 | #undef HAVE_UTIME_NULL 15 | 16 | /* Define to `int' if doesn't define. */ 17 | #undef mode_t 18 | 19 | /* Define to `long' if doesn't define. */ 20 | #undef off_t 21 | 22 | /* Define if the setvbuf function takes the buffering type as its second 23 | argument and the buffer pointer as the third, as on System V 24 | before release 3. */ 25 | #undef SETVBUF_REVERSED 26 | 27 | /* Define to `unsigned' if doesn't define. */ 28 | #undef size_t 29 | 30 | /* Define if you have the ANSI C header files. */ 31 | #undef STDC_HEADERS 32 | 33 | /* Define if your declares struct tm. */ 34 | #undef TM_IN_SYS_TIME 35 | 36 | /* Define to `int' if doesn't define. */ 37 | #undef mode_t 38 | 39 | /* Define to `long' if doesn't define. */ 40 | #undef off_t 41 | 42 | /* Define to `unsigned' if doesn't define. */ 43 | #undef size_t 44 | 45 | /* Define if you have the memmove function. */ 46 | #undef HAVE_MEMMOVE 47 | 48 | /* Define if you have the mkdir function. */ 49 | #undef HAVE_MKDIR 50 | 51 | /* Define if you have the strcasecmp function. */ 52 | #undef HAVE_STRCASECMP 53 | 54 | /* Define if you have the strncasecmp function. */ 55 | #undef HAVE_STRNCASECMP 56 | 57 | /* Define if you have the strerror function. */ 58 | #undef HAVE_STRERROR 59 | 60 | /* Define if you have the strtoul function. */ 61 | #undef HAVE_STRTOUL 62 | 63 | /* Define if you have the header file. */ 64 | #undef HAVE_DIRENT_H 65 | 66 | /* Define if you have the header file. */ 67 | #undef HAVE_FCNTL_H 68 | 69 | /* Define if you have the header file. */ 70 | #undef HAVE_LIMITS_H 71 | 72 | /* Define if you have the header file. */ 73 | #undef HAVE_MALLOC_H 74 | 75 | /* Define if you have the header file. */ 76 | #undef HAVE_STDLIB_H 77 | 78 | /* Define if you have the header file. */ 79 | #undef HAVE_NDIR_H 80 | 81 | /* Define if you have the header file. */ 82 | #undef HAVE_STRINGS_H 83 | 84 | /* Define if you have the header file. */ 85 | #undef HAVE_SYS_DIR_H 86 | 87 | /* Define if you have the header file. */ 88 | #undef HAVE_SYS_NDIR_H 89 | 90 | /* Define if you have the header file. */ 91 | #undef HAVE_SYS_STAT_H 92 | 93 | /* Define if you have the header file. */ 94 | #undef HAVE_SYS_TIME_H 95 | 96 | /* Define if you have the header file. */ 97 | #undef HAVE_SYS_TYPES_H 98 | 99 | /* Define if you have the header file. */ 100 | #undef HAVE_UNISTD_H 101 | 102 | /* Define if we want to use the dmalloc library (--enable-dmalloc). */ 103 | #undef USE_DMALLOC 104 | 105 | -------------------------------------------------------------------------------- /nulib2/Add.c: -------------------------------------------------------------------------------- 1 | /* 2 | * NuLib2 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING. 6 | * 7 | * Add files to or update files in the archive. 8 | */ 9 | #include "NuLib2.h" 10 | 11 | static NuError AddToArchive(NulibState* pState, NuArchive* pArchive); 12 | 13 | 14 | /* 15 | * Add the specified files to a new or existing archive. 16 | */ 17 | NuError DoAdd(NulibState* pState) 18 | { 19 | NuError err; 20 | NuArchive* pArchive = NULL; 21 | uint32_t flushStatus; 22 | 23 | Assert(pState != NULL); 24 | 25 | err = OpenArchiveReadWrite(pState); 26 | if (err != kNuErrNone) 27 | goto bail; 28 | 29 | pArchive = NState_GetNuArchive(pState); 30 | Assert(pArchive != NULL); 31 | 32 | NState_SetMatchCount(pState, 0); 33 | 34 | /* tell them about the list of files */ 35 | err = AddToArchive(pState, pArchive); 36 | if (err != kNuErrNone) 37 | goto bail; 38 | 39 | /*(void)NuDebugDumpArchive(pArchive);*/ 40 | 41 | if (!NState_GetMatchCount(pState)) 42 | printf("%s: no records matched\n", gProgName); 43 | 44 | bail: 45 | if (pArchive != NULL) { 46 | NuError err2; 47 | 48 | #if 0 49 | if (err != kNuErrNone) { 50 | printf("Attempting to flush changes in spite of errors...\n"); 51 | err = kNuErrNone; 52 | } 53 | #endif 54 | 55 | if (err == kNuErrNone) { 56 | err = NuFlush(pArchive, &flushStatus); 57 | if (err != kNuErrNone) { 58 | if (flushStatus & kNuFlushSucceeded) { 59 | ReportError(err, 60 | "Changes were successfully written, but something " 61 | "failed afterward"); 62 | } else { 63 | ReportError(err, 64 | "Unable to flush archive changes (status=0x%04x)", 65 | flushStatus); 66 | } 67 | NuAbort(pArchive); 68 | } 69 | } else { 70 | NuAbort(pArchive); 71 | } 72 | 73 | err2 = NuClose(pArchive); 74 | Assert(err2 == kNuErrNone); 75 | } 76 | return err; 77 | } 78 | 79 | 80 | /* 81 | * Add the requested files to the specified archive. 82 | * 83 | * This just results in NuAddFile calls; the deferred write operation 84 | * isn't initiated. 85 | */ 86 | static NuError AddToArchive(NulibState* pState, NuArchive* pArchive) 87 | { 88 | NuError err = kNuErrNone; 89 | char* const* pSpec; 90 | int i; 91 | 92 | Assert(pState != NULL); 93 | Assert(pArchive != NULL); 94 | 95 | if (!NState_GetFilespecCount(pState)) { 96 | err = kNuErrSyntax; 97 | ReportError(err, "no files were specified"); 98 | } 99 | 100 | pSpec = NState_GetFilespecPointer(pState); 101 | for (i = NState_GetFilespecCount(pState); i > 0; i--, pSpec++) { 102 | err = AddFile(pState, pArchive, *pSpec); 103 | if (err != kNuErrNone) 104 | goto bail; 105 | } 106 | 107 | bail: 108 | return err; 109 | } 110 | 111 | -------------------------------------------------------------------------------- /nufxlib/samples/TestSimple.c: -------------------------------------------------------------------------------- 1 | /* 2 | * NuFX archive manipulation library 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING.LIB. 6 | * 7 | * Simple test program. Opens an archive, dumps the contents. 8 | * 9 | * If the first argument is "-", this will read from stdin. Otherwise, 10 | * the first argument is taken to be an archive filename, and opened. 11 | */ 12 | #include 13 | #include "NufxLib.h" 14 | #include "Common.h" 15 | 16 | 17 | /* 18 | * Callback function to display the contents of a single record. 19 | * 20 | * "pRecord->filename" is the record's filename, whether from the record 21 | * header, a filename thread, or a default value ("UNKNOWN", stuffed in 22 | * when a record has no filename at all). 23 | */ 24 | NuResult ShowContents(NuArchive* pArchive, void* vpRecord) 25 | { 26 | const NuRecord* pRecord = (NuRecord*) vpRecord; 27 | 28 | size_t bufLen = NuConvertMORToUNI(pRecord->filenameMOR, NULL, 0); 29 | if (bufLen == (size_t) -1) { 30 | fprintf(stderr, "GLITCH: unable to convert '%s'\n", 31 | pRecord->filenameMOR); 32 | } else { 33 | UNICHAR* buf = (UNICHAR*) malloc(bufLen); 34 | NuConvertMORToUNI(pRecord->filenameMOR, buf, bufLen); 35 | printf("*** Filename = '%s'\n", buf); 36 | free(buf); 37 | } 38 | 39 | return kNuOK; 40 | } 41 | 42 | 43 | /* 44 | * Dump the contents from the streaming input. 45 | * 46 | * If we're not interested in handling an archive on stdin, we could just 47 | * pass the filename in here and use NuOpenRO instead. 48 | */ 49 | int DoStreamStuff(FILE* fp) 50 | { 51 | NuError err; 52 | NuArchive* pArchive = NULL; 53 | 54 | err = NuStreamOpenRO(fp, &pArchive); 55 | if (err != kNuErrNone) { 56 | fprintf(stderr, "ERROR: unable to open stream archive (err=%d)\n", err); 57 | goto bail; 58 | } 59 | 60 | printf("*** Streaming contents!\n"); 61 | 62 | err = NuContents(pArchive, ShowContents); 63 | if (err != kNuErrNone) { 64 | fprintf(stderr, "ERROR: NuContents failed (err=%d)\n", err); 65 | goto bail; 66 | } 67 | 68 | bail: 69 | if (pArchive != NULL) { 70 | NuError err2 = NuClose(pArchive); 71 | if (err == kNuErrNone) 72 | err = err2; 73 | } 74 | 75 | return err; 76 | } 77 | 78 | 79 | /* 80 | * Grab the name of an archive to read. If "-" was given, use stdin. 81 | */ 82 | int main(int argc, char** argv) 83 | { 84 | int32_t major, minor, bug; 85 | const char* pBuildDate; 86 | FILE* infp = NULL; 87 | int cc; 88 | 89 | (void) NuGetVersion(&major, &minor, &bug, &pBuildDate, NULL); 90 | printf("Using NuFX lib %d.%d.%d built on or after %s\n", 91 | major, minor, bug, pBuildDate); 92 | 93 | if (argc != 2) { 94 | fprintf(stderr, "Usage: %s (archive-name|-)\n", argv[0]); 95 | exit(2); 96 | } 97 | 98 | if (strcmp(argv[1], "-") == 0) 99 | infp = stdin; 100 | else { 101 | infp = fopen(argv[1], kNuFileOpenReadOnly); 102 | if (infp == NULL) { 103 | fprintf(stderr, "ERROR: unable to open '%s'\n", argv[1]); 104 | exit(1); 105 | } 106 | } 107 | 108 | cc = DoStreamStuff(infp); 109 | exit(cc != 0); 110 | } 111 | 112 | -------------------------------------------------------------------------------- /nulib2/MiscStuff.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 3 | * This is free software; you can redistribute it and/or modify it under the 4 | * terms of the BSD License, see the file COPYING-LIB. 5 | * 6 | * Misc stuff (shared between nufxlib and nulib2). This is a collection 7 | * of standard functions that aren't available in libc on this system. 8 | */ 9 | #include "SysDefs.h" 10 | #include "MiscStuff.h" 11 | #include 12 | 13 | 14 | #ifndef HAVE_STRERROR 15 | /* 16 | * Return a pointer to the appropriate string in the system table, or NULL 17 | * if the value is out of bounds. 18 | */ 19 | const char* Nu_strerror(int errnum) 20 | { 21 | extern int sys_nerr; 22 | extern char *sys_errlist[]; 23 | 24 | if (errnum < 0 || errnum > sys_nerr) 25 | return NULL; 26 | 27 | return sys_errlist[errnum]; 28 | } 29 | #endif 30 | 31 | #ifndef HAVE_MEMMOVE 32 | /* 33 | * Move a block of memory. Unlike memcpy, this is expected to work 34 | * correctly with overlapping blocks. 35 | * 36 | * This is a straightforward implementation. A much faster implementation, 37 | * from BSD, is available in the PGP 2.6.2 distribution, but this should 38 | * suffice for those few systems that don't have memmove. 39 | */ 40 | void* Nu_memmove(void* dst, const void* src, size_t n) 41 | { 42 | void* retval = dst; 43 | char* srcp = (char*)src; 44 | char* dstp = (char*)dst; 45 | 46 | /* you can normally get away with this if n==0 */ 47 | Assert(dst != NULL); 48 | Assert(src != NULL); 49 | 50 | if (dstp == srcp || !n) { 51 | /* nothing to do */ 52 | } else if (dstp > srcp) { 53 | /* start from the end */ 54 | (char*)dstp += n-1; 55 | (char*)srcp += n-1; 56 | while (n--) 57 | *dstp-- = *srcp--; 58 | } else { 59 | /* start from the front */ 60 | while (n--) 61 | *dstp++ = *srcp++; 62 | } 63 | 64 | return retval; 65 | } 66 | #endif 67 | 68 | #ifndef HAVE_STRTOUL 69 | /* 70 | * Perform strtol, but on an unsigned long. 71 | * 72 | * On systems that have strtol but don't have strtoul, the strtol 73 | * function doesn't clamp the return value, making it similar in 74 | * function to strtoul. The comparison is not exact, however, 75 | * because strtoul is expected to lots of fancy things (like set 76 | * errno to ERANGE). 77 | * 78 | * For our purposes here, strtol does all we need it to. Someday 79 | * we should replace this with a "real" version. 80 | */ 81 | unsigned long Nu_strtoul(const char *nptr, char **endptr, int base) 82 | { 83 | return strtol(nptr, endptr, base); 84 | } 85 | #endif 86 | 87 | #ifndef HAVE_STRCASECMP 88 | /* 89 | * Compare two strings, case-insensitive. 90 | */ 91 | int Nu_strcasecmp(const char *str1, const char *str2) 92 | { 93 | while (*str1 && *str2 && toupper(*str1) == toupper(*str2)) 94 | str1++, str2++; 95 | return (toupper(*str1) - toupper(*str2)); 96 | } 97 | 98 | #endif 99 | 100 | #ifndef HAVE_STRNCASECMP 101 | /* 102 | * Compare two strings, case-insensitive, stopping after "n" chars. 103 | */ 104 | int Nu_strncasecmp(const char *str1, const char *str2, size_t n) 105 | { 106 | while (n && *str1 && *str2 && toupper(*str1) == toupper(*str2)) 107 | str1++, str2++, n--; 108 | 109 | if (n) 110 | return (toupper(*str1) - toupper(*str2)); 111 | else 112 | return 0; /* no mismatch in first n chars */ 113 | } 114 | #endif 115 | 116 | -------------------------------------------------------------------------------- /nufxlib/MiscStuff.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 3 | * This is free software; you can redistribute it and/or modify it under the 4 | * terms of the BSD License, see the file COPYING-LIB. 5 | * 6 | * Misc stuff (shared between nufxlib and nulib2). This is a collection 7 | * of standard functions that aren't available in libc on this system. 8 | */ 9 | #include "SysDefs.h" 10 | #include "MiscStuff.h" 11 | #include 12 | 13 | 14 | #ifndef HAVE_STRERROR 15 | /* 16 | * Return a pointer to the appropriate string in the system table, or NULL 17 | * if the value is out of bounds. 18 | */ 19 | const char* Nu_strerror(int errnum) 20 | { 21 | extern int sys_nerr; 22 | extern char *sys_errlist[]; 23 | 24 | if (errnum < 0 || errnum > sys_nerr) 25 | return NULL; 26 | 27 | return sys_errlist[errnum]; 28 | } 29 | #endif 30 | 31 | #ifndef HAVE_MEMMOVE 32 | /* 33 | * Move a block of memory. Unlike memcpy, this is expected to work 34 | * correctly with overlapping blocks. 35 | * 36 | * This is a straightforward implementation. A much faster implementation, 37 | * from BSD, is available in the PGP 2.6.2 distribution, but this should 38 | * suffice for those few systems that don't have memmove. 39 | */ 40 | void* Nu_memmove(void* dst, const void* src, size_t n) 41 | { 42 | void* retval = dst; 43 | char* srcp = (char*)src; 44 | char* dstp = (char*)dst; 45 | 46 | /* you can normally get away with this if n==0 */ 47 | Assert(dst != NULL); 48 | Assert(src != NULL); 49 | 50 | if (dstp == srcp || !n) { 51 | /* nothing to do */ 52 | } else if (dstp > srcp) { 53 | /* start from the end */ 54 | (char*)dstp += n-1; 55 | (char*)srcp += n-1; 56 | while (n--) 57 | *dstp-- = *srcp--; 58 | } else { 59 | /* start from the front */ 60 | while (n--) 61 | *dstp++ = *srcp++; 62 | } 63 | 64 | return retval; 65 | } 66 | #endif 67 | 68 | #ifndef HAVE_STRTOUL 69 | /* 70 | * Perform strtol, but on an unsigned long. 71 | * 72 | * On systems that have strtol but don't have strtoul, the strtol 73 | * function doesn't clamp the return value, making it similar in 74 | * function to strtoul. The comparison is not exact, however, 75 | * because strtoul is expected to lots of fancy things (like set 76 | * errno to ERANGE). 77 | * 78 | * For our purposes here, strtol does all we need it to. Someday 79 | * we should replace this with a "real" version. 80 | */ 81 | unsigned long Nu_strtoul(const char *nptr, char **endptr, int base) 82 | { 83 | return strtol(nptr, endptr, base); 84 | } 85 | #endif 86 | 87 | #ifndef HAVE_STRCASECMP 88 | /* 89 | * Compare two strings, case-insensitive. 90 | */ 91 | int Nu_strcasecmp(const char *str1, const char *str2) 92 | { 93 | while (*str1 && *str2 && toupper(*str1) == toupper(*str2)) 94 | str1++, str2++; 95 | return (toupper(*str1) - toupper(*str2)); 96 | } 97 | 98 | #endif 99 | 100 | #ifndef HAVE_STRNCASECMP 101 | /* 102 | * Compare two strings, case-insensitive, stopping after "n" chars. 103 | */ 104 | int Nu_strncasecmp(const char *str1, const char *str2, size_t n) 105 | { 106 | while (n && *str1 && *str2 && toupper(*str1) == toupper(*str2)) 107 | str1++, str2++, n--; 108 | 109 | if (n) 110 | return (toupper(*str1) - toupper(*str2)); 111 | else 112 | return 0; /* no mismatch in first n chars */ 113 | } 114 | #endif 115 | 116 | -------------------------------------------------------------------------------- /nufxlib/SysDefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NuFX archive manipulation library 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING-LIB. 6 | * 7 | * External type definitions and function prototypes. 8 | */ 9 | #ifndef NUFXLIB_SYSDEFS_H 10 | #define NUFXLIB_SYSDEFS_H 11 | 12 | #ifdef HAVE_CONFIG_H 13 | # include 14 | #endif 15 | 16 | #ifdef DEBUG_VERBOSE 17 | # define DEBUG_MSGS 18 | #endif 19 | 20 | /* these should exist everywhere */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | /* basic Win32 stuff -- info-zip has much more complete defs */ 29 | #if defined(_WIN32) || defined(MSDOS) 30 | # define WINDOWS_LIKE 31 | 32 | # ifndef HAVE_CONFIG_H 33 | # define HAVE_FCNTL_H 34 | # define HAVE_MALLOC_H 35 | # define HAVE_STDLIB_H 36 | # define HAVE_SYS_STAT_H 37 | # undef HAVE_SYS_TIME_H 38 | # define HAVE_SYS_TYPES_H 39 | # undef HAVE_UNISTD_H 40 | # undef HAVE_UTIME_H 41 | # define HAVE_SYS_UTIME_H 42 | # define HAVE_WINDOWS_H 43 | # define HAVE_FDOPEN 44 | # undef HAVE_FTRUNCATE 45 | # define HAVE_MEMMOVE 46 | # undef HAVE_MKSTEMP 47 | # define HAVE_MKTIME 48 | # define HAVE_SNPRINTF 49 | # undef HAVE_STRCASECMP 50 | # undef HAVE_STRNCASECMP 51 | # define HAVE_STRERROR 52 | # define HAVE_STRTOUL 53 | # define HAVE_VSNPRINTF 54 | # define SNPRINTF_DECLARED 55 | # define VSNPRINTF_DECLARED 56 | # define SPRINTF_RETURNS_INT 57 | # define inline /*Visual C++6.0 can't inline ".c" files*/ 58 | # define mode_t int 59 | # define ENABLE_SQ 60 | # define ENABLE_LZW 61 | # define ENABLE_LZC 62 | /*# define ENABLE_DEFLATE*/ 63 | /*# define ENABLE_BZIP2*/ 64 | # endif 65 | 66 | # include 67 | # include 68 | # define FOPEN_WANTS_B 69 | # define HAVE_CHSIZE 70 | # if _MSC_VER < 1900 /* no snprintf until Visual Studio 2015 */ 71 | # define snprintf _snprintf 72 | # define vsnprintf _vsnprintf 73 | # endif 74 | 75 | #endif 76 | 77 | #ifdef HAVE_MALLOC_H 78 | # include 79 | #endif 80 | #ifdef HAVE_STDLIB_H 81 | # include 82 | #endif 83 | #ifdef HAVE_SYS_STAT_H 84 | # include 85 | #endif 86 | #ifdef HAVE_SYS_TIME_H 87 | # include 88 | #endif 89 | #ifdef HAVE_SYS_TYPES_H 90 | # include 91 | #endif 92 | #ifdef HAVE_UNISTD_H 93 | # include 94 | #endif 95 | #ifdef HAVE_UTIME_H 96 | # include 97 | #endif 98 | #ifdef HAVE_SYS_UTIME_H 99 | # include 100 | #endif 101 | 102 | #if defined(WINDOWS_LIKE) 103 | # ifndef F_OK 104 | # define F_OK 0 /* was 02 in <= v1.1.0 */ 105 | # endif 106 | #endif 107 | 108 | #if defined(__APPLE__) && defined(__MACH__) /* OS X */ 109 | # define MAC_LIKE 110 | # define UNIX_LIKE 111 | #endif 112 | 113 | #if defined(__unix__) || defined(__unix) || defined(__BEOS__) || \ 114 | defined(__hpux) || defined(_AIX) 115 | # define UNIX_LIKE /* standardize */ 116 | #endif 117 | 118 | #if defined(UNIX_LIKE) 119 | # ifdef USE_REENTRANT_CALLS 120 | # define _REENTRANT /* Solaris 2.x convention */ 121 | # endif 122 | #endif 123 | 124 | /* not currently using filesystem resource forks */ 125 | //#if defined(__ORCAC__) || defined(MAC_LIKE) 126 | //# define HAS_RESOURCE_FORKS 127 | //#endif 128 | 129 | /* __FUNCTION__ was missing from BeOS __MWERKS__, and might be gcc-only */ 130 | #ifdef __GNUC__ 131 | # define HAS__FUNCTION__ 132 | #endif 133 | 134 | #if defined(__linux__) 135 | # define HAS_MALLOC_CHECK_ 136 | #endif 137 | 138 | #endif /*NUFXLIB_SYSDEFS_H*/ 139 | -------------------------------------------------------------------------------- /nulib2/MiscUtils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * NuLib2 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING. 6 | * 7 | * Misc support functions. 8 | */ 9 | #include "NuLib2.h" 10 | 11 | 12 | /* 13 | * Similar to perror(), but takes the error as an argument, and knows 14 | * about NufxLib errors as well as system errors. 15 | * 16 | * If "format" is NULL, just the error message itself is printed. 17 | */ 18 | void ReportError(NuError err, const char* format, ...) 19 | { 20 | const char* msg; 21 | va_list args; 22 | 23 | Assert(format != NULL); 24 | 25 | va_start(args, format); 26 | 27 | /* print the message, if any */ 28 | if (format != NULL) { 29 | fprintf(stderr, "%s: ERROR: ", gProgName); 30 | vfprintf(stderr, format, args); 31 | } 32 | 33 | /* print the error code data, if any */ 34 | if (err == kNuErrNone) 35 | fprintf(stderr, "\n"); 36 | else { 37 | if (format != NULL) 38 | fprintf(stderr, ": "); 39 | 40 | msg = NULL; 41 | if (err >= 0) 42 | msg = strerror(err); 43 | if (msg == NULL) 44 | msg = NuStrError(err); 45 | 46 | if (msg == NULL) 47 | fprintf(stderr, "(unknown err=%d)\n", err); 48 | else 49 | fprintf(stderr, "%s\n", msg); 50 | } 51 | 52 | va_end(args); 53 | } 54 | 55 | 56 | /* 57 | * Memory allocation wrappers. 58 | * 59 | * Under gcc these would be macros, but not all compilers can handle that. 60 | */ 61 | 62 | #ifndef USE_DMALLOC 63 | void* Malloc(size_t size) 64 | { 65 | void* _result; 66 | 67 | Assert(size > 0); 68 | _result = malloc(size); 69 | if (_result == NULL) { 70 | ReportError(kNuErrMalloc, "malloc(%u) failed", (unsigned int) size); 71 | DebugAbort(); /* leave a core dump if we're built for it */ 72 | } 73 | DebugFill(_result, size); 74 | return _result; 75 | } 76 | 77 | void* Calloc(size_t size) 78 | { 79 | void* _cresult = Malloc(size); 80 | memset(_cresult, 0, size); 81 | return _cresult; 82 | } 83 | 84 | void* Realloc(void* ptr, size_t size) 85 | { 86 | void* _result; 87 | 88 | Assert(ptr != NULL); /* disallow this usage */ 89 | Assert(size > 0); /* disallow this usage */ 90 | _result = realloc(ptr, size); 91 | if (_result == NULL) { 92 | ReportError(kNuErrMalloc, "realloc(%u) failed", (unsigned int) size); 93 | DebugAbort(); /* leave a core dump if we're built for it */ 94 | } 95 | return _result; 96 | } 97 | 98 | void Free(void* ptr) 99 | { 100 | if (ptr != NULL) 101 | free(ptr); 102 | } 103 | #endif 104 | 105 | /* 106 | * This gets called when a buffer DataSource is no longer needed. 107 | */ 108 | NuResult FreeCallback(NuArchive* pArchive, void* args) 109 | { 110 | DBUG(("+++ free callback 0x%08lx\n", (long) args)); 111 | Free(args); 112 | return kNuOK; 113 | } 114 | 115 | /* 116 | * Convert Mac OS Roman to Unicode. The caller must free the string 117 | * returned. 118 | * 119 | * Returns NULL if stringMOR is NULL or if the conversion fails. 120 | */ 121 | UNICHAR* CopyMORToUNI(const char* stringMOR) 122 | { 123 | size_t uniLen; 124 | UNICHAR* uniBuf; 125 | 126 | if (stringMOR == NULL) { 127 | return NULL; 128 | } 129 | 130 | uniLen = NuConvertMORToUNI(stringMOR, NULL, 0); 131 | if (uniLen == (size_t) -1) { 132 | return NULL; 133 | } 134 | uniBuf = (UNICHAR*) malloc(uniLen); 135 | NuConvertMORToUNI(stringMOR, uniBuf, uniLen); 136 | return uniBuf; 137 | } 138 | 139 | -------------------------------------------------------------------------------- /nufxlib/config.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * NuFX archive manipulation library 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING-LIB. 6 | */ 7 | /* config.h.in. */ 8 | 9 | /* Define to empty if the keyword does not work. */ 10 | #undef const 11 | 12 | /* Define to empty if the keyword does not work. */ 13 | #undef inline 14 | 15 | /* Define to `int' if doesn't define. */ 16 | #undef mode_t 17 | 18 | /* Define to `long' if doesn't define. */ 19 | #undef off_t 20 | 21 | /* Define to `unsigned' if doesn't define. */ 22 | #undef size_t 23 | 24 | /* Define if you have the ANSI C header files. */ 25 | #undef STDC_HEADERS 26 | 27 | /* Define if your declares struct tm. */ 28 | #undef TM_IN_SYS_TIME 29 | 30 | /* Define to `int' if doesn't define. */ 31 | #undef mode_t 32 | 33 | /* Define to `long' if doesn't define. */ 34 | #undef off_t 35 | 36 | /* Define to `unsigned' if doesn't define. */ 37 | #undef size_t 38 | 39 | /* Define if you have the fdopen function. */ 40 | #undef HAVE_FDOPEN 41 | 42 | /* Define if you have the ftruncate function. */ 43 | #undef HAVE_FTRUNCATE 44 | 45 | /* Define if you have the localtime_r function. */ 46 | #undef HAVE_LOCALTIME_R 47 | 48 | /* Define if you have the memmove function. */ 49 | #undef HAVE_MEMMOVE 50 | 51 | /* Define if you have the mkdir function. */ 52 | #undef HAVE_MKDIR 53 | 54 | /* Define if you have the mkstemp function. */ 55 | #undef HAVE_MKSTEMP 56 | 57 | /* Define if you have the mktime function. */ 58 | #undef HAVE_MKTIME 59 | 60 | /* Define if you have the snprintf function. */ 61 | #undef HAVE_SNPRINTF 62 | 63 | /* Define if you have the strcasecmp function. */ 64 | #undef HAVE_STRCASECMP 65 | 66 | /* Define if you have the strncasecmp function. */ 67 | #undef HAVE_STRNCASECMP 68 | 69 | /* Define if you have the strerror function. */ 70 | #undef HAVE_STRERROR 71 | 72 | /* Define if you have the strtoul function. */ 73 | #undef HAVE_STRTOUL 74 | 75 | /* Define if you have the timelocal function. */ 76 | #undef HAVE_TIMELOCAL 77 | 78 | /* Define if you have the vsnprintf function. */ 79 | #undef HAVE_VSNPRINTF 80 | 81 | /* Define if you have the header file. */ 82 | #undef HAVE_FCNTL_H 83 | 84 | /* Define if you have the header file. */ 85 | #undef HAVE_MALLOC_H 86 | 87 | /* Define if you have the header file. */ 88 | #undef HAVE_STDLIB_H 89 | 90 | /* Define if you have the header file. */ 91 | #undef HAVE_SYS_STAT_H 92 | 93 | /* Define if you have the header file. */ 94 | #undef HAVE_SYS_TIME_H 95 | 96 | /* Define if you have the header file. */ 97 | #undef HAVE_SYS_TYPES_H 98 | 99 | /* Define if you have the header file. */ 100 | #undef HAVE_SYS_UTIME_H 101 | 102 | /* Define if you have the header file. */ 103 | #undef HAVE_UNISTD_H 104 | 105 | /* Define if you have the header file. */ 106 | #undef HAVE_UTIME_H 107 | 108 | /* Define if sprintf returns an int. */ 109 | #undef SPRINTF_RETURNS_INT 110 | 111 | /* Define if SNPRINTF is declared in stdio.h. */ 112 | #undef SNPRINTF_DECLARED 113 | 114 | /* Define if VSNPRINTF is declared in stdio.h. */ 115 | #undef VSNPRINTF_DECLARED 116 | 117 | /* Define to include SQ (Huffman+RLE) compression. */ 118 | #undef ENABLE_SQ 119 | 120 | /* Define to include LZW (ShrinkIt LZW/1 and LZW/2) compression. */ 121 | #undef ENABLE_LZW 122 | 123 | /* Define to include LZC (12-bit and 16-bit UNIX "compress") compression. */ 124 | #undef ENABLE_LZC 125 | 126 | /* Define to include deflate (zlib) compression (also need -l in Makefile). */ 127 | #undef ENABLE_DEFLATE 128 | 129 | /* Define to include bzip2 (libbz2) compression (also need -l in Makefile). */ 130 | #undef ENABLE_BZIP2 131 | 132 | /* Define if we want to use the dmalloc library (also need -l in Makefile). */ 133 | #undef USE_DMALLOC 134 | 135 | -------------------------------------------------------------------------------- /nufxlib/samples/Makefile.msc: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Microsoft C compilers. Tested against Visual C++ 6.0. 3 | # Not pretty but it seems to work. 4 | # 5 | # Run with "nmake /f Makefile.msc". Expects NufxLib to have been built 6 | # in "..". 7 | # 8 | # To build without debugging info, use "nmake nodebug=1". 9 | # To build with libz, use "nmake libz=1". 10 | # To build with libbz2, use "nmake libbz2=1". 11 | # If you're linking against nufxlib as a DLL, you don't need to specify 12 | # libraries. You probably need to specify DLL=1 and the same setting 13 | # of the NODEBUG flag as you used when building the DLL. If you don't, 14 | # "test-extract" will fail in the fwrite() call in Nu_FWrite, because 15 | # the non-debug /MD libc does something peculiar with FILE*. 16 | # 17 | # For libz/libbz2, you need to have the appropriate library either 18 | # in this directory or in a standard location that the linker can find. 19 | # 20 | 21 | # Windows magic 22 | TARGETOS = BOTH 23 | !include 24 | 25 | NUFXSRCDIR = .. 26 | LIB_PRODUCT = $(NUFXSRCDIR)\nufxlib2.lib 27 | 28 | !ifdef DLL 29 | ### build using the same libc as the DLL 30 | !ifdef NODEBUG 31 | #OPT = /D NUFXLIB_DLL /D NDEBUG /MD /Ogityb2 32 | OPT = /D NUFXLIB_DLL /MD /Ogityb2 33 | LIB_FLAGS = /nodefaultlib:libcd.lib /nologo setargv.obj 34 | !else 35 | #OPT = /D NUFXLIB_DLL /MDd /Od 36 | OPT = /D NUFXLIB_DLL /D DEBUG_MSGS /MDd /Od 37 | LIB_FLAGS = /nodefaultlib:libc.lib /nologo setargv.obj 38 | !endif 39 | !else 40 | 41 | ### build against static lib 42 | !ifdef NODEBUG 43 | #OPT = /D NDEBUG /ML /Ogityb2 44 | OPT = /ML /Ogityb2 45 | LIB_FLAGS = /nodefaultlib:libcd.lib /nologo libc.lib setargv.obj 46 | !else 47 | #OPT = /MLd /Od 48 | OPT = /D DEBUG_MSGS /MLd /Od 49 | LIB_FLAGS = /nodefaultlib:libc.lib /nologo libcd.lib setargv.obj 50 | !endif 51 | !endif 52 | 53 | BUILD_FLAGS = /W3 /GX /D "WIN32" /D "_CONSOLE" /I "$(NUFXSRCDIR)" 54 | !MESSAGE Using OPT = $(OPT) 55 | 56 | !ifdef LIBZ 57 | LIB_FLAGS = zlib.lib $(LIB_FLAGS) 58 | !endif 59 | !ifdef LIBBZ2 60 | LIB_FLAGS = libbz2.lib $(LIB_FLAGS) 61 | !endif 62 | 63 | # how to compile sources 64 | .c.obj: 65 | @$(cc) $(cdebug) $(OPT) $(BUILD_FLAGS) $(cflags) $(cvars) -o $@ $< 66 | 67 | 68 | PRODUCTS = exerciser.exe imgconv.exe launder.exe test-basic.exe test-extract.exe test-simple.exe test-twirl.exe 69 | 70 | all: $(PRODUCTS) 71 | 72 | exerciser.exe: Exerciser.obj $(LIB_PRODUCT) 73 | $(link) $(ldebug) Exerciser.obj -out:$@ $(NUFXSRCDIR)\nufxlib2.lib $(LIB_FLAGS) 74 | 75 | imgconv.exe: ImgConv.obj $(LIB_PRODUCT) 76 | $(link) $(ldebug) ImgConv.obj -out:$@ $(NUFXSRCDIR)\nufxlib2.lib $(LIB_FLAGS) 77 | 78 | launder.exe: Launder.obj $(LIB_PRODUCT) 79 | $(link) $(ldebug) Launder.obj -out:$@ $(NUFXSRCDIR)\nufxlib2.lib $(LIB_FLAGS) 80 | 81 | test-basic.exe: TestBasic.obj $(LIB_PRODUCT) 82 | $(link) $(ldebug) TestBasic.obj -out:$@ $(NUFXSRCDIR)\nufxlib2.lib $(LIB_FLAGS) 83 | 84 | test-simple.exe: TestSimple.obj $(LIB_PRODUCT) 85 | $(link) $(ldebug) TestSimple.obj -out:$@ $(NUFXSRCDIR)\nufxlib2.lib $(LIB_FLAGS) 86 | 87 | test-extract.exe: TestExtract.obj $(LIB_PRODUCT) 88 | $(link) $(ldebug) TestExtract.obj -out:$@ $(NUFXSRCDIR)\nufxlib2.lib $(LIB_FLAGS) 89 | 90 | test-twirl.exe: TestTwirl.obj $(LIB_PRODUCT) 91 | $(link) $(ldebug) TestTwirl.obj -out:$@ $(NUFXSRCDIR)\nufxlib2.lib $(LIB_FLAGS) 92 | 93 | clean: 94 | -del *.obj 95 | -del *.pdb 96 | -del *.ilk 97 | -del *.exp 98 | -del exerciser.exe 99 | -del imgconv.exe 100 | -del launder.exe 101 | -del test-basic.exe 102 | -del test-simple.exe 103 | -del test-extract.exe 104 | -del test-twirl.exe 105 | 106 | Exerciser.obj: Exerciser.c Common.h $(NUFXSRCDIR)\NufxLib.h $(NUFXSRCDIR)\SysDefs.h 107 | ImgConv.obj: ImgConv.c Common.h $(NUFXSRCDIR)\NufxLib.h $(NUFXSRCDIR)\SysDefs.h 108 | Launder.obj: Launder.c Common.h $(NUFXSRCDIR)\NufxLib.h $(NUFXSRCDIR)\SysDefs.h 109 | TestBasic.obj: TestBasic.c Common.h $(NUFXSRCDIR)\NufxLib.h $(NUFXSRCDIR)\SysDefs.h 110 | TestSimple.obj: TestSimple.c Common.h $(NUFXSRCDIR)\NufxLib.h $(NUFXSRCDIR)\SysDefs.h 111 | TestExtract.obj: TestExtract.c Common.h $(NUFXSRCDIR)\NufxLib.h $(NUFXSRCDIR)\SysDefs.h 112 | TestTwirl.obj: TestTwirl.c Common.h $(NUFXSRCDIR)\NufxLib.h $(NUFXSRCDIR)\SysDefs.h 113 | 114 | -------------------------------------------------------------------------------- /nulib2/NuLib2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NuLib2 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING. 6 | */ 7 | #ifndef NULIB2_NULIB2_H 8 | #define NULIB2_NULIB2_H 9 | 10 | #include "SysDefs.h" /* system-dependent defs; must come first */ 11 | #include 12 | #include "State.h" 13 | #include "MiscStuff.h" 14 | 15 | #ifdef USE_DMALLOC 16 | /* enable with something like "dmalloc -l logfile -i 100 medium" */ 17 | # include "dmalloc.h" 18 | #endif 19 | 20 | /* replace unsupported chars with '%xx' */ 21 | #define kForeignIndic '%' 22 | 23 | /* use this to separate path components in stored filenames */ 24 | #define kStorageFssep ':' 25 | 26 | /* make our one-line comments this big */ 27 | #define kDefaultCommentLen 200 28 | 29 | /* for use with FormatDateShort() */ 30 | #define kDateOutputLen 64 31 | 32 | /* 33 | * Function prototypes. 34 | */ 35 | 36 | /* Add.c */ 37 | NuError DoAdd(NulibState* pState); 38 | 39 | /* ArcUtils.c */ 40 | char* GetSimpleComment(NulibState* pState, const char* pathname, int maxLen); 41 | Boolean IsFilenameStdin(const char* archiveName); 42 | Boolean IsSpecified(NulibState* pState, const NuRecord* pRecord); 43 | NuError OpenArchiveReadOnly(NulibState* pState); 44 | NuError OpenArchiveReadWrite(NulibState* pState); 45 | const NuThread* GetThread(const NuRecord* pRecord, uint32_t idx); 46 | Boolean IsRecordReadOnly(const NuRecord* pRecord); 47 | 48 | /* Binary2.c */ 49 | NuError BNYDoExtract(NulibState* pState); 50 | NuError BNYDoTest(NulibState* pState); 51 | NuError BNYDoListShort(NulibState* pState); 52 | NuError BNYDoListVerbose(NulibState* pState); 53 | NuError BNYDoListDebug(NulibState* pState); 54 | 55 | /* Delete.c */ 56 | NuError DoDelete(NulibState* pState); 57 | 58 | /* Extract.c */ 59 | NuError DoExtract(NulibState* pState); 60 | NuError DoExtractToPipe(NulibState* pState); 61 | NuError DoTest(NulibState* pState); 62 | 63 | /* Filename.c */ 64 | const char* GetFileTypeString(uint32_t fileType); 65 | const char* NormalizePath(NulibState* pState, NuPathnameProposal* pathProposal); 66 | void InterpretExtension(NulibState* pState, const char* pathName, 67 | uint32_t* pFileType, uint32_t* pAuxType); 68 | Boolean ExtractPreservationString(NulibState* pState, char* pathname, 69 | uint32_t* pFileType, uint32_t* pAuxType, NuThreadID* pThreadID); 70 | void DenormalizePath(NulibState* pState, char* pathBuf); 71 | const char* FilenameOnly(NulibState* pState, const char* pathname); 72 | const char* FindExtension(NulibState* pState, const char* pathname); 73 | 74 | /* List.c */ 75 | NuError DoListShort(NulibState* pState); 76 | NuError DoListVerbose(NulibState* pState); 77 | NuError DoListDebug(NulibState* pState); 78 | char* FormatDateShort(const NuDateTime* pDateTime, char* buffer); 79 | 80 | /* Main.c */ 81 | extern const char* gProgName; 82 | 83 | /* MiscUtils.c */ 84 | void ReportError(NuError err, const char* format, ...) 85 | #if defined(__GNUC__) 86 | __attribute__ ((format(printf, 2, 3))) 87 | #endif 88 | ; 89 | #ifdef USE_DMALLOC /* want file and line numbers for calls */ 90 | # define Malloc(size) malloc(size) 91 | # define Calloc(size) calloc(1, size) 92 | # define Realloc(ptr, size) realloc(ptr, size) 93 | # define Free(ptr) (ptr != NULL ? free(ptr) : (void)0) 94 | #else 95 | void* Malloc(size_t size); 96 | void* Calloc(size_t size); 97 | void* Realloc(void* ptr, size_t size); 98 | void Free(void* ptr); 99 | #endif 100 | NuResult FreeCallback(NuArchive* pArchive, void* args); 101 | UNICHAR* CopyMORToUNI(const char* stringMOR); 102 | 103 | /* SysUtils.c */ 104 | NuError NormalizeFileName(NulibState* pState, const char* srcp, long srcLen, 105 | char fssep, char** pDstp, long dstLen); 106 | NuError NormalizeDirectoryName(NulibState* pState, const char* srcp, 107 | long srcLen, char fssep, char** pDstp, long dstLen); 108 | char* MakeTempArchiveName(NulibState* pState); 109 | NuError SetFinderInfo(int fd, uint8_t proType, uint16_t proAux); 110 | NuError AddFile(NulibState* pState, NuArchive* pArchive, 111 | const char* pathname); 112 | NuError Mkdir(const char* dir); 113 | NuError TestFileExistence(const char* fileName, Boolean* pIsDir); 114 | 115 | #endif /*NULIB2_NULIB2_H*/ 116 | -------------------------------------------------------------------------------- /nufxlib/README.txt: -------------------------------------------------------------------------------- 1 | NufxLib README, updated 2014/12/23 2 | http://www.nulib.com/ 3 | 4 | See "COPYING-LIB" for distribution restrictions. 5 | 6 | 7 | UNIX 8 | ==== 9 | 10 | Run the "configure" script. Read through "INSTALL" if you haven't used 11 | one of these before, especially if you want to use a specific compiler 12 | or a particular set of compiler flags. 13 | 14 | You can disable specific compression methods with "--disable-METHOD" 15 | (run "sh ./configure --help" to see the possible options). By default, 16 | all methods are enabled except bzip2. 17 | 18 | Run "make depend" if you have makedepend, and then type "make". This will 19 | build the library and all of the programs in the "samples" directory. 20 | There are some useful programs in "samples", described in a README.txt 21 | file there. In particular, you should run samples/test-basic to verify 22 | that things are more or less working. 23 | 24 | If you want to install the library and header file into standard system 25 | locations (usually /usr/local), run "make install". To learn how to 26 | specify different locations, read the INSTALL document. 27 | 28 | There are some flags in "OPT" you may want to use. The "autoconf" default 29 | for @CFLAGS@ is "-g -O2". 30 | 31 | -DNDEBUG 32 | Disable assert() calls and extra tests. This will speed things up, 33 | but errors won't get caught until later on, making the root cause 34 | harder to locate. 35 | 36 | -DDEBUG_MSGS 37 | Enable debug messages. This increases the size of the executable, 38 | but shouldn't affect performance. When errors occur, more output is 39 | produced. The "debug dump" feature is enabled by this flag. 40 | 41 | -DDEBUG_VERBOSE 42 | (Implicitly sets DEBUG_MSGS.) Spray lots of debugging output. 43 | 44 | If you want to do benchmarks, use "-O2 -DNDEBUG". The recommended 45 | configuration is "-g -O2 -DDEBUG_MSGS", so that verbose debug output is 46 | available when errors occur. 47 | 48 | 49 | BeOS 50 | ==== 51 | 52 | This works just like the UNIX version, but certain defaults have been 53 | changed. Running configure without arguments under BeOS is equivalent to: 54 | 55 | ./configure --prefix=/boot --includedir='${prefix}/develop/headers' 56 | --libdir='${exec_prefix}/home/config/lib' --mandir='/tmp' 57 | --bindir='${exec_prefix}/home/config/bin' 58 | 59 | If you're using BeOS/PPC, it will also do: 60 | 61 | CC=cc CFLAGS='-proc 603 -opt full' 62 | 63 | 64 | Mac OS X 65 | ======== 66 | 67 | This works just like the UNIX version, but includes support for resource 68 | forks and Finder file/aux types. 69 | 70 | Tested with Xcode v5.1.1 and Mac OS 10.8.5. 71 | 72 | 73 | Win32 74 | ===== 75 | 76 | If you're using an environment that supports "configure" scripts, such as 77 | DJGPP, follow the UNIX instructions. 78 | 79 | NufxLib has been tested with Microsoft Visual C++ 12 (Visual Studio 2013). 80 | To build NufxLib, run the "Visual Studio 2013 x86 Native Tools Command 81 | Prompt" shortcut to get a shell. Change to the nufxlib directory, then: 82 | 83 | nmake -f makefile.msc 84 | 85 | When the build finishes, run "test-basic.exe" to confirm things are working. 86 | 87 | If you want to have zlib support enabled, you will need to have zlib.h, 88 | zconf.h, and zlib.lib copied into the directory. See "makefile.msc" for 89 | more details. 90 | 91 | The makefile builds NufxLib as a static library and as a DLL. 92 | 93 | 94 | Other Notes 95 | =========== 96 | 97 | If you want to use the library in a multithreaded application, you should 98 | define "USE_REENTRANT_CALLS" to tell it to use reentrant versions of 99 | certain library calls. This defines _REENTRANT, which causes Solaris to 100 | add the appropriate goodies. (Seems to me you'd always want this on, but 101 | for some reason Solaris makes you take an extra step, so I'm not going to 102 | define it by default.) 103 | 104 | Originally, NufxLib / NuLib2 were intended to be usable natively on the 105 | Apple IIgs, so some of the design decisions were influenced by the need 106 | to minimize memory usage (e.g. being able to get a directory listing 107 | without holding the entire directory in memory) and interact with GS/OS 108 | (forked files have a single filename, files have type/auxtype). The IIgs 109 | port was never started. 110 | 111 | 112 | Legalese 113 | ======== 114 | 115 | NufxLib, a NuFX archive manipulation library. 116 | Copyright (C) 2000-2014 by Andy McFadden, All Rights Reserved. 117 | 118 | See COPYING for license. 119 | 120 | -------------------------------------------------------------------------------- /nufxlib/samples/README-S.txt: -------------------------------------------------------------------------------- 1 | NufxLib "samples" README 2 | 3 | This directory contains some test programs and useful sample code. 4 | 5 | 6 | test-basic 7 | ========== 8 | 9 | Basic tests. Run this to verify that things are working. 10 | 11 | On Win32 there will be a second executable, test-basic-d, that links against 12 | the DLL rather than the static library. 13 | 14 | 15 | exerciser 16 | ========= 17 | 18 | This program allows you to exercise all of NufxLib's basic functions. 19 | Run it without arguments and hit "?" for a list of commands. 20 | 21 | If you think you have found a bug in NufxLib, you can use this to narrow 22 | it down to a repeatable case. 23 | 24 | 25 | imgconv 26 | ======= 27 | 28 | A 2IMG disk image converter. You can convert ".2MG" files to ShrinkIt 29 | disk archives, and ShrinkIt disk archives to 2IMG format. imgconv uses 30 | a creator type of "NFXL". 31 | 32 | You can use it like this: 33 | 34 | % imgconv file.shk file.2mg 35 | or 36 | % imgconv file.2mg file.shk 37 | 38 | It figures out what to do based on the filename. It will recognize ".sdk" 39 | as a ShrinkIt archive. 40 | 41 | Limitations: works for DOS-ordered and ProDOS-ordered 2MG images, but 42 | not for raw nibble images. Converting from .shk only works if the first 43 | record in the archive is a disk image; you don't get to pick the one you 44 | want from an archive with several in it. 45 | 46 | 47 | launder 48 | ======= 49 | 50 | Run an archive through the laundry. This copies the entire contents of 51 | an archive thread-by-thread, reconstructing it such that the data 52 | matches the original even if the archive contents don't (e.g. records 53 | are updated to version 3, files may be recompressed with LZW/2, option 54 | lists are stripped out, etc). 55 | 56 | The basic usage is: 57 | 58 | % launder [-crfa] [-m method] infile.shk outfile.shk 59 | 60 | The flags are: 61 | 62 | -c Just copy data threads rather than recompressing them 63 | -r Add threads in reverse order 64 | -f Call NuFlush after every record 65 | -a Call NuAbort after every record, then re-do the record and call NuFlush 66 | -t Write to temp file, instead of writing directly into outfile.shk 67 | 68 | The "-m method" flag allows you to specify the compression method. Valid 69 | values are sq (SQueeze), lzw1 (ShrinkIt LZW/1), lzw2 (ShrinkIt LZW/2), 70 | lzc12 (12-bit UNIX "compress"), lzc16 (16-bit UNIX "compress"), deflate 71 | (zlib deflate), and bzip2 (libbz2 compression). The default is lzw2. 72 | 73 | If you use the "-c" flag with an archive created by P8 ShrinkIt or NuLib, 74 | the laundered archive may have CRC failures when you try to extract 75 | from it. This is because "launder" creates version 3 records, which 76 | are expected to have a valid CRC in the thread header. The only way 77 | to compute the CRC is to uncompress the data, which "launder" doesn't 78 | do when "-c" is set. The data itself is fine, it's just the thread CRC 79 | that's wrong (if the data were hosed, the LZW/1 CRC would be bad too). 80 | "launder" will issue a warning when it detects this situation. 81 | 82 | By default, launder will try to keep the entire archive in memory and flush 83 | all of the operations at the end. If you find that you're running out 84 | of memory on very large archives, you can reduce the memory requirements 85 | by specifying the "-f" flag. 86 | 87 | 88 | test-names 89 | ========== 90 | 91 | Tests Unicode filename handling. Run without arguments. 92 | 93 | (This currently fails on Win32 because the Unicode filename support is 94 | incomplete there.) 95 | 96 | 97 | test-simple 98 | =========== 99 | 100 | Simple test program. Give it the name of an archive, and it will display 101 | the contents. 102 | 103 | 104 | test-extract 105 | ============ 106 | 107 | Simple test program. Give it the name of an archive, and it will write 108 | all filename threads into "out.buf", "out.fp", and "out.file" using three 109 | different kinds of NuDataSinks. 110 | 111 | 112 | test-twirl 113 | ========== 114 | 115 | Like "launder", but not meant to be useful. This recompresses the file "in 116 | place", deleting and adding threads within existing records several times. 117 | The changes are periodically flushed, but the archive is never closed. 118 | The goal is to test repeated updates on an open archive. 119 | 120 | The CRC verification mechanism will fail on archives created with ProDOS 121 | 8 ShrinkIt. The older "version 1" records didn't have CRCs in the thread 122 | headers, so you will get a series of messages that look like this: 123 | 124 | ERROR: CRC mismatch: 0 old=0x0000 new=0x681b 125 | ERROR: CRC mismatch: 1 old=0x0000 new=0x5570 126 | ERROR: CRC mismatch: 2 old=0x0000 new=0x4ec5 127 | 128 | This will leave the original archive alone, making a copy of it named 129 | "TwirlCopy678" in the current directory. It overwrites its temp file, 130 | "TwirlTmp789", without prompting. 131 | 132 | -------------------------------------------------------------------------------- /nulib2/Makefile.in: -------------------------------------------------------------------------------- 1 | # 2 | # Nulib2 3 | # Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | # This is free software; you can redistribute it and/or modify it under the 5 | # terms of the BSD License, see the file COPYING. 6 | # 7 | # Makefile for nulib2 stuff (should work with non-GNU make). 8 | # 9 | # You can use: 10 | # make (builds nulib2 and checks for libnufx.a) 11 | # make shared (builds nulib2 and checks for libnufx.so) 12 | # 13 | # This will try to link against the library in $(NUFXSRCDIR) first, then 14 | # look for a copy in the standard system install location (usually 15 | # /usr/local/lib). 16 | # 17 | # Note that this really wants to find $(NUFXLIB) for dependency checking. 18 | # If you're building against a copy in /usr/local/lib, just put a '#' in 19 | # front of the "NUFXLIB" line below. 20 | # 21 | 22 | # set this to where the NuFX library and ".h" file live 23 | NUFXSRCDIR = ../nufxlib 24 | NUFXLIB = $(NUFXSRCDIR)/$(LIB_PRODUCT) 25 | 26 | # NuLib2 install location. The man page will go into $(mandir)/man1. 27 | prefix = @prefix@ 28 | exec_prefix = @exec_prefix@ 29 | includedir = @includedir@ 30 | libdir = @libdir@ 31 | bindir = @bindir@ 32 | mandir = @mandir@ 33 | srcdir = @srcdir@ 34 | 35 | SHELL = @SHELL@ 36 | INSTALL = @INSTALL@ 37 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 38 | INSTALL_DATA = @INSTALL_DATA@ 39 | CC = @CC@ 40 | #OPT = @CFLAGS@ -DNDEBUG 41 | OPT = @CFLAGS@ 42 | #OPT = @CFLAGS@ -DDEBUG_MSGS 43 | #OPT = @CFLAGS@ -DDEBUG_VERBOSE 44 | GCC_FLAGS = -Wall -Wwrite-strings -Wstrict-prototypes -Wpointer-arith -Wshadow 45 | CFLAGS = @BUILD_FLAGS@ -I. -I$(NUFXSRCDIR) -I$(includedir) @DEFS@ 46 | 47 | SRCS = Add.c ArcUtils.c Binary2.c Delete.c Extract.c Filename.c \ 48 | List.c Main.c MiscStuff.c MiscUtils.c State.c SysUtils.c 49 | OBJS = Add.o ArcUtils.o Binary2.o Delete.o Extract.o Filename.o \ 50 | List.o Main.o MiscStuff.o MiscUtils.o State.o SysUtils.o 51 | 52 | PRODUCT = nulib2 53 | 54 | # this is used for dependency checking 55 | LIB_PRODUCT = libnufx.a 56 | 57 | 58 | # 59 | # Build stuff 60 | # 61 | 62 | all: $(PRODUCT) 63 | @true 64 | 65 | install: $(PRODUCT) 66 | $(srcdir)/mkinstalldirs $(DESTDIR)$(bindir) 67 | $(INSTALL_PROGRAM) $(PRODUCT) $(DESTDIR)$(bindir) 68 | $(srcdir)/mkinstalldirs $(DESTDIR)$(mandir)/man1 69 | $(INSTALL_DATA) nulib2.1 $(DESTDIR)$(mandir)/man1/ 70 | 71 | install-shared: 72 | LIB_PRODUCT="libnufx.so" $(MAKE) -e install 73 | 74 | # Link against the shared version of libnufx. This is only needed so 75 | # the dependency checking does the right thing during development. Note 76 | # we probably don't need to link against all of LIBS, especially -lz -lbz2, 77 | # but there's little harm in doing so. 78 | shared:: 79 | LIB_PRODUCT="libnufx.so" $(MAKE) -e 80 | 81 | $(PRODUCT): $(OBJS) $(NUFXLIB) 82 | $(CC) $(LDFLAGS) -o $@ $(OBJS) -L$(NUFXSRCDIR) -L$(libdir) -lnufx @LIBS@ 83 | 84 | clean: 85 | -rm -f *.o core 86 | -rm -f $(PRODUCT) 87 | 88 | tags:: 89 | ctags -R --totals * $(NUFXSRCDIR)/* 90 | @#ctags *.[ch] $(NUFXSRCDIR)/*.[ch] 91 | 92 | distclean: clean 93 | -rm -f Makefile Makefile.bak 94 | -rm -f config.log config.cache config.status config.h 95 | -rm -f tags 96 | -rm -f nulib2-@host_alias@ nulib2-@host_alias@.tar.Z 97 | 98 | # Copy all of the binaries into a directory and tar them up for distribution. 99 | # All binaries except "nulib2" are stripped to reduce their size. 100 | distbin: $(PRODUCT) 101 | @ \ 102 | builddir="nulib2-@host_alias@"; \ 103 | samples=$(NUFXSRCDIR)/samples; \ 104 | echo "building $$builddir.tar.Z"; \ 105 | rm -rf $$builddir; \ 106 | mkdir -p $$builddir; \ 107 | cp -p $(PRODUCT) nulib2.1 README.txt COPYING $$samples/README-S.txt \ 108 | $$samples/exerciser $$samples/imgconv $$samples/launder \ 109 | $$samples/test-basic $$samples/test-extract \ 110 | $$samples/test-simple \ 111 | $$builddir; \ 112 | strip $$builddir/$(PRODUCT) \ 113 | $$builddir/exerciser $$builddir/imgconv $$builddir/launder \ 114 | $$builddir/test-basic $$builddir/test-extract \ 115 | $$builddir/test-simple; \ 116 | tar -cf - $$builddir | compress > $$builddir.tar.Z; \ 117 | rm -rf $$builddir 118 | 119 | # Make a tarfile with a backup of the essential files. We include "Makefile" 120 | # so that we can do a "make distclean" during packaging. 121 | baktar: 122 | @tar cvf nulib2.tar *.txt COPYING INSTALL nulib2.1 configure *.in Makefile \ 123 | Makefile.msc install-sh config.guess config.sub mkinstalldirs *.[ch] 124 | @gzip -9 nulib2.tar 125 | @mv -i nulib2.tar.gz /home/fadden/BAK/ 126 | 127 | # dependency info 128 | COMMON_HDRS = NuLib2.h SysDefs.h State.h MiscStuff.h config.h \ 129 | $(NUFXSRCDIR)/NufxLib.h 130 | Add.o: Add.c $(COMMON_HDRS) 131 | ArcUtils.o: ArcUtils.c $(COMMON_HDRS) 132 | Binary2.o: Binary2.c $(COMMON_HDRS) 133 | Delete.o: Delete.c $(COMMON_HDRS) 134 | Extract.o: Extract.c $(COMMON_HDRS) 135 | Filename.o: Filename.c $(COMMON_HDRS) 136 | List.o: List.c $(COMMON_HDRS) 137 | Main.o: Main.c $(COMMON_HDRS) 138 | MiscStuff.o: MiscStuff.c $(COMMON_HDRS) 139 | MiscUtils.o: MiscUtils.c $(COMMON_HDRS) 140 | State.o: State.c $(COMMON_HDRS) 141 | SysUtils.o: SysUtils.c $(COMMON_HDRS) 142 | 143 | -------------------------------------------------------------------------------- /nufxlib/Makefile.in: -------------------------------------------------------------------------------- 1 | # 2 | # NuFX archive manipulation library 3 | # Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | # This is free software; you can redistribute it and/or modify it under the 5 | # terms of the BSD License, see the file COPYING-LIB. 6 | # 7 | # Makefile for nufxlib (should work with non-GNU "make"). 8 | # 9 | # You can use: 10 | # make (builds library and sample applications) 11 | # make shared (builds shared library if you're using GNU ld or similar) 12 | # 13 | # The shared library support currently leaves much to be desired. 14 | # 15 | # If you build with -DDEBUG_MSGS, nulib2 will be able to use the hidden 16 | # 'g' command, which generates a verbose archive dump for debugging. 17 | # 18 | 19 | # NufxLib install location. 20 | prefix = @prefix@ 21 | exec_prefix = @exec_prefix@ 22 | includedir = @includedir@ 23 | libdir = @libdir@ 24 | srcdir = @srcdir@ 25 | 26 | SHELL = @SHELL@ 27 | INSTALL = @INSTALL@ 28 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 29 | INSTALL_DATA = @INSTALL_DATA@ 30 | CC = @CC@ 31 | AR = ar rcv 32 | #OPT = @CFLAGS@ -DNDEBUG 33 | OPT = @CFLAGS@ 34 | #OPT = @CFLAGS@ -DDEBUG_MSGS 35 | #OPT = @CFLAGS@ -DDEBUG_VERBOSE 36 | GCC_FLAGS = -Wall -Wwrite-strings -Wstrict-prototypes -Wpointer-arith -Wshadow 37 | CFLAGS = @BUILD_FLAGS@ -I. @DEFS@ -fPIC -DOPTFLAGSTR="\"$(OPT)\"" 38 | 39 | SRCS = Archive.c ArchiveIO.c Bzip2.c Charset.c Compress.c Crc16.c \ 40 | Debug.c Deferred.c Deflate.c Entry.c Expand.c FileIO.c Funnel.c \ 41 | Lzc.c Lzw.c MiscStuff.c MiscUtils.c Record.c SourceSink.c \ 42 | Squeeze.c Thread.c Value.c Version.c 43 | OBJS = Archive.o ArchiveIO.o Bzip2.o Charset.o Compress.o Crc16.o \ 44 | Debug.o Deferred.o Deflate.o Entry.o Expand.o FileIO.o Funnel.o \ 45 | Lzc.o Lzw.o MiscStuff.o MiscUtils.o Record.o SourceSink.o \ 46 | Squeeze.o Thread.o Value.o Version.o 47 | 48 | STATIC_PRODUCT = libnufx.a 49 | SHARED_PRODUCT = libnufx.so 50 | PRODUCT = $(STATIC_PRODUCT) 51 | 52 | 53 | # 54 | # Build stuff 55 | # 56 | 57 | all: $(PRODUCT) samples 58 | @true 59 | 60 | install: $(STATIC_PRODUCT) 61 | $(srcdir)/mkinstalldirs $(libdir) 62 | $(INSTALL_DATA) $(STATIC_PRODUCT) $(libdir) 63 | $(srcdir)/mkinstalldirs $(includedir) $(libdir)/pkgconfig 64 | $(INSTALL_DATA) NufxLib.h $(includedir) 65 | $(INSTALL_DATA) nufxlib.pc $(libdir)/pkgconfig 66 | 67 | install-shared: $(SHARED_PRODUCT) 68 | $(srcdir)/mkinstalldirs $(libdir) 69 | $(INSTALL_DATA) $(SHARED_PRODUCT) $(libdir) 70 | $(srcdir)/mkinstalldirs $(includedir) $(libdir)/pkgconfig 71 | $(INSTALL_DATA) NufxLib.h $(includedir) 72 | $(INSTALL_DATA) nufxlib.pc $(libdir)/pkgconfig 73 | 74 | samples:: $(STATIC_PRODUCT) 75 | @echo "Building samples..." 76 | @(cd samples; set +e; unset CFLAGS OBJS; set -e; \ 77 | @SET_MAKE@ LIB_PRODUCT="../$(PRODUCT)" $(MAKE)) 78 | 79 | shared:: 80 | PRODUCT="$(SHARED_PRODUCT)" $(MAKE) -e 81 | 82 | $(STATIC_PRODUCT): $(OBJS) 83 | -rm -f $(STATIC_PRODUCT) $(SHARED_PRODUCT) 84 | $(AR) $@ $(OBJS) 85 | @RANLIB@ $@ 86 | 87 | # BUG: we need -fPIC, maybe -D_REENTRANT when compiling for this. 88 | # BUG: for Linux we may want -Wl,-soname,libnufx.so.1 on the link line. 89 | $(SHARED_PRODUCT): $(OBJS) 90 | -rm -f $(STATIC_PRODUCT) $(SHARED_PRODUCT) 91 | $(CC) @SHARE_FLAGS@ -o $@ $(OBJS) @LIBS@ 92 | 93 | clean: 94 | (cd samples; make clean) 95 | -rm -f *.o core 96 | -rm -f $(SHARED_PRODUCT) $(STATIC_PRODUCT) 97 | 98 | # build tags; assumes fancy GNU tag generation 99 | tags:: 100 | @ctags -R --totals * 101 | @#ctags *.[ch] 102 | 103 | distclean: clean 104 | (cd samples; make distclean) 105 | -rm -f Makefile Makefile.bak 106 | -rm -f config.log config.cache config.status config.h 107 | -rm -f tags 108 | 109 | # Make a tarfile with a backup of the essential files. We include "Makefile" 110 | # so that we can do a "make distclean" during packaging. 111 | baktar: 112 | @tar cvf nufxlib.tar *.txt COPYING-LIB INSTALL configure *.in Makefile \ 113 | Makefile.msc Makefile.dll install-sh config.guess config.sub \ 114 | mkinstalldirs *.[ch] samples/*.txt samples/Makefile* samples/*.[ch] 115 | @gzip -9 nufxlib.tar 116 | @mv -i nufxlib.tar.gz /home/fadden/BAK/ 117 | 118 | # dependency info 119 | COMMON_HDRS = NufxLibPriv.h NufxLib.h MiscStuff.h SysDefs.h 120 | Archive.o: Archive.c $(COMMON_HDRS) 121 | ArchiveIO.o: ArchiveIO.c $(COMMON_HDRS) 122 | Bzip2.o: Bzip2.c $(COMMON_HDRS) 123 | Charset.o: Charset.c $(COMMON_HDRS) 124 | Compress.o: Compress.c $(COMMON_HDRS) 125 | Crc16.o: Crc16.c $(COMMON_HDRS) 126 | Debug.o: Debug.c $(COMMON_HDRS) 127 | Deferred.o: Deferred.c $(COMMON_HDRS) 128 | Deflate.o: Deflate.c $(COMMON_HDRS) 129 | Entry.o: Entry.c $(COMMON_HDRS) 130 | Expand.o: Expand.c $(COMMON_HDRS) 131 | FileIO.o: FileIO.c $(COMMON_HDRS) 132 | Funnel.o: Funnel.c $(COMMON_HDRS) 133 | Lzc.o: Lzc.c $(COMMON_HDRS) 134 | Lzw.o: Lzw.c $(COMMON_HDRS) 135 | MiscStuff.o: MiscStuff.c $(COMMON_HDRS) 136 | MiscUtils.o: MiscUtils.c $(COMMON_HDRS) 137 | Record.o: Record.c $(COMMON_HDRS) 138 | SourceSink.o: SourceSink.c $(COMMON_HDRS) 139 | Squeeze.o: Squeeze.c $(COMMON_HDRS) 140 | Thread.o: Thread.c $(COMMON_HDRS) 141 | Value.o: Value.c $(COMMON_HDRS) 142 | Version.o: Version.c $(COMMON_HDRS) Makefile 143 | 144 | -------------------------------------------------------------------------------- /nufxlib/Crc16.c: -------------------------------------------------------------------------------- 1 | /* 2 | * NuFX archive manipulation library 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING-LIB. 6 | * 7 | * Compute 16-bit CRCs. Depending on the hardware, the table version 8 | * might be slower than the loop computation. 9 | */ 10 | #include "NufxLibPriv.h" 11 | 12 | #define CRC_TAB 13 | #ifdef CRC_TAB 14 | /* 15 | * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. 16 | * NOTE: First srgument must be in range 0 to 255. 17 | * Second argument is referenced twice. 18 | * 19 | * Programmers may incorporate any or all code into their programs, 20 | * giving proper credit within the source. Publication of the 21 | * source routines is permitted so long as proper credit is given 22 | * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, 23 | * Omen Technology. 24 | */ 25 | 26 | 27 | /*#define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)*/ 28 | #define updcrc(cp, crc) ( (crctab[((crc >> 8) & 0xFF) ^ cp] ^ (crc << 8)) & 0xFFFF) 29 | 30 | 31 | /* crctab calculated by Mark G. Mendel, Network Systems Corporation */ 32 | const uint16_t gNuCrc16Table[256] = { 33 | 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 34 | 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 35 | 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 36 | 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 37 | 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 38 | 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 39 | 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 40 | 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 41 | 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 42 | 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, 43 | 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 44 | 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, 45 | 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 46 | 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 47 | 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 48 | 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 49 | 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, 50 | 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, 51 | 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 52 | 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, 53 | 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 54 | 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 55 | 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 56 | 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, 57 | 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 58 | 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, 59 | 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 60 | 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, 61 | 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 62 | 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 63 | 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 64 | 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 65 | }; 66 | #endif 67 | 68 | 69 | /* 70 | * Calculate CRC on a region 71 | * 72 | * A CRC is the result of a mathematical operation based on the 73 | * coefficients of a polynomial when multiplied by X^16 then divided by 74 | * the generator polynomial (X^16 + X^12 + X^5 + 1) using modulo two 75 | * arithmetic. 76 | * 77 | * This routine is a slightly modified verison of one found in: 78 | * _Advanced Programming Techniques for the Apple //gs Toolbox_ 79 | * By Morgan Davis and Dan Gookin (Compute! Publications, Inc.) 80 | * It can either calculate the CRC bit-by-bit or use a table. 81 | * 82 | * Depending on CPU architecture, one may be dramatically faster than 83 | * the other. 84 | */ 85 | uint16_t Nu_CalcCRC16(uint16_t seed, const uint8_t* ptr, int count) 86 | { 87 | uint16_t CRC = seed; 88 | #ifndef CRC_TAB 89 | int x; 90 | #endif 91 | 92 | do { 93 | #ifndef CRC_TAB 94 | CRC ^= *ptr++ << 8; /* XOR hi-byte of CRC w/dat */ 95 | for (x = 8; x; --x) /* Then, for 8 bit shifts... */ 96 | if (CRC & 0x8000) /* Test hi order bit of CRC */ 97 | CRC = CRC << 1 ^ 0x1021; /* if set, shift & XOR w/$1021 */ 98 | else 99 | CRC <<= 1; /* Else, just shift left once. */ 100 | #else 101 | CRC = Nu_UpdateCRC16(*ptr++, CRC); /* look up new value in table */ 102 | #endif 103 | } while (--count); 104 | 105 | return (CRC); 106 | } 107 | 108 | -------------------------------------------------------------------------------- /nulib2/SysDefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NuLib2 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING. 6 | * 7 | * This was adapted from gzip's "tailor.h" and NuLib's "nudefs.h". 8 | */ 9 | #ifndef NULIB2_SYSDEFS_H 10 | #define NULIB2_SYSDEFS_H 11 | 12 | #ifdef HAVE_CONFIG_H 13 | # include 14 | #endif 15 | 16 | #ifdef DEBUG_VERBOSE 17 | # define DEBUG_MSGS 18 | #endif 19 | 20 | /* these should exist everywhere */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | /* basic Win32 stuff -- info-zip has much more complete defs */ 31 | #if defined(_WIN32) || defined(MSDOS) 32 | # define WINDOWS_LIKE 33 | 34 | # ifndef HAVE_CONFIG_H 35 | # define HAVE_FCNTL_H 36 | # define HAVE_MALLOC_H 37 | # define HAVE_STDLIB_H 38 | # define HAVE_SYS_STAT_H 39 | # undef HAVE_SYS_TIME_H 40 | # define HAVE_SYS_TYPES_H 41 | # undef HAVE_UNISTD_H 42 | # undef HAVE_UTIME_H 43 | # define HAVE_SYS_UTIME_H 44 | # define HAVE_WINDOWS_H 45 | # define HAVE_FDOPEN 46 | # undef HAVE_FTRUNCATE 47 | # define HAVE_MEMMOVE 48 | # undef HAVE_MKSTEMP 49 | # define HAVE_MKTIME 50 | # define HAVE_SNPRINTF 51 | # undef HAVE_STRCASECMP 52 | # undef HAVE_STRNCASECMP 53 | # define HAVE_STRERROR 54 | # define HAVE_STRTOUL 55 | # define HAVE_VSNPRINTF 56 | # define SNPRINTF_DECLARED 57 | # define VSNPRINTF_DECLARED 58 | # define SPRINTF_RETURNS_INT 59 | # define inline /*Visual C++6.0 can't inline ".c" files*/ 60 | # define mode_t int 61 | # endif 62 | 63 | # include 64 | # include 65 | # define FOPEN_WANTS_B 66 | # define HAVE_CHSIZE 67 | # if _MSC_VER < 1900 /* no snprintf until Visual Studio 2015 */ 68 | # define snprintf _snprintf 69 | # define vsnprintf _vsnprintf 70 | # endif 71 | 72 | #endif 73 | 74 | 75 | #ifdef HAVE_MALLOC_H 76 | # include 77 | #endif 78 | #ifdef HAVE_STDLIB_H 79 | # include 80 | #endif 81 | #ifdef HAVE_SYS_STAT_H 82 | # include 83 | #endif 84 | #ifdef HAVE_SYS_TIME_H 85 | # include 86 | #endif 87 | #ifdef HAVE_SYS_TYPES_H 88 | # include 89 | #endif 90 | #ifdef HAVE_UNISTD_H 91 | # include 92 | #endif 93 | 94 | #if defined(WINDOWS_LIKE) 95 | # ifndef F_OK 96 | # define F_OK 00 97 | # endif 98 | # ifndef R_OK 99 | # define R_OK 04 100 | # endif 101 | #endif 102 | 103 | 104 | #if defined(__unix__) || defined(__unix) || defined(__BEOS__) || \ 105 | defined(__hpux) || defined(_AIX) || defined(__APPLE__) 106 | # define UNIX_LIKE 107 | #endif 108 | 109 | 110 | #if defined(__MSDOS__) && !defined(MSDOS) 111 | # define MSDOS 112 | #endif 113 | 114 | #if defined(__OS2__) && !defined(OS2) 115 | # define OS2 116 | #endif 117 | 118 | #if defined(OS2) && defined(MSDOS) /* MS C under OS/2 */ 119 | # undef MSDOS 120 | #endif 121 | 122 | /* this ought to get trimmed down */ 123 | #ifdef MSDOS 124 | # ifndef __GNUC__ 125 | # ifdef __TURBOC__ 126 | # define NO_OFF_T 127 | # ifdef __BORLANDC__ 128 | # define DIRENT 129 | # else 130 | # define NO_UTIME 131 | # endif 132 | # else /* MSC */ 133 | # define HAVE_SYS_UTIME_H 134 | # define NO_UTIME_H 135 | # endif 136 | # endif 137 | # define PATH_SEP '\\' 138 | # define PATH_SEP2 '/' 139 | # define PATH_SEP3 ':' 140 | # ifdef MAX_PATH 141 | # define MAX_PATH_LEN MAX_PATH 142 | # else 143 | # define MAX_PATH_LEN 128 144 | # endif 145 | # define NO_MULTIPLE_DOTS 146 | # define MAX_EXT_CHARS 3 147 | # define NO_CHOWN 148 | # define PROTO 149 | # ifndef HAVE_CONFIG_H 150 | # define STDC_HEADERS 151 | # endif 152 | # define NO_SIZE_CHECK 153 | # define SYSTEM_DEFAULT_EOL "\r\n" 154 | #endif 155 | 156 | #ifdef WIN32 /* Windows 95/98/NT */ 157 | # define HAVE_SYS_UTIME_H 158 | # define NO_UTIME_H 159 | # define PATH_SEP '\\' 160 | # define PATH_SEP2 '/' 161 | # define PATH_SEP3 ':' 162 | # ifdef MAX_PATH 163 | # define MAX_PATH_LEN MAX_PATH 164 | # else 165 | # define MAX_PATH_LEN 260 166 | # endif 167 | # define PROTO 168 | # define STDC_HEADERS 169 | # define SYSTEM_DEFAULT_EOL "\r\n" 170 | #endif 171 | 172 | #ifdef MACOS 173 | # define PATH_SEP ':' 174 | # define NO_CHOWN 175 | # define NO_UTIME 176 | # define SYSTEM_DEFAULT_EOL "\r" 177 | #endif 178 | 179 | #if defined(__APPLE__) && defined(__MACH__) /* OS X */ 180 | # define MAC_LIKE 181 | # define UNIX_LIKE 182 | #endif 183 | 184 | /* not currently using filesystem resource forks */ 185 | //#if defined(__ORCAC__) || defined(MAC_LIKE) 186 | //# define HAS_RESOURCE_FORKS 187 | //#endif 188 | 189 | #if defined(APW) || defined(__ORCAC__) 190 | # define __appleiigs__ 191 | # pragma lint -1 192 | # pragma memorymodel 1 193 | # pragma optimize 7 194 | /*# pragma debug 25 */ 195 | # define PATH_SEP ':' 196 | # define SYSTEM_DEFAULT_EOL "\r" 197 | 198 | # ifdef GNO 199 | # define HAS_DIRENT 200 | # endif 201 | #endif 202 | 203 | #ifdef __GNUC__ /* this was missing from BeOS __MWERKS__, and probably others */ 204 | # define HAS__FUNCTION__ 205 | #endif 206 | 207 | /* general defaults, mainly for UNIX */ 208 | 209 | #ifndef PATH_SEP 210 | # define PATH_SEP '/' 211 | #endif 212 | #ifndef SYSTEM_DEFAULT_EOL 213 | # define SYSTEM_DEFAULT_EOL "\n" 214 | #endif 215 | #ifndef MAX_PATH_LEN 216 | # define MAX_PATH_LEN 1024 217 | #endif 218 | 219 | #endif /*NULIB2_SYSDEFS_H*/ 220 | -------------------------------------------------------------------------------- /nulib2/configure.in: -------------------------------------------------------------------------------- 1 | dnl Nulib2 2 | dnl Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 3 | dnl This is free software; you can redistribute it and/or modify it under the 4 | dnl terms of the BSD License, see the file COPYING. 5 | dnl 6 | dnl Process this file with autoconf to produce a configure script. 7 | 8 | AC_INIT(Main.c) 9 | AC_CONFIG_HEADER(config.h) 10 | 11 | dnl Checks for programs. 12 | AC_CANONICAL_HOST 13 | AC_PROG_CC 14 | AC_PROG_INSTALL 15 | 16 | dnl Checks for header files. 17 | AC_HEADER_DIRENT 18 | AC_HEADER_STDC 19 | AC_CHECK_HEADERS(fcntl.h limits.h malloc.h stdlib.h strings.h sys/stat.h \ 20 | sys/time.h sys/types.h unistd.h) 21 | 22 | LIBS="" 23 | 24 | dnl 25 | dnl Check for libz and libbz2. We want to link against them in case 26 | dnl NufxLib has them enabled. If they're not enabled, we don't want to 27 | dnl link against them if they're shared libraries, because it'll create 28 | dnl an unnecessary shared lib dependency. Won't matter unless you try 29 | dnl to copy the binary to another machine. 30 | dnl 31 | dnl So, we try to link against the libraries unless they're explicitly 32 | dnl disabled by the person building them. Not ideal, but it'll work. 33 | dnl Of course, if nufxlib is built as a shared library, the dependencies 34 | dnl will be handled correctly without having to use -l here. 35 | dnl 36 | AC_ARG_ENABLE(deflate, 37 | [ --disable-deflate don't link against libz], 38 | [ ], [ enable_deflate=yes ]) 39 | if test $enable_deflate = "yes"; then 40 | dnl Check for zlib. Make sure it comes with zlib.h. 41 | dnl AC_CHECK_LIB(z, deflate, 42 | dnl AC_CHECK_HEADER(zlib.h, LIBS="$LIBS -lz")) 43 | got_zlibh=false 44 | AC_CHECK_LIB(z, deflate, got_libz=true, got_libz=false) 45 | if $got_libz; then 46 | AC_CHECK_HEADER(zlib.h, got_zlibh=true LIBS="$LIBS -lz") 47 | fi 48 | if $got_zlibh; then 49 | echo " (found libz and zlib.h, enabling deflate)" 50 | AC_DEFINE(ENABLE_DEFLATE, [], [Define to include deflate (zlib) compresion (also need -l in Makefile).]) 51 | else 52 | echo " (couldn't find libz and zlib.h, not enabling deflate)" 53 | fi 54 | fi 55 | 56 | AC_ARG_ENABLE(bzip2, 57 | [ --enable-bzip2 do link against libbz2], 58 | [ ], [ enable_bzip2=no ]) 59 | if test $enable_bzip2 = "yes"; then 60 | dnl Check for libbz2. Make sure it comes with bzlib.h. 61 | dnl AC_CHECK_LIB(bz2, BZ2_bzCompress, 62 | dnl AC_CHECK_HEADER(bzlib.h, LIBS="$LIBS -lbz2")) 63 | got_bzlibh=false 64 | AC_CHECK_LIB(bz2, BZ2_bzCompress, got_libbz=true, got_libbz=false) 65 | if $got_libbz; then 66 | AC_CHECK_HEADER(bzlib.h, got_bzlibh=true LIBS="$LIBS -lbz2") 67 | fi 68 | if $got_bzlibh; then 69 | echo " (found libbz2 and bzlib.h, enabling bzip2)" 70 | AC_DEFINE(ENABLE_BZIP2, [], [Define to include bzip2 (libbz2) compression (also need -l in Makefile).]) 71 | else 72 | echo " (couldn't find libbz2 and bzlib.h, not enabling bzip2)" 73 | fi 74 | fi 75 | 76 | dnl Checks for typedefs, structures, and compiler characteristics. 77 | AC_C_CONST 78 | AC_TYPE_MODE_T 79 | AC_TYPE_OFF_T 80 | AC_TYPE_SIZE_T 81 | AC_STRUCT_TM 82 | 83 | dnl Checks for library functions. 84 | dnl AC_FUNC_SETVBUF_REVERSED 85 | AC_FUNC_UTIME_NULL 86 | AC_CHECK_FUNCS(memmove mkdir strtoul strcasecmp strncasecmp strerror) 87 | 88 | dnl if we're using gcc, include gcc-specific warning flags 89 | if test -z "$GCC"; then 90 | BUILD_FLAGS='$(OPT)' 91 | else 92 | BUILD_FLAGS='$(OPT) $(GCC_FLAGS)' 93 | fi 94 | 95 | dnl --------------------------------------------------------------------------- 96 | dnl Some host-specific stuff. Variables you can test (set by the 97 | dnl AC_CANONICAL_HOST call earlier) look like this: 98 | dnl 99 | dnl $host = i686-pc-linux-gnu 100 | dnl $host_cpu = i686 101 | dnl $host_vendor = pc 102 | dnl $host_os = linux-gnu 103 | 104 | dnl BeOS doesn't like /usr/local/include, and gets feisty about it. If libdir 105 | dnl and includedir are set to defaults, replace them with BeOS values. This 106 | dnl might be going a little too far... 107 | if test "$host_os" = "beos"; then 108 | if test "$prefix" = "NONE" -a \ 109 | "$includedir" = '${prefix}/include' -a \ 110 | "$libdir" = '${exec_prefix}/lib' -a \ 111 | "$bindir" = '${exec_prefix}/bin' -a \ 112 | "$mandir" = '${prefix}/man' 113 | then 114 | echo replacing install locations with BeOS values 115 | prefix=/boot 116 | includedir='${prefix}/develop/headers' 117 | libdir='${exec_prefix}/home/config/lib' 118 | bindir='${exec_prefix}/home/config/bin' 119 | mandir='/tmp' 120 | AC_SUBST(prefix) 121 | AC_SUBST(includedir) 122 | AC_SUBST(libdir) 123 | AC_SUBST(bindir) 124 | AC_SUBST(mandir) 125 | fi 126 | fi 127 | 128 | dnl Figure out what the build and link flags should be 129 | if test "$host_cpu" = "powerpc" -a "$host_os" = "beos"; then 130 | dnl BeOS/PPC with Metrowerks compiler 131 | CC=cc 132 | GCC= 133 | CFLAGS='-proc 603 -opt full' 134 | echo "forcing CC to \"$CC\" and CFLAGS to \"$CFLAGS\"" 135 | fi 136 | 137 | AC_SUBST(BUILD_FLAGS) 138 | 139 | AC_ARG_ENABLE(dmalloc, [ --enable-dmalloc do dmalloc stuff], \ 140 | [ echo "--- enabling dmalloc"; 141 | LIBS="$LIBS -L/usr/local/lib -ldmalloc"; AC_DEFINE(USE_DMALLOC, [], [Define if we want to use the dmalloc library (also need -l in Makefile).]) ]) 142 | 143 | AC_OUTPUT(Makefile) 144 | -------------------------------------------------------------------------------- /nulib2/Extract.c: -------------------------------------------------------------------------------- 1 | /* 2 | * NuLib2 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING. 6 | * 7 | * Extract files and test archives. 8 | */ 9 | #include "NuLib2.h" 10 | 11 | 12 | /* 13 | * Extract all of the records from the archive, pulling out and displaying 14 | * comment threads. 15 | * 16 | * The "bulk extract" call doesn't deal with comments. Since we want to 17 | * show them while we're extracting the files, we have to manually find 18 | * and extract them. 19 | */ 20 | static NuError ExtractAllRecords(NulibState* pState, NuArchive* pArchive) 21 | { 22 | NuError err; 23 | const NuRecord* pRecord; 24 | const NuThread* pThread; 25 | NuRecordIdx recordIdx; 26 | NuAttr numRecords; 27 | int idx, threadIdx; 28 | 29 | DBUG(("--- doing manual extract\n")); 30 | Assert(NState_GetCommand(pState) == kCommandExtract); /* no "-p" here */ 31 | 32 | err = NuGetAttr(pArchive, kNuAttrNumRecords, &numRecords); 33 | for (idx = 0; idx < (int) numRecords; idx++) { 34 | err = NuGetRecordIdxByPosition(pArchive, idx, &recordIdx); 35 | if (err != kNuErrNone) { 36 | fprintf(stderr, "ERROR: couldn't get record #%d (err=%d)\n", 37 | idx, err); 38 | goto bail; 39 | } 40 | 41 | err = NuGetRecord(pArchive, recordIdx, &pRecord); 42 | if (err != kNuErrNone) { 43 | fprintf(stderr, "ERROR: unable to get recordIdx %u\n", recordIdx); 44 | goto bail; 45 | } 46 | 47 | /* do we want to extract this record? */ 48 | if (!IsSpecified(pState, pRecord)) 49 | continue; 50 | NState_IncMatchCount(pState); 51 | 52 | /* 53 | * Look for a comment thread. 54 | */ 55 | for (threadIdx = 0; (uint32_t)threadIdx < pRecord->recTotalThreads; 56 | threadIdx++) 57 | { 58 | pThread = NuGetThread(pRecord, threadIdx); 59 | Assert(pThread != NULL); 60 | 61 | if (NuGetThreadID(pThread) == kNuThreadIDComment && 62 | pThread->actualThreadEOF > 0) 63 | { 64 | UNICHAR* filenameUNI = CopyMORToUNI(pRecord->filenameMOR); 65 | printf("----- '%s':\n", filenameUNI); 66 | free(filenameUNI); 67 | err = NuExtractThread(pArchive, pThread->threadIdx, 68 | NState_GetCommentSink(pState)); 69 | if (err != kNuErrNone) { 70 | printf("[comment extraction failed, continuing\n"); 71 | } else { 72 | printf("\n-----\n"); 73 | } 74 | } 75 | } 76 | 77 | /* extract the record, using the usual mechanisms */ 78 | err = NuExtractRecord(pArchive, recordIdx); 79 | if (err != kNuErrNone) 80 | goto bail; 81 | } 82 | 83 | bail: 84 | return err; 85 | } 86 | 87 | 88 | /* 89 | * Extract the specified files. 90 | */ 91 | NuError DoExtract(NulibState* pState) 92 | { 93 | NuError err; 94 | NuArchive* pArchive = NULL; 95 | 96 | Assert(pState != NULL); 97 | 98 | if (NState_GetModBinaryII(pState)) 99 | return BNYDoExtract(pState); 100 | 101 | err = OpenArchiveReadOnly(pState); 102 | if (err == kNuErrIsBinary2) 103 | return BNYDoExtract(pState); 104 | if (err != kNuErrNone) 105 | goto bail; 106 | pArchive = NState_GetNuArchive(pState); 107 | Assert(pArchive != NULL); 108 | 109 | NState_SetMatchCount(pState, 0); 110 | 111 | /* 112 | * If we're not interested in comments, just use the "bulk" extract 113 | * call. If we want comments, we need to do this one at a time. 114 | */ 115 | if (!NState_GetModComments(pState)) { 116 | err = NuExtract(pArchive); 117 | if (err != kNuErrNone) 118 | goto bail; 119 | } else { 120 | err = ExtractAllRecords(pState, pArchive); 121 | if (err != kNuErrNone) 122 | goto bail; 123 | } 124 | 125 | if (!NState_GetMatchCount(pState)) 126 | printf("%s: no records match\n", gProgName); 127 | 128 | bail: 129 | if (pArchive != NULL) 130 | (void) NuClose(pArchive); 131 | return err; 132 | } 133 | 134 | 135 | /* 136 | * Extract the specified files to stdout. 137 | */ 138 | NuError DoExtractToPipe(NulibState* pState) 139 | { 140 | /* we handle the "to pipe" part farther down */ 141 | return DoExtract(pState); 142 | } 143 | 144 | 145 | /* 146 | * Do an integrity check on one or more records in the archive. 147 | */ 148 | NuError DoTest(NulibState* pState) 149 | { 150 | NuError err; 151 | NuArchive* pArchive = NULL; 152 | 153 | Assert(pState != NULL); 154 | 155 | if (NState_GetModBinaryII(pState)) 156 | return BNYDoTest(pState); 157 | 158 | err = OpenArchiveReadOnly(pState); 159 | if (err == kNuErrIsBinary2) 160 | return BNYDoTest(pState); 161 | if (err != kNuErrNone) 162 | goto bail; 163 | pArchive = NState_GetNuArchive(pState); 164 | Assert(pArchive != NULL); 165 | 166 | NState_SetMatchCount(pState, 0); 167 | 168 | err = NuTest(pArchive); 169 | if (err != kNuErrNone) 170 | goto bail; 171 | 172 | if (!NState_GetMatchCount(pState)) 173 | printf("%s: no records match\n", gProgName); 174 | 175 | bail: 176 | if (pArchive != NULL) 177 | (void) NuClose(pArchive); 178 | return err; 179 | } 180 | 181 | -------------------------------------------------------------------------------- /nufxlib/Makefile.msc: -------------------------------------------------------------------------------- 1 | # Makefile for NufxLib using Microsoft Visual C++. This builds the library 2 | # as a static lib and as a DLL, and builds all samples. The test-basic 3 | # sample is built twice, once with the static lib, and once with the DLL. 4 | # 5 | # Tested with VS 2013 Pro. From the "VS2013 x86 Native Tools Command 6 | # Prompt", run "nmake -f makefile.msc". 7 | # 8 | # If you're including zlib support, place copies of zlib.h, zconf.h, 9 | # and the zlib library in this directory. 10 | # 11 | # Adapted from zlib's Makefile.msc. 12 | # 13 | 14 | TOP = . 15 | 16 | STATICLIB = nufxlib2.lib 17 | SHAREDLIB = nufxlib2.dll 18 | IMPLIB = nufxdll.lib 19 | 20 | CC = cl 21 | LD = link 22 | AR = lib 23 | 24 | # C compiler flags 25 | # -Fd: rename PDB file from "VCx0.pdb" (where 'x' is the version number); 26 | # allows DLL debug info to be separate from app debug info 27 | # -Ox: full optimization 28 | # -Oy-: disable frame pointer omission (for easier debugging) 29 | # -MD: create a multithreaded DLL using MSVCRT.lib; alternatively, 30 | # use -MDd to create a debug executable with MSVCRTD.lib 31 | # -nologo: suppress display of copyright banner 32 | # -W3: set warning level to 3 (all production-level warnings) 33 | # -Zi: generate a PDB file with full debugging info 34 | # 35 | # The OPTFLAGSTR define is used by Version.c to show how the library was 36 | # built. Defining NUFXLIB_EXPORTS enables the __declspec(dllexport) 37 | # macros that are required for creating the DLL. 38 | OPTFLAGS = -Ox -Oy- 39 | CFLAGS = -nologo -MD -W3 $(OPTFLAGS) -Zi -Fd"nufxlib" 40 | 41 | LIB_CFLAGS = -DOPTFLAGSTR="\"$(OPTFLAGS)\"" #-DNUFXLIB_EXPORTS 42 | 43 | # Warning suppression flags 44 | WFLAGS = -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE 45 | 46 | # Linker flags 47 | # -debug: creates debugging info for EXE or DLL in PDB file 48 | # -incremental:no: disable incremental linking, making the resulting library 49 | # a tad smaller 50 | # -nologo: suppress display of copyright banner 51 | # -opt:ref: eliminates unreferenced functions and data (default for non-debug 52 | # builds, but we've enabled debug info) 53 | LDFLAGS = -nologo -debug -incremental:no -opt:ref 54 | 55 | # Library creator flags 56 | ARFLAGS = -nologo 57 | 58 | 59 | ZLIB=1 60 | !ifdef ZLIB 61 | # enable deflate support; requires zlib 62 | CFLAGS = $(CFLAGS) -DENABLE_DEFLATE 63 | LDFLAGS = $(LDFLAGS) zlib.lib 64 | !endif 65 | 66 | 67 | # object files 68 | OBJS = Archive.obj ArchiveIO.obj Bzip2.obj Charset.obj Compress.obj \ 69 | Crc16.obj Debug.obj Deferred.obj Deflate.obj Entry.obj Expand.obj \ 70 | FileIO.obj Funnel.obj Lzc.obj Lzw.obj MiscStuff.obj MiscUtils.obj \ 71 | Record.obj SourceSink.obj Squeeze.obj Thread.obj Value.obj Version.obj 72 | 73 | 74 | # build targets -- static library, dynamic library, and test programs 75 | all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) \ 76 | exerciser.exe imgconv.exe launder.exe test-basic.exe test-basic-d.exe \ 77 | test-extract.exe test-names.exe test-simple.exe test-twirl.exe 78 | 79 | clean: 80 | -del *.obj *.pdb *.exp 81 | -del $(STATICLIB) $(SHAREDLIB) $(IMPLIB) 82 | 83 | $(STATICLIB): $(OBJS) 84 | $(AR) $(ARFLAGS) -out:$@ $(OBJS) 85 | 86 | $(IMPLIB): $(SHAREDLIB) 87 | 88 | $(SHAREDLIB): $(OBJS) 89 | $(LD) $(LDFLAGS) -dll -def:nufxlib.def -implib:$(IMPLIB) -out:$@ \ 90 | $(OBJS) 91 | 92 | exerciser.exe: Exerciser.obj $(STATICLIB) 93 | $(LD) $(LDFLAGS) -out:$@ Exerciser.obj $(STATICLIB) 94 | 95 | imgconv.exe: ImgConv.obj $(STATICLIB) 96 | $(LD) $(LDFLAGS) -out:$@ ImgConv.obj $(STATICLIB) 97 | 98 | launder.exe: Launder.obj $(STATICLIB) 99 | $(LD) $(LDFLAGS) -out:$@ Launder.obj $(STATICLIB) 100 | 101 | test-basic.exe: TestBasic.obj $(STATICLIB) 102 | $(LD) $(LDFLAGS) -out:$@ TestBasic.obj $(STATICLIB) 103 | 104 | test-basic-d.exe: TestBasic.obj $(IMPLIB) 105 | $(LD) $(LDFLAGS) -out:$@ TestBasic.obj $(IMPLIB) 106 | 107 | test-extract.exe: TestExtract.obj $(STATICLIB) 108 | $(LD) $(LDFLAGS) -out:$@ TestExtract.obj $(STATICLIB) 109 | 110 | test-names.exe: TestNames.obj $(STATICLIB) 111 | $(LD) $(LDFLAGS) -out:$@ TestNames.obj $(STATICLIB) 112 | 113 | test-simple.exe: TestSimple.obj $(STATICLIB) 114 | $(LD) $(LDFLAGS) -out:$@ TestSimple.obj $(STATICLIB) 115 | 116 | test-twirl.exe: TestTwirl.obj $(STATICLIB) 117 | $(LD) $(LDFLAGS) -out:$@ TestTwirl.obj $(STATICLIB) 118 | 119 | # generic rules 120 | {$(TOP)}.c.obj: 121 | $(CC) -c $(WFLAGS) $(CFLAGS) $(LIB_CFLAGS) $< 122 | 123 | {$(TOP)/samples}.c.obj: 124 | $(CC) -c -I$(TOP) $(WFLAGS) $(CFLAGS) $< 125 | 126 | # dependency info 127 | COMMON_HDRS = NufxLibPriv.h NufxLib.h MiscStuff.h SysDefs.h 128 | Archive.obj: Archive.c $(COMMON_HDRS) 129 | ArchiveIO.obj: ArchiveIO.c $(COMMON_HDRS) 130 | Bzip2.obj: Bzip2.c $(COMMON_HDRS) 131 | Charset.obj: Charset.c $(COMMON_HDRS) 132 | Compress.obj: Compress.c $(COMMON_HDRS) 133 | Crc16.obj: Crc16.c $(COMMON_HDRS) 134 | Debug.obj: Debug.c $(COMMON_HDRS) 135 | Deferred.obj: Deferred.c $(COMMON_HDRS) 136 | Deflate.obj: Deflate.c $(COMMON_HDRS) 137 | Entry.obj: Entry.c $(COMMON_HDRS) 138 | Expand.obj: Expand.c $(COMMON_HDRS) 139 | FileIO.obj: FileIO.c $(COMMON_HDRS) 140 | Funnel.obj: Funnel.c $(COMMON_HDRS) 141 | Lzc.obj: Lzc.c $(COMMON_HDRS) 142 | Lzw.obj: Lzw.c $(COMMON_HDRS) 143 | MiscStuff.obj: MiscStuff.c $(COMMON_HDRS) 144 | MiscUtils.obj: MiscUtils.c $(COMMON_HDRS) 145 | Record.obj: Record.c $(COMMON_HDRS) 146 | SourceSink.obj: SourceSink.c $(COMMON_HDRS) 147 | Squeeze.obj: Squeeze.c $(COMMON_HDRS) 148 | Thread.obj: Thread.c $(COMMON_HDRS) 149 | Value.obj: Value.c $(COMMON_HDRS) 150 | Version.obj: Version.c $(COMMON_HDRS) 151 | 152 | Exerciser.obj: samples/Exerciser.c $(COMMON_HDRS) 153 | ImgConv.obj: samples/ImgConv.c $(COMMON_HDRS) 154 | Launder.obj: samples/Launder.c $(COMMON_HDRS) 155 | TestBasic.obj: samples/TestBasic.c $(COMMON_HDRS) 156 | TestExtract.obj: samples/TestExtract.c $(COMMON_HDRS) 157 | TestNames.obj: samples/TestNames.c $(COMMON_HDRS) 158 | TestSimple.obj: samples/TestSimple.c $(COMMON_HDRS) 159 | TestTwirl.obj: samples/TestTwirl.c $(COMMON_HDRS) 160 | 161 | -------------------------------------------------------------------------------- /nulib2/README.txt: -------------------------------------------------------------------------------- 1 | NuLib2 README, updated 2015/01/03 2 | http://www.nulib.com/ 3 | 4 | 5 | To build NuLib2, you will also need a copy of NufxLib. This should have come 6 | in the same distribution file. Build the NufxLib library first. 7 | 8 | 9 | UNIX 10 | ==== 11 | 12 | Make sure that the "NUFXSRCDIR" define in Makefile.in points to the correct 13 | directory, or that the library has been installed in a standard location 14 | such as /usr/local/lib/. If you received NuLib2 and NufxLib in a single 15 | ".tar.gz" file, the variable is already set correctly. The makefile will 16 | look in $(NUFXSRCDIR) first, /usr/local/lib second. 17 | 18 | Run the "configure" script. Read through "INSTALL" if you haven't used 19 | one of these before, especially if you want to use a specific compiler 20 | or a particular set of compiler flags. 21 | 22 | If you have disabled deflate or enabled bzip2 support in libnufx.a, you 23 | will need to provide the same --enable-METHOD or --disable-METHOD flag 24 | to configure here. If you're using shared libraries then the link 25 | dependencies are taken care of and you don't need to do anything. 26 | 27 | Run "make depend" if you have makedepend, and then type "make". 28 | This should leave you with an executable called "nulib2". If you like, 29 | "make install" will copy files into your install directory, usually 30 | /usr/local/bin/ and /usr/local/man/. You can change this by using 31 | "./configure --prefix=directory". 32 | 33 | You may want to fiddle with the "OPT" setting in Makefile to enable or 34 | disable optimizations and assertions. Because almost all of the hard 35 | work is done by NufxLib, turning compiler optimizations on in NuLib2 has 36 | little impact on performance. 37 | 38 | 39 | A man page for nulib2 is in "nulib2.1", which you can format for viewing 40 | with "nroff -man nulib2.1". A full manual for NuLib2 is available from 41 | the www.nulib.com web site. 42 | 43 | 44 | BeOS 45 | ==== 46 | 47 | This works just like the UNIX version, but certain defaults have been 48 | changed. Running configure without arguments under BeOS is equivalent to: 49 | 50 | ./configure --prefix=/boot --includedir='${prefix}/develop/headers' 51 | --libdir='${exec_prefix}/home/config/lib' --mandir='/tmp' 52 | --bindir='${exec_prefix}/home/config/bin' 53 | 54 | If you're using BeOS/PPC, it will also do: 55 | 56 | CC=cc CFLAGS='-proc 603 -opt full' 57 | 58 | 59 | Mac OS X 60 | ======== 61 | 62 | This works just like the UNIX version, but includes support for resource 63 | forks and Finder file/aux types. 64 | 65 | Tested with Xcode v5.1.1 and Mac OS 10.8.5. 66 | 67 | 68 | Win32 69 | ===== 70 | 71 | If you're using an environment that supports "configure" scripts, such as 72 | DJGPP, follow the UNIX instructions. 73 | 74 | NuLib2 has been tested with Microsoft Visual C++ 12 (Visual Studio 2013). 75 | To build NuLib2, run the "Visual Studio 2013 x86 Native Tools Command 76 | Prompt" shortcut to get a shell. Change to the nulib2 directory, then: 77 | 78 | nmake -f makefile.msc 79 | 80 | If you want to have zlib support enabled, you will need to have zlib.lib 81 | copied into the directory. See "makefile.msc" for more details. 82 | 83 | Unicode filename support has not been ported to Windows. Non-ASCII 84 | characters will be interpreted as the default character set (CP1252). 85 | This is the way NuLib2 has always worked in Windows, but it may not 86 | match with the behavior of CiderPress. In any event, this only affects 87 | files with non-ASCII filenames. 88 | 89 | 90 | Other Notes 91 | =========== 92 | 93 | Fun benchmark of the day: 94 | 95 | Time to compress 1525 files, totaling 19942152 bytes, on an Apple IIgs 96 | with an 8MHz ZipGS accelerator and Apple HS SCSI card, running System 97 | 6.0.1, from a 20MB ProDOS partition to a 13.9MB archive on an HFS volume, 98 | with GS/ShrinkIt 1.1: about 40 minutes. 99 | 100 | Time to compress the same files, on a 128MB 500MHz Pentium-III running 101 | Red Hat Linux 6.0, with NuLib2 v0.3: about six seconds. 102 | 103 | 104 | 105 | Here's a nifty way to evaluate GSHK vs NuLib2 (as well as Linux NuLib2 106 | vs Win32 NuLib2): 107 | 108 | - Archive a whole bunch of files from a ProDOS volume with GS/ShrinkIt. 109 | I used a 20MB partition, which resulted in a 14MB archive. Transfer 110 | the archive to a machine running NuLib2 (perhaps a Linux system). 111 | - Create a new subdirectory, cd into it, and extract the entire archive 112 | with "nulib2 xe ../foo.shk". 113 | - Now create a new archive with all of the files, using 114 | "nulib2 aer ../new.shk *". 115 | - Change back to the directory above, and use "nulib2 v" to see what's 116 | in them, e.g. "nulib2 v foo.shk > out.orig" and 117 | "nulib2 v new.shk > out.new". 118 | - Edit both of the "out" files with vi. Do a global search-and-replace 119 | in both files to set the file dates to be the same. I used 120 | ":%s/..-...-.. ..:../01-Jan-00 00:00/". This is necessary because, 121 | like ShrinkIt, NuLib displays the date on which the files were archived, 122 | not when they were last modified. 123 | - Sort both files, with ":%!sort". This is necessary because you 124 | added the files with '*' up above, so the NuLib2-created archive 125 | has the top-level files alphabetized. 126 | - Quit out of vi. Diff the two files. 127 | 128 | I did this for a 20MB hard drive partition with 1500 files on it. 129 | The only discrepancies (accounting for a total difference of 116 bytes) 130 | were a zero-byte "Kangaroo.data" file that GSHK stored improperly and some 131 | semi-random GSHK behavior that I can't mimic. When the "Mimic ShrinkIt" 132 | flag is disabled, the resulting archive is 13K smaller. 133 | 134 | 135 | The largest archive I've tried had 4700 files for a total of 76MB 136 | (compressed down to 47MB), and contained the entire contents of four 20MB 137 | ProDOS hard drive partitions. NuLib2 under Linux handled it without 138 | breaking a sweat. 139 | 140 | 141 | Legalese 142 | ======== 143 | 144 | NuLib2, a NuFX and Binary II archive application. 145 | Copyright (C) 2000-2014 by Andy McFadden, All Rights Reserved. 146 | 147 | See COPYING for license. 148 | 149 | -------------------------------------------------------------------------------- /nulib2/install-sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # install - install a program, script, or datafile 4 | # This comes from X11R5 (mit/util/scripts/install.sh). 5 | # 6 | # Copyright 1991 by the Massachusetts Institute of Technology 7 | # 8 | # Permission to use, copy, modify, distribute, and sell this software and its 9 | # documentation for any purpose is hereby granted without fee, provided that 10 | # the above copyright notice appear in all copies and that both that 11 | # copyright notice and this permission notice appear in supporting 12 | # documentation, and that the name of M.I.T. not be used in advertising or 13 | # publicity pertaining to distribution of the software without specific, 14 | # written prior permission. M.I.T. makes no representations about the 15 | # suitability of this software for any purpose. It is provided "as is" 16 | # without express or implied warranty. 17 | # 18 | # Calling this script install-sh is preferred over install.sh, to prevent 19 | # `make' implicit rules from creating a file called install from it 20 | # when there is no Makefile. 21 | # 22 | # This script is compatible with the BSD install script, but was written 23 | # from scratch. It can only install one file at a time, a restriction 24 | # shared with many OS's install programs. 25 | 26 | 27 | # set DOITPROG to echo to test this script 28 | 29 | # Don't use :- since 4.3BSD and earlier shells don't like it. 30 | doit="${DOITPROG-}" 31 | 32 | 33 | # put in absolute paths if you don't have them in your path; or use env. vars. 34 | 35 | mvprog="${MVPROG-mv}" 36 | cpprog="${CPPROG-cp}" 37 | chmodprog="${CHMODPROG-chmod}" 38 | chownprog="${CHOWNPROG-chown}" 39 | chgrpprog="${CHGRPPROG-chgrp}" 40 | stripprog="${STRIPPROG-strip}" 41 | rmprog="${RMPROG-rm}" 42 | mkdirprog="${MKDIRPROG-mkdir}" 43 | 44 | transformbasename="" 45 | transform_arg="" 46 | instcmd="$mvprog" 47 | chmodcmd="$chmodprog 0755" 48 | chowncmd="" 49 | chgrpcmd="" 50 | stripcmd="" 51 | rmcmd="$rmprog -f" 52 | mvcmd="$mvprog" 53 | src="" 54 | dst="" 55 | dir_arg="" 56 | 57 | while [ x"$1" != x ]; do 58 | case $1 in 59 | -c) instcmd="$cpprog" 60 | shift 61 | continue;; 62 | 63 | -d) dir_arg=true 64 | shift 65 | continue;; 66 | 67 | -m) chmodcmd="$chmodprog $2" 68 | shift 69 | shift 70 | continue;; 71 | 72 | -o) chowncmd="$chownprog $2" 73 | shift 74 | shift 75 | continue;; 76 | 77 | -g) chgrpcmd="$chgrpprog $2" 78 | shift 79 | shift 80 | continue;; 81 | 82 | -s) stripcmd="$stripprog" 83 | shift 84 | continue;; 85 | 86 | -t=*) transformarg=`echo $1 | sed 's/-t=//'` 87 | shift 88 | continue;; 89 | 90 | -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 91 | shift 92 | continue;; 93 | 94 | *) if [ x"$src" = x ] 95 | then 96 | src=$1 97 | else 98 | # this colon is to work around a 386BSD /bin/sh bug 99 | : 100 | dst=$1 101 | fi 102 | shift 103 | continue;; 104 | esac 105 | done 106 | 107 | if [ x"$src" = x ] 108 | then 109 | echo "install: no input file specified" 110 | exit 1 111 | else 112 | true 113 | fi 114 | 115 | if [ x"$dir_arg" != x ]; then 116 | dst=$src 117 | src="" 118 | 119 | if [ -d $dst ]; then 120 | instcmd=: 121 | chmodcmd="" 122 | else 123 | instcmd=mkdir 124 | fi 125 | else 126 | 127 | # Waiting for this to be detected by the "$instcmd $src $dsttmp" command 128 | # might cause directories to be created, which would be especially bad 129 | # if $src (and thus $dsttmp) contains '*'. 130 | 131 | if [ -f $src -o -d $src ] 132 | then 133 | true 134 | else 135 | echo "install: $src does not exist" 136 | exit 1 137 | fi 138 | 139 | if [ x"$dst" = x ] 140 | then 141 | echo "install: no destination specified" 142 | exit 1 143 | else 144 | true 145 | fi 146 | 147 | # If destination is a directory, append the input filename; if your system 148 | # does not like double slashes in filenames, you may need to add some logic 149 | 150 | if [ -d $dst ] 151 | then 152 | dst="$dst"/`basename $src` 153 | else 154 | true 155 | fi 156 | fi 157 | 158 | ## this sed command emulates the dirname command 159 | dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` 160 | 161 | # Make sure that the destination directory exists. 162 | # this part is taken from Noah Friedman's mkinstalldirs script 163 | 164 | # Skip lots of stat calls in the usual case. 165 | if [ ! -d "$dstdir" ]; then 166 | defaultIFS=' 167 | ' 168 | IFS="${IFS-${defaultIFS}}" 169 | 170 | oIFS="${IFS}" 171 | # Some sh's can't handle IFS=/ for some reason. 172 | IFS='%' 173 | set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` 174 | IFS="${oIFS}" 175 | 176 | pathcomp='' 177 | 178 | while [ $# -ne 0 ] ; do 179 | pathcomp="${pathcomp}${1}" 180 | shift 181 | 182 | if [ ! -d "${pathcomp}" ] ; 183 | then 184 | $mkdirprog "${pathcomp}" 185 | else 186 | true 187 | fi 188 | 189 | pathcomp="${pathcomp}/" 190 | done 191 | fi 192 | 193 | if [ x"$dir_arg" != x ] 194 | then 195 | $doit $instcmd $dst && 196 | 197 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && 198 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && 199 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && 200 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi 201 | else 202 | 203 | # If we're going to rename the final executable, determine the name now. 204 | 205 | if [ x"$transformarg" = x ] 206 | then 207 | dstfile=`basename $dst` 208 | else 209 | dstfile=`basename $dst $transformbasename | 210 | sed $transformarg`$transformbasename 211 | fi 212 | 213 | # don't allow the sed command to completely eliminate the filename 214 | 215 | if [ x"$dstfile" = x ] 216 | then 217 | dstfile=`basename $dst` 218 | else 219 | true 220 | fi 221 | 222 | # Make a temp file name in the proper directory. 223 | 224 | dsttmp=$dstdir/#inst.$$# 225 | 226 | # Move or copy the file name to the temp name 227 | 228 | $doit $instcmd $src $dsttmp && 229 | 230 | trap "rm -f ${dsttmp}" 0 && 231 | 232 | # and set any options; do chmod last to preserve setuid bits 233 | 234 | # If any of these fail, we abort the whole thing. If we want to 235 | # ignore errors from any of these, just make sure not to ignore 236 | # errors from the above "$doit $instcmd $src $dsttmp" command. 237 | 238 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && 239 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && 240 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && 241 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && 242 | 243 | # Now rename the file to the real destination. 244 | 245 | $doit $rmcmd -f $dstdir/$dstfile && 246 | $doit $mvcmd $dsttmp $dstdir/$dstfile 247 | 248 | fi && 249 | 250 | 251 | exit 0 252 | -------------------------------------------------------------------------------- /nufxlib/install-sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # install - install a program, script, or datafile 4 | # This comes from X11R5 (mit/util/scripts/install.sh). 5 | # 6 | # Copyright 1991 by the Massachusetts Institute of Technology 7 | # 8 | # Permission to use, copy, modify, distribute, and sell this software and its 9 | # documentation for any purpose is hereby granted without fee, provided that 10 | # the above copyright notice appear in all copies and that both that 11 | # copyright notice and this permission notice appear in supporting 12 | # documentation, and that the name of M.I.T. not be used in advertising or 13 | # publicity pertaining to distribution of the software without specific, 14 | # written prior permission. M.I.T. makes no representations about the 15 | # suitability of this software for any purpose. It is provided "as is" 16 | # without express or implied warranty. 17 | # 18 | # Calling this script install-sh is preferred over install.sh, to prevent 19 | # `make' implicit rules from creating a file called install from it 20 | # when there is no Makefile. 21 | # 22 | # This script is compatible with the BSD install script, but was written 23 | # from scratch. It can only install one file at a time, a restriction 24 | # shared with many OS's install programs. 25 | 26 | 27 | # set DOITPROG to echo to test this script 28 | 29 | # Don't use :- since 4.3BSD and earlier shells don't like it. 30 | doit="${DOITPROG-}" 31 | 32 | 33 | # put in absolute paths if you don't have them in your path; or use env. vars. 34 | 35 | mvprog="${MVPROG-mv}" 36 | cpprog="${CPPROG-cp}" 37 | chmodprog="${CHMODPROG-chmod}" 38 | chownprog="${CHOWNPROG-chown}" 39 | chgrpprog="${CHGRPPROG-chgrp}" 40 | stripprog="${STRIPPROG-strip}" 41 | rmprog="${RMPROG-rm}" 42 | mkdirprog="${MKDIRPROG-mkdir}" 43 | 44 | transformbasename="" 45 | transform_arg="" 46 | instcmd="$mvprog" 47 | chmodcmd="$chmodprog 0755" 48 | chowncmd="" 49 | chgrpcmd="" 50 | stripcmd="" 51 | rmcmd="$rmprog -f" 52 | mvcmd="$mvprog" 53 | src="" 54 | dst="" 55 | dir_arg="" 56 | 57 | while [ x"$1" != x ]; do 58 | case $1 in 59 | -c) instcmd="$cpprog" 60 | shift 61 | continue;; 62 | 63 | -d) dir_arg=true 64 | shift 65 | continue;; 66 | 67 | -m) chmodcmd="$chmodprog $2" 68 | shift 69 | shift 70 | continue;; 71 | 72 | -o) chowncmd="$chownprog $2" 73 | shift 74 | shift 75 | continue;; 76 | 77 | -g) chgrpcmd="$chgrpprog $2" 78 | shift 79 | shift 80 | continue;; 81 | 82 | -s) stripcmd="$stripprog" 83 | shift 84 | continue;; 85 | 86 | -t=*) transformarg=`echo $1 | sed 's/-t=//'` 87 | shift 88 | continue;; 89 | 90 | -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 91 | shift 92 | continue;; 93 | 94 | *) if [ x"$src" = x ] 95 | then 96 | src=$1 97 | else 98 | # this colon is to work around a 386BSD /bin/sh bug 99 | : 100 | dst=$1 101 | fi 102 | shift 103 | continue;; 104 | esac 105 | done 106 | 107 | if [ x"$src" = x ] 108 | then 109 | echo "install: no input file specified" 110 | exit 1 111 | else 112 | true 113 | fi 114 | 115 | if [ x"$dir_arg" != x ]; then 116 | dst=$src 117 | src="" 118 | 119 | if [ -d $dst ]; then 120 | instcmd=: 121 | chmodcmd="" 122 | else 123 | instcmd=mkdir 124 | fi 125 | else 126 | 127 | # Waiting for this to be detected by the "$instcmd $src $dsttmp" command 128 | # might cause directories to be created, which would be especially bad 129 | # if $src (and thus $dsttmp) contains '*'. 130 | 131 | if [ -f $src -o -d $src ] 132 | then 133 | true 134 | else 135 | echo "install: $src does not exist" 136 | exit 1 137 | fi 138 | 139 | if [ x"$dst" = x ] 140 | then 141 | echo "install: no destination specified" 142 | exit 1 143 | else 144 | true 145 | fi 146 | 147 | # If destination is a directory, append the input filename; if your system 148 | # does not like double slashes in filenames, you may need to add some logic 149 | 150 | if [ -d $dst ] 151 | then 152 | dst="$dst"/`basename $src` 153 | else 154 | true 155 | fi 156 | fi 157 | 158 | ## this sed command emulates the dirname command 159 | dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` 160 | 161 | # Make sure that the destination directory exists. 162 | # this part is taken from Noah Friedman's mkinstalldirs script 163 | 164 | # Skip lots of stat calls in the usual case. 165 | if [ ! -d "$dstdir" ]; then 166 | defaultIFS=' 167 | ' 168 | IFS="${IFS-${defaultIFS}}" 169 | 170 | oIFS="${IFS}" 171 | # Some sh's can't handle IFS=/ for some reason. 172 | IFS='%' 173 | set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` 174 | IFS="${oIFS}" 175 | 176 | pathcomp='' 177 | 178 | while [ $# -ne 0 ] ; do 179 | pathcomp="${pathcomp}${1}" 180 | shift 181 | 182 | if [ ! -d "${pathcomp}" ] ; 183 | then 184 | $mkdirprog "${pathcomp}" 185 | else 186 | true 187 | fi 188 | 189 | pathcomp="${pathcomp}/" 190 | done 191 | fi 192 | 193 | if [ x"$dir_arg" != x ] 194 | then 195 | $doit $instcmd $dst && 196 | 197 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && 198 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && 199 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && 200 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi 201 | else 202 | 203 | # If we're going to rename the final executable, determine the name now. 204 | 205 | if [ x"$transformarg" = x ] 206 | then 207 | dstfile=`basename $dst` 208 | else 209 | dstfile=`basename $dst $transformbasename | 210 | sed $transformarg`$transformbasename 211 | fi 212 | 213 | # don't allow the sed command to completely eliminate the filename 214 | 215 | if [ x"$dstfile" = x ] 216 | then 217 | dstfile=`basename $dst` 218 | else 219 | true 220 | fi 221 | 222 | # Make a temp file name in the proper directory. 223 | 224 | dsttmp=$dstdir/#inst.$$# 225 | 226 | # Move or copy the file name to the temp name 227 | 228 | $doit $instcmd $src $dsttmp && 229 | 230 | trap "rm -f ${dsttmp}" 0 && 231 | 232 | # and set any options; do chmod last to preserve setuid bits 233 | 234 | # If any of these fail, we abort the whole thing. If we want to 235 | # ignore errors from any of these, just make sure not to ignore 236 | # errors from the above "$doit $instcmd $src $dsttmp" command. 237 | 238 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && 239 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && 240 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && 241 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && 242 | 243 | # Now rename the file to the real destination. 244 | 245 | $doit $rmcmd -f $dstdir/$dstfile && 246 | $doit $mvcmd $dsttmp $dstdir/$dstfile 247 | 248 | fi && 249 | 250 | 251 | exit 0 252 | -------------------------------------------------------------------------------- /nulib2/State.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NuLib2 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING. 6 | */ 7 | #ifndef NULIB2_STATE_H 8 | #define NULIB2_STATE_H 9 | 10 | #include "MiscStuff.h" 11 | #include "NufxLib.h" 12 | 13 | /* 14 | * Things you can tell NuLib2 to do. 15 | * 16 | * (Some debug code in NState_DebugDump() is sensitive to the order here.) 17 | */ 18 | typedef enum Command { 19 | kCommandUnknown = 0, 20 | kCommandAdd, 21 | kCommandDelete, 22 | kCommandExtract, 23 | kCommandExtractToPipe, 24 | kCommandListShort, 25 | kCommandListVerbose, 26 | kCommandListDebug, 27 | kCommandTest, 28 | kCommandHelp 29 | } Command; 30 | 31 | 32 | /* 33 | * Program-wide state. 34 | */ 35 | typedef struct NulibState { 36 | /* global goodness */ 37 | const char* programVersion; 38 | 39 | /* system-specific values */ 40 | char systemPathSeparator; 41 | char altSystemPathSeparator; 42 | 43 | /* pointer to archive we're working with */ 44 | NuArchive* pArchive; 45 | 46 | /* misc state */ 47 | Boolean suppressOutput; 48 | Boolean inputUnavailable; 49 | NuRecordIdx renameFromIdx; 50 | char* renameToStr; 51 | NuDataSink* pPipeSink; 52 | NuDataSink* pCommentSink; 53 | long matchCount; 54 | long totalLen; 55 | long totalCompLen; 56 | 57 | /* temp storage */ 58 | long tempPathnameAlloc; 59 | char* tempPathnameBuf; 60 | 61 | /* command-line options */ 62 | Command command; 63 | Boolean modUpdate; 64 | Boolean modFreshen; 65 | Boolean modRecurse; 66 | Boolean modJunkPaths; 67 | Boolean modNoCompression; 68 | Boolean modCompressDeflate; 69 | Boolean modCompressBzip2; 70 | Boolean modComments; 71 | Boolean modBinaryII; 72 | Boolean modConvertText; 73 | Boolean modConvertAll; 74 | Boolean modOverwriteExisting; 75 | Boolean modAddAsDisk; 76 | Boolean modPreserveType; 77 | Boolean modPreserveTypeExtended; 78 | 79 | const char* archiveFilename; 80 | char* const* filespecPointer; 81 | long filespecCount; 82 | } NulibState; 83 | 84 | NuError NState_Init(NulibState** ppState); 85 | NuError NState_ExtraInit(NulibState* pState); 86 | void NState_Free(NulibState* pState); 87 | #ifdef DEBUG_MSGS 88 | void NState_DebugDump(const NulibState* pState); 89 | #endif 90 | 91 | char NState_GetSystemPathSeparator(const NulibState* pState); 92 | char NState_GetAltSystemPathSeparator(const NulibState* pState); 93 | const char* NState_GetProgramVersion(const NulibState* pState); 94 | NuArchive* NState_GetNuArchive(const NulibState* pState); 95 | void NState_SetNuArchive(NulibState* pState, NuArchive* pArchive); 96 | 97 | Boolean NState_GetSuppressOutput(const NulibState* pState); 98 | void NState_SetSuppressOutput(NulibState* pState, Boolean doSuppress); 99 | Boolean NState_GetInputUnavailable(const NulibState* pState); 100 | void NState_SetInputUnavailable(NulibState* pState, Boolean isUnavailable); 101 | NuRecordIdx NState_GetRenameFromIdx(const NulibState* pState); 102 | void NState_SetRenameFromIdx(NulibState* pState, NuRecordIdx recordIdx); 103 | char* NState_GetRenameToStr(const NulibState* pState); 104 | void NState_SetRenameToStr(NulibState* pState, char* str); 105 | NuDataSink* NState_GetPipeSink(const NulibState* pState); 106 | NuDataSink* NState_GetCommentSink(const NulibState* pState); 107 | long NState_GetMatchCount(const NulibState* pState); 108 | void NState_SetMatchCount(NulibState* pState, long count); 109 | void NState_IncMatchCount(NulibState* pState); 110 | void NState_AddToTotals(NulibState* pState, long len, long compLen); 111 | void NState_GetTotals(NulibState* pState, long* pTotalLen, long* pTotalCompLen); 112 | 113 | long NState_GetTempPathnameLen(NulibState* pState); 114 | void NState_SetTempPathnameLen(NulibState* pState, long len); 115 | char* NState_GetTempPathnameBuf(NulibState* pState); 116 | 117 | Command NState_GetCommand(const NulibState* pState); 118 | void NState_SetCommand(NulibState* pState, Command cmd); 119 | const char* NState_GetArchiveFilename(const NulibState* pState); 120 | void NState_SetArchiveFilename(NulibState* pState, const char* archiveFilename); 121 | char* const* NState_GetFilespecPointer(const NulibState* pState); 122 | void NState_SetFilespecPointer(NulibState* pState, char* const* filespec); 123 | long NState_GetFilespecCount(const NulibState* pState); 124 | void NState_SetFilespecCount(NulibState* pState, long filespecCount); 125 | 126 | Boolean NState_GetModUpdate(const NulibState* pState); 127 | void NState_SetModUpdate(NulibState* pState, Boolean val); 128 | Boolean NState_GetModFreshen(const NulibState* pState); 129 | void NState_SetModFreshen(NulibState* pState, Boolean val); 130 | Boolean NState_GetModRecurse(const NulibState* pState); 131 | void NState_SetModRecurse(NulibState* pState, Boolean val); 132 | Boolean NState_GetModJunkPaths(const NulibState* pState); 133 | void NState_SetModJunkPaths(NulibState* pState, Boolean val); 134 | Boolean NState_GetModNoCompression(const NulibState* pState); 135 | void NState_SetModNoCompression(NulibState* pState, Boolean val); 136 | Boolean NState_GetModCompressDeflate(const NulibState* pState); 137 | void NState_SetModCompressDeflate(NulibState* pState, Boolean val); 138 | Boolean NState_GetModCompressBzip2(const NulibState* pState); 139 | void NState_SetModCompressBzip2(NulibState* pState, Boolean val); 140 | Boolean NState_GetModComments(const NulibState* pState); 141 | void NState_SetModComments(NulibState* pState, Boolean val); 142 | Boolean NState_GetModBinaryII(const NulibState* pState); 143 | void NState_SetModBinaryII(NulibState* pState, Boolean val); 144 | Boolean NState_GetModConvertText(const NulibState* pState); 145 | void NState_SetModConvertText(NulibState* pState, Boolean val); 146 | Boolean NState_GetModConvertAll(const NulibState* pState); 147 | void NState_SetModConvertAll(NulibState* pState, Boolean val); 148 | Boolean NState_GetModOverwriteExisting(const NulibState* pState); 149 | void NState_SetModOverwriteExisting(NulibState* pState, Boolean val); 150 | Boolean NState_GetModAddAsDisk(const NulibState* pState); 151 | void NState_SetModAddAsDisk(NulibState* pState, Boolean val); 152 | Boolean NState_GetModPreserveType(const NulibState* pState); 153 | void NState_SetModPreserveType(NulibState* pState, Boolean val); 154 | Boolean NState_GetModPreserveTypeExtended(const NulibState* pState); 155 | void NState_SetModPreserveTypeExtended(NulibState* pState, Boolean val); 156 | 157 | #endif /*NULIB2_STATE_H*/ 158 | -------------------------------------------------------------------------------- /nulib2/nulib2-man.txt: -------------------------------------------------------------------------------- 1 | NULIB2(1L) NULIB2(1L) 2 | 3 | 4 | 5 | NAME 6 | nulib2 - package and compress (archive) files 7 | 8 | SYNOPSIS 9 | nulib2 -command[modifiers] archive [ filenames ] 10 | 11 | DESCRIPTION 12 | nulib2 is a disk and file archiver for NuFX (ShrinkIt) files. It can 13 | add files to and extract files from .SHK, .BXY, .SEA (as created by 14 | GS/ShrinkIt), and .BSE files. In addition, it can extract files from 15 | .BNY and .BQY Binary II archives. 16 | 17 | When extracting, testing, or listing the contents of an archive, you 18 | can specify "-" for the archive name. The archive will be read from 19 | stdin. (If the archive is Binary II, you must specify the "-b" flag.) 20 | 21 | Filenames are considered case-sensitive. 22 | 23 | This man page contains a summary of available options. For full docu- 24 | mentation and the latest versions, visit http://www.nulib.com/. 25 | 26 | OPTIONS 27 | -h Get verbose help output. 28 | 29 | -a Add files to an archive. If the archive does not exist, a new 30 | one will be created. The list of files to add must be given. 31 | 32 | -d Delete files from an archive. The set of files to delete must 33 | be provided. 34 | 35 | -i Integrity test. If no files are listed, all files in the ar- 36 | chive are tested. 37 | 38 | -p Pipe extraction. All extracted files are written to stdout 39 | instead of a file on disk. Normal archive progress messages are 40 | suppressed. 41 | 42 | -t Table of contents. Provides a simple list of files in the ar- 43 | chive, one per line. 44 | 45 | -v Verbose table of contents. Output similar to what ShrinkIt dis- 46 | plays is shown. 47 | 48 | -x Extract files from an archive. If no files are listed, all 49 | files in the archive are extracted. 50 | 51 | MODIFIERS 52 | -c Comments. When extracting, comments will be displayed. When 53 | adding, you will be prompted to enter a one-line comment for 54 | every file. 55 | 56 | -e Preserve ProDOS file types. See the ProDOS File Type Preserva- 57 | tion document on http://www.nulib.com/ for details on how this 58 | works. 59 | 60 | -ee Preserve file types, using extended names. A file extension is 61 | appended to extracted files. Useful on operating systems like 62 | Windows, where filename extensions are important. When adding 63 | files, nulib2 will try to guess at correct file types by examin- 64 | ing the filename extension. 65 | 66 | -f Freshen files. When adding, files in the archive that are older 67 | than files on disk are "freshened", meaning that no new files 68 | are added, and files that are the same age or newer aren't 69 | touched. Works similarly when extracting. 70 | 71 | -j Junk directory names. Only the filename is kept; the rest of 72 | the pathname is thrown away. Empty directories aren't stored. 73 | Works when adding or extracting. 74 | 75 | -k Store files as disk images. Files that are a multiple of 512 76 | bytes will be added as disk images rather than normal files. 77 | This does not override the "-e" flag. 78 | 79 | -l Auto-convert text files. A reasonably smart algorithm is used 80 | to identify which files are text and which aren't during extrac- 81 | tion. It then converts whatever EOL indicator is being used by 82 | the text file into something appropriate for the current system. 83 | 84 | -ll Auto-convert all files. All files being extracted are consid- 85 | ered text, and will be converted. Don't use this unless you're 86 | sure you need it. 87 | 88 | -r Recurse into subdirectories. When adding, this causes nulib2 to 89 | descend into subdirectories and store all of the files found. 90 | When extracting, testing, or deleting, this causes the files 91 | listed to match against all records whose prefix matches, allow- 92 | ing you to extract, test, or delete entire subdirectories from 93 | the archive. 94 | 95 | -u Update files. When adding, files in the archive that are older 96 | than files on disk are updated. Files in the archive that are 97 | the same age or newer aren't touched. New files will be added. 98 | Works similarly when extracting. 99 | 100 | -b Binary II. Forces NuLib2 to treat the archive as Binary II. 101 | Useful for opening NuFX-in-BNY archives (.BXY) if you want to 102 | strip the wrapper off. You must specify this for Binary II ar- 103 | chives on stdin. 104 | 105 | -0 Don't use compression. Files added will be stored without com- 106 | pression. (Note that's dash-zero, not dash-oh.) 107 | 108 | -z Use "deflate" compression. This option is only available if 109 | libz was linked against. Archives created with this algorithm 110 | will not be usable on an Apple II. 111 | 112 | -zz Use "bzip2" compression. This option is only available if 113 | libbz2 was linked against. Archives created with this algorithm 114 | will not be usable on an Apple II. 115 | 116 | EXAMPLES 117 | A simple example: 118 | 119 | nulib2 a foo.shk * 120 | 121 | creates the archive foo.shk (assuming it doesn't exist) and stores all 122 | of the files in the current directory in it, in compressed form. 123 | 124 | If you wanted to add all the files in the current directory, as well as 125 | all files in all subdirectories, you could use: 126 | 127 | nulib2 ar foo.shk * 128 | 129 | to recursively descend into the directory tree. 130 | 131 | Using the command: 132 | 133 | nulib2 xe foo.shk 134 | 135 | would extract all files from foo.shk, preserving ProDOS file types. If 136 | you then used the command: 137 | 138 | nulib2 aer foo.shk * 139 | 140 | you would add the files, preserving the file types of anything that was 141 | extracted with the "-e" flag set. 142 | 143 | A handy way to look at text documents is to use: 144 | 145 | nulib2 xeel foo.shk 146 | 147 | to convert end-of-line terminators (e.g. CRLF to LF) as the files are 148 | being extracted. The "-ee" flag adds ".TXT" to all files with a ProDOS 149 | file type of TXT ($04). 150 | 151 | SEE ALSO 152 | compress(1), tar(1), zip(1L), unzip(1L), nulib(1L) 153 | 154 | BUGS 155 | Nah. 156 | 157 | AUTHOR 158 | Copyright (C) 2007 by Andy McFadden. All Rights Reserved. 159 | 160 | 161 | 162 | 08 Feb 2003 NULIB2(1L) 163 | -------------------------------------------------------------------------------- /nulib2/nulib2.1: -------------------------------------------------------------------------------- 1 | .\" nulib2.1 2 | .\" Copyright (C) 2000-2007 by Andy McFadden. All Rights Reserved. 3 | .\" This is free software; you can redistribute it and/or modify it under the 4 | .\" terms of the BSD License, see the file COPYING. 5 | .\" 6 | .\" The general structure of this man page was borrowed from "zip.1" in 7 | .\" the Red Hat Linux 6.0 distribution. 8 | .\" 9 | .\" Format with: nroff -man nulib2.1 | col -b > nulib2-man.txt 10 | .\" 11 | .TH NULIB2 1L "08 Feb 2003" 12 | .SH NAME 13 | nulib2 \- package and compress (archive) files 14 | .SH SYNOPSIS 15 | .B nulib2 16 | .RB \-command[modifiers] 17 | .I archive 18 | .I [ filenames ] 19 | .SH DESCRIPTION 20 | .I nulib2 21 | is a disk and file archiver for NuFX (ShrinkIt) files. It can add files 22 | to and extract files from 23 | .IR .SHK , 24 | .IR .BXY , 25 | .IR .SEA 26 | (as created by GS/ShrinkIt), and 27 | .I .BSE 28 | files. In addition, it can extract files from 29 | .IR .BNY 30 | and 31 | .IR .BQY 32 | Binary II archives. 33 | .LP 34 | When extracting, testing, or listing the contents of an archive, you can 35 | specify "-" for the archive name. The archive will be read from stdin. 36 | (If the archive is Binary II, you must specify the "-b" flag.) 37 | .LP 38 | Filenames are considered case-sensitive. 39 | .\" .LP 40 | .\" The 41 | .\" .I filenames 42 | .\" will be compared in a case-sensitive fashion. While this would be 43 | .\" inappropriate for most UNIX systems, it makes sense for Apple II archives, 44 | .\" because most Apple II filesystems are case-insensitive. 45 | .LP 46 | This man page contains a summary of available options. For full 47 | documentation and the latest versions, visit http://www.nulib.com/. 48 | .SH "OPTIONS" 49 | .TP 50 | .B \-h 51 | Get verbose help output. 52 | .TP 53 | .B \-a 54 | Add files to an archive. If the archive does not exist, a new one 55 | will be created. The list of files to add must be given. 56 | .TP 57 | .B \-d 58 | Delete files from an archive. The set of files to delete must be provided. 59 | .TP 60 | .B \-i 61 | Integrity test. If no files are listed, all files in the archive are 62 | tested. 63 | .TP 64 | .B \-p 65 | Pipe extraction. All extracted files are written to stdout instead of 66 | a file on disk. Normal archive progress messages are suppressed. 67 | .TP 68 | .B \-t 69 | Table of contents. Provides a simple list of files in the archive, one 70 | per line. 71 | .TP 72 | .B \-v 73 | Verbose table of contents. Output similar to what ShrinkIt displays is 74 | shown. 75 | .TP 76 | .B \-x 77 | Extract files from an archive. If no files are listed, all files in 78 | the archive are extracted. 79 | .\" There's also a '-g' command that does a verbose archive dump, but it's 80 | .\" only available if NufxLib was built with debugging enabled. 81 | .SH "MODIFIERS" 82 | .TP 83 | .B \-c 84 | Comments. When extracting, comments will be displayed. When adding, 85 | you will be prompted to enter a one-line comment for every file. 86 | .TP 87 | .B \-e 88 | Preserve ProDOS file types. See the ProDOS File Type Preservation document 89 | on http://www.nulib.com/ for details on how this works. 90 | .TP 91 | .B \-ee 92 | Preserve file types, using extended names. A file extension is appended 93 | to extracted files. Useful on operating systems like Windows, where 94 | filename extensions are important. When adding files, 95 | .I nulib2 96 | will try to guess at correct file types by examining the filename extension. 97 | .TP 98 | .B \-f 99 | Freshen files. When adding, files in the archive that are older than files 100 | on disk are "freshened", meaning that no new files are added, and files 101 | that are the same age or newer aren't touched. Works similarly when 102 | extracting. 103 | .TP 104 | .B \-j 105 | Junk directory names. Only the filename is kept; the rest of the pathname 106 | is thrown away. Empty directories aren't stored. Works when adding or 107 | extracting. 108 | .TP 109 | .B \-k 110 | Store files as disk images. Files that are a multiple of 512 bytes will 111 | be added as disk images rather than normal files. This does not override 112 | the "-e" flag. 113 | .TP 114 | .B \-l 115 | Auto-convert text files. A reasonably smart algorithm is used to identify 116 | which files are text and which aren't during extraction. It then converts 117 | whatever EOL 118 | indicator is being used by the text file into something appropriate for 119 | the current system. 120 | .TP 121 | .B \-ll 122 | Auto-convert all files. All files being extracted are considered text, 123 | and will be converted. Don't use this unless you're sure you need it. 124 | .TP 125 | .B \-r 126 | Recurse into subdirectories. When adding, this causes 127 | .I nulib2 128 | to descend into subdirectories and store all of the files found. When 129 | extracting, testing, or deleting, this causes the files listed to match 130 | against all records whose prefix matches, allowing you to extract, test, 131 | or delete entire subdirectories from the archive. 132 | .TP 133 | .B \-u 134 | Update files. When adding, files in the archive that are older than files 135 | on disk are updated. Files in the archive that are the same age or newer 136 | aren't touched. New files will be added. Works similarly when extracting. 137 | .TP 138 | .B \-b 139 | Binary II. Forces NuLib2 to treat the archive as Binary II. Useful for 140 | opening NuFX-in-BNY archives (.BXY) if you want to strip the wrapper off. 141 | You must specify this for Binary II archives on stdin. 142 | .TP 143 | .B \-0 144 | Don't use compression. Files added will be stored without compression. 145 | (Note that's dash-zero, not dash-oh.) 146 | .TP 147 | .B \-z 148 | Use "deflate" compression. This option is only available if libz was 149 | linked against. Archives created with this algorithm will not be 150 | usable on an Apple II. 151 | .TP 152 | .B \-zz 153 | Use "bzip2" compression. This option is only available if libbz2 was 154 | linked against. Archives created with this algorithm will not be 155 | usable on an Apple II. 156 | .SH "EXAMPLES" 157 | A simple example: 158 | .IP 159 | \fCnulib2 a foo.shk *\fP 160 | .LP 161 | creates the archive 162 | .I foo.shk 163 | (assuming it doesn't exist) and stores all of the files in the current 164 | directory in it, in compressed form. 165 | .LP 166 | If you wanted to add all the files in the current directory, as well as 167 | all files in all subdirectories, you could use: 168 | .IP 169 | \fCnulib2 ar foo.shk *\fP 170 | .LP 171 | to recursively descend into the directory tree. 172 | .LP 173 | Using the command: 174 | .IP 175 | \fCnulib2 xe foo.shk\fP 176 | .LP 177 | would extract all files from 178 | .I foo.shk, 179 | preserving ProDOS file types. If you then used the command: 180 | .IP 181 | \fCnulib2 aer foo.shk *\fP 182 | .LP 183 | you would add the files, 184 | preserving the file types of anything that was extracted with the 185 | "-e" flag set. 186 | .LP 187 | A handy way to look at text documents is to use: 188 | .IP 189 | \fCnulib2 xeel foo.shk\fP 190 | .LP 191 | to convert end-of-line terminators (e.g. CRLF to LF) as the files are 192 | being extracted. The "-ee" flag adds ".TXT" to all files with a ProDOS 193 | file type of TXT ($04). 194 | .SH "SEE ALSO" 195 | compress(1), 196 | tar(1), 197 | zip(1L), 198 | unzip(1L), 199 | nulib(1L) 200 | .SH BUGS 201 | Nah. 202 | .SH AUTHOR 203 | Copyright (C) 2007 by Andy McFadden. All Rights Reserved. 204 | .\" end of file 205 | -------------------------------------------------------------------------------- /nulib2/ChangeLog.txt: -------------------------------------------------------------------------------- 1 | 2017/09/21 ***** v3.1.0 shipped ***** 2 | 3 | 2015/12/26 fadden 4 | - Fix handling of entries with missing threads. 5 | - Improve handling of Mac OS X file type attributes. 6 | - Updated "recognized extensions" table. 7 | 8 | 2015/01/09 ***** v3.0.0 shipped ***** 9 | 10 | 2015/01/03 fadden 11 | - Mac OS X: get file/aux type from FinderInfo when adding files. 12 | - Mac OS X: set file type and creator when extracting from Binary ][. 13 | 14 | 2015/01/02 fadden 15 | - Distinguish Unicode and Mac OS Roman strings. 16 | 17 | 2014/12/22 fadden 18 | - Source code cleanup. 19 | 20 | 2014/10/30 ***** v2.2.2 shipped ***** 21 | 22 | 2014/10/28 fadden 23 | - Switched from CVS on sourceforge to github. 24 | - Updated configure scripts and makefiles. 25 | 26 | 2009/01/13 fadden 27 | - Handle files wrapped in Binary ][ by ProTERM. 28 | - (This was marked as 2.2.1, but not delivered as a formal release.) 29 | 30 | 2007/02/19 ***** v2.2.0 shipped ***** 31 | 32 | 2007/02/19 fadden 33 | - Enable "bad Mac" handling. 34 | - Switched from GPL to BSD license. 35 | 36 | 2006/02/18 ***** v2.1.1 shipped ***** 37 | 38 | 2006/02/18 fadden 39 | - Fix handling of MS-DOS reserved names. Besides handling names like 40 | "con", we also need to handle "con.foo.txt". 41 | 42 | 2005/09/17 ***** v2.1.0 shipped ***** 43 | 44 | 2004/10/11 ***** v2.0.3 shipped ***** 45 | 46 | 2004/03/10 ***** v2.0.2 shipped ***** 47 | 48 | 2003/10/16 ***** v2.0.1 shipped ***** 49 | 50 | 2003/03/18 ***** v2.0.0 shipped ***** 51 | 52 | 2003/02/18 fadden 53 | - When extracting with "-ee", disk images now have ".PO" appended. 54 | - Resurrected HandleAddNotFound(). 55 | - Switched to case-sensitive filename comparisons. 56 | 57 | 2003/02/08 fadden 58 | - Upped version to v2.0.0. 59 | - Many fixes to pathname handling: 60 | - Correctly handle '%' when preservation is OFF. 61 | - Accept 4-char extensions in '-ee' without risk of buffer overflow. 62 | - Fixed broken assert when converting long %xx names. 63 | - Store "AUX" as "%00AUX" when preserving Win32 names (vs. "_AUX"). 64 | - Always store files with ':' as path separator. 65 | - Recognize that some Win32 variants (Win2K and later at the least) 66 | will accept both '/' and '\' as pathname separators. 67 | - Correctly convert ".//foo" to "foo" instead of "/foo". 68 | - Tracked changes to NufxLib DataSource API. 69 | 70 | 2003/01/10 fadden 71 | - Check NufxLib "compiled" version against "linked" version. 72 | 73 | 2002/12/06 fadden 74 | - Made minor changes to allow linking NufxLib in as a DLL. 75 | 76 | 2002/10/20 ***** v1.1.0 shipped ***** 77 | 78 | 2002/10/10 fadden 79 | - added fancy help text (-h) 80 | 81 | 2002/10/09 fadden 82 | - added "-zz" flag to specify libbz2's "bzip2" compression 83 | 84 | 2002/10/08 fadden 85 | - added Binary II support 86 | 87 | 2002/09/30 fadden 88 | - added "-z" flag to specify zlib's "deflate" compression (the 89 | "secret" debug dump command is now -g) 90 | 91 | 2002/09/26 fadden 92 | - progress updater now shows "analyzing" for scan pass of SQ 93 | 94 | 2002/09/23 fadden 95 | - ran the code through valgrind; found and fixed some minor bugs 96 | 97 | 2002/09/20 fadden 98 | - pulled the sources out and started fiddling with them again 99 | - changed hard tabs to spaces 100 | 101 | 2000/05/22 ***** v1.0.1 shipped (no changes - version follows nufxlib) ***** 102 | 103 | 2000/05/18 ***** v1.0.0 shipped ***** 104 | 105 | 2000/05/18 fadden 106 | - added nulib2 to set of things stripped by "distbin" 107 | - updated version information to indicate final release 108 | 109 | 2000/03/25 ***** v0.6.1 shipped ***** 110 | 111 | 2000/03/25 fadden 112 | - Sheppy says Mac OS X PPC v1.02 and v1.2 work with minor SysDefs tweak 113 | 114 | 2000/03/05 ***** v0.6.0 (beta) shipped ***** 115 | 116 | 2000/03/05 fadden 117 | - don't call mktemp(), just pass template into NuOpenRW 118 | - removed DEBUG_MSGS from default CFLAGS 119 | - updated version information to indicate beta release 120 | 121 | 2000/02/24 ***** v0.5.1 shipped ***** 122 | 123 | 2000/02/20 changes from Scott Blackman 124 | - portability fixes for DJGPP under Win95 125 | 126 | 2000/02/17 changes from Devin Reade 127 | - portability fixes for BSD, AIX, and others 128 | - added "distbin" target 129 | 130 | 2000/02/09 ***** v0.5.0 (alpha) shipped ***** 131 | 132 | 2000/02/09 fadden 133 | - changed the comparison used when extracting/deleting a list of files 134 | from strcasecmp to strcmp, since NufxLib does case-sensitive compares. 135 | - fixed the percentage for files and archives larger than 21MB 136 | 137 | 2000/02/08 fadden 138 | - tweaked the BeOS/PPC config around a little 139 | - deleted some commas to make "gcc -pedantic" happy 140 | - changed version to x.y.z format here too 141 | - generalized the "aux" handling to include all MS-DOS device names 142 | 143 | 2000/02/06 fadden 144 | - include @CFLAGS@ in case somebody wants to override them 145 | 146 | 2000/02/06 ***** v0.4b shipped ***** 147 | 148 | 2000/02/06 fadden 149 | - added "install-shared" make target 150 | - portability fixes for HP/UX 151 | 152 | 2000/02/06 ***** v0.4a shipped ***** 153 | 154 | 2000/02/06 fadden 155 | - massaged configure.in for BeOS, and added some type casts for mwerks 156 | 157 | 2000/02/06 ***** v0.4 shipped ***** 158 | 159 | 2000/02/05 fadden 160 | - added "mkinstalldirs" to install target 161 | - added Win32 makefile 162 | - made a few implicit typecasts explicit for Visual C++'s benefit 163 | - change "aux" to "_aux", because FAT filesystems choke on it 164 | 165 | 2000/02/04 fadden 166 | - added Win32 recursive directory descent 167 | 168 | 2000/02/02 fadden 169 | - minor changes to get it working under Win32 (Visual C++ 6.0) 170 | - added --enable-dmalloc to configuration 171 | 172 | 2000/02/01 fadden 173 | - screen out leading "./", and junk the path if ".." shows up in path 174 | - don't try to add comments to records we're skipping 175 | - set kNuValueEOL appropriately for the current system 176 | 177 | 2000/01/29 ***** v0.3 shipped ***** 178 | 179 | 2000/01/29 fadden 180 | - added "make install" target, with the standard autoconf defines 181 | - added some examples to the man page 182 | 183 | 2000/01/28 fadden 184 | - merged "Kind" and "Type" columns in "v" output 185 | - display a '+' when doing EOL conversions on an extracted file 186 | 187 | 2000/01/26 fadden 188 | - added UI for allowing the user to ignore bad CRCs 189 | - implemented "-j" (junk paths) for add and extract 190 | - implemented "-c" (comments) for add and extract 191 | - added totals to bottom of "v" output 192 | 193 | 2000/01/25 fadden 194 | - when extracting without type preservation, append "_rsrc_" to 195 | resource forks 196 | 197 | 2000/01/24 fadden 198 | - added support for "-k" (add as disk image) flag 199 | 200 | 2000/01/24 ***** v0.2 shipped ***** 201 | 202 | 2000/01/22 fadden 203 | - added support for "-u" (update) and "-f" (freshen) flags 204 | - set file dates in AddFile call 205 | 206 | 2000/01/20 fadden 207 | - restructed the progress updater 208 | 209 | 2000/01/19 fadden 210 | - normalized SysDefs.h, changing UNIX to UNIX_LIKE and defining for BeOS 211 | - added "shared" target to makefile 212 | - added BeOS stuff to autoconf setup 213 | 214 | 2000/01/17 fadden 215 | - started recording locked/unlocked status 216 | - some BeOS/Metrowerks "it's not gcc" changes from Eric Shepherd 217 | - implemented "-s" (stomp existing) and "-0" (no compression) modifiers 218 | 219 | 2000/01/17 ***** v0.1 shipped ***** 220 | 221 | (much time passes) 222 | 223 | mid-1998 fadden 224 | - work begins 225 | 226 | -------------------------------------------------------------------------------- /nufxlib/Expand.c: -------------------------------------------------------------------------------- 1 | /* 2 | * NuFX archive manipulation library 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING-LIB. 6 | * 7 | * Expand a thread from an archive. 8 | */ 9 | #include "NufxLibPriv.h" 10 | 11 | 12 | /* 13 | * "Expand" an uncompressed thread. 14 | */ 15 | static NuError Nu_ExpandUncompressed(NuArchive* pArchive, 16 | const NuRecord* pRecord, const NuThread* pThread, FILE* infp, 17 | NuFunnel* pFunnel, uint16_t* pCrc) 18 | { 19 | NuError err; 20 | /*uint8_t* buffer = NULL;*/ 21 | uint32_t count, getsize; 22 | 23 | Assert(pArchive != NULL); 24 | Assert(pThread != NULL); 25 | Assert(infp != NULL); 26 | Assert(pFunnel != NULL); 27 | 28 | /* doesn't have to be same size as funnel, but it's not a bad idea */ 29 | /*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/ 30 | /*BailAlloc(buffer);*/ 31 | err = Nu_AllocCompressionBufferIFN(pArchive); 32 | BailError(err); 33 | 34 | /* quick assert for bad archive that should have been caught earlier */ 35 | /* (filename threads are uncompressed, but compThreadEOF is buf len) */ 36 | if (pThread->thThreadClass == kNuThreadClassData) 37 | Assert(pThread->actualThreadEOF == pThread->thCompThreadEOF); 38 | 39 | count = pThread->actualThreadEOF; 40 | 41 | while (count) { 42 | getsize = (count > kNuGenCompBufSize) ? kNuGenCompBufSize : count; 43 | 44 | err = Nu_FRead(infp, pArchive->compBuf, getsize); 45 | BailError(err); 46 | if (pCrc != NULL) 47 | *pCrc = Nu_CalcCRC16(*pCrc, pArchive->compBuf, getsize); 48 | err = Nu_FunnelWrite(pArchive, pFunnel, pArchive->compBuf, getsize); 49 | BailError(err); 50 | 51 | count -= getsize; 52 | } 53 | 54 | err = Nu_FunnelFlush(pArchive, pFunnel); 55 | BailError(err); 56 | 57 | bail: 58 | /*Nu_Free(pArchive, buffer);*/ 59 | return err; 60 | } 61 | 62 | /* 63 | * Copy the "raw" data out of the thread. Unlike the preceeding function, 64 | * this reads up to "thCompThreadEOF", and doesn't even try to compute a CRC. 65 | */ 66 | static NuError Nu_ExpandRaw(NuArchive* pArchive, const NuThread* pThread, 67 | FILE* infp, NuFunnel* pFunnel) 68 | { 69 | NuError err; 70 | /*uint8_t* buffer = NULL;*/ 71 | uint32_t count, getsize; 72 | 73 | Assert(pArchive != NULL); 74 | Assert(pThread != NULL); 75 | Assert(infp != NULL); 76 | Assert(pFunnel != NULL); 77 | 78 | /* doesn't have to be same size as funnel, but it's not a bad idea */ 79 | /*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/ 80 | /*BailAlloc(buffer);*/ 81 | err = Nu_AllocCompressionBufferIFN(pArchive); 82 | BailError(err); 83 | 84 | count = pThread->thCompThreadEOF; 85 | 86 | while (count) { 87 | getsize = (count > kNuGenCompBufSize) ? kNuGenCompBufSize : count; 88 | 89 | err = Nu_FRead(infp, pArchive->compBuf, getsize); 90 | BailError(err); 91 | err = Nu_FunnelWrite(pArchive, pFunnel, pArchive->compBuf, getsize); 92 | BailError(err); 93 | 94 | count -= getsize; 95 | } 96 | 97 | err = Nu_FunnelFlush(pArchive, pFunnel); 98 | BailError(err); 99 | 100 | bail: 101 | /*Nu_Free(pArchive, buffer);*/ 102 | return err; 103 | } 104 | 105 | 106 | /* 107 | * Expand a thread from "infp" to "pFunnel", using the compression 108 | * and stream length specified by "pThread". 109 | */ 110 | NuError Nu_ExpandStream(NuArchive* pArchive, const NuRecord* pRecord, 111 | const NuThread* pThread, FILE* infp, NuFunnel* pFunnel) 112 | { 113 | NuError err = kNuErrNone; 114 | uint16_t calcCrc; 115 | uint16_t* pCalcCrc; 116 | 117 | if (!pThread->thThreadEOF && !pThread->thCompThreadEOF) { 118 | /* somebody stored an empty file! */ 119 | goto done; 120 | } 121 | 122 | /* 123 | * A brief history of the "threadCRC" field in the thread header: 124 | * record versions 0 and 1 didn't use the threadCRC field 125 | * record version 2 put the CRC of the compressed data in threadCRC 126 | * record version 3 put the CRC of the uncompressed data in threadCRC 127 | * 128 | * P8 ShrinkIt uses v1, GSHK uses v3. If something ever shipped with 129 | * v2, it didn't last long enough to leave an impression, so I'm not 130 | * going to support it. BTW, P8 ShrinkIt always uses LZW/1, which 131 | * puts a CRC in the compressed stream. Your uncompressed data is, 132 | * unfortunately, unprotected before v3. 133 | */ 134 | calcCrc = kNuInitialThreadCRC; 135 | pCalcCrc = NULL; 136 | if (Nu_ThreadHasCRC(pRecord->recVersionNumber, NuGetThreadID(pThread)) && 137 | !pArchive->valIgnoreCRC) 138 | { 139 | pCalcCrc = &calcCrc; 140 | } 141 | 142 | err = Nu_ProgressDataExpandPrep(pArchive, pFunnel, pThread); 143 | BailError(err); 144 | 145 | /* 146 | * If we're not expanding the data, use a simple copier. 147 | */ 148 | if (!Nu_FunnelGetDoExpand(pFunnel)) { 149 | Nu_FunnelSetProgressState(pFunnel, kNuProgressCopying); 150 | err = Nu_ExpandRaw(pArchive, pThread, infp, pFunnel); 151 | BailError(err); 152 | goto done; 153 | } 154 | 155 | Nu_FunnelSetProgressState(pFunnel, kNuProgressExpanding); 156 | switch (pThread->thThreadFormat) { 157 | case kNuThreadFormatUncompressed: 158 | Nu_FunnelSetProgressState(pFunnel, kNuProgressCopying); 159 | err = Nu_ExpandUncompressed(pArchive, pRecord, pThread, infp, pFunnel, 160 | pCalcCrc); 161 | break; 162 | #ifdef ENABLE_SQ 163 | case kNuThreadFormatHuffmanSQ: 164 | err = Nu_ExpandHuffmanSQ(pArchive, pRecord, pThread, infp, pFunnel, 165 | pCalcCrc); 166 | break; 167 | #endif 168 | #ifdef ENABLE_LZW 169 | case kNuThreadFormatLZW1: 170 | case kNuThreadFormatLZW2: 171 | err = Nu_ExpandLZW(pArchive, pRecord, pThread, infp, pFunnel, pCalcCrc); 172 | break; 173 | #endif 174 | #ifdef ENABLE_LZC 175 | case kNuThreadFormatLZC12: 176 | case kNuThreadFormatLZC16: 177 | err = Nu_ExpandLZC(pArchive, pRecord, pThread, infp, pFunnel, pCalcCrc); 178 | break; 179 | #endif 180 | #ifdef ENABLE_DEFLATE 181 | case kNuThreadFormatDeflate: 182 | err = Nu_ExpandDeflate(pArchive, pRecord, pThread, infp, pFunnel, 183 | pCalcCrc); 184 | break; 185 | #endif 186 | #ifdef ENABLE_BZIP2 187 | case kNuThreadFormatBzip2: 188 | err = Nu_ExpandBzip2(pArchive, pRecord, pThread, infp, pFunnel, 189 | pCalcCrc); 190 | break; 191 | #endif 192 | default: 193 | err = kNuErrBadFormat; 194 | Nu_ReportError(NU_BLOB, err, 195 | "compression format %u not supported", pThread->thThreadFormat); 196 | break; 197 | } 198 | BailError(err); 199 | 200 | err = Nu_FunnelFlush(pArchive, pFunnel); 201 | BailError(err); 202 | 203 | /* 204 | * If we have a CRC to check, check it. 205 | */ 206 | if (pCalcCrc != NULL) { 207 | if (calcCrc != pThread->thThreadCRC) { 208 | if (!Nu_ShouldIgnoreBadCRC(pArchive, pRecord, kNuErrBadThreadCRC)) { 209 | err = kNuErrBadDataCRC; 210 | Nu_ReportError(NU_BLOB, err, "expected 0x%04x, got 0x%04x", 211 | pThread->thThreadCRC, calcCrc); 212 | goto bail; 213 | } 214 | } else { 215 | DBUG(("--- thread CRCs match\n")); 216 | } 217 | } 218 | 219 | done: 220 | /* make sure we send a final "success" progress message at 100% */ 221 | (void) Nu_FunnelSetProgressState(pFunnel, kNuProgressDone); 222 | err = Nu_FunnelSendProgressUpdate(pArchive, pFunnel); 223 | BailError(err); 224 | 225 | bail: 226 | return err; 227 | } 228 | 229 | -------------------------------------------------------------------------------- /nufxlib/configure.in: -------------------------------------------------------------------------------- 1 | dnl NuFX archive manipulation library 2 | dnl Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 3 | dnl This is free software; you can redistribute it and/or modify it under the 4 | dnl terms of the BSD License, see the file COPYING-LIB. 5 | dnl 6 | dnl Process this file with autoconf to produce a configure script. 7 | 8 | AC_INIT(NufxLibPriv.h) 9 | AC_CONFIG_HEADER(config.h) 10 | 11 | dnl Checks for programs. 12 | AC_CANONICAL_HOST 13 | dnl AC_PROG_AWK 14 | AC_PROG_CC 15 | AC_PROG_INSTALL 16 | AC_PROG_MAKE_SET 17 | AC_PROG_RANLIB 18 | 19 | NUFX_VERSION=3.1.0 20 | AC_SUBST(NUFX_VERSION) 21 | 22 | 23 | dnl Checks for header files. 24 | AC_CHECK_HEADERS(fcntl.h malloc.h stdlib.h sys/stat.h sys/time.h sys/types.h \ 25 | sys/utime.h unistd.h utime.h) 26 | 27 | LIBS="" 28 | 29 | dnl Checks for typedefs, structures, and compiler characteristics. 30 | AC_C_CONST 31 | AC_C_INLINE 32 | AC_TYPE_MODE_T 33 | AC_TYPE_OFF_T 34 | AC_TYPE_SIZE_T 35 | AC_STRUCT_TM 36 | 37 | dnl Checks for library functions. 38 | AC_CHECK_FUNCS(fdopen ftruncate memmove mkdir mkstemp mktime timelocal \ 39 | localtime_r snprintf strcasecmp strncasecmp strtoul strerror vsnprintf) 40 | 41 | dnl Kent says: snprintf doesn't always have a declaration 42 | AC_MSG_CHECKING(if snprintf is declared) 43 | AC_CACHE_VAL(nufxlib_cv_snprintf_in_header, [ 44 | AC_EGREP_HEADER(snprintf, stdio.h, 45 | [nufxlib_cv_snprintf_in_header=yes], 46 | [nufxlib_cv_snprintf_in_header=no]) 47 | ]) 48 | if test $nufxlib_cv_snprintf_in_header = "yes"; then 49 | AC_DEFINE(SNPRINTF_DECLARED, [], [Define it SNPRINTF is declared in stdio.h.]) 50 | fi 51 | AC_MSG_RESULT($nufxlib_cv_snprintf_in_header) 52 | 53 | dnl Kent says: vsnprintf doesn't always have a declaration 54 | AC_MSG_CHECKING(if vsnprintf is declared) 55 | AC_CACHE_VAL(nufxlib_cv_vsnprintf_in_header, [ 56 | AC_EGREP_HEADER(vsnprintf, stdio.h, 57 | [nufxlib_cv_vsnprintf_in_header=yes], 58 | [nufxlib_cv_vsnprintf_in_header=no]) 59 | ]) 60 | if test $nufxlib_cv_vsnprintf_in_header = "yes"; then 61 | AC_DEFINE(VSNPRINTF_DECLARED, [], [Define if VSNPRINTF is declared in stdio.h.]) 62 | fi 63 | AC_MSG_RESULT($nufxlib_cv_vsnprintf_in_header) 64 | 65 | dnl if we're using gcc, include gcc-specific warning flags 66 | if test -z "$GCC"; then 67 | BUILD_FLAGS='$(OPT)' 68 | else 69 | BUILD_FLAGS='$(OPT) $(GCC_FLAGS)' 70 | fi 71 | 72 | dnl --------------------------------------------------------------------------- 73 | dnl Some host-specific stuff. Variables you can test (set by the 74 | dnl AC_CANONICAL_HOST call earlier) look like this: 75 | dnl 76 | dnl $host = i686-pc-linux-gnu 77 | dnl $host_cpu = i686 78 | dnl $host_vendor = pc 79 | dnl $host_os = linux-gnu 80 | 81 | dnl Figure out what the build and link flags should be; different for BeOS. 82 | dnl (Should really use the auto-shared-lib stuff, but that adds a whole 83 | dnl bunch of stuff.) 84 | SHARE_FLAGS='-shared' 85 | if test "$host_cpu" = "powerpc" -a "$host_os" = "beos"; then 86 | dnl BeOS/PPC, with Metrowerks compiler 87 | CC=cc 88 | GCC= 89 | CFLAGS='-proc 603 -opt full' 90 | SHARE_FLAGS='-shared -nostdlib' 91 | echo "forcing CC to \"$CC\" and CFLAGS to \"$CFLAGS\"" 92 | elif test "$host_os" = "beos"; then 93 | dnl BeOS/x86 94 | SHARE_FLAGS='-nostartfiles -Xlinker -soname="$@"' 95 | fi 96 | 97 | AC_SUBST(BUILD_FLAGS) 98 | AC_SUBST(SHARE_FLAGS) 99 | 100 | dnl BeOS doesn't like /usr/local/include, and gets feisty about it. If libdir 101 | dnl and includedir are set to defaults, replace them with BeOS values. This 102 | dnl might be going a little too far... 103 | if test "$host_os" = "beos"; then 104 | if test "$prefix" = "NONE" -a \ 105 | "$includedir" = '${prefix}/include' -a \ 106 | "$libdir" = '${exec_prefix}/lib' -a \ 107 | "$bindir" = '${exec_prefix}/bin' -a \ 108 | "$mandir" = '${prefix}/man' 109 | then 110 | echo replacing install locations with BeOS values 111 | prefix=/boot 112 | includedir='${prefix}/develop/headers' 113 | libdir='${exec_prefix}/home/config/lib' 114 | bindir='${exec_prefix}/home/config/bin' 115 | mandir='/tmp' 116 | AC_SUBST(prefix) 117 | AC_SUBST(includedir) 118 | AC_SUBST(libdir) 119 | AC_SUBST(bindir) 120 | AC_SUBST(mandir) 121 | fi 122 | fi 123 | 124 | 125 | 126 | dnl Test to see if sprintf does something reasonable. I'm going to assume 127 | dnl that vsprintf and (if available) vsnprintf return the same thing. 128 | AC_MSG_CHECKING(if sprintf returns int) 129 | AC_CACHE_VAL(nufxlib_cv_sprintf_returns_int, [ 130 | AC_TRY_RUN([ 131 | #include 132 | int main(void) 133 | { 134 | int count; 135 | char buf[8]; 136 | count = sprintf(buf, "123"); /* should return three */ 137 | return count != 3; 138 | } 139 | ], 140 | [nufxlib_cv_sprintf_returns_int=yes], [nufxlib_cv_sprintf_returns_int=no], 141 | [nufxlib_cv_sprintf_returns_int=no]) 142 | ]) 143 | 144 | if test $nufxlib_cv_sprintf_returns_int = "yes"; then 145 | AC_DEFINE(SPRINTF_RETURNS_INT, [], [Define if sprintf returns an int.]) 146 | fi 147 | AC_MSG_RESULT($nufxlib_cv_sprintf_returns_int) 148 | 149 | dnl 150 | dnl Allow selective disabling of compression algorithms. By default, 151 | dnl all are enabled. We do a little extra work for libz and libbz2 152 | dnl because they're not built in. 153 | dnl 154 | dnl If we're creating a shared library, we need to explicitly link 155 | dnl against libz and/or libbz2 when those features are enabled. 156 | dnl 157 | 158 | AC_ARG_ENABLE(sq, 159 | [ --disable-sq disable SQ compression], 160 | [ ], [ enable_sq=yes ]) 161 | if test $enable_sq = "yes"; then 162 | AC_DEFINE(ENABLE_SQ, [], [Define to include SQ (Huffman+RLE) compression.]) 163 | fi 164 | 165 | AC_ARG_ENABLE(lzw, 166 | [ --disable-lzw disable LZW/1 and LZW/2 compression], 167 | [ ], [ enable_lzw=yes ]) 168 | if test $enable_lzw = "yes"; then 169 | AC_DEFINE(ENABLE_LZW, [], [Define to include LZW (ShrinkIt LZW/1 and LZW/2) compression.]) 170 | fi 171 | 172 | AC_ARG_ENABLE(lzc, 173 | [ --disable-lzc disable 12- and 16-bit LZC compression], 174 | [ ], [ enable_lzc=yes ]) 175 | if test $enable_lzc = "yes"; then 176 | AC_DEFINE(ENABLE_LZC, [], [Define to include LZC (12-bit and 16-bit UNIX "compress") compression.]) 177 | fi 178 | 179 | AC_ARG_ENABLE(deflate, 180 | [ --disable-deflate disable zlib deflate compression], 181 | [ ], [ enable_deflate=yes ]) 182 | if test $enable_deflate = "yes"; then 183 | dnl Check for zlib. Make sure it comes with zlib.h. 184 | got_zlibh=false 185 | AC_CHECK_LIB(z, deflate, got_libz=true, got_libz=false) 186 | if $got_libz; then 187 | AC_CHECK_HEADER(zlib.h, got_zlibh=true LIBS="$LIBS -lz") 188 | fi 189 | if $got_zlibh; then 190 | echo " (found libz and zlib.h, enabling deflate)" 191 | AC_DEFINE(ENABLE_DEFLATE, [], [Define to include deflate (zlib) compression (also need -l in Makefile).]) 192 | else 193 | echo " (couldn't find libz and zlib.h, not enabling deflate)" 194 | fi 195 | fi 196 | 197 | AC_ARG_ENABLE(bzip2, 198 | [ --enable-bzip2 enable libbz2 bzip2 compression], 199 | [ ], [ enable_bzip2=no ]) 200 | if test $enable_bzip2 = "yes"; then 201 | dnl Check for libbz2. Make sure it comes with bzlib.h. 202 | dnl AC_CHECK_LIB(bz2, BZ2_bzCompress, 203 | dnl AC_CHECK_HEADER(bzlib.h, AC_DEFINE(ENABLE_BZIP2) LIBS="$LIBS -lbz2")) 204 | got_bzlibh=false 205 | AC_CHECK_LIB(bz2, BZ2_bzCompress, got_libbz=true, got_libbz=false) 206 | if $got_libbz; then 207 | AC_CHECK_HEADER(bzlib.h, got_bzlibh=true LIBS="$LIBS -lbz2") 208 | fi 209 | if $got_bzlibh; then 210 | echo " (found libbz2 and bzlib.h, enabling bzip2)" 211 | AC_DEFINE(ENABLE_BZIP2, [], [Define to include bzip2 (libbz2) compression (also need -l in Makefile).]) 212 | else 213 | echo " (couldn't find libbz2 and bzlib.h, not enabling bzip2)" 214 | fi 215 | fi 216 | 217 | 218 | AC_ARG_ENABLE(dmalloc, [ --enable-dmalloc do dmalloc stuff], 219 | [ echo "--- enabling dmalloc"; 220 | LIBS="$LIBS -L/usr/local/lib -ldmalloc"; AC_DEFINE(USE_DMALLOC, [], [Define if we want to use the dmalloc library (also need -l in Makefile).]) ]) 221 | 222 | AC_OUTPUT(Makefile samples/Makefile nufxlib.pc) 223 | -------------------------------------------------------------------------------- /nufxlib/INSTALL: -------------------------------------------------------------------------------- 1 | Basic Installation 2 | ================== 3 | 4 | These are generic installation instructions. 5 | 6 | The `configure' shell script attempts to guess correct values for 7 | various system-dependent variables used during compilation. It uses 8 | those values to create a `Makefile' in each directory of the package. 9 | It may also create one or more `.h' files containing system-dependent 10 | definitions. Finally, it creates a shell script `config.status' that 11 | you can run in the future to recreate the current configuration, a file 12 | `config.cache' that saves the results of its tests to speed up 13 | reconfiguring, and a file `config.log' containing compiler output 14 | (useful mainly for debugging `configure'). 15 | 16 | If you need to do unusual things to compile the package, please try 17 | to figure out how `configure' could check whether to do them, and mail 18 | diffs or instructions to the address given in the `README' so they can 19 | be considered for the next release. If at some point `config.cache' 20 | contains results you don't want to keep, you may remove or edit it. 21 | 22 | The file `configure.in' is used to create `configure' by a program 23 | called `autoconf'. You only need `configure.in' if you want to change 24 | it or regenerate `configure' using a newer version of `autoconf'. 25 | 26 | The simplest way to compile this package is: 27 | 28 | 1. `cd' to the directory containing the package's source code and type 29 | `./configure' to configure the package for your system. If you're 30 | using `csh' on an old version of System V, you might need to type 31 | `sh ./configure' instead to prevent `csh' from trying to execute 32 | `configure' itself. 33 | 34 | Running `configure' takes awhile. While running, it prints some 35 | messages telling which features it is checking for. 36 | 37 | 2. Type `make' to compile the package. 38 | 39 | 3. Optionally, type `make check' to run any self-tests that come with 40 | the package. 41 | 42 | 4. Type `make install' to install the programs and any data files and 43 | documentation. 44 | 45 | 5. You can remove the program binaries and object files from the 46 | source code directory by typing `make clean'. To also remove the 47 | files that `configure' created (so you can compile the package for 48 | a different kind of computer), type `make distclean'. There is 49 | also a `make maintainer-clean' target, but that is intended mainly 50 | for the package's developers. If you use it, you may have to get 51 | all sorts of other programs in order to regenerate files that came 52 | with the distribution. 53 | 54 | Compilers and Options 55 | ===================== 56 | 57 | Some systems require unusual options for compilation or linking that 58 | the `configure' script does not know about. You can give `configure' 59 | initial values for variables by setting them in the environment. Using 60 | a Bourne-compatible shell, you can do that on the command line like 61 | this: 62 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure 63 | 64 | Or on systems that have the `env' program, you can do it like this: 65 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure 66 | 67 | Compiling For Multiple Architectures 68 | ==================================== 69 | 70 | You can compile the package for more than one kind of computer at the 71 | same time, by placing the object files for each architecture in their 72 | own directory. To do this, you must use a version of `make' that 73 | supports the `VPATH' variable, such as GNU `make'. `cd' to the 74 | directory where you want the object files and executables to go and run 75 | the `configure' script. `configure' automatically checks for the 76 | source code in the directory that `configure' is in and in `..'. 77 | 78 | If you have to use a `make' that does not supports the `VPATH' 79 | variable, you have to compile the package for one architecture at a time 80 | in the source code directory. After you have installed the package for 81 | one architecture, use `make distclean' before reconfiguring for another 82 | architecture. 83 | 84 | Installation Names 85 | ================== 86 | 87 | By default, `make install' will install the package's files in 88 | `/usr/local/bin', `/usr/local/man', etc. You can specify an 89 | installation prefix other than `/usr/local' by giving `configure' the 90 | option `--prefix=PATH'. 91 | 92 | You can specify separate installation prefixes for 93 | architecture-specific files and architecture-independent files. If you 94 | give `configure' the option `--exec-prefix=PATH', the package will use 95 | PATH as the prefix for installing programs and libraries. 96 | Documentation and other data files will still use the regular prefix. 97 | 98 | In addition, if you use an unusual directory layout you can give 99 | options like `--bindir=PATH' to specify different values for particular 100 | kinds of files. Run `configure --help' for a list of the directories 101 | you can set and what kinds of files go in them. 102 | 103 | If the package supports it, you can cause programs to be installed 104 | with an extra prefix or suffix on their names by giving `configure' the 105 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 106 | 107 | Optional Features 108 | ================= 109 | 110 | Some packages pay attention to `--enable-FEATURE' options to 111 | `configure', where FEATURE indicates an optional part of the package. 112 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 113 | is something like `gnu-as' or `x' (for the X Window System). The 114 | `README' should mention any `--enable-' and `--with-' options that the 115 | package recognizes. 116 | 117 | For packages that use the X Window System, `configure' can usually 118 | find the X include and library files automatically, but if it doesn't, 119 | you can use the `configure' options `--x-includes=DIR' and 120 | `--x-libraries=DIR' to specify their locations. 121 | 122 | Specifying the System Type 123 | ========================== 124 | 125 | There may be some features `configure' can not figure out 126 | automatically, but needs to determine by the type of host the package 127 | will run on. Usually `configure' can figure that out, but if it prints 128 | a message saying it can not guess the host type, give it the 129 | `--host=TYPE' option. TYPE can either be a short name for the system 130 | type, such as `sun4', or a canonical name with three fields: 131 | CPU-COMPANY-SYSTEM 132 | 133 | See the file `config.sub' for the possible values of each field. If 134 | `config.sub' isn't included in this package, then this package doesn't 135 | need to know the host type. 136 | 137 | If you are building compiler tools for cross-compiling, you can also 138 | use the `--target=TYPE' option to select the type of system they will 139 | produce code for and the `--build=TYPE' option to select the type of 140 | system on which you are compiling the package. 141 | 142 | Sharing Defaults 143 | ================ 144 | 145 | If you want to set default values for `configure' scripts to share, 146 | you can create a site shell script called `config.site' that gives 147 | default values for variables like `CC', `cache_file', and `prefix'. 148 | `configure' looks for `PREFIX/share/config.site' if it exists, then 149 | `PREFIX/etc/config.site' if it exists. Or, you can set the 150 | `CONFIG_SITE' environment variable to the location of the site script. 151 | A warning: not all `configure' scripts look for a site script. 152 | 153 | Operation Controls 154 | ================== 155 | 156 | `configure' recognizes the following options to control how it 157 | operates. 158 | 159 | `--cache-file=FILE' 160 | Use and save the results of the tests in FILE instead of 161 | `./config.cache'. Set FILE to `/dev/null' to disable caching, for 162 | debugging `configure'. 163 | 164 | `--help' 165 | Print a summary of the options to `configure', and exit. 166 | 167 | `--quiet' 168 | `--silent' 169 | `-q' 170 | Do not print messages saying which checks are being made. To 171 | suppress all normal output, redirect it to `/dev/null' (any error 172 | messages will still be shown). 173 | 174 | `--srcdir=DIR' 175 | Look for the package's source code in directory DIR. Usually 176 | `configure' can determine that directory automatically. 177 | 178 | `--version' 179 | Print the version of Autoconf used to generate the `configure' 180 | script, and exit. 181 | 182 | `configure' also accepts some other, not widely useful, options. 183 | 184 | -------------------------------------------------------------------------------- /nulib2/INSTALL: -------------------------------------------------------------------------------- 1 | Basic Installation 2 | ================== 3 | 4 | These are generic installation instructions. 5 | 6 | The `configure' shell script attempts to guess correct values for 7 | various system-dependent variables used during compilation. It uses 8 | those values to create a `Makefile' in each directory of the package. 9 | It may also create one or more `.h' files containing system-dependent 10 | definitions. Finally, it creates a shell script `config.status' that 11 | you can run in the future to recreate the current configuration, a file 12 | `config.cache' that saves the results of its tests to speed up 13 | reconfiguring, and a file `config.log' containing compiler output 14 | (useful mainly for debugging `configure'). 15 | 16 | If you need to do unusual things to compile the package, please try 17 | to figure out how `configure' could check whether to do them, and mail 18 | diffs or instructions to the address given in the `README' so they can 19 | be considered for the next release. If at some point `config.cache' 20 | contains results you don't want to keep, you may remove or edit it. 21 | 22 | The file `configure.in' is used to create `configure' by a program 23 | called `autoconf'. You only need `configure.in' if you want to change 24 | it or regenerate `configure' using a newer version of `autoconf'. 25 | 26 | The simplest way to compile this package is: 27 | 28 | 1. `cd' to the directory containing the package's source code and type 29 | `./configure' to configure the package for your system. If you're 30 | using `csh' on an old version of System V, you might need to type 31 | `sh ./configure' instead to prevent `csh' from trying to execute 32 | `configure' itself. 33 | 34 | Running `configure' takes awhile. While running, it prints some 35 | messages telling which features it is checking for. 36 | 37 | 2. Type `make' to compile the package. 38 | 39 | 3. Optionally, type `make check' to run any self-tests that come with 40 | the package. 41 | 42 | 4. Type `make install' to install the programs and any data files and 43 | documentation. 44 | 45 | 5. You can remove the program binaries and object files from the 46 | source code directory by typing `make clean'. To also remove the 47 | files that `configure' created (so you can compile the package for 48 | a different kind of computer), type `make distclean'. There is 49 | also a `make maintainer-clean' target, but that is intended mainly 50 | for the package's developers. If you use it, you may have to get 51 | all sorts of other programs in order to regenerate files that came 52 | with the distribution. 53 | 54 | Compilers and Options 55 | ===================== 56 | 57 | Some systems require unusual options for compilation or linking that 58 | the `configure' script does not know about. You can give `configure' 59 | initial values for variables by setting them in the environment. Using 60 | a Bourne-compatible shell, you can do that on the command line like 61 | this: 62 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure 63 | 64 | Or on systems that have the `env' program, you can do it like this: 65 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure 66 | 67 | Compiling For Multiple Architectures 68 | ==================================== 69 | 70 | You can compile the package for more than one kind of computer at the 71 | same time, by placing the object files for each architecture in their 72 | own directory. To do this, you must use a version of `make' that 73 | supports the `VPATH' variable, such as GNU `make'. `cd' to the 74 | directory where you want the object files and executables to go and run 75 | the `configure' script. `configure' automatically checks for the 76 | source code in the directory that `configure' is in and in `..'. 77 | 78 | If you have to use a `make' that does not supports the `VPATH' 79 | variable, you have to compile the package for one architecture at a time 80 | in the source code directory. After you have installed the package for 81 | one architecture, use `make distclean' before reconfiguring for another 82 | architecture. 83 | 84 | Installation Names 85 | ================== 86 | 87 | By default, `make install' will install the package's files in 88 | `/usr/local/bin', `/usr/local/man', etc. You can specify an 89 | installation prefix other than `/usr/local' by giving `configure' the 90 | option `--prefix=PATH'. 91 | 92 | You can specify separate installation prefixes for 93 | architecture-specific files and architecture-independent files. If you 94 | give `configure' the option `--exec-prefix=PATH', the package will use 95 | PATH as the prefix for installing programs and libraries. 96 | Documentation and other data files will still use the regular prefix. 97 | 98 | In addition, if you use an unusual directory layout you can give 99 | options like `--bindir=PATH' to specify different values for particular 100 | kinds of files. Run `configure --help' for a list of the directories 101 | you can set and what kinds of files go in them. 102 | 103 | If the package supports it, you can cause programs to be installed 104 | with an extra prefix or suffix on their names by giving `configure' the 105 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 106 | 107 | Optional Features 108 | ================= 109 | 110 | Some packages pay attention to `--enable-FEATURE' options to 111 | `configure', where FEATURE indicates an optional part of the package. 112 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 113 | is something like `gnu-as' or `x' (for the X Window System). The 114 | `README' should mention any `--enable-' and `--with-' options that the 115 | package recognizes. 116 | 117 | For packages that use the X Window System, `configure' can usually 118 | find the X include and library files automatically, but if it doesn't, 119 | you can use the `configure' options `--x-includes=DIR' and 120 | `--x-libraries=DIR' to specify their locations. 121 | 122 | Specifying the System Type 123 | ========================== 124 | 125 | There may be some features `configure' can not figure out 126 | automatically, but needs to determine by the type of host the package 127 | will run on. Usually `configure' can figure that out, but if it prints 128 | a message saying it can not guess the host type, give it the 129 | `--host=TYPE' option. TYPE can either be a short name for the system 130 | type, such as `sun4', or a canonical name with three fields: 131 | CPU-COMPANY-SYSTEM 132 | 133 | See the file `config.sub' for the possible values of each field. If 134 | `config.sub' isn't included in this package, then this package doesn't 135 | need to know the host type. 136 | 137 | If you are building compiler tools for cross-compiling, you can also 138 | use the `--target=TYPE' option to select the type of system they will 139 | produce code for and the `--build=TYPE' option to select the type of 140 | system on which you are compiling the package. 141 | 142 | Sharing Defaults 143 | ================ 144 | 145 | If you want to set default values for `configure' scripts to share, 146 | you can create a site shell script called `config.site' that gives 147 | default values for variables like `CC', `cache_file', and `prefix'. 148 | `configure' looks for `PREFIX/share/config.site' if it exists, then 149 | `PREFIX/etc/config.site' if it exists. Or, you can set the 150 | `CONFIG_SITE' environment variable to the location of the site script. 151 | A warning: not all `configure' scripts look for a site script. 152 | 153 | Operation Controls 154 | ================== 155 | 156 | `configure' recognizes the following options to control how it 157 | operates. 158 | 159 | `--cache-file=FILE' 160 | Use and save the results of the tests in FILE instead of 161 | `./config.cache'. Set FILE to `/dev/null' to disable caching, for 162 | debugging `configure'. 163 | 164 | `--help' 165 | Print a summary of the options to `configure', and exit. 166 | 167 | `--quiet' 168 | `--silent' 169 | `-q' 170 | Do not print messages saying which checks are being made. To 171 | suppress all normal output, redirect it to `/dev/null' (any error 172 | messages will still be shown). 173 | 174 | `--srcdir=DIR' 175 | Look for the package's source code in directory DIR. Usually 176 | `configure' can determine that directory automatically. 177 | 178 | `--version' 179 | Print the version of Autoconf used to generate the `configure' 180 | script, and exit. 181 | 182 | `configure' also accepts some other, not widely useful, options. 183 | 184 | -------------------------------------------------------------------------------- /nufxlib/Deflate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * NuFX archive manipulation library 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING-LIB. 6 | * 7 | * Support for the "deflate" algorithm, via the "zlib" library. 8 | * 9 | * This compression format is totally unsupported on the Apple II. This 10 | * is provided primarily for the benefit of Apple II emulators that want 11 | * a better storage format for disk images than SHK+LZW or a ZIP file. 12 | * 13 | * This code was developed and tested with ZLIB_VERSION "1.1.3". It is 14 | * expected to work with any version >= 1.1.3 and < 2.x. Please visit 15 | * http://www.zlib.org/ for more information. 16 | */ 17 | #include "NufxLibPriv.h" 18 | 19 | #ifdef ENABLE_DEFLATE 20 | #include "zlib.h" 21 | 22 | #define kNuDeflateLevel 9 /* use maximum compression */ 23 | 24 | 25 | /* 26 | * Alloc and free functions provided to zlib. 27 | */ 28 | static voidpf Nu_zalloc(voidpf opaque, uInt items, uInt size) 29 | { 30 | return Nu_Malloc(opaque, items * size); 31 | } 32 | static void Nu_zfree(voidpf opaque, voidpf address) 33 | { 34 | Nu_Free(opaque, address); 35 | } 36 | 37 | 38 | /* 39 | * =========================================================================== 40 | * Compression 41 | * =========================================================================== 42 | */ 43 | 44 | /* 45 | * Compress "srcLen" bytes from "pStraw" to "fp". 46 | */ 47 | NuError Nu_CompressDeflate(NuArchive* pArchive, NuStraw* pStraw, FILE* fp, 48 | uint32_t srcLen, uint32_t* pDstLen, uint16_t* pCrc) 49 | { 50 | NuError err = kNuErrNone; 51 | z_stream zstream; 52 | int zerr; 53 | Bytef* outbuf = NULL; 54 | 55 | Assert(pArchive != NULL); 56 | Assert(pStraw != NULL); 57 | Assert(fp != NULL); 58 | Assert(srcLen > 0); 59 | Assert(pDstLen != NULL); 60 | Assert(pCrc != NULL); 61 | 62 | err = Nu_AllocCompressionBufferIFN(pArchive); 63 | if (err != kNuErrNone) 64 | return err; 65 | 66 | /* allocate a similarly-sized buffer for the output */ 67 | outbuf = Nu_Malloc(pArchive, kNuGenCompBufSize); 68 | BailAlloc(outbuf); 69 | 70 | /* 71 | * Initialize the zlib stream. 72 | */ 73 | zstream.zalloc = Nu_zalloc; 74 | zstream.zfree = Nu_zfree; 75 | zstream.opaque = pArchive; 76 | zstream.next_in = NULL; 77 | zstream.avail_in = 0; 78 | zstream.next_out = outbuf; 79 | zstream.avail_out = kNuGenCompBufSize; 80 | zstream.data_type = Z_UNKNOWN; 81 | 82 | zerr = deflateInit(&zstream, kNuDeflateLevel); 83 | if (zerr != Z_OK) { 84 | err = kNuErrInternal; 85 | if (zerr == Z_VERSION_ERROR) { 86 | Nu_ReportError(NU_BLOB, err, 87 | "installed zlib is not compatible with linked version (%s)", 88 | ZLIB_VERSION); 89 | } else { 90 | Nu_ReportError(NU_BLOB, err, 91 | "call to deflateInit failed (zerr=%d)", zerr); 92 | } 93 | goto bail; 94 | } 95 | 96 | /* 97 | * Loop while we have data. 98 | */ 99 | do { 100 | uint32_t getSize; 101 | int flush; 102 | 103 | /* should be able to read a full buffer every time */ 104 | if (zstream.avail_in == 0 && srcLen) { 105 | getSize = (srcLen > kNuGenCompBufSize) ? kNuGenCompBufSize : srcLen; 106 | DBUG(("+++ reading %ld bytes\n", getSize)); 107 | 108 | err = Nu_StrawRead(pArchive, pStraw, pArchive->compBuf, getSize); 109 | if (err != kNuErrNone) { 110 | Nu_ReportError(NU_BLOB, err, "deflate read failed"); 111 | goto z_bail; 112 | } 113 | 114 | srcLen -= getSize; 115 | 116 | *pCrc = Nu_CalcCRC16(*pCrc, pArchive->compBuf, getSize); 117 | 118 | zstream.next_in = pArchive->compBuf; 119 | zstream.avail_in = getSize; 120 | } 121 | 122 | if (srcLen == 0) 123 | flush = Z_FINISH; /* tell zlib that we're done */ 124 | else 125 | flush = Z_NO_FLUSH; /* more to come! */ 126 | 127 | zerr = deflate(&zstream, flush); 128 | if (zerr != Z_OK && zerr != Z_STREAM_END) { 129 | err = kNuErrInternal; 130 | Nu_ReportError(NU_BLOB, err, "zlib deflate call failed (zerr=%d)", 131 | zerr); 132 | goto z_bail; 133 | } 134 | 135 | /* write when we're full or when we're done */ 136 | if (zstream.avail_out == 0 || 137 | (zerr == Z_STREAM_END && zstream.avail_out != kNuGenCompBufSize)) 138 | { 139 | DBUG(("+++ writing %d bytes\n", zstream.next_out - outbuf)); 140 | err = Nu_FWrite(fp, outbuf, zstream.next_out - outbuf); 141 | if (err != kNuErrNone) { 142 | Nu_ReportError(NU_BLOB, err, "fwrite failed in deflate"); 143 | goto z_bail; 144 | } 145 | 146 | zstream.next_out = outbuf; 147 | zstream.avail_out = kNuGenCompBufSize; 148 | } 149 | } while (zerr == Z_OK); 150 | 151 | Assert(zerr == Z_STREAM_END); /* other errors should've been caught */ 152 | 153 | *pDstLen = zstream.total_out; 154 | 155 | z_bail: 156 | deflateEnd(&zstream); /* free up any allocated structures */ 157 | 158 | bail: 159 | if (outbuf != NULL) 160 | free(outbuf); 161 | return err; 162 | } 163 | 164 | 165 | /* 166 | * =========================================================================== 167 | * Expansion 168 | * =========================================================================== 169 | */ 170 | 171 | /* 172 | * Expand from "infp" to "pFunnel". 173 | */ 174 | NuError Nu_ExpandDeflate(NuArchive* pArchive, const NuRecord* pRecord, 175 | const NuThread* pThread, FILE* infp, NuFunnel* pFunnel, uint16_t* pCrc) 176 | { 177 | NuError err = kNuErrNone; 178 | z_stream zstream; 179 | int zerr; 180 | uint32_t compRemaining; 181 | Bytef* outbuf; 182 | 183 | Assert(pArchive != NULL); 184 | Assert(pThread != NULL); 185 | Assert(infp != NULL); 186 | Assert(pFunnel != NULL); 187 | 188 | err = Nu_AllocCompressionBufferIFN(pArchive); 189 | if (err != kNuErrNone) 190 | return err; 191 | 192 | /* allocate a similarly-sized buffer for the output */ 193 | outbuf = Nu_Malloc(pArchive, kNuGenCompBufSize); 194 | BailAlloc(outbuf); 195 | 196 | compRemaining = pThread->thCompThreadEOF; 197 | 198 | /* 199 | * Initialize the zlib stream. 200 | */ 201 | zstream.zalloc = Nu_zalloc; 202 | zstream.zfree = Nu_zfree; 203 | zstream.opaque = pArchive; 204 | zstream.next_in = NULL; 205 | zstream.avail_in = 0; 206 | zstream.next_out = outbuf; 207 | zstream.avail_out = kNuGenCompBufSize; 208 | zstream.data_type = Z_UNKNOWN; 209 | 210 | zerr = inflateInit(&zstream); 211 | if (zerr != Z_OK) { 212 | err = kNuErrInternal; 213 | if (zerr == Z_VERSION_ERROR) { 214 | Nu_ReportError(NU_BLOB, err, 215 | "installed zlib is not compatible with linked version (%s)", 216 | ZLIB_VERSION); 217 | } else { 218 | Nu_ReportError(NU_BLOB, err, 219 | "call to inflateInit failed (zerr=%d)", zerr); 220 | } 221 | goto bail; 222 | } 223 | 224 | /* 225 | * Loop while we have data. 226 | */ 227 | do { 228 | uint32_t getSize; 229 | 230 | /* read as much as we can */ 231 | if (zstream.avail_in == 0) { 232 | getSize = (compRemaining > kNuGenCompBufSize) ? 233 | kNuGenCompBufSize : compRemaining; 234 | DBUG(("+++ reading %ld bytes (%ld left)\n", getSize, 235 | compRemaining)); 236 | 237 | err = Nu_FRead(infp, pArchive->compBuf, getSize); 238 | if (err != kNuErrNone) { 239 | Nu_ReportError(NU_BLOB, err, "inflate read failed"); 240 | goto z_bail; 241 | } 242 | 243 | compRemaining -= getSize; 244 | 245 | zstream.next_in = pArchive->compBuf; 246 | zstream.avail_in = getSize; 247 | } 248 | 249 | /* uncompress the data */ 250 | zerr = inflate(&zstream, Z_NO_FLUSH); 251 | if (zerr != Z_OK && zerr != Z_STREAM_END) { 252 | err = kNuErrInternal; 253 | Nu_ReportError(NU_BLOB, err, "zlib inflate call failed (zerr=%d)", 254 | zerr); 255 | goto z_bail; 256 | } 257 | 258 | /* write every time there's anything (buffer will usually be full) */ 259 | if (zstream.avail_out != kNuGenCompBufSize) { 260 | DBUG(("+++ writing %d bytes\n", zstream.next_out - outbuf)); 261 | err = Nu_FunnelWrite(pArchive, pFunnel, outbuf, 262 | zstream.next_out - outbuf); 263 | if (err != kNuErrNone) { 264 | Nu_ReportError(NU_BLOB, err, "write failed in inflate"); 265 | goto z_bail; 266 | } 267 | 268 | if (pCrc != NULL) 269 | *pCrc = Nu_CalcCRC16(*pCrc, outbuf, zstream.next_out - outbuf); 270 | 271 | zstream.next_out = outbuf; 272 | zstream.avail_out = kNuGenCompBufSize; 273 | } 274 | } while (zerr == Z_OK); 275 | 276 | Assert(zerr == Z_STREAM_END); /* other errors should've been caught */ 277 | 278 | if (zstream.total_out != pThread->actualThreadEOF) { 279 | err = kNuErrBadData; 280 | Nu_ReportError(NU_BLOB, err, 281 | "size mismatch on inflated file (%ld vs %u)", 282 | zstream.total_out, pThread->actualThreadEOF); 283 | goto z_bail; 284 | } 285 | 286 | z_bail: 287 | inflateEnd(&zstream); /* free up any allocated structures */ 288 | 289 | bail: 290 | if (outbuf != NULL) 291 | free(outbuf); 292 | return err; 293 | } 294 | 295 | #endif /*ENABLE_DEFLATE*/ 296 | -------------------------------------------------------------------------------- /nufxlib/Bzip2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * NuFX archive manipulation library 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING-LIB. 6 | * 7 | * Support for the "bzip2" (BTW+Huffman) algorithm, via "libbz2". 8 | * 9 | * This compression format is totally unsupported on the Apple II. This 10 | * is provided primarily for the benefit of Apple II emulators that want 11 | * a better storage format for disk images than SHK+LZW or a ZIP file. 12 | * 13 | * This code was developed and tested with libz2 version 1.0.2. Visit 14 | * http://sources.redhat.com/bzip2/ for more information. 15 | */ 16 | #include "NufxLibPriv.h" 17 | 18 | #ifdef ENABLE_BZIP2 19 | #include "bzlib.h" 20 | 21 | #define kBZBlockSize 8 /* use 800K blocks */ 22 | #define kBZVerbosity 1 /* library verbosity level (0-4) */ 23 | 24 | 25 | /* 26 | * Alloc and free functions provided to libbz2. 27 | */ 28 | static void* Nu_bzalloc(void* opaque, int items, int size) 29 | { 30 | return Nu_Malloc(opaque, items * size); 31 | } 32 | static void Nu_bzfree(void* opaque, void* address) 33 | { 34 | Nu_Free(opaque, address); 35 | } 36 | 37 | 38 | /* 39 | * =========================================================================== 40 | * Compression 41 | * =========================================================================== 42 | */ 43 | 44 | /* 45 | * Compress "srcLen" bytes from "pStraw" to "fp". 46 | */ 47 | NuError Nu_CompressBzip2(NuArchive* pArchive, NuStraw* pStraw, FILE* fp, 48 | uint32_t srcLen, uint32_t* pDstLen, uint16_t* pCrc) 49 | { 50 | NuError err = kNuErrNone; 51 | bz_stream bzstream; 52 | int bzerr; 53 | uint8_t* outbuf = NULL; 54 | 55 | Assert(pArchive != NULL); 56 | Assert(pStraw != NULL); 57 | Assert(fp != NULL); 58 | Assert(srcLen > 0); 59 | Assert(pDstLen != NULL); 60 | Assert(pCrc != NULL); 61 | 62 | err = Nu_AllocCompressionBufferIFN(pArchive); 63 | if (err != kNuErrNone) 64 | return err; 65 | 66 | /* allocate a similarly-sized buffer for the output */ 67 | outbuf = Nu_Malloc(pArchive, kNuGenCompBufSize); 68 | BailAlloc(outbuf); 69 | 70 | /* 71 | * Initialize the bz2lib stream. 72 | */ 73 | bzstream.bzalloc = Nu_bzalloc; 74 | bzstream.bzfree = Nu_bzfree; 75 | bzstream.opaque = pArchive; 76 | bzstream.next_in = NULL; 77 | bzstream.avail_in = 0; 78 | bzstream.next_out = outbuf; 79 | bzstream.avail_out = kNuGenCompBufSize; 80 | 81 | /* fourth arg is "workFactor"; set to zero for default (30) */ 82 | bzerr = BZ2_bzCompressInit(&bzstream, kBZBlockSize, kBZVerbosity, 0); 83 | if (bzerr != BZ_OK) { 84 | err = kNuErrInternal; 85 | if (bzerr == BZ_CONFIG_ERROR) { 86 | Nu_ReportError(NU_BLOB, err, "error configuring bz2lib"); 87 | } else { 88 | Nu_ReportError(NU_BLOB, err, 89 | "call to BZ2_bzCompressInit failed (bzerr=%d)", bzerr); 90 | } 91 | goto bail; 92 | } 93 | 94 | /* 95 | * Loop while we have data. 96 | */ 97 | do { 98 | uint32_t getSize; 99 | int action; 100 | 101 | /* should be able to read a full buffer every time */ 102 | if (bzstream.avail_in == 0 && srcLen) { 103 | getSize = (srcLen > kNuGenCompBufSize) ? kNuGenCompBufSize : srcLen; 104 | DBUG(("+++ reading %ld bytes\n", getSize)); 105 | 106 | err = Nu_StrawRead(pArchive, pStraw, pArchive->compBuf, getSize); 107 | if (err != kNuErrNone) { 108 | Nu_ReportError(NU_BLOB, err, "bzip2 read failed"); 109 | goto bz_bail; 110 | } 111 | 112 | srcLen -= getSize; 113 | 114 | *pCrc = Nu_CalcCRC16(*pCrc, pArchive->compBuf, getSize); 115 | 116 | bzstream.next_in = pArchive->compBuf; 117 | bzstream.avail_in = getSize; 118 | } 119 | 120 | if (srcLen == 0) 121 | action = BZ_FINISH; /* tell libbz2 that we're done */ 122 | else 123 | action = BZ_RUN; /* more to come! */ 124 | 125 | bzerr = BZ2_bzCompress(&bzstream, action); 126 | if (bzerr != BZ_RUN_OK && bzerr != BZ_FINISH_OK && bzerr != BZ_STREAM_END) 127 | { 128 | err = kNuErrInternal; 129 | Nu_ReportError(NU_BLOB, err, 130 | "libbz2 compress call failed (bzerr=%d)", bzerr); 131 | goto bz_bail; 132 | } 133 | 134 | /* write when we're full or when we're done */ 135 | if (bzstream.avail_out == 0 || 136 | (bzerr == BZ_STREAM_END && bzstream.avail_out != kNuGenCompBufSize)) 137 | { 138 | DBUG(("+++ writing %d bytes\n", 139 | (uint8_t*)bzstream.next_out - outbuf)); 140 | err = Nu_FWrite(fp, outbuf, (uint8_t*)bzstream.next_out - outbuf); 141 | if (err != kNuErrNone) { 142 | Nu_ReportError(NU_BLOB, err, "fwrite failed in bzip2"); 143 | goto bz_bail; 144 | } 145 | 146 | bzstream.next_out = outbuf; 147 | bzstream.avail_out = kNuGenCompBufSize; 148 | } 149 | } while (bzerr != BZ_STREAM_END); 150 | 151 | *pDstLen = bzstream.total_out_lo32; 152 | Assert(bzstream.total_out_hi32 == 0); /* no huge files for us */ 153 | 154 | bz_bail: 155 | BZ2_bzCompressEnd(&bzstream); /* free up any allocated structures */ 156 | 157 | bail: 158 | if (outbuf != NULL) 159 | Nu_Free(NULL, outbuf); 160 | return err; 161 | } 162 | 163 | 164 | /* 165 | * =========================================================================== 166 | * Expansion 167 | * =========================================================================== 168 | */ 169 | 170 | /* 171 | * Expand from "infp" to "pFunnel". 172 | */ 173 | NuError Nu_ExpandBzip2(NuArchive* pArchive, const NuRecord* pRecord, 174 | const NuThread* pThread, FILE* infp, NuFunnel* pFunnel, uint16_t* pCrc) 175 | { 176 | NuError err = kNuErrNone; 177 | bz_stream bzstream; 178 | int bzerr; 179 | uint32_t compRemaining; 180 | uint8_t* outbuf; 181 | 182 | Assert(pArchive != NULL); 183 | Assert(pThread != NULL); 184 | Assert(infp != NULL); 185 | Assert(pFunnel != NULL); 186 | 187 | err = Nu_AllocCompressionBufferIFN(pArchive); 188 | if (err != kNuErrNone) 189 | return err; 190 | 191 | /* allocate a similarly-sized buffer for the output */ 192 | outbuf = Nu_Malloc(pArchive, kNuGenCompBufSize); 193 | BailAlloc(outbuf); 194 | 195 | compRemaining = pThread->thCompThreadEOF; 196 | 197 | /* 198 | * Initialize the libbz2 stream. 199 | */ 200 | bzstream.bzalloc = Nu_bzalloc; 201 | bzstream.bzfree = Nu_bzfree; 202 | bzstream.opaque = pArchive; 203 | bzstream.next_in = NULL; 204 | bzstream.avail_in = 0; 205 | bzstream.next_out = outbuf; 206 | bzstream.avail_out = kNuGenCompBufSize; 207 | 208 | /* third arg is "small" (set nonzero to reduce mem) */ 209 | bzerr = BZ2_bzDecompressInit(&bzstream, kBZVerbosity, 0); 210 | if (bzerr != BZ_OK) { 211 | err = kNuErrInternal; 212 | if (bzerr == BZ_CONFIG_ERROR) { 213 | Nu_ReportError(NU_BLOB, err, "error configuring libbz2"); 214 | } else { 215 | Nu_ReportError(NU_BLOB, err, 216 | "call to BZ2_bzDecompressInit failed (bzerr=%d)", bzerr); 217 | } 218 | goto bail; 219 | } 220 | 221 | /* 222 | * Loop while we have data. 223 | */ 224 | do { 225 | uint32_t getSize; 226 | 227 | /* read as much as we can */ 228 | if (bzstream.avail_in == 0) { 229 | getSize = (compRemaining > kNuGenCompBufSize) ? 230 | kNuGenCompBufSize : compRemaining; 231 | DBUG(("+++ reading %ld bytes (%ld left)\n", getSize, 232 | compRemaining)); 233 | 234 | err = Nu_FRead(infp, pArchive->compBuf, getSize); 235 | if (err != kNuErrNone) { 236 | Nu_ReportError(NU_BLOB, err, "bzip2 read failed"); 237 | goto bz_bail; 238 | } 239 | 240 | compRemaining -= getSize; 241 | 242 | bzstream.next_in = pArchive->compBuf; 243 | bzstream.avail_in = getSize; 244 | } 245 | 246 | /* uncompress the data */ 247 | bzerr = BZ2_bzDecompress(&bzstream); 248 | if (bzerr != BZ_OK && bzerr != BZ_STREAM_END) { 249 | err = kNuErrInternal; 250 | Nu_ReportError(NU_BLOB, err, 251 | "libbz2 decompress call failed (bzerr=%d)", bzerr); 252 | goto bz_bail; 253 | } 254 | 255 | /* write every time there's anything (buffer will usually be full) */ 256 | if (bzstream.avail_out != kNuGenCompBufSize) { 257 | DBUG(("+++ writing %d bytes\n", 258 | (uint8_t*) bzstream.next_out - outbuf)); 259 | err = Nu_FunnelWrite(pArchive, pFunnel, outbuf, 260 | (uint8_t*)bzstream.next_out - outbuf); 261 | if (err != kNuErrNone) { 262 | Nu_ReportError(NU_BLOB, err, "write failed in bzip2"); 263 | goto bz_bail; 264 | } 265 | 266 | if (pCrc != NULL) 267 | *pCrc = Nu_CalcCRC16(*pCrc, outbuf, 268 | (uint8_t*) bzstream.next_out - outbuf); 269 | 270 | bzstream.next_out = outbuf; 271 | bzstream.avail_out = kNuGenCompBufSize; 272 | } 273 | } while (bzerr == BZ_OK); 274 | 275 | Assert(bzerr == BZ_STREAM_END); /* other errors should've been caught */ 276 | 277 | Assert(bzstream.total_out_hi32 == 0); /* no huge files for us */ 278 | 279 | if (bzstream.total_out_lo32 != pThread->actualThreadEOF) { 280 | err = kNuErrBadData; 281 | Nu_ReportError(NU_BLOB, err, 282 | "size mismatch on expanded bzip2 file (%d vs %ld)", 283 | bzstream.total_out_lo32, pThread->actualThreadEOF); 284 | goto bz_bail; 285 | } 286 | 287 | bz_bail: 288 | BZ2_bzDecompressEnd(&bzstream); /* free up any allocated structures */ 289 | 290 | bail: 291 | if (outbuf != NULL) 292 | Nu_Free(NULL, outbuf); 293 | return err; 294 | } 295 | 296 | #endif /*ENABLE_BZIP2*/ 297 | -------------------------------------------------------------------------------- /nufxlib/Value.c: -------------------------------------------------------------------------------- 1 | /* 2 | * NuFX archive manipulation library 3 | * Copyright (C) 2000-2007 by Andy McFadden, All Rights Reserved. 4 | * This is free software; you can redistribute it and/or modify it under the 5 | * terms of the BSD License, see the file COPYING-LIB. 6 | * 7 | * Get/set certain values and attributes. 8 | */ 9 | #include "NufxLibPriv.h" 10 | 11 | #define kMaxJunkSkipMax 8192 12 | 13 | 14 | /* 15 | * Get a configurable parameter. 16 | */ 17 | NuError Nu_GetValue(NuArchive* pArchive, NuValueID ident, NuValue* pValue) 18 | { 19 | NuError err = kNuErrNone; 20 | 21 | if (pValue == NULL) 22 | return kNuErrInvalidArg; 23 | 24 | switch (ident) { 25 | case kNuValueAllowDuplicates: 26 | *pValue = pArchive->valAllowDuplicates; 27 | break; 28 | case kNuValueConvertExtractedEOL: 29 | *pValue = pArchive->valConvertExtractedEOL; 30 | break; 31 | case kNuValueDataCompression: 32 | *pValue = pArchive->valDataCompression; 33 | break; 34 | case kNuValueDiscardWrapper: 35 | *pValue = pArchive->valDiscardWrapper; 36 | break; 37 | case kNuValueEOL: 38 | *pValue = pArchive->valEOL; 39 | break; 40 | case kNuValueHandleExisting: 41 | *pValue = pArchive->valHandleExisting; 42 | break; 43 | case kNuValueIgnoreCRC: 44 | *pValue = pArchive->valIgnoreCRC; 45 | break; 46 | case kNuValueMaskDataless: 47 | *pValue = pArchive->valMaskDataless; 48 | break; 49 | case kNuValueMimicSHK: 50 | *pValue = pArchive->valMimicSHK; 51 | break; 52 | case kNuValueModifyOrig: 53 | *pValue = pArchive->valModifyOrig; 54 | break; 55 | case kNuValueOnlyUpdateOlder: 56 | *pValue = pArchive->valOnlyUpdateOlder; 57 | break; 58 | case kNuValueStripHighASCII: 59 | *pValue = pArchive->valStripHighASCII; 60 | break; 61 | case kNuValueJunkSkipMax: 62 | *pValue = pArchive->valJunkSkipMax; 63 | break; 64 | case kNuValueIgnoreLZW2Len: 65 | *pValue = pArchive->valIgnoreLZW2Len; 66 | break; 67 | case kNuValueHandleBadMac: 68 | *pValue = pArchive->valHandleBadMac; 69 | break; 70 | default: 71 | err = kNuErrInvalidArg; 72 | Nu_ReportError(NU_BLOB, err, "Unknown ValueID %d requested", ident); 73 | goto bail; 74 | } 75 | 76 | bail: 77 | return err; 78 | } 79 | 80 | 81 | /* 82 | * Set a configurable parameter. 83 | */ 84 | NuError Nu_SetValue(NuArchive* pArchive, NuValueID ident, NuValue value) 85 | { 86 | NuError err = kNuErrInvalidArg; 87 | 88 | switch (ident) { 89 | case kNuValueAllowDuplicates: 90 | if (value != true && value != false) { 91 | Nu_ReportError(NU_BLOB, err, 92 | "Invalid kNuValueAllowDuplicates value %u", value); 93 | goto bail; 94 | } 95 | pArchive->valAllowDuplicates = value; 96 | break; 97 | case kNuValueConvertExtractedEOL: 98 | if (value < kNuConvertOff || value > kNuConvertAuto) { 99 | Nu_ReportError(NU_BLOB, err, 100 | "Invalid kNuValueConvertExtractedEOL value %u", value); 101 | goto bail; 102 | } 103 | pArchive->valConvertExtractedEOL = value; 104 | break; 105 | case kNuValueDataCompression: 106 | if (value < kNuCompressNone || value > kNuCompressBzip2) { 107 | Nu_ReportError(NU_BLOB, err, 108 | "Invalid kNuValueDataCompression value %u", value); 109 | goto bail; 110 | } 111 | pArchive->valDataCompression = value; 112 | break; 113 | case kNuValueDiscardWrapper: 114 | if (value != true && value != false) { 115 | Nu_ReportError(NU_BLOB, err, 116 | "Invalid kNuValueDiscardWrapper value %u", value); 117 | goto bail; 118 | } 119 | pArchive->valDiscardWrapper = value; 120 | break; 121 | case kNuValueEOL: 122 | if (value < kNuEOLUnknown || value > kNuEOLCRLF) { 123 | Nu_ReportError(NU_BLOB, err, 124 | "Invalid kNuValueEOL value %u", value); 125 | goto bail; 126 | } 127 | pArchive->valEOL = value; 128 | break; 129 | case kNuValueHandleExisting: 130 | if (value < kNuMaybeOverwrite || value > kNuMustOverwrite) { 131 | Nu_ReportError(NU_BLOB, err, 132 | "Invalid kNuValueHandleExisting value %u", value); 133 | goto bail; 134 | } 135 | pArchive->valHandleExisting = value; 136 | break; 137 | case kNuValueIgnoreCRC: 138 | if (value != true && value != false) { 139 | Nu_ReportError(NU_BLOB, err, 140 | "Invalid kNuValueIgnoreCRC value %u", value); 141 | goto bail; 142 | } 143 | pArchive->valIgnoreCRC = value; 144 | break; 145 | case kNuValueMaskDataless: 146 | if (value != true && value != false) { 147 | Nu_ReportError(NU_BLOB, err, 148 | "Invalid kNuValueMaskDataless value %u", value); 149 | goto bail; 150 | } 151 | pArchive->valMaskDataless = value; 152 | break; 153 | case kNuValueMimicSHK: 154 | if (value != true && value != false) { 155 | Nu_ReportError(NU_BLOB, err, 156 | "Invalid kNuValueMimicSHK value %u", value); 157 | goto bail; 158 | } 159 | pArchive->valMimicSHK = value; 160 | break; 161 | case kNuValueModifyOrig: 162 | if (value != true && value != false) { 163 | Nu_ReportError(NU_BLOB, err, 164 | "Invalid kNuValueModifyOrig value %u", value); 165 | goto bail; 166 | } 167 | pArchive->valModifyOrig = value; 168 | break; 169 | case kNuValueOnlyUpdateOlder: 170 | if (value != true && value != false) { 171 | Nu_ReportError(NU_BLOB, err, 172 | "Invalid kNuValueOnlyUpdateOlder value %u", value); 173 | goto bail; 174 | } 175 | pArchive->valOnlyUpdateOlder = value; 176 | break; 177 | case kNuValueStripHighASCII: 178 | if (value != true && value != false) { 179 | Nu_ReportError(NU_BLOB, err, 180 | "Invalid kNuValueStripHighASCII value %u", value); 181 | goto bail; 182 | } 183 | pArchive->valStripHighASCII = value; 184 | break; 185 | case kNuValueJunkSkipMax: 186 | if (value > kMaxJunkSkipMax) { 187 | Nu_ReportError(NU_BLOB, err, 188 | "Invalid kNuValueJunkSkipMax value %u", value); 189 | goto bail; 190 | } 191 | pArchive->valJunkSkipMax = value; 192 | break; 193 | case kNuValueIgnoreLZW2Len: 194 | if (value != true && value != false) { 195 | Nu_ReportError(NU_BLOB, err, 196 | "Invalid kNuValueIgnoreLZW2Len value %u", value); 197 | goto bail; 198 | } 199 | pArchive->valIgnoreLZW2Len = value; 200 | break; 201 | case kNuValueHandleBadMac: 202 | if (value != true && value != false) { 203 | Nu_ReportError(NU_BLOB, err, 204 | "Invalid kNuValueHandleBadMac value %u", value); 205 | goto bail; 206 | } 207 | pArchive->valHandleBadMac = value; 208 | break; 209 | default: 210 | Nu_ReportError(NU_BLOB, err, "Unknown ValueID %d requested", ident); 211 | goto bail; 212 | } 213 | 214 | err = kNuErrNone; 215 | 216 | bail: 217 | return err; 218 | } 219 | 220 | 221 | /* 222 | * Get an archive attribute. These are things that you would have to 223 | * pry into pArchive to get at (like the archive type) or get the master 224 | * header (like the number of records). 225 | */ 226 | NuError Nu_GetAttr(NuArchive* pArchive, NuAttrID ident, NuAttr* pAttr) 227 | { 228 | NuError err = kNuErrNone; 229 | if (pAttr == NULL) 230 | return kNuErrInvalidArg; 231 | 232 | switch (ident) { 233 | case kNuAttrArchiveType: 234 | *pAttr = pArchive->archiveType; 235 | break; 236 | case kNuAttrNumRecords: 237 | *pAttr = pArchive->masterHeader.mhTotalRecords; 238 | break; 239 | case kNuAttrHeaderOffset: 240 | *pAttr = pArchive->headerOffset; 241 | break; 242 | case kNuAttrJunkOffset: 243 | *pAttr = pArchive->junkOffset; 244 | break; 245 | default: 246 | err = kNuErrInvalidArg; 247 | Nu_ReportError(NU_BLOB, err, "Unknown AttrID %d requested", ident); 248 | goto bail; 249 | } 250 | 251 | bail: 252 | return err; 253 | } 254 | 255 | /* 256 | * Convert a NuValue compression type to a "phyiscal" ThreadFormat. 257 | * 258 | * Unsupported compression types cause a warning to be flagged. 259 | */ 260 | NuThreadFormat Nu_ConvertCompressValToFormat(NuArchive* pArchive, 261 | NuValue compValue) 262 | { 263 | NuThreadFormat threadFormat; 264 | Boolean unsup = false; 265 | 266 | switch (compValue) { 267 | case kNuCompressNone: threadFormat = kNuThreadFormatUncompressed; break; 268 | 269 | #ifdef ENABLE_SQ 270 | case kNuCompressSQ: threadFormat = kNuThreadFormatHuffmanSQ; break; 271 | #else 272 | case kNuCompressSQ: threadFormat = kNuThreadFormatHuffmanSQ; 273 | unsup = true; break; 274 | #endif 275 | 276 | #ifdef ENABLE_LZW 277 | case kNuCompressLZW1: threadFormat = kNuThreadFormatLZW1; break; 278 | case kNuCompressLZW2: threadFormat = kNuThreadFormatLZW2; break; 279 | #else 280 | case kNuCompressLZW1: threadFormat = kNuThreadFormatLZW1; 281 | unsup = true; break; 282 | case kNuCompressLZW2: threadFormat = kNuThreadFormatLZW2; 283 | unsup = true; break; 284 | #endif 285 | 286 | #ifdef ENABLE_LZC 287 | case kNuCompressLZC12: threadFormat = kNuThreadFormatLZC12; break; 288 | case kNuCompressLZC16: threadFormat = kNuThreadFormatLZC16; break; 289 | #else 290 | case kNuCompressLZC12: threadFormat = kNuThreadFormatLZC12; 291 | unsup = true; break; 292 | case kNuCompressLZC16: threadFormat = kNuThreadFormatLZC16; 293 | unsup = true; break; 294 | #endif 295 | 296 | #ifdef ENABLE_DEFLATE 297 | case kNuCompressDeflate: threadFormat = kNuThreadFormatDeflate; break; 298 | #else 299 | case kNuCompressDeflate: threadFormat = kNuThreadFormatDeflate; 300 | unsup = true; break; 301 | #endif 302 | 303 | #ifdef ENABLE_BZIP2 304 | case kNuCompressBzip2: threadFormat = kNuThreadFormatBzip2; break; 305 | #else 306 | case kNuCompressBzip2: threadFormat = kNuThreadFormatBzip2; 307 | unsup = true; break; 308 | #endif 309 | 310 | default: 311 | Nu_ReportError(NU_BLOB, kNuErrInvalidArg, 312 | "Unknown compress value %u", compValue); 313 | Assert(false); 314 | return kNuThreadFormatUncompressed; 315 | } 316 | 317 | if (unsup) { 318 | Nu_ReportError(NU_BLOB, kNuErrNone, 319 | "Unsupported compression 0x%04x requested (%u), storing", 320 | threadFormat, compValue); 321 | return kNuThreadFormatUncompressed; 322 | } 323 | 324 | return threadFormat; 325 | } 326 | 327 | --------------------------------------------------------------------------------