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