mirror of https://github.com/stella-emu/stella.git
Some NULL/nullptr and formatting cleanups in src/common.
Renamed mainSDL.c to main.c, since it is no longer dependent on SDL, and I'm trying to encapsulate SDL-specific code into as few places as possible. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3047 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
08649b2069
commit
a165c48fab
|
@ -202,7 +202,7 @@ void EventHandlerSDL2::pollEvent()
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
EventHandlerSDL2::JoystickSDL2::JoystickSDL2(int idx)
|
EventHandlerSDL2::JoystickSDL2::JoystickSDL2(int idx)
|
||||||
: myStick(NULL)
|
: myStick(nullptr)
|
||||||
{
|
{
|
||||||
myStick = SDL_JoystickOpen(idx);
|
myStick = SDL_JoystickOpen(idx);
|
||||||
if(myStick)
|
if(myStick)
|
||||||
|
@ -218,5 +218,5 @@ EventHandlerSDL2::JoystickSDL2::~JoystickSDL2()
|
||||||
{
|
{
|
||||||
if(myStick)
|
if(myStick)
|
||||||
SDL_JoystickClose(myStick);
|
SDL_JoystickClose(myStick);
|
||||||
myStick = NULL;
|
myStick = nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,15 +23,15 @@
|
||||||
FBSurfaceSDL2::FBSurfaceSDL2(FrameBufferSDL2& buffer,
|
FBSurfaceSDL2::FBSurfaceSDL2(FrameBufferSDL2& buffer,
|
||||||
uInt32 width, uInt32 height, const uInt32* data)
|
uInt32 width, uInt32 height, const uInt32* data)
|
||||||
: myFB(buffer),
|
: myFB(buffer),
|
||||||
mySurface(NULL),
|
mySurface(nullptr),
|
||||||
myTexture(NULL),
|
myTexture(nullptr),
|
||||||
mySurfaceIsDirty(true),
|
mySurfaceIsDirty(true),
|
||||||
myIsVisible(true),
|
myIsVisible(true),
|
||||||
myTexAccess(SDL_TEXTUREACCESS_STREAMING),
|
myTexAccess(SDL_TEXTUREACCESS_STREAMING),
|
||||||
myInterpolate(false),
|
myInterpolate(false),
|
||||||
myBlendEnabled(false),
|
myBlendEnabled(false),
|
||||||
myBlendAlpha(255),
|
myBlendAlpha(255),
|
||||||
myStaticData(NULL)
|
myStaticData(nullptr)
|
||||||
{
|
{
|
||||||
createSurface(width, height, data);
|
createSurface(width, height, data);
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ FBSurfaceSDL2::~FBSurfaceSDL2()
|
||||||
if(myStaticData)
|
if(myStaticData)
|
||||||
{
|
{
|
||||||
delete[] myStaticData;
|
delete[] myStaticData;
|
||||||
myStaticData = NULL;
|
myStaticData = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ bool FBSurfaceSDL2::render()
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void FBSurfaceSDL2::invalidate()
|
void FBSurfaceSDL2::invalidate()
|
||||||
{
|
{
|
||||||
SDL_FillRect(mySurface, NULL, 0);
|
SDL_FillRect(mySurface, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -161,7 +161,7 @@ void FBSurfaceSDL2::free()
|
||||||
if(myTexture)
|
if(myTexture)
|
||||||
{
|
{
|
||||||
SDL_DestroyTexture(myTexture);
|
SDL_DestroyTexture(myTexture);
|
||||||
myTexture = NULL;
|
myTexture = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ void FBSurfaceSDL2::reload()
|
||||||
|
|
||||||
// If the data is static, we only upload it once
|
// If the data is static, we only upload it once
|
||||||
if(myTexAccess == SDL_TEXTUREACCESS_STATIC)
|
if(myTexAccess == SDL_TEXTUREACCESS_STATIC)
|
||||||
SDL_UpdateTexture(myTexture, NULL, myStaticData, myStaticPitch);
|
SDL_UpdateTexture(myTexture, nullptr, myStaticData, myStaticPitch);
|
||||||
|
|
||||||
// Blending enabled?
|
// Blending enabled?
|
||||||
if(myBlendEnabled)
|
if(myBlendEnabled)
|
||||||
|
@ -197,7 +197,7 @@ void FBSurfaceSDL2::resize(uInt32 width, uInt32 height)
|
||||||
SDL_FreeSurface(mySurface);
|
SDL_FreeSurface(mySurface);
|
||||||
free();
|
free();
|
||||||
|
|
||||||
createSurface(width, height, NULL);
|
createSurface(width, height, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -36,8 +36,8 @@
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
FrameBufferSDL2::FrameBufferSDL2(OSystem& osystem)
|
FrameBufferSDL2::FrameBufferSDL2(OSystem& osystem)
|
||||||
: FrameBuffer(osystem),
|
: FrameBuffer(osystem),
|
||||||
myWindow(NULL),
|
myWindow(nullptr),
|
||||||
myRenderer(NULL),
|
myRenderer(nullptr),
|
||||||
myDirtyFlag(true),
|
myDirtyFlag(true),
|
||||||
myDblBufferedFlag(true)
|
myDblBufferedFlag(true)
|
||||||
{
|
{
|
||||||
|
@ -66,14 +66,14 @@ FrameBufferSDL2::~FrameBufferSDL2()
|
||||||
if(myRenderer)
|
if(myRenderer)
|
||||||
{
|
{
|
||||||
SDL_DestroyRenderer(myRenderer);
|
SDL_DestroyRenderer(myRenderer);
|
||||||
myRenderer = NULL;
|
myRenderer = nullptr;
|
||||||
}
|
}
|
||||||
if(myWindow)
|
if(myWindow)
|
||||||
{
|
{
|
||||||
SDL_SetWindowFullscreen(myWindow, 0); // on some systems, a crash occurs
|
SDL_SetWindowFullscreen(myWindow, 0); // on some systems, a crash occurs
|
||||||
// when destroying fullscreen window
|
// when destroying fullscreen window
|
||||||
SDL_DestroyWindow(myWindow);
|
SDL_DestroyWindow(myWindow);
|
||||||
myWindow = NULL;
|
myWindow = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode,
|
||||||
SDL_RenderPresent(myRenderer);
|
SDL_RenderPresent(myRenderer);
|
||||||
SDL_RenderClear(myRenderer);
|
SDL_RenderClear(myRenderer);
|
||||||
SDL_DestroyRenderer(myRenderer);
|
SDL_DestroyRenderer(myRenderer);
|
||||||
myRenderer = NULL;
|
myRenderer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int32 displayIndex = mode.fsIndex;
|
Int32 displayIndex = mode.fsIndex;
|
||||||
|
@ -162,7 +162,7 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode,
|
||||||
if((uInt32)w != mode.screen.w || (uInt32)h != mode.screen.h)
|
if((uInt32)w != mode.screen.w || (uInt32)h != mode.screen.h)
|
||||||
{
|
{
|
||||||
SDL_DestroyWindow(myWindow);
|
SDL_DestroyWindow(myWindow);
|
||||||
myWindow = NULL;
|
myWindow = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(myWindow)
|
if(myWindow)
|
||||||
|
@ -186,7 +186,7 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode,
|
||||||
{
|
{
|
||||||
myWindow = SDL_CreateWindow(title.c_str(), pos, pos,
|
myWindow = SDL_CreateWindow(title.c_str(), pos, pos,
|
||||||
mode.screen.w, mode.screen.h, flags);
|
mode.screen.w, mode.screen.h, flags);
|
||||||
if(myWindow == NULL)
|
if(myWindow == nullptr)
|
||||||
{
|
{
|
||||||
string msg = "ERROR: Unable to open SDL window: " + string(SDL_GetError());
|
string msg = "ERROR: Unable to open SDL window: " + string(SDL_GetError());
|
||||||
myOSystem.logMessage(msg, 0);
|
myOSystem.logMessage(msg, 0);
|
||||||
|
@ -202,7 +202,7 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode,
|
||||||
if(video != "")
|
if(video != "")
|
||||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, video.c_str());
|
SDL_SetHint(SDL_HINT_RENDER_DRIVER, video.c_str());
|
||||||
myRenderer = SDL_CreateRenderer(myWindow, -1, renderFlags);
|
myRenderer = SDL_CreateRenderer(myWindow, -1, renderFlags);
|
||||||
if(myRenderer == NULL)
|
if(myRenderer == nullptr)
|
||||||
{
|
{
|
||||||
string msg = "ERROR: Unable to create SDL renderer: " + string(SDL_GetError());
|
string msg = "ERROR: Unable to create SDL renderer: " + string(SDL_GetError());
|
||||||
myOSystem.logMessage(msg, 0);
|
myOSystem.logMessage(msg, 0);
|
||||||
|
|
|
@ -162,8 +162,8 @@ MouseControl::MouseControl(Console& console, const string& mode)
|
||||||
myModeList.push_back(MouseMode("Mouse not used for current controllers"));
|
myModeList.push_back(MouseMode("Mouse not used for current controllers"));
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
for(unsigned int i = 0; i < myModeList.size(); ++i)
|
for(MouseMode m: myModeList)
|
||||||
cerr << myModeList[i] << endl;
|
cerr << mode << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,25 +46,25 @@ void PNGLibrary::loadImage(const string& filename, FBSurface& surface)
|
||||||
{
|
{
|
||||||
#define loadImageERROR(s) { err_message = s; goto done; }
|
#define loadImageERROR(s) { err_message = s; goto done; }
|
||||||
|
|
||||||
png_structp png_ptr = NULL;
|
png_structp png_ptr = nullptr;
|
||||||
png_infop info_ptr = NULL;
|
png_infop info_ptr = nullptr;
|
||||||
png_uint_32 iwidth, iheight;
|
png_uint_32 iwidth, iheight;
|
||||||
int bit_depth, color_type, interlace_type;
|
int bit_depth, color_type, interlace_type;
|
||||||
const char* err_message = NULL;
|
const char* err_message = nullptr;
|
||||||
|
|
||||||
ifstream in(filename.c_str(), ios_base::binary);
|
ifstream in(filename.c_str(), ios_base::binary);
|
||||||
if(!in.is_open())
|
if(!in.is_open())
|
||||||
loadImageERROR("No image found");
|
loadImageERROR("No image found");
|
||||||
|
|
||||||
// Create the PNG loading context structure
|
// Create the PNG loading context structure
|
||||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
|
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr,
|
||||||
png_user_error, png_user_warn);
|
png_user_error, png_user_warn);
|
||||||
if(png_ptr == NULL)
|
if(png_ptr == nullptr)
|
||||||
loadImageERROR("Couldn't allocate memory for PNG file");
|
loadImageERROR("Couldn't allocate memory for PNG file");
|
||||||
|
|
||||||
// Allocate/initialize the memory for image information. REQUIRED.
|
// Allocate/initialize the memory for image information. REQUIRED.
|
||||||
info_ptr = png_create_info_struct(png_ptr);
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
if(info_ptr == NULL)
|
if(info_ptr == nullptr)
|
||||||
loadImageERROR("Couldn't create image information for PNG file");
|
loadImageERROR("Couldn't create image information for PNG file");
|
||||||
|
|
||||||
// Set up the input control
|
// Set up the input control
|
||||||
|
@ -73,7 +73,7 @@ void PNGLibrary::loadImage(const string& filename, FBSurface& surface)
|
||||||
// Read PNG header info
|
// Read PNG header info
|
||||||
png_read_info(png_ptr, info_ptr);
|
png_read_info(png_ptr, info_ptr);
|
||||||
png_get_IHDR(png_ptr, info_ptr, &iwidth, &iheight, &bit_depth,
|
png_get_IHDR(png_ptr, info_ptr, &iwidth, &iheight, &bit_depth,
|
||||||
&color_type, &interlace_type, NULL, NULL);
|
&color_type, &interlace_type, nullptr, nullptr);
|
||||||
|
|
||||||
// Tell libpng to strip 16 bit/color files down to 8 bits/color
|
// Tell libpng to strip 16 bit/color files down to 8 bits/color
|
||||||
png_set_strip_16(png_ptr);
|
png_set_strip_16(png_ptr);
|
||||||
|
@ -184,19 +184,19 @@ void PNGLibrary::saveImage(ofstream& out, png_bytep& buffer, png_bytep*& rows,
|
||||||
{
|
{
|
||||||
#define saveImageERROR(s) { err_message = s; goto done; }
|
#define saveImageERROR(s) { err_message = s; goto done; }
|
||||||
|
|
||||||
png_structp png_ptr = NULL;
|
png_structp png_ptr = nullptr;
|
||||||
png_infop info_ptr = NULL;
|
png_infop info_ptr = nullptr;
|
||||||
const char* err_message = NULL;
|
const char* err_message = nullptr;
|
||||||
|
|
||||||
// Create the PNG saving context structure
|
// Create the PNG saving context structure
|
||||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
|
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr,
|
||||||
png_user_error, png_user_warn);
|
png_user_error, png_user_warn);
|
||||||
if(png_ptr == NULL)
|
if(png_ptr == nullptr)
|
||||||
saveImageERROR("Couldn't allocate memory for PNG file");
|
saveImageERROR("Couldn't allocate memory for PNG file");
|
||||||
|
|
||||||
// Allocate/initialize the memory for image information. REQUIRED.
|
// Allocate/initialize the memory for image information. REQUIRED.
|
||||||
info_ptr = png_create_info_struct(png_ptr);
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
if(info_ptr == NULL)
|
if(info_ptr == nullptr)
|
||||||
saveImageERROR("Couldn't create image information for PNG file");
|
saveImageERROR("Couldn't create image information for PNG file");
|
||||||
|
|
||||||
// Set up the output control
|
// Set up the output control
|
||||||
|
@ -252,7 +252,7 @@ bool PNGLibrary::allocateStorage(png_uint_32 w, png_uint_32 h)
|
||||||
{
|
{
|
||||||
delete[] ReadInfo.buffer;
|
delete[] ReadInfo.buffer;
|
||||||
ReadInfo.buffer = new uInt8[req_buffer_size];
|
ReadInfo.buffer = new uInt8[req_buffer_size];
|
||||||
if(ReadInfo.buffer == NULL)
|
if(ReadInfo.buffer == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ReadInfo.buffer_size = req_buffer_size;
|
ReadInfo.buffer_size = req_buffer_size;
|
||||||
|
@ -262,7 +262,7 @@ bool PNGLibrary::allocateStorage(png_uint_32 w, png_uint_32 h)
|
||||||
{
|
{
|
||||||
delete[] ReadInfo.row_pointers;
|
delete[] ReadInfo.row_pointers;
|
||||||
ReadInfo.row_pointers = new png_bytep[req_row_size];
|
ReadInfo.row_pointers = new png_bytep[req_row_size];
|
||||||
if(ReadInfo.row_pointers == NULL)
|
if(ReadInfo.row_pointers == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ReadInfo.row_size = req_row_size;
|
ReadInfo.row_size = req_row_size;
|
||||||
|
@ -360,5 +360,5 @@ void PNGLibrary::png_user_error(png_structp ctx, png_const_charp str)
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
PNGLibrary::ReadInfoType PNGLibrary::ReadInfo = {
|
PNGLibrary::ReadInfoType PNGLibrary::ReadInfo = {
|
||||||
NULL, NULL, 0, 0, 0, 0, 0
|
nullptr, nullptr, 0, 0, 0, 0, 0
|
||||||
};
|
};
|
||||||
|
|
|
@ -91,12 +91,12 @@ class PNGLibrary
|
||||||
|
|
||||||
// The following data remains between invocations of allocateStorage,
|
// The following data remains between invocations of allocateStorage,
|
||||||
// and is only changed when absolutely necessary.
|
// and is only changed when absolutely necessary.
|
||||||
typedef struct {
|
struct ReadInfoType {
|
||||||
uInt8* buffer;
|
uInt8* buffer;
|
||||||
png_bytep* row_pointers;
|
png_bytep* row_pointers;
|
||||||
png_uint_32 width, height, pitch;
|
png_uint_32 width, height, pitch;
|
||||||
uInt32 buffer_size, row_size;
|
uInt32 buffer_size, row_size;
|
||||||
} ReadInfoType;
|
};
|
||||||
static ReadInfoType ReadInfo;
|
static ReadInfoType ReadInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
class StringList : public Common::Array<string>
|
class StringList : public Common::Array<string>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void push_back(const char *str)
|
void push_back(const char* str)
|
||||||
{
|
{
|
||||||
ensureCapacity(_size + 1);
|
ensureCapacity(_size + 1);
|
||||||
_data[_size++] = str;
|
_data[_size++] = str;
|
||||||
|
|
|
@ -79,7 +79,7 @@ class Variant
|
||||||
static const Variant EmptyVariant("");
|
static const Variant EmptyVariant("");
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
class VariantList : public Common::Array< pair<string,Variant> >
|
class VariantList : public Common::Array<pair<string,Variant>>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VariantList() { }
|
VariantList() { }
|
||||||
|
|
|
@ -25,10 +25,10 @@
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
ZipHandler::ZipHandler()
|
ZipHandler::ZipHandler()
|
||||||
: myZip(NULL)
|
: myZip(nullptr)
|
||||||
{
|
{
|
||||||
for (int cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
for(int cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
||||||
myZipCache[cachenum] = NULL;
|
myZipCache[cachenum] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -70,7 +70,7 @@ string ZipHandler::next()
|
||||||
if(myZip)
|
if(myZip)
|
||||||
{
|
{
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
const zip_file_header* header = NULL;
|
const zip_file_header* header = nullptr;
|
||||||
do {
|
do {
|
||||||
header = zip_file_next_file(myZip);
|
header = zip_file_next_file(myZip);
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ uInt32 ZipHandler::decompress(uInt8*& image)
|
||||||
return length;
|
return length;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete[] image; image = NULL;
|
delete[] image; image = nullptr;
|
||||||
|
|
||||||
throw zip_error_s[err];
|
throw zip_error_s[err];
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ bool ZipHandler::stream_open(const char* filename, fstream** stream,
|
||||||
fstream* in = new fstream(filename, fstream::in | fstream::binary);
|
fstream* in = new fstream(filename, fstream::in | fstream::binary);
|
||||||
if(!in || !in->is_open())
|
if(!in || !in->is_open())
|
||||||
{
|
{
|
||||||
*stream = NULL;
|
*stream = nullptr;
|
||||||
length = 0;
|
length = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ void ZipHandler::stream_close(fstream** stream)
|
||||||
if((*stream)->is_open())
|
if((*stream)->is_open())
|
||||||
(*stream)->close();
|
(*stream)->close();
|
||||||
delete *stream;
|
delete *stream;
|
||||||
*stream = NULL;
|
*stream = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,27 +193,27 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char *filename, zip_file *
|
||||||
bool success;
|
bool success;
|
||||||
|
|
||||||
/* ensure we start with a NULL result */
|
/* ensure we start with a NULL result */
|
||||||
*zip = NULL;
|
*zip = nullptr;
|
||||||
|
|
||||||
/* see if we are in the cache, and reopen if so */
|
/* see if we are in the cache, and reopen if so */
|
||||||
for (cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
for(cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
||||||
{
|
{
|
||||||
zip_file *cached = myZipCache[cachenum];
|
zip_file *cached = myZipCache[cachenum];
|
||||||
|
|
||||||
/* if we have a valid entry and it matches our filename, use it and remove
|
/* if we have a valid entry and it matches our filename, use it and remove
|
||||||
from the cache */
|
from the cache */
|
||||||
if (cached != NULL && cached->filename != NULL &&
|
if(cached != nullptr && cached->filename != nullptr &&
|
||||||
strcmp(filename, cached->filename) == 0)
|
strcmp(filename, cached->filename) == 0)
|
||||||
{
|
{
|
||||||
*zip = cached;
|
*zip = cached;
|
||||||
myZipCache[cachenum] = NULL;
|
myZipCache[cachenum] = nullptr;
|
||||||
return ZIPERR_NONE;
|
return ZIPERR_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate memory for the zip_file structure */
|
/* allocate memory for the zip_file structure */
|
||||||
newzip = (zip_file *)malloc(sizeof(*newzip));
|
newzip = (zip_file *)malloc(sizeof(*newzip));
|
||||||
if (newzip == NULL)
|
if (newzip == nullptr)
|
||||||
return ZIPERR_OUT_OF_MEMORY;
|
return ZIPERR_OUT_OF_MEMORY;
|
||||||
memset(newzip, 0, sizeof(*newzip));
|
memset(newzip, 0, sizeof(*newzip));
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char *filename, zip_file *
|
||||||
|
|
||||||
/* read ecd data */
|
/* read ecd data */
|
||||||
ziperr = read_ecd(newzip);
|
ziperr = read_ecd(newzip);
|
||||||
if (ziperr != ZIPERR_NONE)
|
if(ziperr != ZIPERR_NONE)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* verify that we can work with this zipfile (no disk spanning allowed) */
|
/* verify that we can work with this zipfile (no disk spanning allowed) */
|
||||||
|
@ -239,7 +239,7 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char *filename, zip_file *
|
||||||
|
|
||||||
/* allocate memory for the central directory */
|
/* allocate memory for the central directory */
|
||||||
newzip->cd = (uInt8 *)malloc(newzip->ecd.cd_size + 1);
|
newzip->cd = (uInt8 *)malloc(newzip->ecd.cd_size + 1);
|
||||||
if (newzip->cd == NULL)
|
if(newzip->cd == nullptr)
|
||||||
{
|
{
|
||||||
ziperr = ZIPERR_OUT_OF_MEMORY;
|
ziperr = ZIPERR_OUT_OF_MEMORY;
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -248,7 +248,7 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char *filename, zip_file *
|
||||||
/* read the central directory */
|
/* read the central directory */
|
||||||
success = stream_read(newzip->file, newzip->cd, newzip->ecd.cd_start_disk_offset,
|
success = stream_read(newzip->file, newzip->cd, newzip->ecd.cd_start_disk_offset,
|
||||||
newzip->ecd.cd_size, read_length);
|
newzip->ecd.cd_size, read_length);
|
||||||
if (!success || read_length != newzip->ecd.cd_size)
|
if(!success || read_length != newzip->ecd.cd_size)
|
||||||
{
|
{
|
||||||
ziperr = success ? ZIPERR_FILE_TRUNCATED : ZIPERR_FILE_ERROR;
|
ziperr = success ? ZIPERR_FILE_TRUNCATED : ZIPERR_FILE_ERROR;
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -256,7 +256,7 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char *filename, zip_file *
|
||||||
|
|
||||||
/* make a copy of the filename for caching purposes */
|
/* make a copy of the filename for caching purposes */
|
||||||
string = (char *)malloc(strlen(filename) + 1);
|
string = (char *)malloc(strlen(filename) + 1);
|
||||||
if (string == NULL)
|
if (string == nullptr)
|
||||||
{
|
{
|
||||||
ziperr = ZIPERR_OUT_OF_MEMORY;
|
ziperr = ZIPERR_OUT_OF_MEMORY;
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -293,20 +293,20 @@ void ZipHandler::zip_file_close(zip_file *zip)
|
||||||
int cachenum;
|
int cachenum;
|
||||||
|
|
||||||
/* close the open files */
|
/* close the open files */
|
||||||
if (zip->file)
|
if(zip->file)
|
||||||
stream_close(&zip->file);
|
stream_close(&zip->file);
|
||||||
|
|
||||||
/* find the first NULL entry in the cache */
|
/* find the first NULL entry in the cache */
|
||||||
for (cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
for(cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
||||||
if (myZipCache[cachenum] == NULL)
|
if (myZipCache[cachenum] == nullptr)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* if no room left in the cache, free the bottommost entry */
|
/* if no room left in the cache, free the bottommost entry */
|
||||||
if (cachenum == ZIP_CACHE_SIZE)
|
if(cachenum == ZIP_CACHE_SIZE)
|
||||||
free_zip_file(myZipCache[--cachenum]);
|
free_zip_file(myZipCache[--cachenum]);
|
||||||
|
|
||||||
/* move everyone else down and place us at the top */
|
/* move everyone else down and place us at the top */
|
||||||
if (cachenum != 0)
|
if(cachenum != 0)
|
||||||
memmove(&myZipCache[1], &myZipCache[0], cachenum * sizeof(myZipCache[0]));
|
memmove(&myZipCache[1], &myZipCache[0], cachenum * sizeof(myZipCache[0]));
|
||||||
myZipCache[0] = zip;
|
myZipCache[0] = zip;
|
||||||
}
|
}
|
||||||
|
@ -319,11 +319,11 @@ void ZipHandler::zip_file_close(zip_file *zip)
|
||||||
void ZipHandler::zip_file_cache_clear(void)
|
void ZipHandler::zip_file_cache_clear(void)
|
||||||
{
|
{
|
||||||
/* clear call cache entries */
|
/* clear call cache entries */
|
||||||
for (int cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
for(int cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
||||||
if (myZipCache[cachenum] != NULL)
|
if(myZipCache[cachenum] != nullptr)
|
||||||
{
|
{
|
||||||
free_zip_file(myZipCache[cachenum]);
|
free_zip_file(myZipCache[cachenum]);
|
||||||
myZipCache[cachenum] = NULL;
|
myZipCache[cachenum] = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,15 +339,15 @@ void ZipHandler::zip_file_cache_clear(void)
|
||||||
const ZipHandler::zip_file_header* ZipHandler::zip_file_next_file(zip_file *zip)
|
const ZipHandler::zip_file_header* ZipHandler::zip_file_next_file(zip_file *zip)
|
||||||
{
|
{
|
||||||
/* fix up any modified data */
|
/* fix up any modified data */
|
||||||
if (zip->header.raw != NULL)
|
if(zip->header.raw != nullptr)
|
||||||
{
|
{
|
||||||
zip->header.raw[ZIPCFN + zip->header.filename_length] = zip->header.saved;
|
zip->header.raw[ZIPCFN + zip->header.filename_length] = zip->header.saved;
|
||||||
zip->header.raw = NULL;
|
zip->header.raw = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we're at or past the end, we're done */
|
/* if we're at or past the end, we're done */
|
||||||
if (zip->cd_pos >= zip->ecd.cd_size)
|
if(zip->cd_pos >= zip->ecd.cd_size)
|
||||||
return NULL;
|
return nullptr;
|
||||||
|
|
||||||
/* extract file header info */
|
/* extract file header info */
|
||||||
zip->header.raw = zip->cd + zip->cd_pos;
|
zip->header.raw = zip->cd + zip->cd_pos;
|
||||||
|
@ -375,8 +375,8 @@ const ZipHandler::zip_file_header* ZipHandler::zip_file_next_file(zip_file *zip)
|
||||||
zip->header.rawlength += zip->header.filename_length;
|
zip->header.rawlength += zip->header.filename_length;
|
||||||
zip->header.rawlength += zip->header.extra_field_length;
|
zip->header.rawlength += zip->header.extra_field_length;
|
||||||
zip->header.rawlength += zip->header.file_comment_length;
|
zip->header.rawlength += zip->header.file_comment_length;
|
||||||
if (zip->cd_pos + zip->header.rawlength > zip->ecd.cd_size)
|
if(zip->cd_pos + zip->header.rawlength > zip->ecd.cd_size)
|
||||||
return NULL;
|
return nullptr;
|
||||||
|
|
||||||
/* NULL terminate the filename */
|
/* NULL terminate the filename */
|
||||||
zip->header.saved = zip->header.raw[ZIPCFN + zip->header.filename_length];
|
zip->header.saved = zip->header.raw[ZIPCFN + zip->header.filename_length];
|
||||||
|
@ -398,20 +398,20 @@ ZipHandler::zip_error
|
||||||
uInt64 offset;
|
uInt64 offset;
|
||||||
|
|
||||||
/* if we don't have enough buffer, error */
|
/* if we don't have enough buffer, error */
|
||||||
if (length < zip->header.uncompressed_length)
|
if(length < zip->header.uncompressed_length)
|
||||||
return ZIPERR_BUFFER_TOO_SMALL;
|
return ZIPERR_BUFFER_TOO_SMALL;
|
||||||
|
|
||||||
/* make sure the info in the header aligns with what we know */
|
/* make sure the info in the header aligns with what we know */
|
||||||
if (zip->header.start_disk_number != zip->ecd.disk_number)
|
if(zip->header.start_disk_number != zip->ecd.disk_number)
|
||||||
return ZIPERR_UNSUPPORTED;
|
return ZIPERR_UNSUPPORTED;
|
||||||
|
|
||||||
/* get the compressed data offset */
|
/* get the compressed data offset */
|
||||||
ziperr = get_compressed_data_offset(zip, &offset);
|
ziperr = get_compressed_data_offset(zip, &offset);
|
||||||
if (ziperr != ZIPERR_NONE)
|
if(ziperr != ZIPERR_NONE)
|
||||||
return ziperr;
|
return ziperr;
|
||||||
|
|
||||||
/* handle compression types */
|
/* handle compression types */
|
||||||
switch (zip->header.compression)
|
switch(zip->header.compression)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
ziperr = decompress_data_type_0(zip, offset, buffer, length);
|
ziperr = decompress_data_type_0(zip, offset, buffer, length);
|
||||||
|
@ -438,15 +438,15 @@ ZipHandler::zip_error
|
||||||
-------------------------------------------------*/
|
-------------------------------------------------*/
|
||||||
void ZipHandler::free_zip_file(zip_file *zip)
|
void ZipHandler::free_zip_file(zip_file *zip)
|
||||||
{
|
{
|
||||||
if (zip != NULL)
|
if(zip != nullptr)
|
||||||
{
|
{
|
||||||
if (zip->file)
|
if(zip->file)
|
||||||
stream_close(&zip->file);
|
stream_close(&zip->file);
|
||||||
if (zip->filename != NULL)
|
if(zip->filename != nullptr)
|
||||||
free((void *)zip->filename);
|
free((void *)zip->filename);
|
||||||
if (zip->ecd.raw != NULL)
|
if(zip->ecd.raw != nullptr)
|
||||||
free(zip->ecd.raw);
|
free(zip->ecd.raw);
|
||||||
if (zip->cd != NULL)
|
if(zip->cd != nullptr)
|
||||||
free(zip->cd);
|
free(zip->cd);
|
||||||
free(zip);
|
free(zip);
|
||||||
}
|
}
|
||||||
|
@ -466,37 +466,37 @@ ZipHandler::zip_error ZipHandler::read_ecd(zip_file *zip)
|
||||||
uInt8 *buffer;
|
uInt8 *buffer;
|
||||||
|
|
||||||
/* we may need multiple tries */
|
/* we may need multiple tries */
|
||||||
while (buflen < 65536)
|
while(buflen < 65536)
|
||||||
{
|
{
|
||||||
uInt32 read_length;
|
uInt32 read_length;
|
||||||
Int32 offset;
|
Int32 offset;
|
||||||
|
|
||||||
/* max out the buffer length at the size of the file */
|
/* max out the buffer length at the size of the file */
|
||||||
if (buflen > zip->length)
|
if(buflen > zip->length)
|
||||||
buflen = (uInt32)zip->length;
|
buflen = (uInt32)zip->length;
|
||||||
|
|
||||||
/* allocate buffer */
|
/* allocate buffer */
|
||||||
buffer = (uInt8 *)malloc(buflen + 1);
|
buffer = (uInt8 *)malloc(buflen + 1);
|
||||||
if (buffer == NULL)
|
if(buffer == nullptr)
|
||||||
return ZIPERR_OUT_OF_MEMORY;
|
return ZIPERR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
/* read in one buffers' worth of data */
|
/* read in one buffers' worth of data */
|
||||||
bool success = stream_read(zip->file, buffer, zip->length - buflen,
|
bool success = stream_read(zip->file, buffer, zip->length - buflen,
|
||||||
buflen, read_length);
|
buflen, read_length);
|
||||||
if (!success || read_length != buflen)
|
if(!success || read_length != buflen)
|
||||||
{
|
{
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return ZIPERR_FILE_ERROR;
|
return ZIPERR_FILE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find the ECD signature */
|
/* find the ECD signature */
|
||||||
for (offset = buflen - 22; offset >= 0; offset--)
|
for(offset = buflen - 22; offset >= 0; offset--)
|
||||||
if (buffer[offset + 0] == 'P' && buffer[offset + 1] == 'K' &&
|
if(buffer[offset + 0] == 'P' && buffer[offset + 1] == 'K' &&
|
||||||
buffer[offset + 2] == 0x05 && buffer[offset + 3] == 0x06)
|
buffer[offset + 2] == 0x05 && buffer[offset + 3] == 0x06)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* if we found it, fill out the data */
|
/* if we found it, fill out the data */
|
||||||
if (offset >= 0)
|
if(offset >= 0)
|
||||||
{
|
{
|
||||||
/* reuse the buffer as our ECD buffer */
|
/* reuse the buffer as our ECD buffer */
|
||||||
zip->ecd.raw = buffer;
|
zip->ecd.raw = buffer;
|
||||||
|
@ -521,7 +521,7 @@ ZipHandler::zip_error ZipHandler::read_ecd(zip_file *zip)
|
||||||
|
|
||||||
/* didn't find it; free this buffer and expand our search */
|
/* didn't find it; free this buffer and expand our search */
|
||||||
free(buffer);
|
free(buffer);
|
||||||
if (buflen < zip->length)
|
if(buflen < zip->length)
|
||||||
buflen *= 2;
|
buflen *= 2;
|
||||||
else
|
else
|
||||||
return ZIPERR_BAD_SIGNATURE;
|
return ZIPERR_BAD_SIGNATURE;
|
||||||
|
@ -539,13 +539,13 @@ ZipHandler::zip_error
|
||||||
uInt32 read_length;
|
uInt32 read_length;
|
||||||
|
|
||||||
/* make sure the file handle is open */
|
/* make sure the file handle is open */
|
||||||
if (zip->file == NULL && !stream_open(zip->filename, &zip->file, zip->length))
|
if(zip->file == nullptr && !stream_open(zip->filename, &zip->file, zip->length))
|
||||||
return ZIPERR_FILE_ERROR;
|
return ZIPERR_FILE_ERROR;
|
||||||
|
|
||||||
/* now go read the fixed-sized part of the local file header */
|
/* now go read the fixed-sized part of the local file header */
|
||||||
bool success = stream_read(zip->file, zip->buffer, zip->header.local_header_offset,
|
bool success = stream_read(zip->file, zip->buffer, zip->header.local_header_offset,
|
||||||
ZIPNAME, read_length);
|
ZIPNAME, read_length);
|
||||||
if (!success || read_length != ZIPNAME)
|
if(!success || read_length != ZIPNAME)
|
||||||
return success ? ZIPERR_FILE_TRUNCATED : ZIPERR_FILE_ERROR;
|
return success ? ZIPERR_FILE_TRUNCATED : ZIPERR_FILE_ERROR;
|
||||||
|
|
||||||
/* compute the final offset */
|
/* compute the final offset */
|
||||||
|
@ -573,9 +573,9 @@ ZipHandler::zip_error
|
||||||
/* the data is uncompressed; just read it */
|
/* the data is uncompressed; just read it */
|
||||||
bool success = stream_read(zip->file, buffer, offset, zip->header.compressed_length,
|
bool success = stream_read(zip->file, buffer, offset, zip->header.compressed_length,
|
||||||
read_length);
|
read_length);
|
||||||
if (!success)
|
if(!success)
|
||||||
return ZIPERR_FILE_ERROR;
|
return ZIPERR_FILE_ERROR;
|
||||||
else if (read_length != zip->header.compressed_length)
|
else if(read_length != zip->header.compressed_length)
|
||||||
return ZIPERR_FILE_TRUNCATED;
|
return ZIPERR_FILE_TRUNCATED;
|
||||||
else
|
else
|
||||||
return ZIPERR_NONE;
|
return ZIPERR_NONE;
|
||||||
|
@ -609,17 +609,17 @@ ZipHandler::zip_error
|
||||||
|
|
||||||
/* initialize the decompressor */
|
/* initialize the decompressor */
|
||||||
zerr = inflateInit2(&stream, -MAX_WBITS);
|
zerr = inflateInit2(&stream, -MAX_WBITS);
|
||||||
if (zerr != Z_OK)
|
if(zerr != Z_OK)
|
||||||
return ZIPERR_DECOMPRESS_ERROR;
|
return ZIPERR_DECOMPRESS_ERROR;
|
||||||
|
|
||||||
/* loop until we're done */
|
/* loop until we're done */
|
||||||
while (1)
|
while(1)
|
||||||
{
|
{
|
||||||
/* read in the next chunk of data */
|
/* read in the next chunk of data */
|
||||||
bool success = stream_read(zip->file, zip->buffer, offset,
|
bool success = stream_read(zip->file, zip->buffer, offset,
|
||||||
BSPF_min(input_remaining, (uInt32)sizeof(zip->buffer)),
|
BSPF_min(input_remaining, (uInt32)sizeof(zip->buffer)),
|
||||||
read_length);
|
read_length);
|
||||||
if (!success)
|
if(!success)
|
||||||
{
|
{
|
||||||
inflateEnd(&stream);
|
inflateEnd(&stream);
|
||||||
return ZIPERR_FILE_ERROR;
|
return ZIPERR_FILE_ERROR;
|
||||||
|
@ -627,7 +627,7 @@ ZipHandler::zip_error
|
||||||
offset += read_length;
|
offset += read_length;
|
||||||
|
|
||||||
/* if we read nothing, but still have data left, the file is truncated */
|
/* if we read nothing, but still have data left, the file is truncated */
|
||||||
if (read_length == 0 && input_remaining > 0)
|
if(read_length == 0 && input_remaining > 0)
|
||||||
{
|
{
|
||||||
inflateEnd(&stream);
|
inflateEnd(&stream);
|
||||||
return ZIPERR_FILE_TRUNCATED;
|
return ZIPERR_FILE_TRUNCATED;
|
||||||
|
@ -639,14 +639,14 @@ ZipHandler::zip_error
|
||||||
input_remaining -= read_length;
|
input_remaining -= read_length;
|
||||||
|
|
||||||
/* add a dummy byte at end of compressed data */
|
/* add a dummy byte at end of compressed data */
|
||||||
if (input_remaining == 0)
|
if(input_remaining == 0)
|
||||||
stream.avail_in++;
|
stream.avail_in++;
|
||||||
|
|
||||||
/* now inflate */
|
/* now inflate */
|
||||||
zerr = inflate(&stream, Z_NO_FLUSH);
|
zerr = inflate(&stream, Z_NO_FLUSH);
|
||||||
if (zerr == Z_STREAM_END)
|
if(zerr == Z_STREAM_END)
|
||||||
break;
|
break;
|
||||||
if (zerr != Z_OK)
|
if(zerr != Z_OK)
|
||||||
{
|
{
|
||||||
inflateEnd(&stream);
|
inflateEnd(&stream);
|
||||||
return ZIPERR_DECOMPRESS_ERROR;
|
return ZIPERR_DECOMPRESS_ERROR;
|
||||||
|
@ -655,11 +655,11 @@ ZipHandler::zip_error
|
||||||
|
|
||||||
/* finish decompression */
|
/* finish decompression */
|
||||||
zerr = inflateEnd(&stream);
|
zerr = inflateEnd(&stream);
|
||||||
if (zerr != Z_OK)
|
if(zerr != Z_OK)
|
||||||
return ZIPERR_DECOMPRESS_ERROR;
|
return ZIPERR_DECOMPRESS_ERROR;
|
||||||
|
|
||||||
/* if anything looks funny, report an error */
|
/* if anything looks funny, report an error */
|
||||||
if (stream.avail_out > 0 || input_remaining > 0)
|
if(stream.avail_out > 0 || input_remaining > 0)
|
||||||
return ZIPERR_DECOMPRESS_ERROR;
|
return ZIPERR_DECOMPRESS_ERROR;
|
||||||
|
|
||||||
return ZIPERR_NONE;
|
return ZIPERR_NONE;
|
||||||
|
|
|
@ -47,7 +47,7 @@ unique_ptr<OSystem> theOSystem;
|
||||||
// Does general Cleanup in case any operation failed (or at end of program)
|
// Does general Cleanup in case any operation failed (or at end of program)
|
||||||
int Cleanup()
|
int Cleanup()
|
||||||
{
|
{
|
||||||
theOSystem->logMessage("Cleanup from mainSDL", 2);
|
theOSystem->logMessage("Cleanup from main", 2);
|
||||||
theOSystem->saveConfig();
|
theOSystem->saveConfig();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
|
@ -1,7 +1,7 @@
|
||||||
MODULE := src/common
|
MODULE := src/common
|
||||||
|
|
||||||
MODULE_OBJS := \
|
MODULE_OBJS := \
|
||||||
src/common/mainSDL.o \
|
src/common/main.o \
|
||||||
src/common/Base.o \
|
src/common/Base.o \
|
||||||
src/common/EventHandlerSDL2.o \
|
src/common/EventHandlerSDL2.o \
|
||||||
src/common/FrameBufferSDL2.o \
|
src/common/FrameBufferSDL2.o \
|
||||||
|
|
Loading…
Reference in New Issue