aboutsummaryrefslogtreecommitdiff
path: root/tool_src/BspLib/BspTool.cpp
blob: 23bcb8d52962a88f26275efdb49d34ccce17871e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//-----------------------------------------------------------------------------
//	BSPLIB MODULE: BspTool.cpp
//
//  Copyright (c) 1997 by Markus Hadwiger
//  All Rights Reserved.
//-----------------------------------------------------------------------------

// bsplib header files
#include "BspTool.h"

// flags
#define STRIP_PATH


BSPLIB_NAMESPACE_BEGIN


// create new string with altered extension -----------------------------------
//
String BspTool::ChangeExtension( const char *filename, const char *extension )
{
	if ( ( filename == NULL ) || ( extension == NULL ) )
		return String( NULL );

	int		len   = strlen( filename );
	int		pos	  = len;
	char	*name = NULL;
	const char *scan = filename + pos;

	while ( ( --pos > 0 ) && ( *--scan != '.' ) ) ;

	if ( pos > 0 ) {
		// change extension if there was an extension
		name = new char[ pos + strlen( extension ) + 1 ];
		strncpy( name, filename, pos );
		strcpy( name + pos, extension );
	} else {
		// append new extension if there was no extension
		name = new char[ len + strlen( extension ) + 1 ];
		strcpy( name, filename );
		strcpy( name + len, extension );
	}

#ifdef STRIP_PATH
	String ret( SkipPath( name ) );
#else
	String ret( name );
#endif

	delete name;
	return ret;
}


// create filename without path -----------------------------------------------
//
const String BspTool::SkipPath( const char *fullname )
{
	const char *scan = fullname + strlen( fullname ) - 1;
	while ( ( *scan != '\\' ) && ( *scan != ':' ) && ( scan >= fullname ) )
		scan--;
	return String( scan + 1 );
}


BSPLIB_NAMESPACE_END

//-----------------------------------------------------------------------------