mirror of
https://github.com/TTimo/GtkRadiant.git
synced 2025-01-10 03:51:18 +00:00
[quake3/common/unzip.c] Add braces to make nested if/else less brittle; attempt to make whitespace a bit more uniform
This commit is contained in:
parent
6409de3029
commit
df3ebf5173
1 changed files with 111 additions and 104 deletions
|
@ -1856,19 +1856,24 @@ static int unzlocal_GetCurrentFileInfoInternal (unzFile file,
|
||||||
uLong uMagic;
|
uLong uMagic;
|
||||||
long lSeek=0;
|
long lSeek=0;
|
||||||
|
|
||||||
if (file==NULL)
|
if (file == NULL) {
|
||||||
return UNZ_PARAMERROR;
|
return UNZ_PARAMERROR;
|
||||||
s=(unz_s*)file;
|
}
|
||||||
if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0)
|
|
||||||
err=UNZ_ERRNO;
|
|
||||||
|
|
||||||
|
s = (unz_s*)file;
|
||||||
|
|
||||||
|
if (fseek(s->file, s->pos_in_central_dir + s->byte_before_the_zipfile, SEEK_SET) != 0) {
|
||||||
|
err=UNZ_ERRNO;
|
||||||
|
}
|
||||||
|
|
||||||
/* we check the magic */
|
/* we check the magic */
|
||||||
if (err==UNZ_OK)
|
if (err == UNZ_OK) {
|
||||||
if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
|
if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) {
|
||||||
err = UNZ_ERRNO;
|
err = UNZ_ERRNO;
|
||||||
else if (uMagic!=0x02014b50)
|
} else if (uMagic != 0x02014b50) {
|
||||||
err = UNZ_BADZIPFILE;
|
err = UNZ_BADZIPFILE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK)
|
if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK)
|
||||||
err=UNZ_ERRNO;
|
err=UNZ_ERRNO;
|
||||||
|
@ -1918,16 +1923,15 @@ static int unzlocal_GetCurrentFileInfoInternal (unzFile file,
|
||||||
err=UNZ_ERRNO;
|
err=UNZ_ERRNO;
|
||||||
|
|
||||||
lSeek += file_info.size_filename;
|
lSeek += file_info.size_filename;
|
||||||
if ((err==UNZ_OK) && (szFileName!=NULL))
|
|
||||||
{
|
if ((err == UNZ_OK) && (szFileName != NULL)) {
|
||||||
uLong uSizeRead ;
|
uLong uSizeRead ;
|
||||||
if (file_info.size_filename<fileNameBufferSize)
|
if (file_info.size_filename<fileNameBufferSize) {
|
||||||
{
|
|
||||||
*(szFileName+file_info.size_filename)='\0';
|
*(szFileName+file_info.size_filename)='\0';
|
||||||
uSizeRead = file_info.size_filename;
|
uSizeRead = file_info.size_filename;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
uSizeRead = fileNameBufferSize;
|
uSizeRead = fileNameBufferSize;
|
||||||
|
}
|
||||||
|
|
||||||
if ((file_info.size_filename>0) && (fileNameBufferSize>0)) {
|
if ((file_info.size_filename>0) && (fileNameBufferSize>0)) {
|
||||||
size_t gametype;
|
size_t gametype;
|
||||||
|
@ -1937,26 +1941,28 @@ static int unzlocal_GetCurrentFileInfoInternal (unzFile file,
|
||||||
gametype = fread(szFileName, (uInt)uSizeRead, 1, s->file);
|
gametype = fread(szFileName, (uInt)uSizeRead, 1, s->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gametype!=1)
|
if (gametype != 1) {
|
||||||
err = UNZ_ERRNO;
|
err = UNZ_ERRNO;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
lSeek -= uSizeRead;
|
lSeek -= uSizeRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((err == UNZ_OK) && (extraField != NULL)) {
|
||||||
if ((err==UNZ_OK) && (extraField!=NULL))
|
|
||||||
{
|
|
||||||
uLong uSizeRead ;
|
uLong uSizeRead ;
|
||||||
if (file_info.size_file_extra<extraFieldBufferSize)
|
if (file_info.size_file_extra < extraFieldBufferSize) {
|
||||||
uSizeRead = file_info.size_file_extra;
|
uSizeRead = file_info.size_file_extra;
|
||||||
else
|
} else {
|
||||||
uSizeRead = extraFieldBufferSize;
|
uSizeRead = extraFieldBufferSize;
|
||||||
|
}
|
||||||
|
|
||||||
if (lSeek!=0)
|
if (lSeek != 0) {
|
||||||
if (fseek(s->file,lSeek,SEEK_CUR)==0)
|
if (fseek(s->file, lSeek, SEEK_CUR) == 0) {
|
||||||
lSeek=0;
|
lSeek=0;
|
||||||
else
|
} else {
|
||||||
err=UNZ_ERRNO;
|
err=UNZ_ERRNO;
|
||||||
|
}
|
||||||
|
}
|
||||||
if ((file_info.size_file_extra > 0) && (extraFieldBufferSize > 0)) {
|
if ((file_info.size_file_extra > 0) && (extraFieldBufferSize > 0)) {
|
||||||
size_t gametype;
|
size_t gametype;
|
||||||
if (unz_GAME_QL == 1) {
|
if (unz_GAME_QL == 1) {
|
||||||
|
@ -1964,31 +1970,31 @@ static int unzlocal_GetCurrentFileInfoInternal (unzFile file,
|
||||||
} else {
|
} else {
|
||||||
gametype = fread(extraField, (uInt)uSizeRead, 1, s->file);
|
gametype = fread(extraField, (uInt)uSizeRead, 1, s->file);
|
||||||
}
|
}
|
||||||
if (gametype!=1)
|
if (gametype != 1) {
|
||||||
err=UNZ_ERRNO;
|
err=UNZ_ERRNO;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
lSeek += file_info.size_file_extra - uSizeRead;
|
lSeek += file_info.size_file_extra - uSizeRead;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
lSeek += file_info.size_file_extra;
|
lSeek += file_info.size_file_extra;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((err == UNZ_OK) && (szComment != NULL)) {
|
||||||
if ((err==UNZ_OK) && (szComment!=NULL))
|
|
||||||
{
|
|
||||||
uLong uSizeRead ;
|
uLong uSizeRead ;
|
||||||
if (file_info.size_file_comment<commentBufferSize)
|
if (file_info.size_file_comment < commentBufferSize) {
|
||||||
{
|
|
||||||
*(szComment+file_info.size_file_comment) = '\0';
|
*(szComment+file_info.size_file_comment) = '\0';
|
||||||
uSizeRead = file_info.size_file_comment;
|
uSizeRead = file_info.size_file_comment;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
uSizeRead = commentBufferSize;
|
uSizeRead = commentBufferSize;
|
||||||
|
}
|
||||||
|
|
||||||
if (lSeek!=0)
|
if (lSeek != 0) {
|
||||||
if (fseek(s->file,lSeek,SEEK_CUR)==0)
|
if (fseek(s->file, lSeek, SEEK_CUR) ==0 ) {
|
||||||
lSeek=0;
|
lSeek=0;
|
||||||
else
|
} else {
|
||||||
err=UNZ_ERRNO;
|
err=UNZ_ERRNO;
|
||||||
|
}
|
||||||
|
}
|
||||||
if ((file_info.size_file_comment>0) && (commentBufferSize>0)) {
|
if ((file_info.size_file_comment>0) && (commentBufferSize>0)) {
|
||||||
size_t gametype;
|
size_t gametype;
|
||||||
if (unz_GAME_QL == 1) {
|
if (unz_GAME_QL == 1) {
|
||||||
|
@ -1996,19 +2002,22 @@ static int unzlocal_GetCurrentFileInfoInternal (unzFile file,
|
||||||
} else {
|
} else {
|
||||||
gametype = fread(szComment, (uInt)uSizeRead, 1, s->file);
|
gametype = fread(szComment, (uInt)uSizeRead, 1, s->file);
|
||||||
}
|
}
|
||||||
if (gametype!=1)
|
if (gametype!=1) {
|
||||||
err=UNZ_ERRNO;
|
err=UNZ_ERRNO;
|
||||||
}
|
}
|
||||||
lSeek+=file_info.size_file_comment - uSizeRead;
|
|
||||||
}
|
}
|
||||||
else
|
lSeek += file_info.size_file_comment - uSizeRead;
|
||||||
|
} else {
|
||||||
lSeek+=file_info.size_file_comment;
|
lSeek+=file_info.size_file_comment;
|
||||||
|
}
|
||||||
|
|
||||||
if ((err==UNZ_OK) && (pfile_info!=NULL))
|
if ((err==UNZ_OK) && (pfile_info!=NULL)) {
|
||||||
*pfile_info=file_info;
|
*pfile_info=file_info;
|
||||||
|
}
|
||||||
|
|
||||||
if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
|
if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) {
|
||||||
*pfile_info_internal=file_info_internal;
|
*pfile_info_internal=file_info_internal;
|
||||||
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -2153,15 +2162,17 @@ static int unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s, uInt* piSizeVar,
|
||||||
*psize_local_extrafield = 0;
|
*psize_local_extrafield = 0;
|
||||||
|
|
||||||
if (fseek(s->file, s->cur_file_info_internal.offset_curfile +
|
if (fseek(s->file, s->cur_file_info_internal.offset_curfile +
|
||||||
s->byte_before_the_zipfile,SEEK_SET)!=0)
|
s->byte_before_the_zipfile, SEEK_SET) != 0) {
|
||||||
return UNZ_ERRNO;
|
return UNZ_ERRNO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err == UNZ_OK) {
|
||||||
if (err==UNZ_OK)
|
if (unzlocal_getLong(s->file, &uMagic) != UNZ_OK) {
|
||||||
if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
|
|
||||||
err=UNZ_ERRNO;
|
err=UNZ_ERRNO;
|
||||||
else if (uMagic!=0x04034b50)
|
} else if (uMagic!=0x04034b50) {
|
||||||
err=UNZ_BADZIPFILE;
|
err=UNZ_BADZIPFILE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
|
if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
|
||||||
err=UNZ_ERRNO;
|
err=UNZ_ERRNO;
|
||||||
|
@ -2340,7 +2351,7 @@ extern int unzReadCurrentFile (unzFile file, void *buf, unsigned len)
|
||||||
return UNZ_PARAMERROR;
|
return UNZ_PARAMERROR;
|
||||||
|
|
||||||
|
|
||||||
if ((pfile_in_zip_read_info->read_buffer == NULL))
|
if (pfile_in_zip_read_info->read_buffer == NULL)
|
||||||
return UNZ_END_OF_LIST_OF_FILE;
|
return UNZ_END_OF_LIST_OF_FILE;
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2353,17 +2364,17 @@ extern int unzReadCurrentFile (unzFile file, void *buf, unsigned len)
|
||||||
pfile_in_zip_read_info->stream.avail_out =
|
pfile_in_zip_read_info->stream.avail_out =
|
||||||
(uInt)pfile_in_zip_read_info->rest_read_uncompressed;
|
(uInt)pfile_in_zip_read_info->rest_read_uncompressed;
|
||||||
|
|
||||||
while (pfile_in_zip_read_info->stream.avail_out>0)
|
while (pfile_in_zip_read_info->stream.avail_out > 0) {
|
||||||
{
|
|
||||||
if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
|
if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
|
||||||
(pfile_in_zip_read_info->rest_read_compressed>0))
|
(pfile_in_zip_read_info->rest_read_compressed > 0)) {
|
||||||
{
|
|
||||||
uInt uReadThis = UNZ_BUFSIZE;
|
uInt uReadThis = UNZ_BUFSIZE;
|
||||||
size_t gametype;
|
size_t gametype;
|
||||||
if (pfile_in_zip_read_info->rest_read_compressed<uReadThis) {
|
if (pfile_in_zip_read_info->rest_read_compressed<uReadThis) {
|
||||||
uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; }
|
uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; }
|
||||||
if (uReadThis == 0) {
|
if (uReadThis == 0) {
|
||||||
return UNZ_EOF; }
|
return UNZ_EOF;
|
||||||
|
}
|
||||||
if (s->cur_file_info.compressed_size == pfile_in_zip_read_info->rest_read_compressed) {
|
if (s->cur_file_info.compressed_size == pfile_in_zip_read_info->rest_read_compressed) {
|
||||||
if (fseek(pfile_in_zip_read_info->file,
|
if (fseek(pfile_in_zip_read_info->file,
|
||||||
pfile_in_zip_read_info->pos_in_zipfile +
|
pfile_in_zip_read_info->pos_in_zipfile +
|
||||||
|
@ -2379,8 +2390,9 @@ extern int unzReadCurrentFile (unzFile file, void *buf, unsigned len)
|
||||||
gametype = fread(pfile_in_zip_read_info->read_buffer,uReadThis,1,
|
gametype = fread(pfile_in_zip_read_info->read_buffer,uReadThis,1,
|
||||||
pfile_in_zip_read_info->file);
|
pfile_in_zip_read_info->file);
|
||||||
}
|
}
|
||||||
if (gametype!=1)
|
if (gametype!=1) {
|
||||||
return UNZ_ERRNO;
|
return UNZ_ERRNO;
|
||||||
|
}
|
||||||
pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
|
pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
|
||||||
|
|
||||||
pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
|
pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
|
||||||
|
@ -2390,8 +2402,7 @@ extern int unzReadCurrentFile (unzFile file, void *buf, unsigned len)
|
||||||
pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
|
pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pfile_in_zip_read_info->compression_method==0)
|
if (pfile_in_zip_read_info->compression_method==0) {
|
||||||
{
|
|
||||||
uInt uDoCopy,i ;
|
uInt uDoCopy,i ;
|
||||||
if (pfile_in_zip_read_info->stream.avail_out <
|
if (pfile_in_zip_read_info->stream.avail_out <
|
||||||
pfile_in_zip_read_info->stream.avail_in)
|
pfile_in_zip_read_info->stream.avail_in)
|
||||||
|
@ -2413,9 +2424,7 @@ extern int unzReadCurrentFile (unzFile file, void *buf, unsigned len)
|
||||||
pfile_in_zip_read_info->stream.next_in += uDoCopy;
|
pfile_in_zip_read_info->stream.next_in += uDoCopy;
|
||||||
pfile_in_zip_read_info->stream.total_out += uDoCopy;
|
pfile_in_zip_read_info->stream.total_out += uDoCopy;
|
||||||
iRead += uDoCopy;
|
iRead += uDoCopy;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
uLong uTotalOutBefore,uTotalOutAfter;
|
uLong uTotalOutBefore,uTotalOutAfter;
|
||||||
const Byte *bufBefore;
|
const Byte *bufBefore;
|
||||||
uLong uOutThis;
|
uLong uOutThis;
|
||||||
|
@ -2436,11 +2445,9 @@ extern int unzReadCurrentFile (unzFile file, void *buf, unsigned len)
|
||||||
uOutThis = uTotalOutAfter-uTotalOutBefore;
|
uOutThis = uTotalOutAfter-uTotalOutBefore;
|
||||||
|
|
||||||
pfile_in_zip_read_info->crc32 =
|
pfile_in_zip_read_info->crc32 =
|
||||||
crc32(pfile_in_zip_read_info->crc32,bufBefore,
|
crc32(pfile_in_zip_read_info->crc32, bufBefore, (uInt)(uOutThis));
|
||||||
(uInt)(uOutThis));
|
|
||||||
|
|
||||||
pfile_in_zip_read_info->rest_read_uncompressed -=
|
pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
|
||||||
uOutThis;
|
|
||||||
|
|
||||||
iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
|
iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue