mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
fix a bunch of bugs with single-cpp processing when not keeping temps
This commit is contained in:
parent
598b16b78d
commit
1925bef0c1
3 changed files with 22 additions and 12 deletions
|
@ -37,7 +37,7 @@ struct dstring_s;
|
|||
void parse_cpp_name (void);
|
||||
void add_cpp_def (const char *arg);
|
||||
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);
|
||||
extern const char *cpp_name;
|
||||
extern struct dstring_s *tempname;
|
||||
|
|
|
@ -148,7 +148,8 @@ build_cpp_args (const char *in_name, const char *out_name)
|
|||
//============================================================================
|
||||
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
free (basename);
|
||||
} if (local) {
|
||||
char *temp2 = strrchr (this_program, PATH_SEPARATOR);
|
||||
dsprintf (ifile, "%sXXXXXX", temp2 ? temp2 + 1 : this_program);
|
||||
} else {
|
||||
const char *temp1 = getenv ("TMPDIR");
|
||||
char *temp2 = strrchr (this_program, PATH_SEPARATOR);
|
||||
|
@ -199,7 +203,7 @@ preprocess_file (const char *filename, const char *ext)
|
|||
#endif
|
||||
|
||||
if (cpp_name) {
|
||||
intermediate_file (tempname, filename, ext ? ext : "p");
|
||||
intermediate_file (tempname, filename, ext ? ext : "p", 0);
|
||||
build_cpp_args (filename, tempname->str);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -211,7 +215,7 @@ preprocess_file (const char *filename, const char *ext)
|
|||
if (tmp == NULL) {
|
||||
fprintf (stderr, "%s: qfcc was unable to open\n",
|
||||
tempname->str);
|
||||
exit(1);
|
||||
return 0;
|
||||
}
|
||||
fclose (tmp);
|
||||
}
|
||||
|
@ -232,7 +236,7 @@ preprocess_file (const char *filename, const char *ext)
|
|||
fprintf (stderr, "%s: cpp returned error code %d\n",
|
||||
filename,
|
||||
status);
|
||||
exit (1);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,7 +249,7 @@ preprocess_file (const char *filename, const char *ext)
|
|||
|
||||
if ((pid = fork ()) == -1) {
|
||||
perror ("fork");
|
||||
exit (1);
|
||||
return 0;
|
||||
}
|
||||
if (!pid) {
|
||||
// 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 == -1) {
|
||||
perror ("wait");
|
||||
exit (1);
|
||||
return 0;
|
||||
}
|
||||
fprintf (stderr, "%s: The wrong child (%ld) died. Don't ask me, I don't know either.\n",
|
||||
this_program,
|
||||
(long) rc);
|
||||
exit (1);
|
||||
return 0;
|
||||
}
|
||||
if (WIFEXITED (status)) {
|
||||
if (WEXITSTATUS (status)) {
|
||||
fprintf (stderr, "%s: cpp returned error code %d\n",
|
||||
filename,
|
||||
WEXITSTATUS (status));
|
||||
exit (1);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
fprintf (stderr, "%s: cpp returned prematurely.\n", filename);
|
||||
exit (1);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (options.preprocess_only)
|
||||
|
|
|
@ -667,6 +667,12 @@ load_file (const char *fname)
|
|||
src[Qfilesize (file)] = 0;
|
||||
Qread (file, src, Qfilesize (file));
|
||||
Qclose (file);
|
||||
if (cpp_name && (!options.save_temps)) {
|
||||
if (unlink (tempname->str)) {
|
||||
perror ("unlink");
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
return src;
|
||||
}
|
||||
|
||||
|
@ -735,13 +741,13 @@ progs_src_compile (void)
|
|||
dsprintf (filename, "%s", progs_src);
|
||||
|
||||
if (options.single_cpp) {
|
||||
intermediate_file (single_name, filename->str, "i2");
|
||||
intermediate_file (single_name, filename->str, "i2", 1);
|
||||
if (!options.save_temps) {
|
||||
#ifdef _WIN32
|
||||
mktemp (single_name->str);
|
||||
#else
|
||||
int tempfd = mkstemp (single_name->str);
|
||||
single = fdopen (tempfd, "rt");
|
||||
single = fdopen (tempfd, "wt");
|
||||
#endif
|
||||
}
|
||||
if (!single)
|
||||
|
|
Loading…
Reference in a new issue