diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07a97b26..6b4db97b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,12 +57,13 @@ jobs: run: | sudo apt update sudo apt install -y --no-install-recommends \ - ninja-build cmake g++ libsdl1.2-dev libsdl-image1.2-dev libncurses-dev + ninja-build cmake g++ libsdl1.2-dev libsdl-image1.2-dev libncurses-dev zlib1g-dev - name: Configure CMake env: CC: ${{ matrix.os.cc }} CXX: ${{ matrix.os.cxx }} + VCPKG_ROOT: C:/vcpkg run: cmake --preset ${{ matrix.os.preset }} - name: Debug Build diff --git a/2dlib/CMakeLists.txt b/2dlib/CMakeLists.txt index a0300092..038ebe05 100644 --- a/2dlib/CMakeLists.txt +++ b/2dlib/CMakeLists.txt @@ -10,4 +10,6 @@ set(CPPS viewport.cpp) add_library(2dlib STATIC ${HEADERS} ${CPPS}) - +target_link_libraries(2dlib PRIVATE + cfile +) diff --git a/2dlib/font.cpp b/2dlib/font.cpp index 58d27986..5411b999 100644 --- a/2dlib/font.cpp +++ b/2dlib/font.cpp @@ -120,7 +120,7 @@ #include "renderer.h" #include "gr.h" #include "mono.h" -#include "CFILE.H" +#include "cfile.h" #include "bitmap.h" #include "mem.h" diff --git a/Brewfile b/Brewfile index 9a10932c..c97a6a11 100644 --- a/Brewfile +++ b/Brewfile @@ -10,3 +10,6 @@ brew "sdl2_image" brew "cmake" brew "ninja" + +# zlib +brew "zlib" diff --git a/CMakeLists.txt b/CMakeLists.txt index 000e75a8..de02d4fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.19) +cmake_minimum_required(VERSION 3.20) # For using CMAKE__BYTE_ORDER project(Descent3 VERSION 1.5.500) @@ -13,6 +13,18 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_CXX_EXTENSIONS OFF) +if(CMAKE_CXX_BYTE_ORDER STREQUAL "BIG_ENDIAN") + message(STATUS "Big Endian system detected.") + add_definitions("-DOUTRAGE_BIG_ENDIAN") +endif() + +if(BUILD_TESTING) + find_package(GTest REQUIRED) + enable_testing() + include(GoogleTest) + add_subdirectory(tests) +endif() + if(NOT MSVC) # check if this is some kind of clang (Clang, AppleClang, whatever) # (convert compiler ID to lowercase so we match Clang, clang, AppleClang etc, regardless of case) @@ -102,12 +114,19 @@ endif() add_compile_definitions($<$:RELEASE>) add_compile_definitions($<$:_DEBUG>) +find_package(ZLIB REQUIRED) + if(LOGGER) message("Enabling Logging") add_definitions(-DLOGGER) endif() -include_directories("lib" "Descent3" ${PLATFORM_INCLUDES}) +include_directories( + "cfile" # TODO: Remove after untying all modules + "lib" # TODO: Remove after untying all modules + "Descent3" + ${PLATFORM_INCLUDES} +) # file(GLOB_RECURSE INCS "*.h") diff --git a/CMakePresets.json b/CMakePresets.json index 3677950e..78d48221 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -15,7 +15,8 @@ "lhs": "${hostSystemName}", "rhs": "Windows" }, - "architecture": "Win32" + "architecture": "Win32", + "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" }, { "name": "mac", diff --git a/Descent3/BriefingParse.cpp b/Descent3/BriefingParse.cpp index 91284eda..0d844cfe 100644 --- a/Descent3/BriefingParse.cpp +++ b/Descent3/BriefingParse.cpp @@ -65,7 +65,7 @@ #include #include #include -#include "CFILE.H" +#include "cfile.h" #include "pserror.h" #include "game.h" #include "mem.h" @@ -242,7 +242,7 @@ int ReadFullLine(char **data, CFILE *ifile) { // read in a byte c = cfgetc(ifile); - if ((c == EOF) || (!(ifile->flags & CF_TEXT) && (c == 0)) || ((ifile->flags & CF_TEXT) && (c == '\n'))) { + if ((c == EOF) || (!(ifile->flags & CFF_TEXT) && (c == 0)) || ((ifile->flags & CFF_TEXT) && (c == '\n'))) { // we've hit the end of the line done = true; } else { diff --git a/Descent3/ConfigItem.cpp b/Descent3/ConfigItem.cpp index 525caa44..2236ac24 100644 --- a/Descent3/ConfigItem.cpp +++ b/Descent3/ConfigItem.cpp @@ -95,7 +95,7 @@ #include "ddio.h" #include "gamefont.h" #include "multi_ui.h" -#include "CFILE.H" +#include "cfile.h" #include "mem.h" #include "game.h" #include "stringtable.h" diff --git a/Descent3/DllWrappers.cpp b/Descent3/DllWrappers.cpp index 0329b5e0..a6a0e0ac 100644 --- a/Descent3/DllWrappers.cpp +++ b/Descent3/DllWrappers.cpp @@ -19,7 +19,7 @@ #include "DllWrappers.h" #include "pserror.h" #include "pstring.h" -#include "CFILE.H" +#include "cfile.h" #include "gamefont.h" #include "grdefs.h" #include "descent.h" diff --git a/Descent3/DllWrappers.h b/Descent3/DllWrappers.h index 15a881c0..6f0e703d 100644 --- a/Descent3/DllWrappers.h +++ b/Descent3/DllWrappers.h @@ -20,7 +20,7 @@ #define DLLWRAPPERS_H_ #include "pserror.h" -#include "CFILE.H" +#include "cfile.h" #include "gamefont.h" #include "grdefs.h" #include "descent.h" diff --git a/Descent3/Inventory.h b/Descent3/Inventory.h index 531c39ca..8859f9d1 100644 --- a/Descent3/Inventory.h +++ b/Descent3/Inventory.h @@ -182,7 +182,7 @@ #define __INVENTORY_H__ #include "pstypes.h" -#include "CFILE.H" +#include "cfile.h" struct object; diff --git a/Descent3/LoadLevel.cpp b/Descent3/LoadLevel.cpp index 6434fbd9..5b56da75 100644 --- a/Descent3/LoadLevel.cpp +++ b/Descent3/LoadLevel.cpp @@ -1248,7 +1248,7 @@ #include "LoadLevel.h" -#include "CFILE.H" +#include "cfile.h" #include "descent.h" #include "object.h" diff --git a/Descent3/LoadLevel.h b/Descent3/LoadLevel.h index 8dcf7657..78184ada 100644 --- a/Descent3/LoadLevel.h +++ b/Descent3/LoadLevel.h @@ -443,7 +443,7 @@ * $NoKeywords: $ */ -#include "CFILE.H" +#include "cfile.h" #include "room.h" // Chunk types diff --git a/Descent3/Mission.cpp b/Descent3/Mission.cpp index 6f70e3e8..d9c6207c 100644 --- a/Descent3/Mission.cpp +++ b/Descent3/Mission.cpp @@ -640,7 +640,7 @@ #include "3d.h" #include "LoadLevel.h" #include "pserror.h" -#include "CFILE.H" +#include "cfile.h" #include "gamefont.h" #include "grdefs.h" #include "descent.h" diff --git a/Descent3/OsirisLoadandBind.cpp b/Descent3/OsirisLoadandBind.cpp index 20f52d85..5b3eb887 100644 --- a/Descent3/OsirisLoadandBind.cpp +++ b/Descent3/OsirisLoadandBind.cpp @@ -402,7 +402,7 @@ #include "osiris_dll.h" #include "pserror.h" #include "mono.h" -#include "CFILE.H" +#include "cfile.h" #include "ddio.h" #include "manage.h" #include @@ -917,11 +917,11 @@ int _get_full_path_to_module(char *module_name, char *fullpath, char *basename) int exist = cfexist(modfilename); switch (exist) { - case CF_ON_DISK: + case CFES_ON_DISK: ddio_MakePath(fullpath, LocalScriptDir, modfilename, NULL); return -1; break; - case CF_IN_LIBRARY: { + case CFES_IN_LIBRARY: { ASSERT(OSIRIS_Extracted_script_dir); if (!OSIRIS_Extracted_script_dir) return -2; diff --git a/Descent3/PilotPicsAPI.cpp b/Descent3/PilotPicsAPI.cpp index 5e54ccf0..ff659808 100644 --- a/Descent3/PilotPicsAPI.cpp +++ b/Descent3/PilotPicsAPI.cpp @@ -63,7 +63,7 @@ #include "bitmap.h" #include "player.h" #include "pilot.h" -#include "CFILE.H" +#include "cfile.h" #include "mono.h" #include "ddio.h" #include "manage.h" diff --git a/Descent3/TelCom.cpp b/Descent3/TelCom.cpp index dae27f58..d09a3732 100644 --- a/Descent3/TelCom.cpp +++ b/Descent3/TelCom.cpp @@ -501,7 +501,7 @@ #include "ddio.h" #include "descent.h" #include "game.h" -#include "CFILE.H" +#include "cfile.h" #include "application.h" #include "TelCom.h" #include "TelComEffects.h" diff --git a/Descent3/TelComAutoMap.cpp b/Descent3/TelComAutoMap.cpp index d9adc3a9..b886bf85 100644 --- a/Descent3/TelComAutoMap.cpp +++ b/Descent3/TelComAutoMap.cpp @@ -151,7 +151,7 @@ #include #include -#include "CFILE.H" +#include "cfile.h" #include "pserror.h" #include "ddio.h" #include "bitmap.h" diff --git a/Descent3/TelComCargo.cpp b/Descent3/TelComCargo.cpp index 42dde837..16ebdfce 100644 --- a/Descent3/TelComCargo.cpp +++ b/Descent3/TelComCargo.cpp @@ -82,7 +82,7 @@ #include #include -#include "CFILE.H" +#include "cfile.h" #include "pserror.h" #include "ddio.h" #include "bitmap.h" diff --git a/Descent3/TelComGoals.cpp b/Descent3/TelComGoals.cpp index 904403e3..374bf928 100644 --- a/Descent3/TelComGoals.cpp +++ b/Descent3/TelComGoals.cpp @@ -85,7 +85,7 @@ #include #include -#include "CFILE.H" +#include "cfile.h" #include "pserror.h" #include "ddio.h" #include "bitmap.h" diff --git a/Descent3/aiambient.cpp b/Descent3/aiambient.cpp index 195732fb..19dea324 100644 --- a/Descent3/aiambient.cpp +++ b/Descent3/aiambient.cpp @@ -1,5 +1,5 @@ /* -* Descent 3 +* Descent 3 * Copyright (C) 2024 Parallax Software * * This program is free software: you can redistribute it and/or modify @@ -16,10 +16,10 @@ * along with this program. If not, see . */ +#include #include "aiambient.h" #include "string.h" #include "objinfo.h" -#include #include "game.h" #include "psrand.h" diff --git a/Descent3/aiambient.h b/Descent3/aiambient.h index 72897cf3..28d71043 100644 --- a/Descent3/aiambient.h +++ b/Descent3/aiambient.h @@ -19,7 +19,7 @@ #ifndef _AIAMBIENT_H_ #define _AIAMBIENT_H_ -#include "CFILE.H" +#include "cfile.h" #define MAX_AL_TYPES 6 #define MAX_ALS_PER_TYPE 130 diff --git a/Descent3/ambient.cpp b/Descent3/ambient.cpp index c8e1cf78..1dad6abc 100644 --- a/Descent3/ambient.cpp +++ b/Descent3/ambient.cpp @@ -156,7 +156,6 @@ void InitAmbientSounds() { } #include "ddio.h" -#include "CFILE.H" #include "soundload.h" #include "descent.h" #include "mem.h" diff --git a/Descent3/audiotaunts.cpp b/Descent3/audiotaunts.cpp index de2ffc2f..0c11c4f6 100644 --- a/Descent3/audiotaunts.cpp +++ b/Descent3/audiotaunts.cpp @@ -24,7 +24,7 @@ #include "pserror.h" #include "pstypes.h" #include "audiotaunts.h" -#include "CFILE.H" +#include "cfile.h" #include "audio_encode.h" #include "byteswap.h" #include "mem.h" diff --git a/Descent3/bsp.h b/Descent3/bsp.h index a9e1842b..79c43bed 100644 --- a/Descent3/bsp.h +++ b/Descent3/bsp.h @@ -43,7 +43,7 @@ #include "list.h" #include "vecmat.h" -#include "CFILE.H" +#include "cfile.h" #define BSP_IN_FRONT 1 #define BSP_BEHIND 2 diff --git a/Descent3/buddymenu.cpp b/Descent3/buddymenu.cpp index 7d85c661..57ba1099 100644 --- a/Descent3/buddymenu.cpp +++ b/Descent3/buddymenu.cpp @@ -59,7 +59,7 @@ #include "ddio.h" #include "descent.h" #include "game.h" -#include "CFILE.H" +#include "cfile.h" #include "application.h" #include #include diff --git a/Descent3/config.cpp b/Descent3/config.cpp index 41002f92..facde0c4 100644 --- a/Descent3/config.cpp +++ b/Descent3/config.cpp @@ -296,7 +296,7 @@ #include "cinematics.h" #include "hlsoundlib.h" #include "terrain.h" -#include "CFILE.H" +#include "cfile.h" #include "mem.h" #include "lighting.h" #include "PHYSICS.H" diff --git a/Descent3/d3serial.cpp b/Descent3/d3serial.cpp index b21d40b3..bd114403 100644 --- a/Descent3/d3serial.cpp +++ b/Descent3/d3serial.cpp @@ -83,7 +83,7 @@ #include "descent.h" #include #include "mono.h" -#include "CFILE.H" +#include "cfile.h" #include "program.h" #include diff --git a/Descent3/dedicated_server.cpp b/Descent3/dedicated_server.cpp index ccc49329..bef77f0a 100644 --- a/Descent3/dedicated_server.cpp +++ b/Descent3/dedicated_server.cpp @@ -112,8 +112,8 @@ typedef int socklen_t; #include "pstypes.h" #include "pserror.h" #include "pstring.h" -#include "CFILE.H" -#include "InfFile.h" +#include "cfile.h" +#include "inffile.h" #include "dedicated_server.h" #include "multi.h" #include "args.h" diff --git a/Descent3/demofile.cpp b/Descent3/demofile.cpp index 59d79b9a..7c95cbf0 100644 --- a/Descent3/demofile.cpp +++ b/Descent3/demofile.cpp @@ -266,7 +266,7 @@ */ #include -#include "CFILE.H" +#include "cfile.h" #include "objinfo.h" #include "ship.h" #include "ui.h" diff --git a/Descent3/descent.cpp b/Descent3/descent.cpp index bf4d6f4f..bfe9ab6d 100644 --- a/Descent3/descent.cpp +++ b/Descent3/descent.cpp @@ -385,7 +385,7 @@ #include "pserror.h" #include "grdefs.h" #include "mono.h" -#include "CFILE.H" +#include "cfile.h" #include "init.h" #include "game.h" diff --git a/Descent3/game.cpp b/Descent3/game.cpp index ebcb4f8a..992581de 100644 --- a/Descent3/game.cpp +++ b/Descent3/game.cpp @@ -676,7 +676,7 @@ #include "cinematics.h" #include "SmallViews.h" #include "Mission.h" -#include "CFILE.H" +#include "cfile.h" #include "gameloop.h" #include "cockpit.h" #include "game2dll.h" diff --git a/Descent3/gamesave.cpp b/Descent3/gamesave.cpp index 465ddc0f..505e3b25 100644 --- a/Descent3/gamesave.cpp +++ b/Descent3/gamesave.cpp @@ -266,7 +266,7 @@ #include "gamesave.h" #include "descent.h" #include "newui.h" -#include "CFILE.H" +#include "cfile.h" #include "Mission.h" #include "gamesequence.h" #include "gameevent.h" diff --git a/Descent3/gamesave.h b/Descent3/gamesave.h index 96b8a679..19a73a53 100644 --- a/Descent3/gamesave.h +++ b/Descent3/gamesave.h @@ -85,7 +85,7 @@ #define GAMESAVE_H #include "pstypes.h" -#include "CFILE.H" +#include "cfile.h" #include "object.h" #include "objinfo.h" diff --git a/Descent3/help.cpp b/Descent3/help.cpp index d83f959f..c9befa4b 100644 --- a/Descent3/help.cpp +++ b/Descent3/help.cpp @@ -132,7 +132,7 @@ #include "ddio.h" #include "descent.h" #include "game.h" -#include "CFILE.H" +#include "cfile.h" #include "application.h" #include #include diff --git a/Descent3/hotspotmap.cpp b/Descent3/hotspotmap.cpp index b2211e42..a7882b25 100644 --- a/Descent3/hotspotmap.cpp +++ b/Descent3/hotspotmap.cpp @@ -105,7 +105,7 @@ #include "ddio.h" #include "descent.h" #include "game.h" -#include "CFILE.H" +#include "cfile.h" #include "application.h" #include #include diff --git a/Descent3/levelgoal.h b/Descent3/levelgoal.h index 0298a77e..d0dcf5cb 100644 --- a/Descent3/levelgoal.h +++ b/Descent3/levelgoal.h @@ -20,7 +20,7 @@ #define _LEVELGOAL_H_ #include "object.h" -#include "CFILE.H" +#include "cfile.h" #if defined(MACOSX) #include #else diff --git a/Descent3/lnxmain.cpp b/Descent3/lnxmain.cpp index 3e304824..efe31f48 100644 --- a/Descent3/lnxmain.cpp +++ b/Descent3/lnxmain.cpp @@ -35,6 +35,7 @@ #include #define _GNU_SOURCE #include +#include "hogfile.h" #endif #include "SDL.h" @@ -330,8 +331,6 @@ void StartDedicatedServer(); static void hogfileRefresh(const char *x) { printf(" - %s\n", x); } // hogfileRefresh -int CreateNewHogFile(const char *hogname, int nfiles, const char **filenames, void (*UpdateFunction)(char *)); - // hack of the century. static void buildNewHogFromFileList(char *fileName) { setbuf(stdout, NULL); @@ -422,7 +421,7 @@ static void buildNewHogFromFileList(char *fileName) { } // for } while (swapped); - CreateNewHogFile("new.hog", i, (const char **)files, (void (*)(char *))hogfileRefresh); + NewHogFile("new.hog", i, (const char **)files, (void (*)(char *))hogfileRefresh); } // buildNewHogFileFromList #endif @@ -547,8 +546,15 @@ int main(int argc, char *argv[]) { snprintf(game_version_buffer, sizeof(game_version_buffer), "\n\n" - "Descent 3 Linux %s v%d.%d.%d%s\n" + "Descent 3 %s %s v%d.%d.%d%s\n" "Copyright (C) 1999 Outrage Entertainment, Inc.\n", + +#if defined(__APPLE__) && defined(__MACH__) + "macOS", +#else + "Linux", +#endif + #ifdef DEDICATED "Dedicated Server", #elif DEMO diff --git a/Descent3/loadstate.cpp b/Descent3/loadstate.cpp index 300ca09e..53d3024b 100644 --- a/Descent3/loadstate.cpp +++ b/Descent3/loadstate.cpp @@ -181,7 +181,7 @@ #include "gamesave.h" #include "descent.h" -#include "CFILE.H" +#include "cfile.h" #include "Mission.h" #include "gamesequence.h" #include "gameevent.h" diff --git a/Descent3/localization.cpp b/Descent3/localization.cpp index 7d2eb06f..39099357 100644 --- a/Descent3/localization.cpp +++ b/Descent3/localization.cpp @@ -91,7 +91,7 @@ #include "game.h" #include "descent.h" #include "mono.h" -#include "CFILE.H" +#include "cfile.h" #include "localization.h" #include "mem.h" #include "ddio.h" diff --git a/Descent3/matcen.h b/Descent3/matcen.h index b64181bb..8ae8a6b4 100644 --- a/Descent3/matcen.h +++ b/Descent3/matcen.h @@ -19,7 +19,7 @@ #ifndef _MATCEN_H_ #define _MATCEN_H_ -#include "CFILE.H" +#include "cfile.h" #include "vecmat.h" #include "matcen_external.h" diff --git a/Descent3/multi.cpp b/Descent3/multi.cpp index 31feb295..e2e6fcb9 100644 --- a/Descent3/multi.cpp +++ b/Descent3/multi.cpp @@ -7631,7 +7631,7 @@ void MultiAskForFile(ushort file_id, ushort file_who, ushort who) { // Check to see if this file exists already char *p = GetFileNameFromPlayerAndID(file_who, file_id); if (*p) { - if (CF_ON_DISK == cfexist(p)) { + if (CFES_ON_DISK == cfexist(p)) { char szcrc[_MAX_PATH]; char path[_MAX_PATH]; char ext[_MAX_PATH]; diff --git a/Descent3/multi_external.h b/Descent3/multi_external.h index 6fd12386..9d45d373 100644 --- a/Descent3/multi_external.h +++ b/Descent3/multi_external.h @@ -113,7 +113,7 @@ #include "pstypes.h" #include "manage_external.h" -#include "CFILE.H" +#include "cfile.h" #include "networking.h" #include "descent.h" //for MSN_NAMELEN #include "byteswap.h" diff --git a/Descent3/multi_save_setting.cpp b/Descent3/multi_save_setting.cpp index 69d7d997..00c1eff6 100644 --- a/Descent3/multi_save_setting.cpp +++ b/Descent3/multi_save_setting.cpp @@ -68,7 +68,7 @@ */ #include -#include "CFILE.H" +#include "cfile.h" #include "multi.h" #include "objinfo.h" #include "ship.h" diff --git a/Descent3/newui_filedlg.cpp b/Descent3/newui_filedlg.cpp index 6de8a217..96c0dd73 100644 --- a/Descent3/newui_filedlg.cpp +++ b/Descent3/newui_filedlg.cpp @@ -106,7 +106,7 @@ #include "ddio.h" #include "descent.h" #include "game.h" -#include "CFILE.H" +#include "cfile.h" #include "application.h" #include #include diff --git a/Descent3/osiris_dll.h b/Descent3/osiris_dll.h index c4b244b2..dbb60369 100644 --- a/Descent3/osiris_dll.h +++ b/Descent3/osiris_dll.h @@ -116,7 +116,7 @@ #include "object_external_struct.h" #include "osiris_share.h" #include "module.h" -#include "CFILE.H" +#include "cfile.h" extern uint Osiris_game_checksum; diff --git a/Descent3/osiris_predefs.h b/Descent3/osiris_predefs.h index 66c9ed7e..a2062e22 100644 --- a/Descent3/osiris_predefs.h +++ b/Descent3/osiris_predefs.h @@ -174,7 +174,7 @@ #define __OSIRIS_PREDEF_H_ #include "osiris_dll.h" -#include "CFILE.H" +#include "cfile.h" // osipf_CallObjectEvent // Sends an event to an object. Returns true if the default action should diff --git a/Descent3/pilot.cpp b/Descent3/pilot.cpp index e296129f..d50f4ea2 100644 --- a/Descent3/pilot.cpp +++ b/Descent3/pilot.cpp @@ -581,7 +581,7 @@ #include "ddio.h" #include "descent.h" #include "game.h" -#include "CFILE.H" +#include "cfile.h" #include "application.h" #include "manage.h" #include "newui.h" @@ -951,7 +951,7 @@ void PilotSelect(void) { int res = -1; bool done = false; - if (cfexist(Default_pilot) != CF_NOT_FOUND) { + if (cfexist(Default_pilot) != CFES_NOT_FOUND) { // ok so the default pilot file is around, mark this as the current pilot Current_pilot.set_filename(Default_pilot); PltReadFile(&Current_pilot); @@ -1002,7 +1002,7 @@ void PilotSelect(void) { // use this in case they cancel out Current_pilot.get_filename(pfilename); - if (cfexist(pfilename) != CF_NOT_FOUND) { + if (cfexist(pfilename) != CFES_NOT_FOUND) { strcpy(old_file, pfilename); } else { old_file[0] = '\0'; @@ -1058,7 +1058,7 @@ void PilotSelect(void) { case UID_CANCEL: { // Cancel out - bool found_old = (cfexist(old_file) != CF_NOT_FOUND); + bool found_old = (cfexist(old_file) != CFES_NOT_FOUND); bool display_error; if (filecount && found_old) @@ -1512,7 +1512,7 @@ void NewPltUpdate(newuiListBox *list, char **flist, int filecount, int selected, list->SetCurrentIndex(selected); - if (filename && (cfexist(filename) != CF_NOT_FOUND)) { + if (filename && (cfexist(filename) != CFES_NOT_FOUND)) { // get the selected pilot from the filename mprintf((0, "Looking for Pilot: %s\n", filename)); for (int d = 0; d < filecount; d++) { @@ -2230,7 +2230,7 @@ bool CreateCRCFileName(const char *src, char *dest) { ASSERT(src); ASSERT(dest); - if (cfexist(src) != CF_ON_DISK) + if (cfexist(src) != CFES_ON_DISK) return false; unsigned int crc_value = cf_GetfileCRC((char *)src); @@ -2261,7 +2261,7 @@ bool CreateCRCFileName(const char *src, char *base, char *newfilename) { ASSERT(base); ASSERT(newfilename); - if (cfexist(src) != CF_ON_DISK) + if (cfexist(src) != CFES_ON_DISK) return false; unsigned int crc_value = cf_GetfileCRC((char *)src); @@ -2363,7 +2363,7 @@ float getdist(angle ang, float height) { // newfile = on return true is the filename of the new bitmap bool ImportGraphic(char *pathname, char *newfile) { ASSERT(pathname); - if (cfexist(pathname) != CF_ON_DISK) { + if (cfexist(pathname) != CFES_ON_DISK) { mprintf((0, "'%s' not found\n", pathname)); return false; } diff --git a/Descent3/pilot_class.h b/Descent3/pilot_class.h index d3ea0298..5cbd0544 100644 --- a/Descent3/pilot_class.h +++ b/Descent3/pilot_class.h @@ -90,7 +90,7 @@ #include "pstypes.h" #include "controls.h" #include "Controller.h" -#include "CFILE.H" +#include "cfile.h" #include "weapon.h" #include "config.h" diff --git a/Descent3/vclip.cpp b/Descent3/vclip.cpp index 964ede7b..572a53e5 100644 --- a/Descent3/vclip.cpp +++ b/Descent3/vclip.cpp @@ -160,7 +160,7 @@ #include "pserror.h" #include "bitmap.h" #include "vclip.h" -#include "CFILE.H" +#include "cfile.h" #include "mono.h" #include "ddio.h" #include "gametexture.h" diff --git a/Descent3/weapon.cpp b/Descent3/weapon.cpp index 72064bfb..6dd115a1 100644 --- a/Descent3/weapon.cpp +++ b/Descent3/weapon.cpp @@ -356,7 +356,7 @@ #include "sounds.h" #include "stringtable.h" #include "Macros.h" -#include "CFILE.H" +#include "cfile.h" #include "AIMain.h" #include diff --git a/README.md b/README.md index b66852cb..0f87512b 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ There is no "release" yet. The current milestone is "1.5 Stable", which is meant The milestone needs testing on all platforms. Please report issues when found. ## Usage -Purchase Descent 3 from a reputable source and install it, then replace the main binary with the newly build Descent3 binary under `${CMAKE_BINARY_DIR}/Descent3/*/Descent3[.exe]`. +Purchase Descent 3 from a reputable source and install it, then replace the main binary with the newly built `Descent3` binary under `${CMAKE_BINARY_DIR}/Descent3/*/Descent3[.exe]`. See your platform below: #### Windows @@ -25,26 +25,26 @@ Back up your `Descent3` binary and drop your built `Descent3` binary into the in Build steps below assume you have already cloned the repository and entered it locally. #### Building - Windows -Requires Visual Studio C++ Tools (cmake and nmake) +Requires Visual Studio C++ Tools (cmake and vcpkg) ```sh cmake --preset win -cmake --build --preset win --config [Debug/Release] -D LOGGER=[ON|OFF] +cmake --build --preset win --config [Debug|Release] -D LOGGER=[ON|OFF] ``` #### Building - MacOS ```sh brew bundle install cmake --preset mac -cmake --build --preset mac --config [Debug/Release] -D LOGGER=[ON|OFF] +cmake --build --preset mac --config [Debug|Release] -D LOGGER=[ON|OFF] ``` #### Building - Linux ```sh sudo dpkg --add-architecture i386 sudo apt update -sudo apt install -y --no-install-recommends ninja-build cmake g++ libsdl1.2-dev libsdl-image1.2-dev libncurses-dev libxext6:i386 +sudo apt install -y --no-install-recommends ninja-build cmake g++ libsdl1.2-dev libsdl-image1.2-dev libncurses-dev libxext6:i386 zlib1g-dev cmake --preset linux -cmake --build --preset linux --config [Debug/Release] -D LOGGER=[ON|OFF] +cmake --build --preset linux --config [Debug|Release] -D LOGGER=[ON|OFF] ``` ## Contributing diff --git a/bitmap/CMakeLists.txt b/bitmap/CMakeLists.txt index 8258792f..4822c8f9 100644 --- a/bitmap/CMakeLists.txt +++ b/bitmap/CMakeLists.txt @@ -8,3 +8,6 @@ set(CPPS tga.cpp) add_library(bitmap STATIC ${HEADERS} ${CPPS}) +target_link_libraries(bitmap PRIVATE + cfile +) diff --git a/bitmap/bitmain.cpp b/bitmap/bitmain.cpp index fdfb7cb7..17b40c99 100644 --- a/bitmap/bitmain.cpp +++ b/bitmap/bitmain.cpp @@ -300,7 +300,7 @@ #include #include #include -#include "CFILE.H" +#include "cfile.h" #include "texture.h" #include "bitmap.h" #include "pstypes.h" diff --git a/bitmap/iff.cpp b/bitmap/iff.cpp index 666de390..87b7baa1 100644 --- a/bitmap/iff.cpp +++ b/bitmap/iff.cpp @@ -74,7 +74,7 @@ #include "mem.h" #include "iff.h" #include "byteswap.h" -#include "CFILE.H" +#include "cfile.h" #include "pserror.h" #include "pstypes.h" #include "bitmap.h" diff --git a/bitmap/iff.h b/bitmap/iff.h index 1eecb548..4cbe9558 100644 --- a/bitmap/iff.h +++ b/bitmap/iff.h @@ -19,7 +19,7 @@ #ifndef _IFF_H #define _IFF_H -#include "CFILE.H" +#include "cfile.h" // Error codes for read & write routines diff --git a/bitmap/tga.cpp b/bitmap/tga.cpp index a1a16df2..3accd71c 100644 --- a/bitmap/tga.cpp +++ b/bitmap/tga.cpp @@ -132,7 +132,7 @@ * $NoKeywords: $ */ -#include "CFILE.H" +#include "cfile.h" #include "pserror.h" #include "pstypes.h" #include "bitmap.h" diff --git a/cfile/CMakeLists.txt b/cfile/CMakeLists.txt index 704e3f08..caa9be26 100644 --- a/cfile/CMakeLists.txt +++ b/cfile/CMakeLists.txt @@ -1,7 +1,12 @@ -set(HEADERS) set(CPPS - CFILE.cpp - hog.cpp - InfFile.cpp) + cfile.cpp + hogfile.cpp + inffile.cpp +) -add_library(cfile STATIC ${HEADERS} ${CPPS}) +add_library(cfile STATIC ${CPPS}) +target_include_directories(cfile PUBLIC + $ +) diff --git a/cfile/CFILE.cpp b/cfile/cfile.cpp similarity index 93% rename from cfile/CFILE.cpp rename to cfile/cfile.cpp index e9c46d3a..82b023cc 100644 --- a/cfile/CFILE.cpp +++ b/cfile/cfile.cpp @@ -33,13 +33,15 @@ // Linux Build Includes #include "linux/linux_fix.h" #endif + #include "byteswap.h" #include "pserror.h" #include "ddio.h" #include "psglob.h" -#include "CFILE.H" +#include "cfile.h" #include "hogfile.h" //info about library file #include "mem.h" + // Library structures typedef struct { char name[PSFILENAME_LEN + 1]; // just the filename part @@ -48,25 +50,30 @@ typedef struct { ulong timestamp; // time and date of file int flags; // misc flags } library_entry; + typedef struct library { char name[_MAX_PATH]; // includes path + filename int nfiles; library_entry *entries; struct library *next; - int handle; // indentifier for this lib + int handle; // identifier for this lib FILE *file; // pointer to file for this lib, if no one using it } library; + // entry in extension->path table typedef struct { char ext[_MAX_EXT]; ubyte pathnum; } ext_entry; + // entry in list of paths typedef struct { char path[_MAX_PATH]; ubyte specific; // if non-zero, only for specific extensions } path_entry; + #define MAX_PATHS 100 + path_entry paths[MAX_PATHS]; int N_paths = 0; #define MAX_EXTENSIONS 100 @@ -74,11 +81,12 @@ ext_entry extensions[MAX_EXTENSIONS]; int N_extensions; library *Libraries = NULL; int lib_handle = 0; -void cf_Close(); + // Structure thrown on disk error cfile_error cfe; // The message for unexpected end of file char *eof_error = "Unexpected end of file"; + // Generates a cfile error void ThrowCFileError(int type, CFILE *file, char *msg) { cfe.read_write = type; @@ -86,6 +94,9 @@ void ThrowCFileError(int type, CFILE *file, char *msg) { cfe.file = file; throw &cfe; } + +void cf_Close(); + // Opens a HOG file. Future calls to cfopen(), etc. will look in this HOG. // Parameters: libname - the path & filename of the HOG file // NOTE: libname must be valid for the entire execution of the program. Therefore, it should either @@ -101,7 +112,7 @@ int cf_OpenLibrary(const char *libname) { tHogFileEntry entry; fp = fopen(libname, "rb"); - if (fp == NULL) + if (fp == nullptr) return 0; // CF_NO_FILE; fread(id, strlen(HOG_TAG_STR), 1, fp); if (strncmp(id, HOG_TAG_STR, strlen(HOG_TAG_STR))) { @@ -166,10 +177,13 @@ int cf_OpenLibrary(const char *libname) { // Sucess. Return the handle return lib->handle; } -// Closes a library file. -// Parameters: handle: the handle returned by cf_OpenLibrary() + +/** + * Closes a library file. + * @param handle the handle returned by cf_OpenLibrary() + */ void cf_CloseLibrary(int handle) { - library *lib, *prev = NULL; + library *lib, *prev = nullptr; for (lib = Libraries; lib; prev = lib, lib = lib->next) { if (lib->handle == handle) { if (prev) @@ -180,10 +194,11 @@ void cf_CloseLibrary(int handle) { fclose(lib->file); mem_free(lib->entries); mem_free(lib); - return; // sucessful close + return; // successful close } } } + // Closes down the CFILE system, freeing up all data, etc. void cf_Close() { library *next; @@ -232,16 +247,23 @@ int cf_SetSearchPath(const char *path, ...) { return 1; } -// Removes all search paths that have been added by cf_SetSearchPath -void cf_ClearAllSearchPaths(void) { +/** + * Removes all search paths that have been added by cf_SetSearchPath + */ +void cf_ClearAllSearchPaths() { N_paths = 0; N_extensions = 0; } -// Opens a file for reading in a library, given the library id +/** + * Opens a file for reading in a library, given the library id + * @param filename + * @param libhandle + * @return + */ CFILE *cf_OpenFileInLibrary(const char *filename, int libhandle) { if (libhandle <= 0) - return NULL; + return nullptr; library *lib; CFILE *cfile; @@ -254,9 +276,9 @@ CFILE *cf_OpenFileInLibrary(const char *filename, int libhandle) { lib = lib->next; } - if (NULL == lib) { + if (nullptr == lib) { // couldn't find the library handle - return NULL; + return nullptr; } // now do a binary search for the file entry @@ -276,10 +298,10 @@ CFILE *cf_OpenFileInLibrary(const char *filename, int libhandle) { first = i + 1; else // search key before check key last = i - 1; - } while (1); + } while (true); if (!found) - return NULL; // file not in library + return nullptr; // file not in library // open the file for reading FILE *fp; @@ -287,13 +309,13 @@ CFILE *cf_OpenFileInLibrary(const char *filename, int libhandle) { // See if there's an available FILE if (lib->file) { fp = lib->file; - lib->file = NULL; + lib->file = nullptr; } else { fp = fopen(lib->name, "rb"); if (!fp) { mprintf((1, "Error opening library <%s> when opening file <%s>; errno=%d.", lib->name, filename, errno)); Int3(); - return NULL; + return nullptr; } } cfile = (CFILE *)mem_malloc(sizeof(*cfile)); @@ -333,20 +355,20 @@ CFILE *open_file_in_lib(const char *filename) { first = i + 1; else // search key before check key last = i - 1; - } while (1); + } while (true); if (found) { FILE *fp; int r; // See if there's an available FILE if (lib->file) { fp = lib->file; - lib->file = NULL; + lib->file = nullptr; } else { fp = fopen(lib->name, "rb"); if (!fp) { mprintf((1, "Error opening library <%s> when opening file <%s>; errno=%d.", lib->name, filename, errno)); Int3(); - return NULL; + return nullptr; } } cfile = (CFILE *)mem_malloc(sizeof(*cfile)); @@ -365,7 +387,7 @@ CFILE *open_file_in_lib(const char *filename) { } lib = lib->next; } - return NULL; + return nullptr; } #ifdef __LINUX__ @@ -382,7 +404,7 @@ public: bool Start(const char *wildcard, char *namebuf); bool Next(char *namebuf); - void Close(void); + void Close(); private: int globindex; @@ -411,7 +433,7 @@ bool CFindFiles::Start(const char *wildcard, char *namebuf) { globindex = 0; char ext[256]; - ddio_SplitPath(ffres.gl_pathv[0], NULL, namebuf, ext); + ddio_SplitPath(ffres.gl_pathv[0], nullptr, namebuf, ext); strcat(namebuf, ext); return true; } @@ -425,12 +447,12 @@ bool CFindFiles::Next(char *namebuf) { return false; char ext[256]; - ddio_SplitPath(ffres.gl_pathv[globindex], NULL, namebuf, ext); + ddio_SplitPath(ffres.gl_pathv[globindex], nullptr, namebuf, ext); strcat(namebuf, ext); return true; } -void CFindFiles::Close(void) { +void CFindFiles::Close() { if (globindex == -1) return; globindex = -1; @@ -467,7 +489,7 @@ bool cf_FindRealFileNameCaseInsenstive(const char *directory, const char *fname, mprintf((1, "CFILE: Found directory \"%s\" in filename, new filename is \"%s\"\n", real_dir, real_file)); } else { use_dir = false; - real_dir = NULL; + real_dir = nullptr; real_file = (char *)fname; } } @@ -574,7 +596,7 @@ FILE *open_file_in_directory_case_sensitive(const char *directory, const char *f if (cf_FindRealFileNameCaseInsenstive(directory, filename, new_filename)) { // we have a file, open it open and use it char full_path[_MAX_PATH * 2]; - if (directory != NULL) { + if (directory != nullptr) { ddio_MakePath(full_path, directory, new_filename, NULL); } else { strcpy(full_path, new_filename); @@ -583,7 +605,7 @@ FILE *open_file_in_directory_case_sensitive(const char *directory, const char *f return fopen(full_path, mode); } - return NULL; + return nullptr; } #endif @@ -593,7 +615,7 @@ CFILE *open_file_in_directory(const char *filename, const char *mode, const char CFILE *cfile; char path[_MAX_PATH * 2]; char tmode[3] = "rb"; - if (directory != NULL) { + if (directory != nullptr) { // Make a full path ddio_MakePath(path, directory, filename, NULL); } else // no directory specified, so just use filename passed @@ -634,7 +656,7 @@ CFILE *open_file_in_directory(const char *filename, const char *mode, const char fp = open_file_in_directory_case_sensitive(directory, filename, tmode, using_filename); if (!fp) { // no dice - return NULL; + return nullptr; } else { // found a version of the file! mprintf((0, "CFILE: Unable to find %s, but using %s instead\n", filename, using_filename)); @@ -692,9 +714,9 @@ CFILE *cfopen(const char *filename, const char *mode) { ddio_SplitPath(filename, path, fname, ext); // if there is a path specified, use it instead of the libraries, search dirs, etc. // if the file is writable, just open it, instead of looking in libs, etc. - if (strlen(path) || (mode[0] == 'w')) { // found a path - cfile = open_file_in_directory(filename, mode, NULL); // use path specified with file - goto got_file; // don't look in libs, etc. + if (strlen(path) || (mode[0] == 'w')) { // found a path + cfile = open_file_in_directory(filename, mode, nullptr); // use path specified with file + goto got_file; // don't look in libs, etc. } //@@ Don't look in current dir. mt, 3-12-97 //@@ //first look in current directory @@ -722,15 +744,17 @@ CFILE *cfopen(const char *filename, const char *mode) { got_file:; if (cfile) { if (mode[0] == 'w') - cfile->flags |= CF_WRITING; + cfile->flags |= CFF_WRITING; if (mode[1] == 't') - cfile->flags |= CF_TEXT; + cfile->flags |= CFF_TEXT; } return cfile; } + // Returns the length of the specified file // Parameters: cfp - the file pointer returned by cfopen() int cfilelength(CFILE *cfp) { return cfp->size; } + // Closes an open CFILE. // Parameters: cfile - the file pointer returned by cfopen() void cfclose(CFILE *cfp) { @@ -740,9 +764,9 @@ void cfclose(CFILE *cfp) { for (lib = Libraries; lib; lib = lib->next) { if (lib->handle == cfp->lib_handle) { // found the library // if library doesn't already have a file, give it this one - if (lib->file == NULL) { + if (lib->file == nullptr) { lib->file = cfp->file; - cfp->file = NULL; + cfp->file = nullptr; } break; } @@ -757,6 +781,7 @@ void cfclose(CFILE *cfp) { // free the cfile struct mem_free(cfp); } + // Just like stdio fgetc(), except works on a CFILE // Returns a char or EOF int cfgetc(CFILE *cfp) { @@ -775,7 +800,7 @@ int cfgetc(CFILE *cfp) { // do special newline handling for text files: // if CR or LF by itself, return as newline // if CR/LF pair, return as newline - if (cfp->flags & CF_TEXT) { + if (cfp->flags & CFF_TEXT) { if (c == 10) // return LF as newline c = '\n'; else if (c == 13) { // check for CR/LF pair @@ -816,10 +841,13 @@ int cfseek(CFILE *cfp, long int offset, int where) { cfp->position = ftell(cfp->file) - cfp->lib_offset; return c; } + // Just like stdio ftell(), except works on a CFILE int cftell(CFILE *cfp) { return cfp->position; } + // Returns true if at EOF int cfeof(CFILE *cfp) { return (cfp->position >= cfp->size); } + // Tells if the file exists // Returns non-zero if file exists. Also tells if the file is on disk // or in a hog - See return values in cfile.h @@ -830,12 +858,12 @@ int cfexist(const char *filename) { cfp = cfopen(filename, "rb"); if (!cfp) { // Didn't get file. Why? if (errno == EACCES) // File exists, but couldn't open it - return CF_ON_DISK; //..so say it exists on the disk + return CFES_ON_DISK; // so say it exists on the disk // DAJ if (errno != ENOENT) //Check if error is "file not found" // DAJ Int3(); //..warn if not - return CF_NOT_FOUND; // Say we didn't find the file + return CFES_NOT_FOUND; // Say we didn't find the file } - ret = cfp->lib_offset ? CF_IN_LIBRARY : CF_ON_DISK; + ret = cfp->lib_offset ? CFES_IN_LIBRARY : CFES_ON_DISK; cfclose(cfp); return ret; } @@ -847,7 +875,7 @@ int cfexist(const char *filename) { int cf_ReadBytes(ubyte *buf, int count, CFILE *cfp) { int i; char *error_msg = eof_error; // default error - ASSERT(!(cfp->flags & CF_TEXT)); + ASSERT(!(cfp->flags & CFF_TEXT)); if (cfp->position + count <= cfp->size) { i = fread(buf, 1, count, cfp->file); if (i == count) { @@ -871,26 +899,26 @@ int cf_ReadBytes(ubyte *buf, int count, CFILE *cfp) { // to be present. // Read and return an integer (32 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on read -int cf_ReadInt(CFILE *cfp) { - int i; +int32_t cf_ReadInt(CFILE *cfp) { + int32_t i; cf_ReadBytes((ubyte *)&i, sizeof(i), cfp); return INTEL_INT(i); } // Read and return a short (16 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on read -short cf_ReadShort(CFILE *cfp) { - short i; +int16_t cf_ReadShort(CFILE *cfp) { + int16_t i; cf_ReadBytes((ubyte *)&i, sizeof(i), cfp); return INTEL_SHORT(i); } // Read and return a byte (8 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on read -sbyte cf_ReadByte(CFILE *cfp) { +int8_t cf_ReadByte(CFILE *cfp) { int i; i = cfgetc(cfp); if (i == EOF) ThrowCFileError(CFE_READING, cfp, cfeof(cfp) ? eof_error : strerror(errno)); - return (sbyte)i; + return (int8_t)i; } // Read and return a float (32 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on read @@ -947,7 +975,7 @@ int cf_ReadString(char *buf, size_t n, CFILE *cfp) { break; } - if ((!(cfp->flags & CF_TEXT) && (c == 0)) || ((cfp->flags & CF_TEXT) && (c == '\n'))) + if ((!(cfp->flags & CFF_TEXT) && (c == 0)) || ((cfp->flags & CFF_TEXT) && (c == '\n'))) break; // end-of-string if (count < n - 1) // store char if room in buffer *bp++ = c; @@ -962,7 +990,7 @@ int cf_ReadString(char *buf, size_t n, CFILE *cfp) { // Throws an exception of type (cfile_error *) if the OS returns an error on write int cf_WriteBytes(const ubyte *buf, int count, CFILE *cfp) { int i; - if (!(cfp->flags & CF_WRITING)) + if (!(cfp->flags & CFF_WRITING)) return 0; ASSERT(count > 0); i = fwrite(buf, 1, count, cfp->file); @@ -984,9 +1012,10 @@ int cf_WriteString(CFILE *cfp, const char *buf) { if (len != 0) // write string cf_WriteBytes((ubyte *)buf, len, cfp); // Terminate with newline (text file) or NULL (binary file) - cf_WriteByte(cfp, (cfp->flags & CF_TEXT) ? '\n' : 0); + cf_WriteByte(cfp, (cfp->flags & CFF_TEXT) ? '\n' : 0); return len + 1; } + // Just like stdio fprintf(), except works on a CFILE int cfprintf(CFILE *cfp, const char *format, ...) { #ifndef MACINTOSH @@ -999,40 +1028,45 @@ int cfprintf(CFILE *cfp, const char *format, ...) { return count; #endif } + // The following functions write numeric vales to a CFILE. All values are // stored to the file in Intel (little-endian) format. // All these throw an exception if there's an error on write. // Write an integer (32 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on write -void cf_WriteInt(CFILE *cfp, int i) { +void cf_WriteInt(CFILE *cfp, int32_t i) { int t = INTEL_INT(i); cf_WriteBytes((ubyte *)&t, sizeof(t), cfp); } + // Write a short (16 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on write -void cf_WriteShort(CFILE *cfp, short s) { +void cf_WriteShort(CFILE *cfp, int16_t s) { short t = INTEL_SHORT(s); cf_WriteBytes((ubyte *)&t, sizeof(t), cfp); } + // Write a byte (8 bits). // Throws an exception of type (cfile_error *) if the OS returns an error on write -void cf_WriteByte(CFILE *cfp, sbyte b) { +void cf_WriteByte(CFILE *cfp, int8_t b) { if (fputc(b, cfp->file) == EOF) ThrowCFileError(CFE_WRITING, cfp, strerror(errno)); cfp->position++; // If text file & writing newline, increment again for LF - if ((cfp->flags & CF_TEXT) && (b == '\n')) // check for text mode newline + if ((cfp->flags & CFF_TEXT) && (b == '\n')) // check for text mode newline cfp->position++; } + // Write a float (32 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on write -void cf_WriteFloat(CFILE *cfp, float f) { +void cf_WriteFloat(CFILE *cfp, float_t f) { float t = INTEL_FLOAT(f); cf_WriteBytes((ubyte *)&t, sizeof(t), cfp); } + // Write a double (64 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on write -void cf_WriteDouble(CFILE *cfp, double d) { +void cf_WriteDouble(CFILE *cfp, double_t d) { #ifdef OUTRAGE_BIG_ENDIAN { double t; @@ -1045,19 +1079,20 @@ void cf_WriteDouble(CFILE *cfp, double d) { #endif cf_WriteBytes((ubyte *)&d, sizeof(d), cfp); } + // Copies a file. Returns TRUE if copied ok. Returns FALSE if error opening either file. // Throws an exception of type (cfile_error *) if the OS returns an error on read or write bool cf_CopyFile(char *dest, const char *src, int copytime) { CFILE *infile, *outfile; if (!stricmp(dest, src)) - return 1; // don't copy files if they are the same + return true; // don't copy files if they are the same infile = (CFILE *)cfopen(src, "rb"); if (!infile) - return 0; + return false; outfile = (CFILE *)cfopen(dest, "wb"); if (!outfile) { cfclose(infile); - return 0; + return false; } int progress = 0; int readcount = 0; @@ -1083,13 +1118,16 @@ bool cf_CopyFile(char *dest, const char *src, int copytime) { if (!infile_lib_offset && copytime) { cf_CopyFileTime(dest, src); } - return 1; + return true; } + // Checks to see if two files are different. // Returns TRUE if the files are different, or FALSE if they are the same. bool cf_Diff(const char *a, const char *b) { return (ddio_FileDiff(a, b)); } + // Copies the file time from one file to another void cf_CopyFileTime(char *dest, const char *src) { ddio_CopyFileTime(dest, src); } + // Changes a files attributes (ie read/write only) void cf_ChangeFileAttributes(const char *name, int attr) { #ifdef MACINTOSH @@ -1099,6 +1137,7 @@ void cf_ChangeFileAttributes(const char *name, int attr) { Int3(); // Get Jason or Matt, file not found! #endif } + // rewinds cfile position void cf_Rewind(CFILE *fp) { if (fp->lib_offset) { @@ -1109,7 +1148,8 @@ void cf_Rewind(CFILE *fp) { } fp->position = 0; } -// Calculates a 32 bit CRC for the specified file. a return code of -1 means file note found + +// Calculates a 32-bit CRC for the specified file. a return code of -1 means file note found #define CRC32_POLYNOMIAL 0xEDB88320L #define CRC_BUFFER_SIZE 5000 @@ -1174,7 +1214,7 @@ unsigned int cf_GetfileCRC(char *src) { } char cfile_search_wildcard[256]; -library *cfile_search_library = NULL; +library *cfile_search_library = nullptr; int cfile_search_curr_index = 0; bool cfile_search_ispattern = false; // the following cf_LibraryFind function are similar to the ddio_Find functions as they look @@ -1220,6 +1260,7 @@ bool cf_LibraryFindFirst(int handle, const char *wildcard, char *buffer) { // we didn't find a match return false; } + bool cf_LibraryFindNext(char *buffer) { while (cfile_search_curr_index < cfile_search_library->nfiles) { if (cfile_search_ispattern) { @@ -1240,8 +1281,9 @@ bool cf_LibraryFindNext(char *buffer) { } return false; } -void cf_LibraryFindClose(void) { - cfile_search_library = NULL; + +void cf_LibraryFindClose() { + cfile_search_library = nullptr; cfile_search_curr_index = 0; cfile_search_ispattern = false; } @@ -1277,7 +1319,7 @@ bool cf_ReadHogFileEntry(int libr, const char *filename, tHogFileEntry *entry, i else // search key before check key last = i - 1; - } while (1); + } while (true); if (found) { strcpy(entry->name, lib->entries[i].name); diff --git a/lib/CFILE.H b/cfile/cfile.h similarity index 92% rename from lib/CFILE.H rename to cfile/cfile.h index 6dd11765..7b7cf94f 100644 --- a/lib/CFILE.H +++ b/cfile/cfile.h @@ -76,7 +76,9 @@ #ifndef CFILE_H #define CFILE_H -#include +#include +#include +#include #include "pstypes.h" @@ -94,8 +96,10 @@ typedef struct CFILE { } CFILE; // Defines for cfile_error -#define CFE_READING 1 -#define CFE_WRITING 2 +enum CFileError { + CFE_READING = 1, + CFE_WRITING, +}; // The structure thrown by a cfile error typedef struct { @@ -105,8 +109,17 @@ typedef struct { } cfile_error; // Flags for CFILE struct -#define CF_TEXT 1 // if this bit set, file is text -#define CF_WRITING 2 // if bit set, file opened for writing +enum CFileFlags { + CFF_TEXT = 1, // if this bit set, file is text + CFF_WRITING, // if bit set, file opened for writing +}; + +// return values for cfexist() +enum CFileExitStatus { + CFES_NOT_FOUND = 0, + CFES_ON_DISK, + CFES_IN_LIBRARY, +}; // See if a file is in a hog bool cf_IsFileInHog(char *filename, char *hogname); @@ -130,7 +143,7 @@ void cf_CloseLibrary(int handle); int cf_SetSearchPath(const char *path, ...); // Removes all search paths that have been added by cf_SetSearchPath -void cf_ClearAllSearchPaths(void); +void cf_ClearAllSearchPaths(); // Opens a file for reading or writing // If a path is specified, will try to open the file only in that path. @@ -167,11 +180,6 @@ int cftell(CFILE *cfp); // Returns true if at EOF int cfeof(CFILE *cfp); -// return values for cfexist() -#define CF_NOT_FOUND 0 -#define CF_ON_DISK 1 -#define CF_IN_LIBRARY 2 - // Tells if the file exists // Returns non-zero if file exists. Also tells if the file is on disk // or in a hog - See return values in cfile.h @@ -192,15 +200,15 @@ int cf_ReadBytes(ubyte *buf, int count, CFILE *cfp); // Read and return an integer (32 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on read -int cf_ReadInt(CFILE *cfp); +int32_t cf_ReadInt(CFILE *cfp); // Read and return a short (16 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on read -short cf_ReadShort(CFILE *cfp); +int16_t cf_ReadShort(CFILE *cfp); // Read and return a byte (8 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on read -sbyte cf_ReadByte(CFILE *cfp); +int8_t cf_ReadByte(CFILE *cfp); // Read and return a float (32 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on read @@ -246,23 +254,23 @@ int cfprintf(CFILE *cfp, const char *format, ...); // Write an integer (32 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on write -void cf_WriteInt(CFILE *cfp, int i); +void cf_WriteInt(CFILE *cfp, int32_t i); // Write a short (16 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on write -void cf_WriteShort(CFILE *cfp, short s); +void cf_WriteShort(CFILE *cfp, int16_t s); // Write a byte (8 bits). If the byte is a newline & the file is a text file, writes a CR/LF pair. // Throws an exception of type (cfile_error *) if the OS returns an error on write -void cf_WriteByte(CFILE *cfp, sbyte b); +void cf_WriteByte(CFILE *cfp, int8_t b); // Write a float (32 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on write -void cf_WriteFloat(CFILE *cfp, float f); +void cf_WriteFloat(CFILE *cfp, float_t f); // Write a double (64 bits) // Throws an exception of type (cfile_error *) if the OS returns an error on write -void cf_WriteDouble(CFILE *cfp, double d); +void cf_WriteDouble(CFILE *cfp, double_t d); // Copies a file. Returns TRUE if copied ok. Returns FALSE if error opening either file. // Throws an exception of type (cfile_error *) if the OS returns an error on read or write @@ -279,17 +287,17 @@ void cf_CopyFileTime(char *dest, const char *src); // Changes a files attributes (ie read/write only) void cf_ChangeFileAttributes(const char *name, int attr); -// rewinds cfile position +// rewinds cfile position void cf_Rewind(CFILE *fp); // Calculates a 32 bit CRC unsigned int cf_GetfileCRC(char *src); unsigned int cf_CalculateFileCRC(CFILE *fp); // same as cf_GetfileCRC, except works with CFILE pointers -// the following cf_LibraryFind function are similar to the ddio_Find functions as they look -// for files that match the wildcard passed in, however, this is to be used for hog files. +// the following cf_LibraryFind function are similar to the ddio_Find functions as they look +// for files that match the wildcard passed in, however, this is to be used for hog files. bool cf_LibraryFindFirst(int handle, const char *wildcard, char *buffer); bool cf_LibraryFindNext(char *buffer); -void cf_LibraryFindClose(void); +void cf_LibraryFindClose(); #endif diff --git a/cfile/hog.cpp b/cfile/hogfile.cpp similarity index 67% rename from cfile/hog.cpp rename to cfile/hogfile.cpp index 1128ff59..2e05fefc 100644 --- a/cfile/hog.cpp +++ b/cfile/hogfile.cpp @@ -152,7 +152,7 @@ bool FileCopy(FILE *ofp, FILE *ifp, int length) { return true; } bool ReadHogHeader(FILE *fp, tHogHeader *header) { - int res = 0; + int res; res = fread(&header->nfiles, sizeof(header->nfiles), 1, fp); header->nfiles = INTEL_INT(header->nfiles); res = fread(&header->file_data_offset, sizeof(header->file_data_offset), 1, fp); @@ -164,7 +164,7 @@ bool ReadHogHeader(FILE *fp, tHogHeader *header) { return false; } bool ReadHogEntry(FILE *fp, tHogFileEntry *entry) { - int res = 0; + int res; res = fread(entry->name, sizeof(char), HOG_FILENAME_LEN, fp); res = fread(&entry->flags, sizeof(entry->flags), 1, fp); entry->flags = INTEL_INT(entry->flags); @@ -179,8 +179,8 @@ bool ReadHogEntry(FILE *fp, tHogFileEntry *entry) { return false; } -bool WRITE_FILE_ENTRY(FILE *fp, tHogFileEntry *entry) { - int res = 0; +bool WriteHogEntry(FILE *fp, tHogFileEntry *entry) { + int res; res = fwrite(entry->name, sizeof(char), HOG_FILENAME_LEN, fp); res = fwrite(&entry->flags, sizeof(entry->flags), 1, fp); res = fwrite(&entry->len, sizeof(entry->len), 1, fp); @@ -191,127 +191,11 @@ bool WRITE_FILE_ENTRY(FILE *fp, tHogFileEntry *entry) { else return false; } -//////////////////////////////////////////////////////////////////////// -// create new hog file -int NewHogFile(const char *hogname, int nfiles, const char **filenames) { - unsigned i; - int table_pos; - FILE *hog_fp; - tHogHeader header; - tHogFileEntry *table; - char ext[_MAX_EXT]; - hogerr_filename[0] = '\0'; - // allocate file table - if (nfiles <= 0) - return HOGMAKER_ERROR; - table = new tHogFileEntry[nfiles]; - if (!table) - return HOGMAKER_MEMORY; - // create new file - hog_fp = fopen(hogname, "wb"); - if (hog_fp == NULL) { - delete[] table; - strcpy(hogerr_filename, hogname); - return HOGMAKER_OPENOUTFILE; - } - // write the tag - if (!fwrite(HOG_TAG_STR, strlen(HOG_TAG_STR), 1, hog_fp)) { - delete[] table; - fclose(hog_fp); - strcpy(hogerr_filename, hogname); - return HOGMAKER_OUTFILE; - } - // write number of files - ubyte filler = 0xff; - header.nfiles = (unsigned)nfiles; - header.file_data_offset = strlen(HOG_TAG_STR) + HOG_HDR_SIZE + (sizeof(tHogFileEntry) * header.nfiles); - if (!fwrite(&header.nfiles, sizeof(header.nfiles), 1, hog_fp)) { - delete[] table; - fclose(hog_fp); - strcpy(hogerr_filename, hogname); - return HOGMAKER_OUTFILE; - } - if (!fwrite(&header.file_data_offset, sizeof(header.file_data_offset), 1, hog_fp)) { - delete[] table; - fclose(hog_fp); - strcpy(hogerr_filename, hogname); - return HOGMAKER_OUTFILE; - } - // write out filler - for (i = 0; i < HOG_HDR_SIZE - sizeof(tHogHeader); i++) - if (!fwrite(&filler, sizeof(ubyte), 1, hog_fp)) { - delete[] table; - fclose(hog_fp); - strcpy(hogerr_filename, hogname); - return HOGMAKER_OUTFILE; - } - // save file position of index table and write out dummy table - table_pos = strlen(HOG_TAG_STR) + HOG_HDR_SIZE; - memset(&table[0], 0, sizeof(table[0])); - for (i = 0; i < header.nfiles; i++) { - if (!WRITE_FILE_ENTRY(hog_fp, &table[0])) { - delete[] table; - fclose(hog_fp); - strcpy(hogerr_filename, hogname); - return HOGMAKER_OUTFILE; - } - } - // write files (& build index) - for (i = 0; i < header.nfiles; i++) { - FILE *ifp; -#if defined(__LINUX__) || defined(MACINTOSH) - struct stat mystat; -#else - struct _stat32 mystat; -#endif - ifp = fopen(filenames[i], "rb"); - if (ifp == NULL) { - delete[] table; - fclose(hog_fp); - strcpy(hogerr_filename, filenames[i]); - return HOGMAKER_INFILE; - } - // JEFF: make call to ddio lib, linux doesn't have _splitpath - //_splitpath(filenames[i],NULL,NULL,table[i].name,ext); - ddio_SplitPath(filenames[i], NULL, table[i].name, ext); - _fstat32(fileno(ifp), &mystat); - - strcat(table[i].name, ext); - table[i].flags = 0; -#ifdef MACINTOSH - table[i].len = mystat.st_size; -#else - table[i].len = _filelength(fileno(ifp)); -#endif - table[i].timestamp = mystat.st_mtime; - if (!FileCopy(hog_fp, ifp, table[i].len)) { - delete[] table; - fclose(hog_fp); - strcpy(hogerr_filename, filenames[i]); - return HOGMAKER_COPY; - } - fclose(ifp); - } - // now write the real index - fseek(hog_fp, table_pos, SEEK_SET); - for (i = 0; i < header.nfiles; i++) { - if (!WRITE_FILE_ENTRY(hog_fp, &table[i])) { - delete[] table; - fclose(hog_fp); - strcpy(hogerr_filename, hogname); - return HOGMAKER_OUTFILE; - } - } - // cleanup - fclose(hog_fp); - delete[] table; - return HOGMAKER_OK; -} -// A modifed version of NewHogFile() +// A modified version of NewHogFile() // This one also takes a pointer to a function that will perform // progress updates (for the user) -int CreateNewHogFile(const char *hogname, int nfiles, const char **filenames, void (*UpdateFunction)(char *)) { +int NewHogFile(const char *hogname, int nfiles, const char **filenames, void (*UpdateFunction)(char *)) { unsigned i; int table_pos; FILE *hog_fp; @@ -319,7 +203,7 @@ int CreateNewHogFile(const char *hogname, int nfiles, const char **filenames, vo tHogFileEntry *table; char ext[_MAX_EXT]; hogerr_filename[0] = '\0'; - // allocate file table + // allocate file table if (nfiles <= 0) return HOGMAKER_ERROR; table = new tHogFileEntry[nfiles]; @@ -367,7 +251,7 @@ int CreateNewHogFile(const char *hogname, int nfiles, const char **filenames, vo table_pos = strlen(HOG_TAG_STR) + HOG_HDR_SIZE; memset(&table[0], 0, sizeof(table[0])); for (i = 0; i < header.nfiles; i++) { - if (!WRITE_FILE_ENTRY(hog_fp, &table[0])) { + if (!WriteHogEntry(hog_fp, &table[0])) { delete[] table; fclose(hog_fp); strcpy(hogerr_filename, hogname); @@ -408,30 +292,32 @@ int CreateNewHogFile(const char *hogname, int nfiles, const char **filenames, vo return HOGMAKER_COPY; } fclose(ifp); - // Setup the update message and send it - char msg[256]; - int ipct = int(100.0 * (double(i) / double(header.nfiles))); - snprintf(msg, sizeof(msg), "Creating Hog File... (%d%% done)", ipct); - if (UpdateFunction != NULL) + if (UpdateFunction != nullptr) { + // Setup the update message and send it + char msg[256]; + int ipct = int(100.0 * (double(i) / double(header.nfiles))); + snprintf(msg, sizeof(msg), "Creating Hog File... (%d%% done)", ipct); UpdateFunction(msg); + } } // now write the real index fseek(hog_fp, table_pos, SEEK_SET); for (i = 0; i < header.nfiles; i++) { - if (!WRITE_FILE_ENTRY(hog_fp, &table[i])) { + if (!WriteHogEntry(hog_fp, &table[i])) { delete[] table; fclose(hog_fp); strcpy(hogerr_filename, hogname); return HOGMAKER_OUTFILE; } } - // cleanup + // cleanup fclose(hog_fp); delete[] table; - // Setup the update message and send it - char msg[256]; - snprintf(msg, sizeof(msg), "Done Creating Hog File."); - if (UpdateFunction != NULL) + if (UpdateFunction != nullptr) { + // Setup the update message and send it + char msg[256]; + snprintf(msg, sizeof(msg), "Done Creating Hog File."); UpdateFunction(msg); + } return HOGMAKER_OK; } diff --git a/lib/hogfile.h b/cfile/hogfile.h similarity index 70% rename from lib/hogfile.h rename to cfile/hogfile.h index d141d55c..6c709e80 100644 --- a/lib/hogfile.h +++ b/cfile/hogfile.h @@ -60,6 +60,7 @@ #ifndef HOGFILE_H #define HOGFILE_H +#include #include "pstypes.h" #define HOG_HDR_SIZE (64) @@ -67,37 +68,37 @@ #define HOG_FILENAME_LEN (36) typedef struct tHogHeader { - unsigned nfiles; // number of files in header - unsigned file_data_offset; // offset in file to filedata. + uint32_t nfiles; // number of files in header + uint32_t file_data_offset; // offset in file to filedata. } tHogHeader; typedef struct tHogFileEntry { char name[HOG_FILENAME_LEN]; // file name - unsigned flags; // extra info - unsigned len; // length of file - unsigned timestamp; // time of file. + uint32_t flags; // extra info + uint32_t len; // length of file + uint32_t timestamp; // time of file. } tHogFileEntry; -#define HOGMAKER_ERROR 0 // Incorrect number of files passed in -#define HOGMAKER_OK 1 // Hog file was created successfully -#define HOGMAKER_MEMORY 2 // Could not allocated hog entry table -#define HOGMAKER_OUTFILE 3 // Error occurred writing to output hog file -#define HOGMAKER_INFILE 4 // An input file could not be found (filename is stored in hogerr_filename) -#define HOGMAKER_COPY 5 // An error occurred copying an input file into the hog file -#define HOGMAKER_OPENOUTFILE 6 // The specified hog file could not be opened for output +enum HogErrors { + HOGMAKER_ERROR = 0, // Incorrect number of files passed in + HOGMAKER_OK, // Hog file was created successfully + HOGMAKER_MEMORY, // Could not allocate hog entry table + HOGMAKER_OUTFILE, // Error occurred writing to output hog file + HOGMAKER_INFILE, // An input file could not be found (filename is stored in hogerr_filename) + HOGMAKER_COPY, // An error occurred copying an input file into the hog file + HOGMAKER_OPENOUTFILE, // The specified hog file could not be opened for output +}; // Used to return filenames involved in a NewHogFile() error extern char hogerr_filename[PSPATHNAME_LEN]; -int NewHogFile(const char *hogname, int nfiles, const char **filenames); +int NewHogFile(const char *hogname, int nfiles, const char **filenames, void (*UpdateFunction)(char *) = nullptr); bool ReadHogHeader(FILE *fp, tHogHeader *header); bool ReadHogEntry(FILE *fp, tHogFileEntry *entry); -bool WRITE_FILE_ENTRY(FILE *fp, tHogFileEntry *entry); +bool WriteHogEntry(FILE *fp, tHogFileEntry *entry); bool FileCopy(FILE *ofp, FILE *ifp, int length); -int CreateNewHogFile(const char *hogname, int nfiles, const char **filenames, void (*UpdateFunction)(char *)); - // returns hog cfile info, using a library handle opened via cf_OpenLibrary. bool cf_ReadHogFileEntry(int library, const char *filename, tHogFileEntry *entry, int *fileoffset); -#endif \ No newline at end of file +#endif diff --git a/cfile/InfFile.cpp b/cfile/inffile.cpp similarity index 97% rename from cfile/InfFile.cpp rename to cfile/inffile.cpp index 5be72c22..f94e002d 100644 --- a/cfile/InfFile.cpp +++ b/cfile/inffile.cpp @@ -20,21 +20,21 @@ // ////////////////////////////////////////////////////////////////////// -#include "InfFile.h" +#include "inffile.h" -#include "CFILE.H" +#include "cfile.h" #include "pstring.h" #include "pserror.h" #include -#define INFFILE_NULL -1024 +#define INFFILE_NULL (-1024) ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// -InfFile::InfFile() { m_fp = NULL; } +InfFile::InfFile() { m_fp = nullptr; } InfFile::~InfFile() { // close file and free symbol lists @@ -74,7 +74,7 @@ const char *InfFile::GetSymbolText(const char *name) { return (const char *)sym->t.text; } - return NULL; + return nullptr; } // opens an inf file, pass in a lexical analyzer that will return a command index. diff --git a/lib/InfFile.h b/cfile/inffile.h similarity index 85% rename from lib/InfFile.h rename to cfile/inffile.h index d7d55723..22ae31da 100644 --- a/lib/InfFile.h +++ b/cfile/inffile.h @@ -20,8 +20,8 @@ // ////////////////////////////////////////////////////////////////////// -#if !defined(AFX_INFFILE_H__D8F94664_216E_11D2_AF2D_0060089A8025__INCLUDED_) -#define AFX_INFFILE_H__D8F94664_216E_11D2_AF2D_0060089A8025__INCLUDED_ +#ifndef INFFILE_H +#define INFFILE_H #if _MSC_VER >= 1000 #pragma once @@ -32,12 +32,14 @@ struct CFILE; -#define INFFILE_LINELEN 256 -#define INFFILE_CUSTOM -128 -#define INFFILE_ERROR -1 -#define INFFILE_COMMENT -2 -#define INFFILE_EOL -3 -#define INFFILE_SYMBOL 1024 +enum InfFileError { + INFFILE_LINELEN = 256, + INFFILE_CUSTOM = -128, + INFFILE_ERROR = -1, + INFFILE_COMMENT = -2, + INFFILE_EOL = -3, + INFFILE_SYMBOL = 1024, +}; class InfFile { public: @@ -86,4 +88,4 @@ public: int line() const { return m_line; }; }; -#endif // !defined(AFX_INFFILE_H__D8F94664_216E_11D2_AF2D_0060089A8025__INCLUDED_) +#endif diff --git a/dd_lnxsound/lnxsound.cpp b/dd_lnxsound/lnxsound.cpp index 86c25b0d..dc75ded7 100644 --- a/dd_lnxsound/lnxsound.cpp +++ b/dd_lnxsound/lnxsound.cpp @@ -108,7 +108,7 @@ #include #include #include -#include "CFILE.H" +#include "cfile.h" #include "pserror.h" #include "mono.h" #include "soundload.h" diff --git a/dd_lnxsound/sdlsound.cpp b/dd_lnxsound/sdlsound.cpp index e8591491..4f253921 100644 --- a/dd_lnxsound/sdlsound.cpp +++ b/dd_lnxsound/sdlsound.cpp @@ -30,7 +30,7 @@ #include #include #include -#include "CFILE.H" +#include "cfile.h" #include "pserror.h" #include "mono.h" #include "soundload.h" diff --git a/dd_sndlib/CMakeLists.txt b/dd_sndlib/CMakeLists.txt index 6db7ec36..d50bc484 100644 --- a/dd_sndlib/CMakeLists.txt +++ b/dd_sndlib/CMakeLists.txt @@ -16,3 +16,6 @@ set(CPPS ssl_lib.cpp) add_library(dd_sndlib STATIC ${HEADERS} ${CPPS}) +target_link_libraries(dd_sndlib PRIVATE + cfile +) diff --git a/dd_sndlib/ddsoundload.cpp b/dd_sndlib/ddsoundload.cpp index 9246daba..f703eac6 100644 --- a/dd_sndlib/ddsoundload.cpp +++ b/dd_sndlib/ddsoundload.cpp @@ -101,7 +101,7 @@ #else #include #endif -#include "CFILE.H" +#include "cfile.h" #include "mem.h" #include "pserror.h" #include diff --git a/grtext/grfont.cpp b/grtext/grfont.cpp index 520cb342..f08117f7 100644 --- a/grtext/grfont.cpp +++ b/grtext/grfont.cpp @@ -108,7 +108,7 @@ */ #include "grtextlib.h" -#include "CFILE.H" +#include "cfile.h" #include "bitmap.h" #include "pserror.h" #include "renderer.h" diff --git a/lib/bitmap.h b/lib/bitmap.h index 92999409..3030b36c 100644 --- a/lib/bitmap.h +++ b/lib/bitmap.h @@ -19,7 +19,7 @@ #ifndef PSBITMAP_H #define PSBITMAP_H #include "pstypes.h" -#include "CFILE.H" +#include "cfile.h" #ifdef __LINUX__ #include "linux/linux_fix.h" //needed for stricmp's throughout bitmap lib #endif diff --git a/lib/byteswap.h b/lib/byteswap.h index 8c6b2d3a..7ee39fe9 100644 --- a/lib/byteswap.h +++ b/lib/byteswap.h @@ -1,20 +1,21 @@ /* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ + * Descent 3 + * Copyright (C) 2024 Parallax Software + * Copyright (C) 2024 Descent Developers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ /* * $Logfile: /DescentIII/Main/lib/BYTESWAP.H $ @@ -61,72 +62,53 @@ * $NoKeywords: $ */ -#ifndef _BYTESWAP_H -#define _BYTESWAP_H +#ifndef BYTESWAP_H +#define BYTESWAP_H -#include "pstypes.h" +#include +#include -/* -#include "psendian.h" +namespace D3 { -#define SWAPSHORT(x) ( ((x) << 8) | (((ushort)(x)) >> 8) ) -#define SWAPINT(x) ( ((x) << 24) | (((ulong)(x)) >> 24) | (((x) & 0x0000ff00) << 8) | (((x) & 0x00ff0000) >> -8) ) - -//Stupid function to trick the compiler into letting me byteswap a float -inline float SWAPFLOAT(float x) -{ - int i = SWAPINT(*((int *) &(x))); - return *((float *) &(i)); +// std::byteswap from C++23 +template constexpr T byteswap(T n) { + T m; + for (size_t i = 0; i < sizeof(T); i++) + reinterpret_cast(&m)[i] = reinterpret_cast(&n)[sizeof(T) - 1 - i]; + return m; } -// INTEL_ assumes the returned value will be in "Little Endian Format" -#define INTEL_INT(x) Endian_SwapInt(x) -#define INTEL_SHORT(x) Endian_SwapShort(x) -#define INTEL_FLOAT(x) Endian_SwapFloat(x) - -// MOTOROLA_ assumes the returned value will be in "Big Endian Format" -#define MOTOROLA_INT(x) SWAPINT(Endian_SwapInt(x)) -#define MOTOROLA_SHORT(x) SWAPSHORT(Endian_SwapShort(x)) -#define MOTOROLA_FLOAT(x) SWAPFLOAT(Endian_SwapFloat(x)) -*/ -#define SWAPSHORT(x) (short)(0xFFFF & (((x) << 8) | (((ushort)(x)) >> 8))) -#define SWAPINT(x) (int)(((x) << 24) | (((ulong)(x)) >> 24) | (((x) & 0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8)) - -// Stupid function to trick the compiler into letting me byteswap a float -inline float SWAPFLOAT(float x) { - int i = SWAPINT(*((int *)&(x))); - return *((float *)&(i)); -} - -// Default is little endian, so change for Macintosh -#if (MACOSX && MACOSXPPC) -#define OUTRAGE_BIG_ENDIAN -#endif - -#if (defined __LINUX__) && (!defined(MACOSX)) -#include - -#if BYTE_ORDER == BIG_ENDIAN -#define OUTRAGE_BIG_ENDIAN -#endif -#endif - +/** + * Convert integer to/from BE order + */ +template constexpr T convert_be(T val) { #ifndef OUTRAGE_BIG_ENDIAN - -#define INTEL_INT(x) x -#define INTEL_SHORT(x) x -#define INTEL_FLOAT(x) x -#define MOTOROLA_INT(x) SWAPINT(x) -#define MOTOROLA_SHORT(x) SWAPSHORT(x) -#define MOTOROLA_FLOAT(x) SWAPFLOAT(x) + return byteswap(val); #else -#define INTEL_INT(x) SWAPINT(x) -#define INTEL_SHORT(x) SWAPSHORT(x) -#define INTEL_FLOAT(x) SWAPFLOAT(x) -#define MOTOROLA_INT(x) x -#define MOTOROLA_SHORT(x) x -#define MOTOROLA_FLOAT(x) x + return (val); #endif +} + +/** + * Convert integer to/from LE order + */ +template constexpr T convert_le(T val) { +#ifndef OUTRAGE_BIG_ENDIAN + return (val); +#else + return byteswap(val); +#endif +} + +} // namespace D3 + +// Compatibility macros. Use D3::convert_le / D3::convert_be when possible + +#define INTEL_INT(x) D3::convert_le(x) +#define INTEL_SHORT(x) D3::convert_le(x) +#define INTEL_FLOAT(x) D3::convert_le(x) +#define MOTOROLA_INT(x) D3::convert_be(x) +#define MOTOROLA_SHORT(x) D3::convert_be(x) +#define MOTOROLA_FLOAT(x) D3::convert_be(x) #endif diff --git a/lib/manage.h b/lib/manage.h index da008693..804c9662 100644 --- a/lib/manage.h +++ b/lib/manage.h @@ -21,7 +21,7 @@ #define MANAGE_H #include -#include "CFILE.H" +#include "cfile.h" #include "bitmap.h" #include "manage_external.h" diff --git a/lnxcontroller/CMakeLists.txt b/lnxcontroller/CMakeLists.txt index c306ff02..912ba4e6 100644 --- a/lnxcontroller/CMakeLists.txt +++ b/lnxcontroller/CMakeLists.txt @@ -2,3 +2,6 @@ set(HEADERS) set(CPPS lnxcontroller.cpp) add_library(lnxcontroller STATIC ${HEADERS} ${CPPS}) +target_link_libraries(lnxcontroller PRIVATE + cfile +) diff --git a/lnxcontroller/lnxcontroller.cpp b/lnxcontroller/lnxcontroller.cpp index e1e4486f..8e7b30e8 100644 --- a/lnxcontroller/lnxcontroller.cpp +++ b/lnxcontroller/lnxcontroller.cpp @@ -47,7 +47,7 @@ #include "ddio.h" #include "pserror.h" #include "joystick.h" -#include "InfFile.h" +#include "inffile.h" // Sorry! This is needed for the semi-hacky mouselook support #include "descent.h" diff --git a/mac/MACGAMESPY.CPP b/mac/MACGAMESPY.CPP index ccab9dfd..8f8ec5c2 100644 --- a/mac/MACGAMESPY.CPP +++ b/mac/MACGAMESPY.CPP @@ -32,7 +32,7 @@ #include "descent.h" #include "ddio.h" #include "args.h" -#include "CFILE.H" +#include "cfile.h" #include "program.h" #include #include diff --git a/mac/MACSOUND.CPP b/mac/MACSOUND.CPP index 57de93c8..edd24ce6 100644 --- a/mac/MACSOUND.CPP +++ b/mac/MACSOUND.CPP @@ -25,7 +25,7 @@ #include #include // #include -#include "CFILE.H" +#include "cfile.h" #include "pserror.h" #include "mono.h" #include "soundload.h" diff --git a/mac/MACSTREAMAUDIO.CPP b/mac/MACSTREAMAUDIO.CPP index b4759c17..e961f5dc 100644 --- a/mac/MACSTREAMAUDIO.CPP +++ b/mac/MACSTREAMAUDIO.CPP @@ -149,7 +149,7 @@ #include #include "streamaudio.h" #include "pserror.h" -#include "CFILE.H" +#include "cfile.h" #include "mem.h" #include "Macros.h" #include "ddio.h" diff --git a/manage/CMakeLists.txt b/manage/CMakeLists.txt index 36fedf99..b4f9ae03 100644 --- a/manage/CMakeLists.txt +++ b/manage/CMakeLists.txt @@ -22,3 +22,6 @@ set(CPPS weaponpage.cpp) add_library(manage STATIC ${HEADERS} ${CPPS}) +target_link_libraries(manage PRIVATE + cfile +) diff --git a/manage/doorpage.cpp b/manage/doorpage.cpp index c7477eb3..535aa07a 100644 --- a/manage/doorpage.cpp +++ b/manage/doorpage.cpp @@ -147,7 +147,7 @@ #include #endif -#include "CFILE.H" +#include "cfile.h" #include "manage.h" #include "door.h" #include "doorpage.h" diff --git a/manage/doorpage.h b/manage/doorpage.h index e07eddef..0037732d 100644 --- a/manage/doorpage.h +++ b/manage/doorpage.h @@ -21,7 +21,7 @@ #include "manage.h" #include "door.h" -#include "CFILE.H" +#include "cfile.h" #include "pstypes.h" typedef struct { diff --git a/manage/gamefilepage.cpp b/manage/gamefilepage.cpp index 0a799756..f3184da9 100644 --- a/manage/gamefilepage.cpp +++ b/manage/gamefilepage.cpp @@ -20,7 +20,7 @@ #include #endif -#include "CFILE.H" +#include "cfile.h" #include "manage.h" #include "mono.h" #include "pserror.h" diff --git a/manage/gamefilepage.h b/manage/gamefilepage.h index da05515b..37f901f5 100644 --- a/manage/gamefilepage.h +++ b/manage/gamefilepage.h @@ -20,7 +20,7 @@ #define GAMEFILEPAGE_H #include "manage.h" -#include "CFILE.H" +#include "cfile.h" #include "pstypes.h" #include "gamefile.h" diff --git a/manage/generic.cpp b/manage/generic.cpp index 03bc06ce..10e297ab 100644 --- a/manage/generic.cpp +++ b/manage/generic.cpp @@ -355,7 +355,7 @@ #include #endif -#include "CFILE.H" +#include "cfile.h" #include "manage.h" #include "genericpage.h" #include "soundpage.h" diff --git a/manage/genericpage.h b/manage/genericpage.h index 02b00a43..f59c98c8 100644 --- a/manage/genericpage.h +++ b/manage/genericpage.h @@ -20,7 +20,7 @@ #define GENERICPAGE_H #include "manage.h" -#include "CFILE.H" +#include "cfile.h" #include "pstypes.h" #include "objinfo.h" #include "robotfirestruct.h" diff --git a/manage/manage.cpp b/manage/manage.cpp index 57c9b0d2..93830e16 100644 --- a/manage/manage.cpp +++ b/manage/manage.cpp @@ -456,7 +456,7 @@ #include "mono.h" #include "object.h" #include "ddio.h" -#include "CFILE.H" +#include "cfile.h" #include "appdatabase.h" #include "genericpage.h" #include "mem.h" diff --git a/manage/megapage.cpp b/manage/megapage.cpp index b5ef0157..68e90357 100644 --- a/manage/megapage.cpp +++ b/manage/megapage.cpp @@ -64,7 +64,7 @@ #if defined(WIN32) #include #endif -#include "CFILE.H" +#include "cfile.h" #include "manage.h" #include "megacell.h" #include "megapage.h" diff --git a/manage/megapage.h b/manage/megapage.h index 8ed3a335..a163af1c 100644 --- a/manage/megapage.h +++ b/manage/megapage.h @@ -21,7 +21,7 @@ #include "manage.h" #include "megacell.h" -#include "CFILE.H" +#include "cfile.h" #include "pstypes.h" typedef struct { diff --git a/manage/pagelock.cpp b/manage/pagelock.cpp index f25ecfd2..32190c8e 100644 --- a/manage/pagelock.cpp +++ b/manage/pagelock.cpp @@ -178,7 +178,7 @@ #include #include #include -#include "CFILE.H" +#include "cfile.h" #include "manage.h" #include "pstypes.h" #include "pserror.h" diff --git a/manage/shippage.cpp b/manage/shippage.cpp index 2239f217..5d4066b8 100644 --- a/manage/shippage.cpp +++ b/manage/shippage.cpp @@ -201,7 +201,7 @@ #include #endif -#include "CFILE.H" +#include "cfile.h" #include "manage.h" #include "ship.h" #include "shippage.h" diff --git a/manage/shippage.h b/manage/shippage.h index defe097e..4fb35fa1 100644 --- a/manage/shippage.h +++ b/manage/shippage.h @@ -21,7 +21,7 @@ #include "manage.h" #include "ship.h" -#include "CFILE.H" +#include "cfile.h" #include "pstypes.h" typedef struct { diff --git a/manage/soundpage.cpp b/manage/soundpage.cpp index 2fa4d981..1353ced7 100644 --- a/manage/soundpage.cpp +++ b/manage/soundpage.cpp @@ -120,7 +120,7 @@ #if defined(WIN32) #include #endif -#include "CFILE.H" +#include "cfile.h" #include "manage.h" #include "soundpage.h" #include "mono.h" diff --git a/manage/soundpage.h b/manage/soundpage.h index f7b20d4f..596a6ac4 100644 --- a/manage/soundpage.h +++ b/manage/soundpage.h @@ -21,7 +21,7 @@ #include "manage.h" #include "soundload.h" -#include "CFILE.H" +#include "cfile.h" #include "pstypes.h" typedef struct { diff --git a/manage/texpage.cpp b/manage/texpage.cpp index 5970c0c9..cb8d682e 100644 --- a/manage/texpage.cpp +++ b/manage/texpage.cpp @@ -261,7 +261,7 @@ #include #endif -#include "CFILE.H" +#include "cfile.h" #include "manage.h" #include "gametexture.h" #include "bitmap.h" diff --git a/manage/texpage.h b/manage/texpage.h index 033e69af..3a08480d 100644 --- a/manage/texpage.h +++ b/manage/texpage.h @@ -20,7 +20,7 @@ #define TEXPAGE_H #include "manage.h" -#include "CFILE.H" +#include "cfile.h" #include "pstypes.h" #include "procedurals.h" diff --git a/manage/weaponpage.cpp b/manage/weaponpage.cpp index de4791c4..364a90ac 100644 --- a/manage/weaponpage.cpp +++ b/manage/weaponpage.cpp @@ -290,7 +290,7 @@ #include #endif -#include "CFILE.H" +#include "cfile.h" #include "manage.h" #include "weapon.h" #include "weaponpage.h" diff --git a/manage/weaponpage.h b/manage/weaponpage.h index c9699bcc..b482d947 100644 --- a/manage/weaponpage.h +++ b/manage/weaponpage.h @@ -22,7 +22,7 @@ #include "manage.h" #include "weapon.h" -#include "CFILE.H" +#include "cfile.h" #include "pstypes.h" typedef struct { diff --git a/music/CMakeLists.txt b/music/CMakeLists.txt index 05b55b55..e946a424 100644 --- a/music/CMakeLists.txt +++ b/music/CMakeLists.txt @@ -6,3 +6,6 @@ set(CPPS tracklist.cpp) add_library(music STATIC ${HEADERS} ${CPPS}) +target_link_libraries(music + cfile +) diff --git a/music/omflex.cpp b/music/omflex.cpp index 180509d4..0dd5b5ed 100644 --- a/music/omflex.cpp +++ b/music/omflex.cpp @@ -73,7 +73,7 @@ #include "music.h" #include "musiclib.h" -#include "InfFile.h" +#include "inffile.h" #include "mem.h" #include diff --git a/music/sequencer.cpp b/music/sequencer.cpp index 79c9c935..4c43fbaa 100644 --- a/music/sequencer.cpp +++ b/music/sequencer.cpp @@ -150,7 +150,7 @@ #include "pserror.h" #include "ddio.h" #include "Macros.h" -#include "InfFile.h" +#include "inffile.h" #include "streamaudio.h" #include "mem.h" #include diff --git a/rtperformance/rtperformance.cpp b/rtperformance/rtperformance.cpp index f97c0fc8..2c9a810b 100644 --- a/rtperformance/rtperformance.cpp +++ b/rtperformance/rtperformance.cpp @@ -64,7 +64,7 @@ #include "descent.h" #include "manage.h" #include "ddio.h" -#include "CFILE.H" +#include "cfile.h" #include #include diff --git a/sndlib/soundload.cpp b/sndlib/soundload.cpp index 89fb30c1..88ef8d4e 100644 --- a/sndlib/soundload.cpp +++ b/sndlib/soundload.cpp @@ -234,7 +234,7 @@ #include #include "ssl_lib.h" #include "object.h" -#include "CFILE.H" +#include "cfile.h" #include "ddio.h" #include "soundload.h" #include "weapon.h" diff --git a/stream_audio/osfarchive.cpp b/stream_audio/osfarchive.cpp index 72154c6d..b7d3ce0e 100644 --- a/stream_audio/osfarchive.cpp +++ b/stream_audio/osfarchive.cpp @@ -51,7 +51,7 @@ */ #include "streamaudio.h" -#include "CFILE.H" +#include "cfile.h" #include "pserror.h" #include diff --git a/stream_audio/streamaudio.cpp b/stream_audio/streamaudio.cpp index 5a2b7520..f262fd33 100644 --- a/stream_audio/streamaudio.cpp +++ b/stream_audio/streamaudio.cpp @@ -166,7 +166,7 @@ */ #include "streamaudio.h" #include "pserror.h" -#include "CFILE.H" +#include "cfile.h" #include "mem.h" #include "Macros.h" #include "ddio.h" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..5c2c08aa --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable( + byteswap_tests + byteswap_tests.cpp +) +target_link_libraries( + byteswap_tests + GTest::gtest_main +) +target_include_directories(byteswap_tests PRIVATE ${PROJECT_SOURCE_DIR}/lib) + +gtest_discover_tests(byteswap_tests) diff --git a/tests/byteswap_tests.cpp b/tests/byteswap_tests.cpp new file mode 100644 index 00000000..33c7d9fa --- /dev/null +++ b/tests/byteswap_tests.cpp @@ -0,0 +1,90 @@ +/* +* Descent 3 +* Copyright (C) 2024 Descent Developers +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#include + +#include "byteswap.h" + +// This code taken from original byteswap.h for testing float conversion +// It cannot convert negative float numbers in 64-bit systems, so testing only non-negative numbers + +#define SWAPINT(x) (int)(((x) << 24) | (((ulong)(x)) >> 24) | (((x) & 0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8)) + +// Stupid function to trick the compiler into letting me byteswap a float +inline float SWAPFLOAT(float x) { + int i = SWAPINT(*((int *)&(x))); + return *((float *)&(i)); +} + +// Taken from CFILE.cpp +inline double SWAPDOUBLE(double x) { + double t; + int *sp = (int *)&x; + int *dp = (int *)&t; + dp[0] = SWAPINT(sp[1]); + dp[1] = SWAPINT(sp[0]); + x = t; + + return x; +} + + +TEST(D3, ByteSwap) { + EXPECT_EQ(D3::byteswap((uint8_t)0x01), (uint8_t)0x01); + EXPECT_EQ(D3::byteswap((int8_t)0x01), (int16_t)0x01); + EXPECT_EQ(D3::byteswap((uint16_t)0x0123), (uint16_t)0x2301); + EXPECT_EQ(D3::byteswap((int16_t)0x0123), (int16_t)0x2301); + EXPECT_EQ(D3::byteswap((int32_t)0x01234567), (int32_t)0x67452301); + EXPECT_EQ(D3::byteswap((int64_t)0x0123456789ABCDEF), (int64_t)0xEFCDAB8967452301); + + EXPECT_EQ(D3::byteswap((int32_t)(0xFF000000)), (int32_t)0xFF); +} + +TEST(D3, Converting) { +#ifndef OUTRAGE_BIG_ENDIAN + EXPECT_EQ(D3::convert_le((int16_t)0x10), 0x10); + EXPECT_EQ(D3::convert_le((int32_t)0x10), 0x10); + EXPECT_EQ(D3::convert_le((int64_t)0x10), 0x10); + + EXPECT_EQ(D3::convert_be((int16_t)0x10), 0x1000); + EXPECT_EQ(D3::convert_be((int32_t)0x10), 0x10000000); + EXPECT_EQ(D3::convert_be((int64_t)0x10), 0x1000000000000000); +#else + EXPECT_EQ(D3::convert_be((int16_t)0x10), 0x10); + EXPECT_EQ(D3::convert_be((int32_t)0x10), 0x10); + EXPECT_EQ(D3::convert_be((int64_t)0x10), 0x10); + + EXPECT_EQ(D3::convert_le((int16_t)0x10), 0x1000); + EXPECT_EQ(D3::convert_le((int16_t)0x10), 0x10000000); + EXPECT_EQ(D3::convert_le((int16_t)0x10), 0x1000000000000000); +#endif +} + +TEST(D3, FloatDoubleOperations) { + // float/double sanity checks + EXPECT_EQ(sizeof(float), 4); + EXPECT_EQ(sizeof(double), 8); + + EXPECT_EQ(D3::byteswap(0.0f), SWAPFLOAT(0.0f)); + EXPECT_EQ(D3::byteswap(10.0f), SWAPFLOAT(10.0f)); + EXPECT_EQ(D3::byteswap(10000.0f), SWAPFLOAT(10000.0f)); + + EXPECT_EQ(D3::byteswap(0.0), SWAPDOUBLE(0.0)); + EXPECT_EQ(D3::byteswap(10.0), SWAPDOUBLE(10.0)); + EXPECT_EQ(D3::byteswap(10000.0), SWAPDOUBLE(10000.0)); +} diff --git a/tools/HogMaker/IOOps.h b/tools/HogMaker/IOOps.h index c254e2e3..3222fdf4 100644 --- a/tools/HogMaker/IOOps.h +++ b/tools/HogMaker/IOOps.h @@ -24,36 +24,6 @@ namespace D3 { -// std::byteswap from C++23 -template constexpr T byteswap(T n) { - T m; - for (size_t i = 0; i < sizeof(T); i++) - reinterpret_cast(&m)[i] = reinterpret_cast(&n)[sizeof(T) - 1 - i]; - return m; -} - -/** - * Convert integer to/from BE order - */ -template constexpr T convert_be(T val) { -#ifndef OUTRAGE_BIG_ENDIAN - return byteswap(val); -#else - return (val); -#endif -} - -/** - * Convert integer to/from LE order - */ -template constexpr T convert_le(T val) { -#ifndef OUTRAGE_BIG_ENDIAN - return (val); -#else - return byteswap(val); -#endif -} - template inline std::ostream &bin_write(std::ostream &output, T value, bool is_little_endian = true, size_t n = sizeof(T)) { value = is_little_endian ? convert_le(value) : convert_be(value); diff --git a/unzip/CMakeLists.txt b/unzip/CMakeLists.txt index 694bfa33..cc071a39 100644 --- a/unzip/CMakeLists.txt +++ b/unzip/CMakeLists.txt @@ -1,21 +1,6 @@ -set(HEADERS - infblock.h - infcodes.h - inffast.h - inffixed.h - inftrees.h - infutil.h - zconf.h - zlib.h - zutil.h) -set(CPPS - unzip.cpp - adler32.c - infblock.c - infcodes.c - inffast.c - inflate.c - inftrees.c - infutil.c) +set(HEADERS) +set(CPPS unzip.cpp) add_library(unzip STATIC ${HEADERS} ${CPPS}) + +target_link_libraries(unzip ZLIB::ZLIB) diff --git a/unzip/adler32.c b/unzip/adler32.c deleted file mode 100644 index 005e37ff..00000000 --- a/unzip/adler32.c +++ /dev/null @@ -1,89 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: $ - * $Revision: $ - * $Date: $ - * $Author: $ - * - * - * - * $Log: $ - * - * $NoKeywords: $ - */ - -/* adler32.c -- compute the Adler-32 checksum of a data stream - * Copyright (C) 1995-1998 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zlib.h" - -#define BASE 65521L /* largest prime smaller than 65536 */ -#define NMAX 5552 -/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ - -#define DO1(buf, i) \ - { \ - s1 += buf[i]; \ - s2 += s1; \ - } -#define DO2(buf, i) \ - DO1(buf, i); \ - DO1(buf, i + 1); -#define DO4(buf, i) \ - DO2(buf, i); \ - DO2(buf, i + 2); -#define DO8(buf, i) \ - DO4(buf, i); \ - DO4(buf, i + 4); -#define DO16(buf) \ - DO8(buf, 0); \ - DO8(buf, 8); - -/* ========================================================================= */ -uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) { - unsigned long s1 = adler & 0xffff; - unsigned long s2 = (adler >> 16) & 0xffff; - int k; - - if (buf == Z_NULL) - return 1L; - - while (len > 0) { - k = len < NMAX ? len : NMAX; - len -= k; - while (k >= 16) { - DO16(buf); - buf += 16; - k -= 16; - } - if (k != 0) - do { - s1 += *buf++; - s2 += s1; - } while (--k); - s1 %= BASE; - s2 %= BASE; - } - return (s2 << 16) | s1; -} diff --git a/unzip/infblock.c b/unzip/infblock.c deleted file mode 100644 index 04b60fa9..00000000 --- a/unzip/infblock.c +++ /dev/null @@ -1,377 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: $ - * $Revision: $ - * $Date: $ - * $Author: $ - * - * - * - * $Log: $ - * - * $NoKeywords: $ - */ - -/* infblock.c -- interpret and process block types to last block - * Copyright (C) 1995-1998 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "infblock.h" -#include "inftrees.h" -#include "infcodes.h" -#include "infutil.h" - -struct inflate_codes_state { - int dummy; -}; /* for buggy compilers */ - -/* simplify the use of the inflate_huft type with some defines */ -#define exop word.what.Exop -#define bits word.what.Bits - -/* Table for deflate from PKZIP's appnote.txt. */ -local const uInt border[] = {/* Order of the bit length code lengths */ - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; - -/* - Notes beyond the 1.93a appnote.txt: - - 1. Distance pointers never point before the beginning of the output - stream. - 2. Distance pointers can point back across blocks, up to 32k away. - 3. There is an implied maximum of 7 bits for the bit length table and - 15 bits for the actual data. - 4. If only one code exists, then it is encoded using one bit. (Zero - would be more efficient, but perhaps a little confusing.) If two - codes exist, they are coded using one bit each (0 and 1). - 5. There is no way of sending zero distance codes--a dummy must be - sent if there are none. (History: a pre 2.0 version of PKZIP would - store blocks with no distance codes, but this was discovered to be - too harsh a criterion.) Valid only for 1.93a. 2.04c does allow - zero distance codes, which is sent as one code of zero bits in - length. - 6. There are up to 286 literal/length codes. Code 256 represents the - end-of-block. Note however that the static length tree defines - 288 codes just to fill out the Huffman codes. Codes 286 and 287 - cannot be used though, since there is no length base or extra bits - defined for them. Similarily, there are up to 30 distance codes. - However, static trees define 32 codes (all 5 bits) to fill out the - Huffman codes, but the last two had better not show up in the data. - 7. Unzip can check dynamic Huffman blocks for complete code sets. - The exception is that a single code would not be complete (see #4). - 8. The five bits following the block type is really the number of - literal codes sent minus 257. - 9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits - (1+6+6). Therefore, to output three times the length, you output - three codes (1+1+1), whereas to output four times the same length, - you only need two codes (1+3). Hmm. - 10. In the tree reconstruction algorithm, Code = Code + Increment - only if BitLength(i) is not zero. (Pretty obvious.) - 11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19) - 12. Note: length code 284 can represent 227-258, but length code 285 - really is 258. The last length deserves its own, short code - since it gets used a lot in very redundant files. The length - 258 is special since 258 - 3 (the min match length) is 255. - 13. The literal/length and distance code bit lengths are read as a - single stream of lengths. It is possible (and advantageous) for - a repeat code (16, 17, or 18) to go across the boundary between - the two sets of lengths. - */ - -void inflate_blocks_reset(inflate_blocks_statef *s, z_streamp z, uLongf *c) { - if (c != Z_NULL) - *c = s->check; - if (s->mode == BTREE || s->mode == DTREE) - ZFREE(z, s->sub.trees.blens); - if (s->mode == CODES) - inflate_codes_free(s->sub.decode.codes, z); - s->mode = TYPE; - s->bitk = 0; - s->bitb = 0; - s->read = s->write = s->window; - if (s->checkfn != Z_NULL) - z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0); - Tracev((stderr, "inflate: blocks reset\n")); -} - -inflate_blocks_statef *inflate_blocks_new(z_streamp z, check_func c, uInt w) { - inflate_blocks_statef *s; - - if ((s = (inflate_blocks_statef *)ZALLOC(z, 1, sizeof(struct inflate_blocks_state))) == Z_NULL) - return s; - if ((s->hufts = (inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL) { - ZFREE(z, s); - return Z_NULL; - } - if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL) { - ZFREE(z, s->hufts); - ZFREE(z, s); - return Z_NULL; - } - s->end = s->window + w; - s->checkfn = c; - s->mode = TYPE; - Tracev((stderr, "inflate: blocks allocated\n")); - inflate_blocks_reset(s, z, Z_NULL); - return s; -} - -int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r) { - uInt t; /* temporary storage */ - uLong b; /* bit buffer */ - uInt k; /* bits in bit buffer */ - Bytef *p; /* input data pointer */ - uInt n; /* bytes available there */ - Bytef *q; /* output window write pointer */ - uInt m; /* bytes to end of window or read pointer */ - - /* copy input/output information to locals (UPDATE macro restores) */ - LOAD - - /* process input based on current state */ - while (1) switch (s->mode) { - case TYPE: - NEEDBITS(3) - t = (uInt)b & 7; - s->last = t & 1; - switch (t >> 1) { - case 0: /* stored */ - Tracev((stderr, "inflate: stored block%s\n", s->last ? " (last)" : "")); - DUMPBITS(3) - t = k & 7; /* go to byte boundary */ - DUMPBITS(t) - s->mode = LENS; /* get length of stored block */ - break; - case 1: /* fixed */ - Tracev((stderr, "inflate: fixed codes block%s\n", s->last ? " (last)" : "")); - { - uInt bl, bd; - inflate_huft *tl, *td; - - inflate_trees_fixed(&bl, &bd, &tl, &td, z); - s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z); - if (s->sub.decode.codes == Z_NULL) { - r = Z_MEM_ERROR; - LEAVE - } - } - DUMPBITS(3) - s->mode = CODES; - break; - case 2: /* dynamic */ - Tracev((stderr, "inflate: dynamic codes block%s\n", s->last ? " (last)" : "")); - DUMPBITS(3) - s->mode = TABLE; - break; - case 3: /* illegal */ - DUMPBITS(3) - s->mode = BAD; - z->msg = (char *)"invalid block type"; - r = Z_DATA_ERROR; - LEAVE - } - break; - case LENS: - NEEDBITS(32) - if ((((~b) >> 16) & 0xffff) != (b & 0xffff)) { - s->mode = BAD; - z->msg = (char *)"invalid stored block lengths"; - r = Z_DATA_ERROR; - LEAVE - } - s->sub.left = (uInt)b & 0xffff; - b = k = 0; /* dump bits */ - Tracev((stderr, "inflate: stored length %u\n", s->sub.left)); - s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE); - break; - case STORED: - if (n == 0) - LEAVE - NEEDOUT - t = s->sub.left; - if (t > n) - t = n; - if (t > m) - t = m; - zmemcpy(q, p, t); - p += t; - n -= t; - q += t; - m -= t; - if ((s->sub.left -= t) != 0) - break; - Tracev((stderr, "inflate: stored end, %lu total out\n", - z->total_out + (q >= s->read ? q - s->read : (s->end - s->read) + (q - s->window)))); - s->mode = s->last ? DRY : TYPE; - break; - case TABLE: - NEEDBITS(14) - s->sub.trees.table = t = (uInt)b & 0x3fff; -#ifndef PKZIP_BUG_WORKAROUND - if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) { - s->mode = BAD; - z->msg = (char *)"too many length or distance symbols"; - r = Z_DATA_ERROR; - LEAVE - } -#endif - t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f); - if ((s->sub.trees.blens = (uIntf *)ZALLOC(z, t, sizeof(uInt))) == Z_NULL) { - r = Z_MEM_ERROR; - LEAVE - } - DUMPBITS(14) - s->sub.trees.index = 0; - Tracev((stderr, "inflate: table sizes ok\n")); - s->mode = BTREE; - case BTREE: - while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10)) { - NEEDBITS(3) - s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7; - DUMPBITS(3) - } - while (s->sub.trees.index < 19) - s->sub.trees.blens[border[s->sub.trees.index++]] = 0; - s->sub.trees.bb = 7; - t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb, &s->sub.trees.tb, s->hufts, z); - if (t != Z_OK) { - ZFREE(z, s->sub.trees.blens); - r = t; - if (r == Z_DATA_ERROR) - s->mode = BAD; - LEAVE - } - s->sub.trees.index = 0; - Tracev((stderr, "inflate: bits tree ok\n")); - s->mode = DTREE; - case DTREE: - while (t = s->sub.trees.table, s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f)) { - inflate_huft *h; - uInt i, j, c; - - t = s->sub.trees.bb; - NEEDBITS(t) - h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]); - t = h->bits; - c = h->base; - if (c < 16) { - DUMPBITS(t) - s->sub.trees.blens[s->sub.trees.index++] = c; - } else /* c == 16..18 */ - { - i = c == 18 ? 7 : c - 14; - j = c == 18 ? 11 : 3; - NEEDBITS(t + i) - DUMPBITS(t) - j += (uInt)b & inflate_mask[i]; - DUMPBITS(i) - i = s->sub.trees.index; - t = s->sub.trees.table; - if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) { - ZFREE(z, s->sub.trees.blens); - s->mode = BAD; - z->msg = (char *)"invalid bit length repeat"; - r = Z_DATA_ERROR; - LEAVE - } - c = c == 16 ? s->sub.trees.blens[i - 1] : 0; - do { - s->sub.trees.blens[i++] = c; - } while (--j); - s->sub.trees.index = i; - } - } - s->sub.trees.tb = Z_NULL; - { - uInt bl, bd; - inflate_huft *tl, *td; - inflate_codes_statef *c; - - bl = 9; /* must be <= 9 for lookahead assumptions */ - bd = 6; /* must be <= 9 for lookahead assumptions */ - t = s->sub.trees.table; - t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), s->sub.trees.blens, &bl, &bd, &tl, &td, - s->hufts, z); - ZFREE(z, s->sub.trees.blens); - if (t != Z_OK) { - if (t == (uInt)Z_DATA_ERROR) - s->mode = BAD; - r = t; - LEAVE - } - Tracev((stderr, "inflate: trees ok\n")); - if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL) { - r = Z_MEM_ERROR; - LEAVE - } - s->sub.decode.codes = c; - } - s->mode = CODES; - case CODES: - UPDATE - if ((r = inflate_codes(s, z, r)) != Z_STREAM_END) - return inflate_flush(s, z, r); - r = Z_OK; - inflate_codes_free(s->sub.decode.codes, z); - LOAD Tracev((stderr, "inflate: codes end, %lu total out\n", - z->total_out + (q >= s->read ? q - s->read : (s->end - s->read) + (q - s->window)))); - if (!s->last) { - s->mode = TYPE; - break; - } - s->mode = DRY; - case DRY: - FLUSH - if (s->read != s->write) - LEAVE - s->mode = DONE; - case DONE: - r = Z_STREAM_END; - LEAVE - case BAD: - r = Z_DATA_ERROR; - LEAVE - default: - r = Z_STREAM_ERROR; - LEAVE - } -} - -int inflate_blocks_free(inflate_blocks_statef *s, z_streamp z) { - inflate_blocks_reset(s, z, Z_NULL); - ZFREE(z, s->window); - ZFREE(z, s->hufts); - ZFREE(z, s); - Tracev((stderr, "inflate: blocks freed\n")); - return Z_OK; -} - -void inflate_set_dictionary(inflate_blocks_statef *s, const Bytef *d, uInt n) { - zmemcpy(s->window, d, n); - s->read = s->write = s->window + n; -} - -/* Returns true if inflate is currently at the end of a block generated - * by Z_SYNC_FLUSH or Z_FULL_FLUSH. - * IN assertion: s != Z_NULL - */ -int inflate_blocks_sync_point(inflate_blocks_statef *s) { return s->mode == LENS; } diff --git a/unzip/infblock.h b/unzip/infblock.h deleted file mode 100644 index 8522a22d..00000000 --- a/unzip/infblock.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: /DescentIII/Main/unzip/infblock.h $ - * $Revision: 2 $ - * $Date: 8/13/99 8:01p $ - * $Author: Jeff $ - * - * - * - * $Log: /DescentIII/Main/unzip/infblock.h $ - * - * 2 8/13/99 8:01p Jeff - * initial creation of zip class - * - * $NoKeywords: $ - */ - -/* infblock.h -- header to use infblock.c - * Copyright (C) 1995-1998 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -struct inflate_blocks_state; -typedef struct inflate_blocks_state FAR inflate_blocks_statef; - -extern inflate_blocks_statef *inflate_blocks_new OF((z_streamp z, check_func c, /* check function */ - uInt w)); /* window size */ - -extern int inflate_blocks OF((inflate_blocks_statef *, z_streamp, int)); /* initial return code */ - -extern void inflate_blocks_reset OF((inflate_blocks_statef *, z_streamp, uLongf *)); /* check value on output */ - -extern int inflate_blocks_free OF((inflate_blocks_statef *, z_streamp)); - -extern void inflate_set_dictionary OF((inflate_blocks_statef * s, const Bytef *d, /* dictionary */ - uInt n)); /* dictionary length */ - -extern int inflate_blocks_sync_point OF((inflate_blocks_statef * s)); diff --git a/unzip/infcodes.c b/unzip/infcodes.c deleted file mode 100644 index 509f0f9d..00000000 --- a/unzip/infcodes.c +++ /dev/null @@ -1,264 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: $ - * $Revision: $ - * $Date: $ - * $Author: $ - * - * - * - * $Log: $ - * - * $NoKeywords: $ - */ - -/* infcodes.c -- process literals and length/distance pairs - * Copyright (C) 1995-1998 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" -#include "infblock.h" -#include "infcodes.h" -#include "infutil.h" -#include "inffast.h" - -/* simplify the use of the inflate_huft type with some defines */ -#define exop word.what.Exop -#define bits word.what.Bits - -typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */ - START, /* x: set up for LEN */ - LEN, /* i: get length/literal/eob next */ - LENEXT, /* i: getting length extra (have base) */ - DIST, /* i: get distance next */ - DISTEXT, /* i: getting distance extra */ - COPY, /* o: copying bytes in window, waiting for space */ - LIT, /* o: got literal, waiting for output space */ - WASH, /* o: got eob, possibly still output waiting */ - END, /* x: got eob and all data flushed */ - BADCODE -} /* x: got error */ -inflate_codes_mode; - -/* inflate codes private state */ -struct inflate_codes_state { - - /* mode */ - inflate_codes_mode mode; /* current inflate_codes mode */ - - /* mode dependent information */ - uInt len; - union { - struct { - inflate_huft *tree; /* pointer into tree */ - uInt need; /* bits needed */ - } code; /* if LEN or DIST, where in tree */ - uInt lit; /* if LIT, literal */ - struct { - uInt get; /* bits to get for extra */ - uInt dist; /* distance back to copy from */ - } copy; /* if EXT or COPY, where and how much */ - } sub; /* submode */ - - /* mode independent information */ - Byte lbits; /* ltree bits decoded per branch */ - Byte dbits; /* dtree bits decoder per branch */ - inflate_huft *ltree; /* literal/length/eob tree */ - inflate_huft *dtree; /* distance tree */ -}; - -inflate_codes_statef *inflate_codes_new(uInt bl, uInt bd, inflate_huft *tl, inflate_huft *td, z_streamp z) { - inflate_codes_statef *c; - - if ((c = (inflate_codes_statef *)ZALLOC(z, 1, sizeof(struct inflate_codes_state))) != Z_NULL) { - c->mode = START; - c->lbits = (Byte)bl; - c->dbits = (Byte)bd; - c->ltree = tl; - c->dtree = td; - Tracev((stderr, "inflate: codes new\n")); - } - return c; -} - -int inflate_codes(inflate_blocks_statef *s, z_streamp z, int r) { - uInt j; /* temporary storage */ - inflate_huft *t; /* temporary pointer */ - uInt e; /* extra bits or operation */ - uLong b; /* bit buffer */ - uInt k; /* bits in bit buffer */ - Bytef *p; /* input data pointer */ - uInt n; /* bytes available there */ - Bytef *q; /* output window write pointer */ - uInt m; /* bytes to end of window or read pointer */ - Bytef *f; /* pointer to copy strings from */ - inflate_codes_statef *c = s->sub.decode.codes; /* codes state */ - - /* copy input/output information to locals (UPDATE macro restores) */ - LOAD - - /* process input and output based on current state */ - while (1) switch (c->mode) { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */ - case START: /* x: set up for LEN */ -#ifndef SLOW - if (m >= 258 && n >= 10) { - UPDATE - r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z); - LOAD if (r != Z_OK) { - c->mode = r == Z_STREAM_END ? WASH : BADCODE; - break; - } - } -#endif /* !SLOW */ - c->sub.code.need = c->lbits; - c->sub.code.tree = c->ltree; - c->mode = LEN; - case LEN: /* i: get length/literal/eob next */ - j = c->sub.code.need; - NEEDBITS(j) - t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); - DUMPBITS(t->bits) - e = (uInt)(t->exop); - if (e == 0) /* literal */ - { - c->sub.lit = t->base; - Tracevv( - (stderr, - t->base >= 0x20 && t->base < 0x7f ? "inflate: literal '%c'\n" : "inflate: literal 0x%02x\n", - t->base)); - c->mode = LIT; - break; - } - if (e & 16) /* length */ - { - c->sub.copy.get = e & 15; - c->len = t->base; - c->mode = LENEXT; - break; - } - if ((e & 64) == 0) /* next table */ - { - c->sub.code.need = e; - c->sub.code.tree = t + t->base; - break; - } - if (e & 32) /* end of block */ - { - Tracevv((stderr, "inflate: end of block\n")); - c->mode = WASH; - break; - } - c->mode = BADCODE; /* invalid code */ - z->msg = (char *)"invalid literal/length code"; - r = Z_DATA_ERROR; - LEAVE - case LENEXT: /* i: getting length extra (have base) */ - j = c->sub.copy.get; - NEEDBITS(j) - c->len += (uInt)b & inflate_mask[j]; - DUMPBITS(j) - c->sub.code.need = c->dbits; - c->sub.code.tree = c->dtree; - Tracevv((stderr, "inflate: length %u\n", c->len)); - c->mode = DIST; - case DIST: /* i: get distance next */ - j = c->sub.code.need; - NEEDBITS(j) - t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); - DUMPBITS(t->bits) - e = (uInt)(t->exop); - if (e & 16) /* distance */ - { - c->sub.copy.get = e & 15; - c->sub.copy.dist = t->base; - c->mode = DISTEXT; - break; - } - if ((e & 64) == 0) /* next table */ - { - c->sub.code.need = e; - c->sub.code.tree = t + t->base; - break; - } - c->mode = BADCODE; /* invalid code */ - z->msg = (char *)"invalid distance code"; - r = Z_DATA_ERROR; - LEAVE - case DISTEXT: /* i: getting distance extra */ - j = c->sub.copy.get; - NEEDBITS(j) - c->sub.copy.dist += (uInt)b & inflate_mask[j]; - DUMPBITS(j) - Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist)); - c->mode = COPY; - case COPY: /* o: copying bytes in window, waiting for space */ -#ifndef __TURBOC__ /* Turbo C bug for following expression */ - f = (uInt)(q - s->window) < c->sub.copy.dist ? s->end - (c->sub.copy.dist - (q - s->window)) : q - c->sub.copy.dist; -#else - f = q - c->sub.copy.dist; - if ((uInt)(q - s->window) < c->sub.copy.dist) - f = s->end - (c->sub.copy.dist - (uInt)(q - s->window)); -#endif - while (c->len) { - NEEDOUT - OUTBYTE(*f++) - if (f == s->end) - f = s->window; - c->len--; - } - c->mode = START; - break; - case LIT: /* o: got literal, waiting for output space */ - NEEDOUT - OUTBYTE(c->sub.lit) - c->mode = START; - break; - case WASH: /* o: got eob, possibly more output */ - if (k > 7) /* return unused byte, if any */ - { - Assert(k < 16, "inflate_codes grabbed too many bytes") k -= 8; - n++; - p--; /* can always return one */ - } - FLUSH - if (s->read != s->write) - LEAVE - c->mode = END; - case END: - r = Z_STREAM_END; - LEAVE - case BADCODE: /* x: got error */ - r = Z_DATA_ERROR; - LEAVE - default: - r = Z_STREAM_ERROR; - LEAVE - } -#ifdef NEED_DUMMY_RETURN - return Z_STREAM_ERROR; /* Some dumb compilers complain without this */ -#endif -} - -void inflate_codes_free(inflate_codes_statef *c, z_streamp z) { - ZFREE(z, c); - Tracev((stderr, "inflate: codes free\n")); -} diff --git a/unzip/infcodes.h b/unzip/infcodes.h deleted file mode 100644 index e857fe0c..00000000 --- a/unzip/infcodes.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: /DescentIII/Main/unzip/infcodes.h $ - * $Revision: 2 $ - * $Date: 8/13/99 8:01p $ - * $Author: Jeff $ - * - * - * - * $Log: /DescentIII/Main/unzip/infcodes.h $ - * - * 2 8/13/99 8:01p Jeff - * initial creation of zip class - * - * $NoKeywords: $ - */ - -/* infcodes.h -- header to use infcodes.c - * Copyright (C) 1995-1998 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -struct inflate_codes_state; -typedef struct inflate_codes_state FAR inflate_codes_statef; - -extern inflate_codes_statef *inflate_codes_new OF((uInt, uInt, inflate_huft *, inflate_huft *, z_streamp)); - -extern int inflate_codes OF((inflate_blocks_statef *, z_streamp, int)); - -extern void inflate_codes_free OF((inflate_codes_statef *, z_streamp)); diff --git a/unzip/inffast.c b/unzip/inffast.c deleted file mode 100644 index 139f56f4..00000000 --- a/unzip/inffast.c +++ /dev/null @@ -1,200 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: $ - * $Revision: $ - * $Date: $ - * $Author: $ - * - * - * - * $Log: $ - * - * $NoKeywords: $ - */ - -/* inffast.c -- process literals and length/distance pairs fast - * Copyright (C) 1995-1998 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" -#include "infblock.h" -#include "infcodes.h" -#include "infutil.h" -#include "inffast.h" - -struct inflate_codes_state { - int dummy; -}; /* for buggy compilers */ - -/* simplify the use of the inflate_huft type with some defines */ -#define exop word.what.Exop -#define bits word.what.Bits - -/* macros for bit input with no checking and for returning unused bytes */ -#define GRABBITS(j) \ - { \ - while (k < (j)) { \ - b |= ((uLong)NEXTBYTE) << k; \ - k += 8; \ - } \ - } -#define UNGRAB \ - { \ - c = z->avail_in - n; \ - c = (k >> 3) < c ? k >> 3 : c; \ - n += c; \ - p -= c; \ - k -= c << 3; \ - } - -/* Called with number of bytes left to write in window at least 258 - (the maximum string length) and number of input bytes available - at least ten. The ten bytes are six bytes for the longest length/ - distance pair plus four bytes for overloading the bit buffer. */ - -int inflate_fast(uInt bl, uInt bd, inflate_huft *tl, inflate_huft *td, inflate_blocks_statef *s, z_streamp z) { - inflate_huft *t; /* temporary pointer */ - uInt e; /* extra bits or operation */ - uLong b; /* bit buffer */ - uInt k; /* bits in bit buffer */ - Bytef *p; /* input data pointer */ - uInt n; /* bytes available there */ - Bytef *q; /* output window write pointer */ - uInt m; /* bytes to end of window or read pointer */ - uInt ml; /* mask for literal/length tree */ - uInt md; /* mask for distance tree */ - uInt c; /* bytes to copy */ - uInt d; /* distance back to copy from */ - Bytef *r; /* copy source pointer */ - - /* load input, output, bit values */ - LOAD - - /* initialize masks */ - ml = inflate_mask[bl]; - md = inflate_mask[bd]; - - /* do until not enough input or output space for fast loop */ - do { /* assume called with m >= 258 && n >= 10 */ - /* get literal/length code */ - GRABBITS(20) /* max bits for literal/length code */ - if ((e = (t = tl + ((uInt)b & ml))->exop) == 0) { - DUMPBITS(t->bits) - Tracevv((stderr, - t->base >= 0x20 && t->base < 0x7f ? "inflate: * literal '%c'\n" - : "inflate: * literal 0x%02x\n", - t->base)); - *q++ = (Byte)t->base; - m--; - continue; - } - do { - DUMPBITS(t->bits) - if (e & 16) { - /* get extra bits for length */ - e &= 15; - c = t->base + ((uInt)b & inflate_mask[e]); - DUMPBITS(e) - Tracevv((stderr, "inflate: * length %u\n", c)); - - /* decode distance base of block to copy */ - GRABBITS(15); /* max bits for distance code */ - e = (t = td + ((uInt)b & md))->exop; - do { - DUMPBITS(t->bits) - if (e & 16) { - /* get extra bits to add to distance base */ - e &= 15; - GRABBITS(e) /* get extra bits (up to 13) */ - d = t->base + ((uInt)b & inflate_mask[e]); - DUMPBITS(e) - Tracevv((stderr, "inflate: * distance %u\n", d)); - - /* do the copy */ - m -= c; - if ((uInt)(q - s->window) >= d) /* offset before dest */ - { /* just copy */ - r = q - d; - *q++ = *r++; - c--; /* minimum count is three, */ - *q++ = *r++; - c--; /* so unroll loop a little */ - } else /* else offset after destination */ - { - e = d - (uInt)(q - s->window); /* bytes from offset to end */ - r = s->end - e; /* pointer to offset */ - if (c > e) /* if source crosses, */ - { - c -= e; /* copy to end of window */ - do { - *q++ = *r++; - } while (--e); - r = s->window; /* copy rest from start of window */ - } - } - do { /* copy all or what's left */ - *q++ = *r++; - } while (--c); - break; - } else if ((e & 64) == 0) { - t += t->base; - e = (t += ((uInt)b & inflate_mask[e]))->exop; - } else { - z->msg = (char *)"invalid distance code"; - UNGRAB - UPDATE - return Z_DATA_ERROR; - } - } while (1); - break; - } - if ((e & 64) == 0) { - t += t->base; - if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0) { - DUMPBITS(t->bits) - Tracevv((stderr, - t->base >= 0x20 && t->base < 0x7f ? "inflate: * literal '%c'\n" - : "inflate: * literal 0x%02x\n", - t->base)); - *q++ = (Byte)t->base; - m--; - break; - } - } else if (e & 32) { - Tracevv((stderr, "inflate: * end of block\n")); - UNGRAB - UPDATE - return Z_STREAM_END; - } else { - z->msg = (char *)"invalid literal/length code"; - UNGRAB - UPDATE - return Z_DATA_ERROR; - } - } while (1); - } while (m >= 258 && n >= 10); - - /* not enough input or output--restore pointers and return */ - UNGRAB - UPDATE - return Z_OK; -} diff --git a/unzip/inffast.h b/unzip/inffast.h deleted file mode 100644 index 777393c6..00000000 --- a/unzip/inffast.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: /DescentIII/Main/unzip/inffast.h $ - * $Revision: 2 $ - * $Date: 8/13/99 8:01p $ - * $Author: Jeff $ - * - * - * - * $Log: /DescentIII/Main/unzip/inffast.h $ - * - * 2 8/13/99 8:01p Jeff - * initial creation of zip class - * - * $NoKeywords: $ - */ - -/* inffast.h -- header to use inffast.c - * Copyright (C) 1995-1998 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -extern int inflate_fast OF((uInt, uInt, inflate_huft *, inflate_huft *, inflate_blocks_statef *, z_streamp)); diff --git a/unzip/inffixed.h b/unzip/inffixed.h deleted file mode 100644 index 0c3ff4a3..00000000 --- a/unzip/inffixed.h +++ /dev/null @@ -1,139 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: /DescentIII/Main/unzip/inffixed.h $ - * $Revision: 2 $ - * $Date: 8/13/99 8:01p $ - * $Author: Jeff $ - * - * - * - * $Log: /DescentIII/Main/unzip/inffixed.h $ - * - * 2 8/13/99 8:01p Jeff - * initial creation of zip class - * - * $NoKeywords: $ - */ - -/* inffixed.h -- table for decoding fixed codes - * Generated automatically by the maketree.c program - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -local uInt fixed_bl = 9; -local uInt fixed_bd = 5; -local inflate_huft fixed_tl[] = { - {{{96, 7}}, 256}, {{{0, 8}}, 80}, {{{0, 8}}, 16}, {{{84, 8}}, 115}, {{{82, 7}}, 31}, {{{0, 8}}, 112}, - {{{0, 8}}, 48}, {{{0, 9}}, 192}, {{{80, 7}}, 10}, {{{0, 8}}, 96}, {{{0, 8}}, 32}, {{{0, 9}}, 160}, - {{{0, 8}}, 0}, {{{0, 8}}, 128}, {{{0, 8}}, 64}, {{{0, 9}}, 224}, {{{80, 7}}, 6}, {{{0, 8}}, 88}, - {{{0, 8}}, 24}, {{{0, 9}}, 144}, {{{83, 7}}, 59}, {{{0, 8}}, 120}, {{{0, 8}}, 56}, {{{0, 9}}, 208}, - {{{81, 7}}, 17}, {{{0, 8}}, 104}, {{{0, 8}}, 40}, {{{0, 9}}, 176}, {{{0, 8}}, 8}, {{{0, 8}}, 136}, - {{{0, 8}}, 72}, {{{0, 9}}, 240}, {{{80, 7}}, 4}, {{{0, 8}}, 84}, {{{0, 8}}, 20}, {{{85, 8}}, 227}, - {{{83, 7}}, 43}, {{{0, 8}}, 116}, {{{0, 8}}, 52}, {{{0, 9}}, 200}, {{{81, 7}}, 13}, {{{0, 8}}, 100}, - {{{0, 8}}, 36}, {{{0, 9}}, 168}, {{{0, 8}}, 4}, {{{0, 8}}, 132}, {{{0, 8}}, 68}, {{{0, 9}}, 232}, - {{{80, 7}}, 8}, {{{0, 8}}, 92}, {{{0, 8}}, 28}, {{{0, 9}}, 152}, {{{84, 7}}, 83}, {{{0, 8}}, 124}, - {{{0, 8}}, 60}, {{{0, 9}}, 216}, {{{82, 7}}, 23}, {{{0, 8}}, 108}, {{{0, 8}}, 44}, {{{0, 9}}, 184}, - {{{0, 8}}, 12}, {{{0, 8}}, 140}, {{{0, 8}}, 76}, {{{0, 9}}, 248}, {{{80, 7}}, 3}, {{{0, 8}}, 82}, - {{{0, 8}}, 18}, {{{85, 8}}, 163}, {{{83, 7}}, 35}, {{{0, 8}}, 114}, {{{0, 8}}, 50}, {{{0, 9}}, 196}, - {{{81, 7}}, 11}, {{{0, 8}}, 98}, {{{0, 8}}, 34}, {{{0, 9}}, 164}, {{{0, 8}}, 2}, {{{0, 8}}, 130}, - {{{0, 8}}, 66}, {{{0, 9}}, 228}, {{{80, 7}}, 7}, {{{0, 8}}, 90}, {{{0, 8}}, 26}, {{{0, 9}}, 148}, - {{{84, 7}}, 67}, {{{0, 8}}, 122}, {{{0, 8}}, 58}, {{{0, 9}}, 212}, {{{82, 7}}, 19}, {{{0, 8}}, 106}, - {{{0, 8}}, 42}, {{{0, 9}}, 180}, {{{0, 8}}, 10}, {{{0, 8}}, 138}, {{{0, 8}}, 74}, {{{0, 9}}, 244}, - {{{80, 7}}, 5}, {{{0, 8}}, 86}, {{{0, 8}}, 22}, {{{192, 8}}, 0}, {{{83, 7}}, 51}, {{{0, 8}}, 118}, - {{{0, 8}}, 54}, {{{0, 9}}, 204}, {{{81, 7}}, 15}, {{{0, 8}}, 102}, {{{0, 8}}, 38}, {{{0, 9}}, 172}, - {{{0, 8}}, 6}, {{{0, 8}}, 134}, {{{0, 8}}, 70}, {{{0, 9}}, 236}, {{{80, 7}}, 9}, {{{0, 8}}, 94}, - {{{0, 8}}, 30}, {{{0, 9}}, 156}, {{{84, 7}}, 99}, {{{0, 8}}, 126}, {{{0, 8}}, 62}, {{{0, 9}}, 220}, - {{{82, 7}}, 27}, {{{0, 8}}, 110}, {{{0, 8}}, 46}, {{{0, 9}}, 188}, {{{0, 8}}, 14}, {{{0, 8}}, 142}, - {{{0, 8}}, 78}, {{{0, 9}}, 252}, {{{96, 7}}, 256}, {{{0, 8}}, 81}, {{{0, 8}}, 17}, {{{85, 8}}, 131}, - {{{82, 7}}, 31}, {{{0, 8}}, 113}, {{{0, 8}}, 49}, {{{0, 9}}, 194}, {{{80, 7}}, 10}, {{{0, 8}}, 97}, - {{{0, 8}}, 33}, {{{0, 9}}, 162}, {{{0, 8}}, 1}, {{{0, 8}}, 129}, {{{0, 8}}, 65}, {{{0, 9}}, 226}, - {{{80, 7}}, 6}, {{{0, 8}}, 89}, {{{0, 8}}, 25}, {{{0, 9}}, 146}, {{{83, 7}}, 59}, {{{0, 8}}, 121}, - {{{0, 8}}, 57}, {{{0, 9}}, 210}, {{{81, 7}}, 17}, {{{0, 8}}, 105}, {{{0, 8}}, 41}, {{{0, 9}}, 178}, - {{{0, 8}}, 9}, {{{0, 8}}, 137}, {{{0, 8}}, 73}, {{{0, 9}}, 242}, {{{80, 7}}, 4}, {{{0, 8}}, 85}, - {{{0, 8}}, 21}, {{{80, 8}}, 258}, {{{83, 7}}, 43}, {{{0, 8}}, 117}, {{{0, 8}}, 53}, {{{0, 9}}, 202}, - {{{81, 7}}, 13}, {{{0, 8}}, 101}, {{{0, 8}}, 37}, {{{0, 9}}, 170}, {{{0, 8}}, 5}, {{{0, 8}}, 133}, - {{{0, 8}}, 69}, {{{0, 9}}, 234}, {{{80, 7}}, 8}, {{{0, 8}}, 93}, {{{0, 8}}, 29}, {{{0, 9}}, 154}, - {{{84, 7}}, 83}, {{{0, 8}}, 125}, {{{0, 8}}, 61}, {{{0, 9}}, 218}, {{{82, 7}}, 23}, {{{0, 8}}, 109}, - {{{0, 8}}, 45}, {{{0, 9}}, 186}, {{{0, 8}}, 13}, {{{0, 8}}, 141}, {{{0, 8}}, 77}, {{{0, 9}}, 250}, - {{{80, 7}}, 3}, {{{0, 8}}, 83}, {{{0, 8}}, 19}, {{{85, 8}}, 195}, {{{83, 7}}, 35}, {{{0, 8}}, 115}, - {{{0, 8}}, 51}, {{{0, 9}}, 198}, {{{81, 7}}, 11}, {{{0, 8}}, 99}, {{{0, 8}}, 35}, {{{0, 9}}, 166}, - {{{0, 8}}, 3}, {{{0, 8}}, 131}, {{{0, 8}}, 67}, {{{0, 9}}, 230}, {{{80, 7}}, 7}, {{{0, 8}}, 91}, - {{{0, 8}}, 27}, {{{0, 9}}, 150}, {{{84, 7}}, 67}, {{{0, 8}}, 123}, {{{0, 8}}, 59}, {{{0, 9}}, 214}, - {{{82, 7}}, 19}, {{{0, 8}}, 107}, {{{0, 8}}, 43}, {{{0, 9}}, 182}, {{{0, 8}}, 11}, {{{0, 8}}, 139}, - {{{0, 8}}, 75}, {{{0, 9}}, 246}, {{{80, 7}}, 5}, {{{0, 8}}, 87}, {{{0, 8}}, 23}, {{{192, 8}}, 0}, - {{{83, 7}}, 51}, {{{0, 8}}, 119}, {{{0, 8}}, 55}, {{{0, 9}}, 206}, {{{81, 7}}, 15}, {{{0, 8}}, 103}, - {{{0, 8}}, 39}, {{{0, 9}}, 174}, {{{0, 8}}, 7}, {{{0, 8}}, 135}, {{{0, 8}}, 71}, {{{0, 9}}, 238}, - {{{80, 7}}, 9}, {{{0, 8}}, 95}, {{{0, 8}}, 31}, {{{0, 9}}, 158}, {{{84, 7}}, 99}, {{{0, 8}}, 127}, - {{{0, 8}}, 63}, {{{0, 9}}, 222}, {{{82, 7}}, 27}, {{{0, 8}}, 111}, {{{0, 8}}, 47}, {{{0, 9}}, 190}, - {{{0, 8}}, 15}, {{{0, 8}}, 143}, {{{0, 8}}, 79}, {{{0, 9}}, 254}, {{{96, 7}}, 256}, {{{0, 8}}, 80}, - {{{0, 8}}, 16}, {{{84, 8}}, 115}, {{{82, 7}}, 31}, {{{0, 8}}, 112}, {{{0, 8}}, 48}, {{{0, 9}}, 193}, - {{{80, 7}}, 10}, {{{0, 8}}, 96}, {{{0, 8}}, 32}, {{{0, 9}}, 161}, {{{0, 8}}, 0}, {{{0, 8}}, 128}, - {{{0, 8}}, 64}, {{{0, 9}}, 225}, {{{80, 7}}, 6}, {{{0, 8}}, 88}, {{{0, 8}}, 24}, {{{0, 9}}, 145}, - {{{83, 7}}, 59}, {{{0, 8}}, 120}, {{{0, 8}}, 56}, {{{0, 9}}, 209}, {{{81, 7}}, 17}, {{{0, 8}}, 104}, - {{{0, 8}}, 40}, {{{0, 9}}, 177}, {{{0, 8}}, 8}, {{{0, 8}}, 136}, {{{0, 8}}, 72}, {{{0, 9}}, 241}, - {{{80, 7}}, 4}, {{{0, 8}}, 84}, {{{0, 8}}, 20}, {{{85, 8}}, 227}, {{{83, 7}}, 43}, {{{0, 8}}, 116}, - {{{0, 8}}, 52}, {{{0, 9}}, 201}, {{{81, 7}}, 13}, {{{0, 8}}, 100}, {{{0, 8}}, 36}, {{{0, 9}}, 169}, - {{{0, 8}}, 4}, {{{0, 8}}, 132}, {{{0, 8}}, 68}, {{{0, 9}}, 233}, {{{80, 7}}, 8}, {{{0, 8}}, 92}, - {{{0, 8}}, 28}, {{{0, 9}}, 153}, {{{84, 7}}, 83}, {{{0, 8}}, 124}, {{{0, 8}}, 60}, {{{0, 9}}, 217}, - {{{82, 7}}, 23}, {{{0, 8}}, 108}, {{{0, 8}}, 44}, {{{0, 9}}, 185}, {{{0, 8}}, 12}, {{{0, 8}}, 140}, - {{{0, 8}}, 76}, {{{0, 9}}, 249}, {{{80, 7}}, 3}, {{{0, 8}}, 82}, {{{0, 8}}, 18}, {{{85, 8}}, 163}, - {{{83, 7}}, 35}, {{{0, 8}}, 114}, {{{0, 8}}, 50}, {{{0, 9}}, 197}, {{{81, 7}}, 11}, {{{0, 8}}, 98}, - {{{0, 8}}, 34}, {{{0, 9}}, 165}, {{{0, 8}}, 2}, {{{0, 8}}, 130}, {{{0, 8}}, 66}, {{{0, 9}}, 229}, - {{{80, 7}}, 7}, {{{0, 8}}, 90}, {{{0, 8}}, 26}, {{{0, 9}}, 149}, {{{84, 7}}, 67}, {{{0, 8}}, 122}, - {{{0, 8}}, 58}, {{{0, 9}}, 213}, {{{82, 7}}, 19}, {{{0, 8}}, 106}, {{{0, 8}}, 42}, {{{0, 9}}, 181}, - {{{0, 8}}, 10}, {{{0, 8}}, 138}, {{{0, 8}}, 74}, {{{0, 9}}, 245}, {{{80, 7}}, 5}, {{{0, 8}}, 86}, - {{{0, 8}}, 22}, {{{192, 8}}, 0}, {{{83, 7}}, 51}, {{{0, 8}}, 118}, {{{0, 8}}, 54}, {{{0, 9}}, 205}, - {{{81, 7}}, 15}, {{{0, 8}}, 102}, {{{0, 8}}, 38}, {{{0, 9}}, 173}, {{{0, 8}}, 6}, {{{0, 8}}, 134}, - {{{0, 8}}, 70}, {{{0, 9}}, 237}, {{{80, 7}}, 9}, {{{0, 8}}, 94}, {{{0, 8}}, 30}, {{{0, 9}}, 157}, - {{{84, 7}}, 99}, {{{0, 8}}, 126}, {{{0, 8}}, 62}, {{{0, 9}}, 221}, {{{82, 7}}, 27}, {{{0, 8}}, 110}, - {{{0, 8}}, 46}, {{{0, 9}}, 189}, {{{0, 8}}, 14}, {{{0, 8}}, 142}, {{{0, 8}}, 78}, {{{0, 9}}, 253}, - {{{96, 7}}, 256}, {{{0, 8}}, 81}, {{{0, 8}}, 17}, {{{85, 8}}, 131}, {{{82, 7}}, 31}, {{{0, 8}}, 113}, - {{{0, 8}}, 49}, {{{0, 9}}, 195}, {{{80, 7}}, 10}, {{{0, 8}}, 97}, {{{0, 8}}, 33}, {{{0, 9}}, 163}, - {{{0, 8}}, 1}, {{{0, 8}}, 129}, {{{0, 8}}, 65}, {{{0, 9}}, 227}, {{{80, 7}}, 6}, {{{0, 8}}, 89}, - {{{0, 8}}, 25}, {{{0, 9}}, 147}, {{{83, 7}}, 59}, {{{0, 8}}, 121}, {{{0, 8}}, 57}, {{{0, 9}}, 211}, - {{{81, 7}}, 17}, {{{0, 8}}, 105}, {{{0, 8}}, 41}, {{{0, 9}}, 179}, {{{0, 8}}, 9}, {{{0, 8}}, 137}, - {{{0, 8}}, 73}, {{{0, 9}}, 243}, {{{80, 7}}, 4}, {{{0, 8}}, 85}, {{{0, 8}}, 21}, {{{80, 8}}, 258}, - {{{83, 7}}, 43}, {{{0, 8}}, 117}, {{{0, 8}}, 53}, {{{0, 9}}, 203}, {{{81, 7}}, 13}, {{{0, 8}}, 101}, - {{{0, 8}}, 37}, {{{0, 9}}, 171}, {{{0, 8}}, 5}, {{{0, 8}}, 133}, {{{0, 8}}, 69}, {{{0, 9}}, 235}, - {{{80, 7}}, 8}, {{{0, 8}}, 93}, {{{0, 8}}, 29}, {{{0, 9}}, 155}, {{{84, 7}}, 83}, {{{0, 8}}, 125}, - {{{0, 8}}, 61}, {{{0, 9}}, 219}, {{{82, 7}}, 23}, {{{0, 8}}, 109}, {{{0, 8}}, 45}, {{{0, 9}}, 187}, - {{{0, 8}}, 13}, {{{0, 8}}, 141}, {{{0, 8}}, 77}, {{{0, 9}}, 251}, {{{80, 7}}, 3}, {{{0, 8}}, 83}, - {{{0, 8}}, 19}, {{{85, 8}}, 195}, {{{83, 7}}, 35}, {{{0, 8}}, 115}, {{{0, 8}}, 51}, {{{0, 9}}, 199}, - {{{81, 7}}, 11}, {{{0, 8}}, 99}, {{{0, 8}}, 35}, {{{0, 9}}, 167}, {{{0, 8}}, 3}, {{{0, 8}}, 131}, - {{{0, 8}}, 67}, {{{0, 9}}, 231}, {{{80, 7}}, 7}, {{{0, 8}}, 91}, {{{0, 8}}, 27}, {{{0, 9}}, 151}, - {{{84, 7}}, 67}, {{{0, 8}}, 123}, {{{0, 8}}, 59}, {{{0, 9}}, 215}, {{{82, 7}}, 19}, {{{0, 8}}, 107}, - {{{0, 8}}, 43}, {{{0, 9}}, 183}, {{{0, 8}}, 11}, {{{0, 8}}, 139}, {{{0, 8}}, 75}, {{{0, 9}}, 247}, - {{{80, 7}}, 5}, {{{0, 8}}, 87}, {{{0, 8}}, 23}, {{{192, 8}}, 0}, {{{83, 7}}, 51}, {{{0, 8}}, 119}, - {{{0, 8}}, 55}, {{{0, 9}}, 207}, {{{81, 7}}, 15}, {{{0, 8}}, 103}, {{{0, 8}}, 39}, {{{0, 9}}, 175}, - {{{0, 8}}, 7}, {{{0, 8}}, 135}, {{{0, 8}}, 71}, {{{0, 9}}, 239}, {{{80, 7}}, 9}, {{{0, 8}}, 95}, - {{{0, 8}}, 31}, {{{0, 9}}, 159}, {{{84, 7}}, 99}, {{{0, 8}}, 127}, {{{0, 8}}, 63}, {{{0, 9}}, 223}, - {{{82, 7}}, 27}, {{{0, 8}}, 111}, {{{0, 8}}, 47}, {{{0, 9}}, 191}, {{{0, 8}}, 15}, {{{0, 8}}, 143}, - {{{0, 8}}, 79}, {{{0, 9}}, 255}}; -local inflate_huft fixed_td[] = { - {{{80, 5}}, 1}, {{{87, 5}}, 257}, {{{83, 5}}, 17}, {{{91, 5}}, 4097}, {{{81, 5}}, 5}, {{{89, 5}}, 1025}, - {{{85, 5}}, 65}, {{{93, 5}}, 16385}, {{{80, 5}}, 3}, {{{88, 5}}, 513}, {{{84, 5}}, 33}, {{{92, 5}}, 8193}, - {{{82, 5}}, 9}, {{{90, 5}}, 2049}, {{{86, 5}}, 129}, {{{192, 5}}, 24577}, {{{80, 5}}, 2}, {{{87, 5}}, 385}, - {{{83, 5}}, 25}, {{{91, 5}}, 6145}, {{{81, 5}}, 7}, {{{89, 5}}, 1537}, {{{85, 5}}, 97}, {{{93, 5}}, 24577}, - {{{80, 5}}, 4}, {{{88, 5}}, 769}, {{{84, 5}}, 49}, {{{92, 5}}, 12289}, {{{82, 5}}, 13}, {{{90, 5}}, 3073}, - {{{86, 5}}, 193}, {{{192, 5}}, 24577}}; diff --git a/unzip/inflate.c b/unzip/inflate.c deleted file mode 100644 index 8166c6fa..00000000 --- a/unzip/inflate.c +++ /dev/null @@ -1,370 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: $ - * $Revision: $ - * $Date: $ - * $Author: $ - * - * - * - * $Log: $ - * - * $NoKeywords: $ - */ - -/* inflate.c -- zlib interface to inflate modules - * Copyright (C) 1995-1998 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "infblock.h" - -// needed by zlib -voidpf zcalloc(voidpf opaque, unsigned items, unsigned size) { - if (opaque) - items += size - size; /* make compiler happy */ - return (voidpf)calloc(items, size); -} - -void zcfree(voidpf opaque, voidpf ptr) { - free(ptr); - if (opaque) - return; /* make compiler happy */ -} - -struct inflate_blocks_state { - int dummy; -}; /* for buggy compilers */ - -typedef enum { - METHOD, /* waiting for method byte */ - FLAG, /* waiting for flag byte */ - DICT4, /* four dictionary check bytes to go */ - DICT3, /* three dictionary check bytes to go */ - DICT2, /* two dictionary check bytes to go */ - DICT1, /* one dictionary check byte to go */ - DICT0, /* waiting for inflateSetDictionary */ - BLOCKS, /* decompressing blocks */ - CHECK4, /* four check bytes to go */ - CHECK3, /* three check bytes to go */ - CHECK2, /* two check bytes to go */ - CHECK1, /* one check byte to go */ - DONE, /* finished check, done */ - BAD -} /* got an error--stay here */ -inflate_mode; - -/* inflate private state */ -struct internal_state { - - /* mode */ - inflate_mode mode; /* current inflate mode */ - - /* mode dependent information */ - union { - uInt method; /* if FLAGS, method byte */ - struct { - uLong was; /* computed check value */ - uLong need; /* stream check value */ - } check; /* if CHECK, check values to compare */ - uInt marker; /* if BAD, inflateSync's marker bytes count */ - } sub; /* submode */ - - /* mode independent information */ - int nowrap; /* flag for no wrapper */ - uInt wbits; /* log2(window size) (8..15, defaults to 15) */ - inflate_blocks_statef *blocks; /* current inflate_blocks state */ -}; - -int ZEXPORT inflateReset(z_streamp z) { - if (z == Z_NULL || z->state == Z_NULL) - return Z_STREAM_ERROR; - z->total_in = z->total_out = 0; - z->msg = Z_NULL; - z->state->mode = z->state->nowrap ? BLOCKS : METHOD; - inflate_blocks_reset(z->state->blocks, z, Z_NULL); - Tracev((stderr, "inflate: reset\n")); - return Z_OK; -} - -int ZEXPORT inflateEnd(z_streamp z) { - if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL) - return Z_STREAM_ERROR; - if (z->state->blocks != Z_NULL) - inflate_blocks_free(z->state->blocks, z); - ZFREE(z, z->state); - z->state = Z_NULL; - Tracev((stderr, "inflate: end\n")); - return Z_OK; -} - -int ZEXPORT inflateInit2_(z_streamp z, int w, const char *version, int stream_size) { - if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || stream_size != sizeof(z_stream)) - return Z_VERSION_ERROR; - - /* initialize state */ - if (z == Z_NULL) - return Z_STREAM_ERROR; - z->msg = Z_NULL; - if (z->zalloc == Z_NULL) { - z->zalloc = zcalloc; - z->opaque = (voidpf)0; - } - if (z->zfree == Z_NULL) - z->zfree = zcfree; - if ((z->state = (struct internal_state FAR *)ZALLOC(z, 1, sizeof(struct internal_state))) == Z_NULL) - return Z_MEM_ERROR; - z->state->blocks = Z_NULL; - - /* handle undocumented nowrap option (no zlib header or check) */ - z->state->nowrap = 0; - if (w < 0) { - w = -w; - z->state->nowrap = 1; - } - - /* set window size */ - if (w < 8 || w > 15) { - inflateEnd(z); - return Z_STREAM_ERROR; - } - z->state->wbits = (uInt)w; - - /* create inflate_blocks state */ - if ((z->state->blocks = inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w)) == Z_NULL) { - inflateEnd(z); - return Z_MEM_ERROR; - } - Tracev((stderr, "inflate: allocated\n")); - - /* reset state */ - inflateReset(z); - return Z_OK; -} - -int ZEXPORT inflateInit_(z_streamp z, const char *version, int stream_size) { - return inflateInit2_(z, DEF_WBITS, version, stream_size); -} - -#define NEEDBYTE \ - { \ - if (z->avail_in == 0) \ - return r; \ - r = f; \ - } -#define NEXTBYTE (z->avail_in--, z->total_in++, *z->next_in++) - -int ZEXPORT inflate(z_streamp z, int f) { - int r; - uInt b; - - if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL) - return Z_STREAM_ERROR; - f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK; - r = Z_BUF_ERROR; - while (1) - switch (z->state->mode) { - case METHOD: - NEEDBYTE - if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED) { - z->state->mode = BAD; - z->msg = (char *)"unknown compression method"; - z->state->sub.marker = 5; /* can't try inflateSync */ - break; - } - if ((z->state->sub.method >> 4) + 8 > z->state->wbits) { - z->state->mode = BAD; - z->msg = (char *)"invalid window size"; - z->state->sub.marker = 5; /* can't try inflateSync */ - break; - } - z->state->mode = FLAG; - case FLAG: - NEEDBYTE - b = NEXTBYTE; - if (((z->state->sub.method << 8) + b) % 31) { - z->state->mode = BAD; - z->msg = (char *)"incorrect header check"; - z->state->sub.marker = 5; /* can't try inflateSync */ - break; - } - Tracev((stderr, "inflate: zlib header ok\n")); - if (!(b & PRESET_DICT)) { - z->state->mode = BLOCKS; - break; - } - z->state->mode = DICT4; - case DICT4: - NEEDBYTE - z->state->sub.check.need = (uLong)NEXTBYTE << 24; - z->state->mode = DICT3; - case DICT3: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE << 16; - z->state->mode = DICT2; - case DICT2: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE << 8; - z->state->mode = DICT1; - case DICT1: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE; - z->adler = z->state->sub.check.need; - z->state->mode = DICT0; - return Z_NEED_DICT; - case DICT0: - z->state->mode = BAD; - z->msg = (char *)"need dictionary"; - z->state->sub.marker = 0; /* can try inflateSync */ - return Z_STREAM_ERROR; - case BLOCKS: - r = inflate_blocks(z->state->blocks, z, r); - if (r == Z_DATA_ERROR) { - z->state->mode = BAD; - z->state->sub.marker = 0; /* can try inflateSync */ - break; - } - if (r == Z_OK) - r = f; - if (r != Z_STREAM_END) - return r; - r = f; - inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was); - if (z->state->nowrap) { - z->state->mode = DONE; - break; - } - z->state->mode = CHECK4; - case CHECK4: - NEEDBYTE - z->state->sub.check.need = (uLong)NEXTBYTE << 24; - z->state->mode = CHECK3; - case CHECK3: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE << 16; - z->state->mode = CHECK2; - case CHECK2: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE << 8; - z->state->mode = CHECK1; - case CHECK1: - NEEDBYTE - z->state->sub.check.need += (uLong)NEXTBYTE; - - if (z->state->sub.check.was != z->state->sub.check.need) { - z->state->mode = BAD; - z->msg = (char *)"incorrect data check"; - z->state->sub.marker = 5; /* can't try inflateSync */ - break; - } - Tracev((stderr, "inflate: zlib check ok\n")); - z->state->mode = DONE; - case DONE: - return Z_STREAM_END; - case BAD: - return Z_DATA_ERROR; - default: - return Z_STREAM_ERROR; - } -#ifdef NEED_DUMMY_RETURN - return Z_STREAM_ERROR; /* Some dumb compilers complain without this */ -#endif -} - -int ZEXPORT inflateSetDictionary(z_streamp z, const Bytef *dictionary, uInt dictLength) { - uInt length = dictLength; - - if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0) - return Z_STREAM_ERROR; - - if (adler32(1L, dictionary, dictLength) != z->adler) - return Z_DATA_ERROR; - z->adler = 1L; - - if (length >= ((uInt)1 << z->state->wbits)) { - length = (1 << z->state->wbits) - 1; - dictionary += dictLength - length; - } - inflate_set_dictionary(z->state->blocks, dictionary, length); - z->state->mode = BLOCKS; - return Z_OK; -} - -int ZEXPORT inflateSync(z_streamp z) { - uInt n; /* number of bytes to look at */ - Bytef *p; /* pointer to bytes */ - uInt m; /* number of marker bytes found in a row */ - uLong r, w; /* temporaries to save total_in and total_out */ - - /* set up */ - if (z == Z_NULL || z->state == Z_NULL) - return Z_STREAM_ERROR; - if (z->state->mode != BAD) { - z->state->mode = BAD; - z->state->sub.marker = 0; - } - if ((n = z->avail_in) == 0) - return Z_BUF_ERROR; - p = z->next_in; - m = z->state->sub.marker; - - /* search */ - while (n && m < 4) { - static const Byte mark[4] = {0, 0, 0xff, 0xff}; - if (*p == mark[m]) - m++; - else if (*p) - m = 0; - else - m = 4 - m; - p++, n--; - } - - /* restore */ - z->total_in += p - z->next_in; - z->next_in = p; - z->avail_in = n; - z->state->sub.marker = m; - - /* return no joy or set up to restart on a new block */ - if (m != 4) - return Z_DATA_ERROR; - r = z->total_in; - w = z->total_out; - inflateReset(z); - z->total_in = r; - z->total_out = w; - z->state->mode = BLOCKS; - return Z_OK; -} - -/* Returns true if inflate is currently at the end of a block generated - * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP - * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH - * but removes the length bytes of the resulting empty stored block. When - * decompressing, PPP checks that at the end of input packet, inflate is - * waiting for these length bytes. - */ -int ZEXPORT inflateSyncPoint(z_streamp z) { - if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL) - return Z_STREAM_ERROR; - return inflate_blocks_sync_point(z->state->blocks); -} diff --git a/unzip/inftrees.c b/unzip/inftrees.c deleted file mode 100644 index 55fb9fbd..00000000 --- a/unzip/inftrees.c +++ /dev/null @@ -1,458 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: $ - * $Revision: $ - * $Date: $ - * $Author: $ - * - * - * - * $Log: $ - * - * $NoKeywords: $ - */ - -/* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-1998 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" - -#if !defined(BUILDFIXED) && !defined(STDC) -#define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */ -#endif - -const char inflate_copyright[] = " inflate 1.1.3 Copyright 1995-1998 Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ -struct internal_state { - int dummy; -}; /* for buggy compilers */ - -/* simplify the use of the inflate_huft type with some defines */ -#define exop word.what.Exop -#define bits word.what.Bits - -local int huft_build OF((uIntf *, /* code lengths in bits */ - uInt, /* number of codes */ - uInt, /* number of "simple" codes */ - const uIntf *, /* list of base values for non-simple codes */ - const uIntf *, /* list of extra bits for non-simple codes */ - inflate_huft *FAR *, /* result: starting table */ - uIntf *, /* maximum lookup bits (returns actual) */ - inflate_huft *, /* space for trees */ - uInt *, /* hufts used in space */ - uIntf *)); /* space for values */ - -/* Tables for deflate from PKZIP's appnote.txt. */ -local const uInt cplens[31] = {/* Copy lengths for literal codes 257..285 */ - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; -/* see note #13 above about 258 */ -local const uInt cplext[31] = {/* Extra bits for literal codes 257..285 */ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */ -local const uInt cpdist[30] = {/* Copy offsets for distance codes 0..29 */ - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, - 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; -local const uInt cpdext[30] = {/* Extra bits for distance codes */ - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, - 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; - -/* - Huffman code decoding is performed using a multi-level table lookup. - The fastest way to decode is to simply build a lookup table whose - size is determined by the longest code. However, the time it takes - to build this table can also be a factor if the data being decoded - is not very long. The most common codes are necessarily the - shortest codes, so those codes dominate the decoding time, and hence - the speed. The idea is you can have a shorter table that decodes the - shorter, more probable codes, and then point to subsidiary tables for - the longer codes. The time it costs to decode the longer codes is - then traded against the time it takes to make longer tables. - - This results of this trade are in the variables lbits and dbits - below. lbits is the number of bits the first level table for literal/ - length codes can decode in one step, and dbits is the same thing for - the distance codes. Subsequent tables are also less than or equal to - those sizes. These values may be adjusted either when all of the - codes are shorter than that, in which case the longest code length in - bits is used, or when the shortest code is *longer* than the requested - table size, in which case the length of the shortest code in bits is - used. - - There are two different values for the two tables, since they code a - different number of possibilities each. The literal/length table - codes 286 possible values, or in a flat code, a little over eight - bits. The distance table codes 30 possible values, or a little less - than five bits, flat. The optimum values for speed end up being - about one bit more than those, so lbits is 8+1 and dbits is 5+1. - The optimum values may differ though from machine to machine, and - possibly even between compilers. Your mileage may vary. - */ - -/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */ -#define BMAX 15 /* maximum bit length of any code */ -/* -uIntf *b; code lengths in bits (all assumed <= BMAX) -uInt n; number of codes (assumed <= 288) -uInt s; number of simple-valued codes (0..s-1) -const uIntf *d; list of base values for non-simple codes -const uIntf *e; list of extra bits for non-simple codes -inflate_huft * FAR *t; result: starting table -uIntf *m; maximum lookup bits, returns actual -inflate_huft *hp; space for trees -uInt *hn; hufts used in space -uIntf *v; working area: values in order of bit length - Given a list of code lengths and a maximum table size, make a set of - tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR - if the given code set is incomplete (the tables are still built in this - case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of - lengths), or Z_MEM_ERROR if not enough memory. */ -local int huft_build(uIntf *b, uInt n, uInt s, const uIntf *d, const uIntf *e, inflate_huft *FAR *t, uIntf *m, - inflate_huft *hp, uInt *hn, uIntf *v) { - - uInt a; /* counter for codes of length k */ - uInt c[BMAX + 1]; /* bit length count table */ - uInt f; /* i repeats in table every f entries */ - int g; /* maximum code length */ - int h; /* table level */ - register uInt i; /* counter, current code */ - register uInt j; /* counter */ - register int k; /* number of bits in current code */ - int l; /* bits per table (returned in m) */ - uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */ - register uIntf *p; /* pointer into c[], b[], or v[] */ - inflate_huft *q; /* points to current table */ - struct inflate_huft_s r; /* table entry for structure assignment */ - inflate_huft *u[BMAX]; /* table stack */ - register int w; /* bits before this table == (l * h) */ - uInt x[BMAX + 1]; /* bit offsets, then code stack */ - uIntf *xp; /* pointer into x */ - int y; /* number of dummy codes added */ - uInt z; /* number of entries in current table */ - - /* Generate counts for each bit length */ - p = c; -#define C0 *p++ = 0; -#define C2 C0 C0 C0 C0 -#define C4 C2 C2 C2 C2 - C4 /* clear c[]--assume BMAX+1 is 16 */ - p = b; - i = n; - do { - c[*p++]++; /* assume all entries <= BMAX */ - } while (--i); - if (c[0] == n) /* null input--all zero length codes */ - { - *t = (inflate_huft *)Z_NULL; - *m = 0; - return Z_OK; - } - - /* Find minimum and maximum length, bound *m by those */ - l = *m; - for (j = 1; j <= BMAX; j++) - if (c[j]) - break; - k = j; /* minimum code length */ - if ((uInt)l < j) - l = j; - for (i = BMAX; i; i--) - if (c[i]) - break; - g = i; /* maximum code length */ - if ((uInt)l > i) - l = i; - *m = l; - - /* Adjust last length count to fill out codes, if needed */ - for (y = 1 << j; j < i; j++, y <<= 1) - if ((y -= c[j]) < 0) - return Z_DATA_ERROR; - if ((y -= c[i]) < 0) - return Z_DATA_ERROR; - c[i] += y; - - /* Generate starting offsets into the value table for each length */ - x[1] = j = 0; - p = c + 1; - xp = x + 2; - while (--i) { /* note that i == g from above */ - *xp++ = (j += *p++); - } - - /* Make a table of values in order of bit lengths */ - p = b; - i = 0; - do { - if ((j = *p++) != 0) - v[x[j]++] = i; - } while (++i < n); - n = x[g]; /* set n to length of v */ - - /* Generate the Huffman codes and for each, make the table entries */ - x[0] = i = 0; /* first Huffman code is zero */ - p = v; /* grab values in bit order */ - h = -1; /* no tables yet--level -1 */ - w = -l; /* bits decoded == (l * h) */ - u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */ - q = (inflate_huft *)Z_NULL; /* ditto */ - z = 0; /* ditto */ - - /* go through the bit lengths (k already is bits in shortest code) */ - for (; k <= g; k++) { - a = c[k]; - while (a--) { - /* here i is the Huffman code of length k bits for value *p */ - /* make tables up to required level */ - while (k > w + l) { - h++; - w += l; /* previous table always l bits */ - - /* compute minimum size table less than or equal to l bits */ - z = g - w; - z = z > (uInt)l ? l : z; /* table size upper limit */ - if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */ - { /* too few codes for k-w bit table */ - f -= a + 1; /* deduct codes from patterns left */ - xp = c + k; - if (j < z) - while (++j < z) /* try smaller tables up to z bits */ - { - if ((f <<= 1) <= *++xp) - break; /* enough codes to use up j bits */ - f -= *xp; /* else deduct codes from patterns */ - } - } - z = 1 << j; /* table entries for j-bit table */ - - /* allocate new table */ - if (*hn + z > MANY) /* (note: doesn't matter for fixed) */ - return Z_MEM_ERROR; /* not enough memory */ - u[h] = q = hp + *hn; - *hn += z; - - /* connect to last table, if there is one */ - if (h) { - x[h] = i; /* save pattern for backing up */ - r.bits = (Byte)l; /* bits to dump before this table */ - r.exop = (Byte)j; /* bits in this table */ - j = i >> (w - l); - r.base = (uInt)(q - u[h - 1] - j); /* offset to this table */ - u[h - 1][j] = r; /* connect to last table */ - } else - *t = q; /* first table is returned result */ - } - - /* set up table entry in r */ - r.bits = (Byte)(k - w); - if (p >= v + n) - r.exop = 128 + 64; /* out of values--invalid code */ - else if (*p < s) { - r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */ - r.base = *p++; /* simple code is just the value */ - } else { - r.exop = (Byte)(e[*p - s] + 16 + 64); /* non-simple--look up in lists */ - r.base = d[*p++ - s]; - } - - /* fill code-like entries with r */ - f = 1 << (k - w); - for (j = i >> w; j < z; j += f) - q[j] = r; - - /* backwards increment the k-bit code i */ - for (j = 1 << (k - 1); i & j; j >>= 1) - i ^= j; - i ^= j; - - /* backup over finished tables */ - mask = (1 << w) - 1; /* needed on HP, cc -O bug */ - while ((i & mask) != x[h]) { - h--; /* don't need to update q */ - w -= l; - mask = (1 << w) - 1; - } - } - } - - /* Return Z_BUF_ERROR if we were given an incomplete table */ - return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK; -} - -/* -uIntf *c; 19 code lengths -uIntf *bb; bits tree desired/actual depth -inflate_huft * FAR *tb; bits tree result -inflate_huft *hp; space for trees -z_streamp z; for messages -*/ -int inflate_trees_bits(uIntf *c, uIntf *bb, inflate_huft *FAR *tb, inflate_huft *hp, z_streamp z) { - int r; - uInt hn = 0; /* hufts used in space */ - uIntf *v; /* work area for huft_build */ - - if ((v = (uIntf *)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL) - return Z_MEM_ERROR; - r = huft_build(c, 19, 19, (uIntf *)Z_NULL, (uIntf *)Z_NULL, tb, bb, hp, &hn, v); - if (r == Z_DATA_ERROR) - z->msg = (char *)"oversubscribed dynamic bit lengths tree"; - else if (r == Z_BUF_ERROR || *bb == 0) { - z->msg = (char *)"incomplete dynamic bit lengths tree"; - r = Z_DATA_ERROR; - } - ZFREE(z, v); - return r; -} - -/* -uInt nl; number of literal/length codes -uInt nd; number of distance codes -uIntf *c; that many (total) code lengths -uIntf *bl; literal desired/actual bit depth -uIntf *bd; distance desired/actual bit depth -inflate_huft * FAR *tl; literal/length tree result -inflate_huft * FAR *td; distance tree result -inflate_huft *hp; space for trees -z_streamp z; for messages -*/ -int inflate_trees_dynamic(uInt nl, uInt nd, uIntf *c, uIntf *bl, uIntf *bd, inflate_huft *FAR *tl, - inflate_huft *FAR *td, inflate_huft *hp, z_streamp z) { - int r; - uInt hn = 0; /* hufts used in space */ - uIntf *v; /* work area for huft_build */ - - /* allocate work area */ - if ((v = (uIntf *)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL) - return Z_MEM_ERROR; - - /* build literal/length tree */ - r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v); - if (r != Z_OK || *bl == 0) { - if (r == Z_DATA_ERROR) - z->msg = (char *)"oversubscribed literal/length tree"; - else if (r != Z_MEM_ERROR) { - z->msg = (char *)"incomplete literal/length tree"; - r = Z_DATA_ERROR; - } - ZFREE(z, v); - return r; - } - - /* build distance tree */ - r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v); - if (r != Z_OK || (*bd == 0 && nl > 257)) { - if (r == Z_DATA_ERROR) - z->msg = (char *)"oversubscribed distance tree"; - else if (r == Z_BUF_ERROR) { -#ifdef PKZIP_BUG_WORKAROUND - r = Z_OK; - } -#else - z->msg = (char *)"incomplete distance tree"; - r = Z_DATA_ERROR; - } else if (r != Z_MEM_ERROR) { - z->msg = (char *)"empty distance tree with lengths"; - r = Z_DATA_ERROR; - } - ZFREE(z, v); - return r; -#endif - } - - /* done */ - ZFREE(z, v); - return Z_OK; -} - -/* build fixed tables only once--keep them here */ -#ifdef BUILDFIXED -local int fixed_built = 0; -#define FIXEDH 544 /* number of hufts used by fixed tables */ -local inflate_huft fixed_mem[FIXEDH]; -local uInt fixed_bl; -local uInt fixed_bd; -local inflate_huft *fixed_tl; -local inflate_huft *fixed_td; -#else -#include "inffixed.h" -#endif - -/* -uIntf *bl; literal desired/actual bit depth -uIntf *bd; distance desired/actual bit depth -inflate_huft * FAR *tl; literal/length tree result -inflate_huft * FAR *td; distance tree result -z_streamp z; for memory allocation -*/ -int inflate_trees_fixed(uIntf *bl, uIntf *bd, inflate_huft *FAR *tl, inflate_huft *FAR *td, z_streamp z) { -#ifdef BUILDFIXED - /* build fixed tables if not already */ - if (!fixed_built) { - int k; /* temporary variable */ - uInt f = 0; /* number of hufts used in fixed_mem */ - uIntf *c; /* length list for huft_build */ - uIntf *v; /* work area for huft_build */ - - /* allocate memory */ - if ((c = (uIntf *)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL) - return Z_MEM_ERROR; - if ((v = (uIntf *)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL) { - ZFREE(z, c); - return Z_MEM_ERROR; - } - - /* literal table */ - for (k = 0; k < 144; k++) - c[k] = 8; - for (; k < 256; k++) - c[k] = 9; - for (; k < 280; k++) - c[k] = 7; - for (; k < 288; k++) - c[k] = 8; - fixed_bl = 9; - huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, fixed_mem, &f, v); - - /* distance table */ - for (k = 0; k < 30; k++) - c[k] = 5; - fixed_bd = 5; - huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, fixed_mem, &f, v); - - /* done */ - ZFREE(z, v); - ZFREE(z, c); - fixed_built = 1; - } -#endif - *bl = fixed_bl; - *bd = fixed_bd; - *tl = fixed_tl; - *td = fixed_td; - return Z_OK; -} diff --git a/unzip/inftrees.h b/unzip/inftrees.h deleted file mode 100644 index 21737dc4..00000000 --- a/unzip/inftrees.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: /DescentIII/Main/unzip/inftrees.h $ - * $Revision: 2 $ - * $Date: 8/13/99 8:01p $ - * $Author: Jeff $ - * - * - * - * $Log: /DescentIII/Main/unzip/inftrees.h $ - * - * 2 8/13/99 8:01p Jeff - * initial creation of zip class - * - * $NoKeywords: $ - */ - -/* inftrees.h -- header to use inftrees.c - * Copyright (C) 1995-1998 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* Huffman code lookup table entry--this entry is four bytes for machines - that have 16-bit pointers (e.g. PC's in the small or medium model). */ - -typedef struct inflate_huft_s FAR inflate_huft; - -struct inflate_huft_s { - union { - struct { - Byte Exop; /* number of extra bits or operation */ - Byte Bits; /* number of bits in this code or subcode */ - } what; - uInt pad; /* pad structure to a power of 2 (4 bytes for */ - } word; /* 16-bit, 8 bytes for 32-bit int's) */ - uInt base; /* literal, length base, distance base, - or table offset */ -}; - -/* Maximum size of dynamic tree. The maximum found in a long but non- - exhaustive search was 1004 huft structures (850 for length/literals - and 154 for distances, the latter actually the result of an - exhaustive search). The actual maximum is not known, but the - value below is more than safe. */ -#define MANY 1440 - -extern int inflate_trees_bits OF((uIntf *, /* 19 code lengths */ - uIntf *, /* bits tree desired/actual depth */ - inflate_huft *FAR *, /* bits tree result */ - inflate_huft *, /* space for trees */ - z_streamp)); /* for messages */ - -extern int inflate_trees_dynamic OF((uInt, /* number of literal/length codes */ - uInt, /* number of distance codes */ - uIntf *, /* that many (total) code lengths */ - uIntf *, /* literal desired/actual bit depth */ - uIntf *, /* distance desired/actual bit depth */ - inflate_huft *FAR *, /* literal/length tree result */ - inflate_huft *FAR *, /* distance tree result */ - inflate_huft *, /* space for trees */ - z_streamp)); /* for messages */ - -extern int inflate_trees_fixed OF((uIntf *, /* literal desired/actual bit depth */ - uIntf *, /* distance desired/actual bit depth */ - inflate_huft *FAR *, /* literal/length tree result */ - inflate_huft *FAR *, /* distance tree result */ - z_streamp)); /* for memory allocation */ diff --git a/unzip/infutil.c b/unzip/infutil.c deleted file mode 100644 index 16f18c2e..00000000 --- a/unzip/infutil.c +++ /dev/null @@ -1,115 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: $ - * $Revision: $ - * $Date: $ - * $Author: $ - * - * - * - * $Log: $ - * - * $NoKeywords: $ - */ - -/* inflate_util.c -- data and routines common to blocks and codes - * Copyright (C) 1995-1998 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "infblock.h" -#include "inftrees.h" -#include "infcodes.h" -#include "infutil.h" - -struct inflate_codes_state { - int dummy; -}; /* for buggy compilers */ - -/* And'ing with mask[n] masks the lower n bits */ -uInt inflate_mask[17] = {0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, - 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff}; - -/* copy as much as possible from the sliding window to the output area */ -int inflate_flush(inflate_blocks_statef *s, z_streamp z, int r) { - uInt n; - Bytef *p; - Bytef *q; - - /* local copies of source and destination pointers */ - p = z->next_out; - q = s->read; - - /* compute number of bytes to copy as far as end of window */ - n = (uInt)((q <= s->write ? s->write : s->end) - q); - if (n > z->avail_out) - n = z->avail_out; - if (n && r == Z_BUF_ERROR) - r = Z_OK; - - /* update counters */ - z->avail_out -= n; - z->total_out += n; - - /* update check information */ - if (s->checkfn != Z_NULL) - z->adler = s->check = (*s->checkfn)(s->check, q, n); - - /* copy as far as end of window */ - zmemcpy(p, q, n); - p += n; - q += n; - - /* see if more to copy at beginning of window */ - if (q == s->end) { - /* wrap pointers */ - q = s->window; - if (s->write == s->end) - s->write = s->window; - - /* compute bytes to copy */ - n = (uInt)(s->write - q); - if (n > z->avail_out) - n = z->avail_out; - if (n && r == Z_BUF_ERROR) - r = Z_OK; - - /* update counters */ - z->avail_out -= n; - z->total_out += n; - - /* update check information */ - if (s->checkfn != Z_NULL) - z->adler = s->check = (*s->checkfn)(s->check, q, n); - - /* copy */ - zmemcpy(p, q, n); - p += n; - q += n; - } - - /* update pointers */ - z->next_out = p; - s->read = q; - - /* done */ - return r; -} diff --git a/unzip/infutil.h b/unzip/infutil.h deleted file mode 100644 index fe7649de..00000000 --- a/unzip/infutil.h +++ /dev/null @@ -1,189 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: /DescentIII/Main/unzip/infutil.h $ - * $Revision: 2 $ - * $Date: 8/13/99 8:01p $ - * $Author: Jeff $ - * - * - * - * $Log: /DescentIII/Main/unzip/infutil.h $ - * - * 2 8/13/99 8:01p Jeff - * initial creation of zip class - * - * $NoKeywords: $ - */ - -/* infutil.h -- types and macros common to blocks and codes - * Copyright (C) 1995-1998 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -#ifndef _INFUTIL_H -#define _INFUTIL_H - -typedef enum { - TYPE, /* get type bits (3, including end bit) */ - LENS, /* get lengths for stored */ - STORED, /* processing stored block */ - TABLE, /* get table lengths */ - BTREE, /* get bit lengths tree for a dynamic block */ - DTREE, /* get length, distance trees for a dynamic block */ - CODES, /* processing fixed or dynamic block */ - DRY, /* output remaining window bytes */ - DONE, /* finished last block, done */ - BAD -} /* got a data error--stuck here */ -inflate_block_mode; - -/* inflate blocks semi-private state */ -struct inflate_blocks_state { - - /* mode */ - inflate_block_mode mode; /* current inflate_block mode */ - - /* mode dependent information */ - union { - uInt left; /* if STORED, bytes left to copy */ - struct { - uInt table; /* table lengths (14 bits) */ - uInt index; /* index into blens (or border) */ - uIntf *blens; /* bit lengths of codes */ - uInt bb; /* bit length tree depth */ - inflate_huft *tb; /* bit length decoding tree */ - } trees; /* if DTREE, decoding info for trees */ - struct { - inflate_codes_statef *codes; - } decode; /* if CODES, current state */ - } sub; /* submode */ - uInt last; /* true if this block is the last block */ - - /* mode independent information */ - uInt bitk; /* bits in bit buffer */ - uLong bitb; /* bit buffer */ - inflate_huft *hufts; /* single malloc for tree space */ - Bytef *window; /* sliding window */ - Bytef *end; /* one byte after sliding window */ - Bytef *read; /* window read pointer */ - Bytef *write; /* window write pointer */ - check_func checkfn; /* check function */ - uLong check; /* check on output */ -}; - -/* defines for inflate input/output */ -/* update pointers and return */ -#define UPDBITS \ - { \ - s->bitb = b; \ - s->bitk = k; \ - } -#define UPDIN \ - { \ - z->avail_in = n; \ - z->total_in += p - z->next_in; \ - z->next_in = p; \ - } -#define UPDOUT \ - { s->write = q; } -#define UPDATE \ - { UPDBITS UPDIN UPDOUT } -#define LEAVE \ - { UPDATE return inflate_flush(s, z, r); } -/* get bytes and bits */ -#define LOADIN \ - { \ - p = z->next_in; \ - n = z->avail_in; \ - b = s->bitb; \ - k = s->bitk; \ - } -#define NEEDBYTE \ - { \ - if (n) \ - r = Z_OK; \ - else \ - LEAVE \ - } -#define NEXTBYTE (n--, *p++) -#define NEEDBITS(j) \ - { \ - while (k < (j)) { \ - NEEDBYTE; \ - b |= ((uLong)NEXTBYTE) << k; \ - k += 8; \ - } \ - } -#define DUMPBITS(j) \ - { \ - b >>= (j); \ - k -= (j); \ - } -/* output bytes */ -#define WAVAIL (uInt)(q < s->read ? s->read - q - 1 : s->end - q) -#define LOADOUT \ - { \ - q = s->write; \ - m = (uInt)WAVAIL; \ - } -#define WRAP \ - { \ - if (q == s->end && s->read != s->window) { \ - q = s->window; \ - m = (uInt)WAVAIL; \ - } \ - } -#define FLUSH \ - { \ - UPDOUT r = inflate_flush(s, z, r); \ - LOADOUT \ - } -#define NEEDOUT \ - { \ - if (m == 0) { \ - WRAP if (m == 0) { FLUSH WRAP if (m == 0) LEAVE } \ - } \ - r = Z_OK; \ - } -#define OUTBYTE(a) \ - { \ - *q++ = (Byte)(a); \ - m--; \ - } -/* load local pointers */ -#define LOAD \ - { LOADIN LOADOUT } - -/* masks for lower bits (size given to avoid silly warnings with Visual C++) */ -extern uInt inflate_mask[17]; - -/* copy as much as possible from the sliding window to the output area */ -extern int inflate_flush OF((inflate_blocks_statef *, z_streamp, int)); - -struct internal_state { - int dummy; -}; /* for buggy compilers */ - -#endif diff --git a/unzip/unzip.cpp b/unzip/unzip.cpp index 328f45f7..bb225613 100644 --- a/unzip/unzip.cpp +++ b/unzip/unzip.cpp @@ -38,7 +38,9 @@ #include #include #include -#include "zlib.h" + +#include + #include "unzip.h" #include diff --git a/unzip/zconf.h b/unzip/zconf.h deleted file mode 100644 index 1250ca59..00000000 --- a/unzip/zconf.h +++ /dev/null @@ -1,312 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: /DescentIII/Main/unzip/zconf.h $ - * $Revision: 2 $ - * $Date: 8/13/99 8:02p $ - * $Author: Jeff $ - * - * - * - * $Log: /DescentIII/Main/unzip/zconf.h $ - * - * 2 8/13/99 8:02p Jeff - * initial creation of zip class - * - * $NoKeywords: $ - */ - -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-1998 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#ifndef _ZCONF_H -#define _ZCONF_H - -/* - * If you *really* need a unique prefix for all types and library functions, - * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. - */ -#ifdef Z_PREFIX -#define deflateInit_ z_deflateInit_ -#define deflate z_deflate -#define deflateEnd z_deflateEnd -#define inflateInit_ z_inflateInit_ -#define inflate z_inflate -#define inflateEnd z_inflateEnd -#define deflateInit2_ z_deflateInit2_ -#define deflateSetDictionary z_deflateSetDictionary -#define deflateCopy z_deflateCopy -#define deflateReset z_deflateReset -#define deflateParams z_deflateParams -#define inflateInit2_ z_inflateInit2_ -#define inflateSetDictionary z_inflateSetDictionary -#define inflateSync z_inflateSync -#define inflateSyncPoint z_inflateSyncPoint -#define inflateReset z_inflateReset -#define compress z_compress -#define compress2 z_compress2 -#define uncompress z_uncompress -#define adler32 z_adler32 -#define crc32 z_crc32 -#define get_crc_table z_get_crc_table - -#define Byte z_Byte -#define uInt z_uInt -#define uLong z_uLong -#define Bytef z_Bytef -#define charf z_charf -#define intf z_intf -#define uIntf z_uIntf -#define uLongf z_uLongf -#define voidpf z_voidpf -#define voidp z_voidp -#endif - -#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) -#define WIN32 -#endif -#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386) -#ifndef __32BIT__ -#define __32BIT__ -#endif -#endif -#if defined(__MSDOS__) && !defined(MSDOS) -#define MSDOS -#endif - -/* - * Compile with -DMAXSEG_64K if the alloc function cannot allocate more - * than 64k bytes at a time (needed on systems with 16-bit int). - */ -#if defined(MSDOS) && !defined(__32BIT__) -#define MAXSEG_64K -#endif -#ifdef MSDOS -#define UNALIGNED_OK -#endif - -#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC) -#define STDC -#endif -#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__) -#ifndef STDC -#define STDC -#endif -#endif - -#ifndef STDC -#ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -#define const -#endif -#endif - -/* Some Mac compilers merge all .h files incorrectly: */ -#if defined(__MWERKS__) || defined(applec) || defined(THINK_C) || defined(__SC__) -#define NO_DUMMY_DECL -#endif - -/* Old Borland C incorrectly complains about missing returns: */ -#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) -#define NEED_DUMMY_RETURN -#endif - -/* Maximum value for memLevel in deflateInit2 */ -#ifndef MAX_MEM_LEVEL -#ifdef MAXSEG_64K -#define MAX_MEM_LEVEL 8 -#else -#define MAX_MEM_LEVEL 9 -#endif -#endif - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#ifndef MAX_WBITS -#define MAX_WBITS 15 /* 32K LZ77 window */ -#endif - -/* The memory requirements for deflate are (in bytes): - (1 << (windowBits+2)) + (1 << (memLevel+9)) - that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) - plus a few kilobytes for small objects. For example, if you want to reduce - the default memory requirements from 256K to 128K, compile with - make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" - Of course this will generally degrade compression (there's no free lunch). - - The memory requirements for inflate are (in bytes) 1 << windowBits - that is, 32K for windowBits=15 (default value) plus a few kilobytes - for small objects. -*/ - -/* Type declarations */ - -#ifndef OF /* function prototypes */ -#ifdef STDC -#define OF(args) args -#else -#define OF(args) () -#endif -#endif - -/* The following definitions for FAR are needed only for MSDOS mixed - * model programming (small or medium model with some far allocations). - * This was tested only with MSC; for other MSDOS compilers you may have - * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, - * just define FAR to be empty. - */ -#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__) -/* MSC small or medium model */ -#define SMALL_MEDIUM -#ifdef _MSC_VER -#define FAR _far -#else -#define FAR far -#endif -#endif -#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__)) -#ifndef __32BIT__ -#define SMALL_MEDIUM -#define FAR _far -#endif -#endif - -/* Compile with -DZLIB_DLL for Windows DLL support */ -#if defined(ZLIB_DLL) -#if defined(_WINDOWS) || defined(WINDOWS) -#ifdef FAR -#undef FAR -#endif -#include -#define ZEXPORT WINAPI -#ifdef WIN32 -#define ZEXPORTVA WINAPIV -#else -#define ZEXPORTVA FAR _cdecl _export -#endif -#endif -#if defined(__BORLANDC__) -#if (__BORLANDC__ >= 0x0500) && defined(WIN32) -#include -#define ZEXPORT __declspec(dllexport) WINAPI -#define ZEXPORTRVA __declspec(dllexport) WINAPIV -#else -#if defined(_Windows) && defined(__DLL__) -#define ZEXPORT _export -#define ZEXPORTVA _export -#endif -#endif -#endif -#endif - -#if defined(__BEOS__) -#if defined(ZLIB_DLL) -#define ZEXTERN extern __declspec(dllexport) -#else -#define ZEXTERN extern __declspec(dllimport) -#endif -#endif - -#ifndef ZEXPORT -#define ZEXPORT -#endif -#ifndef ZEXPORTVA -#define ZEXPORTVA -#endif -#ifndef ZEXTERN -#define ZEXTERN extern -#endif - -#ifndef FAR -#define FAR -#endif - -#if !defined(MACOS) && !defined(TARGET_OS_MAC) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -#ifdef SMALL_MEDIUM -/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -#define Bytef Byte FAR -#else -typedef Byte FAR Bytef; -#endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -#ifdef STDC -typedef void FAR *voidpf; -typedef void *voidp; -#else -typedef Byte FAR *voidpf; -typedef Byte *voidp; -#endif - -#ifdef HAVE_UNISTD_H -#include /* for off_t */ -#include /* for SEEK_* and off_t */ -#define z_off_t off_t -#endif -#ifndef SEEK_SET -#define SEEK_SET 0 /* Seek from beginning of file. */ -#define SEEK_CUR 1 /* Seek from current position. */ -#define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ -#endif -#ifndef z_off_t -#define z_off_t long -#endif - -/* MVS linker does not support external names larger than 8 bytes */ -#if defined(__MVS__) -#pragma map(deflateInit_, "DEIN") -#pragma map(deflateInit2_, "DEIN2") -#pragma map(deflateEnd, "DEEND") -#pragma map(inflateInit_, "ININ") -#pragma map(inflateInit2_, "ININ2") -#pragma map(inflateEnd, "INEND") -#pragma map(inflateSync, "INSY") -#pragma map(inflateSetDictionary, "INSEDI") -#pragma map(inflate_blocks, "INBL") -#pragma map(inflate_blocks_new, "INBLNE") -#pragma map(inflate_blocks_free, "INBLFR") -#pragma map(inflate_blocks_reset, "INBLRE") -#pragma map(inflate_codes_free, "INCOFR") -#pragma map(inflate_codes, "INCO") -#pragma map(inflate_fast, "INFA") -#pragma map(inflate_flush, "INFLU") -#pragma map(inflate_mask, "INMA") -#pragma map(inflate_set_dictionary, "INSEDI2") -#pragma map(inflate_copyright, "INCOPY") -#pragma map(inflate_trees_bits, "INTRBI") -#pragma map(inflate_trees_dynamic, "INTRDY") -#pragma map(inflate_trees_fixed, "INTRFI") -#pragma map(inflate_trees_free, "INTRFR") -#endif - -#endif /* _ZCONF_H */ diff --git a/unzip/zlib.h b/unzip/zlib.h deleted file mode 100644 index f961ac9b..00000000 --- a/unzip/zlib.h +++ /dev/null @@ -1,898 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: /DescentIII/Main/unzip/zlib.h $ - * $Revision: 2 $ - * $Date: 8/13/99 8:02p $ - * $Author: Jeff $ - * - * - * - * $Log: /DescentIII/Main/unzip/zlib.h $ - * - * 2 8/13/99 8:02p Jeff - * initial creation of zip class - * - * $NoKeywords: $ - */ - -/* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.1.3, July 9th, 1998 - - Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt - (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). -*/ - -#ifndef _ZLIB_H -#define _ZLIB_H - -#include "zconf.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ZLIB_VERSION "1.1.3" - -/* - The 'zlib' compression library provides in-memory compression and - decompression functions, including integrity checks of the uncompressed - data. This version of the library supports only one compression method - (deflation) but other algorithms will be added later and will have the same - stream interface. - - Compression can be done in a single step if the buffers are large - enough (for example if an input file is mmap'ed), or can be done by - repeated calls of the compression function. In the latter case, the - application must provide more input and/or consume the output - (providing more output space) before each call. - - The library also supports reading and writing files in gzip (.gz) format - with an interface similar to that of stdio. - - The library does not install any signal handler. The decoder checks - the consistency of the compressed data, so the library should never - crash even in case of corrupted input. -*/ - -typedef voidpf(*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void(*free_func) OF((voidpf opaque, voidpf address)); - -struct internal_state; - -typedef struct z_stream_s { - Bytef *next_in; /* next input byte */ - uInt avail_in; /* number of bytes available at next_in */ - uLong total_in; /* total nb of input bytes read so far */ - - Bytef *next_out; /* next output byte should be put there */ - uInt avail_out; /* remaining free space at next_out */ - uLong total_out; /* total nb of bytes output so far */ - - char *msg; /* last error message, NULL if no error */ - struct internal_state FAR *state; /* not visible by applications */ - - alloc_func zalloc; /* used to allocate the internal state */ - free_func zfree; /* used to free the internal state */ - voidpf opaque; /* private data object passed to zalloc and zfree */ - - int data_type; /* best guess about the data type: ascii or binary */ - uLong adler; /* adler32 value of the uncompressed data */ - uLong reserved; /* reserved for future use */ -} z_stream; - -typedef z_stream FAR *z_streamp; - -/* - The application must update next_in and avail_in when avail_in has - dropped to zero. It must update next_out and avail_out when avail_out - has dropped to zero. The application must initialize zalloc, zfree and - opaque before calling the init function. All other fields are set by the - compression library and must not be updated by the application. - - The opaque value provided by the application will be passed as the first - parameter for calls of zalloc and zfree. This can be useful for custom - memory management. The compression library attaches no meaning to the - opaque value. - - zalloc must return Z_NULL if there is not enough memory for the object. - If zlib is used in a multi-threaded application, zalloc and zfree must be - thread safe. - - On 16-bit systems, the functions zalloc and zfree must be able to allocate - exactly 65536 bytes, but will not be required to allocate more than this - if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, - pointers returned by zalloc for objects of exactly 65536 bytes *must* - have their offset normalized to zero. The default allocation function - provided by this library ensures this (see zutil.c). To reduce memory - requirements and avoid any allocation of 64K objects, at the expense of - compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). - - The fields total_in and total_out can be used for statistics or - progress reports. After compression, total_in holds the total size of - the uncompressed data and may be saved for use in the decompressor - (particularly if the decompressor wants to decompress everything in - a single step). -*/ - -/* constants */ - -#define Z_NO_FLUSH 0 -#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ -#define Z_SYNC_FLUSH 2 -#define Z_FULL_FLUSH 3 -#define Z_FINISH 4 -/* Allowed flush values; see deflate() below for details */ - -#define Z_OK 0 -#define Z_STREAM_END 1 -#define Z_NEED_DICT 2 -#define Z_ERRNO (-1) -#define Z_STREAM_ERROR (-2) -#define Z_DATA_ERROR (-3) -#define Z_MEM_ERROR (-4) -#define Z_BUF_ERROR (-5) -#define Z_VERSION_ERROR (-6) -/* Return codes for the compression/decompression functions. Negative - * values are errors, positive values are used for special but normal events. - */ - -#define Z_NO_COMPRESSION 0 -#define Z_BEST_SPEED 1 -#define Z_BEST_COMPRESSION 9 -#define Z_DEFAULT_COMPRESSION (-1) -/* compression levels */ - -#define Z_FILTERED 1 -#define Z_HUFFMAN_ONLY 2 -#define Z_DEFAULT_STRATEGY 0 -/* compression strategy; see deflateInit2() below for details */ - -#define Z_BINARY 0 -#define Z_ASCII 1 -#define Z_UNKNOWN 2 -/* Possible values of the data_type field */ - -#define Z_DEFLATED 8 -/* The deflate compression method (the only one supported in this version) */ - -#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ - -#define zlib_version zlibVersion() -/* for compatibility with versions < 1.0.2 */ - -/* basic functions */ - -ZEXTERN const char *ZEXPORT zlibVersion OF((void)); -/* The application can compare zlibVersion and ZLIB_VERSION for consistency. - If the first character differs, the library code actually used is - not compatible with the zlib.h header file used by the application. - This check is automatically made by deflateInit and inflateInit. - */ - -/* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); - - Initializes the internal stream state for compression. The fields - zalloc, zfree and opaque must be initialized before by the caller. - If zalloc and zfree are set to Z_NULL, deflateInit updates them to - use default allocation functions. - - The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: - 1 gives best speed, 9 gives best compression, 0 gives no compression at - all (the input data is simply copied a block at a time). - Z_DEFAULT_COMPRESSION requests a default compromise between speed and - compression (currently equivalent to level 6). - - deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if level is not a valid compression level, - Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible - with the version assumed by the caller (ZLIB_VERSION). - msg is set to null if there is no error message. deflateInit does not - perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); -/* - deflate compresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce some - output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. deflate performs one or both of the - following actions: - - - Compress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in and avail_in are updated and - processing will resume at this point for the next call of deflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. This action is forced if the parameter flush is non zero. - Forcing flush frequently degrades the compression ratio, so this parameter - should be set only when necessary (in interactive applications). - Some output may be provided even if flush is not set. - - Before the call of deflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming - more output, and updating avail_in or avail_out accordingly; avail_out - should never be zero before the call. The application can consume the - compressed output when it wants, for example when the output buffer is full - (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK - and with zero avail_out, it must be called again after making room in the - output buffer because there might be more output pending. - - If the parameter flush is set to Z_SYNC_FLUSH, all pending output is - flushed to the output buffer and the output is aligned on a byte boundary, so - that the decompressor can get all input data available so far. (In particular - avail_in is zero after the call if enough output space has been provided - before the call.) Flushing may degrade compression for some compression - algorithms and so it should be used only when necessary. - - If flush is set to Z_FULL_FLUSH, all output is flushed as with - Z_SYNC_FLUSH, and the compression state is reset so that decompression can - restart from this point if previous compressed data has been damaged or if - random access is desired. Using Z_FULL_FLUSH too often can seriously degrade - the compression. - - If deflate returns with avail_out == 0, this function must be called again - with the same value of the flush parameter and more output space (updated - avail_out), until the flush is complete (deflate returns with non-zero - avail_out). - - If the parameter flush is set to Z_FINISH, pending input is processed, - pending output is flushed and deflate returns with Z_STREAM_END if there - was enough output space; if deflate returns with Z_OK, this function must be - called again with Z_FINISH and more output space (updated avail_out) but no - more input data, until it returns with Z_STREAM_END or an error. After - deflate has returned Z_STREAM_END, the only possible operations on the - stream are deflateReset or deflateEnd. - - Z_FINISH can be used immediately after deflateInit if all the compression - is to be done in a single step. In this case, avail_out must be at least - 0.1% larger than avail_in plus 12 bytes. If deflate does not return - Z_STREAM_END, then it must be called again as described above. - - deflate() sets strm->adler to the adler32 checksum of all input read - so far (that is, total_in bytes). - - deflate() may update data_type if it can make a good guess about - the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered - binary. This field is only for information purposes and does not affect - the compression algorithm in any manner. - - deflate() returns Z_OK if some progress has been made (more input - processed or more output produced), Z_STREAM_END if all input has been - consumed and all output has been produced (only when flush is set to - Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example - if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible - (for example avail_in or avail_out was zero). -*/ - -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any - pending output. - - deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the - stream state was inconsistent, Z_DATA_ERROR if the stream was freed - prematurely (some input or output was discarded). In the error case, - msg may be set but then points to a static string (which must not be - deallocated). -*/ - -/* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); - - Initializes the internal stream state for decompression. The fields - next_in, avail_in, zalloc, zfree and opaque must be initialized before by - the caller. If next_in is not Z_NULL and avail_in is large enough (the exact - value depends on the compression method), inflateInit determines the - compression method from the zlib header and allocates all data structures - accordingly; otherwise the allocation will be deferred to the first call of - inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to - use default allocation functions. - - inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller. msg is set to null if there is no error - message. inflateInit does not perform any decompression apart from reading - the zlib header if present: this will be done by inflate(). (So next_in and - avail_in may be modified, but next_out and avail_out are unchanged.) -*/ - -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); -/* - inflate decompresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may some - introduce some output latency (reading input without producing any output) - except when forced to flush. - - The detailed semantics are as follows. inflate performs one or both of the - following actions: - - - Decompress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in is updated and processing - will resume at this point for the next call of inflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. inflate() provides as much output as possible, until there - is no more input data or no more space in the output buffer (see below - about the flush parameter). - - Before the call of inflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming - more output, and updating the next_* and avail_* values accordingly. - The application can consume the uncompressed output when it wants, for - example when the output buffer is full (avail_out == 0), or after each - call of inflate(). If inflate returns Z_OK and with zero avail_out, it - must be called again after making room in the output buffer because there - might be more output pending. - - If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much - output as possible to the output buffer. The flushing behavior of inflate is - not specified for values of the flush parameter other than Z_SYNC_FLUSH - and Z_FINISH, but the current implementation actually flushes as much output - as possible anyway. - - inflate() should normally be called until it returns Z_STREAM_END or an - error. However if all decompression is to be performed in a single step - (a single call of inflate), the parameter flush should be set to - Z_FINISH. In this case all pending input is processed and all pending - output is flushed; avail_out must be large enough to hold all the - uncompressed data. (The size of the uncompressed data may have been saved - by the compressor for this purpose.) The next operation on this stream must - be inflateEnd to deallocate the decompression state. The use of Z_FINISH - is never required, but can be used to inform inflate that a faster routine - may be used for the single inflate() call. - - If a preset dictionary is needed at this point (see inflateSetDictionary - below), inflate sets strm-adler to the adler32 checksum of the - dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise - it sets strm->adler to the adler32 checksum of all output produced - so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or - an error code as described below. At the end of the stream, inflate() - checks that its computed adler32 checksum is equal to that saved by the - compressor and returns Z_STREAM_END only if the checksum is correct. - - inflate() returns Z_OK if some progress has been made (more input processed - or more output produced), Z_STREAM_END if the end of the compressed data has - been reached and all uncompressed output has been produced, Z_NEED_DICT if a - preset dictionary is needed at this point, Z_DATA_ERROR if the input data was - corrupted (input stream not conforming to the zlib format or incorrect - adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent - (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if no progress is possible or if there was not - enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR - case, the application may then call inflateSync to look for a good - compression block. -*/ - -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any - pending output. - - inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state - was inconsistent. In the error case, msg may be set but then points to a - static string (which must not be deallocated). -*/ - -/* Advanced functions */ - -/* - The following functions are needed only in some special applications. -*/ - -/* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); - - This is another version of deflateInit with more compression options. The - fields next_in, zalloc, zfree and opaque must be initialized before by - the caller. - - The method parameter is the compression method. It must be Z_DEFLATED in - this version of the library. - - The windowBits parameter is the base two logarithm of the window size - (the size of the history buffer). It should be in the range 8..15 for this - version of the library. Larger values of this parameter result in better - compression at the expense of memory usage. The default value is 15 if - deflateInit is used instead. - - The memLevel parameter specifies how much memory should be allocated - for the internal compression state. memLevel=1 uses minimum memory but - is slow and reduces compression ratio; memLevel=9 uses maximum memory - for optimal speed. The default value is 8. See zconf.h for total memory - usage as a function of windowBits and memLevel. - - The strategy parameter is used to tune the compression algorithm. Use the - value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a - filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no - string match). Filtered data consists mostly of small values with a - somewhat random distribution. In this case, the compression algorithm is - tuned to compress them better. The effect of Z_FILTERED is to force more - Huffman coding and less string matching; it is somewhat intermediate - between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects - the compression ratio but not the correctness of the compressed output even - if it is not set appropriately. - - deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid - method). msg is set to null if there is no error message. deflateInit2 does - not perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, const Bytef *dictionary, uInt dictLength)); -/* - Initializes the compression dictionary from the given byte sequence - without producing any compressed output. This function must be called - immediately after deflateInit, deflateInit2 or deflateReset, before any - call of deflate. The compressor and decompressor must use exactly the same - dictionary (see inflateSetDictionary). - - The dictionary should consist of strings (byte sequences) that are likely - to be encountered later in the data to be compressed, with the most commonly - used strings preferably put towards the end of the dictionary. Using a - dictionary is most useful when the data to be compressed is short and can be - predicted with good accuracy; the data can then be compressed better than - with the default empty dictionary. - - Depending on the size of the compression data structures selected by - deflateInit or deflateInit2, a part of the dictionary may in effect be - discarded, for example if the dictionary is larger than the window size in - deflate or deflate2. Thus the strings most likely to be useful should be - put at the end of the dictionary, not at the front. - - Upon return of this function, strm->adler is set to the Adler32 value - of the dictionary; the decompressor may later use this value to determine - which dictionary has been used by the compressor. (The Adler32 value - applies to the whole dictionary even if only a subset of the dictionary is - actually used by the compressor.) - - deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a - parameter is invalid (such as NULL dictionary) or the stream state is - inconsistent (for example if deflate has already been called for this stream - or if the compression method is bsort). deflateSetDictionary does not - perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when several compression strategies will be - tried, for example when there are several ways of pre-processing the input - data with a filter. The streams that will be discarded should then be freed - by calling deflateEnd. Note that deflateCopy duplicates the internal - compression state which can be quite large, so this strategy is slow and - can consume lots of memory. - - deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); -/* - This function is equivalent to deflateEnd followed by deflateInit, - but does not free and reallocate all the internal compression state. - The stream will keep the same compression level and any other attributes - that may have been set by deflateInit2. - - deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being NULL). -*/ - -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, int level, int strategy)); -/* - Dynamically update the compression level and compression strategy. The - interpretation of level and strategy is as in deflateInit2. This can be - used to switch between compression and straight copy of the input data, or - to switch to a different kind of input data requiring a different - strategy. If the compression level is changed, the input available so far - is compressed with the old level (and may be flushed); the new level will - take effect only at the next call of deflate(). - - Before the call of deflateParams, the stream state must be set as for - a call of deflate(), since the currently available input may have to - be compressed and flushed. In particular, strm->avail_out must be non-zero. - - deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source - stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR - if strm->avail_out was zero. -*/ - -/* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); - - This is another version of inflateInit with an extra parameter. The - fields next_in, avail_in, zalloc, zfree and opaque must be initialized - before by the caller. - - The windowBits parameter is the base two logarithm of the maximum window - size (the size of the history buffer). It should be in the range 8..15 for - this version of the library. The default value is 15 if inflateInit is used - instead. If a compressed stream with a larger window size is given as - input, inflate() will return with the error code Z_DATA_ERROR instead of - trying to allocate a larger window. - - inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative - memLevel). msg is set to null if there is no error message. inflateInit2 - does not perform any decompression apart from reading the zlib header if - present: this will be done by inflate(). (So next_in and avail_in may be - modified, but next_out and avail_out are unchanged.) -*/ - -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, const Bytef *dictionary, uInt dictLength)); -/* - Initializes the decompression dictionary from the given uncompressed byte - sequence. This function must be called immediately after a call of inflate - if this call returned Z_NEED_DICT. The dictionary chosen by the compressor - can be determined from the Adler32 value returned by this call of - inflate. The compressor and decompressor must use exactly the same - dictionary (see deflateSetDictionary). - - inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a - parameter is invalid (such as NULL dictionary) or the stream state is - inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the - expected one (incorrect Adler32 value). inflateSetDictionary does not - perform any decompression: this will be done by subsequent calls of - inflate(). -*/ - -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); -/* - Skips invalid compressed data until a full flush point (see above the - description of deflate with Z_FULL_FLUSH) can be found, or until all - available input is skipped. No output is provided. - - inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR - if no more input was provided, Z_DATA_ERROR if no flush point has been found, - or Z_STREAM_ERROR if the stream structure was inconsistent. In the success - case, the application may save the current current value of total_in which - indicates where valid compressed data was found. In the error case, the - application may repeatedly call inflateSync, providing more input each time, - until success or end of the input data. -*/ - -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); -/* - This function is equivalent to inflateEnd followed by inflateInit, - but does not free and reallocate all the internal decompression state. - The stream will keep attributes that may have been set by inflateInit2. - - inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being NULL). -*/ - -/* utility functions */ - -/* - The following utility functions are implemented on top of the - basic stream-oriented functions. To simplify the interface, some - default options are assumed (compression level and memory usage, - standard memory allocation functions). The source code of these - utility functions can easily be modified if you need special options. -*/ - -ZEXTERN int ZEXPORT compress OF((Bytef * dest, uLongf *destLen, const Bytef *source, uLong sourceLen)); -/* - Compresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be at least 0.1% larger than - sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the - compressed buffer. - This function can be used to compress a whole file at once if the - input file is mmap'ed. - compress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer. -*/ - -ZEXTERN int ZEXPORT compress2 OF((Bytef * dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)); -/* - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least 0.1% larger than sourceLen plus - 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ - -ZEXTERN int ZEXPORT uncompress OF((Bytef * dest, uLongf *destLen, const Bytef *source, uLong sourceLen)); -/* - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be large enough to hold the - entire uncompressed data. (The size of the uncompressed data must have - been saved previously by the compressor and transmitted to the decompressor - by some mechanism outside the scope of this compression library.) - Upon exit, destLen is the actual size of the compressed buffer. - This function can be used to decompress a whole file at once if the - input file is mmap'ed. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted. -*/ - -typedef voidp gzFile; - -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); -/* - Opens a gzip (.gz) file for reading or writing. The mode parameter - is as in fopen ("rb" or "wb") but can also include a compression level - ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for - Huffman only compression as in "wb1h". (See the description - of deflateInit2 for more information about the strategy parameter.) - - gzopen can be used to read a file which is not in gzip format; in this - case gzread will directly read from the file without decompression. - - gzopen returns NULL if the file could not be opened or if there was - insufficient memory to allocate the (de)compression state; errno - can be checked to distinguish the two cases (if errno is zero, the - zlib error is Z_MEM_ERROR). */ - -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); -/* - gzdopen() associates a gzFile with the file descriptor fd. File - descriptors are obtained from calls like open, dup, creat, pipe or - fileno (in the file has been previously opened with fopen). - The mode parameter is as in gzopen. - The next call of gzclose on the returned gzFile will also close the - file descriptor fd, just like fclose(fdopen(fd), mode) closes the file - descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). - gzdopen returns NULL if there was insufficient memory to allocate - the (de)compression state. -*/ - -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); -/* - Dynamically update the compression level or strategy. See the description - of deflateInit2 for the meaning of these parameters. - gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not - opened for writing. -*/ - -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); -/* - Reads the given number of uncompressed bytes from the compressed file. - If the input file was not in gzip format, gzread copies the given number - of bytes into the buffer. - gzread returns the number of uncompressed bytes actually read (0 for - end of file, -1 for error). */ - -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len)); -/* - Writes the given number of uncompressed bytes into the compressed file. - gzwrite returns the number of uncompressed bytes actually written - (0 in case of error). -*/ - -ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); -/* - Converts, formats, and writes the args to the compressed file under - control of the format string, as in fprintf. gzprintf returns the number of - uncompressed bytes actually written (0 in case of error). -*/ - -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); -/* - Writes the given null-terminated string to the compressed file, excluding - the terminating null character. - gzputs returns the number of characters written, or -1 in case of error. -*/ - -ZEXTERN char *ZEXPORT gzgets OF((gzFile file, char *buf, int len)); -/* - Reads bytes from the compressed file until len-1 characters are read, or - a newline character is read and transferred to buf, or an end-of-file - condition is encountered. The string is then terminated with a null - character. - gzgets returns buf, or Z_NULL in case of error. -*/ - -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); -/* - Writes c, converted to an unsigned char, into the compressed file. - gzputc returns the value that was written, or -1 in case of error. -*/ - -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); -/* - Reads one byte from the compressed file. gzgetc returns this byte - or -1 in case of end of file or error. -*/ - -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); -/* - Flushes all pending output into the compressed file. The parameter - flush is as in the deflate() function. The return value is the zlib - error number (see function gzerror below). gzflush returns Z_OK if - the flush parameter is Z_FINISH and all output could be flushed. - gzflush should be called only when strictly necessary because it can - degrade compression. -*/ - -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, z_off_t offset, int whence)); -/* - Sets the starting position for the next gzread or gzwrite on the - given compressed file. The offset represents a number of bytes in the - uncompressed data stream. The whence parameter is defined as in lseek(2); - the value SEEK_END is not supported. - If the file is opened for reading, this function is emulated but can be - extremely slow. If the file is opened for writing, only forward seeks are - supported; gzseek then compresses a sequence of zeroes up to the new - starting position. - - gzseek returns the resulting offset location as measured in bytes from - the beginning of the uncompressed stream, or -1 in case of error, in - particular if the file is opened for writing and the new starting position - would be before the current position. -*/ - -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); -/* - Rewinds the given file. This function is supported only for reading. - - gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) -*/ - -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); -/* - Returns the starting position for the next gzread or gzwrite on the - given compressed file. This position represents a number of bytes in the - uncompressed data stream. - - gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) -*/ - -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); -/* - Returns 1 when EOF has previously been detected reading the given - input stream, otherwise zero. -*/ - -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); -/* - Flushes all pending output if necessary, closes the compressed file - and deallocates all the (de)compression state. The return value is the zlib - error number (see function gzerror below). -*/ - -ZEXTERN const char *ZEXPORT gzerror OF((gzFile file, int *errnum)); -/* - Returns the error message for the last error which occurred on the - given compressed file. errnum is set to zlib error number. If an - error occurred in the file system and not in the compression library, - errnum is set to Z_ERRNO and the application may consult errno - to get the exact error code. -*/ - -/* checksum functions */ - -/* - These functions are not related to compression but are exported - anyway because they might be useful in applications using the - compression library. -*/ - -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); - -/* - Update a running Adler-32 checksum with the bytes buf[0..len-1] and - return the updated checksum. If buf is NULL, this function returns - the required initial value for the checksum. - An Adler-32 checksum is almost as reliable as a CRC32 but can be computed - much faster. Usage example: - - uLong adler = adler32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - adler = adler32(adler, buffer, length); - } - if (adler != original_adler) error(); -*/ - -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); -/* - Update a running crc with the bytes buf[0..len-1] and return the updated - crc. If buf is NULL, this function returns the required initial value - for the crc. Pre- and post-conditioning (one's complement) is performed - within this function so it shouldn't be done by the application. - Usage example: - - uLong crc = crc32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - crc = crc32(crc, buffer, length); - } - if (crc != original_crc) error(); -*/ - -/* various hacks, don't look :) */ - -/* deflateInit and inflateInit are macros to allow checking the zlib version - * and the compiler's view of z_stream: - */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, const char *version, int stream_size)); -#define deflateInit(strm, level) deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) -#define inflateInit(strm) inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) -#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm), (level), (method), (windowBits), (memLevel), (strategy), ZLIB_VERSION, sizeof(z_stream)) -#define inflateInit2(strm, windowBits) inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) - -#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) -struct internal_state { - int dummy; -}; /* hack for buggy compilers */ -#endif - -ZEXTERN const char *ZEXPORT zError OF((int err)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); -ZEXTERN const uLongf *ZEXPORT get_crc_table OF((void)); - -#ifdef __cplusplus -} -#endif - -#endif /* _ZLIB_H */ diff --git a/unzip/zutil.h b/unzip/zutil.h deleted file mode 100644 index 29a55205..00000000 --- a/unzip/zutil.h +++ /dev/null @@ -1,276 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -/* - * $Logfile: /DescentIII/Main/unzip/zutil.h $ - * $Revision: 2 $ - * $Date: 8/13/99 8:02p $ - * $Author: Jeff $ - * - * - * - * $Log: /DescentIII/Main/unzip/zutil.h $ - * - * 2 8/13/99 8:02p Jeff - * initial creation of zip class - * - * $NoKeywords: $ - */ - -/* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-1998 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id$ */ - -#ifndef _Z_UTIL_H -#define _Z_UTIL_H - -#include "zlib.h" - -#ifdef STDC -#include -#include -#include -#endif -#ifdef NO_ERRNO_H -extern int errno; -#else -#include -#endif - -#ifndef local -#define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -typedef unsigned char uch; -typedef uch FAR uchf; -typedef unsigned short ush; -typedef ush FAR ushf; -typedef unsigned long ulg; - -extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ -/* (size given to avoid silly warnings with Visual C++) */ - -#define ERR_MSG(err) z_errmsg[Z_NEED_DICT - (err)] - -#define ERR_RETURN(strm, err) return (strm->msg = (char *)ERR_MSG(err), (err)) -/* To be used only when the state is known to be valid */ - -/* common constants */ - -#ifndef DEF_WBITS -#define DEF_WBITS MAX_WBITS -#endif -/* default windowBits for decompression. MAX_WBITS is for compression only */ - -#if MAX_MEM_LEVEL >= 8 -#define DEF_MEM_LEVEL 8 -#else -#define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif -/* default memLevel */ - -#define STORED_BLOCK 0 -#define STATIC_TREES 1 -#define DYN_TREES 2 -/* The three kinds of block type */ - -#define MIN_MATCH 3 -#define MAX_MATCH 258 -/* The minimum and maximum match lengths */ - -#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ - -/* target dependencies */ - -#ifdef MSDOS -#define OS_CODE 0x00 -#if defined(__TURBOC__) || defined(__BORLANDC__) -#if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) -/* Allow compilation with ANSI keywords only enabled */ -void _Cdecl farfree(void *block); -void *_Cdecl farmalloc(unsigned long nbytes); -#else -#include -#endif -#else /* MSC or DJGPP */ -#include -#endif -#endif - -#ifdef OS2 -#define OS_CODE 0x06 -#endif - -#ifdef WIN32 /* Window 95 & Windows NT */ -#define OS_CODE 0x0b -#endif - -#if defined(VAXC) || defined(VMS) -#define OS_CODE 0x02 -#define F_OPEN(name, mode) fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") -#endif - -#ifdef AMIGA -#define OS_CODE 0x01 -#endif - -#if defined(ATARI) || defined(atarist) -#define OS_CODE 0x05 -#endif - -#if defined(MACOS) || defined(TARGET_OS_MAC) -#define OS_CODE 0x07 -#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -#include /* for fdopen */ -#else -#ifndef fdopen -#define fdopen(fd, mode) NULL /* No fdopen() */ -#endif -#endif -#endif - -#ifdef __50SERIES /* Prime/PRIMOS */ -#define OS_CODE 0x0F -#endif - -#ifdef TOPS20 -#define OS_CODE 0x0a -#endif - -#if defined(_BEOS_) || defined(RISCOS) -#define fdopen(fd, mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) -#define fdopen(fd, type) _fdopen(fd, type) -#endif - -/* Common defaults */ - -#ifndef OS_CODE -#define OS_CODE 0x03 /* assume Unix */ -#endif - -#ifndef F_OPEN -#define F_OPEN(name, mode) fopen((name), (mode)) -#endif - -/* functions */ - -#ifdef HAVE_STRERROR -extern char *strerror OF((int)); -#define zstrerror(errnum) strerror(errnum) -#else -#define zstrerror(errnum) "" -#endif - -#if defined(pyr) -#define NO_MEMCPY -#endif -#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) -/* Use our own functions for small and medium model with MSC <= 5.0. - * You may have to use the same strategy for Borland C (untested). - * The __SC__ check is for Symantec. - */ -#define NO_MEMCPY -#endif -#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) -#define HAVE_MEMCPY -#endif -#ifdef HAVE_MEMCPY -#ifdef SMALL_MEDIUM /* MSDOS small or medium model */ -#define zmemcpy _fmemcpy -#define zmemcmp _fmemcmp -#define zmemzero(dest, len) _fmemset(dest, 0, len) -#else -#define zmemcpy memcpy -#define zmemcmp memcmp -#define zmemzero(dest, len) memset(dest, 0, len) -#endif -#else -extern void zmemcpy OF((Bytef * dest, const Bytef *source, uInt len)); -extern int zmemcmp OF((const Bytef *s1, const Bytef *s2, uInt len)); -extern void zmemzero OF((Bytef * dest, uInt len)); -#endif - -/* Diagnostic functions */ -#ifdef DEBUG -#include -extern int z_verbose; -extern void z_error OF((char *m)); -#define Assert(cond, msg) \ - { \ - if (!(cond)) \ - z_error(msg); \ - } -#define Trace(x) \ - { \ - if (z_verbose >= 0) \ - fprintf x; \ - } -#define Tracev(x) \ - { \ - if (z_verbose > 0) \ - fprintf x; \ - } -#define Tracevv(x) \ - { \ - if (z_verbose > 1) \ - fprintf x; \ - } -#define Tracec(c, x) \ - { \ - if (z_verbose > 0 && (c)) \ - fprintf x; \ - } -#define Tracecv(c, x) \ - { \ - if (z_verbose > 1 && (c)) \ - fprintf x; \ - } -#else -#define Assert(cond, msg) -#define Trace(x) -#define Tracev(x) -#define Tracevv(x) -#define Tracec(c, x) -#define Tracecv(c, x) -#endif - -typedef uLong(ZEXPORT *check_func) OF((uLong check, const Bytef *buf, uInt len)); -voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); -void zcfree OF((voidpf opaque, voidpf ptr)); - -#define ZALLOC(strm, items, size) (*((strm)->zalloc))((strm)->opaque, (items), (size)) -#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) -#define TRY_FREE(s, p) \ - { \ - if (p) \ - ZFREE(s, p); \ - } - -#endif /* _Z_UTIL_H */ diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 00000000..d7705cf2 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,6 @@ +{ + "builtin-baseline": "000d1bda1ffa95a73e0b40334fa4103d6f4d3d48", + "dependencies": [ + "zlib" + ] +}