1 /*
2  *      cook - file construction tool
3  *      Copyright (C) 1994, 1997, 2006, 2007 Peter Miller;
4  *      All rights reserved.
5  *
6  *      This program is free software; you can redistribute it and/or modify
7  *      it under the terms of the GNU General Public License as published by
8  *      the Free Software Foundation; either version 3 of the License, or
9  *      (at your option) any later version.
10  *
11  *      This program is distributed in the hope that it will be useful,
12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *      GNU General Public License for more details.
15  *
16  *      You should have received a copy of the GNU General Public License
17  *      along with this program. If not, see
18  *      <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <make2cook/emit.h>
22 #include <common/mem.h>
23 #include <make2cook/stmt/define.h>
24 
25 typedef struct stmt_define_ty stmt_define_ty;
26 struct stmt_define_ty
27 {
28     STMT
29     blob_ty         *first;
30     blob_list_ty    *body;
31 };
32 
33 
34 static void
constructor(stmt_ty * that)35 constructor(stmt_ty *that)
36 {
37     stmt_define_ty  *this;
38 
39     this = (stmt_define_ty *)that;
40     this->first = 0;
41     this->body = blob_list_alloc();
42 }
43 
44 
45 static void
destructor(stmt_ty * that)46 destructor(stmt_ty *that)
47 {
48     stmt_define_ty  *this;
49 
50     this = (stmt_define_ty *)that;
51     if (this->first)
52         blob_free(this->first);
53     blob_list_free(this->body);
54 }
55 
56 
57 static void
emit(stmt_ty * that)58 emit(stmt_ty *that)
59 {
60     stmt_define_ty  *this;
61     size_t          j;
62 
63     this = (stmt_define_ty *)that;
64     blob_emit(this->first);
65     emit_str(" =\n");
66 
67     for (j = 0; j < this->body->length; ++j)
68     {
69         emit_str("    ");
70         blob_emit(this->body->list[j]);
71         emit_str(" \"\\n\"\n");
72     }
73     emit_str("    ;\n");
74 }
75 
76 
77 static stmt_method_ty method =
78 {
79     sizeof(stmt_define_ty),
80     "define",
81     constructor,
82     destructor,
83     emit,
84     0,
85     0,
86 };
87 
88 
89 stmt_ty *
stmt_define_alloc(blob_ty * first)90 stmt_define_alloc(blob_ty *first)
91 {
92     stmt_define_ty  *result;
93 
94     result = (stmt_define_ty *)stmt_alloc(&method);
95     result->first = first;
96     return (stmt_ty *)result;
97 }
98 
99 
100 void
stmt_define_append(stmt_ty * that,blob_ty * lp)101 stmt_define_append(stmt_ty *that, blob_ty *lp)
102 {
103     stmt_define_ty  *this;
104 
105     this = (stmt_define_ty *)that;
106     blob_list_append(this->body, lp);
107 }
108