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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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,7 +193,7 @@ 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++)
|
||||||
|
@ -202,18 +202,18 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char *filename, zip_file *
|
||||||
|
|
||||||
/* 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));
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
@ -298,7 +298,7 @@ void ZipHandler::zip_file_close(zip_file *zip)
|
||||||
|
|
||||||
/* 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 */
|
||||||
|
@ -320,10 +320,10 @@ 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;
|
||||||
|
@ -376,7 +376,7 @@ const ZipHandler::zip_file_header* ZipHandler::zip_file_next_file(zip_file *zip)
|
||||||
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];
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -477,7 +477,7 @@ ZipHandler::zip_error ZipHandler::read_ecd(zip_file *zip)
|
||||||
|
|
||||||
/* 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 */
|
||||||
|
@ -539,7 +539,7 @@ 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 */
|
||||||
|
|
|
@ -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