1 /*---------------------------------------------------------------------*
2 Project:  TexConv
3 File:     input.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: input.cpp,v $
16  Revision 1.2  2008/05/23 04:16:03  iwai_yuma
17  Improved for handling of VC2005.
18 
19  Revision 1.1  2006/02/17 09:03:29  mitu
20  1st version
21 
22 
23     2     4/11/01 3:19p John
24     Updated header copyrights and pathname.
25 
26     1     12/03/99 3:48p Ryan
27 
28     1     10/12/99 7:47p Mikepc
29     renamed copy of io.cpp to resolve (io.h) name conflict.
30 
31     1     10/08/99 3:06p Mikepc
32     changed old .c to .cpp extension.  Required for use of tplConv.h
33     prototypes.
34 
35     1     10/08/99 3:01p Mikepc
36     changed old .c extension to .cpp to make this a cpp project.  This was
37     required for inclusion of tplConv.h prototypes
38 
39     7     8/26/99 11:36a Mikepc
40 
41     6     8/26/99 11:06a Mikepc
42     added batch file processing option to main
43 
44  $NoKeywords: $
45 
46 -----------------------------------------------------------------------*/
47 
48 
49 #include <stdio.h>
50 #include <string.h>
51 #include "input.h"
52 
53 //---------------------------------------------------------------------
54 
GetFileNames(char * inputFile,char * outputFile)55 int GetFileNames( char* inputFile, char* outputFile )
56 {
57 	char* inputPrompt  = "source file name:";
58 	char* outputPrompt = "destination file name:";
59 	int done;
60 
61 
62 	ShowConverterTitle();
63 
64 
65 	if( (done = GetFileName( inputPrompt, inputFile, SRC_TXT_FILE_SIZE )) == IO_QUIT )
66 	{
67 		return IO_QUIT;
68 	}
69 
70 	if( (done = GetFileName( outputPrompt, outputFile, DST_TPL_FILE_SIZE )) == IO_QUIT )
71 	{
72 		return IO_QUIT;
73 	}
74 
75 	return IO_DONE;
76 
77 }
78 
79 //---------------------------------------------------------------------
80 
ShowConverterTitle()81 void ShowConverterTitle()
82 {
83 
84 	printf(".tpl file converter.\n");
85 	printf("press 'q' anytime to quit.\n");
86 	printf("\n");
87 
88 }
89 
90 //---------------------------------------------------------------------
91 
92 // 'promptString' is one of "source file name:" or "dest. file name:"
GetFileName(char * promptString,char * fileName,const unsigned int bufSize)93 int GetFileName( char* promptString, char* fileName, const unsigned int bufSize )
94 {
95 	int done;
96 
97 
98 	// scan for fileName until user indicates done
99 	while(1)
100 	{
101 		printf("%s\n", promptString);
102 		printf("(include full path name, use '/' as separators)\n\n");
103 
104         gets_s( fileName, bufSize );
105 //		gets(fileName);
106 
107 		done = CheckYN(fileName);
108 
109 		if(done == IO_QUIT)
110 		{
111 			return IO_QUIT;
112 		}
113 		else if(done == IO_DONE)
114 		{
115 			return IO_DONE;
116 		}
117 
118 		//else (IO_NOT_DONE) continue to prompt until user is satisfied
119 
120 	}
121 
122 	return IO_DONE;
123 }
124 
125 
126 //---------------------------------------------------------------------
127 
CheckYN(char * fileName)128 int CheckYN( char* fileName )
129 {
130 	int check = 0;
131 	int done = IO_NOT_DONE;
132 	char yn[255];
133 
134 
135 	// first check if user entered 'q' for 'fileName
136 	if( ((check = strcmp( fileName, "q")) == 0) || ((check = strcmp( fileName, "Q")) == 0) )
137 	{
138 		return IO_QUIT;
139 	}
140 
141 	// prompt for 'yes', 'no', or 'quit'
142 	while(1)
143 	{
144 
145 		printf("is this correct? (y/n)\n");
146 
147 
148 		// check for quit
149 		if( ((check = strcmp( yn, "q")) == 0) || ((check = strcmp( yn, "Q")) == 0) )
150 		{
151 			return IO_QUIT;
152 		}
153 
154 		// check for yes
155 		else if( ((check = strcmp( yn, "y")) == 0) || ((check = strcmp( yn, "Y")) == 0) )
156 		{
157 			return IO_DONE;
158 		}
159 
160 		// check for no
161 		else if( ((check = strcmp( yn, "n")) == 0) || ((check = strcmp( yn, "N")) == 0) )
162 		{
163 			return IO_NOT_DONE;
164 		}
165 
166 		// invalid response- prompt again
167 		else
168 		{
169 			printf("your response must be one of 'y', 'n', or 'q'\n");
170 			continue;
171 		}
172 
173 	}
174 
175 	return IO_DONE;
176 }
177 
178 //---------------------------------------------------------------------
179