mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 04:13:20 +02:00
Project description files can now begin with comment lines.
- solidify/project.h (struct project), solidify/project.c (make_project, load_project, save_project): allow project descriptions to begin with any numer of comment lines and preserve them across sessions
This commit is contained in:
parent
d9ddd52427
commit
34117153cb
@ -30,6 +30,7 @@ static struct project *make_project(const char *name,
|
|||||||
|
|
||||||
prj = alloc_type(struct project);
|
prj = alloc_type(struct project);
|
||||||
prj->name = stralloc(name);
|
prj->name = stralloc(name);
|
||||||
|
prj->comment = NULL;
|
||||||
prj->top = stralloc(top);
|
prj->top = stralloc(top);
|
||||||
prj->bottom = stralloc(bottom);
|
prj->bottom = stralloc(bottom);
|
||||||
prj->s.a = read_face(top);
|
prj->s.a = read_face(top);
|
||||||
@ -112,6 +113,7 @@ struct project *load_project(const char *name)
|
|||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char top[1000], bottom[1000]; /* @@@ enough */
|
char top[1000], bottom[1000]; /* @@@ enough */
|
||||||
|
char *comment;
|
||||||
struct project *prj;
|
struct project *prj;
|
||||||
|
|
||||||
file = fopen(name, "r");
|
file = fopen(name, "r");
|
||||||
@ -120,10 +122,19 @@ struct project *load_project(const char *name)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
comment = stralloc("");
|
||||||
|
|
||||||
|
while (1) {
|
||||||
if (!fgets(top, sizeof(top), file)) {
|
if (!fgets(top, sizeof(top), file)) {
|
||||||
fprintf(stderr, "%s: can't read name of top face\n", name);
|
fprintf(stderr, "%s: can't read name of top face\n",
|
||||||
|
name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
if (*top != '#')
|
||||||
|
break;
|
||||||
|
comment = realloc(comment, strlen(comment)+strlen(top)+1);
|
||||||
|
strcat(comment, top);
|
||||||
|
}
|
||||||
if (strchr(top, '\n'))
|
if (strchr(top, '\n'))
|
||||||
*strchr(top, '\n') = 0;
|
*strchr(top, '\n') = 0;
|
||||||
|
|
||||||
@ -136,7 +147,7 @@ struct project *load_project(const char *name)
|
|||||||
*strchr(bottom, '\n') = 0;
|
*strchr(bottom, '\n') = 0;
|
||||||
|
|
||||||
prj = make_project(name, top, bottom, 0);
|
prj = make_project(name, top, bottom, 0);
|
||||||
|
prj->comment = comment;
|
||||||
read_optional(file, prj);
|
read_optional(file, prj);
|
||||||
|
|
||||||
return prj;
|
return prj;
|
||||||
@ -172,8 +183,8 @@ void save_project(const struct project *prj)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (fprintf(file,
|
if (fprintf(file,
|
||||||
"%s\n%s\n%g\n", prj->top, prj->bottom,
|
"%s%s\n%s\n%g\n", prj->comment ? prj->comment : "",
|
||||||
prj->s.dist*prj->s.a->z_step) < 0) {
|
prj->top, prj->bottom, prj->s.dist*prj->s.a->z_step) < 0) {
|
||||||
perror(tmp);
|
perror(tmp);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
/*
|
/*
|
||||||
* Project file structure:
|
* Project file structure:
|
||||||
*
|
*
|
||||||
|
* Zero or more comment lines beginning with a hash sign (#)
|
||||||
* line 1: file name of top face (required)
|
* line 1: file name of top face (required)
|
||||||
* line 2: file name of bottom face (required)
|
* line 2: file name of bottom face (required)
|
||||||
* line 3 and beyond, separated by whitespace:
|
* line 3 and beyond, separated by whitespace:
|
||||||
@ -34,6 +35,7 @@
|
|||||||
|
|
||||||
struct project {
|
struct project {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
const char *comment;
|
||||||
const char *top;
|
const char *top;
|
||||||
const char *bottom;
|
const char *bottom;
|
||||||
struct solid s;
|
struct solid s;
|
||||||
|
Loading…
Reference in New Issue
Block a user