1 /*
2 * cook - file construction tool
3 * Copyright (C) 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 <make2cook/stmt/unexport.h>
23 #include <common/symtab.h>
24 #include <make2cook/variable.h>
25
26 typedef struct stmt_unexport_ty stmt_unexport_ty;
27 struct stmt_unexport_ty
28 {
29 STMT
30 blob_ty *name;
31 };
32
33
34 static void
destructor(stmt_ty * that)35 destructor(stmt_ty *that)
36 {
37 stmt_unexport_ty *this;
38
39 this = (stmt_unexport_ty *)that;
40 blob_free(this->name);
41 }
42
43
44 static void
emit(stmt_ty * that)45 emit(stmt_ty *that)
46 {
47 stmt_unexport_ty *this;
48
49 this = (stmt_unexport_ty *)that;
50 emit_line_number(this->name->line_number, this->name->file_name);
51 emit_str("unsetenv ");
52 emit_string(this->name->text);
53 emit_str(";\n");
54 }
55
56
57 static stmt_method_ty method =
58 {
59 sizeof(stmt_unexport_ty),
60 "unexport",
61 0, /* constructor */
62 destructor,
63 emit,
64 0,
65 0,
66 };
67
68
69 stmt_ty *
stmt_unexport_alloc(blob_ty * name)70 stmt_unexport_alloc(blob_ty *name)
71 {
72 stmt_unexport_ty *this;
73 blob_list_ty *tmp;
74
75 this = (stmt_unexport_ty *)stmt_alloc(&method);
76
77 /*
78 * turn the make names into cook names
79 */
80 tmp = blob_list_alloc();
81 variable_rename(name, tmp, &this->ref, VAREN_QUOTE_SPACES);
82 blob_free(name);
83
84 this->name = blob_copy(tmp->list[0]);
85 blob_list_free(tmp);
86
87 return (stmt_ty *)this;
88 }
89