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)
|
||||
: myStick(NULL)
|
||||
: myStick(nullptr)
|
||||
{
|
||||
myStick = SDL_JoystickOpen(idx);
|
||||
if(myStick)
|
||||
|
@ -218,5 +218,5 @@ EventHandlerSDL2::JoystickSDL2::~JoystickSDL2()
|
|||
{
|
||||
if(myStick)
|
||||
SDL_JoystickClose(myStick);
|
||||
myStick = NULL;
|
||||
myStick = nullptr;
|
||||
}
|
||||
|
|
|
@ -23,15 +23,15 @@
|
|||
FBSurfaceSDL2::FBSurfaceSDL2(FrameBufferSDL2& buffer,
|
||||
uInt32 width, uInt32 height, const uInt32* data)
|
||||
: myFB(buffer),
|
||||
mySurface(NULL),
|
||||
myTexture(NULL),
|
||||
mySurface(nullptr),
|
||||
myTexture(nullptr),
|
||||
mySurfaceIsDirty(true),
|
||||
myIsVisible(true),
|
||||
myTexAccess(SDL_TEXTUREACCESS_STREAMING),
|
||||
myInterpolate(false),
|
||||
myBlendEnabled(false),
|
||||
myBlendAlpha(255),
|
||||
myStaticData(NULL)
|
||||
myStaticData(nullptr)
|
||||
{
|
||||
createSurface(width, height, data);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ FBSurfaceSDL2::~FBSurfaceSDL2()
|
|||
if(myStaticData)
|
||||
{
|
||||
delete[] myStaticData;
|
||||
myStaticData = NULL;
|
||||
myStaticData = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ bool FBSurfaceSDL2::render()
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void FBSurfaceSDL2::invalidate()
|
||||
{
|
||||
SDL_FillRect(mySurface, NULL, 0);
|
||||
SDL_FillRect(mySurface, nullptr, 0);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -161,7 +161,7 @@ void FBSurfaceSDL2::free()
|
|||
if(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(myTexAccess == SDL_TEXTUREACCESS_STATIC)
|
||||
SDL_UpdateTexture(myTexture, NULL, myStaticData, myStaticPitch);
|
||||
SDL_UpdateTexture(myTexture, nullptr, myStaticData, myStaticPitch);
|
||||
|
||||
// Blending enabled?
|
||||
if(myBlendEnabled)
|
||||
|
@ -197,7 +197,7 @@ void FBSurfaceSDL2::resize(uInt32 width, uInt32 height)
|
|||
SDL_FreeSurface(mySurface);
|
||||
free();
|
||||
|
||||
createSurface(width, height, NULL);
|
||||
createSurface(width, height, nullptr);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
FrameBufferSDL2::FrameBufferSDL2(OSystem& osystem)
|
||||
: FrameBuffer(osystem),
|
||||
myWindow(NULL),
|
||||
myRenderer(NULL),
|
||||
myWindow(nullptr),
|
||||
myRenderer(nullptr),
|
||||
myDirtyFlag(true),
|
||||
myDblBufferedFlag(true)
|
||||
{
|
||||
|
@ -66,14 +66,14 @@ FrameBufferSDL2::~FrameBufferSDL2()
|
|||
if(myRenderer)
|
||||
{
|
||||
SDL_DestroyRenderer(myRenderer);
|
||||
myRenderer = NULL;
|
||||
myRenderer = nullptr;
|
||||
}
|
||||
if(myWindow)
|
||||
{
|
||||
SDL_SetWindowFullscreen(myWindow, 0); // on some systems, a crash occurs
|
||||
// when destroying fullscreen window
|
||||
SDL_DestroyWindow(myWindow);
|
||||
myWindow = NULL;
|
||||
myWindow = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode,
|
|||
SDL_RenderPresent(myRenderer);
|
||||
SDL_RenderClear(myRenderer);
|
||||
SDL_DestroyRenderer(myRenderer);
|
||||
myRenderer = NULL;
|
||||
myRenderer = nullptr;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
SDL_DestroyWindow(myWindow);
|
||||
myWindow = NULL;
|
||||
myWindow = nullptr;
|
||||
}
|
||||
}
|
||||
if(myWindow)
|
||||
|
@ -186,7 +186,7 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode,
|
|||
{
|
||||
myWindow = SDL_CreateWindow(title.c_str(), pos, pos,
|
||||
mode.screen.w, mode.screen.h, flags);
|
||||
if(myWindow == NULL)
|
||||
if(myWindow == nullptr)
|
||||
{
|
||||
string msg = "ERROR: Unable to open SDL window: " + string(SDL_GetError());
|
||||
myOSystem.logMessage(msg, 0);
|
||||
|
@ -202,7 +202,7 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode,
|
|||
if(video != "")
|
||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, video.c_str());
|
||||
myRenderer = SDL_CreateRenderer(myWindow, -1, renderFlags);
|
||||
if(myRenderer == NULL)
|
||||
if(myRenderer == nullptr)
|
||||
{
|
||||
string msg = "ERROR: Unable to create SDL renderer: " + string(SDL_GetError());
|
||||
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"));
|
||||
|
||||
#if 0
|
||||
for(unsigned int i = 0; i < myModeList.size(); ++i)
|
||||
cerr << myModeList[i] << endl;
|
||||
for(MouseMode m: myModeList)
|
||||
cerr << mode << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -46,25 +46,25 @@ void PNGLibrary::loadImage(const string& filename, FBSurface& surface)
|
|||
{
|
||||
#define loadImageERROR(s) { err_message = s; goto done; }
|
||||
|
||||
png_structp png_ptr = NULL;
|
||||
png_infop info_ptr = NULL;
|
||||
png_structp png_ptr = nullptr;
|
||||
png_infop info_ptr = nullptr;
|
||||
png_uint_32 iwidth, iheight;
|
||||
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);
|
||||
if(!in.is_open())
|
||||
loadImageERROR("No image found");
|
||||
|
||||
// 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);
|
||||
if(png_ptr == NULL)
|
||||
if(png_ptr == nullptr)
|
||||
loadImageERROR("Couldn't allocate memory for PNG file");
|
||||
|
||||
// Allocate/initialize the memory for image information. REQUIRED.
|
||||
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");
|
||||
|
||||
// Set up the input control
|
||||
|
@ -73,7 +73,7 @@ void PNGLibrary::loadImage(const string& filename, FBSurface& surface)
|
|||
// Read PNG header info
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
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
|
||||
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; }
|
||||
|
||||
png_structp png_ptr = NULL;
|
||||
png_infop info_ptr = NULL;
|
||||
const char* err_message = NULL;
|
||||
png_structp png_ptr = nullptr;
|
||||
png_infop info_ptr = nullptr;
|
||||
const char* err_message = nullptr;
|
||||
|
||||
// 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);
|
||||
if(png_ptr == NULL)
|
||||
if(png_ptr == nullptr)
|
||||
saveImageERROR("Couldn't allocate memory for PNG file");
|
||||
|
||||
// Allocate/initialize the memory for image information. REQUIRED.
|
||||
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");
|
||||
|
||||
// Set up the output control
|
||||
|
@ -252,7 +252,7 @@ bool PNGLibrary::allocateStorage(png_uint_32 w, png_uint_32 h)
|
|||
{
|
||||
delete[] ReadInfo.buffer;
|
||||
ReadInfo.buffer = new uInt8[req_buffer_size];
|
||||
if(ReadInfo.buffer == NULL)
|
||||
if(ReadInfo.buffer == nullptr)
|
||||
return false;
|
||||
|
||||
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;
|
||||
ReadInfo.row_pointers = new png_bytep[req_row_size];
|
||||
if(ReadInfo.row_pointers == NULL)
|
||||
if(ReadInfo.row_pointers == nullptr)
|
||||
return false;
|
||||
|
||||
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 = {
|
||||
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,
|
||||
// and is only changed when absolutely necessary.
|
||||
typedef struct {
|
||||
struct ReadInfoType {
|
||||
uInt8* buffer;
|
||||
png_bytep* row_pointers;
|
||||
png_uint_32 width, height, pitch;
|
||||
uInt32 buffer_size, row_size;
|
||||
} ReadInfoType;
|
||||
};
|
||||
static ReadInfoType ReadInfo;
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
class StringList : public Common::Array<string>
|
||||
{
|
||||
public:
|
||||
void push_back(const char *str)
|
||||
void push_back(const char* str)
|
||||
{
|
||||
ensureCapacity(_size + 1);
|
||||
_data[_size++] = str;
|
||||
|
|
|
@ -79,7 +79,7 @@ class Variant
|
|||
static const Variant EmptyVariant("");
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
class VariantList : public Common::Array< pair<string,Variant> >
|
||||
class VariantList : public Common::Array<pair<string,Variant>>
|
||||
{
|
||||
public:
|
||||
VariantList() { }
|
||||
|
|
|
@ -25,10 +25,10 @@
|
|||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
ZipHandler::ZipHandler()
|
||||
: myZip(NULL)
|
||||
: myZip(nullptr)
|
||||
{
|
||||
for (int cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
||||
myZipCache[cachenum] = NULL;
|
||||
for(int cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
||||
myZipCache[cachenum] = nullptr;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -70,7 +70,7 @@ string ZipHandler::next()
|
|||
if(myZip)
|
||||
{
|
||||
bool valid = false;
|
||||
const zip_file_header* header = NULL;
|
||||
const zip_file_header* header = nullptr;
|
||||
do {
|
||||
header = zip_file_next_file(myZip);
|
||||
|
||||
|
@ -111,7 +111,7 @@ uInt32 ZipHandler::decompress(uInt8*& image)
|
|||
return length;
|
||||
else
|
||||
{
|
||||
delete[] image; image = NULL;
|
||||
delete[] image; image = nullptr;
|
||||
|
||||
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);
|
||||
if(!in || !in->is_open())
|
||||
{
|
||||
*stream = NULL;
|
||||
*stream = nullptr;
|
||||
length = 0;
|
||||
return false;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ void ZipHandler::stream_close(fstream** stream)
|
|||
if((*stream)->is_open())
|
||||
(*stream)->close();
|
||||
delete *stream;
|
||||
*stream = NULL;
|
||||
*stream = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,27 +193,27 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char *filename, zip_file *
|
|||
bool success;
|
||||
|
||||
/* ensure we start with a NULL result */
|
||||
*zip = NULL;
|
||||
*zip = nullptr;
|
||||
|
||||
/* 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];
|
||||
|
||||
/* if we have a valid entry and it matches our filename, use it and remove
|
||||
from the cache */
|
||||
if (cached != NULL && cached->filename != NULL &&
|
||||
strcmp(filename, cached->filename) == 0)
|
||||
if(cached != nullptr && cached->filename != nullptr &&
|
||||
strcmp(filename, cached->filename) == 0)
|
||||
{
|
||||
*zip = cached;
|
||||
myZipCache[cachenum] = NULL;
|
||||
myZipCache[cachenum] = nullptr;
|
||||
return ZIPERR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
/* allocate memory for the zip_file structure */
|
||||
newzip = (zip_file *)malloc(sizeof(*newzip));
|
||||
if (newzip == NULL)
|
||||
if (newzip == nullptr)
|
||||
return ZIPERR_OUT_OF_MEMORY;
|
||||
memset(newzip, 0, sizeof(*newzip));
|
||||
|
||||
|
@ -226,7 +226,7 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char *filename, zip_file *
|
|||
|
||||
/* read ecd data */
|
||||
ziperr = read_ecd(newzip);
|
||||
if (ziperr != ZIPERR_NONE)
|
||||
if(ziperr != ZIPERR_NONE)
|
||||
goto error;
|
||||
|
||||
/* 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 */
|
||||
newzip->cd = (uInt8 *)malloc(newzip->ecd.cd_size + 1);
|
||||
if (newzip->cd == NULL)
|
||||
if(newzip->cd == nullptr)
|
||||
{
|
||||
ziperr = ZIPERR_OUT_OF_MEMORY;
|
||||
goto error;
|
||||
|
@ -248,7 +248,7 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char *filename, zip_file *
|
|||
/* read the central directory */
|
||||
success = stream_read(newzip->file, newzip->cd, newzip->ecd.cd_start_disk_offset,
|
||||
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;
|
||||
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 */
|
||||
string = (char *)malloc(strlen(filename) + 1);
|
||||
if (string == NULL)
|
||||
if (string == nullptr)
|
||||
{
|
||||
ziperr = ZIPERR_OUT_OF_MEMORY;
|
||||
goto error;
|
||||
|
@ -293,20 +293,20 @@ void ZipHandler::zip_file_close(zip_file *zip)
|
|||
int cachenum;
|
||||
|
||||
/* close the open files */
|
||||
if (zip->file)
|
||||
if(zip->file)
|
||||
stream_close(&zip->file);
|
||||
|
||||
/* find the first NULL entry in the cache */
|
||||
for (cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
||||
if (myZipCache[cachenum] == NULL)
|
||||
for(cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
||||
if (myZipCache[cachenum] == nullptr)
|
||||
break;
|
||||
|
||||
/* 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]);
|
||||
|
||||
/* 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]));
|
||||
myZipCache[0] = zip;
|
||||
}
|
||||
|
@ -319,11 +319,11 @@ void ZipHandler::zip_file_close(zip_file *zip)
|
|||
void ZipHandler::zip_file_cache_clear(void)
|
||||
{
|
||||
/* clear call cache entries */
|
||||
for (int cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
||||
if (myZipCache[cachenum] != NULL)
|
||||
for(int cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
||||
if(myZipCache[cachenum] != nullptr)
|
||||
{
|
||||
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)
|
||||
{
|
||||
/* 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 = NULL;
|
||||
zip->header.raw = nullptr;
|
||||
}
|
||||
|
||||
/* if we're at or past the end, we're done */
|
||||
if (zip->cd_pos >= zip->ecd.cd_size)
|
||||
return NULL;
|
||||
if(zip->cd_pos >= zip->ecd.cd_size)
|
||||
return nullptr;
|
||||
|
||||
/* extract file header info */
|
||||
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.extra_field_length;
|
||||
zip->header.rawlength += zip->header.file_comment_length;
|
||||
if (zip->cd_pos + zip->header.rawlength > zip->ecd.cd_size)
|
||||
return NULL;
|
||||
if(zip->cd_pos + zip->header.rawlength > zip->ecd.cd_size)
|
||||
return nullptr;
|
||||
|
||||
/* NULL terminate the filename */
|
||||
zip->header.saved = zip->header.raw[ZIPCFN + zip->header.filename_length];
|
||||
|
@ -398,20 +398,20 @@ ZipHandler::zip_error
|
|||
uInt64 offset;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* get the compressed data offset */
|
||||
ziperr = get_compressed_data_offset(zip, &offset);
|
||||
if (ziperr != ZIPERR_NONE)
|
||||
if(ziperr != ZIPERR_NONE)
|
||||
return ziperr;
|
||||
|
||||
/* handle compression types */
|
||||
switch (zip->header.compression)
|
||||
switch(zip->header.compression)
|
||||
{
|
||||
case 0:
|
||||
ziperr = decompress_data_type_0(zip, offset, buffer, length);
|
||||
|
@ -438,15 +438,15 @@ ZipHandler::zip_error
|
|||
-------------------------------------------------*/
|
||||
void ZipHandler::free_zip_file(zip_file *zip)
|
||||
{
|
||||
if (zip != NULL)
|
||||
if(zip != nullptr)
|
||||
{
|
||||
if (zip->file)
|
||||
if(zip->file)
|
||||
stream_close(&zip->file);
|
||||
if (zip->filename != NULL)
|
||||
if(zip->filename != nullptr)
|
||||
free((void *)zip->filename);
|
||||
if (zip->ecd.raw != NULL)
|
||||
if(zip->ecd.raw != nullptr)
|
||||
free(zip->ecd.raw);
|
||||
if (zip->cd != NULL)
|
||||
if(zip->cd != nullptr)
|
||||
free(zip->cd);
|
||||
free(zip);
|
||||
}
|
||||
|
@ -466,37 +466,37 @@ ZipHandler::zip_error ZipHandler::read_ecd(zip_file *zip)
|
|||
uInt8 *buffer;
|
||||
|
||||
/* we may need multiple tries */
|
||||
while (buflen < 65536)
|
||||
while(buflen < 65536)
|
||||
{
|
||||
uInt32 read_length;
|
||||
Int32 offset;
|
||||
|
||||
/* max out the buffer length at the size of the file */
|
||||
if (buflen > zip->length)
|
||||
if(buflen > zip->length)
|
||||
buflen = (uInt32)zip->length;
|
||||
|
||||
/* allocate buffer */
|
||||
buffer = (uInt8 *)malloc(buflen + 1);
|
||||
if (buffer == NULL)
|
||||
if(buffer == nullptr)
|
||||
return ZIPERR_OUT_OF_MEMORY;
|
||||
|
||||
/* read in one buffers' worth of data */
|
||||
bool success = stream_read(zip->file, buffer, zip->length - buflen,
|
||||
buflen, read_length);
|
||||
if (!success || read_length != buflen)
|
||||
if(!success || read_length != buflen)
|
||||
{
|
||||
free(buffer);
|
||||
return ZIPERR_FILE_ERROR;
|
||||
}
|
||||
|
||||
/* find the ECD signature */
|
||||
for (offset = buflen - 22; offset >= 0; offset--)
|
||||
if (buffer[offset + 0] == 'P' && buffer[offset + 1] == 'K' &&
|
||||
buffer[offset + 2] == 0x05 && buffer[offset + 3] == 0x06)
|
||||
for(offset = buflen - 22; offset >= 0; offset--)
|
||||
if(buffer[offset + 0] == 'P' && buffer[offset + 1] == 'K' &&
|
||||
buffer[offset + 2] == 0x05 && buffer[offset + 3] == 0x06)
|
||||
break;
|
||||
|
||||
/* if we found it, fill out the data */
|
||||
if (offset >= 0)
|
||||
if(offset >= 0)
|
||||
{
|
||||
/* reuse the buffer as our ECD 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 */
|
||||
free(buffer);
|
||||
if (buflen < zip->length)
|
||||
if(buflen < zip->length)
|
||||
buflen *= 2;
|
||||
else
|
||||
return ZIPERR_BAD_SIGNATURE;
|
||||
|
@ -539,13 +539,13 @@ ZipHandler::zip_error
|
|||
uInt32 read_length;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* 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,
|
||||
ZIPNAME, read_length);
|
||||
if (!success || read_length != ZIPNAME)
|
||||
if(!success || read_length != ZIPNAME)
|
||||
return success ? ZIPERR_FILE_TRUNCATED : ZIPERR_FILE_ERROR;
|
||||
|
||||
/* compute the final offset */
|
||||
|
@ -573,9 +573,9 @@ ZipHandler::zip_error
|
|||
/* the data is uncompressed; just read it */
|
||||
bool success = stream_read(zip->file, buffer, offset, zip->header.compressed_length,
|
||||
read_length);
|
||||
if (!success)
|
||||
if(!success)
|
||||
return ZIPERR_FILE_ERROR;
|
||||
else if (read_length != zip->header.compressed_length)
|
||||
else if(read_length != zip->header.compressed_length)
|
||||
return ZIPERR_FILE_TRUNCATED;
|
||||
else
|
||||
return ZIPERR_NONE;
|
||||
|
@ -609,17 +609,17 @@ ZipHandler::zip_error
|
|||
|
||||
/* initialize the decompressor */
|
||||
zerr = inflateInit2(&stream, -MAX_WBITS);
|
||||
if (zerr != Z_OK)
|
||||
if(zerr != Z_OK)
|
||||
return ZIPERR_DECOMPRESS_ERROR;
|
||||
|
||||
/* loop until we're done */
|
||||
while (1)
|
||||
while(1)
|
||||
{
|
||||
/* read in the next chunk of data */
|
||||
bool success = stream_read(zip->file, zip->buffer, offset,
|
||||
BSPF_min(input_remaining, (uInt32)sizeof(zip->buffer)),
|
||||
read_length);
|
||||
if (!success)
|
||||
if(!success)
|
||||
{
|
||||
inflateEnd(&stream);
|
||||
return ZIPERR_FILE_ERROR;
|
||||
|
@ -627,7 +627,7 @@ ZipHandler::zip_error
|
|||
offset += read_length;
|
||||
|
||||
/* 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);
|
||||
return ZIPERR_FILE_TRUNCATED;
|
||||
|
@ -639,14 +639,14 @@ ZipHandler::zip_error
|
|||
input_remaining -= read_length;
|
||||
|
||||
/* add a dummy byte at end of compressed data */
|
||||
if (input_remaining == 0)
|
||||
if(input_remaining == 0)
|
||||
stream.avail_in++;
|
||||
|
||||
/* now inflate */
|
||||
zerr = inflate(&stream, Z_NO_FLUSH);
|
||||
if (zerr == Z_STREAM_END)
|
||||
if(zerr == Z_STREAM_END)
|
||||
break;
|
||||
if (zerr != Z_OK)
|
||||
if(zerr != Z_OK)
|
||||
{
|
||||
inflateEnd(&stream);
|
||||
return ZIPERR_DECOMPRESS_ERROR;
|
||||
|
@ -655,11 +655,11 @@ ZipHandler::zip_error
|
|||
|
||||
/* finish decompression */
|
||||
zerr = inflateEnd(&stream);
|
||||
if (zerr != Z_OK)
|
||||
if(zerr != Z_OK)
|
||||
return ZIPERR_DECOMPRESS_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_NONE;
|
||||
|
|
|
@ -47,7 +47,7 @@ unique_ptr<OSystem> theOSystem;
|
|||
// Does general Cleanup in case any operation failed (or at end of program)
|
||||
int Cleanup()
|
||||
{
|
||||
theOSystem->logMessage("Cleanup from mainSDL", 2);
|
||||
theOSystem->logMessage("Cleanup from main", 2);
|
||||
theOSystem->saveConfig();
|
||||
|
||||
return 0;
|
|
@ -1,7 +1,7 @@
|
|||
MODULE := src/common
|
||||
|
||||
MODULE_OBJS := \
|
||||
src/common/mainSDL.o \
|
||||
src/common/main.o \
|
||||
src/common/Base.o \
|
||||
src/common/EventHandlerSDL2.o \
|
||||
src/common/FrameBufferSDL2.o \
|
||||
|
|
Loading…
Reference in New Issue