wrc: Move temp file management from wpp directly into the load_file function.

This commit is contained in:
Alexandre Julliard 2010-03-30 15:33:54 +02:00
parent 74ad854e41
commit cb9be96437
1 changed files with 33 additions and 23 deletions

View File

@ -256,40 +256,50 @@ static int load_file( const char *input_name, const char *output_name )
/* Run the preprocessor on the input */ /* Run the preprocessor on the input */
if(!no_preprocess) if(!no_preprocess)
{ {
FILE *output;
int ret, fd;
char *name;
/* /*
* Preprocess the input to a temp-file, or stdout if * Preprocess the input to a temp-file, or stdout if
* no output was given. * no output was given.
*/ */
chat("Starting preprocess\n"); if (preprocess_only)
if (!preprocess_only)
{ {
ret = wpp_parse_temp( input_name, output_name, &temp_name ); if (output_name)
}
else if (output_name)
{ {
FILE *output;
if (!(output = fopen( output_name, "w" ))) if (!(output = fopen( output_name, "w" )))
fatal_perror( "Could not open %s for writing", output_name ); fatal_perror( "Could not open %s for writing", output_name );
ret = wpp_parse( input_name, output ); ret = wpp_parse( input_name, output );
fclose( output ); fclose( output );
} }
else else ret = wpp_parse( input_name, stdout );
{
ret = wpp_parse( input_name, stdout );
}
if (ret) return ret; if (ret) return ret;
if(preprocess_only)
{
output_name = NULL; output_name = NULL;
exit(0); exit(0);
} }
input_name = temp_name; if (output_name && output_name[0])
{
name = xmalloc( strlen(output_name) + 8 );
strcpy( name, output_name );
strcat( name, ".XXXXXX" );
}
else name = xstrdup( "wrc.XXXXXX" );
if ((fd = mkstemps( name, 0 )) == -1)
error("Could not generate a temp name from %s\n", name);
temp_name = name;
if (!(output = fdopen(fd, "wt")))
error("Could not open fd %s for writing\n", name);
ret = wpp_parse( input_name, output );
fclose( output );
if (ret) return ret;
input_name = name;
} }
/* Reset the language */ /* Reset the language */