fix a bunch of bugs with single-cpp processing when not keeping temps

This commit is contained in:
Bill Currie 2006-08-20 06:20:30 +00:00 committed by Jeff Teunissen
parent 598b16b78d
commit 1925bef0c1
3 changed files with 22 additions and 12 deletions

View file

@ -37,7 +37,7 @@ struct dstring_s;
void parse_cpp_name (void); void parse_cpp_name (void);
void add_cpp_def (const char *arg); void add_cpp_def (const char *arg);
void intermediate_file (struct dstring_s *ifile, const char *filename, void intermediate_file (struct dstring_s *ifile, const char *filename,
const char *ext); const char *ext, int local);
FILE * preprocess_file (const char *filename, const char *ext); FILE * preprocess_file (const char *filename, const char *ext);
extern const char *cpp_name; extern const char *cpp_name;
extern struct dstring_s *tempname; extern struct dstring_s *tempname;

View file

@ -148,7 +148,8 @@ build_cpp_args (const char *in_name, const char *out_name)
//============================================================================ //============================================================================
void void
intermediate_file (dstring_t *ifile, const char *filename, const char *ext) intermediate_file (dstring_t *ifile, const char *filename, const char *ext,
int local)
{ {
if (options.save_temps) { if (options.save_temps) {
char *basename = strdup (filename); char *basename = strdup (filename);
@ -174,6 +175,9 @@ intermediate_file (dstring_t *ifile, const char *filename, const char *ext)
dsprintf (ifile, "%s.%s", temp, ext); dsprintf (ifile, "%s.%s", temp, ext);
} }
free (basename); free (basename);
} if (local) {
char *temp2 = strrchr (this_program, PATH_SEPARATOR);
dsprintf (ifile, "%sXXXXXX", temp2 ? temp2 + 1 : this_program);
} else { } else {
const char *temp1 = getenv ("TMPDIR"); const char *temp1 = getenv ("TMPDIR");
char *temp2 = strrchr (this_program, PATH_SEPARATOR); char *temp2 = strrchr (this_program, PATH_SEPARATOR);
@ -199,7 +203,7 @@ preprocess_file (const char *filename, const char *ext)
#endif #endif
if (cpp_name) { if (cpp_name) {
intermediate_file (tempname, filename, ext ? ext : "p"); intermediate_file (tempname, filename, ext ? ext : "p", 0);
build_cpp_args (filename, tempname->str); build_cpp_args (filename, tempname->str);
#ifdef _WIN32 #ifdef _WIN32
@ -211,7 +215,7 @@ preprocess_file (const char *filename, const char *ext)
if (tmp == NULL) { if (tmp == NULL) {
fprintf (stderr, "%s: qfcc was unable to open\n", fprintf (stderr, "%s: qfcc was unable to open\n",
tempname->str); tempname->str);
exit(1); return 0;
} }
fclose (tmp); fclose (tmp);
} }
@ -232,7 +236,7 @@ preprocess_file (const char *filename, const char *ext)
fprintf (stderr, "%s: cpp returned error code %d\n", fprintf (stderr, "%s: cpp returned error code %d\n",
filename, filename,
status); status);
exit (1); return 0;
} }
} }
@ -245,7 +249,7 @@ preprocess_file (const char *filename, const char *ext)
if ((pid = fork ()) == -1) { if ((pid = fork ()) == -1) {
perror ("fork"); perror ("fork");
exit (1); return 0;
} }
if (!pid) { if (!pid) {
// we're a child, check for abuse // we're a child, check for abuse
@ -267,23 +271,23 @@ preprocess_file (const char *filename, const char *ext)
if ((rc = waitpid (0, &status, 0 | WUNTRACED)) != pid) { if ((rc = waitpid (0, &status, 0 | WUNTRACED)) != pid) {
if (rc == -1) { if (rc == -1) {
perror ("wait"); perror ("wait");
exit (1); return 0;
} }
fprintf (stderr, "%s: The wrong child (%ld) died. Don't ask me, I don't know either.\n", fprintf (stderr, "%s: The wrong child (%ld) died. Don't ask me, I don't know either.\n",
this_program, this_program,
(long) rc); (long) rc);
exit (1); return 0;
} }
if (WIFEXITED (status)) { if (WIFEXITED (status)) {
if (WEXITSTATUS (status)) { if (WEXITSTATUS (status)) {
fprintf (stderr, "%s: cpp returned error code %d\n", fprintf (stderr, "%s: cpp returned error code %d\n",
filename, filename,
WEXITSTATUS (status)); WEXITSTATUS (status));
exit (1); return 0;
} }
} else { } else {
fprintf (stderr, "%s: cpp returned prematurely.\n", filename); fprintf (stderr, "%s: cpp returned prematurely.\n", filename);
exit (1); return 0;
} }
} }
if (options.preprocess_only) if (options.preprocess_only)

View file

@ -667,6 +667,12 @@ load_file (const char *fname)
src[Qfilesize (file)] = 0; src[Qfilesize (file)] = 0;
Qread (file, src, Qfilesize (file)); Qread (file, src, Qfilesize (file));
Qclose (file); Qclose (file);
if (cpp_name && (!options.save_temps)) {
if (unlink (tempname->str)) {
perror ("unlink");
exit (1);
}
}
return src; return src;
} }
@ -735,13 +741,13 @@ progs_src_compile (void)
dsprintf (filename, "%s", progs_src); dsprintf (filename, "%s", progs_src);
if (options.single_cpp) { if (options.single_cpp) {
intermediate_file (single_name, filename->str, "i2"); intermediate_file (single_name, filename->str, "i2", 1);
if (!options.save_temps) { if (!options.save_temps) {
#ifdef _WIN32 #ifdef _WIN32
mktemp (single_name->str); mktemp (single_name->str);
#else #else
int tempfd = mkstemp (single_name->str); int tempfd = mkstemp (single_name->str);
single = fdopen (tempfd, "rt"); single = fdopen (tempfd, "wt");
#endif #endif
} }
if (!single) if (!single)