|
@@ -15,6 +15,7 @@
|
|
#include <stdarg.h>
|
|
#include <stdarg.h>
|
|
#include <time.h>
|
|
#include <time.h>
|
|
#include <math.h>
|
|
#include <math.h>
|
|
|
|
+#include <unistd.h>
|
|
|
|
|
|
#include <grass/gis.h>
|
|
#include <grass/gis.h>
|
|
#include <grass/glocale.h>
|
|
#include <grass/glocale.h>
|
|
@@ -24,8 +25,6 @@
|
|
|
|
|
|
struct ps_state ps;
|
|
struct ps_state ps;
|
|
|
|
|
|
-static const char *file_name;
|
|
|
|
-
|
|
|
|
static double width, height;
|
|
static double width, height;
|
|
static int landscape;
|
|
static int landscape;
|
|
|
|
|
|
@@ -72,7 +71,7 @@ static void write_prolog(void)
|
|
|
|
|
|
output("%%%%LanguageLevel: %d\n", 3);
|
|
output("%%%%LanguageLevel: %d\n", 3);
|
|
output("%%%%Creator: GRASS PS Driver\n");
|
|
output("%%%%Creator: GRASS PS Driver\n");
|
|
- output("%%%%Title: %s\n", file_name);
|
|
|
|
|
|
+ output("%%%%Title: %s\n", ps.outfile);
|
|
output("%%%%For: %s\n", G_whoami());
|
|
output("%%%%For: %s\n", G_whoami());
|
|
output("%%%%Orientation: %s\n", landscape ? "Landscape" : "Portrait");
|
|
output("%%%%Orientation: %s\n", landscape ? "Landscape" : "Portrait");
|
|
output("%%%%BoundingBox: %d %d %d %d\n",
|
|
output("%%%%BoundingBox: %d %d %d %d\n",
|
|
@@ -88,7 +87,7 @@ static void write_prolog(void)
|
|
if (!fgets(buf, sizeof(buf), prolog_fp))
|
|
if (!fgets(buf, sizeof(buf), prolog_fp))
|
|
break;
|
|
break;
|
|
|
|
|
|
- fputs(buf, ps.outfp);
|
|
|
|
|
|
+ fputs(buf, ps.tempfp);
|
|
}
|
|
}
|
|
output("%%%%EndProlog\n");
|
|
output("%%%%EndProlog\n");
|
|
|
|
|
|
@@ -180,8 +179,8 @@ int PS_Graph_set(void)
|
|
if (!p || strlen(p) == 0)
|
|
if (!p || strlen(p) == 0)
|
|
p = FILE_NAME;
|
|
p = FILE_NAME;
|
|
|
|
|
|
- file_name = p;
|
|
|
|
- p = file_name + strlen(file_name) - 4;
|
|
|
|
|
|
+ ps.outfile = p;
|
|
|
|
+ p = ps.outfile + strlen(ps.outfile) - 4;
|
|
ps.encapsulated = (G_strcasecmp(p, ".eps") == 0);
|
|
ps.encapsulated = (G_strcasecmp(p, ".eps") == 0);
|
|
|
|
|
|
p = getenv("GRASS_RENDER_TRUECOLOR");
|
|
p = getenv("GRASS_RENDER_TRUECOLOR");
|
|
@@ -201,21 +200,25 @@ int PS_Graph_set(void)
|
|
|
|
|
|
get_paper();
|
|
get_paper();
|
|
|
|
|
|
- ps.outfp = fopen(file_name, ps.no_header ? "a" : "w");
|
|
|
|
|
|
+ ps.tempfile = G_tempfile();
|
|
|
|
+ if (ps.no_header && access(ps.outfile, F_OK) == 0)
|
|
|
|
+ G_rename_file(ps.outfile, ps.tempfile);
|
|
|
|
+
|
|
|
|
+ ps.tempfp = fopen(ps.tempfile, ps.no_header ? "a" : "w");
|
|
|
|
|
|
- if (!ps.outfp)
|
|
|
|
- G_fatal_error("Unable to open output file: %s", file_name);
|
|
|
|
|
|
+ if (!ps.tempfp)
|
|
|
|
+ G_fatal_error("Unable to open output file: %s", ps.outfile);
|
|
|
|
|
|
if (!ps.no_header) {
|
|
if (!ps.no_header) {
|
|
write_prolog();
|
|
write_prolog();
|
|
write_setup();
|
|
write_setup();
|
|
}
|
|
}
|
|
|
|
|
|
- G_verbose_message(_("ps: collecting to file '%s'"), file_name);
|
|
|
|
|
|
+ G_verbose_message(_("ps: collecting to file '%s'"), ps.outfile);
|
|
G_verbose_message(_("ps: image size %dx%d"),
|
|
G_verbose_message(_("ps: image size %dx%d"),
|
|
screen_width, screen_height);
|
|
screen_width, screen_height);
|
|
|
|
|
|
- fflush(ps.outfp);
|
|
|
|
|
|
+ fflush(ps.tempfp);
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -227,7 +230,7 @@ int PS_Graph_set(void)
|
|
*/
|
|
*/
|
|
const char *PS_Graph_get_file(void)
|
|
const char *PS_Graph_get_file(void)
|
|
{
|
|
{
|
|
- return file_name;
|
|
|
|
|
|
+ return ps.outfile;
|
|
}
|
|
}
|
|
|
|
|
|
void output(const char *fmt, ...)
|
|
void output(const char *fmt, ...)
|
|
@@ -235,6 +238,6 @@ void output(const char *fmt, ...)
|
|
va_list va;
|
|
va_list va;
|
|
|
|
|
|
va_start(va, fmt);
|
|
va_start(va, fmt);
|
|
- vfprintf(ps.outfp, fmt, va);
|
|
|
|
|
|
+ vfprintf(ps.tempfp, fmt, va);
|
|
va_end(va);
|
|
va_end(va);
|
|
}
|
|
}
|