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