uncrustify! now the code is only ugly on the *inside*
This commit is contained in:
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
Copyright (c) 2001, Loki software, inc.
|
||||
All rights reserved.
|
||||
Copyright (c) 2001, Loki software, inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
Neither the name of Loki software nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without specific prior
|
||||
written permission.
|
||||
Neither the name of Loki software nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
//
|
||||
// Missing functions
|
||||
@@ -37,7 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "missing.h"
|
||||
#include "qsysprintf.h"
|
||||
|
||||
#if defined (__linux__) || defined (__APPLE__)
|
||||
#if defined ( __linux__ ) || defined ( __APPLE__ )
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@@ -47,42 +47,44 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
|
||||
bool radCopyFile(const char *lpExistingFileName, const char *lpNewFileName)
|
||||
{
|
||||
FILE *src, *dst;
|
||||
void* buf;
|
||||
int l;
|
||||
bool ret = false;
|
||||
char realsrc[PATH_MAX], realdest[PATH_MAX];
|
||||
bool radCopyFile( const char *lpExistingFileName, const char *lpNewFileName ){
|
||||
FILE *src, *dst;
|
||||
void* buf;
|
||||
int l;
|
||||
bool ret = false;
|
||||
char realsrc[PATH_MAX], realdest[PATH_MAX];
|
||||
|
||||
realpath (lpExistingFileName, realsrc);
|
||||
realpath (lpNewFileName, realdest);
|
||||
realpath( lpExistingFileName, realsrc );
|
||||
realpath( lpNewFileName, realdest );
|
||||
|
||||
src = fopen (realsrc, "rb");
|
||||
if ( !src ) {
|
||||
return false;
|
||||
}
|
||||
dst = fopen (realdest, "wb");
|
||||
if (!dst) {
|
||||
fclose (src);
|
||||
return false;
|
||||
}
|
||||
src = fopen( realsrc, "rb" );
|
||||
if ( !src ) {
|
||||
return false;
|
||||
}
|
||||
dst = fopen( realdest, "wb" );
|
||||
if ( !dst ) {
|
||||
fclose( src );
|
||||
return false;
|
||||
}
|
||||
|
||||
fseek (src, 0, SEEK_END);
|
||||
l = ftell (src);
|
||||
rewind (src);
|
||||
buf = g_malloc (l);
|
||||
fseek( src, 0, SEEK_END );
|
||||
l = ftell( src );
|
||||
rewind( src );
|
||||
buf = g_malloc( l );
|
||||
|
||||
if (buf != NULL)
|
||||
if (fread (buf, l, 1, src) == 1)
|
||||
if (fwrite (buf, l, 1, dst) == 1)
|
||||
ret = true;
|
||||
if ( buf != NULL ) {
|
||||
if ( fread( buf, l, 1, src ) == 1 ) {
|
||||
if ( fwrite( buf, l, 1, dst ) == 1 ) {
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_free (buf);
|
||||
fclose (src);
|
||||
fclose (dst);
|
||||
g_free( buf );
|
||||
fclose( src );
|
||||
fclose( dst );
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool radCreateDirectory( const char *directory ) {
|
||||
@@ -93,46 +95,44 @@ bool radCreateDirectory( const char *directory ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int GetFullPathName(const char *lpFileName, int nBufferLength, char *lpBuffer, char **lpFilePart)
|
||||
{
|
||||
if (lpFileName[0] == '/')
|
||||
{
|
||||
strcpy (lpBuffer, lpFileName);
|
||||
*lpFilePart = strrchr (lpBuffer, '/');
|
||||
return strlen (lpBuffer);
|
||||
}
|
||||
int GetFullPathName( const char *lpFileName, int nBufferLength, char *lpBuffer, char **lpFilePart ){
|
||||
if ( lpFileName[0] == '/' ) {
|
||||
strcpy( lpBuffer, lpFileName );
|
||||
*lpFilePart = strrchr( lpBuffer, '/' );
|
||||
return strlen( lpBuffer );
|
||||
}
|
||||
|
||||
if (getcwd (lpBuffer, nBufferLength) == NULL)
|
||||
return 0;
|
||||
if ( getcwd( lpBuffer, nBufferLength ) == NULL ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcat (lpBuffer, "/");
|
||||
*lpFilePart = lpBuffer + strlen (lpBuffer);
|
||||
strcat (lpBuffer, lpFileName);
|
||||
strcat( lpBuffer, "/" );
|
||||
*lpFilePart = lpBuffer + strlen( lpBuffer );
|
||||
strcat( lpBuffer, lpFileName );
|
||||
|
||||
char *scr = lpBuffer, *dst = lpBuffer;
|
||||
for (int i = 0; (i < nBufferLength) && (*scr != 0); i++)
|
||||
{
|
||||
if (*scr == '/' && *(scr+1) == '.' && *(scr+2) == '.')
|
||||
{
|
||||
scr += 4;
|
||||
while (dst != lpBuffer && *dst != '/')
|
||||
{
|
||||
dst--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
char *scr = lpBuffer, *dst = lpBuffer;
|
||||
for ( int i = 0; ( i < nBufferLength ) && ( *scr != 0 ); i++ )
|
||||
{
|
||||
if ( *scr == '/' && *( scr + 1 ) == '.' && *( scr + 2 ) == '.' ) {
|
||||
scr += 4;
|
||||
while ( dst != lpBuffer && *dst != '/' )
|
||||
{
|
||||
dst--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
*dst = *scr;
|
||||
*dst = *scr;
|
||||
|
||||
scr++; dst++;
|
||||
}
|
||||
*dst = 0;
|
||||
scr++; dst++;
|
||||
}
|
||||
*dst = 0;
|
||||
|
||||
return strlen (lpBuffer);
|
||||
return strlen( lpBuffer );
|
||||
}
|
||||
|
||||
EPathCheck CheckFile( const char *path ) {
|
||||
struct stat sbuf;
|
||||
struct stat sbuf;
|
||||
if ( stat( path, &sbuf ) == -1 ) {
|
||||
return PATH_FAIL;
|
||||
}
|
||||
@@ -156,12 +156,14 @@ FindFiles::~FindFiles() {
|
||||
const char* FindFiles::NextFile() {
|
||||
struct dirent *d;
|
||||
|
||||
if ( findHandle == NULL )
|
||||
if ( findHandle == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
d = readdir( findHandle );
|
||||
if ( d )
|
||||
if ( d ) {
|
||||
return d->d_name;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -170,9 +172,9 @@ const char* FindFiles::NextFile() {
|
||||
FindFiles::FindFiles( const char *_directory ) {
|
||||
char endChar;
|
||||
directory = _directory;
|
||||
if (directory.GetLength() > 0) {
|
||||
endChar = directory.GetAt(directory.GetLength() - 1);
|
||||
if (!(endChar == '/' || endChar == '\\')) {
|
||||
if ( directory.GetLength() > 0 ) {
|
||||
endChar = directory.GetAt( directory.GetLength() - 1 );
|
||||
if ( !( endChar == '/' || endChar == '\\' ) ) {
|
||||
// We're only using '/' as the path separator throughout this code, not '\'.
|
||||
// However, I'd hate to see the code silently fail due to a trailing '\', so
|
||||
// I added the check for it.
|
||||
@@ -228,10 +230,10 @@ bool radCopyFile( const char *lpExistingFileName, const char *lpNewFileName ) {
|
||||
#endif
|
||||
|
||||
bool CopyTree( const char *source, const char *dest ) {
|
||||
Str srcEntry;
|
||||
Str dstEntry;
|
||||
const char *dirname;
|
||||
FindFiles fileScan( source );
|
||||
Str srcEntry;
|
||||
Str dstEntry;
|
||||
const char *dirname;
|
||||
FindFiles fileScan( source );
|
||||
|
||||
while ( ( dirname = fileScan.NextFile() ) != NULL ) {
|
||||
if ( strcmp( dirname, "." ) == 0 || strcmp( dirname, ".." ) == 0 ) {
|
||||
@@ -247,28 +249,28 @@ bool CopyTree( const char *source, const char *dest ) {
|
||||
dstEntry += "/";
|
||||
dstEntry += dirname;
|
||||
switch ( CheckFile( srcEntry.GetBuffer() ) ) {
|
||||
case PATH_DIRECTORY: {
|
||||
if ( CheckFile( dstEntry.GetBuffer() ) == PATH_FAIL ) {
|
||||
if ( !radCreateDirectory( dstEntry.GetBuffer() ) ) {
|
||||
Sys_Printf( "create directory %s failed\n", dstEntry.GetBuffer() );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool ret;
|
||||
ret = CopyTree( srcEntry.GetBuffer(), dstEntry.GetBuffer() );
|
||||
if ( !ret ) {
|
||||
case PATH_DIRECTORY: {
|
||||
if ( CheckFile( dstEntry.GetBuffer() ) == PATH_FAIL ) {
|
||||
if ( !radCreateDirectory( dstEntry.GetBuffer() ) ) {
|
||||
Sys_Printf( "create directory %s failed\n", dstEntry.GetBuffer() );
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PATH_FILE: {
|
||||
Sys_Printf( "copy %s -> %s\n", srcEntry.GetBuffer(), dstEntry.GetBuffer() );
|
||||
bool ret = radCopyFile( srcEntry.GetBuffer(), dstEntry.GetBuffer() );
|
||||
if ( !ret ) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
bool ret;
|
||||
ret = CopyTree( srcEntry.GetBuffer(), dstEntry.GetBuffer() );
|
||||
if ( !ret ) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PATH_FILE: {
|
||||
Sys_Printf( "copy %s -> %s\n", srcEntry.GetBuffer(), dstEntry.GetBuffer() );
|
||||
bool ret = radCopyFile( srcEntry.GetBuffer(), dstEntry.GetBuffer() );
|
||||
if ( !ret ) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user