1 /*---------------------------------------------------------------------*
2 Project:  tc library
3 File:     TCCommon.cpp
4 
5 Copyright 1998-2001 Nintendo.  All rights reserved.
6 
7 These coded instructions, statements and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law.  They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12 
13 Change History:
14 
15  $Log: TCCommon.cpp,v $
16  Revision 1.2  2008/05/23 04:26:10  iwai_yuma
17  Improved for handling of VC2005.
18 
19  Revision 1.1  2006/02/17 09:01:53  mitu
20  1st version
21 
22 
23     5     4/11/01 3:08p John
24     Updated header copyrights and pathname.
25 
26     4     8/10/00 6:01p Mikepc
27     removed redundant #include<assert.h>,
28     changed any remaining asserts to TCAssertMsg
29 
30     3     3/17/00 1:19p Mikepc
31     change tc to use indices numbered from 0.
32 
33     2     12/06/99 1:32p Mikepc
34     removed #ifdef INTRACTIVE from ErrorMsg() code so the user always sees
35     the error message before the program quits.
36 
37     1     12/03/99 3:45p Ryan
38 
39     14    11/16/99 12:01p Yasu
40     Add #ifdef INTERACTIVE
41 
42     13    11/16/99 9:41a Yasu
43     Delete waiting key input in ErrorMsg
44 
45     12    10/12/99 8:00p Mikepc
46     changed include paths to vcc (tools/options) relative.
47 
48     11    10/08/99 2:45p Mikepc
49     update for tplConv portability: altered data structures, replaced
50     references to 'read tga code' with ' *fileFn, removed redundant
51     functions.  Changed some file conversion paths.
52 
53     10    9/16/99 8:47p Mikepc
54     updated code for auto-palette generation
55 
56     9     8/26/99 4:59p Mikepc
57     renamed file extensions from .c to .cpp.
58     .cpp extension allows addition of namespace protection to remove
59     potential name collisions with tool code.  Exceptions are CreateTplFile
60     and QuickConvert.  These are extern "C" linked.
61 
62     8     8/26/99 11:38a Mikepc
63 
64     7     8/26/99 11:03a Mikepc
65     tplCon rewrite for efficient memory usage, batch file processing
66     ability.
67 
68  $NoKeywords: $
69 
70 -----------------------------------------------------------------------*/
71 
72 
73 // common functions referenced by a number of source files
74 
75 #include <stdio.h>
76 #include <stdlib.h>
77 #include <locale>
78 
79 #include <charPipeline/tc/TCCommon.h>
80 
81 #include "TCImageList.h"
82 #include "TCPaletteList.h"
83 #include "TCSrcImageList.h"
84 #include "TCTextureList.h"
85 #include "TCMem.h"
86 
87 #pragma warning(disable : 4996)
88 
89 /*>*******************************(*)*******************************<*/
TCErrorMsg(char * msg,...)90 void TCErrorMsg( char* msg, ... )
91 {
92 	va_list argPtr;
93 	char dummy[255];
94 
95 
96 	printf("error:\n");
97 
98 	va_start( argPtr, msg    );
99 	vprintf(  msg,    argPtr );
100 	va_end(   argPtr         );
101 
102 	// free all of the app's allocated memory
103 	TCFreeMem();
104 
105 	// give the user a chance to read the error message
106 	printf( "press <enter> to quit\n" );
107 	gets( dummy );
108 
109 	exit(1);
110 }
111 
112 /*>*******************************(*)*******************************<*/
113 // if 'test' is false,
114 // print a 'printf' style message, free all of the app's allocated
115 // memory and quit the program.
116 /*>*******************************(*)*******************************<*/
TCAssertMsg(int exp,char * msg,...)117 void TCAssertMsg( int exp, char* msg, ... )
118 {
119 	va_list argPtr;
120 	char    dummy[255];
121 
122 
123     if( !exp )
124     {
125     	printf("error:\n");
126 
127     	va_start( argPtr, msg    );
128     	vprintf(  msg,    argPtr );
129     	va_end(   argPtr         );
130 
131     	// free all of the app's allocated memory
132     	TCFreeMem();
133 
134     	// give the user a chance to read the error message
135     	printf( "press <enter> to quit\n" );
136     	gets( dummy );
137 
138     	exit(1);
139     }
140 }
141 
142 /*>*******************************(*)*******************************<*/
143 // transform all characters of a string to uppercase
144 /*>*******************************(*)*******************************<*/
TCStrToUpper(char * str)145 void TCStrToUpper( char* str )
146 {
147     int c;
148     char* cPtr;
149 
150 
151     cPtr = str;
152     while( *cPtr != '\0' )
153     {
154         c = toupper( (int)(*cPtr) );
155 
156         *cPtr++ = (char)c;
157     }
158 }
159 
160 /*>*******************************(*)*******************************<*/