1 /*---------------------------------------------------------------------*
2 Project: tc library
3 File: TCVerify.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: TCVerify.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 3 4/11/01 3:08p John
24 Updated header copyrights and pathname.
25
26 2 3/17/00 1:19p Mikepc
27 change tc to use indices numbered from 0.
28
29 1 12/03/99 3:45p Ryan
30
31 3 10/08/99 2:45p Mikepc
32 update for tplConv portability: altered data structures, replaced
33 references to 'read tga code' with ' *fileFn, removed redundant
34 functions. Changed some file conversion paths.
35
36 2 9/16/99 8:47p Mikepc
37 updated code for auto-palette generation
38
39 1 9/02/99 10:57a Mikepc
40 contains code for VerifyLists() ( formerly in convert.cpp ) that checks
41 list contents against each other and against real files
42
43 $NoKeywords: $
44
45 -----------------------------------------------------------------------*/
46
47 #include <stdio.h>
48
49 #include <charPipeline/tc/TCCommon.h>
50
51 #include "TCVerify.h"
52 #include "TCPaletteList.h"
53 #include "TCImageList.h"
54 #include "TCSrcImageList.h"
55 #include "TCTextureList.h"
56
57 #pragma warning(disable : 4996)
58
59 /*>*******************************(*)*******************************<*/
60 static void TCSortListsByIndex ( void );
61
62 /*>*******************************(*)*******************************<*/
63 // compare SiHead, ImHead, PlHead, TxHead lists to ensure that all index
64 // references are valid
65 /*>*******************************(*)*******************************<*/
TCVerifyLists(void)66 void TCVerifyLists ( void )
67 {
68 TCSrcImage* siPtr = SiHead;
69 TCImage* imPtr = ImHead;
70 TCPalette* plPtr = PlHead;
71 TCTexture* txPtr = TxHead;
72 FILE* fp;
73
74
75 // sort each of SiHead, ImHead, PlHead, TxHead in ascending order
76 TCSortListsByIndex();
77
78 // verify that each source image exists
79 // note: extensions will be checked when files are opened for conversion
80 while( siPtr )
81 {
82 if( (fp = fopen( siPtr->fileName, "rb" )) == NULL )
83 {
84 TCErrorMsg( "TCVerifyLists: unable to open file %s for read\n", siPtr->fileName );
85 return;
86 }
87 fclose( fp );
88 siPtr = siPtr->next;
89 }
90
91 // verify that each image has a corresponding source image
92 while( imPtr )
93 {
94 // find the source image corresponding to the color index
95 // color layer is mandatory
96 if( (siPtr = TCFindSrcImageByIndex( imPtr->colorSrcImage )) == NULL )
97 {
98 TCErrorMsg( "TCVerifyLists: no matching source image for image %d color layer\n", imPtr->index );
99 return;
100 }
101
102 // alpha layer is optional
103 if( imPtr->alphaSrcImage != TC_UNUSED )
104 {
105 if( (siPtr = TCFindSrcImageByIndex( imPtr->alphaSrcImage )) == NULL )
106 {
107 TCErrorMsg( "TCVerifyLists: no matching source image for image %d alpha layer\n", imPtr->index );
108 return;
109 }
110 }
111
112 imPtr = imPtr->next;
113
114 } // end while( imPtr )
115
116
117 // verify each palette
118 while( plPtr )
119 {
120 // find the source image corresponding to the palette image index
121 if( (siPtr = TCFindSrcImageByIndex( plPtr->srcImage )) == NULL )
122 {
123 TCErrorMsg( "TCVerifyLists: no matching source image for palette %d srcImage\n", plPtr->index);
124 return;
125 }
126 plPtr = plPtr->next;
127
128 } // end while( plPtr )
129
130
131 // verify each texture
132 txPtr = TxHead;
133 while( txPtr )
134 {
135 // texture->image is mandatory
136 if( (imPtr = TCFindImageByIndex( txPtr->image )) == NULL )
137 {
138 TCErrorMsg( "TCVerifyLists: no matching image for texture %d\n", txPtr->index);
139 return;
140 }
141
142 // palette is optional
143 if( txPtr->palette != TC_UNUSED )
144 {
145 if( (plPtr = TCFindPaletteByIndex( txPtr->palette )) == NULL )
146 {
147 TCErrorMsg( "TCVerifyLists: no matching palette for texture %d\n", txPtr->index);
148 return;
149 }
150 }
151
152 txPtr = txPtr->next;
153 } // end while( txPtr )
154 }
155
156 /*>*******************************(*)*******************************<*/
157 // sort SiHead, ImHead, PlHead, TxHead into ascending order
158 /*>*******************************(*)*******************************<*/
TCSortListsByIndex(void)159 static void TCSortListsByIndex ( void )
160 {
161 TCSortSrcImageByIndex();
162 TCSortImageByIndex();
163 TCSortPaletteByIndex();
164 TCSortTextureByIndex();
165 }
166
167 /*>*******************************(*)*******************************<*/
168