File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -180,6 +180,16 @@ static void reopen_stderr(const char *fname)
180180 }
181181}
182182
183+ static void reopen_stdin (const char * fname )
184+ {
185+ if (!fname || !* fname )
186+ fname = "autoscript" ;
187+ if (freopen (fname , "r" , stdin ) != stdin ) {
188+ fprintf (stderr , "Error opening '%s': %s\n" , fname , strerror (errno ));
189+ exit (1 );
190+ }
191+ }
192+
183193static char * get_input (void )
184194{
185195 static char input [256 ];
@@ -221,10 +231,7 @@ int main(int argc, const char **argv)
221231 } else if (!strncmp (argv [i ], "-w" , 2 )) {
222232 opt_width = atoi (argv [i ] + 2 );
223233 } else if (!strncmp (argv [i ], "-i" , 2 )) {
224- if (freopen (argv [i ] + 2 , "r" , stdin ) != stdin ) {
225- fprintf (stderr , "Error opening '%s': %s\n" , argv [i ] + 2 , strerror (errno ));
226- exit (1 );
227- }
234+ reopen_stdin (argv [i ] + 2 );
228235 } else if (!game ) {
229236 game = argv [i ];
230237 }
You can’t perform that action at this time.
0 commit comments