mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-22 23:04:16 +02: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:
parent
7a64e425da
commit
b8f6545821
@ -45,10 +45,13 @@ translation.
|
||||
File output:
|
||||
|
||||
write [<filename>]
|
||||
append [<filenname>]
|
||||
|
||||
Writes all loaded paths in gnuplot format to the specified file. If the
|
||||
file name is omitted, "write" writes to standard output.
|
||||
|
||||
"append" is like "write", except that it appends to an existing file.
|
||||
|
||||
File names can contain spaces and any printable characters, but no leading
|
||||
or trailing spaces. It is not possible to place a comment after a file
|
||||
name or at a place where a file name could be.
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,8 @@ NUM -?[0-9]+\.?[0-9]*
|
||||
<INITIAL>translate return TOK_TRANSLATE;
|
||||
<INITIAL>z return TOK_Z;
|
||||
|
||||
<INITIAL>append { BEGIN(FILENAME);
|
||||
return TOK_APPEND; }
|
||||
<INITIAL>gerber { file_name_follows = 1;
|
||||
return TOK_GERBER; }
|
||||
<INITIAL>gnuplot { file_name_follows = 1;
|
||||
|
@ -152,7 +152,7 @@ static struct path **classify(struct path **anchor, struct path *path)
|
||||
%token TOK_ALIGN TOK_ARRAY TOK_CLEAR TOK_DRILL TOK_EMPTY
|
||||
%token TOK_MILL TOK_OFFSET TOK_REMAINDER TOK_RESET
|
||||
%token TOK_TRANSLATE TOK_Z
|
||||
%token TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE
|
||||
%token TOK_APPEND TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE
|
||||
%token TOK_DOG TOK_INSIDE
|
||||
|
||||
%token <num> NUM_EXP_MIL NUM_EXP_MM NUM_IMP_MIL NUM_IMP_MM REF
|
||||
@ -241,6 +241,12 @@ command:
|
||||
gnuplot_write($2, paths);
|
||||
translate(0, 0, -zo);
|
||||
}
|
||||
| TOK_APPEND opt_filename
|
||||
{
|
||||
translate(0, 0, zo);
|
||||
gnuplot_append($2, paths);
|
||||
translate(0, 0, -zo);
|
||||
}
|
||||
| TOK_DRILL dimen dimen
|
||||
{
|
||||
struct path **walk;
|
||||
|
Loading…
Reference in New Issue
Block a user