@@ -30,8 +30,9 @@ int savelines[MAXINCBASIC];
3030char savelinesname [MAXINCBASIC ][MAXINCBASIC ];
3131
3232extern char stdoutfilename [256 ];
33- extern FILE * stdoutfilepointer ;
3433extern FILE * preprocessedfd ;
34+ extern FILE * main_asm_fp ;
35+ extern FILE * current_output_fp ;
3536extern char backupname [256 ];
3637extern int maxpasses ;
3738
@@ -1316,8 +1317,13 @@ void dmahole (char **statement)
13161317 if (requestedhole > 0 )
13171318 printf ("DMAHOLEEND%d SET .\n" , requestedhole - 1 );
13181319
1320+ fflush (current_output_fp );
1321+ if (current_output_fp != main_asm_fp )
1322+ fclose (current_output_fp );
1323+
13191324 sprintf (stdoutfilename , "7800hole.%d.asm" , requestedhole );
1320- if ((stdoutfilepointer = freopen (stdoutfilename , "w" , stdout )) == NULL )
1325+ current_output_fp = fopen (stdoutfilename , "w" );
1326+ if (current_output_fp == NULL )
13211327 {
13221328 prerror ("couldn't create the %s file" , stdoutfilename );
13231329 }
@@ -4964,15 +4970,10 @@ void barf_graphic_file (void)
49644970 printf ("DMAHOLEEND%d SET .\n" , currentdmahole );
49654971
49664972 //if stdout is redirected, its time change it back to 7800.asm
4967- if (strcmp (stdoutfilename , "7800.asm" ) != 0 )
4968- {
4969- strcpy (stdoutfilename , "7800.asm" );
4970- if ((stdoutfilepointer = freopen (stdoutfilename , "a" , stdout )) == NULL )
4971- {
4972- prerror ("couldn't reopen the 7800.asm file" );
4973- }
4974- }
4975-
4973+ fflush (current_output_fp );
4974+ if (current_output_fp != main_asm_fp )
4975+ fclose (current_output_fp );
4976+ current_output_fp = main_asm_fp ;
49764977
49774978 ADDRBASE = BANKSTART - (dmaplain * DMASIZE );
49784979
@@ -5250,7 +5251,7 @@ void barf_graphic_file (void)
52505251 prout (" DMA hole code found and imported\n" );
52515252 int c ;
52525253 while ((c = getc (holefilepointer )) != EOF )
5253- putchar ( c );
5254+ printf ( "%c" , c );
52545255 fclose (holefilepointer );
52555256 remove (holefilename );
52565257 }
@@ -12268,4 +12269,18 @@ void lastrites()
1226812269 remove ("7800hole.0.asm" );
1226912270 remove ("7800hole.1.asm" );
1227012271 remove ("7800hole.2.asm" );
12272+
12273+ // Close all our managed file pointers
12274+ if (current_output_fp != NULL )
12275+ {
12276+ fflush (current_output_fp );
12277+ if (current_output_fp != main_asm_fp )
12278+ fclose (current_output_fp );
12279+ current_output_fp = NULL ;
12280+ }
12281+ if (main_asm_fp != NULL )
12282+ {
12283+ fclose (main_asm_fp );
12284+ main_asm_fp = NULL ;
12285+ }
1227112286}
0 commit comments