mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2025-04-21 12:27:27 +03:00
cameo: added command "append", improved file output error checking
- README: added description of "append" - lang.l, lang.y: added command "append" - gnuplot.h, gnuplot.c (gnuplot_append): append gnuplot paths to an existing file - gnuplot.c (gnuplot_do_write): if writing to standard output, at least check that fflush() works at the end
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "path.h"
|
||||
#include "gnuplot.h"
|
||||
@@ -99,8 +100,13 @@ static int gnuplot_do_write(FILE *file, const struct path *paths)
|
||||
if (fprintf(file, "%f %f %f\n", p->x, p->y, p->z) < 0)
|
||||
return 0;
|
||||
}
|
||||
if (file != stdout && fclose(file) < 0)
|
||||
return 0;
|
||||
if (file == stdout) {
|
||||
if (fflush(file) == EOF)
|
||||
return 0;
|
||||
} else {
|
||||
if (fclose(file) < 0)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -120,3 +126,30 @@ void gnuplot_write(const char *name, const struct path *paths)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void gnuplot_append(const char *name, const struct path *paths)
|
||||
{
|
||||
FILE *file;
|
||||
struct stat st;
|
||||
|
||||
if (!name) {
|
||||
printf("\n");
|
||||
gnuplot_write(NULL, paths);
|
||||
return;
|
||||
}
|
||||
file = fopen(name, "a");
|
||||
if (!file) {
|
||||
perror(name);
|
||||
exit(1);
|
||||
}
|
||||
if (stat(name, &st) < 0) {
|
||||
perror("lstat");
|
||||
exit(1);
|
||||
}
|
||||
if (!S_ISREG(st.st_mode) || st.st_size)
|
||||
fprintf(file, "\n");
|
||||
if (!gnuplot_do_write(file, paths)) {
|
||||
perror(name);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user